]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/ada/sem_util.adb
[Ada] Do not rewrite argument of pragma Entry_Queue_Length in analysis
[thirdparty/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-2019, 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 Treepr; -- ???For debugging code below
27
28 with Aspects; use Aspects;
29 with Casing; use Casing;
30 with Checks; use Checks;
31 with Debug; use Debug;
32 with Elists; use Elists;
33 with Errout; use Errout;
34 with Erroutc; use Erroutc;
35 with Exp_Ch11; use Exp_Ch11;
36 with Exp_Util; use Exp_Util;
37 with Fname; use Fname;
38 with Freeze; use Freeze;
39 with Lib; use Lib;
40 with Lib.Xref; use Lib.Xref;
41 with Namet.Sp; use Namet.Sp;
42 with Nlists; use Nlists;
43 with Nmake; use Nmake;
44 with Output; use Output;
45 with Restrict; use Restrict;
46 with Rident; use Rident;
47 with Rtsfind; use Rtsfind;
48 with Sem; use Sem;
49 with Sem_Aux; use Sem_Aux;
50 with Sem_Attr; use Sem_Attr;
51 with Sem_Ch6; use Sem_Ch6;
52 with Sem_Ch8; use Sem_Ch8;
53 with Sem_Disp; use Sem_Disp;
54 with Sem_Elab; use Sem_Elab;
55 with Sem_Eval; use Sem_Eval;
56 with Sem_Prag; use Sem_Prag;
57 with Sem_Res; use Sem_Res;
58 with Sem_Warn; use Sem_Warn;
59 with Sem_Type; use Sem_Type;
60 with Sinfo; use Sinfo;
61 with Sinput; use Sinput;
62 with Stand; use Stand;
63 with Style;
64 with Stringt; use Stringt;
65 with Targparm; use Targparm;
66 with Tbuild; use Tbuild;
67 with Ttypes; use Ttypes;
68 with Uname; use Uname;
69
70 with GNAT.HTable; use GNAT.HTable;
71
72 package body Sem_Util is
73
74 ---------------------------
75 -- Local Data Structures --
76 ---------------------------
77
78 Invalid_Binder_Values : array (Scalar_Id) of Entity_Id := (others => Empty);
79 -- A collection to hold the entities of the variables declared in package
80 -- System.Scalar_Values which describe the invalid values of scalar types.
81
82 Invalid_Binder_Values_Set : Boolean := False;
83 -- This flag prevents multiple attempts to initialize Invalid_Binder_Values
84
85 Invalid_Floats : array (Float_Scalar_Id) of Ureal := (others => No_Ureal);
86 -- A collection to hold the invalid values of float types as specified by
87 -- pragma Initialize_Scalars.
88
89 Invalid_Integers : array (Integer_Scalar_Id) of Uint := (others => No_Uint);
90 -- A collection to hold the invalid values of integer types as specified
91 -- by pragma Initialize_Scalars.
92
93 -----------------------
94 -- Local Subprograms --
95 -----------------------
96
97 function Build_Component_Subtype
98 (C : List_Id;
99 Loc : Source_Ptr;
100 T : Entity_Id) return Node_Id;
101 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
102 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
103 -- Loc is the source location, T is the original subtype.
104
105 procedure Examine_Array_Bounds
106 (Typ : Entity_Id;
107 All_Static : out Boolean;
108 Has_Empty : out Boolean);
109 -- Inspect the index constraints of array type Typ. Flag All_Static is set
110 -- when all ranges are static. Flag Has_Empty is set only when All_Static
111 -- is set and indicates that at least one range is empty.
112
113 function Has_Enabled_Property
114 (Item_Id : Entity_Id;
115 Property : Name_Id) return Boolean;
116 -- Subsidiary to routines Async_xxx_Enabled and Effective_xxx_Enabled.
117 -- Determine whether an abstract state or a variable denoted by entity
118 -- Item_Id has enabled property Property.
119
120 function Has_Null_Extension (T : Entity_Id) return Boolean;
121 -- T is a derived tagged type. Check whether the type extension is null.
122 -- If the parent type is fully initialized, T can be treated as such.
123
124 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
125 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
126 -- with discriminants whose default values are static, examine only the
127 -- components in the selected variant to determine whether all of them
128 -- have a default.
129
130 type Null_Status_Kind is
131 (Is_Null,
132 -- This value indicates that a subexpression is known to have a null
133 -- value at compile time.
134
135 Is_Non_Null,
136 -- This value indicates that a subexpression is known to have a non-null
137 -- value at compile time.
138
139 Unknown);
140 -- This value indicates that it cannot be determined at compile time
141 -- whether a subexpression yields a null or non-null value.
142
143 function Null_Status (N : Node_Id) return Null_Status_Kind;
144 -- Determine whether subexpression N of an access type yields a null value,
145 -- a non-null value, or the value cannot be determined at compile time. The
146 -- routine does not take simple flow diagnostics into account, it relies on
147 -- static facts such as the presence of null exclusions.
148
149 function Old_Requires_Transient_Scope (Id : Entity_Id) return Boolean;
150 function New_Requires_Transient_Scope (Id : Entity_Id) return Boolean;
151 -- ???We retain the old and new algorithms for Requires_Transient_Scope for
152 -- the time being. New_Requires_Transient_Scope is used by default; the
153 -- debug switch -gnatdQ can be used to do Old_Requires_Transient_Scope
154 -- instead. The intent is to use this temporarily to measure before/after
155 -- efficiency. Note: when this temporary code is removed, the documentation
156 -- of dQ in debug.adb should be removed.
157
158 procedure Results_Differ
159 (Id : Entity_Id;
160 Old_Val : Boolean;
161 New_Val : Boolean);
162 -- ???Debugging code. Called when the Old_Val and New_Val differ. This
163 -- routine will be removed eventially when New_Requires_Transient_Scope
164 -- becomes Requires_Transient_Scope and Old_Requires_Transient_Scope is
165 -- eliminated.
166
167 function Subprogram_Name (N : Node_Id) return String;
168 -- Return the fully qualified name of the enclosing subprogram for the
169 -- given node N, with file:line:col information appended, e.g.
170 -- "subp:file:line:col", corresponding to the source location of the
171 -- body of the subprogram.
172
173 ------------------------------
174 -- Abstract_Interface_List --
175 ------------------------------
176
177 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
178 Nod : Node_Id;
179
180 begin
181 if Is_Concurrent_Type (Typ) then
182
183 -- If we are dealing with a synchronized subtype, go to the base
184 -- type, whose declaration has the interface list.
185
186 Nod := Declaration_Node (Base_Type (Typ));
187
188 if Nkind_In (Nod, N_Full_Type_Declaration,
189 N_Private_Type_Declaration)
190 then
191 return Empty_List;
192 end if;
193
194 elsif Ekind (Typ) = E_Record_Type_With_Private then
195 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
196 Nod := Type_Definition (Parent (Typ));
197
198 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
199 if Present (Full_View (Typ))
200 and then
201 Nkind (Parent (Full_View (Typ))) = N_Full_Type_Declaration
202 then
203 Nod := Type_Definition (Parent (Full_View (Typ)));
204
205 -- If the full-view is not available we cannot do anything else
206 -- here (the source has errors).
207
208 else
209 return Empty_List;
210 end if;
211
212 -- Support for generic formals with interfaces is still missing ???
213
214 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
215 return Empty_List;
216
217 else
218 pragma Assert
219 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
220 Nod := Parent (Typ);
221 end if;
222
223 elsif Ekind (Typ) = E_Record_Subtype then
224 Nod := Type_Definition (Parent (Etype (Typ)));
225
226 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
227
228 -- Recurse, because parent may still be a private extension. Also
229 -- note that the full view of the subtype or the full view of its
230 -- base type may (both) be unavailable.
231
232 return Abstract_Interface_List (Etype (Typ));
233
234 elsif Ekind (Typ) = E_Record_Type then
235 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
236 Nod := Formal_Type_Definition (Parent (Typ));
237 else
238 Nod := Type_Definition (Parent (Typ));
239 end if;
240
241 -- Otherwise the type is of a kind which does not implement interfaces
242
243 else
244 return Empty_List;
245 end if;
246
247 return Interface_List (Nod);
248 end Abstract_Interface_List;
249
250 ----------------------------------
251 -- Acquire_Warning_Match_String --
252 ----------------------------------
253
254 function Acquire_Warning_Match_String (Str_Lit : Node_Id) return String is
255 S : constant String := To_String (Strval (Str_Lit));
256 begin
257 if S = "" then
258 return "";
259 else
260 -- Put "*" before or after or both, if it's not already there
261
262 declare
263 F : constant Boolean := S (S'First) = '*';
264 L : constant Boolean := S (S'Last) = '*';
265 begin
266 if F then
267 if L then
268 return S;
269 else
270 return S & "*";
271 end if;
272 else
273 if L then
274 return "*" & S;
275 else
276 return "*" & S & "*";
277 end if;
278 end if;
279 end;
280 end if;
281 end Acquire_Warning_Match_String;
282
283 --------------------------------
284 -- Add_Access_Type_To_Process --
285 --------------------------------
286
287 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
288 L : Elist_Id;
289
290 begin
291 Ensure_Freeze_Node (E);
292 L := Access_Types_To_Process (Freeze_Node (E));
293
294 if No (L) then
295 L := New_Elmt_List;
296 Set_Access_Types_To_Process (Freeze_Node (E), L);
297 end if;
298
299 Append_Elmt (A, L);
300 end Add_Access_Type_To_Process;
301
302 --------------------------
303 -- Add_Block_Identifier --
304 --------------------------
305
306 procedure Add_Block_Identifier (N : Node_Id; Id : out Entity_Id) is
307 Loc : constant Source_Ptr := Sloc (N);
308
309 begin
310 pragma Assert (Nkind (N) = N_Block_Statement);
311
312 -- The block already has a label, return its entity
313
314 if Present (Identifier (N)) then
315 Id := Entity (Identifier (N));
316
317 -- Create a new block label and set its attributes
318
319 else
320 Id := New_Internal_Entity (E_Block, Current_Scope, Loc, 'B');
321 Set_Etype (Id, Standard_Void_Type);
322 Set_Parent (Id, N);
323
324 Set_Identifier (N, New_Occurrence_Of (Id, Loc));
325 Set_Block_Node (Id, Identifier (N));
326 end if;
327 end Add_Block_Identifier;
328
329 ----------------------------
330 -- Add_Global_Declaration --
331 ----------------------------
332
333 procedure Add_Global_Declaration (N : Node_Id) is
334 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
335
336 begin
337 if No (Declarations (Aux_Node)) then
338 Set_Declarations (Aux_Node, New_List);
339 end if;
340
341 Append_To (Declarations (Aux_Node), N);
342 Analyze (N);
343 end Add_Global_Declaration;
344
345 --------------------------------
346 -- Address_Integer_Convert_OK --
347 --------------------------------
348
349 function Address_Integer_Convert_OK (T1, T2 : Entity_Id) return Boolean is
350 begin
351 if Allow_Integer_Address
352 and then ((Is_Descendant_Of_Address (T1)
353 and then Is_Private_Type (T1)
354 and then Is_Integer_Type (T2))
355 or else
356 (Is_Descendant_Of_Address (T2)
357 and then Is_Private_Type (T2)
358 and then Is_Integer_Type (T1)))
359 then
360 return True;
361 else
362 return False;
363 end if;
364 end Address_Integer_Convert_OK;
365
366 -------------------
367 -- Address_Value --
368 -------------------
369
370 function Address_Value (N : Node_Id) return Node_Id is
371 Expr : Node_Id := N;
372
373 begin
374 loop
375 -- For constant, get constant expression
376
377 if Is_Entity_Name (Expr)
378 and then Ekind (Entity (Expr)) = E_Constant
379 then
380 Expr := Constant_Value (Entity (Expr));
381
382 -- For unchecked conversion, get result to convert
383
384 elsif Nkind (Expr) = N_Unchecked_Type_Conversion then
385 Expr := Expression (Expr);
386
387 -- For (common case) of To_Address call, get argument
388
389 elsif Nkind (Expr) = N_Function_Call
390 and then Is_Entity_Name (Name (Expr))
391 and then Is_RTE (Entity (Name (Expr)), RE_To_Address)
392 then
393 Expr := First (Parameter_Associations (Expr));
394
395 if Nkind (Expr) = N_Parameter_Association then
396 Expr := Explicit_Actual_Parameter (Expr);
397 end if;
398
399 -- We finally have the real expression
400
401 else
402 exit;
403 end if;
404 end loop;
405
406 return Expr;
407 end Address_Value;
408
409 -----------------
410 -- Addressable --
411 -----------------
412
413 -- For now, just 8/16/32/64
414
415 function Addressable (V : Uint) return Boolean is
416 begin
417 return V = Uint_8 or else
418 V = Uint_16 or else
419 V = Uint_32 or else
420 V = Uint_64;
421 end Addressable;
422
423 function Addressable (V : Int) return Boolean is
424 begin
425 return V = 8 or else
426 V = 16 or else
427 V = 32 or else
428 V = 64;
429 end Addressable;
430
431 ---------------------------------
432 -- Aggregate_Constraint_Checks --
433 ---------------------------------
434
435 procedure Aggregate_Constraint_Checks
436 (Exp : Node_Id;
437 Check_Typ : Entity_Id)
438 is
439 Exp_Typ : constant Entity_Id := Etype (Exp);
440
441 begin
442 if Raises_Constraint_Error (Exp) then
443 return;
444 end if;
445
446 -- Ada 2005 (AI-230): Generate a conversion to an anonymous access
447 -- component's type to force the appropriate accessibility checks.
448
449 -- Ada 2005 (AI-231): Generate conversion to the null-excluding type to
450 -- force the corresponding run-time check
451
452 if Is_Access_Type (Check_Typ)
453 and then Is_Local_Anonymous_Access (Check_Typ)
454 then
455 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
456 Analyze_And_Resolve (Exp, Check_Typ);
457 Check_Unset_Reference (Exp);
458 end if;
459
460 -- What follows is really expansion activity, so check that expansion
461 -- is on and is allowed. In GNATprove mode, we also want check flags to
462 -- be added in the tree, so that the formal verification can rely on
463 -- those to be present. In GNATprove mode for formal verification, some
464 -- treatment typically only done during expansion needs to be performed
465 -- on the tree, but it should not be applied inside generics. Otherwise,
466 -- this breaks the name resolution mechanism for generic instances.
467
468 if not Expander_Active
469 and (Inside_A_Generic or not Full_Analysis or not GNATprove_Mode)
470 then
471 return;
472 end if;
473
474 if Is_Access_Type (Check_Typ)
475 and then Can_Never_Be_Null (Check_Typ)
476 and then not Can_Never_Be_Null (Exp_Typ)
477 then
478 Install_Null_Excluding_Check (Exp);
479 end if;
480
481 -- First check if we have to insert discriminant checks
482
483 if Has_Discriminants (Exp_Typ) then
484 Apply_Discriminant_Check (Exp, Check_Typ);
485
486 -- Next emit length checks for array aggregates
487
488 elsif Is_Array_Type (Exp_Typ) then
489 Apply_Length_Check (Exp, Check_Typ);
490
491 -- Finally emit scalar and string checks. If we are dealing with a
492 -- scalar literal we need to check by hand because the Etype of
493 -- literals is not necessarily correct.
494
495 elsif Is_Scalar_Type (Exp_Typ)
496 and then Compile_Time_Known_Value (Exp)
497 then
498 if Is_Out_Of_Range (Exp, Base_Type (Check_Typ)) then
499 Apply_Compile_Time_Constraint_Error
500 (Exp, "value not in range of}??", CE_Range_Check_Failed,
501 Ent => Base_Type (Check_Typ),
502 Typ => Base_Type (Check_Typ));
503
504 elsif Is_Out_Of_Range (Exp, Check_Typ) then
505 Apply_Compile_Time_Constraint_Error
506 (Exp, "value not in range of}??", CE_Range_Check_Failed,
507 Ent => Check_Typ,
508 Typ => Check_Typ);
509
510 elsif not Range_Checks_Suppressed (Check_Typ) then
511 Apply_Scalar_Range_Check (Exp, Check_Typ);
512 end if;
513
514 -- Verify that target type is also scalar, to prevent view anomalies
515 -- in instantiations.
516
517 elsif (Is_Scalar_Type (Exp_Typ)
518 or else Nkind (Exp) = N_String_Literal)
519 and then Is_Scalar_Type (Check_Typ)
520 and then Exp_Typ /= Check_Typ
521 then
522 if Is_Entity_Name (Exp)
523 and then Ekind (Entity (Exp)) = E_Constant
524 then
525 -- If expression is a constant, it is worthwhile checking whether
526 -- it is a bound of the type.
527
528 if (Is_Entity_Name (Type_Low_Bound (Check_Typ))
529 and then Entity (Exp) = Entity (Type_Low_Bound (Check_Typ)))
530 or else
531 (Is_Entity_Name (Type_High_Bound (Check_Typ))
532 and then Entity (Exp) = Entity (Type_High_Bound (Check_Typ)))
533 then
534 return;
535
536 else
537 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
538 Analyze_And_Resolve (Exp, Check_Typ);
539 Check_Unset_Reference (Exp);
540 end if;
541
542 -- Could use a comment on this case ???
543
544 else
545 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
546 Analyze_And_Resolve (Exp, Check_Typ);
547 Check_Unset_Reference (Exp);
548 end if;
549
550 end if;
551 end Aggregate_Constraint_Checks;
552
553 -----------------------
554 -- Alignment_In_Bits --
555 -----------------------
556
557 function Alignment_In_Bits (E : Entity_Id) return Uint is
558 begin
559 return Alignment (E) * System_Storage_Unit;
560 end Alignment_In_Bits;
561
562 --------------------------------------
563 -- All_Composite_Constraints_Static --
564 --------------------------------------
565
566 function All_Composite_Constraints_Static
567 (Constr : Node_Id) return Boolean
568 is
569 begin
570 if No (Constr) or else Error_Posted (Constr) then
571 return True;
572 end if;
573
574 case Nkind (Constr) is
575 when N_Subexpr =>
576 if Nkind (Constr) in N_Has_Entity
577 and then Present (Entity (Constr))
578 then
579 if Is_Type (Entity (Constr)) then
580 return
581 not Is_Discrete_Type (Entity (Constr))
582 or else Is_OK_Static_Subtype (Entity (Constr));
583 end if;
584
585 elsif Nkind (Constr) = N_Range then
586 return
587 Is_OK_Static_Expression (Low_Bound (Constr))
588 and then
589 Is_OK_Static_Expression (High_Bound (Constr));
590
591 elsif Nkind (Constr) = N_Attribute_Reference
592 and then Attribute_Name (Constr) = Name_Range
593 then
594 return
595 Is_OK_Static_Expression
596 (Type_Low_Bound (Etype (Prefix (Constr))))
597 and then
598 Is_OK_Static_Expression
599 (Type_High_Bound (Etype (Prefix (Constr))));
600 end if;
601
602 return
603 not Present (Etype (Constr)) -- previous error
604 or else not Is_Discrete_Type (Etype (Constr))
605 or else Is_OK_Static_Expression (Constr);
606
607 when N_Discriminant_Association =>
608 return All_Composite_Constraints_Static (Expression (Constr));
609
610 when N_Range_Constraint =>
611 return
612 All_Composite_Constraints_Static (Range_Expression (Constr));
613
614 when N_Index_Or_Discriminant_Constraint =>
615 declare
616 One_Cstr : Entity_Id;
617 begin
618 One_Cstr := First (Constraints (Constr));
619 while Present (One_Cstr) loop
620 if not All_Composite_Constraints_Static (One_Cstr) then
621 return False;
622 end if;
623
624 Next (One_Cstr);
625 end loop;
626 end;
627
628 return True;
629
630 when N_Subtype_Indication =>
631 return
632 All_Composite_Constraints_Static (Subtype_Mark (Constr))
633 and then
634 All_Composite_Constraints_Static (Constraint (Constr));
635
636 when others =>
637 raise Program_Error;
638 end case;
639 end All_Composite_Constraints_Static;
640
641 ------------------------
642 -- Append_Entity_Name --
643 ------------------------
644
645 procedure Append_Entity_Name (Buf : in out Bounded_String; E : Entity_Id) is
646 Temp : Bounded_String;
647
648 procedure Inner (E : Entity_Id);
649 -- Inner recursive routine, keep outer routine nonrecursive to ease
650 -- debugging when we get strange results from this routine.
651
652 -----------
653 -- Inner --
654 -----------
655
656 procedure Inner (E : Entity_Id) is
657 Scop : Node_Id;
658
659 begin
660 -- If entity has an internal name, skip by it, and print its scope.
661 -- Note that we strip a final R from the name before the test; this
662 -- is needed for some cases of instantiations.
663
664 declare
665 E_Name : Bounded_String;
666
667 begin
668 Append (E_Name, Chars (E));
669
670 if E_Name.Chars (E_Name.Length) = 'R' then
671 E_Name.Length := E_Name.Length - 1;
672 end if;
673
674 if Is_Internal_Name (E_Name) then
675 Inner (Scope (E));
676 return;
677 end if;
678 end;
679
680 Scop := Scope (E);
681
682 -- Just print entity name if its scope is at the outer level
683
684 if Scop = Standard_Standard then
685 null;
686
687 -- If scope comes from source, write scope and entity
688
689 elsif Comes_From_Source (Scop) then
690 Append_Entity_Name (Temp, Scop);
691 Append (Temp, '.');
692
693 -- If in wrapper package skip past it
694
695 elsif Present (Scop) and then Is_Wrapper_Package (Scop) then
696 Append_Entity_Name (Temp, Scope (Scop));
697 Append (Temp, '.');
698
699 -- Otherwise nothing to output (happens in unnamed block statements)
700
701 else
702 null;
703 end if;
704
705 -- Output the name
706
707 declare
708 E_Name : Bounded_String;
709
710 begin
711 Append_Unqualified_Decoded (E_Name, Chars (E));
712
713 -- Remove trailing upper-case letters from the name (useful for
714 -- dealing with some cases of internal names generated in the case
715 -- of references from within a generic).
716
717 while E_Name.Length > 1
718 and then E_Name.Chars (E_Name.Length) in 'A' .. 'Z'
719 loop
720 E_Name.Length := E_Name.Length - 1;
721 end loop;
722
723 -- Adjust casing appropriately (gets name from source if possible)
724
725 Adjust_Name_Case (E_Name, Sloc (E));
726 Append (Temp, E_Name);
727 end;
728 end Inner;
729
730 -- Start of processing for Append_Entity_Name
731
732 begin
733 Inner (E);
734 Append (Buf, Temp);
735 end Append_Entity_Name;
736
737 ---------------------------------
738 -- Append_Inherited_Subprogram --
739 ---------------------------------
740
741 procedure Append_Inherited_Subprogram (S : Entity_Id) is
742 Par : constant Entity_Id := Alias (S);
743 -- The parent subprogram
744
745 Scop : constant Entity_Id := Scope (Par);
746 -- The scope of definition of the parent subprogram
747
748 Typ : constant Entity_Id := Defining_Entity (Parent (S));
749 -- The derived type of which S is a primitive operation
750
751 Decl : Node_Id;
752 Next_E : Entity_Id;
753
754 begin
755 if Ekind (Current_Scope) = E_Package
756 and then In_Private_Part (Current_Scope)
757 and then Has_Private_Declaration (Typ)
758 and then Is_Tagged_Type (Typ)
759 and then Scop = Current_Scope
760 then
761 -- The inherited operation is available at the earliest place after
762 -- the derived type declaration (RM 7.3.1 (6/1)). This is only
763 -- relevant for type extensions. If the parent operation appears
764 -- after the type extension, the operation is not visible.
765
766 Decl := First
767 (Visible_Declarations
768 (Package_Specification (Current_Scope)));
769 while Present (Decl) loop
770 if Nkind (Decl) = N_Private_Extension_Declaration
771 and then Defining_Entity (Decl) = Typ
772 then
773 if Sloc (Decl) > Sloc (Par) then
774 Next_E := Next_Entity (Par);
775 Link_Entities (Par, S);
776 Link_Entities (S, Next_E);
777 return;
778
779 else
780 exit;
781 end if;
782 end if;
783
784 Next (Decl);
785 end loop;
786 end if;
787
788 -- If partial view is not a type extension, or it appears before the
789 -- subprogram declaration, insert normally at end of entity list.
790
791 Append_Entity (S, Current_Scope);
792 end Append_Inherited_Subprogram;
793
794 -----------------------------------------
795 -- Apply_Compile_Time_Constraint_Error --
796 -----------------------------------------
797
798 procedure Apply_Compile_Time_Constraint_Error
799 (N : Node_Id;
800 Msg : String;
801 Reason : RT_Exception_Code;
802 Ent : Entity_Id := Empty;
803 Typ : Entity_Id := Empty;
804 Loc : Source_Ptr := No_Location;
805 Rep : Boolean := True;
806 Warn : Boolean := False)
807 is
808 Stat : constant Boolean := Is_Static_Expression (N);
809 R_Stat : constant Node_Id :=
810 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
811 Rtyp : Entity_Id;
812
813 begin
814 if No (Typ) then
815 Rtyp := Etype (N);
816 else
817 Rtyp := Typ;
818 end if;
819
820 Discard_Node
821 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
822
823 -- In GNATprove mode, do not replace the node with an exception raised.
824 -- In such a case, either the call to Compile_Time_Constraint_Error
825 -- issues an error which stops analysis, or it issues a warning in
826 -- a few cases where a suitable check flag is set for GNATprove to
827 -- generate a check message.
828
829 if not Rep or GNATprove_Mode then
830 return;
831 end if;
832
833 -- Now we replace the node by an N_Raise_Constraint_Error node
834 -- This does not need reanalyzing, so set it as analyzed now.
835
836 Rewrite (N, R_Stat);
837 Set_Analyzed (N, True);
838
839 Set_Etype (N, Rtyp);
840 Set_Raises_Constraint_Error (N);
841
842 -- Now deal with possible local raise handling
843
844 Possible_Local_Raise (N, Standard_Constraint_Error);
845
846 -- If the original expression was marked as static, the result is
847 -- still marked as static, but the Raises_Constraint_Error flag is
848 -- always set so that further static evaluation is not attempted.
849
850 if Stat then
851 Set_Is_Static_Expression (N);
852 end if;
853 end Apply_Compile_Time_Constraint_Error;
854
855 ---------------------------
856 -- Async_Readers_Enabled --
857 ---------------------------
858
859 function Async_Readers_Enabled (Id : Entity_Id) return Boolean is
860 begin
861 return Has_Enabled_Property (Id, Name_Async_Readers);
862 end Async_Readers_Enabled;
863
864 ---------------------------
865 -- Async_Writers_Enabled --
866 ---------------------------
867
868 function Async_Writers_Enabled (Id : Entity_Id) return Boolean is
869 begin
870 return Has_Enabled_Property (Id, Name_Async_Writers);
871 end Async_Writers_Enabled;
872
873 --------------------------------------
874 -- Available_Full_View_Of_Component --
875 --------------------------------------
876
877 function Available_Full_View_Of_Component (T : Entity_Id) return Boolean is
878 ST : constant Entity_Id := Scope (T);
879 SCT : constant Entity_Id := Scope (Component_Type (T));
880 begin
881 return In_Open_Scopes (ST)
882 and then In_Open_Scopes (SCT)
883 and then Scope_Depth (ST) >= Scope_Depth (SCT);
884 end Available_Full_View_Of_Component;
885
886 -------------------
887 -- Bad_Attribute --
888 -------------------
889
890 procedure Bad_Attribute
891 (N : Node_Id;
892 Nam : Name_Id;
893 Warn : Boolean := False)
894 is
895 begin
896 Error_Msg_Warn := Warn;
897 Error_Msg_N ("unrecognized attribute&<<", N);
898
899 -- Check for possible misspelling
900
901 Error_Msg_Name_1 := First_Attribute_Name;
902 while Error_Msg_Name_1 <= Last_Attribute_Name loop
903 if Is_Bad_Spelling_Of (Nam, Error_Msg_Name_1) then
904 Error_Msg_N -- CODEFIX
905 ("\possible misspelling of %<<", N);
906 exit;
907 end if;
908
909 Error_Msg_Name_1 := Error_Msg_Name_1 + 1;
910 end loop;
911 end Bad_Attribute;
912
913 --------------------------------
914 -- Bad_Predicated_Subtype_Use --
915 --------------------------------
916
917 procedure Bad_Predicated_Subtype_Use
918 (Msg : String;
919 N : Node_Id;
920 Typ : Entity_Id;
921 Suggest_Static : Boolean := False)
922 is
923 Gen : Entity_Id;
924
925 begin
926 -- Avoid cascaded errors
927
928 if Error_Posted (N) then
929 return;
930 end if;
931
932 if Inside_A_Generic then
933 Gen := Current_Scope;
934 while Present (Gen) and then Ekind (Gen) /= E_Generic_Package loop
935 Gen := Scope (Gen);
936 end loop;
937
938 if No (Gen) then
939 return;
940 end if;
941
942 if Is_Generic_Formal (Typ) and then Is_Discrete_Type (Typ) then
943 Set_No_Predicate_On_Actual (Typ);
944 end if;
945
946 elsif Has_Predicates (Typ) then
947 if Is_Generic_Actual_Type (Typ) then
948
949 -- The restriction on loop parameters is only that the type
950 -- should have no dynamic predicates.
951
952 if Nkind (Parent (N)) = N_Loop_Parameter_Specification
953 and then not Has_Dynamic_Predicate_Aspect (Typ)
954 and then Is_OK_Static_Subtype (Typ)
955 then
956 return;
957 end if;
958
959 Gen := Current_Scope;
960 while not Is_Generic_Instance (Gen) loop
961 Gen := Scope (Gen);
962 end loop;
963
964 pragma Assert (Present (Gen));
965
966 if Ekind (Gen) = E_Package and then In_Package_Body (Gen) then
967 Error_Msg_Warn := SPARK_Mode /= On;
968 Error_Msg_FE (Msg & "<<", N, Typ);
969 Error_Msg_F ("\Program_Error [<<", N);
970
971 Insert_Action (N,
972 Make_Raise_Program_Error (Sloc (N),
973 Reason => PE_Bad_Predicated_Generic_Type));
974
975 else
976 Error_Msg_FE (Msg & "<<", N, Typ);
977 end if;
978
979 else
980 Error_Msg_FE (Msg, N, Typ);
981 end if;
982
983 -- Emit an optional suggestion on how to remedy the error if the
984 -- context warrants it.
985
986 if Suggest_Static and then Has_Static_Predicate (Typ) then
987 Error_Msg_FE ("\predicate of & should be marked static", N, Typ);
988 end if;
989 end if;
990 end Bad_Predicated_Subtype_Use;
991
992 -----------------------------------------
993 -- Bad_Unordered_Enumeration_Reference --
994 -----------------------------------------
995
996 function Bad_Unordered_Enumeration_Reference
997 (N : Node_Id;
998 T : Entity_Id) return Boolean
999 is
1000 begin
1001 return Is_Enumeration_Type (T)
1002 and then Warn_On_Unordered_Enumeration_Type
1003 and then not Is_Generic_Type (T)
1004 and then Comes_From_Source (N)
1005 and then not Has_Pragma_Ordered (T)
1006 and then not In_Same_Extended_Unit (N, T);
1007 end Bad_Unordered_Enumeration_Reference;
1008
1009 ----------------------------
1010 -- Begin_Keyword_Location --
1011 ----------------------------
1012
1013 function Begin_Keyword_Location (N : Node_Id) return Source_Ptr is
1014 HSS : Node_Id;
1015
1016 begin
1017 pragma Assert (Nkind_In (N, N_Block_Statement,
1018 N_Entry_Body,
1019 N_Package_Body,
1020 N_Subprogram_Body,
1021 N_Task_Body));
1022
1023 HSS := Handled_Statement_Sequence (N);
1024
1025 -- When the handled sequence of statements comes from source, the
1026 -- location of the "begin" keyword is that of the sequence itself.
1027 -- Note that an internal construct may inherit a source sequence.
1028
1029 if Comes_From_Source (HSS) then
1030 return Sloc (HSS);
1031
1032 -- The parser generates an internal handled sequence of statements to
1033 -- capture the location of the "begin" keyword if present in the source.
1034 -- Since there are no source statements, the location of the "begin"
1035 -- keyword is effectively that of the "end" keyword.
1036
1037 elsif Comes_From_Source (N) then
1038 return Sloc (HSS);
1039
1040 -- Otherwise the construct is internal and should carry the location of
1041 -- the original construct which prompted its creation.
1042
1043 else
1044 return Sloc (N);
1045 end if;
1046 end Begin_Keyword_Location;
1047
1048 --------------------------
1049 -- Build_Actual_Subtype --
1050 --------------------------
1051
1052 function Build_Actual_Subtype
1053 (T : Entity_Id;
1054 N : Node_Or_Entity_Id) return Node_Id
1055 is
1056 Loc : Source_Ptr;
1057 -- Normally Sloc (N), but may point to corresponding body in some cases
1058
1059 Constraints : List_Id;
1060 Decl : Node_Id;
1061 Discr : Entity_Id;
1062 Hi : Node_Id;
1063 Lo : Node_Id;
1064 Subt : Entity_Id;
1065 Disc_Type : Entity_Id;
1066 Obj : Node_Id;
1067
1068 begin
1069 Loc := Sloc (N);
1070
1071 if Nkind (N) = N_Defining_Identifier then
1072 Obj := New_Occurrence_Of (N, Loc);
1073
1074 -- If this is a formal parameter of a subprogram declaration, and
1075 -- we are compiling the body, we want the declaration for the
1076 -- actual subtype to carry the source position of the body, to
1077 -- prevent anomalies in gdb when stepping through the code.
1078
1079 if Is_Formal (N) then
1080 declare
1081 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
1082 begin
1083 if Nkind (Decl) = N_Subprogram_Declaration
1084 and then Present (Corresponding_Body (Decl))
1085 then
1086 Loc := Sloc (Corresponding_Body (Decl));
1087 end if;
1088 end;
1089 end if;
1090
1091 else
1092 Obj := N;
1093 end if;
1094
1095 if Is_Array_Type (T) then
1096 Constraints := New_List;
1097 for J in 1 .. Number_Dimensions (T) loop
1098
1099 -- Build an array subtype declaration with the nominal subtype and
1100 -- the bounds of the actual. Add the declaration in front of the
1101 -- local declarations for the subprogram, for analysis before any
1102 -- reference to the formal in the body.
1103
1104 Lo :=
1105 Make_Attribute_Reference (Loc,
1106 Prefix =>
1107 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
1108 Attribute_Name => Name_First,
1109 Expressions => New_List (
1110 Make_Integer_Literal (Loc, J)));
1111
1112 Hi :=
1113 Make_Attribute_Reference (Loc,
1114 Prefix =>
1115 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
1116 Attribute_Name => Name_Last,
1117 Expressions => New_List (
1118 Make_Integer_Literal (Loc, J)));
1119
1120 Append (Make_Range (Loc, Lo, Hi), Constraints);
1121 end loop;
1122
1123 -- If the type has unknown discriminants there is no constrained
1124 -- subtype to build. This is never called for a formal or for a
1125 -- lhs, so returning the type is ok ???
1126
1127 elsif Has_Unknown_Discriminants (T) then
1128 return T;
1129
1130 else
1131 Constraints := New_List;
1132
1133 -- Type T is a generic derived type, inherit the discriminants from
1134 -- the parent type.
1135
1136 if Is_Private_Type (T)
1137 and then No (Full_View (T))
1138
1139 -- T was flagged as an error if it was declared as a formal
1140 -- derived type with known discriminants. In this case there
1141 -- is no need to look at the parent type since T already carries
1142 -- its own discriminants.
1143
1144 and then not Error_Posted (T)
1145 then
1146 Disc_Type := Etype (Base_Type (T));
1147 else
1148 Disc_Type := T;
1149 end if;
1150
1151 Discr := First_Discriminant (Disc_Type);
1152 while Present (Discr) loop
1153 Append_To (Constraints,
1154 Make_Selected_Component (Loc,
1155 Prefix =>
1156 Duplicate_Subexpr_No_Checks (Obj),
1157 Selector_Name => New_Occurrence_Of (Discr, Loc)));
1158 Next_Discriminant (Discr);
1159 end loop;
1160 end if;
1161
1162 Subt := Make_Temporary (Loc, 'S', Related_Node => N);
1163 Set_Is_Internal (Subt);
1164
1165 Decl :=
1166 Make_Subtype_Declaration (Loc,
1167 Defining_Identifier => Subt,
1168 Subtype_Indication =>
1169 Make_Subtype_Indication (Loc,
1170 Subtype_Mark => New_Occurrence_Of (T, Loc),
1171 Constraint =>
1172 Make_Index_Or_Discriminant_Constraint (Loc,
1173 Constraints => Constraints)));
1174
1175 Mark_Rewrite_Insertion (Decl);
1176 return Decl;
1177 end Build_Actual_Subtype;
1178
1179 ---------------------------------------
1180 -- Build_Actual_Subtype_Of_Component --
1181 ---------------------------------------
1182
1183 function Build_Actual_Subtype_Of_Component
1184 (T : Entity_Id;
1185 N : Node_Id) return Node_Id
1186 is
1187 Loc : constant Source_Ptr := Sloc (N);
1188 P : constant Node_Id := Prefix (N);
1189 D : Elmt_Id;
1190 Id : Node_Id;
1191 Index_Typ : Entity_Id;
1192
1193 Desig_Typ : Entity_Id;
1194 -- This is either a copy of T, or if T is an access type, then it is
1195 -- the directly designated type of this access type.
1196
1197 function Build_Actual_Array_Constraint return List_Id;
1198 -- If one or more of the bounds of the component depends on
1199 -- discriminants, build actual constraint using the discriminants
1200 -- of the prefix.
1201
1202 function Build_Actual_Record_Constraint return List_Id;
1203 -- Similar to previous one, for discriminated components constrained
1204 -- by the discriminant of the enclosing object.
1205
1206 -----------------------------------
1207 -- Build_Actual_Array_Constraint --
1208 -----------------------------------
1209
1210 function Build_Actual_Array_Constraint return List_Id is
1211 Constraints : constant List_Id := New_List;
1212 Indx : Node_Id;
1213 Hi : Node_Id;
1214 Lo : Node_Id;
1215 Old_Hi : Node_Id;
1216 Old_Lo : Node_Id;
1217
1218 begin
1219 Indx := First_Index (Desig_Typ);
1220 while Present (Indx) loop
1221 Old_Lo := Type_Low_Bound (Etype (Indx));
1222 Old_Hi := Type_High_Bound (Etype (Indx));
1223
1224 if Denotes_Discriminant (Old_Lo) then
1225 Lo :=
1226 Make_Selected_Component (Loc,
1227 Prefix => New_Copy_Tree (P),
1228 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
1229
1230 else
1231 Lo := New_Copy_Tree (Old_Lo);
1232
1233 -- The new bound will be reanalyzed in the enclosing
1234 -- declaration. For literal bounds that come from a type
1235 -- declaration, the type of the context must be imposed, so
1236 -- insure that analysis will take place. For non-universal
1237 -- types this is not strictly necessary.
1238
1239 Set_Analyzed (Lo, False);
1240 end if;
1241
1242 if Denotes_Discriminant (Old_Hi) then
1243 Hi :=
1244 Make_Selected_Component (Loc,
1245 Prefix => New_Copy_Tree (P),
1246 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
1247
1248 else
1249 Hi := New_Copy_Tree (Old_Hi);
1250 Set_Analyzed (Hi, False);
1251 end if;
1252
1253 Append (Make_Range (Loc, Lo, Hi), Constraints);
1254 Next_Index (Indx);
1255 end loop;
1256
1257 return Constraints;
1258 end Build_Actual_Array_Constraint;
1259
1260 ------------------------------------
1261 -- Build_Actual_Record_Constraint --
1262 ------------------------------------
1263
1264 function Build_Actual_Record_Constraint return List_Id is
1265 Constraints : constant List_Id := New_List;
1266 D : Elmt_Id;
1267 D_Val : Node_Id;
1268
1269 begin
1270 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1271 while Present (D) loop
1272 if Denotes_Discriminant (Node (D)) then
1273 D_Val := Make_Selected_Component (Loc,
1274 Prefix => New_Copy_Tree (P),
1275 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
1276
1277 else
1278 D_Val := New_Copy_Tree (Node (D));
1279 end if;
1280
1281 Append (D_Val, Constraints);
1282 Next_Elmt (D);
1283 end loop;
1284
1285 return Constraints;
1286 end Build_Actual_Record_Constraint;
1287
1288 -- Start of processing for Build_Actual_Subtype_Of_Component
1289
1290 begin
1291 -- Why the test for Spec_Expression mode here???
1292
1293 if In_Spec_Expression then
1294 return Empty;
1295
1296 -- More comments for the rest of this body would be good ???
1297
1298 elsif Nkind (N) = N_Explicit_Dereference then
1299 if Is_Composite_Type (T)
1300 and then not Is_Constrained (T)
1301 and then not (Is_Class_Wide_Type (T)
1302 and then Is_Constrained (Root_Type (T)))
1303 and then not Has_Unknown_Discriminants (T)
1304 then
1305 -- If the type of the dereference is already constrained, it is an
1306 -- actual subtype.
1307
1308 if Is_Array_Type (Etype (N))
1309 and then Is_Constrained (Etype (N))
1310 then
1311 return Empty;
1312 else
1313 Remove_Side_Effects (P);
1314 return Build_Actual_Subtype (T, N);
1315 end if;
1316 else
1317 return Empty;
1318 end if;
1319 end if;
1320
1321 if Ekind (T) = E_Access_Subtype then
1322 Desig_Typ := Designated_Type (T);
1323 else
1324 Desig_Typ := T;
1325 end if;
1326
1327 if Ekind (Desig_Typ) = E_Array_Subtype then
1328 Id := First_Index (Desig_Typ);
1329 while Present (Id) loop
1330 Index_Typ := Underlying_Type (Etype (Id));
1331
1332 if Denotes_Discriminant (Type_Low_Bound (Index_Typ))
1333 or else
1334 Denotes_Discriminant (Type_High_Bound (Index_Typ))
1335 then
1336 Remove_Side_Effects (P);
1337 return
1338 Build_Component_Subtype
1339 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
1340 end if;
1341
1342 Next_Index (Id);
1343 end loop;
1344
1345 elsif Is_Composite_Type (Desig_Typ)
1346 and then Has_Discriminants (Desig_Typ)
1347 and then not Has_Unknown_Discriminants (Desig_Typ)
1348 then
1349 if Is_Private_Type (Desig_Typ)
1350 and then No (Discriminant_Constraint (Desig_Typ))
1351 then
1352 Desig_Typ := Full_View (Desig_Typ);
1353 end if;
1354
1355 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1356 while Present (D) loop
1357 if Denotes_Discriminant (Node (D)) then
1358 Remove_Side_Effects (P);
1359 return
1360 Build_Component_Subtype (
1361 Build_Actual_Record_Constraint, Loc, Base_Type (T));
1362 end if;
1363
1364 Next_Elmt (D);
1365 end loop;
1366 end if;
1367
1368 -- If none of the above, the actual and nominal subtypes are the same
1369
1370 return Empty;
1371 end Build_Actual_Subtype_Of_Component;
1372
1373 ---------------------------------
1374 -- Build_Class_Wide_Clone_Body --
1375 ---------------------------------
1376
1377 procedure Build_Class_Wide_Clone_Body
1378 (Spec_Id : Entity_Id;
1379 Bod : Node_Id)
1380 is
1381 Loc : constant Source_Ptr := Sloc (Bod);
1382 Clone_Id : constant Entity_Id := Class_Wide_Clone (Spec_Id);
1383 Clone_Body : Node_Id;
1384
1385 begin
1386 -- The declaration of the class-wide clone was created when the
1387 -- corresponding class-wide condition was analyzed.
1388
1389 Clone_Body :=
1390 Make_Subprogram_Body (Loc,
1391 Specification =>
1392 Copy_Subprogram_Spec (Parent (Clone_Id)),
1393 Declarations => Declarations (Bod),
1394 Handled_Statement_Sequence => Handled_Statement_Sequence (Bod));
1395
1396 -- The new operation is internal and overriding indicators do not apply
1397 -- (the original primitive may have carried one).
1398
1399 Set_Must_Override (Specification (Clone_Body), False);
1400
1401 -- If the subprogram body is the proper body of a stub, insert the
1402 -- subprogram after the stub, i.e. the same declarative region as
1403 -- the original sugprogram.
1404
1405 if Nkind (Parent (Bod)) = N_Subunit then
1406 Insert_After (Corresponding_Stub (Parent (Bod)), Clone_Body);
1407
1408 else
1409 Insert_Before (Bod, Clone_Body);
1410 end if;
1411
1412 Analyze (Clone_Body);
1413 end Build_Class_Wide_Clone_Body;
1414
1415 ---------------------------------
1416 -- Build_Class_Wide_Clone_Call --
1417 ---------------------------------
1418
1419 function Build_Class_Wide_Clone_Call
1420 (Loc : Source_Ptr;
1421 Decls : List_Id;
1422 Spec_Id : Entity_Id;
1423 Spec : Node_Id) return Node_Id
1424 is
1425 Clone_Id : constant Entity_Id := Class_Wide_Clone (Spec_Id);
1426 Par_Type : constant Entity_Id := Find_Dispatching_Type (Spec_Id);
1427
1428 Actuals : List_Id;
1429 Call : Node_Id;
1430 Formal : Entity_Id;
1431 New_Body : Node_Id;
1432 New_F_Spec : Entity_Id;
1433 New_Formal : Entity_Id;
1434
1435 begin
1436 Actuals := Empty_List;
1437 Formal := First_Formal (Spec_Id);
1438 New_F_Spec := First (Parameter_Specifications (Spec));
1439
1440 -- Build parameter association for call to class-wide clone.
1441
1442 while Present (Formal) loop
1443 New_Formal := Defining_Identifier (New_F_Spec);
1444
1445 -- If controlling argument and operation is inherited, add conversion
1446 -- to parent type for the call.
1447
1448 if Etype (Formal) = Par_Type
1449 and then not Is_Empty_List (Decls)
1450 then
1451 Append_To (Actuals,
1452 Make_Type_Conversion (Loc,
1453 New_Occurrence_Of (Par_Type, Loc),
1454 New_Occurrence_Of (New_Formal, Loc)));
1455
1456 else
1457 Append_To (Actuals, New_Occurrence_Of (New_Formal, Loc));
1458 end if;
1459
1460 Next_Formal (Formal);
1461 Next (New_F_Spec);
1462 end loop;
1463
1464 if Ekind (Spec_Id) = E_Procedure then
1465 Call :=
1466 Make_Procedure_Call_Statement (Loc,
1467 Name => New_Occurrence_Of (Clone_Id, Loc),
1468 Parameter_Associations => Actuals);
1469 else
1470 Call :=
1471 Make_Simple_Return_Statement (Loc,
1472 Expression =>
1473 Make_Function_Call (Loc,
1474 Name => New_Occurrence_Of (Clone_Id, Loc),
1475 Parameter_Associations => Actuals));
1476 end if;
1477
1478 New_Body :=
1479 Make_Subprogram_Body (Loc,
1480 Specification =>
1481 Copy_Subprogram_Spec (Spec),
1482 Declarations => Decls,
1483 Handled_Statement_Sequence =>
1484 Make_Handled_Sequence_Of_Statements (Loc,
1485 Statements => New_List (Call),
1486 End_Label => Make_Identifier (Loc, Chars (Spec_Id))));
1487
1488 return New_Body;
1489 end Build_Class_Wide_Clone_Call;
1490
1491 ---------------------------------
1492 -- Build_Class_Wide_Clone_Decl --
1493 ---------------------------------
1494
1495 procedure Build_Class_Wide_Clone_Decl (Spec_Id : Entity_Id) is
1496 Loc : constant Source_Ptr := Sloc (Spec_Id);
1497 Clone_Id : constant Entity_Id :=
1498 Make_Defining_Identifier (Loc,
1499 New_External_Name (Chars (Spec_Id), Suffix => "CL"));
1500
1501 Decl : Node_Id;
1502 Spec : Node_Id;
1503
1504 begin
1505 Spec := Copy_Subprogram_Spec (Parent (Spec_Id));
1506 Set_Must_Override (Spec, False);
1507 Set_Must_Not_Override (Spec, False);
1508 Set_Defining_Unit_Name (Spec, Clone_Id);
1509
1510 Decl := Make_Subprogram_Declaration (Loc, Spec);
1511 Append (Decl, List_Containing (Unit_Declaration_Node (Spec_Id)));
1512
1513 -- Link clone to original subprogram, for use when building body and
1514 -- wrapper call to inherited operation.
1515
1516 Set_Class_Wide_Clone (Spec_Id, Clone_Id);
1517 end Build_Class_Wide_Clone_Decl;
1518
1519 -----------------------------
1520 -- Build_Component_Subtype --
1521 -----------------------------
1522
1523 function Build_Component_Subtype
1524 (C : List_Id;
1525 Loc : Source_Ptr;
1526 T : Entity_Id) return Node_Id
1527 is
1528 Subt : Entity_Id;
1529 Decl : Node_Id;
1530
1531 begin
1532 -- Unchecked_Union components do not require component subtypes
1533
1534 if Is_Unchecked_Union (T) then
1535 return Empty;
1536 end if;
1537
1538 Subt := Make_Temporary (Loc, 'S');
1539 Set_Is_Internal (Subt);
1540
1541 Decl :=
1542 Make_Subtype_Declaration (Loc,
1543 Defining_Identifier => Subt,
1544 Subtype_Indication =>
1545 Make_Subtype_Indication (Loc,
1546 Subtype_Mark => New_Occurrence_Of (Base_Type (T), Loc),
1547 Constraint =>
1548 Make_Index_Or_Discriminant_Constraint (Loc,
1549 Constraints => C)));
1550
1551 Mark_Rewrite_Insertion (Decl);
1552 return Decl;
1553 end Build_Component_Subtype;
1554
1555 ---------------------------
1556 -- Build_Default_Subtype --
1557 ---------------------------
1558
1559 function Build_Default_Subtype
1560 (T : Entity_Id;
1561 N : Node_Id) return Entity_Id
1562 is
1563 Loc : constant Source_Ptr := Sloc (N);
1564 Disc : Entity_Id;
1565
1566 Bas : Entity_Id;
1567 -- The base type that is to be constrained by the defaults
1568
1569 begin
1570 if not Has_Discriminants (T) or else Is_Constrained (T) then
1571 return T;
1572 end if;
1573
1574 Bas := Base_Type (T);
1575
1576 -- If T is non-private but its base type is private, this is the
1577 -- completion of a subtype declaration whose parent type is private
1578 -- (see Complete_Private_Subtype in Sem_Ch3). The proper discriminants
1579 -- are to be found in the full view of the base. Check that the private
1580 -- status of T and its base differ.
1581
1582 if Is_Private_Type (Bas)
1583 and then not Is_Private_Type (T)
1584 and then Present (Full_View (Bas))
1585 then
1586 Bas := Full_View (Bas);
1587 end if;
1588
1589 Disc := First_Discriminant (T);
1590
1591 if No (Discriminant_Default_Value (Disc)) then
1592 return T;
1593 end if;
1594
1595 declare
1596 Act : constant Entity_Id := Make_Temporary (Loc, 'S');
1597 Constraints : constant List_Id := New_List;
1598 Decl : Node_Id;
1599
1600 begin
1601 while Present (Disc) loop
1602 Append_To (Constraints,
1603 New_Copy_Tree (Discriminant_Default_Value (Disc)));
1604 Next_Discriminant (Disc);
1605 end loop;
1606
1607 Decl :=
1608 Make_Subtype_Declaration (Loc,
1609 Defining_Identifier => Act,
1610 Subtype_Indication =>
1611 Make_Subtype_Indication (Loc,
1612 Subtype_Mark => New_Occurrence_Of (Bas, Loc),
1613 Constraint =>
1614 Make_Index_Or_Discriminant_Constraint (Loc,
1615 Constraints => Constraints)));
1616
1617 Insert_Action (N, Decl);
1618
1619 -- If the context is a component declaration the subtype declaration
1620 -- will be analyzed when the enclosing type is frozen, otherwise do
1621 -- it now.
1622
1623 if Ekind (Current_Scope) /= E_Record_Type then
1624 Analyze (Decl);
1625 end if;
1626
1627 return Act;
1628 end;
1629 end Build_Default_Subtype;
1630
1631 --------------------------------------------
1632 -- Build_Discriminal_Subtype_Of_Component --
1633 --------------------------------------------
1634
1635 function Build_Discriminal_Subtype_Of_Component
1636 (T : Entity_Id) return Node_Id
1637 is
1638 Loc : constant Source_Ptr := Sloc (T);
1639 D : Elmt_Id;
1640 Id : Node_Id;
1641
1642 function Build_Discriminal_Array_Constraint return List_Id;
1643 -- If one or more of the bounds of the component depends on
1644 -- discriminants, build actual constraint using the discriminants
1645 -- of the prefix.
1646
1647 function Build_Discriminal_Record_Constraint return List_Id;
1648 -- Similar to previous one, for discriminated components constrained by
1649 -- the discriminant of the enclosing object.
1650
1651 ----------------------------------------
1652 -- Build_Discriminal_Array_Constraint --
1653 ----------------------------------------
1654
1655 function Build_Discriminal_Array_Constraint return List_Id is
1656 Constraints : constant List_Id := New_List;
1657 Indx : Node_Id;
1658 Hi : Node_Id;
1659 Lo : Node_Id;
1660 Old_Hi : Node_Id;
1661 Old_Lo : Node_Id;
1662
1663 begin
1664 Indx := First_Index (T);
1665 while Present (Indx) loop
1666 Old_Lo := Type_Low_Bound (Etype (Indx));
1667 Old_Hi := Type_High_Bound (Etype (Indx));
1668
1669 if Denotes_Discriminant (Old_Lo) then
1670 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
1671
1672 else
1673 Lo := New_Copy_Tree (Old_Lo);
1674 end if;
1675
1676 if Denotes_Discriminant (Old_Hi) then
1677 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
1678
1679 else
1680 Hi := New_Copy_Tree (Old_Hi);
1681 end if;
1682
1683 Append (Make_Range (Loc, Lo, Hi), Constraints);
1684 Next_Index (Indx);
1685 end loop;
1686
1687 return Constraints;
1688 end Build_Discriminal_Array_Constraint;
1689
1690 -----------------------------------------
1691 -- Build_Discriminal_Record_Constraint --
1692 -----------------------------------------
1693
1694 function Build_Discriminal_Record_Constraint return List_Id is
1695 Constraints : constant List_Id := New_List;
1696 D : Elmt_Id;
1697 D_Val : Node_Id;
1698
1699 begin
1700 D := First_Elmt (Discriminant_Constraint (T));
1701 while Present (D) loop
1702 if Denotes_Discriminant (Node (D)) then
1703 D_Val :=
1704 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
1705 else
1706 D_Val := New_Copy_Tree (Node (D));
1707 end if;
1708
1709 Append (D_Val, Constraints);
1710 Next_Elmt (D);
1711 end loop;
1712
1713 return Constraints;
1714 end Build_Discriminal_Record_Constraint;
1715
1716 -- Start of processing for Build_Discriminal_Subtype_Of_Component
1717
1718 begin
1719 if Ekind (T) = E_Array_Subtype then
1720 Id := First_Index (T);
1721 while Present (Id) loop
1722 if Denotes_Discriminant (Type_Low_Bound (Etype (Id)))
1723 or else
1724 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
1725 then
1726 return Build_Component_Subtype
1727 (Build_Discriminal_Array_Constraint, Loc, T);
1728 end if;
1729
1730 Next_Index (Id);
1731 end loop;
1732
1733 elsif Ekind (T) = E_Record_Subtype
1734 and then Has_Discriminants (T)
1735 and then not Has_Unknown_Discriminants (T)
1736 then
1737 D := First_Elmt (Discriminant_Constraint (T));
1738 while Present (D) loop
1739 if Denotes_Discriminant (Node (D)) then
1740 return Build_Component_Subtype
1741 (Build_Discriminal_Record_Constraint, Loc, T);
1742 end if;
1743
1744 Next_Elmt (D);
1745 end loop;
1746 end if;
1747
1748 -- If none of the above, the actual and nominal subtypes are the same
1749
1750 return Empty;
1751 end Build_Discriminal_Subtype_Of_Component;
1752
1753 ------------------------------
1754 -- Build_Elaboration_Entity --
1755 ------------------------------
1756
1757 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
1758 Loc : constant Source_Ptr := Sloc (N);
1759 Decl : Node_Id;
1760 Elab_Ent : Entity_Id;
1761
1762 procedure Set_Package_Name (Ent : Entity_Id);
1763 -- Given an entity, sets the fully qualified name of the entity in
1764 -- Name_Buffer, with components separated by double underscores. This
1765 -- is a recursive routine that climbs the scope chain to Standard.
1766
1767 ----------------------
1768 -- Set_Package_Name --
1769 ----------------------
1770
1771 procedure Set_Package_Name (Ent : Entity_Id) is
1772 begin
1773 if Scope (Ent) /= Standard_Standard then
1774 Set_Package_Name (Scope (Ent));
1775
1776 declare
1777 Nam : constant String := Get_Name_String (Chars (Ent));
1778 begin
1779 Name_Buffer (Name_Len + 1) := '_';
1780 Name_Buffer (Name_Len + 2) := '_';
1781 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
1782 Name_Len := Name_Len + Nam'Length + 2;
1783 end;
1784
1785 else
1786 Get_Name_String (Chars (Ent));
1787 end if;
1788 end Set_Package_Name;
1789
1790 -- Start of processing for Build_Elaboration_Entity
1791
1792 begin
1793 -- Ignore call if already constructed
1794
1795 if Present (Elaboration_Entity (Spec_Id)) then
1796 return;
1797
1798 -- Ignore in ASIS mode, elaboration entity is not in source and plays
1799 -- no role in analysis.
1800
1801 elsif ASIS_Mode then
1802 return;
1803
1804 -- Do not generate an elaboration entity in GNATprove move because the
1805 -- elaboration counter is a form of expansion.
1806
1807 elsif GNATprove_Mode then
1808 return;
1809
1810 -- See if we need elaboration entity
1811
1812 -- We always need an elaboration entity when preserving control flow, as
1813 -- we want to remain explicit about the unit's elaboration order.
1814
1815 elsif Opt.Suppress_Control_Flow_Optimizations then
1816 null;
1817
1818 -- We always need an elaboration entity for the dynamic elaboration
1819 -- model, since it is needed to properly generate the PE exception for
1820 -- access before elaboration.
1821
1822 elsif Dynamic_Elaboration_Checks then
1823 null;
1824
1825 -- For the static model, we don't need the elaboration counter if this
1826 -- unit is sure to have no elaboration code, since that means there
1827 -- is no elaboration unit to be called. Note that we can't just decide
1828 -- after the fact by looking to see whether there was elaboration code,
1829 -- because that's too late to make this decision.
1830
1831 elsif Restriction_Active (No_Elaboration_Code) then
1832 return;
1833
1834 -- Similarly, for the static model, we can skip the elaboration counter
1835 -- if we have the No_Multiple_Elaboration restriction, since for the
1836 -- static model, that's the only purpose of the counter (to avoid
1837 -- multiple elaboration).
1838
1839 elsif Restriction_Active (No_Multiple_Elaboration) then
1840 return;
1841 end if;
1842
1843 -- Here we need the elaboration entity
1844
1845 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
1846 -- name with dots replaced by double underscore. We have to manually
1847 -- construct this name, since it will be elaborated in the outer scope,
1848 -- and thus will not have the unit name automatically prepended.
1849
1850 Set_Package_Name (Spec_Id);
1851 Add_Str_To_Name_Buffer ("_E");
1852
1853 -- Create elaboration counter
1854
1855 Elab_Ent := Make_Defining_Identifier (Loc, Chars => Name_Find);
1856 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
1857
1858 Decl :=
1859 Make_Object_Declaration (Loc,
1860 Defining_Identifier => Elab_Ent,
1861 Object_Definition =>
1862 New_Occurrence_Of (Standard_Short_Integer, Loc),
1863 Expression => Make_Integer_Literal (Loc, Uint_0));
1864
1865 Push_Scope (Standard_Standard);
1866 Add_Global_Declaration (Decl);
1867 Pop_Scope;
1868
1869 -- Reset True_Constant indication, since we will indeed assign a value
1870 -- to the variable in the binder main. We also kill the Current_Value
1871 -- and Last_Assignment fields for the same reason.
1872
1873 Set_Is_True_Constant (Elab_Ent, False);
1874 Set_Current_Value (Elab_Ent, Empty);
1875 Set_Last_Assignment (Elab_Ent, Empty);
1876
1877 -- We do not want any further qualification of the name (if we did not
1878 -- do this, we would pick up the name of the generic package in the case
1879 -- of a library level generic instantiation).
1880
1881 Set_Has_Qualified_Name (Elab_Ent);
1882 Set_Has_Fully_Qualified_Name (Elab_Ent);
1883 end Build_Elaboration_Entity;
1884
1885 --------------------------------
1886 -- Build_Explicit_Dereference --
1887 --------------------------------
1888
1889 procedure Build_Explicit_Dereference
1890 (Expr : Node_Id;
1891 Disc : Entity_Id)
1892 is
1893 Loc : constant Source_Ptr := Sloc (Expr);
1894 I : Interp_Index;
1895 It : Interp;
1896
1897 begin
1898 -- An entity of a type with a reference aspect is overloaded with
1899 -- both interpretations: with and without the dereference. Now that
1900 -- the dereference is made explicit, set the type of the node properly,
1901 -- to prevent anomalies in the backend. Same if the expression is an
1902 -- overloaded function call whose return type has a reference aspect.
1903
1904 if Is_Entity_Name (Expr) then
1905 Set_Etype (Expr, Etype (Entity (Expr)));
1906
1907 -- The designated entity will not be examined again when resolving
1908 -- the dereference, so generate a reference to it now.
1909
1910 Generate_Reference (Entity (Expr), Expr);
1911
1912 elsif Nkind (Expr) = N_Function_Call then
1913
1914 -- If the name of the indexing function is overloaded, locate the one
1915 -- whose return type has an implicit dereference on the desired
1916 -- discriminant, and set entity and type of function call.
1917
1918 if Is_Overloaded (Name (Expr)) then
1919 Get_First_Interp (Name (Expr), I, It);
1920
1921 while Present (It.Nam) loop
1922 if Ekind ((It.Typ)) = E_Record_Type
1923 and then First_Entity ((It.Typ)) = Disc
1924 then
1925 Set_Entity (Name (Expr), It.Nam);
1926 Set_Etype (Name (Expr), Etype (It.Nam));
1927 exit;
1928 end if;
1929
1930 Get_Next_Interp (I, It);
1931 end loop;
1932 end if;
1933
1934 -- Set type of call from resolved function name.
1935
1936 Set_Etype (Expr, Etype (Name (Expr)));
1937 end if;
1938
1939 Set_Is_Overloaded (Expr, False);
1940
1941 -- The expression will often be a generalized indexing that yields a
1942 -- container element that is then dereferenced, in which case the
1943 -- generalized indexing call is also non-overloaded.
1944
1945 if Nkind (Expr) = N_Indexed_Component
1946 and then Present (Generalized_Indexing (Expr))
1947 then
1948 Set_Is_Overloaded (Generalized_Indexing (Expr), False);
1949 end if;
1950
1951 Rewrite (Expr,
1952 Make_Explicit_Dereference (Loc,
1953 Prefix =>
1954 Make_Selected_Component (Loc,
1955 Prefix => Relocate_Node (Expr),
1956 Selector_Name => New_Occurrence_Of (Disc, Loc))));
1957 Set_Etype (Prefix (Expr), Etype (Disc));
1958 Set_Etype (Expr, Designated_Type (Etype (Disc)));
1959 end Build_Explicit_Dereference;
1960
1961 ---------------------------
1962 -- Build_Overriding_Spec --
1963 ---------------------------
1964
1965 function Build_Overriding_Spec
1966 (Op : Entity_Id;
1967 Typ : Entity_Id) return Node_Id
1968 is
1969 Loc : constant Source_Ptr := Sloc (Typ);
1970 Par_Typ : constant Entity_Id := Find_Dispatching_Type (Op);
1971 Spec : constant Node_Id := Specification (Unit_Declaration_Node (Op));
1972
1973 Formal_Spec : Node_Id;
1974 Formal_Type : Node_Id;
1975 New_Spec : Node_Id;
1976
1977 begin
1978 New_Spec := Copy_Subprogram_Spec (Spec);
1979
1980 Formal_Spec := First (Parameter_Specifications (New_Spec));
1981 while Present (Formal_Spec) loop
1982 Formal_Type := Parameter_Type (Formal_Spec);
1983
1984 if Is_Entity_Name (Formal_Type)
1985 and then Entity (Formal_Type) = Par_Typ
1986 then
1987 Rewrite (Formal_Type, New_Occurrence_Of (Typ, Loc));
1988 end if;
1989
1990 -- Nothing needs to be done for access parameters
1991
1992 Next (Formal_Spec);
1993 end loop;
1994
1995 return New_Spec;
1996 end Build_Overriding_Spec;
1997
1998 -----------------------------------
1999 -- Cannot_Raise_Constraint_Error --
2000 -----------------------------------
2001
2002 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
2003 begin
2004 if Compile_Time_Known_Value (Expr) then
2005 return True;
2006
2007 elsif Do_Range_Check (Expr) then
2008 return False;
2009
2010 elsif Raises_Constraint_Error (Expr) then
2011 return False;
2012
2013 else
2014 case Nkind (Expr) is
2015 when N_Identifier =>
2016 return True;
2017
2018 when N_Expanded_Name =>
2019 return True;
2020
2021 when N_Selected_Component =>
2022 return not Do_Discriminant_Check (Expr);
2023
2024 when N_Attribute_Reference =>
2025 if Do_Overflow_Check (Expr) then
2026 return False;
2027
2028 elsif No (Expressions (Expr)) then
2029 return True;
2030
2031 else
2032 declare
2033 N : Node_Id;
2034
2035 begin
2036 N := First (Expressions (Expr));
2037 while Present (N) loop
2038 if Cannot_Raise_Constraint_Error (N) then
2039 Next (N);
2040 else
2041 return False;
2042 end if;
2043 end loop;
2044
2045 return True;
2046 end;
2047 end if;
2048
2049 when N_Type_Conversion =>
2050 if Do_Overflow_Check (Expr)
2051 or else Do_Length_Check (Expr)
2052 or else Do_Tag_Check (Expr)
2053 then
2054 return False;
2055 else
2056 return Cannot_Raise_Constraint_Error (Expression (Expr));
2057 end if;
2058
2059 when N_Unchecked_Type_Conversion =>
2060 return Cannot_Raise_Constraint_Error (Expression (Expr));
2061
2062 when N_Unary_Op =>
2063 if Do_Overflow_Check (Expr) then
2064 return False;
2065 else
2066 return Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
2067 end if;
2068
2069 when N_Op_Divide
2070 | N_Op_Mod
2071 | N_Op_Rem
2072 =>
2073 if Do_Division_Check (Expr)
2074 or else
2075 Do_Overflow_Check (Expr)
2076 then
2077 return False;
2078 else
2079 return
2080 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
2081 and then
2082 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
2083 end if;
2084
2085 when N_Op_Add
2086 | N_Op_And
2087 | N_Op_Concat
2088 | N_Op_Eq
2089 | N_Op_Expon
2090 | N_Op_Ge
2091 | N_Op_Gt
2092 | N_Op_Le
2093 | N_Op_Lt
2094 | N_Op_Multiply
2095 | N_Op_Ne
2096 | N_Op_Or
2097 | N_Op_Rotate_Left
2098 | N_Op_Rotate_Right
2099 | N_Op_Shift_Left
2100 | N_Op_Shift_Right
2101 | N_Op_Shift_Right_Arithmetic
2102 | N_Op_Subtract
2103 | N_Op_Xor
2104 =>
2105 if Do_Overflow_Check (Expr) then
2106 return False;
2107 else
2108 return
2109 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
2110 and then
2111 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
2112 end if;
2113
2114 when others =>
2115 return False;
2116 end case;
2117 end if;
2118 end Cannot_Raise_Constraint_Error;
2119
2120 -----------------------------------------
2121 -- Check_Dynamically_Tagged_Expression --
2122 -----------------------------------------
2123
2124 procedure Check_Dynamically_Tagged_Expression
2125 (Expr : Node_Id;
2126 Typ : Entity_Id;
2127 Related_Nod : Node_Id)
2128 is
2129 begin
2130 pragma Assert (Is_Tagged_Type (Typ));
2131
2132 -- In order to avoid spurious errors when analyzing the expanded code,
2133 -- this check is done only for nodes that come from source and for
2134 -- actuals of generic instantiations.
2135
2136 if (Comes_From_Source (Related_Nod)
2137 or else In_Generic_Actual (Expr))
2138 and then (Is_Class_Wide_Type (Etype (Expr))
2139 or else Is_Dynamically_Tagged (Expr))
2140 and then not Is_Class_Wide_Type (Typ)
2141 then
2142 Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
2143 end if;
2144 end Check_Dynamically_Tagged_Expression;
2145
2146 --------------------------
2147 -- Check_Fully_Declared --
2148 --------------------------
2149
2150 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
2151 begin
2152 if Ekind (T) = E_Incomplete_Type then
2153
2154 -- Ada 2005 (AI-50217): If the type is available through a limited
2155 -- with_clause, verify that its full view has been analyzed.
2156
2157 if From_Limited_With (T)
2158 and then Present (Non_Limited_View (T))
2159 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
2160 then
2161 -- The non-limited view is fully declared
2162
2163 null;
2164
2165 else
2166 Error_Msg_NE
2167 ("premature usage of incomplete}", N, First_Subtype (T));
2168 end if;
2169
2170 -- Need comments for these tests ???
2171
2172 elsif Has_Private_Component (T)
2173 and then not Is_Generic_Type (Root_Type (T))
2174 and then not In_Spec_Expression
2175 then
2176 -- Special case: if T is the anonymous type created for a single
2177 -- task or protected object, use the name of the source object.
2178
2179 if Is_Concurrent_Type (T)
2180 and then not Comes_From_Source (T)
2181 and then Nkind (N) = N_Object_Declaration
2182 then
2183 Error_Msg_NE
2184 ("type of& has incomplete component",
2185 N, Defining_Identifier (N));
2186 else
2187 Error_Msg_NE
2188 ("premature usage of incomplete}",
2189 N, First_Subtype (T));
2190 end if;
2191 end if;
2192 end Check_Fully_Declared;
2193
2194 -------------------------------------------
2195 -- Check_Function_With_Address_Parameter --
2196 -------------------------------------------
2197
2198 procedure Check_Function_With_Address_Parameter (Subp_Id : Entity_Id) is
2199 F : Entity_Id;
2200 T : Entity_Id;
2201
2202 begin
2203 F := First_Formal (Subp_Id);
2204 while Present (F) loop
2205 T := Etype (F);
2206
2207 if Is_Private_Type (T) and then Present (Full_View (T)) then
2208 T := Full_View (T);
2209 end if;
2210
2211 if Is_Descendant_Of_Address (T) or else Is_Limited_Type (T) then
2212 Set_Is_Pure (Subp_Id, False);
2213 exit;
2214 end if;
2215
2216 Next_Formal (F);
2217 end loop;
2218 end Check_Function_With_Address_Parameter;
2219
2220 -------------------------------------
2221 -- Check_Function_Writable_Actuals --
2222 -------------------------------------
2223
2224 procedure Check_Function_Writable_Actuals (N : Node_Id) is
2225 Writable_Actuals_List : Elist_Id := No_Elist;
2226 Identifiers_List : Elist_Id := No_Elist;
2227 Aggr_Error_Node : Node_Id := Empty;
2228 Error_Node : Node_Id := Empty;
2229
2230 procedure Collect_Identifiers (N : Node_Id);
2231 -- In a single traversal of subtree N collect in Writable_Actuals_List
2232 -- all the actuals of functions with writable actuals, and in the list
2233 -- Identifiers_List collect all the identifiers that are not actuals of
2234 -- functions with writable actuals. If a writable actual is referenced
2235 -- twice as writable actual then Error_Node is set to reference its
2236 -- second occurrence, the error is reported, and the tree traversal
2237 -- is abandoned.
2238
2239 procedure Preanalyze_Without_Errors (N : Node_Id);
2240 -- Preanalyze N without reporting errors. Very dubious, you can't just
2241 -- go analyzing things more than once???
2242
2243 -------------------------
2244 -- Collect_Identifiers --
2245 -------------------------
2246
2247 procedure Collect_Identifiers (N : Node_Id) is
2248
2249 function Check_Node (N : Node_Id) return Traverse_Result;
2250 -- Process a single node during the tree traversal to collect the
2251 -- writable actuals of functions and all the identifiers which are
2252 -- not writable actuals of functions.
2253
2254 function Contains (List : Elist_Id; N : Node_Id) return Boolean;
2255 -- Returns True if List has a node whose Entity is Entity (N)
2256
2257 ----------------
2258 -- Check_Node --
2259 ----------------
2260
2261 function Check_Node (N : Node_Id) return Traverse_Result is
2262 Is_Writable_Actual : Boolean := False;
2263 Id : Entity_Id;
2264
2265 begin
2266 if Nkind (N) = N_Identifier then
2267
2268 -- No analysis possible if the entity is not decorated
2269
2270 if No (Entity (N)) then
2271 return Skip;
2272
2273 -- Don't collect identifiers of packages, called functions, etc
2274
2275 elsif Ekind_In (Entity (N), E_Package,
2276 E_Function,
2277 E_Procedure,
2278 E_Entry)
2279 then
2280 return Skip;
2281
2282 -- For rewritten nodes, continue the traversal in the original
2283 -- subtree. Needed to handle aggregates in original expressions
2284 -- extracted from the tree by Remove_Side_Effects.
2285
2286 elsif Is_Rewrite_Substitution (N) then
2287 Collect_Identifiers (Original_Node (N));
2288 return Skip;
2289
2290 -- For now we skip aggregate discriminants, since they require
2291 -- performing the analysis in two phases to identify conflicts:
2292 -- first one analyzing discriminants and second one analyzing
2293 -- the rest of components (since at run time, discriminants are
2294 -- evaluated prior to components): too much computation cost
2295 -- to identify a corner case???
2296
2297 elsif Nkind (Parent (N)) = N_Component_Association
2298 and then Nkind_In (Parent (Parent (N)),
2299 N_Aggregate,
2300 N_Extension_Aggregate)
2301 then
2302 declare
2303 Choice : constant Node_Id := First (Choices (Parent (N)));
2304
2305 begin
2306 if Ekind (Entity (N)) = E_Discriminant then
2307 return Skip;
2308
2309 elsif Expression (Parent (N)) = N
2310 and then Nkind (Choice) = N_Identifier
2311 and then Ekind (Entity (Choice)) = E_Discriminant
2312 then
2313 return Skip;
2314 end if;
2315 end;
2316
2317 -- Analyze if N is a writable actual of a function
2318
2319 elsif Nkind (Parent (N)) = N_Function_Call then
2320 declare
2321 Call : constant Node_Id := Parent (N);
2322 Actual : Node_Id;
2323 Formal : Node_Id;
2324
2325 begin
2326 Id := Get_Called_Entity (Call);
2327
2328 -- In case of previous error, no check is possible
2329
2330 if No (Id) then
2331 return Abandon;
2332 end if;
2333
2334 if Ekind_In (Id, E_Function, E_Generic_Function)
2335 and then Has_Out_Or_In_Out_Parameter (Id)
2336 then
2337 Formal := First_Formal (Id);
2338 Actual := First_Actual (Call);
2339 while Present (Actual) and then Present (Formal) loop
2340 if Actual = N then
2341 if Ekind_In (Formal, E_Out_Parameter,
2342 E_In_Out_Parameter)
2343 then
2344 Is_Writable_Actual := True;
2345 end if;
2346
2347 exit;
2348 end if;
2349
2350 Next_Formal (Formal);
2351 Next_Actual (Actual);
2352 end loop;
2353 end if;
2354 end;
2355 end if;
2356
2357 if Is_Writable_Actual then
2358
2359 -- Skip checking the error in non-elementary types since
2360 -- RM 6.4.1(6.15/3) is restricted to elementary types, but
2361 -- store this actual in Writable_Actuals_List since it is
2362 -- needed to perform checks on other constructs that have
2363 -- arbitrary order of evaluation (for example, aggregates).
2364
2365 if not Is_Elementary_Type (Etype (N)) then
2366 if not Contains (Writable_Actuals_List, N) then
2367 Append_New_Elmt (N, To => Writable_Actuals_List);
2368 end if;
2369
2370 -- Second occurrence of an elementary type writable actual
2371
2372 elsif Contains (Writable_Actuals_List, N) then
2373
2374 -- Report the error on the second occurrence of the
2375 -- identifier. We cannot assume that N is the second
2376 -- occurrence (according to their location in the
2377 -- sources), since Traverse_Func walks through Field2
2378 -- last (see comment in the body of Traverse_Func).
2379
2380 declare
2381 Elmt : Elmt_Id;
2382
2383 begin
2384 Elmt := First_Elmt (Writable_Actuals_List);
2385 while Present (Elmt)
2386 and then Entity (Node (Elmt)) /= Entity (N)
2387 loop
2388 Next_Elmt (Elmt);
2389 end loop;
2390
2391 if Sloc (N) > Sloc (Node (Elmt)) then
2392 Error_Node := N;
2393 else
2394 Error_Node := Node (Elmt);
2395 end if;
2396
2397 Error_Msg_NE
2398 ("value may be affected by call to & "
2399 & "because order of evaluation is arbitrary",
2400 Error_Node, Id);
2401 return Abandon;
2402 end;
2403
2404 -- First occurrence of a elementary type writable actual
2405
2406 else
2407 Append_New_Elmt (N, To => Writable_Actuals_List);
2408 end if;
2409
2410 else
2411 if Identifiers_List = No_Elist then
2412 Identifiers_List := New_Elmt_List;
2413 end if;
2414
2415 Append_Unique_Elmt (N, Identifiers_List);
2416 end if;
2417 end if;
2418
2419 return OK;
2420 end Check_Node;
2421
2422 --------------
2423 -- Contains --
2424 --------------
2425
2426 function Contains
2427 (List : Elist_Id;
2428 N : Node_Id) return Boolean
2429 is
2430 pragma Assert (Nkind (N) in N_Has_Entity);
2431
2432 Elmt : Elmt_Id;
2433
2434 begin
2435 if List = No_Elist then
2436 return False;
2437 end if;
2438
2439 Elmt := First_Elmt (List);
2440 while Present (Elmt) loop
2441 if Entity (Node (Elmt)) = Entity (N) then
2442 return True;
2443 else
2444 Next_Elmt (Elmt);
2445 end if;
2446 end loop;
2447
2448 return False;
2449 end Contains;
2450
2451 ------------------
2452 -- Do_Traversal --
2453 ------------------
2454
2455 procedure Do_Traversal is new Traverse_Proc (Check_Node);
2456 -- The traversal procedure
2457
2458 -- Start of processing for Collect_Identifiers
2459
2460 begin
2461 if Present (Error_Node) then
2462 return;
2463 end if;
2464
2465 if Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then
2466 return;
2467 end if;
2468
2469 Do_Traversal (N);
2470 end Collect_Identifiers;
2471
2472 -------------------------------
2473 -- Preanalyze_Without_Errors --
2474 -------------------------------
2475
2476 procedure Preanalyze_Without_Errors (N : Node_Id) is
2477 Status : constant Boolean := Get_Ignore_Errors;
2478 begin
2479 Set_Ignore_Errors (True);
2480 Preanalyze (N);
2481 Set_Ignore_Errors (Status);
2482 end Preanalyze_Without_Errors;
2483
2484 -- Start of processing for Check_Function_Writable_Actuals
2485
2486 begin
2487 -- The check only applies to Ada 2012 code on which Check_Actuals has
2488 -- been set, and only to constructs that have multiple constituents
2489 -- whose order of evaluation is not specified by the language.
2490
2491 if Ada_Version < Ada_2012
2492 or else not Check_Actuals (N)
2493 or else (not (Nkind (N) in N_Op)
2494 and then not (Nkind (N) in N_Membership_Test)
2495 and then not Nkind_In (N, N_Range,
2496 N_Aggregate,
2497 N_Extension_Aggregate,
2498 N_Full_Type_Declaration,
2499 N_Function_Call,
2500 N_Procedure_Call_Statement,
2501 N_Entry_Call_Statement))
2502 or else (Nkind (N) = N_Full_Type_Declaration
2503 and then not Is_Record_Type (Defining_Identifier (N)))
2504
2505 -- In addition, this check only applies to source code, not to code
2506 -- generated by constraint checks.
2507
2508 or else not Comes_From_Source (N)
2509 then
2510 return;
2511 end if;
2512
2513 -- If a construct C has two or more direct constituents that are names
2514 -- or expressions whose evaluation may occur in an arbitrary order, at
2515 -- least one of which contains a function call with an in out or out
2516 -- parameter, then the construct is legal only if: for each name N that
2517 -- is passed as a parameter of mode in out or out to some inner function
2518 -- call C2 (not including the construct C itself), there is no other
2519 -- name anywhere within a direct constituent of the construct C other
2520 -- than the one containing C2, that is known to refer to the same
2521 -- object (RM 6.4.1(6.17/3)).
2522
2523 case Nkind (N) is
2524 when N_Range =>
2525 Collect_Identifiers (Low_Bound (N));
2526 Collect_Identifiers (High_Bound (N));
2527
2528 when N_Membership_Test
2529 | N_Op
2530 =>
2531 declare
2532 Expr : Node_Id;
2533
2534 begin
2535 Collect_Identifiers (Left_Opnd (N));
2536
2537 if Present (Right_Opnd (N)) then
2538 Collect_Identifiers (Right_Opnd (N));
2539 end if;
2540
2541 if Nkind_In (N, N_In, N_Not_In)
2542 and then Present (Alternatives (N))
2543 then
2544 Expr := First (Alternatives (N));
2545 while Present (Expr) loop
2546 Collect_Identifiers (Expr);
2547
2548 Next (Expr);
2549 end loop;
2550 end if;
2551 end;
2552
2553 when N_Full_Type_Declaration =>
2554 declare
2555 function Get_Record_Part (N : Node_Id) return Node_Id;
2556 -- Return the record part of this record type definition
2557
2558 function Get_Record_Part (N : Node_Id) return Node_Id is
2559 Type_Def : constant Node_Id := Type_Definition (N);
2560 begin
2561 if Nkind (Type_Def) = N_Derived_Type_Definition then
2562 return Record_Extension_Part (Type_Def);
2563 else
2564 return Type_Def;
2565 end if;
2566 end Get_Record_Part;
2567
2568 Comp : Node_Id;
2569 Def_Id : Entity_Id := Defining_Identifier (N);
2570 Rec : Node_Id := Get_Record_Part (N);
2571
2572 begin
2573 -- No need to perform any analysis if the record has no
2574 -- components
2575
2576 if No (Rec) or else No (Component_List (Rec)) then
2577 return;
2578 end if;
2579
2580 -- Collect the identifiers starting from the deepest
2581 -- derivation. Done to report the error in the deepest
2582 -- derivation.
2583
2584 loop
2585 if Present (Component_List (Rec)) then
2586 Comp := First (Component_Items (Component_List (Rec)));
2587 while Present (Comp) loop
2588 if Nkind (Comp) = N_Component_Declaration
2589 and then Present (Expression (Comp))
2590 then
2591 Collect_Identifiers (Expression (Comp));
2592 end if;
2593
2594 Next (Comp);
2595 end loop;
2596 end if;
2597
2598 exit when No (Underlying_Type (Etype (Def_Id)))
2599 or else Base_Type (Underlying_Type (Etype (Def_Id)))
2600 = Def_Id;
2601
2602 Def_Id := Base_Type (Underlying_Type (Etype (Def_Id)));
2603 Rec := Get_Record_Part (Parent (Def_Id));
2604 end loop;
2605 end;
2606
2607 when N_Entry_Call_Statement
2608 | N_Subprogram_Call
2609 =>
2610 declare
2611 Id : constant Entity_Id := Get_Called_Entity (N);
2612 Formal : Node_Id;
2613 Actual : Node_Id;
2614
2615 begin
2616 Formal := First_Formal (Id);
2617 Actual := First_Actual (N);
2618 while Present (Actual) and then Present (Formal) loop
2619 if Ekind_In (Formal, E_Out_Parameter,
2620 E_In_Out_Parameter)
2621 then
2622 Collect_Identifiers (Actual);
2623 end if;
2624
2625 Next_Formal (Formal);
2626 Next_Actual (Actual);
2627 end loop;
2628 end;
2629
2630 when N_Aggregate
2631 | N_Extension_Aggregate
2632 =>
2633 declare
2634 Assoc : Node_Id;
2635 Choice : Node_Id;
2636 Comp_Expr : Node_Id;
2637
2638 begin
2639 -- Handle the N_Others_Choice of array aggregates with static
2640 -- bounds. There is no need to perform this analysis in
2641 -- aggregates without static bounds since we cannot evaluate
2642 -- if the N_Others_Choice covers several elements. There is
2643 -- no need to handle the N_Others choice of record aggregates
2644 -- since at this stage it has been already expanded by
2645 -- Resolve_Record_Aggregate.
2646
2647 if Is_Array_Type (Etype (N))
2648 and then Nkind (N) = N_Aggregate
2649 and then Present (Aggregate_Bounds (N))
2650 and then Compile_Time_Known_Bounds (Etype (N))
2651 and then Expr_Value (High_Bound (Aggregate_Bounds (N)))
2652 >
2653 Expr_Value (Low_Bound (Aggregate_Bounds (N)))
2654 then
2655 declare
2656 Count_Components : Uint := Uint_0;
2657 Num_Components : Uint;
2658 Others_Assoc : Node_Id;
2659 Others_Choice : Node_Id := Empty;
2660 Others_Box_Present : Boolean := False;
2661
2662 begin
2663 -- Count positional associations
2664
2665 if Present (Expressions (N)) then
2666 Comp_Expr := First (Expressions (N));
2667 while Present (Comp_Expr) loop
2668 Count_Components := Count_Components + 1;
2669 Next (Comp_Expr);
2670 end loop;
2671 end if;
2672
2673 -- Count the rest of elements and locate the N_Others
2674 -- choice (if any)
2675
2676 Assoc := First (Component_Associations (N));
2677 while Present (Assoc) loop
2678 Choice := First (Choices (Assoc));
2679 while Present (Choice) loop
2680 if Nkind (Choice) = N_Others_Choice then
2681 Others_Assoc := Assoc;
2682 Others_Choice := Choice;
2683 Others_Box_Present := Box_Present (Assoc);
2684
2685 -- Count several components
2686
2687 elsif Nkind_In (Choice, N_Range,
2688 N_Subtype_Indication)
2689 or else (Is_Entity_Name (Choice)
2690 and then Is_Type (Entity (Choice)))
2691 then
2692 declare
2693 L, H : Node_Id;
2694 begin
2695 Get_Index_Bounds (Choice, L, H);
2696 pragma Assert
2697 (Compile_Time_Known_Value (L)
2698 and then Compile_Time_Known_Value (H));
2699 Count_Components :=
2700 Count_Components
2701 + Expr_Value (H) - Expr_Value (L) + 1;
2702 end;
2703
2704 -- Count single component. No other case available
2705 -- since we are handling an aggregate with static
2706 -- bounds.
2707
2708 else
2709 pragma Assert (Is_OK_Static_Expression (Choice)
2710 or else Nkind (Choice) = N_Identifier
2711 or else Nkind (Choice) = N_Integer_Literal);
2712
2713 Count_Components := Count_Components + 1;
2714 end if;
2715
2716 Next (Choice);
2717 end loop;
2718
2719 Next (Assoc);
2720 end loop;
2721
2722 Num_Components :=
2723 Expr_Value (High_Bound (Aggregate_Bounds (N))) -
2724 Expr_Value (Low_Bound (Aggregate_Bounds (N))) + 1;
2725
2726 pragma Assert (Count_Components <= Num_Components);
2727
2728 -- Handle the N_Others choice if it covers several
2729 -- components
2730
2731 if Present (Others_Choice)
2732 and then (Num_Components - Count_Components) > 1
2733 then
2734 if not Others_Box_Present then
2735
2736 -- At this stage, if expansion is active, the
2737 -- expression of the others choice has not been
2738 -- analyzed. Hence we generate a duplicate and
2739 -- we analyze it silently to have available the
2740 -- minimum decoration required to collect the
2741 -- identifiers.
2742
2743 if not Expander_Active then
2744 Comp_Expr := Expression (Others_Assoc);
2745 else
2746 Comp_Expr :=
2747 New_Copy_Tree (Expression (Others_Assoc));
2748 Preanalyze_Without_Errors (Comp_Expr);
2749 end if;
2750
2751 Collect_Identifiers (Comp_Expr);
2752
2753 if Writable_Actuals_List /= No_Elist then
2754
2755 -- As suggested by Robert, at current stage we
2756 -- report occurrences of this case as warnings.
2757
2758 Error_Msg_N
2759 ("writable function parameter may affect "
2760 & "value in other component because order "
2761 & "of evaluation is unspecified??",
2762 Node (First_Elmt (Writable_Actuals_List)));
2763 end if;
2764 end if;
2765 end if;
2766 end;
2767
2768 -- For an array aggregate, a discrete_choice_list that has
2769 -- a nonstatic range is considered as two or more separate
2770 -- occurrences of the expression (RM 6.4.1(20/3)).
2771
2772 elsif Is_Array_Type (Etype (N))
2773 and then Nkind (N) = N_Aggregate
2774 and then Present (Aggregate_Bounds (N))
2775 and then not Compile_Time_Known_Bounds (Etype (N))
2776 then
2777 -- Collect identifiers found in the dynamic bounds
2778
2779 declare
2780 Count_Components : Natural := 0;
2781 Low, High : Node_Id;
2782
2783 begin
2784 Assoc := First (Component_Associations (N));
2785 while Present (Assoc) loop
2786 Choice := First (Choices (Assoc));
2787 while Present (Choice) loop
2788 if Nkind_In (Choice, N_Range,
2789 N_Subtype_Indication)
2790 or else (Is_Entity_Name (Choice)
2791 and then Is_Type (Entity (Choice)))
2792 then
2793 Get_Index_Bounds (Choice, Low, High);
2794
2795 if not Compile_Time_Known_Value (Low) then
2796 Collect_Identifiers (Low);
2797
2798 if No (Aggr_Error_Node) then
2799 Aggr_Error_Node := Low;
2800 end if;
2801 end if;
2802
2803 if not Compile_Time_Known_Value (High) then
2804 Collect_Identifiers (High);
2805
2806 if No (Aggr_Error_Node) then
2807 Aggr_Error_Node := High;
2808 end if;
2809 end if;
2810
2811 -- The RM rule is violated if there is more than
2812 -- a single choice in a component association.
2813
2814 else
2815 Count_Components := Count_Components + 1;
2816
2817 if No (Aggr_Error_Node)
2818 and then Count_Components > 1
2819 then
2820 Aggr_Error_Node := Choice;
2821 end if;
2822
2823 if not Compile_Time_Known_Value (Choice) then
2824 Collect_Identifiers (Choice);
2825 end if;
2826 end if;
2827
2828 Next (Choice);
2829 end loop;
2830
2831 Next (Assoc);
2832 end loop;
2833 end;
2834 end if;
2835
2836 -- Handle ancestor part of extension aggregates
2837
2838 if Nkind (N) = N_Extension_Aggregate then
2839 Collect_Identifiers (Ancestor_Part (N));
2840 end if;
2841
2842 -- Handle positional associations
2843
2844 if Present (Expressions (N)) then
2845 Comp_Expr := First (Expressions (N));
2846 while Present (Comp_Expr) loop
2847 if not Is_OK_Static_Expression (Comp_Expr) then
2848 Collect_Identifiers (Comp_Expr);
2849 end if;
2850
2851 Next (Comp_Expr);
2852 end loop;
2853 end if;
2854
2855 -- Handle discrete associations
2856
2857 if Present (Component_Associations (N)) then
2858 Assoc := First (Component_Associations (N));
2859 while Present (Assoc) loop
2860
2861 if not Box_Present (Assoc) then
2862 Choice := First (Choices (Assoc));
2863 while Present (Choice) loop
2864
2865 -- For now we skip discriminants since it requires
2866 -- performing the analysis in two phases: first one
2867 -- analyzing discriminants and second one analyzing
2868 -- the rest of components since discriminants are
2869 -- evaluated prior to components: too much extra
2870 -- work to detect a corner case???
2871
2872 if Nkind (Choice) in N_Has_Entity
2873 and then Present (Entity (Choice))
2874 and then Ekind (Entity (Choice)) = E_Discriminant
2875 then
2876 null;
2877
2878 elsif Box_Present (Assoc) then
2879 null;
2880
2881 else
2882 if not Analyzed (Expression (Assoc)) then
2883 Comp_Expr :=
2884 New_Copy_Tree (Expression (Assoc));
2885 Set_Parent (Comp_Expr, Parent (N));
2886 Preanalyze_Without_Errors (Comp_Expr);
2887 else
2888 Comp_Expr := Expression (Assoc);
2889 end if;
2890
2891 Collect_Identifiers (Comp_Expr);
2892 end if;
2893
2894 Next (Choice);
2895 end loop;
2896 end if;
2897
2898 Next (Assoc);
2899 end loop;
2900 end if;
2901 end;
2902
2903 when others =>
2904 return;
2905 end case;
2906
2907 -- No further action needed if we already reported an error
2908
2909 if Present (Error_Node) then
2910 return;
2911 end if;
2912
2913 -- Check violation of RM 6.20/3 in aggregates
2914
2915 if Present (Aggr_Error_Node)
2916 and then Writable_Actuals_List /= No_Elist
2917 then
2918 Error_Msg_N
2919 ("value may be affected by call in other component because they "
2920 & "are evaluated in unspecified order",
2921 Node (First_Elmt (Writable_Actuals_List)));
2922 return;
2923 end if;
2924
2925 -- Check if some writable argument of a function is referenced
2926
2927 if Writable_Actuals_List /= No_Elist
2928 and then Identifiers_List /= No_Elist
2929 then
2930 declare
2931 Elmt_1 : Elmt_Id;
2932 Elmt_2 : Elmt_Id;
2933
2934 begin
2935 Elmt_1 := First_Elmt (Writable_Actuals_List);
2936 while Present (Elmt_1) loop
2937 Elmt_2 := First_Elmt (Identifiers_List);
2938 while Present (Elmt_2) loop
2939 if Entity (Node (Elmt_1)) = Entity (Node (Elmt_2)) then
2940 case Nkind (Parent (Node (Elmt_2))) is
2941 when N_Aggregate
2942 | N_Component_Association
2943 | N_Component_Declaration
2944 =>
2945 Error_Msg_N
2946 ("value may be affected by call in other "
2947 & "component because they are evaluated "
2948 & "in unspecified order",
2949 Node (Elmt_2));
2950
2951 when N_In
2952 | N_Not_In
2953 =>
2954 Error_Msg_N
2955 ("value may be affected by call in other "
2956 & "alternative because they are evaluated "
2957 & "in unspecified order",
2958 Node (Elmt_2));
2959
2960 when others =>
2961 Error_Msg_N
2962 ("value of actual may be affected by call in "
2963 & "other actual because they are evaluated "
2964 & "in unspecified order",
2965 Node (Elmt_2));
2966 end case;
2967 end if;
2968
2969 Next_Elmt (Elmt_2);
2970 end loop;
2971
2972 Next_Elmt (Elmt_1);
2973 end loop;
2974 end;
2975 end if;
2976 end Check_Function_Writable_Actuals;
2977
2978 --------------------------------
2979 -- Check_Implicit_Dereference --
2980 --------------------------------
2981
2982 procedure Check_Implicit_Dereference (N : Node_Id; Typ : Entity_Id) is
2983 Disc : Entity_Id;
2984 Desig : Entity_Id;
2985 Nam : Node_Id;
2986
2987 begin
2988 if Nkind (N) = N_Indexed_Component
2989 and then Present (Generalized_Indexing (N))
2990 then
2991 Nam := Generalized_Indexing (N);
2992 else
2993 Nam := N;
2994 end if;
2995
2996 if Ada_Version < Ada_2012
2997 or else not Has_Implicit_Dereference (Base_Type (Typ))
2998 then
2999 return;
3000
3001 elsif not Comes_From_Source (N)
3002 and then Nkind (N) /= N_Indexed_Component
3003 then
3004 return;
3005
3006 elsif Is_Entity_Name (Nam) and then Is_Type (Entity (Nam)) then
3007 null;
3008
3009 else
3010 Disc := First_Discriminant (Typ);
3011 while Present (Disc) loop
3012 if Has_Implicit_Dereference (Disc) then
3013 Desig := Designated_Type (Etype (Disc));
3014 Add_One_Interp (Nam, Disc, Desig);
3015
3016 -- If the node is a generalized indexing, add interpretation
3017 -- to that node as well, for subsequent resolution.
3018
3019 if Nkind (N) = N_Indexed_Component then
3020 Add_One_Interp (N, Disc, Desig);
3021 end if;
3022
3023 -- If the operation comes from a generic unit and the context
3024 -- is a selected component, the selector name may be global
3025 -- and set in the instance already. Remove the entity to
3026 -- force resolution of the selected component, and the
3027 -- generation of an explicit dereference if needed.
3028
3029 if In_Instance
3030 and then Nkind (Parent (Nam)) = N_Selected_Component
3031 then
3032 Set_Entity (Selector_Name (Parent (Nam)), Empty);
3033 end if;
3034
3035 exit;
3036 end if;
3037
3038 Next_Discriminant (Disc);
3039 end loop;
3040 end if;
3041 end Check_Implicit_Dereference;
3042
3043 ----------------------------------
3044 -- Check_Internal_Protected_Use --
3045 ----------------------------------
3046
3047 procedure Check_Internal_Protected_Use (N : Node_Id; Nam : Entity_Id) is
3048 S : Entity_Id;
3049 Prot : Entity_Id;
3050
3051 begin
3052 Prot := Empty;
3053
3054 S := Current_Scope;
3055 while Present (S) loop
3056 if S = Standard_Standard then
3057 exit;
3058
3059 elsif Ekind (S) = E_Function
3060 and then Ekind (Scope (S)) = E_Protected_Type
3061 then
3062 Prot := Scope (S);
3063 exit;
3064 end if;
3065
3066 S := Scope (S);
3067 end loop;
3068
3069 if Present (Prot)
3070 and then Scope (Nam) = Prot
3071 and then Ekind (Nam) /= E_Function
3072 then
3073 -- An indirect function call (e.g. a callback within a protected
3074 -- function body) is not statically illegal. If the access type is
3075 -- anonymous and is the type of an access parameter, the scope of Nam
3076 -- will be the protected type, but it is not a protected operation.
3077
3078 if Ekind (Nam) = E_Subprogram_Type
3079 and then Nkind (Associated_Node_For_Itype (Nam)) =
3080 N_Function_Specification
3081 then
3082 null;
3083
3084 elsif Nkind (N) = N_Subprogram_Renaming_Declaration then
3085 Error_Msg_N
3086 ("within protected function cannot use protected procedure in "
3087 & "renaming or as generic actual", N);
3088
3089 elsif Nkind (N) = N_Attribute_Reference then
3090 Error_Msg_N
3091 ("within protected function cannot take access of protected "
3092 & "procedure", N);
3093
3094 else
3095 Error_Msg_N
3096 ("within protected function, protected object is constant", N);
3097 Error_Msg_N
3098 ("\cannot call operation that may modify it", N);
3099 end if;
3100 end if;
3101
3102 -- Verify that an internal call does not appear within a precondition
3103 -- of a protected operation. This implements AI12-0166.
3104 -- The precondition aspect has been rewritten as a pragma Precondition
3105 -- and we check whether the scope of the called subprogram is the same
3106 -- as that of the entity to which the aspect applies.
3107
3108 if Convention (Nam) = Convention_Protected then
3109 declare
3110 P : Node_Id;
3111
3112 begin
3113 P := Parent (N);
3114 while Present (P) loop
3115 if Nkind (P) = N_Pragma
3116 and then Chars (Pragma_Identifier (P)) = Name_Precondition
3117 and then From_Aspect_Specification (P)
3118 and then
3119 Scope (Entity (Corresponding_Aspect (P))) = Scope (Nam)
3120 then
3121 Error_Msg_N
3122 ("internal call cannot appear in precondition of "
3123 & "protected operation", N);
3124 return;
3125
3126 elsif Nkind (P) = N_Pragma
3127 and then Chars (Pragma_Identifier (P)) = Name_Contract_Cases
3128 then
3129 -- Check whether call is in a case guard. It is legal in a
3130 -- consequence.
3131
3132 P := N;
3133 while Present (P) loop
3134 if Nkind (Parent (P)) = N_Component_Association
3135 and then P /= Expression (Parent (P))
3136 then
3137 Error_Msg_N
3138 ("internal call cannot appear in case guard in a "
3139 & "contract case", N);
3140 end if;
3141
3142 P := Parent (P);
3143 end loop;
3144
3145 return;
3146
3147 elsif Nkind (P) = N_Parameter_Specification
3148 and then Scope (Current_Scope) = Scope (Nam)
3149 and then Nkind_In (Parent (P), N_Entry_Declaration,
3150 N_Subprogram_Declaration)
3151 then
3152 Error_Msg_N
3153 ("internal call cannot appear in default for formal of "
3154 & "protected operation", N);
3155 return;
3156 end if;
3157
3158 P := Parent (P);
3159 end loop;
3160 end;
3161 end if;
3162 end Check_Internal_Protected_Use;
3163
3164 ---------------------------------------
3165 -- Check_Later_Vs_Basic_Declarations --
3166 ---------------------------------------
3167
3168 procedure Check_Later_Vs_Basic_Declarations
3169 (Decls : List_Id;
3170 During_Parsing : Boolean)
3171 is
3172 Body_Sloc : Source_Ptr;
3173 Decl : Node_Id;
3174
3175 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean;
3176 -- Return whether Decl is considered as a declarative item.
3177 -- When During_Parsing is True, the semantics of Ada 83 is followed.
3178 -- When During_Parsing is False, the semantics of SPARK is followed.
3179
3180 -------------------------------
3181 -- Is_Later_Declarative_Item --
3182 -------------------------------
3183
3184 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean is
3185 begin
3186 if Nkind (Decl) in N_Later_Decl_Item then
3187 return True;
3188
3189 elsif Nkind (Decl) = N_Pragma then
3190 return True;
3191
3192 elsif During_Parsing then
3193 return False;
3194
3195 -- In SPARK, a package declaration is not considered as a later
3196 -- declarative item.
3197
3198 elsif Nkind (Decl) = N_Package_Declaration then
3199 return False;
3200
3201 -- In SPARK, a renaming is considered as a later declarative item
3202
3203 elsif Nkind (Decl) in N_Renaming_Declaration then
3204 return True;
3205
3206 else
3207 return False;
3208 end if;
3209 end Is_Later_Declarative_Item;
3210
3211 -- Start of processing for Check_Later_Vs_Basic_Declarations
3212
3213 begin
3214 Decl := First (Decls);
3215
3216 -- Loop through sequence of basic declarative items
3217
3218 Outer : while Present (Decl) loop
3219 if not Nkind_In (Decl, N_Subprogram_Body, N_Package_Body, N_Task_Body)
3220 and then Nkind (Decl) not in N_Body_Stub
3221 then
3222 Next (Decl);
3223
3224 -- Once a body is encountered, we only allow later declarative
3225 -- items. The inner loop checks the rest of the list.
3226
3227 else
3228 Body_Sloc := Sloc (Decl);
3229
3230 Inner : while Present (Decl) loop
3231 if not Is_Later_Declarative_Item (Decl) then
3232 if During_Parsing then
3233 if Ada_Version = Ada_83 then
3234 Error_Msg_Sloc := Body_Sloc;
3235 Error_Msg_N
3236 ("(Ada 83) decl cannot appear after body#", Decl);
3237 end if;
3238 else
3239 Error_Msg_Sloc := Body_Sloc;
3240 Check_SPARK_05_Restriction
3241 ("decl cannot appear after body#", Decl);
3242 end if;
3243 end if;
3244
3245 Next (Decl);
3246 end loop Inner;
3247 end if;
3248 end loop Outer;
3249 end Check_Later_Vs_Basic_Declarations;
3250
3251 ---------------------------
3252 -- Check_No_Hidden_State --
3253 ---------------------------
3254
3255 procedure Check_No_Hidden_State (Id : Entity_Id) is
3256 Context : Entity_Id := Empty;
3257 Not_Visible : Boolean := False;
3258 Scop : Entity_Id;
3259
3260 begin
3261 pragma Assert (Ekind_In (Id, E_Abstract_State, E_Variable));
3262
3263 -- Nothing to do for internally-generated abstract states and variables
3264 -- because they do not represent the hidden state of the source unit.
3265
3266 if not Comes_From_Source (Id) then
3267 return;
3268 end if;
3269
3270 -- Find the proper context where the object or state appears
3271
3272 Scop := Scope (Id);
3273 while Present (Scop) loop
3274 Context := Scop;
3275
3276 -- Keep track of the context's visibility
3277
3278 Not_Visible := Not_Visible or else In_Private_Part (Context);
3279
3280 -- Prevent the search from going too far
3281
3282 if Context = Standard_Standard then
3283 return;
3284
3285 -- Objects and states that appear immediately within a subprogram or
3286 -- inside a construct nested within a subprogram do not introduce a
3287 -- hidden state. They behave as local variable declarations.
3288
3289 elsif Is_Subprogram (Context) then
3290 return;
3291
3292 -- When examining a package body, use the entity of the spec as it
3293 -- carries the abstract state declarations.
3294
3295 elsif Ekind (Context) = E_Package_Body then
3296 Context := Spec_Entity (Context);
3297 end if;
3298
3299 -- Stop the traversal when a package subject to a null abstract state
3300 -- has been found.
3301
3302 if Ekind_In (Context, E_Generic_Package, E_Package)
3303 and then Has_Null_Abstract_State (Context)
3304 then
3305 exit;
3306 end if;
3307
3308 Scop := Scope (Scop);
3309 end loop;
3310
3311 -- At this point we know that there is at least one package with a null
3312 -- abstract state in visibility. Emit an error message unconditionally
3313 -- if the entity being processed is a state because the placement of the
3314 -- related package is irrelevant. This is not the case for objects as
3315 -- the intermediate context matters.
3316
3317 if Present (Context)
3318 and then (Ekind (Id) = E_Abstract_State or else Not_Visible)
3319 then
3320 Error_Msg_N ("cannot introduce hidden state &", Id);
3321 Error_Msg_NE ("\package & has null abstract state", Id, Context);
3322 end if;
3323 end Check_No_Hidden_State;
3324
3325 ----------------------------------------
3326 -- Check_Nonvolatile_Function_Profile --
3327 ----------------------------------------
3328
3329 procedure Check_Nonvolatile_Function_Profile (Func_Id : Entity_Id) is
3330 Formal : Entity_Id;
3331
3332 begin
3333 -- Inspect all formal parameters
3334
3335 Formal := First_Formal (Func_Id);
3336 while Present (Formal) loop
3337 if Is_Effectively_Volatile (Etype (Formal)) then
3338 Error_Msg_NE
3339 ("nonvolatile function & cannot have a volatile parameter",
3340 Formal, Func_Id);
3341 end if;
3342
3343 Next_Formal (Formal);
3344 end loop;
3345
3346 -- Inspect the return type
3347
3348 if Is_Effectively_Volatile (Etype (Func_Id)) then
3349 Error_Msg_NE
3350 ("nonvolatile function & cannot have a volatile return type",
3351 Result_Definition (Parent (Func_Id)), Func_Id);
3352 end if;
3353 end Check_Nonvolatile_Function_Profile;
3354
3355 -----------------------------
3356 -- Check_Part_Of_Reference --
3357 -----------------------------
3358
3359 procedure Check_Part_Of_Reference (Var_Id : Entity_Id; Ref : Node_Id) is
3360 function Is_Enclosing_Package_Body
3361 (Body_Decl : Node_Id;
3362 Obj_Id : Entity_Id) return Boolean;
3363 pragma Inline (Is_Enclosing_Package_Body);
3364 -- Determine whether package body Body_Decl or its corresponding spec
3365 -- immediately encloses the declaration of object Obj_Id.
3366
3367 function Is_Internal_Declaration_Or_Body
3368 (Decl : Node_Id) return Boolean;
3369 pragma Inline (Is_Internal_Declaration_Or_Body);
3370 -- Determine whether declaration or body denoted by Decl is internal
3371
3372 function Is_Single_Declaration_Or_Body
3373 (Decl : Node_Id;
3374 Conc_Typ : Entity_Id) return Boolean;
3375 pragma Inline (Is_Single_Declaration_Or_Body);
3376 -- Determine whether protected/task declaration or body denoted by Decl
3377 -- belongs to single concurrent type Conc_Typ.
3378
3379 function Is_Single_Task_Pragma
3380 (Prag : Node_Id;
3381 Task_Typ : Entity_Id) return Boolean;
3382 pragma Inline (Is_Single_Task_Pragma);
3383 -- Determine whether pragma Prag belongs to single task type Task_Typ
3384
3385 -------------------------------
3386 -- Is_Enclosing_Package_Body --
3387 -------------------------------
3388
3389 function Is_Enclosing_Package_Body
3390 (Body_Decl : Node_Id;
3391 Obj_Id : Entity_Id) return Boolean
3392 is
3393 Obj_Context : Node_Id;
3394
3395 begin
3396 -- Find the context of the object declaration
3397
3398 Obj_Context := Parent (Declaration_Node (Obj_Id));
3399
3400 if Nkind (Obj_Context) = N_Package_Specification then
3401 Obj_Context := Parent (Obj_Context);
3402 end if;
3403
3404 -- The object appears immediately within the package body
3405
3406 if Obj_Context = Body_Decl then
3407 return True;
3408
3409 -- The object appears immediately within the corresponding spec
3410
3411 elsif Nkind (Obj_Context) = N_Package_Declaration
3412 and then Unit_Declaration_Node (Corresponding_Spec (Body_Decl)) =
3413 Obj_Context
3414 then
3415 return True;
3416 end if;
3417
3418 return False;
3419 end Is_Enclosing_Package_Body;
3420
3421 -------------------------------------
3422 -- Is_Internal_Declaration_Or_Body --
3423 -------------------------------------
3424
3425 function Is_Internal_Declaration_Or_Body
3426 (Decl : Node_Id) return Boolean
3427 is
3428 begin
3429 if Comes_From_Source (Decl) then
3430 return False;
3431
3432 -- A body generated for an expression function which has not been
3433 -- inserted into the tree yet (In_Spec_Expression is True) is not
3434 -- considered internal.
3435
3436 elsif Nkind (Decl) = N_Subprogram_Body
3437 and then Was_Expression_Function (Decl)
3438 and then not In_Spec_Expression
3439 then
3440 return False;
3441 end if;
3442
3443 return True;
3444 end Is_Internal_Declaration_Or_Body;
3445
3446 -----------------------------------
3447 -- Is_Single_Declaration_Or_Body --
3448 -----------------------------------
3449
3450 function Is_Single_Declaration_Or_Body
3451 (Decl : Node_Id;
3452 Conc_Typ : Entity_Id) return Boolean
3453 is
3454 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Decl);
3455
3456 begin
3457 return
3458 Present (Anonymous_Object (Spec_Id))
3459 and then Anonymous_Object (Spec_Id) = Conc_Typ;
3460 end Is_Single_Declaration_Or_Body;
3461
3462 ---------------------------
3463 -- Is_Single_Task_Pragma --
3464 ---------------------------
3465
3466 function Is_Single_Task_Pragma
3467 (Prag : Node_Id;
3468 Task_Typ : Entity_Id) return Boolean
3469 is
3470 Decl : constant Node_Id := Find_Related_Declaration_Or_Body (Prag);
3471
3472 begin
3473 -- To qualify, the pragma must be associated with single task type
3474 -- Task_Typ.
3475
3476 return
3477 Is_Single_Task_Object (Task_Typ)
3478 and then Nkind (Decl) = N_Object_Declaration
3479 and then Defining_Entity (Decl) = Task_Typ;
3480 end Is_Single_Task_Pragma;
3481
3482 -- Local variables
3483
3484 Conc_Obj : constant Entity_Id := Encapsulating_State (Var_Id);
3485 Par : Node_Id;
3486 Prag_Nam : Name_Id;
3487 Prev : Node_Id;
3488
3489 -- Start of processing for Check_Part_Of_Reference
3490
3491 begin
3492 -- Nothing to do when the variable was recorded, but did not become a
3493 -- constituent of a single concurrent type.
3494
3495 if No (Conc_Obj) then
3496 return;
3497 end if;
3498
3499 -- Traverse the parent chain looking for a suitable context for the
3500 -- reference to the concurrent constituent.
3501
3502 Prev := Ref;
3503 Par := Parent (Prev);
3504 while Present (Par) loop
3505 if Nkind (Par) = N_Pragma then
3506 Prag_Nam := Pragma_Name (Par);
3507
3508 -- A concurrent constituent is allowed to appear in pragmas
3509 -- Initial_Condition and Initializes as this is part of the
3510 -- elaboration checks for the constituent (SPARK RM 9(3)).
3511
3512 if Nam_In (Prag_Nam, Name_Initial_Condition, Name_Initializes) then
3513 return;
3514
3515 -- When the reference appears within pragma Depends or Global,
3516 -- check whether the pragma applies to a single task type. Note
3517 -- that the pragma may not encapsulated by the type definition,
3518 -- but this is still a valid context.
3519
3520 elsif Nam_In (Prag_Nam, Name_Depends, Name_Global)
3521 and then Is_Single_Task_Pragma (Par, Conc_Obj)
3522 then
3523 return;
3524 end if;
3525
3526 -- The reference appears somewhere in the definition of a single
3527 -- concurrent type (SPARK RM 9(3)).
3528
3529 elsif Nkind_In (Par, N_Single_Protected_Declaration,
3530 N_Single_Task_Declaration)
3531 and then Defining_Entity (Par) = Conc_Obj
3532 then
3533 return;
3534
3535 -- The reference appears within the declaration or body of a single
3536 -- concurrent type (SPARK RM 9(3)).
3537
3538 elsif Nkind_In (Par, N_Protected_Body,
3539 N_Protected_Type_Declaration,
3540 N_Task_Body,
3541 N_Task_Type_Declaration)
3542 and then Is_Single_Declaration_Or_Body (Par, Conc_Obj)
3543 then
3544 return;
3545
3546 -- The reference appears within the statement list of the object's
3547 -- immediately enclosing package (SPARK RM 9(3)).
3548
3549 elsif Nkind (Par) = N_Package_Body
3550 and then Nkind (Prev) = N_Handled_Sequence_Of_Statements
3551 and then Is_Enclosing_Package_Body (Par, Var_Id)
3552 then
3553 return;
3554
3555 -- The reference has been relocated within an internally generated
3556 -- package or subprogram. Assume that the reference is legal as the
3557 -- real check was already performed in the original context of the
3558 -- reference.
3559
3560 elsif Nkind_In (Par, N_Package_Body,
3561 N_Package_Declaration,
3562 N_Subprogram_Body,
3563 N_Subprogram_Declaration)
3564 and then Is_Internal_Declaration_Or_Body (Par)
3565 then
3566 return;
3567
3568 -- The reference has been relocated to an inlined body for GNATprove.
3569 -- Assume that the reference is legal as the real check was already
3570 -- performed in the original context of the reference.
3571
3572 elsif GNATprove_Mode
3573 and then Nkind (Par) = N_Subprogram_Body
3574 and then Chars (Defining_Entity (Par)) = Name_uParent
3575 then
3576 return;
3577 end if;
3578
3579 Prev := Par;
3580 Par := Parent (Prev);
3581 end loop;
3582
3583 -- At this point it is known that the reference does not appear within a
3584 -- legal context.
3585
3586 Error_Msg_NE
3587 ("reference to variable & cannot appear in this context", Ref, Var_Id);
3588 Error_Msg_Name_1 := Chars (Var_Id);
3589
3590 if Is_Single_Protected_Object (Conc_Obj) then
3591 Error_Msg_NE
3592 ("\% is constituent of single protected type &", Ref, Conc_Obj);
3593
3594 else
3595 Error_Msg_NE
3596 ("\% is constituent of single task type &", Ref, Conc_Obj);
3597 end if;
3598 end Check_Part_Of_Reference;
3599
3600 ------------------------------------------
3601 -- Check_Potentially_Blocking_Operation --
3602 ------------------------------------------
3603
3604 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
3605 S : Entity_Id;
3606
3607 begin
3608 -- N is one of the potentially blocking operations listed in 9.5.1(8).
3609 -- When pragma Detect_Blocking is active, the run time will raise
3610 -- Program_Error. Here we only issue a warning, since we generally
3611 -- support the use of potentially blocking operations in the absence
3612 -- of the pragma.
3613
3614 -- Indirect blocking through a subprogram call cannot be diagnosed
3615 -- statically without interprocedural analysis, so we do not attempt
3616 -- to do it here.
3617
3618 S := Scope (Current_Scope);
3619 while Present (S) and then S /= Standard_Standard loop
3620 if Is_Protected_Type (S) then
3621 Error_Msg_N
3622 ("potentially blocking operation in protected operation??", N);
3623 return;
3624 end if;
3625
3626 S := Scope (S);
3627 end loop;
3628 end Check_Potentially_Blocking_Operation;
3629
3630 ------------------------------------
3631 -- Check_Previous_Null_Procedure --
3632 ------------------------------------
3633
3634 procedure Check_Previous_Null_Procedure
3635 (Decl : Node_Id;
3636 Prev : Entity_Id)
3637 is
3638 begin
3639 if Ekind (Prev) = E_Procedure
3640 and then Nkind (Parent (Prev)) = N_Procedure_Specification
3641 and then Null_Present (Parent (Prev))
3642 then
3643 Error_Msg_Sloc := Sloc (Prev);
3644 Error_Msg_N
3645 ("declaration cannot complete previous null procedure#", Decl);
3646 end if;
3647 end Check_Previous_Null_Procedure;
3648
3649 ---------------------------------
3650 -- Check_Result_And_Post_State --
3651 ---------------------------------
3652
3653 procedure Check_Result_And_Post_State (Subp_Id : Entity_Id) is
3654 procedure Check_Result_And_Post_State_In_Pragma
3655 (Prag : Node_Id;
3656 Result_Seen : in out Boolean);
3657 -- Determine whether pragma Prag mentions attribute 'Result and whether
3658 -- the pragma contains an expression that evaluates differently in pre-
3659 -- and post-state. Prag is a [refined] postcondition or a contract-cases
3660 -- pragma. Result_Seen is set when the pragma mentions attribute 'Result
3661
3662 function Has_In_Out_Parameter (Subp_Id : Entity_Id) return Boolean;
3663 -- Determine whether subprogram Subp_Id contains at least one IN OUT
3664 -- formal parameter.
3665
3666 -------------------------------------------
3667 -- Check_Result_And_Post_State_In_Pragma --
3668 -------------------------------------------
3669
3670 procedure Check_Result_And_Post_State_In_Pragma
3671 (Prag : Node_Id;
3672 Result_Seen : in out Boolean)
3673 is
3674 procedure Check_Conjunct (Expr : Node_Id);
3675 -- Check an individual conjunct in a conjunction of Boolean
3676 -- expressions, connected by "and" or "and then" operators.
3677
3678 procedure Check_Conjuncts (Expr : Node_Id);
3679 -- Apply the post-state check to every conjunct in an expression, in
3680 -- case this is a conjunction of Boolean expressions. Otherwise apply
3681 -- it to the expression as a whole.
3682
3683 procedure Check_Expression (Expr : Node_Id);
3684 -- Perform the 'Result and post-state checks on a given expression
3685
3686 function Is_Function_Result (N : Node_Id) return Traverse_Result;
3687 -- Attempt to find attribute 'Result in a subtree denoted by N
3688
3689 function Is_Trivial_Boolean (N : Node_Id) return Boolean;
3690 -- Determine whether source node N denotes "True" or "False"
3691
3692 function Mentions_Post_State (N : Node_Id) return Boolean;
3693 -- Determine whether a subtree denoted by N mentions any construct
3694 -- that denotes a post-state.
3695
3696 procedure Check_Function_Result is
3697 new Traverse_Proc (Is_Function_Result);
3698
3699 --------------------
3700 -- Check_Conjunct --
3701 --------------------
3702
3703 procedure Check_Conjunct (Expr : Node_Id) is
3704 function Adjust_Message (Msg : String) return String;
3705 -- Prepend a prefix to the input message Msg denoting that the
3706 -- message applies to a conjunct in the expression, when this
3707 -- is the case.
3708
3709 function Applied_On_Conjunct return Boolean;
3710 -- Returns True if the message applies to a conjunct in the
3711 -- expression, instead of the whole expression.
3712
3713 function Has_Global_Output (Subp : Entity_Id) return Boolean;
3714 -- Returns True if Subp has an output in its Global contract
3715
3716 function Has_No_Output (Subp : Entity_Id) return Boolean;
3717 -- Returns True if Subp has no declared output: no function
3718 -- result, no output parameter, and no output in its Global
3719 -- contract.
3720
3721 --------------------
3722 -- Adjust_Message --
3723 --------------------
3724
3725 function Adjust_Message (Msg : String) return String is
3726 begin
3727 if Applied_On_Conjunct then
3728 return "conjunct in " & Msg;
3729 else
3730 return Msg;
3731 end if;
3732 end Adjust_Message;
3733
3734 -------------------------
3735 -- Applied_On_Conjunct --
3736 -------------------------
3737
3738 function Applied_On_Conjunct return Boolean is
3739 begin
3740 -- Expr is the conjunct of an enclosing "and" expression
3741
3742 return Nkind (Parent (Expr)) in N_Subexpr
3743
3744 -- or Expr is a conjunct of an enclosing "and then"
3745 -- expression in a postcondition aspect that was split into
3746 -- multiple pragmas. The first conjunct has the "and then"
3747 -- expression as Original_Node, and other conjuncts have
3748 -- Split_PCC set to True.
3749
3750 or else Nkind (Original_Node (Expr)) = N_And_Then
3751 or else Split_PPC (Prag);
3752 end Applied_On_Conjunct;
3753
3754 -----------------------
3755 -- Has_Global_Output --
3756 -----------------------
3757
3758 function Has_Global_Output (Subp : Entity_Id) return Boolean is
3759 Global : constant Node_Id := Get_Pragma (Subp, Pragma_Global);
3760 List : Node_Id;
3761 Assoc : Node_Id;
3762
3763 begin
3764 if No (Global) then
3765 return False;
3766 end if;
3767
3768 List := Expression (Get_Argument (Global, Subp));
3769
3770 -- Empty list (no global items) or single global item
3771 -- declaration (only input items).
3772
3773 if Nkind_In (List, N_Null,
3774 N_Expanded_Name,
3775 N_Identifier,
3776 N_Selected_Component)
3777 then
3778 return False;
3779
3780 -- Simple global list (only input items) or moded global list
3781 -- declaration.
3782
3783 elsif Nkind (List) = N_Aggregate then
3784 if Present (Expressions (List)) then
3785 return False;
3786
3787 else
3788 Assoc := First (Component_Associations (List));
3789 while Present (Assoc) loop
3790 if Chars (First (Choices (Assoc))) /= Name_Input then
3791 return True;
3792 end if;
3793
3794 Next (Assoc);
3795 end loop;
3796
3797 return False;
3798 end if;
3799
3800 -- To accommodate partial decoration of disabled SPARK
3801 -- features, this routine may be called with illegal input.
3802 -- If this is the case, do not raise Program_Error.
3803
3804 else
3805 return False;
3806 end if;
3807 end Has_Global_Output;
3808
3809 -------------------
3810 -- Has_No_Output --
3811 -------------------
3812
3813 function Has_No_Output (Subp : Entity_Id) return Boolean is
3814 Param : Node_Id;
3815
3816 begin
3817 -- A function has its result as output
3818
3819 if Ekind (Subp) = E_Function then
3820 return False;
3821 end if;
3822
3823 -- An OUT or IN OUT parameter is an output
3824
3825 Param := First_Formal (Subp);
3826 while Present (Param) loop
3827 if Ekind_In (Param, E_Out_Parameter, E_In_Out_Parameter) then
3828 return False;
3829 end if;
3830
3831 Next_Formal (Param);
3832 end loop;
3833
3834 -- An item of mode Output or In_Out in the Global contract is
3835 -- an output.
3836
3837 if Has_Global_Output (Subp) then
3838 return False;
3839 end if;
3840
3841 return True;
3842 end Has_No_Output;
3843
3844 -- Local variables
3845
3846 Err_Node : Node_Id;
3847 -- Error node when reporting a warning on a (refined)
3848 -- postcondition.
3849
3850 -- Start of processing for Check_Conjunct
3851
3852 begin
3853 if Applied_On_Conjunct then
3854 Err_Node := Expr;
3855 else
3856 Err_Node := Prag;
3857 end if;
3858
3859 -- Do not report missing reference to outcome in postcondition if
3860 -- either the postcondition is trivially True or False, or if the
3861 -- subprogram is ghost and has no declared output.
3862
3863 if not Is_Trivial_Boolean (Expr)
3864 and then not Mentions_Post_State (Expr)
3865 and then not (Is_Ghost_Entity (Subp_Id)
3866 and then Has_No_Output (Subp_Id))
3867 then
3868 if Pragma_Name (Prag) = Name_Contract_Cases then
3869 Error_Msg_NE (Adjust_Message
3870 ("contract case does not check the outcome of calling "
3871 & "&?T?"), Expr, Subp_Id);
3872
3873 elsif Pragma_Name (Prag) = Name_Refined_Post then
3874 Error_Msg_NE (Adjust_Message
3875 ("refined postcondition does not check the outcome of "
3876 & "calling &?T?"), Err_Node, Subp_Id);
3877
3878 else
3879 Error_Msg_NE (Adjust_Message
3880 ("postcondition does not check the outcome of calling "
3881 & "&?T?"), Err_Node, Subp_Id);
3882 end if;
3883 end if;
3884 end Check_Conjunct;
3885
3886 ---------------------
3887 -- Check_Conjuncts --
3888 ---------------------
3889
3890 procedure Check_Conjuncts (Expr : Node_Id) is
3891 begin
3892 if Nkind_In (Expr, N_Op_And, N_And_Then) then
3893 Check_Conjuncts (Left_Opnd (Expr));
3894 Check_Conjuncts (Right_Opnd (Expr));
3895 else
3896 Check_Conjunct (Expr);
3897 end if;
3898 end Check_Conjuncts;
3899
3900 ----------------------
3901 -- Check_Expression --
3902 ----------------------
3903
3904 procedure Check_Expression (Expr : Node_Id) is
3905 begin
3906 if not Is_Trivial_Boolean (Expr) then
3907 Check_Function_Result (Expr);
3908 Check_Conjuncts (Expr);
3909 end if;
3910 end Check_Expression;
3911
3912 ------------------------
3913 -- Is_Function_Result --
3914 ------------------------
3915
3916 function Is_Function_Result (N : Node_Id) return Traverse_Result is
3917 begin
3918 if Is_Attribute_Result (N) then
3919 Result_Seen := True;
3920 return Abandon;
3921
3922 -- Warn on infinite recursion if call is to current function
3923
3924 elsif Nkind (N) = N_Function_Call
3925 and then Is_Entity_Name (Name (N))
3926 and then Entity (Name (N)) = Subp_Id
3927 and then not Is_Potentially_Unevaluated (N)
3928 then
3929 Error_Msg_NE
3930 ("call to & within its postcondition will lead to infinite "
3931 & "recursion?", N, Subp_Id);
3932 return OK;
3933
3934 -- Continue the traversal
3935
3936 else
3937 return OK;
3938 end if;
3939 end Is_Function_Result;
3940
3941 ------------------------
3942 -- Is_Trivial_Boolean --
3943 ------------------------
3944
3945 function Is_Trivial_Boolean (N : Node_Id) return Boolean is
3946 begin
3947 return
3948 Comes_From_Source (N)
3949 and then Is_Entity_Name (N)
3950 and then (Entity (N) = Standard_True
3951 or else
3952 Entity (N) = Standard_False);
3953 end Is_Trivial_Boolean;
3954
3955 -------------------------
3956 -- Mentions_Post_State --
3957 -------------------------
3958
3959 function Mentions_Post_State (N : Node_Id) return Boolean is
3960 Post_State_Seen : Boolean := False;
3961
3962 function Is_Post_State (N : Node_Id) return Traverse_Result;
3963 -- Attempt to find a construct that denotes a post-state. If this
3964 -- is the case, set flag Post_State_Seen.
3965
3966 -------------------
3967 -- Is_Post_State --
3968 -------------------
3969
3970 function Is_Post_State (N : Node_Id) return Traverse_Result is
3971 Ent : Entity_Id;
3972
3973 begin
3974 if Nkind_In (N, N_Explicit_Dereference, N_Function_Call) then
3975 Post_State_Seen := True;
3976 return Abandon;
3977
3978 elsif Nkind_In (N, N_Expanded_Name, N_Identifier) then
3979 Ent := Entity (N);
3980
3981 -- Treat an undecorated reference as OK
3982
3983 if No (Ent)
3984
3985 -- A reference to an assignable entity is considered a
3986 -- change in the post-state of a subprogram.
3987
3988 or else Ekind_In (Ent, E_Generic_In_Out_Parameter,
3989 E_In_Out_Parameter,
3990 E_Out_Parameter,
3991 E_Variable)
3992
3993 -- The reference may be modified through a dereference
3994
3995 or else (Is_Access_Type (Etype (Ent))
3996 and then Nkind (Parent (N)) =
3997 N_Selected_Component)
3998 then
3999 Post_State_Seen := True;
4000 return Abandon;
4001 end if;
4002
4003 elsif Nkind (N) = N_Attribute_Reference then
4004 if Attribute_Name (N) = Name_Old then
4005 return Skip;
4006
4007 elsif Attribute_Name (N) = Name_Result then
4008 Post_State_Seen := True;
4009 return Abandon;
4010 end if;
4011 end if;
4012
4013 return OK;
4014 end Is_Post_State;
4015
4016 procedure Find_Post_State is new Traverse_Proc (Is_Post_State);
4017
4018 -- Start of processing for Mentions_Post_State
4019
4020 begin
4021 Find_Post_State (N);
4022
4023 return Post_State_Seen;
4024 end Mentions_Post_State;
4025
4026 -- Local variables
4027
4028 Expr : constant Node_Id :=
4029 Get_Pragma_Arg
4030 (First (Pragma_Argument_Associations (Prag)));
4031 Nam : constant Name_Id := Pragma_Name (Prag);
4032 CCase : Node_Id;
4033
4034 -- Start of processing for Check_Result_And_Post_State_In_Pragma
4035
4036 begin
4037 -- Examine all consequences
4038
4039 if Nam = Name_Contract_Cases then
4040 CCase := First (Component_Associations (Expr));
4041 while Present (CCase) loop
4042 Check_Expression (Expression (CCase));
4043
4044 Next (CCase);
4045 end loop;
4046
4047 -- Examine the expression of a postcondition
4048
4049 else pragma Assert (Nam_In (Nam, Name_Postcondition,
4050 Name_Refined_Post));
4051 Check_Expression (Expr);
4052 end if;
4053 end Check_Result_And_Post_State_In_Pragma;
4054
4055 --------------------------
4056 -- Has_In_Out_Parameter --
4057 --------------------------
4058
4059 function Has_In_Out_Parameter (Subp_Id : Entity_Id) return Boolean is
4060 Formal : Entity_Id;
4061
4062 begin
4063 -- Traverse the formals looking for an IN OUT parameter
4064
4065 Formal := First_Formal (Subp_Id);
4066 while Present (Formal) loop
4067 if Ekind (Formal) = E_In_Out_Parameter then
4068 return True;
4069 end if;
4070
4071 Next_Formal (Formal);
4072 end loop;
4073
4074 return False;
4075 end Has_In_Out_Parameter;
4076
4077 -- Local variables
4078
4079 Items : constant Node_Id := Contract (Subp_Id);
4080 Subp_Decl : constant Node_Id := Unit_Declaration_Node (Subp_Id);
4081 Case_Prag : Node_Id := Empty;
4082 Post_Prag : Node_Id := Empty;
4083 Prag : Node_Id;
4084 Seen_In_Case : Boolean := False;
4085 Seen_In_Post : Boolean := False;
4086 Spec_Id : Entity_Id;
4087
4088 -- Start of processing for Check_Result_And_Post_State
4089
4090 begin
4091 -- The lack of attribute 'Result or a post-state is classified as a
4092 -- suspicious contract. Do not perform the check if the corresponding
4093 -- swich is not set.
4094
4095 if not Warn_On_Suspicious_Contract then
4096 return;
4097
4098 -- Nothing to do if there is no contract
4099
4100 elsif No (Items) then
4101 return;
4102 end if;
4103
4104 -- Retrieve the entity of the subprogram spec (if any)
4105
4106 if Nkind (Subp_Decl) = N_Subprogram_Body
4107 and then Present (Corresponding_Spec (Subp_Decl))
4108 then
4109 Spec_Id := Corresponding_Spec (Subp_Decl);
4110
4111 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
4112 and then Present (Corresponding_Spec_Of_Stub (Subp_Decl))
4113 then
4114 Spec_Id := Corresponding_Spec_Of_Stub (Subp_Decl);
4115
4116 else
4117 Spec_Id := Subp_Id;
4118 end if;
4119
4120 -- Examine all postconditions for attribute 'Result and a post-state
4121
4122 Prag := Pre_Post_Conditions (Items);
4123 while Present (Prag) loop
4124 if Nam_In (Pragma_Name_Unmapped (Prag),
4125 Name_Postcondition, Name_Refined_Post)
4126 and then not Error_Posted (Prag)
4127 then
4128 Post_Prag := Prag;
4129 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Post);
4130 end if;
4131
4132 Prag := Next_Pragma (Prag);
4133 end loop;
4134
4135 -- Examine the contract cases of the subprogram for attribute 'Result
4136 -- and a post-state.
4137
4138 Prag := Contract_Test_Cases (Items);
4139 while Present (Prag) loop
4140 if Pragma_Name (Prag) = Name_Contract_Cases
4141 and then not Error_Posted (Prag)
4142 then
4143 Case_Prag := Prag;
4144 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Case);
4145 end if;
4146
4147 Prag := Next_Pragma (Prag);
4148 end loop;
4149
4150 -- Do not emit any errors if the subprogram is not a function
4151
4152 if not Ekind_In (Spec_Id, E_Function, E_Generic_Function) then
4153 null;
4154
4155 -- Regardless of whether the function has postconditions or contract
4156 -- cases, or whether they mention attribute 'Result, an IN OUT formal
4157 -- parameter is always treated as a result.
4158
4159 elsif Has_In_Out_Parameter (Spec_Id) then
4160 null;
4161
4162 -- The function has both a postcondition and contract cases and they do
4163 -- not mention attribute 'Result.
4164
4165 elsif Present (Case_Prag)
4166 and then not Seen_In_Case
4167 and then Present (Post_Prag)
4168 and then not Seen_In_Post
4169 then
4170 Error_Msg_N
4171 ("neither postcondition nor contract cases mention function "
4172 & "result?T?", Post_Prag);
4173
4174 -- The function has contract cases only and they do not mention
4175 -- attribute 'Result.
4176
4177 elsif Present (Case_Prag) and then not Seen_In_Case then
4178 Error_Msg_N ("contract cases do not mention result?T?", Case_Prag);
4179
4180 -- The function has postconditions only and they do not mention
4181 -- attribute 'Result.
4182
4183 elsif Present (Post_Prag) and then not Seen_In_Post then
4184 Error_Msg_N
4185 ("postcondition does not mention function result?T?", Post_Prag);
4186 end if;
4187 end Check_Result_And_Post_State;
4188
4189 -----------------------------
4190 -- Check_State_Refinements --
4191 -----------------------------
4192
4193 procedure Check_State_Refinements
4194 (Context : Node_Id;
4195 Is_Main_Unit : Boolean := False)
4196 is
4197 procedure Check_Package (Pack : Node_Id);
4198 -- Verify that all abstract states of a [generic] package denoted by its
4199 -- declarative node Pack have proper refinement. Recursively verify the
4200 -- visible and private declarations of the [generic] package for other
4201 -- nested packages.
4202
4203 procedure Check_Packages_In (Decls : List_Id);
4204 -- Seek out [generic] package declarations within declarative list Decls
4205 -- and verify the status of their abstract state refinement.
4206
4207 function SPARK_Mode_Is_Off (N : Node_Id) return Boolean;
4208 -- Determine whether construct N is subject to pragma SPARK_Mode Off
4209
4210 -------------------
4211 -- Check_Package --
4212 -------------------
4213
4214 procedure Check_Package (Pack : Node_Id) is
4215 Body_Id : constant Entity_Id := Corresponding_Body (Pack);
4216 Spec : constant Node_Id := Specification (Pack);
4217 States : constant Elist_Id :=
4218 Abstract_States (Defining_Entity (Pack));
4219
4220 State_Elmt : Elmt_Id;
4221 State_Id : Entity_Id;
4222
4223 begin
4224 -- Do not verify proper state refinement when the package is subject
4225 -- to pragma SPARK_Mode Off because this disables the requirement for
4226 -- state refinement.
4227
4228 if SPARK_Mode_Is_Off (Pack) then
4229 null;
4230
4231 -- State refinement can only occur in a completing package body. Do
4232 -- not verify proper state refinement when the body is subject to
4233 -- pragma SPARK_Mode Off because this disables the requirement for
4234 -- state refinement.
4235
4236 elsif Present (Body_Id)
4237 and then SPARK_Mode_Is_Off (Unit_Declaration_Node (Body_Id))
4238 then
4239 null;
4240
4241 -- Do not verify proper state refinement when the package is an
4242 -- instance as this check was already performed in the generic.
4243
4244 elsif Present (Generic_Parent (Spec)) then
4245 null;
4246
4247 -- Otherwise examine the contents of the package
4248
4249 else
4250 if Present (States) then
4251 State_Elmt := First_Elmt (States);
4252 while Present (State_Elmt) loop
4253 State_Id := Node (State_Elmt);
4254
4255 -- Emit an error when a non-null state lacks any form of
4256 -- refinement.
4257
4258 if not Is_Null_State (State_Id)
4259 and then not Has_Null_Refinement (State_Id)
4260 and then not Has_Non_Null_Refinement (State_Id)
4261 then
4262 Error_Msg_N ("state & requires refinement", State_Id);
4263 end if;
4264
4265 Next_Elmt (State_Elmt);
4266 end loop;
4267 end if;
4268
4269 Check_Packages_In (Visible_Declarations (Spec));
4270 Check_Packages_In (Private_Declarations (Spec));
4271 end if;
4272 end Check_Package;
4273
4274 -----------------------
4275 -- Check_Packages_In --
4276 -----------------------
4277
4278 procedure Check_Packages_In (Decls : List_Id) is
4279 Decl : Node_Id;
4280
4281 begin
4282 if Present (Decls) then
4283 Decl := First (Decls);
4284 while Present (Decl) loop
4285 if Nkind_In (Decl, N_Generic_Package_Declaration,
4286 N_Package_Declaration)
4287 then
4288 Check_Package (Decl);
4289 end if;
4290
4291 Next (Decl);
4292 end loop;
4293 end if;
4294 end Check_Packages_In;
4295
4296 -----------------------
4297 -- SPARK_Mode_Is_Off --
4298 -----------------------
4299
4300 function SPARK_Mode_Is_Off (N : Node_Id) return Boolean is
4301 Id : constant Entity_Id := Defining_Entity (N);
4302 Prag : constant Node_Id := SPARK_Pragma (Id);
4303
4304 begin
4305 -- Default the mode to "off" when the context is an instance and all
4306 -- SPARK_Mode pragmas found within are to be ignored.
4307
4308 if Ignore_SPARK_Mode_Pragmas (Id) then
4309 return True;
4310
4311 else
4312 return
4313 Present (Prag)
4314 and then Get_SPARK_Mode_From_Annotation (Prag) = Off;
4315 end if;
4316 end SPARK_Mode_Is_Off;
4317
4318 -- Start of processing for Check_State_Refinements
4319
4320 begin
4321 -- A block may declare a nested package
4322
4323 if Nkind (Context) = N_Block_Statement then
4324 Check_Packages_In (Declarations (Context));
4325
4326 -- An entry, protected, subprogram, or task body may declare a nested
4327 -- package.
4328
4329 elsif Nkind_In (Context, N_Entry_Body,
4330 N_Protected_Body,
4331 N_Subprogram_Body,
4332 N_Task_Body)
4333 then
4334 -- Do not verify proper state refinement when the body is subject to
4335 -- pragma SPARK_Mode Off because this disables the requirement for
4336 -- state refinement.
4337
4338 if not SPARK_Mode_Is_Off (Context) then
4339 Check_Packages_In (Declarations (Context));
4340 end if;
4341
4342 -- A package body may declare a nested package
4343
4344 elsif Nkind (Context) = N_Package_Body then
4345 Check_Package (Unit_Declaration_Node (Corresponding_Spec (Context)));
4346
4347 -- Do not verify proper state refinement when the body is subject to
4348 -- pragma SPARK_Mode Off because this disables the requirement for
4349 -- state refinement.
4350
4351 if not SPARK_Mode_Is_Off (Context) then
4352 Check_Packages_In (Declarations (Context));
4353 end if;
4354
4355 -- A library level [generic] package may declare a nested package
4356
4357 elsif Nkind_In (Context, N_Generic_Package_Declaration,
4358 N_Package_Declaration)
4359 and then Is_Main_Unit
4360 then
4361 Check_Package (Context);
4362 end if;
4363 end Check_State_Refinements;
4364
4365 ------------------------------
4366 -- Check_Unprotected_Access --
4367 ------------------------------
4368
4369 procedure Check_Unprotected_Access
4370 (Context : Node_Id;
4371 Expr : Node_Id)
4372 is
4373 Cont_Encl_Typ : Entity_Id;
4374 Pref_Encl_Typ : Entity_Id;
4375
4376 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
4377 -- Check whether Obj is a private component of a protected object.
4378 -- Return the protected type where the component resides, Empty
4379 -- otherwise.
4380
4381 function Is_Public_Operation return Boolean;
4382 -- Verify that the enclosing operation is callable from outside the
4383 -- protected object, to minimize false positives.
4384
4385 ------------------------------
4386 -- Enclosing_Protected_Type --
4387 ------------------------------
4388
4389 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
4390 begin
4391 if Is_Entity_Name (Obj) then
4392 declare
4393 Ent : Entity_Id := Entity (Obj);
4394
4395 begin
4396 -- The object can be a renaming of a private component, use
4397 -- the original record component.
4398
4399 if Is_Prival (Ent) then
4400 Ent := Prival_Link (Ent);
4401 end if;
4402
4403 if Is_Protected_Type (Scope (Ent)) then
4404 return Scope (Ent);
4405 end if;
4406 end;
4407 end if;
4408
4409 -- For indexed and selected components, recursively check the prefix
4410
4411 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
4412 return Enclosing_Protected_Type (Prefix (Obj));
4413
4414 -- The object does not denote a protected component
4415
4416 else
4417 return Empty;
4418 end if;
4419 end Enclosing_Protected_Type;
4420
4421 -------------------------
4422 -- Is_Public_Operation --
4423 -------------------------
4424
4425 function Is_Public_Operation return Boolean is
4426 S : Entity_Id;
4427 E : Entity_Id;
4428
4429 begin
4430 S := Current_Scope;
4431 while Present (S) and then S /= Pref_Encl_Typ loop
4432 if Scope (S) = Pref_Encl_Typ then
4433 E := First_Entity (Pref_Encl_Typ);
4434 while Present (E)
4435 and then E /= First_Private_Entity (Pref_Encl_Typ)
4436 loop
4437 if E = S then
4438 return True;
4439 end if;
4440
4441 Next_Entity (E);
4442 end loop;
4443 end if;
4444
4445 S := Scope (S);
4446 end loop;
4447
4448 return False;
4449 end Is_Public_Operation;
4450
4451 -- Start of processing for Check_Unprotected_Access
4452
4453 begin
4454 if Nkind (Expr) = N_Attribute_Reference
4455 and then Attribute_Name (Expr) = Name_Unchecked_Access
4456 then
4457 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
4458 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
4459
4460 -- Check whether we are trying to export a protected component to a
4461 -- context with an equal or lower access level.
4462
4463 if Present (Pref_Encl_Typ)
4464 and then No (Cont_Encl_Typ)
4465 and then Is_Public_Operation
4466 and then Scope_Depth (Pref_Encl_Typ) >=
4467 Object_Access_Level (Context)
4468 then
4469 Error_Msg_N
4470 ("??possible unprotected access to protected data", Expr);
4471 end if;
4472 end if;
4473 end Check_Unprotected_Access;
4474
4475 ------------------------------
4476 -- Check_Unused_Body_States --
4477 ------------------------------
4478
4479 procedure Check_Unused_Body_States (Body_Id : Entity_Id) is
4480 procedure Process_Refinement_Clause
4481 (Clause : Node_Id;
4482 States : Elist_Id);
4483 -- Inspect all constituents of refinement clause Clause and remove any
4484 -- matches from body state list States.
4485
4486 procedure Report_Unused_Body_States (States : Elist_Id);
4487 -- Emit errors for each abstract state or object found in list States
4488
4489 -------------------------------
4490 -- Process_Refinement_Clause --
4491 -------------------------------
4492
4493 procedure Process_Refinement_Clause
4494 (Clause : Node_Id;
4495 States : Elist_Id)
4496 is
4497 procedure Process_Constituent (Constit : Node_Id);
4498 -- Remove constituent Constit from body state list States
4499
4500 -------------------------
4501 -- Process_Constituent --
4502 -------------------------
4503
4504 procedure Process_Constituent (Constit : Node_Id) is
4505 Constit_Id : Entity_Id;
4506
4507 begin
4508 -- Guard against illegal constituents. Only abstract states and
4509 -- objects can appear on the right hand side of a refinement.
4510
4511 if Is_Entity_Name (Constit) then
4512 Constit_Id := Entity_Of (Constit);
4513
4514 if Present (Constit_Id)
4515 and then Ekind_In (Constit_Id, E_Abstract_State,
4516 E_Constant,
4517 E_Variable)
4518 then
4519 Remove (States, Constit_Id);
4520 end if;
4521 end if;
4522 end Process_Constituent;
4523
4524 -- Local variables
4525
4526 Constit : Node_Id;
4527
4528 -- Start of processing for Process_Refinement_Clause
4529
4530 begin
4531 if Nkind (Clause) = N_Component_Association then
4532 Constit := Expression (Clause);
4533
4534 -- Multiple constituents appear as an aggregate
4535
4536 if Nkind (Constit) = N_Aggregate then
4537 Constit := First (Expressions (Constit));
4538 while Present (Constit) loop
4539 Process_Constituent (Constit);
4540 Next (Constit);
4541 end loop;
4542
4543 -- Various forms of a single constituent
4544
4545 else
4546 Process_Constituent (Constit);
4547 end if;
4548 end if;
4549 end Process_Refinement_Clause;
4550
4551 -------------------------------
4552 -- Report_Unused_Body_States --
4553 -------------------------------
4554
4555 procedure Report_Unused_Body_States (States : Elist_Id) is
4556 Posted : Boolean := False;
4557 State_Elmt : Elmt_Id;
4558 State_Id : Entity_Id;
4559
4560 begin
4561 if Present (States) then
4562 State_Elmt := First_Elmt (States);
4563 while Present (State_Elmt) loop
4564 State_Id := Node (State_Elmt);
4565
4566 -- Constants are part of the hidden state of a package, but the
4567 -- compiler cannot determine whether they have variable input
4568 -- (SPARK RM 7.1.1(2)) and cannot classify them properly as a
4569 -- hidden state. Do not emit an error when a constant does not
4570 -- participate in a state refinement, even though it acts as a
4571 -- hidden state.
4572
4573 if Ekind (State_Id) = E_Constant then
4574 null;
4575
4576 -- Generate an error message of the form:
4577
4578 -- body of package ... has unused hidden states
4579 -- abstract state ... defined at ...
4580 -- variable ... defined at ...
4581
4582 else
4583 if not Posted then
4584 Posted := True;
4585 SPARK_Msg_N
4586 ("body of package & has unused hidden states", Body_Id);
4587 end if;
4588
4589 Error_Msg_Sloc := Sloc (State_Id);
4590
4591 if Ekind (State_Id) = E_Abstract_State then
4592 SPARK_Msg_NE
4593 ("\abstract state & defined #", Body_Id, State_Id);
4594
4595 else
4596 SPARK_Msg_NE ("\variable & defined #", Body_Id, State_Id);
4597 end if;
4598 end if;
4599
4600 Next_Elmt (State_Elmt);
4601 end loop;
4602 end if;
4603 end Report_Unused_Body_States;
4604
4605 -- Local variables
4606
4607 Prag : constant Node_Id := Get_Pragma (Body_Id, Pragma_Refined_State);
4608 Spec_Id : constant Entity_Id := Spec_Entity (Body_Id);
4609 Clause : Node_Id;
4610 States : Elist_Id;
4611
4612 -- Start of processing for Check_Unused_Body_States
4613
4614 begin
4615 -- Inspect the clauses of pragma Refined_State and determine whether all
4616 -- visible states declared within the package body participate in the
4617 -- refinement.
4618
4619 if Present (Prag) then
4620 Clause := Expression (Get_Argument (Prag, Spec_Id));
4621 States := Collect_Body_States (Body_Id);
4622
4623 -- Multiple non-null state refinements appear as an aggregate
4624
4625 if Nkind (Clause) = N_Aggregate then
4626 Clause := First (Component_Associations (Clause));
4627 while Present (Clause) loop
4628 Process_Refinement_Clause (Clause, States);
4629 Next (Clause);
4630 end loop;
4631
4632 -- Various forms of a single state refinement
4633
4634 else
4635 Process_Refinement_Clause (Clause, States);
4636 end if;
4637
4638 -- Ensure that all abstract states and objects declared in the
4639 -- package body state space are utilized as constituents.
4640
4641 Report_Unused_Body_States (States);
4642 end if;
4643 end Check_Unused_Body_States;
4644
4645 -----------------
4646 -- Choice_List --
4647 -----------------
4648
4649 function Choice_List (N : Node_Id) return List_Id is
4650 begin
4651 if Nkind (N) = N_Iterated_Component_Association then
4652 return Discrete_Choices (N);
4653 else
4654 return Choices (N);
4655 end if;
4656 end Choice_List;
4657
4658 -------------------------
4659 -- Collect_Body_States --
4660 -------------------------
4661
4662 function Collect_Body_States (Body_Id : Entity_Id) return Elist_Id is
4663 function Is_Visible_Object (Obj_Id : Entity_Id) return Boolean;
4664 -- Determine whether object Obj_Id is a suitable visible state of a
4665 -- package body.
4666
4667 procedure Collect_Visible_States
4668 (Pack_Id : Entity_Id;
4669 States : in out Elist_Id);
4670 -- Gather the entities of all abstract states and objects declared in
4671 -- the visible state space of package Pack_Id.
4672
4673 ----------------------------
4674 -- Collect_Visible_States --
4675 ----------------------------
4676
4677 procedure Collect_Visible_States
4678 (Pack_Id : Entity_Id;
4679 States : in out Elist_Id)
4680 is
4681 Item_Id : Entity_Id;
4682
4683 begin
4684 -- Traverse the entity chain of the package and inspect all visible
4685 -- items.
4686
4687 Item_Id := First_Entity (Pack_Id);
4688 while Present (Item_Id) and then not In_Private_Part (Item_Id) loop
4689
4690 -- Do not consider internally generated items as those cannot be
4691 -- named and participate in refinement.
4692
4693 if not Comes_From_Source (Item_Id) then
4694 null;
4695
4696 elsif Ekind (Item_Id) = E_Abstract_State then
4697 Append_New_Elmt (Item_Id, States);
4698
4699 elsif Ekind_In (Item_Id, E_Constant, E_Variable)
4700 and then Is_Visible_Object (Item_Id)
4701 then
4702 Append_New_Elmt (Item_Id, States);
4703
4704 -- Recursively gather the visible states of a nested package
4705
4706 elsif Ekind (Item_Id) = E_Package then
4707 Collect_Visible_States (Item_Id, States);
4708 end if;
4709
4710 Next_Entity (Item_Id);
4711 end loop;
4712 end Collect_Visible_States;
4713
4714 -----------------------
4715 -- Is_Visible_Object --
4716 -----------------------
4717
4718 function Is_Visible_Object (Obj_Id : Entity_Id) return Boolean is
4719 begin
4720 -- Objects that map generic formals to their actuals are not visible
4721 -- from outside the generic instantiation.
4722
4723 if Present (Corresponding_Generic_Association
4724 (Declaration_Node (Obj_Id)))
4725 then
4726 return False;
4727
4728 -- Constituents of a single protected/task type act as components of
4729 -- the type and are not visible from outside the type.
4730
4731 elsif Ekind (Obj_Id) = E_Variable
4732 and then Present (Encapsulating_State (Obj_Id))
4733 and then Is_Single_Concurrent_Object (Encapsulating_State (Obj_Id))
4734 then
4735 return False;
4736
4737 else
4738 return True;
4739 end if;
4740 end Is_Visible_Object;
4741
4742 -- Local variables
4743
4744 Body_Decl : constant Node_Id := Unit_Declaration_Node (Body_Id);
4745 Decl : Node_Id;
4746 Item_Id : Entity_Id;
4747 States : Elist_Id := No_Elist;
4748
4749 -- Start of processing for Collect_Body_States
4750
4751 begin
4752 -- Inspect the declarations of the body looking for source objects,
4753 -- packages and package instantiations. Note that even though this
4754 -- processing is very similar to Collect_Visible_States, a package
4755 -- body does not have a First/Next_Entity list.
4756
4757 Decl := First (Declarations (Body_Decl));
4758 while Present (Decl) loop
4759
4760 -- Capture source objects as internally generated temporaries cannot
4761 -- be named and participate in refinement.
4762
4763 if Nkind (Decl) = N_Object_Declaration then
4764 Item_Id := Defining_Entity (Decl);
4765
4766 if Comes_From_Source (Item_Id)
4767 and then Is_Visible_Object (Item_Id)
4768 then
4769 Append_New_Elmt (Item_Id, States);
4770 end if;
4771
4772 -- Capture the visible abstract states and objects of a source
4773 -- package [instantiation].
4774
4775 elsif Nkind (Decl) = N_Package_Declaration then
4776 Item_Id := Defining_Entity (Decl);
4777
4778 if Comes_From_Source (Item_Id) then
4779 Collect_Visible_States (Item_Id, States);
4780 end if;
4781 end if;
4782
4783 Next (Decl);
4784 end loop;
4785
4786 return States;
4787 end Collect_Body_States;
4788
4789 ------------------------
4790 -- Collect_Interfaces --
4791 ------------------------
4792
4793 procedure Collect_Interfaces
4794 (T : Entity_Id;
4795 Ifaces_List : out Elist_Id;
4796 Exclude_Parents : Boolean := False;
4797 Use_Full_View : Boolean := True)
4798 is
4799 procedure Collect (Typ : Entity_Id);
4800 -- Subsidiary subprogram used to traverse the whole list
4801 -- of directly and indirectly implemented interfaces
4802
4803 -------------
4804 -- Collect --
4805 -------------
4806
4807 procedure Collect (Typ : Entity_Id) is
4808 Ancestor : Entity_Id;
4809 Full_T : Entity_Id;
4810 Id : Node_Id;
4811 Iface : Entity_Id;
4812
4813 begin
4814 Full_T := Typ;
4815
4816 -- Handle private types and subtypes
4817
4818 if Use_Full_View
4819 and then Is_Private_Type (Typ)
4820 and then Present (Full_View (Typ))
4821 then
4822 Full_T := Full_View (Typ);
4823
4824 if Ekind (Full_T) = E_Record_Subtype then
4825 Full_T := Etype (Typ);
4826
4827 if Present (Full_View (Full_T)) then
4828 Full_T := Full_View (Full_T);
4829 end if;
4830 end if;
4831 end if;
4832
4833 -- Include the ancestor if we are generating the whole list of
4834 -- abstract interfaces.
4835
4836 if Etype (Full_T) /= Typ
4837
4838 -- Protect the frontend against wrong sources. For example:
4839
4840 -- package P is
4841 -- type A is tagged null record;
4842 -- type B is new A with private;
4843 -- type C is new A with private;
4844 -- private
4845 -- type B is new C with null record;
4846 -- type C is new B with null record;
4847 -- end P;
4848
4849 and then Etype (Full_T) /= T
4850 then
4851 Ancestor := Etype (Full_T);
4852 Collect (Ancestor);
4853
4854 if Is_Interface (Ancestor) and then not Exclude_Parents then
4855 Append_Unique_Elmt (Ancestor, Ifaces_List);
4856 end if;
4857 end if;
4858
4859 -- Traverse the graph of ancestor interfaces
4860
4861 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
4862 Id := First (Abstract_Interface_List (Full_T));
4863 while Present (Id) loop
4864 Iface := Etype (Id);
4865
4866 -- Protect against wrong uses. For example:
4867 -- type I is interface;
4868 -- type O is tagged null record;
4869 -- type Wrong is new I and O with null record; -- ERROR
4870
4871 if Is_Interface (Iface) then
4872 if Exclude_Parents
4873 and then Etype (T) /= T
4874 and then Interface_Present_In_Ancestor (Etype (T), Iface)
4875 then
4876 null;
4877 else
4878 Collect (Iface);
4879 Append_Unique_Elmt (Iface, Ifaces_List);
4880 end if;
4881 end if;
4882
4883 Next (Id);
4884 end loop;
4885 end if;
4886 end Collect;
4887
4888 -- Start of processing for Collect_Interfaces
4889
4890 begin
4891 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
4892 Ifaces_List := New_Elmt_List;
4893 Collect (T);
4894 end Collect_Interfaces;
4895
4896 ----------------------------------
4897 -- Collect_Interface_Components --
4898 ----------------------------------
4899
4900 procedure Collect_Interface_Components
4901 (Tagged_Type : Entity_Id;
4902 Components_List : out Elist_Id)
4903 is
4904 procedure Collect (Typ : Entity_Id);
4905 -- Subsidiary subprogram used to climb to the parents
4906
4907 -------------
4908 -- Collect --
4909 -------------
4910
4911 procedure Collect (Typ : Entity_Id) is
4912 Tag_Comp : Entity_Id;
4913 Parent_Typ : Entity_Id;
4914
4915 begin
4916 -- Handle private types
4917
4918 if Present (Full_View (Etype (Typ))) then
4919 Parent_Typ := Full_View (Etype (Typ));
4920 else
4921 Parent_Typ := Etype (Typ);
4922 end if;
4923
4924 if Parent_Typ /= Typ
4925
4926 -- Protect the frontend against wrong sources. For example:
4927
4928 -- package P is
4929 -- type A is tagged null record;
4930 -- type B is new A with private;
4931 -- type C is new A with private;
4932 -- private
4933 -- type B is new C with null record;
4934 -- type C is new B with null record;
4935 -- end P;
4936
4937 and then Parent_Typ /= Tagged_Type
4938 then
4939 Collect (Parent_Typ);
4940 end if;
4941
4942 -- Collect the components containing tags of secondary dispatch
4943 -- tables.
4944
4945 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
4946 while Present (Tag_Comp) loop
4947 pragma Assert (Present (Related_Type (Tag_Comp)));
4948 Append_Elmt (Tag_Comp, Components_List);
4949
4950 Tag_Comp := Next_Tag_Component (Tag_Comp);
4951 end loop;
4952 end Collect;
4953
4954 -- Start of processing for Collect_Interface_Components
4955
4956 begin
4957 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
4958 and then Is_Tagged_Type (Tagged_Type));
4959
4960 Components_List := New_Elmt_List;
4961 Collect (Tagged_Type);
4962 end Collect_Interface_Components;
4963
4964 -----------------------------
4965 -- Collect_Interfaces_Info --
4966 -----------------------------
4967
4968 procedure Collect_Interfaces_Info
4969 (T : Entity_Id;
4970 Ifaces_List : out Elist_Id;
4971 Components_List : out Elist_Id;
4972 Tags_List : out Elist_Id)
4973 is
4974 Comps_List : Elist_Id;
4975 Comp_Elmt : Elmt_Id;
4976 Comp_Iface : Entity_Id;
4977 Iface_Elmt : Elmt_Id;
4978 Iface : Entity_Id;
4979
4980 function Search_Tag (Iface : Entity_Id) return Entity_Id;
4981 -- Search for the secondary tag associated with the interface type
4982 -- Iface that is implemented by T.
4983
4984 ----------------
4985 -- Search_Tag --
4986 ----------------
4987
4988 function Search_Tag (Iface : Entity_Id) return Entity_Id is
4989 ADT : Elmt_Id;
4990 begin
4991 if not Is_CPP_Class (T) then
4992 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
4993 else
4994 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
4995 end if;
4996
4997 while Present (ADT)
4998 and then Is_Tag (Node (ADT))
4999 and then Related_Type (Node (ADT)) /= Iface
5000 loop
5001 -- Skip secondary dispatch table referencing thunks to user
5002 -- defined primitives covered by this interface.
5003
5004 pragma Assert (Has_Suffix (Node (ADT), 'P'));
5005 Next_Elmt (ADT);
5006
5007 -- Skip secondary dispatch tables of Ada types
5008
5009 if not Is_CPP_Class (T) then
5010
5011 -- Skip secondary dispatch table referencing thunks to
5012 -- predefined primitives.
5013
5014 pragma Assert (Has_Suffix (Node (ADT), 'Y'));
5015 Next_Elmt (ADT);
5016
5017 -- Skip secondary dispatch table referencing user-defined
5018 -- primitives covered by this interface.
5019
5020 pragma Assert (Has_Suffix (Node (ADT), 'D'));
5021 Next_Elmt (ADT);
5022
5023 -- Skip secondary dispatch table referencing predefined
5024 -- primitives.
5025
5026 pragma Assert (Has_Suffix (Node (ADT), 'Z'));
5027 Next_Elmt (ADT);
5028 end if;
5029 end loop;
5030
5031 pragma Assert (Is_Tag (Node (ADT)));
5032 return Node (ADT);
5033 end Search_Tag;
5034
5035 -- Start of processing for Collect_Interfaces_Info
5036
5037 begin
5038 Collect_Interfaces (T, Ifaces_List);
5039 Collect_Interface_Components (T, Comps_List);
5040
5041 -- Search for the record component and tag associated with each
5042 -- interface type of T.
5043
5044 Components_List := New_Elmt_List;
5045 Tags_List := New_Elmt_List;
5046
5047 Iface_Elmt := First_Elmt (Ifaces_List);
5048 while Present (Iface_Elmt) loop
5049 Iface := Node (Iface_Elmt);
5050
5051 -- Associate the primary tag component and the primary dispatch table
5052 -- with all the interfaces that are parents of T
5053
5054 if Is_Ancestor (Iface, T, Use_Full_View => True) then
5055 Append_Elmt (First_Tag_Component (T), Components_List);
5056 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
5057
5058 -- Otherwise search for the tag component and secondary dispatch
5059 -- table of Iface
5060
5061 else
5062 Comp_Elmt := First_Elmt (Comps_List);
5063 while Present (Comp_Elmt) loop
5064 Comp_Iface := Related_Type (Node (Comp_Elmt));
5065
5066 if Comp_Iface = Iface
5067 or else Is_Ancestor (Iface, Comp_Iface, Use_Full_View => True)
5068 then
5069 Append_Elmt (Node (Comp_Elmt), Components_List);
5070 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
5071 exit;
5072 end if;
5073
5074 Next_Elmt (Comp_Elmt);
5075 end loop;
5076 pragma Assert (Present (Comp_Elmt));
5077 end if;
5078
5079 Next_Elmt (Iface_Elmt);
5080 end loop;
5081 end Collect_Interfaces_Info;
5082
5083 ---------------------
5084 -- Collect_Parents --
5085 ---------------------
5086
5087 procedure Collect_Parents
5088 (T : Entity_Id;
5089 List : out Elist_Id;
5090 Use_Full_View : Boolean := True)
5091 is
5092 Current_Typ : Entity_Id := T;
5093 Parent_Typ : Entity_Id;
5094
5095 begin
5096 List := New_Elmt_List;
5097
5098 -- No action if the if the type has no parents
5099
5100 if T = Etype (T) then
5101 return;
5102 end if;
5103
5104 loop
5105 Parent_Typ := Etype (Current_Typ);
5106
5107 if Is_Private_Type (Parent_Typ)
5108 and then Present (Full_View (Parent_Typ))
5109 and then Use_Full_View
5110 then
5111 Parent_Typ := Full_View (Base_Type (Parent_Typ));
5112 end if;
5113
5114 Append_Elmt (Parent_Typ, List);
5115
5116 exit when Parent_Typ = Current_Typ;
5117 Current_Typ := Parent_Typ;
5118 end loop;
5119 end Collect_Parents;
5120
5121 ----------------------------------
5122 -- Collect_Primitive_Operations --
5123 ----------------------------------
5124
5125 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
5126 B_Type : constant Entity_Id := Base_Type (T);
5127
5128 function Match (E : Entity_Id) return Boolean;
5129 -- True if E's base type is B_Type, or E is of an anonymous access type
5130 -- and the base type of its designated type is B_Type.
5131
5132 -----------
5133 -- Match --
5134 -----------
5135
5136 function Match (E : Entity_Id) return Boolean is
5137 Etyp : Entity_Id := Etype (E);
5138
5139 begin
5140 if Ekind (Etyp) = E_Anonymous_Access_Type then
5141 Etyp := Designated_Type (Etyp);
5142 end if;
5143
5144 -- In Ada 2012 a primitive operation may have a formal of an
5145 -- incomplete view of the parent type.
5146
5147 return Base_Type (Etyp) = B_Type
5148 or else
5149 (Ada_Version >= Ada_2012
5150 and then Ekind (Etyp) = E_Incomplete_Type
5151 and then Full_View (Etyp) = B_Type);
5152 end Match;
5153
5154 -- Local variables
5155
5156 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
5157 B_Scope : Entity_Id := Scope (B_Type);
5158 Op_List : Elist_Id;
5159 Eq_Prims_List : Elist_Id := No_Elist;
5160 Formal : Entity_Id;
5161 Is_Prim : Boolean;
5162 Is_Type_In_Pkg : Boolean;
5163 Formal_Derived : Boolean := False;
5164 Id : Entity_Id;
5165
5166 -- Start of processing for Collect_Primitive_Operations
5167
5168 begin
5169 -- For tagged types, the primitive operations are collected as they
5170 -- are declared, and held in an explicit list which is simply returned.
5171
5172 if Is_Tagged_Type (B_Type) then
5173 return Primitive_Operations (B_Type);
5174
5175 -- An untagged generic type that is a derived type inherits the
5176 -- primitive operations of its parent type. Other formal types only
5177 -- have predefined operators, which are not explicitly represented.
5178
5179 elsif Is_Generic_Type (B_Type) then
5180 if Nkind (B_Decl) = N_Formal_Type_Declaration
5181 and then Nkind (Formal_Type_Definition (B_Decl)) =
5182 N_Formal_Derived_Type_Definition
5183 then
5184 Formal_Derived := True;
5185 else
5186 return New_Elmt_List;
5187 end if;
5188 end if;
5189
5190 Op_List := New_Elmt_List;
5191
5192 if B_Scope = Standard_Standard then
5193 if B_Type = Standard_String then
5194 Append_Elmt (Standard_Op_Concat, Op_List);
5195
5196 elsif B_Type = Standard_Wide_String then
5197 Append_Elmt (Standard_Op_Concatw, Op_List);
5198
5199 else
5200 null;
5201 end if;
5202
5203 -- Locate the primitive subprograms of the type
5204
5205 else
5206 -- The primitive operations appear after the base type, except if the
5207 -- derivation happens within the private part of B_Scope and the type
5208 -- is a private type, in which case both the type and some primitive
5209 -- operations may appear before the base type, and the list of
5210 -- candidates starts after the type.
5211
5212 if In_Open_Scopes (B_Scope)
5213 and then Scope (T) = B_Scope
5214 and then In_Private_Part (B_Scope)
5215 then
5216 Id := Next_Entity (T);
5217
5218 -- In Ada 2012, If the type has an incomplete partial view, there may
5219 -- be primitive operations declared before the full view, so we need
5220 -- to start scanning from the incomplete view, which is earlier on
5221 -- the entity chain.
5222
5223 elsif Nkind (Parent (B_Type)) = N_Full_Type_Declaration
5224 and then Present (Incomplete_View (Parent (B_Type)))
5225 then
5226 Id := Defining_Entity (Incomplete_View (Parent (B_Type)));
5227
5228 -- If T is a derived from a type with an incomplete view declared
5229 -- elsewhere, that incomplete view is irrelevant, we want the
5230 -- operations in the scope of T.
5231
5232 if Scope (Id) /= Scope (B_Type) then
5233 Id := Next_Entity (B_Type);
5234 end if;
5235
5236 else
5237 Id := Next_Entity (B_Type);
5238 end if;
5239
5240 -- Set flag if this is a type in a package spec
5241
5242 Is_Type_In_Pkg :=
5243 Is_Package_Or_Generic_Package (B_Scope)
5244 and then
5245 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
5246 N_Package_Body;
5247
5248 while Present (Id) loop
5249
5250 -- Test whether the result type or any of the parameter types of
5251 -- each subprogram following the type match that type when the
5252 -- type is declared in a package spec, is a derived type, or the
5253 -- subprogram is marked as primitive. (The Is_Primitive test is
5254 -- needed to find primitives of nonderived types in declarative
5255 -- parts that happen to override the predefined "=" operator.)
5256
5257 -- Note that generic formal subprograms are not considered to be
5258 -- primitive operations and thus are never inherited.
5259
5260 if Is_Overloadable (Id)
5261 and then (Is_Type_In_Pkg
5262 or else Is_Derived_Type (B_Type)
5263 or else Is_Primitive (Id))
5264 and then Nkind (Parent (Parent (Id)))
5265 not in N_Formal_Subprogram_Declaration
5266 then
5267 Is_Prim := False;
5268
5269 if Match (Id) then
5270 Is_Prim := True;
5271
5272 else
5273 Formal := First_Formal (Id);
5274 while Present (Formal) loop
5275 if Match (Formal) then
5276 Is_Prim := True;
5277 exit;
5278 end if;
5279
5280 Next_Formal (Formal);
5281 end loop;
5282 end if;
5283
5284 -- For a formal derived type, the only primitives are the ones
5285 -- inherited from the parent type. Operations appearing in the
5286 -- package declaration are not primitive for it.
5287
5288 if Is_Prim
5289 and then (not Formal_Derived or else Present (Alias (Id)))
5290 then
5291 -- In the special case of an equality operator aliased to
5292 -- an overriding dispatching equality belonging to the same
5293 -- type, we don't include it in the list of primitives.
5294 -- This avoids inheriting multiple equality operators when
5295 -- deriving from untagged private types whose full type is
5296 -- tagged, which can otherwise cause ambiguities. Note that
5297 -- this should only happen for this kind of untagged parent
5298 -- type, since normally dispatching operations are inherited
5299 -- using the type's Primitive_Operations list.
5300
5301 if Chars (Id) = Name_Op_Eq
5302 and then Is_Dispatching_Operation (Id)
5303 and then Present (Alias (Id))
5304 and then Present (Overridden_Operation (Alias (Id)))
5305 and then Base_Type (Etype (First_Entity (Id))) =
5306 Base_Type (Etype (First_Entity (Alias (Id))))
5307 then
5308 null;
5309
5310 -- Include the subprogram in the list of primitives
5311
5312 else
5313 Append_Elmt (Id, Op_List);
5314
5315 -- Save collected equality primitives for later filtering
5316 -- (if we are processing a private type for which we can
5317 -- collect several candidates).
5318
5319 if Inherits_From_Tagged_Full_View (T)
5320 and then Chars (Id) = Name_Op_Eq
5321 and then Etype (First_Formal (Id)) =
5322 Etype (Next_Formal (First_Formal (Id)))
5323 then
5324 if No (Eq_Prims_List) then
5325 Eq_Prims_List := New_Elmt_List;
5326 end if;
5327
5328 Append_Elmt (Id, Eq_Prims_List);
5329 end if;
5330 end if;
5331 end if;
5332 end if;
5333
5334 Next_Entity (Id);
5335
5336 -- For a type declared in System, some of its operations may
5337 -- appear in the target-specific extension to System.
5338
5339 if No (Id)
5340 and then B_Scope = RTU_Entity (System)
5341 and then Present_System_Aux
5342 then
5343 B_Scope := System_Aux_Id;
5344 Id := First_Entity (System_Aux_Id);
5345 end if;
5346 end loop;
5347
5348 -- Filter collected equality primitives
5349
5350 if Inherits_From_Tagged_Full_View (T)
5351 and then Present (Eq_Prims_List)
5352 then
5353 declare
5354 First : constant Elmt_Id := First_Elmt (Eq_Prims_List);
5355 Second : Elmt_Id;
5356
5357 begin
5358 pragma Assert (No (Next_Elmt (First))
5359 or else No (Next_Elmt (Next_Elmt (First))));
5360
5361 -- No action needed if we have collected a single equality
5362 -- primitive
5363
5364 if Present (Next_Elmt (First)) then
5365 Second := Next_Elmt (First);
5366
5367 if Is_Dispatching_Operation
5368 (Ultimate_Alias (Node (First)))
5369 then
5370 Remove (Op_List, Node (First));
5371
5372 elsif Is_Dispatching_Operation
5373 (Ultimate_Alias (Node (Second)))
5374 then
5375 Remove (Op_List, Node (Second));
5376
5377 else
5378 pragma Assert (False);
5379 raise Program_Error;
5380 end if;
5381 end if;
5382 end;
5383 end if;
5384 end if;
5385
5386 return Op_List;
5387 end Collect_Primitive_Operations;
5388
5389 -----------------------------------
5390 -- Compile_Time_Constraint_Error --
5391 -----------------------------------
5392
5393 function Compile_Time_Constraint_Error
5394 (N : Node_Id;
5395 Msg : String;
5396 Ent : Entity_Id := Empty;
5397 Loc : Source_Ptr := No_Location;
5398 Warn : Boolean := False;
5399 Extra_Msg : String := "") return Node_Id
5400 is
5401 Msgc : String (1 .. Msg'Length + 3);
5402 -- Copy of message, with room for possible ?? or << and ! at end
5403
5404 Msgl : Natural;
5405 Wmsg : Boolean;
5406 Eloc : Source_Ptr;
5407
5408 -- Start of processing for Compile_Time_Constraint_Error
5409
5410 begin
5411 -- If this is a warning, convert it into an error if we are in code
5412 -- subject to SPARK_Mode being set On, unless Warn is True to force a
5413 -- warning. The rationale is that a compile-time constraint error should
5414 -- lead to an error instead of a warning when SPARK_Mode is On, but in
5415 -- a few cases we prefer to issue a warning and generate both a suitable
5416 -- run-time error in GNAT and a suitable check message in GNATprove.
5417 -- Those cases are those that likely correspond to deactivated SPARK
5418 -- code, so that this kind of code can be compiled and analyzed instead
5419 -- of being rejected.
5420
5421 Error_Msg_Warn := Warn or SPARK_Mode /= On;
5422
5423 -- A static constraint error in an instance body is not a fatal error.
5424 -- we choose to inhibit the message altogether, because there is no
5425 -- obvious node (for now) on which to post it. On the other hand the
5426 -- offending node must be replaced with a constraint_error in any case.
5427
5428 -- No messages are generated if we already posted an error on this node
5429
5430 if not Error_Posted (N) then
5431 if Loc /= No_Location then
5432 Eloc := Loc;
5433 else
5434 Eloc := Sloc (N);
5435 end if;
5436
5437 -- Copy message to Msgc, converting any ? in the message into <
5438 -- instead, so that we have an error in GNATprove mode.
5439
5440 Msgl := Msg'Length;
5441
5442 for J in 1 .. Msgl loop
5443 if Msg (J) = '?' and then (J = 1 or else Msg (J - 1) /= ''') then
5444 Msgc (J) := '<';
5445 else
5446 Msgc (J) := Msg (J);
5447 end if;
5448 end loop;
5449
5450 -- Message is a warning, even in Ada 95 case
5451
5452 if Msg (Msg'Last) = '?' or else Msg (Msg'Last) = '<' then
5453 Wmsg := True;
5454
5455 -- In Ada 83, all messages are warnings. In the private part and the
5456 -- body of an instance, constraint_checks are only warnings. We also
5457 -- make this a warning if the Warn parameter is set.
5458
5459 elsif Warn
5460 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
5461 or else In_Instance_Not_Visible
5462 then
5463 Msgl := Msgl + 1;
5464 Msgc (Msgl) := '<';
5465 Msgl := Msgl + 1;
5466 Msgc (Msgl) := '<';
5467 Wmsg := True;
5468
5469 -- Otherwise we have a real error message (Ada 95 static case) and we
5470 -- make this an unconditional message. Note that in the warning case
5471 -- we do not make the message unconditional, it seems reasonable to
5472 -- delete messages like this (about exceptions that will be raised)
5473 -- in dead code.
5474
5475 else
5476 Wmsg := False;
5477 Msgl := Msgl + 1;
5478 Msgc (Msgl) := '!';
5479 end if;
5480
5481 -- One more test, skip the warning if the related expression is
5482 -- statically unevaluated, since we don't want to warn about what
5483 -- will happen when something is evaluated if it never will be
5484 -- evaluated.
5485
5486 if not Is_Statically_Unevaluated (N) then
5487 if Present (Ent) then
5488 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
5489 else
5490 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
5491 end if;
5492
5493 -- Emit any extra message as a continuation
5494
5495 if Extra_Msg /= "" then
5496 Error_Msg_N ('\' & Extra_Msg, N);
5497 end if;
5498
5499 if Wmsg then
5500
5501 -- Check whether the context is an Init_Proc
5502
5503 if Inside_Init_Proc then
5504 declare
5505 Conc_Typ : constant Entity_Id :=
5506 Corresponding_Concurrent_Type
5507 (Entity (Parameter_Type (First
5508 (Parameter_Specifications
5509 (Parent (Current_Scope))))));
5510
5511 begin
5512 -- Don't complain if the corresponding concurrent type
5513 -- doesn't come from source (i.e. a single task/protected
5514 -- object).
5515
5516 if Present (Conc_Typ)
5517 and then not Comes_From_Source (Conc_Typ)
5518 then
5519 Error_Msg_NEL
5520 ("\& [<<", N, Standard_Constraint_Error, Eloc);
5521
5522 else
5523 if GNATprove_Mode then
5524 Error_Msg_NEL
5525 ("\& would have been raised for objects of this "
5526 & "type", N, Standard_Constraint_Error, Eloc);
5527 else
5528 Error_Msg_NEL
5529 ("\& will be raised for objects of this type??",
5530 N, Standard_Constraint_Error, Eloc);
5531 end if;
5532 end if;
5533 end;
5534
5535 else
5536 Error_Msg_NEL ("\& [<<", N, Standard_Constraint_Error, Eloc);
5537 end if;
5538
5539 else
5540 Error_Msg ("\static expression fails Constraint_Check", Eloc);
5541 Set_Error_Posted (N);
5542 end if;
5543 end if;
5544 end if;
5545
5546 return N;
5547 end Compile_Time_Constraint_Error;
5548
5549 -----------------------
5550 -- Conditional_Delay --
5551 -----------------------
5552
5553 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
5554 begin
5555 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
5556 Set_Has_Delayed_Freeze (New_Ent);
5557 end if;
5558 end Conditional_Delay;
5559
5560 -------------------------
5561 -- Copy_Component_List --
5562 -------------------------
5563
5564 function Copy_Component_List
5565 (R_Typ : Entity_Id;
5566 Loc : Source_Ptr) return List_Id
5567 is
5568 Comp : Node_Id;
5569 Comps : constant List_Id := New_List;
5570
5571 begin
5572 Comp := First_Component (Underlying_Type (R_Typ));
5573 while Present (Comp) loop
5574 if Comes_From_Source (Comp) then
5575 declare
5576 Comp_Decl : constant Node_Id := Declaration_Node (Comp);
5577 begin
5578 Append_To (Comps,
5579 Make_Component_Declaration (Loc,
5580 Defining_Identifier =>
5581 Make_Defining_Identifier (Loc, Chars (Comp)),
5582 Component_Definition =>
5583 New_Copy_Tree
5584 (Component_Definition (Comp_Decl), New_Sloc => Loc)));
5585 end;
5586 end if;
5587
5588 Next_Component (Comp);
5589 end loop;
5590
5591 return Comps;
5592 end Copy_Component_List;
5593
5594 -------------------------
5595 -- Copy_Parameter_List --
5596 -------------------------
5597
5598 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
5599 Loc : constant Source_Ptr := Sloc (Subp_Id);
5600 Plist : List_Id;
5601 Formal : Entity_Id;
5602
5603 begin
5604 if No (First_Formal (Subp_Id)) then
5605 return No_List;
5606 else
5607 Plist := New_List;
5608 Formal := First_Formal (Subp_Id);
5609 while Present (Formal) loop
5610 Append_To (Plist,
5611 Make_Parameter_Specification (Loc,
5612 Defining_Identifier =>
5613 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)),
5614 In_Present => In_Present (Parent (Formal)),
5615 Out_Present => Out_Present (Parent (Formal)),
5616 Parameter_Type =>
5617 New_Occurrence_Of (Etype (Formal), Loc),
5618 Expression =>
5619 New_Copy_Tree (Expression (Parent (Formal)))));
5620
5621 Next_Formal (Formal);
5622 end loop;
5623 end if;
5624
5625 return Plist;
5626 end Copy_Parameter_List;
5627
5628 ----------------------------
5629 -- Copy_SPARK_Mode_Aspect --
5630 ----------------------------
5631
5632 procedure Copy_SPARK_Mode_Aspect (From : Node_Id; To : Node_Id) is
5633 pragma Assert (not Has_Aspects (To));
5634 Asp : Node_Id;
5635
5636 begin
5637 if Has_Aspects (From) then
5638 Asp := Find_Aspect (Defining_Entity (From), Aspect_SPARK_Mode);
5639
5640 if Present (Asp) then
5641 Set_Aspect_Specifications (To, New_List (New_Copy_Tree (Asp)));
5642 Set_Has_Aspects (To, True);
5643 end if;
5644 end if;
5645 end Copy_SPARK_Mode_Aspect;
5646
5647 --------------------------
5648 -- Copy_Subprogram_Spec --
5649 --------------------------
5650
5651 function Copy_Subprogram_Spec (Spec : Node_Id) return Node_Id is
5652 Def_Id : Node_Id;
5653 Formal_Spec : Node_Id;
5654 Result : Node_Id;
5655
5656 begin
5657 -- The structure of the original tree must be replicated without any
5658 -- alterations. Use New_Copy_Tree for this purpose.
5659
5660 Result := New_Copy_Tree (Spec);
5661
5662 -- However, the spec of a null procedure carries the corresponding null
5663 -- statement of the body (created by the parser), and this cannot be
5664 -- shared with the new subprogram spec.
5665
5666 if Nkind (Result) = N_Procedure_Specification then
5667 Set_Null_Statement (Result, Empty);
5668 end if;
5669
5670 -- Create a new entity for the defining unit name
5671
5672 Def_Id := Defining_Unit_Name (Result);
5673 Set_Defining_Unit_Name (Result,
5674 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
5675
5676 -- Create new entities for the formal parameters
5677
5678 if Present (Parameter_Specifications (Result)) then
5679 Formal_Spec := First (Parameter_Specifications (Result));
5680 while Present (Formal_Spec) loop
5681 Def_Id := Defining_Identifier (Formal_Spec);
5682 Set_Defining_Identifier (Formal_Spec,
5683 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
5684
5685 Next (Formal_Spec);
5686 end loop;
5687 end if;
5688
5689 return Result;
5690 end Copy_Subprogram_Spec;
5691
5692 --------------------------------
5693 -- Corresponding_Generic_Type --
5694 --------------------------------
5695
5696 function Corresponding_Generic_Type (T : Entity_Id) return Entity_Id is
5697 Inst : Entity_Id;
5698 Gen : Entity_Id;
5699 Typ : Entity_Id;
5700
5701 begin
5702 if not Is_Generic_Actual_Type (T) then
5703 return Any_Type;
5704
5705 -- If the actual is the actual of an enclosing instance, resolution
5706 -- was correct in the generic.
5707
5708 elsif Nkind (Parent (T)) = N_Subtype_Declaration
5709 and then Is_Entity_Name (Subtype_Indication (Parent (T)))
5710 and then
5711 Is_Generic_Actual_Type (Entity (Subtype_Indication (Parent (T))))
5712 then
5713 return Any_Type;
5714
5715 else
5716 Inst := Scope (T);
5717
5718 if Is_Wrapper_Package (Inst) then
5719 Inst := Related_Instance (Inst);
5720 end if;
5721
5722 Gen :=
5723 Generic_Parent
5724 (Specification (Unit_Declaration_Node (Inst)));
5725
5726 -- Generic actual has the same name as the corresponding formal
5727
5728 Typ := First_Entity (Gen);
5729 while Present (Typ) loop
5730 if Chars (Typ) = Chars (T) then
5731 return Typ;
5732 end if;
5733
5734 Next_Entity (Typ);
5735 end loop;
5736
5737 return Any_Type;
5738 end if;
5739 end Corresponding_Generic_Type;
5740
5741 --------------------
5742 -- Current_Entity --
5743 --------------------
5744
5745 -- The currently visible definition for a given identifier is the
5746 -- one most chained at the start of the visibility chain, i.e. the
5747 -- one that is referenced by the Node_Id value of the name of the
5748 -- given identifier.
5749
5750 function Current_Entity (N : Node_Id) return Entity_Id is
5751 begin
5752 return Get_Name_Entity_Id (Chars (N));
5753 end Current_Entity;
5754
5755 -----------------------------
5756 -- Current_Entity_In_Scope --
5757 -----------------------------
5758
5759 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
5760 E : Entity_Id;
5761 CS : constant Entity_Id := Current_Scope;
5762
5763 Transient_Case : constant Boolean := Scope_Is_Transient;
5764
5765 begin
5766 E := Get_Name_Entity_Id (Chars (N));
5767 while Present (E)
5768 and then Scope (E) /= CS
5769 and then (not Transient_Case or else Scope (E) /= Scope (CS))
5770 loop
5771 E := Homonym (E);
5772 end loop;
5773
5774 return E;
5775 end Current_Entity_In_Scope;
5776
5777 -------------------
5778 -- Current_Scope --
5779 -------------------
5780
5781 function Current_Scope return Entity_Id is
5782 begin
5783 if Scope_Stack.Last = -1 then
5784 return Standard_Standard;
5785 else
5786 declare
5787 C : constant Entity_Id :=
5788 Scope_Stack.Table (Scope_Stack.Last).Entity;
5789 begin
5790 if Present (C) then
5791 return C;
5792 else
5793 return Standard_Standard;
5794 end if;
5795 end;
5796 end if;
5797 end Current_Scope;
5798
5799 ----------------------------
5800 -- Current_Scope_No_Loops --
5801 ----------------------------
5802
5803 function Current_Scope_No_Loops return Entity_Id is
5804 S : Entity_Id;
5805
5806 begin
5807 -- Examine the scope stack starting from the current scope and skip any
5808 -- internally generated loops.
5809
5810 S := Current_Scope;
5811 while Present (S) and then S /= Standard_Standard loop
5812 if Ekind (S) = E_Loop and then not Comes_From_Source (S) then
5813 S := Scope (S);
5814 else
5815 exit;
5816 end if;
5817 end loop;
5818
5819 return S;
5820 end Current_Scope_No_Loops;
5821
5822 ------------------------
5823 -- Current_Subprogram --
5824 ------------------------
5825
5826 function Current_Subprogram return Entity_Id is
5827 Scop : constant Entity_Id := Current_Scope;
5828 begin
5829 if Is_Subprogram_Or_Generic_Subprogram (Scop) then
5830 return Scop;
5831 else
5832 return Enclosing_Subprogram (Scop);
5833 end if;
5834 end Current_Subprogram;
5835
5836 ----------------------------------
5837 -- Deepest_Type_Access_Level --
5838 ----------------------------------
5839
5840 function Deepest_Type_Access_Level (Typ : Entity_Id) return Uint is
5841 begin
5842 if Ekind (Typ) = E_Anonymous_Access_Type
5843 and then not Is_Local_Anonymous_Access (Typ)
5844 and then Nkind (Associated_Node_For_Itype (Typ)) = N_Object_Declaration
5845 then
5846 -- Typ is the type of an Ada 2012 stand-alone object of an anonymous
5847 -- access type.
5848
5849 return
5850 Scope_Depth (Enclosing_Dynamic_Scope
5851 (Defining_Identifier
5852 (Associated_Node_For_Itype (Typ))));
5853
5854 -- For generic formal type, return Int'Last (infinite).
5855 -- See comment preceding Is_Generic_Type call in Type_Access_Level.
5856
5857 elsif Is_Generic_Type (Root_Type (Typ)) then
5858 return UI_From_Int (Int'Last);
5859
5860 else
5861 return Type_Access_Level (Typ);
5862 end if;
5863 end Deepest_Type_Access_Level;
5864
5865 ---------------------
5866 -- Defining_Entity --
5867 ---------------------
5868
5869 function Defining_Entity
5870 (N : Node_Id;
5871 Empty_On_Errors : Boolean := False;
5872 Concurrent_Subunit : Boolean := False) return Entity_Id
5873 is
5874 begin
5875 case Nkind (N) is
5876 when N_Abstract_Subprogram_Declaration
5877 | N_Expression_Function
5878 | N_Formal_Subprogram_Declaration
5879 | N_Generic_Package_Declaration
5880 | N_Generic_Subprogram_Declaration
5881 | N_Package_Declaration
5882 | N_Subprogram_Body
5883 | N_Subprogram_Body_Stub
5884 | N_Subprogram_Declaration
5885 | N_Subprogram_Renaming_Declaration
5886 =>
5887 return Defining_Entity (Specification (N));
5888
5889 when N_Component_Declaration
5890 | N_Defining_Program_Unit_Name
5891 | N_Discriminant_Specification
5892 | N_Entry_Body
5893 | N_Entry_Declaration
5894 | N_Entry_Index_Specification
5895 | N_Exception_Declaration
5896 | N_Exception_Renaming_Declaration
5897 | N_Formal_Object_Declaration
5898 | N_Formal_Package_Declaration
5899 | N_Formal_Type_Declaration
5900 | N_Full_Type_Declaration
5901 | N_Implicit_Label_Declaration
5902 | N_Incomplete_Type_Declaration
5903 | N_Iterator_Specification
5904 | N_Loop_Parameter_Specification
5905 | N_Number_Declaration
5906 | N_Object_Declaration
5907 | N_Object_Renaming_Declaration
5908 | N_Package_Body_Stub
5909 | N_Parameter_Specification
5910 | N_Private_Extension_Declaration
5911 | N_Private_Type_Declaration
5912 | N_Protected_Body
5913 | N_Protected_Body_Stub
5914 | N_Protected_Type_Declaration
5915 | N_Single_Protected_Declaration
5916 | N_Single_Task_Declaration
5917 | N_Subtype_Declaration
5918 | N_Task_Body
5919 | N_Task_Body_Stub
5920 | N_Task_Type_Declaration
5921 =>
5922 return Defining_Identifier (N);
5923
5924 when N_Subunit =>
5925 declare
5926 Bod : constant Node_Id := Proper_Body (N);
5927 Orig_Bod : constant Node_Id := Original_Node (Bod);
5928
5929 begin
5930 -- Retrieve the entity of the original protected or task body
5931 -- if requested by the caller.
5932
5933 if Concurrent_Subunit
5934 and then Nkind (Bod) = N_Null_Statement
5935 and then Nkind_In (Orig_Bod, N_Protected_Body, N_Task_Body)
5936 then
5937 return Defining_Entity (Orig_Bod);
5938 else
5939 return Defining_Entity (Bod);
5940 end if;
5941 end;
5942
5943 when N_Function_Instantiation
5944 | N_Function_Specification
5945 | N_Generic_Function_Renaming_Declaration
5946 | N_Generic_Package_Renaming_Declaration
5947 | N_Generic_Procedure_Renaming_Declaration
5948 | N_Package_Body
5949 | N_Package_Instantiation
5950 | N_Package_Renaming_Declaration
5951 | N_Package_Specification
5952 | N_Procedure_Instantiation
5953 | N_Procedure_Specification
5954 =>
5955 declare
5956 Nam : constant Node_Id := Defining_Unit_Name (N);
5957 Err : Entity_Id := Empty;
5958
5959 begin
5960 if Nkind (Nam) in N_Entity then
5961 return Nam;
5962
5963 -- For Error, make up a name and attach to declaration so we
5964 -- can continue semantic analysis.
5965
5966 elsif Nam = Error then
5967 if Empty_On_Errors then
5968 return Empty;
5969 else
5970 Err := Make_Temporary (Sloc (N), 'T');
5971 Set_Defining_Unit_Name (N, Err);
5972
5973 return Err;
5974 end if;
5975
5976 -- If not an entity, get defining identifier
5977
5978 else
5979 return Defining_Identifier (Nam);
5980 end if;
5981 end;
5982
5983 when N_Block_Statement
5984 | N_Loop_Statement
5985 =>
5986 return Entity (Identifier (N));
5987
5988 when others =>
5989 if Empty_On_Errors then
5990 return Empty;
5991 else
5992 raise Program_Error;
5993 end if;
5994 end case;
5995 end Defining_Entity;
5996
5997 --------------------------
5998 -- Denotes_Discriminant --
5999 --------------------------
6000
6001 function Denotes_Discriminant
6002 (N : Node_Id;
6003 Check_Concurrent : Boolean := False) return Boolean
6004 is
6005 E : Entity_Id;
6006
6007 begin
6008 if not Is_Entity_Name (N) or else No (Entity (N)) then
6009 return False;
6010 else
6011 E := Entity (N);
6012 end if;
6013
6014 -- If we are checking for a protected type, the discriminant may have
6015 -- been rewritten as the corresponding discriminal of the original type
6016 -- or of the corresponding concurrent record, depending on whether we
6017 -- are in the spec or body of the protected type.
6018
6019 return Ekind (E) = E_Discriminant
6020 or else
6021 (Check_Concurrent
6022 and then Ekind (E) = E_In_Parameter
6023 and then Present (Discriminal_Link (E))
6024 and then
6025 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
6026 or else
6027 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
6028 end Denotes_Discriminant;
6029
6030 -------------------------
6031 -- Denotes_Same_Object --
6032 -------------------------
6033
6034 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
6035 function Is_Renaming (N : Node_Id) return Boolean;
6036 -- Return true if N names a renaming entity
6037
6038 function Is_Valid_Renaming (N : Node_Id) return Boolean;
6039 -- For renamings, return False if the prefix of any dereference within
6040 -- the renamed object_name is a variable, or any expression within the
6041 -- renamed object_name contains references to variables or calls on
6042 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
6043
6044 -----------------
6045 -- Is_Renaming --
6046 -----------------
6047
6048 function Is_Renaming (N : Node_Id) return Boolean is
6049 begin
6050 return
6051 Is_Entity_Name (N) and then Present (Renamed_Entity (Entity (N)));
6052 end Is_Renaming;
6053
6054 -----------------------
6055 -- Is_Valid_Renaming --
6056 -----------------------
6057
6058 function Is_Valid_Renaming (N : Node_Id) return Boolean is
6059 function Check_Renaming (N : Node_Id) return Boolean;
6060 -- Recursive function used to traverse all the prefixes of N
6061
6062 --------------------
6063 -- Check_Renaming --
6064 --------------------
6065
6066 function Check_Renaming (N : Node_Id) return Boolean is
6067 begin
6068 if Is_Renaming (N)
6069 and then not Check_Renaming (Renamed_Entity (Entity (N)))
6070 then
6071 return False;
6072 end if;
6073
6074 if Nkind (N) = N_Indexed_Component then
6075 declare
6076 Indx : Node_Id;
6077
6078 begin
6079 Indx := First (Expressions (N));
6080 while Present (Indx) loop
6081 if not Is_OK_Static_Expression (Indx) then
6082 return False;
6083 end if;
6084
6085 Next_Index (Indx);
6086 end loop;
6087 end;
6088 end if;
6089
6090 if Has_Prefix (N) then
6091 declare
6092 P : constant Node_Id := Prefix (N);
6093
6094 begin
6095 if Nkind (N) = N_Explicit_Dereference
6096 and then Is_Variable (P)
6097 then
6098 return False;
6099
6100 elsif Is_Entity_Name (P)
6101 and then Ekind (Entity (P)) = E_Function
6102 then
6103 return False;
6104
6105 elsif Nkind (P) = N_Function_Call then
6106 return False;
6107 end if;
6108
6109 -- Recursion to continue traversing the prefix of the
6110 -- renaming expression
6111
6112 return Check_Renaming (P);
6113 end;
6114 end if;
6115
6116 return True;
6117 end Check_Renaming;
6118
6119 -- Start of processing for Is_Valid_Renaming
6120
6121 begin
6122 return Check_Renaming (N);
6123 end Is_Valid_Renaming;
6124
6125 -- Local variables
6126
6127 Obj1 : Node_Id := A1;
6128 Obj2 : Node_Id := A2;
6129
6130 -- Start of processing for Denotes_Same_Object
6131
6132 begin
6133 -- Both names statically denote the same stand-alone object or parameter
6134 -- (RM 6.4.1(6.5/3))
6135
6136 if Is_Entity_Name (Obj1)
6137 and then Is_Entity_Name (Obj2)
6138 and then Entity (Obj1) = Entity (Obj2)
6139 then
6140 return True;
6141 end if;
6142
6143 -- For renamings, the prefix of any dereference within the renamed
6144 -- object_name is not a variable, and any expression within the
6145 -- renamed object_name contains no references to variables nor
6146 -- calls on nonstatic functions (RM 6.4.1(6.10/3)).
6147
6148 if Is_Renaming (Obj1) then
6149 if Is_Valid_Renaming (Obj1) then
6150 Obj1 := Renamed_Entity (Entity (Obj1));
6151 else
6152 return False;
6153 end if;
6154 end if;
6155
6156 if Is_Renaming (Obj2) then
6157 if Is_Valid_Renaming (Obj2) then
6158 Obj2 := Renamed_Entity (Entity (Obj2));
6159 else
6160 return False;
6161 end if;
6162 end if;
6163
6164 -- No match if not same node kind (such cases are handled by
6165 -- Denotes_Same_Prefix)
6166
6167 if Nkind (Obj1) /= Nkind (Obj2) then
6168 return False;
6169
6170 -- After handling valid renamings, one of the two names statically
6171 -- denoted a renaming declaration whose renamed object_name is known
6172 -- to denote the same object as the other (RM 6.4.1(6.10/3))
6173
6174 elsif Is_Entity_Name (Obj1) then
6175 if Is_Entity_Name (Obj2) then
6176 return Entity (Obj1) = Entity (Obj2);
6177 else
6178 return False;
6179 end if;
6180
6181 -- Both names are selected_components, their prefixes are known to
6182 -- denote the same object, and their selector_names denote the same
6183 -- component (RM 6.4.1(6.6/3)).
6184
6185 elsif Nkind (Obj1) = N_Selected_Component then
6186 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
6187 and then
6188 Entity (Selector_Name (Obj1)) = Entity (Selector_Name (Obj2));
6189
6190 -- Both names are dereferences and the dereferenced names are known to
6191 -- denote the same object (RM 6.4.1(6.7/3))
6192
6193 elsif Nkind (Obj1) = N_Explicit_Dereference then
6194 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2));
6195
6196 -- Both names are indexed_components, their prefixes are known to denote
6197 -- the same object, and each of the pairs of corresponding index values
6198 -- are either both static expressions with the same static value or both
6199 -- names that are known to denote the same object (RM 6.4.1(6.8/3))
6200
6201 elsif Nkind (Obj1) = N_Indexed_Component then
6202 if not Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2)) then
6203 return False;
6204 else
6205 declare
6206 Indx1 : Node_Id;
6207 Indx2 : Node_Id;
6208
6209 begin
6210 Indx1 := First (Expressions (Obj1));
6211 Indx2 := First (Expressions (Obj2));
6212 while Present (Indx1) loop
6213
6214 -- Indexes must denote the same static value or same object
6215
6216 if Is_OK_Static_Expression (Indx1) then
6217 if not Is_OK_Static_Expression (Indx2) then
6218 return False;
6219
6220 elsif Expr_Value (Indx1) /= Expr_Value (Indx2) then
6221 return False;
6222 end if;
6223
6224 elsif not Denotes_Same_Object (Indx1, Indx2) then
6225 return False;
6226 end if;
6227
6228 Next (Indx1);
6229 Next (Indx2);
6230 end loop;
6231
6232 return True;
6233 end;
6234 end if;
6235
6236 -- Both names are slices, their prefixes are known to denote the same
6237 -- object, and the two slices have statically matching index constraints
6238 -- (RM 6.4.1(6.9/3))
6239
6240 elsif Nkind (Obj1) = N_Slice
6241 and then Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
6242 then
6243 declare
6244 Lo1, Lo2, Hi1, Hi2 : Node_Id;
6245
6246 begin
6247 Get_Index_Bounds (Etype (Obj1), Lo1, Hi1);
6248 Get_Index_Bounds (Etype (Obj2), Lo2, Hi2);
6249
6250 -- Check whether bounds are statically identical. There is no
6251 -- attempt to detect partial overlap of slices.
6252
6253 return Denotes_Same_Object (Lo1, Lo2)
6254 and then
6255 Denotes_Same_Object (Hi1, Hi2);
6256 end;
6257
6258 -- In the recursion, literals appear as indexes
6259
6260 elsif Nkind (Obj1) = N_Integer_Literal
6261 and then
6262 Nkind (Obj2) = N_Integer_Literal
6263 then
6264 return Intval (Obj1) = Intval (Obj2);
6265
6266 else
6267 return False;
6268 end if;
6269 end Denotes_Same_Object;
6270
6271 -------------------------
6272 -- Denotes_Same_Prefix --
6273 -------------------------
6274
6275 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
6276 begin
6277 if Is_Entity_Name (A1) then
6278 if Nkind_In (A2, N_Selected_Component, N_Indexed_Component)
6279 and then not Is_Access_Type (Etype (A1))
6280 then
6281 return Denotes_Same_Object (A1, Prefix (A2))
6282 or else Denotes_Same_Prefix (A1, Prefix (A2));
6283 else
6284 return False;
6285 end if;
6286
6287 elsif Is_Entity_Name (A2) then
6288 return Denotes_Same_Prefix (A1 => A2, A2 => A1);
6289
6290 elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
6291 and then
6292 Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
6293 then
6294 declare
6295 Root1, Root2 : Node_Id;
6296 Depth1, Depth2 : Nat := 0;
6297
6298 begin
6299 Root1 := Prefix (A1);
6300 while not Is_Entity_Name (Root1) loop
6301 if not Nkind_In
6302 (Root1, N_Selected_Component, N_Indexed_Component)
6303 then
6304 return False;
6305 else
6306 Root1 := Prefix (Root1);
6307 end if;
6308
6309 Depth1 := Depth1 + 1;
6310 end loop;
6311
6312 Root2 := Prefix (A2);
6313 while not Is_Entity_Name (Root2) loop
6314 if not Nkind_In (Root2, N_Selected_Component,
6315 N_Indexed_Component)
6316 then
6317 return False;
6318 else
6319 Root2 := Prefix (Root2);
6320 end if;
6321
6322 Depth2 := Depth2 + 1;
6323 end loop;
6324
6325 -- If both have the same depth and they do not denote the same
6326 -- object, they are disjoint and no warning is needed.
6327
6328 if Depth1 = Depth2 then
6329 return False;
6330
6331 elsif Depth1 > Depth2 then
6332 Root1 := Prefix (A1);
6333 for J in 1 .. Depth1 - Depth2 - 1 loop
6334 Root1 := Prefix (Root1);
6335 end loop;
6336
6337 return Denotes_Same_Object (Root1, A2);
6338
6339 else
6340 Root2 := Prefix (A2);
6341 for J in 1 .. Depth2 - Depth1 - 1 loop
6342 Root2 := Prefix (Root2);
6343 end loop;
6344
6345 return Denotes_Same_Object (A1, Root2);
6346 end if;
6347 end;
6348
6349 else
6350 return False;
6351 end if;
6352 end Denotes_Same_Prefix;
6353
6354 ----------------------
6355 -- Denotes_Variable --
6356 ----------------------
6357
6358 function Denotes_Variable (N : Node_Id) return Boolean is
6359 begin
6360 return Is_Variable (N) and then Paren_Count (N) = 0;
6361 end Denotes_Variable;
6362
6363 -----------------------------
6364 -- Depends_On_Discriminant --
6365 -----------------------------
6366
6367 function Depends_On_Discriminant (N : Node_Id) return Boolean is
6368 L : Node_Id;
6369 H : Node_Id;
6370
6371 begin
6372 Get_Index_Bounds (N, L, H);
6373 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
6374 end Depends_On_Discriminant;
6375
6376 -------------------------
6377 -- Designate_Same_Unit --
6378 -------------------------
6379
6380 function Designate_Same_Unit
6381 (Name1 : Node_Id;
6382 Name2 : Node_Id) return Boolean
6383 is
6384 K1 : constant Node_Kind := Nkind (Name1);
6385 K2 : constant Node_Kind := Nkind (Name2);
6386
6387 function Prefix_Node (N : Node_Id) return Node_Id;
6388 -- Returns the parent unit name node of a defining program unit name
6389 -- or the prefix if N is a selected component or an expanded name.
6390
6391 function Select_Node (N : Node_Id) return Node_Id;
6392 -- Returns the defining identifier node of a defining program unit
6393 -- name or the selector node if N is a selected component or an
6394 -- expanded name.
6395
6396 -----------------
6397 -- Prefix_Node --
6398 -----------------
6399
6400 function Prefix_Node (N : Node_Id) return Node_Id is
6401 begin
6402 if Nkind (N) = N_Defining_Program_Unit_Name then
6403 return Name (N);
6404 else
6405 return Prefix (N);
6406 end if;
6407 end Prefix_Node;
6408
6409 -----------------
6410 -- Select_Node --
6411 -----------------
6412
6413 function Select_Node (N : Node_Id) return Node_Id is
6414 begin
6415 if Nkind (N) = N_Defining_Program_Unit_Name then
6416 return Defining_Identifier (N);
6417 else
6418 return Selector_Name (N);
6419 end if;
6420 end Select_Node;
6421
6422 -- Start of processing for Designate_Same_Unit
6423
6424 begin
6425 if Nkind_In (K1, N_Identifier, N_Defining_Identifier)
6426 and then
6427 Nkind_In (K2, N_Identifier, N_Defining_Identifier)
6428 then
6429 return Chars (Name1) = Chars (Name2);
6430
6431 elsif Nkind_In (K1, N_Expanded_Name,
6432 N_Selected_Component,
6433 N_Defining_Program_Unit_Name)
6434 and then
6435 Nkind_In (K2, N_Expanded_Name,
6436 N_Selected_Component,
6437 N_Defining_Program_Unit_Name)
6438 then
6439 return
6440 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
6441 and then
6442 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
6443
6444 else
6445 return False;
6446 end if;
6447 end Designate_Same_Unit;
6448
6449 ---------------------------------------------
6450 -- Diagnose_Iterated_Component_Association --
6451 ---------------------------------------------
6452
6453 procedure Diagnose_Iterated_Component_Association (N : Node_Id) is
6454 Def_Id : constant Entity_Id := Defining_Identifier (N);
6455 Aggr : Node_Id;
6456
6457 begin
6458 -- Determine whether the iterated component association appears within
6459 -- an aggregate. If this is the case, raise Program_Error because the
6460 -- iterated component association cannot be left in the tree as is and
6461 -- must always be processed by the related aggregate.
6462
6463 Aggr := N;
6464 while Present (Aggr) loop
6465 if Nkind (Aggr) = N_Aggregate then
6466 raise Program_Error;
6467
6468 -- Prevent the search from going too far
6469
6470 elsif Is_Body_Or_Package_Declaration (Aggr) then
6471 exit;
6472 end if;
6473
6474 Aggr := Parent (Aggr);
6475 end loop;
6476
6477 -- At this point it is known that the iterated component association is
6478 -- not within an aggregate. This is really a quantified expression with
6479 -- a missing "all" or "some" quantifier.
6480
6481 Error_Msg_N ("missing quantifier", Def_Id);
6482
6483 -- Rewrite the iterated component association as True to prevent any
6484 -- cascaded errors.
6485
6486 Rewrite (N, New_Occurrence_Of (Standard_True, Sloc (N)));
6487 Analyze (N);
6488 end Diagnose_Iterated_Component_Association;
6489
6490 ---------------------------------
6491 -- Dynamic_Accessibility_Level --
6492 ---------------------------------
6493
6494 function Dynamic_Accessibility_Level (N : Node_Id) return Node_Id is
6495 Loc : constant Source_Ptr := Sloc (N);
6496
6497 function Make_Level_Literal (Level : Uint) return Node_Id;
6498 -- Construct an integer literal representing an accessibility level
6499 -- with its type set to Natural.
6500
6501 ------------------------
6502 -- Make_Level_Literal --
6503 ------------------------
6504
6505 function Make_Level_Literal (Level : Uint) return Node_Id is
6506 Result : constant Node_Id := Make_Integer_Literal (Loc, Level);
6507
6508 begin
6509 Set_Etype (Result, Standard_Natural);
6510 return Result;
6511 end Make_Level_Literal;
6512
6513 -- Local variables
6514
6515 Expr : constant Node_Id := Original_Node (N);
6516 -- Expr references the original node because at this stage N may be the
6517 -- reference to a variable internally created by the frontend to remove
6518 -- side effects of an expression.
6519
6520 E : Entity_Id;
6521
6522 -- Start of processing for Dynamic_Accessibility_Level
6523
6524 begin
6525 if Is_Entity_Name (Expr) then
6526 E := Entity (Expr);
6527
6528 if Present (Renamed_Object (E)) then
6529 return Dynamic_Accessibility_Level (Renamed_Object (E));
6530 end if;
6531
6532 if Is_Formal (E) or else Ekind_In (E, E_Variable, E_Constant) then
6533 if Present (Extra_Accessibility (E)) then
6534 return New_Occurrence_Of (Extra_Accessibility (E), Loc);
6535 end if;
6536 end if;
6537 end if;
6538
6539 -- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
6540
6541 case Nkind (Expr) is
6542
6543 -- For access discriminant, the level of the enclosing object
6544
6545 when N_Selected_Component =>
6546 if Ekind (Entity (Selector_Name (Expr))) = E_Discriminant
6547 and then Ekind (Etype (Entity (Selector_Name (Expr)))) =
6548 E_Anonymous_Access_Type
6549 then
6550 return Make_Level_Literal (Object_Access_Level (Expr));
6551 end if;
6552
6553 when N_Attribute_Reference =>
6554 case Get_Attribute_Id (Attribute_Name (Expr)) is
6555
6556 -- For X'Access, the level of the prefix X
6557
6558 when Attribute_Access =>
6559 return Make_Level_Literal
6560 (Object_Access_Level (Prefix (Expr)));
6561
6562 -- Treat the unchecked attributes as library-level
6563
6564 when Attribute_Unchecked_Access
6565 | Attribute_Unrestricted_Access
6566 =>
6567 return Make_Level_Literal (Scope_Depth (Standard_Standard));
6568
6569 -- No other access-valued attributes
6570
6571 when others =>
6572 raise Program_Error;
6573 end case;
6574
6575 when N_Allocator =>
6576
6577 -- This is not fully implemented since it depends on context (see
6578 -- 3.10.2(14/3-14.2/3). More work is needed in the following cases
6579 --
6580 -- 1) For an anonymous allocator defining the value of an access
6581 -- parameter, the accessibility level is that of the innermost
6582 -- master of the call; however currently we pass the level of
6583 -- execution of the called subprogram, which is one greater
6584 -- than the current scope level (see Expand_Call_Helper).
6585 --
6586 -- For example, a statement is a master and a declaration is
6587 -- not a master; so we should not pass in the same level for
6588 -- the following cases:
6589 --
6590 -- function F (X : access Integer) return T is ... ;
6591 -- Decl : T := F (new Integer); -- level is off by one
6592 -- begin
6593 -- Decl := F (new Integer); -- we get this case right
6594 --
6595 -- 2) For an anonymous allocator that defines the result of a
6596 -- function with an access result, the accessibility level is
6597 -- determined as though the allocator were in place of the call
6598 -- of the function. In the special case of a call that is the
6599 -- operand of a type conversion the level is that of the target
6600 -- access type of the conversion.
6601 --
6602 -- 3) For an anonymous allocator defining an access discriminant
6603 -- the accessibility level is determined as follows:
6604 -- * for an allocator used to define the discriminant of an
6605 -- object, the level of the object
6606 -- * for an allocator used to define the constraint in a
6607 -- subtype_indication in any other context, the level of
6608 -- the master that elaborates the subtype_indication.
6609
6610 case Nkind (Parent (N)) is
6611 when N_Object_Declaration =>
6612
6613 -- For an anonymous allocator whose type is that of a
6614 -- stand-alone object of an anonymous access-to-object type,
6615 -- the accessibility level is that of the declaration of the
6616 -- stand-alone object.
6617
6618 return
6619 Make_Level_Literal
6620 (Object_Access_Level
6621 (Defining_Identifier (Parent (N))));
6622
6623 when N_Assignment_Statement =>
6624 return
6625 Make_Level_Literal
6626 (Object_Access_Level (Name (Parent (N))));
6627
6628 when others =>
6629 declare
6630 S : constant String :=
6631 Node_Kind'Image (Nkind (Parent (N)));
6632 begin
6633 Error_Msg_Strlen := S'Length;
6634 Error_Msg_String (1 .. Error_Msg_Strlen) := S;
6635 Error_Msg_N
6636 ("unsupported context for anonymous allocator (~)",
6637 Parent (N));
6638 end;
6639 end case;
6640
6641 when N_Type_Conversion =>
6642 if not Is_Local_Anonymous_Access (Etype (Expr)) then
6643
6644 -- Handle type conversions introduced for a rename of an
6645 -- Ada 2012 stand-alone object of an anonymous access type.
6646
6647 return Dynamic_Accessibility_Level (Expression (Expr));
6648 end if;
6649
6650 when others =>
6651 null;
6652 end case;
6653
6654 return Make_Level_Literal (Type_Access_Level (Etype (Expr)));
6655 end Dynamic_Accessibility_Level;
6656
6657 ------------------------
6658 -- Discriminated_Size --
6659 ------------------------
6660
6661 function Discriminated_Size (Comp : Entity_Id) return Boolean is
6662 function Non_Static_Bound (Bound : Node_Id) return Boolean;
6663 -- Check whether the bound of an index is non-static and does denote
6664 -- a discriminant, in which case any object of the type (protected or
6665 -- otherwise) will have a non-static size.
6666
6667 ----------------------
6668 -- Non_Static_Bound --
6669 ----------------------
6670
6671 function Non_Static_Bound (Bound : Node_Id) return Boolean is
6672 begin
6673 if Is_OK_Static_Expression (Bound) then
6674 return False;
6675
6676 -- If the bound is given by a discriminant it is non-static
6677 -- (A static constraint replaces the reference with the value).
6678 -- In an protected object the discriminant has been replaced by
6679 -- the corresponding discriminal within the protected operation.
6680
6681 elsif Is_Entity_Name (Bound)
6682 and then
6683 (Ekind (Entity (Bound)) = E_Discriminant
6684 or else Present (Discriminal_Link (Entity (Bound))))
6685 then
6686 return False;
6687
6688 else
6689 return True;
6690 end if;
6691 end Non_Static_Bound;
6692
6693 -- Local variables
6694
6695 Typ : constant Entity_Id := Etype (Comp);
6696 Index : Node_Id;
6697
6698 -- Start of processing for Discriminated_Size
6699
6700 begin
6701 if not Is_Array_Type (Typ) then
6702 return False;
6703 end if;
6704
6705 if Ekind (Typ) = E_Array_Subtype then
6706 Index := First_Index (Typ);
6707 while Present (Index) loop
6708 if Non_Static_Bound (Low_Bound (Index))
6709 or else Non_Static_Bound (High_Bound (Index))
6710 then
6711 return False;
6712 end if;
6713
6714 Next_Index (Index);
6715 end loop;
6716
6717 return True;
6718 end if;
6719
6720 return False;
6721 end Discriminated_Size;
6722
6723 -----------------------------------
6724 -- Effective_Extra_Accessibility --
6725 -----------------------------------
6726
6727 function Effective_Extra_Accessibility (Id : Entity_Id) return Entity_Id is
6728 begin
6729 if Present (Renamed_Object (Id))
6730 and then Is_Entity_Name (Renamed_Object (Id))
6731 then
6732 return Effective_Extra_Accessibility (Entity (Renamed_Object (Id)));
6733 else
6734 return Extra_Accessibility (Id);
6735 end if;
6736 end Effective_Extra_Accessibility;
6737
6738 -----------------------------
6739 -- Effective_Reads_Enabled --
6740 -----------------------------
6741
6742 function Effective_Reads_Enabled (Id : Entity_Id) return Boolean is
6743 begin
6744 return Has_Enabled_Property (Id, Name_Effective_Reads);
6745 end Effective_Reads_Enabled;
6746
6747 ------------------------------
6748 -- Effective_Writes_Enabled --
6749 ------------------------------
6750
6751 function Effective_Writes_Enabled (Id : Entity_Id) return Boolean is
6752 begin
6753 return Has_Enabled_Property (Id, Name_Effective_Writes);
6754 end Effective_Writes_Enabled;
6755
6756 ------------------------------
6757 -- Enclosing_Comp_Unit_Node --
6758 ------------------------------
6759
6760 function Enclosing_Comp_Unit_Node (N : Node_Id) return Node_Id is
6761 Current_Node : Node_Id;
6762
6763 begin
6764 Current_Node := N;
6765 while Present (Current_Node)
6766 and then Nkind (Current_Node) /= N_Compilation_Unit
6767 loop
6768 Current_Node := Parent (Current_Node);
6769 end loop;
6770
6771 if Nkind (Current_Node) /= N_Compilation_Unit then
6772 return Empty;
6773 else
6774 return Current_Node;
6775 end if;
6776 end Enclosing_Comp_Unit_Node;
6777
6778 --------------------------
6779 -- Enclosing_CPP_Parent --
6780 --------------------------
6781
6782 function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is
6783 Parent_Typ : Entity_Id := Typ;
6784
6785 begin
6786 while not Is_CPP_Class (Parent_Typ)
6787 and then Etype (Parent_Typ) /= Parent_Typ
6788 loop
6789 Parent_Typ := Etype (Parent_Typ);
6790
6791 if Is_Private_Type (Parent_Typ) then
6792 Parent_Typ := Full_View (Base_Type (Parent_Typ));
6793 end if;
6794 end loop;
6795
6796 pragma Assert (Is_CPP_Class (Parent_Typ));
6797 return Parent_Typ;
6798 end Enclosing_CPP_Parent;
6799
6800 ---------------------------
6801 -- Enclosing_Declaration --
6802 ---------------------------
6803
6804 function Enclosing_Declaration (N : Node_Id) return Node_Id is
6805 Decl : Node_Id := N;
6806
6807 begin
6808 while Present (Decl)
6809 and then not (Nkind (Decl) in N_Declaration
6810 or else
6811 Nkind (Decl) in N_Later_Decl_Item
6812 or else
6813 Nkind (Decl) = N_Number_Declaration)
6814 loop
6815 Decl := Parent (Decl);
6816 end loop;
6817
6818 return Decl;
6819 end Enclosing_Declaration;
6820
6821 ----------------------------
6822 -- Enclosing_Generic_Body --
6823 ----------------------------
6824
6825 function Enclosing_Generic_Body (N : Node_Id) return Node_Id is
6826 Par : Node_Id;
6827 Spec_Id : Entity_Id;
6828
6829 begin
6830 Par := Parent (N);
6831 while Present (Par) loop
6832 if Nkind_In (Par, N_Package_Body, N_Subprogram_Body) then
6833 Spec_Id := Corresponding_Spec (Par);
6834
6835 if Present (Spec_Id)
6836 and then Nkind_In (Unit_Declaration_Node (Spec_Id),
6837 N_Generic_Package_Declaration,
6838 N_Generic_Subprogram_Declaration)
6839 then
6840 return Par;
6841 end if;
6842 end if;
6843
6844 Par := Parent (Par);
6845 end loop;
6846
6847 return Empty;
6848 end Enclosing_Generic_Body;
6849
6850 ----------------------------
6851 -- Enclosing_Generic_Unit --
6852 ----------------------------
6853
6854 function Enclosing_Generic_Unit (N : Node_Id) return Node_Id is
6855 Par : Node_Id;
6856 Spec_Decl : Node_Id;
6857 Spec_Id : Entity_Id;
6858
6859 begin
6860 Par := Parent (N);
6861 while Present (Par) loop
6862 if Nkind_In (Par, N_Generic_Package_Declaration,
6863 N_Generic_Subprogram_Declaration)
6864 then
6865 return Par;
6866
6867 elsif Nkind_In (Par, N_Package_Body, N_Subprogram_Body) then
6868 Spec_Id := Corresponding_Spec (Par);
6869
6870 if Present (Spec_Id) then
6871 Spec_Decl := Unit_Declaration_Node (Spec_Id);
6872
6873 if Nkind_In (Spec_Decl, N_Generic_Package_Declaration,
6874 N_Generic_Subprogram_Declaration)
6875 then
6876 return Spec_Decl;
6877 end if;
6878 end if;
6879 end if;
6880
6881 Par := Parent (Par);
6882 end loop;
6883
6884 return Empty;
6885 end Enclosing_Generic_Unit;
6886
6887 -------------------------------
6888 -- Enclosing_Lib_Unit_Entity --
6889 -------------------------------
6890
6891 function Enclosing_Lib_Unit_Entity
6892 (E : Entity_Id := Current_Scope) return Entity_Id
6893 is
6894 Unit_Entity : Entity_Id;
6895
6896 begin
6897 -- Look for enclosing library unit entity by following scope links.
6898 -- Equivalent to, but faster than indexing through the scope stack.
6899
6900 Unit_Entity := E;
6901 while (Present (Scope (Unit_Entity))
6902 and then Scope (Unit_Entity) /= Standard_Standard)
6903 and not Is_Child_Unit (Unit_Entity)
6904 loop
6905 Unit_Entity := Scope (Unit_Entity);
6906 end loop;
6907
6908 return Unit_Entity;
6909 end Enclosing_Lib_Unit_Entity;
6910
6911 -----------------------------
6912 -- Enclosing_Lib_Unit_Node --
6913 -----------------------------
6914
6915 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
6916 Encl_Unit : Node_Id;
6917
6918 begin
6919 Encl_Unit := Enclosing_Comp_Unit_Node (N);
6920 while Present (Encl_Unit)
6921 and then Nkind (Unit (Encl_Unit)) = N_Subunit
6922 loop
6923 Encl_Unit := Library_Unit (Encl_Unit);
6924 end loop;
6925
6926 pragma Assert (Nkind (Encl_Unit) = N_Compilation_Unit);
6927 return Encl_Unit;
6928 end Enclosing_Lib_Unit_Node;
6929
6930 -----------------------
6931 -- Enclosing_Package --
6932 -----------------------
6933
6934 function Enclosing_Package (E : Entity_Id) return Entity_Id is
6935 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
6936
6937 begin
6938 if Dynamic_Scope = Standard_Standard then
6939 return Standard_Standard;
6940
6941 elsif Dynamic_Scope = Empty then
6942 return Empty;
6943
6944 elsif Ekind_In (Dynamic_Scope, E_Generic_Package,
6945 E_Package,
6946 E_Package_Body)
6947 then
6948 return Dynamic_Scope;
6949
6950 else
6951 return Enclosing_Package (Dynamic_Scope);
6952 end if;
6953 end Enclosing_Package;
6954
6955 -------------------------------------
6956 -- Enclosing_Package_Or_Subprogram --
6957 -------------------------------------
6958
6959 function Enclosing_Package_Or_Subprogram (E : Entity_Id) return Entity_Id is
6960 S : Entity_Id;
6961
6962 begin
6963 S := Scope (E);
6964 while Present (S) loop
6965 if Is_Package_Or_Generic_Package (S)
6966 or else Is_Subprogram_Or_Generic_Subprogram (S)
6967 then
6968 return S;
6969
6970 else
6971 S := Scope (S);
6972 end if;
6973 end loop;
6974
6975 return Empty;
6976 end Enclosing_Package_Or_Subprogram;
6977
6978 --------------------------
6979 -- Enclosing_Subprogram --
6980 --------------------------
6981
6982 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
6983 Dyn_Scop : constant Entity_Id := Enclosing_Dynamic_Scope (E);
6984
6985 begin
6986 if Dyn_Scop = Standard_Standard then
6987 return Empty;
6988
6989 elsif Dyn_Scop = Empty then
6990 return Empty;
6991
6992 elsif Ekind (Dyn_Scop) = E_Subprogram_Body then
6993 return Corresponding_Spec (Parent (Parent (Dyn_Scop)));
6994
6995 elsif Ekind_In (Dyn_Scop, E_Block, E_Loop, E_Return_Statement) then
6996 return Enclosing_Subprogram (Dyn_Scop);
6997
6998 elsif Ekind (Dyn_Scop) = E_Entry then
6999
7000 -- For a task entry, return the enclosing subprogram of the
7001 -- task itself.
7002
7003 if Ekind (Scope (Dyn_Scop)) = E_Task_Type then
7004 return Enclosing_Subprogram (Dyn_Scop);
7005
7006 -- A protected entry is rewritten as a protected procedure which is
7007 -- the desired enclosing subprogram. This is relevant when unnesting
7008 -- a procedure local to an entry body.
7009
7010 else
7011 return Protected_Body_Subprogram (Dyn_Scop);
7012 end if;
7013
7014 elsif Ekind (Dyn_Scop) = E_Task_Type then
7015 return Get_Task_Body_Procedure (Dyn_Scop);
7016
7017 -- The scope may appear as a private type or as a private extension
7018 -- whose completion is a task or protected type.
7019
7020 elsif Ekind_In (Dyn_Scop, E_Limited_Private_Type,
7021 E_Record_Type_With_Private)
7022 and then Present (Full_View (Dyn_Scop))
7023 and then Ekind_In (Full_View (Dyn_Scop), E_Task_Type, E_Protected_Type)
7024 then
7025 return Get_Task_Body_Procedure (Full_View (Dyn_Scop));
7026
7027 -- No body is generated if the protected operation is eliminated
7028
7029 elsif Convention (Dyn_Scop) = Convention_Protected
7030 and then not Is_Eliminated (Dyn_Scop)
7031 and then Present (Protected_Body_Subprogram (Dyn_Scop))
7032 then
7033 return Protected_Body_Subprogram (Dyn_Scop);
7034
7035 else
7036 return Dyn_Scop;
7037 end if;
7038 end Enclosing_Subprogram;
7039
7040 --------------------------
7041 -- End_Keyword_Location --
7042 --------------------------
7043
7044 function End_Keyword_Location (N : Node_Id) return Source_Ptr is
7045 function End_Label_Loc (Nod : Node_Id) return Source_Ptr;
7046 -- Return the source location of Nod's end label according to the
7047 -- following precedence rules:
7048 --
7049 -- 1) If the end label exists, return its location
7050 -- 2) If Nod exists, return its location
7051 -- 3) Return the location of N
7052
7053 -------------------
7054 -- End_Label_Loc --
7055 -------------------
7056
7057 function End_Label_Loc (Nod : Node_Id) return Source_Ptr is
7058 Label : Node_Id;
7059
7060 begin
7061 if Present (Nod) then
7062 Label := End_Label (Nod);
7063
7064 if Present (Label) then
7065 return Sloc (Label);
7066 else
7067 return Sloc (Nod);
7068 end if;
7069
7070 else
7071 return Sloc (N);
7072 end if;
7073 end End_Label_Loc;
7074
7075 -- Local variables
7076
7077 Owner : Node_Id;
7078
7079 -- Start of processing for End_Keyword_Location
7080
7081 begin
7082 if Nkind_In (N, N_Block_Statement,
7083 N_Entry_Body,
7084 N_Package_Body,
7085 N_Subprogram_Body,
7086 N_Task_Body)
7087 then
7088 Owner := Handled_Statement_Sequence (N);
7089
7090 elsif Nkind (N) = N_Package_Declaration then
7091 Owner := Specification (N);
7092
7093 elsif Nkind (N) = N_Protected_Body then
7094 Owner := N;
7095
7096 elsif Nkind_In (N, N_Protected_Type_Declaration,
7097 N_Single_Protected_Declaration)
7098 then
7099 Owner := Protected_Definition (N);
7100
7101 elsif Nkind_In (N, N_Single_Task_Declaration,
7102 N_Task_Type_Declaration)
7103 then
7104 Owner := Task_Definition (N);
7105
7106 -- This routine should not be called with other contexts
7107
7108 else
7109 pragma Assert (False);
7110 null;
7111 end if;
7112
7113 return End_Label_Loc (Owner);
7114 end End_Keyword_Location;
7115
7116 ------------------------
7117 -- Ensure_Freeze_Node --
7118 ------------------------
7119
7120 procedure Ensure_Freeze_Node (E : Entity_Id) is
7121 FN : Node_Id;
7122 begin
7123 if No (Freeze_Node (E)) then
7124 FN := Make_Freeze_Entity (Sloc (E));
7125 Set_Has_Delayed_Freeze (E);
7126 Set_Freeze_Node (E, FN);
7127 Set_Access_Types_To_Process (FN, No_Elist);
7128 Set_TSS_Elist (FN, No_Elist);
7129 Set_Entity (FN, E);
7130 end if;
7131 end Ensure_Freeze_Node;
7132
7133 ----------------
7134 -- Enter_Name --
7135 ----------------
7136
7137 procedure Enter_Name (Def_Id : Entity_Id) is
7138 C : constant Entity_Id := Current_Entity (Def_Id);
7139 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
7140 S : constant Entity_Id := Current_Scope;
7141
7142 begin
7143 Generate_Definition (Def_Id);
7144
7145 -- Add new name to current scope declarations. Check for duplicate
7146 -- declaration, which may or may not be a genuine error.
7147
7148 if Present (E) then
7149
7150 -- Case of previous entity entered because of a missing declaration
7151 -- or else a bad subtype indication. Best is to use the new entity,
7152 -- and make the previous one invisible.
7153
7154 if Etype (E) = Any_Type then
7155 Set_Is_Immediately_Visible (E, False);
7156
7157 -- Case of renaming declaration constructed for package instances.
7158 -- if there is an explicit declaration with the same identifier,
7159 -- the renaming is not immediately visible any longer, but remains
7160 -- visible through selected component notation.
7161
7162 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
7163 and then not Comes_From_Source (E)
7164 then
7165 Set_Is_Immediately_Visible (E, False);
7166
7167 -- The new entity may be the package renaming, which has the same
7168 -- same name as a generic formal which has been seen already.
7169
7170 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
7171 and then not Comes_From_Source (Def_Id)
7172 then
7173 Set_Is_Immediately_Visible (E, False);
7174
7175 -- For a fat pointer corresponding to a remote access to subprogram,
7176 -- we use the same identifier as the RAS type, so that the proper
7177 -- name appears in the stub. This type is only retrieved through
7178 -- the RAS type and never by visibility, and is not added to the
7179 -- visibility list (see below).
7180
7181 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
7182 and then Ekind (Def_Id) = E_Record_Type
7183 and then Present (Corresponding_Remote_Type (Def_Id))
7184 then
7185 null;
7186
7187 -- Case of an implicit operation or derived literal. The new entity
7188 -- hides the implicit one, which is removed from all visibility,
7189 -- i.e. the entity list of its scope, and homonym chain of its name.
7190
7191 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
7192 or else Is_Internal (E)
7193 then
7194 declare
7195 Decl : constant Node_Id := Parent (E);
7196 Prev : Entity_Id;
7197 Prev_Vis : Entity_Id;
7198
7199 begin
7200 -- If E is an implicit declaration, it cannot be the first
7201 -- entity in the scope.
7202
7203 Prev := First_Entity (Current_Scope);
7204 while Present (Prev) and then Next_Entity (Prev) /= E loop
7205 Next_Entity (Prev);
7206 end loop;
7207
7208 if No (Prev) then
7209
7210 -- If E is not on the entity chain of the current scope,
7211 -- it is an implicit declaration in the generic formal
7212 -- part of a generic subprogram. When analyzing the body,
7213 -- the generic formals are visible but not on the entity
7214 -- chain of the subprogram. The new entity will become
7215 -- the visible one in the body.
7216
7217 pragma Assert
7218 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
7219 null;
7220
7221 else
7222 Link_Entities (Prev, Next_Entity (E));
7223
7224 if No (Next_Entity (Prev)) then
7225 Set_Last_Entity (Current_Scope, Prev);
7226 end if;
7227
7228 if E = Current_Entity (E) then
7229 Prev_Vis := Empty;
7230
7231 else
7232 Prev_Vis := Current_Entity (E);
7233 while Homonym (Prev_Vis) /= E loop
7234 Prev_Vis := Homonym (Prev_Vis);
7235 end loop;
7236 end if;
7237
7238 if Present (Prev_Vis) then
7239
7240 -- Skip E in the visibility chain
7241
7242 Set_Homonym (Prev_Vis, Homonym (E));
7243
7244 else
7245 Set_Name_Entity_Id (Chars (E), Homonym (E));
7246 end if;
7247 end if;
7248 end;
7249
7250 -- This section of code could use a comment ???
7251
7252 elsif Present (Etype (E))
7253 and then Is_Concurrent_Type (Etype (E))
7254 and then E = Def_Id
7255 then
7256 return;
7257
7258 -- If the homograph is a protected component renaming, it should not
7259 -- be hiding the current entity. Such renamings are treated as weak
7260 -- declarations.
7261
7262 elsif Is_Prival (E) then
7263 Set_Is_Immediately_Visible (E, False);
7264
7265 -- In this case the current entity is a protected component renaming.
7266 -- Perform minimal decoration by setting the scope and return since
7267 -- the prival should not be hiding other visible entities.
7268
7269 elsif Is_Prival (Def_Id) then
7270 Set_Scope (Def_Id, Current_Scope);
7271 return;
7272
7273 -- Analogous to privals, the discriminal generated for an entry index
7274 -- parameter acts as a weak declaration. Perform minimal decoration
7275 -- to avoid bogus errors.
7276
7277 elsif Is_Discriminal (Def_Id)
7278 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
7279 then
7280 Set_Scope (Def_Id, Current_Scope);
7281 return;
7282
7283 -- In the body or private part of an instance, a type extension may
7284 -- introduce a component with the same name as that of an actual. The
7285 -- legality rule is not enforced, but the semantics of the full type
7286 -- with two components of same name are not clear at this point???
7287
7288 elsif In_Instance_Not_Visible then
7289 null;
7290
7291 -- When compiling a package body, some child units may have become
7292 -- visible. They cannot conflict with local entities that hide them.
7293
7294 elsif Is_Child_Unit (E)
7295 and then In_Open_Scopes (Scope (E))
7296 and then not Is_Immediately_Visible (E)
7297 then
7298 null;
7299
7300 -- Conversely, with front-end inlining we may compile the parent body
7301 -- first, and a child unit subsequently. The context is now the
7302 -- parent spec, and body entities are not visible.
7303
7304 elsif Is_Child_Unit (Def_Id)
7305 and then Is_Package_Body_Entity (E)
7306 and then not In_Package_Body (Current_Scope)
7307 then
7308 null;
7309
7310 -- Case of genuine duplicate declaration
7311
7312 else
7313 Error_Msg_Sloc := Sloc (E);
7314
7315 -- If the previous declaration is an incomplete type declaration
7316 -- this may be an attempt to complete it with a private type. The
7317 -- following avoids confusing cascaded errors.
7318
7319 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
7320 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
7321 then
7322 Error_Msg_N
7323 ("incomplete type cannot be completed with a private " &
7324 "declaration", Parent (Def_Id));
7325 Set_Is_Immediately_Visible (E, False);
7326 Set_Full_View (E, Def_Id);
7327
7328 -- An inherited component of a record conflicts with a new
7329 -- discriminant. The discriminant is inserted first in the scope,
7330 -- but the error should be posted on it, not on the component.
7331
7332 elsif Ekind (E) = E_Discriminant
7333 and then Present (Scope (Def_Id))
7334 and then Scope (Def_Id) /= Current_Scope
7335 then
7336 Error_Msg_Sloc := Sloc (Def_Id);
7337 Error_Msg_N ("& conflicts with declaration#", E);
7338 return;
7339
7340 -- If the name of the unit appears in its own context clause, a
7341 -- dummy package with the name has already been created, and the
7342 -- error emitted. Try to continue quietly.
7343
7344 elsif Error_Posted (E)
7345 and then Sloc (E) = No_Location
7346 and then Nkind (Parent (E)) = N_Package_Specification
7347 and then Current_Scope = Standard_Standard
7348 then
7349 Set_Scope (Def_Id, Current_Scope);
7350 return;
7351
7352 else
7353 Error_Msg_N ("& conflicts with declaration#", Def_Id);
7354
7355 -- Avoid cascaded messages with duplicate components in
7356 -- derived types.
7357
7358 if Ekind_In (E, E_Component, E_Discriminant) then
7359 return;
7360 end if;
7361 end if;
7362
7363 if Nkind (Parent (Parent (Def_Id))) =
7364 N_Generic_Subprogram_Declaration
7365 and then Def_Id =
7366 Defining_Entity (Specification (Parent (Parent (Def_Id))))
7367 then
7368 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
7369 end if;
7370
7371 -- If entity is in standard, then we are in trouble, because it
7372 -- means that we have a library package with a duplicated name.
7373 -- That's hard to recover from, so abort.
7374
7375 if S = Standard_Standard then
7376 raise Unrecoverable_Error;
7377
7378 -- Otherwise we continue with the declaration. Having two
7379 -- identical declarations should not cause us too much trouble.
7380
7381 else
7382 null;
7383 end if;
7384 end if;
7385 end if;
7386
7387 -- If we fall through, declaration is OK, at least OK enough to continue
7388
7389 -- If Def_Id is a discriminant or a record component we are in the midst
7390 -- of inheriting components in a derived record definition. Preserve
7391 -- their Ekind and Etype.
7392
7393 if Ekind_In (Def_Id, E_Discriminant, E_Component) then
7394 null;
7395
7396 -- If a type is already set, leave it alone (happens when a type
7397 -- declaration is reanalyzed following a call to the optimizer).
7398
7399 elsif Present (Etype (Def_Id)) then
7400 null;
7401
7402 -- Otherwise, the kind E_Void insures that premature uses of the entity
7403 -- will be detected. Any_Type insures that no cascaded errors will occur
7404
7405 else
7406 Set_Ekind (Def_Id, E_Void);
7407 Set_Etype (Def_Id, Any_Type);
7408 end if;
7409
7410 -- Inherited discriminants and components in derived record types are
7411 -- immediately visible. Itypes are not.
7412
7413 -- Unless the Itype is for a record type with a corresponding remote
7414 -- type (what is that about, it was not commented ???)
7415
7416 if Ekind_In (Def_Id, E_Discriminant, E_Component)
7417 or else
7418 ((not Is_Record_Type (Def_Id)
7419 or else No (Corresponding_Remote_Type (Def_Id)))
7420 and then not Is_Itype (Def_Id))
7421 then
7422 Set_Is_Immediately_Visible (Def_Id);
7423 Set_Current_Entity (Def_Id);
7424 end if;
7425
7426 Set_Homonym (Def_Id, C);
7427 Append_Entity (Def_Id, S);
7428 Set_Public_Status (Def_Id);
7429
7430 -- Declaring a homonym is not allowed in SPARK ...
7431
7432 if Present (C) and then Restriction_Check_Required (SPARK_05) then
7433 declare
7434 Enclosing_Subp : constant Node_Id := Enclosing_Subprogram (Def_Id);
7435 Enclosing_Pack : constant Node_Id := Enclosing_Package (Def_Id);
7436 Other_Scope : constant Node_Id := Enclosing_Dynamic_Scope (C);
7437
7438 begin
7439 -- ... unless the new declaration is in a subprogram, and the
7440 -- visible declaration is a variable declaration or a parameter
7441 -- specification outside that subprogram.
7442
7443 if Present (Enclosing_Subp)
7444 and then Nkind_In (Parent (C), N_Object_Declaration,
7445 N_Parameter_Specification)
7446 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Subp)
7447 then
7448 null;
7449
7450 -- ... or the new declaration is in a package, and the visible
7451 -- declaration occurs outside that package.
7452
7453 elsif Present (Enclosing_Pack)
7454 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Pack)
7455 then
7456 null;
7457
7458 -- ... or the new declaration is a component declaration in a
7459 -- record type definition.
7460
7461 elsif Nkind (Parent (Def_Id)) = N_Component_Declaration then
7462 null;
7463
7464 -- Don't issue error for non-source entities
7465
7466 elsif Comes_From_Source (Def_Id)
7467 and then Comes_From_Source (C)
7468 then
7469 Error_Msg_Sloc := Sloc (C);
7470 Check_SPARK_05_Restriction
7471 ("redeclaration of identifier &#", Def_Id);
7472 end if;
7473 end;
7474 end if;
7475
7476 -- Warn if new entity hides an old one
7477
7478 if Warn_On_Hiding and then Present (C)
7479
7480 -- Don't warn for record components since they always have a well
7481 -- defined scope which does not confuse other uses. Note that in
7482 -- some cases, Ekind has not been set yet.
7483
7484 and then Ekind (C) /= E_Component
7485 and then Ekind (C) /= E_Discriminant
7486 and then Nkind (Parent (C)) /= N_Component_Declaration
7487 and then Ekind (Def_Id) /= E_Component
7488 and then Ekind (Def_Id) /= E_Discriminant
7489 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
7490
7491 -- Don't warn for one character variables. It is too common to use
7492 -- such variables as locals and will just cause too many false hits.
7493
7494 and then Length_Of_Name (Chars (C)) /= 1
7495
7496 -- Don't warn for non-source entities
7497
7498 and then Comes_From_Source (C)
7499 and then Comes_From_Source (Def_Id)
7500
7501 -- Don't warn unless entity in question is in extended main source
7502
7503 and then In_Extended_Main_Source_Unit (Def_Id)
7504
7505 -- Finally, the hidden entity must be either immediately visible or
7506 -- use visible (i.e. from a used package).
7507
7508 and then
7509 (Is_Immediately_Visible (C)
7510 or else
7511 Is_Potentially_Use_Visible (C))
7512 then
7513 Error_Msg_Sloc := Sloc (C);
7514 Error_Msg_N ("declaration hides &#?h?", Def_Id);
7515 end if;
7516 end Enter_Name;
7517
7518 ---------------
7519 -- Entity_Of --
7520 ---------------
7521
7522 function Entity_Of (N : Node_Id) return Entity_Id is
7523 Id : Entity_Id;
7524 Ren : Node_Id;
7525
7526 begin
7527 -- Assume that the arbitrary node does not have an entity
7528
7529 Id := Empty;
7530
7531 if Is_Entity_Name (N) then
7532 Id := Entity (N);
7533
7534 -- Follow a possible chain of renamings to reach the earliest renamed
7535 -- source object.
7536
7537 while Present (Id)
7538 and then Is_Object (Id)
7539 and then Present (Renamed_Object (Id))
7540 loop
7541 Ren := Renamed_Object (Id);
7542
7543 -- The reference renames an abstract state or a whole object
7544
7545 -- Obj : ...;
7546 -- Ren : ... renames Obj;
7547
7548 if Is_Entity_Name (Ren) then
7549
7550 -- Do not follow a renaming that goes through a generic formal,
7551 -- because these entities are hidden and must not be referenced
7552 -- from outside the generic.
7553
7554 if Is_Hidden (Entity (Ren)) then
7555 exit;
7556
7557 else
7558 Id := Entity (Ren);
7559 end if;
7560
7561 -- The reference renames a function result. Check the original
7562 -- node in case expansion relocates the function call.
7563
7564 -- Ren : ... renames Func_Call;
7565
7566 elsif Nkind (Original_Node (Ren)) = N_Function_Call then
7567 exit;
7568
7569 -- Otherwise the reference renames something which does not yield
7570 -- an abstract state or a whole object. Treat the reference as not
7571 -- having a proper entity for SPARK legality purposes.
7572
7573 else
7574 Id := Empty;
7575 exit;
7576 end if;
7577 end loop;
7578 end if;
7579
7580 return Id;
7581 end Entity_Of;
7582
7583 --------------------------
7584 -- Examine_Array_Bounds --
7585 --------------------------
7586
7587 procedure Examine_Array_Bounds
7588 (Typ : Entity_Id;
7589 All_Static : out Boolean;
7590 Has_Empty : out Boolean)
7591 is
7592 function Is_OK_Static_Bound (Bound : Node_Id) return Boolean;
7593 -- Determine whether bound Bound is a suitable static bound
7594
7595 ------------------------
7596 -- Is_OK_Static_Bound --
7597 ------------------------
7598
7599 function Is_OK_Static_Bound (Bound : Node_Id) return Boolean is
7600 begin
7601 return
7602 not Error_Posted (Bound)
7603 and then Is_OK_Static_Expression (Bound);
7604 end Is_OK_Static_Bound;
7605
7606 -- Local variables
7607
7608 Hi_Bound : Node_Id;
7609 Index : Node_Id;
7610 Lo_Bound : Node_Id;
7611
7612 -- Start of processing for Examine_Array_Bounds
7613
7614 begin
7615 -- An unconstrained array type does not have static bounds, and it is
7616 -- not known whether they are empty or not.
7617
7618 if not Is_Constrained (Typ) then
7619 All_Static := False;
7620 Has_Empty := False;
7621
7622 -- A string literal has static bounds, and is not empty as long as it
7623 -- contains at least one character.
7624
7625 elsif Ekind (Typ) = E_String_Literal_Subtype then
7626 All_Static := True;
7627 Has_Empty := String_Literal_Length (Typ) > 0;
7628 end if;
7629
7630 -- Assume that all bounds are static and not empty
7631
7632 All_Static := True;
7633 Has_Empty := False;
7634
7635 -- Examine each index
7636
7637 Index := First_Index (Typ);
7638 while Present (Index) loop
7639 if Is_Discrete_Type (Etype (Index)) then
7640 Get_Index_Bounds (Index, Lo_Bound, Hi_Bound);
7641
7642 if Is_OK_Static_Bound (Lo_Bound)
7643 and then
7644 Is_OK_Static_Bound (Hi_Bound)
7645 then
7646 -- The static bounds produce an empty range
7647
7648 if Is_Null_Range (Lo_Bound, Hi_Bound) then
7649 Has_Empty := True;
7650 end if;
7651
7652 -- Otherwise at least one of the bounds is not static
7653
7654 else
7655 All_Static := False;
7656 end if;
7657
7658 -- Otherwise the index is non-discrete, therefore not static
7659
7660 else
7661 All_Static := False;
7662 end if;
7663
7664 Next_Index (Index);
7665 end loop;
7666 end Examine_Array_Bounds;
7667
7668 -------------------
7669 -- Exceptions_OK --
7670 -------------------
7671
7672 function Exceptions_OK return Boolean is
7673 begin
7674 return
7675 not (Restriction_Active (No_Exception_Handlers) or else
7676 Restriction_Active (No_Exception_Propagation) or else
7677 Restriction_Active (No_Exceptions));
7678 end Exceptions_OK;
7679
7680 --------------------------
7681 -- Explain_Limited_Type --
7682 --------------------------
7683
7684 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
7685 C : Entity_Id;
7686
7687 begin
7688 -- For array, component type must be limited
7689
7690 if Is_Array_Type (T) then
7691 Error_Msg_Node_2 := T;
7692 Error_Msg_NE
7693 ("\component type& of type& is limited", N, Component_Type (T));
7694 Explain_Limited_Type (Component_Type (T), N);
7695
7696 elsif Is_Record_Type (T) then
7697
7698 -- No need for extra messages if explicit limited record
7699
7700 if Is_Limited_Record (Base_Type (T)) then
7701 return;
7702 end if;
7703
7704 -- Otherwise find a limited component. Check only components that
7705 -- come from source, or inherited components that appear in the
7706 -- source of the ancestor.
7707
7708 C := First_Component (T);
7709 while Present (C) loop
7710 if Is_Limited_Type (Etype (C))
7711 and then
7712 (Comes_From_Source (C)
7713 or else
7714 (Present (Original_Record_Component (C))
7715 and then
7716 Comes_From_Source (Original_Record_Component (C))))
7717 then
7718 Error_Msg_Node_2 := T;
7719 Error_Msg_NE ("\component& of type& has limited type", N, C);
7720 Explain_Limited_Type (Etype (C), N);
7721 return;
7722 end if;
7723
7724 Next_Component (C);
7725 end loop;
7726
7727 -- The type may be declared explicitly limited, even if no component
7728 -- of it is limited, in which case we fall out of the loop.
7729 return;
7730 end if;
7731 end Explain_Limited_Type;
7732
7733 ---------------------------------------
7734 -- Expression_Of_Expression_Function --
7735 ---------------------------------------
7736
7737 function Expression_Of_Expression_Function
7738 (Subp : Entity_Id) return Node_Id
7739 is
7740 Expr_Func : Node_Id;
7741
7742 begin
7743 pragma Assert (Is_Expression_Function_Or_Completion (Subp));
7744
7745 if Nkind (Original_Node (Subprogram_Spec (Subp))) =
7746 N_Expression_Function
7747 then
7748 Expr_Func := Original_Node (Subprogram_Spec (Subp));
7749
7750 elsif Nkind (Original_Node (Subprogram_Body (Subp))) =
7751 N_Expression_Function
7752 then
7753 Expr_Func := Original_Node (Subprogram_Body (Subp));
7754
7755 else
7756 pragma Assert (False);
7757 null;
7758 end if;
7759
7760 return Original_Node (Expression (Expr_Func));
7761 end Expression_Of_Expression_Function;
7762
7763 -------------------------------
7764 -- Extensions_Visible_Status --
7765 -------------------------------
7766
7767 function Extensions_Visible_Status
7768 (Id : Entity_Id) return Extensions_Visible_Mode
7769 is
7770 Arg : Node_Id;
7771 Decl : Node_Id;
7772 Expr : Node_Id;
7773 Prag : Node_Id;
7774 Subp : Entity_Id;
7775
7776 begin
7777 -- When a formal parameter is subject to Extensions_Visible, the pragma
7778 -- is stored in the contract of related subprogram.
7779
7780 if Is_Formal (Id) then
7781 Subp := Scope (Id);
7782
7783 elsif Is_Subprogram_Or_Generic_Subprogram (Id) then
7784 Subp := Id;
7785
7786 -- No other construct carries this pragma
7787
7788 else
7789 return Extensions_Visible_None;
7790 end if;
7791
7792 Prag := Get_Pragma (Subp, Pragma_Extensions_Visible);
7793
7794 -- In certain cases analysis may request the Extensions_Visible status
7795 -- of an expression function before the pragma has been analyzed yet.
7796 -- Inspect the declarative items after the expression function looking
7797 -- for the pragma (if any).
7798
7799 if No (Prag) and then Is_Expression_Function (Subp) then
7800 Decl := Next (Unit_Declaration_Node (Subp));
7801 while Present (Decl) loop
7802 if Nkind (Decl) = N_Pragma
7803 and then Pragma_Name (Decl) = Name_Extensions_Visible
7804 then
7805 Prag := Decl;
7806 exit;
7807
7808 -- A source construct ends the region where Extensions_Visible may
7809 -- appear, stop the traversal. An expanded expression function is
7810 -- no longer a source construct, but it must still be recognized.
7811
7812 elsif Comes_From_Source (Decl)
7813 or else
7814 (Nkind_In (Decl, N_Subprogram_Body,
7815 N_Subprogram_Declaration)
7816 and then Is_Expression_Function (Defining_Entity (Decl)))
7817 then
7818 exit;
7819 end if;
7820
7821 Next (Decl);
7822 end loop;
7823 end if;
7824
7825 -- Extract the value from the Boolean expression (if any)
7826
7827 if Present (Prag) then
7828 Arg := First (Pragma_Argument_Associations (Prag));
7829
7830 if Present (Arg) then
7831 Expr := Get_Pragma_Arg (Arg);
7832
7833 -- When the associated subprogram is an expression function, the
7834 -- argument of the pragma may not have been analyzed.
7835
7836 if not Analyzed (Expr) then
7837 Preanalyze_And_Resolve (Expr, Standard_Boolean);
7838 end if;
7839
7840 -- Guard against cascading errors when the argument of pragma
7841 -- Extensions_Visible is not a valid static Boolean expression.
7842
7843 if Error_Posted (Expr) then
7844 return Extensions_Visible_None;
7845
7846 elsif Is_True (Expr_Value (Expr)) then
7847 return Extensions_Visible_True;
7848
7849 else
7850 return Extensions_Visible_False;
7851 end if;
7852
7853 -- Otherwise the aspect or pragma defaults to True
7854
7855 else
7856 return Extensions_Visible_True;
7857 end if;
7858
7859 -- Otherwise aspect or pragma Extensions_Visible is not inherited or
7860 -- directly specified. In SPARK code, its value defaults to "False".
7861
7862 elsif SPARK_Mode = On then
7863 return Extensions_Visible_False;
7864
7865 -- In non-SPARK code, aspect or pragma Extensions_Visible defaults to
7866 -- "True".
7867
7868 else
7869 return Extensions_Visible_True;
7870 end if;
7871 end Extensions_Visible_Status;
7872
7873 -----------------
7874 -- Find_Actual --
7875 -----------------
7876
7877 procedure Find_Actual
7878 (N : Node_Id;
7879 Formal : out Entity_Id;
7880 Call : out Node_Id)
7881 is
7882 Context : constant Node_Id := Parent (N);
7883 Actual : Node_Id;
7884 Call_Nam : Node_Id;
7885
7886 begin
7887 if Nkind_In (Context, N_Indexed_Component, N_Selected_Component)
7888 and then N = Prefix (Context)
7889 then
7890 Find_Actual (Context, Formal, Call);
7891 return;
7892
7893 elsif Nkind (Context) = N_Parameter_Association
7894 and then N = Explicit_Actual_Parameter (Context)
7895 then
7896 Call := Parent (Context);
7897
7898 elsif Nkind_In (Context, N_Entry_Call_Statement,
7899 N_Function_Call,
7900 N_Procedure_Call_Statement)
7901 then
7902 Call := Context;
7903
7904 else
7905 Formal := Empty;
7906 Call := Empty;
7907 return;
7908 end if;
7909
7910 -- If we have a call to a subprogram look for the parameter. Note that
7911 -- we exclude overloaded calls, since we don't know enough to be sure
7912 -- of giving the right answer in this case.
7913
7914 if Nkind_In (Call, N_Entry_Call_Statement,
7915 N_Function_Call,
7916 N_Procedure_Call_Statement)
7917 then
7918 Call_Nam := Name (Call);
7919
7920 -- A call to a protected or task entry appears as a selected
7921 -- component rather than an expanded name.
7922
7923 if Nkind (Call_Nam) = N_Selected_Component then
7924 Call_Nam := Selector_Name (Call_Nam);
7925 end if;
7926
7927 if Is_Entity_Name (Call_Nam)
7928 and then Present (Entity (Call_Nam))
7929 and then Is_Overloadable (Entity (Call_Nam))
7930 and then not Is_Overloaded (Call_Nam)
7931 then
7932 -- If node is name in call it is not an actual
7933
7934 if N = Call_Nam then
7935 Formal := Empty;
7936 Call := Empty;
7937 return;
7938 end if;
7939
7940 -- Fall here if we are definitely a parameter
7941
7942 Actual := First_Actual (Call);
7943 Formal := First_Formal (Entity (Call_Nam));
7944 while Present (Formal) and then Present (Actual) loop
7945 if Actual = N then
7946 return;
7947
7948 -- An actual that is the prefix in a prefixed call may have
7949 -- been rewritten in the call, after the deferred reference
7950 -- was collected. Check if sloc and kinds and names match.
7951
7952 elsif Sloc (Actual) = Sloc (N)
7953 and then Nkind (Actual) = N_Identifier
7954 and then Nkind (Actual) = Nkind (N)
7955 and then Chars (Actual) = Chars (N)
7956 then
7957 return;
7958
7959 else
7960 Actual := Next_Actual (Actual);
7961 Formal := Next_Formal (Formal);
7962 end if;
7963 end loop;
7964 end if;
7965 end if;
7966
7967 -- Fall through here if we did not find matching actual
7968
7969 Formal := Empty;
7970 Call := Empty;
7971 end Find_Actual;
7972
7973 ---------------------------
7974 -- Find_Body_Discriminal --
7975 ---------------------------
7976
7977 function Find_Body_Discriminal
7978 (Spec_Discriminant : Entity_Id) return Entity_Id
7979 is
7980 Tsk : Entity_Id;
7981 Disc : Entity_Id;
7982
7983 begin
7984 -- If expansion is suppressed, then the scope can be the concurrent type
7985 -- itself rather than a corresponding concurrent record type.
7986
7987 if Is_Concurrent_Type (Scope (Spec_Discriminant)) then
7988 Tsk := Scope (Spec_Discriminant);
7989
7990 else
7991 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
7992
7993 Tsk := Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
7994 end if;
7995
7996 -- Find discriminant of original concurrent type, and use its current
7997 -- discriminal, which is the renaming within the task/protected body.
7998
7999 Disc := First_Discriminant (Tsk);
8000 while Present (Disc) loop
8001 if Chars (Disc) = Chars (Spec_Discriminant) then
8002 return Discriminal (Disc);
8003 end if;
8004
8005 Next_Discriminant (Disc);
8006 end loop;
8007
8008 -- That loop should always succeed in finding a matching entry and
8009 -- returning. Fatal error if not.
8010
8011 raise Program_Error;
8012 end Find_Body_Discriminal;
8013
8014 -------------------------------------
8015 -- Find_Corresponding_Discriminant --
8016 -------------------------------------
8017
8018 function Find_Corresponding_Discriminant
8019 (Id : Node_Id;
8020 Typ : Entity_Id) return Entity_Id
8021 is
8022 Par_Disc : Entity_Id;
8023 Old_Disc : Entity_Id;
8024 New_Disc : Entity_Id;
8025
8026 begin
8027 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
8028
8029 -- The original type may currently be private, and the discriminant
8030 -- only appear on its full view.
8031
8032 if Is_Private_Type (Scope (Par_Disc))
8033 and then not Has_Discriminants (Scope (Par_Disc))
8034 and then Present (Full_View (Scope (Par_Disc)))
8035 then
8036 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
8037 else
8038 Old_Disc := First_Discriminant (Scope (Par_Disc));
8039 end if;
8040
8041 if Is_Class_Wide_Type (Typ) then
8042 New_Disc := First_Discriminant (Root_Type (Typ));
8043 else
8044 New_Disc := First_Discriminant (Typ);
8045 end if;
8046
8047 while Present (Old_Disc) and then Present (New_Disc) loop
8048 if Old_Disc = Par_Disc then
8049 return New_Disc;
8050 end if;
8051
8052 Next_Discriminant (Old_Disc);
8053 Next_Discriminant (New_Disc);
8054 end loop;
8055
8056 -- Should always find it
8057
8058 raise Program_Error;
8059 end Find_Corresponding_Discriminant;
8060
8061 -------------------
8062 -- Find_DIC_Type --
8063 -------------------
8064
8065 function Find_DIC_Type (Typ : Entity_Id) return Entity_Id is
8066 Curr_Typ : Entity_Id;
8067 -- The current type being examined in the parent hierarchy traversal
8068
8069 DIC_Typ : Entity_Id;
8070 -- The type which carries the DIC pragma. This variable denotes the
8071 -- partial view when private types are involved.
8072
8073 Par_Typ : Entity_Id;
8074 -- The parent type of the current type. This variable denotes the full
8075 -- view when private types are involved.
8076
8077 begin
8078 -- The input type defines its own DIC pragma, therefore it is the owner
8079
8080 if Has_Own_DIC (Typ) then
8081 DIC_Typ := Typ;
8082
8083 -- Otherwise the DIC pragma is inherited from a parent type
8084
8085 else
8086 pragma Assert (Has_Inherited_DIC (Typ));
8087
8088 -- Climb the parent chain
8089
8090 Curr_Typ := Typ;
8091 loop
8092 -- Inspect the parent type. Do not consider subtypes as they
8093 -- inherit the DIC attributes from their base types.
8094
8095 DIC_Typ := Base_Type (Etype (Curr_Typ));
8096
8097 -- Look at the full view of a private type because the type may
8098 -- have a hidden parent introduced in the full view.
8099
8100 Par_Typ := DIC_Typ;
8101
8102 if Is_Private_Type (Par_Typ)
8103 and then Present (Full_View (Par_Typ))
8104 then
8105 Par_Typ := Full_View (Par_Typ);
8106 end if;
8107
8108 -- Stop the climb once the nearest parent type which defines a DIC
8109 -- pragma of its own is encountered or when the root of the parent
8110 -- chain is reached.
8111
8112 exit when Has_Own_DIC (DIC_Typ) or else Curr_Typ = Par_Typ;
8113
8114 Curr_Typ := Par_Typ;
8115 end loop;
8116 end if;
8117
8118 return DIC_Typ;
8119 end Find_DIC_Type;
8120
8121 ----------------------------------
8122 -- Find_Enclosing_Iterator_Loop --
8123 ----------------------------------
8124
8125 function Find_Enclosing_Iterator_Loop (Id : Entity_Id) return Entity_Id is
8126 Constr : Node_Id;
8127 S : Entity_Id;
8128
8129 begin
8130 -- Traverse the scope chain looking for an iterator loop. Such loops are
8131 -- usually transformed into blocks, hence the use of Original_Node.
8132
8133 S := Id;
8134 while Present (S) and then S /= Standard_Standard loop
8135 if Ekind (S) = E_Loop
8136 and then Nkind (Parent (S)) = N_Implicit_Label_Declaration
8137 then
8138 Constr := Original_Node (Label_Construct (Parent (S)));
8139
8140 if Nkind (Constr) = N_Loop_Statement
8141 and then Present (Iteration_Scheme (Constr))
8142 and then Nkind (Iterator_Specification
8143 (Iteration_Scheme (Constr))) =
8144 N_Iterator_Specification
8145 then
8146 return S;
8147 end if;
8148 end if;
8149
8150 S := Scope (S);
8151 end loop;
8152
8153 return Empty;
8154 end Find_Enclosing_Iterator_Loop;
8155
8156 --------------------------
8157 -- Find_Enclosing_Scope --
8158 --------------------------
8159
8160 function Find_Enclosing_Scope (N : Node_Id) return Entity_Id is
8161 Par : Node_Id;
8162
8163 begin
8164 -- Examine the parent chain looking for a construct which defines a
8165 -- scope.
8166
8167 Par := Parent (N);
8168 while Present (Par) loop
8169 case Nkind (Par) is
8170
8171 -- The construct denotes a declaration, the proper scope is its
8172 -- entity.
8173
8174 when N_Entry_Declaration
8175 | N_Expression_Function
8176 | N_Full_Type_Declaration
8177 | N_Generic_Package_Declaration
8178 | N_Generic_Subprogram_Declaration
8179 | N_Package_Declaration
8180 | N_Private_Extension_Declaration
8181 | N_Protected_Type_Declaration
8182 | N_Single_Protected_Declaration
8183 | N_Single_Task_Declaration
8184 | N_Subprogram_Declaration
8185 | N_Task_Type_Declaration
8186 =>
8187 return Defining_Entity (Par);
8188
8189 -- The construct denotes a body, the proper scope is the entity of
8190 -- the corresponding spec or that of the body if the body does not
8191 -- complete a previous declaration.
8192
8193 when N_Entry_Body
8194 | N_Package_Body
8195 | N_Protected_Body
8196 | N_Subprogram_Body
8197 | N_Task_Body
8198 =>
8199 return Unique_Defining_Entity (Par);
8200
8201 -- Special cases
8202
8203 -- Blocks carry either a source or an internally-generated scope,
8204 -- unless the block is a byproduct of exception handling.
8205
8206 when N_Block_Statement =>
8207 if not Exception_Junk (Par) then
8208 return Entity (Identifier (Par));
8209 end if;
8210
8211 -- Loops carry an internally-generated scope
8212
8213 when N_Loop_Statement =>
8214 return Entity (Identifier (Par));
8215
8216 -- Extended return statements carry an internally-generated scope
8217
8218 when N_Extended_Return_Statement =>
8219 return Return_Statement_Entity (Par);
8220
8221 -- A traversal from a subunit continues via the corresponding stub
8222
8223 when N_Subunit =>
8224 Par := Corresponding_Stub (Par);
8225
8226 when others =>
8227 null;
8228 end case;
8229
8230 Par := Parent (Par);
8231 end loop;
8232
8233 return Standard_Standard;
8234 end Find_Enclosing_Scope;
8235
8236 ------------------------------------
8237 -- Find_Loop_In_Conditional_Block --
8238 ------------------------------------
8239
8240 function Find_Loop_In_Conditional_Block (N : Node_Id) return Node_Id is
8241 Stmt : Node_Id;
8242
8243 begin
8244 Stmt := N;
8245
8246 if Nkind (Stmt) = N_If_Statement then
8247 Stmt := First (Then_Statements (Stmt));
8248 end if;
8249
8250 pragma Assert (Nkind (Stmt) = N_Block_Statement);
8251
8252 -- Inspect the statements of the conditional block. In general the loop
8253 -- should be the first statement in the statement sequence of the block,
8254 -- but the finalization machinery may have introduced extra object
8255 -- declarations.
8256
8257 Stmt := First (Statements (Handled_Statement_Sequence (Stmt)));
8258 while Present (Stmt) loop
8259 if Nkind (Stmt) = N_Loop_Statement then
8260 return Stmt;
8261 end if;
8262
8263 Next (Stmt);
8264 end loop;
8265
8266 -- The expansion of attribute 'Loop_Entry produced a malformed block
8267
8268 raise Program_Error;
8269 end Find_Loop_In_Conditional_Block;
8270
8271 --------------------------
8272 -- Find_Overlaid_Entity --
8273 --------------------------
8274
8275 procedure Find_Overlaid_Entity
8276 (N : Node_Id;
8277 Ent : out Entity_Id;
8278 Off : out Boolean)
8279 is
8280 Expr : Node_Id;
8281
8282 begin
8283 -- We are looking for one of the two following forms:
8284
8285 -- for X'Address use Y'Address
8286
8287 -- or
8288
8289 -- Const : constant Address := expr;
8290 -- ...
8291 -- for X'Address use Const;
8292
8293 -- In the second case, the expr is either Y'Address, or recursively a
8294 -- constant that eventually references Y'Address.
8295
8296 Ent := Empty;
8297 Off := False;
8298
8299 if Nkind (N) = N_Attribute_Definition_Clause
8300 and then Chars (N) = Name_Address
8301 then
8302 Expr := Expression (N);
8303
8304 -- This loop checks the form of the expression for Y'Address,
8305 -- using recursion to deal with intermediate constants.
8306
8307 loop
8308 -- Check for Y'Address
8309
8310 if Nkind (Expr) = N_Attribute_Reference
8311 and then Attribute_Name (Expr) = Name_Address
8312 then
8313 Expr := Prefix (Expr);
8314 exit;
8315
8316 -- Check for Const where Const is a constant entity
8317
8318 elsif Is_Entity_Name (Expr)
8319 and then Ekind (Entity (Expr)) = E_Constant
8320 then
8321 Expr := Constant_Value (Entity (Expr));
8322
8323 -- Anything else does not need checking
8324
8325 else
8326 return;
8327 end if;
8328 end loop;
8329
8330 -- This loop checks the form of the prefix for an entity, using
8331 -- recursion to deal with intermediate components.
8332
8333 loop
8334 -- Check for Y where Y is an entity
8335
8336 if Is_Entity_Name (Expr) then
8337 Ent := Entity (Expr);
8338 return;
8339
8340 -- Check for components
8341
8342 elsif
8343 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component)
8344 then
8345 Expr := Prefix (Expr);
8346 Off := True;
8347
8348 -- Anything else does not need checking
8349
8350 else
8351 return;
8352 end if;
8353 end loop;
8354 end if;
8355 end Find_Overlaid_Entity;
8356
8357 -------------------------
8358 -- Find_Parameter_Type --
8359 -------------------------
8360
8361 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
8362 begin
8363 if Nkind (Param) /= N_Parameter_Specification then
8364 return Empty;
8365
8366 -- For an access parameter, obtain the type from the formal entity
8367 -- itself, because access to subprogram nodes do not carry a type.
8368 -- Shouldn't we always use the formal entity ???
8369
8370 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
8371 return Etype (Defining_Identifier (Param));
8372
8373 else
8374 return Etype (Parameter_Type (Param));
8375 end if;
8376 end Find_Parameter_Type;
8377
8378 -----------------------------------
8379 -- Find_Placement_In_State_Space --
8380 -----------------------------------
8381
8382 procedure Find_Placement_In_State_Space
8383 (Item_Id : Entity_Id;
8384 Placement : out State_Space_Kind;
8385 Pack_Id : out Entity_Id)
8386 is
8387 Context : Entity_Id;
8388
8389 begin
8390 -- Assume that the item does not appear in the state space of a package
8391
8392 Placement := Not_In_Package;
8393 Pack_Id := Empty;
8394
8395 -- Climb the scope stack and examine the enclosing context
8396
8397 Context := Scope (Item_Id);
8398 while Present (Context) and then Context /= Standard_Standard loop
8399 if Is_Package_Or_Generic_Package (Context) then
8400 Pack_Id := Context;
8401
8402 -- A package body is a cut off point for the traversal as the item
8403 -- cannot be visible to the outside from this point on. Note that
8404 -- this test must be done first as a body is also classified as a
8405 -- private part.
8406
8407 if In_Package_Body (Context) then
8408 Placement := Body_State_Space;
8409 return;
8410
8411 -- The private part of a package is a cut off point for the
8412 -- traversal as the item cannot be visible to the outside from
8413 -- this point on.
8414
8415 elsif In_Private_Part (Context) then
8416 Placement := Private_State_Space;
8417 return;
8418
8419 -- When the item appears in the visible state space of a package,
8420 -- continue to climb the scope stack as this may not be the final
8421 -- state space.
8422
8423 else
8424 Placement := Visible_State_Space;
8425
8426 -- The visible state space of a child unit acts as the proper
8427 -- placement of an item.
8428
8429 if Is_Child_Unit (Context) then
8430 return;
8431 end if;
8432 end if;
8433
8434 -- The item or its enclosing package appear in a construct that has
8435 -- no state space.
8436
8437 else
8438 Placement := Not_In_Package;
8439 return;
8440 end if;
8441
8442 Context := Scope (Context);
8443 end loop;
8444 end Find_Placement_In_State_Space;
8445
8446 -----------------------
8447 -- Find_Primitive_Eq --
8448 -----------------------
8449
8450 function Find_Primitive_Eq (Typ : Entity_Id) return Entity_Id is
8451 function Find_Eq_Prim (Prims_List : Elist_Id) return Entity_Id;
8452 -- Search for the equality primitive; return Empty if the primitive is
8453 -- not found.
8454
8455 ------------------
8456 -- Find_Eq_Prim --
8457 ------------------
8458
8459 function Find_Eq_Prim (Prims_List : Elist_Id) return Entity_Id is
8460 Prim : Entity_Id;
8461 Prim_Elmt : Elmt_Id;
8462
8463 begin
8464 Prim_Elmt := First_Elmt (Prims_List);
8465 while Present (Prim_Elmt) loop
8466 Prim := Node (Prim_Elmt);
8467
8468 -- Locate primitive equality with the right signature
8469
8470 if Chars (Prim) = Name_Op_Eq
8471 and then Etype (First_Formal (Prim)) =
8472 Etype (Next_Formal (First_Formal (Prim)))
8473 and then Base_Type (Etype (Prim)) = Standard_Boolean
8474 then
8475 return Prim;
8476 end if;
8477
8478 Next_Elmt (Prim_Elmt);
8479 end loop;
8480
8481 return Empty;
8482 end Find_Eq_Prim;
8483
8484 -- Local Variables
8485
8486 Eq_Prim : Entity_Id;
8487 Full_Type : Entity_Id;
8488
8489 -- Start of processing for Find_Primitive_Eq
8490
8491 begin
8492 if Is_Private_Type (Typ) then
8493 Full_Type := Underlying_Type (Typ);
8494 else
8495 Full_Type := Typ;
8496 end if;
8497
8498 if No (Full_Type) then
8499 return Empty;
8500 end if;
8501
8502 Full_Type := Base_Type (Full_Type);
8503
8504 -- When the base type itself is private, use the full view
8505
8506 if Is_Private_Type (Full_Type) then
8507 Full_Type := Underlying_Type (Full_Type);
8508 end if;
8509
8510 if Is_Class_Wide_Type (Full_Type) then
8511 Full_Type := Root_Type (Full_Type);
8512 end if;
8513
8514 if not Is_Tagged_Type (Full_Type) then
8515 Eq_Prim := Find_Eq_Prim (Collect_Primitive_Operations (Typ));
8516
8517 -- If this is an untagged private type completed with a derivation of
8518 -- an untagged private type whose full view is a tagged type, we use
8519 -- the primitive operations of the private parent type (since it does
8520 -- not have a full view, and also because its equality primitive may
8521 -- have been overridden in its untagged full view). If no equality was
8522 -- defined for it then take its dispatching equality primitive.
8523
8524 elsif Inherits_From_Tagged_Full_View (Typ) then
8525 Eq_Prim := Find_Eq_Prim (Collect_Primitive_Operations (Typ));
8526
8527 if No (Eq_Prim) then
8528 Eq_Prim := Find_Eq_Prim (Primitive_Operations (Full_Type));
8529 end if;
8530
8531 else
8532 Eq_Prim := Find_Eq_Prim (Primitive_Operations (Full_Type));
8533 end if;
8534
8535 return Eq_Prim;
8536 end Find_Primitive_Eq;
8537
8538 ------------------------
8539 -- Find_Specific_Type --
8540 ------------------------
8541
8542 function Find_Specific_Type (CW : Entity_Id) return Entity_Id is
8543 Typ : Entity_Id := Root_Type (CW);
8544
8545 begin
8546 if Ekind (Typ) = E_Incomplete_Type then
8547 if From_Limited_With (Typ) then
8548 Typ := Non_Limited_View (Typ);
8549 else
8550 Typ := Full_View (Typ);
8551 end if;
8552 end if;
8553
8554 if Is_Private_Type (Typ)
8555 and then not Is_Tagged_Type (Typ)
8556 and then Present (Full_View (Typ))
8557 then
8558 return Full_View (Typ);
8559 else
8560 return Typ;
8561 end if;
8562 end Find_Specific_Type;
8563
8564 -----------------------------
8565 -- Find_Static_Alternative --
8566 -----------------------------
8567
8568 function Find_Static_Alternative (N : Node_Id) return Node_Id is
8569 Expr : constant Node_Id := Expression (N);
8570 Val : constant Uint := Expr_Value (Expr);
8571 Alt : Node_Id;
8572 Choice : Node_Id;
8573
8574 begin
8575 Alt := First (Alternatives (N));
8576
8577 Search : loop
8578 if Nkind (Alt) /= N_Pragma then
8579 Choice := First (Discrete_Choices (Alt));
8580 while Present (Choice) loop
8581
8582 -- Others choice, always matches
8583
8584 if Nkind (Choice) = N_Others_Choice then
8585 exit Search;
8586
8587 -- Range, check if value is in the range
8588
8589 elsif Nkind (Choice) = N_Range then
8590 exit Search when
8591 Val >= Expr_Value (Low_Bound (Choice))
8592 and then
8593 Val <= Expr_Value (High_Bound (Choice));
8594
8595 -- Choice is a subtype name. Note that we know it must
8596 -- be a static subtype, since otherwise it would have
8597 -- been diagnosed as illegal.
8598
8599 elsif Is_Entity_Name (Choice)
8600 and then Is_Type (Entity (Choice))
8601 then
8602 exit Search when Is_In_Range (Expr, Etype (Choice),
8603 Assume_Valid => False);
8604
8605 -- Choice is a subtype indication
8606
8607 elsif Nkind (Choice) = N_Subtype_Indication then
8608 declare
8609 C : constant Node_Id := Constraint (Choice);
8610 R : constant Node_Id := Range_Expression (C);
8611
8612 begin
8613 exit Search when
8614 Val >= Expr_Value (Low_Bound (R))
8615 and then
8616 Val <= Expr_Value (High_Bound (R));
8617 end;
8618
8619 -- Choice is a simple expression
8620
8621 else
8622 exit Search when Val = Expr_Value (Choice);
8623 end if;
8624
8625 Next (Choice);
8626 end loop;
8627 end if;
8628
8629 Next (Alt);
8630 pragma Assert (Present (Alt));
8631 end loop Search;
8632
8633 -- The above loop *must* terminate by finding a match, since we know the
8634 -- case statement is valid, and the value of the expression is known at
8635 -- compile time. When we fall out of the loop, Alt points to the
8636 -- alternative that we know will be selected at run time.
8637
8638 return Alt;
8639 end Find_Static_Alternative;
8640
8641 ------------------
8642 -- First_Actual --
8643 ------------------
8644
8645 function First_Actual (Node : Node_Id) return Node_Id is
8646 N : Node_Id;
8647
8648 begin
8649 if No (Parameter_Associations (Node)) then
8650 return Empty;
8651 end if;
8652
8653 N := First (Parameter_Associations (Node));
8654
8655 if Nkind (N) = N_Parameter_Association then
8656 return First_Named_Actual (Node);
8657 else
8658 return N;
8659 end if;
8660 end First_Actual;
8661
8662 ------------------
8663 -- First_Global --
8664 ------------------
8665
8666 function First_Global
8667 (Subp : Entity_Id;
8668 Global_Mode : Name_Id;
8669 Refined : Boolean := False) return Node_Id
8670 is
8671 function First_From_Global_List
8672 (List : Node_Id;
8673 Global_Mode : Name_Id := Name_Input) return Entity_Id;
8674 -- Get the first item with suitable mode from List
8675
8676 ----------------------------
8677 -- First_From_Global_List --
8678 ----------------------------
8679
8680 function First_From_Global_List
8681 (List : Node_Id;
8682 Global_Mode : Name_Id := Name_Input) return Entity_Id
8683 is
8684 Assoc : Node_Id;
8685
8686 begin
8687 -- Empty list (no global items)
8688
8689 if Nkind (List) = N_Null then
8690 return Empty;
8691
8692 -- Single global item declaration (only input items)
8693
8694 elsif Nkind_In (List, N_Expanded_Name, N_Identifier) then
8695 if Global_Mode = Name_Input then
8696 return List;
8697 else
8698 return Empty;
8699 end if;
8700
8701 -- Simple global list (only input items) or moded global list
8702 -- declaration.
8703
8704 elsif Nkind (List) = N_Aggregate then
8705 if Present (Expressions (List)) then
8706 if Global_Mode = Name_Input then
8707 return First (Expressions (List));
8708 else
8709 return Empty;
8710 end if;
8711
8712 else
8713 Assoc := First (Component_Associations (List));
8714 while Present (Assoc) loop
8715
8716 -- When we find the desired mode in an association, call
8717 -- recursively First_From_Global_List as if the mode was
8718 -- Name_Input, in order to reuse the existing machinery
8719 -- for the other cases.
8720
8721 if Chars (First (Choices (Assoc))) = Global_Mode then
8722 return First_From_Global_List (Expression (Assoc));
8723 end if;
8724
8725 Next (Assoc);
8726 end loop;
8727
8728 return Empty;
8729 end if;
8730
8731 -- To accommodate partial decoration of disabled SPARK features,
8732 -- this routine may be called with illegal input. If this is the
8733 -- case, do not raise Program_Error.
8734
8735 else
8736 return Empty;
8737 end if;
8738 end First_From_Global_List;
8739
8740 -- Local variables
8741
8742 Global : Node_Id := Empty;
8743 Body_Id : Entity_Id;
8744
8745 -- Start of processing for First_Global
8746
8747 begin
8748 pragma Assert (Nam_In (Global_Mode, Name_In_Out,
8749 Name_Input,
8750 Name_Output,
8751 Name_Proof_In));
8752
8753 -- Retrieve the suitable pragma Global or Refined_Global. In the second
8754 -- case, it can only be located on the body entity.
8755
8756 if Refined then
8757 if Is_Subprogram_Or_Generic_Subprogram (Subp) then
8758 Body_Id := Subprogram_Body_Entity (Subp);
8759
8760 elsif Is_Entry (Subp) or else Is_Task_Type (Subp) then
8761 Body_Id := Corresponding_Body (Parent (Subp));
8762
8763 -- ??? It should be possible to retrieve the Refined_Global on the
8764 -- task body associated to the task object. This is not yet possible.
8765
8766 elsif Is_Single_Task_Object (Subp) then
8767 Body_Id := Empty;
8768
8769 else
8770 Body_Id := Empty;
8771 end if;
8772
8773 if Present (Body_Id) then
8774 Global := Get_Pragma (Body_Id, Pragma_Refined_Global);
8775 end if;
8776 else
8777 Global := Get_Pragma (Subp, Pragma_Global);
8778 end if;
8779
8780 -- No corresponding global if pragma is not present
8781
8782 if No (Global) then
8783 return Empty;
8784
8785 -- Otherwise retrieve the corresponding list of items depending on the
8786 -- Global_Mode.
8787
8788 else
8789 return First_From_Global_List
8790 (Expression (Get_Argument (Global, Subp)), Global_Mode);
8791 end if;
8792 end First_Global;
8793
8794 -------------
8795 -- Fix_Msg --
8796 -------------
8797
8798 function Fix_Msg (Id : Entity_Id; Msg : String) return String is
8799 Is_Task : constant Boolean :=
8800 Ekind_In (Id, E_Task_Body, E_Task_Type)
8801 or else Is_Single_Task_Object (Id);
8802 Msg_Last : constant Natural := Msg'Last;
8803 Msg_Index : Natural;
8804 Res : String (Msg'Range) := (others => ' ');
8805 Res_Index : Natural;
8806
8807 begin
8808 -- Copy all characters from the input message Msg to result Res with
8809 -- suitable replacements.
8810
8811 Msg_Index := Msg'First;
8812 Res_Index := Res'First;
8813 while Msg_Index <= Msg_Last loop
8814
8815 -- Replace "subprogram" with a different word
8816
8817 if Msg_Index <= Msg_Last - 10
8818 and then Msg (Msg_Index .. Msg_Index + 9) = "subprogram"
8819 then
8820 if Ekind_In (Id, E_Entry, E_Entry_Family) then
8821 Res (Res_Index .. Res_Index + 4) := "entry";
8822 Res_Index := Res_Index + 5;
8823
8824 elsif Is_Task then
8825 Res (Res_Index .. Res_Index + 8) := "task type";
8826 Res_Index := Res_Index + 9;
8827
8828 else
8829 Res (Res_Index .. Res_Index + 9) := "subprogram";
8830 Res_Index := Res_Index + 10;
8831 end if;
8832
8833 Msg_Index := Msg_Index + 10;
8834
8835 -- Replace "protected" with a different word
8836
8837 elsif Msg_Index <= Msg_Last - 9
8838 and then Msg (Msg_Index .. Msg_Index + 8) = "protected"
8839 and then Is_Task
8840 then
8841 Res (Res_Index .. Res_Index + 3) := "task";
8842 Res_Index := Res_Index + 4;
8843 Msg_Index := Msg_Index + 9;
8844
8845 -- Otherwise copy the character
8846
8847 else
8848 Res (Res_Index) := Msg (Msg_Index);
8849 Msg_Index := Msg_Index + 1;
8850 Res_Index := Res_Index + 1;
8851 end if;
8852 end loop;
8853
8854 return Res (Res'First .. Res_Index - 1);
8855 end Fix_Msg;
8856
8857 -------------------------
8858 -- From_Nested_Package --
8859 -------------------------
8860
8861 function From_Nested_Package (T : Entity_Id) return Boolean is
8862 Pack : constant Entity_Id := Scope (T);
8863
8864 begin
8865 return
8866 Ekind (Pack) = E_Package
8867 and then not Is_Frozen (Pack)
8868 and then not Scope_Within_Or_Same (Current_Scope, Pack)
8869 and then In_Open_Scopes (Scope (Pack));
8870 end From_Nested_Package;
8871
8872 -----------------------
8873 -- Gather_Components --
8874 -----------------------
8875
8876 procedure Gather_Components
8877 (Typ : Entity_Id;
8878 Comp_List : Node_Id;
8879 Governed_By : List_Id;
8880 Into : Elist_Id;
8881 Report_Errors : out Boolean)
8882 is
8883 Assoc : Node_Id;
8884 Variant : Node_Id;
8885 Discrete_Choice : Node_Id;
8886 Comp_Item : Node_Id;
8887
8888 Discrim : Entity_Id;
8889 Discrim_Name : Node_Id;
8890 Discrim_Value : Node_Id;
8891
8892 begin
8893 Report_Errors := False;
8894
8895 if No (Comp_List) or else Null_Present (Comp_List) then
8896 return;
8897
8898 elsif Present (Component_Items (Comp_List)) then
8899 Comp_Item := First (Component_Items (Comp_List));
8900
8901 else
8902 Comp_Item := Empty;
8903 end if;
8904
8905 while Present (Comp_Item) loop
8906
8907 -- Skip the tag of a tagged record, the interface tags, as well
8908 -- as all items that are not user components (anonymous types,
8909 -- rep clauses, Parent field, controller field).
8910
8911 if Nkind (Comp_Item) = N_Component_Declaration then
8912 declare
8913 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
8914 begin
8915 if not Is_Tag (Comp) and then Chars (Comp) /= Name_uParent then
8916 Append_Elmt (Comp, Into);
8917 end if;
8918 end;
8919 end if;
8920
8921 Next (Comp_Item);
8922 end loop;
8923
8924 if No (Variant_Part (Comp_List)) then
8925 return;
8926 else
8927 Discrim_Name := Name (Variant_Part (Comp_List));
8928 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
8929 end if;
8930
8931 -- Look for the discriminant that governs this variant part.
8932 -- The discriminant *must* be in the Governed_By List
8933
8934 Assoc := First (Governed_By);
8935 Find_Constraint : loop
8936 Discrim := First (Choices (Assoc));
8937 exit Find_Constraint when
8938 Chars (Discrim_Name) = Chars (Discrim)
8939 or else
8940 (Present (Corresponding_Discriminant (Entity (Discrim)))
8941 and then Chars (Corresponding_Discriminant
8942 (Entity (Discrim))) = Chars (Discrim_Name))
8943 or else
8944 Chars (Original_Record_Component (Entity (Discrim))) =
8945 Chars (Discrim_Name);
8946
8947 if No (Next (Assoc)) then
8948 if not Is_Constrained (Typ) and then Is_Derived_Type (Typ) then
8949
8950 -- If the type is a tagged type with inherited discriminants,
8951 -- use the stored constraint on the parent in order to find
8952 -- the values of discriminants that are otherwise hidden by an
8953 -- explicit constraint. Renamed discriminants are handled in
8954 -- the code above.
8955
8956 -- If several parent discriminants are renamed by a single
8957 -- discriminant of the derived type, the call to obtain the
8958 -- Corresponding_Discriminant field only retrieves the last
8959 -- of them. We recover the constraint on the others from the
8960 -- Stored_Constraint as well.
8961
8962 -- An inherited discriminant may have been constrained in a
8963 -- later ancestor (not the immediate parent) so we must examine
8964 -- the stored constraint of all of them to locate the inherited
8965 -- value.
8966
8967 declare
8968 C : Elmt_Id;
8969 D : Entity_Id;
8970 T : Entity_Id := Typ;
8971
8972 begin
8973 while Is_Derived_Type (T) loop
8974 if Present (Stored_Constraint (T)) then
8975 D := First_Discriminant (Etype (T));
8976 C := First_Elmt (Stored_Constraint (T));
8977 while Present (D) and then Present (C) loop
8978 if Chars (Discrim_Name) = Chars (D) then
8979 if Is_Entity_Name (Node (C))
8980 and then Entity (Node (C)) = Entity (Discrim)
8981 then
8982 -- D is renamed by Discrim, whose value is
8983 -- given in Assoc.
8984
8985 null;
8986
8987 else
8988 Assoc :=
8989 Make_Component_Association (Sloc (Typ),
8990 New_List
8991 (New_Occurrence_Of (D, Sloc (Typ))),
8992 Duplicate_Subexpr_No_Checks (Node (C)));
8993 end if;
8994
8995 exit Find_Constraint;
8996 end if;
8997
8998 Next_Discriminant (D);
8999 Next_Elmt (C);
9000 end loop;
9001 end if;
9002
9003 -- Discriminant may be inherited from ancestor
9004
9005 T := Etype (T);
9006 end loop;
9007 end;
9008 end if;
9009 end if;
9010
9011 if No (Next (Assoc)) then
9012 Error_Msg_NE
9013 (" missing value for discriminant&",
9014 First (Governed_By), Discrim_Name);
9015
9016 Report_Errors := True;
9017 return;
9018 end if;
9019
9020 Next (Assoc);
9021 end loop Find_Constraint;
9022
9023 Discrim_Value := Expression (Assoc);
9024
9025 if not Is_OK_Static_Expression (Discrim_Value) then
9026
9027 -- If the variant part is governed by a discriminant of the type
9028 -- this is an error. If the variant part and the discriminant are
9029 -- inherited from an ancestor this is legal (AI05-120) unless the
9030 -- components are being gathered for an aggregate, in which case
9031 -- the caller must check Report_Errors.
9032
9033 if Scope (Original_Record_Component
9034 ((Entity (First (Choices (Assoc)))))) = Typ
9035 then
9036 Error_Msg_FE
9037 ("value for discriminant & must be static!",
9038 Discrim_Value, Discrim);
9039 Why_Not_Static (Discrim_Value);
9040 end if;
9041
9042 Report_Errors := True;
9043 return;
9044 end if;
9045
9046 Search_For_Discriminant_Value : declare
9047 Low : Node_Id;
9048 High : Node_Id;
9049
9050 UI_High : Uint;
9051 UI_Low : Uint;
9052 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
9053
9054 begin
9055 Find_Discrete_Value : while Present (Variant) loop
9056
9057 -- If a choice is a subtype with a static predicate, it must
9058 -- be rewritten as an explicit list of non-predicated choices.
9059
9060 Expand_Static_Predicates_In_Choices (Variant);
9061
9062 Discrete_Choice := First (Discrete_Choices (Variant));
9063 while Present (Discrete_Choice) loop
9064 exit Find_Discrete_Value when
9065 Nkind (Discrete_Choice) = N_Others_Choice;
9066
9067 Get_Index_Bounds (Discrete_Choice, Low, High);
9068
9069 UI_Low := Expr_Value (Low);
9070 UI_High := Expr_Value (High);
9071
9072 exit Find_Discrete_Value when
9073 UI_Low <= UI_Discrim_Value
9074 and then
9075 UI_High >= UI_Discrim_Value;
9076
9077 Next (Discrete_Choice);
9078 end loop;
9079
9080 Next_Non_Pragma (Variant);
9081 end loop Find_Discrete_Value;
9082 end Search_For_Discriminant_Value;
9083
9084 -- The case statement must include a variant that corresponds to the
9085 -- value of the discriminant, unless the discriminant type has a
9086 -- static predicate. In that case the absence of an others_choice that
9087 -- would cover this value becomes a run-time error (3.8,1 (21.1/2)).
9088
9089 if No (Variant)
9090 and then not Has_Static_Predicate (Etype (Discrim_Name))
9091 then
9092 Error_Msg_NE
9093 ("value of discriminant & is out of range", Discrim_Value, Discrim);
9094 Report_Errors := True;
9095 return;
9096 end if;
9097
9098 -- If we have found the corresponding choice, recursively add its
9099 -- components to the Into list. The nested components are part of
9100 -- the same record type.
9101
9102 if Present (Variant) then
9103 Gather_Components
9104 (Typ, Component_List (Variant), Governed_By, Into, Report_Errors);
9105 end if;
9106 end Gather_Components;
9107
9108 ------------------------
9109 -- Get_Actual_Subtype --
9110 ------------------------
9111
9112 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
9113 Typ : constant Entity_Id := Etype (N);
9114 Utyp : Entity_Id := Underlying_Type (Typ);
9115 Decl : Node_Id;
9116 Atyp : Entity_Id;
9117
9118 begin
9119 if No (Utyp) then
9120 Utyp := Typ;
9121 end if;
9122
9123 -- If what we have is an identifier that references a subprogram
9124 -- formal, or a variable or constant object, then we get the actual
9125 -- subtype from the referenced entity if one has been built.
9126
9127 if Nkind (N) = N_Identifier
9128 and then
9129 (Is_Formal (Entity (N))
9130 or else Ekind (Entity (N)) = E_Constant
9131 or else Ekind (Entity (N)) = E_Variable)
9132 and then Present (Actual_Subtype (Entity (N)))
9133 then
9134 return Actual_Subtype (Entity (N));
9135
9136 -- Actual subtype of unchecked union is always itself. We never need
9137 -- the "real" actual subtype. If we did, we couldn't get it anyway
9138 -- because the discriminant is not available. The restrictions on
9139 -- Unchecked_Union are designed to make sure that this is OK.
9140
9141 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
9142 return Typ;
9143
9144 -- Here for the unconstrained case, we must find actual subtype
9145 -- No actual subtype is available, so we must build it on the fly.
9146
9147 -- Checking the type, not the underlying type, for constrainedness
9148 -- seems to be necessary. Maybe all the tests should be on the type???
9149
9150 elsif (not Is_Constrained (Typ))
9151 and then (Is_Array_Type (Utyp)
9152 or else (Is_Record_Type (Utyp)
9153 and then Has_Discriminants (Utyp)))
9154 and then not Has_Unknown_Discriminants (Utyp)
9155 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
9156 then
9157 -- Nothing to do if in spec expression (why not???)
9158
9159 if In_Spec_Expression then
9160 return Typ;
9161
9162 elsif Is_Private_Type (Typ) and then not Has_Discriminants (Typ) then
9163
9164 -- If the type has no discriminants, there is no subtype to
9165 -- build, even if the underlying type is discriminated.
9166
9167 return Typ;
9168
9169 -- Else build the actual subtype
9170
9171 else
9172 Decl := Build_Actual_Subtype (Typ, N);
9173
9174 -- The call may yield a declaration, or just return the entity
9175
9176 if Decl = Typ then
9177 return Typ;
9178 end if;
9179
9180 Atyp := Defining_Identifier (Decl);
9181
9182 -- If Build_Actual_Subtype generated a new declaration then use it
9183
9184 if Atyp /= Typ then
9185
9186 -- The actual subtype is an Itype, so analyze the declaration,
9187 -- but do not attach it to the tree, to get the type defined.
9188
9189 Set_Parent (Decl, N);
9190 Set_Is_Itype (Atyp);
9191 Analyze (Decl, Suppress => All_Checks);
9192 Set_Associated_Node_For_Itype (Atyp, N);
9193 Set_Has_Delayed_Freeze (Atyp, False);
9194
9195 -- We need to freeze the actual subtype immediately. This is
9196 -- needed, because otherwise this Itype will not get frozen
9197 -- at all, and it is always safe to freeze on creation because
9198 -- any associated types must be frozen at this point.
9199
9200 Freeze_Itype (Atyp, N);
9201 return Atyp;
9202
9203 -- Otherwise we did not build a declaration, so return original
9204
9205 else
9206 return Typ;
9207 end if;
9208 end if;
9209
9210 -- For all remaining cases, the actual subtype is the same as
9211 -- the nominal type.
9212
9213 else
9214 return Typ;
9215 end if;
9216 end Get_Actual_Subtype;
9217
9218 -------------------------------------
9219 -- Get_Actual_Subtype_If_Available --
9220 -------------------------------------
9221
9222 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
9223 Typ : constant Entity_Id := Etype (N);
9224
9225 begin
9226 -- If what we have is an identifier that references a subprogram
9227 -- formal, or a variable or constant object, then we get the actual
9228 -- subtype from the referenced entity if one has been built.
9229
9230 if Nkind (N) = N_Identifier
9231 and then
9232 (Is_Formal (Entity (N))
9233 or else Ekind (Entity (N)) = E_Constant
9234 or else Ekind (Entity (N)) = E_Variable)
9235 and then Present (Actual_Subtype (Entity (N)))
9236 then
9237 return Actual_Subtype (Entity (N));
9238
9239 -- Otherwise the Etype of N is returned unchanged
9240
9241 else
9242 return Typ;
9243 end if;
9244 end Get_Actual_Subtype_If_Available;
9245
9246 ------------------------
9247 -- Get_Body_From_Stub --
9248 ------------------------
9249
9250 function Get_Body_From_Stub (N : Node_Id) return Node_Id is
9251 begin
9252 return Proper_Body (Unit (Library_Unit (N)));
9253 end Get_Body_From_Stub;
9254
9255 ---------------------
9256 -- Get_Cursor_Type --
9257 ---------------------
9258
9259 function Get_Cursor_Type
9260 (Aspect : Node_Id;
9261 Typ : Entity_Id) return Entity_Id
9262 is
9263 Assoc : Node_Id;
9264 Func : Entity_Id;
9265 First_Op : Entity_Id;
9266 Cursor : Entity_Id;
9267
9268 begin
9269 -- If error already detected, return
9270
9271 if Error_Posted (Aspect) then
9272 return Any_Type;
9273 end if;
9274
9275 -- The cursor type for an Iterable aspect is the return type of a
9276 -- non-overloaded First primitive operation. Locate association for
9277 -- First.
9278
9279 Assoc := First (Component_Associations (Expression (Aspect)));
9280 First_Op := Any_Id;
9281 while Present (Assoc) loop
9282 if Chars (First (Choices (Assoc))) = Name_First then
9283 First_Op := Expression (Assoc);
9284 exit;
9285 end if;
9286
9287 Next (Assoc);
9288 end loop;
9289
9290 if First_Op = Any_Id then
9291 Error_Msg_N ("aspect Iterable must specify First operation", Aspect);
9292 return Any_Type;
9293
9294 elsif not Analyzed (First_Op) then
9295 Analyze (First_Op);
9296 end if;
9297
9298 Cursor := Any_Type;
9299
9300 -- Locate function with desired name and profile in scope of type
9301 -- In the rare case where the type is an integer type, a base type
9302 -- is created for it, check that the base type of the first formal
9303 -- of First matches the base type of the domain.
9304
9305 Func := First_Entity (Scope (Typ));
9306 while Present (Func) loop
9307 if Chars (Func) = Chars (First_Op)
9308 and then Ekind (Func) = E_Function
9309 and then Present (First_Formal (Func))
9310 and then Base_Type (Etype (First_Formal (Func))) = Base_Type (Typ)
9311 and then No (Next_Formal (First_Formal (Func)))
9312 then
9313 if Cursor /= Any_Type then
9314 Error_Msg_N
9315 ("Operation First for iterable type must be unique", Aspect);
9316 return Any_Type;
9317 else
9318 Cursor := Etype (Func);
9319 end if;
9320 end if;
9321
9322 Next_Entity (Func);
9323 end loop;
9324
9325 -- If not found, no way to resolve remaining primitives
9326
9327 if Cursor = Any_Type then
9328 Error_Msg_N
9329 ("primitive operation for Iterable type must appear in the same "
9330 & "list of declarations as the type", Aspect);
9331 end if;
9332
9333 return Cursor;
9334 end Get_Cursor_Type;
9335
9336 function Get_Cursor_Type (Typ : Entity_Id) return Entity_Id is
9337 begin
9338 return Etype (Get_Iterable_Type_Primitive (Typ, Name_First));
9339 end Get_Cursor_Type;
9340
9341 -------------------------------
9342 -- Get_Default_External_Name --
9343 -------------------------------
9344
9345 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
9346 begin
9347 Get_Decoded_Name_String (Chars (E));
9348
9349 if Opt.External_Name_Imp_Casing = Uppercase then
9350 Set_Casing (All_Upper_Case);
9351 else
9352 Set_Casing (All_Lower_Case);
9353 end if;
9354
9355 return
9356 Make_String_Literal (Sloc (E),
9357 Strval => String_From_Name_Buffer);
9358 end Get_Default_External_Name;
9359
9360 --------------------------
9361 -- Get_Enclosing_Object --
9362 --------------------------
9363
9364 function Get_Enclosing_Object (N : Node_Id) return Entity_Id is
9365 begin
9366 if Is_Entity_Name (N) then
9367 return Entity (N);
9368 else
9369 case Nkind (N) is
9370 when N_Indexed_Component
9371 | N_Selected_Component
9372 | N_Slice
9373 =>
9374 -- If not generating code, a dereference may be left implicit.
9375 -- In thoses cases, return Empty.
9376
9377 if Is_Access_Type (Etype (Prefix (N))) then
9378 return Empty;
9379 else
9380 return Get_Enclosing_Object (Prefix (N));
9381 end if;
9382
9383 when N_Type_Conversion =>
9384 return Get_Enclosing_Object (Expression (N));
9385
9386 when others =>
9387 return Empty;
9388 end case;
9389 end if;
9390 end Get_Enclosing_Object;
9391
9392 ---------------------------
9393 -- Get_Enum_Lit_From_Pos --
9394 ---------------------------
9395
9396 function Get_Enum_Lit_From_Pos
9397 (T : Entity_Id;
9398 Pos : Uint;
9399 Loc : Source_Ptr) return Node_Id
9400 is
9401 Btyp : Entity_Id := Base_Type (T);
9402 Lit : Node_Id;
9403 LLoc : Source_Ptr;
9404
9405 begin
9406 -- In the case where the literal is of type Character, Wide_Character
9407 -- or Wide_Wide_Character or of a type derived from them, there needs
9408 -- to be some special handling since there is no explicit chain of
9409 -- literals to search. Instead, an N_Character_Literal node is created
9410 -- with the appropriate Char_Code and Chars fields.
9411
9412 if Is_Standard_Character_Type (T) then
9413 Set_Character_Literal_Name (UI_To_CC (Pos));
9414
9415 return
9416 Make_Character_Literal (Loc,
9417 Chars => Name_Find,
9418 Char_Literal_Value => Pos);
9419
9420 -- For all other cases, we have a complete table of literals, and
9421 -- we simply iterate through the chain of literal until the one
9422 -- with the desired position value is found.
9423
9424 else
9425 if Is_Private_Type (Btyp) and then Present (Full_View (Btyp)) then
9426 Btyp := Full_View (Btyp);
9427 end if;
9428
9429 Lit := First_Literal (Btyp);
9430
9431 -- Position in the enumeration type starts at 0
9432
9433 if UI_To_Int (Pos) < 0 then
9434 raise Constraint_Error;
9435 end if;
9436
9437 for J in 1 .. UI_To_Int (Pos) loop
9438 Next_Literal (Lit);
9439
9440 -- If Lit is Empty, Pos is not in range, so raise Constraint_Error
9441 -- inside the loop to avoid calling Next_Literal on Empty.
9442
9443 if No (Lit) then
9444 raise Constraint_Error;
9445 end if;
9446 end loop;
9447
9448 -- Create a new node from Lit, with source location provided by Loc
9449 -- if not equal to No_Location, or by copying the source location of
9450 -- Lit otherwise.
9451
9452 LLoc := Loc;
9453
9454 if LLoc = No_Location then
9455 LLoc := Sloc (Lit);
9456 end if;
9457
9458 return New_Occurrence_Of (Lit, LLoc);
9459 end if;
9460 end Get_Enum_Lit_From_Pos;
9461
9462 ------------------------
9463 -- Get_Generic_Entity --
9464 ------------------------
9465
9466 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
9467 Ent : constant Entity_Id := Entity (Name (N));
9468 begin
9469 if Present (Renamed_Object (Ent)) then
9470 return Renamed_Object (Ent);
9471 else
9472 return Ent;
9473 end if;
9474 end Get_Generic_Entity;
9475
9476 -------------------------------------
9477 -- Get_Incomplete_View_Of_Ancestor --
9478 -------------------------------------
9479
9480 function Get_Incomplete_View_Of_Ancestor (E : Entity_Id) return Entity_Id is
9481 Cur_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
9482 Par_Scope : Entity_Id;
9483 Par_Type : Entity_Id;
9484
9485 begin
9486 -- The incomplete view of an ancestor is only relevant for private
9487 -- derived types in child units.
9488
9489 if not Is_Derived_Type (E)
9490 or else not Is_Child_Unit (Cur_Unit)
9491 then
9492 return Empty;
9493
9494 else
9495 Par_Scope := Scope (Cur_Unit);
9496 if No (Par_Scope) then
9497 return Empty;
9498 end if;
9499
9500 Par_Type := Etype (Base_Type (E));
9501
9502 -- Traverse list of ancestor types until we find one declared in
9503 -- a parent or grandparent unit (two levels seem sufficient).
9504
9505 while Present (Par_Type) loop
9506 if Scope (Par_Type) = Par_Scope
9507 or else Scope (Par_Type) = Scope (Par_Scope)
9508 then
9509 return Par_Type;
9510
9511 elsif not Is_Derived_Type (Par_Type) then
9512 return Empty;
9513
9514 else
9515 Par_Type := Etype (Base_Type (Par_Type));
9516 end if;
9517 end loop;
9518
9519 -- If none found, there is no relevant ancestor type.
9520
9521 return Empty;
9522 end if;
9523 end Get_Incomplete_View_Of_Ancestor;
9524
9525 ----------------------
9526 -- Get_Index_Bounds --
9527 ----------------------
9528
9529 procedure Get_Index_Bounds
9530 (N : Node_Id;
9531 L : out Node_Id;
9532 H : out Node_Id;
9533 Use_Full_View : Boolean := False)
9534 is
9535 function Scalar_Range_Of_Type (Typ : Entity_Id) return Node_Id;
9536 -- Obtain the scalar range of type Typ. If flag Use_Full_View is set and
9537 -- Typ qualifies, the scalar range is obtained from the full view of the
9538 -- type.
9539
9540 --------------------------
9541 -- Scalar_Range_Of_Type --
9542 --------------------------
9543
9544 function Scalar_Range_Of_Type (Typ : Entity_Id) return Node_Id is
9545 T : Entity_Id := Typ;
9546
9547 begin
9548 if Use_Full_View and then Present (Full_View (T)) then
9549 T := Full_View (T);
9550 end if;
9551
9552 return Scalar_Range (T);
9553 end Scalar_Range_Of_Type;
9554
9555 -- Local variables
9556
9557 Kind : constant Node_Kind := Nkind (N);
9558 Rng : Node_Id;
9559
9560 -- Start of processing for Get_Index_Bounds
9561
9562 begin
9563 if Kind = N_Range then
9564 L := Low_Bound (N);
9565 H := High_Bound (N);
9566
9567 elsif Kind = N_Subtype_Indication then
9568 Rng := Range_Expression (Constraint (N));
9569
9570 if Rng = Error then
9571 L := Error;
9572 H := Error;
9573 return;
9574
9575 else
9576 L := Low_Bound (Range_Expression (Constraint (N)));
9577 H := High_Bound (Range_Expression (Constraint (N)));
9578 end if;
9579
9580 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
9581 Rng := Scalar_Range_Of_Type (Entity (N));
9582
9583 if Error_Posted (Rng) then
9584 L := Error;
9585 H := Error;
9586
9587 elsif Nkind (Rng) = N_Subtype_Indication then
9588 Get_Index_Bounds (Rng, L, H);
9589
9590 else
9591 L := Low_Bound (Rng);
9592 H := High_Bound (Rng);
9593 end if;
9594
9595 else
9596 -- N is an expression, indicating a range with one value
9597
9598 L := N;
9599 H := N;
9600 end if;
9601 end Get_Index_Bounds;
9602
9603 -----------------------------
9604 -- Get_Interfacing_Aspects --
9605 -----------------------------
9606
9607 procedure Get_Interfacing_Aspects
9608 (Iface_Asp : Node_Id;
9609 Conv_Asp : out Node_Id;
9610 EN_Asp : out Node_Id;
9611 Expo_Asp : out Node_Id;
9612 Imp_Asp : out Node_Id;
9613 LN_Asp : out Node_Id;
9614 Do_Checks : Boolean := False)
9615 is
9616 procedure Save_Or_Duplication_Error
9617 (Asp : Node_Id;
9618 To : in out Node_Id);
9619 -- Save the value of aspect Asp in node To. If To already has a value,
9620 -- then this is considered a duplicate use of aspect. Emit an error if
9621 -- flag Do_Checks is set.
9622
9623 -------------------------------
9624 -- Save_Or_Duplication_Error --
9625 -------------------------------
9626
9627 procedure Save_Or_Duplication_Error
9628 (Asp : Node_Id;
9629 To : in out Node_Id)
9630 is
9631 begin
9632 -- Detect an extra aspect and issue an error
9633
9634 if Present (To) then
9635 if Do_Checks then
9636 Error_Msg_Name_1 := Chars (Identifier (Asp));
9637 Error_Msg_Sloc := Sloc (To);
9638 Error_Msg_N ("aspect % previously given #", Asp);
9639 end if;
9640
9641 -- Otherwise capture the aspect
9642
9643 else
9644 To := Asp;
9645 end if;
9646 end Save_Or_Duplication_Error;
9647
9648 -- Local variables
9649
9650 Asp : Node_Id;
9651 Asp_Id : Aspect_Id;
9652
9653 -- The following variables capture each individual aspect
9654
9655 Conv : Node_Id := Empty;
9656 EN : Node_Id := Empty;
9657 Expo : Node_Id := Empty;
9658 Imp : Node_Id := Empty;
9659 LN : Node_Id := Empty;
9660
9661 -- Start of processing for Get_Interfacing_Aspects
9662
9663 begin
9664 -- The input interfacing aspect should reside in an aspect specification
9665 -- list.
9666
9667 pragma Assert (Is_List_Member (Iface_Asp));
9668
9669 -- Examine the aspect specifications of the related entity. Find and
9670 -- capture all interfacing aspects. Detect duplicates and emit errors
9671 -- if applicable.
9672
9673 Asp := First (List_Containing (Iface_Asp));
9674 while Present (Asp) loop
9675 Asp_Id := Get_Aspect_Id (Asp);
9676
9677 if Asp_Id = Aspect_Convention then
9678 Save_Or_Duplication_Error (Asp, Conv);
9679
9680 elsif Asp_Id = Aspect_External_Name then
9681 Save_Or_Duplication_Error (Asp, EN);
9682
9683 elsif Asp_Id = Aspect_Export then
9684 Save_Or_Duplication_Error (Asp, Expo);
9685
9686 elsif Asp_Id = Aspect_Import then
9687 Save_Or_Duplication_Error (Asp, Imp);
9688
9689 elsif Asp_Id = Aspect_Link_Name then
9690 Save_Or_Duplication_Error (Asp, LN);
9691 end if;
9692
9693 Next (Asp);
9694 end loop;
9695
9696 Conv_Asp := Conv;
9697 EN_Asp := EN;
9698 Expo_Asp := Expo;
9699 Imp_Asp := Imp;
9700 LN_Asp := LN;
9701 end Get_Interfacing_Aspects;
9702
9703 ---------------------------------
9704 -- Get_Iterable_Type_Primitive --
9705 ---------------------------------
9706
9707 function Get_Iterable_Type_Primitive
9708 (Typ : Entity_Id;
9709 Nam : Name_Id) return Entity_Id
9710 is
9711 Funcs : constant Node_Id := Find_Value_Of_Aspect (Typ, Aspect_Iterable);
9712 Assoc : Node_Id;
9713
9714 begin
9715 if No (Funcs) then
9716 return Empty;
9717
9718 else
9719 Assoc := First (Component_Associations (Funcs));
9720 while Present (Assoc) loop
9721 if Chars (First (Choices (Assoc))) = Nam then
9722 return Entity (Expression (Assoc));
9723 end if;
9724
9725 Assoc := Next (Assoc);
9726 end loop;
9727
9728 return Empty;
9729 end if;
9730 end Get_Iterable_Type_Primitive;
9731
9732 ----------------------------------
9733 -- Get_Library_Unit_Name_String --
9734 ----------------------------------
9735
9736 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
9737 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
9738
9739 begin
9740 Get_Unit_Name_String (Unit_Name_Id);
9741
9742 -- Remove seven last character (" (spec)" or " (body)")
9743
9744 Name_Len := Name_Len - 7;
9745 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
9746 end Get_Library_Unit_Name_String;
9747
9748 --------------------------
9749 -- Get_Max_Queue_Length --
9750 --------------------------
9751
9752 function Get_Max_Queue_Length (Id : Entity_Id) return Uint is
9753 pragma Assert (Is_Entry (Id));
9754 Prag : constant Entity_Id := Get_Pragma (Id, Pragma_Max_Queue_Length);
9755 Max : Uint;
9756
9757 begin
9758 -- A value of 0 or -1 represents no maximum specified, and entries and
9759 -- entry families with no Max_Queue_Length aspect or pragma default to
9760 -- it.
9761
9762 if not Present (Prag) then
9763 return Uint_0;
9764 end if;
9765
9766 Max := Expr_Value
9767 (Expression (First (Pragma_Argument_Associations (Prag))));
9768
9769 -- Since -1 and 0 are equivalent, return 0 for instances of -1 for
9770 -- uniformity.
9771
9772 if Max = -1 then
9773 return Uint_0;
9774 end if;
9775
9776 return Max;
9777 end Get_Max_Queue_Length;
9778
9779 ------------------------
9780 -- Get_Name_Entity_Id --
9781 ------------------------
9782
9783 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
9784 begin
9785 return Entity_Id (Get_Name_Table_Int (Id));
9786 end Get_Name_Entity_Id;
9787
9788 ------------------------------
9789 -- Get_Name_From_CTC_Pragma --
9790 ------------------------------
9791
9792 function Get_Name_From_CTC_Pragma (N : Node_Id) return String_Id is
9793 Arg : constant Node_Id :=
9794 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
9795 begin
9796 return Strval (Expr_Value_S (Arg));
9797 end Get_Name_From_CTC_Pragma;
9798
9799 -----------------------
9800 -- Get_Parent_Entity --
9801 -----------------------
9802
9803 function Get_Parent_Entity (Unit : Node_Id) return Entity_Id is
9804 begin
9805 if Nkind (Unit) = N_Package_Body
9806 and then Nkind (Original_Node (Unit)) = N_Package_Instantiation
9807 then
9808 return Defining_Entity
9809 (Specification (Instance_Spec (Original_Node (Unit))));
9810 elsif Nkind (Unit) = N_Package_Instantiation then
9811 return Defining_Entity (Specification (Instance_Spec (Unit)));
9812 else
9813 return Defining_Entity (Unit);
9814 end if;
9815 end Get_Parent_Entity;
9816
9817 -------------------
9818 -- Get_Pragma_Id --
9819 -------------------
9820
9821 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
9822 begin
9823 return Get_Pragma_Id (Pragma_Name_Unmapped (N));
9824 end Get_Pragma_Id;
9825
9826 ------------------------
9827 -- Get_Qualified_Name --
9828 ------------------------
9829
9830 function Get_Qualified_Name
9831 (Id : Entity_Id;
9832 Suffix : Entity_Id := Empty) return Name_Id
9833 is
9834 Suffix_Nam : Name_Id := No_Name;
9835
9836 begin
9837 if Present (Suffix) then
9838 Suffix_Nam := Chars (Suffix);
9839 end if;
9840
9841 return Get_Qualified_Name (Chars (Id), Suffix_Nam, Scope (Id));
9842 end Get_Qualified_Name;
9843
9844 function Get_Qualified_Name
9845 (Nam : Name_Id;
9846 Suffix : Name_Id := No_Name;
9847 Scop : Entity_Id := Current_Scope) return Name_Id
9848 is
9849 procedure Add_Scope (S : Entity_Id);
9850 -- Add the fully qualified form of scope S to the name buffer. The
9851 -- format is:
9852 -- s-1__s__
9853
9854 ---------------
9855 -- Add_Scope --
9856 ---------------
9857
9858 procedure Add_Scope (S : Entity_Id) is
9859 begin
9860 if S = Empty then
9861 null;
9862
9863 elsif S = Standard_Standard then
9864 null;
9865
9866 else
9867 Add_Scope (Scope (S));
9868 Get_Name_String_And_Append (Chars (S));
9869 Add_Str_To_Name_Buffer ("__");
9870 end if;
9871 end Add_Scope;
9872
9873 -- Start of processing for Get_Qualified_Name
9874
9875 begin
9876 Name_Len := 0;
9877 Add_Scope (Scop);
9878
9879 -- Append the base name after all scopes have been chained
9880
9881 Get_Name_String_And_Append (Nam);
9882
9883 -- Append the suffix (if present)
9884
9885 if Suffix /= No_Name then
9886 Add_Str_To_Name_Buffer ("__");
9887 Get_Name_String_And_Append (Suffix);
9888 end if;
9889
9890 return Name_Find;
9891 end Get_Qualified_Name;
9892
9893 -----------------------
9894 -- Get_Reason_String --
9895 -----------------------
9896
9897 procedure Get_Reason_String (N : Node_Id) is
9898 begin
9899 if Nkind (N) = N_String_Literal then
9900 Store_String_Chars (Strval (N));
9901
9902 elsif Nkind (N) = N_Op_Concat then
9903 Get_Reason_String (Left_Opnd (N));
9904 Get_Reason_String (Right_Opnd (N));
9905
9906 -- If not of required form, error
9907
9908 else
9909 Error_Msg_N
9910 ("Reason for pragma Warnings has wrong form", N);
9911 Error_Msg_N
9912 ("\must be string literal or concatenation of string literals", N);
9913 return;
9914 end if;
9915 end Get_Reason_String;
9916
9917 --------------------------------
9918 -- Get_Reference_Discriminant --
9919 --------------------------------
9920
9921 function Get_Reference_Discriminant (Typ : Entity_Id) return Entity_Id is
9922 D : Entity_Id;
9923
9924 begin
9925 D := First_Discriminant (Typ);
9926 while Present (D) loop
9927 if Has_Implicit_Dereference (D) then
9928 return D;
9929 end if;
9930 Next_Discriminant (D);
9931 end loop;
9932
9933 return Empty;
9934 end Get_Reference_Discriminant;
9935
9936 ---------------------------
9937 -- Get_Referenced_Object --
9938 ---------------------------
9939
9940 function Get_Referenced_Object (N : Node_Id) return Node_Id is
9941 R : Node_Id;
9942
9943 begin
9944 R := N;
9945 while Is_Entity_Name (R)
9946 and then Present (Renamed_Object (Entity (R)))
9947 loop
9948 R := Renamed_Object (Entity (R));
9949 end loop;
9950
9951 return R;
9952 end Get_Referenced_Object;
9953
9954 ------------------------
9955 -- Get_Renamed_Entity --
9956 ------------------------
9957
9958 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
9959 R : Entity_Id;
9960
9961 begin
9962 R := E;
9963 while Present (Renamed_Entity (R)) loop
9964 R := Renamed_Entity (R);
9965 end loop;
9966
9967 return R;
9968 end Get_Renamed_Entity;
9969
9970 -----------------------
9971 -- Get_Return_Object --
9972 -----------------------
9973
9974 function Get_Return_Object (N : Node_Id) return Entity_Id is
9975 Decl : Node_Id;
9976
9977 begin
9978 Decl := First (Return_Object_Declarations (N));
9979 while Present (Decl) loop
9980 exit when Nkind (Decl) = N_Object_Declaration
9981 and then Is_Return_Object (Defining_Identifier (Decl));
9982 Next (Decl);
9983 end loop;
9984
9985 pragma Assert (Present (Decl));
9986 return Defining_Identifier (Decl);
9987 end Get_Return_Object;
9988
9989 ---------------------------
9990 -- Get_Subprogram_Entity --
9991 ---------------------------
9992
9993 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
9994 Subp : Node_Id;
9995 Subp_Id : Entity_Id;
9996
9997 begin
9998 if Nkind (Nod) = N_Accept_Statement then
9999 Subp := Entry_Direct_Name (Nod);
10000
10001 elsif Nkind (Nod) = N_Slice then
10002 Subp := Prefix (Nod);
10003
10004 else
10005 Subp := Name (Nod);
10006 end if;
10007
10008 -- Strip the subprogram call
10009
10010 loop
10011 if Nkind_In (Subp, N_Explicit_Dereference,
10012 N_Indexed_Component,
10013 N_Selected_Component)
10014 then
10015 Subp := Prefix (Subp);
10016
10017 elsif Nkind_In (Subp, N_Type_Conversion,
10018 N_Unchecked_Type_Conversion)
10019 then
10020 Subp := Expression (Subp);
10021
10022 else
10023 exit;
10024 end if;
10025 end loop;
10026
10027 -- Extract the entity of the subprogram call
10028
10029 if Is_Entity_Name (Subp) then
10030 Subp_Id := Entity (Subp);
10031
10032 if Ekind (Subp_Id) = E_Access_Subprogram_Type then
10033 Subp_Id := Directly_Designated_Type (Subp_Id);
10034 end if;
10035
10036 if Is_Subprogram (Subp_Id) then
10037 return Subp_Id;
10038 else
10039 return Empty;
10040 end if;
10041
10042 -- The search did not find a construct that denotes a subprogram
10043
10044 else
10045 return Empty;
10046 end if;
10047 end Get_Subprogram_Entity;
10048
10049 -----------------------------
10050 -- Get_Task_Body_Procedure --
10051 -----------------------------
10052
10053 function Get_Task_Body_Procedure (E : Entity_Id) return Entity_Id is
10054 begin
10055 -- Note: A task type may be the completion of a private type with
10056 -- discriminants. When performing elaboration checks on a task
10057 -- declaration, the current view of the type may be the private one,
10058 -- and the procedure that holds the body of the task is held in its
10059 -- underlying type.
10060
10061 -- This is an odd function, why not have Task_Body_Procedure do
10062 -- the following digging???
10063
10064 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
10065 end Get_Task_Body_Procedure;
10066
10067 -------------------------
10068 -- Get_User_Defined_Eq --
10069 -------------------------
10070
10071 function Get_User_Defined_Eq (E : Entity_Id) return Entity_Id is
10072 Prim : Elmt_Id;
10073 Op : Entity_Id;
10074
10075 begin
10076 Prim := First_Elmt (Collect_Primitive_Operations (E));
10077 while Present (Prim) loop
10078 Op := Node (Prim);
10079
10080 if Chars (Op) = Name_Op_Eq
10081 and then Etype (Op) = Standard_Boolean
10082 and then Etype (First_Formal (Op)) = E
10083 and then Etype (Next_Formal (First_Formal (Op))) = E
10084 then
10085 return Op;
10086 end if;
10087
10088 Next_Elmt (Prim);
10089 end loop;
10090
10091 return Empty;
10092 end Get_User_Defined_Eq;
10093
10094 ---------------
10095 -- Get_Views --
10096 ---------------
10097
10098 procedure Get_Views
10099 (Typ : Entity_Id;
10100 Priv_Typ : out Entity_Id;
10101 Full_Typ : out Entity_Id;
10102 Full_Base : out Entity_Id;
10103 CRec_Typ : out Entity_Id)
10104 is
10105 IP_View : Entity_Id;
10106
10107 begin
10108 -- Assume that none of the views can be recovered
10109
10110 Priv_Typ := Empty;
10111 Full_Typ := Empty;
10112 Full_Base := Empty;
10113 CRec_Typ := Empty;
10114
10115 -- The input type is the corresponding record type of a protected or a
10116 -- task type.
10117
10118 if Ekind (Typ) = E_Record_Type
10119 and then Is_Concurrent_Record_Type (Typ)
10120 then
10121 CRec_Typ := Typ;
10122 Full_Typ := Corresponding_Concurrent_Type (CRec_Typ);
10123 Full_Base := Base_Type (Full_Typ);
10124 Priv_Typ := Incomplete_Or_Partial_View (Full_Typ);
10125
10126 -- Otherwise the input type denotes an arbitrary type
10127
10128 else
10129 IP_View := Incomplete_Or_Partial_View (Typ);
10130
10131 -- The input type denotes the full view of a private type
10132
10133 if Present (IP_View) then
10134 Priv_Typ := IP_View;
10135 Full_Typ := Typ;
10136
10137 -- The input type is a private type
10138
10139 elsif Is_Private_Type (Typ) then
10140 Priv_Typ := Typ;
10141 Full_Typ := Full_View (Priv_Typ);
10142
10143 -- Otherwise the input type does not have any views
10144
10145 else
10146 Full_Typ := Typ;
10147 end if;
10148
10149 if Present (Full_Typ) then
10150 Full_Base := Base_Type (Full_Typ);
10151
10152 if Ekind_In (Full_Typ, E_Protected_Type, E_Task_Type) then
10153 CRec_Typ := Corresponding_Record_Type (Full_Typ);
10154 end if;
10155 end if;
10156 end if;
10157 end Get_Views;
10158
10159 -----------------------
10160 -- Has_Access_Values --
10161 -----------------------
10162
10163 function Has_Access_Values (T : Entity_Id) return Boolean is
10164 Typ : constant Entity_Id := Underlying_Type (T);
10165
10166 begin
10167 -- Case of a private type which is not completed yet. This can only
10168 -- happen in the case of a generic format type appearing directly, or
10169 -- as a component of the type to which this function is being applied
10170 -- at the top level. Return False in this case, since we certainly do
10171 -- not know that the type contains access types.
10172
10173 if No (Typ) then
10174 return False;
10175
10176 elsif Is_Access_Type (Typ) then
10177 return True;
10178
10179 elsif Is_Array_Type (Typ) then
10180 return Has_Access_Values (Component_Type (Typ));
10181
10182 elsif Is_Record_Type (Typ) then
10183 declare
10184 Comp : Entity_Id;
10185
10186 begin
10187 -- Loop to Check components
10188
10189 Comp := First_Component_Or_Discriminant (Typ);
10190 while Present (Comp) loop
10191
10192 -- Check for access component, tag field does not count, even
10193 -- though it is implemented internally using an access type.
10194
10195 if Has_Access_Values (Etype (Comp))
10196 and then Chars (Comp) /= Name_uTag
10197 then
10198 return True;
10199 end if;
10200
10201 Next_Component_Or_Discriminant (Comp);
10202 end loop;
10203 end;
10204
10205 return False;
10206
10207 else
10208 return False;
10209 end if;
10210 end Has_Access_Values;
10211
10212 ------------------------------
10213 -- Has_Compatible_Alignment --
10214 ------------------------------
10215
10216 function Has_Compatible_Alignment
10217 (Obj : Entity_Id;
10218 Expr : Node_Id;
10219 Layout_Done : Boolean) return Alignment_Result
10220 is
10221 function Has_Compatible_Alignment_Internal
10222 (Obj : Entity_Id;
10223 Expr : Node_Id;
10224 Layout_Done : Boolean;
10225 Default : Alignment_Result) return Alignment_Result;
10226 -- This is the internal recursive function that actually does the work.
10227 -- There is one additional parameter, which says what the result should
10228 -- be if no alignment information is found, and there is no definite
10229 -- indication of compatible alignments. At the outer level, this is set
10230 -- to Unknown, but for internal recursive calls in the case where types
10231 -- are known to be correct, it is set to Known_Compatible.
10232
10233 ---------------------------------------
10234 -- Has_Compatible_Alignment_Internal --
10235 ---------------------------------------
10236
10237 function Has_Compatible_Alignment_Internal
10238 (Obj : Entity_Id;
10239 Expr : Node_Id;
10240 Layout_Done : Boolean;
10241 Default : Alignment_Result) return Alignment_Result
10242 is
10243 Result : Alignment_Result := Known_Compatible;
10244 -- Holds the current status of the result. Note that once a value of
10245 -- Known_Incompatible is set, it is sticky and does not get changed
10246 -- to Unknown (the value in Result only gets worse as we go along,
10247 -- never better).
10248
10249 Offs : Uint := No_Uint;
10250 -- Set to a factor of the offset from the base object when Expr is a
10251 -- selected or indexed component, based on Component_Bit_Offset and
10252 -- Component_Size respectively. A negative value is used to represent
10253 -- a value which is not known at compile time.
10254
10255 procedure Check_Prefix;
10256 -- Checks the prefix recursively in the case where the expression
10257 -- is an indexed or selected component.
10258
10259 procedure Set_Result (R : Alignment_Result);
10260 -- If R represents a worse outcome (unknown instead of known
10261 -- compatible, or known incompatible), then set Result to R.
10262
10263 ------------------
10264 -- Check_Prefix --
10265 ------------------
10266
10267 procedure Check_Prefix is
10268 begin
10269 -- The subtlety here is that in doing a recursive call to check
10270 -- the prefix, we have to decide what to do in the case where we
10271 -- don't find any specific indication of an alignment problem.
10272
10273 -- At the outer level, we normally set Unknown as the result in
10274 -- this case, since we can only set Known_Compatible if we really
10275 -- know that the alignment value is OK, but for the recursive
10276 -- call, in the case where the types match, and we have not
10277 -- specified a peculiar alignment for the object, we are only
10278 -- concerned about suspicious rep clauses, the default case does
10279 -- not affect us, since the compiler will, in the absence of such
10280 -- rep clauses, ensure that the alignment is correct.
10281
10282 if Default = Known_Compatible
10283 or else
10284 (Etype (Obj) = Etype (Expr)
10285 and then (Unknown_Alignment (Obj)
10286 or else
10287 Alignment (Obj) = Alignment (Etype (Obj))))
10288 then
10289 Set_Result
10290 (Has_Compatible_Alignment_Internal
10291 (Obj, Prefix (Expr), Layout_Done, Known_Compatible));
10292
10293 -- In all other cases, we need a full check on the prefix
10294
10295 else
10296 Set_Result
10297 (Has_Compatible_Alignment_Internal
10298 (Obj, Prefix (Expr), Layout_Done, Unknown));
10299 end if;
10300 end Check_Prefix;
10301
10302 ----------------
10303 -- Set_Result --
10304 ----------------
10305
10306 procedure Set_Result (R : Alignment_Result) is
10307 begin
10308 if R > Result then
10309 Result := R;
10310 end if;
10311 end Set_Result;
10312
10313 -- Start of processing for Has_Compatible_Alignment_Internal
10314
10315 begin
10316 -- If Expr is a selected component, we must make sure there is no
10317 -- potentially troublesome component clause and that the record is
10318 -- not packed if the layout is not done.
10319
10320 if Nkind (Expr) = N_Selected_Component then
10321
10322 -- Packing generates unknown alignment if layout is not done
10323
10324 if Is_Packed (Etype (Prefix (Expr))) and then not Layout_Done then
10325 Set_Result (Unknown);
10326 end if;
10327
10328 -- Check prefix and component offset
10329
10330 Check_Prefix;
10331 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
10332
10333 -- If Expr is an indexed component, we must make sure there is no
10334 -- potentially troublesome Component_Size clause and that the array
10335 -- is not bit-packed if the layout is not done.
10336
10337 elsif Nkind (Expr) = N_Indexed_Component then
10338 declare
10339 Typ : constant Entity_Id := Etype (Prefix (Expr));
10340
10341 begin
10342 -- Packing generates unknown alignment if layout is not done
10343
10344 if Is_Bit_Packed_Array (Typ) and then not Layout_Done then
10345 Set_Result (Unknown);
10346 end if;
10347
10348 -- Check prefix and component offset (or at least size)
10349
10350 Check_Prefix;
10351 Offs := Indexed_Component_Bit_Offset (Expr);
10352 if Offs = No_Uint then
10353 Offs := Component_Size (Typ);
10354 end if;
10355 end;
10356 end if;
10357
10358 -- If we have a null offset, the result is entirely determined by
10359 -- the base object and has already been computed recursively.
10360
10361 if Offs = Uint_0 then
10362 null;
10363
10364 -- Case where we know the alignment of the object
10365
10366 elsif Known_Alignment (Obj) then
10367 declare
10368 ObjA : constant Uint := Alignment (Obj);
10369 ExpA : Uint := No_Uint;
10370 SizA : Uint := No_Uint;
10371
10372 begin
10373 -- If alignment of Obj is 1, then we are always OK
10374
10375 if ObjA = 1 then
10376 Set_Result (Known_Compatible);
10377
10378 -- Alignment of Obj is greater than 1, so we need to check
10379
10380 else
10381 -- If we have an offset, see if it is compatible
10382
10383 if Offs /= No_Uint and Offs > Uint_0 then
10384 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
10385 Set_Result (Known_Incompatible);
10386 end if;
10387
10388 -- See if Expr is an object with known alignment
10389
10390 elsif Is_Entity_Name (Expr)
10391 and then Known_Alignment (Entity (Expr))
10392 then
10393 ExpA := Alignment (Entity (Expr));
10394
10395 -- Otherwise, we can use the alignment of the type of
10396 -- Expr given that we already checked for
10397 -- discombobulating rep clauses for the cases of indexed
10398 -- and selected components above.
10399
10400 elsif Known_Alignment (Etype (Expr)) then
10401 ExpA := Alignment (Etype (Expr));
10402
10403 -- Otherwise the alignment is unknown
10404
10405 else
10406 Set_Result (Default);
10407 end if;
10408
10409 -- If we got an alignment, see if it is acceptable
10410
10411 if ExpA /= No_Uint and then ExpA < ObjA then
10412 Set_Result (Known_Incompatible);
10413 end if;
10414
10415 -- If Expr is not a piece of a larger object, see if size
10416 -- is given. If so, check that it is not too small for the
10417 -- required alignment.
10418
10419 if Offs /= No_Uint then
10420 null;
10421
10422 -- See if Expr is an object with known size
10423
10424 elsif Is_Entity_Name (Expr)
10425 and then Known_Static_Esize (Entity (Expr))
10426 then
10427 SizA := Esize (Entity (Expr));
10428
10429 -- Otherwise, we check the object size of the Expr type
10430
10431 elsif Known_Static_Esize (Etype (Expr)) then
10432 SizA := Esize (Etype (Expr));
10433 end if;
10434
10435 -- If we got a size, see if it is a multiple of the Obj
10436 -- alignment, if not, then the alignment cannot be
10437 -- acceptable, since the size is always a multiple of the
10438 -- alignment.
10439
10440 if SizA /= No_Uint then
10441 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
10442 Set_Result (Known_Incompatible);
10443 end if;
10444 end if;
10445 end if;
10446 end;
10447
10448 -- If we do not know required alignment, any non-zero offset is a
10449 -- potential problem (but certainly may be OK, so result is unknown).
10450
10451 elsif Offs /= No_Uint then
10452 Set_Result (Unknown);
10453
10454 -- If we can't find the result by direct comparison of alignment
10455 -- values, then there is still one case that we can determine known
10456 -- result, and that is when we can determine that the types are the
10457 -- same, and no alignments are specified. Then we known that the
10458 -- alignments are compatible, even if we don't know the alignment
10459 -- value in the front end.
10460
10461 elsif Etype (Obj) = Etype (Expr) then
10462
10463 -- Types are the same, but we have to check for possible size
10464 -- and alignments on the Expr object that may make the alignment
10465 -- different, even though the types are the same.
10466
10467 if Is_Entity_Name (Expr) then
10468
10469 -- First check alignment of the Expr object. Any alignment less
10470 -- than Maximum_Alignment is worrisome since this is the case
10471 -- where we do not know the alignment of Obj.
10472
10473 if Known_Alignment (Entity (Expr))
10474 and then UI_To_Int (Alignment (Entity (Expr))) <
10475 Ttypes.Maximum_Alignment
10476 then
10477 Set_Result (Unknown);
10478
10479 -- Now check size of Expr object. Any size that is not an
10480 -- even multiple of Maximum_Alignment is also worrisome
10481 -- since it may cause the alignment of the object to be less
10482 -- than the alignment of the type.
10483
10484 elsif Known_Static_Esize (Entity (Expr))
10485 and then
10486 (UI_To_Int (Esize (Entity (Expr))) mod
10487 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
10488 /= 0
10489 then
10490 Set_Result (Unknown);
10491
10492 -- Otherwise same type is decisive
10493
10494 else
10495 Set_Result (Known_Compatible);
10496 end if;
10497 end if;
10498
10499 -- Another case to deal with is when there is an explicit size or
10500 -- alignment clause when the types are not the same. If so, then the
10501 -- result is Unknown. We don't need to do this test if the Default is
10502 -- Unknown, since that result will be set in any case.
10503
10504 elsif Default /= Unknown
10505 and then (Has_Size_Clause (Etype (Expr))
10506 or else
10507 Has_Alignment_Clause (Etype (Expr)))
10508 then
10509 Set_Result (Unknown);
10510
10511 -- If no indication found, set default
10512
10513 else
10514 Set_Result (Default);
10515 end if;
10516
10517 -- Return worst result found
10518
10519 return Result;
10520 end Has_Compatible_Alignment_Internal;
10521
10522 -- Start of processing for Has_Compatible_Alignment
10523
10524 begin
10525 -- If Obj has no specified alignment, then set alignment from the type
10526 -- alignment. Perhaps we should always do this, but for sure we should
10527 -- do it when there is an address clause since we can do more if the
10528 -- alignment is known.
10529
10530 if Unknown_Alignment (Obj) then
10531 Set_Alignment (Obj, Alignment (Etype (Obj)));
10532 end if;
10533
10534 -- Now do the internal call that does all the work
10535
10536 return
10537 Has_Compatible_Alignment_Internal (Obj, Expr, Layout_Done, Unknown);
10538 end Has_Compatible_Alignment;
10539
10540 ----------------------
10541 -- Has_Declarations --
10542 ----------------------
10543
10544 function Has_Declarations (N : Node_Id) return Boolean is
10545 begin
10546 return Nkind_In (Nkind (N), N_Accept_Statement,
10547 N_Block_Statement,
10548 N_Compilation_Unit_Aux,
10549 N_Entry_Body,
10550 N_Package_Body,
10551 N_Protected_Body,
10552 N_Subprogram_Body,
10553 N_Task_Body,
10554 N_Package_Specification);
10555 end Has_Declarations;
10556
10557 ---------------------------------
10558 -- Has_Defaulted_Discriminants --
10559 ---------------------------------
10560
10561 function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean is
10562 begin
10563 return Has_Discriminants (Typ)
10564 and then Present (First_Discriminant (Typ))
10565 and then Present (Discriminant_Default_Value
10566 (First_Discriminant (Typ)));
10567 end Has_Defaulted_Discriminants;
10568
10569 -------------------
10570 -- Has_Denormals --
10571 -------------------
10572
10573 function Has_Denormals (E : Entity_Id) return Boolean is
10574 begin
10575 return Is_Floating_Point_Type (E) and then Denorm_On_Target;
10576 end Has_Denormals;
10577
10578 -------------------------------------------
10579 -- Has_Discriminant_Dependent_Constraint --
10580 -------------------------------------------
10581
10582 function Has_Discriminant_Dependent_Constraint
10583 (Comp : Entity_Id) return Boolean
10584 is
10585 Comp_Decl : constant Node_Id := Parent (Comp);
10586 Subt_Indic : Node_Id;
10587 Constr : Node_Id;
10588 Assn : Node_Id;
10589
10590 begin
10591 -- Discriminants can't depend on discriminants
10592
10593 if Ekind (Comp) = E_Discriminant then
10594 return False;
10595
10596 else
10597 Subt_Indic := Subtype_Indication (Component_Definition (Comp_Decl));
10598
10599 if Nkind (Subt_Indic) = N_Subtype_Indication then
10600 Constr := Constraint (Subt_Indic);
10601
10602 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
10603 Assn := First (Constraints (Constr));
10604 while Present (Assn) loop
10605 case Nkind (Assn) is
10606 when N_Identifier
10607 | N_Range
10608 | N_Subtype_Indication
10609 =>
10610 if Depends_On_Discriminant (Assn) then
10611 return True;
10612 end if;
10613
10614 when N_Discriminant_Association =>
10615 if Depends_On_Discriminant (Expression (Assn)) then
10616 return True;
10617 end if;
10618
10619 when others =>
10620 null;
10621 end case;
10622
10623 Next (Assn);
10624 end loop;
10625 end if;
10626 end if;
10627 end if;
10628
10629 return False;
10630 end Has_Discriminant_Dependent_Constraint;
10631
10632 --------------------------------------
10633 -- Has_Effectively_Volatile_Profile --
10634 --------------------------------------
10635
10636 function Has_Effectively_Volatile_Profile
10637 (Subp_Id : Entity_Id) return Boolean
10638 is
10639 Formal : Entity_Id;
10640
10641 begin
10642 -- Inspect the formal parameters looking for an effectively volatile
10643 -- type.
10644
10645 Formal := First_Formal (Subp_Id);
10646 while Present (Formal) loop
10647 if Is_Effectively_Volatile (Etype (Formal)) then
10648 return True;
10649 end if;
10650
10651 Next_Formal (Formal);
10652 end loop;
10653
10654 -- Inspect the return type of functions
10655
10656 if Ekind_In (Subp_Id, E_Function, E_Generic_Function)
10657 and then Is_Effectively_Volatile (Etype (Subp_Id))
10658 then
10659 return True;
10660 end if;
10661
10662 return False;
10663 end Has_Effectively_Volatile_Profile;
10664
10665 --------------------------
10666 -- Has_Enabled_Property --
10667 --------------------------
10668
10669 function Has_Enabled_Property
10670 (Item_Id : Entity_Id;
10671 Property : Name_Id) return Boolean
10672 is
10673 function Protected_Object_Has_Enabled_Property return Boolean;
10674 -- Determine whether a protected object denoted by Item_Id has the
10675 -- property enabled.
10676
10677 function State_Has_Enabled_Property return Boolean;
10678 -- Determine whether a state denoted by Item_Id has the property enabled
10679
10680 function Variable_Has_Enabled_Property return Boolean;
10681 -- Determine whether a variable denoted by Item_Id has the property
10682 -- enabled.
10683
10684 -------------------------------------------
10685 -- Protected_Object_Has_Enabled_Property --
10686 -------------------------------------------
10687
10688 function Protected_Object_Has_Enabled_Property return Boolean is
10689 Constits : constant Elist_Id := Part_Of_Constituents (Item_Id);
10690 Constit_Elmt : Elmt_Id;
10691 Constit_Id : Entity_Id;
10692
10693 begin
10694 -- Protected objects always have the properties Async_Readers and
10695 -- Async_Writers (SPARK RM 7.1.2(16)).
10696
10697 if Property = Name_Async_Readers
10698 or else Property = Name_Async_Writers
10699 then
10700 return True;
10701
10702 -- Protected objects that have Part_Of components also inherit their
10703 -- properties Effective_Reads and Effective_Writes
10704 -- (SPARK RM 7.1.2(16)).
10705
10706 elsif Present (Constits) then
10707 Constit_Elmt := First_Elmt (Constits);
10708 while Present (Constit_Elmt) loop
10709 Constit_Id := Node (Constit_Elmt);
10710
10711 if Has_Enabled_Property (Constit_Id, Property) then
10712 return True;
10713 end if;
10714
10715 Next_Elmt (Constit_Elmt);
10716 end loop;
10717 end if;
10718
10719 return False;
10720 end Protected_Object_Has_Enabled_Property;
10721
10722 --------------------------------
10723 -- State_Has_Enabled_Property --
10724 --------------------------------
10725
10726 function State_Has_Enabled_Property return Boolean is
10727 Decl : constant Node_Id := Parent (Item_Id);
10728
10729 procedure Find_Simple_Properties
10730 (Has_External : out Boolean;
10731 Has_Synchronous : out Boolean);
10732 -- Extract the simple properties associated with declaration Decl
10733
10734 function Is_Enabled_External_Property return Boolean;
10735 -- Determine whether property Property appears within the external
10736 -- property list of declaration Decl, and return its status.
10737
10738 ----------------------------
10739 -- Find_Simple_Properties --
10740 ----------------------------
10741
10742 procedure Find_Simple_Properties
10743 (Has_External : out Boolean;
10744 Has_Synchronous : out Boolean)
10745 is
10746 Opt : Node_Id;
10747
10748 begin
10749 -- Assume that none of the properties are available
10750
10751 Has_External := False;
10752 Has_Synchronous := False;
10753
10754 Opt := First (Expressions (Decl));
10755 while Present (Opt) loop
10756 if Nkind (Opt) = N_Identifier then
10757 if Chars (Opt) = Name_External then
10758 Has_External := True;
10759
10760 elsif Chars (Opt) = Name_Synchronous then
10761 Has_Synchronous := True;
10762 end if;
10763 end if;
10764
10765 Next (Opt);
10766 end loop;
10767 end Find_Simple_Properties;
10768
10769 ----------------------------------
10770 -- Is_Enabled_External_Property --
10771 ----------------------------------
10772
10773 function Is_Enabled_External_Property return Boolean is
10774 Opt : Node_Id;
10775 Opt_Nam : Node_Id;
10776 Prop : Node_Id;
10777 Prop_Nam : Node_Id;
10778 Props : Node_Id;
10779
10780 begin
10781 Opt := First (Component_Associations (Decl));
10782 while Present (Opt) loop
10783 Opt_Nam := First (Choices (Opt));
10784
10785 if Nkind (Opt_Nam) = N_Identifier
10786 and then Chars (Opt_Nam) = Name_External
10787 then
10788 Props := Expression (Opt);
10789
10790 -- Multiple properties appear as an aggregate
10791
10792 if Nkind (Props) = N_Aggregate then
10793
10794 -- Simple property form
10795
10796 Prop := First (Expressions (Props));
10797 while Present (Prop) loop
10798 if Chars (Prop) = Property then
10799 return True;
10800 end if;
10801
10802 Next (Prop);
10803 end loop;
10804
10805 -- Property with expression form
10806
10807 Prop := First (Component_Associations (Props));
10808 while Present (Prop) loop
10809 Prop_Nam := First (Choices (Prop));
10810
10811 -- The property can be represented in two ways:
10812 -- others => <value>
10813 -- <property> => <value>
10814
10815 if Nkind (Prop_Nam) = N_Others_Choice
10816 or else (Nkind (Prop_Nam) = N_Identifier
10817 and then Chars (Prop_Nam) = Property)
10818 then
10819 return Is_True (Expr_Value (Expression (Prop)));
10820 end if;
10821
10822 Next (Prop);
10823 end loop;
10824
10825 -- Single property
10826
10827 else
10828 return Chars (Props) = Property;
10829 end if;
10830 end if;
10831
10832 Next (Opt);
10833 end loop;
10834
10835 return False;
10836 end Is_Enabled_External_Property;
10837
10838 -- Local variables
10839
10840 Has_External : Boolean;
10841 Has_Synchronous : Boolean;
10842
10843 -- Start of processing for State_Has_Enabled_Property
10844
10845 begin
10846 -- The declaration of an external abstract state appears as an
10847 -- extension aggregate. If this is not the case, properties can
10848 -- never be set.
10849
10850 if Nkind (Decl) /= N_Extension_Aggregate then
10851 return False;
10852 end if;
10853
10854 Find_Simple_Properties (Has_External, Has_Synchronous);
10855
10856 -- Simple option External enables all properties (SPARK RM 7.1.2(2))
10857
10858 if Has_External then
10859 return True;
10860
10861 -- Option External may enable or disable specific properties
10862
10863 elsif Is_Enabled_External_Property then
10864 return True;
10865
10866 -- Simple option Synchronous
10867 --
10868 -- enables disables
10869 -- Async_Readers Effective_Reads
10870 -- Async_Writers Effective_Writes
10871 --
10872 -- Note that both forms of External have higher precedence than
10873 -- Synchronous (SPARK RM 7.1.4(9)).
10874
10875 elsif Has_Synchronous then
10876 return Nam_In (Property, Name_Async_Readers, Name_Async_Writers);
10877 end if;
10878
10879 return False;
10880 end State_Has_Enabled_Property;
10881
10882 -----------------------------------
10883 -- Variable_Has_Enabled_Property --
10884 -----------------------------------
10885
10886 function Variable_Has_Enabled_Property return Boolean is
10887 function Is_Enabled (Prag : Node_Id) return Boolean;
10888 -- Determine whether property pragma Prag (if present) denotes an
10889 -- enabled property.
10890
10891 ----------------
10892 -- Is_Enabled --
10893 ----------------
10894
10895 function Is_Enabled (Prag : Node_Id) return Boolean is
10896 Arg1 : Node_Id;
10897
10898 begin
10899 if Present (Prag) then
10900 Arg1 := First (Pragma_Argument_Associations (Prag));
10901
10902 -- The pragma has an optional Boolean expression, the related
10903 -- property is enabled only when the expression evaluates to
10904 -- True.
10905
10906 if Present (Arg1) then
10907 return Is_True (Expr_Value (Get_Pragma_Arg (Arg1)));
10908
10909 -- Otherwise the lack of expression enables the property by
10910 -- default.
10911
10912 else
10913 return True;
10914 end if;
10915
10916 -- The property was never set in the first place
10917
10918 else
10919 return False;
10920 end if;
10921 end Is_Enabled;
10922
10923 -- Local variables
10924
10925 AR : constant Node_Id :=
10926 Get_Pragma (Item_Id, Pragma_Async_Readers);
10927 AW : constant Node_Id :=
10928 Get_Pragma (Item_Id, Pragma_Async_Writers);
10929 ER : constant Node_Id :=
10930 Get_Pragma (Item_Id, Pragma_Effective_Reads);
10931 EW : constant Node_Id :=
10932 Get_Pragma (Item_Id, Pragma_Effective_Writes);
10933
10934 -- Start of processing for Variable_Has_Enabled_Property
10935
10936 begin
10937 -- A non-effectively volatile object can never possess external
10938 -- properties.
10939
10940 if not Is_Effectively_Volatile (Item_Id) then
10941 return False;
10942
10943 -- External properties related to variables come in two flavors -
10944 -- explicit and implicit. The explicit case is characterized by the
10945 -- presence of a property pragma with an optional Boolean flag. The
10946 -- property is enabled when the flag evaluates to True or the flag is
10947 -- missing altogether.
10948
10949 elsif Property = Name_Async_Readers and then Is_Enabled (AR) then
10950 return True;
10951
10952 elsif Property = Name_Async_Writers and then Is_Enabled (AW) then
10953 return True;
10954
10955 elsif Property = Name_Effective_Reads and then Is_Enabled (ER) then
10956 return True;
10957
10958 elsif Property = Name_Effective_Writes and then Is_Enabled (EW) then
10959 return True;
10960
10961 -- The implicit case lacks all property pragmas
10962
10963 elsif No (AR) and then No (AW) and then No (ER) and then No (EW) then
10964 if Is_Protected_Type (Etype (Item_Id)) then
10965 return Protected_Object_Has_Enabled_Property;
10966 else
10967 return True;
10968 end if;
10969
10970 else
10971 return False;
10972 end if;
10973 end Variable_Has_Enabled_Property;
10974
10975 -- Start of processing for Has_Enabled_Property
10976
10977 begin
10978 -- Abstract states and variables have a flexible scheme of specifying
10979 -- external properties.
10980
10981 if Ekind (Item_Id) = E_Abstract_State then
10982 return State_Has_Enabled_Property;
10983
10984 elsif Ekind (Item_Id) = E_Variable then
10985 return Variable_Has_Enabled_Property;
10986
10987 -- By default, protected objects only have the properties Async_Readers
10988 -- and Async_Writers. If they have Part_Of components, they also inherit
10989 -- their properties Effective_Reads and Effective_Writes
10990 -- (SPARK RM 7.1.2(16)).
10991
10992 elsif Ekind (Item_Id) = E_Protected_Object then
10993 return Protected_Object_Has_Enabled_Property;
10994
10995 -- Otherwise a property is enabled when the related item is effectively
10996 -- volatile.
10997
10998 else
10999 return Is_Effectively_Volatile (Item_Id);
11000 end if;
11001 end Has_Enabled_Property;
11002
11003 -------------------------------------
11004 -- Has_Full_Default_Initialization --
11005 -------------------------------------
11006
11007 function Has_Full_Default_Initialization (Typ : Entity_Id) return Boolean is
11008 Comp : Entity_Id;
11009
11010 begin
11011 -- A type subject to pragma Default_Initial_Condition may be fully
11012 -- default initialized depending on inheritance and the argument of
11013 -- the pragma. Since any type may act as the full view of a private
11014 -- type, this check must be performed prior to the specialized tests
11015 -- below.
11016
11017 if Has_Fully_Default_Initializing_DIC_Pragma (Typ) then
11018 return True;
11019 end if;
11020
11021 -- A scalar type is fully default initialized if it is subject to aspect
11022 -- Default_Value.
11023
11024 if Is_Scalar_Type (Typ) then
11025 return Has_Default_Aspect (Typ);
11026
11027 -- An access type is fully default initialized by default
11028
11029 elsif Is_Access_Type (Typ) then
11030 return True;
11031
11032 -- An array type is fully default initialized if its element type is
11033 -- scalar and the array type carries aspect Default_Component_Value or
11034 -- the element type is fully default initialized.
11035
11036 elsif Is_Array_Type (Typ) then
11037 return
11038 Has_Default_Aspect (Typ)
11039 or else Has_Full_Default_Initialization (Component_Type (Typ));
11040
11041 -- A protected type, record type, or type extension is fully default
11042 -- initialized if all its components either carry an initialization
11043 -- expression or have a type that is fully default initialized. The
11044 -- parent type of a type extension must be fully default initialized.
11045
11046 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
11047
11048 -- Inspect all entities defined in the scope of the type, looking for
11049 -- uninitialized components.
11050
11051 Comp := First_Entity (Typ);
11052 while Present (Comp) loop
11053 if Ekind (Comp) = E_Component
11054 and then Comes_From_Source (Comp)
11055 and then No (Expression (Parent (Comp)))
11056 and then not Has_Full_Default_Initialization (Etype (Comp))
11057 then
11058 return False;
11059 end if;
11060
11061 Next_Entity (Comp);
11062 end loop;
11063
11064 -- Ensure that the parent type of a type extension is fully default
11065 -- initialized.
11066
11067 if Etype (Typ) /= Typ
11068 and then not Has_Full_Default_Initialization (Etype (Typ))
11069 then
11070 return False;
11071 end if;
11072
11073 -- If we get here, then all components and parent portion are fully
11074 -- default initialized.
11075
11076 return True;
11077
11078 -- A task type is fully default initialized by default
11079
11080 elsif Is_Task_Type (Typ) then
11081 return True;
11082
11083 -- Otherwise the type is not fully default initialized
11084
11085 else
11086 return False;
11087 end if;
11088 end Has_Full_Default_Initialization;
11089
11090 -----------------------------------------------
11091 -- Has_Fully_Default_Initializing_DIC_Pragma --
11092 -----------------------------------------------
11093
11094 function Has_Fully_Default_Initializing_DIC_Pragma
11095 (Typ : Entity_Id) return Boolean
11096 is
11097 Args : List_Id;
11098 Prag : Node_Id;
11099
11100 begin
11101 -- A type that inherits pragma Default_Initial_Condition from a parent
11102 -- type is automatically fully default initialized.
11103
11104 if Has_Inherited_DIC (Typ) then
11105 return True;
11106
11107 -- Otherwise the type is fully default initialized only when the pragma
11108 -- appears without an argument, or the argument is non-null.
11109
11110 elsif Has_Own_DIC (Typ) then
11111 Prag := Get_Pragma (Typ, Pragma_Default_Initial_Condition);
11112 pragma Assert (Present (Prag));
11113 Args := Pragma_Argument_Associations (Prag);
11114
11115 -- The pragma appears without an argument in which case it defaults
11116 -- to True.
11117
11118 if No (Args) then
11119 return True;
11120
11121 -- The pragma appears with a non-null expression
11122
11123 elsif Nkind (Get_Pragma_Arg (First (Args))) /= N_Null then
11124 return True;
11125 end if;
11126 end if;
11127
11128 return False;
11129 end Has_Fully_Default_Initializing_DIC_Pragma;
11130
11131 --------------------
11132 -- Has_Infinities --
11133 --------------------
11134
11135 function Has_Infinities (E : Entity_Id) return Boolean is
11136 begin
11137 return
11138 Is_Floating_Point_Type (E)
11139 and then Nkind (Scalar_Range (E)) = N_Range
11140 and then Includes_Infinities (Scalar_Range (E));
11141 end Has_Infinities;
11142
11143 --------------------
11144 -- Has_Interfaces --
11145 --------------------
11146
11147 function Has_Interfaces
11148 (T : Entity_Id;
11149 Use_Full_View : Boolean := True) return Boolean
11150 is
11151 Typ : Entity_Id := Base_Type (T);
11152
11153 begin
11154 -- Handle concurrent types
11155
11156 if Is_Concurrent_Type (Typ) then
11157 Typ := Corresponding_Record_Type (Typ);
11158 end if;
11159
11160 if not Present (Typ)
11161 or else not Is_Record_Type (Typ)
11162 or else not Is_Tagged_Type (Typ)
11163 then
11164 return False;
11165 end if;
11166
11167 -- Handle private types
11168
11169 if Use_Full_View and then Present (Full_View (Typ)) then
11170 Typ := Full_View (Typ);
11171 end if;
11172
11173 -- Handle concurrent record types
11174
11175 if Is_Concurrent_Record_Type (Typ)
11176 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
11177 then
11178 return True;
11179 end if;
11180
11181 loop
11182 if Is_Interface (Typ)
11183 or else
11184 (Is_Record_Type (Typ)
11185 and then Present (Interfaces (Typ))
11186 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
11187 then
11188 return True;
11189 end if;
11190
11191 exit when Etype (Typ) = Typ
11192
11193 -- Handle private types
11194
11195 or else (Present (Full_View (Etype (Typ)))
11196 and then Full_View (Etype (Typ)) = Typ)
11197
11198 -- Protect frontend against wrong sources with cyclic derivations
11199
11200 or else Etype (Typ) = T;
11201
11202 -- Climb to the ancestor type handling private types
11203
11204 if Present (Full_View (Etype (Typ))) then
11205 Typ := Full_View (Etype (Typ));
11206 else
11207 Typ := Etype (Typ);
11208 end if;
11209 end loop;
11210
11211 return False;
11212 end Has_Interfaces;
11213
11214 --------------------------
11215 -- Has_Max_Queue_Length --
11216 --------------------------
11217
11218 function Has_Max_Queue_Length (Id : Entity_Id) return Boolean is
11219 begin
11220 return
11221 Ekind (Id) = E_Entry
11222 and then Present (Get_Pragma (Id, Pragma_Max_Queue_Length));
11223 end Has_Max_Queue_Length;
11224
11225 ---------------------------------
11226 -- Has_No_Obvious_Side_Effects --
11227 ---------------------------------
11228
11229 function Has_No_Obvious_Side_Effects (N : Node_Id) return Boolean is
11230 begin
11231 -- For now handle literals, constants, and non-volatile variables and
11232 -- expressions combining these with operators or short circuit forms.
11233
11234 if Nkind (N) in N_Numeric_Or_String_Literal then
11235 return True;
11236
11237 elsif Nkind (N) = N_Character_Literal then
11238 return True;
11239
11240 elsif Nkind (N) in N_Unary_Op then
11241 return Has_No_Obvious_Side_Effects (Right_Opnd (N));
11242
11243 elsif Nkind (N) in N_Binary_Op or else Nkind (N) in N_Short_Circuit then
11244 return Has_No_Obvious_Side_Effects (Left_Opnd (N))
11245 and then
11246 Has_No_Obvious_Side_Effects (Right_Opnd (N));
11247
11248 elsif Nkind (N) = N_Expression_With_Actions
11249 and then Is_Empty_List (Actions (N))
11250 then
11251 return Has_No_Obvious_Side_Effects (Expression (N));
11252
11253 elsif Nkind (N) in N_Has_Entity then
11254 return Present (Entity (N))
11255 and then Ekind_In (Entity (N), E_Variable,
11256 E_Constant,
11257 E_Enumeration_Literal,
11258 E_In_Parameter,
11259 E_Out_Parameter,
11260 E_In_Out_Parameter)
11261 and then not Is_Volatile (Entity (N));
11262
11263 else
11264 return False;
11265 end if;
11266 end Has_No_Obvious_Side_Effects;
11267
11268 -----------------------------
11269 -- Has_Non_Null_Refinement --
11270 -----------------------------
11271
11272 function Has_Non_Null_Refinement (Id : Entity_Id) return Boolean is
11273 Constits : Elist_Id;
11274
11275 begin
11276 pragma Assert (Ekind (Id) = E_Abstract_State);
11277 Constits := Refinement_Constituents (Id);
11278
11279 -- For a refinement to be non-null, the first constituent must be
11280 -- anything other than null.
11281
11282 return
11283 Present (Constits)
11284 and then Nkind (Node (First_Elmt (Constits))) /= N_Null;
11285 end Has_Non_Null_Refinement;
11286
11287 -----------------------------
11288 -- Has_Non_Null_Statements --
11289 -----------------------------
11290
11291 function Has_Non_Null_Statements (L : List_Id) return Boolean is
11292 Node : Node_Id;
11293
11294 begin
11295 if Is_Non_Empty_List (L) then
11296 Node := First (L);
11297
11298 loop
11299 if Nkind (Node) /= N_Null_Statement then
11300 return True;
11301 end if;
11302
11303 Next (Node);
11304 exit when Node = Empty;
11305 end loop;
11306 end if;
11307
11308 return False;
11309 end Has_Non_Null_Statements;
11310
11311 ----------------------------------
11312 -- Has_Non_Trivial_Precondition --
11313 ----------------------------------
11314
11315 function Has_Non_Trivial_Precondition (Subp : Entity_Id) return Boolean is
11316 Pre : constant Node_Id := Find_Aspect (Subp, Aspect_Pre);
11317
11318 begin
11319 return
11320 Present (Pre)
11321 and then Class_Present (Pre)
11322 and then not Is_Entity_Name (Expression (Pre));
11323 end Has_Non_Trivial_Precondition;
11324
11325 -------------------
11326 -- Has_Null_Body --
11327 -------------------
11328
11329 function Has_Null_Body (Proc_Id : Entity_Id) return Boolean is
11330 Body_Id : Entity_Id;
11331 Decl : Node_Id;
11332 Spec : Node_Id;
11333 Stmt1 : Node_Id;
11334 Stmt2 : Node_Id;
11335
11336 begin
11337 Spec := Parent (Proc_Id);
11338 Decl := Parent (Spec);
11339
11340 -- Retrieve the entity of the procedure body (e.g. invariant proc).
11341
11342 if Nkind (Spec) = N_Procedure_Specification
11343 and then Nkind (Decl) = N_Subprogram_Declaration
11344 then
11345 Body_Id := Corresponding_Body (Decl);
11346
11347 -- The body acts as a spec
11348
11349 else
11350 Body_Id := Proc_Id;
11351 end if;
11352
11353 -- The body will be generated later
11354
11355 if No (Body_Id) then
11356 return False;
11357 end if;
11358
11359 Spec := Parent (Body_Id);
11360 Decl := Parent (Spec);
11361
11362 pragma Assert
11363 (Nkind (Spec) = N_Procedure_Specification
11364 and then Nkind (Decl) = N_Subprogram_Body);
11365
11366 Stmt1 := First (Statements (Handled_Statement_Sequence (Decl)));
11367
11368 -- Look for a null statement followed by an optional return
11369 -- statement.
11370
11371 if Nkind (Stmt1) = N_Null_Statement then
11372 Stmt2 := Next (Stmt1);
11373
11374 if Present (Stmt2) then
11375 return Nkind (Stmt2) = N_Simple_Return_Statement;
11376 else
11377 return True;
11378 end if;
11379 end if;
11380
11381 return False;
11382 end Has_Null_Body;
11383
11384 ------------------------
11385 -- Has_Null_Exclusion --
11386 ------------------------
11387
11388 function Has_Null_Exclusion (N : Node_Id) return Boolean is
11389 begin
11390 case Nkind (N) is
11391 when N_Access_Definition
11392 | N_Access_Function_Definition
11393 | N_Access_Procedure_Definition
11394 | N_Access_To_Object_Definition
11395 | N_Allocator
11396 | N_Derived_Type_Definition
11397 | N_Function_Specification
11398 | N_Subtype_Declaration
11399 =>
11400 return Null_Exclusion_Present (N);
11401
11402 when N_Component_Definition
11403 | N_Formal_Object_Declaration
11404 | N_Object_Renaming_Declaration
11405 =>
11406 if Present (Subtype_Mark (N)) then
11407 return Null_Exclusion_Present (N);
11408 else pragma Assert (Present (Access_Definition (N)));
11409 return Null_Exclusion_Present (Access_Definition (N));
11410 end if;
11411
11412 when N_Discriminant_Specification =>
11413 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
11414 return Null_Exclusion_Present (Discriminant_Type (N));
11415 else
11416 return Null_Exclusion_Present (N);
11417 end if;
11418
11419 when N_Object_Declaration =>
11420 if Nkind (Object_Definition (N)) = N_Access_Definition then
11421 return Null_Exclusion_Present (Object_Definition (N));
11422 else
11423 return Null_Exclusion_Present (N);
11424 end if;
11425
11426 when N_Parameter_Specification =>
11427 if Nkind (Parameter_Type (N)) = N_Access_Definition then
11428 return Null_Exclusion_Present (Parameter_Type (N));
11429 else
11430 return Null_Exclusion_Present (N);
11431 end if;
11432
11433 when others =>
11434 return False;
11435 end case;
11436 end Has_Null_Exclusion;
11437
11438 ------------------------
11439 -- Has_Null_Extension --
11440 ------------------------
11441
11442 function Has_Null_Extension (T : Entity_Id) return Boolean is
11443 B : constant Entity_Id := Base_Type (T);
11444 Comps : Node_Id;
11445 Ext : Node_Id;
11446
11447 begin
11448 if Nkind (Parent (B)) = N_Full_Type_Declaration
11449 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
11450 then
11451 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
11452
11453 if Present (Ext) then
11454 if Null_Present (Ext) then
11455 return True;
11456 else
11457 Comps := Component_List (Ext);
11458
11459 -- The null component list is rewritten during analysis to
11460 -- include the parent component. Any other component indicates
11461 -- that the extension was not originally null.
11462
11463 return Null_Present (Comps)
11464 or else No (Next (First (Component_Items (Comps))));
11465 end if;
11466 else
11467 return False;
11468 end if;
11469
11470 else
11471 return False;
11472 end if;
11473 end Has_Null_Extension;
11474
11475 -------------------------
11476 -- Has_Null_Refinement --
11477 -------------------------
11478
11479 function Has_Null_Refinement (Id : Entity_Id) return Boolean is
11480 Constits : Elist_Id;
11481
11482 begin
11483 pragma Assert (Ekind (Id) = E_Abstract_State);
11484 Constits := Refinement_Constituents (Id);
11485
11486 -- For a refinement to be null, the state's sole constituent must be a
11487 -- null.
11488
11489 return
11490 Present (Constits)
11491 and then Nkind (Node (First_Elmt (Constits))) = N_Null;
11492 end Has_Null_Refinement;
11493
11494 -------------------------------
11495 -- Has_Overriding_Initialize --
11496 -------------------------------
11497
11498 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
11499 BT : constant Entity_Id := Base_Type (T);
11500 P : Elmt_Id;
11501
11502 begin
11503 if Is_Controlled (BT) then
11504 if Is_RTU (Scope (BT), Ada_Finalization) then
11505 return False;
11506
11507 elsif Present (Primitive_Operations (BT)) then
11508 P := First_Elmt (Primitive_Operations (BT));
11509 while Present (P) loop
11510 declare
11511 Init : constant Entity_Id := Node (P);
11512 Formal : constant Entity_Id := First_Formal (Init);
11513 begin
11514 if Ekind (Init) = E_Procedure
11515 and then Chars (Init) = Name_Initialize
11516 and then Comes_From_Source (Init)
11517 and then Present (Formal)
11518 and then Etype (Formal) = BT
11519 and then No (Next_Formal (Formal))
11520 and then (Ada_Version < Ada_2012
11521 or else not Null_Present (Parent (Init)))
11522 then
11523 return True;
11524 end if;
11525 end;
11526
11527 Next_Elmt (P);
11528 end loop;
11529 end if;
11530
11531 -- Here if type itself does not have a non-null Initialize operation:
11532 -- check immediate ancestor.
11533
11534 if Is_Derived_Type (BT)
11535 and then Has_Overriding_Initialize (Etype (BT))
11536 then
11537 return True;
11538 end if;
11539 end if;
11540
11541 return False;
11542 end Has_Overriding_Initialize;
11543
11544 --------------------------------------
11545 -- Has_Preelaborable_Initialization --
11546 --------------------------------------
11547
11548 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
11549 Has_PE : Boolean;
11550
11551 procedure Check_Components (E : Entity_Id);
11552 -- Check component/discriminant chain, sets Has_PE False if a component
11553 -- or discriminant does not meet the preelaborable initialization rules.
11554
11555 ----------------------
11556 -- Check_Components --
11557 ----------------------
11558
11559 procedure Check_Components (E : Entity_Id) is
11560 Ent : Entity_Id;
11561 Exp : Node_Id;
11562
11563 begin
11564 -- Loop through entities of record or protected type
11565
11566 Ent := E;
11567 while Present (Ent) loop
11568
11569 -- We are interested only in components and discriminants
11570
11571 Exp := Empty;
11572
11573 case Ekind (Ent) is
11574 when E_Component =>
11575
11576 -- Get default expression if any. If there is no declaration
11577 -- node, it means we have an internal entity. The parent and
11578 -- tag fields are examples of such entities. For such cases,
11579 -- we just test the type of the entity.
11580
11581 if Present (Declaration_Node (Ent)) then
11582 Exp := Expression (Declaration_Node (Ent));
11583 end if;
11584
11585 when E_Discriminant =>
11586
11587 -- Note: for a renamed discriminant, the Declaration_Node
11588 -- may point to the one from the ancestor, and have a
11589 -- different expression, so use the proper attribute to
11590 -- retrieve the expression from the derived constraint.
11591
11592 Exp := Discriminant_Default_Value (Ent);
11593
11594 when others =>
11595 goto Check_Next_Entity;
11596 end case;
11597
11598 -- A component has PI if it has no default expression and the
11599 -- component type has PI.
11600
11601 if No (Exp) then
11602 if not Has_Preelaborable_Initialization (Etype (Ent)) then
11603 Has_PE := False;
11604 exit;
11605 end if;
11606
11607 -- Require the default expression to be preelaborable
11608
11609 elsif not Is_Preelaborable_Construct (Exp) then
11610 Has_PE := False;
11611 exit;
11612 end if;
11613
11614 <<Check_Next_Entity>>
11615 Next_Entity (Ent);
11616 end loop;
11617 end Check_Components;
11618
11619 -- Start of processing for Has_Preelaborable_Initialization
11620
11621 begin
11622 -- Immediate return if already marked as known preelaborable init. This
11623 -- covers types for which this function has already been called once
11624 -- and returned True (in which case the result is cached), and also
11625 -- types to which a pragma Preelaborable_Initialization applies.
11626
11627 if Known_To_Have_Preelab_Init (E) then
11628 return True;
11629 end if;
11630
11631 -- If the type is a subtype representing a generic actual type, then
11632 -- test whether its base type has preelaborable initialization since
11633 -- the subtype representing the actual does not inherit this attribute
11634 -- from the actual or formal. (but maybe it should???)
11635
11636 if Is_Generic_Actual_Type (E) then
11637 return Has_Preelaborable_Initialization (Base_Type (E));
11638 end if;
11639
11640 -- All elementary types have preelaborable initialization
11641
11642 if Is_Elementary_Type (E) then
11643 Has_PE := True;
11644
11645 -- Array types have PI if the component type has PI
11646
11647 elsif Is_Array_Type (E) then
11648 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
11649
11650 -- A derived type has preelaborable initialization if its parent type
11651 -- has preelaborable initialization and (in the case of a derived record
11652 -- extension) if the non-inherited components all have preelaborable
11653 -- initialization. However, a user-defined controlled type with an
11654 -- overriding Initialize procedure does not have preelaborable
11655 -- initialization.
11656
11657 elsif Is_Derived_Type (E) then
11658
11659 -- If the derived type is a private extension then it doesn't have
11660 -- preelaborable initialization.
11661
11662 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
11663 return False;
11664 end if;
11665
11666 -- First check whether ancestor type has preelaborable initialization
11667
11668 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
11669
11670 -- If OK, check extension components (if any)
11671
11672 if Has_PE and then Is_Record_Type (E) then
11673 Check_Components (First_Entity (E));
11674 end if;
11675
11676 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
11677 -- with a user defined Initialize procedure does not have PI. If
11678 -- the type is untagged, the control primitives come from a component
11679 -- that has already been checked.
11680
11681 if Has_PE
11682 and then Is_Controlled (E)
11683 and then Is_Tagged_Type (E)
11684 and then Has_Overriding_Initialize (E)
11685 then
11686 Has_PE := False;
11687 end if;
11688
11689 -- Private types not derived from a type having preelaborable init and
11690 -- that are not marked with pragma Preelaborable_Initialization do not
11691 -- have preelaborable initialization.
11692
11693 elsif Is_Private_Type (E) then
11694 return False;
11695
11696 -- Record type has PI if it is non private and all components have PI
11697
11698 elsif Is_Record_Type (E) then
11699 Has_PE := True;
11700 Check_Components (First_Entity (E));
11701
11702 -- Protected types must not have entries, and components must meet
11703 -- same set of rules as for record components.
11704
11705 elsif Is_Protected_Type (E) then
11706 if Has_Entries (E) then
11707 Has_PE := False;
11708 else
11709 Has_PE := True;
11710 Check_Components (First_Entity (E));
11711 Check_Components (First_Private_Entity (E));
11712 end if;
11713
11714 -- Type System.Address always has preelaborable initialization
11715
11716 elsif Is_RTE (E, RE_Address) then
11717 Has_PE := True;
11718
11719 -- In all other cases, type does not have preelaborable initialization
11720
11721 else
11722 return False;
11723 end if;
11724
11725 -- If type has preelaborable initialization, cache result
11726
11727 if Has_PE then
11728 Set_Known_To_Have_Preelab_Init (E);
11729 end if;
11730
11731 return Has_PE;
11732 end Has_Preelaborable_Initialization;
11733
11734 ----------------
11735 -- Has_Prefix --
11736 ----------------
11737
11738 function Has_Prefix (N : Node_Id) return Boolean is
11739 begin
11740 return
11741 Nkind_In (N, N_Attribute_Reference,
11742 N_Expanded_Name,
11743 N_Explicit_Dereference,
11744 N_Indexed_Component,
11745 N_Reference,
11746 N_Selected_Component,
11747 N_Slice);
11748 end Has_Prefix;
11749
11750 ---------------------------
11751 -- Has_Private_Component --
11752 ---------------------------
11753
11754 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
11755 Btype : Entity_Id := Base_Type (Type_Id);
11756 Component : Entity_Id;
11757
11758 begin
11759 if Error_Posted (Type_Id)
11760 or else Error_Posted (Btype)
11761 then
11762 return False;
11763 end if;
11764
11765 if Is_Class_Wide_Type (Btype) then
11766 Btype := Root_Type (Btype);
11767 end if;
11768
11769 if Is_Private_Type (Btype) then
11770 declare
11771 UT : constant Entity_Id := Underlying_Type (Btype);
11772 begin
11773 if No (UT) then
11774 if No (Full_View (Btype)) then
11775 return not Is_Generic_Type (Btype)
11776 and then
11777 not Is_Generic_Type (Root_Type (Btype));
11778 else
11779 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
11780 end if;
11781 else
11782 return not Is_Frozen (UT) and then Has_Private_Component (UT);
11783 end if;
11784 end;
11785
11786 elsif Is_Array_Type (Btype) then
11787 return Has_Private_Component (Component_Type (Btype));
11788
11789 elsif Is_Record_Type (Btype) then
11790 Component := First_Component (Btype);
11791 while Present (Component) loop
11792 if Has_Private_Component (Etype (Component)) then
11793 return True;
11794 end if;
11795
11796 Next_Component (Component);
11797 end loop;
11798
11799 return False;
11800
11801 elsif Is_Protected_Type (Btype)
11802 and then Present (Corresponding_Record_Type (Btype))
11803 then
11804 return Has_Private_Component (Corresponding_Record_Type (Btype));
11805
11806 else
11807 return False;
11808 end if;
11809 end Has_Private_Component;
11810
11811 ----------------------
11812 -- Has_Signed_Zeros --
11813 ----------------------
11814
11815 function Has_Signed_Zeros (E : Entity_Id) return Boolean is
11816 begin
11817 return Is_Floating_Point_Type (E) and then Signed_Zeros_On_Target;
11818 end Has_Signed_Zeros;
11819
11820 ------------------------------
11821 -- Has_Significant_Contract --
11822 ------------------------------
11823
11824 function Has_Significant_Contract (Subp_Id : Entity_Id) return Boolean is
11825 Subp_Nam : constant Name_Id := Chars (Subp_Id);
11826
11827 begin
11828 -- _Finalizer procedure
11829
11830 if Subp_Nam = Name_uFinalizer then
11831 return False;
11832
11833 -- _Postconditions procedure
11834
11835 elsif Subp_Nam = Name_uPostconditions then
11836 return False;
11837
11838 -- Predicate function
11839
11840 elsif Ekind (Subp_Id) = E_Function
11841 and then Is_Predicate_Function (Subp_Id)
11842 then
11843 return False;
11844
11845 -- TSS subprogram
11846
11847 elsif Get_TSS_Name (Subp_Id) /= TSS_Null then
11848 return False;
11849
11850 else
11851 return True;
11852 end if;
11853 end Has_Significant_Contract;
11854
11855 -----------------------------
11856 -- Has_Static_Array_Bounds --
11857 -----------------------------
11858
11859 function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is
11860 All_Static : Boolean;
11861 Dummy : Boolean;
11862
11863 begin
11864 Examine_Array_Bounds (Typ, All_Static, Dummy);
11865
11866 return All_Static;
11867 end Has_Static_Array_Bounds;
11868
11869 ---------------------------------------
11870 -- Has_Static_Non_Empty_Array_Bounds --
11871 ---------------------------------------
11872
11873 function Has_Static_Non_Empty_Array_Bounds (Typ : Node_Id) return Boolean is
11874 All_Static : Boolean;
11875 Has_Empty : Boolean;
11876
11877 begin
11878 Examine_Array_Bounds (Typ, All_Static, Has_Empty);
11879
11880 return All_Static and not Has_Empty;
11881 end Has_Static_Non_Empty_Array_Bounds;
11882
11883 ----------------
11884 -- Has_Stream --
11885 ----------------
11886
11887 function Has_Stream (T : Entity_Id) return Boolean is
11888 E : Entity_Id;
11889
11890 begin
11891 if No (T) then
11892 return False;
11893
11894 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
11895 return True;
11896
11897 elsif Is_Array_Type (T) then
11898 return Has_Stream (Component_Type (T));
11899
11900 elsif Is_Record_Type (T) then
11901 E := First_Component (T);
11902 while Present (E) loop
11903 if Has_Stream (Etype (E)) then
11904 return True;
11905 else
11906 Next_Component (E);
11907 end if;
11908 end loop;
11909
11910 return False;
11911
11912 elsif Is_Private_Type (T) then
11913 return Has_Stream (Underlying_Type (T));
11914
11915 else
11916 return False;
11917 end if;
11918 end Has_Stream;
11919
11920 ----------------
11921 -- Has_Suffix --
11922 ----------------
11923
11924 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
11925 begin
11926 Get_Name_String (Chars (E));
11927 return Name_Buffer (Name_Len) = Suffix;
11928 end Has_Suffix;
11929
11930 ----------------
11931 -- Add_Suffix --
11932 ----------------
11933
11934 function Add_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
11935 begin
11936 Get_Name_String (Chars (E));
11937 Add_Char_To_Name_Buffer (Suffix);
11938 return Name_Find;
11939 end Add_Suffix;
11940
11941 -------------------
11942 -- Remove_Suffix --
11943 -------------------
11944
11945 function Remove_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
11946 begin
11947 pragma Assert (Has_Suffix (E, Suffix));
11948 Get_Name_String (Chars (E));
11949 Name_Len := Name_Len - 1;
11950 return Name_Find;
11951 end Remove_Suffix;
11952
11953 ----------------------------------
11954 -- Replace_Null_By_Null_Address --
11955 ----------------------------------
11956
11957 procedure Replace_Null_By_Null_Address (N : Node_Id) is
11958 procedure Replace_Null_Operand (Op : Node_Id; Other_Op : Node_Id);
11959 -- Replace operand Op with a reference to Null_Address when the operand
11960 -- denotes a null Address. Other_Op denotes the other operand.
11961
11962 --------------------------
11963 -- Replace_Null_Operand --
11964 --------------------------
11965
11966 procedure Replace_Null_Operand (Op : Node_Id; Other_Op : Node_Id) is
11967 begin
11968 -- Check the type of the complementary operand since the N_Null node
11969 -- has not been decorated yet.
11970
11971 if Nkind (Op) = N_Null
11972 and then Is_Descendant_Of_Address (Etype (Other_Op))
11973 then
11974 Rewrite (Op, New_Occurrence_Of (RTE (RE_Null_Address), Sloc (Op)));
11975 end if;
11976 end Replace_Null_Operand;
11977
11978 -- Start of processing for Replace_Null_By_Null_Address
11979
11980 begin
11981 pragma Assert (Relaxed_RM_Semantics);
11982 pragma Assert (Nkind_In (N, N_Null,
11983 N_Op_Eq,
11984 N_Op_Ge,
11985 N_Op_Gt,
11986 N_Op_Le,
11987 N_Op_Lt,
11988 N_Op_Ne));
11989
11990 if Nkind (N) = N_Null then
11991 Rewrite (N, New_Occurrence_Of (RTE (RE_Null_Address), Sloc (N)));
11992
11993 else
11994 declare
11995 L : constant Node_Id := Left_Opnd (N);
11996 R : constant Node_Id := Right_Opnd (N);
11997
11998 begin
11999 Replace_Null_Operand (L, Other_Op => R);
12000 Replace_Null_Operand (R, Other_Op => L);
12001 end;
12002 end if;
12003 end Replace_Null_By_Null_Address;
12004
12005 --------------------------
12006 -- Has_Tagged_Component --
12007 --------------------------
12008
12009 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
12010 Comp : Entity_Id;
12011
12012 begin
12013 if Is_Private_Type (Typ) and then Present (Underlying_Type (Typ)) then
12014 return Has_Tagged_Component (Underlying_Type (Typ));
12015
12016 elsif Is_Array_Type (Typ) then
12017 return Has_Tagged_Component (Component_Type (Typ));
12018
12019 elsif Is_Tagged_Type (Typ) then
12020 return True;
12021
12022 elsif Is_Record_Type (Typ) then
12023 Comp := First_Component (Typ);
12024 while Present (Comp) loop
12025 if Has_Tagged_Component (Etype (Comp)) then
12026 return True;
12027 end if;
12028
12029 Next_Component (Comp);
12030 end loop;
12031
12032 return False;
12033
12034 else
12035 return False;
12036 end if;
12037 end Has_Tagged_Component;
12038
12039 -----------------------------
12040 -- Has_Undefined_Reference --
12041 -----------------------------
12042
12043 function Has_Undefined_Reference (Expr : Node_Id) return Boolean is
12044 Has_Undef_Ref : Boolean := False;
12045 -- Flag set when expression Expr contains at least one undefined
12046 -- reference.
12047
12048 function Is_Undefined_Reference (N : Node_Id) return Traverse_Result;
12049 -- Determine whether N denotes a reference and if it does, whether it is
12050 -- undefined.
12051
12052 ----------------------------
12053 -- Is_Undefined_Reference --
12054 ----------------------------
12055
12056 function Is_Undefined_Reference (N : Node_Id) return Traverse_Result is
12057 begin
12058 if Is_Entity_Name (N)
12059 and then Present (Entity (N))
12060 and then Entity (N) = Any_Id
12061 then
12062 Has_Undef_Ref := True;
12063 return Abandon;
12064 end if;
12065
12066 return OK;
12067 end Is_Undefined_Reference;
12068
12069 procedure Find_Undefined_References is
12070 new Traverse_Proc (Is_Undefined_Reference);
12071
12072 -- Start of processing for Has_Undefined_Reference
12073
12074 begin
12075 Find_Undefined_References (Expr);
12076
12077 return Has_Undef_Ref;
12078 end Has_Undefined_Reference;
12079
12080 ----------------------------
12081 -- Has_Volatile_Component --
12082 ----------------------------
12083
12084 function Has_Volatile_Component (Typ : Entity_Id) return Boolean is
12085 Comp : Entity_Id;
12086
12087 begin
12088 if Has_Volatile_Components (Typ) then
12089 return True;
12090
12091 elsif Is_Array_Type (Typ) then
12092 return Is_Volatile (Component_Type (Typ));
12093
12094 elsif Is_Record_Type (Typ) then
12095 Comp := First_Component (Typ);
12096 while Present (Comp) loop
12097 if Is_Volatile_Object (Comp) then
12098 return True;
12099 end if;
12100
12101 Comp := Next_Component (Comp);
12102 end loop;
12103 end if;
12104
12105 return False;
12106 end Has_Volatile_Component;
12107
12108 -------------------------
12109 -- Implementation_Kind --
12110 -------------------------
12111
12112 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
12113 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
12114 Arg : Node_Id;
12115 begin
12116 pragma Assert (Present (Impl_Prag));
12117 Arg := Last (Pragma_Argument_Associations (Impl_Prag));
12118 return Chars (Get_Pragma_Arg (Arg));
12119 end Implementation_Kind;
12120
12121 --------------------------
12122 -- Implements_Interface --
12123 --------------------------
12124
12125 function Implements_Interface
12126 (Typ_Ent : Entity_Id;
12127 Iface_Ent : Entity_Id;
12128 Exclude_Parents : Boolean := False) return Boolean
12129 is
12130 Ifaces_List : Elist_Id;
12131 Elmt : Elmt_Id;
12132 Iface : Entity_Id := Base_Type (Iface_Ent);
12133 Typ : Entity_Id := Base_Type (Typ_Ent);
12134
12135 begin
12136 if Is_Class_Wide_Type (Typ) then
12137 Typ := Root_Type (Typ);
12138 end if;
12139
12140 if not Has_Interfaces (Typ) then
12141 return False;
12142 end if;
12143
12144 if Is_Class_Wide_Type (Iface) then
12145 Iface := Root_Type (Iface);
12146 end if;
12147
12148 Collect_Interfaces (Typ, Ifaces_List);
12149
12150 Elmt := First_Elmt (Ifaces_List);
12151 while Present (Elmt) loop
12152 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
12153 and then Exclude_Parents
12154 then
12155 null;
12156
12157 elsif Node (Elmt) = Iface then
12158 return True;
12159 end if;
12160
12161 Next_Elmt (Elmt);
12162 end loop;
12163
12164 return False;
12165 end Implements_Interface;
12166
12167 ------------------------------------
12168 -- In_Assertion_Expression_Pragma --
12169 ------------------------------------
12170
12171 function In_Assertion_Expression_Pragma (N : Node_Id) return Boolean is
12172 Par : Node_Id;
12173 Prag : Node_Id := Empty;
12174
12175 begin
12176 -- Climb the parent chain looking for an enclosing pragma
12177
12178 Par := N;
12179 while Present (Par) loop
12180 if Nkind (Par) = N_Pragma then
12181 Prag := Par;
12182 exit;
12183
12184 -- Precondition-like pragmas are expanded into if statements, check
12185 -- the original node instead.
12186
12187 elsif Nkind (Original_Node (Par)) = N_Pragma then
12188 Prag := Original_Node (Par);
12189 exit;
12190
12191 -- The expansion of attribute 'Old generates a constant to capture
12192 -- the result of the prefix. If the parent traversal reaches
12193 -- one of these constants, then the node technically came from a
12194 -- postcondition-like pragma. Note that the Ekind is not tested here
12195 -- because N may be the expression of an object declaration which is
12196 -- currently being analyzed. Such objects carry Ekind of E_Void.
12197
12198 elsif Nkind (Par) = N_Object_Declaration
12199 and then Constant_Present (Par)
12200 and then Stores_Attribute_Old_Prefix (Defining_Entity (Par))
12201 then
12202 return True;
12203
12204 -- Prevent the search from going too far
12205
12206 elsif Is_Body_Or_Package_Declaration (Par) then
12207 return False;
12208 end if;
12209
12210 Par := Parent (Par);
12211 end loop;
12212
12213 return
12214 Present (Prag)
12215 and then Assertion_Expression_Pragma (Get_Pragma_Id (Prag));
12216 end In_Assertion_Expression_Pragma;
12217
12218 ----------------------
12219 -- In_Generic_Scope --
12220 ----------------------
12221
12222 function In_Generic_Scope (E : Entity_Id) return Boolean is
12223 S : Entity_Id;
12224
12225 begin
12226 S := Scope (E);
12227 while Present (S) and then S /= Standard_Standard loop
12228 if Is_Generic_Unit (S) then
12229 return True;
12230 end if;
12231
12232 S := Scope (S);
12233 end loop;
12234
12235 return False;
12236 end In_Generic_Scope;
12237
12238 -----------------
12239 -- In_Instance --
12240 -----------------
12241
12242 function In_Instance return Boolean is
12243 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
12244 S : Entity_Id;
12245
12246 begin
12247 S := Current_Scope;
12248 while Present (S) and then S /= Standard_Standard loop
12249 if Is_Generic_Instance (S) then
12250
12251 -- A child instance is always compiled in the context of a parent
12252 -- instance. Nevertheless, the actuals are not analyzed in an
12253 -- instance context. We detect this case by examining the current
12254 -- compilation unit, which must be a child instance, and checking
12255 -- that it is not currently on the scope stack.
12256
12257 if Is_Child_Unit (Curr_Unit)
12258 and then Nkind (Unit (Cunit (Current_Sem_Unit))) =
12259 N_Package_Instantiation
12260 and then not In_Open_Scopes (Curr_Unit)
12261 then
12262 return False;
12263 else
12264 return True;
12265 end if;
12266 end if;
12267
12268 S := Scope (S);
12269 end loop;
12270
12271 return False;
12272 end In_Instance;
12273
12274 ----------------------
12275 -- In_Instance_Body --
12276 ----------------------
12277
12278 function In_Instance_Body return Boolean is
12279 S : Entity_Id;
12280
12281 begin
12282 S := Current_Scope;
12283 while Present (S) and then S /= Standard_Standard loop
12284 if Ekind_In (S, E_Function, E_Procedure)
12285 and then Is_Generic_Instance (S)
12286 then
12287 return True;
12288
12289 elsif Ekind (S) = E_Package
12290 and then In_Package_Body (S)
12291 and then Is_Generic_Instance (S)
12292 then
12293 return True;
12294 end if;
12295
12296 S := Scope (S);
12297 end loop;
12298
12299 return False;
12300 end In_Instance_Body;
12301
12302 -----------------------------
12303 -- In_Instance_Not_Visible --
12304 -----------------------------
12305
12306 function In_Instance_Not_Visible return Boolean is
12307 S : Entity_Id;
12308
12309 begin
12310 S := Current_Scope;
12311 while Present (S) and then S /= Standard_Standard loop
12312 if Ekind_In (S, E_Function, E_Procedure)
12313 and then Is_Generic_Instance (S)
12314 then
12315 return True;
12316
12317 elsif Ekind (S) = E_Package
12318 and then (In_Package_Body (S) or else In_Private_Part (S))
12319 and then Is_Generic_Instance (S)
12320 then
12321 return True;
12322 end if;
12323
12324 S := Scope (S);
12325 end loop;
12326
12327 return False;
12328 end In_Instance_Not_Visible;
12329
12330 ------------------------------
12331 -- In_Instance_Visible_Part --
12332 ------------------------------
12333
12334 function In_Instance_Visible_Part
12335 (Id : Entity_Id := Current_Scope) return Boolean
12336 is
12337 Inst : Entity_Id;
12338
12339 begin
12340 Inst := Id;
12341 while Present (Inst) and then Inst /= Standard_Standard loop
12342 if Ekind (Inst) = E_Package
12343 and then Is_Generic_Instance (Inst)
12344 and then not In_Package_Body (Inst)
12345 and then not In_Private_Part (Inst)
12346 then
12347 return True;
12348 end if;
12349
12350 Inst := Scope (Inst);
12351 end loop;
12352
12353 return False;
12354 end In_Instance_Visible_Part;
12355
12356 ---------------------
12357 -- In_Package_Body --
12358 ---------------------
12359
12360 function In_Package_Body return Boolean is
12361 S : Entity_Id;
12362
12363 begin
12364 S := Current_Scope;
12365 while Present (S) and then S /= Standard_Standard loop
12366 if Ekind (S) = E_Package and then In_Package_Body (S) then
12367 return True;
12368 else
12369 S := Scope (S);
12370 end if;
12371 end loop;
12372
12373 return False;
12374 end In_Package_Body;
12375
12376 --------------------------
12377 -- In_Pragma_Expression --
12378 --------------------------
12379
12380 function In_Pragma_Expression (N : Node_Id; Nam : Name_Id) return Boolean is
12381 P : Node_Id;
12382 begin
12383 P := Parent (N);
12384 loop
12385 if No (P) then
12386 return False;
12387 elsif Nkind (P) = N_Pragma and then Pragma_Name (P) = Nam then
12388 return True;
12389 else
12390 P := Parent (P);
12391 end if;
12392 end loop;
12393 end In_Pragma_Expression;
12394
12395 ---------------------------
12396 -- In_Pre_Post_Condition --
12397 ---------------------------
12398
12399 function In_Pre_Post_Condition (N : Node_Id) return Boolean is
12400 Par : Node_Id;
12401 Prag : Node_Id := Empty;
12402 Prag_Id : Pragma_Id;
12403
12404 begin
12405 -- Climb the parent chain looking for an enclosing pragma
12406
12407 Par := N;
12408 while Present (Par) loop
12409 if Nkind (Par) = N_Pragma then
12410 Prag := Par;
12411 exit;
12412
12413 -- Prevent the search from going too far
12414
12415 elsif Is_Body_Or_Package_Declaration (Par) then
12416 exit;
12417 end if;
12418
12419 Par := Parent (Par);
12420 end loop;
12421
12422 if Present (Prag) then
12423 Prag_Id := Get_Pragma_Id (Prag);
12424
12425 return
12426 Prag_Id = Pragma_Post
12427 or else Prag_Id = Pragma_Post_Class
12428 or else Prag_Id = Pragma_Postcondition
12429 or else Prag_Id = Pragma_Pre
12430 or else Prag_Id = Pragma_Pre_Class
12431 or else Prag_Id = Pragma_Precondition;
12432
12433 -- Otherwise the node is not enclosed by a pre/postcondition pragma
12434
12435 else
12436 return False;
12437 end if;
12438 end In_Pre_Post_Condition;
12439
12440 ------------------------------
12441 -- In_Quantified_Expression --
12442 ------------------------------
12443
12444 function In_Quantified_Expression (N : Node_Id) return Boolean is
12445 P : Node_Id;
12446 begin
12447 P := Parent (N);
12448 loop
12449 if No (P) then
12450 return False;
12451 elsif Nkind (P) = N_Quantified_Expression then
12452 return True;
12453 else
12454 P := Parent (P);
12455 end if;
12456 end loop;
12457 end In_Quantified_Expression;
12458
12459 -------------------------------------
12460 -- In_Reverse_Storage_Order_Object --
12461 -------------------------------------
12462
12463 function In_Reverse_Storage_Order_Object (N : Node_Id) return Boolean is
12464 Pref : Node_Id;
12465 Btyp : Entity_Id := Empty;
12466
12467 begin
12468 -- Climb up indexed components
12469
12470 Pref := N;
12471 loop
12472 case Nkind (Pref) is
12473 when N_Selected_Component =>
12474 Pref := Prefix (Pref);
12475 exit;
12476
12477 when N_Indexed_Component =>
12478 Pref := Prefix (Pref);
12479
12480 when others =>
12481 Pref := Empty;
12482 exit;
12483 end case;
12484 end loop;
12485
12486 if Present (Pref) then
12487 Btyp := Base_Type (Etype (Pref));
12488 end if;
12489
12490 return Present (Btyp)
12491 and then (Is_Record_Type (Btyp) or else Is_Array_Type (Btyp))
12492 and then Reverse_Storage_Order (Btyp);
12493 end In_Reverse_Storage_Order_Object;
12494
12495 ------------------------------
12496 -- In_Same_Declarative_Part --
12497 ------------------------------
12498
12499 function In_Same_Declarative_Part
12500 (Context : Node_Id;
12501 N : Node_Id) return Boolean
12502 is
12503 Cont : Node_Id := Context;
12504 Nod : Node_Id;
12505
12506 begin
12507 if Nkind (Cont) = N_Compilation_Unit_Aux then
12508 Cont := Parent (Cont);
12509 end if;
12510
12511 Nod := Parent (N);
12512 while Present (Nod) loop
12513 if Nod = Cont then
12514 return True;
12515
12516 elsif Nkind_In (Nod, N_Accept_Statement,
12517 N_Block_Statement,
12518 N_Compilation_Unit,
12519 N_Entry_Body,
12520 N_Package_Body,
12521 N_Package_Declaration,
12522 N_Protected_Body,
12523 N_Subprogram_Body,
12524 N_Task_Body)
12525 then
12526 return False;
12527
12528 elsif Nkind (Nod) = N_Subunit then
12529 Nod := Corresponding_Stub (Nod);
12530
12531 else
12532 Nod := Parent (Nod);
12533 end if;
12534 end loop;
12535
12536 return False;
12537 end In_Same_Declarative_Part;
12538
12539 --------------------------------------
12540 -- In_Subprogram_Or_Concurrent_Unit --
12541 --------------------------------------
12542
12543 function In_Subprogram_Or_Concurrent_Unit return Boolean is
12544 E : Entity_Id;
12545 K : Entity_Kind;
12546
12547 begin
12548 -- Use scope chain to check successively outer scopes
12549
12550 E := Current_Scope;
12551 loop
12552 K := Ekind (E);
12553
12554 if K in Subprogram_Kind
12555 or else K in Concurrent_Kind
12556 or else K in Generic_Subprogram_Kind
12557 then
12558 return True;
12559
12560 elsif E = Standard_Standard then
12561 return False;
12562 end if;
12563
12564 E := Scope (E);
12565 end loop;
12566 end In_Subprogram_Or_Concurrent_Unit;
12567
12568 ----------------
12569 -- In_Subtree --
12570 ----------------
12571
12572 function In_Subtree (N : Node_Id; Root : Node_Id) return Boolean is
12573 Curr : Node_Id;
12574
12575 begin
12576 Curr := N;
12577 while Present (Curr) loop
12578 if Curr = Root then
12579 return True;
12580 end if;
12581
12582 Curr := Parent (Curr);
12583 end loop;
12584
12585 return False;
12586 end In_Subtree;
12587
12588 ----------------
12589 -- In_Subtree --
12590 ----------------
12591
12592 function In_Subtree
12593 (N : Node_Id;
12594 Root1 : Node_Id;
12595 Root2 : Node_Id) return Boolean
12596 is
12597 Curr : Node_Id;
12598
12599 begin
12600 Curr := N;
12601 while Present (Curr) loop
12602 if Curr = Root1 or else Curr = Root2 then
12603 return True;
12604 end if;
12605
12606 Curr := Parent (Curr);
12607 end loop;
12608
12609 return False;
12610 end In_Subtree;
12611
12612 ---------------------
12613 -- In_Visible_Part --
12614 ---------------------
12615
12616 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
12617 begin
12618 return Is_Package_Or_Generic_Package (Scope_Id)
12619 and then In_Open_Scopes (Scope_Id)
12620 and then not In_Package_Body (Scope_Id)
12621 and then not In_Private_Part (Scope_Id);
12622 end In_Visible_Part;
12623
12624 --------------------------------
12625 -- Incomplete_Or_Partial_View --
12626 --------------------------------
12627
12628 function Incomplete_Or_Partial_View (Id : Entity_Id) return Entity_Id is
12629 function Inspect_Decls
12630 (Decls : List_Id;
12631 Taft : Boolean := False) return Entity_Id;
12632 -- Check whether a declarative region contains the incomplete or partial
12633 -- view of Id.
12634
12635 -------------------
12636 -- Inspect_Decls --
12637 -------------------
12638
12639 function Inspect_Decls
12640 (Decls : List_Id;
12641 Taft : Boolean := False) return Entity_Id
12642 is
12643 Decl : Node_Id;
12644 Match : Node_Id;
12645
12646 begin
12647 Decl := First (Decls);
12648 while Present (Decl) loop
12649 Match := Empty;
12650
12651 -- The partial view of a Taft-amendment type is an incomplete
12652 -- type.
12653
12654 if Taft then
12655 if Nkind (Decl) = N_Incomplete_Type_Declaration then
12656 Match := Defining_Identifier (Decl);
12657 end if;
12658
12659 -- Otherwise look for a private type whose full view matches the
12660 -- input type. Note that this checks full_type_declaration nodes
12661 -- to account for derivations from a private type where the type
12662 -- declaration hold the partial view and the full view is an
12663 -- itype.
12664
12665 elsif Nkind_In (Decl, N_Full_Type_Declaration,
12666 N_Private_Extension_Declaration,
12667 N_Private_Type_Declaration)
12668 then
12669 Match := Defining_Identifier (Decl);
12670 end if;
12671
12672 -- Guard against unanalyzed entities
12673
12674 if Present (Match)
12675 and then Is_Type (Match)
12676 and then Present (Full_View (Match))
12677 and then Full_View (Match) = Id
12678 then
12679 return Match;
12680 end if;
12681
12682 Next (Decl);
12683 end loop;
12684
12685 return Empty;
12686 end Inspect_Decls;
12687
12688 -- Local variables
12689
12690 Prev : Entity_Id;
12691
12692 -- Start of processing for Incomplete_Or_Partial_View
12693
12694 begin
12695 -- Deferred constant or incomplete type case
12696
12697 Prev := Current_Entity_In_Scope (Id);
12698
12699 if Present (Prev)
12700 and then (Is_Incomplete_Type (Prev) or else Ekind (Prev) = E_Constant)
12701 and then Present (Full_View (Prev))
12702 and then Full_View (Prev) = Id
12703 then
12704 return Prev;
12705 end if;
12706
12707 -- Private or Taft amendment type case
12708
12709 declare
12710 Pkg : constant Entity_Id := Scope (Id);
12711 Pkg_Decl : Node_Id := Pkg;
12712
12713 begin
12714 if Present (Pkg)
12715 and then Ekind_In (Pkg, E_Generic_Package, E_Package)
12716 then
12717 while Nkind (Pkg_Decl) /= N_Package_Specification loop
12718 Pkg_Decl := Parent (Pkg_Decl);
12719 end loop;
12720
12721 -- It is knows that Typ has a private view, look for it in the
12722 -- visible declarations of the enclosing scope. A special case
12723 -- of this is when the two views have been exchanged - the full
12724 -- appears earlier than the private.
12725
12726 if Has_Private_Declaration (Id) then
12727 Prev := Inspect_Decls (Visible_Declarations (Pkg_Decl));
12728
12729 -- Exchanged view case, look in the private declarations
12730
12731 if No (Prev) then
12732 Prev := Inspect_Decls (Private_Declarations (Pkg_Decl));
12733 end if;
12734
12735 return Prev;
12736
12737 -- Otherwise if this is the package body, then Typ is a potential
12738 -- Taft amendment type. The incomplete view should be located in
12739 -- the private declarations of the enclosing scope.
12740
12741 elsif In_Package_Body (Pkg) then
12742 return Inspect_Decls (Private_Declarations (Pkg_Decl), True);
12743 end if;
12744 end if;
12745 end;
12746
12747 -- The type has no incomplete or private view
12748
12749 return Empty;
12750 end Incomplete_Or_Partial_View;
12751
12752 ---------------------------------------
12753 -- Incomplete_View_From_Limited_With --
12754 ---------------------------------------
12755
12756 function Incomplete_View_From_Limited_With
12757 (Typ : Entity_Id) return Entity_Id
12758 is
12759 begin
12760 -- It might make sense to make this an attribute in Einfo, and set it
12761 -- in Sem_Ch10 in Build_Shadow_Entity. However, we're running short on
12762 -- slots for new attributes, and it seems a bit simpler to just search
12763 -- the Limited_View (if it exists) for an incomplete type whose
12764 -- Non_Limited_View is Typ.
12765
12766 if Ekind (Scope (Typ)) = E_Package
12767 and then Present (Limited_View (Scope (Typ)))
12768 then
12769 declare
12770 Ent : Entity_Id := First_Entity (Limited_View (Scope (Typ)));
12771 begin
12772 while Present (Ent) loop
12773 if Ekind (Ent) in Incomplete_Kind
12774 and then Non_Limited_View (Ent) = Typ
12775 then
12776 return Ent;
12777 end if;
12778
12779 Ent := Next_Entity (Ent);
12780 end loop;
12781 end;
12782 end if;
12783
12784 return Typ;
12785 end Incomplete_View_From_Limited_With;
12786
12787 ----------------------------------
12788 -- Indexed_Component_Bit_Offset --
12789 ----------------------------------
12790
12791 function Indexed_Component_Bit_Offset (N : Node_Id) return Uint is
12792 Exp : constant Node_Id := First (Expressions (N));
12793 Typ : constant Entity_Id := Etype (Prefix (N));
12794 Off : constant Uint := Component_Size (Typ);
12795 Ind : Node_Id;
12796
12797 begin
12798 -- Return early if the component size is not known or variable
12799
12800 if Off = No_Uint or else Off < Uint_0 then
12801 return No_Uint;
12802 end if;
12803
12804 -- Deal with the degenerate case of an empty component
12805
12806 if Off = Uint_0 then
12807 return Off;
12808 end if;
12809
12810 -- Check that both the index value and the low bound are known
12811
12812 if not Compile_Time_Known_Value (Exp) then
12813 return No_Uint;
12814 end if;
12815
12816 Ind := First_Index (Typ);
12817 if No (Ind) then
12818 return No_Uint;
12819 end if;
12820
12821 if Nkind (Ind) = N_Subtype_Indication then
12822 Ind := Constraint (Ind);
12823
12824 if Nkind (Ind) = N_Range_Constraint then
12825 Ind := Range_Expression (Ind);
12826 end if;
12827 end if;
12828
12829 if Nkind (Ind) /= N_Range
12830 or else not Compile_Time_Known_Value (Low_Bound (Ind))
12831 then
12832 return No_Uint;
12833 end if;
12834
12835 -- Return the scaled offset
12836
12837 return Off * (Expr_Value (Exp) - Expr_Value (Low_Bound ((Ind))));
12838 end Indexed_Component_Bit_Offset;
12839
12840 ----------------------------
12841 -- Inherit_Rep_Item_Chain --
12842 ----------------------------
12843
12844 procedure Inherit_Rep_Item_Chain (Typ : Entity_Id; From_Typ : Entity_Id) is
12845 Item : Node_Id;
12846 Next_Item : Node_Id;
12847
12848 begin
12849 -- There are several inheritance scenarios to consider depending on
12850 -- whether both types have rep item chains and whether the destination
12851 -- type already inherits part of the source type's rep item chain.
12852
12853 -- 1) The source type lacks a rep item chain
12854 -- From_Typ ---> Empty
12855 --
12856 -- Typ --------> Item (or Empty)
12857
12858 -- In this case inheritance cannot take place because there are no items
12859 -- to inherit.
12860
12861 -- 2) The destination type lacks a rep item chain
12862 -- From_Typ ---> Item ---> ...
12863 --
12864 -- Typ --------> Empty
12865
12866 -- Inheritance takes place by setting the First_Rep_Item of the
12867 -- destination type to the First_Rep_Item of the source type.
12868 -- From_Typ ---> Item ---> ...
12869 -- ^
12870 -- Typ -----------+
12871
12872 -- 3.1) Both source and destination types have at least one rep item.
12873 -- The destination type does NOT inherit a rep item from the source
12874 -- type.
12875 -- From_Typ ---> Item ---> Item
12876 --
12877 -- Typ --------> Item ---> Item
12878
12879 -- Inheritance takes place by setting the Next_Rep_Item of the last item
12880 -- of the destination type to the First_Rep_Item of the source type.
12881 -- From_Typ -------------------> Item ---> Item
12882 -- ^
12883 -- Typ --------> Item ---> Item --+
12884
12885 -- 3.2) Both source and destination types have at least one rep item.
12886 -- The destination type DOES inherit part of the rep item chain of the
12887 -- source type.
12888 -- From_Typ ---> Item ---> Item ---> Item
12889 -- ^
12890 -- Typ --------> Item ------+
12891
12892 -- This rare case arises when the full view of a private extension must
12893 -- inherit the rep item chain from the full view of its parent type and
12894 -- the full view of the parent type contains extra rep items. Currently
12895 -- only invariants may lead to such form of inheritance.
12896
12897 -- type From_Typ is tagged private
12898 -- with Type_Invariant'Class => Item_2;
12899
12900 -- type Typ is new From_Typ with private
12901 -- with Type_Invariant => Item_4;
12902
12903 -- At this point the rep item chains contain the following items
12904
12905 -- From_Typ -----------> Item_2 ---> Item_3
12906 -- ^
12907 -- Typ --------> Item_4 --+
12908
12909 -- The full views of both types may introduce extra invariants
12910
12911 -- type From_Typ is tagged null record
12912 -- with Type_Invariant => Item_1;
12913
12914 -- type Typ is new From_Typ with null record;
12915
12916 -- The full view of Typ would have to inherit any new rep items added to
12917 -- the full view of From_Typ.
12918
12919 -- From_Typ -----------> Item_1 ---> Item_2 ---> Item_3
12920 -- ^
12921 -- Typ --------> Item_4 --+
12922
12923 -- To achieve this form of inheritance, the destination type must first
12924 -- sever the link between its own rep chain and that of the source type,
12925 -- then inheritance 3.1 takes place.
12926
12927 -- Case 1: The source type lacks a rep item chain
12928
12929 if No (First_Rep_Item (From_Typ)) then
12930 return;
12931
12932 -- Case 2: The destination type lacks a rep item chain
12933
12934 elsif No (First_Rep_Item (Typ)) then
12935 Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ));
12936
12937 -- Case 3: Both the source and destination types have at least one rep
12938 -- item. Traverse the rep item chain of the destination type to find the
12939 -- last rep item.
12940
12941 else
12942 Item := Empty;
12943 Next_Item := First_Rep_Item (Typ);
12944 while Present (Next_Item) loop
12945
12946 -- Detect a link between the destination type's rep chain and that
12947 -- of the source type. There are two possibilities:
12948
12949 -- Variant 1
12950 -- Next_Item
12951 -- V
12952 -- From_Typ ---> Item_1 --->
12953 -- ^
12954 -- Typ -----------+
12955 --
12956 -- Item is Empty
12957
12958 -- Variant 2
12959 -- Next_Item
12960 -- V
12961 -- From_Typ ---> Item_1 ---> Item_2 --->
12962 -- ^
12963 -- Typ --------> Item_3 ------+
12964 -- ^
12965 -- Item
12966
12967 if Has_Rep_Item (From_Typ, Next_Item) then
12968 exit;
12969 end if;
12970
12971 Item := Next_Item;
12972 Next_Item := Next_Rep_Item (Next_Item);
12973 end loop;
12974
12975 -- Inherit the source type's rep item chain
12976
12977 if Present (Item) then
12978 Set_Next_Rep_Item (Item, First_Rep_Item (From_Typ));
12979 else
12980 Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ));
12981 end if;
12982 end if;
12983 end Inherit_Rep_Item_Chain;
12984
12985 ------------------------------------
12986 -- Inherits_From_Tagged_Full_View --
12987 ------------------------------------
12988
12989 function Inherits_From_Tagged_Full_View (Typ : Entity_Id) return Boolean is
12990 begin
12991 return Is_Private_Type (Typ)
12992 and then Present (Full_View (Typ))
12993 and then Is_Private_Type (Full_View (Typ))
12994 and then not Is_Tagged_Type (Full_View (Typ))
12995 and then Present (Underlying_Type (Full_View (Typ)))
12996 and then Is_Tagged_Type (Underlying_Type (Full_View (Typ)));
12997 end Inherits_From_Tagged_Full_View;
12998
12999 ---------------------------------
13000 -- Insert_Explicit_Dereference --
13001 ---------------------------------
13002
13003 procedure Insert_Explicit_Dereference (N : Node_Id) is
13004 New_Prefix : constant Node_Id := Relocate_Node (N);
13005 Ent : Entity_Id := Empty;
13006 Pref : Node_Id;
13007 I : Interp_Index;
13008 It : Interp;
13009 T : Entity_Id;
13010
13011 begin
13012 Save_Interps (N, New_Prefix);
13013
13014 Rewrite (N,
13015 Make_Explicit_Dereference (Sloc (Parent (N)),
13016 Prefix => New_Prefix));
13017
13018 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
13019
13020 if Is_Overloaded (New_Prefix) then
13021
13022 -- The dereference is also overloaded, and its interpretations are
13023 -- the designated types of the interpretations of the original node.
13024
13025 Set_Etype (N, Any_Type);
13026
13027 Get_First_Interp (New_Prefix, I, It);
13028 while Present (It.Nam) loop
13029 T := It.Typ;
13030
13031 if Is_Access_Type (T) then
13032 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
13033 end if;
13034
13035 Get_Next_Interp (I, It);
13036 end loop;
13037
13038 End_Interp_List;
13039
13040 else
13041 -- Prefix is unambiguous: mark the original prefix (which might
13042 -- Come_From_Source) as a reference, since the new (relocated) one
13043 -- won't be taken into account.
13044
13045 if Is_Entity_Name (New_Prefix) then
13046 Ent := Entity (New_Prefix);
13047 Pref := New_Prefix;
13048
13049 -- For a retrieval of a subcomponent of some composite object,
13050 -- retrieve the ultimate entity if there is one.
13051
13052 elsif Nkind_In (New_Prefix, N_Selected_Component,
13053 N_Indexed_Component)
13054 then
13055 Pref := Prefix (New_Prefix);
13056 while Present (Pref)
13057 and then Nkind_In (Pref, N_Selected_Component,
13058 N_Indexed_Component)
13059 loop
13060 Pref := Prefix (Pref);
13061 end loop;
13062
13063 if Present (Pref) and then Is_Entity_Name (Pref) then
13064 Ent := Entity (Pref);
13065 end if;
13066 end if;
13067
13068 -- Place the reference on the entity node
13069
13070 if Present (Ent) then
13071 Generate_Reference (Ent, Pref);
13072 end if;
13073 end if;
13074 end Insert_Explicit_Dereference;
13075
13076 ------------------------------------------
13077 -- Inspect_Deferred_Constant_Completion --
13078 ------------------------------------------
13079
13080 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
13081 Decl : Node_Id;
13082
13083 begin
13084 Decl := First (Decls);
13085 while Present (Decl) loop
13086
13087 -- Deferred constant signature
13088
13089 if Nkind (Decl) = N_Object_Declaration
13090 and then Constant_Present (Decl)
13091 and then No (Expression (Decl))
13092
13093 -- No need to check internally generated constants
13094
13095 and then Comes_From_Source (Decl)
13096
13097 -- The constant is not completed. A full object declaration or a
13098 -- pragma Import complete a deferred constant.
13099
13100 and then not Has_Completion (Defining_Identifier (Decl))
13101 then
13102 Error_Msg_N
13103 ("constant declaration requires initialization expression",
13104 Defining_Identifier (Decl));
13105 end if;
13106
13107 Decl := Next (Decl);
13108 end loop;
13109 end Inspect_Deferred_Constant_Completion;
13110
13111 -------------------------------
13112 -- Install_Elaboration_Model --
13113 -------------------------------
13114
13115 procedure Install_Elaboration_Model (Unit_Id : Entity_Id) is
13116 function Find_Elaboration_Checks_Pragma (L : List_Id) return Node_Id;
13117 -- Try to find pragma Elaboration_Checks in arbitrary list L. Return
13118 -- Empty if there is no such pragma.
13119
13120 ------------------------------------
13121 -- Find_Elaboration_Checks_Pragma --
13122 ------------------------------------
13123
13124 function Find_Elaboration_Checks_Pragma (L : List_Id) return Node_Id is
13125 Item : Node_Id;
13126
13127 begin
13128 Item := First (L);
13129 while Present (Item) loop
13130 if Nkind (Item) = N_Pragma
13131 and then Pragma_Name (Item) = Name_Elaboration_Checks
13132 then
13133 return Item;
13134 end if;
13135
13136 Next (Item);
13137 end loop;
13138
13139 return Empty;
13140 end Find_Elaboration_Checks_Pragma;
13141
13142 -- Local variables
13143
13144 Args : List_Id;
13145 Model : Node_Id;
13146 Prag : Node_Id;
13147 Unit : Node_Id;
13148
13149 -- Start of processing for Install_Elaboration_Model
13150
13151 begin
13152 -- Nothing to do when the unit does not exist
13153
13154 if No (Unit_Id) then
13155 return;
13156 end if;
13157
13158 Unit := Parent (Unit_Declaration_Node (Unit_Id));
13159
13160 -- Nothing to do when the unit is not a library unit
13161
13162 if Nkind (Unit) /= N_Compilation_Unit then
13163 return;
13164 end if;
13165
13166 Prag := Find_Elaboration_Checks_Pragma (Context_Items (Unit));
13167
13168 -- The compilation unit is subject to pragma Elaboration_Checks. Set the
13169 -- elaboration model as specified by the pragma.
13170
13171 if Present (Prag) then
13172 Args := Pragma_Argument_Associations (Prag);
13173
13174 -- Guard against an illegal pragma. The sole argument must be an
13175 -- identifier which specifies either Dynamic or Static model.
13176
13177 if Present (Args) then
13178 Model := Get_Pragma_Arg (First (Args));
13179
13180 if Nkind (Model) = N_Identifier then
13181 Dynamic_Elaboration_Checks := Chars (Model) = Name_Dynamic;
13182 end if;
13183 end if;
13184 end if;
13185 end Install_Elaboration_Model;
13186
13187 -----------------------------
13188 -- Install_Generic_Formals --
13189 -----------------------------
13190
13191 procedure Install_Generic_Formals (Subp_Id : Entity_Id) is
13192 E : Entity_Id;
13193
13194 begin
13195 pragma Assert (Is_Generic_Subprogram (Subp_Id));
13196
13197 E := First_Entity (Subp_Id);
13198 while Present (E) loop
13199 Install_Entity (E);
13200 Next_Entity (E);
13201 end loop;
13202 end Install_Generic_Formals;
13203
13204 ------------------------
13205 -- Install_SPARK_Mode --
13206 ------------------------
13207
13208 procedure Install_SPARK_Mode (Mode : SPARK_Mode_Type; Prag : Node_Id) is
13209 begin
13210 SPARK_Mode := Mode;
13211 SPARK_Mode_Pragma := Prag;
13212 end Install_SPARK_Mode;
13213
13214 --------------------------
13215 -- Invalid_Scalar_Value --
13216 --------------------------
13217
13218 function Invalid_Scalar_Value
13219 (Loc : Source_Ptr;
13220 Scal_Typ : Scalar_Id) return Node_Id
13221 is
13222 function Invalid_Binder_Value return Node_Id;
13223 -- Return a reference to the corresponding invalid value for type
13224 -- Scal_Typ as defined in unit System.Scalar_Values.
13225
13226 function Invalid_Float_Value return Node_Id;
13227 -- Return the invalid value of float type Scal_Typ
13228
13229 function Invalid_Integer_Value return Node_Id;
13230 -- Return the invalid value of integer type Scal_Typ
13231
13232 procedure Set_Invalid_Binder_Values;
13233 -- Set the contents of collection Invalid_Binder_Values
13234
13235 --------------------------
13236 -- Invalid_Binder_Value --
13237 --------------------------
13238
13239 function Invalid_Binder_Value return Node_Id is
13240 Val_Id : Entity_Id;
13241
13242 begin
13243 -- Initialize the collection of invalid binder values the first time
13244 -- around.
13245
13246 Set_Invalid_Binder_Values;
13247
13248 -- Obtain the corresponding variable from System.Scalar_Values which
13249 -- holds the invalid value for this type.
13250
13251 Val_Id := Invalid_Binder_Values (Scal_Typ);
13252 pragma Assert (Present (Val_Id));
13253
13254 return New_Occurrence_Of (Val_Id, Loc);
13255 end Invalid_Binder_Value;
13256
13257 -------------------------
13258 -- Invalid_Float_Value --
13259 -------------------------
13260
13261 function Invalid_Float_Value return Node_Id is
13262 Value : constant Ureal := Invalid_Floats (Scal_Typ);
13263
13264 begin
13265 -- Pragma Invalid_Scalars did not specify an invalid value for this
13266 -- type. Fall back to the value provided by the binder.
13267
13268 if Value = No_Ureal then
13269 return Invalid_Binder_Value;
13270 else
13271 return Make_Real_Literal (Loc, Realval => Value);
13272 end if;
13273 end Invalid_Float_Value;
13274
13275 ---------------------------
13276 -- Invalid_Integer_Value --
13277 ---------------------------
13278
13279 function Invalid_Integer_Value return Node_Id is
13280 Value : constant Uint := Invalid_Integers (Scal_Typ);
13281
13282 begin
13283 -- Pragma Invalid_Scalars did not specify an invalid value for this
13284 -- type. Fall back to the value provided by the binder.
13285
13286 if Value = No_Uint then
13287 return Invalid_Binder_Value;
13288 else
13289 return Make_Integer_Literal (Loc, Intval => Value);
13290 end if;
13291 end Invalid_Integer_Value;
13292
13293 -------------------------------
13294 -- Set_Invalid_Binder_Values --
13295 -------------------------------
13296
13297 procedure Set_Invalid_Binder_Values is
13298 begin
13299 if not Invalid_Binder_Values_Set then
13300 Invalid_Binder_Values_Set := True;
13301
13302 -- Initialize the contents of the collection once since RTE calls
13303 -- are not cheap.
13304
13305 Invalid_Binder_Values :=
13306 (Name_Short_Float => RTE (RE_IS_Isf),
13307 Name_Float => RTE (RE_IS_Ifl),
13308 Name_Long_Float => RTE (RE_IS_Ilf),
13309 Name_Long_Long_Float => RTE (RE_IS_Ill),
13310 Name_Signed_8 => RTE (RE_IS_Is1),
13311 Name_Signed_16 => RTE (RE_IS_Is2),
13312 Name_Signed_32 => RTE (RE_IS_Is4),
13313 Name_Signed_64 => RTE (RE_IS_Is8),
13314 Name_Unsigned_8 => RTE (RE_IS_Iu1),
13315 Name_Unsigned_16 => RTE (RE_IS_Iu2),
13316 Name_Unsigned_32 => RTE (RE_IS_Iu4),
13317 Name_Unsigned_64 => RTE (RE_IS_Iu8));
13318 end if;
13319 end Set_Invalid_Binder_Values;
13320
13321 -- Start of processing for Invalid_Scalar_Value
13322
13323 begin
13324 if Scal_Typ in Float_Scalar_Id then
13325 return Invalid_Float_Value;
13326
13327 else pragma Assert (Scal_Typ in Integer_Scalar_Id);
13328 return Invalid_Integer_Value;
13329 end if;
13330 end Invalid_Scalar_Value;
13331
13332 -----------------------------
13333 -- Is_Actual_Out_Parameter --
13334 -----------------------------
13335
13336 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
13337 Formal : Entity_Id;
13338 Call : Node_Id;
13339 begin
13340 Find_Actual (N, Formal, Call);
13341 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
13342 end Is_Actual_Out_Parameter;
13343
13344 -------------------------
13345 -- Is_Actual_Parameter --
13346 -------------------------
13347
13348 function Is_Actual_Parameter (N : Node_Id) return Boolean is
13349 PK : constant Node_Kind := Nkind (Parent (N));
13350
13351 begin
13352 case PK is
13353 when N_Parameter_Association =>
13354 return N = Explicit_Actual_Parameter (Parent (N));
13355
13356 when N_Subprogram_Call =>
13357 return Is_List_Member (N)
13358 and then
13359 List_Containing (N) = Parameter_Associations (Parent (N));
13360
13361 when others =>
13362 return False;
13363 end case;
13364 end Is_Actual_Parameter;
13365
13366 --------------------------------
13367 -- Is_Actual_Tagged_Parameter --
13368 --------------------------------
13369
13370 function Is_Actual_Tagged_Parameter (N : Node_Id) return Boolean is
13371 Formal : Entity_Id;
13372 Call : Node_Id;
13373 begin
13374 Find_Actual (N, Formal, Call);
13375 return Present (Formal) and then Is_Tagged_Type (Etype (Formal));
13376 end Is_Actual_Tagged_Parameter;
13377
13378 ---------------------
13379 -- Is_Aliased_View --
13380 ---------------------
13381
13382 function Is_Aliased_View (Obj : Node_Id) return Boolean is
13383 E : Entity_Id;
13384
13385 begin
13386 if Is_Entity_Name (Obj) then
13387 E := Entity (Obj);
13388
13389 return
13390 (Is_Object (E)
13391 and then
13392 (Is_Aliased (E)
13393 or else (Present (Renamed_Object (E))
13394 and then Is_Aliased_View (Renamed_Object (E)))))
13395
13396 or else ((Is_Formal (E) or else Is_Formal_Object (E))
13397 and then Is_Tagged_Type (Etype (E)))
13398
13399 or else (Is_Concurrent_Type (E) and then In_Open_Scopes (E))
13400
13401 -- Current instance of type, either directly or as rewritten
13402 -- reference to the current object.
13403
13404 or else (Is_Entity_Name (Original_Node (Obj))
13405 and then Present (Entity (Original_Node (Obj)))
13406 and then Is_Type (Entity (Original_Node (Obj))))
13407
13408 or else (Is_Type (E) and then E = Current_Scope)
13409
13410 or else (Is_Incomplete_Or_Private_Type (E)
13411 and then Full_View (E) = Current_Scope)
13412
13413 -- Ada 2012 AI05-0053: the return object of an extended return
13414 -- statement is aliased if its type is immutably limited.
13415
13416 or else (Is_Return_Object (E)
13417 and then Is_Limited_View (Etype (E)));
13418
13419 elsif Nkind (Obj) = N_Selected_Component then
13420 return Is_Aliased (Entity (Selector_Name (Obj)));
13421
13422 elsif Nkind (Obj) = N_Indexed_Component then
13423 return Has_Aliased_Components (Etype (Prefix (Obj)))
13424 or else
13425 (Is_Access_Type (Etype (Prefix (Obj)))
13426 and then Has_Aliased_Components
13427 (Designated_Type (Etype (Prefix (Obj)))));
13428
13429 elsif Nkind_In (Obj, N_Unchecked_Type_Conversion, N_Type_Conversion) then
13430 return Is_Tagged_Type (Etype (Obj))
13431 and then Is_Aliased_View (Expression (Obj));
13432
13433 elsif Nkind (Obj) = N_Explicit_Dereference then
13434 return Nkind (Original_Node (Obj)) /= N_Function_Call;
13435
13436 else
13437 return False;
13438 end if;
13439 end Is_Aliased_View;
13440
13441 -------------------------
13442 -- Is_Ancestor_Package --
13443 -------------------------
13444
13445 function Is_Ancestor_Package
13446 (E1 : Entity_Id;
13447 E2 : Entity_Id) return Boolean
13448 is
13449 Par : Entity_Id;
13450
13451 begin
13452 Par := E2;
13453 while Present (Par) and then Par /= Standard_Standard loop
13454 if Par = E1 then
13455 return True;
13456 end if;
13457
13458 Par := Scope (Par);
13459 end loop;
13460
13461 return False;
13462 end Is_Ancestor_Package;
13463
13464 ----------------------
13465 -- Is_Atomic_Object --
13466 ----------------------
13467
13468 function Is_Atomic_Object (N : Node_Id) return Boolean is
13469 function Is_Atomic_Entity (Id : Entity_Id) return Boolean;
13470 pragma Inline (Is_Atomic_Entity);
13471 -- Determine whether arbitrary entity Id is either atomic or has atomic
13472 -- components.
13473
13474 function Is_Atomic_Prefix (Pref : Node_Id) return Boolean;
13475 -- Determine whether prefix Pref of an indexed or selected component is
13476 -- an atomic object.
13477
13478 ----------------------
13479 -- Is_Atomic_Entity --
13480 ----------------------
13481
13482 function Is_Atomic_Entity (Id : Entity_Id) return Boolean is
13483 begin
13484 return Is_Atomic (Id) or else Has_Atomic_Components (Id);
13485 end Is_Atomic_Entity;
13486
13487 ----------------------
13488 -- Is_Atomic_Prefix --
13489 ----------------------
13490
13491 function Is_Atomic_Prefix (Pref : Node_Id) return Boolean is
13492 Typ : constant Entity_Id := Etype (Pref);
13493
13494 begin
13495 if Is_Access_Type (Typ) then
13496 return Has_Atomic_Components (Designated_Type (Typ));
13497
13498 elsif Is_Atomic_Entity (Typ) then
13499 return True;
13500
13501 elsif Is_Entity_Name (Pref)
13502 and then Is_Atomic_Entity (Entity (Pref))
13503 then
13504 return True;
13505
13506 elsif Nkind (Pref) = N_Indexed_Component then
13507 return Is_Atomic_Prefix (Prefix (Pref));
13508
13509 elsif Nkind (Pref) = N_Selected_Component then
13510 return
13511 Is_Atomic_Prefix (Prefix (Pref))
13512 or else Is_Atomic (Entity (Selector_Name (Pref)));
13513 end if;
13514
13515 return False;
13516 end Is_Atomic_Prefix;
13517
13518 -- Start of processing for Is_Atomic_Object
13519
13520 begin
13521 if Is_Entity_Name (N) then
13522 return Is_Atomic_Object_Entity (Entity (N));
13523
13524 elsif Nkind (N) = N_Indexed_Component then
13525 return Is_Atomic (Etype (N)) or else Is_Atomic_Prefix (Prefix (N));
13526
13527 elsif Nkind (N) = N_Selected_Component then
13528 return
13529 Is_Atomic (Etype (N))
13530 or else Is_Atomic_Prefix (Prefix (N))
13531 or else Is_Atomic (Entity (Selector_Name (N)));
13532 end if;
13533
13534 return False;
13535 end Is_Atomic_Object;
13536
13537 -----------------------------
13538 -- Is_Atomic_Object_Entity --
13539 -----------------------------
13540
13541 function Is_Atomic_Object_Entity (Id : Entity_Id) return Boolean is
13542 begin
13543 return
13544 Is_Object (Id)
13545 and then (Is_Atomic (Id) or else Is_Atomic (Etype (Id)));
13546 end Is_Atomic_Object_Entity;
13547
13548 -----------------------------
13549 -- Is_Atomic_Or_VFA_Object --
13550 -----------------------------
13551
13552 function Is_Atomic_Or_VFA_Object (N : Node_Id) return Boolean is
13553 begin
13554 return Is_Atomic_Object (N)
13555 or else (Is_Object_Reference (N)
13556 and then Is_Entity_Name (N)
13557 and then (Is_Volatile_Full_Access (Entity (N))
13558 or else
13559 Is_Volatile_Full_Access (Etype (Entity (N)))));
13560 end Is_Atomic_Or_VFA_Object;
13561
13562 -------------------------
13563 -- Is_Attribute_Result --
13564 -------------------------
13565
13566 function Is_Attribute_Result (N : Node_Id) return Boolean is
13567 begin
13568 return Nkind (N) = N_Attribute_Reference
13569 and then Attribute_Name (N) = Name_Result;
13570 end Is_Attribute_Result;
13571
13572 -------------------------
13573 -- Is_Attribute_Update --
13574 -------------------------
13575
13576 function Is_Attribute_Update (N : Node_Id) return Boolean is
13577 begin
13578 return Nkind (N) = N_Attribute_Reference
13579 and then Attribute_Name (N) = Name_Update;
13580 end Is_Attribute_Update;
13581
13582 ------------------------------------
13583 -- Is_Body_Or_Package_Declaration --
13584 ------------------------------------
13585
13586 function Is_Body_Or_Package_Declaration (N : Node_Id) return Boolean is
13587 begin
13588 return Is_Body (N) or else Nkind (N) = N_Package_Declaration;
13589 end Is_Body_Or_Package_Declaration;
13590
13591 -----------------------
13592 -- Is_Bounded_String --
13593 -----------------------
13594
13595 function Is_Bounded_String (T : Entity_Id) return Boolean is
13596 Under : constant Entity_Id := Underlying_Type (Root_Type (T));
13597
13598 begin
13599 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
13600 -- Super_String, or one of the [Wide_]Wide_ versions. This will
13601 -- be True for all the Bounded_String types in instances of the
13602 -- Generic_Bounded_Length generics, and for types derived from those.
13603
13604 return Present (Under)
13605 and then (Is_RTE (Root_Type (Under), RO_SU_Super_String) or else
13606 Is_RTE (Root_Type (Under), RO_WI_Super_String) or else
13607 Is_RTE (Root_Type (Under), RO_WW_Super_String));
13608 end Is_Bounded_String;
13609
13610 ---------------------
13611 -- Is_CCT_Instance --
13612 ---------------------
13613
13614 function Is_CCT_Instance
13615 (Ref_Id : Entity_Id;
13616 Context_Id : Entity_Id) return Boolean
13617 is
13618 begin
13619 pragma Assert (Ekind_In (Ref_Id, E_Protected_Type, E_Task_Type));
13620
13621 if Is_Single_Task_Object (Context_Id) then
13622 return Scope_Within_Or_Same (Etype (Context_Id), Ref_Id);
13623
13624 else
13625 pragma Assert (Ekind_In (Context_Id, E_Entry,
13626 E_Entry_Family,
13627 E_Function,
13628 E_Package,
13629 E_Procedure,
13630 E_Protected_Type,
13631 E_Task_Type)
13632 or else
13633 Is_Record_Type (Context_Id));
13634 return Scope_Within_Or_Same (Context_Id, Ref_Id);
13635 end if;
13636 end Is_CCT_Instance;
13637
13638 -------------------------
13639 -- Is_Child_Or_Sibling --
13640 -------------------------
13641
13642 function Is_Child_Or_Sibling
13643 (Pack_1 : Entity_Id;
13644 Pack_2 : Entity_Id) return Boolean
13645 is
13646 function Distance_From_Standard (Pack : Entity_Id) return Nat;
13647 -- Given an arbitrary package, return the number of "climbs" necessary
13648 -- to reach scope Standard_Standard.
13649
13650 procedure Equalize_Depths
13651 (Pack : in out Entity_Id;
13652 Depth : in out Nat;
13653 Depth_To_Reach : Nat);
13654 -- Given an arbitrary package, its depth and a target depth to reach,
13655 -- climb the scope chain until the said depth is reached. The pointer
13656 -- to the package and its depth a modified during the climb.
13657
13658 ----------------------------
13659 -- Distance_From_Standard --
13660 ----------------------------
13661
13662 function Distance_From_Standard (Pack : Entity_Id) return Nat is
13663 Dist : Nat;
13664 Scop : Entity_Id;
13665
13666 begin
13667 Dist := 0;
13668 Scop := Pack;
13669 while Present (Scop) and then Scop /= Standard_Standard loop
13670 Dist := Dist + 1;
13671 Scop := Scope (Scop);
13672 end loop;
13673
13674 return Dist;
13675 end Distance_From_Standard;
13676
13677 ---------------------
13678 -- Equalize_Depths --
13679 ---------------------
13680
13681 procedure Equalize_Depths
13682 (Pack : in out Entity_Id;
13683 Depth : in out Nat;
13684 Depth_To_Reach : Nat)
13685 is
13686 begin
13687 -- The package must be at a greater or equal depth
13688
13689 if Depth < Depth_To_Reach then
13690 raise Program_Error;
13691 end if;
13692
13693 -- Climb the scope chain until the desired depth is reached
13694
13695 while Present (Pack) and then Depth /= Depth_To_Reach loop
13696 Pack := Scope (Pack);
13697 Depth := Depth - 1;
13698 end loop;
13699 end Equalize_Depths;
13700
13701 -- Local variables
13702
13703 P_1 : Entity_Id := Pack_1;
13704 P_1_Child : Boolean := False;
13705 P_1_Depth : Nat := Distance_From_Standard (P_1);
13706 P_2 : Entity_Id := Pack_2;
13707 P_2_Child : Boolean := False;
13708 P_2_Depth : Nat := Distance_From_Standard (P_2);
13709
13710 -- Start of processing for Is_Child_Or_Sibling
13711
13712 begin
13713 pragma Assert
13714 (Ekind (Pack_1) = E_Package and then Ekind (Pack_2) = E_Package);
13715
13716 -- Both packages denote the same entity, therefore they cannot be
13717 -- children or siblings.
13718
13719 if P_1 = P_2 then
13720 return False;
13721
13722 -- One of the packages is at a deeper level than the other. Note that
13723 -- both may still come from different hierarchies.
13724
13725 -- (root) P_2
13726 -- / \ :
13727 -- X P_2 or X
13728 -- : :
13729 -- P_1 P_1
13730
13731 elsif P_1_Depth > P_2_Depth then
13732 Equalize_Depths
13733 (Pack => P_1,
13734 Depth => P_1_Depth,
13735 Depth_To_Reach => P_2_Depth);
13736 P_1_Child := True;
13737
13738 -- (root) P_1
13739 -- / \ :
13740 -- P_1 X or X
13741 -- : :
13742 -- P_2 P_2
13743
13744 elsif P_2_Depth > P_1_Depth then
13745 Equalize_Depths
13746 (Pack => P_2,
13747 Depth => P_2_Depth,
13748 Depth_To_Reach => P_1_Depth);
13749 P_2_Child := True;
13750 end if;
13751
13752 -- At this stage the package pointers have been elevated to the same
13753 -- depth. If the related entities are the same, then one package is a
13754 -- potential child of the other:
13755
13756 -- P_1
13757 -- :
13758 -- X became P_1 P_2 or vice versa
13759 -- :
13760 -- P_2
13761
13762 if P_1 = P_2 then
13763 if P_1_Child then
13764 return Is_Child_Unit (Pack_1);
13765
13766 else pragma Assert (P_2_Child);
13767 return Is_Child_Unit (Pack_2);
13768 end if;
13769
13770 -- The packages may come from the same package chain or from entirely
13771 -- different hierarcies. To determine this, climb the scope stack until
13772 -- a common root is found.
13773
13774 -- (root) (root 1) (root 2)
13775 -- / \ | |
13776 -- P_1 P_2 P_1 P_2
13777
13778 else
13779 while Present (P_1) and then Present (P_2) loop
13780
13781 -- The two packages may be siblings
13782
13783 if P_1 = P_2 then
13784 return Is_Child_Unit (Pack_1) and then Is_Child_Unit (Pack_2);
13785 end if;
13786
13787 P_1 := Scope (P_1);
13788 P_2 := Scope (P_2);
13789 end loop;
13790 end if;
13791
13792 return False;
13793 end Is_Child_Or_Sibling;
13794
13795 -----------------------------
13796 -- Is_Concurrent_Interface --
13797 -----------------------------
13798
13799 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
13800 begin
13801 return Is_Interface (T)
13802 and then
13803 (Is_Protected_Interface (T)
13804 or else Is_Synchronized_Interface (T)
13805 or else Is_Task_Interface (T));
13806 end Is_Concurrent_Interface;
13807
13808 -----------------------
13809 -- Is_Constant_Bound --
13810 -----------------------
13811
13812 function Is_Constant_Bound (Exp : Node_Id) return Boolean is
13813 begin
13814 if Compile_Time_Known_Value (Exp) then
13815 return True;
13816
13817 elsif Is_Entity_Name (Exp) and then Present (Entity (Exp)) then
13818 return Is_Constant_Object (Entity (Exp))
13819 or else Ekind (Entity (Exp)) = E_Enumeration_Literal;
13820
13821 elsif Nkind (Exp) in N_Binary_Op then
13822 return Is_Constant_Bound (Left_Opnd (Exp))
13823 and then Is_Constant_Bound (Right_Opnd (Exp))
13824 and then Scope (Entity (Exp)) = Standard_Standard;
13825
13826 else
13827 return False;
13828 end if;
13829 end Is_Constant_Bound;
13830
13831 ---------------------------
13832 -- Is_Container_Element --
13833 ---------------------------
13834
13835 function Is_Container_Element (Exp : Node_Id) return Boolean is
13836 Loc : constant Source_Ptr := Sloc (Exp);
13837 Pref : constant Node_Id := Prefix (Exp);
13838
13839 Call : Node_Id;
13840 -- Call to an indexing aspect
13841
13842 Cont_Typ : Entity_Id;
13843 -- The type of the container being accessed
13844
13845 Elem_Typ : Entity_Id;
13846 -- Its element type
13847
13848 Indexing : Entity_Id;
13849 Is_Const : Boolean;
13850 -- Indicates that constant indexing is used, and the element is thus
13851 -- a constant.
13852
13853 Ref_Typ : Entity_Id;
13854 -- The reference type returned by the indexing operation
13855
13856 begin
13857 -- If C is a container, in a context that imposes the element type of
13858 -- that container, the indexing notation C (X) is rewritten as:
13859
13860 -- Indexing (C, X).Discr.all
13861
13862 -- where Indexing is one of the indexing aspects of the container.
13863 -- If the context does not require a reference, the construct can be
13864 -- rewritten as
13865
13866 -- Element (C, X)
13867
13868 -- First, verify that the construct has the proper form
13869
13870 if not Expander_Active then
13871 return False;
13872
13873 elsif Nkind (Pref) /= N_Selected_Component then
13874 return False;
13875
13876 elsif Nkind (Prefix (Pref)) /= N_Function_Call then
13877 return False;
13878
13879 else
13880 Call := Prefix (Pref);
13881 Ref_Typ := Etype (Call);
13882 end if;
13883
13884 if not Has_Implicit_Dereference (Ref_Typ)
13885 or else No (First (Parameter_Associations (Call)))
13886 or else not Is_Entity_Name (Name (Call))
13887 then
13888 return False;
13889 end if;
13890
13891 -- Retrieve type of container object, and its iterator aspects
13892
13893 Cont_Typ := Etype (First (Parameter_Associations (Call)));
13894 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Constant_Indexing);
13895 Is_Const := False;
13896
13897 if No (Indexing) then
13898
13899 -- Container should have at least one indexing operation
13900
13901 return False;
13902
13903 elsif Entity (Name (Call)) /= Entity (Indexing) then
13904
13905 -- This may be a variable indexing operation
13906
13907 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Variable_Indexing);
13908
13909 if No (Indexing)
13910 or else Entity (Name (Call)) /= Entity (Indexing)
13911 then
13912 return False;
13913 end if;
13914
13915 else
13916 Is_Const := True;
13917 end if;
13918
13919 Elem_Typ := Find_Value_Of_Aspect (Cont_Typ, Aspect_Iterator_Element);
13920
13921 if No (Elem_Typ) or else Entity (Elem_Typ) /= Etype (Exp) then
13922 return False;
13923 end if;
13924
13925 -- Check that the expression is not the target of an assignment, in
13926 -- which case the rewriting is not possible.
13927
13928 if not Is_Const then
13929 declare
13930 Par : Node_Id;
13931
13932 begin
13933 Par := Exp;
13934 while Present (Par)
13935 loop
13936 if Nkind (Parent (Par)) = N_Assignment_Statement
13937 and then Par = Name (Parent (Par))
13938 then
13939 return False;
13940
13941 -- A renaming produces a reference, and the transformation
13942 -- does not apply.
13943
13944 elsif Nkind (Parent (Par)) = N_Object_Renaming_Declaration then
13945 return False;
13946
13947 elsif Nkind_In
13948 (Nkind (Parent (Par)), N_Function_Call,
13949 N_Procedure_Call_Statement,
13950 N_Entry_Call_Statement)
13951 then
13952 -- Check that the element is not part of an actual for an
13953 -- in-out parameter.
13954
13955 declare
13956 F : Entity_Id;
13957 A : Node_Id;
13958
13959 begin
13960 F := First_Formal (Entity (Name (Parent (Par))));
13961 A := First (Parameter_Associations (Parent (Par)));
13962 while Present (F) loop
13963 if A = Par and then Ekind (F) /= E_In_Parameter then
13964 return False;
13965 end if;
13966
13967 Next_Formal (F);
13968 Next (A);
13969 end loop;
13970 end;
13971
13972 -- E_In_Parameter in a call: element is not modified.
13973
13974 exit;
13975 end if;
13976
13977 Par := Parent (Par);
13978 end loop;
13979 end;
13980 end if;
13981
13982 -- The expression has the proper form and the context requires the
13983 -- element type. Retrieve the Element function of the container and
13984 -- rewrite the construct as a call to it.
13985
13986 declare
13987 Op : Elmt_Id;
13988
13989 begin
13990 Op := First_Elmt (Primitive_Operations (Cont_Typ));
13991 while Present (Op) loop
13992 exit when Chars (Node (Op)) = Name_Element;
13993 Next_Elmt (Op);
13994 end loop;
13995
13996 if No (Op) then
13997 return False;
13998
13999 else
14000 Rewrite (Exp,
14001 Make_Function_Call (Loc,
14002 Name => New_Occurrence_Of (Node (Op), Loc),
14003 Parameter_Associations => Parameter_Associations (Call)));
14004 Analyze_And_Resolve (Exp, Entity (Elem_Typ));
14005 return True;
14006 end if;
14007 end;
14008 end Is_Container_Element;
14009
14010 ----------------------------
14011 -- Is_Contract_Annotation --
14012 ----------------------------
14013
14014 function Is_Contract_Annotation (Item : Node_Id) return Boolean is
14015 begin
14016 return Is_Package_Contract_Annotation (Item)
14017 or else
14018 Is_Subprogram_Contract_Annotation (Item);
14019 end Is_Contract_Annotation;
14020
14021 --------------------------------------
14022 -- Is_Controlling_Limited_Procedure --
14023 --------------------------------------
14024
14025 function Is_Controlling_Limited_Procedure
14026 (Proc_Nam : Entity_Id) return Boolean
14027 is
14028 Param : Node_Id;
14029 Param_Typ : Entity_Id := Empty;
14030
14031 begin
14032 if Ekind (Proc_Nam) = E_Procedure
14033 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
14034 then
14035 Param :=
14036 Parameter_Type
14037 (First (Parameter_Specifications (Parent (Proc_Nam))));
14038
14039 -- The formal may be an anonymous access type
14040
14041 if Nkind (Param) = N_Access_Definition then
14042 Param_Typ := Entity (Subtype_Mark (Param));
14043 else
14044 Param_Typ := Etype (Param);
14045 end if;
14046
14047 -- In the case where an Itype was created for a dispatchin call, the
14048 -- procedure call has been rewritten. The actual may be an access to
14049 -- interface type in which case it is the designated type that is the
14050 -- controlling type.
14051
14052 elsif Present (Associated_Node_For_Itype (Proc_Nam))
14053 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
14054 and then
14055 Present (Parameter_Associations
14056 (Associated_Node_For_Itype (Proc_Nam)))
14057 then
14058 Param_Typ :=
14059 Etype (First (Parameter_Associations
14060 (Associated_Node_For_Itype (Proc_Nam))));
14061
14062 if Ekind (Param_Typ) = E_Anonymous_Access_Type then
14063 Param_Typ := Directly_Designated_Type (Param_Typ);
14064 end if;
14065 end if;
14066
14067 if Present (Param_Typ) then
14068 return
14069 Is_Interface (Param_Typ)
14070 and then Is_Limited_Record (Param_Typ);
14071 end if;
14072
14073 return False;
14074 end Is_Controlling_Limited_Procedure;
14075
14076 -----------------------------
14077 -- Is_CPP_Constructor_Call --
14078 -----------------------------
14079
14080 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
14081 begin
14082 return Nkind (N) = N_Function_Call
14083 and then Is_CPP_Class (Etype (Etype (N)))
14084 and then Is_Constructor (Entity (Name (N)))
14085 and then Is_Imported (Entity (Name (N)));
14086 end Is_CPP_Constructor_Call;
14087
14088 -------------------------
14089 -- Is_Current_Instance --
14090 -------------------------
14091
14092 function Is_Current_Instance (N : Node_Id) return Boolean is
14093 Typ : constant Entity_Id := Entity (N);
14094 P : Node_Id;
14095
14096 begin
14097 -- Simplest case: entity is a concurrent type and we are currently
14098 -- inside the body. This will eventually be expanded into a call to
14099 -- Self (for tasks) or _object (for protected objects).
14100
14101 if Is_Concurrent_Type (Typ) and then In_Open_Scopes (Typ) then
14102 return True;
14103
14104 else
14105 -- Check whether the context is a (sub)type declaration for the
14106 -- type entity.
14107
14108 P := Parent (N);
14109 while Present (P) loop
14110 if Nkind_In (P, N_Full_Type_Declaration,
14111 N_Private_Type_Declaration,
14112 N_Subtype_Declaration)
14113 and then Comes_From_Source (P)
14114 and then Defining_Entity (P) = Typ
14115 then
14116 return True;
14117
14118 -- A subtype name may appear in an aspect specification for a
14119 -- Predicate_Failure aspect, for which we do not construct a
14120 -- wrapper procedure. The subtype will be replaced by the
14121 -- expression being tested when the corresponding predicate
14122 -- check is expanded.
14123
14124 elsif Nkind (P) = N_Aspect_Specification
14125 and then Nkind (Parent (P)) = N_Subtype_Declaration
14126 then
14127 return True;
14128
14129 elsif Nkind (P) = N_Pragma
14130 and then Get_Pragma_Id (P) = Pragma_Predicate_Failure
14131 then
14132 return True;
14133 end if;
14134
14135 P := Parent (P);
14136 end loop;
14137 end if;
14138
14139 -- In any other context this is not a current occurrence
14140
14141 return False;
14142 end Is_Current_Instance;
14143
14144 --------------------
14145 -- Is_Declaration --
14146 --------------------
14147
14148 function Is_Declaration
14149 (N : Node_Id;
14150 Body_OK : Boolean := True;
14151 Concurrent_OK : Boolean := True;
14152 Formal_OK : Boolean := True;
14153 Generic_OK : Boolean := True;
14154 Instantiation_OK : Boolean := True;
14155 Renaming_OK : Boolean := True;
14156 Stub_OK : Boolean := True;
14157 Subprogram_OK : Boolean := True;
14158 Type_OK : Boolean := True) return Boolean
14159 is
14160 begin
14161 case Nkind (N) is
14162
14163 -- Body declarations
14164
14165 when N_Proper_Body =>
14166 return Body_OK;
14167
14168 -- Concurrent type declarations
14169
14170 when N_Protected_Type_Declaration
14171 | N_Single_Protected_Declaration
14172 | N_Single_Task_Declaration
14173 | N_Task_Type_Declaration
14174 =>
14175 return Concurrent_OK or Type_OK;
14176
14177 -- Formal declarations
14178
14179 when N_Formal_Abstract_Subprogram_Declaration
14180 | N_Formal_Concrete_Subprogram_Declaration
14181 | N_Formal_Object_Declaration
14182 | N_Formal_Package_Declaration
14183 | N_Formal_Type_Declaration
14184 =>
14185 return Formal_OK;
14186
14187 -- Generic declarations
14188
14189 when N_Generic_Package_Declaration
14190 | N_Generic_Subprogram_Declaration
14191 =>
14192 return Generic_OK;
14193
14194 -- Generic instantiations
14195
14196 when N_Function_Instantiation
14197 | N_Package_Instantiation
14198 | N_Procedure_Instantiation
14199 =>
14200 return Instantiation_OK;
14201
14202 -- Generic renaming declarations
14203
14204 when N_Generic_Renaming_Declaration =>
14205 return Generic_OK or Renaming_OK;
14206
14207 -- Renaming declarations
14208
14209 when N_Exception_Renaming_Declaration
14210 | N_Object_Renaming_Declaration
14211 | N_Package_Renaming_Declaration
14212 | N_Subprogram_Renaming_Declaration
14213 =>
14214 return Renaming_OK;
14215
14216 -- Stub declarations
14217
14218 when N_Body_Stub =>
14219 return Stub_OK;
14220
14221 -- Subprogram declarations
14222
14223 when N_Abstract_Subprogram_Declaration
14224 | N_Entry_Declaration
14225 | N_Expression_Function
14226 | N_Subprogram_Declaration
14227 =>
14228 return Subprogram_OK;
14229
14230 -- Type declarations
14231
14232 when N_Full_Type_Declaration
14233 | N_Incomplete_Type_Declaration
14234 | N_Private_Extension_Declaration
14235 | N_Private_Type_Declaration
14236 | N_Subtype_Declaration
14237 =>
14238 return Type_OK;
14239
14240 -- Miscellaneous
14241
14242 when N_Component_Declaration
14243 | N_Exception_Declaration
14244 | N_Implicit_Label_Declaration
14245 | N_Number_Declaration
14246 | N_Object_Declaration
14247 | N_Package_Declaration
14248 =>
14249 return True;
14250
14251 when others =>
14252 return False;
14253 end case;
14254 end Is_Declaration;
14255
14256 --------------------------------
14257 -- Is_Declared_Within_Variant --
14258 --------------------------------
14259
14260 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
14261 Comp_Decl : constant Node_Id := Parent (Comp);
14262 Comp_List : constant Node_Id := Parent (Comp_Decl);
14263 begin
14264 return Nkind (Parent (Comp_List)) = N_Variant;
14265 end Is_Declared_Within_Variant;
14266
14267 ----------------------------------------------
14268 -- Is_Dependent_Component_Of_Mutable_Object --
14269 ----------------------------------------------
14270
14271 function Is_Dependent_Component_Of_Mutable_Object
14272 (Object : Node_Id) return Boolean
14273 is
14274 P : Node_Id;
14275 Prefix_Type : Entity_Id;
14276 P_Aliased : Boolean := False;
14277 Comp : Entity_Id;
14278
14279 Deref : Node_Id := Object;
14280 -- Dereference node, in something like X.all.Y(2)
14281
14282 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
14283
14284 begin
14285 -- Find the dereference node if any
14286
14287 while Nkind_In (Deref, N_Indexed_Component,
14288 N_Selected_Component,
14289 N_Slice)
14290 loop
14291 Deref := Prefix (Deref);
14292 end loop;
14293
14294 -- If the prefix is a qualified expression of a variable, then function
14295 -- Is_Variable will return False for that because a qualified expression
14296 -- denotes a constant view, so we need to get the name being qualified
14297 -- so we can test below whether that's a variable (or a dereference).
14298
14299 if Nkind (Deref) = N_Qualified_Expression then
14300 Deref := Expression (Deref);
14301 end if;
14302
14303 -- Ada 2005: If we have a component or slice of a dereference, something
14304 -- like X.all.Y (2) and the type of X is access-to-constant, Is_Variable
14305 -- will return False, because it is indeed a constant view. But it might
14306 -- be a view of a variable object, so we want the following condition to
14307 -- be True in that case.
14308
14309 if Is_Variable (Object)
14310 or else Is_Variable (Deref)
14311 or else (Ada_Version >= Ada_2005
14312 and then (Nkind (Deref) = N_Explicit_Dereference
14313 or else Is_Access_Type (Etype (Deref))))
14314 then
14315 if Nkind (Object) = N_Selected_Component then
14316
14317 -- If the selector is not a component, then we definitely return
14318 -- False (it could be a function selector in a prefix form call
14319 -- occurring in an iterator specification).
14320
14321 if not Ekind_In (Entity (Selector_Name (Object)), E_Component,
14322 E_Discriminant)
14323 then
14324 return False;
14325 end if;
14326
14327 -- Get the original node of the prefix in case it has been
14328 -- rewritten, which can occur, for example, in qualified
14329 -- expression cases. Also, a discriminant check on a selected
14330 -- component may be expanded into a dereference when removing
14331 -- side effects, and the subtype of the original node may be
14332 -- unconstrained.
14333
14334 P := Original_Node (Prefix (Object));
14335 Prefix_Type := Etype (P);
14336
14337 -- If the prefix is a qualified expression, we want to look at its
14338 -- operand.
14339
14340 if Nkind (P) = N_Qualified_Expression then
14341 P := Expression (P);
14342 Prefix_Type := Etype (P);
14343 end if;
14344
14345 if Is_Entity_Name (P) then
14346 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
14347 Prefix_Type := Base_Type (Prefix_Type);
14348 end if;
14349
14350 if Is_Aliased (Entity (P)) then
14351 P_Aliased := True;
14352 end if;
14353
14354 -- For explicit dereferences we get the access prefix so we can
14355 -- treat this similarly to implicit dereferences and examine the
14356 -- kind of the access type and its designated subtype further
14357 -- below.
14358
14359 elsif Nkind (P) = N_Explicit_Dereference then
14360 P := Prefix (P);
14361 Prefix_Type := Etype (P);
14362
14363 else
14364 -- Check for prefix being an aliased component???
14365
14366 null;
14367 end if;
14368
14369 -- A heap object is constrained by its initial value
14370
14371 -- Ada 2005 (AI-363): Always assume the object could be mutable in
14372 -- the dereferenced case, since the access value might denote an
14373 -- unconstrained aliased object, whereas in Ada 95 the designated
14374 -- object is guaranteed to be constrained. A worst-case assumption
14375 -- has to apply in Ada 2005 because we can't tell at compile
14376 -- time whether the object is "constrained by its initial value",
14377 -- despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are semantic
14378 -- rules (these rules are acknowledged to need fixing). We don't
14379 -- impose this more stringent checking for earlier Ada versions or
14380 -- when Relaxed_RM_Semantics applies (the latter for CodePeer's
14381 -- benefit, though it's unclear on why using -gnat95 would not be
14382 -- sufficient???).
14383
14384 if Ada_Version < Ada_2005 or else Relaxed_RM_Semantics then
14385 if Is_Access_Type (Prefix_Type)
14386 or else Nkind (P) = N_Explicit_Dereference
14387 then
14388 return False;
14389 end if;
14390
14391 else pragma Assert (Ada_Version >= Ada_2005);
14392 if Is_Access_Type (Prefix_Type) then
14393 -- We need to make sure we have the base subtype, in case
14394 -- this is actually an access subtype (whose Ekind will be
14395 -- E_Access_Subtype).
14396
14397 Prefix_Type := Etype (Prefix_Type);
14398
14399 -- If the access type is pool-specific, and there is no
14400 -- constrained partial view of the designated type, then the
14401 -- designated object is known to be constrained. If it's a
14402 -- formal access type and the renaming is in the generic
14403 -- spec, we also treat it as pool-specific (known to be
14404 -- constrained), but assume the worst if in the generic body
14405 -- (see RM 3.3(23.3/3)).
14406
14407 if Ekind (Prefix_Type) = E_Access_Type
14408 and then (not Is_Generic_Type (Prefix_Type)
14409 or else not In_Generic_Body (Current_Scope))
14410 and then not Object_Type_Has_Constrained_Partial_View
14411 (Typ => Designated_Type (Prefix_Type),
14412 Scop => Current_Scope)
14413 then
14414 return False;
14415
14416 -- Otherwise (general access type, or there is a constrained
14417 -- partial view of the designated type), we need to check
14418 -- based on the designated type.
14419
14420 else
14421 Prefix_Type := Designated_Type (Prefix_Type);
14422 end if;
14423 end if;
14424 end if;
14425
14426 Comp :=
14427 Original_Record_Component (Entity (Selector_Name (Object)));
14428
14429 -- As per AI-0017, the renaming is illegal in a generic body, even
14430 -- if the subtype is indefinite (only applies to prefixes of an
14431 -- untagged formal type, see RM 3.3 (23.11/3)).
14432
14433 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
14434
14435 if not Is_Constrained (Prefix_Type)
14436 and then (Is_Definite_Subtype (Prefix_Type)
14437 or else
14438 (not Is_Tagged_Type (Prefix_Type)
14439 and then Is_Generic_Type (Prefix_Type)
14440 and then In_Generic_Body (Current_Scope)))
14441
14442 and then (Is_Declared_Within_Variant (Comp)
14443 or else Has_Discriminant_Dependent_Constraint (Comp))
14444 and then (not P_Aliased or else Ada_Version >= Ada_2005)
14445 then
14446 return True;
14447
14448 -- If the prefix is of an access type at this point, then we want
14449 -- to return False, rather than calling this function recursively
14450 -- on the access object (which itself might be a discriminant-
14451 -- dependent component of some other object, but that isn't
14452 -- relevant to checking the object passed to us). This avoids
14453 -- issuing wrong errors when compiling with -gnatc, where there
14454 -- can be implicit dereferences that have not been expanded.
14455
14456 elsif Is_Access_Type (Etype (Prefix (Object))) then
14457 return False;
14458
14459 else
14460 return
14461 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
14462 end if;
14463
14464 elsif Nkind (Object) = N_Indexed_Component
14465 or else Nkind (Object) = N_Slice
14466 then
14467 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
14468
14469 -- A type conversion that Is_Variable is a view conversion:
14470 -- go back to the denoted object.
14471
14472 elsif Nkind (Object) = N_Type_Conversion then
14473 return
14474 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
14475 end if;
14476 end if;
14477
14478 return False;
14479 end Is_Dependent_Component_Of_Mutable_Object;
14480
14481 ---------------------
14482 -- Is_Dereferenced --
14483 ---------------------
14484
14485 function Is_Dereferenced (N : Node_Id) return Boolean is
14486 P : constant Node_Id := Parent (N);
14487 begin
14488 return Nkind_In (P, N_Selected_Component,
14489 N_Explicit_Dereference,
14490 N_Indexed_Component,
14491 N_Slice)
14492 and then Prefix (P) = N;
14493 end Is_Dereferenced;
14494
14495 ----------------------
14496 -- Is_Descendant_Of --
14497 ----------------------
14498
14499 function Is_Descendant_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
14500 T : Entity_Id;
14501 Etyp : Entity_Id;
14502
14503 begin
14504 pragma Assert (Nkind (T1) in N_Entity);
14505 pragma Assert (Nkind (T2) in N_Entity);
14506
14507 T := Base_Type (T1);
14508
14509 -- Immediate return if the types match
14510
14511 if T = T2 then
14512 return True;
14513
14514 -- Comment needed here ???
14515
14516 elsif Ekind (T) = E_Class_Wide_Type then
14517 return Etype (T) = T2;
14518
14519 -- All other cases
14520
14521 else
14522 loop
14523 Etyp := Etype (T);
14524
14525 -- Done if we found the type we are looking for
14526
14527 if Etyp = T2 then
14528 return True;
14529
14530 -- Done if no more derivations to check
14531
14532 elsif T = T1
14533 or else T = Etyp
14534 then
14535 return False;
14536
14537 -- Following test catches error cases resulting from prev errors
14538
14539 elsif No (Etyp) then
14540 return False;
14541
14542 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
14543 return False;
14544
14545 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
14546 return False;
14547 end if;
14548
14549 T := Base_Type (Etyp);
14550 end loop;
14551 end if;
14552 end Is_Descendant_Of;
14553
14554 ----------------------------------------
14555 -- Is_Descendant_Of_Suspension_Object --
14556 ----------------------------------------
14557
14558 function Is_Descendant_Of_Suspension_Object
14559 (Typ : Entity_Id) return Boolean
14560 is
14561 Cur_Typ : Entity_Id;
14562 Par_Typ : Entity_Id;
14563
14564 begin
14565 -- Climb the type derivation chain checking each parent type against
14566 -- Suspension_Object.
14567
14568 Cur_Typ := Base_Type (Typ);
14569 while Present (Cur_Typ) loop
14570 Par_Typ := Etype (Cur_Typ);
14571
14572 -- The current type is a match
14573
14574 if Is_Suspension_Object (Cur_Typ) then
14575 return True;
14576
14577 -- Stop the traversal once the root of the derivation chain has been
14578 -- reached. In that case the current type is its own base type.
14579
14580 elsif Cur_Typ = Par_Typ then
14581 exit;
14582 end if;
14583
14584 Cur_Typ := Base_Type (Par_Typ);
14585 end loop;
14586
14587 return False;
14588 end Is_Descendant_Of_Suspension_Object;
14589
14590 ---------------------------------------------
14591 -- Is_Double_Precision_Floating_Point_Type --
14592 ---------------------------------------------
14593
14594 function Is_Double_Precision_Floating_Point_Type
14595 (E : Entity_Id) return Boolean is
14596 begin
14597 return Is_Floating_Point_Type (E)
14598 and then Machine_Radix_Value (E) = Uint_2
14599 and then Machine_Mantissa_Value (E) = UI_From_Int (53)
14600 and then Machine_Emax_Value (E) = Uint_2 ** Uint_10
14601 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_10);
14602 end Is_Double_Precision_Floating_Point_Type;
14603
14604 -----------------------------
14605 -- Is_Effectively_Volatile --
14606 -----------------------------
14607
14608 function Is_Effectively_Volatile (Id : Entity_Id) return Boolean is
14609 begin
14610 if Is_Type (Id) then
14611
14612 -- An arbitrary type is effectively volatile when it is subject to
14613 -- pragma Atomic or Volatile.
14614
14615 if Is_Volatile (Id) then
14616 return True;
14617
14618 -- An array type is effectively volatile when it is subject to pragma
14619 -- Atomic_Components or Volatile_Components or its component type is
14620 -- effectively volatile.
14621
14622 elsif Is_Array_Type (Id) then
14623 declare
14624 Anc : Entity_Id := Base_Type (Id);
14625 begin
14626 if Is_Private_Type (Anc) then
14627 Anc := Full_View (Anc);
14628 end if;
14629
14630 -- Test for presence of ancestor, as the full view of a private
14631 -- type may be missing in case of error.
14632
14633 return
14634 Has_Volatile_Components (Id)
14635 or else
14636 (Present (Anc)
14637 and then Is_Effectively_Volatile (Component_Type (Anc)));
14638 end;
14639
14640 -- A protected type is always volatile
14641
14642 elsif Is_Protected_Type (Id) then
14643 return True;
14644
14645 -- A descendant of Ada.Synchronous_Task_Control.Suspension_Object is
14646 -- automatically volatile.
14647
14648 elsif Is_Descendant_Of_Suspension_Object (Id) then
14649 return True;
14650
14651 -- Otherwise the type is not effectively volatile
14652
14653 else
14654 return False;
14655 end if;
14656
14657 -- Otherwise Id denotes an object
14658
14659 else
14660 -- A volatile object for which No_Caching is enabled is not
14661 -- effectively volatile.
14662
14663 return
14664 (Is_Volatile (Id) and then not No_Caching_Enabled (Id))
14665 or else Has_Volatile_Components (Id)
14666 or else Is_Effectively_Volatile (Etype (Id));
14667 end if;
14668 end Is_Effectively_Volatile;
14669
14670 ------------------------------------
14671 -- Is_Effectively_Volatile_Object --
14672 ------------------------------------
14673
14674 function Is_Effectively_Volatile_Object (N : Node_Id) return Boolean is
14675 begin
14676 if Is_Entity_Name (N) then
14677 return Is_Effectively_Volatile (Entity (N));
14678
14679 elsif Nkind (N) = N_Indexed_Component then
14680 return Is_Effectively_Volatile_Object (Prefix (N));
14681
14682 elsif Nkind (N) = N_Selected_Component then
14683 return
14684 Is_Effectively_Volatile_Object (Prefix (N))
14685 or else
14686 Is_Effectively_Volatile_Object (Selector_Name (N));
14687
14688 else
14689 return False;
14690 end if;
14691 end Is_Effectively_Volatile_Object;
14692
14693 -------------------
14694 -- Is_Entry_Body --
14695 -------------------
14696
14697 function Is_Entry_Body (Id : Entity_Id) return Boolean is
14698 begin
14699 return
14700 Ekind_In (Id, E_Entry, E_Entry_Family)
14701 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Body;
14702 end Is_Entry_Body;
14703
14704 --------------------------
14705 -- Is_Entry_Declaration --
14706 --------------------------
14707
14708 function Is_Entry_Declaration (Id : Entity_Id) return Boolean is
14709 begin
14710 return
14711 Ekind_In (Id, E_Entry, E_Entry_Family)
14712 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Declaration;
14713 end Is_Entry_Declaration;
14714
14715 ------------------------------------
14716 -- Is_Expanded_Priority_Attribute --
14717 ------------------------------------
14718
14719 function Is_Expanded_Priority_Attribute (E : Entity_Id) return Boolean is
14720 begin
14721 return
14722 Nkind (E) = N_Function_Call
14723 and then not Configurable_Run_Time_Mode
14724 and then Nkind (Original_Node (E)) = N_Attribute_Reference
14725 and then (Entity (Name (E)) = RTE (RE_Get_Ceiling)
14726 or else Entity (Name (E)) = RTE (RO_PE_Get_Ceiling));
14727 end Is_Expanded_Priority_Attribute;
14728
14729 ----------------------------
14730 -- Is_Expression_Function --
14731 ----------------------------
14732
14733 function Is_Expression_Function (Subp : Entity_Id) return Boolean is
14734 begin
14735 if Ekind_In (Subp, E_Function, E_Subprogram_Body) then
14736 return
14737 Nkind (Original_Node (Unit_Declaration_Node (Subp))) =
14738 N_Expression_Function;
14739 else
14740 return False;
14741 end if;
14742 end Is_Expression_Function;
14743
14744 ------------------------------------------
14745 -- Is_Expression_Function_Or_Completion --
14746 ------------------------------------------
14747
14748 function Is_Expression_Function_Or_Completion
14749 (Subp : Entity_Id) return Boolean
14750 is
14751 Subp_Decl : Node_Id;
14752
14753 begin
14754 if Ekind (Subp) = E_Function then
14755 Subp_Decl := Unit_Declaration_Node (Subp);
14756
14757 -- The function declaration is either an expression function or is
14758 -- completed by an expression function body.
14759
14760 return
14761 Is_Expression_Function (Subp)
14762 or else (Nkind (Subp_Decl) = N_Subprogram_Declaration
14763 and then Present (Corresponding_Body (Subp_Decl))
14764 and then Is_Expression_Function
14765 (Corresponding_Body (Subp_Decl)));
14766
14767 elsif Ekind (Subp) = E_Subprogram_Body then
14768 return Is_Expression_Function (Subp);
14769
14770 else
14771 return False;
14772 end if;
14773 end Is_Expression_Function_Or_Completion;
14774
14775 -----------------------
14776 -- Is_EVF_Expression --
14777 -----------------------
14778
14779 function Is_EVF_Expression (N : Node_Id) return Boolean is
14780 Orig_N : constant Node_Id := Original_Node (N);
14781 Alt : Node_Id;
14782 Expr : Node_Id;
14783 Id : Entity_Id;
14784
14785 begin
14786 -- Detect a reference to a formal parameter of a specific tagged type
14787 -- whose related subprogram is subject to pragma Expresions_Visible with
14788 -- value "False".
14789
14790 if Is_Entity_Name (N) and then Present (Entity (N)) then
14791 Id := Entity (N);
14792
14793 return
14794 Is_Formal (Id)
14795 and then Is_Specific_Tagged_Type (Etype (Id))
14796 and then Extensions_Visible_Status (Id) =
14797 Extensions_Visible_False;
14798
14799 -- A case expression is an EVF expression when it contains at least one
14800 -- EVF dependent_expression. Note that a case expression may have been
14801 -- expanded, hence the use of Original_Node.
14802
14803 elsif Nkind (Orig_N) = N_Case_Expression then
14804 Alt := First (Alternatives (Orig_N));
14805 while Present (Alt) loop
14806 if Is_EVF_Expression (Expression (Alt)) then
14807 return True;
14808 end if;
14809
14810 Next (Alt);
14811 end loop;
14812
14813 -- An if expression is an EVF expression when it contains at least one
14814 -- EVF dependent_expression. Note that an if expression may have been
14815 -- expanded, hence the use of Original_Node.
14816
14817 elsif Nkind (Orig_N) = N_If_Expression then
14818 Expr := Next (First (Expressions (Orig_N)));
14819 while Present (Expr) loop
14820 if Is_EVF_Expression (Expr) then
14821 return True;
14822 end if;
14823
14824 Next (Expr);
14825 end loop;
14826
14827 -- A qualified expression or a type conversion is an EVF expression when
14828 -- its operand is an EVF expression.
14829
14830 elsif Nkind_In (N, N_Qualified_Expression,
14831 N_Unchecked_Type_Conversion,
14832 N_Type_Conversion)
14833 then
14834 return Is_EVF_Expression (Expression (N));
14835
14836 -- Attributes 'Loop_Entry, 'Old, and 'Update are EVF expressions when
14837 -- their prefix denotes an EVF expression.
14838
14839 elsif Nkind (N) = N_Attribute_Reference
14840 and then Nam_In (Attribute_Name (N), Name_Loop_Entry,
14841 Name_Old,
14842 Name_Update)
14843 then
14844 return Is_EVF_Expression (Prefix (N));
14845 end if;
14846
14847 return False;
14848 end Is_EVF_Expression;
14849
14850 --------------
14851 -- Is_False --
14852 --------------
14853
14854 function Is_False (U : Uint) return Boolean is
14855 begin
14856 return (U = 0);
14857 end Is_False;
14858
14859 ---------------------------
14860 -- Is_Fixed_Model_Number --
14861 ---------------------------
14862
14863 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
14864 S : constant Ureal := Small_Value (T);
14865 M : Urealp.Save_Mark;
14866 R : Boolean;
14867
14868 begin
14869 M := Urealp.Mark;
14870 R := (U = UR_Trunc (U / S) * S);
14871 Urealp.Release (M);
14872 return R;
14873 end Is_Fixed_Model_Number;
14874
14875 -------------------------------
14876 -- Is_Fully_Initialized_Type --
14877 -------------------------------
14878
14879 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
14880 begin
14881 -- Scalar types
14882
14883 if Is_Scalar_Type (Typ) then
14884
14885 -- A scalar type with an aspect Default_Value is fully initialized
14886
14887 -- Note: Iniitalize/Normalize_Scalars also ensure full initialization
14888 -- of a scalar type, but we don't take that into account here, since
14889 -- we don't want these to affect warnings.
14890
14891 return Has_Default_Aspect (Typ);
14892
14893 elsif Is_Access_Type (Typ) then
14894 return True;
14895
14896 elsif Is_Array_Type (Typ) then
14897 if Is_Fully_Initialized_Type (Component_Type (Typ))
14898 or else (Ada_Version >= Ada_2012 and then Has_Default_Aspect (Typ))
14899 then
14900 return True;
14901 end if;
14902
14903 -- An interesting case, if we have a constrained type one of whose
14904 -- bounds is known to be null, then there are no elements to be
14905 -- initialized, so all the elements are initialized.
14906
14907 if Is_Constrained (Typ) then
14908 declare
14909 Indx : Node_Id;
14910 Indx_Typ : Entity_Id;
14911 Lbd, Hbd : Node_Id;
14912
14913 begin
14914 Indx := First_Index (Typ);
14915 while Present (Indx) loop
14916 if Etype (Indx) = Any_Type then
14917 return False;
14918
14919 -- If index is a range, use directly
14920
14921 elsif Nkind (Indx) = N_Range then
14922 Lbd := Low_Bound (Indx);
14923 Hbd := High_Bound (Indx);
14924
14925 else
14926 Indx_Typ := Etype (Indx);
14927
14928 if Is_Private_Type (Indx_Typ) then
14929 Indx_Typ := Full_View (Indx_Typ);
14930 end if;
14931
14932 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
14933 return False;
14934 else
14935 Lbd := Type_Low_Bound (Indx_Typ);
14936 Hbd := Type_High_Bound (Indx_Typ);
14937 end if;
14938 end if;
14939
14940 if Compile_Time_Known_Value (Lbd)
14941 and then
14942 Compile_Time_Known_Value (Hbd)
14943 then
14944 if Expr_Value (Hbd) < Expr_Value (Lbd) then
14945 return True;
14946 end if;
14947 end if;
14948
14949 Next_Index (Indx);
14950 end loop;
14951 end;
14952 end if;
14953
14954 -- If no null indexes, then type is not fully initialized
14955
14956 return False;
14957
14958 -- Record types
14959
14960 elsif Is_Record_Type (Typ) then
14961 if Has_Discriminants (Typ)
14962 and then
14963 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
14964 and then Is_Fully_Initialized_Variant (Typ)
14965 then
14966 return True;
14967 end if;
14968
14969 -- We consider bounded string types to be fully initialized, because
14970 -- otherwise we get false alarms when the Data component is not
14971 -- default-initialized.
14972
14973 if Is_Bounded_String (Typ) then
14974 return True;
14975 end if;
14976
14977 -- Controlled records are considered to be fully initialized if
14978 -- there is a user defined Initialize routine. This may not be
14979 -- entirely correct, but as the spec notes, we are guessing here
14980 -- what is best from the point of view of issuing warnings.
14981
14982 if Is_Controlled (Typ) then
14983 declare
14984 Utyp : constant Entity_Id := Underlying_Type (Typ);
14985
14986 begin
14987 if Present (Utyp) then
14988 declare
14989 Init : constant Entity_Id :=
14990 (Find_Optional_Prim_Op
14991 (Underlying_Type (Typ), Name_Initialize));
14992
14993 begin
14994 if Present (Init)
14995 and then Comes_From_Source (Init)
14996 and then not In_Predefined_Unit (Init)
14997 then
14998 return True;
14999
15000 elsif Has_Null_Extension (Typ)
15001 and then
15002 Is_Fully_Initialized_Type
15003 (Etype (Base_Type (Typ)))
15004 then
15005 return True;
15006 end if;
15007 end;
15008 end if;
15009 end;
15010 end if;
15011
15012 -- Otherwise see if all record components are initialized
15013
15014 declare
15015 Ent : Entity_Id;
15016
15017 begin
15018 Ent := First_Entity (Typ);
15019 while Present (Ent) loop
15020 if Ekind (Ent) = E_Component
15021 and then (No (Parent (Ent))
15022 or else No (Expression (Parent (Ent))))
15023 and then not Is_Fully_Initialized_Type (Etype (Ent))
15024
15025 -- Special VM case for tag components, which need to be
15026 -- defined in this case, but are never initialized as VMs
15027 -- are using other dispatching mechanisms. Ignore this
15028 -- uninitialized case. Note that this applies both to the
15029 -- uTag entry and the main vtable pointer (CPP_Class case).
15030
15031 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
15032 then
15033 return False;
15034 end if;
15035
15036 Next_Entity (Ent);
15037 end loop;
15038 end;
15039
15040 -- No uninitialized components, so type is fully initialized.
15041 -- Note that this catches the case of no components as well.
15042
15043 return True;
15044
15045 elsif Is_Concurrent_Type (Typ) then
15046 return True;
15047
15048 elsif Is_Private_Type (Typ) then
15049 declare
15050 U : constant Entity_Id := Underlying_Type (Typ);
15051
15052 begin
15053 if No (U) then
15054 return False;
15055 else
15056 return Is_Fully_Initialized_Type (U);
15057 end if;
15058 end;
15059
15060 else
15061 return False;
15062 end if;
15063 end Is_Fully_Initialized_Type;
15064
15065 ----------------------------------
15066 -- Is_Fully_Initialized_Variant --
15067 ----------------------------------
15068
15069 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
15070 Loc : constant Source_Ptr := Sloc (Typ);
15071 Constraints : constant List_Id := New_List;
15072 Components : constant Elist_Id := New_Elmt_List;
15073 Comp_Elmt : Elmt_Id;
15074 Comp_Id : Node_Id;
15075 Comp_List : Node_Id;
15076 Discr : Entity_Id;
15077 Discr_Val : Node_Id;
15078
15079 Report_Errors : Boolean;
15080 pragma Warnings (Off, Report_Errors);
15081
15082 begin
15083 if Serious_Errors_Detected > 0 then
15084 return False;
15085 end if;
15086
15087 if Is_Record_Type (Typ)
15088 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
15089 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
15090 then
15091 Comp_List := Component_List (Type_Definition (Parent (Typ)));
15092
15093 Discr := First_Discriminant (Typ);
15094 while Present (Discr) loop
15095 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
15096 Discr_Val := Expression (Parent (Discr));
15097
15098 if Present (Discr_Val)
15099 and then Is_OK_Static_Expression (Discr_Val)
15100 then
15101 Append_To (Constraints,
15102 Make_Component_Association (Loc,
15103 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
15104 Expression => New_Copy (Discr_Val)));
15105 else
15106 return False;
15107 end if;
15108 else
15109 return False;
15110 end if;
15111
15112 Next_Discriminant (Discr);
15113 end loop;
15114
15115 Gather_Components
15116 (Typ => Typ,
15117 Comp_List => Comp_List,
15118 Governed_By => Constraints,
15119 Into => Components,
15120 Report_Errors => Report_Errors);
15121
15122 -- Check that each component present is fully initialized
15123
15124 Comp_Elmt := First_Elmt (Components);
15125 while Present (Comp_Elmt) loop
15126 Comp_Id := Node (Comp_Elmt);
15127
15128 if Ekind (Comp_Id) = E_Component
15129 and then (No (Parent (Comp_Id))
15130 or else No (Expression (Parent (Comp_Id))))
15131 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
15132 then
15133 return False;
15134 end if;
15135
15136 Next_Elmt (Comp_Elmt);
15137 end loop;
15138
15139 return True;
15140
15141 elsif Is_Private_Type (Typ) then
15142 declare
15143 U : constant Entity_Id := Underlying_Type (Typ);
15144
15145 begin
15146 if No (U) then
15147 return False;
15148 else
15149 return Is_Fully_Initialized_Variant (U);
15150 end if;
15151 end;
15152
15153 else
15154 return False;
15155 end if;
15156 end Is_Fully_Initialized_Variant;
15157
15158 ------------------------------------
15159 -- Is_Generic_Declaration_Or_Body --
15160 ------------------------------------
15161
15162 function Is_Generic_Declaration_Or_Body (Decl : Node_Id) return Boolean is
15163 Spec_Decl : Node_Id;
15164
15165 begin
15166 -- Package/subprogram body
15167
15168 if Nkind_In (Decl, N_Package_Body, N_Subprogram_Body)
15169 and then Present (Corresponding_Spec (Decl))
15170 then
15171 Spec_Decl := Unit_Declaration_Node (Corresponding_Spec (Decl));
15172
15173 -- Package/subprogram body stub
15174
15175 elsif Nkind_In (Decl, N_Package_Body_Stub, N_Subprogram_Body_Stub)
15176 and then Present (Corresponding_Spec_Of_Stub (Decl))
15177 then
15178 Spec_Decl :=
15179 Unit_Declaration_Node (Corresponding_Spec_Of_Stub (Decl));
15180
15181 -- All other cases
15182
15183 else
15184 Spec_Decl := Decl;
15185 end if;
15186
15187 -- Rather than inspecting the defining entity of the spec declaration,
15188 -- look at its Nkind. This takes care of the case where the analysis of
15189 -- a generic body modifies the Ekind of its spec to allow for recursive
15190 -- calls.
15191
15192 return
15193 Nkind_In (Spec_Decl, N_Generic_Package_Declaration,
15194 N_Generic_Subprogram_Declaration);
15195 end Is_Generic_Declaration_Or_Body;
15196
15197 ----------------------------
15198 -- Is_Inherited_Operation --
15199 ----------------------------
15200
15201 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
15202 pragma Assert (Is_Overloadable (E));
15203 Kind : constant Node_Kind := Nkind (Parent (E));
15204 begin
15205 return Kind = N_Full_Type_Declaration
15206 or else Kind = N_Private_Extension_Declaration
15207 or else Kind = N_Subtype_Declaration
15208 or else (Ekind (E) = E_Enumeration_Literal
15209 and then Is_Derived_Type (Etype (E)));
15210 end Is_Inherited_Operation;
15211
15212 -------------------------------------
15213 -- Is_Inherited_Operation_For_Type --
15214 -------------------------------------
15215
15216 function Is_Inherited_Operation_For_Type
15217 (E : Entity_Id;
15218 Typ : Entity_Id) return Boolean
15219 is
15220 begin
15221 -- Check that the operation has been created by the type declaration
15222
15223 return Is_Inherited_Operation (E)
15224 and then Defining_Identifier (Parent (E)) = Typ;
15225 end Is_Inherited_Operation_For_Type;
15226
15227 --------------------------------------
15228 -- Is_Inlinable_Expression_Function --
15229 --------------------------------------
15230
15231 function Is_Inlinable_Expression_Function
15232 (Subp : Entity_Id) return Boolean
15233 is
15234 Return_Expr : Node_Id;
15235
15236 begin
15237 if Is_Expression_Function_Or_Completion (Subp)
15238 and then Has_Pragma_Inline_Always (Subp)
15239 and then Needs_No_Actuals (Subp)
15240 and then No (Contract (Subp))
15241 and then not Is_Dispatching_Operation (Subp)
15242 and then Needs_Finalization (Etype (Subp))
15243 and then not Is_Class_Wide_Type (Etype (Subp))
15244 and then not (Has_Invariants (Etype (Subp)))
15245 and then Present (Subprogram_Body (Subp))
15246 and then Was_Expression_Function (Subprogram_Body (Subp))
15247 then
15248 Return_Expr := Expression_Of_Expression_Function (Subp);
15249
15250 -- The returned object must not have a qualified expression and its
15251 -- nominal subtype must be statically compatible with the result
15252 -- subtype of the expression function.
15253
15254 return
15255 Nkind (Return_Expr) = N_Identifier
15256 and then Etype (Return_Expr) = Etype (Subp);
15257 end if;
15258
15259 return False;
15260 end Is_Inlinable_Expression_Function;
15261
15262 -----------------
15263 -- Is_Iterator --
15264 -----------------
15265
15266 function Is_Iterator (Typ : Entity_Id) return Boolean is
15267 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean;
15268 -- Determine whether type Iter_Typ is a predefined forward or reversible
15269 -- iterator.
15270
15271 ----------------------
15272 -- Denotes_Iterator --
15273 ----------------------
15274
15275 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean is
15276 begin
15277 -- Check that the name matches, and that the ultimate ancestor is in
15278 -- a predefined unit, i.e the one that declares iterator interfaces.
15279
15280 return
15281 Nam_In (Chars (Iter_Typ), Name_Forward_Iterator,
15282 Name_Reversible_Iterator)
15283 and then In_Predefined_Unit (Root_Type (Iter_Typ));
15284 end Denotes_Iterator;
15285
15286 -- Local variables
15287
15288 Iface_Elmt : Elmt_Id;
15289 Ifaces : Elist_Id;
15290
15291 -- Start of processing for Is_Iterator
15292
15293 begin
15294 -- The type may be a subtype of a descendant of the proper instance of
15295 -- the predefined interface type, so we must use the root type of the
15296 -- given type. The same is done for Is_Reversible_Iterator.
15297
15298 if Is_Class_Wide_Type (Typ)
15299 and then Denotes_Iterator (Root_Type (Typ))
15300 then
15301 return True;
15302
15303 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
15304 return False;
15305
15306 elsif Present (Find_Value_Of_Aspect (Typ, Aspect_Iterable)) then
15307 return True;
15308
15309 else
15310 Collect_Interfaces (Typ, Ifaces);
15311
15312 Iface_Elmt := First_Elmt (Ifaces);
15313 while Present (Iface_Elmt) loop
15314 if Denotes_Iterator (Node (Iface_Elmt)) then
15315 return True;
15316 end if;
15317
15318 Next_Elmt (Iface_Elmt);
15319 end loop;
15320
15321 return False;
15322 end if;
15323 end Is_Iterator;
15324
15325 ----------------------------
15326 -- Is_Iterator_Over_Array --
15327 ----------------------------
15328
15329 function Is_Iterator_Over_Array (N : Node_Id) return Boolean is
15330 Container : constant Node_Id := Name (N);
15331 Container_Typ : constant Entity_Id := Base_Type (Etype (Container));
15332 begin
15333 return Is_Array_Type (Container_Typ);
15334 end Is_Iterator_Over_Array;
15335
15336 ------------
15337 -- Is_LHS --
15338 ------------
15339
15340 -- We seem to have a lot of overlapping functions that do similar things
15341 -- (testing for left hand sides or lvalues???).
15342
15343 function Is_LHS (N : Node_Id) return Is_LHS_Result is
15344 P : constant Node_Id := Parent (N);
15345
15346 begin
15347 -- Return True if we are the left hand side of an assignment statement
15348
15349 if Nkind (P) = N_Assignment_Statement then
15350 if Name (P) = N then
15351 return Yes;
15352 else
15353 return No;
15354 end if;
15355
15356 -- Case of prefix of indexed or selected component or slice
15357
15358 elsif Nkind_In (P, N_Indexed_Component, N_Selected_Component, N_Slice)
15359 and then N = Prefix (P)
15360 then
15361 -- Here we have the case where the parent P is N.Q or N(Q .. R).
15362 -- If P is an LHS, then N is also effectively an LHS, but there
15363 -- is an important exception. If N is of an access type, then
15364 -- what we really have is N.all.Q (or N.all(Q .. R)). In either
15365 -- case this makes N.all a left hand side but not N itself.
15366
15367 -- If we don't know the type yet, this is the case where we return
15368 -- Unknown, since the answer depends on the type which is unknown.
15369
15370 if No (Etype (N)) then
15371 return Unknown;
15372
15373 -- We have an Etype set, so we can check it
15374
15375 elsif Is_Access_Type (Etype (N)) then
15376 return No;
15377
15378 -- OK, not access type case, so just test whole expression
15379
15380 else
15381 return Is_LHS (P);
15382 end if;
15383
15384 -- All other cases are not left hand sides
15385
15386 else
15387 return No;
15388 end if;
15389 end Is_LHS;
15390
15391 -----------------------------
15392 -- Is_Library_Level_Entity --
15393 -----------------------------
15394
15395 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
15396 begin
15397 -- The following is a small optimization, and it also properly handles
15398 -- discriminals, which in task bodies might appear in expressions before
15399 -- the corresponding procedure has been created, and which therefore do
15400 -- not have an assigned scope.
15401
15402 if Is_Formal (E) then
15403 return False;
15404 end if;
15405
15406 -- Normal test is simply that the enclosing dynamic scope is Standard
15407
15408 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
15409 end Is_Library_Level_Entity;
15410
15411 --------------------------------
15412 -- Is_Limited_Class_Wide_Type --
15413 --------------------------------
15414
15415 function Is_Limited_Class_Wide_Type (Typ : Entity_Id) return Boolean is
15416 begin
15417 return
15418 Is_Class_Wide_Type (Typ)
15419 and then (Is_Limited_Type (Typ) or else From_Limited_With (Typ));
15420 end Is_Limited_Class_Wide_Type;
15421
15422 ---------------------------------
15423 -- Is_Local_Variable_Reference --
15424 ---------------------------------
15425
15426 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
15427 begin
15428 if not Is_Entity_Name (Expr) then
15429 return False;
15430
15431 else
15432 declare
15433 Ent : constant Entity_Id := Entity (Expr);
15434 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
15435 begin
15436 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
15437 return False;
15438 else
15439 return Present (Sub) and then Sub = Current_Subprogram;
15440 end if;
15441 end;
15442 end if;
15443 end Is_Local_Variable_Reference;
15444
15445 -----------------------
15446 -- Is_Name_Reference --
15447 -----------------------
15448
15449 function Is_Name_Reference (N : Node_Id) return Boolean is
15450 begin
15451 if Is_Entity_Name (N) then
15452 return Present (Entity (N)) and then Is_Object (Entity (N));
15453 end if;
15454
15455 case Nkind (N) is
15456 when N_Indexed_Component
15457 | N_Slice
15458 =>
15459 return
15460 Is_Name_Reference (Prefix (N))
15461 or else Is_Access_Type (Etype (Prefix (N)));
15462
15463 -- Attributes 'Input, 'Old and 'Result produce objects
15464
15465 when N_Attribute_Reference =>
15466 return
15467 Nam_In (Attribute_Name (N), Name_Input, Name_Old, Name_Result);
15468
15469 when N_Selected_Component =>
15470 return
15471 Is_Name_Reference (Selector_Name (N))
15472 and then
15473 (Is_Name_Reference (Prefix (N))
15474 or else Is_Access_Type (Etype (Prefix (N))));
15475
15476 when N_Explicit_Dereference =>
15477 return True;
15478
15479 -- A view conversion of a tagged name is a name reference
15480
15481 when N_Type_Conversion =>
15482 return
15483 Is_Tagged_Type (Etype (Subtype_Mark (N)))
15484 and then Is_Tagged_Type (Etype (Expression (N)))
15485 and then Is_Name_Reference (Expression (N));
15486
15487 -- An unchecked type conversion is considered to be a name if the
15488 -- operand is a name (this construction arises only as a result of
15489 -- expansion activities).
15490
15491 when N_Unchecked_Type_Conversion =>
15492 return Is_Name_Reference (Expression (N));
15493
15494 when others =>
15495 return False;
15496 end case;
15497 end Is_Name_Reference;
15498
15499 ------------------------------------
15500 -- Is_Non_Preelaborable_Construct --
15501 ------------------------------------
15502
15503 function Is_Non_Preelaborable_Construct (N : Node_Id) return Boolean is
15504
15505 -- NOTE: the routines within Is_Non_Preelaborable_Construct are
15506 -- intentionally unnested to avoid deep indentation of code.
15507
15508 Non_Preelaborable : exception;
15509 -- This exception is raised when the construct violates preelaborability
15510 -- to terminate the recursion.
15511
15512 procedure Visit (Nod : Node_Id);
15513 -- Semantically inspect construct Nod to determine whether it violates
15514 -- preelaborability. This routine raises Non_Preelaborable.
15515
15516 procedure Visit_List (List : List_Id);
15517 pragma Inline (Visit_List);
15518 -- Invoke Visit on each element of list List. This routine raises
15519 -- Non_Preelaborable.
15520
15521 procedure Visit_Pragma (Prag : Node_Id);
15522 pragma Inline (Visit_Pragma);
15523 -- Semantically inspect pragma Prag to determine whether it violates
15524 -- preelaborability. This routine raises Non_Preelaborable.
15525
15526 procedure Visit_Subexpression (Expr : Node_Id);
15527 pragma Inline (Visit_Subexpression);
15528 -- Semantically inspect expression Expr to determine whether it violates
15529 -- preelaborability. This routine raises Non_Preelaborable.
15530
15531 -----------
15532 -- Visit --
15533 -----------
15534
15535 procedure Visit (Nod : Node_Id) is
15536 begin
15537 case Nkind (Nod) is
15538
15539 -- Declarations
15540
15541 when N_Component_Declaration =>
15542
15543 -- Defining_Identifier is left out because it is not relevant
15544 -- for preelaborability.
15545
15546 Visit (Component_Definition (Nod));
15547 Visit (Expression (Nod));
15548
15549 when N_Derived_Type_Definition =>
15550
15551 -- Interface_List is left out because it is not relevant for
15552 -- preelaborability.
15553
15554 Visit (Record_Extension_Part (Nod));
15555 Visit (Subtype_Indication (Nod));
15556
15557 when N_Entry_Declaration =>
15558
15559 -- A protected type with at leat one entry is not preelaborable
15560 -- while task types are never preelaborable. This renders entry
15561 -- declarations non-preelaborable.
15562
15563 raise Non_Preelaborable;
15564
15565 when N_Full_Type_Declaration =>
15566
15567 -- Defining_Identifier and Discriminant_Specifications are left
15568 -- out because they are not relevant for preelaborability.
15569
15570 Visit (Type_Definition (Nod));
15571
15572 when N_Function_Instantiation
15573 | N_Package_Instantiation
15574 | N_Procedure_Instantiation
15575 =>
15576 -- Defining_Unit_Name and Name are left out because they are
15577 -- not relevant for preelaborability.
15578
15579 Visit_List (Generic_Associations (Nod));
15580
15581 when N_Object_Declaration =>
15582
15583 -- Defining_Identifier is left out because it is not relevant
15584 -- for preelaborability.
15585
15586 Visit (Object_Definition (Nod));
15587
15588 if Has_Init_Expression (Nod) then
15589 Visit (Expression (Nod));
15590
15591 elsif not Has_Preelaborable_Initialization
15592 (Etype (Defining_Entity (Nod)))
15593 then
15594 raise Non_Preelaborable;
15595 end if;
15596
15597 when N_Private_Extension_Declaration
15598 | N_Subtype_Declaration
15599 =>
15600 -- Defining_Identifier, Discriminant_Specifications, and
15601 -- Interface_List are left out because they are not relevant
15602 -- for preelaborability.
15603
15604 Visit (Subtype_Indication (Nod));
15605
15606 when N_Protected_Type_Declaration
15607 | N_Single_Protected_Declaration
15608 =>
15609 -- Defining_Identifier, Discriminant_Specifications, and
15610 -- Interface_List are left out because they are not relevant
15611 -- for preelaborability.
15612
15613 Visit (Protected_Definition (Nod));
15614
15615 -- A [single] task type is never preelaborable
15616
15617 when N_Single_Task_Declaration
15618 | N_Task_Type_Declaration
15619 =>
15620 raise Non_Preelaborable;
15621
15622 -- Pragmas
15623
15624 when N_Pragma =>
15625 Visit_Pragma (Nod);
15626
15627 -- Statements
15628
15629 when N_Statement_Other_Than_Procedure_Call =>
15630 if Nkind (Nod) /= N_Null_Statement then
15631 raise Non_Preelaborable;
15632 end if;
15633
15634 -- Subexpressions
15635
15636 when N_Subexpr =>
15637 Visit_Subexpression (Nod);
15638
15639 -- Special
15640
15641 when N_Access_To_Object_Definition =>
15642 Visit (Subtype_Indication (Nod));
15643
15644 when N_Case_Expression_Alternative =>
15645 Visit (Expression (Nod));
15646 Visit_List (Discrete_Choices (Nod));
15647
15648 when N_Component_Definition =>
15649 Visit (Access_Definition (Nod));
15650 Visit (Subtype_Indication (Nod));
15651
15652 when N_Component_List =>
15653 Visit_List (Component_Items (Nod));
15654 Visit (Variant_Part (Nod));
15655
15656 when N_Constrained_Array_Definition =>
15657 Visit_List (Discrete_Subtype_Definitions (Nod));
15658 Visit (Component_Definition (Nod));
15659
15660 when N_Delta_Constraint
15661 | N_Digits_Constraint
15662 =>
15663 -- Delta_Expression and Digits_Expression are left out because
15664 -- they are not relevant for preelaborability.
15665
15666 Visit (Range_Constraint (Nod));
15667
15668 when N_Discriminant_Specification =>
15669
15670 -- Defining_Identifier and Expression are left out because they
15671 -- are not relevant for preelaborability.
15672
15673 Visit (Discriminant_Type (Nod));
15674
15675 when N_Generic_Association =>
15676
15677 -- Selector_Name is left out because it is not relevant for
15678 -- preelaborability.
15679
15680 Visit (Explicit_Generic_Actual_Parameter (Nod));
15681
15682 when N_Index_Or_Discriminant_Constraint =>
15683 Visit_List (Constraints (Nod));
15684
15685 when N_Iterator_Specification =>
15686
15687 -- Defining_Identifier is left out because it is not relevant
15688 -- for preelaborability.
15689
15690 Visit (Name (Nod));
15691 Visit (Subtype_Indication (Nod));
15692
15693 when N_Loop_Parameter_Specification =>
15694
15695 -- Defining_Identifier is left out because it is not relevant
15696 -- for preelaborability.
15697
15698 Visit (Discrete_Subtype_Definition (Nod));
15699
15700 when N_Protected_Definition =>
15701
15702 -- End_Label is left out because it is not relevant for
15703 -- preelaborability.
15704
15705 Visit_List (Private_Declarations (Nod));
15706 Visit_List (Visible_Declarations (Nod));
15707
15708 when N_Range_Constraint =>
15709 Visit (Range_Expression (Nod));
15710
15711 when N_Record_Definition
15712 | N_Variant
15713 =>
15714 -- End_Label, Discrete_Choices, and Interface_List are left out
15715 -- because they are not relevant for preelaborability.
15716
15717 Visit (Component_List (Nod));
15718
15719 when N_Subtype_Indication =>
15720
15721 -- Subtype_Mark is left out because it is not relevant for
15722 -- preelaborability.
15723
15724 Visit (Constraint (Nod));
15725
15726 when N_Unconstrained_Array_Definition =>
15727
15728 -- Subtype_Marks is left out because it is not relevant for
15729 -- preelaborability.
15730
15731 Visit (Component_Definition (Nod));
15732
15733 when N_Variant_Part =>
15734
15735 -- Name is left out because it is not relevant for
15736 -- preelaborability.
15737
15738 Visit_List (Variants (Nod));
15739
15740 -- Default
15741
15742 when others =>
15743 null;
15744 end case;
15745 end Visit;
15746
15747 ----------------
15748 -- Visit_List --
15749 ----------------
15750
15751 procedure Visit_List (List : List_Id) is
15752 Nod : Node_Id;
15753
15754 begin
15755 if Present (List) then
15756 Nod := First (List);
15757 while Present (Nod) loop
15758 Visit (Nod);
15759 Next (Nod);
15760 end loop;
15761 end if;
15762 end Visit_List;
15763
15764 ------------------
15765 -- Visit_Pragma --
15766 ------------------
15767
15768 procedure Visit_Pragma (Prag : Node_Id) is
15769 begin
15770 case Get_Pragma_Id (Prag) is
15771 when Pragma_Assert
15772 | Pragma_Assert_And_Cut
15773 | Pragma_Assume
15774 | Pragma_Async_Readers
15775 | Pragma_Async_Writers
15776 | Pragma_Attribute_Definition
15777 | Pragma_Check
15778 | Pragma_Constant_After_Elaboration
15779 | Pragma_CPU
15780 | Pragma_Deadline_Floor
15781 | Pragma_Dispatching_Domain
15782 | Pragma_Effective_Reads
15783 | Pragma_Effective_Writes
15784 | Pragma_Extensions_Visible
15785 | Pragma_Ghost
15786 | Pragma_Secondary_Stack_Size
15787 | Pragma_Task_Name
15788 | Pragma_Volatile_Function
15789 =>
15790 Visit_List (Pragma_Argument_Associations (Prag));
15791
15792 -- Default
15793
15794 when others =>
15795 null;
15796 end case;
15797 end Visit_Pragma;
15798
15799 -------------------------
15800 -- Visit_Subexpression --
15801 -------------------------
15802
15803 procedure Visit_Subexpression (Expr : Node_Id) is
15804 procedure Visit_Aggregate (Aggr : Node_Id);
15805 pragma Inline (Visit_Aggregate);
15806 -- Semantically inspect aggregate Aggr to determine whether it
15807 -- violates preelaborability.
15808
15809 ---------------------
15810 -- Visit_Aggregate --
15811 ---------------------
15812
15813 procedure Visit_Aggregate (Aggr : Node_Id) is
15814 begin
15815 if not Is_Preelaborable_Aggregate (Aggr) then
15816 raise Non_Preelaborable;
15817 end if;
15818 end Visit_Aggregate;
15819
15820 -- Start of processing for Visit_Subexpression
15821
15822 begin
15823 case Nkind (Expr) is
15824 when N_Allocator
15825 | N_Qualified_Expression
15826 | N_Type_Conversion
15827 | N_Unchecked_Expression
15828 | N_Unchecked_Type_Conversion
15829 =>
15830 -- Subpool_Handle_Name and Subtype_Mark are left out because
15831 -- they are not relevant for preelaborability.
15832
15833 Visit (Expression (Expr));
15834
15835 when N_Aggregate
15836 | N_Extension_Aggregate
15837 =>
15838 Visit_Aggregate (Expr);
15839
15840 when N_Attribute_Reference
15841 | N_Explicit_Dereference
15842 | N_Reference
15843 =>
15844 -- Attribute_Name and Expressions are left out because they are
15845 -- not relevant for preelaborability.
15846
15847 Visit (Prefix (Expr));
15848
15849 when N_Case_Expression =>
15850
15851 -- End_Span is left out because it is not relevant for
15852 -- preelaborability.
15853
15854 Visit_List (Alternatives (Expr));
15855 Visit (Expression (Expr));
15856
15857 when N_Delta_Aggregate =>
15858 Visit_Aggregate (Expr);
15859 Visit (Expression (Expr));
15860
15861 when N_Expression_With_Actions =>
15862 Visit_List (Actions (Expr));
15863 Visit (Expression (Expr));
15864
15865 when N_If_Expression =>
15866 Visit_List (Expressions (Expr));
15867
15868 when N_Quantified_Expression =>
15869 Visit (Condition (Expr));
15870 Visit (Iterator_Specification (Expr));
15871 Visit (Loop_Parameter_Specification (Expr));
15872
15873 when N_Range =>
15874 Visit (High_Bound (Expr));
15875 Visit (Low_Bound (Expr));
15876
15877 when N_Slice =>
15878 Visit (Discrete_Range (Expr));
15879 Visit (Prefix (Expr));
15880
15881 -- Default
15882
15883 when others =>
15884
15885 -- The evaluation of an object name is not preelaborable,
15886 -- unless the name is a static expression (checked further
15887 -- below), or statically denotes a discriminant.
15888
15889 if Is_Entity_Name (Expr) then
15890 Object_Name : declare
15891 Id : constant Entity_Id := Entity (Expr);
15892
15893 begin
15894 if Is_Object (Id) then
15895 if Ekind (Id) = E_Discriminant then
15896 null;
15897
15898 elsif Ekind_In (Id, E_Constant, E_In_Parameter)
15899 and then Present (Discriminal_Link (Id))
15900 then
15901 null;
15902
15903 else
15904 raise Non_Preelaborable;
15905 end if;
15906 end if;
15907 end Object_Name;
15908
15909 -- A non-static expression is not preelaborable
15910
15911 elsif not Is_OK_Static_Expression (Expr) then
15912 raise Non_Preelaborable;
15913 end if;
15914 end case;
15915 end Visit_Subexpression;
15916
15917 -- Start of processing for Is_Non_Preelaborable_Construct
15918
15919 begin
15920 Visit (N);
15921
15922 -- At this point it is known that the construct is preelaborable
15923
15924 return False;
15925
15926 exception
15927
15928 -- The elaboration of the construct performs an action which violates
15929 -- preelaborability.
15930
15931 when Non_Preelaborable =>
15932 return True;
15933 end Is_Non_Preelaborable_Construct;
15934
15935 ---------------------------------
15936 -- Is_Nontrivial_DIC_Procedure --
15937 ---------------------------------
15938
15939 function Is_Nontrivial_DIC_Procedure (Id : Entity_Id) return Boolean is
15940 Body_Decl : Node_Id;
15941 Stmt : Node_Id;
15942
15943 begin
15944 if Ekind (Id) = E_Procedure and then Is_DIC_Procedure (Id) then
15945 Body_Decl :=
15946 Unit_Declaration_Node
15947 (Corresponding_Body (Unit_Declaration_Node (Id)));
15948
15949 -- The body of the Default_Initial_Condition procedure must contain
15950 -- at least one statement, otherwise the generation of the subprogram
15951 -- body failed.
15952
15953 pragma Assert (Present (Handled_Statement_Sequence (Body_Decl)));
15954
15955 -- To qualify as nontrivial, the first statement of the procedure
15956 -- must be a check in the form of an if statement. If the original
15957 -- Default_Initial_Condition expression was folded, then the first
15958 -- statement is not a check.
15959
15960 Stmt := First (Statements (Handled_Statement_Sequence (Body_Decl)));
15961
15962 return
15963 Nkind (Stmt) = N_If_Statement
15964 and then Nkind (Original_Node (Stmt)) = N_Pragma;
15965 end if;
15966
15967 return False;
15968 end Is_Nontrivial_DIC_Procedure;
15969
15970 -------------------------
15971 -- Is_Null_Record_Type --
15972 -------------------------
15973
15974 function Is_Null_Record_Type (T : Entity_Id) return Boolean is
15975 Decl : constant Node_Id := Parent (T);
15976 begin
15977 return Nkind (Decl) = N_Full_Type_Declaration
15978 and then Nkind (Type_Definition (Decl)) = N_Record_Definition
15979 and then
15980 (No (Component_List (Type_Definition (Decl)))
15981 or else Null_Present (Component_List (Type_Definition (Decl))));
15982 end Is_Null_Record_Type;
15983
15984 ---------------------
15985 -- Is_Object_Image --
15986 ---------------------
15987
15988 function Is_Object_Image (Prefix : Node_Id) return Boolean is
15989 begin
15990 -- When the type of the prefix is not scalar, then the prefix is not
15991 -- valid in any scenario.
15992
15993 if not Is_Scalar_Type (Etype (Prefix)) then
15994 return False;
15995 end if;
15996
15997 -- Here we test for the case that the prefix is not a type and assume
15998 -- if it is not then it must be a named value or an object reference.
15999 -- This is because the parser always checks that prefixes of attributes
16000 -- are named.
16001
16002 return not (Is_Entity_Name (Prefix) and then Is_Type (Entity (Prefix)));
16003 end Is_Object_Image;
16004
16005 -------------------------
16006 -- Is_Object_Reference --
16007 -------------------------
16008
16009 function Is_Object_Reference (N : Node_Id) return Boolean is
16010 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean;
16011 -- Determine whether N is the name of an internally-generated renaming
16012
16013 --------------------------------------
16014 -- Is_Internally_Generated_Renaming --
16015 --------------------------------------
16016
16017 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean is
16018 P : Node_Id;
16019
16020 begin
16021 P := N;
16022 while Present (P) loop
16023 if Nkind (P) = N_Object_Renaming_Declaration then
16024 return not Comes_From_Source (P);
16025 elsif Is_List_Member (P) then
16026 return False;
16027 end if;
16028
16029 P := Parent (P);
16030 end loop;
16031
16032 return False;
16033 end Is_Internally_Generated_Renaming;
16034
16035 -- Start of processing for Is_Object_Reference
16036
16037 begin
16038 if Is_Entity_Name (N) then
16039 return Present (Entity (N)) and then Is_Object (Entity (N));
16040
16041 else
16042 case Nkind (N) is
16043 when N_Indexed_Component
16044 | N_Slice
16045 =>
16046 return
16047 Is_Object_Reference (Prefix (N))
16048 or else Is_Access_Type (Etype (Prefix (N)));
16049
16050 -- In Ada 95, a function call is a constant object; a procedure
16051 -- call is not.
16052
16053 -- Note that predefined operators are functions as well, and so
16054 -- are attributes that are (can be renamed as) functions.
16055
16056 when N_Binary_Op
16057 | N_Function_Call
16058 | N_Unary_Op
16059 =>
16060 return Etype (N) /= Standard_Void_Type;
16061
16062 -- Attributes references 'Loop_Entry, 'Old, and 'Result yield
16063 -- objects, even though they are not functions.
16064
16065 when N_Attribute_Reference =>
16066 return
16067 Nam_In (Attribute_Name (N), Name_Loop_Entry,
16068 Name_Old,
16069 Name_Result)
16070 or else Is_Function_Attribute_Name (Attribute_Name (N));
16071
16072 when N_Selected_Component =>
16073 return
16074 Is_Object_Reference (Selector_Name (N))
16075 and then
16076 (Is_Object_Reference (Prefix (N))
16077 or else Is_Access_Type (Etype (Prefix (N))));
16078
16079 -- An explicit dereference denotes an object, except that a
16080 -- conditional expression gets turned into an explicit dereference
16081 -- in some cases, and conditional expressions are not object
16082 -- names.
16083
16084 when N_Explicit_Dereference =>
16085 return not Nkind_In (Original_Node (N), N_Case_Expression,
16086 N_If_Expression);
16087
16088 -- A view conversion of a tagged object is an object reference
16089
16090 when N_Type_Conversion =>
16091 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
16092 and then Is_Tagged_Type (Etype (Expression (N)))
16093 and then Is_Object_Reference (Expression (N));
16094
16095 -- An unchecked type conversion is considered to be an object if
16096 -- the operand is an object (this construction arises only as a
16097 -- result of expansion activities).
16098
16099 when N_Unchecked_Type_Conversion =>
16100 return True;
16101
16102 -- Allow string literals to act as objects as long as they appear
16103 -- in internally-generated renamings. The expansion of iterators
16104 -- may generate such renamings when the range involves a string
16105 -- literal.
16106
16107 when N_String_Literal =>
16108 return Is_Internally_Generated_Renaming (Parent (N));
16109
16110 -- AI05-0003: In Ada 2012 a qualified expression is a name.
16111 -- This allows disambiguation of function calls and the use
16112 -- of aggregates in more contexts.
16113
16114 when N_Qualified_Expression =>
16115 if Ada_Version < Ada_2012 then
16116 return False;
16117 else
16118 return Is_Object_Reference (Expression (N))
16119 or else Nkind (Expression (N)) = N_Aggregate;
16120 end if;
16121
16122 when others =>
16123 return False;
16124 end case;
16125 end if;
16126 end Is_Object_Reference;
16127
16128 -----------------------------------
16129 -- Is_OK_Variable_For_Out_Formal --
16130 -----------------------------------
16131
16132 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
16133 begin
16134 Note_Possible_Modification (AV, Sure => True);
16135
16136 -- We must reject parenthesized variable names. Comes_From_Source is
16137 -- checked because there are currently cases where the compiler violates
16138 -- this rule (e.g. passing a task object to its controlled Initialize
16139 -- routine). This should be properly documented in sinfo???
16140
16141 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
16142 return False;
16143
16144 -- A variable is always allowed
16145
16146 elsif Is_Variable (AV) then
16147 return True;
16148
16149 -- Generalized indexing operations are rewritten as explicit
16150 -- dereferences, and it is only during resolution that we can
16151 -- check whether the context requires an access_to_variable type.
16152
16153 elsif Nkind (AV) = N_Explicit_Dereference
16154 and then Ada_Version >= Ada_2012
16155 and then Nkind (Original_Node (AV)) = N_Indexed_Component
16156 and then Present (Etype (Original_Node (AV)))
16157 and then Has_Implicit_Dereference (Etype (Original_Node (AV)))
16158 then
16159 return not Is_Access_Constant (Etype (Prefix (AV)));
16160
16161 -- Unchecked conversions are allowed only if they come from the
16162 -- generated code, which sometimes uses unchecked conversions for out
16163 -- parameters in cases where code generation is unaffected. We tell
16164 -- source unchecked conversions by seeing if they are rewrites of
16165 -- an original Unchecked_Conversion function call, or of an explicit
16166 -- conversion of a function call or an aggregate (as may happen in the
16167 -- expansion of a packed array aggregate).
16168
16169 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
16170 if Nkind_In (Original_Node (AV), N_Function_Call, N_Aggregate) then
16171 return False;
16172
16173 elsif Comes_From_Source (AV)
16174 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
16175 then
16176 return False;
16177
16178 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
16179 return Is_OK_Variable_For_Out_Formal (Expression (AV));
16180
16181 else
16182 return True;
16183 end if;
16184
16185 -- Normal type conversions are allowed if argument is a variable
16186
16187 elsif Nkind (AV) = N_Type_Conversion then
16188 if Is_Variable (Expression (AV))
16189 and then Paren_Count (Expression (AV)) = 0
16190 then
16191 Note_Possible_Modification (Expression (AV), Sure => True);
16192 return True;
16193
16194 -- We also allow a non-parenthesized expression that raises
16195 -- constraint error if it rewrites what used to be a variable
16196
16197 elsif Raises_Constraint_Error (Expression (AV))
16198 and then Paren_Count (Expression (AV)) = 0
16199 and then Is_Variable (Original_Node (Expression (AV)))
16200 then
16201 return True;
16202
16203 -- Type conversion of something other than a variable
16204
16205 else
16206 return False;
16207 end if;
16208
16209 -- If this node is rewritten, then test the original form, if that is
16210 -- OK, then we consider the rewritten node OK (for example, if the
16211 -- original node is a conversion, then Is_Variable will not be true
16212 -- but we still want to allow the conversion if it converts a variable).
16213
16214 elsif Is_Rewrite_Substitution (AV) then
16215
16216 -- In Ada 2012, the explicit dereference may be a rewritten call to a
16217 -- Reference function.
16218
16219 if Ada_Version >= Ada_2012
16220 and then Nkind (Original_Node (AV)) = N_Function_Call
16221 and then
16222 Has_Implicit_Dereference (Etype (Name (Original_Node (AV))))
16223 then
16224
16225 -- Check that this is not a constant reference.
16226
16227 return not Is_Access_Constant (Etype (Prefix (AV)));
16228
16229 elsif Has_Implicit_Dereference (Etype (Original_Node (AV))) then
16230 return
16231 not Is_Access_Constant (Etype
16232 (Get_Reference_Discriminant (Etype (Original_Node (AV)))));
16233
16234 else
16235 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
16236 end if;
16237
16238 -- All other non-variables are rejected
16239
16240 else
16241 return False;
16242 end if;
16243 end Is_OK_Variable_For_Out_Formal;
16244
16245 ----------------------------
16246 -- Is_OK_Volatile_Context --
16247 ----------------------------
16248
16249 function Is_OK_Volatile_Context
16250 (Context : Node_Id;
16251 Obj_Ref : Node_Id) return Boolean
16252 is
16253 function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean;
16254 -- Determine whether an arbitrary node denotes a call to a protected
16255 -- entry, function, or procedure in prefixed form where the prefix is
16256 -- Obj_Ref.
16257
16258 function Within_Check (Nod : Node_Id) return Boolean;
16259 -- Determine whether an arbitrary node appears in a check node
16260
16261 function Within_Volatile_Function (Id : Entity_Id) return Boolean;
16262 -- Determine whether an arbitrary entity appears in a volatile function
16263
16264 ---------------------------------
16265 -- Is_Protected_Operation_Call --
16266 ---------------------------------
16267
16268 function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean is
16269 Pref : Node_Id;
16270 Subp : Node_Id;
16271
16272 begin
16273 -- A call to a protected operations retains its selected component
16274 -- form as opposed to other prefixed calls that are transformed in
16275 -- expanded names.
16276
16277 if Nkind (Nod) = N_Selected_Component then
16278 Pref := Prefix (Nod);
16279 Subp := Selector_Name (Nod);
16280
16281 return
16282 Pref = Obj_Ref
16283 and then Present (Etype (Pref))
16284 and then Is_Protected_Type (Etype (Pref))
16285 and then Is_Entity_Name (Subp)
16286 and then Present (Entity (Subp))
16287 and then Ekind_In (Entity (Subp), E_Entry,
16288 E_Entry_Family,
16289 E_Function,
16290 E_Procedure);
16291 else
16292 return False;
16293 end if;
16294 end Is_Protected_Operation_Call;
16295
16296 ------------------
16297 -- Within_Check --
16298 ------------------
16299
16300 function Within_Check (Nod : Node_Id) return Boolean is
16301 Par : Node_Id;
16302
16303 begin
16304 -- Climb the parent chain looking for a check node
16305
16306 Par := Nod;
16307 while Present (Par) loop
16308 if Nkind (Par) in N_Raise_xxx_Error then
16309 return True;
16310
16311 -- Prevent the search from going too far
16312
16313 elsif Is_Body_Or_Package_Declaration (Par) then
16314 exit;
16315 end if;
16316
16317 Par := Parent (Par);
16318 end loop;
16319
16320 return False;
16321 end Within_Check;
16322
16323 ------------------------------
16324 -- Within_Volatile_Function --
16325 ------------------------------
16326
16327 function Within_Volatile_Function (Id : Entity_Id) return Boolean is
16328 Func_Id : Entity_Id;
16329
16330 begin
16331 -- Traverse the scope stack looking for a [generic] function
16332
16333 Func_Id := Id;
16334 while Present (Func_Id) and then Func_Id /= Standard_Standard loop
16335 if Ekind_In (Func_Id, E_Function, E_Generic_Function) then
16336 return Is_Volatile_Function (Func_Id);
16337 end if;
16338
16339 Func_Id := Scope (Func_Id);
16340 end loop;
16341
16342 return False;
16343 end Within_Volatile_Function;
16344
16345 -- Local variables
16346
16347 Obj_Id : Entity_Id;
16348
16349 -- Start of processing for Is_OK_Volatile_Context
16350
16351 begin
16352 -- The volatile object appears on either side of an assignment
16353
16354 if Nkind (Context) = N_Assignment_Statement then
16355 return True;
16356
16357 -- The volatile object is part of the initialization expression of
16358 -- another object.
16359
16360 elsif Nkind (Context) = N_Object_Declaration
16361 and then Present (Expression (Context))
16362 and then Expression (Context) = Obj_Ref
16363 then
16364 Obj_Id := Defining_Entity (Context);
16365
16366 -- The volatile object acts as the initialization expression of an
16367 -- extended return statement. This is valid context as long as the
16368 -- function is volatile.
16369
16370 if Is_Return_Object (Obj_Id) then
16371 return Within_Volatile_Function (Obj_Id);
16372
16373 -- Otherwise this is a normal object initialization
16374
16375 else
16376 return True;
16377 end if;
16378
16379 -- The volatile object acts as the name of a renaming declaration
16380
16381 elsif Nkind (Context) = N_Object_Renaming_Declaration
16382 and then Name (Context) = Obj_Ref
16383 then
16384 return True;
16385
16386 -- The volatile object appears as an actual parameter in a call to an
16387 -- instance of Unchecked_Conversion whose result is renamed.
16388
16389 elsif Nkind (Context) = N_Function_Call
16390 and then Is_Entity_Name (Name (Context))
16391 and then Is_Unchecked_Conversion_Instance (Entity (Name (Context)))
16392 and then Nkind (Parent (Context)) = N_Object_Renaming_Declaration
16393 then
16394 return True;
16395
16396 -- The volatile object is actually the prefix in a protected entry,
16397 -- function, or procedure call.
16398
16399 elsif Is_Protected_Operation_Call (Context) then
16400 return True;
16401
16402 -- The volatile object appears as the expression of a simple return
16403 -- statement that applies to a volatile function.
16404
16405 elsif Nkind (Context) = N_Simple_Return_Statement
16406 and then Expression (Context) = Obj_Ref
16407 then
16408 return
16409 Within_Volatile_Function (Return_Statement_Entity (Context));
16410
16411 -- The volatile object appears as the prefix of a name occurring in a
16412 -- non-interfering context.
16413
16414 elsif Nkind_In (Context, N_Attribute_Reference,
16415 N_Explicit_Dereference,
16416 N_Indexed_Component,
16417 N_Selected_Component,
16418 N_Slice)
16419 and then Prefix (Context) = Obj_Ref
16420 and then Is_OK_Volatile_Context
16421 (Context => Parent (Context),
16422 Obj_Ref => Context)
16423 then
16424 return True;
16425
16426 -- The volatile object appears as the prefix of attributes Address,
16427 -- Alignment, Component_Size, First, First_Bit, Last, Last_Bit, Length,
16428 -- Position, Size, Storage_Size.
16429
16430 elsif Nkind (Context) = N_Attribute_Reference
16431 and then Prefix (Context) = Obj_Ref
16432 and then Nam_In (Attribute_Name (Context), Name_Address,
16433 Name_Alignment,
16434 Name_Component_Size,
16435 Name_First,
16436 Name_First_Bit,
16437 Name_Last,
16438 Name_Last_Bit,
16439 Name_Length,
16440 Name_Position,
16441 Name_Size,
16442 Name_Storage_Size)
16443 then
16444 return True;
16445
16446 -- The volatile object appears as the expression of a type conversion
16447 -- occurring in a non-interfering context.
16448
16449 elsif Nkind_In (Context, N_Type_Conversion,
16450 N_Unchecked_Type_Conversion)
16451 and then Expression (Context) = Obj_Ref
16452 and then Is_OK_Volatile_Context
16453 (Context => Parent (Context),
16454 Obj_Ref => Context)
16455 then
16456 return True;
16457
16458 -- The volatile object appears as the expression in a delay statement
16459
16460 elsif Nkind (Context) in N_Delay_Statement then
16461 return True;
16462
16463 -- Allow references to volatile objects in various checks. This is not a
16464 -- direct SPARK 2014 requirement.
16465
16466 elsif Within_Check (Context) then
16467 return True;
16468
16469 -- Assume that references to effectively volatile objects that appear
16470 -- as actual parameters in a subprogram call are always legal. A full
16471 -- legality check is done when the actuals are resolved (see routine
16472 -- Resolve_Actuals).
16473
16474 elsif Within_Subprogram_Call (Context) then
16475 return True;
16476
16477 -- Otherwise the context is not suitable for an effectively volatile
16478 -- object.
16479
16480 else
16481 return False;
16482 end if;
16483 end Is_OK_Volatile_Context;
16484
16485 ------------------------------------
16486 -- Is_Package_Contract_Annotation --
16487 ------------------------------------
16488
16489 function Is_Package_Contract_Annotation (Item : Node_Id) return Boolean is
16490 Nam : Name_Id;
16491
16492 begin
16493 if Nkind (Item) = N_Aspect_Specification then
16494 Nam := Chars (Identifier (Item));
16495
16496 else pragma Assert (Nkind (Item) = N_Pragma);
16497 Nam := Pragma_Name (Item);
16498 end if;
16499
16500 return Nam = Name_Abstract_State
16501 or else Nam = Name_Initial_Condition
16502 or else Nam = Name_Initializes
16503 or else Nam = Name_Refined_State;
16504 end Is_Package_Contract_Annotation;
16505
16506 -----------------------------------
16507 -- Is_Partially_Initialized_Type --
16508 -----------------------------------
16509
16510 function Is_Partially_Initialized_Type
16511 (Typ : Entity_Id;
16512 Include_Implicit : Boolean := True) return Boolean
16513 is
16514 begin
16515 if Is_Scalar_Type (Typ) then
16516 return False;
16517
16518 elsif Is_Access_Type (Typ) then
16519 return Include_Implicit;
16520
16521 elsif Is_Array_Type (Typ) then
16522
16523 -- If component type is partially initialized, so is array type
16524
16525 if Is_Partially_Initialized_Type
16526 (Component_Type (Typ), Include_Implicit)
16527 then
16528 return True;
16529
16530 -- Otherwise we are only partially initialized if we are fully
16531 -- initialized (this is the empty array case, no point in us
16532 -- duplicating that code here).
16533
16534 else
16535 return Is_Fully_Initialized_Type (Typ);
16536 end if;
16537
16538 elsif Is_Record_Type (Typ) then
16539
16540 -- A discriminated type is always partially initialized if in
16541 -- all mode
16542
16543 if Has_Discriminants (Typ) and then Include_Implicit then
16544 return True;
16545
16546 -- A tagged type is always partially initialized
16547
16548 elsif Is_Tagged_Type (Typ) then
16549 return True;
16550
16551 -- Case of non-discriminated record
16552
16553 else
16554 declare
16555 Ent : Entity_Id;
16556
16557 Component_Present : Boolean := False;
16558 -- Set True if at least one component is present. If no
16559 -- components are present, then record type is fully
16560 -- initialized (another odd case, like the null array).
16561
16562 begin
16563 -- Loop through components
16564
16565 Ent := First_Entity (Typ);
16566 while Present (Ent) loop
16567 if Ekind (Ent) = E_Component then
16568 Component_Present := True;
16569
16570 -- If a component has an initialization expression then
16571 -- the enclosing record type is partially initialized
16572
16573 if Present (Parent (Ent))
16574 and then Present (Expression (Parent (Ent)))
16575 then
16576 return True;
16577
16578 -- If a component is of a type which is itself partially
16579 -- initialized, then the enclosing record type is also.
16580
16581 elsif Is_Partially_Initialized_Type
16582 (Etype (Ent), Include_Implicit)
16583 then
16584 return True;
16585 end if;
16586 end if;
16587
16588 Next_Entity (Ent);
16589 end loop;
16590
16591 -- No initialized components found. If we found any components
16592 -- they were all uninitialized so the result is false.
16593
16594 if Component_Present then
16595 return False;
16596
16597 -- But if we found no components, then all the components are
16598 -- initialized so we consider the type to be initialized.
16599
16600 else
16601 return True;
16602 end if;
16603 end;
16604 end if;
16605
16606 -- Concurrent types are always fully initialized
16607
16608 elsif Is_Concurrent_Type (Typ) then
16609 return True;
16610
16611 -- For a private type, go to underlying type. If there is no underlying
16612 -- type then just assume this partially initialized. Not clear if this
16613 -- can happen in a non-error case, but no harm in testing for this.
16614
16615 elsif Is_Private_Type (Typ) then
16616 declare
16617 U : constant Entity_Id := Underlying_Type (Typ);
16618 begin
16619 if No (U) then
16620 return True;
16621 else
16622 return Is_Partially_Initialized_Type (U, Include_Implicit);
16623 end if;
16624 end;
16625
16626 -- For any other type (are there any?) assume partially initialized
16627
16628 else
16629 return True;
16630 end if;
16631 end Is_Partially_Initialized_Type;
16632
16633 ------------------------------------
16634 -- Is_Potentially_Persistent_Type --
16635 ------------------------------------
16636
16637 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
16638 Comp : Entity_Id;
16639 Indx : Node_Id;
16640
16641 begin
16642 -- For private type, test corresponding full type
16643
16644 if Is_Private_Type (T) then
16645 return Is_Potentially_Persistent_Type (Full_View (T));
16646
16647 -- Scalar types are potentially persistent
16648
16649 elsif Is_Scalar_Type (T) then
16650 return True;
16651
16652 -- Record type is potentially persistent if not tagged and the types of
16653 -- all it components are potentially persistent, and no component has
16654 -- an initialization expression.
16655
16656 elsif Is_Record_Type (T)
16657 and then not Is_Tagged_Type (T)
16658 and then not Is_Partially_Initialized_Type (T)
16659 then
16660 Comp := First_Component (T);
16661 while Present (Comp) loop
16662 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
16663 return False;
16664 else
16665 Next_Entity (Comp);
16666 end if;
16667 end loop;
16668
16669 return True;
16670
16671 -- Array type is potentially persistent if its component type is
16672 -- potentially persistent and if all its constraints are static.
16673
16674 elsif Is_Array_Type (T) then
16675 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
16676 return False;
16677 end if;
16678
16679 Indx := First_Index (T);
16680 while Present (Indx) loop
16681 if not Is_OK_Static_Subtype (Etype (Indx)) then
16682 return False;
16683 else
16684 Next_Index (Indx);
16685 end if;
16686 end loop;
16687
16688 return True;
16689
16690 -- All other types are not potentially persistent
16691
16692 else
16693 return False;
16694 end if;
16695 end Is_Potentially_Persistent_Type;
16696
16697 --------------------------------
16698 -- Is_Potentially_Unevaluated --
16699 --------------------------------
16700
16701 function Is_Potentially_Unevaluated (N : Node_Id) return Boolean is
16702 Par : Node_Id;
16703 Expr : Node_Id;
16704
16705 begin
16706 Expr := N;
16707 Par := N;
16708
16709 -- A postcondition whose expression is a short-circuit is broken down
16710 -- into individual aspects for better exception reporting. The original
16711 -- short-circuit expression is rewritten as the second operand, and an
16712 -- occurrence of 'Old in that operand is potentially unevaluated.
16713 -- See sem_ch13.adb for details of this transformation. The reference
16714 -- to 'Old may appear within an expression, so we must look for the
16715 -- enclosing pragma argument in the tree that contains the reference.
16716
16717 while Present (Par)
16718 and then Nkind (Par) /= N_Pragma_Argument_Association
16719 loop
16720 if Is_Rewrite_Substitution (Par)
16721 and then Nkind (Original_Node (Par)) = N_And_Then
16722 then
16723 return True;
16724 end if;
16725
16726 Par := Parent (Par);
16727 end loop;
16728
16729 -- Other cases; 'Old appears within other expression (not the top-level
16730 -- conjunct in a postcondition) with a potentially unevaluated operand.
16731
16732 Par := Parent (Expr);
16733 while not Nkind_In (Par, N_And_Then,
16734 N_Case_Expression,
16735 N_If_Expression,
16736 N_In,
16737 N_Not_In,
16738 N_Or_Else,
16739 N_Quantified_Expression)
16740 loop
16741 Expr := Par;
16742 Par := Parent (Par);
16743
16744 -- If the context is not an expression, or if is the result of
16745 -- expansion of an enclosing construct (such as another attribute)
16746 -- the predicate does not apply.
16747
16748 if Nkind (Par) = N_Case_Expression_Alternative then
16749 null;
16750
16751 elsif Nkind (Par) not in N_Subexpr
16752 or else not Comes_From_Source (Par)
16753 then
16754 return False;
16755 end if;
16756 end loop;
16757
16758 if Nkind (Par) = N_If_Expression then
16759 return Is_Elsif (Par) or else Expr /= First (Expressions (Par));
16760
16761 elsif Nkind (Par) = N_Case_Expression then
16762 return Expr /= Expression (Par);
16763
16764 elsif Nkind_In (Par, N_And_Then, N_Or_Else) then
16765 return Expr = Right_Opnd (Par);
16766
16767 elsif Nkind_In (Par, N_In, N_Not_In) then
16768
16769 -- If the membership includes several alternatives, only the first is
16770 -- definitely evaluated.
16771
16772 if Present (Alternatives (Par)) then
16773 return Expr /= First (Alternatives (Par));
16774
16775 -- If this is a range membership both bounds are evaluated
16776
16777 else
16778 return False;
16779 end if;
16780
16781 elsif Nkind (Par) = N_Quantified_Expression then
16782 return Expr = Condition (Par);
16783
16784 else
16785 return False;
16786 end if;
16787 end Is_Potentially_Unevaluated;
16788
16789 -----------------------------------------
16790 -- Is_Predefined_Dispatching_Operation --
16791 -----------------------------------------
16792
16793 function Is_Predefined_Dispatching_Operation
16794 (E : Entity_Id) return Boolean
16795 is
16796 TSS_Name : TSS_Name_Type;
16797
16798 begin
16799 if not Is_Dispatching_Operation (E) then
16800 return False;
16801 end if;
16802
16803 Get_Name_String (Chars (E));
16804
16805 -- Most predefined primitives have internally generated names. Equality
16806 -- must be treated differently; the predefined operation is recognized
16807 -- as a homogeneous binary operator that returns Boolean.
16808
16809 if Name_Len > TSS_Name_Type'Last then
16810 TSS_Name :=
16811 TSS_Name_Type
16812 (Name_Buffer (Name_Len - TSS_Name'Length + 1 .. Name_Len));
16813
16814 if Nam_In (Chars (E), Name_uAssign, Name_uSize)
16815 or else
16816 (Chars (E) = Name_Op_Eq
16817 and then Etype (First_Formal (E)) = Etype (Last_Formal (E)))
16818 or else TSS_Name = TSS_Deep_Adjust
16819 or else TSS_Name = TSS_Deep_Finalize
16820 or else TSS_Name = TSS_Stream_Input
16821 or else TSS_Name = TSS_Stream_Output
16822 or else TSS_Name = TSS_Stream_Read
16823 or else TSS_Name = TSS_Stream_Write
16824 or else Is_Predefined_Interface_Primitive (E)
16825 then
16826 return True;
16827 end if;
16828 end if;
16829
16830 return False;
16831 end Is_Predefined_Dispatching_Operation;
16832
16833 ---------------------------------------
16834 -- Is_Predefined_Interface_Primitive --
16835 ---------------------------------------
16836
16837 function Is_Predefined_Interface_Primitive (E : Entity_Id) return Boolean is
16838 begin
16839 -- In VM targets we don't restrict the functionality of this test to
16840 -- compiling in Ada 2005 mode since in VM targets any tagged type has
16841 -- these primitives.
16842
16843 return (Ada_Version >= Ada_2005 or else not Tagged_Type_Expansion)
16844 and then Nam_In (Chars (E), Name_uDisp_Asynchronous_Select,
16845 Name_uDisp_Conditional_Select,
16846 Name_uDisp_Get_Prim_Op_Kind,
16847 Name_uDisp_Get_Task_Id,
16848 Name_uDisp_Requeue,
16849 Name_uDisp_Timed_Select);
16850 end Is_Predefined_Interface_Primitive;
16851
16852 ---------------------------------------
16853 -- Is_Predefined_Internal_Operation --
16854 ---------------------------------------
16855
16856 function Is_Predefined_Internal_Operation
16857 (E : Entity_Id) return Boolean
16858 is
16859 TSS_Name : TSS_Name_Type;
16860
16861 begin
16862 if not Is_Dispatching_Operation (E) then
16863 return False;
16864 end if;
16865
16866 Get_Name_String (Chars (E));
16867
16868 -- Most predefined primitives have internally generated names. Equality
16869 -- must be treated differently; the predefined operation is recognized
16870 -- as a homogeneous binary operator that returns Boolean.
16871
16872 if Name_Len > TSS_Name_Type'Last then
16873 TSS_Name :=
16874 TSS_Name_Type
16875 (Name_Buffer (Name_Len - TSS_Name'Length + 1 .. Name_Len));
16876
16877 if Nam_In (Chars (E), Name_uSize, Name_uAssign)
16878 or else
16879 (Chars (E) = Name_Op_Eq
16880 and then Etype (First_Formal (E)) = Etype (Last_Formal (E)))
16881 or else TSS_Name = TSS_Deep_Adjust
16882 or else TSS_Name = TSS_Deep_Finalize
16883 or else Is_Predefined_Interface_Primitive (E)
16884 then
16885 return True;
16886 end if;
16887 end if;
16888
16889 return False;
16890 end Is_Predefined_Internal_Operation;
16891
16892 --------------------------------
16893 -- Is_Preelaborable_Aggregate --
16894 --------------------------------
16895
16896 function Is_Preelaborable_Aggregate (Aggr : Node_Id) return Boolean is
16897 Aggr_Typ : constant Entity_Id := Etype (Aggr);
16898 Array_Aggr : constant Boolean := Is_Array_Type (Aggr_Typ);
16899
16900 Anc_Part : Node_Id;
16901 Assoc : Node_Id;
16902 Choice : Node_Id;
16903 Comp_Typ : Entity_Id := Empty; -- init to avoid warning
16904 Expr : Node_Id;
16905
16906 begin
16907 if Array_Aggr then
16908 Comp_Typ := Component_Type (Aggr_Typ);
16909 end if;
16910
16911 -- Inspect the ancestor part
16912
16913 if Nkind (Aggr) = N_Extension_Aggregate then
16914 Anc_Part := Ancestor_Part (Aggr);
16915
16916 -- The ancestor denotes a subtype mark
16917
16918 if Is_Entity_Name (Anc_Part)
16919 and then Is_Type (Entity (Anc_Part))
16920 then
16921 if not Has_Preelaborable_Initialization (Entity (Anc_Part)) then
16922 return False;
16923 end if;
16924
16925 -- Otherwise the ancestor denotes an expression
16926
16927 elsif not Is_Preelaborable_Construct (Anc_Part) then
16928 return False;
16929 end if;
16930 end if;
16931
16932 -- Inspect the positional associations
16933
16934 Expr := First (Expressions (Aggr));
16935 while Present (Expr) loop
16936 if not Is_Preelaborable_Construct (Expr) then
16937 return False;
16938 end if;
16939
16940 Next (Expr);
16941 end loop;
16942
16943 -- Inspect the named associations
16944
16945 Assoc := First (Component_Associations (Aggr));
16946 while Present (Assoc) loop
16947
16948 -- Inspect the choices of the current named association
16949
16950 Choice := First (Choices (Assoc));
16951 while Present (Choice) loop
16952 if Array_Aggr then
16953
16954 -- For a choice to be preelaborable, it must denote either a
16955 -- static range or a static expression.
16956
16957 if Nkind (Choice) = N_Others_Choice then
16958 null;
16959
16960 elsif Nkind (Choice) = N_Range then
16961 if not Is_OK_Static_Range (Choice) then
16962 return False;
16963 end if;
16964
16965 elsif not Is_OK_Static_Expression (Choice) then
16966 return False;
16967 end if;
16968
16969 else
16970 Comp_Typ := Etype (Choice);
16971 end if;
16972
16973 Next (Choice);
16974 end loop;
16975
16976 -- The type of the choice must have preelaborable initialization if
16977 -- the association carries a <>.
16978
16979 pragma Assert (Present (Comp_Typ));
16980 if Box_Present (Assoc) then
16981 if not Has_Preelaborable_Initialization (Comp_Typ) then
16982 return False;
16983 end if;
16984
16985 -- The type of the expression must have preelaborable initialization
16986
16987 elsif not Is_Preelaborable_Construct (Expression (Assoc)) then
16988 return False;
16989 end if;
16990
16991 Next (Assoc);
16992 end loop;
16993
16994 -- At this point the aggregate is preelaborable
16995
16996 return True;
16997 end Is_Preelaborable_Aggregate;
16998
16999 --------------------------------
17000 -- Is_Preelaborable_Construct --
17001 --------------------------------
17002
17003 function Is_Preelaborable_Construct (N : Node_Id) return Boolean is
17004 begin
17005 -- Aggregates
17006
17007 if Nkind_In (N, N_Aggregate, N_Extension_Aggregate) then
17008 return Is_Preelaborable_Aggregate (N);
17009
17010 -- Attributes are allowed in general, even if their prefix is a formal
17011 -- type. It seems that certain attributes known not to be static might
17012 -- not be allowed, but there are no rules to prevent them.
17013
17014 elsif Nkind (N) = N_Attribute_Reference then
17015 return True;
17016
17017 -- Expressions
17018
17019 elsif Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then
17020 return True;
17021
17022 elsif Nkind (N) = N_Qualified_Expression then
17023 return Is_Preelaborable_Construct (Expression (N));
17024
17025 -- Names are preelaborable when they denote a discriminant of an
17026 -- enclosing type. Discriminals are also considered for this check.
17027
17028 elsif Is_Entity_Name (N)
17029 and then Present (Entity (N))
17030 and then
17031 (Ekind (Entity (N)) = E_Discriminant
17032 or else (Ekind_In (Entity (N), E_Constant, E_In_Parameter)
17033 and then Present (Discriminal_Link (Entity (N)))))
17034 then
17035 return True;
17036
17037 -- Statements
17038
17039 elsif Nkind (N) = N_Null then
17040 return True;
17041
17042 -- Otherwise the construct is not preelaborable
17043
17044 else
17045 return False;
17046 end if;
17047 end Is_Preelaborable_Construct;
17048
17049 ---------------------------------
17050 -- Is_Protected_Self_Reference --
17051 ---------------------------------
17052
17053 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
17054
17055 function In_Access_Definition (N : Node_Id) return Boolean;
17056 -- Returns true if N belongs to an access definition
17057
17058 --------------------------
17059 -- In_Access_Definition --
17060 --------------------------
17061
17062 function In_Access_Definition (N : Node_Id) return Boolean is
17063 P : Node_Id;
17064
17065 begin
17066 P := Parent (N);
17067 while Present (P) loop
17068 if Nkind (P) = N_Access_Definition then
17069 return True;
17070 end if;
17071
17072 P := Parent (P);
17073 end loop;
17074
17075 return False;
17076 end In_Access_Definition;
17077
17078 -- Start of processing for Is_Protected_Self_Reference
17079
17080 begin
17081 -- Verify that prefix is analyzed and has the proper form. Note that
17082 -- the attributes Elab_Spec, Elab_Body, and Elab_Subp_Body, which also
17083 -- produce the address of an entity, do not analyze their prefix
17084 -- because they denote entities that are not necessarily visible.
17085 -- Neither of them can apply to a protected type.
17086
17087 return Ada_Version >= Ada_2005
17088 and then Is_Entity_Name (N)
17089 and then Present (Entity (N))
17090 and then Is_Protected_Type (Entity (N))
17091 and then In_Open_Scopes (Entity (N))
17092 and then not In_Access_Definition (N);
17093 end Is_Protected_Self_Reference;
17094
17095 -----------------------------
17096 -- Is_RCI_Pkg_Spec_Or_Body --
17097 -----------------------------
17098
17099 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
17100
17101 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
17102 -- Return True if the unit of Cunit is an RCI package declaration
17103
17104 ---------------------------
17105 -- Is_RCI_Pkg_Decl_Cunit --
17106 ---------------------------
17107
17108 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
17109 The_Unit : constant Node_Id := Unit (Cunit);
17110
17111 begin
17112 if Nkind (The_Unit) /= N_Package_Declaration then
17113 return False;
17114 end if;
17115
17116 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
17117 end Is_RCI_Pkg_Decl_Cunit;
17118
17119 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
17120
17121 begin
17122 return Is_RCI_Pkg_Decl_Cunit (Cunit)
17123 or else
17124 (Nkind (Unit (Cunit)) = N_Package_Body
17125 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
17126 end Is_RCI_Pkg_Spec_Or_Body;
17127
17128 -----------------------------------------
17129 -- Is_Remote_Access_To_Class_Wide_Type --
17130 -----------------------------------------
17131
17132 function Is_Remote_Access_To_Class_Wide_Type
17133 (E : Entity_Id) return Boolean
17134 is
17135 begin
17136 -- A remote access to class-wide type is a general access to object type
17137 -- declared in the visible part of a Remote_Types or Remote_Call_
17138 -- Interface unit.
17139
17140 return Ekind (E) = E_General_Access_Type
17141 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
17142 end Is_Remote_Access_To_Class_Wide_Type;
17143
17144 -----------------------------------------
17145 -- Is_Remote_Access_To_Subprogram_Type --
17146 -----------------------------------------
17147
17148 function Is_Remote_Access_To_Subprogram_Type
17149 (E : Entity_Id) return Boolean
17150 is
17151 begin
17152 return (Ekind (E) = E_Access_Subprogram_Type
17153 or else (Ekind (E) = E_Record_Type
17154 and then Present (Corresponding_Remote_Type (E))))
17155 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
17156 end Is_Remote_Access_To_Subprogram_Type;
17157
17158 --------------------
17159 -- Is_Remote_Call --
17160 --------------------
17161
17162 function Is_Remote_Call (N : Node_Id) return Boolean is
17163 begin
17164 if Nkind (N) not in N_Subprogram_Call then
17165
17166 -- An entry call cannot be remote
17167
17168 return False;
17169
17170 elsif Nkind (Name (N)) in N_Has_Entity
17171 and then Is_Remote_Call_Interface (Entity (Name (N)))
17172 then
17173 -- A subprogram declared in the spec of a RCI package is remote
17174
17175 return True;
17176
17177 elsif Nkind (Name (N)) = N_Explicit_Dereference
17178 and then Is_Remote_Access_To_Subprogram_Type
17179 (Etype (Prefix (Name (N))))
17180 then
17181 -- The dereference of a RAS is a remote call
17182
17183 return True;
17184
17185 elsif Present (Controlling_Argument (N))
17186 and then Is_Remote_Access_To_Class_Wide_Type
17187 (Etype (Controlling_Argument (N)))
17188 then
17189 -- Any primitive operation call with a controlling argument of
17190 -- a RACW type is a remote call.
17191
17192 return True;
17193 end if;
17194
17195 -- All other calls are local calls
17196
17197 return False;
17198 end Is_Remote_Call;
17199
17200 ----------------------
17201 -- Is_Renamed_Entry --
17202 ----------------------
17203
17204 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
17205 Orig_Node : Node_Id := Empty;
17206 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
17207
17208 function Is_Entry (Nam : Node_Id) return Boolean;
17209 -- Determine whether Nam is an entry. Traverse selectors if there are
17210 -- nested selected components.
17211
17212 --------------
17213 -- Is_Entry --
17214 --------------
17215
17216 function Is_Entry (Nam : Node_Id) return Boolean is
17217 begin
17218 if Nkind (Nam) = N_Selected_Component then
17219 return Is_Entry (Selector_Name (Nam));
17220 end if;
17221
17222 return Ekind (Entity (Nam)) = E_Entry;
17223 end Is_Entry;
17224
17225 -- Start of processing for Is_Renamed_Entry
17226
17227 begin
17228 if Present (Alias (Proc_Nam)) then
17229 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
17230 end if;
17231
17232 -- Look for a rewritten subprogram renaming declaration
17233
17234 if Nkind (Subp_Decl) = N_Subprogram_Declaration
17235 and then Present (Original_Node (Subp_Decl))
17236 then
17237 Orig_Node := Original_Node (Subp_Decl);
17238 end if;
17239
17240 -- The rewritten subprogram is actually an entry
17241
17242 if Present (Orig_Node)
17243 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
17244 and then Is_Entry (Name (Orig_Node))
17245 then
17246 return True;
17247 end if;
17248
17249 return False;
17250 end Is_Renamed_Entry;
17251
17252 -----------------------------
17253 -- Is_Renaming_Declaration --
17254 -----------------------------
17255
17256 function Is_Renaming_Declaration (N : Node_Id) return Boolean is
17257 begin
17258 case Nkind (N) is
17259 when N_Exception_Renaming_Declaration
17260 | N_Generic_Function_Renaming_Declaration
17261 | N_Generic_Package_Renaming_Declaration
17262 | N_Generic_Procedure_Renaming_Declaration
17263 | N_Object_Renaming_Declaration
17264 | N_Package_Renaming_Declaration
17265 | N_Subprogram_Renaming_Declaration
17266 =>
17267 return True;
17268
17269 when others =>
17270 return False;
17271 end case;
17272 end Is_Renaming_Declaration;
17273
17274 ----------------------------
17275 -- Is_Reversible_Iterator --
17276 ----------------------------
17277
17278 function Is_Reversible_Iterator (Typ : Entity_Id) return Boolean is
17279 Ifaces_List : Elist_Id;
17280 Iface_Elmt : Elmt_Id;
17281 Iface : Entity_Id;
17282
17283 begin
17284 if Is_Class_Wide_Type (Typ)
17285 and then Chars (Root_Type (Typ)) = Name_Reversible_Iterator
17286 and then In_Predefined_Unit (Root_Type (Typ))
17287 then
17288 return True;
17289
17290 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
17291 return False;
17292
17293 else
17294 Collect_Interfaces (Typ, Ifaces_List);
17295
17296 Iface_Elmt := First_Elmt (Ifaces_List);
17297 while Present (Iface_Elmt) loop
17298 Iface := Node (Iface_Elmt);
17299 if Chars (Iface) = Name_Reversible_Iterator
17300 and then In_Predefined_Unit (Iface)
17301 then
17302 return True;
17303 end if;
17304
17305 Next_Elmt (Iface_Elmt);
17306 end loop;
17307 end if;
17308
17309 return False;
17310 end Is_Reversible_Iterator;
17311
17312 ----------------------
17313 -- Is_Selector_Name --
17314 ----------------------
17315
17316 function Is_Selector_Name (N : Node_Id) return Boolean is
17317 begin
17318 if not Is_List_Member (N) then
17319 declare
17320 P : constant Node_Id := Parent (N);
17321 begin
17322 return Nkind_In (P, N_Expanded_Name,
17323 N_Generic_Association,
17324 N_Parameter_Association,
17325 N_Selected_Component)
17326 and then Selector_Name (P) = N;
17327 end;
17328
17329 else
17330 declare
17331 L : constant List_Id := List_Containing (N);
17332 P : constant Node_Id := Parent (L);
17333 begin
17334 return (Nkind (P) = N_Discriminant_Association
17335 and then Selector_Names (P) = L)
17336 or else
17337 (Nkind (P) = N_Component_Association
17338 and then Choices (P) = L);
17339 end;
17340 end if;
17341 end Is_Selector_Name;
17342
17343 ---------------------------------
17344 -- Is_Single_Concurrent_Object --
17345 ---------------------------------
17346
17347 function Is_Single_Concurrent_Object (Id : Entity_Id) return Boolean is
17348 begin
17349 return
17350 Is_Single_Protected_Object (Id) or else Is_Single_Task_Object (Id);
17351 end Is_Single_Concurrent_Object;
17352
17353 -------------------------------
17354 -- Is_Single_Concurrent_Type --
17355 -------------------------------
17356
17357 function Is_Single_Concurrent_Type (Id : Entity_Id) return Boolean is
17358 begin
17359 return
17360 Ekind_In (Id, E_Protected_Type, E_Task_Type)
17361 and then Is_Single_Concurrent_Type_Declaration
17362 (Declaration_Node (Id));
17363 end Is_Single_Concurrent_Type;
17364
17365 -------------------------------------------
17366 -- Is_Single_Concurrent_Type_Declaration --
17367 -------------------------------------------
17368
17369 function Is_Single_Concurrent_Type_Declaration
17370 (N : Node_Id) return Boolean
17371 is
17372 begin
17373 return Nkind_In (Original_Node (N), N_Single_Protected_Declaration,
17374 N_Single_Task_Declaration);
17375 end Is_Single_Concurrent_Type_Declaration;
17376
17377 ---------------------------------------------
17378 -- Is_Single_Precision_Floating_Point_Type --
17379 ---------------------------------------------
17380
17381 function Is_Single_Precision_Floating_Point_Type
17382 (E : Entity_Id) return Boolean is
17383 begin
17384 return Is_Floating_Point_Type (E)
17385 and then Machine_Radix_Value (E) = Uint_2
17386 and then Machine_Mantissa_Value (E) = Uint_24
17387 and then Machine_Emax_Value (E) = Uint_2 ** Uint_7
17388 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_7);
17389 end Is_Single_Precision_Floating_Point_Type;
17390
17391 --------------------------------
17392 -- Is_Single_Protected_Object --
17393 --------------------------------
17394
17395 function Is_Single_Protected_Object (Id : Entity_Id) return Boolean is
17396 begin
17397 return
17398 Ekind (Id) = E_Variable
17399 and then Ekind (Etype (Id)) = E_Protected_Type
17400 and then Is_Single_Concurrent_Type (Etype (Id));
17401 end Is_Single_Protected_Object;
17402
17403 ---------------------------
17404 -- Is_Single_Task_Object --
17405 ---------------------------
17406
17407 function Is_Single_Task_Object (Id : Entity_Id) return Boolean is
17408 begin
17409 return
17410 Ekind (Id) = E_Variable
17411 and then Ekind (Etype (Id)) = E_Task_Type
17412 and then Is_Single_Concurrent_Type (Etype (Id));
17413 end Is_Single_Task_Object;
17414
17415 -------------------------------------
17416 -- Is_SPARK_05_Initialization_Expr --
17417 -------------------------------------
17418
17419 function Is_SPARK_05_Initialization_Expr (N : Node_Id) return Boolean is
17420 Is_Ok : Boolean;
17421 Expr : Node_Id;
17422 Comp_Assn : Node_Id;
17423 Orig_N : constant Node_Id := Original_Node (N);
17424
17425 begin
17426 Is_Ok := True;
17427
17428 if not Comes_From_Source (Orig_N) then
17429 goto Done;
17430 end if;
17431
17432 pragma Assert (Nkind (Orig_N) in N_Subexpr);
17433
17434 case Nkind (Orig_N) is
17435 when N_Character_Literal
17436 | N_Integer_Literal
17437 | N_Real_Literal
17438 | N_String_Literal
17439 =>
17440 null;
17441
17442 when N_Expanded_Name
17443 | N_Identifier
17444 =>
17445 if Is_Entity_Name (Orig_N)
17446 and then Present (Entity (Orig_N)) -- needed in some cases
17447 then
17448 case Ekind (Entity (Orig_N)) is
17449 when E_Constant
17450 | E_Enumeration_Literal
17451 | E_Named_Integer
17452 | E_Named_Real
17453 =>
17454 null;
17455
17456 when others =>
17457 if Is_Type (Entity (Orig_N)) then
17458 null;
17459 else
17460 Is_Ok := False;
17461 end if;
17462 end case;
17463 end if;
17464
17465 when N_Qualified_Expression
17466 | N_Type_Conversion
17467 =>
17468 Is_Ok := Is_SPARK_05_Initialization_Expr (Expression (Orig_N));
17469
17470 when N_Unary_Op =>
17471 Is_Ok := Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
17472
17473 when N_Binary_Op
17474 | N_Membership_Test
17475 | N_Short_Circuit
17476 =>
17477 Is_Ok := Is_SPARK_05_Initialization_Expr (Left_Opnd (Orig_N))
17478 and then
17479 Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
17480
17481 when N_Aggregate
17482 | N_Extension_Aggregate
17483 =>
17484 if Nkind (Orig_N) = N_Extension_Aggregate then
17485 Is_Ok :=
17486 Is_SPARK_05_Initialization_Expr (Ancestor_Part (Orig_N));
17487 end if;
17488
17489 Expr := First (Expressions (Orig_N));
17490 while Present (Expr) loop
17491 if not Is_SPARK_05_Initialization_Expr (Expr) then
17492 Is_Ok := False;
17493 goto Done;
17494 end if;
17495
17496 Next (Expr);
17497 end loop;
17498
17499 Comp_Assn := First (Component_Associations (Orig_N));
17500 while Present (Comp_Assn) loop
17501 Expr := Expression (Comp_Assn);
17502
17503 -- Note: test for Present here needed for box assocation
17504
17505 if Present (Expr)
17506 and then not Is_SPARK_05_Initialization_Expr (Expr)
17507 then
17508 Is_Ok := False;
17509 goto Done;
17510 end if;
17511
17512 Next (Comp_Assn);
17513 end loop;
17514
17515 when N_Attribute_Reference =>
17516 if Nkind (Prefix (Orig_N)) in N_Subexpr then
17517 Is_Ok := Is_SPARK_05_Initialization_Expr (Prefix (Orig_N));
17518 end if;
17519
17520 Expr := First (Expressions (Orig_N));
17521 while Present (Expr) loop
17522 if not Is_SPARK_05_Initialization_Expr (Expr) then
17523 Is_Ok := False;
17524 goto Done;
17525 end if;
17526
17527 Next (Expr);
17528 end loop;
17529
17530 -- Selected components might be expanded named not yet resolved, so
17531 -- default on the safe side. (Eg on sparklex.ads)
17532
17533 when N_Selected_Component =>
17534 null;
17535
17536 when others =>
17537 Is_Ok := False;
17538 end case;
17539
17540 <<Done>>
17541 return Is_Ok;
17542 end Is_SPARK_05_Initialization_Expr;
17543
17544 ----------------------------------
17545 -- Is_SPARK_05_Object_Reference --
17546 ----------------------------------
17547
17548 function Is_SPARK_05_Object_Reference (N : Node_Id) return Boolean is
17549 begin
17550 if Is_Entity_Name (N) then
17551 return Present (Entity (N))
17552 and then
17553 (Ekind_In (Entity (N), E_Constant, E_Variable)
17554 or else Ekind (Entity (N)) in Formal_Kind);
17555
17556 else
17557 case Nkind (N) is
17558 when N_Selected_Component =>
17559 return Is_SPARK_05_Object_Reference (Prefix (N));
17560
17561 when others =>
17562 return False;
17563 end case;
17564 end if;
17565 end Is_SPARK_05_Object_Reference;
17566
17567 -----------------------------
17568 -- Is_Specific_Tagged_Type --
17569 -----------------------------
17570
17571 function Is_Specific_Tagged_Type (Typ : Entity_Id) return Boolean is
17572 Full_Typ : Entity_Id;
17573
17574 begin
17575 -- Handle private types
17576
17577 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
17578 Full_Typ := Full_View (Typ);
17579 else
17580 Full_Typ := Typ;
17581 end if;
17582
17583 -- A specific tagged type is a non-class-wide tagged type
17584
17585 return Is_Tagged_Type (Full_Typ) and not Is_Class_Wide_Type (Full_Typ);
17586 end Is_Specific_Tagged_Type;
17587
17588 ------------------
17589 -- Is_Statement --
17590 ------------------
17591
17592 function Is_Statement (N : Node_Id) return Boolean is
17593 begin
17594 return
17595 Nkind (N) in N_Statement_Other_Than_Procedure_Call
17596 or else Nkind (N) = N_Procedure_Call_Statement;
17597 end Is_Statement;
17598
17599 ---------------------------------------
17600 -- Is_Subprogram_Contract_Annotation --
17601 ---------------------------------------
17602
17603 function Is_Subprogram_Contract_Annotation
17604 (Item : Node_Id) return Boolean
17605 is
17606 Nam : Name_Id;
17607
17608 begin
17609 if Nkind (Item) = N_Aspect_Specification then
17610 Nam := Chars (Identifier (Item));
17611
17612 else pragma Assert (Nkind (Item) = N_Pragma);
17613 Nam := Pragma_Name (Item);
17614 end if;
17615
17616 return Nam = Name_Contract_Cases
17617 or else Nam = Name_Depends
17618 or else Nam = Name_Extensions_Visible
17619 or else Nam = Name_Global
17620 or else Nam = Name_Post
17621 or else Nam = Name_Post_Class
17622 or else Nam = Name_Postcondition
17623 or else Nam = Name_Pre
17624 or else Nam = Name_Pre_Class
17625 or else Nam = Name_Precondition
17626 or else Nam = Name_Refined_Depends
17627 or else Nam = Name_Refined_Global
17628 or else Nam = Name_Refined_Post
17629 or else Nam = Name_Test_Case;
17630 end Is_Subprogram_Contract_Annotation;
17631
17632 --------------------------------------------------
17633 -- Is_Subprogram_Stub_Without_Prior_Declaration --
17634 --------------------------------------------------
17635
17636 function Is_Subprogram_Stub_Without_Prior_Declaration
17637 (N : Node_Id) return Boolean
17638 is
17639 begin
17640 pragma Assert (Nkind (N) = N_Subprogram_Body_Stub);
17641
17642 case Ekind (Defining_Entity (N)) is
17643
17644 -- A subprogram stub without prior declaration serves as declaration
17645 -- for the actual subprogram body. As such, it has an attached
17646 -- defining entity of E_Function or E_Procedure.
17647
17648 when E_Function
17649 | E_Procedure
17650 =>
17651 return True;
17652
17653 -- Otherwise, it is completes a [generic] subprogram declaration
17654
17655 when E_Generic_Function
17656 | E_Generic_Procedure
17657 | E_Subprogram_Body
17658 =>
17659 return False;
17660
17661 when others =>
17662 raise Program_Error;
17663 end case;
17664 end Is_Subprogram_Stub_Without_Prior_Declaration;
17665
17666 ---------------------------
17667 -- Is_Suitable_Primitive --
17668 ---------------------------
17669
17670 function Is_Suitable_Primitive (Subp_Id : Entity_Id) return Boolean is
17671 begin
17672 -- The Default_Initial_Condition and invariant procedures must not be
17673 -- treated as primitive operations even when they apply to a tagged
17674 -- type. These routines must not act as targets of dispatching calls
17675 -- because they already utilize class-wide-precondition semantics to
17676 -- handle inheritance and overriding.
17677
17678 if Ekind (Subp_Id) = E_Procedure
17679 and then (Is_DIC_Procedure (Subp_Id)
17680 or else
17681 Is_Invariant_Procedure (Subp_Id))
17682 then
17683 return False;
17684 end if;
17685
17686 return True;
17687 end Is_Suitable_Primitive;
17688
17689 --------------------------
17690 -- Is_Suspension_Object --
17691 --------------------------
17692
17693 function Is_Suspension_Object (Id : Entity_Id) return Boolean is
17694 begin
17695 -- This approach does an exact name match rather than to rely on
17696 -- RTSfind. Routine Is_Effectively_Volatile is used by clients of the
17697 -- front end at point where all auxiliary tables are locked and any
17698 -- modifications to them are treated as violations. Do not tamper with
17699 -- the tables, instead examine the Chars fields of all the scopes of Id.
17700
17701 return
17702 Chars (Id) = Name_Suspension_Object
17703 and then Present (Scope (Id))
17704 and then Chars (Scope (Id)) = Name_Synchronous_Task_Control
17705 and then Present (Scope (Scope (Id)))
17706 and then Chars (Scope (Scope (Id))) = Name_Ada
17707 and then Present (Scope (Scope (Scope (Id))))
17708 and then Scope (Scope (Scope (Id))) = Standard_Standard;
17709 end Is_Suspension_Object;
17710
17711 ----------------------------
17712 -- Is_Synchronized_Object --
17713 ----------------------------
17714
17715 function Is_Synchronized_Object (Id : Entity_Id) return Boolean is
17716 Prag : Node_Id;
17717
17718 begin
17719 if Is_Object (Id) then
17720
17721 -- The object is synchronized if it is of a type that yields a
17722 -- synchronized object.
17723
17724 if Yields_Synchronized_Object (Etype (Id)) then
17725 return True;
17726
17727 -- The object is synchronized if it is atomic and Async_Writers is
17728 -- enabled.
17729
17730 elsif Is_Atomic_Object_Entity (Id)
17731 and then Async_Writers_Enabled (Id)
17732 then
17733 return True;
17734
17735 -- A constant is a synchronized object by default
17736
17737 elsif Ekind (Id) = E_Constant then
17738 return True;
17739
17740 -- A variable is a synchronized object if it is subject to pragma
17741 -- Constant_After_Elaboration.
17742
17743 elsif Ekind (Id) = E_Variable then
17744 Prag := Get_Pragma (Id, Pragma_Constant_After_Elaboration);
17745
17746 return Present (Prag) and then Is_Enabled_Pragma (Prag);
17747 end if;
17748 end if;
17749
17750 -- Otherwise the input is not an object or it does not qualify as a
17751 -- synchronized object.
17752
17753 return False;
17754 end Is_Synchronized_Object;
17755
17756 ---------------------------------
17757 -- Is_Synchronized_Tagged_Type --
17758 ---------------------------------
17759
17760 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
17761 Kind : constant Entity_Kind := Ekind (Base_Type (E));
17762
17763 begin
17764 -- A task or protected type derived from an interface is a tagged type.
17765 -- Such a tagged type is called a synchronized tagged type, as are
17766 -- synchronized interfaces and private extensions whose declaration
17767 -- includes the reserved word synchronized.
17768
17769 return (Is_Tagged_Type (E)
17770 and then (Kind = E_Task_Type
17771 or else
17772 Kind = E_Protected_Type))
17773 or else
17774 (Is_Interface (E)
17775 and then Is_Synchronized_Interface (E))
17776 or else
17777 (Ekind (E) = E_Record_Type_With_Private
17778 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
17779 and then (Synchronized_Present (Parent (E))
17780 or else Is_Synchronized_Interface (Etype (E))));
17781 end Is_Synchronized_Tagged_Type;
17782
17783 -----------------
17784 -- Is_Transfer --
17785 -----------------
17786
17787 function Is_Transfer (N : Node_Id) return Boolean is
17788 Kind : constant Node_Kind := Nkind (N);
17789
17790 begin
17791 if Kind = N_Simple_Return_Statement
17792 or else
17793 Kind = N_Extended_Return_Statement
17794 or else
17795 Kind = N_Goto_Statement
17796 or else
17797 Kind = N_Raise_Statement
17798 or else
17799 Kind = N_Requeue_Statement
17800 then
17801 return True;
17802
17803 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
17804 and then No (Condition (N))
17805 then
17806 return True;
17807
17808 elsif Kind = N_Procedure_Call_Statement
17809 and then Is_Entity_Name (Name (N))
17810 and then Present (Entity (Name (N)))
17811 and then No_Return (Entity (Name (N)))
17812 then
17813 return True;
17814
17815 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
17816 return True;
17817
17818 else
17819 return False;
17820 end if;
17821 end Is_Transfer;
17822
17823 -------------
17824 -- Is_True --
17825 -------------
17826
17827 function Is_True (U : Uint) return Boolean is
17828 begin
17829 return (U /= 0);
17830 end Is_True;
17831
17832 --------------------------------------
17833 -- Is_Unchecked_Conversion_Instance --
17834 --------------------------------------
17835
17836 function Is_Unchecked_Conversion_Instance (Id : Entity_Id) return Boolean is
17837 Par : Node_Id;
17838
17839 begin
17840 -- Look for a function whose generic parent is the predefined intrinsic
17841 -- function Unchecked_Conversion, or for one that renames such an
17842 -- instance.
17843
17844 if Ekind (Id) = E_Function then
17845 Par := Parent (Id);
17846
17847 if Nkind (Par) = N_Function_Specification then
17848 Par := Generic_Parent (Par);
17849
17850 if Present (Par) then
17851 return
17852 Chars (Par) = Name_Unchecked_Conversion
17853 and then Is_Intrinsic_Subprogram (Par)
17854 and then In_Predefined_Unit (Par);
17855 else
17856 return
17857 Present (Alias (Id))
17858 and then Is_Unchecked_Conversion_Instance (Alias (Id));
17859 end if;
17860 end if;
17861 end if;
17862
17863 return False;
17864 end Is_Unchecked_Conversion_Instance;
17865
17866 -------------------------------
17867 -- Is_Universal_Numeric_Type --
17868 -------------------------------
17869
17870 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
17871 begin
17872 return T = Universal_Integer or else T = Universal_Real;
17873 end Is_Universal_Numeric_Type;
17874
17875 ------------------------------
17876 -- Is_User_Defined_Equality --
17877 ------------------------------
17878
17879 function Is_User_Defined_Equality (Id : Entity_Id) return Boolean is
17880 begin
17881 return Ekind (Id) = E_Function
17882 and then Chars (Id) = Name_Op_Eq
17883 and then Comes_From_Source (Id)
17884
17885 -- Internally generated equalities have a full type declaration
17886 -- as their parent.
17887
17888 and then Nkind (Parent (Id)) = N_Function_Specification;
17889 end Is_User_Defined_Equality;
17890
17891 --------------------------------------
17892 -- Is_Validation_Variable_Reference --
17893 --------------------------------------
17894
17895 function Is_Validation_Variable_Reference (N : Node_Id) return Boolean is
17896 Var : constant Node_Id := Unqual_Conv (N);
17897 Var_Id : Entity_Id;
17898
17899 begin
17900 Var_Id := Empty;
17901
17902 if Is_Entity_Name (Var) then
17903 Var_Id := Entity (Var);
17904 end if;
17905
17906 return
17907 Present (Var_Id)
17908 and then Ekind (Var_Id) = E_Variable
17909 and then Present (Validated_Object (Var_Id));
17910 end Is_Validation_Variable_Reference;
17911
17912 ----------------------------
17913 -- Is_Variable_Size_Array --
17914 ----------------------------
17915
17916 function Is_Variable_Size_Array (E : Entity_Id) return Boolean is
17917 Idx : Node_Id;
17918
17919 begin
17920 pragma Assert (Is_Array_Type (E));
17921
17922 -- Check if some index is initialized with a non-constant value
17923
17924 Idx := First_Index (E);
17925 while Present (Idx) loop
17926 if Nkind (Idx) = N_Range then
17927 if not Is_Constant_Bound (Low_Bound (Idx))
17928 or else not Is_Constant_Bound (High_Bound (Idx))
17929 then
17930 return True;
17931 end if;
17932 end if;
17933
17934 Idx := Next_Index (Idx);
17935 end loop;
17936
17937 return False;
17938 end Is_Variable_Size_Array;
17939
17940 -----------------------------
17941 -- Is_Variable_Size_Record --
17942 -----------------------------
17943
17944 function Is_Variable_Size_Record (E : Entity_Id) return Boolean is
17945 Comp : Entity_Id;
17946 Comp_Typ : Entity_Id;
17947
17948 begin
17949 pragma Assert (Is_Record_Type (E));
17950
17951 Comp := First_Component (E);
17952 while Present (Comp) loop
17953 Comp_Typ := Underlying_Type (Etype (Comp));
17954
17955 -- Recursive call if the record type has discriminants
17956
17957 if Is_Record_Type (Comp_Typ)
17958 and then Has_Discriminants (Comp_Typ)
17959 and then Is_Variable_Size_Record (Comp_Typ)
17960 then
17961 return True;
17962
17963 elsif Is_Array_Type (Comp_Typ)
17964 and then Is_Variable_Size_Array (Comp_Typ)
17965 then
17966 return True;
17967 end if;
17968
17969 Next_Component (Comp);
17970 end loop;
17971
17972 return False;
17973 end Is_Variable_Size_Record;
17974
17975 -----------------
17976 -- Is_Variable --
17977 -----------------
17978
17979 function Is_Variable
17980 (N : Node_Id;
17981 Use_Original_Node : Boolean := True) return Boolean
17982 is
17983 Orig_Node : Node_Id;
17984
17985 function In_Protected_Function (E : Entity_Id) return Boolean;
17986 -- Within a protected function, the private components of the enclosing
17987 -- protected type are constants. A function nested within a (protected)
17988 -- procedure is not itself protected. Within the body of a protected
17989 -- function the current instance of the protected type is a constant.
17990
17991 function Is_Variable_Prefix (P : Node_Id) return Boolean;
17992 -- Prefixes can involve implicit dereferences, in which case we must
17993 -- test for the case of a reference of a constant access type, which can
17994 -- can never be a variable.
17995
17996 ---------------------------
17997 -- In_Protected_Function --
17998 ---------------------------
17999
18000 function In_Protected_Function (E : Entity_Id) return Boolean is
18001 Prot : Entity_Id;
18002 S : Entity_Id;
18003
18004 begin
18005 -- E is the current instance of a type
18006
18007 if Is_Type (E) then
18008 Prot := E;
18009
18010 -- E is an object
18011
18012 else
18013 Prot := Scope (E);
18014 end if;
18015
18016 if not Is_Protected_Type (Prot) then
18017 return False;
18018
18019 else
18020 S := Current_Scope;
18021 while Present (S) and then S /= Prot loop
18022 if Ekind (S) = E_Function and then Scope (S) = Prot then
18023 return True;
18024 end if;
18025
18026 S := Scope (S);
18027 end loop;
18028
18029 return False;
18030 end if;
18031 end In_Protected_Function;
18032
18033 ------------------------
18034 -- Is_Variable_Prefix --
18035 ------------------------
18036
18037 function Is_Variable_Prefix (P : Node_Id) return Boolean is
18038 begin
18039 if Is_Access_Type (Etype (P)) then
18040 return not Is_Access_Constant (Root_Type (Etype (P)));
18041
18042 -- For the case of an indexed component whose prefix has a packed
18043 -- array type, the prefix has been rewritten into a type conversion.
18044 -- Determine variable-ness from the converted expression.
18045
18046 elsif Nkind (P) = N_Type_Conversion
18047 and then not Comes_From_Source (P)
18048 and then Is_Array_Type (Etype (P))
18049 and then Is_Packed (Etype (P))
18050 then
18051 return Is_Variable (Expression (P));
18052
18053 else
18054 return Is_Variable (P);
18055 end if;
18056 end Is_Variable_Prefix;
18057
18058 -- Start of processing for Is_Variable
18059
18060 begin
18061 -- Special check, allow x'Deref(expr) as a variable
18062
18063 if Nkind (N) = N_Attribute_Reference
18064 and then Attribute_Name (N) = Name_Deref
18065 then
18066 return True;
18067 end if;
18068
18069 -- Check if we perform the test on the original node since this may be a
18070 -- test of syntactic categories which must not be disturbed by whatever
18071 -- rewriting might have occurred. For example, an aggregate, which is
18072 -- certainly NOT a variable, could be turned into a variable by
18073 -- expansion.
18074
18075 if Use_Original_Node then
18076 Orig_Node := Original_Node (N);
18077 else
18078 Orig_Node := N;
18079 end if;
18080
18081 -- Definitely OK if Assignment_OK is set. Since this is something that
18082 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
18083
18084 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
18085 return True;
18086
18087 -- Normally we go to the original node, but there is one exception where
18088 -- we use the rewritten node, namely when it is an explicit dereference.
18089 -- The generated code may rewrite a prefix which is an access type with
18090 -- an explicit dereference. The dereference is a variable, even though
18091 -- the original node may not be (since it could be a constant of the
18092 -- access type).
18093
18094 -- In Ada 2005 we have a further case to consider: the prefix may be a
18095 -- function call given in prefix notation. The original node appears to
18096 -- be a selected component, but we need to examine the call.
18097
18098 elsif Nkind (N) = N_Explicit_Dereference
18099 and then Nkind (Orig_Node) /= N_Explicit_Dereference
18100 and then Present (Etype (Orig_Node))
18101 and then Is_Access_Type (Etype (Orig_Node))
18102 then
18103 -- Note that if the prefix is an explicit dereference that does not
18104 -- come from source, we must check for a rewritten function call in
18105 -- prefixed notation before other forms of rewriting, to prevent a
18106 -- compiler crash.
18107
18108 return
18109 (Nkind (Orig_Node) = N_Function_Call
18110 and then not Is_Access_Constant (Etype (Prefix (N))))
18111 or else
18112 Is_Variable_Prefix (Original_Node (Prefix (N)));
18113
18114 -- in Ada 2012, the dereference may have been added for a type with
18115 -- a declared implicit dereference aspect. Check that it is not an
18116 -- access to constant.
18117
18118 elsif Nkind (N) = N_Explicit_Dereference
18119 and then Present (Etype (Orig_Node))
18120 and then Ada_Version >= Ada_2012
18121 and then Has_Implicit_Dereference (Etype (Orig_Node))
18122 then
18123 return not Is_Access_Constant (Etype (Prefix (N)));
18124
18125 -- A function call is never a variable
18126
18127 elsif Nkind (N) = N_Function_Call then
18128 return False;
18129
18130 -- All remaining checks use the original node
18131
18132 elsif Is_Entity_Name (Orig_Node)
18133 and then Present (Entity (Orig_Node))
18134 then
18135 declare
18136 E : constant Entity_Id := Entity (Orig_Node);
18137 K : constant Entity_Kind := Ekind (E);
18138
18139 begin
18140 if Is_Loop_Parameter (E) then
18141 return False;
18142 end if;
18143
18144 return (K = E_Variable
18145 and then Nkind (Parent (E)) /= N_Exception_Handler)
18146 or else (K = E_Component
18147 and then not In_Protected_Function (E))
18148 or else K = E_Out_Parameter
18149 or else K = E_In_Out_Parameter
18150 or else K = E_Generic_In_Out_Parameter
18151
18152 -- Current instance of type. If this is a protected type, check
18153 -- we are not within the body of one of its protected functions.
18154
18155 or else (Is_Type (E)
18156 and then In_Open_Scopes (E)
18157 and then not In_Protected_Function (E))
18158
18159 or else (Is_Incomplete_Or_Private_Type (E)
18160 and then In_Open_Scopes (Full_View (E)));
18161 end;
18162
18163 else
18164 case Nkind (Orig_Node) is
18165 when N_Indexed_Component
18166 | N_Slice
18167 =>
18168 return Is_Variable_Prefix (Prefix (Orig_Node));
18169
18170 when N_Selected_Component =>
18171 return (Is_Variable (Selector_Name (Orig_Node))
18172 and then Is_Variable_Prefix (Prefix (Orig_Node)))
18173 or else
18174 (Nkind (N) = N_Expanded_Name
18175 and then Scope (Entity (N)) = Entity (Prefix (N)));
18176
18177 -- For an explicit dereference, the type of the prefix cannot
18178 -- be an access to constant or an access to subprogram.
18179
18180 when N_Explicit_Dereference =>
18181 declare
18182 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
18183 begin
18184 return Is_Access_Type (Typ)
18185 and then not Is_Access_Constant (Root_Type (Typ))
18186 and then Ekind (Typ) /= E_Access_Subprogram_Type;
18187 end;
18188
18189 -- The type conversion is the case where we do not deal with the
18190 -- context dependent special case of an actual parameter. Thus
18191 -- the type conversion is only considered a variable for the
18192 -- purposes of this routine if the target type is tagged. However,
18193 -- a type conversion is considered to be a variable if it does not
18194 -- come from source (this deals for example with the conversions
18195 -- of expressions to their actual subtypes).
18196
18197 when N_Type_Conversion =>
18198 return Is_Variable (Expression (Orig_Node))
18199 and then
18200 (not Comes_From_Source (Orig_Node)
18201 or else
18202 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
18203 and then
18204 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
18205
18206 -- GNAT allows an unchecked type conversion as a variable. This
18207 -- only affects the generation of internal expanded code, since
18208 -- calls to instantiations of Unchecked_Conversion are never
18209 -- considered variables (since they are function calls).
18210
18211 when N_Unchecked_Type_Conversion =>
18212 return Is_Variable (Expression (Orig_Node));
18213
18214 when others =>
18215 return False;
18216 end case;
18217 end if;
18218 end Is_Variable;
18219
18220 ---------------------------
18221 -- Is_Visibly_Controlled --
18222 ---------------------------
18223
18224 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
18225 Root : constant Entity_Id := Root_Type (T);
18226 begin
18227 return Chars (Scope (Root)) = Name_Finalization
18228 and then Chars (Scope (Scope (Root))) = Name_Ada
18229 and then Scope (Scope (Scope (Root))) = Standard_Standard;
18230 end Is_Visibly_Controlled;
18231
18232 --------------------------
18233 -- Is_Volatile_Function --
18234 --------------------------
18235
18236 function Is_Volatile_Function (Func_Id : Entity_Id) return Boolean is
18237 begin
18238 pragma Assert (Ekind_In (Func_Id, E_Function, E_Generic_Function));
18239
18240 -- A function declared within a protected type is volatile
18241
18242 if Is_Protected_Type (Scope (Func_Id)) then
18243 return True;
18244
18245 -- An instance of Ada.Unchecked_Conversion is a volatile function if
18246 -- either the source or the target are effectively volatile.
18247
18248 elsif Is_Unchecked_Conversion_Instance (Func_Id)
18249 and then Has_Effectively_Volatile_Profile (Func_Id)
18250 then
18251 return True;
18252
18253 -- Otherwise the function is treated as volatile if it is subject to
18254 -- enabled pragma Volatile_Function.
18255
18256 else
18257 return
18258 Is_Enabled_Pragma (Get_Pragma (Func_Id, Pragma_Volatile_Function));
18259 end if;
18260 end Is_Volatile_Function;
18261
18262 ------------------------
18263 -- Is_Volatile_Object --
18264 ------------------------
18265
18266 function Is_Volatile_Object (N : Node_Id) return Boolean is
18267 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
18268 -- If prefix is an implicit dereference, examine designated type
18269
18270 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
18271 -- Determines if given object has volatile components
18272
18273 ------------------------
18274 -- Is_Volatile_Prefix --
18275 ------------------------
18276
18277 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
18278 Typ : constant Entity_Id := Etype (N);
18279
18280 begin
18281 if Is_Access_Type (Typ) then
18282 declare
18283 Dtyp : constant Entity_Id := Designated_Type (Typ);
18284
18285 begin
18286 return Is_Volatile (Dtyp)
18287 or else Has_Volatile_Components (Dtyp);
18288 end;
18289
18290 else
18291 return Object_Has_Volatile_Components (N);
18292 end if;
18293 end Is_Volatile_Prefix;
18294
18295 ------------------------------------
18296 -- Object_Has_Volatile_Components --
18297 ------------------------------------
18298
18299 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
18300 Typ : constant Entity_Id := Etype (N);
18301
18302 begin
18303 if Is_Volatile (Typ)
18304 or else Has_Volatile_Components (Typ)
18305 then
18306 return True;
18307
18308 elsif Is_Entity_Name (N)
18309 and then (Has_Volatile_Components (Entity (N))
18310 or else Is_Volatile (Entity (N)))
18311 then
18312 return True;
18313
18314 elsif Nkind (N) = N_Indexed_Component
18315 or else Nkind (N) = N_Selected_Component
18316 then
18317 return Is_Volatile_Prefix (Prefix (N));
18318
18319 else
18320 return False;
18321 end if;
18322 end Object_Has_Volatile_Components;
18323
18324 -- Start of processing for Is_Volatile_Object
18325
18326 begin
18327 if Nkind (N) = N_Defining_Identifier then
18328 return Is_Volatile (N) or else Is_Volatile (Etype (N));
18329
18330 elsif Nkind (N) = N_Expanded_Name then
18331 return Is_Volatile_Object (Entity (N));
18332
18333 elsif Is_Volatile (Etype (N))
18334 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
18335 then
18336 return True;
18337
18338 elsif Nkind_In (N, N_Indexed_Component, N_Selected_Component)
18339 and then Is_Volatile_Prefix (Prefix (N))
18340 then
18341 return True;
18342
18343 elsif Nkind (N) = N_Selected_Component
18344 and then Is_Volatile (Entity (Selector_Name (N)))
18345 then
18346 return True;
18347
18348 else
18349 return False;
18350 end if;
18351 end Is_Volatile_Object;
18352
18353 -----------------------------
18354 -- Iterate_Call_Parameters --
18355 -----------------------------
18356
18357 procedure Iterate_Call_Parameters (Call : Node_Id) is
18358 Actual : Node_Id := First_Actual (Call);
18359 Formal : Entity_Id := First_Formal (Get_Called_Entity (Call));
18360
18361 begin
18362 while Present (Formal) and then Present (Actual) loop
18363 Handle_Parameter (Formal, Actual);
18364
18365 Next_Formal (Formal);
18366 Next_Actual (Actual);
18367 end loop;
18368
18369 pragma Assert (No (Formal));
18370 pragma Assert (No (Actual));
18371 end Iterate_Call_Parameters;
18372
18373 ---------------------------
18374 -- Itype_Has_Declaration --
18375 ---------------------------
18376
18377 function Itype_Has_Declaration (Id : Entity_Id) return Boolean is
18378 begin
18379 pragma Assert (Is_Itype (Id));
18380 return Present (Parent (Id))
18381 and then Nkind_In (Parent (Id), N_Full_Type_Declaration,
18382 N_Subtype_Declaration)
18383 and then Defining_Entity (Parent (Id)) = Id;
18384 end Itype_Has_Declaration;
18385
18386 -------------------------
18387 -- Kill_Current_Values --
18388 -------------------------
18389
18390 procedure Kill_Current_Values
18391 (Ent : Entity_Id;
18392 Last_Assignment_Only : Boolean := False)
18393 is
18394 begin
18395 if Is_Assignable (Ent) then
18396 Set_Last_Assignment (Ent, Empty);
18397 end if;
18398
18399 if Is_Object (Ent) then
18400 if not Last_Assignment_Only then
18401 Kill_Checks (Ent);
18402 Set_Current_Value (Ent, Empty);
18403
18404 -- Do not reset the Is_Known_[Non_]Null and Is_Known_Valid flags
18405 -- for a constant. Once the constant is elaborated, its value is
18406 -- not changed, therefore the associated flags that describe the
18407 -- value should not be modified either.
18408
18409 if Ekind (Ent) = E_Constant then
18410 null;
18411
18412 -- Non-constant entities
18413
18414 else
18415 if not Can_Never_Be_Null (Ent) then
18416 Set_Is_Known_Non_Null (Ent, False);
18417 end if;
18418
18419 Set_Is_Known_Null (Ent, False);
18420
18421 -- Reset the Is_Known_Valid flag unless the type is always
18422 -- valid. This does not apply to a loop parameter because its
18423 -- bounds are defined by the loop header and therefore always
18424 -- valid.
18425
18426 if not Is_Known_Valid (Etype (Ent))
18427 and then Ekind (Ent) /= E_Loop_Parameter
18428 then
18429 Set_Is_Known_Valid (Ent, False);
18430 end if;
18431 end if;
18432 end if;
18433 end if;
18434 end Kill_Current_Values;
18435
18436 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
18437 S : Entity_Id;
18438
18439 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
18440 -- Clear current value for entity E and all entities chained to E
18441
18442 ------------------------------------------
18443 -- Kill_Current_Values_For_Entity_Chain --
18444 ------------------------------------------
18445
18446 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
18447 Ent : Entity_Id;
18448 begin
18449 Ent := E;
18450 while Present (Ent) loop
18451 Kill_Current_Values (Ent, Last_Assignment_Only);
18452 Next_Entity (Ent);
18453 end loop;
18454 end Kill_Current_Values_For_Entity_Chain;
18455
18456 -- Start of processing for Kill_Current_Values
18457
18458 begin
18459 -- Kill all saved checks, a special case of killing saved values
18460
18461 if not Last_Assignment_Only then
18462 Kill_All_Checks;
18463 end if;
18464
18465 -- Loop through relevant scopes, which includes the current scope and
18466 -- any parent scopes if the current scope is a block or a package.
18467
18468 S := Current_Scope;
18469 Scope_Loop : loop
18470
18471 -- Clear current values of all entities in current scope
18472
18473 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
18474
18475 -- If scope is a package, also clear current values of all private
18476 -- entities in the scope.
18477
18478 if Is_Package_Or_Generic_Package (S)
18479 or else Is_Concurrent_Type (S)
18480 then
18481 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
18482 end if;
18483
18484 -- If this is a not a subprogram, deal with parents
18485
18486 if not Is_Subprogram (S) then
18487 S := Scope (S);
18488 exit Scope_Loop when S = Standard_Standard;
18489 else
18490 exit Scope_Loop;
18491 end if;
18492 end loop Scope_Loop;
18493 end Kill_Current_Values;
18494
18495 --------------------------
18496 -- Kill_Size_Check_Code --
18497 --------------------------
18498
18499 procedure Kill_Size_Check_Code (E : Entity_Id) is
18500 begin
18501 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
18502 and then Present (Size_Check_Code (E))
18503 then
18504 Remove (Size_Check_Code (E));
18505 Set_Size_Check_Code (E, Empty);
18506 end if;
18507 end Kill_Size_Check_Code;
18508
18509 --------------------
18510 -- Known_Non_Null --
18511 --------------------
18512
18513 function Known_Non_Null (N : Node_Id) return Boolean is
18514 Status : constant Null_Status_Kind := Null_Status (N);
18515
18516 Id : Entity_Id;
18517 Op : Node_Kind;
18518 Val : Node_Id;
18519
18520 begin
18521 -- The expression yields a non-null value ignoring simple flow analysis
18522
18523 if Status = Is_Non_Null then
18524 return True;
18525
18526 -- Otherwise check whether N is a reference to an entity that appears
18527 -- within a conditional construct.
18528
18529 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
18530
18531 -- First check if we are in decisive conditional
18532
18533 Get_Current_Value_Condition (N, Op, Val);
18534
18535 if Known_Null (Val) then
18536 if Op = N_Op_Eq then
18537 return False;
18538 elsif Op = N_Op_Ne then
18539 return True;
18540 end if;
18541 end if;
18542
18543 -- If OK to do replacement, test Is_Known_Non_Null flag
18544
18545 Id := Entity (N);
18546
18547 if OK_To_Do_Constant_Replacement (Id) then
18548 return Is_Known_Non_Null (Id);
18549 end if;
18550 end if;
18551
18552 -- Otherwise it is not possible to determine whether N yields a non-null
18553 -- value.
18554
18555 return False;
18556 end Known_Non_Null;
18557
18558 ----------------
18559 -- Known_Null --
18560 ----------------
18561
18562 function Known_Null (N : Node_Id) return Boolean is
18563 Status : constant Null_Status_Kind := Null_Status (N);
18564
18565 Id : Entity_Id;
18566 Op : Node_Kind;
18567 Val : Node_Id;
18568
18569 begin
18570 -- The expression yields a null value ignoring simple flow analysis
18571
18572 if Status = Is_Null then
18573 return True;
18574
18575 -- Otherwise check whether N is a reference to an entity that appears
18576 -- within a conditional construct.
18577
18578 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
18579
18580 -- First check if we are in decisive conditional
18581
18582 Get_Current_Value_Condition (N, Op, Val);
18583
18584 if Known_Null (Val) then
18585 if Op = N_Op_Eq then
18586 return True;
18587 elsif Op = N_Op_Ne then
18588 return False;
18589 end if;
18590 end if;
18591
18592 -- If OK to do replacement, test Is_Known_Null flag
18593
18594 Id := Entity (N);
18595
18596 if OK_To_Do_Constant_Replacement (Id) then
18597 return Is_Known_Null (Id);
18598 end if;
18599 end if;
18600
18601 -- Otherwise it is not possible to determine whether N yields a null
18602 -- value.
18603
18604 return False;
18605 end Known_Null;
18606
18607 --------------------------
18608 -- Known_To_Be_Assigned --
18609 --------------------------
18610
18611 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
18612 P : constant Node_Id := Parent (N);
18613
18614 begin
18615 case Nkind (P) is
18616
18617 -- Test left side of assignment
18618
18619 when N_Assignment_Statement =>
18620 return N = Name (P);
18621
18622 -- Function call arguments are never lvalues
18623
18624 when N_Function_Call =>
18625 return False;
18626
18627 -- Positional parameter for procedure or accept call
18628
18629 when N_Accept_Statement
18630 | N_Procedure_Call_Statement
18631 =>
18632 declare
18633 Proc : Entity_Id;
18634 Form : Entity_Id;
18635 Act : Node_Id;
18636
18637 begin
18638 Proc := Get_Subprogram_Entity (P);
18639
18640 if No (Proc) then
18641 return False;
18642 end if;
18643
18644 -- If we are not a list member, something is strange, so
18645 -- be conservative and return False.
18646
18647 if not Is_List_Member (N) then
18648 return False;
18649 end if;
18650
18651 -- We are going to find the right formal by stepping forward
18652 -- through the formals, as we step backwards in the actuals.
18653
18654 Form := First_Formal (Proc);
18655 Act := N;
18656 loop
18657 -- If no formal, something is weird, so be conservative
18658 -- and return False.
18659
18660 if No (Form) then
18661 return False;
18662 end if;
18663
18664 Prev (Act);
18665 exit when No (Act);
18666 Next_Formal (Form);
18667 end loop;
18668
18669 return Ekind (Form) /= E_In_Parameter;
18670 end;
18671
18672 -- Named parameter for procedure or accept call
18673
18674 when N_Parameter_Association =>
18675 declare
18676 Proc : Entity_Id;
18677 Form : Entity_Id;
18678
18679 begin
18680 Proc := Get_Subprogram_Entity (Parent (P));
18681
18682 if No (Proc) then
18683 return False;
18684 end if;
18685
18686 -- Loop through formals to find the one that matches
18687
18688 Form := First_Formal (Proc);
18689 loop
18690 -- If no matching formal, that's peculiar, some kind of
18691 -- previous error, so return False to be conservative.
18692 -- Actually this also happens in legal code in the case
18693 -- where P is a parameter association for an Extra_Formal???
18694
18695 if No (Form) then
18696 return False;
18697 end if;
18698
18699 -- Else test for match
18700
18701 if Chars (Form) = Chars (Selector_Name (P)) then
18702 return Ekind (Form) /= E_In_Parameter;
18703 end if;
18704
18705 Next_Formal (Form);
18706 end loop;
18707 end;
18708
18709 -- Test for appearing in a conversion that itself appears
18710 -- in an lvalue context, since this should be an lvalue.
18711
18712 when N_Type_Conversion =>
18713 return Known_To_Be_Assigned (P);
18714
18715 -- All other references are definitely not known to be modifications
18716
18717 when others =>
18718 return False;
18719 end case;
18720 end Known_To_Be_Assigned;
18721
18722 ---------------------------
18723 -- Last_Source_Statement --
18724 ---------------------------
18725
18726 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
18727 N : Node_Id;
18728
18729 begin
18730 N := Last (Statements (HSS));
18731 while Present (N) loop
18732 exit when Comes_From_Source (N);
18733 Prev (N);
18734 end loop;
18735
18736 return N;
18737 end Last_Source_Statement;
18738
18739 -----------------------
18740 -- Mark_Coextensions --
18741 -----------------------
18742
18743 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
18744 Is_Dynamic : Boolean;
18745 -- Indicates whether the context causes nested coextensions to be
18746 -- dynamic or static
18747
18748 function Mark_Allocator (N : Node_Id) return Traverse_Result;
18749 -- Recognize an allocator node and label it as a dynamic coextension
18750
18751 --------------------
18752 -- Mark_Allocator --
18753 --------------------
18754
18755 function Mark_Allocator (N : Node_Id) return Traverse_Result is
18756 begin
18757 if Nkind (N) = N_Allocator then
18758 if Is_Dynamic then
18759 Set_Is_Static_Coextension (N, False);
18760 Set_Is_Dynamic_Coextension (N);
18761
18762 -- If the allocator expression is potentially dynamic, it may
18763 -- be expanded out of order and require dynamic allocation
18764 -- anyway, so we treat the coextension itself as dynamic.
18765 -- Potential optimization ???
18766
18767 elsif Nkind (Expression (N)) = N_Qualified_Expression
18768 and then Nkind (Expression (Expression (N))) = N_Op_Concat
18769 then
18770 Set_Is_Static_Coextension (N, False);
18771 Set_Is_Dynamic_Coextension (N);
18772 else
18773 Set_Is_Dynamic_Coextension (N, False);
18774 Set_Is_Static_Coextension (N);
18775 end if;
18776 end if;
18777
18778 return OK;
18779 end Mark_Allocator;
18780
18781 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
18782
18783 -- Start of processing for Mark_Coextensions
18784
18785 begin
18786 -- An allocator that appears on the right-hand side of an assignment is
18787 -- treated as a potentially dynamic coextension when the right-hand side
18788 -- is an allocator or a qualified expression.
18789
18790 -- Obj := new ...'(new Coextension ...);
18791
18792 if Nkind (Context_Nod) = N_Assignment_Statement then
18793 Is_Dynamic :=
18794 Nkind_In (Expression (Context_Nod), N_Allocator,
18795 N_Qualified_Expression);
18796
18797 -- An allocator that appears within the expression of a simple return
18798 -- statement is treated as a potentially dynamic coextension when the
18799 -- expression is either aggregate, allocator, or qualified expression.
18800
18801 -- return (new Coextension ...);
18802 -- return new ...'(new Coextension ...);
18803
18804 elsif Nkind (Context_Nod) = N_Simple_Return_Statement then
18805 Is_Dynamic :=
18806 Nkind_In (Expression (Context_Nod), N_Aggregate,
18807 N_Allocator,
18808 N_Qualified_Expression);
18809
18810 -- An alloctor that appears within the initialization expression of an
18811 -- object declaration is considered a potentially dynamic coextension
18812 -- when the initialization expression is an allocator or a qualified
18813 -- expression.
18814
18815 -- Obj : ... := new ...'(new Coextension ...);
18816
18817 -- A similar case arises when the object declaration is part of an
18818 -- extended return statement.
18819
18820 -- return Obj : ... := new ...'(new Coextension ...);
18821 -- return Obj : ... := (new Coextension ...);
18822
18823 elsif Nkind (Context_Nod) = N_Object_Declaration then
18824 Is_Dynamic :=
18825 Nkind_In (Root_Nod, N_Allocator, N_Qualified_Expression)
18826 or else
18827 Nkind (Parent (Context_Nod)) = N_Extended_Return_Statement;
18828
18829 -- This routine should not be called with constructs that cannot contain
18830 -- coextensions.
18831
18832 else
18833 raise Program_Error;
18834 end if;
18835
18836 Mark_Allocators (Root_Nod);
18837 end Mark_Coextensions;
18838
18839 ---------------------------------
18840 -- Mark_Elaboration_Attributes --
18841 ---------------------------------
18842
18843 procedure Mark_Elaboration_Attributes
18844 (N_Id : Node_Or_Entity_Id;
18845 Checks : Boolean := False;
18846 Level : Boolean := False;
18847 Modes : Boolean := False;
18848 Warnings : Boolean := False)
18849 is
18850 function Elaboration_Checks_OK
18851 (Target_Id : Entity_Id;
18852 Context_Id : Entity_Id) return Boolean;
18853 -- Determine whether elaboration checks are enabled for target Target_Id
18854 -- which resides within context Context_Id.
18855
18856 procedure Mark_Elaboration_Attributes_Id (Id : Entity_Id);
18857 -- Preserve relevant attributes of the context in arbitrary entity Id
18858
18859 procedure Mark_Elaboration_Attributes_Node (N : Node_Id);
18860 -- Preserve relevant attributes of the context in arbitrary node N
18861
18862 ---------------------------
18863 -- Elaboration_Checks_OK --
18864 ---------------------------
18865
18866 function Elaboration_Checks_OK
18867 (Target_Id : Entity_Id;
18868 Context_Id : Entity_Id) return Boolean
18869 is
18870 Encl_Scop : Entity_Id;
18871
18872 begin
18873 -- Elaboration checks are suppressed for the target
18874
18875 if Elaboration_Checks_Suppressed (Target_Id) then
18876 return False;
18877 end if;
18878
18879 -- Otherwise elaboration checks are OK for the target, but may be
18880 -- suppressed for the context where the target is declared.
18881
18882 Encl_Scop := Context_Id;
18883 while Present (Encl_Scop) and then Encl_Scop /= Standard_Standard loop
18884 if Elaboration_Checks_Suppressed (Encl_Scop) then
18885 return False;
18886 end if;
18887
18888 Encl_Scop := Scope (Encl_Scop);
18889 end loop;
18890
18891 -- Neither the target nor its declarative context have elaboration
18892 -- checks suppressed.
18893
18894 return True;
18895 end Elaboration_Checks_OK;
18896
18897 ------------------------------------
18898 -- Mark_Elaboration_Attributes_Id --
18899 ------------------------------------
18900
18901 procedure Mark_Elaboration_Attributes_Id (Id : Entity_Id) is
18902 begin
18903 -- Mark the status of elaboration checks in effect. Do not reset the
18904 -- status in case the entity is reanalyzed with checks suppressed.
18905
18906 if Checks and then not Is_Elaboration_Checks_OK_Id (Id) then
18907 Set_Is_Elaboration_Checks_OK_Id (Id,
18908 Elaboration_Checks_OK
18909 (Target_Id => Id,
18910 Context_Id => Scope (Id)));
18911 end if;
18912
18913 -- Mark the status of elaboration warnings in effect. Do not reset
18914 -- the status in case the entity is reanalyzed with warnings off.
18915
18916 if Warnings and then not Is_Elaboration_Warnings_OK_Id (Id) then
18917 Set_Is_Elaboration_Warnings_OK_Id (Id, Elab_Warnings);
18918 end if;
18919 end Mark_Elaboration_Attributes_Id;
18920
18921 --------------------------------------
18922 -- Mark_Elaboration_Attributes_Node --
18923 --------------------------------------
18924
18925 procedure Mark_Elaboration_Attributes_Node (N : Node_Id) is
18926 function Extract_Name (N : Node_Id) return Node_Id;
18927 -- Obtain the Name attribute of call or instantiation N
18928
18929 ------------------
18930 -- Extract_Name --
18931 ------------------
18932
18933 function Extract_Name (N : Node_Id) return Node_Id is
18934 Nam : Node_Id;
18935
18936 begin
18937 Nam := Name (N);
18938
18939 -- A call to an entry family appears in indexed form
18940
18941 if Nkind (Nam) = N_Indexed_Component then
18942 Nam := Prefix (Nam);
18943 end if;
18944
18945 -- The name may also appear in qualified form
18946
18947 if Nkind (Nam) = N_Selected_Component then
18948 Nam := Selector_Name (Nam);
18949 end if;
18950
18951 return Nam;
18952 end Extract_Name;
18953
18954 -- Local variables
18955
18956 Context_Id : Entity_Id;
18957 Nam : Node_Id;
18958
18959 -- Start of processing for Mark_Elaboration_Attributes_Node
18960
18961 begin
18962 -- Mark the status of elaboration checks in effect. Do not reset the
18963 -- status in case the node is reanalyzed with checks suppressed.
18964
18965 if Checks and then not Is_Elaboration_Checks_OK_Node (N) then
18966
18967 -- Assignments, attribute references, and variable references do
18968 -- not have a "declarative" context.
18969
18970 Context_Id := Empty;
18971
18972 -- The status of elaboration checks for calls and instantiations
18973 -- depends on the most recent pragma Suppress/Unsuppress, as well
18974 -- as the suppression status of the context where the target is
18975 -- defined.
18976
18977 -- package Pack is
18978 -- function Func ...;
18979 -- end Pack;
18980
18981 -- with Pack;
18982 -- procedure Main is
18983 -- pragma Suppress (Elaboration_Checks, Pack);
18984 -- X : ... := Pack.Func;
18985 -- ...
18986
18987 -- In the example above, the call to Func has elaboration checks
18988 -- enabled because there is no active general purpose suppression
18989 -- pragma, however the elaboration checks of Pack are explicitly
18990 -- suppressed. As a result the elaboration checks of the call must
18991 -- be disabled in order to preserve this dependency.
18992
18993 if Nkind_In (N, N_Entry_Call_Statement,
18994 N_Function_Call,
18995 N_Function_Instantiation,
18996 N_Package_Instantiation,
18997 N_Procedure_Call_Statement,
18998 N_Procedure_Instantiation)
18999 then
19000 Nam := Extract_Name (N);
19001
19002 if Is_Entity_Name (Nam) and then Present (Entity (Nam)) then
19003 Context_Id := Scope (Entity (Nam));
19004 end if;
19005 end if;
19006
19007 Set_Is_Elaboration_Checks_OK_Node (N,
19008 Elaboration_Checks_OK
19009 (Target_Id => Empty,
19010 Context_Id => Context_Id));
19011 end if;
19012
19013 -- Mark the enclosing level of the node. Do not reset the status in
19014 -- case the node is relocated and reanalyzed.
19015
19016 if Level and then not Is_Declaration_Level_Node (N) then
19017 Set_Is_Declaration_Level_Node (N,
19018 Find_Enclosing_Level (N) = Declaration_Level);
19019 end if;
19020
19021 -- Mark the Ghost and SPARK mode in effect
19022
19023 if Modes then
19024 if Ghost_Mode = Ignore then
19025 Set_Is_Ignored_Ghost_Node (N);
19026 end if;
19027
19028 if SPARK_Mode = On then
19029 Set_Is_SPARK_Mode_On_Node (N);
19030 end if;
19031 end if;
19032
19033 -- Mark the status of elaboration warnings in effect. Do not reset
19034 -- the status in case the node is reanalyzed with warnings off.
19035
19036 if Warnings and then not Is_Elaboration_Warnings_OK_Node (N) then
19037 Set_Is_Elaboration_Warnings_OK_Node (N, Elab_Warnings);
19038 end if;
19039 end Mark_Elaboration_Attributes_Node;
19040
19041 -- Start of processing for Mark_Elaboration_Attributes
19042
19043 begin
19044 -- Do not capture any elaboration-related attributes when switch -gnatH
19045 -- (legacy elaboration checking mode enabled) is in effect because the
19046 -- attributes are useless to the legacy model.
19047
19048 if Legacy_Elaboration_Checks then
19049 return;
19050 end if;
19051
19052 if Nkind (N_Id) in N_Entity then
19053 Mark_Elaboration_Attributes_Id (N_Id);
19054 else
19055 Mark_Elaboration_Attributes_Node (N_Id);
19056 end if;
19057 end Mark_Elaboration_Attributes;
19058
19059 ----------------------------------------
19060 -- Mark_Save_Invocation_Graph_Of_Body --
19061 ----------------------------------------
19062
19063 procedure Mark_Save_Invocation_Graph_Of_Body is
19064 Main : constant Node_Id := Cunit (Main_Unit);
19065 Main_Unit : constant Node_Id := Unit (Main);
19066 Aux_Id : Entity_Id;
19067
19068 begin
19069 Set_Save_Invocation_Graph_Of_Body (Main);
19070
19071 -- Assume that the main unit does not have a complimentary unit
19072
19073 Aux_Id := Empty;
19074
19075 -- Obtain the complimentary unit of the main unit
19076
19077 if Nkind_In (Main_Unit, N_Generic_Package_Declaration,
19078 N_Generic_Subprogram_Declaration,
19079 N_Package_Declaration,
19080 N_Subprogram_Declaration)
19081 then
19082 Aux_Id := Corresponding_Body (Main_Unit);
19083
19084 elsif Nkind_In (Main_Unit, N_Package_Body,
19085 N_Subprogram_Body,
19086 N_Subprogram_Renaming_Declaration)
19087 then
19088 Aux_Id := Corresponding_Spec (Main_Unit);
19089 end if;
19090
19091 if Present (Aux_Id) then
19092 Set_Save_Invocation_Graph_Of_Body
19093 (Parent (Unit_Declaration_Node (Aux_Id)));
19094 end if;
19095 end Mark_Save_Invocation_Graph_Of_Body;
19096
19097 ----------------------------------
19098 -- Matching_Static_Array_Bounds --
19099 ----------------------------------
19100
19101 function Matching_Static_Array_Bounds
19102 (L_Typ : Node_Id;
19103 R_Typ : Node_Id) return Boolean
19104 is
19105 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
19106 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
19107
19108 L_Index : Node_Id := Empty; -- init to ...
19109 R_Index : Node_Id := Empty; -- ...avoid warnings
19110 L_Low : Node_Id;
19111 L_High : Node_Id;
19112 L_Len : Uint;
19113 R_Low : Node_Id;
19114 R_High : Node_Id;
19115 R_Len : Uint;
19116
19117 begin
19118 if L_Ndims /= R_Ndims then
19119 return False;
19120 end if;
19121
19122 -- Unconstrained types do not have static bounds
19123
19124 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
19125 return False;
19126 end if;
19127
19128 -- First treat specially the first dimension, as the lower bound and
19129 -- length of string literals are not stored like those of arrays.
19130
19131 if Ekind (L_Typ) = E_String_Literal_Subtype then
19132 L_Low := String_Literal_Low_Bound (L_Typ);
19133 L_Len := String_Literal_Length (L_Typ);
19134 else
19135 L_Index := First_Index (L_Typ);
19136 Get_Index_Bounds (L_Index, L_Low, L_High);
19137
19138 if Is_OK_Static_Expression (L_Low)
19139 and then
19140 Is_OK_Static_Expression (L_High)
19141 then
19142 if Expr_Value (L_High) < Expr_Value (L_Low) then
19143 L_Len := Uint_0;
19144 else
19145 L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
19146 end if;
19147 else
19148 return False;
19149 end if;
19150 end if;
19151
19152 if Ekind (R_Typ) = E_String_Literal_Subtype then
19153 R_Low := String_Literal_Low_Bound (R_Typ);
19154 R_Len := String_Literal_Length (R_Typ);
19155 else
19156 R_Index := First_Index (R_Typ);
19157 Get_Index_Bounds (R_Index, R_Low, R_High);
19158
19159 if Is_OK_Static_Expression (R_Low)
19160 and then
19161 Is_OK_Static_Expression (R_High)
19162 then
19163 if Expr_Value (R_High) < Expr_Value (R_Low) then
19164 R_Len := Uint_0;
19165 else
19166 R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
19167 end if;
19168 else
19169 return False;
19170 end if;
19171 end if;
19172
19173 if (Is_OK_Static_Expression (L_Low)
19174 and then
19175 Is_OK_Static_Expression (R_Low))
19176 and then Expr_Value (L_Low) = Expr_Value (R_Low)
19177 and then L_Len = R_Len
19178 then
19179 null;
19180 else
19181 return False;
19182 end if;
19183
19184 -- Then treat all other dimensions
19185
19186 for Indx in 2 .. L_Ndims loop
19187 Next (L_Index);
19188 Next (R_Index);
19189
19190 Get_Index_Bounds (L_Index, L_Low, L_High);
19191 Get_Index_Bounds (R_Index, R_Low, R_High);
19192
19193 if (Is_OK_Static_Expression (L_Low) and then
19194 Is_OK_Static_Expression (L_High) and then
19195 Is_OK_Static_Expression (R_Low) and then
19196 Is_OK_Static_Expression (R_High))
19197 and then (Expr_Value (L_Low) = Expr_Value (R_Low)
19198 and then
19199 Expr_Value (L_High) = Expr_Value (R_High))
19200 then
19201 null;
19202 else
19203 return False;
19204 end if;
19205 end loop;
19206
19207 -- If we fall through the loop, all indexes matched
19208
19209 return True;
19210 end Matching_Static_Array_Bounds;
19211
19212 -------------------
19213 -- May_Be_Lvalue --
19214 -------------------
19215
19216 function May_Be_Lvalue (N : Node_Id) return Boolean is
19217 P : constant Node_Id := Parent (N);
19218
19219 begin
19220 case Nkind (P) is
19221
19222 -- Test left side of assignment
19223
19224 when N_Assignment_Statement =>
19225 return N = Name (P);
19226
19227 -- Test prefix of component or attribute. Note that the prefix of an
19228 -- explicit or implicit dereference cannot be an l-value. In the case
19229 -- of a 'Read attribute, the reference can be an actual in the
19230 -- argument list of the attribute.
19231
19232 when N_Attribute_Reference =>
19233 return (N = Prefix (P)
19234 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P)))
19235 or else
19236 Attribute_Name (P) = Name_Read;
19237
19238 -- For an expanded name, the name is an lvalue if the expanded name
19239 -- is an lvalue, but the prefix is never an lvalue, since it is just
19240 -- the scope where the name is found.
19241
19242 when N_Expanded_Name =>
19243 if N = Prefix (P) then
19244 return May_Be_Lvalue (P);
19245 else
19246 return False;
19247 end if;
19248
19249 -- For a selected component A.B, A is certainly an lvalue if A.B is.
19250 -- B is a little interesting, if we have A.B := 3, there is some
19251 -- discussion as to whether B is an lvalue or not, we choose to say
19252 -- it is. Note however that A is not an lvalue if it is of an access
19253 -- type since this is an implicit dereference.
19254
19255 when N_Selected_Component =>
19256 if N = Prefix (P)
19257 and then Present (Etype (N))
19258 and then Is_Access_Type (Etype (N))
19259 then
19260 return False;
19261 else
19262 return May_Be_Lvalue (P);
19263 end if;
19264
19265 -- For an indexed component or slice, the index or slice bounds is
19266 -- never an lvalue. The prefix is an lvalue if the indexed component
19267 -- or slice is an lvalue, except if it is an access type, where we
19268 -- have an implicit dereference.
19269
19270 when N_Indexed_Component
19271 | N_Slice
19272 =>
19273 if N /= Prefix (P)
19274 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
19275 then
19276 return False;
19277 else
19278 return May_Be_Lvalue (P);
19279 end if;
19280
19281 -- Prefix of a reference is an lvalue if the reference is an lvalue
19282
19283 when N_Reference =>
19284 return May_Be_Lvalue (P);
19285
19286 -- Prefix of explicit dereference is never an lvalue
19287
19288 when N_Explicit_Dereference =>
19289 return False;
19290
19291 -- Positional parameter for subprogram, entry, or accept call.
19292 -- In older versions of Ada function call arguments are never
19293 -- lvalues. In Ada 2012 functions can have in-out parameters.
19294
19295 when N_Accept_Statement
19296 | N_Entry_Call_Statement
19297 | N_Subprogram_Call
19298 =>
19299 if Nkind (P) = N_Function_Call and then Ada_Version < Ada_2012 then
19300 return False;
19301 end if;
19302
19303 -- The following mechanism is clumsy and fragile. A single flag
19304 -- set in Resolve_Actuals would be preferable ???
19305
19306 declare
19307 Proc : Entity_Id;
19308 Form : Entity_Id;
19309 Act : Node_Id;
19310
19311 begin
19312 Proc := Get_Subprogram_Entity (P);
19313
19314 if No (Proc) then
19315 return True;
19316 end if;
19317
19318 -- If we are not a list member, something is strange, so be
19319 -- conservative and return True.
19320
19321 if not Is_List_Member (N) then
19322 return True;
19323 end if;
19324
19325 -- We are going to find the right formal by stepping forward
19326 -- through the formals, as we step backwards in the actuals.
19327
19328 Form := First_Formal (Proc);
19329 Act := N;
19330 loop
19331 -- If no formal, something is weird, so be conservative and
19332 -- return True.
19333
19334 if No (Form) then
19335 return True;
19336 end if;
19337
19338 Prev (Act);
19339 exit when No (Act);
19340 Next_Formal (Form);
19341 end loop;
19342
19343 return Ekind (Form) /= E_In_Parameter;
19344 end;
19345
19346 -- Named parameter for procedure or accept call
19347
19348 when N_Parameter_Association =>
19349 declare
19350 Proc : Entity_Id;
19351 Form : Entity_Id;
19352
19353 begin
19354 Proc := Get_Subprogram_Entity (Parent (P));
19355
19356 if No (Proc) then
19357 return True;
19358 end if;
19359
19360 -- Loop through formals to find the one that matches
19361
19362 Form := First_Formal (Proc);
19363 loop
19364 -- If no matching formal, that's peculiar, some kind of
19365 -- previous error, so return True to be conservative.
19366 -- Actually happens with legal code for an unresolved call
19367 -- where we may get the wrong homonym???
19368
19369 if No (Form) then
19370 return True;
19371 end if;
19372
19373 -- Else test for match
19374
19375 if Chars (Form) = Chars (Selector_Name (P)) then
19376 return Ekind (Form) /= E_In_Parameter;
19377 end if;
19378
19379 Next_Formal (Form);
19380 end loop;
19381 end;
19382
19383 -- Test for appearing in a conversion that itself appears in an
19384 -- lvalue context, since this should be an lvalue.
19385
19386 when N_Type_Conversion =>
19387 return May_Be_Lvalue (P);
19388
19389 -- Test for appearance in object renaming declaration
19390
19391 when N_Object_Renaming_Declaration =>
19392 return True;
19393
19394 -- All other references are definitely not lvalues
19395
19396 when others =>
19397 return False;
19398 end case;
19399 end May_Be_Lvalue;
19400
19401 -----------------
19402 -- Might_Raise --
19403 -----------------
19404
19405 function Might_Raise (N : Node_Id) return Boolean is
19406 Result : Boolean := False;
19407
19408 function Process (N : Node_Id) return Traverse_Result;
19409 -- Set Result to True if we find something that could raise an exception
19410
19411 -------------
19412 -- Process --
19413 -------------
19414
19415 function Process (N : Node_Id) return Traverse_Result is
19416 begin
19417 if Nkind_In (N, N_Procedure_Call_Statement,
19418 N_Function_Call,
19419 N_Raise_Statement,
19420 N_Raise_Constraint_Error,
19421 N_Raise_Program_Error,
19422 N_Raise_Storage_Error)
19423 then
19424 Result := True;
19425 return Abandon;
19426 else
19427 return OK;
19428 end if;
19429 end Process;
19430
19431 procedure Set_Result is new Traverse_Proc (Process);
19432
19433 -- Start of processing for Might_Raise
19434
19435 begin
19436 -- False if exceptions can't be propagated
19437
19438 if No_Exception_Handlers_Set then
19439 return False;
19440 end if;
19441
19442 -- If the checks handled by the back end are not disabled, we cannot
19443 -- ensure that no exception will be raised.
19444
19445 if not Access_Checks_Suppressed (Empty)
19446 or else not Discriminant_Checks_Suppressed (Empty)
19447 or else not Range_Checks_Suppressed (Empty)
19448 or else not Index_Checks_Suppressed (Empty)
19449 or else Opt.Stack_Checking_Enabled
19450 then
19451 return True;
19452 end if;
19453
19454 Set_Result (N);
19455 return Result;
19456 end Might_Raise;
19457
19458 --------------------------------
19459 -- Nearest_Enclosing_Instance --
19460 --------------------------------
19461
19462 function Nearest_Enclosing_Instance (E : Entity_Id) return Entity_Id is
19463 Inst : Entity_Id;
19464
19465 begin
19466 Inst := Scope (E);
19467 while Present (Inst) and then Inst /= Standard_Standard loop
19468 if Is_Generic_Instance (Inst) then
19469 return Inst;
19470 end if;
19471
19472 Inst := Scope (Inst);
19473 end loop;
19474
19475 return Empty;
19476 end Nearest_Enclosing_Instance;
19477
19478 ------------------------
19479 -- Needs_Finalization --
19480 ------------------------
19481
19482 function Needs_Finalization (Typ : Entity_Id) return Boolean is
19483 function Has_Some_Controlled_Component
19484 (Input_Typ : Entity_Id) return Boolean;
19485 -- Determine whether type Input_Typ has at least one controlled
19486 -- component.
19487
19488 -----------------------------------
19489 -- Has_Some_Controlled_Component --
19490 -----------------------------------
19491
19492 function Has_Some_Controlled_Component
19493 (Input_Typ : Entity_Id) return Boolean
19494 is
19495 Comp : Entity_Id;
19496
19497 begin
19498 -- When a type is already frozen and has at least one controlled
19499 -- component, or is manually decorated, it is sufficient to inspect
19500 -- flag Has_Controlled_Component.
19501
19502 if Has_Controlled_Component (Input_Typ) then
19503 return True;
19504
19505 -- Otherwise inspect the internals of the type
19506
19507 elsif not Is_Frozen (Input_Typ) then
19508 if Is_Array_Type (Input_Typ) then
19509 return Needs_Finalization (Component_Type (Input_Typ));
19510
19511 elsif Is_Record_Type (Input_Typ) then
19512 Comp := First_Component (Input_Typ);
19513 while Present (Comp) loop
19514 if Needs_Finalization (Etype (Comp)) then
19515 return True;
19516 end if;
19517
19518 Next_Component (Comp);
19519 end loop;
19520 end if;
19521 end if;
19522
19523 return False;
19524 end Has_Some_Controlled_Component;
19525
19526 -- Start of processing for Needs_Finalization
19527
19528 begin
19529 -- Certain run-time configurations and targets do not provide support
19530 -- for controlled types.
19531
19532 if Restriction_Active (No_Finalization) then
19533 return False;
19534
19535 -- C++ types are not considered controlled. It is assumed that the non-
19536 -- Ada side will handle their clean up.
19537
19538 elsif Convention (Typ) = Convention_CPP then
19539 return False;
19540
19541 -- Class-wide types are treated as controlled because derivations from
19542 -- the root type may introduce controlled components.
19543
19544 elsif Is_Class_Wide_Type (Typ) then
19545 return True;
19546
19547 -- Concurrent types are controlled as long as their corresponding record
19548 -- is controlled.
19549
19550 elsif Is_Concurrent_Type (Typ)
19551 and then Present (Corresponding_Record_Type (Typ))
19552 and then Needs_Finalization (Corresponding_Record_Type (Typ))
19553 then
19554 return True;
19555
19556 -- Otherwise the type is controlled when it is either derived from type
19557 -- [Limited_]Controlled and not subject to aspect Disable_Controlled, or
19558 -- contains at least one controlled component.
19559
19560 else
19561 return
19562 Is_Controlled (Typ) or else Has_Some_Controlled_Component (Typ);
19563 end if;
19564 end Needs_Finalization;
19565
19566 ----------------------
19567 -- Needs_One_Actual --
19568 ----------------------
19569
19570 function Needs_One_Actual (E : Entity_Id) return Boolean is
19571 Formal : Entity_Id;
19572
19573 begin
19574 -- Ada 2005 or later, and formals present. The first formal must be
19575 -- of a type that supports prefix notation: a controlling argument,
19576 -- a class-wide type, or an access to such.
19577
19578 if Ada_Version >= Ada_2005
19579 and then Present (First_Formal (E))
19580 and then No (Default_Value (First_Formal (E)))
19581 and then
19582 (Is_Controlling_Formal (First_Formal (E))
19583 or else Is_Class_Wide_Type (Etype (First_Formal (E)))
19584 or else Is_Anonymous_Access_Type (Etype (First_Formal (E))))
19585 then
19586 Formal := Next_Formal (First_Formal (E));
19587 while Present (Formal) loop
19588 if No (Default_Value (Formal)) then
19589 return False;
19590 end if;
19591
19592 Next_Formal (Formal);
19593 end loop;
19594
19595 return True;
19596
19597 -- Ada 83/95 or no formals
19598
19599 else
19600 return False;
19601 end if;
19602 end Needs_One_Actual;
19603
19604 ---------------------------------
19605 -- Needs_Simple_Initialization --
19606 ---------------------------------
19607
19608 function Needs_Simple_Initialization
19609 (Typ : Entity_Id;
19610 Consider_IS : Boolean := True) return Boolean
19611 is
19612 Consider_IS_NS : constant Boolean :=
19613 Normalize_Scalars or (Initialize_Scalars and Consider_IS);
19614
19615 begin
19616 -- Never need initialization if it is suppressed
19617
19618 if Initialization_Suppressed (Typ) then
19619 return False;
19620 end if;
19621
19622 -- Check for private type, in which case test applies to the underlying
19623 -- type of the private type.
19624
19625 if Is_Private_Type (Typ) then
19626 declare
19627 RT : constant Entity_Id := Underlying_Type (Typ);
19628 begin
19629 if Present (RT) then
19630 return Needs_Simple_Initialization (RT);
19631 else
19632 return False;
19633 end if;
19634 end;
19635
19636 -- Scalar type with Default_Value aspect requires initialization
19637
19638 elsif Is_Scalar_Type (Typ) and then Has_Default_Aspect (Typ) then
19639 return True;
19640
19641 -- Cases needing simple initialization are access types, and, if pragma
19642 -- Normalize_Scalars or Initialize_Scalars is in effect, then all scalar
19643 -- types.
19644
19645 elsif Is_Access_Type (Typ)
19646 or else (Consider_IS_NS and then (Is_Scalar_Type (Typ)))
19647 then
19648 return True;
19649
19650 -- If Initialize/Normalize_Scalars is in effect, string objects also
19651 -- need initialization, unless they are created in the course of
19652 -- expanding an aggregate (since in the latter case they will be
19653 -- filled with appropriate initializing values before they are used).
19654
19655 elsif Consider_IS_NS
19656 and then Is_Standard_String_Type (Typ)
19657 and then
19658 (not Is_Itype (Typ)
19659 or else Nkind (Associated_Node_For_Itype (Typ)) /= N_Aggregate)
19660 then
19661 return True;
19662
19663 else
19664 return False;
19665 end if;
19666 end Needs_Simple_Initialization;
19667
19668 -------------------------------------
19669 -- Needs_Variable_Reference_Marker --
19670 -------------------------------------
19671
19672 function Needs_Variable_Reference_Marker
19673 (N : Node_Id;
19674 Calls_OK : Boolean) return Boolean
19675 is
19676 function Within_Suitable_Context (Ref : Node_Id) return Boolean;
19677 -- Deteremine whether variable reference Ref appears within a suitable
19678 -- context that allows the creation of a marker.
19679
19680 -----------------------------
19681 -- Within_Suitable_Context --
19682 -----------------------------
19683
19684 function Within_Suitable_Context (Ref : Node_Id) return Boolean is
19685 Par : Node_Id;
19686
19687 begin
19688 Par := Ref;
19689 while Present (Par) loop
19690
19691 -- The context is not suitable when the reference appears within
19692 -- the formal part of an instantiation which acts as compilation
19693 -- unit because there is no proper list for the insertion of the
19694 -- marker.
19695
19696 if Nkind (Par) = N_Generic_Association
19697 and then Nkind (Parent (Par)) in N_Generic_Instantiation
19698 and then Nkind (Parent (Parent (Par))) = N_Compilation_Unit
19699 then
19700 return False;
19701
19702 -- The context is not suitable when the reference appears within
19703 -- a pragma. If the pragma has run-time semantics, the reference
19704 -- will be reconsidered once the pragma is expanded.
19705
19706 elsif Nkind (Par) = N_Pragma then
19707 return False;
19708
19709 -- The context is not suitable when the reference appears within a
19710 -- subprogram call, and the caller requests this behavior.
19711
19712 elsif not Calls_OK
19713 and then Nkind_In (Par, N_Entry_Call_Statement,
19714 N_Function_Call,
19715 N_Procedure_Call_Statement)
19716 then
19717 return False;
19718
19719 -- Prevent the search from going too far
19720
19721 elsif Is_Body_Or_Package_Declaration (Par) then
19722 exit;
19723 end if;
19724
19725 Par := Parent (Par);
19726 end loop;
19727
19728 return True;
19729 end Within_Suitable_Context;
19730
19731 -- Local variables
19732
19733 Prag : Node_Id;
19734 Var_Id : Entity_Id;
19735
19736 -- Start of processing for Needs_Variable_Reference_Marker
19737
19738 begin
19739 -- No marker needs to be created when switch -gnatH (legacy elaboration
19740 -- checking mode enabled) is in effect because the legacy ABE mechanism
19741 -- does not use markers.
19742
19743 if Legacy_Elaboration_Checks then
19744 return False;
19745
19746 -- No marker needs to be created for ASIS because ABE diagnostics and
19747 -- checks are not performed in this mode.
19748
19749 elsif ASIS_Mode then
19750 return False;
19751
19752 -- No marker needs to be created when the reference is preanalyzed
19753 -- because the marker will be inserted in the wrong place.
19754
19755 elsif Preanalysis_Active then
19756 return False;
19757
19758 -- Only references warrant a marker
19759
19760 elsif not Nkind_In (N, N_Expanded_Name, N_Identifier) then
19761 return False;
19762
19763 -- Only source references warrant a marker
19764
19765 elsif not Comes_From_Source (N) then
19766 return False;
19767
19768 -- No marker needs to be created when the reference is erroneous, left
19769 -- in a bad state, or does not denote a variable.
19770
19771 elsif not (Present (Entity (N))
19772 and then Ekind (Entity (N)) = E_Variable
19773 and then Entity (N) /= Any_Id)
19774 then
19775 return False;
19776 end if;
19777
19778 Var_Id := Entity (N);
19779 Prag := SPARK_Pragma (Var_Id);
19780
19781 -- Both the variable and reference must appear in SPARK_Mode On regions
19782 -- because this elaboration scenario falls under the SPARK rules.
19783
19784 if not (Comes_From_Source (Var_Id)
19785 and then Present (Prag)
19786 and then Get_SPARK_Mode_From_Annotation (Prag) = On
19787 and then Is_SPARK_Mode_On_Node (N))
19788 then
19789 return False;
19790
19791 -- No marker needs to be created when the reference does not appear
19792 -- within a suitable context (see body for details).
19793
19794 -- Performance note: parent traversal
19795
19796 elsif not Within_Suitable_Context (N) then
19797 return False;
19798 end if;
19799
19800 -- At this point it is known that the variable reference will play a
19801 -- role in ABE diagnostics and requires a marker.
19802
19803 return True;
19804 end Needs_Variable_Reference_Marker;
19805
19806 ------------------------
19807 -- New_Copy_List_Tree --
19808 ------------------------
19809
19810 function New_Copy_List_Tree (List : List_Id) return List_Id is
19811 NL : List_Id;
19812 E : Node_Id;
19813
19814 begin
19815 if List = No_List then
19816 return No_List;
19817
19818 else
19819 NL := New_List;
19820 E := First (List);
19821
19822 while Present (E) loop
19823 Append (New_Copy_Tree (E), NL);
19824 E := Next (E);
19825 end loop;
19826
19827 return NL;
19828 end if;
19829 end New_Copy_List_Tree;
19830
19831 -------------------
19832 -- New_Copy_Tree --
19833 -------------------
19834
19835 -- The following tables play a key role in replicating entities and Itypes.
19836 -- They are intentionally declared at the library level rather than within
19837 -- New_Copy_Tree to avoid elaborating them on each call. This performance
19838 -- optimization saves up to 2% of the entire compilation time spent in the
19839 -- front end. Care should be taken to reset the tables on each new call to
19840 -- New_Copy_Tree.
19841
19842 NCT_Table_Max : constant := 511;
19843
19844 subtype NCT_Table_Index is Nat range 0 .. NCT_Table_Max - 1;
19845
19846 function NCT_Table_Hash (Key : Node_Or_Entity_Id) return NCT_Table_Index;
19847 -- Obtain the hash value of node or entity Key
19848
19849 --------------------
19850 -- NCT_Table_Hash --
19851 --------------------
19852
19853 function NCT_Table_Hash (Key : Node_Or_Entity_Id) return NCT_Table_Index is
19854 begin
19855 return NCT_Table_Index (Key mod NCT_Table_Max);
19856 end NCT_Table_Hash;
19857
19858 ----------------------
19859 -- NCT_New_Entities --
19860 ----------------------
19861
19862 -- The following table maps old entities and Itypes to their corresponding
19863 -- new entities and Itypes.
19864
19865 -- Aaa -> Xxx
19866
19867 package NCT_New_Entities is new Simple_HTable (
19868 Header_Num => NCT_Table_Index,
19869 Element => Entity_Id,
19870 No_Element => Empty,
19871 Key => Entity_Id,
19872 Hash => NCT_Table_Hash,
19873 Equal => "=");
19874
19875 ------------------------
19876 -- NCT_Pending_Itypes --
19877 ------------------------
19878
19879 -- The following table maps old Associated_Node_For_Itype nodes to a set of
19880 -- new itypes. Given a set of old Itypes Aaa, Bbb, and Ccc, where all three
19881 -- have the same Associated_Node_For_Itype Ppp, and their corresponding new
19882 -- Itypes Xxx, Yyy, Zzz, the table contains the following mapping:
19883
19884 -- Ppp -> (Xxx, Yyy, Zzz)
19885
19886 -- The set is expressed as an Elist
19887
19888 package NCT_Pending_Itypes is new Simple_HTable (
19889 Header_Num => NCT_Table_Index,
19890 Element => Elist_Id,
19891 No_Element => No_Elist,
19892 Key => Node_Id,
19893 Hash => NCT_Table_Hash,
19894 Equal => "=");
19895
19896 NCT_Tables_In_Use : Boolean := False;
19897 -- This flag keeps track of whether the two tables NCT_New_Entities and
19898 -- NCT_Pending_Itypes are in use. The flag is part of an optimization
19899 -- where certain operations are not performed if the tables are not in
19900 -- use. This saves up to 8% of the entire compilation time spent in the
19901 -- front end.
19902
19903 -------------------
19904 -- New_Copy_Tree --
19905 -------------------
19906
19907 function New_Copy_Tree
19908 (Source : Node_Id;
19909 Map : Elist_Id := No_Elist;
19910 New_Sloc : Source_Ptr := No_Location;
19911 New_Scope : Entity_Id := Empty;
19912 Scopes_In_EWA_OK : Boolean := False) return Node_Id
19913 is
19914 -- This routine performs low-level tree manipulations and needs access
19915 -- to the internals of the tree.
19916
19917 use Atree.Unchecked_Access;
19918 use Atree_Private_Part;
19919
19920 EWA_Level : Nat := 0;
19921 -- This counter keeps track of how many N_Expression_With_Actions nodes
19922 -- are encountered during a depth-first traversal of the subtree. These
19923 -- nodes may define new entities in their Actions lists and thus require
19924 -- special processing.
19925
19926 EWA_Inner_Scope_Level : Nat := 0;
19927 -- This counter keeps track of how many scoping constructs appear within
19928 -- an N_Expression_With_Actions node.
19929
19930 procedure Add_New_Entity (Old_Id : Entity_Id; New_Id : Entity_Id);
19931 pragma Inline (Add_New_Entity);
19932 -- Add an entry in the NCT_New_Entities table which maps key Old_Id to
19933 -- value New_Id. Old_Id is an entity which appears within the Actions
19934 -- list of an N_Expression_With_Actions node, or within an entity map.
19935 -- New_Id is the corresponding new entity generated during Phase 1.
19936
19937 procedure Add_Pending_Itype (Assoc_Nod : Node_Id; Itype : Entity_Id);
19938 pragma Inline (Add_New_Entity);
19939 -- Add an entry in the NCT_Pending_Itypes which maps key Assoc_Nod to
19940 -- value Itype. Assoc_Nod is the associated node of an itype. Itype is
19941 -- an itype.
19942
19943 procedure Build_NCT_Tables (Entity_Map : Elist_Id);
19944 pragma Inline (Build_NCT_Tables);
19945 -- Populate tables NCT_New_Entities and NCT_Pending_Itypes with the
19946 -- information supplied in entity map Entity_Map. The format of the
19947 -- entity map must be as follows:
19948 --
19949 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
19950
19951 function Copy_Any_Node_With_Replacement
19952 (N : Node_Or_Entity_Id) return Node_Or_Entity_Id;
19953 pragma Inline (Copy_Any_Node_With_Replacement);
19954 -- Replicate entity or node N by invoking one of the following routines:
19955 --
19956 -- Copy_Node_With_Replacement
19957 -- Corresponding_Entity
19958
19959 function Copy_Elist_With_Replacement (List : Elist_Id) return Elist_Id;
19960 -- Replicate the elements of entity list List
19961
19962 function Copy_Field_With_Replacement
19963 (Field : Union_Id;
19964 Old_Par : Node_Id := Empty;
19965 New_Par : Node_Id := Empty;
19966 Semantic : Boolean := False) return Union_Id;
19967 -- Replicate field Field by invoking one of the following routines:
19968 --
19969 -- Copy_Elist_With_Replacement
19970 -- Copy_List_With_Replacement
19971 -- Copy_Node_With_Replacement
19972 -- Corresponding_Entity
19973 --
19974 -- If the field is not an entity list, entity, itype, syntactic list,
19975 -- or node, then the field is returned unchanged. The routine always
19976 -- replicates entities, itypes, and valid syntactic fields. Old_Par is
19977 -- the expected parent of a syntactic field. New_Par is the new parent
19978 -- associated with a replicated syntactic field. Flag Semantic should
19979 -- be set when the input is a semantic field.
19980
19981 function Copy_List_With_Replacement (List : List_Id) return List_Id;
19982 -- Replicate the elements of syntactic list List
19983
19984 function Copy_Node_With_Replacement (N : Node_Id) return Node_Id;
19985 -- Replicate node N
19986
19987 function Corresponding_Entity (Id : Entity_Id) return Entity_Id;
19988 pragma Inline (Corresponding_Entity);
19989 -- Return the corresponding new entity of Id generated during Phase 1.
19990 -- If there is no such entity, return Id.
19991
19992 function In_Entity_Map
19993 (Id : Entity_Id;
19994 Entity_Map : Elist_Id) return Boolean;
19995 pragma Inline (In_Entity_Map);
19996 -- Determine whether entity Id is one of the old ids specified in entity
19997 -- map Entity_Map. The format of the entity map must be as follows:
19998 --
19999 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
20000
20001 procedure Update_CFS_Sloc (N : Node_Or_Entity_Id);
20002 pragma Inline (Update_CFS_Sloc);
20003 -- Update the Comes_From_Source and Sloc attributes of node or entity N
20004
20005 procedure Update_First_Real_Statement
20006 (Old_HSS : Node_Id;
20007 New_HSS : Node_Id);
20008 pragma Inline (Update_First_Real_Statement);
20009 -- Update semantic attribute First_Real_Statement of handled sequence of
20010 -- statements New_HSS based on handled sequence of statements Old_HSS.
20011
20012 procedure Update_Named_Associations
20013 (Old_Call : Node_Id;
20014 New_Call : Node_Id);
20015 pragma Inline (Update_Named_Associations);
20016 -- Update semantic chain First/Next_Named_Association of call New_call
20017 -- based on call Old_Call.
20018
20019 procedure Update_New_Entities (Entity_Map : Elist_Id);
20020 pragma Inline (Update_New_Entities);
20021 -- Update the semantic attributes of all new entities generated during
20022 -- Phase 1 that do not appear in entity map Entity_Map. The format of
20023 -- the entity map must be as follows:
20024 --
20025 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
20026
20027 procedure Update_Pending_Itypes
20028 (Old_Assoc : Node_Id;
20029 New_Assoc : Node_Id);
20030 pragma Inline (Update_Pending_Itypes);
20031 -- Update semantic attribute Associated_Node_For_Itype to refer to node
20032 -- New_Assoc for all itypes whose associated node is Old_Assoc.
20033
20034 procedure Update_Semantic_Fields (Id : Entity_Id);
20035 pragma Inline (Update_Semantic_Fields);
20036 -- Subsidiary to Update_New_Entities. Update semantic fields of entity
20037 -- or itype Id.
20038
20039 procedure Visit_Any_Node (N : Node_Or_Entity_Id);
20040 pragma Inline (Visit_Any_Node);
20041 -- Visit entity of node N by invoking one of the following routines:
20042 --
20043 -- Visit_Entity
20044 -- Visit_Itype
20045 -- Visit_Node
20046
20047 procedure Visit_Elist (List : Elist_Id);
20048 -- Visit the elements of entity list List
20049
20050 procedure Visit_Entity (Id : Entity_Id);
20051 -- Visit entity Id. This action may create a new entity of Id and save
20052 -- it in table NCT_New_Entities.
20053
20054 procedure Visit_Field
20055 (Field : Union_Id;
20056 Par_Nod : Node_Id := Empty;
20057 Semantic : Boolean := False);
20058 -- Visit field Field by invoking one of the following routines:
20059 --
20060 -- Visit_Elist
20061 -- Visit_Entity
20062 -- Visit_Itype
20063 -- Visit_List
20064 -- Visit_Node
20065 --
20066 -- If the field is not an entity list, entity, itype, syntactic list,
20067 -- or node, then the field is not visited. The routine always visits
20068 -- valid syntactic fields. Par_Nod is the expected parent of the
20069 -- syntactic field. Flag Semantic should be set when the input is a
20070 -- semantic field.
20071
20072 procedure Visit_Itype (Itype : Entity_Id);
20073 -- Visit itype Itype. This action may create a new entity for Itype and
20074 -- save it in table NCT_New_Entities. In addition, the routine may map
20075 -- the associated node of Itype to the new itype in NCT_Pending_Itypes.
20076
20077 procedure Visit_List (List : List_Id);
20078 -- Visit the elements of syntactic list List
20079
20080 procedure Visit_Node (N : Node_Id);
20081 -- Visit node N
20082
20083 procedure Visit_Semantic_Fields (Id : Entity_Id);
20084 pragma Inline (Visit_Semantic_Fields);
20085 -- Subsidiary to Visit_Entity and Visit_Itype. Visit common semantic
20086 -- fields of entity or itype Id.
20087
20088 --------------------
20089 -- Add_New_Entity --
20090 --------------------
20091
20092 procedure Add_New_Entity (Old_Id : Entity_Id; New_Id : Entity_Id) is
20093 begin
20094 pragma Assert (Present (Old_Id));
20095 pragma Assert (Present (New_Id));
20096 pragma Assert (Nkind (Old_Id) in N_Entity);
20097 pragma Assert (Nkind (New_Id) in N_Entity);
20098
20099 NCT_Tables_In_Use := True;
20100
20101 -- Sanity check the NCT_New_Entities table. No previous mapping with
20102 -- key Old_Id should exist.
20103
20104 pragma Assert (No (NCT_New_Entities.Get (Old_Id)));
20105
20106 -- Establish the mapping
20107
20108 -- Old_Id -> New_Id
20109
20110 NCT_New_Entities.Set (Old_Id, New_Id);
20111 end Add_New_Entity;
20112
20113 -----------------------
20114 -- Add_Pending_Itype --
20115 -----------------------
20116
20117 procedure Add_Pending_Itype (Assoc_Nod : Node_Id; Itype : Entity_Id) is
20118 Itypes : Elist_Id;
20119
20120 begin
20121 pragma Assert (Present (Assoc_Nod));
20122 pragma Assert (Present (Itype));
20123 pragma Assert (Nkind (Itype) in N_Entity);
20124 pragma Assert (Is_Itype (Itype));
20125
20126 NCT_Tables_In_Use := True;
20127
20128 -- It is not possible to sanity check the NCT_Pendint_Itypes table
20129 -- directly because a single node may act as the associated node for
20130 -- multiple itypes.
20131
20132 Itypes := NCT_Pending_Itypes.Get (Assoc_Nod);
20133
20134 if No (Itypes) then
20135 Itypes := New_Elmt_List;
20136 NCT_Pending_Itypes.Set (Assoc_Nod, Itypes);
20137 end if;
20138
20139 -- Establish the mapping
20140
20141 -- Assoc_Nod -> (Itype, ...)
20142
20143 -- Avoid inserting the same itype multiple times. This involves a
20144 -- linear search, however the set of itypes with the same associated
20145 -- node is very small.
20146
20147 Append_Unique_Elmt (Itype, Itypes);
20148 end Add_Pending_Itype;
20149
20150 ----------------------
20151 -- Build_NCT_Tables --
20152 ----------------------
20153
20154 procedure Build_NCT_Tables (Entity_Map : Elist_Id) is
20155 Elmt : Elmt_Id;
20156 Old_Id : Entity_Id;
20157 New_Id : Entity_Id;
20158
20159 begin
20160 -- Nothing to do when there is no entity map
20161
20162 if No (Entity_Map) then
20163 return;
20164 end if;
20165
20166 Elmt := First_Elmt (Entity_Map);
20167 while Present (Elmt) loop
20168
20169 -- Extract the (Old_Id, New_Id) pair from the entity map
20170
20171 Old_Id := Node (Elmt);
20172 Next_Elmt (Elmt);
20173
20174 New_Id := Node (Elmt);
20175 Next_Elmt (Elmt);
20176
20177 -- Establish the following mapping within table NCT_New_Entities
20178
20179 -- Old_Id -> New_Id
20180
20181 Add_New_Entity (Old_Id, New_Id);
20182
20183 -- Establish the following mapping within table NCT_Pending_Itypes
20184 -- when the new entity is an itype.
20185
20186 -- Assoc_Nod -> (New_Id, ...)
20187
20188 -- IMPORTANT: the associated node is that of the old itype because
20189 -- the node will be replicated in Phase 2.
20190
20191 if Is_Itype (Old_Id) then
20192 Add_Pending_Itype
20193 (Assoc_Nod => Associated_Node_For_Itype (Old_Id),
20194 Itype => New_Id);
20195 end if;
20196 end loop;
20197 end Build_NCT_Tables;
20198
20199 ------------------------------------
20200 -- Copy_Any_Node_With_Replacement --
20201 ------------------------------------
20202
20203 function Copy_Any_Node_With_Replacement
20204 (N : Node_Or_Entity_Id) return Node_Or_Entity_Id
20205 is
20206 begin
20207 if Nkind (N) in N_Entity then
20208 return Corresponding_Entity (N);
20209 else
20210 return Copy_Node_With_Replacement (N);
20211 end if;
20212 end Copy_Any_Node_With_Replacement;
20213
20214 ---------------------------------
20215 -- Copy_Elist_With_Replacement --
20216 ---------------------------------
20217
20218 function Copy_Elist_With_Replacement (List : Elist_Id) return Elist_Id is
20219 Elmt : Elmt_Id;
20220 Result : Elist_Id;
20221
20222 begin
20223 -- Copy the contents of the old list. Note that the list itself may
20224 -- be empty, in which case the routine returns a new empty list. This
20225 -- avoids sharing lists between subtrees. The element of an entity
20226 -- list could be an entity or a node, hence the invocation of routine
20227 -- Copy_Any_Node_With_Replacement.
20228
20229 if Present (List) then
20230 Result := New_Elmt_List;
20231
20232 Elmt := First_Elmt (List);
20233 while Present (Elmt) loop
20234 Append_Elmt
20235 (Copy_Any_Node_With_Replacement (Node (Elmt)), Result);
20236
20237 Next_Elmt (Elmt);
20238 end loop;
20239
20240 -- Otherwise the list does not exist
20241
20242 else
20243 Result := No_Elist;
20244 end if;
20245
20246 return Result;
20247 end Copy_Elist_With_Replacement;
20248
20249 ---------------------------------
20250 -- Copy_Field_With_Replacement --
20251 ---------------------------------
20252
20253 function Copy_Field_With_Replacement
20254 (Field : Union_Id;
20255 Old_Par : Node_Id := Empty;
20256 New_Par : Node_Id := Empty;
20257 Semantic : Boolean := False) return Union_Id
20258 is
20259 begin
20260 -- The field is empty
20261
20262 if Field = Union_Id (Empty) then
20263 return Field;
20264
20265 -- The field is an entity/itype/node
20266
20267 elsif Field in Node_Range then
20268 declare
20269 Old_N : constant Node_Id := Node_Id (Field);
20270 Syntactic : constant Boolean := Parent (Old_N) = Old_Par;
20271
20272 New_N : Node_Id;
20273
20274 begin
20275 -- The field is an entity/itype
20276
20277 if Nkind (Old_N) in N_Entity then
20278
20279 -- An entity/itype is always replicated
20280
20281 New_N := Corresponding_Entity (Old_N);
20282
20283 -- Update the parent pointer when the entity is a syntactic
20284 -- field. Note that itypes do not have parent pointers.
20285
20286 if Syntactic and then New_N /= Old_N then
20287 Set_Parent (New_N, New_Par);
20288 end if;
20289
20290 -- The field is a node
20291
20292 else
20293 -- A node is replicated when it is either a syntactic field
20294 -- or when the caller treats it as a semantic attribute.
20295
20296 if Syntactic or else Semantic then
20297 New_N := Copy_Node_With_Replacement (Old_N);
20298
20299 -- Update the parent pointer when the node is a syntactic
20300 -- field.
20301
20302 if Syntactic and then New_N /= Old_N then
20303 Set_Parent (New_N, New_Par);
20304 end if;
20305
20306 -- Otherwise the node is returned unchanged
20307
20308 else
20309 New_N := Old_N;
20310 end if;
20311 end if;
20312
20313 return Union_Id (New_N);
20314 end;
20315
20316 -- The field is an entity list
20317
20318 elsif Field in Elist_Range then
20319 return Union_Id (Copy_Elist_With_Replacement (Elist_Id (Field)));
20320
20321 -- The field is a syntactic list
20322
20323 elsif Field in List_Range then
20324 declare
20325 Old_List : constant List_Id := List_Id (Field);
20326 Syntactic : constant Boolean := Parent (Old_List) = Old_Par;
20327
20328 New_List : List_Id;
20329
20330 begin
20331 -- A list is replicated when it is either a syntactic field or
20332 -- when the caller treats it as a semantic attribute.
20333
20334 if Syntactic or else Semantic then
20335 New_List := Copy_List_With_Replacement (Old_List);
20336
20337 -- Update the parent pointer when the list is a syntactic
20338 -- field.
20339
20340 if Syntactic and then New_List /= Old_List then
20341 Set_Parent (New_List, New_Par);
20342 end if;
20343
20344 -- Otherwise the list is returned unchanged
20345
20346 else
20347 New_List := Old_List;
20348 end if;
20349
20350 return Union_Id (New_List);
20351 end;
20352
20353 -- Otherwise the field denotes an attribute that does not need to be
20354 -- replicated (Chars, literals, etc).
20355
20356 else
20357 return Field;
20358 end if;
20359 end Copy_Field_With_Replacement;
20360
20361 --------------------------------
20362 -- Copy_List_With_Replacement --
20363 --------------------------------
20364
20365 function Copy_List_With_Replacement (List : List_Id) return List_Id is
20366 Elmt : Node_Id;
20367 Result : List_Id;
20368
20369 begin
20370 -- Copy the contents of the old list. Note that the list itself may
20371 -- be empty, in which case the routine returns a new empty list. This
20372 -- avoids sharing lists between subtrees. The element of a syntactic
20373 -- list is always a node, never an entity or itype, hence the call to
20374 -- routine Copy_Node_With_Replacement.
20375
20376 if Present (List) then
20377 Result := New_List;
20378
20379 Elmt := First (List);
20380 while Present (Elmt) loop
20381 Append (Copy_Node_With_Replacement (Elmt), Result);
20382
20383 Next (Elmt);
20384 end loop;
20385
20386 -- Otherwise the list does not exist
20387
20388 else
20389 Result := No_List;
20390 end if;
20391
20392 return Result;
20393 end Copy_List_With_Replacement;
20394
20395 --------------------------------
20396 -- Copy_Node_With_Replacement --
20397 --------------------------------
20398
20399 function Copy_Node_With_Replacement (N : Node_Id) return Node_Id is
20400 Result : Node_Id;
20401
20402 begin
20403 -- Assume that the node must be returned unchanged
20404
20405 Result := N;
20406
20407 if N > Empty_Or_Error then
20408 pragma Assert (Nkind (N) not in N_Entity);
20409
20410 Result := New_Copy (N);
20411
20412 Set_Field1 (Result,
20413 Copy_Field_With_Replacement
20414 (Field => Field1 (Result),
20415 Old_Par => N,
20416 New_Par => Result));
20417
20418 Set_Field2 (Result,
20419 Copy_Field_With_Replacement
20420 (Field => Field2 (Result),
20421 Old_Par => N,
20422 New_Par => Result));
20423
20424 Set_Field3 (Result,
20425 Copy_Field_With_Replacement
20426 (Field => Field3 (Result),
20427 Old_Par => N,
20428 New_Par => Result));
20429
20430 Set_Field4 (Result,
20431 Copy_Field_With_Replacement
20432 (Field => Field4 (Result),
20433 Old_Par => N,
20434 New_Par => Result));
20435
20436 Set_Field5 (Result,
20437 Copy_Field_With_Replacement
20438 (Field => Field5 (Result),
20439 Old_Par => N,
20440 New_Par => Result));
20441
20442 -- Update the Comes_From_Source and Sloc attributes of the node
20443 -- in case the caller has supplied new values.
20444
20445 Update_CFS_Sloc (Result);
20446
20447 -- Update the Associated_Node_For_Itype attribute of all itypes
20448 -- created during Phase 1 whose associated node is N. As a result
20449 -- the Associated_Node_For_Itype refers to the replicated node.
20450 -- No action needs to be taken when the Associated_Node_For_Itype
20451 -- refers to an entity because this was already handled during
20452 -- Phase 1, in Visit_Itype.
20453
20454 Update_Pending_Itypes
20455 (Old_Assoc => N,
20456 New_Assoc => Result);
20457
20458 -- Update the First/Next_Named_Association chain for a replicated
20459 -- call.
20460
20461 if Nkind_In (N, N_Entry_Call_Statement,
20462 N_Function_Call,
20463 N_Procedure_Call_Statement)
20464 then
20465 Update_Named_Associations
20466 (Old_Call => N,
20467 New_Call => Result);
20468
20469 -- Update the Renamed_Object attribute of a replicated object
20470 -- declaration.
20471
20472 elsif Nkind (N) = N_Object_Renaming_Declaration then
20473 Set_Renamed_Object (Defining_Entity (Result), Name (Result));
20474
20475 -- Update the First_Real_Statement attribute of a replicated
20476 -- handled sequence of statements.
20477
20478 elsif Nkind (N) = N_Handled_Sequence_Of_Statements then
20479 Update_First_Real_Statement
20480 (Old_HSS => N,
20481 New_HSS => Result);
20482
20483 -- Update the Chars attribute of identifiers
20484
20485 elsif Nkind (N) = N_Identifier then
20486
20487 -- The Entity field of identifiers that denote aspects is used
20488 -- to store arbitrary expressions (and hence we must check that
20489 -- they reference an actual entity before copying their Chars
20490 -- value).
20491
20492 if Present (Entity (Result))
20493 and then Nkind (Entity (Result)) in N_Entity
20494 then
20495 Set_Chars (Result, Chars (Entity (Result)));
20496 end if;
20497 end if;
20498 end if;
20499
20500 return Result;
20501 end Copy_Node_With_Replacement;
20502
20503 --------------------------
20504 -- Corresponding_Entity --
20505 --------------------------
20506
20507 function Corresponding_Entity (Id : Entity_Id) return Entity_Id is
20508 New_Id : Entity_Id;
20509 Result : Entity_Id;
20510
20511 begin
20512 -- Assume that the entity must be returned unchanged
20513
20514 Result := Id;
20515
20516 if Id > Empty_Or_Error then
20517 pragma Assert (Nkind (Id) in N_Entity);
20518
20519 -- Determine whether the entity has a corresponding new entity
20520 -- generated during Phase 1 and if it does, use it.
20521
20522 if NCT_Tables_In_Use then
20523 New_Id := NCT_New_Entities.Get (Id);
20524
20525 if Present (New_Id) then
20526 Result := New_Id;
20527 end if;
20528 end if;
20529 end if;
20530
20531 return Result;
20532 end Corresponding_Entity;
20533
20534 -------------------
20535 -- In_Entity_Map --
20536 -------------------
20537
20538 function In_Entity_Map
20539 (Id : Entity_Id;
20540 Entity_Map : Elist_Id) return Boolean
20541 is
20542 Elmt : Elmt_Id;
20543 Old_Id : Entity_Id;
20544
20545 begin
20546 -- The entity map contains pairs (Old_Id, New_Id). The advancement
20547 -- step always skips the New_Id portion of the pair.
20548
20549 if Present (Entity_Map) then
20550 Elmt := First_Elmt (Entity_Map);
20551 while Present (Elmt) loop
20552 Old_Id := Node (Elmt);
20553
20554 if Old_Id = Id then
20555 return True;
20556 end if;
20557
20558 Next_Elmt (Elmt);
20559 Next_Elmt (Elmt);
20560 end loop;
20561 end if;
20562
20563 return False;
20564 end In_Entity_Map;
20565
20566 ---------------------
20567 -- Update_CFS_Sloc --
20568 ---------------------
20569
20570 procedure Update_CFS_Sloc (N : Node_Or_Entity_Id) is
20571 begin
20572 -- A new source location defaults the Comes_From_Source attribute
20573
20574 if New_Sloc /= No_Location then
20575 Set_Comes_From_Source (N, Default_Node.Comes_From_Source);
20576 Set_Sloc (N, New_Sloc);
20577 end if;
20578 end Update_CFS_Sloc;
20579
20580 ---------------------------------
20581 -- Update_First_Real_Statement --
20582 ---------------------------------
20583
20584 procedure Update_First_Real_Statement
20585 (Old_HSS : Node_Id;
20586 New_HSS : Node_Id)
20587 is
20588 Old_First_Stmt : constant Node_Id := First_Real_Statement (Old_HSS);
20589
20590 New_Stmt : Node_Id;
20591 Old_Stmt : Node_Id;
20592
20593 begin
20594 -- Recreate the First_Real_Statement attribute of a handled sequence
20595 -- of statements by traversing the statement lists of both sequences
20596 -- in parallel.
20597
20598 if Present (Old_First_Stmt) then
20599 New_Stmt := First (Statements (New_HSS));
20600 Old_Stmt := First (Statements (Old_HSS));
20601 while Present (Old_Stmt) and then Old_Stmt /= Old_First_Stmt loop
20602 Next (New_Stmt);
20603 Next (Old_Stmt);
20604 end loop;
20605
20606 pragma Assert (Present (New_Stmt));
20607 pragma Assert (Present (Old_Stmt));
20608
20609 Set_First_Real_Statement (New_HSS, New_Stmt);
20610 end if;
20611 end Update_First_Real_Statement;
20612
20613 -------------------------------
20614 -- Update_Named_Associations --
20615 -------------------------------
20616
20617 procedure Update_Named_Associations
20618 (Old_Call : Node_Id;
20619 New_Call : Node_Id)
20620 is
20621 New_Act : Node_Id;
20622 New_Next : Node_Id;
20623 Old_Act : Node_Id;
20624 Old_Next : Node_Id;
20625
20626 begin
20627 if No (First_Named_Actual (Old_Call)) then
20628 return;
20629 end if;
20630
20631 -- Recreate the First/Next_Named_Actual chain of a call by traversing
20632 -- the chains of both the old and new calls in parallel.
20633
20634 New_Act := First (Parameter_Associations (New_Call));
20635 Old_Act := First (Parameter_Associations (Old_Call));
20636 while Present (Old_Act) loop
20637 if Nkind (Old_Act) = N_Parameter_Association
20638 and then Explicit_Actual_Parameter (Old_Act)
20639 = First_Named_Actual (Old_Call)
20640 then
20641 Set_First_Named_Actual (New_Call,
20642 Explicit_Actual_Parameter (New_Act));
20643 end if;
20644
20645 if Nkind (Old_Act) = N_Parameter_Association
20646 and then Present (Next_Named_Actual (Old_Act))
20647 then
20648 -- Scan the actual parameter list to find the next suitable
20649 -- named actual. Note that the list may be out of order.
20650
20651 New_Next := First (Parameter_Associations (New_Call));
20652 Old_Next := First (Parameter_Associations (Old_Call));
20653 while Nkind (Old_Next) /= N_Parameter_Association
20654 or else Explicit_Actual_Parameter (Old_Next) /=
20655 Next_Named_Actual (Old_Act)
20656 loop
20657 Next (New_Next);
20658 Next (Old_Next);
20659 end loop;
20660
20661 Set_Next_Named_Actual (New_Act,
20662 Explicit_Actual_Parameter (New_Next));
20663 end if;
20664
20665 Next (New_Act);
20666 Next (Old_Act);
20667 end loop;
20668 end Update_Named_Associations;
20669
20670 -------------------------
20671 -- Update_New_Entities --
20672 -------------------------
20673
20674 procedure Update_New_Entities (Entity_Map : Elist_Id) is
20675 New_Id : Entity_Id := Empty;
20676 Old_Id : Entity_Id := Empty;
20677
20678 begin
20679 if NCT_Tables_In_Use then
20680 NCT_New_Entities.Get_First (Old_Id, New_Id);
20681
20682 -- Update the semantic fields of all new entities created during
20683 -- Phase 1 which were not supplied via an entity map.
20684 -- ??? Is there a better way of distinguishing those?
20685
20686 while Present (Old_Id) and then Present (New_Id) loop
20687 if not (Present (Entity_Map)
20688 and then In_Entity_Map (Old_Id, Entity_Map))
20689 then
20690 Update_Semantic_Fields (New_Id);
20691 end if;
20692
20693 NCT_New_Entities.Get_Next (Old_Id, New_Id);
20694 end loop;
20695 end if;
20696 end Update_New_Entities;
20697
20698 ---------------------------
20699 -- Update_Pending_Itypes --
20700 ---------------------------
20701
20702 procedure Update_Pending_Itypes
20703 (Old_Assoc : Node_Id;
20704 New_Assoc : Node_Id)
20705 is
20706 Item : Elmt_Id;
20707 Itypes : Elist_Id;
20708
20709 begin
20710 if NCT_Tables_In_Use then
20711 Itypes := NCT_Pending_Itypes.Get (Old_Assoc);
20712
20713 -- Update the Associated_Node_For_Itype attribute for all itypes
20714 -- which originally refer to Old_Assoc to designate New_Assoc.
20715
20716 if Present (Itypes) then
20717 Item := First_Elmt (Itypes);
20718 while Present (Item) loop
20719 Set_Associated_Node_For_Itype (Node (Item), New_Assoc);
20720
20721 Next_Elmt (Item);
20722 end loop;
20723 end if;
20724 end if;
20725 end Update_Pending_Itypes;
20726
20727 ----------------------------
20728 -- Update_Semantic_Fields --
20729 ----------------------------
20730
20731 procedure Update_Semantic_Fields (Id : Entity_Id) is
20732 begin
20733 -- Discriminant_Constraint
20734
20735 if Is_Type (Id) and then Has_Discriminants (Base_Type (Id)) then
20736 Set_Discriminant_Constraint (Id, Elist_Id (
20737 Copy_Field_With_Replacement
20738 (Field => Union_Id (Discriminant_Constraint (Id)),
20739 Semantic => True)));
20740 end if;
20741
20742 -- Etype
20743
20744 Set_Etype (Id, Node_Id (
20745 Copy_Field_With_Replacement
20746 (Field => Union_Id (Etype (Id)),
20747 Semantic => True)));
20748
20749 -- First_Index
20750 -- Packed_Array_Impl_Type
20751
20752 if Is_Array_Type (Id) then
20753 if Present (First_Index (Id)) then
20754 Set_First_Index (Id, First (List_Id (
20755 Copy_Field_With_Replacement
20756 (Field => Union_Id (List_Containing (First_Index (Id))),
20757 Semantic => True))));
20758 end if;
20759
20760 if Is_Packed (Id) then
20761 Set_Packed_Array_Impl_Type (Id, Node_Id (
20762 Copy_Field_With_Replacement
20763 (Field => Union_Id (Packed_Array_Impl_Type (Id)),
20764 Semantic => True)));
20765 end if;
20766 end if;
20767
20768 -- Prev_Entity
20769
20770 Set_Prev_Entity (Id, Node_Id (
20771 Copy_Field_With_Replacement
20772 (Field => Union_Id (Prev_Entity (Id)),
20773 Semantic => True)));
20774
20775 -- Next_Entity
20776
20777 Set_Next_Entity (Id, Node_Id (
20778 Copy_Field_With_Replacement
20779 (Field => Union_Id (Next_Entity (Id)),
20780 Semantic => True)));
20781
20782 -- Scalar_Range
20783
20784 if Is_Discrete_Type (Id) then
20785 Set_Scalar_Range (Id, Node_Id (
20786 Copy_Field_With_Replacement
20787 (Field => Union_Id (Scalar_Range (Id)),
20788 Semantic => True)));
20789 end if;
20790
20791 -- Scope
20792
20793 -- Update the scope when the caller specified an explicit one
20794
20795 if Present (New_Scope) then
20796 Set_Scope (Id, New_Scope);
20797 else
20798 Set_Scope (Id, Node_Id (
20799 Copy_Field_With_Replacement
20800 (Field => Union_Id (Scope (Id)),
20801 Semantic => True)));
20802 end if;
20803 end Update_Semantic_Fields;
20804
20805 --------------------
20806 -- Visit_Any_Node --
20807 --------------------
20808
20809 procedure Visit_Any_Node (N : Node_Or_Entity_Id) is
20810 begin
20811 if Nkind (N) in N_Entity then
20812 if Is_Itype (N) then
20813 Visit_Itype (N);
20814 else
20815 Visit_Entity (N);
20816 end if;
20817 else
20818 Visit_Node (N);
20819 end if;
20820 end Visit_Any_Node;
20821
20822 -----------------
20823 -- Visit_Elist --
20824 -----------------
20825
20826 procedure Visit_Elist (List : Elist_Id) is
20827 Elmt : Elmt_Id;
20828
20829 begin
20830 -- The element of an entity list could be an entity, itype, or a
20831 -- node, hence the call to Visit_Any_Node.
20832
20833 if Present (List) then
20834 Elmt := First_Elmt (List);
20835 while Present (Elmt) loop
20836 Visit_Any_Node (Node (Elmt));
20837
20838 Next_Elmt (Elmt);
20839 end loop;
20840 end if;
20841 end Visit_Elist;
20842
20843 ------------------
20844 -- Visit_Entity --
20845 ------------------
20846
20847 procedure Visit_Entity (Id : Entity_Id) is
20848 New_Id : Entity_Id;
20849
20850 begin
20851 pragma Assert (Nkind (Id) in N_Entity);
20852 pragma Assert (not Is_Itype (Id));
20853
20854 -- Nothing to do when the entity is not defined in the Actions list
20855 -- of an N_Expression_With_Actions node.
20856
20857 if EWA_Level = 0 then
20858 return;
20859
20860 -- Nothing to do when the entity is defined in a scoping construct
20861 -- within an N_Expression_With_Actions node, unless the caller has
20862 -- requested their replication.
20863
20864 -- ??? should this restriction be eliminated?
20865
20866 elsif EWA_Inner_Scope_Level > 0 and then not Scopes_In_EWA_OK then
20867 return;
20868
20869 -- Nothing to do when the entity does not denote a construct that
20870 -- may appear within an N_Expression_With_Actions node. Relaxing
20871 -- this restriction leads to a performance penalty.
20872
20873 -- ??? this list is flaky, and may hide dormant bugs
20874 -- Should functions be included???
20875
20876 -- Loop parameters appear within quantified expressions and contain
20877 -- an entity declaration that must be replaced when the expander is
20878 -- active if the expression has been preanalyzed or analyzed.
20879
20880 elsif not Ekind_In (Id, E_Block,
20881 E_Constant,
20882 E_Label,
20883 E_Loop_Parameter,
20884 E_Procedure,
20885 E_Variable)
20886 and then not Is_Type (Id)
20887 then
20888 return;
20889
20890 elsif Ekind (Id) = E_Loop_Parameter
20891 and then No (Etype (Condition (Parent (Parent (Id)))))
20892 then
20893 return;
20894
20895 -- Nothing to do when the entity was already visited
20896
20897 elsif NCT_Tables_In_Use
20898 and then Present (NCT_New_Entities.Get (Id))
20899 then
20900 return;
20901
20902 -- Nothing to do when the declaration node of the entity is not in
20903 -- the subtree being replicated.
20904
20905 elsif not In_Subtree
20906 (N => Declaration_Node (Id),
20907 Root => Source)
20908 then
20909 return;
20910 end if;
20911
20912 -- Create a new entity by directly copying the old entity. This
20913 -- action causes all attributes of the old entity to be inherited.
20914
20915 New_Id := New_Copy (Id);
20916
20917 -- Create a new name for the new entity because the back end needs
20918 -- distinct names for debugging purposes.
20919
20920 Set_Chars (New_Id, New_Internal_Name ('T'));
20921
20922 -- Update the Comes_From_Source and Sloc attributes of the entity in
20923 -- case the caller has supplied new values.
20924
20925 Update_CFS_Sloc (New_Id);
20926
20927 -- Establish the following mapping within table NCT_New_Entities:
20928
20929 -- Id -> New_Id
20930
20931 Add_New_Entity (Id, New_Id);
20932
20933 -- Deal with the semantic fields of entities. The fields are visited
20934 -- because they may mention entities which reside within the subtree
20935 -- being copied.
20936
20937 Visit_Semantic_Fields (Id);
20938 end Visit_Entity;
20939
20940 -----------------
20941 -- Visit_Field --
20942 -----------------
20943
20944 procedure Visit_Field
20945 (Field : Union_Id;
20946 Par_Nod : Node_Id := Empty;
20947 Semantic : Boolean := False)
20948 is
20949 begin
20950 -- The field is empty
20951
20952 if Field = Union_Id (Empty) then
20953 return;
20954
20955 -- The field is an entity/itype/node
20956
20957 elsif Field in Node_Range then
20958 declare
20959 N : constant Node_Id := Node_Id (Field);
20960
20961 begin
20962 -- The field is an entity/itype
20963
20964 if Nkind (N) in N_Entity then
20965
20966 -- Itypes are always visited
20967
20968 if Is_Itype (N) then
20969 Visit_Itype (N);
20970
20971 -- An entity is visited when it is either a syntactic field
20972 -- or when the caller treats it as a semantic attribute.
20973
20974 elsif Parent (N) = Par_Nod or else Semantic then
20975 Visit_Entity (N);
20976 end if;
20977
20978 -- The field is a node
20979
20980 else
20981 -- A node is visited when it is either a syntactic field or
20982 -- when the caller treats it as a semantic attribute.
20983
20984 if Parent (N) = Par_Nod or else Semantic then
20985 Visit_Node (N);
20986 end if;
20987 end if;
20988 end;
20989
20990 -- The field is an entity list
20991
20992 elsif Field in Elist_Range then
20993 Visit_Elist (Elist_Id (Field));
20994
20995 -- The field is a syntax list
20996
20997 elsif Field in List_Range then
20998 declare
20999 List : constant List_Id := List_Id (Field);
21000
21001 begin
21002 -- A syntax list is visited when it is either a syntactic field
21003 -- or when the caller treats it as a semantic attribute.
21004
21005 if Parent (List) = Par_Nod or else Semantic then
21006 Visit_List (List);
21007 end if;
21008 end;
21009
21010 -- Otherwise the field denotes information which does not need to be
21011 -- visited (chars, literals, etc.).
21012
21013 else
21014 null;
21015 end if;
21016 end Visit_Field;
21017
21018 -----------------
21019 -- Visit_Itype --
21020 -----------------
21021
21022 procedure Visit_Itype (Itype : Entity_Id) is
21023 New_Assoc : Node_Id;
21024 New_Itype : Entity_Id;
21025 Old_Assoc : Node_Id;
21026
21027 begin
21028 pragma Assert (Nkind (Itype) in N_Entity);
21029 pragma Assert (Is_Itype (Itype));
21030
21031 -- Itypes that describe the designated type of access to subprograms
21032 -- have the structure of subprogram declarations, with signatures,
21033 -- etc. Either we duplicate the signatures completely, or choose to
21034 -- share such itypes, which is fine because their elaboration will
21035 -- have no side effects.
21036
21037 if Ekind (Itype) = E_Subprogram_Type then
21038 return;
21039
21040 -- Nothing to do if the itype was already visited
21041
21042 elsif NCT_Tables_In_Use
21043 and then Present (NCT_New_Entities.Get (Itype))
21044 then
21045 return;
21046
21047 -- Nothing to do if the associated node of the itype is not within
21048 -- the subtree being replicated.
21049
21050 elsif not In_Subtree
21051 (N => Associated_Node_For_Itype (Itype),
21052 Root => Source)
21053 then
21054 return;
21055 end if;
21056
21057 -- Create a new itype by directly copying the old itype. This action
21058 -- causes all attributes of the old itype to be inherited.
21059
21060 New_Itype := New_Copy (Itype);
21061
21062 -- Create a new name for the new itype because the back end requires
21063 -- distinct names for debugging purposes.
21064
21065 Set_Chars (New_Itype, New_Internal_Name ('T'));
21066
21067 -- Update the Comes_From_Source and Sloc attributes of the itype in
21068 -- case the caller has supplied new values.
21069
21070 Update_CFS_Sloc (New_Itype);
21071
21072 -- Establish the following mapping within table NCT_New_Entities:
21073
21074 -- Itype -> New_Itype
21075
21076 Add_New_Entity (Itype, New_Itype);
21077
21078 -- The new itype must be unfrozen because the resulting subtree may
21079 -- be inserted anywhere and cause an earlier or later freezing.
21080
21081 if Present (Freeze_Node (New_Itype)) then
21082 Set_Freeze_Node (New_Itype, Empty);
21083 Set_Is_Frozen (New_Itype, False);
21084 end if;
21085
21086 -- If a record subtype is simply copied, the entity list will be
21087 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
21088 -- ??? What does this do?
21089
21090 if Ekind_In (Itype, E_Class_Wide_Subtype, E_Record_Subtype) then
21091 Set_Cloned_Subtype (New_Itype, Itype);
21092 end if;
21093
21094 -- The associated node may denote an entity, in which case it may
21095 -- already have a new corresponding entity created during a prior
21096 -- call to Visit_Entity or Visit_Itype for the same subtree.
21097
21098 -- Given
21099 -- Old_Assoc ---------> New_Assoc
21100
21101 -- Created by Visit_Itype
21102 -- Itype -------------> New_Itype
21103 -- ANFI = Old_Assoc ANFI = Old_Assoc < must be updated
21104
21105 -- In the example above, Old_Assoc is an arbitrary entity that was
21106 -- already visited for the same subtree and has a corresponding new
21107 -- entity New_Assoc. Old_Assoc was inherited by New_Itype by virtue
21108 -- of copying entities, however it must be updated to New_Assoc.
21109
21110 Old_Assoc := Associated_Node_For_Itype (Itype);
21111
21112 if Nkind (Old_Assoc) in N_Entity then
21113 if NCT_Tables_In_Use then
21114 New_Assoc := NCT_New_Entities.Get (Old_Assoc);
21115
21116 if Present (New_Assoc) then
21117 Set_Associated_Node_For_Itype (New_Itype, New_Assoc);
21118 end if;
21119 end if;
21120
21121 -- Otherwise the associated node denotes a node. Postpone the update
21122 -- until Phase 2 when the node is replicated. Establish the following
21123 -- mapping within table NCT_Pending_Itypes:
21124
21125 -- Old_Assoc -> (New_Type, ...)
21126
21127 else
21128 Add_Pending_Itype (Old_Assoc, New_Itype);
21129 end if;
21130
21131 -- Deal with the semantic fields of itypes. The fields are visited
21132 -- because they may mention entities that reside within the subtree
21133 -- being copied.
21134
21135 Visit_Semantic_Fields (Itype);
21136 end Visit_Itype;
21137
21138 ----------------
21139 -- Visit_List --
21140 ----------------
21141
21142 procedure Visit_List (List : List_Id) is
21143 Elmt : Node_Id;
21144
21145 begin
21146 -- Note that the element of a syntactic list is always a node, never
21147 -- an entity or itype, hence the call to Visit_Node.
21148
21149 if Present (List) then
21150 Elmt := First (List);
21151 while Present (Elmt) loop
21152 Visit_Node (Elmt);
21153
21154 Next (Elmt);
21155 end loop;
21156 end if;
21157 end Visit_List;
21158
21159 ----------------
21160 -- Visit_Node --
21161 ----------------
21162
21163 procedure Visit_Node (N : Node_Or_Entity_Id) is
21164 begin
21165 pragma Assert (Nkind (N) not in N_Entity);
21166
21167 -- If the node is a quantified expression and expander is active,
21168 -- it contains an implicit declaration that may require a new entity
21169 -- when the condition has already been (pre)analyzed.
21170
21171 if Nkind (N) = N_Expression_With_Actions
21172 or else
21173 (Nkind (N) = N_Quantified_Expression and then Expander_Active)
21174 then
21175 EWA_Level := EWA_Level + 1;
21176
21177 elsif EWA_Level > 0
21178 and then Nkind_In (N, N_Block_Statement,
21179 N_Subprogram_Body,
21180 N_Subprogram_Declaration)
21181 then
21182 EWA_Inner_Scope_Level := EWA_Inner_Scope_Level + 1;
21183 end if;
21184
21185 Visit_Field
21186 (Field => Field1 (N),
21187 Par_Nod => N);
21188
21189 Visit_Field
21190 (Field => Field2 (N),
21191 Par_Nod => N);
21192
21193 Visit_Field
21194 (Field => Field3 (N),
21195 Par_Nod => N);
21196
21197 Visit_Field
21198 (Field => Field4 (N),
21199 Par_Nod => N);
21200
21201 Visit_Field
21202 (Field => Field5 (N),
21203 Par_Nod => N);
21204
21205 if EWA_Level > 0
21206 and then Nkind_In (N, N_Block_Statement,
21207 N_Subprogram_Body,
21208 N_Subprogram_Declaration)
21209 then
21210 EWA_Inner_Scope_Level := EWA_Inner_Scope_Level - 1;
21211
21212 elsif Nkind (N) = N_Expression_With_Actions then
21213 EWA_Level := EWA_Level - 1;
21214 end if;
21215 end Visit_Node;
21216
21217 ---------------------------
21218 -- Visit_Semantic_Fields --
21219 ---------------------------
21220
21221 procedure Visit_Semantic_Fields (Id : Entity_Id) is
21222 begin
21223 pragma Assert (Nkind (Id) in N_Entity);
21224
21225 -- Discriminant_Constraint
21226
21227 if Is_Type (Id) and then Has_Discriminants (Base_Type (Id)) then
21228 Visit_Field
21229 (Field => Union_Id (Discriminant_Constraint (Id)),
21230 Semantic => True);
21231 end if;
21232
21233 -- Etype
21234
21235 Visit_Field
21236 (Field => Union_Id (Etype (Id)),
21237 Semantic => True);
21238
21239 -- First_Index
21240 -- Packed_Array_Impl_Type
21241
21242 if Is_Array_Type (Id) then
21243 if Present (First_Index (Id)) then
21244 Visit_Field
21245 (Field => Union_Id (List_Containing (First_Index (Id))),
21246 Semantic => True);
21247 end if;
21248
21249 if Is_Packed (Id) then
21250 Visit_Field
21251 (Field => Union_Id (Packed_Array_Impl_Type (Id)),
21252 Semantic => True);
21253 end if;
21254 end if;
21255
21256 -- Scalar_Range
21257
21258 if Is_Discrete_Type (Id) then
21259 Visit_Field
21260 (Field => Union_Id (Scalar_Range (Id)),
21261 Semantic => True);
21262 end if;
21263 end Visit_Semantic_Fields;
21264
21265 -- Start of processing for New_Copy_Tree
21266
21267 begin
21268 -- Routine New_Copy_Tree performs a deep copy of a subtree by creating
21269 -- shallow copies for each node within, and then updating the child and
21270 -- parent pointers accordingly. This process is straightforward, however
21271 -- the routine must deal with the following complications:
21272
21273 -- * Entities defined within N_Expression_With_Actions nodes must be
21274 -- replicated rather than shared to avoid introducing two identical
21275 -- symbols within the same scope. Note that no other expression can
21276 -- currently define entities.
21277
21278 -- do
21279 -- Source_Low : ...;
21280 -- Source_High : ...;
21281
21282 -- <reference to Source_Low>
21283 -- <reference to Source_High>
21284 -- in ... end;
21285
21286 -- New_Copy_Tree handles this case by first creating new entities
21287 -- and then updating all existing references to point to these new
21288 -- entities.
21289
21290 -- do
21291 -- New_Low : ...;
21292 -- New_High : ...;
21293
21294 -- <reference to New_Low>
21295 -- <reference to New_High>
21296 -- in ... end;
21297
21298 -- * Itypes defined within the subtree must be replicated to avoid any
21299 -- dependencies on invalid or inaccessible data.
21300
21301 -- subtype Source_Itype is ... range Source_Low .. Source_High;
21302
21303 -- New_Copy_Tree handles this case by first creating a new itype in
21304 -- the same fashion as entities, and then updating various relevant
21305 -- constraints.
21306
21307 -- subtype New_Itype is ... range New_Low .. New_High;
21308
21309 -- * The Associated_Node_For_Itype field of itypes must be updated to
21310 -- reference the proper replicated entity or node.
21311
21312 -- * Semantic fields of entities such as Etype and Scope must be
21313 -- updated to reference the proper replicated entities.
21314
21315 -- * Semantic fields of nodes such as First_Real_Statement must be
21316 -- updated to reference the proper replicated nodes.
21317
21318 -- Finally, quantified expressions contain an implicit delaration for
21319 -- the bound variable. Given that quantified expressions appearing
21320 -- in contracts are copied to create pragmas and eventually checking
21321 -- procedures, a new bound variable must be created for each copy, to
21322 -- prevent multiple declarations of the same symbol.
21323
21324 -- To meet all these demands, routine New_Copy_Tree is split into two
21325 -- phases.
21326
21327 -- Phase 1 traverses the tree in order to locate entities and itypes
21328 -- defined within the subtree. New entities are generated and saved in
21329 -- table NCT_New_Entities. The semantic fields of all new entities and
21330 -- itypes are then updated accordingly.
21331
21332 -- Phase 2 traverses the tree in order to replicate each node. Various
21333 -- semantic fields of nodes and entities are updated accordingly.
21334
21335 -- Preparatory phase. Clear the contents of tables NCT_New_Entities and
21336 -- NCT_Pending_Itypes in case a previous call to New_Copy_Tree left some
21337 -- data inside.
21338
21339 if NCT_Tables_In_Use then
21340 NCT_Tables_In_Use := False;
21341
21342 NCT_New_Entities.Reset;
21343 NCT_Pending_Itypes.Reset;
21344 end if;
21345
21346 -- Populate tables NCT_New_Entities and NCT_Pending_Itypes with data
21347 -- supplied by a linear entity map. The tables offer faster access to
21348 -- the same data.
21349
21350 Build_NCT_Tables (Map);
21351
21352 -- Execute Phase 1. Traverse the subtree and generate new entities for
21353 -- the following cases:
21354
21355 -- * An entity defined within an N_Expression_With_Actions node
21356
21357 -- * An itype referenced within the subtree where the associated node
21358 -- is also in the subtree.
21359
21360 -- All new entities are accessible via table NCT_New_Entities, which
21361 -- contains mappings of the form:
21362
21363 -- Old_Entity -> New_Entity
21364 -- Old_Itype -> New_Itype
21365
21366 -- In addition, the associated nodes of all new itypes are mapped in
21367 -- table NCT_Pending_Itypes:
21368
21369 -- Assoc_Nod -> (New_Itype1, New_Itype2, .., New_ItypeN)
21370
21371 Visit_Any_Node (Source);
21372
21373 -- Update the semantic attributes of all new entities generated during
21374 -- Phase 1 before starting Phase 2. The updates could be performed in
21375 -- routine Corresponding_Entity, however this may cause the same entity
21376 -- to be updated multiple times, effectively generating useless nodes.
21377 -- Keeping the updates separates from Phase 2 ensures that only one set
21378 -- of attributes is generated for an entity at any one time.
21379
21380 Update_New_Entities (Map);
21381
21382 -- Execute Phase 2. Replicate the source subtree one node at a time.
21383 -- The following transformations take place:
21384
21385 -- * References to entities and itypes are updated to refer to the
21386 -- new entities and itypes generated during Phase 1.
21387
21388 -- * All Associated_Node_For_Itype attributes of itypes are updated
21389 -- to refer to the new replicated Associated_Node_For_Itype.
21390
21391 return Copy_Node_With_Replacement (Source);
21392 end New_Copy_Tree;
21393
21394 -------------------------
21395 -- New_External_Entity --
21396 -------------------------
21397
21398 function New_External_Entity
21399 (Kind : Entity_Kind;
21400 Scope_Id : Entity_Id;
21401 Sloc_Value : Source_Ptr;
21402 Related_Id : Entity_Id;
21403 Suffix : Character;
21404 Suffix_Index : Int := 0;
21405 Prefix : Character := ' ') return Entity_Id
21406 is
21407 N : constant Entity_Id :=
21408 Make_Defining_Identifier (Sloc_Value,
21409 New_External_Name
21410 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
21411
21412 begin
21413 Set_Ekind (N, Kind);
21414 Set_Is_Internal (N, True);
21415 Append_Entity (N, Scope_Id);
21416 Set_Public_Status (N);
21417
21418 if Kind in Type_Kind then
21419 Init_Size_Align (N);
21420 end if;
21421
21422 return N;
21423 end New_External_Entity;
21424
21425 -------------------------
21426 -- New_Internal_Entity --
21427 -------------------------
21428
21429 function New_Internal_Entity
21430 (Kind : Entity_Kind;
21431 Scope_Id : Entity_Id;
21432 Sloc_Value : Source_Ptr;
21433 Id_Char : Character) return Entity_Id
21434 is
21435 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
21436
21437 begin
21438 Set_Ekind (N, Kind);
21439 Set_Is_Internal (N, True);
21440 Append_Entity (N, Scope_Id);
21441
21442 if Kind in Type_Kind then
21443 Init_Size_Align (N);
21444 end if;
21445
21446 return N;
21447 end New_Internal_Entity;
21448
21449 -----------------
21450 -- Next_Actual --
21451 -----------------
21452
21453 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
21454 Par : constant Node_Id := Parent (Actual_Id);
21455 N : Node_Id;
21456
21457 begin
21458 -- If we are pointing at a positional parameter, it is a member of a
21459 -- node list (the list of parameters), and the next parameter is the
21460 -- next node on the list, unless we hit a parameter association, then
21461 -- we shift to using the chain whose head is the First_Named_Actual in
21462 -- the parent, and then is threaded using the Next_Named_Actual of the
21463 -- Parameter_Association. All this fiddling is because the original node
21464 -- list is in the textual call order, and what we need is the
21465 -- declaration order.
21466
21467 if Is_List_Member (Actual_Id) then
21468 N := Next (Actual_Id);
21469
21470 if Nkind (N) = N_Parameter_Association then
21471
21472 -- In case of a build-in-place call, the call will no longer be a
21473 -- call; it will have been rewritten.
21474
21475 if Nkind_In (Par, N_Entry_Call_Statement,
21476 N_Function_Call,
21477 N_Procedure_Call_Statement)
21478 then
21479 return First_Named_Actual (Par);
21480
21481 -- In case of a call rewritten in GNATprove mode while "inlining
21482 -- for proof" go to the original call.
21483
21484 elsif Nkind (Par) = N_Null_Statement then
21485 pragma Assert
21486 (GNATprove_Mode
21487 and then
21488 Nkind (Original_Node (Par)) in N_Subprogram_Call);
21489
21490 return First_Named_Actual (Original_Node (Par));
21491 else
21492 return Empty;
21493 end if;
21494 else
21495 return N;
21496 end if;
21497
21498 else
21499 return Next_Named_Actual (Parent (Actual_Id));
21500 end if;
21501 end Next_Actual;
21502
21503 procedure Next_Actual (Actual_Id : in out Node_Id) is
21504 begin
21505 Actual_Id := Next_Actual (Actual_Id);
21506 end Next_Actual;
21507
21508 -----------------
21509 -- Next_Global --
21510 -----------------
21511
21512 function Next_Global (Node : Node_Id) return Node_Id is
21513 begin
21514 -- The global item may either be in a list, or by itself, in which case
21515 -- there is no next global item with the same mode.
21516
21517 if Is_List_Member (Node) then
21518 return Next (Node);
21519 else
21520 return Empty;
21521 end if;
21522 end Next_Global;
21523
21524 procedure Next_Global (Node : in out Node_Id) is
21525 begin
21526 Node := Next_Global (Node);
21527 end Next_Global;
21528
21529 ----------------------------------
21530 -- New_Requires_Transient_Scope --
21531 ----------------------------------
21532
21533 function New_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
21534 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean;
21535 -- This is called for untagged records and protected types, with
21536 -- nondefaulted discriminants. Returns True if the size of function
21537 -- results is known at the call site, False otherwise. Returns False
21538 -- if there is a variant part that depends on the discriminants of
21539 -- this type, or if there is an array constrained by the discriminants
21540 -- of this type. ???Currently, this is overly conservative (the array
21541 -- could be nested inside some other record that is constrained by
21542 -- nondiscriminants). That is, the recursive calls are too conservative.
21543
21544 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean;
21545 -- Returns True if Typ is a nonlimited record with defaulted
21546 -- discriminants whose max size makes it unsuitable for allocating on
21547 -- the primary stack.
21548
21549 ------------------------------
21550 -- Caller_Known_Size_Record --
21551 ------------------------------
21552
21553 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean is
21554 pragma Assert (Typ = Underlying_Type (Typ));
21555
21556 begin
21557 if Has_Variant_Part (Typ) and then not Is_Definite_Subtype (Typ) then
21558 return False;
21559 end if;
21560
21561 declare
21562 Comp : Entity_Id;
21563
21564 begin
21565 Comp := First_Entity (Typ);
21566 while Present (Comp) loop
21567
21568 -- Only look at E_Component entities. No need to look at
21569 -- E_Discriminant entities, and we must ignore internal
21570 -- subtypes generated for constrained components.
21571
21572 if Ekind (Comp) = E_Component then
21573 declare
21574 Comp_Type : constant Entity_Id :=
21575 Underlying_Type (Etype (Comp));
21576
21577 begin
21578 if Is_Record_Type (Comp_Type)
21579 or else
21580 Is_Protected_Type (Comp_Type)
21581 then
21582 if not Caller_Known_Size_Record (Comp_Type) then
21583 return False;
21584 end if;
21585
21586 elsif Is_Array_Type (Comp_Type) then
21587 if Size_Depends_On_Discriminant (Comp_Type) then
21588 return False;
21589 end if;
21590 end if;
21591 end;
21592 end if;
21593
21594 Next_Entity (Comp);
21595 end loop;
21596 end;
21597
21598 return True;
21599 end Caller_Known_Size_Record;
21600
21601 ------------------------------
21602 -- Large_Max_Size_Mutable --
21603 ------------------------------
21604
21605 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean is
21606 pragma Assert (Typ = Underlying_Type (Typ));
21607
21608 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean;
21609 -- Returns true if the discrete type T has a large range
21610
21611 ----------------------------
21612 -- Is_Large_Discrete_Type --
21613 ----------------------------
21614
21615 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean is
21616 Threshold : constant Int := 16;
21617 -- Arbitrary threshold above which we consider it "large". We want
21618 -- a fairly large threshold, because these large types really
21619 -- shouldn't have default discriminants in the first place, in
21620 -- most cases.
21621
21622 begin
21623 return UI_To_Int (RM_Size (T)) > Threshold;
21624 end Is_Large_Discrete_Type;
21625
21626 -- Start of processing for Large_Max_Size_Mutable
21627
21628 begin
21629 if Is_Record_Type (Typ)
21630 and then not Is_Limited_View (Typ)
21631 and then Has_Defaulted_Discriminants (Typ)
21632 then
21633 -- Loop through the components, looking for an array whose upper
21634 -- bound(s) depends on discriminants, where both the subtype of
21635 -- the discriminant and the index subtype are too large.
21636
21637 declare
21638 Comp : Entity_Id;
21639
21640 begin
21641 Comp := First_Entity (Typ);
21642 while Present (Comp) loop
21643 if Ekind (Comp) = E_Component then
21644 declare
21645 Comp_Type : constant Entity_Id :=
21646 Underlying_Type (Etype (Comp));
21647
21648 Hi : Node_Id;
21649 Indx : Node_Id;
21650 Ityp : Entity_Id;
21651
21652 begin
21653 if Is_Array_Type (Comp_Type) then
21654 Indx := First_Index (Comp_Type);
21655
21656 while Present (Indx) loop
21657 Ityp := Etype (Indx);
21658 Hi := Type_High_Bound (Ityp);
21659
21660 if Nkind (Hi) = N_Identifier
21661 and then Ekind (Entity (Hi)) = E_Discriminant
21662 and then Is_Large_Discrete_Type (Ityp)
21663 and then Is_Large_Discrete_Type
21664 (Etype (Entity (Hi)))
21665 then
21666 return True;
21667 end if;
21668
21669 Next_Index (Indx);
21670 end loop;
21671 end if;
21672 end;
21673 end if;
21674
21675 Next_Entity (Comp);
21676 end loop;
21677 end;
21678 end if;
21679
21680 return False;
21681 end Large_Max_Size_Mutable;
21682
21683 -- Local declarations
21684
21685 Typ : constant Entity_Id := Underlying_Type (Id);
21686
21687 -- Start of processing for New_Requires_Transient_Scope
21688
21689 begin
21690 -- This is a private type which is not completed yet. This can only
21691 -- happen in a default expression (of a formal parameter or of a
21692 -- record component). Do not expand transient scope in this case.
21693
21694 if No (Typ) then
21695 return False;
21696
21697 -- Do not expand transient scope for non-existent procedure return or
21698 -- string literal types.
21699
21700 elsif Typ = Standard_Void_Type
21701 or else Ekind (Typ) = E_String_Literal_Subtype
21702 then
21703 return False;
21704
21705 -- If Typ is a generic formal incomplete type, then we want to look at
21706 -- the actual type.
21707
21708 elsif Ekind (Typ) = E_Record_Subtype
21709 and then Present (Cloned_Subtype (Typ))
21710 then
21711 return New_Requires_Transient_Scope (Cloned_Subtype (Typ));
21712
21713 -- Functions returning specific tagged types may dispatch on result, so
21714 -- their returned value is allocated on the secondary stack, even in the
21715 -- definite case. We must treat nondispatching functions the same way,
21716 -- because access-to-function types can point at both, so the calling
21717 -- conventions must be compatible. Is_Tagged_Type includes controlled
21718 -- types and class-wide types. Controlled type temporaries need
21719 -- finalization.
21720
21721 -- ???It's not clear why we need to return noncontrolled types with
21722 -- controlled components on the secondary stack.
21723
21724 elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
21725 return True;
21726
21727 -- Untagged definite subtypes are known size. This includes all
21728 -- elementary [sub]types. Tasks are known size even if they have
21729 -- discriminants. So we return False here, with one exception:
21730 -- For a type like:
21731 -- type T (Last : Natural := 0) is
21732 -- X : String (1 .. Last);
21733 -- end record;
21734 -- we return True. That's because for "P(F(...));", where F returns T,
21735 -- we don't know the size of the result at the call site, so if we
21736 -- allocated it on the primary stack, we would have to allocate the
21737 -- maximum size, which is way too big.
21738
21739 elsif Is_Definite_Subtype (Typ) or else Is_Task_Type (Typ) then
21740 return Large_Max_Size_Mutable (Typ);
21741
21742 -- Indefinite (discriminated) untagged record or protected type
21743
21744 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
21745 return not Caller_Known_Size_Record (Typ);
21746
21747 -- Unconstrained array
21748
21749 else
21750 pragma Assert (Is_Array_Type (Typ) and not Is_Definite_Subtype (Typ));
21751 return True;
21752 end if;
21753 end New_Requires_Transient_Scope;
21754
21755 ------------------------
21756 -- No_Caching_Enabled --
21757 ------------------------
21758
21759 function No_Caching_Enabled (Id : Entity_Id) return Boolean is
21760 Prag : constant Node_Id := Get_Pragma (Id, Pragma_No_Caching);
21761 Arg1 : Node_Id;
21762
21763 begin
21764 if Present (Prag) then
21765 Arg1 := First (Pragma_Argument_Associations (Prag));
21766
21767 -- The pragma has an optional Boolean expression, the related
21768 -- property is enabled only when the expression evaluates to True.
21769
21770 if Present (Arg1) then
21771 return Is_True (Expr_Value (Get_Pragma_Arg (Arg1)));
21772
21773 -- Otherwise the lack of expression enables the property by
21774 -- default.
21775
21776 else
21777 return True;
21778 end if;
21779
21780 -- The property was never set in the first place
21781
21782 else
21783 return False;
21784 end if;
21785 end No_Caching_Enabled;
21786
21787 --------------------------
21788 -- No_Heap_Finalization --
21789 --------------------------
21790
21791 function No_Heap_Finalization (Typ : Entity_Id) return Boolean is
21792 begin
21793 if Ekind_In (Typ, E_Access_Type, E_General_Access_Type)
21794 and then Is_Library_Level_Entity (Typ)
21795 then
21796 -- A global No_Heap_Finalization pragma applies to all library-level
21797 -- named access-to-object types.
21798
21799 if Present (No_Heap_Finalization_Pragma) then
21800 return True;
21801
21802 -- The library-level named access-to-object type itself is subject to
21803 -- pragma No_Heap_Finalization.
21804
21805 elsif Present (Get_Pragma (Typ, Pragma_No_Heap_Finalization)) then
21806 return True;
21807 end if;
21808 end if;
21809
21810 return False;
21811 end No_Heap_Finalization;
21812
21813 -----------------------
21814 -- Normalize_Actuals --
21815 -----------------------
21816
21817 -- Chain actuals according to formals of subprogram. If there are no named
21818 -- associations, the chain is simply the list of Parameter Associations,
21819 -- since the order is the same as the declaration order. If there are named
21820 -- associations, then the First_Named_Actual field in the N_Function_Call
21821 -- or N_Procedure_Call_Statement node points to the Parameter_Association
21822 -- node for the parameter that comes first in declaration order. The
21823 -- remaining named parameters are then chained in declaration order using
21824 -- Next_Named_Actual.
21825
21826 -- This routine also verifies that the number of actuals is compatible with
21827 -- the number and default values of formals, but performs no type checking
21828 -- (type checking is done by the caller).
21829
21830 -- If the matching succeeds, Success is set to True and the caller proceeds
21831 -- with type-checking. If the match is unsuccessful, then Success is set to
21832 -- False, and the caller attempts a different interpretation, if there is
21833 -- one.
21834
21835 -- If the flag Report is on, the call is not overloaded, and a failure to
21836 -- match can be reported here, rather than in the caller.
21837
21838 procedure Normalize_Actuals
21839 (N : Node_Id;
21840 S : Entity_Id;
21841 Report : Boolean;
21842 Success : out Boolean)
21843 is
21844 Actuals : constant List_Id := Parameter_Associations (N);
21845 Actual : Node_Id := Empty;
21846 Formal : Entity_Id;
21847 Last : Node_Id := Empty;
21848 First_Named : Node_Id := Empty;
21849 Found : Boolean;
21850
21851 Formals_To_Match : Integer := 0;
21852 Actuals_To_Match : Integer := 0;
21853
21854 procedure Chain (A : Node_Id);
21855 -- Add named actual at the proper place in the list, using the
21856 -- Next_Named_Actual link.
21857
21858 function Reporting return Boolean;
21859 -- Determines if an error is to be reported. To report an error, we
21860 -- need Report to be True, and also we do not report errors caused
21861 -- by calls to init procs that occur within other init procs. Such
21862 -- errors must always be cascaded errors, since if all the types are
21863 -- declared correctly, the compiler will certainly build decent calls.
21864
21865 -----------
21866 -- Chain --
21867 -----------
21868
21869 procedure Chain (A : Node_Id) is
21870 begin
21871 if No (Last) then
21872
21873 -- Call node points to first actual in list
21874
21875 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
21876
21877 else
21878 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
21879 end if;
21880
21881 Last := A;
21882 Set_Next_Named_Actual (Last, Empty);
21883 end Chain;
21884
21885 ---------------
21886 -- Reporting --
21887 ---------------
21888
21889 function Reporting return Boolean is
21890 begin
21891 if not Report then
21892 return False;
21893
21894 elsif not Within_Init_Proc then
21895 return True;
21896
21897 elsif Is_Init_Proc (Entity (Name (N))) then
21898 return False;
21899
21900 else
21901 return True;
21902 end if;
21903 end Reporting;
21904
21905 -- Start of processing for Normalize_Actuals
21906
21907 begin
21908 if Is_Access_Type (S) then
21909
21910 -- The name in the call is a function call that returns an access
21911 -- to subprogram. The designated type has the list of formals.
21912
21913 Formal := First_Formal (Designated_Type (S));
21914 else
21915 Formal := First_Formal (S);
21916 end if;
21917
21918 while Present (Formal) loop
21919 Formals_To_Match := Formals_To_Match + 1;
21920 Next_Formal (Formal);
21921 end loop;
21922
21923 -- Find if there is a named association, and verify that no positional
21924 -- associations appear after named ones.
21925
21926 if Present (Actuals) then
21927 Actual := First (Actuals);
21928 end if;
21929
21930 while Present (Actual)
21931 and then Nkind (Actual) /= N_Parameter_Association
21932 loop
21933 Actuals_To_Match := Actuals_To_Match + 1;
21934 Next (Actual);
21935 end loop;
21936
21937 if No (Actual) and Actuals_To_Match = Formals_To_Match then
21938
21939 -- Most common case: positional notation, no defaults
21940
21941 Success := True;
21942 return;
21943
21944 elsif Actuals_To_Match > Formals_To_Match then
21945
21946 -- Too many actuals: will not work
21947
21948 if Reporting then
21949 if Is_Entity_Name (Name (N)) then
21950 Error_Msg_N ("too many arguments in call to&", Name (N));
21951 else
21952 Error_Msg_N ("too many arguments in call", N);
21953 end if;
21954 end if;
21955
21956 Success := False;
21957 return;
21958 end if;
21959
21960 First_Named := Actual;
21961
21962 while Present (Actual) loop
21963 if Nkind (Actual) /= N_Parameter_Association then
21964 Error_Msg_N
21965 ("positional parameters not allowed after named ones", Actual);
21966 Success := False;
21967 return;
21968
21969 else
21970 Actuals_To_Match := Actuals_To_Match + 1;
21971 end if;
21972
21973 Next (Actual);
21974 end loop;
21975
21976 if Present (Actuals) then
21977 Actual := First (Actuals);
21978 end if;
21979
21980 Formal := First_Formal (S);
21981 while Present (Formal) loop
21982
21983 -- Match the formals in order. If the corresponding actual is
21984 -- positional, nothing to do. Else scan the list of named actuals
21985 -- to find the one with the right name.
21986
21987 if Present (Actual)
21988 and then Nkind (Actual) /= N_Parameter_Association
21989 then
21990 Next (Actual);
21991 Actuals_To_Match := Actuals_To_Match - 1;
21992 Formals_To_Match := Formals_To_Match - 1;
21993
21994 else
21995 -- For named parameters, search the list of actuals to find
21996 -- one that matches the next formal name.
21997
21998 Actual := First_Named;
21999 Found := False;
22000 while Present (Actual) loop
22001 if Chars (Selector_Name (Actual)) = Chars (Formal) then
22002 Found := True;
22003 Chain (Actual);
22004 Actuals_To_Match := Actuals_To_Match - 1;
22005 Formals_To_Match := Formals_To_Match - 1;
22006 exit;
22007 end if;
22008
22009 Next (Actual);
22010 end loop;
22011
22012 if not Found then
22013 if Ekind (Formal) /= E_In_Parameter
22014 or else No (Default_Value (Formal))
22015 then
22016 if Reporting then
22017 if (Comes_From_Source (S)
22018 or else Sloc (S) = Standard_Location)
22019 and then Is_Overloadable (S)
22020 then
22021 if No (Actuals)
22022 and then
22023 Nkind_In (Parent (N), N_Procedure_Call_Statement,
22024 N_Function_Call,
22025 N_Parameter_Association)
22026 and then Ekind (S) /= E_Function
22027 then
22028 Set_Etype (N, Etype (S));
22029
22030 else
22031 Error_Msg_Name_1 := Chars (S);
22032 Error_Msg_Sloc := Sloc (S);
22033 Error_Msg_NE
22034 ("missing argument for parameter & "
22035 & "in call to % declared #", N, Formal);
22036 end if;
22037
22038 elsif Is_Overloadable (S) then
22039 Error_Msg_Name_1 := Chars (S);
22040
22041 -- Point to type derivation that generated the
22042 -- operation.
22043
22044 Error_Msg_Sloc := Sloc (Parent (S));
22045
22046 Error_Msg_NE
22047 ("missing argument for parameter & "
22048 & "in call to % (inherited) #", N, Formal);
22049
22050 else
22051 Error_Msg_NE
22052 ("missing argument for parameter &", N, Formal);
22053 end if;
22054 end if;
22055
22056 Success := False;
22057 return;
22058
22059 else
22060 Formals_To_Match := Formals_To_Match - 1;
22061 end if;
22062 end if;
22063 end if;
22064
22065 Next_Formal (Formal);
22066 end loop;
22067
22068 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
22069 Success := True;
22070 return;
22071
22072 else
22073 if Reporting then
22074
22075 -- Find some superfluous named actual that did not get
22076 -- attached to the list of associations.
22077
22078 Actual := First (Actuals);
22079 while Present (Actual) loop
22080 if Nkind (Actual) = N_Parameter_Association
22081 and then Actual /= Last
22082 and then No (Next_Named_Actual (Actual))
22083 then
22084 -- A validity check may introduce a copy of a call that
22085 -- includes an extra actual (for example for an unrelated
22086 -- accessibility check). Check that the extra actual matches
22087 -- some extra formal, which must exist already because
22088 -- subprogram must be frozen at this point.
22089
22090 if Present (Extra_Formals (S))
22091 and then not Comes_From_Source (Actual)
22092 and then Nkind (Actual) = N_Parameter_Association
22093 and then Chars (Extra_Formals (S)) =
22094 Chars (Selector_Name (Actual))
22095 then
22096 null;
22097 else
22098 Error_Msg_N
22099 ("unmatched actual & in call", Selector_Name (Actual));
22100 exit;
22101 end if;
22102 end if;
22103
22104 Next (Actual);
22105 end loop;
22106 end if;
22107
22108 Success := False;
22109 return;
22110 end if;
22111 end Normalize_Actuals;
22112
22113 --------------------------------
22114 -- Note_Possible_Modification --
22115 --------------------------------
22116
22117 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
22118 Modification_Comes_From_Source : constant Boolean :=
22119 Comes_From_Source (Parent (N));
22120
22121 Ent : Entity_Id;
22122 Exp : Node_Id;
22123
22124 begin
22125 -- Loop to find referenced entity, if there is one
22126
22127 Exp := N;
22128 loop
22129 Ent := Empty;
22130
22131 if Is_Entity_Name (Exp) then
22132 Ent := Entity (Exp);
22133
22134 -- If the entity is missing, it is an undeclared identifier,
22135 -- and there is nothing to annotate.
22136
22137 if No (Ent) then
22138 return;
22139 end if;
22140
22141 elsif Nkind (Exp) = N_Explicit_Dereference then
22142 declare
22143 P : constant Node_Id := Prefix (Exp);
22144
22145 begin
22146 -- In formal verification mode, keep track of all reads and
22147 -- writes through explicit dereferences.
22148
22149 if GNATprove_Mode then
22150 SPARK_Specific.Generate_Dereference (N, 'm');
22151 end if;
22152
22153 if Nkind (P) = N_Selected_Component
22154 and then Present (Entry_Formal (Entity (Selector_Name (P))))
22155 then
22156 -- Case of a reference to an entry formal
22157
22158 Ent := Entry_Formal (Entity (Selector_Name (P)));
22159
22160 elsif Nkind (P) = N_Identifier
22161 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
22162 and then Present (Expression (Parent (Entity (P))))
22163 and then Nkind (Expression (Parent (Entity (P)))) =
22164 N_Reference
22165 then
22166 -- Case of a reference to a value on which side effects have
22167 -- been removed.
22168
22169 Exp := Prefix (Expression (Parent (Entity (P))));
22170 goto Continue;
22171
22172 else
22173 return;
22174 end if;
22175 end;
22176
22177 elsif Nkind_In (Exp, N_Type_Conversion,
22178 N_Unchecked_Type_Conversion)
22179 then
22180 Exp := Expression (Exp);
22181 goto Continue;
22182
22183 elsif Nkind_In (Exp, N_Slice,
22184 N_Indexed_Component,
22185 N_Selected_Component)
22186 then
22187 -- Special check, if the prefix is an access type, then return
22188 -- since we are modifying the thing pointed to, not the prefix.
22189 -- When we are expanding, most usually the prefix is replaced
22190 -- by an explicit dereference, and this test is not needed, but
22191 -- in some cases (notably -gnatc mode and generics) when we do
22192 -- not do full expansion, we need this special test.
22193
22194 if Is_Access_Type (Etype (Prefix (Exp))) then
22195 return;
22196
22197 -- Otherwise go to prefix and keep going
22198
22199 else
22200 Exp := Prefix (Exp);
22201 goto Continue;
22202 end if;
22203
22204 -- All other cases, not a modification
22205
22206 else
22207 return;
22208 end if;
22209
22210 -- Now look for entity being referenced
22211
22212 if Present (Ent) then
22213 if Is_Object (Ent) then
22214 if Comes_From_Source (Exp)
22215 or else Modification_Comes_From_Source
22216 then
22217 -- Give warning if pragma unmodified is given and we are
22218 -- sure this is a modification.
22219
22220 if Has_Pragma_Unmodified (Ent) and then Sure then
22221
22222 -- Note that the entity may be present only as a result
22223 -- of pragma Unused.
22224
22225 if Has_Pragma_Unused (Ent) then
22226 Error_Msg_NE ("??pragma Unused given for &!", N, Ent);
22227 else
22228 Error_Msg_NE
22229 ("??pragma Unmodified given for &!", N, Ent);
22230 end if;
22231 end if;
22232
22233 Set_Never_Set_In_Source (Ent, False);
22234 end if;
22235
22236 Set_Is_True_Constant (Ent, False);
22237 Set_Current_Value (Ent, Empty);
22238 Set_Is_Known_Null (Ent, False);
22239
22240 if not Can_Never_Be_Null (Ent) then
22241 Set_Is_Known_Non_Null (Ent, False);
22242 end if;
22243
22244 -- Follow renaming chain
22245
22246 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
22247 and then Present (Renamed_Object (Ent))
22248 then
22249 Exp := Renamed_Object (Ent);
22250
22251 -- If the entity is the loop variable in an iteration over
22252 -- a container, retrieve container expression to indicate
22253 -- possible modification.
22254
22255 if Present (Related_Expression (Ent))
22256 and then Nkind (Parent (Related_Expression (Ent))) =
22257 N_Iterator_Specification
22258 then
22259 Exp := Original_Node (Related_Expression (Ent));
22260 end if;
22261
22262 goto Continue;
22263
22264 -- The expression may be the renaming of a subcomponent of an
22265 -- array or container. The assignment to the subcomponent is
22266 -- a modification of the container.
22267
22268 elsif Comes_From_Source (Original_Node (Exp))
22269 and then Nkind_In (Original_Node (Exp), N_Selected_Component,
22270 N_Indexed_Component)
22271 then
22272 Exp := Prefix (Original_Node (Exp));
22273 goto Continue;
22274 end if;
22275
22276 -- Generate a reference only if the assignment comes from
22277 -- source. This excludes, for example, calls to a dispatching
22278 -- assignment operation when the left-hand side is tagged. In
22279 -- GNATprove mode, we need those references also on generated
22280 -- code, as these are used to compute the local effects of
22281 -- subprograms.
22282
22283 if Modification_Comes_From_Source or GNATprove_Mode then
22284 Generate_Reference (Ent, Exp, 'm');
22285
22286 -- If the target of the assignment is the bound variable
22287 -- in an iterator, indicate that the corresponding array
22288 -- or container is also modified.
22289
22290 if Ada_Version >= Ada_2012
22291 and then Nkind (Parent (Ent)) = N_Iterator_Specification
22292 then
22293 declare
22294 Domain : constant Node_Id := Name (Parent (Ent));
22295
22296 begin
22297 -- TBD : in the full version of the construct, the
22298 -- domain of iteration can be given by an expression.
22299
22300 if Is_Entity_Name (Domain) then
22301 Generate_Reference (Entity (Domain), Exp, 'm');
22302 Set_Is_True_Constant (Entity (Domain), False);
22303 Set_Never_Set_In_Source (Entity (Domain), False);
22304 end if;
22305 end;
22306 end if;
22307 end if;
22308 end if;
22309
22310 Kill_Checks (Ent);
22311
22312 -- If we are sure this is a modification from source, and we know
22313 -- this modifies a constant, then give an appropriate warning.
22314
22315 if Sure
22316 and then Modification_Comes_From_Source
22317 and then Overlays_Constant (Ent)
22318 and then Address_Clause_Overlay_Warnings
22319 then
22320 declare
22321 Addr : constant Node_Id := Address_Clause (Ent);
22322 O_Ent : Entity_Id;
22323 Off : Boolean;
22324
22325 begin
22326 Find_Overlaid_Entity (Addr, O_Ent, Off);
22327
22328 Error_Msg_Sloc := Sloc (Addr);
22329 Error_Msg_NE
22330 ("??constant& may be modified via address clause#",
22331 N, O_Ent);
22332 end;
22333 end if;
22334
22335 return;
22336 end if;
22337
22338 <<Continue>>
22339 null;
22340 end loop;
22341 end Note_Possible_Modification;
22342
22343 -----------------
22344 -- Null_Status --
22345 -----------------
22346
22347 function Null_Status (N : Node_Id) return Null_Status_Kind is
22348 function Is_Null_Excluding_Def (Def : Node_Id) return Boolean;
22349 -- Determine whether definition Def carries a null exclusion
22350
22351 function Null_Status_Of_Entity (Id : Entity_Id) return Null_Status_Kind;
22352 -- Determine the null status of arbitrary entity Id
22353
22354 function Null_Status_Of_Type (Typ : Entity_Id) return Null_Status_Kind;
22355 -- Determine the null status of type Typ
22356
22357 ---------------------------
22358 -- Is_Null_Excluding_Def --
22359 ---------------------------
22360
22361 function Is_Null_Excluding_Def (Def : Node_Id) return Boolean is
22362 begin
22363 return
22364 Nkind_In (Def, N_Access_Definition,
22365 N_Access_Function_Definition,
22366 N_Access_Procedure_Definition,
22367 N_Access_To_Object_Definition,
22368 N_Component_Definition,
22369 N_Derived_Type_Definition)
22370 and then Null_Exclusion_Present (Def);
22371 end Is_Null_Excluding_Def;
22372
22373 ---------------------------
22374 -- Null_Status_Of_Entity --
22375 ---------------------------
22376
22377 function Null_Status_Of_Entity
22378 (Id : Entity_Id) return Null_Status_Kind
22379 is
22380 Decl : constant Node_Id := Declaration_Node (Id);
22381 Def : Node_Id;
22382
22383 begin
22384 -- The value of an imported or exported entity may be set externally
22385 -- regardless of a null exclusion. As a result, the value cannot be
22386 -- determined statically.
22387
22388 if Is_Imported (Id) or else Is_Exported (Id) then
22389 return Unknown;
22390
22391 elsif Nkind_In (Decl, N_Component_Declaration,
22392 N_Discriminant_Specification,
22393 N_Formal_Object_Declaration,
22394 N_Object_Declaration,
22395 N_Object_Renaming_Declaration,
22396 N_Parameter_Specification)
22397 then
22398 -- A component declaration yields a non-null value when either
22399 -- its component definition or access definition carries a null
22400 -- exclusion.
22401
22402 if Nkind (Decl) = N_Component_Declaration then
22403 Def := Component_Definition (Decl);
22404
22405 if Is_Null_Excluding_Def (Def) then
22406 return Is_Non_Null;
22407 end if;
22408
22409 Def := Access_Definition (Def);
22410
22411 if Present (Def) and then Is_Null_Excluding_Def (Def) then
22412 return Is_Non_Null;
22413 end if;
22414
22415 -- A formal object declaration yields a non-null value if its
22416 -- access definition carries a null exclusion. If the object is
22417 -- default initialized, then the value depends on the expression.
22418
22419 elsif Nkind (Decl) = N_Formal_Object_Declaration then
22420 Def := Access_Definition (Decl);
22421
22422 if Present (Def) and then Is_Null_Excluding_Def (Def) then
22423 return Is_Non_Null;
22424 end if;
22425
22426 -- A constant may yield a null or non-null value depending on its
22427 -- initialization expression.
22428
22429 elsif Ekind (Id) = E_Constant then
22430 return Null_Status (Constant_Value (Id));
22431
22432 -- The construct yields a non-null value when it has a null
22433 -- exclusion.
22434
22435 elsif Null_Exclusion_Present (Decl) then
22436 return Is_Non_Null;
22437
22438 -- An object renaming declaration yields a non-null value if its
22439 -- access definition carries a null exclusion. Otherwise the value
22440 -- depends on the renamed name.
22441
22442 elsif Nkind (Decl) = N_Object_Renaming_Declaration then
22443 Def := Access_Definition (Decl);
22444
22445 if Present (Def) and then Is_Null_Excluding_Def (Def) then
22446 return Is_Non_Null;
22447
22448 else
22449 return Null_Status (Name (Decl));
22450 end if;
22451 end if;
22452 end if;
22453
22454 -- At this point the declaration of the entity does not carry a null
22455 -- exclusion and lacks an initialization expression. Check the status
22456 -- of its type.
22457
22458 return Null_Status_Of_Type (Etype (Id));
22459 end Null_Status_Of_Entity;
22460
22461 -------------------------
22462 -- Null_Status_Of_Type --
22463 -------------------------
22464
22465 function Null_Status_Of_Type (Typ : Entity_Id) return Null_Status_Kind is
22466 Curr : Entity_Id;
22467 Decl : Node_Id;
22468
22469 begin
22470 -- Traverse the type chain looking for types with null exclusion
22471
22472 Curr := Typ;
22473 while Present (Curr) and then Etype (Curr) /= Curr loop
22474 Decl := Parent (Curr);
22475
22476 -- Guard against itypes which do not always have declarations. A
22477 -- type yields a non-null value if it carries a null exclusion.
22478
22479 if Present (Decl) then
22480 if Nkind (Decl) = N_Full_Type_Declaration
22481 and then Is_Null_Excluding_Def (Type_Definition (Decl))
22482 then
22483 return Is_Non_Null;
22484
22485 elsif Nkind (Decl) = N_Subtype_Declaration
22486 and then Null_Exclusion_Present (Decl)
22487 then
22488 return Is_Non_Null;
22489 end if;
22490 end if;
22491
22492 Curr := Etype (Curr);
22493 end loop;
22494
22495 -- The type chain does not contain any null excluding types
22496
22497 return Unknown;
22498 end Null_Status_Of_Type;
22499
22500 -- Start of processing for Null_Status
22501
22502 begin
22503 -- Prevent cascaded errors or infinite loops when trying to determine
22504 -- the null status of an erroneous construct.
22505
22506 if Error_Posted (N) then
22507 return Unknown;
22508
22509 -- An allocator always creates a non-null value
22510
22511 elsif Nkind (N) = N_Allocator then
22512 return Is_Non_Null;
22513
22514 -- Taking the 'Access of something yields a non-null value
22515
22516 elsif Nkind (N) = N_Attribute_Reference
22517 and then Nam_In (Attribute_Name (N), Name_Access,
22518 Name_Unchecked_Access,
22519 Name_Unrestricted_Access)
22520 then
22521 return Is_Non_Null;
22522
22523 -- "null" yields null
22524
22525 elsif Nkind (N) = N_Null then
22526 return Is_Null;
22527
22528 -- Check the status of the operand of a type conversion
22529
22530 elsif Nkind (N) = N_Type_Conversion then
22531 return Null_Status (Expression (N));
22532
22533 -- The input denotes a reference to an entity. Determine whether the
22534 -- entity or its type yields a null or non-null value.
22535
22536 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
22537 return Null_Status_Of_Entity (Entity (N));
22538 end if;
22539
22540 -- Otherwise it is not possible to determine the null status of the
22541 -- subexpression at compile time without resorting to simple flow
22542 -- analysis.
22543
22544 return Unknown;
22545 end Null_Status;
22546
22547 --------------------------------------
22548 -- Null_To_Null_Address_Convert_OK --
22549 --------------------------------------
22550
22551 function Null_To_Null_Address_Convert_OK
22552 (N : Node_Id;
22553 Typ : Entity_Id := Empty) return Boolean
22554 is
22555 begin
22556 if not Relaxed_RM_Semantics then
22557 return False;
22558 end if;
22559
22560 if Nkind (N) = N_Null then
22561 return Present (Typ) and then Is_Descendant_Of_Address (Typ);
22562
22563 elsif Nkind_In (N, N_Op_Eq, N_Op_Ge, N_Op_Gt, N_Op_Le, N_Op_Lt, N_Op_Ne)
22564 then
22565 declare
22566 L : constant Node_Id := Left_Opnd (N);
22567 R : constant Node_Id := Right_Opnd (N);
22568
22569 begin
22570 -- We check the Etype of the complementary operand since the
22571 -- N_Null node is not decorated at this stage.
22572
22573 return
22574 ((Nkind (L) = N_Null
22575 and then Is_Descendant_Of_Address (Etype (R)))
22576 or else
22577 (Nkind (R) = N_Null
22578 and then Is_Descendant_Of_Address (Etype (L))));
22579 end;
22580 end if;
22581
22582 return False;
22583 end Null_To_Null_Address_Convert_OK;
22584
22585 ---------------------------------
22586 -- Number_Of_Elements_In_Array --
22587 ---------------------------------
22588
22589 function Number_Of_Elements_In_Array (T : Entity_Id) return Int is
22590 Indx : Node_Id;
22591 Typ : Entity_Id;
22592 Low : Node_Id;
22593 High : Node_Id;
22594 Num : Int := 1;
22595
22596 begin
22597 pragma Assert (Is_Array_Type (T));
22598
22599 Indx := First_Index (T);
22600 while Present (Indx) loop
22601 Typ := Underlying_Type (Etype (Indx));
22602
22603 -- Never look at junk bounds of a generic type
22604
22605 if Is_Generic_Type (Typ) then
22606 return 0;
22607 end if;
22608
22609 -- Check the array bounds are known at compile time and return zero
22610 -- if they are not.
22611
22612 Low := Type_Low_Bound (Typ);
22613 High := Type_High_Bound (Typ);
22614
22615 if not Compile_Time_Known_Value (Low) then
22616 return 0;
22617 elsif not Compile_Time_Known_Value (High) then
22618 return 0;
22619 else
22620 Num :=
22621 Num * UI_To_Int ((Expr_Value (High) - Expr_Value (Low) + 1));
22622 end if;
22623
22624 Next_Index (Indx);
22625 end loop;
22626
22627 return Num;
22628 end Number_Of_Elements_In_Array;
22629
22630 -------------------------
22631 -- Object_Access_Level --
22632 -------------------------
22633
22634 -- Returns the static accessibility level of the view denoted by Obj. Note
22635 -- that the value returned is the result of a call to Scope_Depth. Only
22636 -- scope depths associated with dynamic scopes can actually be returned.
22637 -- Since only relative levels matter for accessibility checking, the fact
22638 -- that the distance between successive levels of accessibility is not
22639 -- always one is immaterial (invariant: if level(E2) is deeper than
22640 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
22641
22642 function Object_Access_Level (Obj : Node_Id) return Uint is
22643 function Is_Interface_Conversion (N : Node_Id) return Boolean;
22644 -- Determine whether N is a construct of the form
22645 -- Some_Type (Operand._tag'Address)
22646 -- This construct appears in the context of dispatching calls.
22647
22648 function Reference_To (Obj : Node_Id) return Node_Id;
22649 -- An explicit dereference is created when removing side effects from
22650 -- expressions for constraint checking purposes. In this case a local
22651 -- access type is created for it. The correct access level is that of
22652 -- the original source node. We detect this case by noting that the
22653 -- prefix of the dereference is created by an object declaration whose
22654 -- initial expression is a reference.
22655
22656 -----------------------------
22657 -- Is_Interface_Conversion --
22658 -----------------------------
22659
22660 function Is_Interface_Conversion (N : Node_Id) return Boolean is
22661 begin
22662 return Nkind (N) = N_Unchecked_Type_Conversion
22663 and then Nkind (Expression (N)) = N_Attribute_Reference
22664 and then Attribute_Name (Expression (N)) = Name_Address;
22665 end Is_Interface_Conversion;
22666
22667 ------------------
22668 -- Reference_To --
22669 ------------------
22670
22671 function Reference_To (Obj : Node_Id) return Node_Id is
22672 Pref : constant Node_Id := Prefix (Obj);
22673 begin
22674 if Is_Entity_Name (Pref)
22675 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
22676 and then Present (Expression (Parent (Entity (Pref))))
22677 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
22678 then
22679 return (Prefix (Expression (Parent (Entity (Pref)))));
22680 else
22681 return Empty;
22682 end if;
22683 end Reference_To;
22684
22685 -- Local variables
22686
22687 E : Entity_Id;
22688
22689 -- Start of processing for Object_Access_Level
22690
22691 begin
22692 if Nkind (Obj) = N_Defining_Identifier
22693 or else Is_Entity_Name (Obj)
22694 then
22695 if Nkind (Obj) = N_Defining_Identifier then
22696 E := Obj;
22697 else
22698 E := Entity (Obj);
22699 end if;
22700
22701 if Is_Prival (E) then
22702 E := Prival_Link (E);
22703 end if;
22704
22705 -- If E is a type then it denotes a current instance. For this case
22706 -- we add one to the normal accessibility level of the type to ensure
22707 -- that current instances are treated as always being deeper than
22708 -- than the level of any visible named access type (see 3.10.2(21)).
22709
22710 if Is_Type (E) then
22711 return Type_Access_Level (E) + 1;
22712
22713 elsif Present (Renamed_Object (E)) then
22714 return Object_Access_Level (Renamed_Object (E));
22715
22716 -- Similarly, if E is a component of the current instance of a
22717 -- protected type, any instance of it is assumed to be at a deeper
22718 -- level than the type. For a protected object (whose type is an
22719 -- anonymous protected type) its components are at the same level
22720 -- as the type itself.
22721
22722 elsif not Is_Overloadable (E)
22723 and then Ekind (Scope (E)) = E_Protected_Type
22724 and then Comes_From_Source (Scope (E))
22725 then
22726 return Type_Access_Level (Scope (E)) + 1;
22727
22728 else
22729 -- Aliased formals of functions take their access level from the
22730 -- point of call, i.e. require a dynamic check. For static check
22731 -- purposes, this is smaller than the level of the subprogram
22732 -- itself. For procedures the aliased makes no difference.
22733
22734 if Is_Formal (E)
22735 and then Is_Aliased (E)
22736 and then Ekind (Scope (E)) = E_Function
22737 then
22738 return Type_Access_Level (Etype (E));
22739
22740 else
22741 return Scope_Depth (Enclosing_Dynamic_Scope (E));
22742 end if;
22743 end if;
22744
22745 elsif Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
22746 if Is_Access_Type (Etype (Prefix (Obj))) then
22747 return Type_Access_Level (Etype (Prefix (Obj)));
22748 else
22749 return Object_Access_Level (Prefix (Obj));
22750 end if;
22751
22752 elsif Nkind (Obj) = N_Explicit_Dereference then
22753
22754 -- If the prefix is a selected access discriminant then we make a
22755 -- recursive call on the prefix, which will in turn check the level
22756 -- of the prefix object of the selected discriminant.
22757
22758 -- In Ada 2012, if the discriminant has implicit dereference and
22759 -- the context is a selected component, treat this as an object of
22760 -- unknown scope (see below). This is necessary in compile-only mode;
22761 -- otherwise expansion will already have transformed the prefix into
22762 -- a temporary.
22763
22764 if Nkind (Prefix (Obj)) = N_Selected_Component
22765 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
22766 and then
22767 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
22768 and then
22769 (not Has_Implicit_Dereference
22770 (Entity (Selector_Name (Prefix (Obj))))
22771 or else Nkind (Parent (Obj)) /= N_Selected_Component)
22772 then
22773 return Object_Access_Level (Prefix (Obj));
22774
22775 -- Detect an interface conversion in the context of a dispatching
22776 -- call. Use the original form of the conversion to find the access
22777 -- level of the operand.
22778
22779 elsif Is_Interface (Etype (Obj))
22780 and then Is_Interface_Conversion (Prefix (Obj))
22781 and then Nkind (Original_Node (Obj)) = N_Type_Conversion
22782 then
22783 return Object_Access_Level (Original_Node (Obj));
22784
22785 elsif not Comes_From_Source (Obj) then
22786 declare
22787 Ref : constant Node_Id := Reference_To (Obj);
22788 begin
22789 if Present (Ref) then
22790 return Object_Access_Level (Ref);
22791 else
22792 return Type_Access_Level (Etype (Prefix (Obj)));
22793 end if;
22794 end;
22795
22796 else
22797 return Type_Access_Level (Etype (Prefix (Obj)));
22798 end if;
22799
22800 elsif Nkind_In (Obj, N_Type_Conversion, N_Unchecked_Type_Conversion) then
22801 return Object_Access_Level (Expression (Obj));
22802
22803 elsif Nkind (Obj) = N_Function_Call then
22804
22805 -- Function results are objects, so we get either the access level of
22806 -- the function or, in the case of an indirect call, the level of the
22807 -- access-to-subprogram type. (This code is used for Ada 95, but it
22808 -- looks wrong, because it seems that we should be checking the level
22809 -- of the call itself, even for Ada 95. However, using the Ada 2005
22810 -- version of the code causes regressions in several tests that are
22811 -- compiled with -gnat95. ???)
22812
22813 if Ada_Version < Ada_2005 then
22814 if Is_Entity_Name (Name (Obj)) then
22815 return Subprogram_Access_Level (Entity (Name (Obj)));
22816 else
22817 return Type_Access_Level (Etype (Prefix (Name (Obj))));
22818 end if;
22819
22820 -- For Ada 2005, the level of the result object of a function call is
22821 -- defined to be the level of the call's innermost enclosing master.
22822 -- We determine that by querying the depth of the innermost enclosing
22823 -- dynamic scope.
22824
22825 else
22826 Return_Master_Scope_Depth_Of_Call : declare
22827 function Innermost_Master_Scope_Depth
22828 (N : Node_Id) return Uint;
22829 -- Returns the scope depth of the given node's innermost
22830 -- enclosing dynamic scope (effectively the accessibility
22831 -- level of the innermost enclosing master).
22832
22833 ----------------------------------
22834 -- Innermost_Master_Scope_Depth --
22835 ----------------------------------
22836
22837 function Innermost_Master_Scope_Depth
22838 (N : Node_Id) return Uint
22839 is
22840 Node_Par : Node_Id := Parent (N);
22841
22842 begin
22843 -- Locate the nearest enclosing node (by traversing Parents)
22844 -- that Defining_Entity can be applied to, and return the
22845 -- depth of that entity's nearest enclosing dynamic scope.
22846
22847 while Present (Node_Par) loop
22848 case Nkind (Node_Par) is
22849 when N_Abstract_Subprogram_Declaration
22850 | N_Block_Statement
22851 | N_Body_Stub
22852 | N_Component_Declaration
22853 | N_Entry_Body
22854 | N_Entry_Declaration
22855 | N_Exception_Declaration
22856 | N_Formal_Object_Declaration
22857 | N_Formal_Package_Declaration
22858 | N_Formal_Subprogram_Declaration
22859 | N_Formal_Type_Declaration
22860 | N_Full_Type_Declaration
22861 | N_Function_Specification
22862 | N_Generic_Declaration
22863 | N_Generic_Instantiation
22864 | N_Implicit_Label_Declaration
22865 | N_Incomplete_Type_Declaration
22866 | N_Loop_Parameter_Specification
22867 | N_Number_Declaration
22868 | N_Object_Declaration
22869 | N_Package_Declaration
22870 | N_Package_Specification
22871 | N_Parameter_Specification
22872 | N_Private_Extension_Declaration
22873 | N_Private_Type_Declaration
22874 | N_Procedure_Specification
22875 | N_Proper_Body
22876 | N_Protected_Type_Declaration
22877 | N_Renaming_Declaration
22878 | N_Single_Protected_Declaration
22879 | N_Single_Task_Declaration
22880 | N_Subprogram_Declaration
22881 | N_Subtype_Declaration
22882 | N_Subunit
22883 | N_Task_Type_Declaration
22884 =>
22885 return Scope_Depth
22886 (Nearest_Dynamic_Scope
22887 (Defining_Entity (Node_Par)));
22888
22889 -- For a return statement within a function, return
22890 -- the depth of the function itself. This is not just
22891 -- a small optimization, but matters when analyzing
22892 -- the expression in an expression function before
22893 -- the body is created.
22894
22895 when N_Simple_Return_Statement =>
22896 if Ekind (Current_Scope) = E_Function then
22897 return Scope_Depth (Current_Scope);
22898 end if;
22899
22900 when others =>
22901 null;
22902 end case;
22903
22904 Node_Par := Parent (Node_Par);
22905 end loop;
22906
22907 pragma Assert (False);
22908
22909 -- Should never reach the following return
22910
22911 return Scope_Depth (Current_Scope) + 1;
22912 end Innermost_Master_Scope_Depth;
22913
22914 -- Start of processing for Return_Master_Scope_Depth_Of_Call
22915
22916 begin
22917 return Innermost_Master_Scope_Depth (Obj);
22918 end Return_Master_Scope_Depth_Of_Call;
22919 end if;
22920
22921 -- For convenience we handle qualified expressions, even though they
22922 -- aren't technically object names.
22923
22924 elsif Nkind (Obj) = N_Qualified_Expression then
22925 return Object_Access_Level (Expression (Obj));
22926
22927 -- Ditto for aggregates. They have the level of the temporary that
22928 -- will hold their value.
22929
22930 elsif Nkind (Obj) = N_Aggregate then
22931 return Object_Access_Level (Current_Scope);
22932
22933 -- Otherwise return the scope level of Standard. (If there are cases
22934 -- that fall through to this point they will be treated as having
22935 -- global accessibility for now. ???)
22936
22937 else
22938 return Scope_Depth (Standard_Standard);
22939 end if;
22940 end Object_Access_Level;
22941
22942 ----------------------------------
22943 -- Old_Requires_Transient_Scope --
22944 ----------------------------------
22945
22946 function Old_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
22947 Typ : constant Entity_Id := Underlying_Type (Id);
22948
22949 begin
22950 -- This is a private type which is not completed yet. This can only
22951 -- happen in a default expression (of a formal parameter or of a
22952 -- record component). Do not expand transient scope in this case.
22953
22954 if No (Typ) then
22955 return False;
22956
22957 -- Do not expand transient scope for non-existent procedure return
22958
22959 elsif Typ = Standard_Void_Type then
22960 return False;
22961
22962 -- Elementary types do not require a transient scope
22963
22964 elsif Is_Elementary_Type (Typ) then
22965 return False;
22966
22967 -- Generally, indefinite subtypes require a transient scope, since the
22968 -- back end cannot generate temporaries, since this is not a valid type
22969 -- for declaring an object. It might be possible to relax this in the
22970 -- future, e.g. by declaring the maximum possible space for the type.
22971
22972 elsif not Is_Definite_Subtype (Typ) then
22973 return True;
22974
22975 -- Functions returning tagged types may dispatch on result so their
22976 -- returned value is allocated on the secondary stack. Controlled
22977 -- type temporaries need finalization.
22978
22979 elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
22980 return True;
22981
22982 -- Record type
22983
22984 elsif Is_Record_Type (Typ) then
22985 declare
22986 Comp : Entity_Id;
22987
22988 begin
22989 Comp := First_Entity (Typ);
22990 while Present (Comp) loop
22991 if Ekind (Comp) = E_Component then
22992
22993 -- ???It's not clear we need a full recursive call to
22994 -- Old_Requires_Transient_Scope here. Note that the
22995 -- following can't happen.
22996
22997 pragma Assert (Is_Definite_Subtype (Etype (Comp)));
22998 pragma Assert (not Has_Controlled_Component (Etype (Comp)));
22999
23000 if Old_Requires_Transient_Scope (Etype (Comp)) then
23001 return True;
23002 end if;
23003 end if;
23004
23005 Next_Entity (Comp);
23006 end loop;
23007 end;
23008
23009 return False;
23010
23011 -- String literal types never require transient scope
23012
23013 elsif Ekind (Typ) = E_String_Literal_Subtype then
23014 return False;
23015
23016 -- Array type. Note that we already know that this is a constrained
23017 -- array, since unconstrained arrays will fail the indefinite test.
23018
23019 elsif Is_Array_Type (Typ) then
23020
23021 -- If component type requires a transient scope, the array does too
23022
23023 if Old_Requires_Transient_Scope (Component_Type (Typ)) then
23024 return True;
23025
23026 -- Otherwise, we only need a transient scope if the size depends on
23027 -- the value of one or more discriminants.
23028
23029 else
23030 return Size_Depends_On_Discriminant (Typ);
23031 end if;
23032
23033 -- All other cases do not require a transient scope
23034
23035 else
23036 pragma Assert (Is_Protected_Type (Typ) or else Is_Task_Type (Typ));
23037 return False;
23038 end if;
23039 end Old_Requires_Transient_Scope;
23040
23041 ---------------------------------
23042 -- Original_Aspect_Pragma_Name --
23043 ---------------------------------
23044
23045 function Original_Aspect_Pragma_Name (N : Node_Id) return Name_Id is
23046 Item : Node_Id;
23047 Item_Nam : Name_Id;
23048
23049 begin
23050 pragma Assert (Nkind_In (N, N_Aspect_Specification, N_Pragma));
23051
23052 Item := N;
23053
23054 -- The pragma was generated to emulate an aspect, use the original
23055 -- aspect specification.
23056
23057 if Nkind (Item) = N_Pragma and then From_Aspect_Specification (Item) then
23058 Item := Corresponding_Aspect (Item);
23059 end if;
23060
23061 -- Retrieve the name of the aspect/pragma. Note that Pre, Pre_Class,
23062 -- Post and Post_Class rewrite their pragma identifier to preserve the
23063 -- original name.
23064 -- ??? this is kludgey
23065
23066 if Nkind (Item) = N_Pragma then
23067 Item_Nam := Chars (Original_Node (Pragma_Identifier (Item)));
23068
23069 else
23070 pragma Assert (Nkind (Item) = N_Aspect_Specification);
23071 Item_Nam := Chars (Identifier (Item));
23072 end if;
23073
23074 -- Deal with 'Class by converting the name to its _XXX form
23075
23076 if Class_Present (Item) then
23077 if Item_Nam = Name_Invariant then
23078 Item_Nam := Name_uInvariant;
23079
23080 elsif Item_Nam = Name_Post then
23081 Item_Nam := Name_uPost;
23082
23083 elsif Item_Nam = Name_Pre then
23084 Item_Nam := Name_uPre;
23085
23086 elsif Nam_In (Item_Nam, Name_Type_Invariant,
23087 Name_Type_Invariant_Class)
23088 then
23089 Item_Nam := Name_uType_Invariant;
23090
23091 -- Nothing to do for other cases (e.g. a Check that derived from
23092 -- Pre_Class and has the flag set). Also we do nothing if the name
23093 -- is already in special _xxx form.
23094
23095 end if;
23096 end if;
23097
23098 return Item_Nam;
23099 end Original_Aspect_Pragma_Name;
23100
23101 --------------------------------------
23102 -- Original_Corresponding_Operation --
23103 --------------------------------------
23104
23105 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
23106 is
23107 Typ : constant Entity_Id := Find_Dispatching_Type (S);
23108
23109 begin
23110 -- If S is an inherited primitive S2 the original corresponding
23111 -- operation of S is the original corresponding operation of S2
23112
23113 if Present (Alias (S))
23114 and then Find_Dispatching_Type (Alias (S)) /= Typ
23115 then
23116 return Original_Corresponding_Operation (Alias (S));
23117
23118 -- If S overrides an inherited subprogram S2 the original corresponding
23119 -- operation of S is the original corresponding operation of S2
23120
23121 elsif Present (Overridden_Operation (S)) then
23122 return Original_Corresponding_Operation (Overridden_Operation (S));
23123
23124 -- otherwise it is S itself
23125
23126 else
23127 return S;
23128 end if;
23129 end Original_Corresponding_Operation;
23130
23131 -------------------
23132 -- Output_Entity --
23133 -------------------
23134
23135 procedure Output_Entity (Id : Entity_Id) is
23136 Scop : Entity_Id;
23137
23138 begin
23139 Scop := Scope (Id);
23140
23141 -- The entity may lack a scope when it is in the process of being
23142 -- analyzed. Use the current scope as an approximation.
23143
23144 if No (Scop) then
23145 Scop := Current_Scope;
23146 end if;
23147
23148 Output_Name (Chars (Id), Scop);
23149 end Output_Entity;
23150
23151 -----------------
23152 -- Output_Name --
23153 -----------------
23154
23155 procedure Output_Name (Nam : Name_Id; Scop : Entity_Id := Current_Scope) is
23156 begin
23157 Write_Str
23158 (Get_Name_String
23159 (Get_Qualified_Name
23160 (Nam => Nam,
23161 Suffix => No_Name,
23162 Scop => Scop)));
23163 Write_Eol;
23164 end Output_Name;
23165
23166 ----------------------
23167 -- Policy_In_Effect --
23168 ----------------------
23169
23170 function Policy_In_Effect (Policy : Name_Id) return Name_Id is
23171 function Policy_In_List (List : Node_Id) return Name_Id;
23172 -- Determine the mode of a policy in a N_Pragma list
23173
23174 --------------------
23175 -- Policy_In_List --
23176 --------------------
23177
23178 function Policy_In_List (List : Node_Id) return Name_Id is
23179 Arg1 : Node_Id;
23180 Arg2 : Node_Id;
23181 Prag : Node_Id;
23182
23183 begin
23184 Prag := List;
23185 while Present (Prag) loop
23186 Arg1 := First (Pragma_Argument_Associations (Prag));
23187 Arg2 := Next (Arg1);
23188
23189 Arg1 := Get_Pragma_Arg (Arg1);
23190 Arg2 := Get_Pragma_Arg (Arg2);
23191
23192 -- The current Check_Policy pragma matches the requested policy or
23193 -- appears in the single argument form (Assertion, policy_id).
23194
23195 if Nam_In (Chars (Arg1), Name_Assertion, Policy) then
23196 return Chars (Arg2);
23197 end if;
23198
23199 Prag := Next_Pragma (Prag);
23200 end loop;
23201
23202 return No_Name;
23203 end Policy_In_List;
23204
23205 -- Local variables
23206
23207 Kind : Name_Id;
23208
23209 -- Start of processing for Policy_In_Effect
23210
23211 begin
23212 if not Is_Valid_Assertion_Kind (Policy) then
23213 raise Program_Error;
23214 end if;
23215
23216 -- Inspect all policy pragmas that appear within scopes (if any)
23217
23218 Kind := Policy_In_List (Check_Policy_List);
23219
23220 -- Inspect all configuration policy pragmas (if any)
23221
23222 if Kind = No_Name then
23223 Kind := Policy_In_List (Check_Policy_List_Config);
23224 end if;
23225
23226 -- The context lacks policy pragmas, determine the mode based on whether
23227 -- assertions are enabled at the configuration level. This ensures that
23228 -- the policy is preserved when analyzing generics.
23229
23230 if Kind = No_Name then
23231 if Assertions_Enabled_Config then
23232 Kind := Name_Check;
23233 else
23234 Kind := Name_Ignore;
23235 end if;
23236 end if;
23237
23238 -- In CodePeer mode and GNATprove mode, we need to consider all
23239 -- assertions, unless they are disabled. Force Name_Check on
23240 -- ignored assertions.
23241
23242 if Nam_In (Kind, Name_Ignore, Name_Off)
23243 and then (CodePeer_Mode or GNATprove_Mode)
23244 then
23245 Kind := Name_Check;
23246 end if;
23247
23248 return Kind;
23249 end Policy_In_Effect;
23250
23251 ----------------------------------
23252 -- Predicate_Tests_On_Arguments --
23253 ----------------------------------
23254
23255 function Predicate_Tests_On_Arguments (Subp : Entity_Id) return Boolean is
23256 begin
23257 -- Always test predicates on indirect call
23258
23259 if Ekind (Subp) = E_Subprogram_Type then
23260 return True;
23261
23262 -- Do not test predicates on call to generated default Finalize, since
23263 -- we are not interested in whether something we are finalizing (and
23264 -- typically destroying) satisfies its predicates.
23265
23266 elsif Chars (Subp) = Name_Finalize
23267 and then not Comes_From_Source (Subp)
23268 then
23269 return False;
23270
23271 -- Do not test predicates on any internally generated routines
23272
23273 elsif Is_Internal_Name (Chars (Subp)) then
23274 return False;
23275
23276 -- Do not test predicates on call to Init_Proc, since if needed the
23277 -- predicate test will occur at some other point.
23278
23279 elsif Is_Init_Proc (Subp) then
23280 return False;
23281
23282 -- Do not test predicates on call to predicate function, since this
23283 -- would cause infinite recursion.
23284
23285 elsif Ekind (Subp) = E_Function
23286 and then (Is_Predicate_Function (Subp)
23287 or else
23288 Is_Predicate_Function_M (Subp))
23289 then
23290 return False;
23291
23292 -- For now, no other exceptions
23293
23294 else
23295 return True;
23296 end if;
23297 end Predicate_Tests_On_Arguments;
23298
23299 -----------------------
23300 -- Private_Component --
23301 -----------------------
23302
23303 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
23304 Ancestor : constant Entity_Id := Base_Type (Type_Id);
23305
23306 function Trace_Components
23307 (T : Entity_Id;
23308 Check : Boolean) return Entity_Id;
23309 -- Recursive function that does the work, and checks against circular
23310 -- definition for each subcomponent type.
23311
23312 ----------------------
23313 -- Trace_Components --
23314 ----------------------
23315
23316 function Trace_Components
23317 (T : Entity_Id;
23318 Check : Boolean) return Entity_Id
23319 is
23320 Btype : constant Entity_Id := Base_Type (T);
23321 Component : Entity_Id;
23322 P : Entity_Id;
23323 Candidate : Entity_Id := Empty;
23324
23325 begin
23326 if Check and then Btype = Ancestor then
23327 Error_Msg_N ("circular type definition", Type_Id);
23328 return Any_Type;
23329 end if;
23330
23331 if Is_Private_Type (Btype) and then not Is_Generic_Type (Btype) then
23332 if Present (Full_View (Btype))
23333 and then Is_Record_Type (Full_View (Btype))
23334 and then not Is_Frozen (Btype)
23335 then
23336 -- To indicate that the ancestor depends on a private type, the
23337 -- current Btype is sufficient. However, to check for circular
23338 -- definition we must recurse on the full view.
23339
23340 Candidate := Trace_Components (Full_View (Btype), True);
23341
23342 if Candidate = Any_Type then
23343 return Any_Type;
23344 else
23345 return Btype;
23346 end if;
23347
23348 else
23349 return Btype;
23350 end if;
23351
23352 elsif Is_Array_Type (Btype) then
23353 return Trace_Components (Component_Type (Btype), True);
23354
23355 elsif Is_Record_Type (Btype) then
23356 Component := First_Entity (Btype);
23357 while Present (Component)
23358 and then Comes_From_Source (Component)
23359 loop
23360 -- Skip anonymous types generated by constrained components
23361
23362 if not Is_Type (Component) then
23363 P := Trace_Components (Etype (Component), True);
23364
23365 if Present (P) then
23366 if P = Any_Type then
23367 return P;
23368 else
23369 Candidate := P;
23370 end if;
23371 end if;
23372 end if;
23373
23374 Next_Entity (Component);
23375 end loop;
23376
23377 return Candidate;
23378
23379 else
23380 return Empty;
23381 end if;
23382 end Trace_Components;
23383
23384 -- Start of processing for Private_Component
23385
23386 begin
23387 return Trace_Components (Type_Id, False);
23388 end Private_Component;
23389
23390 ---------------------------
23391 -- Primitive_Names_Match --
23392 ---------------------------
23393
23394 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
23395 function Non_Internal_Name (E : Entity_Id) return Name_Id;
23396 -- Given an internal name, returns the corresponding non-internal name
23397
23398 ------------------------
23399 -- Non_Internal_Name --
23400 ------------------------
23401
23402 function Non_Internal_Name (E : Entity_Id) return Name_Id is
23403 begin
23404 Get_Name_String (Chars (E));
23405 Name_Len := Name_Len - 1;
23406 return Name_Find;
23407 end Non_Internal_Name;
23408
23409 -- Start of processing for Primitive_Names_Match
23410
23411 begin
23412 pragma Assert (Present (E1) and then Present (E2));
23413
23414 return Chars (E1) = Chars (E2)
23415 or else
23416 (not Is_Internal_Name (Chars (E1))
23417 and then Is_Internal_Name (Chars (E2))
23418 and then Non_Internal_Name (E2) = Chars (E1))
23419 or else
23420 (not Is_Internal_Name (Chars (E2))
23421 and then Is_Internal_Name (Chars (E1))
23422 and then Non_Internal_Name (E1) = Chars (E2))
23423 or else
23424 (Is_Predefined_Dispatching_Operation (E1)
23425 and then Is_Predefined_Dispatching_Operation (E2)
23426 and then Same_TSS (E1, E2))
23427 or else
23428 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
23429 end Primitive_Names_Match;
23430
23431 -----------------------
23432 -- Process_End_Label --
23433 -----------------------
23434
23435 procedure Process_End_Label
23436 (N : Node_Id;
23437 Typ : Character;
23438 Ent : Entity_Id)
23439 is
23440 Loc : Source_Ptr;
23441 Nam : Node_Id;
23442 Scop : Entity_Id;
23443
23444 Label_Ref : Boolean;
23445 -- Set True if reference to end label itself is required
23446
23447 Endl : Node_Id;
23448 -- Gets set to the operator symbol or identifier that references the
23449 -- entity Ent. For the child unit case, this is the identifier from the
23450 -- designator. For other cases, this is simply Endl.
23451
23452 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
23453 -- N is an identifier node that appears as a parent unit reference in
23454 -- the case where Ent is a child unit. This procedure generates an
23455 -- appropriate cross-reference entry. E is the corresponding entity.
23456
23457 -------------------------
23458 -- Generate_Parent_Ref --
23459 -------------------------
23460
23461 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
23462 begin
23463 -- If names do not match, something weird, skip reference
23464
23465 if Chars (E) = Chars (N) then
23466
23467 -- Generate the reference. We do NOT consider this as a reference
23468 -- for unreferenced symbol purposes.
23469
23470 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
23471
23472 if Style_Check then
23473 Style.Check_Identifier (N, E);
23474 end if;
23475 end if;
23476 end Generate_Parent_Ref;
23477
23478 -- Start of processing for Process_End_Label
23479
23480 begin
23481 -- If no node, ignore. This happens in some error situations, and
23482 -- also for some internally generated structures where no end label
23483 -- references are required in any case.
23484
23485 if No (N) then
23486 return;
23487 end if;
23488
23489 -- Nothing to do if no End_Label, happens for internally generated
23490 -- constructs where we don't want an end label reference anyway. Also
23491 -- nothing to do if Endl is a string literal, which means there was
23492 -- some prior error (bad operator symbol)
23493
23494 Endl := End_Label (N);
23495
23496 if No (Endl) or else Nkind (Endl) = N_String_Literal then
23497 return;
23498 end if;
23499
23500 -- Reference node is not in extended main source unit
23501
23502 if not In_Extended_Main_Source_Unit (N) then
23503
23504 -- Generally we do not collect references except for the extended
23505 -- main source unit. The one exception is the 'e' entry for a
23506 -- package spec, where it is useful for a client to have the
23507 -- ending information to define scopes.
23508
23509 if Typ /= 'e' then
23510 return;
23511
23512 else
23513 Label_Ref := False;
23514
23515 -- For this case, we can ignore any parent references, but we
23516 -- need the package name itself for the 'e' entry.
23517
23518 if Nkind (Endl) = N_Designator then
23519 Endl := Identifier (Endl);
23520 end if;
23521 end if;
23522
23523 -- Reference is in extended main source unit
23524
23525 else
23526 Label_Ref := True;
23527
23528 -- For designator, generate references for the parent entries
23529
23530 if Nkind (Endl) = N_Designator then
23531
23532 -- Generate references for the prefix if the END line comes from
23533 -- source (otherwise we do not need these references) We climb the
23534 -- scope stack to find the expected entities.
23535
23536 if Comes_From_Source (Endl) then
23537 Nam := Name (Endl);
23538 Scop := Current_Scope;
23539 while Nkind (Nam) = N_Selected_Component loop
23540 Scop := Scope (Scop);
23541 exit when No (Scop);
23542 Generate_Parent_Ref (Selector_Name (Nam), Scop);
23543 Nam := Prefix (Nam);
23544 end loop;
23545
23546 if Present (Scop) then
23547 Generate_Parent_Ref (Nam, Scope (Scop));
23548 end if;
23549 end if;
23550
23551 Endl := Identifier (Endl);
23552 end if;
23553 end if;
23554
23555 -- If the end label is not for the given entity, then either we have
23556 -- some previous error, or this is a generic instantiation for which
23557 -- we do not need to make a cross-reference in this case anyway. In
23558 -- either case we simply ignore the call.
23559
23560 if Chars (Ent) /= Chars (Endl) then
23561 return;
23562 end if;
23563
23564 -- If label was really there, then generate a normal reference and then
23565 -- adjust the location in the end label to point past the name (which
23566 -- should almost always be the semicolon).
23567
23568 Loc := Sloc (Endl);
23569
23570 if Comes_From_Source (Endl) then
23571
23572 -- If a label reference is required, then do the style check and
23573 -- generate an l-type cross-reference entry for the label
23574
23575 if Label_Ref then
23576 if Style_Check then
23577 Style.Check_Identifier (Endl, Ent);
23578 end if;
23579
23580 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
23581 end if;
23582
23583 -- Set the location to point past the label (normally this will
23584 -- mean the semicolon immediately following the label). This is
23585 -- done for the sake of the 'e' or 't' entry generated below.
23586
23587 Get_Decoded_Name_String (Chars (Endl));
23588 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
23589
23590 else
23591 -- In SPARK mode, no missing label is allowed for packages and
23592 -- subprogram bodies. Detect those cases by testing whether
23593 -- Process_End_Label was called for a body (Typ = 't') or a package.
23594
23595 if Restriction_Check_Required (SPARK_05)
23596 and then (Typ = 't' or else Ekind (Ent) = E_Package)
23597 then
23598 Error_Msg_Node_1 := Endl;
23599 Check_SPARK_05_Restriction
23600 ("`END &` required", Endl, Force => True);
23601 end if;
23602 end if;
23603
23604 -- Now generate the e/t reference
23605
23606 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
23607
23608 -- Restore Sloc, in case modified above, since we have an identifier
23609 -- and the normal Sloc should be left set in the tree.
23610
23611 Set_Sloc (Endl, Loc);
23612 end Process_End_Label;
23613
23614 --------------------------------
23615 -- Propagate_Concurrent_Flags --
23616 --------------------------------
23617
23618 procedure Propagate_Concurrent_Flags
23619 (Typ : Entity_Id;
23620 Comp_Typ : Entity_Id)
23621 is
23622 begin
23623 if Has_Task (Comp_Typ) then
23624 Set_Has_Task (Typ);
23625 end if;
23626
23627 if Has_Protected (Comp_Typ) then
23628 Set_Has_Protected (Typ);
23629 end if;
23630
23631 if Has_Timing_Event (Comp_Typ) then
23632 Set_Has_Timing_Event (Typ);
23633 end if;
23634 end Propagate_Concurrent_Flags;
23635
23636 ------------------------------
23637 -- Propagate_DIC_Attributes --
23638 ------------------------------
23639
23640 procedure Propagate_DIC_Attributes
23641 (Typ : Entity_Id;
23642 From_Typ : Entity_Id)
23643 is
23644 DIC_Proc : Entity_Id;
23645
23646 begin
23647 if Present (Typ) and then Present (From_Typ) then
23648 pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
23649
23650 -- Nothing to do if both the source and the destination denote the
23651 -- same type.
23652
23653 if From_Typ = Typ then
23654 return;
23655
23656 -- Nothing to do when the destination denotes an incomplete type
23657 -- because the DIC is associated with the current instance of a
23658 -- private type, thus it can never apply to an incomplete type.
23659
23660 elsif Is_Incomplete_Type (Typ) then
23661 return;
23662 end if;
23663
23664 DIC_Proc := DIC_Procedure (From_Typ);
23665
23666 -- The setting of the attributes is intentionally conservative. This
23667 -- prevents accidental clobbering of enabled attributes.
23668
23669 if Has_Inherited_DIC (From_Typ)
23670 and then not Has_Inherited_DIC (Typ)
23671 then
23672 Set_Has_Inherited_DIC (Typ);
23673 end if;
23674
23675 if Has_Own_DIC (From_Typ) and then not Has_Own_DIC (Typ) then
23676 Set_Has_Own_DIC (Typ);
23677 end if;
23678
23679 if Present (DIC_Proc) and then No (DIC_Procedure (Typ)) then
23680 Set_DIC_Procedure (Typ, DIC_Proc);
23681 end if;
23682 end if;
23683 end Propagate_DIC_Attributes;
23684
23685 ------------------------------------
23686 -- Propagate_Invariant_Attributes --
23687 ------------------------------------
23688
23689 procedure Propagate_Invariant_Attributes
23690 (Typ : Entity_Id;
23691 From_Typ : Entity_Id)
23692 is
23693 Full_IP : Entity_Id;
23694 Part_IP : Entity_Id;
23695
23696 begin
23697 if Present (Typ) and then Present (From_Typ) then
23698 pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
23699
23700 -- Nothing to do if both the source and the destination denote the
23701 -- same type.
23702
23703 if From_Typ = Typ then
23704 return;
23705 end if;
23706
23707 Full_IP := Invariant_Procedure (From_Typ);
23708 Part_IP := Partial_Invariant_Procedure (From_Typ);
23709
23710 -- The setting of the attributes is intentionally conservative. This
23711 -- prevents accidental clobbering of enabled attributes.
23712
23713 if Has_Inheritable_Invariants (From_Typ)
23714 and then not Has_Inheritable_Invariants (Typ)
23715 then
23716 Set_Has_Inheritable_Invariants (Typ);
23717 end if;
23718
23719 if Has_Inherited_Invariants (From_Typ)
23720 and then not Has_Inherited_Invariants (Typ)
23721 then
23722 Set_Has_Inherited_Invariants (Typ);
23723 end if;
23724
23725 if Has_Own_Invariants (From_Typ)
23726 and then not Has_Own_Invariants (Typ)
23727 then
23728 Set_Has_Own_Invariants (Typ);
23729 end if;
23730
23731 if Present (Full_IP) and then No (Invariant_Procedure (Typ)) then
23732 Set_Invariant_Procedure (Typ, Full_IP);
23733 end if;
23734
23735 if Present (Part_IP) and then No (Partial_Invariant_Procedure (Typ))
23736 then
23737 Set_Partial_Invariant_Procedure (Typ, Part_IP);
23738 end if;
23739 end if;
23740 end Propagate_Invariant_Attributes;
23741
23742 ---------------------------------------
23743 -- Record_Possible_Part_Of_Reference --
23744 ---------------------------------------
23745
23746 procedure Record_Possible_Part_Of_Reference
23747 (Var_Id : Entity_Id;
23748 Ref : Node_Id)
23749 is
23750 Encap : constant Entity_Id := Encapsulating_State (Var_Id);
23751 Refs : Elist_Id;
23752
23753 begin
23754 -- The variable is a constituent of a single protected/task type. Such
23755 -- a variable acts as a component of the type and must appear within a
23756 -- specific region (SPARK RM 9(3)). Instead of recording the reference,
23757 -- verify its legality now.
23758
23759 if Present (Encap) and then Is_Single_Concurrent_Object (Encap) then
23760 Check_Part_Of_Reference (Var_Id, Ref);
23761
23762 -- The variable is subject to pragma Part_Of and may eventually become a
23763 -- constituent of a single protected/task type. Record the reference to
23764 -- verify its placement when the contract of the variable is analyzed.
23765
23766 elsif Present (Get_Pragma (Var_Id, Pragma_Part_Of)) then
23767 Refs := Part_Of_References (Var_Id);
23768
23769 if No (Refs) then
23770 Refs := New_Elmt_List;
23771 Set_Part_Of_References (Var_Id, Refs);
23772 end if;
23773
23774 Append_Elmt (Ref, Refs);
23775 end if;
23776 end Record_Possible_Part_Of_Reference;
23777
23778 ----------------
23779 -- Referenced --
23780 ----------------
23781
23782 function Referenced (Id : Entity_Id; Expr : Node_Id) return Boolean is
23783 Seen : Boolean := False;
23784
23785 function Is_Reference (N : Node_Id) return Traverse_Result;
23786 -- Determine whether node N denotes a reference to Id. If this is the
23787 -- case, set global flag Seen to True and stop the traversal.
23788
23789 ------------------
23790 -- Is_Reference --
23791 ------------------
23792
23793 function Is_Reference (N : Node_Id) return Traverse_Result is
23794 begin
23795 if Is_Entity_Name (N)
23796 and then Present (Entity (N))
23797 and then Entity (N) = Id
23798 then
23799 Seen := True;
23800 return Abandon;
23801 else
23802 return OK;
23803 end if;
23804 end Is_Reference;
23805
23806 procedure Inspect_Expression is new Traverse_Proc (Is_Reference);
23807
23808 -- Start of processing for Referenced
23809
23810 begin
23811 Inspect_Expression (Expr);
23812 return Seen;
23813 end Referenced;
23814
23815 ------------------------------------
23816 -- References_Generic_Formal_Type --
23817 ------------------------------------
23818
23819 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
23820
23821 function Process (N : Node_Id) return Traverse_Result;
23822 -- Process one node in search for generic formal type
23823
23824 -------------
23825 -- Process --
23826 -------------
23827
23828 function Process (N : Node_Id) return Traverse_Result is
23829 begin
23830 if Nkind (N) in N_Has_Entity then
23831 declare
23832 E : constant Entity_Id := Entity (N);
23833 begin
23834 if Present (E) then
23835 if Is_Generic_Type (E) then
23836 return Abandon;
23837 elsif Present (Etype (E))
23838 and then Is_Generic_Type (Etype (E))
23839 then
23840 return Abandon;
23841 end if;
23842 end if;
23843 end;
23844 end if;
23845
23846 return Atree.OK;
23847 end Process;
23848
23849 function Traverse is new Traverse_Func (Process);
23850 -- Traverse tree to look for generic type
23851
23852 begin
23853 if Inside_A_Generic then
23854 return Traverse (N) = Abandon;
23855 else
23856 return False;
23857 end if;
23858 end References_Generic_Formal_Type;
23859
23860 -------------------------------
23861 -- Remove_Entity_And_Homonym --
23862 -------------------------------
23863
23864 procedure Remove_Entity_And_Homonym (Id : Entity_Id) is
23865 begin
23866 Remove_Entity (Id);
23867 Remove_Homonym (Id);
23868 end Remove_Entity_And_Homonym;
23869
23870 --------------------
23871 -- Remove_Homonym --
23872 --------------------
23873
23874 procedure Remove_Homonym (Id : Entity_Id) is
23875 Hom : Entity_Id;
23876 Prev : Entity_Id := Empty;
23877
23878 begin
23879 if Id = Current_Entity (Id) then
23880 if Present (Homonym (Id)) then
23881 Set_Current_Entity (Homonym (Id));
23882 else
23883 Set_Name_Entity_Id (Chars (Id), Empty);
23884 end if;
23885
23886 else
23887 Hom := Current_Entity (Id);
23888 while Present (Hom) and then Hom /= Id loop
23889 Prev := Hom;
23890 Hom := Homonym (Hom);
23891 end loop;
23892
23893 -- If Id is not on the homonym chain, nothing to do
23894
23895 if Present (Hom) then
23896 Set_Homonym (Prev, Homonym (Id));
23897 end if;
23898 end if;
23899 end Remove_Homonym;
23900
23901 ------------------------------
23902 -- Remove_Overloaded_Entity --
23903 ------------------------------
23904
23905 procedure Remove_Overloaded_Entity (Id : Entity_Id) is
23906 procedure Remove_Primitive_Of (Typ : Entity_Id);
23907 -- Remove primitive subprogram Id from the list of primitives that
23908 -- belong to type Typ.
23909
23910 -------------------------
23911 -- Remove_Primitive_Of --
23912 -------------------------
23913
23914 procedure Remove_Primitive_Of (Typ : Entity_Id) is
23915 Prims : Elist_Id;
23916
23917 begin
23918 if Is_Tagged_Type (Typ) then
23919 Prims := Direct_Primitive_Operations (Typ);
23920
23921 if Present (Prims) then
23922 Remove (Prims, Id);
23923 end if;
23924 end if;
23925 end Remove_Primitive_Of;
23926
23927 -- Local variables
23928
23929 Formal : Entity_Id;
23930
23931 -- Start of processing for Remove_Overloaded_Entity
23932
23933 begin
23934 Remove_Entity_And_Homonym (Id);
23935
23936 -- The entity denotes a primitive subprogram. Remove it from the list of
23937 -- primitives of the associated controlling type.
23938
23939 if Ekind_In (Id, E_Function, E_Procedure) and then Is_Primitive (Id) then
23940 Formal := First_Formal (Id);
23941 while Present (Formal) loop
23942 if Is_Controlling_Formal (Formal) then
23943 Remove_Primitive_Of (Etype (Formal));
23944 exit;
23945 end if;
23946
23947 Next_Formal (Formal);
23948 end loop;
23949
23950 if Ekind (Id) = E_Function and then Has_Controlling_Result (Id) then
23951 Remove_Primitive_Of (Etype (Id));
23952 end if;
23953 end if;
23954 end Remove_Overloaded_Entity;
23955
23956 ---------------------
23957 -- Rep_To_Pos_Flag --
23958 ---------------------
23959
23960 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
23961 begin
23962 return New_Occurrence_Of
23963 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
23964 end Rep_To_Pos_Flag;
23965
23966 --------------------
23967 -- Require_Entity --
23968 --------------------
23969
23970 procedure Require_Entity (N : Node_Id) is
23971 begin
23972 if Is_Entity_Name (N) and then No (Entity (N)) then
23973 if Total_Errors_Detected /= 0 then
23974 Set_Entity (N, Any_Id);
23975 else
23976 raise Program_Error;
23977 end if;
23978 end if;
23979 end Require_Entity;
23980
23981 ------------------------------
23982 -- Requires_Transient_Scope --
23983 ------------------------------
23984
23985 -- A transient scope is required when variable-sized temporaries are
23986 -- allocated on the secondary stack, or when finalization actions must be
23987 -- generated before the next instruction.
23988
23989 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
23990 Old_Result : constant Boolean := Old_Requires_Transient_Scope (Id);
23991
23992 begin
23993 if Debug_Flag_QQ then
23994 return Old_Result;
23995 end if;
23996
23997 declare
23998 New_Result : constant Boolean := New_Requires_Transient_Scope (Id);
23999
24000 begin
24001 -- Assert that we're not putting things on the secondary stack if we
24002 -- didn't before; we are trying to AVOID secondary stack when
24003 -- possible.
24004
24005 if not Old_Result then
24006 pragma Assert (not New_Result);
24007 null;
24008 end if;
24009
24010 if New_Result /= Old_Result then
24011 Results_Differ (Id, Old_Result, New_Result);
24012 end if;
24013
24014 return New_Result;
24015 end;
24016 end Requires_Transient_Scope;
24017
24018 --------------------
24019 -- Results_Differ --
24020 --------------------
24021
24022 procedure Results_Differ
24023 (Id : Entity_Id;
24024 Old_Val : Boolean;
24025 New_Val : Boolean)
24026 is
24027 begin
24028 if False then -- False to disable; True for debugging
24029 Treepr.Print_Tree_Node (Id);
24030
24031 if Old_Val = New_Val then
24032 raise Program_Error;
24033 end if;
24034 end if;
24035 end Results_Differ;
24036
24037 --------------------------
24038 -- Reset_Analyzed_Flags --
24039 --------------------------
24040
24041 procedure Reset_Analyzed_Flags (N : Node_Id) is
24042 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
24043 -- Function used to reset Analyzed flags in tree. Note that we do
24044 -- not reset Analyzed flags in entities, since there is no need to
24045 -- reanalyze entities, and indeed, it is wrong to do so, since it
24046 -- can result in generating auxiliary stuff more than once.
24047
24048 --------------------
24049 -- Clear_Analyzed --
24050 --------------------
24051
24052 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
24053 begin
24054 if Nkind (N) not in N_Entity then
24055 Set_Analyzed (N, False);
24056 end if;
24057
24058 return OK;
24059 end Clear_Analyzed;
24060
24061 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
24062
24063 -- Start of processing for Reset_Analyzed_Flags
24064
24065 begin
24066 Reset_Analyzed (N);
24067 end Reset_Analyzed_Flags;
24068
24069 ------------------------
24070 -- Restore_SPARK_Mode --
24071 ------------------------
24072
24073 procedure Restore_SPARK_Mode
24074 (Mode : SPARK_Mode_Type;
24075 Prag : Node_Id)
24076 is
24077 begin
24078 SPARK_Mode := Mode;
24079 SPARK_Mode_Pragma := Prag;
24080 end Restore_SPARK_Mode;
24081
24082 --------------------------------
24083 -- Returns_Unconstrained_Type --
24084 --------------------------------
24085
24086 function Returns_Unconstrained_Type (Subp : Entity_Id) return Boolean is
24087 begin
24088 return Ekind (Subp) = E_Function
24089 and then not Is_Scalar_Type (Etype (Subp))
24090 and then not Is_Access_Type (Etype (Subp))
24091 and then not Is_Constrained (Etype (Subp));
24092 end Returns_Unconstrained_Type;
24093
24094 ----------------------------
24095 -- Root_Type_Of_Full_View --
24096 ----------------------------
24097
24098 function Root_Type_Of_Full_View (T : Entity_Id) return Entity_Id is
24099 Rtyp : constant Entity_Id := Root_Type (T);
24100
24101 begin
24102 -- The root type of the full view may itself be a private type. Keep
24103 -- looking for the ultimate derivation parent.
24104
24105 if Is_Private_Type (Rtyp) and then Present (Full_View (Rtyp)) then
24106 return Root_Type_Of_Full_View (Full_View (Rtyp));
24107 else
24108 return Rtyp;
24109 end if;
24110 end Root_Type_Of_Full_View;
24111
24112 ---------------------------
24113 -- Safe_To_Capture_Value --
24114 ---------------------------
24115
24116 function Safe_To_Capture_Value
24117 (N : Node_Id;
24118 Ent : Entity_Id;
24119 Cond : Boolean := False) return Boolean
24120 is
24121 begin
24122 -- The only entities for which we track constant values are variables
24123 -- which are not renamings, constants, out parameters, and in out
24124 -- parameters, so check if we have this case.
24125
24126 -- Note: it may seem odd to track constant values for constants, but in
24127 -- fact this routine is used for other purposes than simply capturing
24128 -- the value. In particular, the setting of Known[_Non]_Null.
24129
24130 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
24131 or else
24132 Ekind_In (Ent, E_Constant, E_Out_Parameter, E_In_Out_Parameter)
24133 then
24134 null;
24135
24136 -- For conditionals, we also allow loop parameters and all formals,
24137 -- including in parameters.
24138
24139 elsif Cond and then Ekind_In (Ent, E_Loop_Parameter, E_In_Parameter) then
24140 null;
24141
24142 -- For all other cases, not just unsafe, but impossible to capture
24143 -- Current_Value, since the above are the only entities which have
24144 -- Current_Value fields.
24145
24146 else
24147 return False;
24148 end if;
24149
24150 -- Skip if volatile or aliased, since funny things might be going on in
24151 -- these cases which we cannot necessarily track. Also skip any variable
24152 -- for which an address clause is given, or whose address is taken. Also
24153 -- never capture value of library level variables (an attempt to do so
24154 -- can occur in the case of package elaboration code).
24155
24156 if Treat_As_Volatile (Ent)
24157 or else Is_Aliased (Ent)
24158 or else Present (Address_Clause (Ent))
24159 or else Address_Taken (Ent)
24160 or else (Is_Library_Level_Entity (Ent)
24161 and then Ekind (Ent) = E_Variable)
24162 then
24163 return False;
24164 end if;
24165
24166 -- OK, all above conditions are met. We also require that the scope of
24167 -- the reference be the same as the scope of the entity, not counting
24168 -- packages and blocks and loops.
24169
24170 declare
24171 E_Scope : constant Entity_Id := Scope (Ent);
24172 R_Scope : Entity_Id;
24173
24174 begin
24175 R_Scope := Current_Scope;
24176 while R_Scope /= Standard_Standard loop
24177 exit when R_Scope = E_Scope;
24178
24179 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
24180 return False;
24181 else
24182 R_Scope := Scope (R_Scope);
24183 end if;
24184 end loop;
24185 end;
24186
24187 -- We also require that the reference does not appear in a context
24188 -- where it is not sure to be executed (i.e. a conditional context
24189 -- or an exception handler). We skip this if Cond is True, since the
24190 -- capturing of values from conditional tests handles this ok.
24191
24192 if Cond then
24193 return True;
24194 end if;
24195
24196 declare
24197 Desc : Node_Id;
24198 P : Node_Id;
24199
24200 begin
24201 Desc := N;
24202
24203 -- Seems dubious that case expressions are not handled here ???
24204
24205 P := Parent (N);
24206 while Present (P) loop
24207 if Nkind (P) = N_If_Statement
24208 or else Nkind (P) = N_Case_Statement
24209 or else (Nkind (P) in N_Short_Circuit
24210 and then Desc = Right_Opnd (P))
24211 or else (Nkind (P) = N_If_Expression
24212 and then Desc /= First (Expressions (P)))
24213 or else Nkind (P) = N_Exception_Handler
24214 or else Nkind (P) = N_Selective_Accept
24215 or else Nkind (P) = N_Conditional_Entry_Call
24216 or else Nkind (P) = N_Timed_Entry_Call
24217 or else Nkind (P) = N_Asynchronous_Select
24218 then
24219 return False;
24220
24221 else
24222 Desc := P;
24223 P := Parent (P);
24224
24225 -- A special Ada 2012 case: the original node may be part
24226 -- of the else_actions of a conditional expression, in which
24227 -- case it might not have been expanded yet, and appears in
24228 -- a non-syntactic list of actions. In that case it is clearly
24229 -- not safe to save a value.
24230
24231 if No (P)
24232 and then Is_List_Member (Desc)
24233 and then No (Parent (List_Containing (Desc)))
24234 then
24235 return False;
24236 end if;
24237 end if;
24238 end loop;
24239 end;
24240
24241 -- OK, looks safe to set value
24242
24243 return True;
24244 end Safe_To_Capture_Value;
24245
24246 ---------------
24247 -- Same_Name --
24248 ---------------
24249
24250 function Same_Name (N1, N2 : Node_Id) return Boolean is
24251 K1 : constant Node_Kind := Nkind (N1);
24252 K2 : constant Node_Kind := Nkind (N2);
24253
24254 begin
24255 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
24256 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
24257 then
24258 return Chars (N1) = Chars (N2);
24259
24260 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
24261 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
24262 then
24263 return Same_Name (Selector_Name (N1), Selector_Name (N2))
24264 and then Same_Name (Prefix (N1), Prefix (N2));
24265
24266 else
24267 return False;
24268 end if;
24269 end Same_Name;
24270
24271 -----------------
24272 -- Same_Object --
24273 -----------------
24274
24275 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
24276 N1 : constant Node_Id := Original_Node (Node1);
24277 N2 : constant Node_Id := Original_Node (Node2);
24278 -- We do the tests on original nodes, since we are most interested
24279 -- in the original source, not any expansion that got in the way.
24280
24281 K1 : constant Node_Kind := Nkind (N1);
24282 K2 : constant Node_Kind := Nkind (N2);
24283
24284 begin
24285 -- First case, both are entities with same entity
24286
24287 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
24288 declare
24289 EN1 : constant Entity_Id := Entity (N1);
24290 EN2 : constant Entity_Id := Entity (N2);
24291 begin
24292 if Present (EN1) and then Present (EN2)
24293 and then (Ekind_In (EN1, E_Variable, E_Constant)
24294 or else Is_Formal (EN1))
24295 and then EN1 = EN2
24296 then
24297 return True;
24298 end if;
24299 end;
24300 end if;
24301
24302 -- Second case, selected component with same selector, same record
24303
24304 if K1 = N_Selected_Component
24305 and then K2 = N_Selected_Component
24306 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
24307 then
24308 return Same_Object (Prefix (N1), Prefix (N2));
24309
24310 -- Third case, indexed component with same subscripts, same array
24311
24312 elsif K1 = N_Indexed_Component
24313 and then K2 = N_Indexed_Component
24314 and then Same_Object (Prefix (N1), Prefix (N2))
24315 then
24316 declare
24317 E1, E2 : Node_Id;
24318 begin
24319 E1 := First (Expressions (N1));
24320 E2 := First (Expressions (N2));
24321 while Present (E1) loop
24322 if not Same_Value (E1, E2) then
24323 return False;
24324 else
24325 Next (E1);
24326 Next (E2);
24327 end if;
24328 end loop;
24329
24330 return True;
24331 end;
24332
24333 -- Fourth case, slice of same array with same bounds
24334
24335 elsif K1 = N_Slice
24336 and then K2 = N_Slice
24337 and then Nkind (Discrete_Range (N1)) = N_Range
24338 and then Nkind (Discrete_Range (N2)) = N_Range
24339 and then Same_Value (Low_Bound (Discrete_Range (N1)),
24340 Low_Bound (Discrete_Range (N2)))
24341 and then Same_Value (High_Bound (Discrete_Range (N1)),
24342 High_Bound (Discrete_Range (N2)))
24343 then
24344 return Same_Name (Prefix (N1), Prefix (N2));
24345
24346 -- All other cases, not clearly the same object
24347
24348 else
24349 return False;
24350 end if;
24351 end Same_Object;
24352
24353 ---------------
24354 -- Same_Type --
24355 ---------------
24356
24357 function Same_Type (T1, T2 : Entity_Id) return Boolean is
24358 begin
24359 if T1 = T2 then
24360 return True;
24361
24362 elsif not Is_Constrained (T1)
24363 and then not Is_Constrained (T2)
24364 and then Base_Type (T1) = Base_Type (T2)
24365 then
24366 return True;
24367
24368 -- For now don't bother with case of identical constraints, to be
24369 -- fiddled with later on perhaps (this is only used for optimization
24370 -- purposes, so it is not critical to do a best possible job)
24371
24372 else
24373 return False;
24374 end if;
24375 end Same_Type;
24376
24377 ----------------
24378 -- Same_Value --
24379 ----------------
24380
24381 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
24382 begin
24383 if Compile_Time_Known_Value (Node1)
24384 and then Compile_Time_Known_Value (Node2)
24385 then
24386 -- Handle properly compile-time expressions that are not
24387 -- scalar.
24388
24389 if Is_String_Type (Etype (Node1)) then
24390 return Expr_Value_S (Node1) = Expr_Value_S (Node2);
24391
24392 else
24393 return Expr_Value (Node1) = Expr_Value (Node2);
24394 end if;
24395
24396 elsif Same_Object (Node1, Node2) then
24397 return True;
24398 else
24399 return False;
24400 end if;
24401 end Same_Value;
24402
24403 --------------------
24404 -- Set_SPARK_Mode --
24405 --------------------
24406
24407 procedure Set_SPARK_Mode (Context : Entity_Id) is
24408 begin
24409 -- Do not consider illegal or partially decorated constructs
24410
24411 if Ekind (Context) = E_Void or else Error_Posted (Context) then
24412 null;
24413
24414 elsif Present (SPARK_Pragma (Context)) then
24415 Install_SPARK_Mode
24416 (Mode => Get_SPARK_Mode_From_Annotation (SPARK_Pragma (Context)),
24417 Prag => SPARK_Pragma (Context));
24418 end if;
24419 end Set_SPARK_Mode;
24420
24421 -------------------------
24422 -- Scalar_Part_Present --
24423 -------------------------
24424
24425 function Scalar_Part_Present (Typ : Entity_Id) return Boolean is
24426 Val_Typ : constant Entity_Id := Validated_View (Typ);
24427 Field : Entity_Id;
24428
24429 begin
24430 if Is_Scalar_Type (Val_Typ) then
24431 return True;
24432
24433 elsif Is_Array_Type (Val_Typ) then
24434 return Scalar_Part_Present (Component_Type (Val_Typ));
24435
24436 elsif Is_Record_Type (Val_Typ) then
24437 Field := First_Component_Or_Discriminant (Val_Typ);
24438 while Present (Field) loop
24439 if Scalar_Part_Present (Etype (Field)) then
24440 return True;
24441 end if;
24442
24443 Next_Component_Or_Discriminant (Field);
24444 end loop;
24445 end if;
24446
24447 return False;
24448 end Scalar_Part_Present;
24449
24450 ------------------------
24451 -- Scope_Is_Transient --
24452 ------------------------
24453
24454 function Scope_Is_Transient return Boolean is
24455 begin
24456 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
24457 end Scope_Is_Transient;
24458
24459 ------------------
24460 -- Scope_Within --
24461 ------------------
24462
24463 function Scope_Within
24464 (Inner : Entity_Id;
24465 Outer : Entity_Id) return Boolean
24466 is
24467 Curr : Entity_Id;
24468
24469 begin
24470 Curr := Inner;
24471 while Present (Curr) and then Curr /= Standard_Standard loop
24472 Curr := Scope (Curr);
24473
24474 if Curr = Outer then
24475 return True;
24476
24477 -- A selective accept body appears within a task type, but the
24478 -- enclosing subprogram is the procedure of the task body.
24479
24480 elsif Ekind (Curr) = E_Task_Type
24481 and then Outer = Task_Body_Procedure (Curr)
24482 then
24483 return True;
24484
24485 -- Ditto for the body of a protected operation
24486
24487 elsif Is_Subprogram (Curr)
24488 and then Outer = Protected_Body_Subprogram (Curr)
24489 then
24490 return True;
24491
24492 -- Outside of its scope, a synchronized type may just be private
24493
24494 elsif Is_Private_Type (Curr)
24495 and then Present (Full_View (Curr))
24496 and then Is_Concurrent_Type (Full_View (Curr))
24497 then
24498 return Scope_Within (Full_View (Curr), Outer);
24499 end if;
24500 end loop;
24501
24502 return False;
24503 end Scope_Within;
24504
24505 --------------------------
24506 -- Scope_Within_Or_Same --
24507 --------------------------
24508
24509 function Scope_Within_Or_Same
24510 (Inner : Entity_Id;
24511 Outer : Entity_Id) return Boolean
24512 is
24513 Curr : Entity_Id := Inner;
24514
24515 begin
24516 -- Similar to the above, but check for scope identity first
24517
24518 while Present (Curr) and then Curr /= Standard_Standard loop
24519 if Curr = Outer then
24520 return True;
24521
24522 elsif Ekind (Curr) = E_Task_Type
24523 and then Outer = Task_Body_Procedure (Curr)
24524 then
24525 return True;
24526
24527 elsif Is_Subprogram (Curr)
24528 and then Outer = Protected_Body_Subprogram (Curr)
24529 then
24530 return True;
24531
24532 elsif Is_Private_Type (Curr)
24533 and then Present (Full_View (Curr))
24534 then
24535 if Full_View (Curr) = Outer then
24536 return True;
24537 else
24538 return Scope_Within (Full_View (Curr), Outer);
24539 end if;
24540 end if;
24541
24542 Curr := Scope (Curr);
24543 end loop;
24544
24545 return False;
24546 end Scope_Within_Or_Same;
24547
24548 --------------------
24549 -- Set_Convention --
24550 --------------------
24551
24552 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
24553 begin
24554 Basic_Set_Convention (E, Val);
24555
24556 if Is_Type (E)
24557 and then Is_Access_Subprogram_Type (Base_Type (E))
24558 and then Has_Foreign_Convention (E)
24559 then
24560 Set_Can_Use_Internal_Rep (E, False);
24561 end if;
24562
24563 -- If E is an object, including a component, and the type of E is an
24564 -- anonymous access type with no convention set, then also set the
24565 -- convention of the anonymous access type. We do not do this for
24566 -- anonymous protected types, since protected types always have the
24567 -- default convention.
24568
24569 if Present (Etype (E))
24570 and then (Is_Object (E)
24571
24572 -- Allow E_Void (happens for pragma Convention appearing
24573 -- in the middle of a record applying to a component)
24574
24575 or else Ekind (E) = E_Void)
24576 then
24577 declare
24578 Typ : constant Entity_Id := Etype (E);
24579
24580 begin
24581 if Ekind_In (Typ, E_Anonymous_Access_Type,
24582 E_Anonymous_Access_Subprogram_Type)
24583 and then not Has_Convention_Pragma (Typ)
24584 then
24585 Basic_Set_Convention (Typ, Val);
24586 Set_Has_Convention_Pragma (Typ);
24587
24588 -- And for the access subprogram type, deal similarly with the
24589 -- designated E_Subprogram_Type, which is always internal.
24590
24591 if Ekind (Typ) = E_Anonymous_Access_Subprogram_Type then
24592 declare
24593 Dtype : constant Entity_Id := Designated_Type (Typ);
24594 begin
24595 if Ekind (Dtype) = E_Subprogram_Type
24596 and then not Has_Convention_Pragma (Dtype)
24597 then
24598 Basic_Set_Convention (Dtype, Val);
24599 Set_Has_Convention_Pragma (Dtype);
24600 end if;
24601 end;
24602 end if;
24603 end if;
24604 end;
24605 end if;
24606 end Set_Convention;
24607
24608 ------------------------
24609 -- Set_Current_Entity --
24610 ------------------------
24611
24612 -- The given entity is to be set as the currently visible definition of its
24613 -- associated name (i.e. the Node_Id associated with its name). All we have
24614 -- to do is to get the name from the identifier, and then set the
24615 -- associated Node_Id to point to the given entity.
24616
24617 procedure Set_Current_Entity (E : Entity_Id) is
24618 begin
24619 Set_Name_Entity_Id (Chars (E), E);
24620 end Set_Current_Entity;
24621
24622 ---------------------------
24623 -- Set_Debug_Info_Needed --
24624 ---------------------------
24625
24626 procedure Set_Debug_Info_Needed (T : Entity_Id) is
24627
24628 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
24629 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
24630 -- Used to set debug info in a related node if not set already
24631
24632 --------------------------------------
24633 -- Set_Debug_Info_Needed_If_Not_Set --
24634 --------------------------------------
24635
24636 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
24637 begin
24638 if Present (E) and then not Needs_Debug_Info (E) then
24639 Set_Debug_Info_Needed (E);
24640
24641 -- For a private type, indicate that the full view also needs
24642 -- debug information.
24643
24644 if Is_Type (E)
24645 and then Is_Private_Type (E)
24646 and then Present (Full_View (E))
24647 then
24648 Set_Debug_Info_Needed (Full_View (E));
24649 end if;
24650 end if;
24651 end Set_Debug_Info_Needed_If_Not_Set;
24652
24653 -- Start of processing for Set_Debug_Info_Needed
24654
24655 begin
24656 -- Nothing to do if there is no available entity
24657
24658 if No (T) then
24659 return;
24660
24661 -- Nothing to do for an entity with suppressed debug information
24662
24663 elsif Debug_Info_Off (T) then
24664 return;
24665
24666 -- Nothing to do for an ignored Ghost entity because the entity will be
24667 -- eliminated from the tree.
24668
24669 elsif Is_Ignored_Ghost_Entity (T) then
24670 return;
24671
24672 -- Nothing to do if entity comes from a predefined file. Library files
24673 -- are compiled without debug information, but inlined bodies of these
24674 -- routines may appear in user code, and debug information on them ends
24675 -- up complicating debugging the user code.
24676
24677 elsif In_Inlined_Body and then In_Predefined_Unit (T) then
24678 Set_Needs_Debug_Info (T, False);
24679 end if;
24680
24681 -- Set flag in entity itself. Note that we will go through the following
24682 -- circuitry even if the flag is already set on T. That's intentional,
24683 -- it makes sure that the flag will be set in subsidiary entities.
24684
24685 Set_Needs_Debug_Info (T);
24686
24687 -- Set flag on subsidiary entities if not set already
24688
24689 if Is_Object (T) then
24690 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
24691
24692 elsif Is_Type (T) then
24693 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
24694
24695 if Is_Record_Type (T) then
24696 declare
24697 Ent : Entity_Id := First_Entity (T);
24698 begin
24699 while Present (Ent) loop
24700 Set_Debug_Info_Needed_If_Not_Set (Ent);
24701 Next_Entity (Ent);
24702 end loop;
24703 end;
24704
24705 -- For a class wide subtype, we also need debug information
24706 -- for the equivalent type.
24707
24708 if Ekind (T) = E_Class_Wide_Subtype then
24709 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
24710 end if;
24711
24712 elsif Is_Array_Type (T) then
24713 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
24714
24715 declare
24716 Indx : Node_Id := First_Index (T);
24717 begin
24718 while Present (Indx) loop
24719 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
24720 Indx := Next_Index (Indx);
24721 end loop;
24722 end;
24723
24724 -- For a packed array type, we also need debug information for
24725 -- the type used to represent the packed array. Conversely, we
24726 -- also need it for the former if we need it for the latter.
24727
24728 if Is_Packed (T) then
24729 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Impl_Type (T));
24730 end if;
24731
24732 if Is_Packed_Array_Impl_Type (T) then
24733 Set_Debug_Info_Needed_If_Not_Set (Original_Array_Type (T));
24734 end if;
24735
24736 elsif Is_Access_Type (T) then
24737 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
24738
24739 elsif Is_Private_Type (T) then
24740 declare
24741 FV : constant Entity_Id := Full_View (T);
24742
24743 begin
24744 Set_Debug_Info_Needed_If_Not_Set (FV);
24745
24746 -- If the full view is itself a derived private type, we need
24747 -- debug information on its underlying type.
24748
24749 if Present (FV)
24750 and then Is_Private_Type (FV)
24751 and then Present (Underlying_Full_View (FV))
24752 then
24753 Set_Needs_Debug_Info (Underlying_Full_View (FV));
24754 end if;
24755 end;
24756
24757 elsif Is_Protected_Type (T) then
24758 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
24759
24760 elsif Is_Scalar_Type (T) then
24761
24762 -- If the subrange bounds are materialized by dedicated constant
24763 -- objects, also include them in the debug info to make sure the
24764 -- debugger can properly use them.
24765
24766 if Present (Scalar_Range (T))
24767 and then Nkind (Scalar_Range (T)) = N_Range
24768 then
24769 declare
24770 Low_Bnd : constant Node_Id := Type_Low_Bound (T);
24771 High_Bnd : constant Node_Id := Type_High_Bound (T);
24772
24773 begin
24774 if Is_Entity_Name (Low_Bnd) then
24775 Set_Debug_Info_Needed_If_Not_Set (Entity (Low_Bnd));
24776 end if;
24777
24778 if Is_Entity_Name (High_Bnd) then
24779 Set_Debug_Info_Needed_If_Not_Set (Entity (High_Bnd));
24780 end if;
24781 end;
24782 end if;
24783 end if;
24784 end if;
24785 end Set_Debug_Info_Needed;
24786
24787 ----------------------------
24788 -- Set_Entity_With_Checks --
24789 ----------------------------
24790
24791 procedure Set_Entity_With_Checks (N : Node_Id; Val : Entity_Id) is
24792 Val_Actual : Entity_Id;
24793 Nod : Node_Id;
24794 Post_Node : Node_Id;
24795
24796 begin
24797 -- Unconditionally set the entity
24798
24799 Set_Entity (N, Val);
24800
24801 -- The node to post on is the selector in the case of an expanded name,
24802 -- and otherwise the node itself.
24803
24804 if Nkind (N) = N_Expanded_Name then
24805 Post_Node := Selector_Name (N);
24806 else
24807 Post_Node := N;
24808 end if;
24809
24810 -- Check for violation of No_Fixed_IO
24811
24812 if Restriction_Check_Required (No_Fixed_IO)
24813 and then
24814 ((RTU_Loaded (Ada_Text_IO)
24815 and then (Is_RTE (Val, RE_Decimal_IO)
24816 or else
24817 Is_RTE (Val, RE_Fixed_IO)))
24818
24819 or else
24820 (RTU_Loaded (Ada_Wide_Text_IO)
24821 and then (Is_RTE (Val, RO_WT_Decimal_IO)
24822 or else
24823 Is_RTE (Val, RO_WT_Fixed_IO)))
24824
24825 or else
24826 (RTU_Loaded (Ada_Wide_Wide_Text_IO)
24827 and then (Is_RTE (Val, RO_WW_Decimal_IO)
24828 or else
24829 Is_RTE (Val, RO_WW_Fixed_IO))))
24830
24831 -- A special extra check, don't complain about a reference from within
24832 -- the Ada.Interrupts package itself!
24833
24834 and then not In_Same_Extended_Unit (N, Val)
24835 then
24836 Check_Restriction (No_Fixed_IO, Post_Node);
24837 end if;
24838
24839 -- Remaining checks are only done on source nodes. Note that we test
24840 -- for violation of No_Fixed_IO even on non-source nodes, because the
24841 -- cases for checking violations of this restriction are instantiations
24842 -- where the reference in the instance has Comes_From_Source False.
24843
24844 if not Comes_From_Source (N) then
24845 return;
24846 end if;
24847
24848 -- Check for violation of No_Abort_Statements, which is triggered by
24849 -- call to Ada.Task_Identification.Abort_Task.
24850
24851 if Restriction_Check_Required (No_Abort_Statements)
24852 and then (Is_RTE (Val, RE_Abort_Task))
24853
24854 -- A special extra check, don't complain about a reference from within
24855 -- the Ada.Task_Identification package itself!
24856
24857 and then not In_Same_Extended_Unit (N, Val)
24858 then
24859 Check_Restriction (No_Abort_Statements, Post_Node);
24860 end if;
24861
24862 if Val = Standard_Long_Long_Integer then
24863 Check_Restriction (No_Long_Long_Integers, Post_Node);
24864 end if;
24865
24866 -- Check for violation of No_Dynamic_Attachment
24867
24868 if Restriction_Check_Required (No_Dynamic_Attachment)
24869 and then RTU_Loaded (Ada_Interrupts)
24870 and then (Is_RTE (Val, RE_Is_Reserved) or else
24871 Is_RTE (Val, RE_Is_Attached) or else
24872 Is_RTE (Val, RE_Current_Handler) or else
24873 Is_RTE (Val, RE_Attach_Handler) or else
24874 Is_RTE (Val, RE_Exchange_Handler) or else
24875 Is_RTE (Val, RE_Detach_Handler) or else
24876 Is_RTE (Val, RE_Reference))
24877
24878 -- A special extra check, don't complain about a reference from within
24879 -- the Ada.Interrupts package itself!
24880
24881 and then not In_Same_Extended_Unit (N, Val)
24882 then
24883 Check_Restriction (No_Dynamic_Attachment, Post_Node);
24884 end if;
24885
24886 -- Check for No_Implementation_Identifiers
24887
24888 if Restriction_Check_Required (No_Implementation_Identifiers) then
24889
24890 -- We have an implementation defined entity if it is marked as
24891 -- implementation defined, or is defined in a package marked as
24892 -- implementation defined. However, library packages themselves
24893 -- are excluded (we don't want to flag Interfaces itself, just
24894 -- the entities within it).
24895
24896 if (Is_Implementation_Defined (Val)
24897 or else
24898 (Present (Scope (Val))
24899 and then Is_Implementation_Defined (Scope (Val))))
24900 and then not (Ekind_In (Val, E_Package, E_Generic_Package)
24901 and then Is_Library_Level_Entity (Val))
24902 then
24903 Check_Restriction (No_Implementation_Identifiers, Post_Node);
24904 end if;
24905 end if;
24906
24907 -- Do the style check
24908
24909 if Style_Check
24910 and then not Suppress_Style_Checks (Val)
24911 and then not In_Instance
24912 then
24913 if Nkind (N) = N_Identifier then
24914 Nod := N;
24915 elsif Nkind (N) = N_Expanded_Name then
24916 Nod := Selector_Name (N);
24917 else
24918 return;
24919 end if;
24920
24921 -- A special situation arises for derived operations, where we want
24922 -- to do the check against the parent (since the Sloc of the derived
24923 -- operation points to the derived type declaration itself).
24924
24925 Val_Actual := Val;
24926 while not Comes_From_Source (Val_Actual)
24927 and then Nkind (Val_Actual) in N_Entity
24928 and then (Ekind (Val_Actual) = E_Enumeration_Literal
24929 or else Is_Subprogram_Or_Generic_Subprogram (Val_Actual))
24930 and then Present (Alias (Val_Actual))
24931 loop
24932 Val_Actual := Alias (Val_Actual);
24933 end loop;
24934
24935 -- Renaming declarations for generic actuals do not come from source,
24936 -- and have a different name from that of the entity they rename, so
24937 -- there is no style check to perform here.
24938
24939 if Chars (Nod) = Chars (Val_Actual) then
24940 Style.Check_Identifier (Nod, Val_Actual);
24941 end if;
24942 end if;
24943
24944 Set_Entity (N, Val);
24945 end Set_Entity_With_Checks;
24946
24947 ------------------------------
24948 -- Set_Invalid_Scalar_Value --
24949 ------------------------------
24950
24951 procedure Set_Invalid_Scalar_Value
24952 (Scal_Typ : Float_Scalar_Id;
24953 Value : Ureal)
24954 is
24955 Slot : Ureal renames Invalid_Floats (Scal_Typ);
24956
24957 begin
24958 -- Detect an attempt to set a different value for the same scalar type
24959
24960 pragma Assert (Slot = No_Ureal);
24961 Slot := Value;
24962 end Set_Invalid_Scalar_Value;
24963
24964 ------------------------------
24965 -- Set_Invalid_Scalar_Value --
24966 ------------------------------
24967
24968 procedure Set_Invalid_Scalar_Value
24969 (Scal_Typ : Integer_Scalar_Id;
24970 Value : Uint)
24971 is
24972 Slot : Uint renames Invalid_Integers (Scal_Typ);
24973
24974 begin
24975 -- Detect an attempt to set a different value for the same scalar type
24976
24977 pragma Assert (Slot = No_Uint);
24978 Slot := Value;
24979 end Set_Invalid_Scalar_Value;
24980
24981 ------------------------
24982 -- Set_Name_Entity_Id --
24983 ------------------------
24984
24985 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
24986 begin
24987 Set_Name_Table_Int (Id, Int (Val));
24988 end Set_Name_Entity_Id;
24989
24990 ---------------------
24991 -- Set_Next_Actual --
24992 ---------------------
24993
24994 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
24995 begin
24996 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
24997 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
24998 end if;
24999 end Set_Next_Actual;
25000
25001 ----------------------------------
25002 -- Set_Optimize_Alignment_Flags --
25003 ----------------------------------
25004
25005 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
25006 begin
25007 if Optimize_Alignment = 'S' then
25008 Set_Optimize_Alignment_Space (E);
25009 elsif Optimize_Alignment = 'T' then
25010 Set_Optimize_Alignment_Time (E);
25011 end if;
25012 end Set_Optimize_Alignment_Flags;
25013
25014 -----------------------
25015 -- Set_Public_Status --
25016 -----------------------
25017
25018 procedure Set_Public_Status (Id : Entity_Id) is
25019 S : constant Entity_Id := Current_Scope;
25020
25021 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
25022 -- Determines if E is defined within handled statement sequence or
25023 -- an if statement, returns True if so, False otherwise.
25024
25025 ----------------------
25026 -- Within_HSS_Or_If --
25027 ----------------------
25028
25029 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
25030 N : Node_Id;
25031 begin
25032 N := Declaration_Node (E);
25033 loop
25034 N := Parent (N);
25035
25036 if No (N) then
25037 return False;
25038
25039 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
25040 N_If_Statement)
25041 then
25042 return True;
25043 end if;
25044 end loop;
25045 end Within_HSS_Or_If;
25046
25047 -- Start of processing for Set_Public_Status
25048
25049 begin
25050 -- Everything in the scope of Standard is public
25051
25052 if S = Standard_Standard then
25053 Set_Is_Public (Id);
25054
25055 -- Entity is definitely not public if enclosing scope is not public
25056
25057 elsif not Is_Public (S) then
25058 return;
25059
25060 -- An object or function declaration that occurs in a handled sequence
25061 -- of statements or within an if statement is the declaration for a
25062 -- temporary object or local subprogram generated by the expander. It
25063 -- never needs to be made public and furthermore, making it public can
25064 -- cause back end problems.
25065
25066 elsif Nkind_In (Parent (Id), N_Object_Declaration,
25067 N_Function_Specification)
25068 and then Within_HSS_Or_If (Id)
25069 then
25070 return;
25071
25072 -- Entities in public packages or records are public
25073
25074 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
25075 Set_Is_Public (Id);
25076
25077 -- The bounds of an entry family declaration can generate object
25078 -- declarations that are visible to the back-end, e.g. in the
25079 -- the declaration of a composite type that contains tasks.
25080
25081 elsif Is_Concurrent_Type (S)
25082 and then not Has_Completion (S)
25083 and then Nkind (Parent (Id)) = N_Object_Declaration
25084 then
25085 Set_Is_Public (Id);
25086 end if;
25087 end Set_Public_Status;
25088
25089 -----------------------------
25090 -- Set_Referenced_Modified --
25091 -----------------------------
25092
25093 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
25094 Pref : Node_Id;
25095
25096 begin
25097 -- Deal with indexed or selected component where prefix is modified
25098
25099 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
25100 Pref := Prefix (N);
25101
25102 -- If prefix is access type, then it is the designated object that is
25103 -- being modified, which means we have no entity to set the flag on.
25104
25105 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
25106 return;
25107
25108 -- Otherwise chase the prefix
25109
25110 else
25111 Set_Referenced_Modified (Pref, Out_Param);
25112 end if;
25113
25114 -- Otherwise see if we have an entity name (only other case to process)
25115
25116 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
25117 Set_Referenced_As_LHS (Entity (N), not Out_Param);
25118 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
25119 end if;
25120 end Set_Referenced_Modified;
25121
25122 ------------------
25123 -- Set_Rep_Info --
25124 ------------------
25125
25126 procedure Set_Rep_Info (T1 : Entity_Id; T2 : Entity_Id) is
25127 begin
25128 Set_Is_Atomic (T1, Is_Atomic (T2));
25129 Set_Is_Independent (T1, Is_Independent (T2));
25130 Set_Is_Volatile_Full_Access (T1, Is_Volatile_Full_Access (T2));
25131
25132 if Is_Base_Type (T1) then
25133 Set_Is_Volatile (T1, Is_Volatile (T2));
25134 end if;
25135 end Set_Rep_Info;
25136
25137 ----------------------------
25138 -- Set_Scope_Is_Transient --
25139 ----------------------------
25140
25141 procedure Set_Scope_Is_Transient (V : Boolean := True) is
25142 begin
25143 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
25144 end Set_Scope_Is_Transient;
25145
25146 -------------------
25147 -- Set_Size_Info --
25148 -------------------
25149
25150 procedure Set_Size_Info (T1, T2 : Entity_Id) is
25151 begin
25152 -- We copy Esize, but not RM_Size, since in general RM_Size is
25153 -- subtype specific and does not get inherited by all subtypes.
25154
25155 Set_Esize (T1, Esize (T2));
25156 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
25157
25158 if Is_Discrete_Or_Fixed_Point_Type (T1)
25159 and then
25160 Is_Discrete_Or_Fixed_Point_Type (T2)
25161 then
25162 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
25163 end if;
25164
25165 Set_Alignment (T1, Alignment (T2));
25166 end Set_Size_Info;
25167
25168 ------------------------------
25169 -- Should_Ignore_Pragma_Par --
25170 ------------------------------
25171
25172 function Should_Ignore_Pragma_Par (Prag_Name : Name_Id) return Boolean is
25173 pragma Assert (Compiler_State = Parsing);
25174 -- This one can't work during semantic analysis, because we don't have a
25175 -- correct Current_Source_File.
25176
25177 Result : constant Boolean :=
25178 Get_Name_Table_Boolean3 (Prag_Name)
25179 and then not Is_Internal_File_Name
25180 (File_Name (Current_Source_File));
25181 begin
25182 return Result;
25183 end Should_Ignore_Pragma_Par;
25184
25185 ------------------------------
25186 -- Should_Ignore_Pragma_Sem --
25187 ------------------------------
25188
25189 function Should_Ignore_Pragma_Sem (N : Node_Id) return Boolean is
25190 pragma Assert (Compiler_State = Analyzing);
25191 Prag_Name : constant Name_Id := Pragma_Name (N);
25192 Result : constant Boolean :=
25193 Get_Name_Table_Boolean3 (Prag_Name)
25194 and then not In_Internal_Unit (N);
25195
25196 begin
25197 return Result;
25198 end Should_Ignore_Pragma_Sem;
25199
25200 --------------------
25201 -- Static_Boolean --
25202 --------------------
25203
25204 function Static_Boolean (N : Node_Id) return Uint is
25205 begin
25206 Analyze_And_Resolve (N, Standard_Boolean);
25207
25208 if N = Error
25209 or else Error_Posted (N)
25210 or else Etype (N) = Any_Type
25211 then
25212 return No_Uint;
25213 end if;
25214
25215 if Is_OK_Static_Expression (N) then
25216 if not Raises_Constraint_Error (N) then
25217 return Expr_Value (N);
25218 else
25219 return No_Uint;
25220 end if;
25221
25222 elsif Etype (N) = Any_Type then
25223 return No_Uint;
25224
25225 else
25226 Flag_Non_Static_Expr
25227 ("static boolean expression required here", N);
25228 return No_Uint;
25229 end if;
25230 end Static_Boolean;
25231
25232 --------------------
25233 -- Static_Integer --
25234 --------------------
25235
25236 function Static_Integer (N : Node_Id) return Uint is
25237 begin
25238 Analyze_And_Resolve (N, Any_Integer);
25239
25240 if N = Error
25241 or else Error_Posted (N)
25242 or else Etype (N) = Any_Type
25243 then
25244 return No_Uint;
25245 end if;
25246
25247 if Is_OK_Static_Expression (N) then
25248 if not Raises_Constraint_Error (N) then
25249 return Expr_Value (N);
25250 else
25251 return No_Uint;
25252 end if;
25253
25254 elsif Etype (N) = Any_Type then
25255 return No_Uint;
25256
25257 else
25258 Flag_Non_Static_Expr
25259 ("static integer expression required here", N);
25260 return No_Uint;
25261 end if;
25262 end Static_Integer;
25263
25264 --------------------------
25265 -- Statically_Different --
25266 --------------------------
25267
25268 function Statically_Different (E1, E2 : Node_Id) return Boolean is
25269 R1 : constant Node_Id := Get_Referenced_Object (E1);
25270 R2 : constant Node_Id := Get_Referenced_Object (E2);
25271 begin
25272 return Is_Entity_Name (R1)
25273 and then Is_Entity_Name (R2)
25274 and then Entity (R1) /= Entity (R2)
25275 and then not Is_Formal (Entity (R1))
25276 and then not Is_Formal (Entity (R2));
25277 end Statically_Different;
25278
25279 --------------------------------------
25280 -- Subject_To_Loop_Entry_Attributes --
25281 --------------------------------------
25282
25283 function Subject_To_Loop_Entry_Attributes (N : Node_Id) return Boolean is
25284 Stmt : Node_Id;
25285
25286 begin
25287 Stmt := N;
25288
25289 -- The expansion mechanism transform a loop subject to at least one
25290 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
25291 -- the conditional part.
25292
25293 if Nkind_In (Stmt, N_Block_Statement, N_If_Statement)
25294 and then Nkind (Original_Node (N)) = N_Loop_Statement
25295 then
25296 Stmt := Original_Node (N);
25297 end if;
25298
25299 return
25300 Nkind (Stmt) = N_Loop_Statement
25301 and then Present (Identifier (Stmt))
25302 and then Present (Entity (Identifier (Stmt)))
25303 and then Has_Loop_Entry_Attributes (Entity (Identifier (Stmt)));
25304 end Subject_To_Loop_Entry_Attributes;
25305
25306 -----------------------------
25307 -- Subprogram_Access_Level --
25308 -----------------------------
25309
25310 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
25311 begin
25312 if Present (Alias (Subp)) then
25313 return Subprogram_Access_Level (Alias (Subp));
25314 else
25315 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
25316 end if;
25317 end Subprogram_Access_Level;
25318
25319 ---------------------
25320 -- Subprogram_Name --
25321 ---------------------
25322
25323 function Subprogram_Name (N : Node_Id) return String is
25324 Buf : Bounded_String;
25325 Ent : Node_Id := N;
25326 Nod : Node_Id;
25327
25328 begin
25329 while Present (Ent) loop
25330 case Nkind (Ent) is
25331 when N_Subprogram_Body =>
25332 Ent := Defining_Unit_Name (Specification (Ent));
25333 exit;
25334
25335 when N_Subprogram_Declaration =>
25336 Nod := Corresponding_Body (Ent);
25337
25338 if Present (Nod) then
25339 Ent := Nod;
25340 else
25341 Ent := Defining_Unit_Name (Specification (Ent));
25342 end if;
25343
25344 exit;
25345
25346 when N_Subprogram_Instantiation
25347 | N_Package_Body
25348 | N_Package_Specification
25349 =>
25350 Ent := Defining_Unit_Name (Ent);
25351 exit;
25352
25353 when N_Protected_Type_Declaration =>
25354 Ent := Corresponding_Body (Ent);
25355 exit;
25356
25357 when N_Protected_Body
25358 | N_Task_Body
25359 =>
25360 Ent := Defining_Identifier (Ent);
25361 exit;
25362
25363 when others =>
25364 null;
25365 end case;
25366
25367 Ent := Parent (Ent);
25368 end loop;
25369
25370 if No (Ent) then
25371 return "unknown subprogram:unknown file:0:0";
25372 end if;
25373
25374 -- If the subprogram is a child unit, use its simple name to start the
25375 -- construction of the fully qualified name.
25376
25377 if Nkind (Ent) = N_Defining_Program_Unit_Name then
25378 Ent := Defining_Identifier (Ent);
25379 end if;
25380
25381 Append_Entity_Name (Buf, Ent);
25382
25383 -- Append homonym number if needed
25384
25385 if Nkind (N) in N_Entity and then Has_Homonym (N) then
25386 declare
25387 H : Entity_Id := Homonym (N);
25388 Nr : Nat := 1;
25389
25390 begin
25391 while Present (H) loop
25392 if Scope (H) = Scope (N) then
25393 Nr := Nr + 1;
25394 end if;
25395
25396 H := Homonym (H);
25397 end loop;
25398
25399 if Nr > 1 then
25400 Append (Buf, '#');
25401 Append (Buf, Nr);
25402 end if;
25403 end;
25404 end if;
25405
25406 -- Append source location of Ent to Buf so that the string will
25407 -- look like "subp:file:line:col".
25408
25409 declare
25410 Loc : constant Source_Ptr := Sloc (Ent);
25411 begin
25412 Append (Buf, ':');
25413 Append (Buf, Reference_Name (Get_Source_File_Index (Loc)));
25414 Append (Buf, ':');
25415 Append (Buf, Nat (Get_Logical_Line_Number (Loc)));
25416 Append (Buf, ':');
25417 Append (Buf, Nat (Get_Column_Number (Loc)));
25418 end;
25419
25420 return +Buf;
25421 end Subprogram_Name;
25422
25423 -------------------------------
25424 -- Support_Atomic_Primitives --
25425 -------------------------------
25426
25427 function Support_Atomic_Primitives (Typ : Entity_Id) return Boolean is
25428 Size : Int;
25429
25430 begin
25431 -- Verify the alignment of Typ is known
25432
25433 if not Known_Alignment (Typ) then
25434 return False;
25435 end if;
25436
25437 if Known_Static_Esize (Typ) then
25438 Size := UI_To_Int (Esize (Typ));
25439
25440 -- If the Esize (Object_Size) is unknown at compile time, look at the
25441 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
25442
25443 elsif Known_Static_RM_Size (Typ) then
25444 Size := UI_To_Int (RM_Size (Typ));
25445
25446 -- Otherwise, the size is considered to be unknown.
25447
25448 else
25449 return False;
25450 end if;
25451
25452 -- Check that the size of the component is 8, 16, 32, or 64 bits and
25453 -- that Typ is properly aligned.
25454
25455 case Size is
25456 when 8 | 16 | 32 | 64 =>
25457 return Size = UI_To_Int (Alignment (Typ)) * 8;
25458
25459 when others =>
25460 return False;
25461 end case;
25462 end Support_Atomic_Primitives;
25463
25464 -----------------
25465 -- Trace_Scope --
25466 -----------------
25467
25468 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
25469 begin
25470 if Debug_Flag_W then
25471 for J in 0 .. Scope_Stack.Last loop
25472 Write_Str (" ");
25473 end loop;
25474
25475 Write_Str (Msg);
25476 Write_Name (Chars (E));
25477 Write_Str (" from ");
25478 Write_Location (Sloc (N));
25479 Write_Eol;
25480 end if;
25481 end Trace_Scope;
25482
25483 -----------------------
25484 -- Transfer_Entities --
25485 -----------------------
25486
25487 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
25488 procedure Set_Public_Status_Of (Id : Entity_Id);
25489 -- Set the Is_Public attribute of arbitrary entity Id by calling routine
25490 -- Set_Public_Status. If successful and Id denotes a record type, set
25491 -- the Is_Public attribute of its fields.
25492
25493 --------------------------
25494 -- Set_Public_Status_Of --
25495 --------------------------
25496
25497 procedure Set_Public_Status_Of (Id : Entity_Id) is
25498 Field : Entity_Id;
25499
25500 begin
25501 if not Is_Public (Id) then
25502 Set_Public_Status (Id);
25503
25504 -- When the input entity is a public record type, ensure that all
25505 -- its internal fields are also exposed to the linker. The fields
25506 -- of a class-wide type are never made public.
25507
25508 if Is_Public (Id)
25509 and then Is_Record_Type (Id)
25510 and then not Is_Class_Wide_Type (Id)
25511 then
25512 Field := First_Entity (Id);
25513 while Present (Field) loop
25514 Set_Is_Public (Field);
25515 Next_Entity (Field);
25516 end loop;
25517 end if;
25518 end if;
25519 end Set_Public_Status_Of;
25520
25521 -- Local variables
25522
25523 Full_Id : Entity_Id;
25524 Id : Entity_Id;
25525
25526 -- Start of processing for Transfer_Entities
25527
25528 begin
25529 Id := First_Entity (From);
25530
25531 if Present (Id) then
25532
25533 -- Merge the entity chain of the source scope with that of the
25534 -- destination scope.
25535
25536 if Present (Last_Entity (To)) then
25537 Link_Entities (Last_Entity (To), Id);
25538 else
25539 Set_First_Entity (To, Id);
25540 end if;
25541
25542 Set_Last_Entity (To, Last_Entity (From));
25543
25544 -- Inspect the entities of the source scope and update their Scope
25545 -- attribute.
25546
25547 while Present (Id) loop
25548 Set_Scope (Id, To);
25549 Set_Public_Status_Of (Id);
25550
25551 -- Handle an internally generated full view for a private type
25552
25553 if Is_Private_Type (Id)
25554 and then Present (Full_View (Id))
25555 and then Is_Itype (Full_View (Id))
25556 then
25557 Full_Id := Full_View (Id);
25558
25559 Set_Scope (Full_Id, To);
25560 Set_Public_Status_Of (Full_Id);
25561 end if;
25562
25563 Next_Entity (Id);
25564 end loop;
25565
25566 Set_First_Entity (From, Empty);
25567 Set_Last_Entity (From, Empty);
25568 end if;
25569 end Transfer_Entities;
25570
25571 ------------------------
25572 -- Traverse_More_Func --
25573 ------------------------
25574
25575 function Traverse_More_Func (Node : Node_Id) return Traverse_Final_Result is
25576
25577 Processing_Itype : Boolean := False;
25578 -- Set to True while traversing the nodes under an Itype, to prevent
25579 -- looping on Itype handling during that traversal.
25580
25581 function Process_More (N : Node_Id) return Traverse_Result;
25582 -- Wrapper over the Process callback to handle parts of the AST that
25583 -- are not normally traversed as syntactic children.
25584
25585 function Traverse_Rec (N : Node_Id) return Traverse_Final_Result;
25586 -- Main recursive traversal implemented as an instantiation of
25587 -- Traverse_Func over a modified Process callback.
25588
25589 ------------------
25590 -- Process_More --
25591 ------------------
25592
25593 function Process_More (N : Node_Id) return Traverse_Result is
25594
25595 procedure Traverse_More (N : Node_Id;
25596 Res : in out Traverse_Result);
25597 procedure Traverse_More (L : List_Id;
25598 Res : in out Traverse_Result);
25599 -- Traverse a node or list and update the traversal result to value
25600 -- Abandon when needed.
25601
25602 -------------------
25603 -- Traverse_More --
25604 -------------------
25605
25606 procedure Traverse_More (N : Node_Id;
25607 Res : in out Traverse_Result)
25608 is
25609 begin
25610 -- Do not process any more nodes if Abandon was reached
25611
25612 if Res = Abandon then
25613 return;
25614 end if;
25615
25616 if Traverse_Rec (N) = Abandon then
25617 Res := Abandon;
25618 end if;
25619 end Traverse_More;
25620
25621 procedure Traverse_More (L : List_Id;
25622 Res : in out Traverse_Result)
25623 is
25624 N : Node_Id := First (L);
25625
25626 begin
25627 -- Do not process any more nodes if Abandon was reached
25628
25629 if Res = Abandon then
25630 return;
25631 end if;
25632
25633 while Present (N) loop
25634 Traverse_More (N, Res);
25635 Next (N);
25636 end loop;
25637 end Traverse_More;
25638
25639 -- Local variables
25640
25641 Node : Node_Id;
25642 Result : Traverse_Result;
25643
25644 -- Start of processing for Process_More
25645
25646 begin
25647 -- Initial callback to Process. Return immediately on Skip/Abandon.
25648 -- Otherwise update the value of Node for further processing of
25649 -- non-syntactic children.
25650
25651 Result := Process (N);
25652
25653 case Result is
25654 when OK => Node := N;
25655 when OK_Orig => Node := Original_Node (N);
25656 when Skip => return Skip;
25657 when Abandon => return Abandon;
25658 end case;
25659
25660 -- Process the relevant semantic children which are a logical part of
25661 -- the AST under this node before returning for the processing of
25662 -- syntactic children.
25663
25664 -- Start with all non-syntactic lists of action nodes
25665
25666 case Nkind (Node) is
25667 when N_Component_Association =>
25668 Traverse_More (Loop_Actions (Node), Result);
25669
25670 when N_Elsif_Part =>
25671 Traverse_More (Condition_Actions (Node), Result);
25672
25673 when N_Short_Circuit =>
25674 Traverse_More (Actions (Node), Result);
25675
25676 when N_Case_Expression_Alternative =>
25677 Traverse_More (Actions (Node), Result);
25678
25679 when N_Iterated_Component_Association =>
25680 Traverse_More (Loop_Actions (Node), Result);
25681
25682 when N_Iteration_Scheme =>
25683 Traverse_More (Condition_Actions (Node), Result);
25684
25685 when N_If_Expression =>
25686 Traverse_More (Then_Actions (Node), Result);
25687 Traverse_More (Else_Actions (Node), Result);
25688
25689 -- Various nodes have a field Actions as a syntactic node,
25690 -- so it will be traversed in the regular syntactic traversal.
25691
25692 when N_Compilation_Unit_Aux
25693 | N_Compound_Statement
25694 | N_Expression_With_Actions
25695 | N_Freeze_Entity
25696 =>
25697 null;
25698
25699 when others =>
25700 null;
25701 end case;
25702
25703 -- If Process_Itypes is True, process unattached nodes which come
25704 -- from Itypes. This only concerns currently ranges of scalar
25705 -- (possibly as index) types. This traversal is protected against
25706 -- looping with Processing_Itype.
25707
25708 if Process_Itypes
25709 and then not Processing_Itype
25710 and then Nkind (Node) in N_Has_Etype
25711 and then Present (Etype (Node))
25712 and then Is_Itype (Etype (Node))
25713 then
25714 declare
25715 Typ : constant Entity_Id := Etype (Node);
25716 begin
25717 Processing_Itype := True;
25718
25719 case Ekind (Typ) is
25720 when Scalar_Kind =>
25721 Traverse_More (Scalar_Range (Typ), Result);
25722
25723 when Array_Kind =>
25724 declare
25725 Index : Node_Id := First_Index (Typ);
25726 Rng : Node_Id;
25727 begin
25728 while Present (Index) loop
25729 if Nkind (Index) in N_Has_Entity then
25730 Rng := Scalar_Range (Entity (Index));
25731 else
25732 Rng := Index;
25733 end if;
25734
25735 Traverse_More (Rng, Result);
25736 Next_Index (Index);
25737 end loop;
25738 end;
25739 when others =>
25740 null;
25741 end case;
25742
25743 Processing_Itype := False;
25744 end;
25745 end if;
25746
25747 return Result;
25748 end Process_More;
25749
25750 -- Define Traverse_Rec as a renaming of the instantiation, as an
25751 -- instantiation cannot complete a previous spec.
25752
25753 function Traverse_Recursive is new Traverse_Func (Process_More);
25754 function Traverse_Rec (N : Node_Id) return Traverse_Final_Result
25755 renames Traverse_Recursive;
25756
25757 -- Start of processing for Traverse_More_Func
25758
25759 begin
25760 return Traverse_Rec (Node);
25761 end Traverse_More_Func;
25762
25763 ------------------------
25764 -- Traverse_More_Proc --
25765 ------------------------
25766
25767 procedure Traverse_More_Proc (Node : Node_Id) is
25768 function Traverse is new Traverse_More_Func (Process, Process_Itypes);
25769 Discard : Traverse_Final_Result;
25770 pragma Warnings (Off, Discard);
25771 begin
25772 Discard := Traverse (Node);
25773 end Traverse_More_Proc;
25774
25775 -----------------------
25776 -- Type_Access_Level --
25777 -----------------------
25778
25779 function Type_Access_Level (Typ : Entity_Id) return Uint is
25780 Btyp : Entity_Id;
25781
25782 begin
25783 Btyp := Base_Type (Typ);
25784
25785 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
25786 -- simply use the level where the type is declared. This is true for
25787 -- stand-alone object declarations, and for anonymous access types
25788 -- associated with components the level is the same as that of the
25789 -- enclosing composite type. However, special treatment is needed for
25790 -- the cases of access parameters, return objects of an anonymous access
25791 -- type, and, in Ada 95, access discriminants of limited types.
25792
25793 if Is_Access_Type (Btyp) then
25794 if Ekind (Btyp) = E_Anonymous_Access_Type then
25795
25796 -- If the type is a nonlocal anonymous access type (such as for
25797 -- an access parameter) we treat it as being declared at the
25798 -- library level to ensure that names such as X.all'access don't
25799 -- fail static accessibility checks.
25800
25801 if not Is_Local_Anonymous_Access (Typ) then
25802 return Scope_Depth (Standard_Standard);
25803
25804 -- If this is a return object, the accessibility level is that of
25805 -- the result subtype of the enclosing function. The test here is
25806 -- little complicated, because we have to account for extended
25807 -- return statements that have been rewritten as blocks, in which
25808 -- case we have to find and the Is_Return_Object attribute of the
25809 -- itype's associated object. It would be nice to find a way to
25810 -- simplify this test, but it doesn't seem worthwhile to add a new
25811 -- flag just for purposes of this test. ???
25812
25813 elsif Ekind (Scope (Btyp)) = E_Return_Statement
25814 or else
25815 (Is_Itype (Btyp)
25816 and then Nkind (Associated_Node_For_Itype (Btyp)) =
25817 N_Object_Declaration
25818 and then Is_Return_Object
25819 (Defining_Identifier
25820 (Associated_Node_For_Itype (Btyp))))
25821 then
25822 declare
25823 Scop : Entity_Id;
25824
25825 begin
25826 Scop := Scope (Scope (Btyp));
25827 while Present (Scop) loop
25828 exit when Ekind (Scop) = E_Function;
25829 Scop := Scope (Scop);
25830 end loop;
25831
25832 -- Treat the return object's type as having the level of the
25833 -- function's result subtype (as per RM05-6.5(5.3/2)).
25834
25835 return Type_Access_Level (Etype (Scop));
25836 end;
25837 end if;
25838 end if;
25839
25840 Btyp := Root_Type (Btyp);
25841
25842 -- The accessibility level of anonymous access types associated with
25843 -- discriminants is that of the current instance of the type, and
25844 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
25845
25846 -- AI-402: access discriminants have accessibility based on the
25847 -- object rather than the type in Ada 2005, so the above paragraph
25848 -- doesn't apply.
25849
25850 -- ??? Needs completion with rules from AI-416
25851
25852 if Ada_Version <= Ada_95
25853 and then Ekind (Typ) = E_Anonymous_Access_Type
25854 and then Present (Associated_Node_For_Itype (Typ))
25855 and then Nkind (Associated_Node_For_Itype (Typ)) =
25856 N_Discriminant_Specification
25857 then
25858 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
25859 end if;
25860 end if;
25861
25862 -- Return library level for a generic formal type. This is done because
25863 -- RM(10.3.2) says that "The statically deeper relationship does not
25864 -- apply to ... a descendant of a generic formal type". Rather than
25865 -- checking at each point where a static accessibility check is
25866 -- performed to see if we are dealing with a formal type, this rule is
25867 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
25868 -- return extreme values for a formal type; Deepest_Type_Access_Level
25869 -- returns Int'Last. By calling the appropriate function from among the
25870 -- two, we ensure that the static accessibility check will pass if we
25871 -- happen to run into a formal type. More specifically, we should call
25872 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
25873 -- call occurs as part of a static accessibility check and the error
25874 -- case is the case where the type's level is too shallow (as opposed
25875 -- to too deep).
25876
25877 if Is_Generic_Type (Root_Type (Btyp)) then
25878 return Scope_Depth (Standard_Standard);
25879 end if;
25880
25881 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
25882 end Type_Access_Level;
25883
25884 ------------------------------------
25885 -- Type_Without_Stream_Operation --
25886 ------------------------------------
25887
25888 function Type_Without_Stream_Operation
25889 (T : Entity_Id;
25890 Op : TSS_Name_Type := TSS_Null) return Entity_Id
25891 is
25892 BT : constant Entity_Id := Base_Type (T);
25893 Op_Missing : Boolean;
25894
25895 begin
25896 if not Restriction_Active (No_Default_Stream_Attributes) then
25897 return Empty;
25898 end if;
25899
25900 if Is_Elementary_Type (T) then
25901 if Op = TSS_Null then
25902 Op_Missing :=
25903 No (TSS (BT, TSS_Stream_Read))
25904 or else No (TSS (BT, TSS_Stream_Write));
25905
25906 else
25907 Op_Missing := No (TSS (BT, Op));
25908 end if;
25909
25910 if Op_Missing then
25911 return T;
25912 else
25913 return Empty;
25914 end if;
25915
25916 elsif Is_Array_Type (T) then
25917 return Type_Without_Stream_Operation (Component_Type (T), Op);
25918
25919 elsif Is_Record_Type (T) then
25920 declare
25921 Comp : Entity_Id;
25922 C_Typ : Entity_Id;
25923
25924 begin
25925 Comp := First_Component (T);
25926 while Present (Comp) loop
25927 C_Typ := Type_Without_Stream_Operation (Etype (Comp), Op);
25928
25929 if Present (C_Typ) then
25930 return C_Typ;
25931 end if;
25932
25933 Next_Component (Comp);
25934 end loop;
25935
25936 return Empty;
25937 end;
25938
25939 elsif Is_Private_Type (T) and then Present (Full_View (T)) then
25940 return Type_Without_Stream_Operation (Full_View (T), Op);
25941 else
25942 return Empty;
25943 end if;
25944 end Type_Without_Stream_Operation;
25945
25946 ---------------------
25947 -- Ultimate_Prefix --
25948 ---------------------
25949
25950 function Ultimate_Prefix (N : Node_Id) return Node_Id is
25951 Pref : Node_Id;
25952
25953 begin
25954 Pref := N;
25955 while Nkind_In (Pref, N_Explicit_Dereference,
25956 N_Indexed_Component,
25957 N_Selected_Component,
25958 N_Slice)
25959 loop
25960 Pref := Prefix (Pref);
25961 end loop;
25962
25963 return Pref;
25964 end Ultimate_Prefix;
25965
25966 ----------------------------
25967 -- Unique_Defining_Entity --
25968 ----------------------------
25969
25970 function Unique_Defining_Entity (N : Node_Id) return Entity_Id is
25971 begin
25972 return Unique_Entity (Defining_Entity (N));
25973 end Unique_Defining_Entity;
25974
25975 -------------------
25976 -- Unique_Entity --
25977 -------------------
25978
25979 function Unique_Entity (E : Entity_Id) return Entity_Id is
25980 U : Entity_Id := E;
25981 P : Node_Id;
25982
25983 begin
25984 case Ekind (E) is
25985 when E_Constant =>
25986 if Present (Full_View (E)) then
25987 U := Full_View (E);
25988 end if;
25989
25990 when Entry_Kind =>
25991 if Nkind (Parent (E)) = N_Entry_Body then
25992 declare
25993 Prot_Item : Entity_Id;
25994 Prot_Type : Entity_Id;
25995
25996 begin
25997 if Ekind (E) = E_Entry then
25998 Prot_Type := Scope (E);
25999
26000 -- Bodies of entry families are nested within an extra scope
26001 -- that contains an entry index declaration.
26002
26003 else
26004 Prot_Type := Scope (Scope (E));
26005 end if;
26006
26007 -- A protected type may be declared as a private type, in
26008 -- which case we need to get its full view.
26009
26010 if Is_Private_Type (Prot_Type) then
26011 Prot_Type := Full_View (Prot_Type);
26012 end if;
26013
26014 -- Full view may not be present on error, in which case
26015 -- return E by default.
26016
26017 if Present (Prot_Type) then
26018 pragma Assert (Ekind (Prot_Type) = E_Protected_Type);
26019
26020 -- Traverse the entity list of the protected type and
26021 -- locate an entry declaration which matches the entry
26022 -- body.
26023
26024 Prot_Item := First_Entity (Prot_Type);
26025 while Present (Prot_Item) loop
26026 if Ekind (Prot_Item) in Entry_Kind
26027 and then Corresponding_Body (Parent (Prot_Item)) = E
26028 then
26029 U := Prot_Item;
26030 exit;
26031 end if;
26032
26033 Next_Entity (Prot_Item);
26034 end loop;
26035 end if;
26036 end;
26037 end if;
26038
26039 when Formal_Kind =>
26040 if Present (Spec_Entity (E)) then
26041 U := Spec_Entity (E);
26042 end if;
26043
26044 when E_Package_Body =>
26045 P := Parent (E);
26046
26047 if Nkind (P) = N_Defining_Program_Unit_Name then
26048 P := Parent (P);
26049 end if;
26050
26051 if Nkind (P) = N_Package_Body
26052 and then Present (Corresponding_Spec (P))
26053 then
26054 U := Corresponding_Spec (P);
26055
26056 elsif Nkind (P) = N_Package_Body_Stub
26057 and then Present (Corresponding_Spec_Of_Stub (P))
26058 then
26059 U := Corresponding_Spec_Of_Stub (P);
26060 end if;
26061
26062 when E_Protected_Body =>
26063 P := Parent (E);
26064
26065 if Nkind (P) = N_Protected_Body
26066 and then Present (Corresponding_Spec (P))
26067 then
26068 U := Corresponding_Spec (P);
26069
26070 elsif Nkind (P) = N_Protected_Body_Stub
26071 and then Present (Corresponding_Spec_Of_Stub (P))
26072 then
26073 U := Corresponding_Spec_Of_Stub (P);
26074
26075 if Is_Single_Protected_Object (U) then
26076 U := Etype (U);
26077 end if;
26078 end if;
26079
26080 if Is_Private_Type (U) then
26081 U := Full_View (U);
26082 end if;
26083
26084 when E_Subprogram_Body =>
26085 P := Parent (E);
26086
26087 if Nkind (P) = N_Defining_Program_Unit_Name then
26088 P := Parent (P);
26089 end if;
26090
26091 P := Parent (P);
26092
26093 if Nkind (P) = N_Subprogram_Body
26094 and then Present (Corresponding_Spec (P))
26095 then
26096 U := Corresponding_Spec (P);
26097
26098 elsif Nkind (P) = N_Subprogram_Body_Stub
26099 and then Present (Corresponding_Spec_Of_Stub (P))
26100 then
26101 U := Corresponding_Spec_Of_Stub (P);
26102
26103 elsif Nkind (P) = N_Subprogram_Renaming_Declaration then
26104 U := Corresponding_Spec (P);
26105 end if;
26106
26107 when E_Task_Body =>
26108 P := Parent (E);
26109
26110 if Nkind (P) = N_Task_Body
26111 and then Present (Corresponding_Spec (P))
26112 then
26113 U := Corresponding_Spec (P);
26114
26115 elsif Nkind (P) = N_Task_Body_Stub
26116 and then Present (Corresponding_Spec_Of_Stub (P))
26117 then
26118 U := Corresponding_Spec_Of_Stub (P);
26119
26120 if Is_Single_Task_Object (U) then
26121 U := Etype (U);
26122 end if;
26123 end if;
26124
26125 if Is_Private_Type (U) then
26126 U := Full_View (U);
26127 end if;
26128
26129 when Type_Kind =>
26130 if Present (Full_View (E)) then
26131 U := Full_View (E);
26132 end if;
26133
26134 when others =>
26135 null;
26136 end case;
26137
26138 return U;
26139 end Unique_Entity;
26140
26141 -----------------
26142 -- Unique_Name --
26143 -----------------
26144
26145 function Unique_Name (E : Entity_Id) return String is
26146
26147 -- Names in E_Subprogram_Body or E_Package_Body entities are not
26148 -- reliable, as they may not include the overloading suffix. Instead,
26149 -- when looking for the name of E or one of its enclosing scope, we get
26150 -- the name of the corresponding Unique_Entity.
26151
26152 U : constant Entity_Id := Unique_Entity (E);
26153
26154 function This_Name return String;
26155
26156 ---------------
26157 -- This_Name --
26158 ---------------
26159
26160 function This_Name return String is
26161 begin
26162 return Get_Name_String (Chars (U));
26163 end This_Name;
26164
26165 -- Start of processing for Unique_Name
26166
26167 begin
26168 if E = Standard_Standard
26169 or else Has_Fully_Qualified_Name (E)
26170 then
26171 return This_Name;
26172
26173 elsif Ekind (E) = E_Enumeration_Literal then
26174 return Unique_Name (Etype (E)) & "__" & This_Name;
26175
26176 else
26177 declare
26178 S : constant Entity_Id := Scope (U);
26179 pragma Assert (Present (S));
26180
26181 begin
26182 -- Prefix names of predefined types with standard__, but leave
26183 -- names of user-defined packages and subprograms without prefix
26184 -- (even if technically they are nested in the Standard package).
26185
26186 if S = Standard_Standard then
26187 if Ekind (U) = E_Package or else Is_Subprogram (U) then
26188 return This_Name;
26189 else
26190 return Unique_Name (S) & "__" & This_Name;
26191 end if;
26192
26193 -- For intances of generic subprograms use the name of the related
26194 -- instace and skip the scope of its wrapper package.
26195
26196 elsif Is_Wrapper_Package (S) then
26197 pragma Assert (Scope (S) = Scope (Related_Instance (S)));
26198 -- Wrapper package and the instantiation are in the same scope
26199
26200 declare
26201 Enclosing_Name : constant String :=
26202 Unique_Name (Scope (S)) & "__" &
26203 Get_Name_String (Chars (Related_Instance (S)));
26204
26205 begin
26206 if Is_Subprogram (U)
26207 and then not Is_Generic_Actual_Subprogram (U)
26208 then
26209 return Enclosing_Name;
26210 else
26211 return Enclosing_Name & "__" & This_Name;
26212 end if;
26213 end;
26214
26215 elsif Is_Child_Unit (U) then
26216 return Child_Prefix & Unique_Name (S) & "__" & This_Name;
26217 else
26218 return Unique_Name (S) & "__" & This_Name;
26219 end if;
26220 end;
26221 end if;
26222 end Unique_Name;
26223
26224 ---------------------
26225 -- Unit_Is_Visible --
26226 ---------------------
26227
26228 function Unit_Is_Visible (U : Entity_Id) return Boolean is
26229 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
26230 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
26231
26232 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
26233 -- For a child unit, check whether unit appears in a with_clause
26234 -- of a parent.
26235
26236 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
26237 -- Scan the context clause of one compilation unit looking for a
26238 -- with_clause for the unit in question.
26239
26240 ----------------------------
26241 -- Unit_In_Parent_Context --
26242 ----------------------------
26243
26244 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
26245 begin
26246 if Unit_In_Context (Par_Unit) then
26247 return True;
26248
26249 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
26250 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
26251
26252 else
26253 return False;
26254 end if;
26255 end Unit_In_Parent_Context;
26256
26257 ---------------------
26258 -- Unit_In_Context --
26259 ---------------------
26260
26261 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
26262 Clause : Node_Id;
26263
26264 begin
26265 Clause := First (Context_Items (Comp_Unit));
26266 while Present (Clause) loop
26267 if Nkind (Clause) = N_With_Clause then
26268 if Library_Unit (Clause) = U then
26269 return True;
26270
26271 -- The with_clause may denote a renaming of the unit we are
26272 -- looking for, eg. Text_IO which renames Ada.Text_IO.
26273
26274 elsif
26275 Renamed_Entity (Entity (Name (Clause))) =
26276 Defining_Entity (Unit (U))
26277 then
26278 return True;
26279 end if;
26280 end if;
26281
26282 Next (Clause);
26283 end loop;
26284
26285 return False;
26286 end Unit_In_Context;
26287
26288 -- Start of processing for Unit_Is_Visible
26289
26290 begin
26291 -- The currrent unit is directly visible
26292
26293 if Curr = U then
26294 return True;
26295
26296 elsif Unit_In_Context (Curr) then
26297 return True;
26298
26299 -- If the current unit is a body, check the context of the spec
26300
26301 elsif Nkind (Unit (Curr)) = N_Package_Body
26302 or else
26303 (Nkind (Unit (Curr)) = N_Subprogram_Body
26304 and then not Acts_As_Spec (Unit (Curr)))
26305 then
26306 if Unit_In_Context (Library_Unit (Curr)) then
26307 return True;
26308 end if;
26309 end if;
26310
26311 -- If the spec is a child unit, examine the parents
26312
26313 if Is_Child_Unit (Curr_Entity) then
26314 if Nkind (Unit (Curr)) in N_Unit_Body then
26315 return
26316 Unit_In_Parent_Context
26317 (Parent_Spec (Unit (Library_Unit (Curr))));
26318 else
26319 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
26320 end if;
26321
26322 else
26323 return False;
26324 end if;
26325 end Unit_Is_Visible;
26326
26327 ------------------------------
26328 -- Universal_Interpretation --
26329 ------------------------------
26330
26331 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
26332 Index : Interp_Index;
26333 It : Interp;
26334
26335 begin
26336 -- The argument may be a formal parameter of an operator or subprogram
26337 -- with multiple interpretations, or else an expression for an actual.
26338
26339 if Nkind (Opnd) = N_Defining_Identifier
26340 or else not Is_Overloaded (Opnd)
26341 then
26342 if Etype (Opnd) = Universal_Integer
26343 or else Etype (Opnd) = Universal_Real
26344 then
26345 return Etype (Opnd);
26346 else
26347 return Empty;
26348 end if;
26349
26350 else
26351 Get_First_Interp (Opnd, Index, It);
26352 while Present (It.Typ) loop
26353 if It.Typ = Universal_Integer
26354 or else It.Typ = Universal_Real
26355 then
26356 return It.Typ;
26357 end if;
26358
26359 Get_Next_Interp (Index, It);
26360 end loop;
26361
26362 return Empty;
26363 end if;
26364 end Universal_Interpretation;
26365
26366 ---------------
26367 -- Unqualify --
26368 ---------------
26369
26370 function Unqualify (Expr : Node_Id) return Node_Id is
26371 begin
26372 -- Recurse to handle unlikely case of multiple levels of qualification
26373
26374 if Nkind (Expr) = N_Qualified_Expression then
26375 return Unqualify (Expression (Expr));
26376
26377 -- Normal case, not a qualified expression
26378
26379 else
26380 return Expr;
26381 end if;
26382 end Unqualify;
26383
26384 -----------------
26385 -- Unqual_Conv --
26386 -----------------
26387
26388 function Unqual_Conv (Expr : Node_Id) return Node_Id is
26389 begin
26390 -- Recurse to handle unlikely case of multiple levels of qualification
26391 -- and/or conversion.
26392
26393 if Nkind_In (Expr, N_Qualified_Expression,
26394 N_Type_Conversion,
26395 N_Unchecked_Type_Conversion)
26396 then
26397 return Unqual_Conv (Expression (Expr));
26398
26399 -- Normal case, not a qualified expression
26400
26401 else
26402 return Expr;
26403 end if;
26404 end Unqual_Conv;
26405
26406 --------------------
26407 -- Validated_View --
26408 --------------------
26409
26410 function Validated_View (Typ : Entity_Id) return Entity_Id is
26411 Continue : Boolean;
26412 Val_Typ : Entity_Id;
26413
26414 begin
26415 Continue := True;
26416 Val_Typ := Base_Type (Typ);
26417
26418 -- Obtain the full view of the input type by stripping away concurrency,
26419 -- derivations, and privacy.
26420
26421 while Continue loop
26422 Continue := False;
26423
26424 if Is_Concurrent_Type (Val_Typ) then
26425 if Present (Corresponding_Record_Type (Val_Typ)) then
26426 Continue := True;
26427 Val_Typ := Corresponding_Record_Type (Val_Typ);
26428 end if;
26429
26430 elsif Is_Derived_Type (Val_Typ) then
26431 Continue := True;
26432 Val_Typ := Etype (Val_Typ);
26433
26434 elsif Is_Private_Type (Val_Typ) then
26435 if Present (Underlying_Full_View (Val_Typ)) then
26436 Continue := True;
26437 Val_Typ := Underlying_Full_View (Val_Typ);
26438
26439 elsif Present (Full_View (Val_Typ)) then
26440 Continue := True;
26441 Val_Typ := Full_View (Val_Typ);
26442 end if;
26443 end if;
26444 end loop;
26445
26446 return Val_Typ;
26447 end Validated_View;
26448
26449 -----------------------
26450 -- Visible_Ancestors --
26451 -----------------------
26452
26453 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
26454 List_1 : Elist_Id;
26455 List_2 : Elist_Id;
26456 Elmt : Elmt_Id;
26457
26458 begin
26459 pragma Assert (Is_Record_Type (Typ) and then Is_Tagged_Type (Typ));
26460
26461 -- Collect all the parents and progenitors of Typ. If the full-view of
26462 -- private parents and progenitors is available then it is used to
26463 -- generate the list of visible ancestors; otherwise their partial
26464 -- view is added to the resulting list.
26465
26466 Collect_Parents
26467 (T => Typ,
26468 List => List_1,
26469 Use_Full_View => True);
26470
26471 Collect_Interfaces
26472 (T => Typ,
26473 Ifaces_List => List_2,
26474 Exclude_Parents => True,
26475 Use_Full_View => True);
26476
26477 -- Join the two lists. Avoid duplications because an interface may
26478 -- simultaneously be parent and progenitor of a type.
26479
26480 Elmt := First_Elmt (List_2);
26481 while Present (Elmt) loop
26482 Append_Unique_Elmt (Node (Elmt), List_1);
26483 Next_Elmt (Elmt);
26484 end loop;
26485
26486 return List_1;
26487 end Visible_Ancestors;
26488
26489 ----------------------
26490 -- Within_Init_Proc --
26491 ----------------------
26492
26493 function Within_Init_Proc return Boolean is
26494 S : Entity_Id;
26495
26496 begin
26497 S := Current_Scope;
26498 while not Is_Overloadable (S) loop
26499 if S = Standard_Standard then
26500 return False;
26501 else
26502 S := Scope (S);
26503 end if;
26504 end loop;
26505
26506 return Is_Init_Proc (S);
26507 end Within_Init_Proc;
26508
26509 ---------------------------
26510 -- Within_Protected_Type --
26511 ---------------------------
26512
26513 function Within_Protected_Type (E : Entity_Id) return Boolean is
26514 Scop : Entity_Id := Scope (E);
26515
26516 begin
26517 while Present (Scop) loop
26518 if Ekind (Scop) = E_Protected_Type then
26519 return True;
26520 end if;
26521
26522 Scop := Scope (Scop);
26523 end loop;
26524
26525 return False;
26526 end Within_Protected_Type;
26527
26528 ------------------
26529 -- Within_Scope --
26530 ------------------
26531
26532 function Within_Scope (E : Entity_Id; S : Entity_Id) return Boolean is
26533 begin
26534 return Scope_Within_Or_Same (Scope (E), S);
26535 end Within_Scope;
26536
26537 ----------------------------
26538 -- Within_Subprogram_Call --
26539 ----------------------------
26540
26541 function Within_Subprogram_Call (N : Node_Id) return Boolean is
26542 Par : Node_Id;
26543
26544 begin
26545 -- Climb the parent chain looking for a function or procedure call
26546
26547 Par := N;
26548 while Present (Par) loop
26549 if Nkind_In (Par, N_Entry_Call_Statement,
26550 N_Function_Call,
26551 N_Procedure_Call_Statement)
26552 then
26553 return True;
26554
26555 -- Prevent the search from going too far
26556
26557 elsif Is_Body_Or_Package_Declaration (Par) then
26558 exit;
26559 end if;
26560
26561 Par := Parent (Par);
26562 end loop;
26563
26564 return False;
26565 end Within_Subprogram_Call;
26566
26567 ----------------
26568 -- Wrong_Type --
26569 ----------------
26570
26571 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
26572 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
26573 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
26574
26575 Matching_Field : Entity_Id;
26576 -- Entity to give a more precise suggestion on how to write a one-
26577 -- element positional aggregate.
26578
26579 function Has_One_Matching_Field return Boolean;
26580 -- Determines if Expec_Type is a record type with a single component or
26581 -- discriminant whose type matches the found type or is one dimensional
26582 -- array whose component type matches the found type. In the case of
26583 -- one discriminant, we ignore the variant parts. That's not accurate,
26584 -- but good enough for the warning.
26585
26586 ----------------------------
26587 -- Has_One_Matching_Field --
26588 ----------------------------
26589
26590 function Has_One_Matching_Field return Boolean is
26591 E : Entity_Id;
26592
26593 begin
26594 Matching_Field := Empty;
26595
26596 if Is_Array_Type (Expec_Type)
26597 and then Number_Dimensions (Expec_Type) = 1
26598 and then Covers (Etype (Component_Type (Expec_Type)), Found_Type)
26599 then
26600 -- Use type name if available. This excludes multidimensional
26601 -- arrays and anonymous arrays.
26602
26603 if Comes_From_Source (Expec_Type) then
26604 Matching_Field := Expec_Type;
26605
26606 -- For an assignment, use name of target
26607
26608 elsif Nkind (Parent (Expr)) = N_Assignment_Statement
26609 and then Is_Entity_Name (Name (Parent (Expr)))
26610 then
26611 Matching_Field := Entity (Name (Parent (Expr)));
26612 end if;
26613
26614 return True;
26615
26616 elsif not Is_Record_Type (Expec_Type) then
26617 return False;
26618
26619 else
26620 E := First_Entity (Expec_Type);
26621 loop
26622 if No (E) then
26623 return False;
26624
26625 elsif not Ekind_In (E, E_Discriminant, E_Component)
26626 or else Nam_In (Chars (E), Name_uTag, Name_uParent)
26627 then
26628 Next_Entity (E);
26629
26630 else
26631 exit;
26632 end if;
26633 end loop;
26634
26635 if not Covers (Etype (E), Found_Type) then
26636 return False;
26637
26638 elsif Present (Next_Entity (E))
26639 and then (Ekind (E) = E_Component
26640 or else Ekind (Next_Entity (E)) = E_Discriminant)
26641 then
26642 return False;
26643
26644 else
26645 Matching_Field := E;
26646 return True;
26647 end if;
26648 end if;
26649 end Has_One_Matching_Field;
26650
26651 -- Start of processing for Wrong_Type
26652
26653 begin
26654 -- Don't output message if either type is Any_Type, or if a message
26655 -- has already been posted for this node. We need to do the latter
26656 -- check explicitly (it is ordinarily done in Errout), because we
26657 -- are using ! to force the output of the error messages.
26658
26659 if Expec_Type = Any_Type
26660 or else Found_Type = Any_Type
26661 or else Error_Posted (Expr)
26662 then
26663 return;
26664
26665 -- If one of the types is a Taft-Amendment type and the other it its
26666 -- completion, it must be an illegal use of a TAT in the spec, for
26667 -- which an error was already emitted. Avoid cascaded errors.
26668
26669 elsif Is_Incomplete_Type (Expec_Type)
26670 and then Has_Completion_In_Body (Expec_Type)
26671 and then Full_View (Expec_Type) = Etype (Expr)
26672 then
26673 return;
26674
26675 elsif Is_Incomplete_Type (Etype (Expr))
26676 and then Has_Completion_In_Body (Etype (Expr))
26677 and then Full_View (Etype (Expr)) = Expec_Type
26678 then
26679 return;
26680
26681 -- In an instance, there is an ongoing problem with completion of
26682 -- type derived from private types. Their structure is what Gigi
26683 -- expects, but the Etype is the parent type rather than the
26684 -- derived private type itself. Do not flag error in this case. The
26685 -- private completion is an entity without a parent, like an Itype.
26686 -- Similarly, full and partial views may be incorrect in the instance.
26687 -- There is no simple way to insure that it is consistent ???
26688
26689 -- A similar view discrepancy can happen in an inlined body, for the
26690 -- same reason: inserted body may be outside of the original package
26691 -- and only partial views are visible at the point of insertion.
26692
26693 elsif In_Instance or else In_Inlined_Body then
26694 if Etype (Etype (Expr)) = Etype (Expected_Type)
26695 and then
26696 (Has_Private_Declaration (Expected_Type)
26697 or else Has_Private_Declaration (Etype (Expr)))
26698 and then No (Parent (Expected_Type))
26699 then
26700 return;
26701
26702 elsif Nkind (Parent (Expr)) = N_Qualified_Expression
26703 and then Entity (Subtype_Mark (Parent (Expr))) = Expected_Type
26704 then
26705 return;
26706
26707 elsif Is_Private_Type (Expected_Type)
26708 and then Present (Full_View (Expected_Type))
26709 and then Covers (Full_View (Expected_Type), Etype (Expr))
26710 then
26711 return;
26712
26713 -- Conversely, type of expression may be the private one
26714
26715 elsif Is_Private_Type (Base_Type (Etype (Expr)))
26716 and then Full_View (Base_Type (Etype (Expr))) = Expected_Type
26717 then
26718 return;
26719 end if;
26720 end if;
26721
26722 -- An interesting special check. If the expression is parenthesized
26723 -- and its type corresponds to the type of the sole component of the
26724 -- expected record type, or to the component type of the expected one
26725 -- dimensional array type, then assume we have a bad aggregate attempt.
26726
26727 if Nkind (Expr) in N_Subexpr
26728 and then Paren_Count (Expr) /= 0
26729 and then Has_One_Matching_Field
26730 then
26731 Error_Msg_N ("positional aggregate cannot have one component", Expr);
26732
26733 if Present (Matching_Field) then
26734 if Is_Array_Type (Expec_Type) then
26735 Error_Msg_NE
26736 ("\write instead `&''First ='> ...`", Expr, Matching_Field);
26737 else
26738 Error_Msg_NE
26739 ("\write instead `& ='> ...`", Expr, Matching_Field);
26740 end if;
26741 end if;
26742
26743 -- Another special check, if we are looking for a pool-specific access
26744 -- type and we found an E_Access_Attribute_Type, then we have the case
26745 -- of an Access attribute being used in a context which needs a pool-
26746 -- specific type, which is never allowed. The one extra check we make
26747 -- is that the expected designated type covers the Found_Type.
26748
26749 elsif Is_Access_Type (Expec_Type)
26750 and then Ekind (Found_Type) = E_Access_Attribute_Type
26751 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
26752 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
26753 and then Covers
26754 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
26755 then
26756 Error_Msg_N -- CODEFIX
26757 ("result must be general access type!", Expr);
26758 Error_Msg_NE -- CODEFIX
26759 ("add ALL to }!", Expr, Expec_Type);
26760
26761 -- Another special check, if the expected type is an integer type,
26762 -- but the expression is of type System.Address, and the parent is
26763 -- an addition or subtraction operation whose left operand is the
26764 -- expression in question and whose right operand is of an integral
26765 -- type, then this is an attempt at address arithmetic, so give
26766 -- appropriate message.
26767
26768 elsif Is_Integer_Type (Expec_Type)
26769 and then Is_RTE (Found_Type, RE_Address)
26770 and then Nkind_In (Parent (Expr), N_Op_Add, N_Op_Subtract)
26771 and then Expr = Left_Opnd (Parent (Expr))
26772 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
26773 then
26774 Error_Msg_N
26775 ("address arithmetic not predefined in package System",
26776 Parent (Expr));
26777 Error_Msg_N
26778 ("\possible missing with/use of System.Storage_Elements",
26779 Parent (Expr));
26780 return;
26781
26782 -- If the expected type is an anonymous access type, as for access
26783 -- parameters and discriminants, the error is on the designated types.
26784
26785 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
26786 if Comes_From_Source (Expec_Type) then
26787 Error_Msg_NE ("expected}!", Expr, Expec_Type);
26788 else
26789 Error_Msg_NE
26790 ("expected an access type with designated}",
26791 Expr, Designated_Type (Expec_Type));
26792 end if;
26793
26794 if Is_Access_Type (Found_Type)
26795 and then not Comes_From_Source (Found_Type)
26796 then
26797 Error_Msg_NE
26798 ("\\found an access type with designated}!",
26799 Expr, Designated_Type (Found_Type));
26800 else
26801 if From_Limited_With (Found_Type) then
26802 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
26803 Error_Msg_Qual_Level := 99;
26804 Error_Msg_NE -- CODEFIX
26805 ("\\missing `WITH &;", Expr, Scope (Found_Type));
26806 Error_Msg_Qual_Level := 0;
26807 else
26808 Error_Msg_NE ("found}!", Expr, Found_Type);
26809 end if;
26810 end if;
26811
26812 -- Normal case of one type found, some other type expected
26813
26814 else
26815 -- If the names of the two types are the same, see if some number
26816 -- of levels of qualification will help. Don't try more than three
26817 -- levels, and if we get to standard, it's no use (and probably
26818 -- represents an error in the compiler) Also do not bother with
26819 -- internal scope names.
26820
26821 declare
26822 Expec_Scope : Entity_Id;
26823 Found_Scope : Entity_Id;
26824
26825 begin
26826 Expec_Scope := Expec_Type;
26827 Found_Scope := Found_Type;
26828
26829 for Levels in Nat range 0 .. 3 loop
26830 if Chars (Expec_Scope) /= Chars (Found_Scope) then
26831 Error_Msg_Qual_Level := Levels;
26832 exit;
26833 end if;
26834
26835 Expec_Scope := Scope (Expec_Scope);
26836 Found_Scope := Scope (Found_Scope);
26837
26838 exit when Expec_Scope = Standard_Standard
26839 or else Found_Scope = Standard_Standard
26840 or else not Comes_From_Source (Expec_Scope)
26841 or else not Comes_From_Source (Found_Scope);
26842 end loop;
26843 end;
26844
26845 if Is_Record_Type (Expec_Type)
26846 and then Present (Corresponding_Remote_Type (Expec_Type))
26847 then
26848 Error_Msg_NE ("expected}!", Expr,
26849 Corresponding_Remote_Type (Expec_Type));
26850 else
26851 Error_Msg_NE ("expected}!", Expr, Expec_Type);
26852 end if;
26853
26854 if Is_Entity_Name (Expr)
26855 and then Is_Package_Or_Generic_Package (Entity (Expr))
26856 then
26857 Error_Msg_N ("\\found package name!", Expr);
26858
26859 elsif Is_Entity_Name (Expr)
26860 and then Ekind_In (Entity (Expr), E_Procedure, E_Generic_Procedure)
26861 then
26862 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
26863 Error_Msg_N
26864 ("found procedure name, possibly missing Access attribute!",
26865 Expr);
26866 else
26867 Error_Msg_N
26868 ("\\found procedure name instead of function!", Expr);
26869 end if;
26870
26871 elsif Nkind (Expr) = N_Function_Call
26872 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
26873 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
26874 and then No (Parameter_Associations (Expr))
26875 then
26876 Error_Msg_N
26877 ("found function name, possibly missing Access attribute!",
26878 Expr);
26879
26880 -- Catch common error: a prefix or infix operator which is not
26881 -- directly visible because the type isn't.
26882
26883 elsif Nkind (Expr) in N_Op
26884 and then Is_Overloaded (Expr)
26885 and then not Is_Immediately_Visible (Expec_Type)
26886 and then not Is_Potentially_Use_Visible (Expec_Type)
26887 and then not In_Use (Expec_Type)
26888 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
26889 then
26890 Error_Msg_N
26891 ("operator of the type is not directly visible!", Expr);
26892
26893 elsif Ekind (Found_Type) = E_Void
26894 and then Present (Parent (Found_Type))
26895 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
26896 then
26897 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
26898
26899 else
26900 Error_Msg_NE ("\\found}!", Expr, Found_Type);
26901 end if;
26902
26903 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
26904 -- of the same modular type, and (M1 and M2) = 0 was intended.
26905
26906 if Expec_Type = Standard_Boolean
26907 and then Is_Modular_Integer_Type (Found_Type)
26908 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
26909 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
26910 then
26911 declare
26912 Op : constant Node_Id := Right_Opnd (Parent (Expr));
26913 L : constant Node_Id := Left_Opnd (Op);
26914 R : constant Node_Id := Right_Opnd (Op);
26915
26916 begin
26917 -- The case for the message is when the left operand of the
26918 -- comparison is the same modular type, or when it is an
26919 -- integer literal (or other universal integer expression),
26920 -- which would have been typed as the modular type if the
26921 -- parens had been there.
26922
26923 if (Etype (L) = Found_Type
26924 or else
26925 Etype (L) = Universal_Integer)
26926 and then Is_Integer_Type (Etype (R))
26927 then
26928 Error_Msg_N
26929 ("\\possible missing parens for modular operation", Expr);
26930 end if;
26931 end;
26932 end if;
26933
26934 -- Reset error message qualification indication
26935
26936 Error_Msg_Qual_Level := 0;
26937 end if;
26938 end Wrong_Type;
26939
26940 --------------------------------
26941 -- Yields_Synchronized_Object --
26942 --------------------------------
26943
26944 function Yields_Synchronized_Object (Typ : Entity_Id) return Boolean is
26945 Has_Sync_Comp : Boolean := False;
26946 Id : Entity_Id;
26947
26948 begin
26949 -- An array type yields a synchronized object if its component type
26950 -- yields a synchronized object.
26951
26952 if Is_Array_Type (Typ) then
26953 return Yields_Synchronized_Object (Component_Type (Typ));
26954
26955 -- A descendant of type Ada.Synchronous_Task_Control.Suspension_Object
26956 -- yields a synchronized object by default.
26957
26958 elsif Is_Descendant_Of_Suspension_Object (Typ) then
26959 return True;
26960
26961 -- A protected type yields a synchronized object by default
26962
26963 elsif Is_Protected_Type (Typ) then
26964 return True;
26965
26966 -- A record type or type extension yields a synchronized object when its
26967 -- discriminants (if any) lack default values and all components are of
26968 -- a type that yields a synchronized object.
26969
26970 elsif Is_Record_Type (Typ) then
26971
26972 -- Inspect all entities defined in the scope of the type, looking for
26973 -- components of a type that does not yield a synchronized object or
26974 -- for discriminants with default values.
26975
26976 Id := First_Entity (Typ);
26977 while Present (Id) loop
26978 if Comes_From_Source (Id) then
26979 if Ekind (Id) = E_Component then
26980 if Yields_Synchronized_Object (Etype (Id)) then
26981 Has_Sync_Comp := True;
26982
26983 -- The component does not yield a synchronized object
26984
26985 else
26986 return False;
26987 end if;
26988
26989 elsif Ekind (Id) = E_Discriminant
26990 and then Present (Expression (Parent (Id)))
26991 then
26992 return False;
26993 end if;
26994 end if;
26995
26996 Next_Entity (Id);
26997 end loop;
26998
26999 -- Ensure that the parent type of a type extension yields a
27000 -- synchronized object.
27001
27002 if Etype (Typ) /= Typ
27003 and then not Is_Private_Type (Etype (Typ))
27004 and then not Yields_Synchronized_Object (Etype (Typ))
27005 then
27006 return False;
27007 end if;
27008
27009 -- If we get here, then all discriminants lack default values and all
27010 -- components are of a type that yields a synchronized object.
27011
27012 return Has_Sync_Comp;
27013
27014 -- A synchronized interface type yields a synchronized object by default
27015
27016 elsif Is_Synchronized_Interface (Typ) then
27017 return True;
27018
27019 -- A task type yields a synchronized object by default
27020
27021 elsif Is_Task_Type (Typ) then
27022 return True;
27023
27024 -- A private type yields a synchronized object if its underlying type
27025 -- does.
27026
27027 elsif Is_Private_Type (Typ)
27028 and then Present (Underlying_Type (Typ))
27029 then
27030 return Yields_Synchronized_Object (Underlying_Type (Typ));
27031
27032 -- Otherwise the type does not yield a synchronized object
27033
27034 else
27035 return False;
27036 end if;
27037 end Yields_Synchronized_Object;
27038
27039 ---------------------------
27040 -- Yields_Universal_Type --
27041 ---------------------------
27042
27043 function Yields_Universal_Type (N : Node_Id) return Boolean is
27044 begin
27045 -- Integer and real literals are of a universal type
27046
27047 if Nkind_In (N, N_Integer_Literal, N_Real_Literal) then
27048 return True;
27049
27050 -- The values of certain attributes are of a universal type
27051
27052 elsif Nkind (N) = N_Attribute_Reference then
27053 return
27054 Universal_Type_Attribute (Get_Attribute_Id (Attribute_Name (N)));
27055
27056 -- ??? There are possibly other cases to consider
27057
27058 else
27059 return False;
27060 end if;
27061 end Yields_Universal_Type;
27062
27063 begin
27064 Erroutc.Subprogram_Name_Ptr := Subprogram_Name'Access;
27065 end Sem_Util;