]> gcc.gnu.org Git - gcc.git/blob - gcc/ada/sem_util.adb
exp_ch3.adb (Expand_N_Object_Declaration): Save and restore relevant SPARK-related...
[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-2017, 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 Atree; use Atree;
30 with Casing; use Casing;
31 with Checks; use Checks;
32 with Debug; use Debug;
33 with Elists; use Elists;
34 with Errout; use Errout;
35 with Erroutc; use Erroutc;
36 with Exp_Ch11; use Exp_Ch11;
37 with Exp_Disp; use Exp_Disp;
38 with Exp_Util; use Exp_Util;
39 with Fname; use Fname;
40 with Freeze; use Freeze;
41 with Lib; use Lib;
42 with Lib.Xref; use Lib.Xref;
43 with Namet.Sp; use Namet.Sp;
44 with Nlists; use Nlists;
45 with Nmake; use Nmake;
46 with Output; use Output;
47 with Restrict; use Restrict;
48 with Rident; use Rident;
49 with Rtsfind; use Rtsfind;
50 with Sem; use Sem;
51 with Sem_Aux; use Sem_Aux;
52 with Sem_Attr; use Sem_Attr;
53 with Sem_Ch6; use Sem_Ch6;
54 with Sem_Ch8; use Sem_Ch8;
55 with Sem_Disp; use Sem_Disp;
56 with Sem_Elab; use Sem_Elab;
57 with Sem_Eval; use Sem_Eval;
58 with Sem_Prag; use Sem_Prag;
59 with Sem_Res; use Sem_Res;
60 with Sem_Warn; use Sem_Warn;
61 with Sem_Type; use Sem_Type;
62 with Sinfo; use Sinfo;
63 with Sinput; use Sinput;
64 with Stand; use Stand;
65 with Style;
66 with Stringt; use Stringt;
67 with Targparm; use Targparm;
68 with Tbuild; use Tbuild;
69 with Ttypes; use Ttypes;
70 with Uname; use Uname;
71
72 with GNAT.HTable; use GNAT.HTable;
73
74 package body Sem_Util is
75
76 -----------------------
77 -- Local Subprograms --
78 -----------------------
79
80 function Build_Component_Subtype
81 (C : List_Id;
82 Loc : Source_Ptr;
83 T : Entity_Id) return Node_Id;
84 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
85 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
86 -- Loc is the source location, T is the original subtype.
87
88 function Has_Enabled_Property
89 (Item_Id : Entity_Id;
90 Property : Name_Id) return Boolean;
91 -- Subsidiary to routines Async_xxx_Enabled and Effective_xxx_Enabled.
92 -- Determine whether an abstract state or a variable denoted by entity
93 -- Item_Id has enabled property Property.
94
95 function Has_Null_Extension (T : Entity_Id) return Boolean;
96 -- T is a derived tagged type. Check whether the type extension is null.
97 -- If the parent type is fully initialized, T can be treated as such.
98
99 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
100 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
101 -- with discriminants whose default values are static, examine only the
102 -- components in the selected variant to determine whether all of them
103 -- have a default.
104
105 type Null_Status_Kind is
106 (Is_Null,
107 -- This value indicates that a subexpression is known to have a null
108 -- value at compile time.
109
110 Is_Non_Null,
111 -- This value indicates that a subexpression is known to have a non-null
112 -- value at compile time.
113
114 Unknown);
115 -- This value indicates that it cannot be determined at compile time
116 -- whether a subexpression yields a null or non-null value.
117
118 function Null_Status (N : Node_Id) return Null_Status_Kind;
119 -- Determine whether subexpression N of an access type yields a null value,
120 -- a non-null value, or the value cannot be determined at compile time. The
121 -- routine does not take simple flow diagnostics into account, it relies on
122 -- static facts such as the presence of null exclusions.
123
124 function Old_Requires_Transient_Scope (Id : Entity_Id) return Boolean;
125 function New_Requires_Transient_Scope (Id : Entity_Id) return Boolean;
126 -- ???We retain the old and new algorithms for Requires_Transient_Scope for
127 -- the time being. New_Requires_Transient_Scope is used by default; the
128 -- debug switch -gnatdQ can be used to do Old_Requires_Transient_Scope
129 -- instead. The intent is to use this temporarily to measure before/after
130 -- efficiency. Note: when this temporary code is removed, the documentation
131 -- of dQ in debug.adb should be removed.
132
133 procedure Results_Differ
134 (Id : Entity_Id;
135 Old_Val : Boolean;
136 New_Val : Boolean);
137 -- ???Debugging code. Called when the Old_Val and New_Val differ. This
138 -- routine will be removed eventially when New_Requires_Transient_Scope
139 -- becomes Requires_Transient_Scope and Old_Requires_Transient_Scope is
140 -- eliminated.
141
142 function Subprogram_Name (N : Node_Id) return String;
143 -- Return the fully qualified name of the enclosing subprogram for the
144 -- given node N, with file:line:col information appended, e.g.
145 -- "subp:file:line:col", corresponding to the source location of the
146 -- body of the subprogram.
147
148 ------------------------------
149 -- Abstract_Interface_List --
150 ------------------------------
151
152 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
153 Nod : Node_Id;
154
155 begin
156 if Is_Concurrent_Type (Typ) then
157
158 -- If we are dealing with a synchronized subtype, go to the base
159 -- type, whose declaration has the interface list.
160
161 -- Shouldn't this be Declaration_Node???
162
163 Nod := Parent (Base_Type (Typ));
164
165 if Nkind (Nod) = N_Full_Type_Declaration then
166 return Empty_List;
167 end if;
168
169 elsif Ekind (Typ) = E_Record_Type_With_Private then
170 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
171 Nod := Type_Definition (Parent (Typ));
172
173 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
174 if Present (Full_View (Typ))
175 and then
176 Nkind (Parent (Full_View (Typ))) = N_Full_Type_Declaration
177 then
178 Nod := Type_Definition (Parent (Full_View (Typ)));
179
180 -- If the full-view is not available we cannot do anything else
181 -- here (the source has errors).
182
183 else
184 return Empty_List;
185 end if;
186
187 -- Support for generic formals with interfaces is still missing ???
188
189 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
190 return Empty_List;
191
192 else
193 pragma Assert
194 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
195 Nod := Parent (Typ);
196 end if;
197
198 elsif Ekind (Typ) = E_Record_Subtype then
199 Nod := Type_Definition (Parent (Etype (Typ)));
200
201 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
202
203 -- Recurse, because parent may still be a private extension. Also
204 -- note that the full view of the subtype or the full view of its
205 -- base type may (both) be unavailable.
206
207 return Abstract_Interface_List (Etype (Typ));
208
209 elsif Ekind (Typ) = E_Record_Type then
210 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
211 Nod := Formal_Type_Definition (Parent (Typ));
212 else
213 Nod := Type_Definition (Parent (Typ));
214 end if;
215
216 -- Otherwise the type is of a kind which does not implement interfaces
217
218 else
219 return Empty_List;
220 end if;
221
222 return Interface_List (Nod);
223 end Abstract_Interface_List;
224
225 --------------------------------
226 -- Add_Access_Type_To_Process --
227 --------------------------------
228
229 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
230 L : Elist_Id;
231
232 begin
233 Ensure_Freeze_Node (E);
234 L := Access_Types_To_Process (Freeze_Node (E));
235
236 if No (L) then
237 L := New_Elmt_List;
238 Set_Access_Types_To_Process (Freeze_Node (E), L);
239 end if;
240
241 Append_Elmt (A, L);
242 end Add_Access_Type_To_Process;
243
244 --------------------------
245 -- Add_Block_Identifier --
246 --------------------------
247
248 procedure Add_Block_Identifier (N : Node_Id; Id : out Entity_Id) is
249 Loc : constant Source_Ptr := Sloc (N);
250
251 begin
252 pragma Assert (Nkind (N) = N_Block_Statement);
253
254 -- The block already has a label, return its entity
255
256 if Present (Identifier (N)) then
257 Id := Entity (Identifier (N));
258
259 -- Create a new block label and set its attributes
260
261 else
262 Id := New_Internal_Entity (E_Block, Current_Scope, Loc, 'B');
263 Set_Etype (Id, Standard_Void_Type);
264 Set_Parent (Id, N);
265
266 Set_Identifier (N, New_Occurrence_Of (Id, Loc));
267 Set_Block_Node (Id, Identifier (N));
268 end if;
269 end Add_Block_Identifier;
270
271 ----------------------------
272 -- Add_Global_Declaration --
273 ----------------------------
274
275 procedure Add_Global_Declaration (N : Node_Id) is
276 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
277
278 begin
279 if No (Declarations (Aux_Node)) then
280 Set_Declarations (Aux_Node, New_List);
281 end if;
282
283 Append_To (Declarations (Aux_Node), N);
284 Analyze (N);
285 end Add_Global_Declaration;
286
287 --------------------------------
288 -- Address_Integer_Convert_OK --
289 --------------------------------
290
291 function Address_Integer_Convert_OK (T1, T2 : Entity_Id) return Boolean is
292 begin
293 if Allow_Integer_Address
294 and then ((Is_Descendant_Of_Address (T1)
295 and then Is_Private_Type (T1)
296 and then Is_Integer_Type (T2))
297 or else
298 (Is_Descendant_Of_Address (T2)
299 and then Is_Private_Type (T2)
300 and then Is_Integer_Type (T1)))
301 then
302 return True;
303 else
304 return False;
305 end if;
306 end Address_Integer_Convert_OK;
307
308 -------------------
309 -- Address_Value --
310 -------------------
311
312 function Address_Value (N : Node_Id) return Node_Id is
313 Expr : Node_Id := N;
314
315 begin
316 loop
317 -- For constant, get constant expression
318
319 if Is_Entity_Name (Expr)
320 and then Ekind (Entity (Expr)) = E_Constant
321 then
322 Expr := Constant_Value (Entity (Expr));
323
324 -- For unchecked conversion, get result to convert
325
326 elsif Nkind (Expr) = N_Unchecked_Type_Conversion then
327 Expr := Expression (Expr);
328
329 -- For (common case) of To_Address call, get argument
330
331 elsif Nkind (Expr) = N_Function_Call
332 and then Is_Entity_Name (Name (Expr))
333 and then Is_RTE (Entity (Name (Expr)), RE_To_Address)
334 then
335 Expr := First (Parameter_Associations (Expr));
336
337 if Nkind (Expr) = N_Parameter_Association then
338 Expr := Explicit_Actual_Parameter (Expr);
339 end if;
340
341 -- We finally have the real expression
342
343 else
344 exit;
345 end if;
346 end loop;
347
348 return Expr;
349 end Address_Value;
350
351 -----------------
352 -- Addressable --
353 -----------------
354
355 -- For now, just 8/16/32/64
356
357 function Addressable (V : Uint) return Boolean is
358 begin
359 return V = Uint_8 or else
360 V = Uint_16 or else
361 V = Uint_32 or else
362 V = Uint_64;
363 end Addressable;
364
365 function Addressable (V : Int) return Boolean is
366 begin
367 return V = 8 or else
368 V = 16 or else
369 V = 32 or else
370 V = 64;
371 end Addressable;
372
373 ---------------------------------
374 -- Aggregate_Constraint_Checks --
375 ---------------------------------
376
377 procedure Aggregate_Constraint_Checks
378 (Exp : Node_Id;
379 Check_Typ : Entity_Id)
380 is
381 Exp_Typ : constant Entity_Id := Etype (Exp);
382
383 begin
384 if Raises_Constraint_Error (Exp) then
385 return;
386 end if;
387
388 -- Ada 2005 (AI-230): Generate a conversion to an anonymous access
389 -- component's type to force the appropriate accessibility checks.
390
391 -- Ada 2005 (AI-231): Generate conversion to the null-excluding type to
392 -- force the corresponding run-time check
393
394 if Is_Access_Type (Check_Typ)
395 and then Is_Local_Anonymous_Access (Check_Typ)
396 then
397 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
398 Analyze_And_Resolve (Exp, Check_Typ);
399 Check_Unset_Reference (Exp);
400 end if;
401
402 -- What follows is really expansion activity, so check that expansion
403 -- is on and is allowed. In GNATprove mode, we also want check flags to
404 -- be added in the tree, so that the formal verification can rely on
405 -- those to be present. In GNATprove mode for formal verification, some
406 -- treatment typically only done during expansion needs to be performed
407 -- on the tree, but it should not be applied inside generics. Otherwise,
408 -- this breaks the name resolution mechanism for generic instances.
409
410 if not Expander_Active
411 and (Inside_A_Generic or not Full_Analysis or not GNATprove_Mode)
412 then
413 return;
414 end if;
415
416 if Is_Access_Type (Check_Typ)
417 and then Can_Never_Be_Null (Check_Typ)
418 and then not Can_Never_Be_Null (Exp_Typ)
419 then
420 Install_Null_Excluding_Check (Exp);
421 end if;
422
423 -- First check if we have to insert discriminant checks
424
425 if Has_Discriminants (Exp_Typ) then
426 Apply_Discriminant_Check (Exp, Check_Typ);
427
428 -- Next emit length checks for array aggregates
429
430 elsif Is_Array_Type (Exp_Typ) then
431 Apply_Length_Check (Exp, Check_Typ);
432
433 -- Finally emit scalar and string checks. If we are dealing with a
434 -- scalar literal we need to check by hand because the Etype of
435 -- literals is not necessarily correct.
436
437 elsif Is_Scalar_Type (Exp_Typ)
438 and then Compile_Time_Known_Value (Exp)
439 then
440 if Is_Out_Of_Range (Exp, Base_Type (Check_Typ)) then
441 Apply_Compile_Time_Constraint_Error
442 (Exp, "value not in range of}??", CE_Range_Check_Failed,
443 Ent => Base_Type (Check_Typ),
444 Typ => Base_Type (Check_Typ));
445
446 elsif Is_Out_Of_Range (Exp, Check_Typ) then
447 Apply_Compile_Time_Constraint_Error
448 (Exp, "value not in range of}??", CE_Range_Check_Failed,
449 Ent => Check_Typ,
450 Typ => Check_Typ);
451
452 elsif not Range_Checks_Suppressed (Check_Typ) then
453 Apply_Scalar_Range_Check (Exp, Check_Typ);
454 end if;
455
456 -- Verify that target type is also scalar, to prevent view anomalies
457 -- in instantiations.
458
459 elsif (Is_Scalar_Type (Exp_Typ)
460 or else Nkind (Exp) = N_String_Literal)
461 and then Is_Scalar_Type (Check_Typ)
462 and then Exp_Typ /= Check_Typ
463 then
464 if Is_Entity_Name (Exp)
465 and then Ekind (Entity (Exp)) = E_Constant
466 then
467 -- If expression is a constant, it is worthwhile checking whether
468 -- it is a bound of the type.
469
470 if (Is_Entity_Name (Type_Low_Bound (Check_Typ))
471 and then Entity (Exp) = Entity (Type_Low_Bound (Check_Typ)))
472 or else
473 (Is_Entity_Name (Type_High_Bound (Check_Typ))
474 and then Entity (Exp) = Entity (Type_High_Bound (Check_Typ)))
475 then
476 return;
477
478 else
479 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
480 Analyze_And_Resolve (Exp, Check_Typ);
481 Check_Unset_Reference (Exp);
482 end if;
483
484 -- Could use a comment on this case ???
485
486 else
487 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
488 Analyze_And_Resolve (Exp, Check_Typ);
489 Check_Unset_Reference (Exp);
490 end if;
491
492 end if;
493 end Aggregate_Constraint_Checks;
494
495 -----------------------
496 -- Alignment_In_Bits --
497 -----------------------
498
499 function Alignment_In_Bits (E : Entity_Id) return Uint is
500 begin
501 return Alignment (E) * System_Storage_Unit;
502 end Alignment_In_Bits;
503
504 --------------------------------------
505 -- All_Composite_Constraints_Static --
506 --------------------------------------
507
508 function All_Composite_Constraints_Static
509 (Constr : Node_Id) return Boolean
510 is
511 begin
512 if No (Constr) or else Error_Posted (Constr) then
513 return True;
514 end if;
515
516 case Nkind (Constr) is
517 when N_Subexpr =>
518 if Nkind (Constr) in N_Has_Entity
519 and then Present (Entity (Constr))
520 then
521 if Is_Type (Entity (Constr)) then
522 return
523 not Is_Discrete_Type (Entity (Constr))
524 or else Is_OK_Static_Subtype (Entity (Constr));
525 end if;
526
527 elsif Nkind (Constr) = N_Range then
528 return
529 Is_OK_Static_Expression (Low_Bound (Constr))
530 and then
531 Is_OK_Static_Expression (High_Bound (Constr));
532
533 elsif Nkind (Constr) = N_Attribute_Reference
534 and then Attribute_Name (Constr) = Name_Range
535 then
536 return
537 Is_OK_Static_Expression
538 (Type_Low_Bound (Etype (Prefix (Constr))))
539 and then
540 Is_OK_Static_Expression
541 (Type_High_Bound (Etype (Prefix (Constr))));
542 end if;
543
544 return
545 not Present (Etype (Constr)) -- previous error
546 or else not Is_Discrete_Type (Etype (Constr))
547 or else Is_OK_Static_Expression (Constr);
548
549 when N_Discriminant_Association =>
550 return All_Composite_Constraints_Static (Expression (Constr));
551
552 when N_Range_Constraint =>
553 return
554 All_Composite_Constraints_Static (Range_Expression (Constr));
555
556 when N_Index_Or_Discriminant_Constraint =>
557 declare
558 One_Cstr : Entity_Id;
559 begin
560 One_Cstr := First (Constraints (Constr));
561 while Present (One_Cstr) loop
562 if not All_Composite_Constraints_Static (One_Cstr) then
563 return False;
564 end if;
565
566 Next (One_Cstr);
567 end loop;
568 end;
569
570 return True;
571
572 when N_Subtype_Indication =>
573 return
574 All_Composite_Constraints_Static (Subtype_Mark (Constr))
575 and then
576 All_Composite_Constraints_Static (Constraint (Constr));
577
578 when others =>
579 raise Program_Error;
580 end case;
581 end All_Composite_Constraints_Static;
582
583 ------------------------
584 -- Append_Entity_Name --
585 ------------------------
586
587 procedure Append_Entity_Name (Buf : in out Bounded_String; E : Entity_Id) is
588 Temp : Bounded_String;
589
590 procedure Inner (E : Entity_Id);
591 -- Inner recursive routine, keep outer routine nonrecursive to ease
592 -- debugging when we get strange results from this routine.
593
594 -----------
595 -- Inner --
596 -----------
597
598 procedure Inner (E : Entity_Id) is
599 Scop : Node_Id;
600 begin
601 -- If entity has an internal name, skip by it, and print its scope.
602 -- Note that we strip a final R from the name before the test; this
603 -- is needed for some cases of instantiations.
604
605 declare
606 E_Name : Bounded_String;
607
608 begin
609 Append (E_Name, Chars (E));
610
611 if E_Name.Chars (E_Name.Length) = 'R' then
612 E_Name.Length := E_Name.Length - 1;
613 end if;
614
615 if Is_Internal_Name (E_Name) then
616 Inner (Scope (E));
617 return;
618 end if;
619 end;
620
621 Scop := Scope (E);
622
623 -- Just print entity name if its scope is at the outer level
624
625 if Scop = Standard_Standard then
626 null;
627
628 -- If scope comes from source, write scope and entity
629
630 elsif Comes_From_Source (Scop) then
631 Append_Entity_Name (Temp, Scop);
632 Append (Temp, '.');
633
634 -- If in wrapper package skip past it
635
636 elsif Present (Scop) and then Is_Wrapper_Package (Scop) then
637 Append_Entity_Name (Temp, Scope (Scop));
638 Append (Temp, '.');
639
640 -- Otherwise nothing to output (happens in unnamed block statements)
641
642 else
643 null;
644 end if;
645
646 -- Output the name
647
648 declare
649 E_Name : Bounded_String;
650
651 begin
652 Append_Unqualified_Decoded (E_Name, Chars (E));
653
654 -- Remove trailing upper-case letters from the name (useful for
655 -- dealing with some cases of internal names generated in the case
656 -- of references from within a generic).
657
658 while E_Name.Length > 1
659 and then E_Name.Chars (E_Name.Length) in 'A' .. 'Z'
660 loop
661 E_Name.Length := E_Name.Length - 1;
662 end loop;
663
664 -- Adjust casing appropriately (gets name from source if possible)
665
666 Adjust_Name_Case (E_Name, Sloc (E));
667 Append (Temp, E_Name);
668 end;
669 end Inner;
670
671 -- Start of processing for Append_Entity_Name
672
673 begin
674 Inner (E);
675 Append (Buf, Temp);
676 end Append_Entity_Name;
677
678 ---------------------------------
679 -- Append_Inherited_Subprogram --
680 ---------------------------------
681
682 procedure Append_Inherited_Subprogram (S : Entity_Id) is
683 Par : constant Entity_Id := Alias (S);
684 -- The parent subprogram
685
686 Scop : constant Entity_Id := Scope (Par);
687 -- The scope of definition of the parent subprogram
688
689 Typ : constant Entity_Id := Defining_Entity (Parent (S));
690 -- The derived type of which S is a primitive operation
691
692 Decl : Node_Id;
693 Next_E : Entity_Id;
694
695 begin
696 if Ekind (Current_Scope) = E_Package
697 and then In_Private_Part (Current_Scope)
698 and then Has_Private_Declaration (Typ)
699 and then Is_Tagged_Type (Typ)
700 and then Scop = Current_Scope
701 then
702 -- The inherited operation is available at the earliest place after
703 -- the derived type declaration ( RM 7.3.1 (6/1)). This is only
704 -- relevant for type extensions. If the parent operation appears
705 -- after the type extension, the operation is not visible.
706
707 Decl := First
708 (Visible_Declarations
709 (Package_Specification (Current_Scope)));
710 while Present (Decl) loop
711 if Nkind (Decl) = N_Private_Extension_Declaration
712 and then Defining_Entity (Decl) = Typ
713 then
714 if Sloc (Decl) > Sloc (Par) then
715 Next_E := Next_Entity (Par);
716 Set_Next_Entity (Par, S);
717 Set_Next_Entity (S, Next_E);
718 return;
719
720 else
721 exit;
722 end if;
723 end if;
724
725 Next (Decl);
726 end loop;
727 end if;
728
729 -- If partial view is not a type extension, or it appears before the
730 -- subprogram declaration, insert normally at end of entity list.
731
732 Append_Entity (S, Current_Scope);
733 end Append_Inherited_Subprogram;
734
735 -----------------------------------------
736 -- Apply_Compile_Time_Constraint_Error --
737 -----------------------------------------
738
739 procedure Apply_Compile_Time_Constraint_Error
740 (N : Node_Id;
741 Msg : String;
742 Reason : RT_Exception_Code;
743 Ent : Entity_Id := Empty;
744 Typ : Entity_Id := Empty;
745 Loc : Source_Ptr := No_Location;
746 Rep : Boolean := True;
747 Warn : Boolean := False)
748 is
749 Stat : constant Boolean := Is_Static_Expression (N);
750 R_Stat : constant Node_Id :=
751 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
752 Rtyp : Entity_Id;
753
754 begin
755 if No (Typ) then
756 Rtyp := Etype (N);
757 else
758 Rtyp := Typ;
759 end if;
760
761 Discard_Node
762 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
763
764 -- In GNATprove mode, do not replace the node with an exception raised.
765 -- In such a case, either the call to Compile_Time_Constraint_Error
766 -- issues an error which stops analysis, or it issues a warning in
767 -- a few cases where a suitable check flag is set for GNATprove to
768 -- generate a check message.
769
770 if not Rep or GNATprove_Mode then
771 return;
772 end if;
773
774 -- Now we replace the node by an N_Raise_Constraint_Error node
775 -- This does not need reanalyzing, so set it as analyzed now.
776
777 Rewrite (N, R_Stat);
778 Set_Analyzed (N, True);
779
780 Set_Etype (N, Rtyp);
781 Set_Raises_Constraint_Error (N);
782
783 -- Now deal with possible local raise handling
784
785 Possible_Local_Raise (N, Standard_Constraint_Error);
786
787 -- If the original expression was marked as static, the result is
788 -- still marked as static, but the Raises_Constraint_Error flag is
789 -- always set so that further static evaluation is not attempted.
790
791 if Stat then
792 Set_Is_Static_Expression (N);
793 end if;
794 end Apply_Compile_Time_Constraint_Error;
795
796 ---------------------------
797 -- Async_Readers_Enabled --
798 ---------------------------
799
800 function Async_Readers_Enabled (Id : Entity_Id) return Boolean is
801 begin
802 return Has_Enabled_Property (Id, Name_Async_Readers);
803 end Async_Readers_Enabled;
804
805 ---------------------------
806 -- Async_Writers_Enabled --
807 ---------------------------
808
809 function Async_Writers_Enabled (Id : Entity_Id) return Boolean is
810 begin
811 return Has_Enabled_Property (Id, Name_Async_Writers);
812 end Async_Writers_Enabled;
813
814 --------------------------------------
815 -- Available_Full_View_Of_Component --
816 --------------------------------------
817
818 function Available_Full_View_Of_Component (T : Entity_Id) return Boolean is
819 ST : constant Entity_Id := Scope (T);
820 SCT : constant Entity_Id := Scope (Component_Type (T));
821 begin
822 return In_Open_Scopes (ST)
823 and then In_Open_Scopes (SCT)
824 and then Scope_Depth (ST) >= Scope_Depth (SCT);
825 end Available_Full_View_Of_Component;
826
827 -------------------
828 -- Bad_Attribute --
829 -------------------
830
831 procedure Bad_Attribute
832 (N : Node_Id;
833 Nam : Name_Id;
834 Warn : Boolean := False)
835 is
836 begin
837 Error_Msg_Warn := Warn;
838 Error_Msg_N ("unrecognized attribute&<<", N);
839
840 -- Check for possible misspelling
841
842 Error_Msg_Name_1 := First_Attribute_Name;
843 while Error_Msg_Name_1 <= Last_Attribute_Name loop
844 if Is_Bad_Spelling_Of (Nam, Error_Msg_Name_1) then
845 Error_Msg_N -- CODEFIX
846 ("\possible misspelling of %<<", N);
847 exit;
848 end if;
849
850 Error_Msg_Name_1 := Error_Msg_Name_1 + 1;
851 end loop;
852 end Bad_Attribute;
853
854 --------------------------------
855 -- Bad_Predicated_Subtype_Use --
856 --------------------------------
857
858 procedure Bad_Predicated_Subtype_Use
859 (Msg : String;
860 N : Node_Id;
861 Typ : Entity_Id;
862 Suggest_Static : Boolean := False)
863 is
864 Gen : Entity_Id;
865
866 begin
867 -- Avoid cascaded errors
868
869 if Error_Posted (N) then
870 return;
871 end if;
872
873 if Inside_A_Generic then
874 Gen := Current_Scope;
875 while Present (Gen) and then Ekind (Gen) /= E_Generic_Package loop
876 Gen := Scope (Gen);
877 end loop;
878
879 if No (Gen) then
880 return;
881 end if;
882
883 if Is_Generic_Formal (Typ) and then Is_Discrete_Type (Typ) then
884 Set_No_Predicate_On_Actual (Typ);
885 end if;
886
887 elsif Has_Predicates (Typ) then
888 if Is_Generic_Actual_Type (Typ) then
889
890 -- The restriction on loop parameters is only that the type
891 -- should have no dynamic predicates.
892
893 if Nkind (Parent (N)) = N_Loop_Parameter_Specification
894 and then not Has_Dynamic_Predicate_Aspect (Typ)
895 and then Is_OK_Static_Subtype (Typ)
896 then
897 return;
898 end if;
899
900 Gen := Current_Scope;
901 while not Is_Generic_Instance (Gen) loop
902 Gen := Scope (Gen);
903 end loop;
904
905 pragma Assert (Present (Gen));
906
907 if Ekind (Gen) = E_Package and then In_Package_Body (Gen) then
908 Error_Msg_Warn := SPARK_Mode /= On;
909 Error_Msg_FE (Msg & "<<", N, Typ);
910 Error_Msg_F ("\Program_Error [<<", N);
911
912 Insert_Action (N,
913 Make_Raise_Program_Error (Sloc (N),
914 Reason => PE_Bad_Predicated_Generic_Type));
915
916 else
917 Error_Msg_FE (Msg & "<<", N, Typ);
918 end if;
919
920 else
921 Error_Msg_FE (Msg, N, Typ);
922 end if;
923
924 -- Emit an optional suggestion on how to remedy the error if the
925 -- context warrants it.
926
927 if Suggest_Static and then Has_Static_Predicate (Typ) then
928 Error_Msg_FE ("\predicate of & should be marked static", N, Typ);
929 end if;
930 end if;
931 end Bad_Predicated_Subtype_Use;
932
933 -----------------------------------------
934 -- Bad_Unordered_Enumeration_Reference --
935 -----------------------------------------
936
937 function Bad_Unordered_Enumeration_Reference
938 (N : Node_Id;
939 T : Entity_Id) return Boolean
940 is
941 begin
942 return Is_Enumeration_Type (T)
943 and then Warn_On_Unordered_Enumeration_Type
944 and then not Is_Generic_Type (T)
945 and then Comes_From_Source (N)
946 and then not Has_Pragma_Ordered (T)
947 and then not In_Same_Extended_Unit (N, T);
948 end Bad_Unordered_Enumeration_Reference;
949
950 ----------------------------
951 -- Begin_Keyword_Location --
952 ----------------------------
953
954 function Begin_Keyword_Location (N : Node_Id) return Source_Ptr is
955 HSS : Node_Id;
956
957 begin
958 pragma Assert (Nkind_In (N, N_Block_Statement,
959 N_Entry_Body,
960 N_Package_Body,
961 N_Subprogram_Body,
962 N_Task_Body));
963
964 HSS := Handled_Statement_Sequence (N);
965
966 -- When the handled sequence of statements comes from source, the
967 -- location of the "begin" keyword is that of the sequence itself.
968 -- Note that an internal construct may inherit a source sequence.
969
970 if Comes_From_Source (HSS) then
971 return Sloc (HSS);
972
973 -- The parser generates an internal handled sequence of statements to
974 -- capture the location of the "begin" keyword if present in the source.
975 -- Since there are no source statements, the location of the "begin"
976 -- keyword is effectively that of the "end" keyword.
977
978 elsif Comes_From_Source (N) then
979 return Sloc (HSS);
980
981 -- Otherwise the construct is internal and should carry the location of
982 -- the original construct which prompted its creation.
983
984 else
985 return Sloc (N);
986 end if;
987 end Begin_Keyword_Location;
988
989 --------------------------
990 -- Build_Actual_Subtype --
991 --------------------------
992
993 function Build_Actual_Subtype
994 (T : Entity_Id;
995 N : Node_Or_Entity_Id) return Node_Id
996 is
997 Loc : Source_Ptr;
998 -- Normally Sloc (N), but may point to corresponding body in some cases
999
1000 Constraints : List_Id;
1001 Decl : Node_Id;
1002 Discr : Entity_Id;
1003 Hi : Node_Id;
1004 Lo : Node_Id;
1005 Subt : Entity_Id;
1006 Disc_Type : Entity_Id;
1007 Obj : Node_Id;
1008
1009 begin
1010 Loc := Sloc (N);
1011
1012 if Nkind (N) = N_Defining_Identifier then
1013 Obj := New_Occurrence_Of (N, Loc);
1014
1015 -- If this is a formal parameter of a subprogram declaration, and
1016 -- we are compiling the body, we want the declaration for the
1017 -- actual subtype to carry the source position of the body, to
1018 -- prevent anomalies in gdb when stepping through the code.
1019
1020 if Is_Formal (N) then
1021 declare
1022 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
1023 begin
1024 if Nkind (Decl) = N_Subprogram_Declaration
1025 and then Present (Corresponding_Body (Decl))
1026 then
1027 Loc := Sloc (Corresponding_Body (Decl));
1028 end if;
1029 end;
1030 end if;
1031
1032 else
1033 Obj := N;
1034 end if;
1035
1036 if Is_Array_Type (T) then
1037 Constraints := New_List;
1038 for J in 1 .. Number_Dimensions (T) loop
1039
1040 -- Build an array subtype declaration with the nominal subtype and
1041 -- the bounds of the actual. Add the declaration in front of the
1042 -- local declarations for the subprogram, for analysis before any
1043 -- reference to the formal in the body.
1044
1045 Lo :=
1046 Make_Attribute_Reference (Loc,
1047 Prefix =>
1048 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
1049 Attribute_Name => Name_First,
1050 Expressions => New_List (
1051 Make_Integer_Literal (Loc, J)));
1052
1053 Hi :=
1054 Make_Attribute_Reference (Loc,
1055 Prefix =>
1056 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
1057 Attribute_Name => Name_Last,
1058 Expressions => New_List (
1059 Make_Integer_Literal (Loc, J)));
1060
1061 Append (Make_Range (Loc, Lo, Hi), Constraints);
1062 end loop;
1063
1064 -- If the type has unknown discriminants there is no constrained
1065 -- subtype to build. This is never called for a formal or for a
1066 -- lhs, so returning the type is ok ???
1067
1068 elsif Has_Unknown_Discriminants (T) then
1069 return T;
1070
1071 else
1072 Constraints := New_List;
1073
1074 -- Type T is a generic derived type, inherit the discriminants from
1075 -- the parent type.
1076
1077 if Is_Private_Type (T)
1078 and then No (Full_View (T))
1079
1080 -- T was flagged as an error if it was declared as a formal
1081 -- derived type with known discriminants. In this case there
1082 -- is no need to look at the parent type since T already carries
1083 -- its own discriminants.
1084
1085 and then not Error_Posted (T)
1086 then
1087 Disc_Type := Etype (Base_Type (T));
1088 else
1089 Disc_Type := T;
1090 end if;
1091
1092 Discr := First_Discriminant (Disc_Type);
1093 while Present (Discr) loop
1094 Append_To (Constraints,
1095 Make_Selected_Component (Loc,
1096 Prefix =>
1097 Duplicate_Subexpr_No_Checks (Obj),
1098 Selector_Name => New_Occurrence_Of (Discr, Loc)));
1099 Next_Discriminant (Discr);
1100 end loop;
1101 end if;
1102
1103 Subt := Make_Temporary (Loc, 'S', Related_Node => N);
1104 Set_Is_Internal (Subt);
1105
1106 Decl :=
1107 Make_Subtype_Declaration (Loc,
1108 Defining_Identifier => Subt,
1109 Subtype_Indication =>
1110 Make_Subtype_Indication (Loc,
1111 Subtype_Mark => New_Occurrence_Of (T, Loc),
1112 Constraint =>
1113 Make_Index_Or_Discriminant_Constraint (Loc,
1114 Constraints => Constraints)));
1115
1116 Mark_Rewrite_Insertion (Decl);
1117 return Decl;
1118 end Build_Actual_Subtype;
1119
1120 ---------------------------------------
1121 -- Build_Actual_Subtype_Of_Component --
1122 ---------------------------------------
1123
1124 function Build_Actual_Subtype_Of_Component
1125 (T : Entity_Id;
1126 N : Node_Id) return Node_Id
1127 is
1128 Loc : constant Source_Ptr := Sloc (N);
1129 P : constant Node_Id := Prefix (N);
1130 D : Elmt_Id;
1131 Id : Node_Id;
1132 Index_Typ : Entity_Id;
1133
1134 Desig_Typ : Entity_Id;
1135 -- This is either a copy of T, or if T is an access type, then it is
1136 -- the directly designated type of this access type.
1137
1138 function Build_Actual_Array_Constraint return List_Id;
1139 -- If one or more of the bounds of the component depends on
1140 -- discriminants, build actual constraint using the discriminants
1141 -- of the prefix.
1142
1143 function Build_Actual_Record_Constraint return List_Id;
1144 -- Similar to previous one, for discriminated components constrained
1145 -- by the discriminant of the enclosing object.
1146
1147 -----------------------------------
1148 -- Build_Actual_Array_Constraint --
1149 -----------------------------------
1150
1151 function Build_Actual_Array_Constraint return List_Id is
1152 Constraints : constant List_Id := New_List;
1153 Indx : Node_Id;
1154 Hi : Node_Id;
1155 Lo : Node_Id;
1156 Old_Hi : Node_Id;
1157 Old_Lo : Node_Id;
1158
1159 begin
1160 Indx := First_Index (Desig_Typ);
1161 while Present (Indx) loop
1162 Old_Lo := Type_Low_Bound (Etype (Indx));
1163 Old_Hi := Type_High_Bound (Etype (Indx));
1164
1165 if Denotes_Discriminant (Old_Lo) then
1166 Lo :=
1167 Make_Selected_Component (Loc,
1168 Prefix => New_Copy_Tree (P),
1169 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
1170
1171 else
1172 Lo := New_Copy_Tree (Old_Lo);
1173
1174 -- The new bound will be reanalyzed in the enclosing
1175 -- declaration. For literal bounds that come from a type
1176 -- declaration, the type of the context must be imposed, so
1177 -- insure that analysis will take place. For non-universal
1178 -- types this is not strictly necessary.
1179
1180 Set_Analyzed (Lo, False);
1181 end if;
1182
1183 if Denotes_Discriminant (Old_Hi) then
1184 Hi :=
1185 Make_Selected_Component (Loc,
1186 Prefix => New_Copy_Tree (P),
1187 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
1188
1189 else
1190 Hi := New_Copy_Tree (Old_Hi);
1191 Set_Analyzed (Hi, False);
1192 end if;
1193
1194 Append (Make_Range (Loc, Lo, Hi), Constraints);
1195 Next_Index (Indx);
1196 end loop;
1197
1198 return Constraints;
1199 end Build_Actual_Array_Constraint;
1200
1201 ------------------------------------
1202 -- Build_Actual_Record_Constraint --
1203 ------------------------------------
1204
1205 function Build_Actual_Record_Constraint return List_Id is
1206 Constraints : constant List_Id := New_List;
1207 D : Elmt_Id;
1208 D_Val : Node_Id;
1209
1210 begin
1211 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1212 while Present (D) loop
1213 if Denotes_Discriminant (Node (D)) then
1214 D_Val := Make_Selected_Component (Loc,
1215 Prefix => New_Copy_Tree (P),
1216 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
1217
1218 else
1219 D_Val := New_Copy_Tree (Node (D));
1220 end if;
1221
1222 Append (D_Val, Constraints);
1223 Next_Elmt (D);
1224 end loop;
1225
1226 return Constraints;
1227 end Build_Actual_Record_Constraint;
1228
1229 -- Start of processing for Build_Actual_Subtype_Of_Component
1230
1231 begin
1232 -- Why the test for Spec_Expression mode here???
1233
1234 if In_Spec_Expression then
1235 return Empty;
1236
1237 -- More comments for the rest of this body would be good ???
1238
1239 elsif Nkind (N) = N_Explicit_Dereference then
1240 if Is_Composite_Type (T)
1241 and then not Is_Constrained (T)
1242 and then not (Is_Class_Wide_Type (T)
1243 and then Is_Constrained (Root_Type (T)))
1244 and then not Has_Unknown_Discriminants (T)
1245 then
1246 -- If the type of the dereference is already constrained, it is an
1247 -- actual subtype.
1248
1249 if Is_Array_Type (Etype (N))
1250 and then Is_Constrained (Etype (N))
1251 then
1252 return Empty;
1253 else
1254 Remove_Side_Effects (P);
1255 return Build_Actual_Subtype (T, N);
1256 end if;
1257 else
1258 return Empty;
1259 end if;
1260 end if;
1261
1262 if Ekind (T) = E_Access_Subtype then
1263 Desig_Typ := Designated_Type (T);
1264 else
1265 Desig_Typ := T;
1266 end if;
1267
1268 if Ekind (Desig_Typ) = E_Array_Subtype then
1269 Id := First_Index (Desig_Typ);
1270 while Present (Id) loop
1271 Index_Typ := Underlying_Type (Etype (Id));
1272
1273 if Denotes_Discriminant (Type_Low_Bound (Index_Typ))
1274 or else
1275 Denotes_Discriminant (Type_High_Bound (Index_Typ))
1276 then
1277 Remove_Side_Effects (P);
1278 return
1279 Build_Component_Subtype
1280 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
1281 end if;
1282
1283 Next_Index (Id);
1284 end loop;
1285
1286 elsif Is_Composite_Type (Desig_Typ)
1287 and then Has_Discriminants (Desig_Typ)
1288 and then not Has_Unknown_Discriminants (Desig_Typ)
1289 then
1290 if Is_Private_Type (Desig_Typ)
1291 and then No (Discriminant_Constraint (Desig_Typ))
1292 then
1293 Desig_Typ := Full_View (Desig_Typ);
1294 end if;
1295
1296 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1297 while Present (D) loop
1298 if Denotes_Discriminant (Node (D)) then
1299 Remove_Side_Effects (P);
1300 return
1301 Build_Component_Subtype (
1302 Build_Actual_Record_Constraint, Loc, Base_Type (T));
1303 end if;
1304
1305 Next_Elmt (D);
1306 end loop;
1307 end if;
1308
1309 -- If none of the above, the actual and nominal subtypes are the same
1310
1311 return Empty;
1312 end Build_Actual_Subtype_Of_Component;
1313
1314 ---------------------------------
1315 -- Build_Class_Wide_Clone_Body --
1316 ---------------------------------
1317
1318 procedure Build_Class_Wide_Clone_Body
1319 (Spec_Id : Entity_Id;
1320 Bod : Node_Id)
1321 is
1322 Loc : constant Source_Ptr := Sloc (Bod);
1323 Clone_Id : constant Entity_Id := Class_Wide_Clone (Spec_Id);
1324 Clone_Body : Node_Id;
1325
1326 begin
1327 -- The declaration of the class-wide clone was created when the
1328 -- corresponding class-wide condition was analyzed.
1329
1330 Clone_Body :=
1331 Make_Subprogram_Body (Loc,
1332 Specification =>
1333 Copy_Subprogram_Spec (Parent (Clone_Id)),
1334 Declarations => Declarations (Bod),
1335 Handled_Statement_Sequence => Handled_Statement_Sequence (Bod));
1336
1337 -- The new operation is internal and overriding indicators do not apply
1338 -- (the original primitive may have carried one).
1339
1340 Set_Must_Override (Specification (Clone_Body), False);
1341 Insert_Before (Bod, Clone_Body);
1342 Analyze (Clone_Body);
1343 end Build_Class_Wide_Clone_Body;
1344
1345 ---------------------------------
1346 -- Build_Class_Wide_Clone_Call --
1347 ---------------------------------
1348
1349 function Build_Class_Wide_Clone_Call
1350 (Loc : Source_Ptr;
1351 Decls : List_Id;
1352 Spec_Id : Entity_Id;
1353 Spec : Node_Id) return Node_Id
1354 is
1355 Clone_Id : constant Entity_Id := Class_Wide_Clone (Spec_Id);
1356 Par_Type : constant Entity_Id := Find_Dispatching_Type (Spec_Id);
1357
1358 Actuals : List_Id;
1359 Call : Node_Id;
1360 Formal : Entity_Id;
1361 New_Body : Node_Id;
1362 New_F_Spec : Entity_Id;
1363 New_Formal : Entity_Id;
1364
1365 begin
1366 Actuals := Empty_List;
1367 Formal := First_Formal (Spec_Id);
1368 New_F_Spec := First (Parameter_Specifications (Spec));
1369
1370 -- Build parameter association for call to class-wide clone.
1371
1372 while Present (Formal) loop
1373 New_Formal := Defining_Identifier (New_F_Spec);
1374
1375 -- If controlling argument and operation is inherited, add conversion
1376 -- to parent type for the call.
1377
1378 if Etype (Formal) = Par_Type
1379 and then not Is_Empty_List (Decls)
1380 then
1381 Append_To (Actuals,
1382 Make_Type_Conversion (Loc,
1383 New_Occurrence_Of (Par_Type, Loc),
1384 New_Occurrence_Of (New_Formal, Loc)));
1385
1386 else
1387 Append_To (Actuals, New_Occurrence_Of (New_Formal, Loc));
1388 end if;
1389
1390 Next_Formal (Formal);
1391 Next (New_F_Spec);
1392 end loop;
1393
1394 if Ekind (Spec_Id) = E_Procedure then
1395 Call :=
1396 Make_Procedure_Call_Statement (Loc,
1397 Name => New_Occurrence_Of (Clone_Id, Loc),
1398 Parameter_Associations => Actuals);
1399 else
1400 Call :=
1401 Make_Simple_Return_Statement (Loc,
1402 Expression =>
1403 Make_Function_Call (Loc,
1404 Name => New_Occurrence_Of (Clone_Id, Loc),
1405 Parameter_Associations => Actuals));
1406 end if;
1407
1408 New_Body :=
1409 Make_Subprogram_Body (Loc,
1410 Specification =>
1411 Copy_Subprogram_Spec (Spec),
1412 Declarations => Decls,
1413 Handled_Statement_Sequence =>
1414 Make_Handled_Sequence_Of_Statements (Loc,
1415 Statements => New_List (Call),
1416 End_Label => Make_Identifier (Loc, Chars (Spec_Id))));
1417
1418 return New_Body;
1419 end Build_Class_Wide_Clone_Call;
1420
1421 ---------------------------------
1422 -- Build_Class_Wide_Clone_Decl --
1423 ---------------------------------
1424
1425 procedure Build_Class_Wide_Clone_Decl (Spec_Id : Entity_Id) is
1426 Loc : constant Source_Ptr := Sloc (Spec_Id);
1427 Clone_Id : constant Entity_Id :=
1428 Make_Defining_Identifier (Loc,
1429 New_External_Name (Chars (Spec_Id), Suffix => "CL"));
1430
1431 Decl : Node_Id;
1432 Spec : Node_Id;
1433
1434 begin
1435 Spec := Copy_Subprogram_Spec (Parent (Spec_Id));
1436 Set_Must_Override (Spec, False);
1437 Set_Must_Not_Override (Spec, False);
1438 Set_Defining_Unit_Name (Spec, Clone_Id);
1439
1440 Decl := Make_Subprogram_Declaration (Loc, Spec);
1441 Append (Decl, List_Containing (Unit_Declaration_Node (Spec_Id)));
1442
1443 -- Link clone to original subprogram, for use when building body and
1444 -- wrapper call to inherited operation.
1445
1446 Set_Class_Wide_Clone (Spec_Id, Clone_Id);
1447 end Build_Class_Wide_Clone_Decl;
1448
1449 -----------------------------
1450 -- Build_Component_Subtype --
1451 -----------------------------
1452
1453 function Build_Component_Subtype
1454 (C : List_Id;
1455 Loc : Source_Ptr;
1456 T : Entity_Id) return Node_Id
1457 is
1458 Subt : Entity_Id;
1459 Decl : Node_Id;
1460
1461 begin
1462 -- Unchecked_Union components do not require component subtypes
1463
1464 if Is_Unchecked_Union (T) then
1465 return Empty;
1466 end if;
1467
1468 Subt := Make_Temporary (Loc, 'S');
1469 Set_Is_Internal (Subt);
1470
1471 Decl :=
1472 Make_Subtype_Declaration (Loc,
1473 Defining_Identifier => Subt,
1474 Subtype_Indication =>
1475 Make_Subtype_Indication (Loc,
1476 Subtype_Mark => New_Occurrence_Of (Base_Type (T), Loc),
1477 Constraint =>
1478 Make_Index_Or_Discriminant_Constraint (Loc,
1479 Constraints => C)));
1480
1481 Mark_Rewrite_Insertion (Decl);
1482 return Decl;
1483 end Build_Component_Subtype;
1484
1485 ---------------------------
1486 -- Build_Default_Subtype --
1487 ---------------------------
1488
1489 function Build_Default_Subtype
1490 (T : Entity_Id;
1491 N : Node_Id) return Entity_Id
1492 is
1493 Loc : constant Source_Ptr := Sloc (N);
1494 Disc : Entity_Id;
1495
1496 Bas : Entity_Id;
1497 -- The base type that is to be constrained by the defaults
1498
1499 begin
1500 if not Has_Discriminants (T) or else Is_Constrained (T) then
1501 return T;
1502 end if;
1503
1504 Bas := Base_Type (T);
1505
1506 -- If T is non-private but its base type is private, this is the
1507 -- completion of a subtype declaration whose parent type is private
1508 -- (see Complete_Private_Subtype in Sem_Ch3). The proper discriminants
1509 -- are to be found in the full view of the base. Check that the private
1510 -- status of T and its base differ.
1511
1512 if Is_Private_Type (Bas)
1513 and then not Is_Private_Type (T)
1514 and then Present (Full_View (Bas))
1515 then
1516 Bas := Full_View (Bas);
1517 end if;
1518
1519 Disc := First_Discriminant (T);
1520
1521 if No (Discriminant_Default_Value (Disc)) then
1522 return T;
1523 end if;
1524
1525 declare
1526 Act : constant Entity_Id := Make_Temporary (Loc, 'S');
1527 Constraints : constant List_Id := New_List;
1528 Decl : Node_Id;
1529
1530 begin
1531 while Present (Disc) loop
1532 Append_To (Constraints,
1533 New_Copy_Tree (Discriminant_Default_Value (Disc)));
1534 Next_Discriminant (Disc);
1535 end loop;
1536
1537 Decl :=
1538 Make_Subtype_Declaration (Loc,
1539 Defining_Identifier => Act,
1540 Subtype_Indication =>
1541 Make_Subtype_Indication (Loc,
1542 Subtype_Mark => New_Occurrence_Of (Bas, Loc),
1543 Constraint =>
1544 Make_Index_Or_Discriminant_Constraint (Loc,
1545 Constraints => Constraints)));
1546
1547 Insert_Action (N, Decl);
1548
1549 -- If the context is a component declaration the subtype declaration
1550 -- will be analyzed when the enclosing type is frozen, otherwise do
1551 -- it now.
1552
1553 if Ekind (Current_Scope) /= E_Record_Type then
1554 Analyze (Decl);
1555 end if;
1556
1557 return Act;
1558 end;
1559 end Build_Default_Subtype;
1560
1561 --------------------------------------------
1562 -- Build_Discriminal_Subtype_Of_Component --
1563 --------------------------------------------
1564
1565 function Build_Discriminal_Subtype_Of_Component
1566 (T : Entity_Id) return Node_Id
1567 is
1568 Loc : constant Source_Ptr := Sloc (T);
1569 D : Elmt_Id;
1570 Id : Node_Id;
1571
1572 function Build_Discriminal_Array_Constraint return List_Id;
1573 -- If one or more of the bounds of the component depends on
1574 -- discriminants, build actual constraint using the discriminants
1575 -- of the prefix.
1576
1577 function Build_Discriminal_Record_Constraint return List_Id;
1578 -- Similar to previous one, for discriminated components constrained by
1579 -- the discriminant of the enclosing object.
1580
1581 ----------------------------------------
1582 -- Build_Discriminal_Array_Constraint --
1583 ----------------------------------------
1584
1585 function Build_Discriminal_Array_Constraint return List_Id is
1586 Constraints : constant List_Id := New_List;
1587 Indx : Node_Id;
1588 Hi : Node_Id;
1589 Lo : Node_Id;
1590 Old_Hi : Node_Id;
1591 Old_Lo : Node_Id;
1592
1593 begin
1594 Indx := First_Index (T);
1595 while Present (Indx) loop
1596 Old_Lo := Type_Low_Bound (Etype (Indx));
1597 Old_Hi := Type_High_Bound (Etype (Indx));
1598
1599 if Denotes_Discriminant (Old_Lo) then
1600 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
1601
1602 else
1603 Lo := New_Copy_Tree (Old_Lo);
1604 end if;
1605
1606 if Denotes_Discriminant (Old_Hi) then
1607 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
1608
1609 else
1610 Hi := New_Copy_Tree (Old_Hi);
1611 end if;
1612
1613 Append (Make_Range (Loc, Lo, Hi), Constraints);
1614 Next_Index (Indx);
1615 end loop;
1616
1617 return Constraints;
1618 end Build_Discriminal_Array_Constraint;
1619
1620 -----------------------------------------
1621 -- Build_Discriminal_Record_Constraint --
1622 -----------------------------------------
1623
1624 function Build_Discriminal_Record_Constraint return List_Id is
1625 Constraints : constant List_Id := New_List;
1626 D : Elmt_Id;
1627 D_Val : Node_Id;
1628
1629 begin
1630 D := First_Elmt (Discriminant_Constraint (T));
1631 while Present (D) loop
1632 if Denotes_Discriminant (Node (D)) then
1633 D_Val :=
1634 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
1635 else
1636 D_Val := New_Copy_Tree (Node (D));
1637 end if;
1638
1639 Append (D_Val, Constraints);
1640 Next_Elmt (D);
1641 end loop;
1642
1643 return Constraints;
1644 end Build_Discriminal_Record_Constraint;
1645
1646 -- Start of processing for Build_Discriminal_Subtype_Of_Component
1647
1648 begin
1649 if Ekind (T) = E_Array_Subtype then
1650 Id := First_Index (T);
1651 while Present (Id) loop
1652 if Denotes_Discriminant (Type_Low_Bound (Etype (Id)))
1653 or else
1654 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
1655 then
1656 return Build_Component_Subtype
1657 (Build_Discriminal_Array_Constraint, Loc, T);
1658 end if;
1659
1660 Next_Index (Id);
1661 end loop;
1662
1663 elsif Ekind (T) = E_Record_Subtype
1664 and then Has_Discriminants (T)
1665 and then not Has_Unknown_Discriminants (T)
1666 then
1667 D := First_Elmt (Discriminant_Constraint (T));
1668 while Present (D) loop
1669 if Denotes_Discriminant (Node (D)) then
1670 return Build_Component_Subtype
1671 (Build_Discriminal_Record_Constraint, Loc, T);
1672 end if;
1673
1674 Next_Elmt (D);
1675 end loop;
1676 end if;
1677
1678 -- If none of the above, the actual and nominal subtypes are the same
1679
1680 return Empty;
1681 end Build_Discriminal_Subtype_Of_Component;
1682
1683 ------------------------------
1684 -- Build_Elaboration_Entity --
1685 ------------------------------
1686
1687 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
1688 Loc : constant Source_Ptr := Sloc (N);
1689 Decl : Node_Id;
1690 Elab_Ent : Entity_Id;
1691
1692 procedure Set_Package_Name (Ent : Entity_Id);
1693 -- Given an entity, sets the fully qualified name of the entity in
1694 -- Name_Buffer, with components separated by double underscores. This
1695 -- is a recursive routine that climbs the scope chain to Standard.
1696
1697 ----------------------
1698 -- Set_Package_Name --
1699 ----------------------
1700
1701 procedure Set_Package_Name (Ent : Entity_Id) is
1702 begin
1703 if Scope (Ent) /= Standard_Standard then
1704 Set_Package_Name (Scope (Ent));
1705
1706 declare
1707 Nam : constant String := Get_Name_String (Chars (Ent));
1708 begin
1709 Name_Buffer (Name_Len + 1) := '_';
1710 Name_Buffer (Name_Len + 2) := '_';
1711 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
1712 Name_Len := Name_Len + Nam'Length + 2;
1713 end;
1714
1715 else
1716 Get_Name_String (Chars (Ent));
1717 end if;
1718 end Set_Package_Name;
1719
1720 -- Start of processing for Build_Elaboration_Entity
1721
1722 begin
1723 -- Ignore call if already constructed
1724
1725 if Present (Elaboration_Entity (Spec_Id)) then
1726 return;
1727
1728 -- Ignore in ASIS mode, elaboration entity is not in source and plays
1729 -- no role in analysis.
1730
1731 elsif ASIS_Mode then
1732 return;
1733
1734 -- Do not generate an elaboration entity in GNATprove move because the
1735 -- elaboration counter is a form of expansion.
1736
1737 elsif GNATprove_Mode then
1738 return;
1739
1740 -- See if we need elaboration entity
1741
1742 -- We always need an elaboration entity when preserving control flow, as
1743 -- we want to remain explicit about the unit's elaboration order.
1744
1745 elsif Opt.Suppress_Control_Flow_Optimizations then
1746 null;
1747
1748 -- We always need an elaboration entity for the dynamic elaboration
1749 -- model, since it is needed to properly generate the PE exception for
1750 -- access before elaboration.
1751
1752 elsif Dynamic_Elaboration_Checks then
1753 null;
1754
1755 -- For the static model, we don't need the elaboration counter if this
1756 -- unit is sure to have no elaboration code, since that means there
1757 -- is no elaboration unit to be called. Note that we can't just decide
1758 -- after the fact by looking to see whether there was elaboration code,
1759 -- because that's too late to make this decision.
1760
1761 elsif Restriction_Active (No_Elaboration_Code) then
1762 return;
1763
1764 -- Similarly, for the static model, we can skip the elaboration counter
1765 -- if we have the No_Multiple_Elaboration restriction, since for the
1766 -- static model, that's the only purpose of the counter (to avoid
1767 -- multiple elaboration).
1768
1769 elsif Restriction_Active (No_Multiple_Elaboration) then
1770 return;
1771 end if;
1772
1773 -- Here we need the elaboration entity
1774
1775 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
1776 -- name with dots replaced by double underscore. We have to manually
1777 -- construct this name, since it will be elaborated in the outer scope,
1778 -- and thus will not have the unit name automatically prepended.
1779
1780 Set_Package_Name (Spec_Id);
1781 Add_Str_To_Name_Buffer ("_E");
1782
1783 -- Create elaboration counter
1784
1785 Elab_Ent := Make_Defining_Identifier (Loc, Chars => Name_Find);
1786 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
1787
1788 Decl :=
1789 Make_Object_Declaration (Loc,
1790 Defining_Identifier => Elab_Ent,
1791 Object_Definition =>
1792 New_Occurrence_Of (Standard_Short_Integer, Loc),
1793 Expression => Make_Integer_Literal (Loc, Uint_0));
1794
1795 Push_Scope (Standard_Standard);
1796 Add_Global_Declaration (Decl);
1797 Pop_Scope;
1798
1799 -- Reset True_Constant indication, since we will indeed assign a value
1800 -- to the variable in the binder main. We also kill the Current_Value
1801 -- and Last_Assignment fields for the same reason.
1802
1803 Set_Is_True_Constant (Elab_Ent, False);
1804 Set_Current_Value (Elab_Ent, Empty);
1805 Set_Last_Assignment (Elab_Ent, Empty);
1806
1807 -- We do not want any further qualification of the name (if we did not
1808 -- do this, we would pick up the name of the generic package in the case
1809 -- of a library level generic instantiation).
1810
1811 Set_Has_Qualified_Name (Elab_Ent);
1812 Set_Has_Fully_Qualified_Name (Elab_Ent);
1813 end Build_Elaboration_Entity;
1814
1815 --------------------------------
1816 -- Build_Explicit_Dereference --
1817 --------------------------------
1818
1819 procedure Build_Explicit_Dereference
1820 (Expr : Node_Id;
1821 Disc : Entity_Id)
1822 is
1823 Loc : constant Source_Ptr := Sloc (Expr);
1824 I : Interp_Index;
1825 It : Interp;
1826
1827 begin
1828 -- An entity of a type with a reference aspect is overloaded with
1829 -- both interpretations: with and without the dereference. Now that
1830 -- the dereference is made explicit, set the type of the node properly,
1831 -- to prevent anomalies in the backend. Same if the expression is an
1832 -- overloaded function call whose return type has a reference aspect.
1833
1834 if Is_Entity_Name (Expr) then
1835 Set_Etype (Expr, Etype (Entity (Expr)));
1836
1837 -- The designated entity will not be examined again when resolving
1838 -- the dereference, so generate a reference to it now.
1839
1840 Generate_Reference (Entity (Expr), Expr);
1841
1842 elsif Nkind (Expr) = N_Function_Call then
1843
1844 -- If the name of the indexing function is overloaded, locate the one
1845 -- whose return type has an implicit dereference on the desired
1846 -- discriminant, and set entity and type of function call.
1847
1848 if Is_Overloaded (Name (Expr)) then
1849 Get_First_Interp (Name (Expr), I, It);
1850
1851 while Present (It.Nam) loop
1852 if Ekind ((It.Typ)) = E_Record_Type
1853 and then First_Entity ((It.Typ)) = Disc
1854 then
1855 Set_Entity (Name (Expr), It.Nam);
1856 Set_Etype (Name (Expr), Etype (It.Nam));
1857 exit;
1858 end if;
1859
1860 Get_Next_Interp (I, It);
1861 end loop;
1862 end if;
1863
1864 -- Set type of call from resolved function name.
1865
1866 Set_Etype (Expr, Etype (Name (Expr)));
1867 end if;
1868
1869 Set_Is_Overloaded (Expr, False);
1870
1871 -- The expression will often be a generalized indexing that yields a
1872 -- container element that is then dereferenced, in which case the
1873 -- generalized indexing call is also non-overloaded.
1874
1875 if Nkind (Expr) = N_Indexed_Component
1876 and then Present (Generalized_Indexing (Expr))
1877 then
1878 Set_Is_Overloaded (Generalized_Indexing (Expr), False);
1879 end if;
1880
1881 Rewrite (Expr,
1882 Make_Explicit_Dereference (Loc,
1883 Prefix =>
1884 Make_Selected_Component (Loc,
1885 Prefix => Relocate_Node (Expr),
1886 Selector_Name => New_Occurrence_Of (Disc, Loc))));
1887 Set_Etype (Prefix (Expr), Etype (Disc));
1888 Set_Etype (Expr, Designated_Type (Etype (Disc)));
1889 end Build_Explicit_Dereference;
1890
1891 ---------------------------
1892 -- Build_Overriding_Spec --
1893 ---------------------------
1894
1895 function Build_Overriding_Spec
1896 (Op : Entity_Id;
1897 Typ : Entity_Id) return Node_Id
1898 is
1899 Loc : constant Source_Ptr := Sloc (Typ);
1900 Par_Typ : constant Entity_Id := Find_Dispatching_Type (Op);
1901 Spec : constant Node_Id := Specification (Unit_Declaration_Node (Op));
1902
1903 Formal_Spec : Node_Id;
1904 Formal_Type : Node_Id;
1905 New_Spec : Node_Id;
1906
1907 begin
1908 New_Spec := Copy_Subprogram_Spec (Spec);
1909
1910 Formal_Spec := First (Parameter_Specifications (New_Spec));
1911 while Present (Formal_Spec) loop
1912 Formal_Type := Parameter_Type (Formal_Spec);
1913
1914 if Is_Entity_Name (Formal_Type)
1915 and then Entity (Formal_Type) = Par_Typ
1916 then
1917 Rewrite (Formal_Type, New_Occurrence_Of (Typ, Loc));
1918 end if;
1919
1920 -- Nothing needs to be done for access parameters
1921
1922 Next (Formal_Spec);
1923 end loop;
1924
1925 return New_Spec;
1926 end Build_Overriding_Spec;
1927
1928 -----------------------------------
1929 -- Cannot_Raise_Constraint_Error --
1930 -----------------------------------
1931
1932 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
1933 begin
1934 if Compile_Time_Known_Value (Expr) then
1935 return True;
1936
1937 elsif Do_Range_Check (Expr) then
1938 return False;
1939
1940 elsif Raises_Constraint_Error (Expr) then
1941 return False;
1942
1943 else
1944 case Nkind (Expr) is
1945 when N_Identifier =>
1946 return True;
1947
1948 when N_Expanded_Name =>
1949 return True;
1950
1951 when N_Selected_Component =>
1952 return not Do_Discriminant_Check (Expr);
1953
1954 when N_Attribute_Reference =>
1955 if Do_Overflow_Check (Expr) then
1956 return False;
1957
1958 elsif No (Expressions (Expr)) then
1959 return True;
1960
1961 else
1962 declare
1963 N : Node_Id;
1964
1965 begin
1966 N := First (Expressions (Expr));
1967 while Present (N) loop
1968 if Cannot_Raise_Constraint_Error (N) then
1969 Next (N);
1970 else
1971 return False;
1972 end if;
1973 end loop;
1974
1975 return True;
1976 end;
1977 end if;
1978
1979 when N_Type_Conversion =>
1980 if Do_Overflow_Check (Expr)
1981 or else Do_Length_Check (Expr)
1982 or else Do_Tag_Check (Expr)
1983 then
1984 return False;
1985 else
1986 return Cannot_Raise_Constraint_Error (Expression (Expr));
1987 end if;
1988
1989 when N_Unchecked_Type_Conversion =>
1990 return Cannot_Raise_Constraint_Error (Expression (Expr));
1991
1992 when N_Unary_Op =>
1993 if Do_Overflow_Check (Expr) then
1994 return False;
1995 else
1996 return Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1997 end if;
1998
1999 when N_Op_Divide
2000 | N_Op_Mod
2001 | N_Op_Rem
2002 =>
2003 if Do_Division_Check (Expr)
2004 or else
2005 Do_Overflow_Check (Expr)
2006 then
2007 return False;
2008 else
2009 return
2010 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
2011 and then
2012 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
2013 end if;
2014
2015 when N_Op_Add
2016 | N_Op_And
2017 | N_Op_Concat
2018 | N_Op_Eq
2019 | N_Op_Expon
2020 | N_Op_Ge
2021 | N_Op_Gt
2022 | N_Op_Le
2023 | N_Op_Lt
2024 | N_Op_Multiply
2025 | N_Op_Ne
2026 | N_Op_Or
2027 | N_Op_Rotate_Left
2028 | N_Op_Rotate_Right
2029 | N_Op_Shift_Left
2030 | N_Op_Shift_Right
2031 | N_Op_Shift_Right_Arithmetic
2032 | N_Op_Subtract
2033 | N_Op_Xor
2034 =>
2035 if Do_Overflow_Check (Expr) then
2036 return False;
2037 else
2038 return
2039 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
2040 and then
2041 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
2042 end if;
2043
2044 when others =>
2045 return False;
2046 end case;
2047 end if;
2048 end Cannot_Raise_Constraint_Error;
2049
2050 -----------------------------------------
2051 -- Check_Dynamically_Tagged_Expression --
2052 -----------------------------------------
2053
2054 procedure Check_Dynamically_Tagged_Expression
2055 (Expr : Node_Id;
2056 Typ : Entity_Id;
2057 Related_Nod : Node_Id)
2058 is
2059 begin
2060 pragma Assert (Is_Tagged_Type (Typ));
2061
2062 -- In order to avoid spurious errors when analyzing the expanded code,
2063 -- this check is done only for nodes that come from source and for
2064 -- actuals of generic instantiations.
2065
2066 if (Comes_From_Source (Related_Nod)
2067 or else In_Generic_Actual (Expr))
2068 and then (Is_Class_Wide_Type (Etype (Expr))
2069 or else Is_Dynamically_Tagged (Expr))
2070 and then not Is_Class_Wide_Type (Typ)
2071 then
2072 Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
2073 end if;
2074 end Check_Dynamically_Tagged_Expression;
2075
2076 --------------------------
2077 -- Check_Fully_Declared --
2078 --------------------------
2079
2080 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
2081 begin
2082 if Ekind (T) = E_Incomplete_Type then
2083
2084 -- Ada 2005 (AI-50217): If the type is available through a limited
2085 -- with_clause, verify that its full view has been analyzed.
2086
2087 if From_Limited_With (T)
2088 and then Present (Non_Limited_View (T))
2089 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
2090 then
2091 -- The non-limited view is fully declared
2092
2093 null;
2094
2095 else
2096 Error_Msg_NE
2097 ("premature usage of incomplete}", N, First_Subtype (T));
2098 end if;
2099
2100 -- Need comments for these tests ???
2101
2102 elsif Has_Private_Component (T)
2103 and then not Is_Generic_Type (Root_Type (T))
2104 and then not In_Spec_Expression
2105 then
2106 -- Special case: if T is the anonymous type created for a single
2107 -- task or protected object, use the name of the source object.
2108
2109 if Is_Concurrent_Type (T)
2110 and then not Comes_From_Source (T)
2111 and then Nkind (N) = N_Object_Declaration
2112 then
2113 Error_Msg_NE
2114 ("type of& has incomplete component",
2115 N, Defining_Identifier (N));
2116 else
2117 Error_Msg_NE
2118 ("premature usage of incomplete}",
2119 N, First_Subtype (T));
2120 end if;
2121 end if;
2122 end Check_Fully_Declared;
2123
2124 -------------------------------------------
2125 -- Check_Function_With_Address_Parameter --
2126 -------------------------------------------
2127
2128 procedure Check_Function_With_Address_Parameter (Subp_Id : Entity_Id) is
2129 F : Entity_Id;
2130 T : Entity_Id;
2131
2132 begin
2133 F := First_Formal (Subp_Id);
2134 while Present (F) loop
2135 T := Etype (F);
2136
2137 if Is_Private_Type (T) and then Present (Full_View (T)) then
2138 T := Full_View (T);
2139 end if;
2140
2141 if Is_Descendant_Of_Address (T) or else Is_Limited_Type (T) then
2142 Set_Is_Pure (Subp_Id, False);
2143 exit;
2144 end if;
2145
2146 Next_Formal (F);
2147 end loop;
2148 end Check_Function_With_Address_Parameter;
2149
2150 -------------------------------------
2151 -- Check_Function_Writable_Actuals --
2152 -------------------------------------
2153
2154 procedure Check_Function_Writable_Actuals (N : Node_Id) is
2155 Writable_Actuals_List : Elist_Id := No_Elist;
2156 Identifiers_List : Elist_Id := No_Elist;
2157 Aggr_Error_Node : Node_Id := Empty;
2158 Error_Node : Node_Id := Empty;
2159
2160 procedure Collect_Identifiers (N : Node_Id);
2161 -- In a single traversal of subtree N collect in Writable_Actuals_List
2162 -- all the actuals of functions with writable actuals, and in the list
2163 -- Identifiers_List collect all the identifiers that are not actuals of
2164 -- functions with writable actuals. If a writable actual is referenced
2165 -- twice as writable actual then Error_Node is set to reference its
2166 -- second occurrence, the error is reported, and the tree traversal
2167 -- is abandoned.
2168
2169 procedure Preanalyze_Without_Errors (N : Node_Id);
2170 -- Preanalyze N without reporting errors. Very dubious, you can't just
2171 -- go analyzing things more than once???
2172
2173 -------------------------
2174 -- Collect_Identifiers --
2175 -------------------------
2176
2177 procedure Collect_Identifiers (N : Node_Id) is
2178
2179 function Check_Node (N : Node_Id) return Traverse_Result;
2180 -- Process a single node during the tree traversal to collect the
2181 -- writable actuals of functions and all the identifiers which are
2182 -- not writable actuals of functions.
2183
2184 function Contains (List : Elist_Id; N : Node_Id) return Boolean;
2185 -- Returns True if List has a node whose Entity is Entity (N)
2186
2187 ----------------
2188 -- Check_Node --
2189 ----------------
2190
2191 function Check_Node (N : Node_Id) return Traverse_Result is
2192 Is_Writable_Actual : Boolean := False;
2193 Id : Entity_Id;
2194
2195 begin
2196 if Nkind (N) = N_Identifier then
2197
2198 -- No analysis possible if the entity is not decorated
2199
2200 if No (Entity (N)) then
2201 return Skip;
2202
2203 -- Don't collect identifiers of packages, called functions, etc
2204
2205 elsif Ekind_In (Entity (N), E_Package,
2206 E_Function,
2207 E_Procedure,
2208 E_Entry)
2209 then
2210 return Skip;
2211
2212 -- For rewritten nodes, continue the traversal in the original
2213 -- subtree. Needed to handle aggregates in original expressions
2214 -- extracted from the tree by Remove_Side_Effects.
2215
2216 elsif Is_Rewrite_Substitution (N) then
2217 Collect_Identifiers (Original_Node (N));
2218 return Skip;
2219
2220 -- For now we skip aggregate discriminants, since they require
2221 -- performing the analysis in two phases to identify conflicts:
2222 -- first one analyzing discriminants and second one analyzing
2223 -- the rest of components (since at run time, discriminants are
2224 -- evaluated prior to components): too much computation cost
2225 -- to identify a corner case???
2226
2227 elsif Nkind (Parent (N)) = N_Component_Association
2228 and then Nkind_In (Parent (Parent (N)),
2229 N_Aggregate,
2230 N_Extension_Aggregate)
2231 then
2232 declare
2233 Choice : constant Node_Id := First (Choices (Parent (N)));
2234
2235 begin
2236 if Ekind (Entity (N)) = E_Discriminant then
2237 return Skip;
2238
2239 elsif Expression (Parent (N)) = N
2240 and then Nkind (Choice) = N_Identifier
2241 and then Ekind (Entity (Choice)) = E_Discriminant
2242 then
2243 return Skip;
2244 end if;
2245 end;
2246
2247 -- Analyze if N is a writable actual of a function
2248
2249 elsif Nkind (Parent (N)) = N_Function_Call then
2250 declare
2251 Call : constant Node_Id := Parent (N);
2252 Actual : Node_Id;
2253 Formal : Node_Id;
2254
2255 begin
2256 Id := Get_Called_Entity (Call);
2257
2258 -- In case of previous error, no check is possible
2259
2260 if No (Id) then
2261 return Abandon;
2262 end if;
2263
2264 if Ekind_In (Id, E_Function, E_Generic_Function)
2265 and then Has_Out_Or_In_Out_Parameter (Id)
2266 then
2267 Formal := First_Formal (Id);
2268 Actual := First_Actual (Call);
2269 while Present (Actual) and then Present (Formal) loop
2270 if Actual = N then
2271 if Ekind_In (Formal, E_Out_Parameter,
2272 E_In_Out_Parameter)
2273 then
2274 Is_Writable_Actual := True;
2275 end if;
2276
2277 exit;
2278 end if;
2279
2280 Next_Formal (Formal);
2281 Next_Actual (Actual);
2282 end loop;
2283 end if;
2284 end;
2285 end if;
2286
2287 if Is_Writable_Actual then
2288
2289 -- Skip checking the error in non-elementary types since
2290 -- RM 6.4.1(6.15/3) is restricted to elementary types, but
2291 -- store this actual in Writable_Actuals_List since it is
2292 -- needed to perform checks on other constructs that have
2293 -- arbitrary order of evaluation (for example, aggregates).
2294
2295 if not Is_Elementary_Type (Etype (N)) then
2296 if not Contains (Writable_Actuals_List, N) then
2297 Append_New_Elmt (N, To => Writable_Actuals_List);
2298 end if;
2299
2300 -- Second occurrence of an elementary type writable actual
2301
2302 elsif Contains (Writable_Actuals_List, N) then
2303
2304 -- Report the error on the second occurrence of the
2305 -- identifier. We cannot assume that N is the second
2306 -- occurrence (according to their location in the
2307 -- sources), since Traverse_Func walks through Field2
2308 -- last (see comment in the body of Traverse_Func).
2309
2310 declare
2311 Elmt : Elmt_Id;
2312
2313 begin
2314 Elmt := First_Elmt (Writable_Actuals_List);
2315 while Present (Elmt)
2316 and then Entity (Node (Elmt)) /= Entity (N)
2317 loop
2318 Next_Elmt (Elmt);
2319 end loop;
2320
2321 if Sloc (N) > Sloc (Node (Elmt)) then
2322 Error_Node := N;
2323 else
2324 Error_Node := Node (Elmt);
2325 end if;
2326
2327 Error_Msg_NE
2328 ("value may be affected by call to & "
2329 & "because order of evaluation is arbitrary",
2330 Error_Node, Id);
2331 return Abandon;
2332 end;
2333
2334 -- First occurrence of a elementary type writable actual
2335
2336 else
2337 Append_New_Elmt (N, To => Writable_Actuals_List);
2338 end if;
2339
2340 else
2341 if Identifiers_List = No_Elist then
2342 Identifiers_List := New_Elmt_List;
2343 end if;
2344
2345 Append_Unique_Elmt (N, Identifiers_List);
2346 end if;
2347 end if;
2348
2349 return OK;
2350 end Check_Node;
2351
2352 --------------
2353 -- Contains --
2354 --------------
2355
2356 function Contains
2357 (List : Elist_Id;
2358 N : Node_Id) return Boolean
2359 is
2360 pragma Assert (Nkind (N) in N_Has_Entity);
2361
2362 Elmt : Elmt_Id;
2363
2364 begin
2365 if List = No_Elist then
2366 return False;
2367 end if;
2368
2369 Elmt := First_Elmt (List);
2370 while Present (Elmt) loop
2371 if Entity (Node (Elmt)) = Entity (N) then
2372 return True;
2373 else
2374 Next_Elmt (Elmt);
2375 end if;
2376 end loop;
2377
2378 return False;
2379 end Contains;
2380
2381 ------------------
2382 -- Do_Traversal --
2383 ------------------
2384
2385 procedure Do_Traversal is new Traverse_Proc (Check_Node);
2386 -- The traversal procedure
2387
2388 -- Start of processing for Collect_Identifiers
2389
2390 begin
2391 if Present (Error_Node) then
2392 return;
2393 end if;
2394
2395 if Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then
2396 return;
2397 end if;
2398
2399 Do_Traversal (N);
2400 end Collect_Identifiers;
2401
2402 -------------------------------
2403 -- Preanalyze_Without_Errors --
2404 -------------------------------
2405
2406 procedure Preanalyze_Without_Errors (N : Node_Id) is
2407 Status : constant Boolean := Get_Ignore_Errors;
2408 begin
2409 Set_Ignore_Errors (True);
2410 Preanalyze (N);
2411 Set_Ignore_Errors (Status);
2412 end Preanalyze_Without_Errors;
2413
2414 -- Start of processing for Check_Function_Writable_Actuals
2415
2416 begin
2417 -- The check only applies to Ada 2012 code on which Check_Actuals has
2418 -- been set, and only to constructs that have multiple constituents
2419 -- whose order of evaluation is not specified by the language.
2420
2421 if Ada_Version < Ada_2012
2422 or else not Check_Actuals (N)
2423 or else (not (Nkind (N) in N_Op)
2424 and then not (Nkind (N) in N_Membership_Test)
2425 and then not Nkind_In (N, N_Range,
2426 N_Aggregate,
2427 N_Extension_Aggregate,
2428 N_Full_Type_Declaration,
2429 N_Function_Call,
2430 N_Procedure_Call_Statement,
2431 N_Entry_Call_Statement))
2432 or else (Nkind (N) = N_Full_Type_Declaration
2433 and then not Is_Record_Type (Defining_Identifier (N)))
2434
2435 -- In addition, this check only applies to source code, not to code
2436 -- generated by constraint checks.
2437
2438 or else not Comes_From_Source (N)
2439 then
2440 return;
2441 end if;
2442
2443 -- If a construct C has two or more direct constituents that are names
2444 -- or expressions whose evaluation may occur in an arbitrary order, at
2445 -- least one of which contains a function call with an in out or out
2446 -- parameter, then the construct is legal only if: for each name N that
2447 -- is passed as a parameter of mode in out or out to some inner function
2448 -- call C2 (not including the construct C itself), there is no other
2449 -- name anywhere within a direct constituent of the construct C other
2450 -- than the one containing C2, that is known to refer to the same
2451 -- object (RM 6.4.1(6.17/3)).
2452
2453 case Nkind (N) is
2454 when N_Range =>
2455 Collect_Identifiers (Low_Bound (N));
2456 Collect_Identifiers (High_Bound (N));
2457
2458 when N_Membership_Test
2459 | N_Op
2460 =>
2461 declare
2462 Expr : Node_Id;
2463
2464 begin
2465 Collect_Identifiers (Left_Opnd (N));
2466
2467 if Present (Right_Opnd (N)) then
2468 Collect_Identifiers (Right_Opnd (N));
2469 end if;
2470
2471 if Nkind_In (N, N_In, N_Not_In)
2472 and then Present (Alternatives (N))
2473 then
2474 Expr := First (Alternatives (N));
2475 while Present (Expr) loop
2476 Collect_Identifiers (Expr);
2477
2478 Next (Expr);
2479 end loop;
2480 end if;
2481 end;
2482
2483 when N_Full_Type_Declaration =>
2484 declare
2485 function Get_Record_Part (N : Node_Id) return Node_Id;
2486 -- Return the record part of this record type definition
2487
2488 function Get_Record_Part (N : Node_Id) return Node_Id is
2489 Type_Def : constant Node_Id := Type_Definition (N);
2490 begin
2491 if Nkind (Type_Def) = N_Derived_Type_Definition then
2492 return Record_Extension_Part (Type_Def);
2493 else
2494 return Type_Def;
2495 end if;
2496 end Get_Record_Part;
2497
2498 Comp : Node_Id;
2499 Def_Id : Entity_Id := Defining_Identifier (N);
2500 Rec : Node_Id := Get_Record_Part (N);
2501
2502 begin
2503 -- No need to perform any analysis if the record has no
2504 -- components
2505
2506 if No (Rec) or else No (Component_List (Rec)) then
2507 return;
2508 end if;
2509
2510 -- Collect the identifiers starting from the deepest
2511 -- derivation. Done to report the error in the deepest
2512 -- derivation.
2513
2514 loop
2515 if Present (Component_List (Rec)) then
2516 Comp := First (Component_Items (Component_List (Rec)));
2517 while Present (Comp) loop
2518 if Nkind (Comp) = N_Component_Declaration
2519 and then Present (Expression (Comp))
2520 then
2521 Collect_Identifiers (Expression (Comp));
2522 end if;
2523
2524 Next (Comp);
2525 end loop;
2526 end if;
2527
2528 exit when No (Underlying_Type (Etype (Def_Id)))
2529 or else Base_Type (Underlying_Type (Etype (Def_Id)))
2530 = Def_Id;
2531
2532 Def_Id := Base_Type (Underlying_Type (Etype (Def_Id)));
2533 Rec := Get_Record_Part (Parent (Def_Id));
2534 end loop;
2535 end;
2536
2537 when N_Entry_Call_Statement
2538 | N_Subprogram_Call
2539 =>
2540 declare
2541 Id : constant Entity_Id := Get_Called_Entity (N);
2542 Formal : Node_Id;
2543 Actual : Node_Id;
2544
2545 begin
2546 Formal := First_Formal (Id);
2547 Actual := First_Actual (N);
2548 while Present (Actual) and then Present (Formal) loop
2549 if Ekind_In (Formal, E_Out_Parameter,
2550 E_In_Out_Parameter)
2551 then
2552 Collect_Identifiers (Actual);
2553 end if;
2554
2555 Next_Formal (Formal);
2556 Next_Actual (Actual);
2557 end loop;
2558 end;
2559
2560 when N_Aggregate
2561 | N_Extension_Aggregate
2562 =>
2563 declare
2564 Assoc : Node_Id;
2565 Choice : Node_Id;
2566 Comp_Expr : Node_Id;
2567
2568 begin
2569 -- Handle the N_Others_Choice of array aggregates with static
2570 -- bounds. There is no need to perform this analysis in
2571 -- aggregates without static bounds since we cannot evaluate
2572 -- if the N_Others_Choice covers several elements. There is
2573 -- no need to handle the N_Others choice of record aggregates
2574 -- since at this stage it has been already expanded by
2575 -- Resolve_Record_Aggregate.
2576
2577 if Is_Array_Type (Etype (N))
2578 and then Nkind (N) = N_Aggregate
2579 and then Present (Aggregate_Bounds (N))
2580 and then Compile_Time_Known_Bounds (Etype (N))
2581 and then Expr_Value (High_Bound (Aggregate_Bounds (N)))
2582 >
2583 Expr_Value (Low_Bound (Aggregate_Bounds (N)))
2584 then
2585 declare
2586 Count_Components : Uint := Uint_0;
2587 Num_Components : Uint;
2588 Others_Assoc : Node_Id;
2589 Others_Choice : Node_Id := Empty;
2590 Others_Box_Present : Boolean := False;
2591
2592 begin
2593 -- Count positional associations
2594
2595 if Present (Expressions (N)) then
2596 Comp_Expr := First (Expressions (N));
2597 while Present (Comp_Expr) loop
2598 Count_Components := Count_Components + 1;
2599 Next (Comp_Expr);
2600 end loop;
2601 end if;
2602
2603 -- Count the rest of elements and locate the N_Others
2604 -- choice (if any)
2605
2606 Assoc := First (Component_Associations (N));
2607 while Present (Assoc) loop
2608 Choice := First (Choices (Assoc));
2609 while Present (Choice) loop
2610 if Nkind (Choice) = N_Others_Choice then
2611 Others_Assoc := Assoc;
2612 Others_Choice := Choice;
2613 Others_Box_Present := Box_Present (Assoc);
2614
2615 -- Count several components
2616
2617 elsif Nkind_In (Choice, N_Range,
2618 N_Subtype_Indication)
2619 or else (Is_Entity_Name (Choice)
2620 and then Is_Type (Entity (Choice)))
2621 then
2622 declare
2623 L, H : Node_Id;
2624 begin
2625 Get_Index_Bounds (Choice, L, H);
2626 pragma Assert
2627 (Compile_Time_Known_Value (L)
2628 and then Compile_Time_Known_Value (H));
2629 Count_Components :=
2630 Count_Components
2631 + Expr_Value (H) - Expr_Value (L) + 1;
2632 end;
2633
2634 -- Count single component. No other case available
2635 -- since we are handling an aggregate with static
2636 -- bounds.
2637
2638 else
2639 pragma Assert (Is_OK_Static_Expression (Choice)
2640 or else Nkind (Choice) = N_Identifier
2641 or else Nkind (Choice) = N_Integer_Literal);
2642
2643 Count_Components := Count_Components + 1;
2644 end if;
2645
2646 Next (Choice);
2647 end loop;
2648
2649 Next (Assoc);
2650 end loop;
2651
2652 Num_Components :=
2653 Expr_Value (High_Bound (Aggregate_Bounds (N))) -
2654 Expr_Value (Low_Bound (Aggregate_Bounds (N))) + 1;
2655
2656 pragma Assert (Count_Components <= Num_Components);
2657
2658 -- Handle the N_Others choice if it covers several
2659 -- components
2660
2661 if Present (Others_Choice)
2662 and then (Num_Components - Count_Components) > 1
2663 then
2664 if not Others_Box_Present then
2665
2666 -- At this stage, if expansion is active, the
2667 -- expression of the others choice has not been
2668 -- analyzed. Hence we generate a duplicate and
2669 -- we analyze it silently to have available the
2670 -- minimum decoration required to collect the
2671 -- identifiers.
2672
2673 if not Expander_Active then
2674 Comp_Expr := Expression (Others_Assoc);
2675 else
2676 Comp_Expr :=
2677 New_Copy_Tree (Expression (Others_Assoc));
2678 Preanalyze_Without_Errors (Comp_Expr);
2679 end if;
2680
2681 Collect_Identifiers (Comp_Expr);
2682
2683 if Writable_Actuals_List /= No_Elist then
2684
2685 -- As suggested by Robert, at current stage we
2686 -- report occurrences of this case as warnings.
2687
2688 Error_Msg_N
2689 ("writable function parameter may affect "
2690 & "value in other component because order "
2691 & "of evaluation is unspecified??",
2692 Node (First_Elmt (Writable_Actuals_List)));
2693 end if;
2694 end if;
2695 end if;
2696 end;
2697
2698 -- For an array aggregate, a discrete_choice_list that has
2699 -- a nonstatic range is considered as two or more separate
2700 -- occurrences of the expression (RM 6.4.1(20/3)).
2701
2702 elsif Is_Array_Type (Etype (N))
2703 and then Nkind (N) = N_Aggregate
2704 and then Present (Aggregate_Bounds (N))
2705 and then not Compile_Time_Known_Bounds (Etype (N))
2706 then
2707 -- Collect identifiers found in the dynamic bounds
2708
2709 declare
2710 Count_Components : Natural := 0;
2711 Low, High : Node_Id;
2712
2713 begin
2714 Assoc := First (Component_Associations (N));
2715 while Present (Assoc) loop
2716 Choice := First (Choices (Assoc));
2717 while Present (Choice) loop
2718 if Nkind_In (Choice, N_Range,
2719 N_Subtype_Indication)
2720 or else (Is_Entity_Name (Choice)
2721 and then Is_Type (Entity (Choice)))
2722 then
2723 Get_Index_Bounds (Choice, Low, High);
2724
2725 if not Compile_Time_Known_Value (Low) then
2726 Collect_Identifiers (Low);
2727
2728 if No (Aggr_Error_Node) then
2729 Aggr_Error_Node := Low;
2730 end if;
2731 end if;
2732
2733 if not Compile_Time_Known_Value (High) then
2734 Collect_Identifiers (High);
2735
2736 if No (Aggr_Error_Node) then
2737 Aggr_Error_Node := High;
2738 end if;
2739 end if;
2740
2741 -- The RM rule is violated if there is more than
2742 -- a single choice in a component association.
2743
2744 else
2745 Count_Components := Count_Components + 1;
2746
2747 if No (Aggr_Error_Node)
2748 and then Count_Components > 1
2749 then
2750 Aggr_Error_Node := Choice;
2751 end if;
2752
2753 if not Compile_Time_Known_Value (Choice) then
2754 Collect_Identifiers (Choice);
2755 end if;
2756 end if;
2757
2758 Next (Choice);
2759 end loop;
2760
2761 Next (Assoc);
2762 end loop;
2763 end;
2764 end if;
2765
2766 -- Handle ancestor part of extension aggregates
2767
2768 if Nkind (N) = N_Extension_Aggregate then
2769 Collect_Identifiers (Ancestor_Part (N));
2770 end if;
2771
2772 -- Handle positional associations
2773
2774 if Present (Expressions (N)) then
2775 Comp_Expr := First (Expressions (N));
2776 while Present (Comp_Expr) loop
2777 if not Is_OK_Static_Expression (Comp_Expr) then
2778 Collect_Identifiers (Comp_Expr);
2779 end if;
2780
2781 Next (Comp_Expr);
2782 end loop;
2783 end if;
2784
2785 -- Handle discrete associations
2786
2787 if Present (Component_Associations (N)) then
2788 Assoc := First (Component_Associations (N));
2789 while Present (Assoc) loop
2790
2791 if not Box_Present (Assoc) then
2792 Choice := First (Choices (Assoc));
2793 while Present (Choice) loop
2794
2795 -- For now we skip discriminants since it requires
2796 -- performing the analysis in two phases: first one
2797 -- analyzing discriminants and second one analyzing
2798 -- the rest of components since discriminants are
2799 -- evaluated prior to components: too much extra
2800 -- work to detect a corner case???
2801
2802 if Nkind (Choice) in N_Has_Entity
2803 and then Present (Entity (Choice))
2804 and then Ekind (Entity (Choice)) = E_Discriminant
2805 then
2806 null;
2807
2808 elsif Box_Present (Assoc) then
2809 null;
2810
2811 else
2812 if not Analyzed (Expression (Assoc)) then
2813 Comp_Expr :=
2814 New_Copy_Tree (Expression (Assoc));
2815 Set_Parent (Comp_Expr, Parent (N));
2816 Preanalyze_Without_Errors (Comp_Expr);
2817 else
2818 Comp_Expr := Expression (Assoc);
2819 end if;
2820
2821 Collect_Identifiers (Comp_Expr);
2822 end if;
2823
2824 Next (Choice);
2825 end loop;
2826 end if;
2827
2828 Next (Assoc);
2829 end loop;
2830 end if;
2831 end;
2832
2833 when others =>
2834 return;
2835 end case;
2836
2837 -- No further action needed if we already reported an error
2838
2839 if Present (Error_Node) then
2840 return;
2841 end if;
2842
2843 -- Check violation of RM 6.20/3 in aggregates
2844
2845 if Present (Aggr_Error_Node)
2846 and then Writable_Actuals_List /= No_Elist
2847 then
2848 Error_Msg_N
2849 ("value may be affected by call in other component because they "
2850 & "are evaluated in unspecified order",
2851 Node (First_Elmt (Writable_Actuals_List)));
2852 return;
2853 end if;
2854
2855 -- Check if some writable argument of a function is referenced
2856
2857 if Writable_Actuals_List /= No_Elist
2858 and then Identifiers_List /= No_Elist
2859 then
2860 declare
2861 Elmt_1 : Elmt_Id;
2862 Elmt_2 : Elmt_Id;
2863
2864 begin
2865 Elmt_1 := First_Elmt (Writable_Actuals_List);
2866 while Present (Elmt_1) loop
2867 Elmt_2 := First_Elmt (Identifiers_List);
2868 while Present (Elmt_2) loop
2869 if Entity (Node (Elmt_1)) = Entity (Node (Elmt_2)) then
2870 case Nkind (Parent (Node (Elmt_2))) is
2871 when N_Aggregate
2872 | N_Component_Association
2873 | N_Component_Declaration
2874 =>
2875 Error_Msg_N
2876 ("value may be affected by call in other "
2877 & "component because they are evaluated "
2878 & "in unspecified order",
2879 Node (Elmt_2));
2880
2881 when N_In
2882 | N_Not_In
2883 =>
2884 Error_Msg_N
2885 ("value may be affected by call in other "
2886 & "alternative because they are evaluated "
2887 & "in unspecified order",
2888 Node (Elmt_2));
2889
2890 when others =>
2891 Error_Msg_N
2892 ("value of actual may be affected by call in "
2893 & "other actual because they are evaluated "
2894 & "in unspecified order",
2895 Node (Elmt_2));
2896 end case;
2897 end if;
2898
2899 Next_Elmt (Elmt_2);
2900 end loop;
2901
2902 Next_Elmt (Elmt_1);
2903 end loop;
2904 end;
2905 end if;
2906 end Check_Function_Writable_Actuals;
2907
2908 --------------------------------
2909 -- Check_Implicit_Dereference --
2910 --------------------------------
2911
2912 procedure Check_Implicit_Dereference (N : Node_Id; Typ : Entity_Id) is
2913 Disc : Entity_Id;
2914 Desig : Entity_Id;
2915 Nam : Node_Id;
2916
2917 begin
2918 if Nkind (N) = N_Indexed_Component
2919 and then Present (Generalized_Indexing (N))
2920 then
2921 Nam := Generalized_Indexing (N);
2922 else
2923 Nam := N;
2924 end if;
2925
2926 if Ada_Version < Ada_2012
2927 or else not Has_Implicit_Dereference (Base_Type (Typ))
2928 then
2929 return;
2930
2931 elsif not Comes_From_Source (N)
2932 and then Nkind (N) /= N_Indexed_Component
2933 then
2934 return;
2935
2936 elsif Is_Entity_Name (Nam) and then Is_Type (Entity (Nam)) then
2937 null;
2938
2939 else
2940 Disc := First_Discriminant (Typ);
2941 while Present (Disc) loop
2942 if Has_Implicit_Dereference (Disc) then
2943 Desig := Designated_Type (Etype (Disc));
2944 Add_One_Interp (Nam, Disc, Desig);
2945
2946 -- If the node is a generalized indexing, add interpretation
2947 -- to that node as well, for subsequent resolution.
2948
2949 if Nkind (N) = N_Indexed_Component then
2950 Add_One_Interp (N, Disc, Desig);
2951 end if;
2952
2953 -- If the operation comes from a generic unit and the context
2954 -- is a selected component, the selector name may be global
2955 -- and set in the instance already. Remove the entity to
2956 -- force resolution of the selected component, and the
2957 -- generation of an explicit dereference if needed.
2958
2959 if In_Instance
2960 and then Nkind (Parent (Nam)) = N_Selected_Component
2961 then
2962 Set_Entity (Selector_Name (Parent (Nam)), Empty);
2963 end if;
2964
2965 exit;
2966 end if;
2967
2968 Next_Discriminant (Disc);
2969 end loop;
2970 end if;
2971 end Check_Implicit_Dereference;
2972
2973 ----------------------------------
2974 -- Check_Internal_Protected_Use --
2975 ----------------------------------
2976
2977 procedure Check_Internal_Protected_Use (N : Node_Id; Nam : Entity_Id) is
2978 S : Entity_Id;
2979 Prot : Entity_Id;
2980
2981 begin
2982 Prot := Empty;
2983
2984 S := Current_Scope;
2985 while Present (S) loop
2986 if S = Standard_Standard then
2987 exit;
2988
2989 elsif Ekind (S) = E_Function
2990 and then Ekind (Scope (S)) = E_Protected_Type
2991 then
2992 Prot := Scope (S);
2993 exit;
2994 end if;
2995
2996 S := Scope (S);
2997 end loop;
2998
2999 if Present (Prot)
3000 and then Scope (Nam) = Prot
3001 and then Ekind (Nam) /= E_Function
3002 then
3003 -- An indirect function call (e.g. a callback within a protected
3004 -- function body) is not statically illegal. If the access type is
3005 -- anonymous and is the type of an access parameter, the scope of Nam
3006 -- will be the protected type, but it is not a protected operation.
3007
3008 if Ekind (Nam) = E_Subprogram_Type
3009 and then Nkind (Associated_Node_For_Itype (Nam)) =
3010 N_Function_Specification
3011 then
3012 null;
3013
3014 elsif Nkind (N) = N_Subprogram_Renaming_Declaration then
3015 Error_Msg_N
3016 ("within protected function cannot use protected procedure in "
3017 & "renaming or as generic actual", N);
3018
3019 elsif Nkind (N) = N_Attribute_Reference then
3020 Error_Msg_N
3021 ("within protected function cannot take access of protected "
3022 & "procedure", N);
3023
3024 else
3025 Error_Msg_N
3026 ("within protected function, protected object is constant", N);
3027 Error_Msg_N
3028 ("\cannot call operation that may modify it", N);
3029 end if;
3030 end if;
3031
3032 -- Verify that an internal call does not appear within a precondition
3033 -- of a protected operation. This implements AI12-0166.
3034 -- The precondition aspect has been rewritten as a pragma Precondition
3035 -- and we check whether the scope of the called subprogram is the same
3036 -- as that of the entity to which the aspect applies.
3037
3038 if Convention (Nam) = Convention_Protected then
3039 declare
3040 P : Node_Id;
3041
3042 begin
3043 P := Parent (N);
3044 while Present (P) loop
3045 if Nkind (P) = N_Pragma
3046 and then Chars (Pragma_Identifier (P)) = Name_Precondition
3047 and then From_Aspect_Specification (P)
3048 and then
3049 Scope (Entity (Corresponding_Aspect (P))) = Scope (Nam)
3050 then
3051 Error_Msg_N
3052 ("internal call cannot appear in precondition of "
3053 & "protected operation", N);
3054 return;
3055
3056 elsif Nkind (P) = N_Pragma
3057 and then Chars (Pragma_Identifier (P)) = Name_Contract_Cases
3058 then
3059 -- Check whether call is in a case guard. It is legal in a
3060 -- consequence.
3061
3062 P := N;
3063 while Present (P) loop
3064 if Nkind (Parent (P)) = N_Component_Association
3065 and then P /= Expression (Parent (P))
3066 then
3067 Error_Msg_N
3068 ("internal call cannot appear in case guard in a "
3069 & "contract case", N);
3070 end if;
3071
3072 P := Parent (P);
3073 end loop;
3074
3075 return;
3076
3077 elsif Nkind (P) = N_Parameter_Specification
3078 and then Scope (Current_Scope) = Scope (Nam)
3079 and then Nkind_In (Parent (P), N_Entry_Declaration,
3080 N_Subprogram_Declaration)
3081 then
3082 Error_Msg_N
3083 ("internal call cannot appear in default for formal of "
3084 & "protected operation", N);
3085 return;
3086 end if;
3087
3088 P := Parent (P);
3089 end loop;
3090 end;
3091 end if;
3092 end Check_Internal_Protected_Use;
3093
3094 ---------------------------------------
3095 -- Check_Later_Vs_Basic_Declarations --
3096 ---------------------------------------
3097
3098 procedure Check_Later_Vs_Basic_Declarations
3099 (Decls : List_Id;
3100 During_Parsing : Boolean)
3101 is
3102 Body_Sloc : Source_Ptr;
3103 Decl : Node_Id;
3104
3105 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean;
3106 -- Return whether Decl is considered as a declarative item.
3107 -- When During_Parsing is True, the semantics of Ada 83 is followed.
3108 -- When During_Parsing is False, the semantics of SPARK is followed.
3109
3110 -------------------------------
3111 -- Is_Later_Declarative_Item --
3112 -------------------------------
3113
3114 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean is
3115 begin
3116 if Nkind (Decl) in N_Later_Decl_Item then
3117 return True;
3118
3119 elsif Nkind (Decl) = N_Pragma then
3120 return True;
3121
3122 elsif During_Parsing then
3123 return False;
3124
3125 -- In SPARK, a package declaration is not considered as a later
3126 -- declarative item.
3127
3128 elsif Nkind (Decl) = N_Package_Declaration then
3129 return False;
3130
3131 -- In SPARK, a renaming is considered as a later declarative item
3132
3133 elsif Nkind (Decl) in N_Renaming_Declaration then
3134 return True;
3135
3136 else
3137 return False;
3138 end if;
3139 end Is_Later_Declarative_Item;
3140
3141 -- Start of processing for Check_Later_Vs_Basic_Declarations
3142
3143 begin
3144 Decl := First (Decls);
3145
3146 -- Loop through sequence of basic declarative items
3147
3148 Outer : while Present (Decl) loop
3149 if not Nkind_In (Decl, N_Subprogram_Body, N_Package_Body, N_Task_Body)
3150 and then Nkind (Decl) not in N_Body_Stub
3151 then
3152 Next (Decl);
3153
3154 -- Once a body is encountered, we only allow later declarative
3155 -- items. The inner loop checks the rest of the list.
3156
3157 else
3158 Body_Sloc := Sloc (Decl);
3159
3160 Inner : while Present (Decl) loop
3161 if not Is_Later_Declarative_Item (Decl) then
3162 if During_Parsing then
3163 if Ada_Version = Ada_83 then
3164 Error_Msg_Sloc := Body_Sloc;
3165 Error_Msg_N
3166 ("(Ada 83) decl cannot appear after body#", Decl);
3167 end if;
3168 else
3169 Error_Msg_Sloc := Body_Sloc;
3170 Check_SPARK_05_Restriction
3171 ("decl cannot appear after body#", Decl);
3172 end if;
3173 end if;
3174
3175 Next (Decl);
3176 end loop Inner;
3177 end if;
3178 end loop Outer;
3179 end Check_Later_Vs_Basic_Declarations;
3180
3181 ---------------------------
3182 -- Check_No_Hidden_State --
3183 ---------------------------
3184
3185 procedure Check_No_Hidden_State (Id : Entity_Id) is
3186 Context : Entity_Id := Empty;
3187 Not_Visible : Boolean := False;
3188 Scop : Entity_Id;
3189
3190 begin
3191 pragma Assert (Ekind_In (Id, E_Abstract_State, E_Variable));
3192
3193 -- Find the proper context where the object or state appears
3194
3195 Scop := Scope (Id);
3196 while Present (Scop) loop
3197 Context := Scop;
3198
3199 -- Keep track of the context's visibility
3200
3201 Not_Visible := Not_Visible or else In_Private_Part (Context);
3202
3203 -- Prevent the search from going too far
3204
3205 if Context = Standard_Standard then
3206 return;
3207
3208 -- Objects and states that appear immediately within a subprogram or
3209 -- inside a construct nested within a subprogram do not introduce a
3210 -- hidden state. They behave as local variable declarations.
3211
3212 elsif Is_Subprogram (Context) then
3213 return;
3214
3215 -- When examining a package body, use the entity of the spec as it
3216 -- carries the abstract state declarations.
3217
3218 elsif Ekind (Context) = E_Package_Body then
3219 Context := Spec_Entity (Context);
3220 end if;
3221
3222 -- Stop the traversal when a package subject to a null abstract state
3223 -- has been found.
3224
3225 if Ekind_In (Context, E_Generic_Package, E_Package)
3226 and then Has_Null_Abstract_State (Context)
3227 then
3228 exit;
3229 end if;
3230
3231 Scop := Scope (Scop);
3232 end loop;
3233
3234 -- At this point we know that there is at least one package with a null
3235 -- abstract state in visibility. Emit an error message unconditionally
3236 -- if the entity being processed is a state because the placement of the
3237 -- related package is irrelevant. This is not the case for objects as
3238 -- the intermediate context matters.
3239
3240 if Present (Context)
3241 and then (Ekind (Id) = E_Abstract_State or else Not_Visible)
3242 then
3243 Error_Msg_N ("cannot introduce hidden state &", Id);
3244 Error_Msg_NE ("\package & has null abstract state", Id, Context);
3245 end if;
3246 end Check_No_Hidden_State;
3247
3248 ----------------------------------------
3249 -- Check_Nonvolatile_Function_Profile --
3250 ----------------------------------------
3251
3252 procedure Check_Nonvolatile_Function_Profile (Func_Id : Entity_Id) is
3253 Formal : Entity_Id;
3254
3255 begin
3256 -- Inspect all formal parameters
3257
3258 Formal := First_Formal (Func_Id);
3259 while Present (Formal) loop
3260 if Is_Effectively_Volatile (Etype (Formal)) then
3261 Error_Msg_NE
3262 ("nonvolatile function & cannot have a volatile parameter",
3263 Formal, Func_Id);
3264 end if;
3265
3266 Next_Formal (Formal);
3267 end loop;
3268
3269 -- Inspect the return type
3270
3271 if Is_Effectively_Volatile (Etype (Func_Id)) then
3272 Error_Msg_NE
3273 ("nonvolatile function & cannot have a volatile return type",
3274 Result_Definition (Parent (Func_Id)), Func_Id);
3275 end if;
3276 end Check_Nonvolatile_Function_Profile;
3277
3278 -----------------------------
3279 -- Check_Part_Of_Reference --
3280 -----------------------------
3281
3282 procedure Check_Part_Of_Reference (Var_Id : Entity_Id; Ref : Node_Id) is
3283 Conc_Obj : constant Entity_Id := Encapsulating_State (Var_Id);
3284 Decl : Node_Id;
3285 OK_Use : Boolean := False;
3286 Par : Node_Id;
3287 Prag_Nam : Name_Id;
3288 Spec_Id : Entity_Id;
3289
3290 begin
3291 -- Traverse the parent chain looking for a suitable context for the
3292 -- reference to the concurrent constituent.
3293
3294 Par := Parent (Ref);
3295 while Present (Par) loop
3296 if Nkind (Par) = N_Pragma then
3297 Prag_Nam := Pragma_Name (Par);
3298
3299 -- A concurrent constituent is allowed to appear in pragmas
3300 -- Initial_Condition and Initializes as this is part of the
3301 -- elaboration checks for the constituent (SPARK RM 9.3).
3302
3303 if Nam_In (Prag_Nam, Name_Initial_Condition, Name_Initializes) then
3304 OK_Use := True;
3305 exit;
3306
3307 -- When the reference appears within pragma Depends or Global,
3308 -- check whether the pragma applies to a single task type. Note
3309 -- that the pragma is not encapsulated by the type definition,
3310 -- but this is still a valid context.
3311
3312 elsif Nam_In (Prag_Nam, Name_Depends, Name_Global) then
3313 Decl := Find_Related_Declaration_Or_Body (Par);
3314
3315 if Nkind (Decl) = N_Object_Declaration
3316 and then Defining_Entity (Decl) = Conc_Obj
3317 then
3318 OK_Use := True;
3319 exit;
3320 end if;
3321 end if;
3322
3323 -- The reference appears somewhere in the definition of the single
3324 -- protected/task type (SPARK RM 9.3).
3325
3326 elsif Nkind_In (Par, N_Single_Protected_Declaration,
3327 N_Single_Task_Declaration)
3328 and then Defining_Entity (Par) = Conc_Obj
3329 then
3330 OK_Use := True;
3331 exit;
3332
3333 -- The reference appears within the expanded declaration or the body
3334 -- of the single protected/task type (SPARK RM 9.3).
3335
3336 elsif Nkind_In (Par, N_Protected_Body,
3337 N_Protected_Type_Declaration,
3338 N_Task_Body,
3339 N_Task_Type_Declaration)
3340 then
3341 Spec_Id := Unique_Defining_Entity (Par);
3342
3343 if Present (Anonymous_Object (Spec_Id))
3344 and then Anonymous_Object (Spec_Id) = Conc_Obj
3345 then
3346 OK_Use := True;
3347 exit;
3348 end if;
3349
3350 -- The reference has been relocated within an internally generated
3351 -- package or subprogram. Assume that the reference is legal as the
3352 -- real check was already performed in the original context of the
3353 -- reference.
3354
3355 elsif Nkind_In (Par, N_Package_Body,
3356 N_Package_Declaration,
3357 N_Subprogram_Body,
3358 N_Subprogram_Declaration)
3359 and then not Comes_From_Source (Par)
3360 then
3361 -- Continue to examine the context if the reference appears in a
3362 -- subprogram body which was previously an expression function,
3363 -- unless this is during preanalysis (when In_Spec_Expression is
3364 -- True), as the body may not yet be inserted in the tree.
3365
3366 if Nkind (Par) = N_Subprogram_Body
3367 and then Was_Expression_Function (Par)
3368 and then not In_Spec_Expression
3369 then
3370 null;
3371
3372 -- Otherwise the reference is legal
3373
3374 else
3375 OK_Use := True;
3376 exit;
3377 end if;
3378
3379 -- The reference has been relocated to an inlined body for GNATprove.
3380 -- Assume that the reference is legal as the real check was already
3381 -- performed in the original context of the reference.
3382
3383 elsif GNATprove_Mode
3384 and then Nkind (Par) = N_Subprogram_Body
3385 and then Chars (Defining_Entity (Par)) = Name_uParent
3386 then
3387 OK_Use := True;
3388 exit;
3389 end if;
3390
3391 Par := Parent (Par);
3392 end loop;
3393
3394 -- The reference is illegal as it appears outside the definition or
3395 -- body of the single protected/task type.
3396
3397 if not OK_Use then
3398 Error_Msg_NE
3399 ("reference to variable & cannot appear in this context",
3400 Ref, Var_Id);
3401 Error_Msg_Name_1 := Chars (Var_Id);
3402
3403 if Is_Single_Protected_Object (Conc_Obj) then
3404 Error_Msg_NE
3405 ("\% is constituent of single protected type &", Ref, Conc_Obj);
3406
3407 else
3408 Error_Msg_NE
3409 ("\% is constituent of single task type &", Ref, Conc_Obj);
3410 end if;
3411 end if;
3412 end Check_Part_Of_Reference;
3413
3414 ------------------------------------------
3415 -- Check_Potentially_Blocking_Operation --
3416 ------------------------------------------
3417
3418 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
3419 S : Entity_Id;
3420
3421 begin
3422 -- N is one of the potentially blocking operations listed in 9.5.1(8).
3423 -- When pragma Detect_Blocking is active, the run time will raise
3424 -- Program_Error. Here we only issue a warning, since we generally
3425 -- support the use of potentially blocking operations in the absence
3426 -- of the pragma.
3427
3428 -- Indirect blocking through a subprogram call cannot be diagnosed
3429 -- statically without interprocedural analysis, so we do not attempt
3430 -- to do it here.
3431
3432 S := Scope (Current_Scope);
3433 while Present (S) and then S /= Standard_Standard loop
3434 if Is_Protected_Type (S) then
3435 Error_Msg_N
3436 ("potentially blocking operation in protected operation??", N);
3437 return;
3438 end if;
3439
3440 S := Scope (S);
3441 end loop;
3442 end Check_Potentially_Blocking_Operation;
3443
3444 ------------------------------------
3445 -- Check_Previous_Null_Procedure --
3446 ------------------------------------
3447
3448 procedure Check_Previous_Null_Procedure
3449 (Decl : Node_Id;
3450 Prev : Entity_Id)
3451 is
3452 begin
3453 if Ekind (Prev) = E_Procedure
3454 and then Nkind (Parent (Prev)) = N_Procedure_Specification
3455 and then Null_Present (Parent (Prev))
3456 then
3457 Error_Msg_Sloc := Sloc (Prev);
3458 Error_Msg_N
3459 ("declaration cannot complete previous null procedure#", Decl);
3460 end if;
3461 end Check_Previous_Null_Procedure;
3462
3463 ---------------------------------
3464 -- Check_Result_And_Post_State --
3465 ---------------------------------
3466
3467 procedure Check_Result_And_Post_State (Subp_Id : Entity_Id) is
3468 procedure Check_Result_And_Post_State_In_Pragma
3469 (Prag : Node_Id;
3470 Result_Seen : in out Boolean);
3471 -- Determine whether pragma Prag mentions attribute 'Result and whether
3472 -- the pragma contains an expression that evaluates differently in pre-
3473 -- and post-state. Prag is a [refined] postcondition or a contract-cases
3474 -- pragma. Result_Seen is set when the pragma mentions attribute 'Result
3475
3476 function Has_In_Out_Parameter (Subp_Id : Entity_Id) return Boolean;
3477 -- Determine whether subprogram Subp_Id contains at least one IN OUT
3478 -- formal parameter.
3479
3480 -------------------------------------------
3481 -- Check_Result_And_Post_State_In_Pragma --
3482 -------------------------------------------
3483
3484 procedure Check_Result_And_Post_State_In_Pragma
3485 (Prag : Node_Id;
3486 Result_Seen : in out Boolean)
3487 is
3488 procedure Check_Conjunct (Expr : Node_Id);
3489 -- Check an individual conjunct in a conjunction of Boolean
3490 -- expressions, connected by "and" or "and then" operators.
3491
3492 procedure Check_Conjuncts (Expr : Node_Id);
3493 -- Apply the post-state check to every conjunct in an expression, in
3494 -- case this is a conjunction of Boolean expressions. Otherwise apply
3495 -- it to the expression as a whole.
3496
3497 procedure Check_Expression (Expr : Node_Id);
3498 -- Perform the 'Result and post-state checks on a given expression
3499
3500 function Is_Function_Result (N : Node_Id) return Traverse_Result;
3501 -- Attempt to find attribute 'Result in a subtree denoted by N
3502
3503 function Is_Trivial_Boolean (N : Node_Id) return Boolean;
3504 -- Determine whether source node N denotes "True" or "False"
3505
3506 function Mentions_Post_State (N : Node_Id) return Boolean;
3507 -- Determine whether a subtree denoted by N mentions any construct
3508 -- that denotes a post-state.
3509
3510 procedure Check_Function_Result is
3511 new Traverse_Proc (Is_Function_Result);
3512
3513 --------------------
3514 -- Check_Conjunct --
3515 --------------------
3516
3517 procedure Check_Conjunct (Expr : Node_Id) is
3518 function Adjust_Message (Msg : String) return String;
3519 -- Prepend a prefix to the input message Msg denoting that the
3520 -- message applies to a conjunct in the expression, when this
3521 -- is the case.
3522
3523 function Applied_On_Conjunct return Boolean;
3524 -- Returns True if the message applies to a conjunct in the
3525 -- expression, instead of the whole expression.
3526
3527 function Has_Global_Output (Subp : Entity_Id) return Boolean;
3528 -- Returns True if Subp has an output in its Global contract
3529
3530 function Has_No_Output (Subp : Entity_Id) return Boolean;
3531 -- Returns True if Subp has no declared output: no function
3532 -- result, no output parameter, and no output in its Global
3533 -- contract.
3534
3535 --------------------
3536 -- Adjust_Message --
3537 --------------------
3538
3539 function Adjust_Message (Msg : String) return String is
3540 begin
3541 if Applied_On_Conjunct then
3542 return "conjunct in " & Msg;
3543 else
3544 return Msg;
3545 end if;
3546 end Adjust_Message;
3547
3548 -------------------------
3549 -- Applied_On_Conjunct --
3550 -------------------------
3551
3552 function Applied_On_Conjunct return Boolean is
3553 begin
3554 -- Expr is the conjunct of an enclosing "and" expression
3555
3556 return Nkind (Parent (Expr)) in N_Subexpr
3557
3558 -- or Expr is a conjunct of an enclosing "and then"
3559 -- expression in a postcondition aspect that was split into
3560 -- multiple pragmas. The first conjunct has the "and then"
3561 -- expression as Original_Node, and other conjuncts have
3562 -- Split_PCC set to True.
3563
3564 or else Nkind (Original_Node (Expr)) = N_And_Then
3565 or else Split_PPC (Prag);
3566 end Applied_On_Conjunct;
3567
3568 -----------------------
3569 -- Has_Global_Output --
3570 -----------------------
3571
3572 function Has_Global_Output (Subp : Entity_Id) return Boolean is
3573 Global : constant Node_Id := Get_Pragma (Subp, Pragma_Global);
3574 List : Node_Id;
3575 Assoc : Node_Id;
3576
3577 begin
3578 if No (Global) then
3579 return False;
3580 end if;
3581
3582 List := Expression (Get_Argument (Global, Subp));
3583
3584 -- Empty list (no global items) or single global item
3585 -- declaration (only input items).
3586
3587 if Nkind_In (List, N_Null,
3588 N_Expanded_Name,
3589 N_Identifier,
3590 N_Selected_Component)
3591 then
3592 return False;
3593
3594 -- Simple global list (only input items) or moded global list
3595 -- declaration.
3596
3597 elsif Nkind (List) = N_Aggregate then
3598 if Present (Expressions (List)) then
3599 return False;
3600
3601 else
3602 Assoc := First (Component_Associations (List));
3603 while Present (Assoc) loop
3604 if Chars (First (Choices (Assoc))) /= Name_Input then
3605 return True;
3606 end if;
3607
3608 Next (Assoc);
3609 end loop;
3610
3611 return False;
3612 end if;
3613
3614 -- To accommodate partial decoration of disabled SPARK
3615 -- features, this routine may be called with illegal input.
3616 -- If this is the case, do not raise Program_Error.
3617
3618 else
3619 return False;
3620 end if;
3621 end Has_Global_Output;
3622
3623 -------------------
3624 -- Has_No_Output --
3625 -------------------
3626
3627 function Has_No_Output (Subp : Entity_Id) return Boolean is
3628 Param : Node_Id;
3629
3630 begin
3631 -- A function has its result as output
3632
3633 if Ekind (Subp) = E_Function then
3634 return False;
3635 end if;
3636
3637 -- An OUT or IN OUT parameter is an output
3638
3639 Param := First_Formal (Subp);
3640 while Present (Param) loop
3641 if Ekind_In (Param, E_Out_Parameter, E_In_Out_Parameter) then
3642 return False;
3643 end if;
3644
3645 Next_Formal (Param);
3646 end loop;
3647
3648 -- An item of mode Output or In_Out in the Global contract is
3649 -- an output.
3650
3651 if Has_Global_Output (Subp) then
3652 return False;
3653 end if;
3654
3655 return True;
3656 end Has_No_Output;
3657
3658 -- Local variables
3659
3660 Err_Node : Node_Id;
3661 -- Error node when reporting a warning on a (refined)
3662 -- postcondition.
3663
3664 -- Start of processing for Check_Conjunct
3665
3666 begin
3667 if Applied_On_Conjunct then
3668 Err_Node := Expr;
3669 else
3670 Err_Node := Prag;
3671 end if;
3672
3673 -- Do not report missing reference to outcome in postcondition if
3674 -- either the postcondition is trivially True or False, or if the
3675 -- subprogram is ghost and has no declared output.
3676
3677 if not Is_Trivial_Boolean (Expr)
3678 and then not Mentions_Post_State (Expr)
3679 and then not (Is_Ghost_Entity (Subp_Id)
3680 and then Has_No_Output (Subp_Id))
3681 then
3682 if Pragma_Name (Prag) = Name_Contract_Cases then
3683 Error_Msg_NE (Adjust_Message
3684 ("contract case does not check the outcome of calling "
3685 & "&?T?"), Expr, Subp_Id);
3686
3687 elsif Pragma_Name (Prag) = Name_Refined_Post then
3688 Error_Msg_NE (Adjust_Message
3689 ("refined postcondition does not check the outcome of "
3690 & "calling &?T?"), Err_Node, Subp_Id);
3691
3692 else
3693 Error_Msg_NE (Adjust_Message
3694 ("postcondition does not check the outcome of calling "
3695 & "&?T?"), Err_Node, Subp_Id);
3696 end if;
3697 end if;
3698 end Check_Conjunct;
3699
3700 ---------------------
3701 -- Check_Conjuncts --
3702 ---------------------
3703
3704 procedure Check_Conjuncts (Expr : Node_Id) is
3705 begin
3706 if Nkind_In (Expr, N_Op_And, N_And_Then) then
3707 Check_Conjuncts (Left_Opnd (Expr));
3708 Check_Conjuncts (Right_Opnd (Expr));
3709 else
3710 Check_Conjunct (Expr);
3711 end if;
3712 end Check_Conjuncts;
3713
3714 ----------------------
3715 -- Check_Expression --
3716 ----------------------
3717
3718 procedure Check_Expression (Expr : Node_Id) is
3719 begin
3720 if not Is_Trivial_Boolean (Expr) then
3721 Check_Function_Result (Expr);
3722 Check_Conjuncts (Expr);
3723 end if;
3724 end Check_Expression;
3725
3726 ------------------------
3727 -- Is_Function_Result --
3728 ------------------------
3729
3730 function Is_Function_Result (N : Node_Id) return Traverse_Result is
3731 begin
3732 if Is_Attribute_Result (N) then
3733 Result_Seen := True;
3734 return Abandon;
3735
3736 -- Continue the traversal
3737
3738 else
3739 return OK;
3740 end if;
3741 end Is_Function_Result;
3742
3743 ------------------------
3744 -- Is_Trivial_Boolean --
3745 ------------------------
3746
3747 function Is_Trivial_Boolean (N : Node_Id) return Boolean is
3748 begin
3749 return
3750 Comes_From_Source (N)
3751 and then Is_Entity_Name (N)
3752 and then (Entity (N) = Standard_True
3753 or else
3754 Entity (N) = Standard_False);
3755 end Is_Trivial_Boolean;
3756
3757 -------------------------
3758 -- Mentions_Post_State --
3759 -------------------------
3760
3761 function Mentions_Post_State (N : Node_Id) return Boolean is
3762 Post_State_Seen : Boolean := False;
3763
3764 function Is_Post_State (N : Node_Id) return Traverse_Result;
3765 -- Attempt to find a construct that denotes a post-state. If this
3766 -- is the case, set flag Post_State_Seen.
3767
3768 -------------------
3769 -- Is_Post_State --
3770 -------------------
3771
3772 function Is_Post_State (N : Node_Id) return Traverse_Result is
3773 Ent : Entity_Id;
3774
3775 begin
3776 if Nkind_In (N, N_Explicit_Dereference, N_Function_Call) then
3777 Post_State_Seen := True;
3778 return Abandon;
3779
3780 elsif Nkind_In (N, N_Expanded_Name, N_Identifier) then
3781 Ent := Entity (N);
3782
3783 -- Treat an undecorated reference as OK
3784
3785 if No (Ent)
3786
3787 -- A reference to an assignable entity is considered a
3788 -- change in the post-state of a subprogram.
3789
3790 or else Ekind_In (Ent, E_Generic_In_Out_Parameter,
3791 E_In_Out_Parameter,
3792 E_Out_Parameter,
3793 E_Variable)
3794
3795 -- The reference may be modified through a dereference
3796
3797 or else (Is_Access_Type (Etype (Ent))
3798 and then Nkind (Parent (N)) =
3799 N_Selected_Component)
3800 then
3801 Post_State_Seen := True;
3802 return Abandon;
3803 end if;
3804
3805 elsif Nkind (N) = N_Attribute_Reference then
3806 if Attribute_Name (N) = Name_Old then
3807 return Skip;
3808
3809 elsif Attribute_Name (N) = Name_Result then
3810 Post_State_Seen := True;
3811 return Abandon;
3812 end if;
3813 end if;
3814
3815 return OK;
3816 end Is_Post_State;
3817
3818 procedure Find_Post_State is new Traverse_Proc (Is_Post_State);
3819
3820 -- Start of processing for Mentions_Post_State
3821
3822 begin
3823 Find_Post_State (N);
3824
3825 return Post_State_Seen;
3826 end Mentions_Post_State;
3827
3828 -- Local variables
3829
3830 Expr : constant Node_Id :=
3831 Get_Pragma_Arg
3832 (First (Pragma_Argument_Associations (Prag)));
3833 Nam : constant Name_Id := Pragma_Name (Prag);
3834 CCase : Node_Id;
3835
3836 -- Start of processing for Check_Result_And_Post_State_In_Pragma
3837
3838 begin
3839 -- Examine all consequences
3840
3841 if Nam = Name_Contract_Cases then
3842 CCase := First (Component_Associations (Expr));
3843 while Present (CCase) loop
3844 Check_Expression (Expression (CCase));
3845
3846 Next (CCase);
3847 end loop;
3848
3849 -- Examine the expression of a postcondition
3850
3851 else pragma Assert (Nam_In (Nam, Name_Postcondition,
3852 Name_Refined_Post));
3853 Check_Expression (Expr);
3854 end if;
3855 end Check_Result_And_Post_State_In_Pragma;
3856
3857 --------------------------
3858 -- Has_In_Out_Parameter --
3859 --------------------------
3860
3861 function Has_In_Out_Parameter (Subp_Id : Entity_Id) return Boolean is
3862 Formal : Entity_Id;
3863
3864 begin
3865 -- Traverse the formals looking for an IN OUT parameter
3866
3867 Formal := First_Formal (Subp_Id);
3868 while Present (Formal) loop
3869 if Ekind (Formal) = E_In_Out_Parameter then
3870 return True;
3871 end if;
3872
3873 Next_Formal (Formal);
3874 end loop;
3875
3876 return False;
3877 end Has_In_Out_Parameter;
3878
3879 -- Local variables
3880
3881 Items : constant Node_Id := Contract (Subp_Id);
3882 Subp_Decl : constant Node_Id := Unit_Declaration_Node (Subp_Id);
3883 Case_Prag : Node_Id := Empty;
3884 Post_Prag : Node_Id := Empty;
3885 Prag : Node_Id;
3886 Seen_In_Case : Boolean := False;
3887 Seen_In_Post : Boolean := False;
3888 Spec_Id : Entity_Id;
3889
3890 -- Start of processing for Check_Result_And_Post_State
3891
3892 begin
3893 -- The lack of attribute 'Result or a post-state is classified as a
3894 -- suspicious contract. Do not perform the check if the corresponding
3895 -- swich is not set.
3896
3897 if not Warn_On_Suspicious_Contract then
3898 return;
3899
3900 -- Nothing to do if there is no contract
3901
3902 elsif No (Items) then
3903 return;
3904 end if;
3905
3906 -- Retrieve the entity of the subprogram spec (if any)
3907
3908 if Nkind (Subp_Decl) = N_Subprogram_Body
3909 and then Present (Corresponding_Spec (Subp_Decl))
3910 then
3911 Spec_Id := Corresponding_Spec (Subp_Decl);
3912
3913 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
3914 and then Present (Corresponding_Spec_Of_Stub (Subp_Decl))
3915 then
3916 Spec_Id := Corresponding_Spec_Of_Stub (Subp_Decl);
3917
3918 else
3919 Spec_Id := Subp_Id;
3920 end if;
3921
3922 -- Examine all postconditions for attribute 'Result and a post-state
3923
3924 Prag := Pre_Post_Conditions (Items);
3925 while Present (Prag) loop
3926 if Nam_In (Pragma_Name_Unmapped (Prag),
3927 Name_Postcondition, Name_Refined_Post)
3928 and then not Error_Posted (Prag)
3929 then
3930 Post_Prag := Prag;
3931 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Post);
3932 end if;
3933
3934 Prag := Next_Pragma (Prag);
3935 end loop;
3936
3937 -- Examine the contract cases of the subprogram for attribute 'Result
3938 -- and a post-state.
3939
3940 Prag := Contract_Test_Cases (Items);
3941 while Present (Prag) loop
3942 if Pragma_Name (Prag) = Name_Contract_Cases
3943 and then not Error_Posted (Prag)
3944 then
3945 Case_Prag := Prag;
3946 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Case);
3947 end if;
3948
3949 Prag := Next_Pragma (Prag);
3950 end loop;
3951
3952 -- Do not emit any errors if the subprogram is not a function
3953
3954 if not Ekind_In (Spec_Id, E_Function, E_Generic_Function) then
3955 null;
3956
3957 -- Regardless of whether the function has postconditions or contract
3958 -- cases, or whether they mention attribute 'Result, an IN OUT formal
3959 -- parameter is always treated as a result.
3960
3961 elsif Has_In_Out_Parameter (Spec_Id) then
3962 null;
3963
3964 -- The function has both a postcondition and contract cases and they do
3965 -- not mention attribute 'Result.
3966
3967 elsif Present (Case_Prag)
3968 and then not Seen_In_Case
3969 and then Present (Post_Prag)
3970 and then not Seen_In_Post
3971 then
3972 Error_Msg_N
3973 ("neither postcondition nor contract cases mention function "
3974 & "result?T?", Post_Prag);
3975
3976 -- The function has contract cases only and they do not mention
3977 -- attribute 'Result.
3978
3979 elsif Present (Case_Prag) and then not Seen_In_Case then
3980 Error_Msg_N ("contract cases do not mention result?T?", Case_Prag);
3981
3982 -- The function has postconditions only and they do not mention
3983 -- attribute 'Result.
3984
3985 elsif Present (Post_Prag) and then not Seen_In_Post then
3986 Error_Msg_N
3987 ("postcondition does not mention function result?T?", Post_Prag);
3988 end if;
3989 end Check_Result_And_Post_State;
3990
3991 -----------------------------
3992 -- Check_State_Refinements --
3993 -----------------------------
3994
3995 procedure Check_State_Refinements
3996 (Context : Node_Id;
3997 Is_Main_Unit : Boolean := False)
3998 is
3999 procedure Check_Package (Pack : Node_Id);
4000 -- Verify that all abstract states of a [generic] package denoted by its
4001 -- declarative node Pack have proper refinement. Recursively verify the
4002 -- visible and private declarations of the [generic] package for other
4003 -- nested packages.
4004
4005 procedure Check_Packages_In (Decls : List_Id);
4006 -- Seek out [generic] package declarations within declarative list Decls
4007 -- and verify the status of their abstract state refinement.
4008
4009 function SPARK_Mode_Is_Off (N : Node_Id) return Boolean;
4010 -- Determine whether construct N is subject to pragma SPARK_Mode Off
4011
4012 -------------------
4013 -- Check_Package --
4014 -------------------
4015
4016 procedure Check_Package (Pack : Node_Id) is
4017 Body_Id : constant Entity_Id := Corresponding_Body (Pack);
4018 Spec : constant Node_Id := Specification (Pack);
4019 States : constant Elist_Id :=
4020 Abstract_States (Defining_Entity (Pack));
4021
4022 State_Elmt : Elmt_Id;
4023 State_Id : Entity_Id;
4024
4025 begin
4026 -- Do not verify proper state refinement when the package is subject
4027 -- to pragma SPARK_Mode Off because this disables the requirement for
4028 -- state refinement.
4029
4030 if SPARK_Mode_Is_Off (Pack) then
4031 null;
4032
4033 -- State refinement can only occur in a completing packge body. Do
4034 -- not verify proper state refinement when the body is subject to
4035 -- pragma SPARK_Mode Off because this disables the requirement for
4036 -- state refinement.
4037
4038 elsif Present (Body_Id)
4039 and then SPARK_Mode_Is_Off (Unit_Declaration_Node (Body_Id))
4040 then
4041 null;
4042
4043 -- Do not verify proper state refinement when the package is an
4044 -- instance as this check was already performed in the generic.
4045
4046 elsif Present (Generic_Parent (Spec)) then
4047 null;
4048
4049 -- Otherwise examine the contents of the package
4050
4051 else
4052 if Present (States) then
4053 State_Elmt := First_Elmt (States);
4054 while Present (State_Elmt) loop
4055 State_Id := Node (State_Elmt);
4056
4057 -- Emit an error when a non-null state lacks any form of
4058 -- refinement.
4059
4060 if not Is_Null_State (State_Id)
4061 and then not Has_Null_Refinement (State_Id)
4062 and then not Has_Non_Null_Refinement (State_Id)
4063 then
4064 Error_Msg_N ("state & requires refinement", State_Id);
4065 end if;
4066
4067 Next_Elmt (State_Elmt);
4068 end loop;
4069 end if;
4070
4071 Check_Packages_In (Visible_Declarations (Spec));
4072 Check_Packages_In (Private_Declarations (Spec));
4073 end if;
4074 end Check_Package;
4075
4076 -----------------------
4077 -- Check_Packages_In --
4078 -----------------------
4079
4080 procedure Check_Packages_In (Decls : List_Id) is
4081 Decl : Node_Id;
4082
4083 begin
4084 if Present (Decls) then
4085 Decl := First (Decls);
4086 while Present (Decl) loop
4087 if Nkind_In (Decl, N_Generic_Package_Declaration,
4088 N_Package_Declaration)
4089 then
4090 Check_Package (Decl);
4091 end if;
4092
4093 Next (Decl);
4094 end loop;
4095 end if;
4096 end Check_Packages_In;
4097
4098 -----------------------
4099 -- SPARK_Mode_Is_Off --
4100 -----------------------
4101
4102 function SPARK_Mode_Is_Off (N : Node_Id) return Boolean is
4103 Id : constant Entity_Id := Defining_Entity (N);
4104 Prag : constant Node_Id := SPARK_Pragma (Id);
4105
4106 begin
4107 -- Default the mode to "off" when the context is an instance and all
4108 -- SPARK_Mode pragmas found within are to be ignored.
4109
4110 if Ignore_SPARK_Mode_Pragmas (Id) then
4111 return True;
4112
4113 else
4114 return
4115 Present (Prag)
4116 and then Get_SPARK_Mode_From_Annotation (Prag) = Off;
4117 end if;
4118 end SPARK_Mode_Is_Off;
4119
4120 -- Start of processing for Check_State_Refinements
4121
4122 begin
4123 -- A block may declare a nested package
4124
4125 if Nkind (Context) = N_Block_Statement then
4126 Check_Packages_In (Declarations (Context));
4127
4128 -- An entry, protected, subprogram, or task body may declare a nested
4129 -- package.
4130
4131 elsif Nkind_In (Context, N_Entry_Body,
4132 N_Protected_Body,
4133 N_Subprogram_Body,
4134 N_Task_Body)
4135 then
4136 -- Do not verify proper state refinement when the body is subject to
4137 -- pragma SPARK_Mode Off because this disables the requirement for
4138 -- state refinement.
4139
4140 if not SPARK_Mode_Is_Off (Context) then
4141 Check_Packages_In (Declarations (Context));
4142 end if;
4143
4144 -- A package body may declare a nested package
4145
4146 elsif Nkind (Context) = N_Package_Body then
4147 Check_Package (Unit_Declaration_Node (Corresponding_Spec (Context)));
4148
4149 -- Do not verify proper state refinement when the body is subject to
4150 -- pragma SPARK_Mode Off because this disables the requirement for
4151 -- state refinement.
4152
4153 if not SPARK_Mode_Is_Off (Context) then
4154 Check_Packages_In (Declarations (Context));
4155 end if;
4156
4157 -- A library level [generic] package may declare a nested package
4158
4159 elsif Nkind_In (Context, N_Generic_Package_Declaration,
4160 N_Package_Declaration)
4161 and then Is_Main_Unit
4162 then
4163 Check_Package (Context);
4164 end if;
4165 end Check_State_Refinements;
4166
4167 ------------------------------
4168 -- Check_Unprotected_Access --
4169 ------------------------------
4170
4171 procedure Check_Unprotected_Access
4172 (Context : Node_Id;
4173 Expr : Node_Id)
4174 is
4175 Cont_Encl_Typ : Entity_Id;
4176 Pref_Encl_Typ : Entity_Id;
4177
4178 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
4179 -- Check whether Obj is a private component of a protected object.
4180 -- Return the protected type where the component resides, Empty
4181 -- otherwise.
4182
4183 function Is_Public_Operation return Boolean;
4184 -- Verify that the enclosing operation is callable from outside the
4185 -- protected object, to minimize false positives.
4186
4187 ------------------------------
4188 -- Enclosing_Protected_Type --
4189 ------------------------------
4190
4191 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
4192 begin
4193 if Is_Entity_Name (Obj) then
4194 declare
4195 Ent : Entity_Id := Entity (Obj);
4196
4197 begin
4198 -- The object can be a renaming of a private component, use
4199 -- the original record component.
4200
4201 if Is_Prival (Ent) then
4202 Ent := Prival_Link (Ent);
4203 end if;
4204
4205 if Is_Protected_Type (Scope (Ent)) then
4206 return Scope (Ent);
4207 end if;
4208 end;
4209 end if;
4210
4211 -- For indexed and selected components, recursively check the prefix
4212
4213 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
4214 return Enclosing_Protected_Type (Prefix (Obj));
4215
4216 -- The object does not denote a protected component
4217
4218 else
4219 return Empty;
4220 end if;
4221 end Enclosing_Protected_Type;
4222
4223 -------------------------
4224 -- Is_Public_Operation --
4225 -------------------------
4226
4227 function Is_Public_Operation return Boolean is
4228 S : Entity_Id;
4229 E : Entity_Id;
4230
4231 begin
4232 S := Current_Scope;
4233 while Present (S) and then S /= Pref_Encl_Typ loop
4234 if Scope (S) = Pref_Encl_Typ then
4235 E := First_Entity (Pref_Encl_Typ);
4236 while Present (E)
4237 and then E /= First_Private_Entity (Pref_Encl_Typ)
4238 loop
4239 if E = S then
4240 return True;
4241 end if;
4242
4243 Next_Entity (E);
4244 end loop;
4245 end if;
4246
4247 S := Scope (S);
4248 end loop;
4249
4250 return False;
4251 end Is_Public_Operation;
4252
4253 -- Start of processing for Check_Unprotected_Access
4254
4255 begin
4256 if Nkind (Expr) = N_Attribute_Reference
4257 and then Attribute_Name (Expr) = Name_Unchecked_Access
4258 then
4259 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
4260 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
4261
4262 -- Check whether we are trying to export a protected component to a
4263 -- context with an equal or lower access level.
4264
4265 if Present (Pref_Encl_Typ)
4266 and then No (Cont_Encl_Typ)
4267 and then Is_Public_Operation
4268 and then Scope_Depth (Pref_Encl_Typ) >=
4269 Object_Access_Level (Context)
4270 then
4271 Error_Msg_N
4272 ("??possible unprotected access to protected data", Expr);
4273 end if;
4274 end if;
4275 end Check_Unprotected_Access;
4276
4277 ------------------------------
4278 -- Check_Unused_Body_States --
4279 ------------------------------
4280
4281 procedure Check_Unused_Body_States (Body_Id : Entity_Id) is
4282 procedure Process_Refinement_Clause
4283 (Clause : Node_Id;
4284 States : Elist_Id);
4285 -- Inspect all constituents of refinement clause Clause and remove any
4286 -- matches from body state list States.
4287
4288 procedure Report_Unused_Body_States (States : Elist_Id);
4289 -- Emit errors for each abstract state or object found in list States
4290
4291 -------------------------------
4292 -- Process_Refinement_Clause --
4293 -------------------------------
4294
4295 procedure Process_Refinement_Clause
4296 (Clause : Node_Id;
4297 States : Elist_Id)
4298 is
4299 procedure Process_Constituent (Constit : Node_Id);
4300 -- Remove constituent Constit from body state list States
4301
4302 -------------------------
4303 -- Process_Constituent --
4304 -------------------------
4305
4306 procedure Process_Constituent (Constit : Node_Id) is
4307 Constit_Id : Entity_Id;
4308
4309 begin
4310 -- Guard against illegal constituents. Only abstract states and
4311 -- objects can appear on the right hand side of a refinement.
4312
4313 if Is_Entity_Name (Constit) then
4314 Constit_Id := Entity_Of (Constit);
4315
4316 if Present (Constit_Id)
4317 and then Ekind_In (Constit_Id, E_Abstract_State,
4318 E_Constant,
4319 E_Variable)
4320 then
4321 Remove (States, Constit_Id);
4322 end if;
4323 end if;
4324 end Process_Constituent;
4325
4326 -- Local variables
4327
4328 Constit : Node_Id;
4329
4330 -- Start of processing for Process_Refinement_Clause
4331
4332 begin
4333 if Nkind (Clause) = N_Component_Association then
4334 Constit := Expression (Clause);
4335
4336 -- Multiple constituents appear as an aggregate
4337
4338 if Nkind (Constit) = N_Aggregate then
4339 Constit := First (Expressions (Constit));
4340 while Present (Constit) loop
4341 Process_Constituent (Constit);
4342 Next (Constit);
4343 end loop;
4344
4345 -- Various forms of a single constituent
4346
4347 else
4348 Process_Constituent (Constit);
4349 end if;
4350 end if;
4351 end Process_Refinement_Clause;
4352
4353 -------------------------------
4354 -- Report_Unused_Body_States --
4355 -------------------------------
4356
4357 procedure Report_Unused_Body_States (States : Elist_Id) is
4358 Posted : Boolean := False;
4359 State_Elmt : Elmt_Id;
4360 State_Id : Entity_Id;
4361
4362 begin
4363 if Present (States) then
4364 State_Elmt := First_Elmt (States);
4365 while Present (State_Elmt) loop
4366 State_Id := Node (State_Elmt);
4367
4368 -- Constants are part of the hidden state of a package, but the
4369 -- compiler cannot determine whether they have variable input
4370 -- (SPARK RM 7.1.1(2)) and cannot classify them properly as a
4371 -- hidden state. Do not emit an error when a constant does not
4372 -- participate in a state refinement, even though it acts as a
4373 -- hidden state.
4374
4375 if Ekind (State_Id) = E_Constant then
4376 null;
4377
4378 -- Generate an error message of the form:
4379
4380 -- body of package ... has unused hidden states
4381 -- abstract state ... defined at ...
4382 -- variable ... defined at ...
4383
4384 else
4385 if not Posted then
4386 Posted := True;
4387 SPARK_Msg_N
4388 ("body of package & has unused hidden states", Body_Id);
4389 end if;
4390
4391 Error_Msg_Sloc := Sloc (State_Id);
4392
4393 if Ekind (State_Id) = E_Abstract_State then
4394 SPARK_Msg_NE
4395 ("\abstract state & defined #", Body_Id, State_Id);
4396
4397 else
4398 SPARK_Msg_NE ("\variable & defined #", Body_Id, State_Id);
4399 end if;
4400 end if;
4401
4402 Next_Elmt (State_Elmt);
4403 end loop;
4404 end if;
4405 end Report_Unused_Body_States;
4406
4407 -- Local variables
4408
4409 Prag : constant Node_Id := Get_Pragma (Body_Id, Pragma_Refined_State);
4410 Spec_Id : constant Entity_Id := Spec_Entity (Body_Id);
4411 Clause : Node_Id;
4412 States : Elist_Id;
4413
4414 -- Start of processing for Check_Unused_Body_States
4415
4416 begin
4417 -- Inspect the clauses of pragma Refined_State and determine whether all
4418 -- visible states declared within the package body participate in the
4419 -- refinement.
4420
4421 if Present (Prag) then
4422 Clause := Expression (Get_Argument (Prag, Spec_Id));
4423 States := Collect_Body_States (Body_Id);
4424
4425 -- Multiple non-null state refinements appear as an aggregate
4426
4427 if Nkind (Clause) = N_Aggregate then
4428 Clause := First (Component_Associations (Clause));
4429 while Present (Clause) loop
4430 Process_Refinement_Clause (Clause, States);
4431 Next (Clause);
4432 end loop;
4433
4434 -- Various forms of a single state refinement
4435
4436 else
4437 Process_Refinement_Clause (Clause, States);
4438 end if;
4439
4440 -- Ensure that all abstract states and objects declared in the
4441 -- package body state space are utilized as constituents.
4442
4443 Report_Unused_Body_States (States);
4444 end if;
4445 end Check_Unused_Body_States;
4446
4447 -----------------
4448 -- Choice_List --
4449 -----------------
4450
4451 function Choice_List (N : Node_Id) return List_Id is
4452 begin
4453 if Nkind (N) = N_Iterated_Component_Association then
4454 return Discrete_Choices (N);
4455 else
4456 return Choices (N);
4457 end if;
4458 end Choice_List;
4459
4460 -------------------------
4461 -- Collect_Body_States --
4462 -------------------------
4463
4464 function Collect_Body_States (Body_Id : Entity_Id) return Elist_Id is
4465 function Is_Visible_Object (Obj_Id : Entity_Id) return Boolean;
4466 -- Determine whether object Obj_Id is a suitable visible state of a
4467 -- package body.
4468
4469 procedure Collect_Visible_States
4470 (Pack_Id : Entity_Id;
4471 States : in out Elist_Id);
4472 -- Gather the entities of all abstract states and objects declared in
4473 -- the visible state space of package Pack_Id.
4474
4475 ----------------------------
4476 -- Collect_Visible_States --
4477 ----------------------------
4478
4479 procedure Collect_Visible_States
4480 (Pack_Id : Entity_Id;
4481 States : in out Elist_Id)
4482 is
4483 Item_Id : Entity_Id;
4484
4485 begin
4486 -- Traverse the entity chain of the package and inspect all visible
4487 -- items.
4488
4489 Item_Id := First_Entity (Pack_Id);
4490 while Present (Item_Id) and then not In_Private_Part (Item_Id) loop
4491
4492 -- Do not consider internally generated items as those cannot be
4493 -- named and participate in refinement.
4494
4495 if not Comes_From_Source (Item_Id) then
4496 null;
4497
4498 elsif Ekind (Item_Id) = E_Abstract_State then
4499 Append_New_Elmt (Item_Id, States);
4500
4501 elsif Ekind_In (Item_Id, E_Constant, E_Variable)
4502 and then Is_Visible_Object (Item_Id)
4503 then
4504 Append_New_Elmt (Item_Id, States);
4505
4506 -- Recursively gather the visible states of a nested package
4507
4508 elsif Ekind (Item_Id) = E_Package then
4509 Collect_Visible_States (Item_Id, States);
4510 end if;
4511
4512 Next_Entity (Item_Id);
4513 end loop;
4514 end Collect_Visible_States;
4515
4516 -----------------------
4517 -- Is_Visible_Object --
4518 -----------------------
4519
4520 function Is_Visible_Object (Obj_Id : Entity_Id) return Boolean is
4521 begin
4522 -- Objects that map generic formals to their actuals are not visible
4523 -- from outside the generic instantiation.
4524
4525 if Present (Corresponding_Generic_Association
4526 (Declaration_Node (Obj_Id)))
4527 then
4528 return False;
4529
4530 -- Constituents of a single protected/task type act as components of
4531 -- the type and are not visible from outside the type.
4532
4533 elsif Ekind (Obj_Id) = E_Variable
4534 and then Present (Encapsulating_State (Obj_Id))
4535 and then Is_Single_Concurrent_Object (Encapsulating_State (Obj_Id))
4536 then
4537 return False;
4538
4539 else
4540 return True;
4541 end if;
4542 end Is_Visible_Object;
4543
4544 -- Local variables
4545
4546 Body_Decl : constant Node_Id := Unit_Declaration_Node (Body_Id);
4547 Decl : Node_Id;
4548 Item_Id : Entity_Id;
4549 States : Elist_Id := No_Elist;
4550
4551 -- Start of processing for Collect_Body_States
4552
4553 begin
4554 -- Inspect the declarations of the body looking for source objects,
4555 -- packages and package instantiations. Note that even though this
4556 -- processing is very similar to Collect_Visible_States, a package
4557 -- body does not have a First/Next_Entity list.
4558
4559 Decl := First (Declarations (Body_Decl));
4560 while Present (Decl) loop
4561
4562 -- Capture source objects as internally generated temporaries cannot
4563 -- be named and participate in refinement.
4564
4565 if Nkind (Decl) = N_Object_Declaration then
4566 Item_Id := Defining_Entity (Decl);
4567
4568 if Comes_From_Source (Item_Id)
4569 and then Is_Visible_Object (Item_Id)
4570 then
4571 Append_New_Elmt (Item_Id, States);
4572 end if;
4573
4574 -- Capture the visible abstract states and objects of a source
4575 -- package [instantiation].
4576
4577 elsif Nkind (Decl) = N_Package_Declaration then
4578 Item_Id := Defining_Entity (Decl);
4579
4580 if Comes_From_Source (Item_Id) then
4581 Collect_Visible_States (Item_Id, States);
4582 end if;
4583 end if;
4584
4585 Next (Decl);
4586 end loop;
4587
4588 return States;
4589 end Collect_Body_States;
4590
4591 ------------------------
4592 -- Collect_Interfaces --
4593 ------------------------
4594
4595 procedure Collect_Interfaces
4596 (T : Entity_Id;
4597 Ifaces_List : out Elist_Id;
4598 Exclude_Parents : Boolean := False;
4599 Use_Full_View : Boolean := True)
4600 is
4601 procedure Collect (Typ : Entity_Id);
4602 -- Subsidiary subprogram used to traverse the whole list
4603 -- of directly and indirectly implemented interfaces
4604
4605 -------------
4606 -- Collect --
4607 -------------
4608
4609 procedure Collect (Typ : Entity_Id) is
4610 Ancestor : Entity_Id;
4611 Full_T : Entity_Id;
4612 Id : Node_Id;
4613 Iface : Entity_Id;
4614
4615 begin
4616 Full_T := Typ;
4617
4618 -- Handle private types and subtypes
4619
4620 if Use_Full_View
4621 and then Is_Private_Type (Typ)
4622 and then Present (Full_View (Typ))
4623 then
4624 Full_T := Full_View (Typ);
4625
4626 if Ekind (Full_T) = E_Record_Subtype then
4627 Full_T := Etype (Typ);
4628
4629 if Present (Full_View (Full_T)) then
4630 Full_T := Full_View (Full_T);
4631 end if;
4632 end if;
4633 end if;
4634
4635 -- Include the ancestor if we are generating the whole list of
4636 -- abstract interfaces.
4637
4638 if Etype (Full_T) /= Typ
4639
4640 -- Protect the frontend against wrong sources. For example:
4641
4642 -- package P is
4643 -- type A is tagged null record;
4644 -- type B is new A with private;
4645 -- type C is new A with private;
4646 -- private
4647 -- type B is new C with null record;
4648 -- type C is new B with null record;
4649 -- end P;
4650
4651 and then Etype (Full_T) /= T
4652 then
4653 Ancestor := Etype (Full_T);
4654 Collect (Ancestor);
4655
4656 if Is_Interface (Ancestor) and then not Exclude_Parents then
4657 Append_Unique_Elmt (Ancestor, Ifaces_List);
4658 end if;
4659 end if;
4660
4661 -- Traverse the graph of ancestor interfaces
4662
4663 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
4664 Id := First (Abstract_Interface_List (Full_T));
4665 while Present (Id) loop
4666 Iface := Etype (Id);
4667
4668 -- Protect against wrong uses. For example:
4669 -- type I is interface;
4670 -- type O is tagged null record;
4671 -- type Wrong is new I and O with null record; -- ERROR
4672
4673 if Is_Interface (Iface) then
4674 if Exclude_Parents
4675 and then Etype (T) /= T
4676 and then Interface_Present_In_Ancestor (Etype (T), Iface)
4677 then
4678 null;
4679 else
4680 Collect (Iface);
4681 Append_Unique_Elmt (Iface, Ifaces_List);
4682 end if;
4683 end if;
4684
4685 Next (Id);
4686 end loop;
4687 end if;
4688 end Collect;
4689
4690 -- Start of processing for Collect_Interfaces
4691
4692 begin
4693 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
4694 Ifaces_List := New_Elmt_List;
4695 Collect (T);
4696 end Collect_Interfaces;
4697
4698 ----------------------------------
4699 -- Collect_Interface_Components --
4700 ----------------------------------
4701
4702 procedure Collect_Interface_Components
4703 (Tagged_Type : Entity_Id;
4704 Components_List : out Elist_Id)
4705 is
4706 procedure Collect (Typ : Entity_Id);
4707 -- Subsidiary subprogram used to climb to the parents
4708
4709 -------------
4710 -- Collect --
4711 -------------
4712
4713 procedure Collect (Typ : Entity_Id) is
4714 Tag_Comp : Entity_Id;
4715 Parent_Typ : Entity_Id;
4716
4717 begin
4718 -- Handle private types
4719
4720 if Present (Full_View (Etype (Typ))) then
4721 Parent_Typ := Full_View (Etype (Typ));
4722 else
4723 Parent_Typ := Etype (Typ);
4724 end if;
4725
4726 if Parent_Typ /= Typ
4727
4728 -- Protect the frontend against wrong sources. For example:
4729
4730 -- package P is
4731 -- type A is tagged null record;
4732 -- type B is new A with private;
4733 -- type C is new A with private;
4734 -- private
4735 -- type B is new C with null record;
4736 -- type C is new B with null record;
4737 -- end P;
4738
4739 and then Parent_Typ /= Tagged_Type
4740 then
4741 Collect (Parent_Typ);
4742 end if;
4743
4744 -- Collect the components containing tags of secondary dispatch
4745 -- tables.
4746
4747 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
4748 while Present (Tag_Comp) loop
4749 pragma Assert (Present (Related_Type (Tag_Comp)));
4750 Append_Elmt (Tag_Comp, Components_List);
4751
4752 Tag_Comp := Next_Tag_Component (Tag_Comp);
4753 end loop;
4754 end Collect;
4755
4756 -- Start of processing for Collect_Interface_Components
4757
4758 begin
4759 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
4760 and then Is_Tagged_Type (Tagged_Type));
4761
4762 Components_List := New_Elmt_List;
4763 Collect (Tagged_Type);
4764 end Collect_Interface_Components;
4765
4766 -----------------------------
4767 -- Collect_Interfaces_Info --
4768 -----------------------------
4769
4770 procedure Collect_Interfaces_Info
4771 (T : Entity_Id;
4772 Ifaces_List : out Elist_Id;
4773 Components_List : out Elist_Id;
4774 Tags_List : out Elist_Id)
4775 is
4776 Comps_List : Elist_Id;
4777 Comp_Elmt : Elmt_Id;
4778 Comp_Iface : Entity_Id;
4779 Iface_Elmt : Elmt_Id;
4780 Iface : Entity_Id;
4781
4782 function Search_Tag (Iface : Entity_Id) return Entity_Id;
4783 -- Search for the secondary tag associated with the interface type
4784 -- Iface that is implemented by T.
4785
4786 ----------------
4787 -- Search_Tag --
4788 ----------------
4789
4790 function Search_Tag (Iface : Entity_Id) return Entity_Id is
4791 ADT : Elmt_Id;
4792 begin
4793 if not Is_CPP_Class (T) then
4794 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
4795 else
4796 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
4797 end if;
4798
4799 while Present (ADT)
4800 and then Is_Tag (Node (ADT))
4801 and then Related_Type (Node (ADT)) /= Iface
4802 loop
4803 -- Skip secondary dispatch table referencing thunks to user
4804 -- defined primitives covered by this interface.
4805
4806 pragma Assert (Has_Suffix (Node (ADT), 'P'));
4807 Next_Elmt (ADT);
4808
4809 -- Skip secondary dispatch tables of Ada types
4810
4811 if not Is_CPP_Class (T) then
4812
4813 -- Skip secondary dispatch table referencing thunks to
4814 -- predefined primitives.
4815
4816 pragma Assert (Has_Suffix (Node (ADT), 'Y'));
4817 Next_Elmt (ADT);
4818
4819 -- Skip secondary dispatch table referencing user-defined
4820 -- primitives covered by this interface.
4821
4822 pragma Assert (Has_Suffix (Node (ADT), 'D'));
4823 Next_Elmt (ADT);
4824
4825 -- Skip secondary dispatch table referencing predefined
4826 -- primitives.
4827
4828 pragma Assert (Has_Suffix (Node (ADT), 'Z'));
4829 Next_Elmt (ADT);
4830 end if;
4831 end loop;
4832
4833 pragma Assert (Is_Tag (Node (ADT)));
4834 return Node (ADT);
4835 end Search_Tag;
4836
4837 -- Start of processing for Collect_Interfaces_Info
4838
4839 begin
4840 Collect_Interfaces (T, Ifaces_List);
4841 Collect_Interface_Components (T, Comps_List);
4842
4843 -- Search for the record component and tag associated with each
4844 -- interface type of T.
4845
4846 Components_List := New_Elmt_List;
4847 Tags_List := New_Elmt_List;
4848
4849 Iface_Elmt := First_Elmt (Ifaces_List);
4850 while Present (Iface_Elmt) loop
4851 Iface := Node (Iface_Elmt);
4852
4853 -- Associate the primary tag component and the primary dispatch table
4854 -- with all the interfaces that are parents of T
4855
4856 if Is_Ancestor (Iface, T, Use_Full_View => True) then
4857 Append_Elmt (First_Tag_Component (T), Components_List);
4858 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
4859
4860 -- Otherwise search for the tag component and secondary dispatch
4861 -- table of Iface
4862
4863 else
4864 Comp_Elmt := First_Elmt (Comps_List);
4865 while Present (Comp_Elmt) loop
4866 Comp_Iface := Related_Type (Node (Comp_Elmt));
4867
4868 if Comp_Iface = Iface
4869 or else Is_Ancestor (Iface, Comp_Iface, Use_Full_View => True)
4870 then
4871 Append_Elmt (Node (Comp_Elmt), Components_List);
4872 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
4873 exit;
4874 end if;
4875
4876 Next_Elmt (Comp_Elmt);
4877 end loop;
4878 pragma Assert (Present (Comp_Elmt));
4879 end if;
4880
4881 Next_Elmt (Iface_Elmt);
4882 end loop;
4883 end Collect_Interfaces_Info;
4884
4885 ---------------------
4886 -- Collect_Parents --
4887 ---------------------
4888
4889 procedure Collect_Parents
4890 (T : Entity_Id;
4891 List : out Elist_Id;
4892 Use_Full_View : Boolean := True)
4893 is
4894 Current_Typ : Entity_Id := T;
4895 Parent_Typ : Entity_Id;
4896
4897 begin
4898 List := New_Elmt_List;
4899
4900 -- No action if the if the type has no parents
4901
4902 if T = Etype (T) then
4903 return;
4904 end if;
4905
4906 loop
4907 Parent_Typ := Etype (Current_Typ);
4908
4909 if Is_Private_Type (Parent_Typ)
4910 and then Present (Full_View (Parent_Typ))
4911 and then Use_Full_View
4912 then
4913 Parent_Typ := Full_View (Base_Type (Parent_Typ));
4914 end if;
4915
4916 Append_Elmt (Parent_Typ, List);
4917
4918 exit when Parent_Typ = Current_Typ;
4919 Current_Typ := Parent_Typ;
4920 end loop;
4921 end Collect_Parents;
4922
4923 ----------------------------------
4924 -- Collect_Primitive_Operations --
4925 ----------------------------------
4926
4927 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
4928 B_Type : constant Entity_Id := Base_Type (T);
4929 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
4930 B_Scope : Entity_Id := Scope (B_Type);
4931 Op_List : Elist_Id;
4932 Formal : Entity_Id;
4933 Is_Prim : Boolean;
4934 Is_Type_In_Pkg : Boolean;
4935 Formal_Derived : Boolean := False;
4936 Id : Entity_Id;
4937
4938 function Match (E : Entity_Id) return Boolean;
4939 -- True if E's base type is B_Type, or E is of an anonymous access type
4940 -- and the base type of its designated type is B_Type.
4941
4942 -----------
4943 -- Match --
4944 -----------
4945
4946 function Match (E : Entity_Id) return Boolean is
4947 Etyp : Entity_Id := Etype (E);
4948
4949 begin
4950 if Ekind (Etyp) = E_Anonymous_Access_Type then
4951 Etyp := Designated_Type (Etyp);
4952 end if;
4953
4954 -- In Ada 2012 a primitive operation may have a formal of an
4955 -- incomplete view of the parent type.
4956
4957 return Base_Type (Etyp) = B_Type
4958 or else
4959 (Ada_Version >= Ada_2012
4960 and then Ekind (Etyp) = E_Incomplete_Type
4961 and then Full_View (Etyp) = B_Type);
4962 end Match;
4963
4964 -- Start of processing for Collect_Primitive_Operations
4965
4966 begin
4967 -- For tagged types, the primitive operations are collected as they
4968 -- are declared, and held in an explicit list which is simply returned.
4969
4970 if Is_Tagged_Type (B_Type) then
4971 return Primitive_Operations (B_Type);
4972
4973 -- An untagged generic type that is a derived type inherits the
4974 -- primitive operations of its parent type. Other formal types only
4975 -- have predefined operators, which are not explicitly represented.
4976
4977 elsif Is_Generic_Type (B_Type) then
4978 if Nkind (B_Decl) = N_Formal_Type_Declaration
4979 and then Nkind (Formal_Type_Definition (B_Decl)) =
4980 N_Formal_Derived_Type_Definition
4981 then
4982 Formal_Derived := True;
4983 else
4984 return New_Elmt_List;
4985 end if;
4986 end if;
4987
4988 Op_List := New_Elmt_List;
4989
4990 if B_Scope = Standard_Standard then
4991 if B_Type = Standard_String then
4992 Append_Elmt (Standard_Op_Concat, Op_List);
4993
4994 elsif B_Type = Standard_Wide_String then
4995 Append_Elmt (Standard_Op_Concatw, Op_List);
4996
4997 else
4998 null;
4999 end if;
5000
5001 -- Locate the primitive subprograms of the type
5002
5003 else
5004 -- The primitive operations appear after the base type, except
5005 -- if the derivation happens within the private part of B_Scope
5006 -- and the type is a private type, in which case both the type
5007 -- and some primitive operations may appear before the base
5008 -- type, and the list of candidates starts after the type.
5009
5010 if In_Open_Scopes (B_Scope)
5011 and then Scope (T) = B_Scope
5012 and then In_Private_Part (B_Scope)
5013 then
5014 Id := Next_Entity (T);
5015
5016 -- In Ada 2012, If the type has an incomplete partial view, there
5017 -- may be primitive operations declared before the full view, so
5018 -- we need to start scanning from the incomplete view, which is
5019 -- earlier on the entity chain.
5020
5021 elsif Nkind (Parent (B_Type)) = N_Full_Type_Declaration
5022 and then Present (Incomplete_View (Parent (B_Type)))
5023 then
5024 Id := Defining_Entity (Incomplete_View (Parent (B_Type)));
5025
5026 -- If T is a derived from a type with an incomplete view declared
5027 -- elsewhere, that incomplete view is irrelevant, we want the
5028 -- operations in the scope of T.
5029
5030 if Scope (Id) /= Scope (B_Type) then
5031 Id := Next_Entity (B_Type);
5032 end if;
5033
5034 else
5035 Id := Next_Entity (B_Type);
5036 end if;
5037
5038 -- Set flag if this is a type in a package spec
5039
5040 Is_Type_In_Pkg :=
5041 Is_Package_Or_Generic_Package (B_Scope)
5042 and then
5043 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
5044 N_Package_Body;
5045
5046 while Present (Id) loop
5047
5048 -- Test whether the result type or any of the parameter types of
5049 -- each subprogram following the type match that type when the
5050 -- type is declared in a package spec, is a derived type, or the
5051 -- subprogram is marked as primitive. (The Is_Primitive test is
5052 -- needed to find primitives of nonderived types in declarative
5053 -- parts that happen to override the predefined "=" operator.)
5054
5055 -- Note that generic formal subprograms are not considered to be
5056 -- primitive operations and thus are never inherited.
5057
5058 if Is_Overloadable (Id)
5059 and then (Is_Type_In_Pkg
5060 or else Is_Derived_Type (B_Type)
5061 or else Is_Primitive (Id))
5062 and then Nkind (Parent (Parent (Id)))
5063 not in N_Formal_Subprogram_Declaration
5064 then
5065 Is_Prim := False;
5066
5067 if Match (Id) then
5068 Is_Prim := True;
5069
5070 else
5071 Formal := First_Formal (Id);
5072 while Present (Formal) loop
5073 if Match (Formal) then
5074 Is_Prim := True;
5075 exit;
5076 end if;
5077
5078 Next_Formal (Formal);
5079 end loop;
5080 end if;
5081
5082 -- For a formal derived type, the only primitives are the ones
5083 -- inherited from the parent type. Operations appearing in the
5084 -- package declaration are not primitive for it.
5085
5086 if Is_Prim
5087 and then (not Formal_Derived or else Present (Alias (Id)))
5088 then
5089 -- In the special case of an equality operator aliased to
5090 -- an overriding dispatching equality belonging to the same
5091 -- type, we don't include it in the list of primitives.
5092 -- This avoids inheriting multiple equality operators when
5093 -- deriving from untagged private types whose full type is
5094 -- tagged, which can otherwise cause ambiguities. Note that
5095 -- this should only happen for this kind of untagged parent
5096 -- type, since normally dispatching operations are inherited
5097 -- using the type's Primitive_Operations list.
5098
5099 if Chars (Id) = Name_Op_Eq
5100 and then Is_Dispatching_Operation (Id)
5101 and then Present (Alias (Id))
5102 and then Present (Overridden_Operation (Alias (Id)))
5103 and then Base_Type (Etype (First_Entity (Id))) =
5104 Base_Type (Etype (First_Entity (Alias (Id))))
5105 then
5106 null;
5107
5108 -- Include the subprogram in the list of primitives
5109
5110 else
5111 Append_Elmt (Id, Op_List);
5112 end if;
5113 end if;
5114 end if;
5115
5116 Next_Entity (Id);
5117
5118 -- For a type declared in System, some of its operations may
5119 -- appear in the target-specific extension to System.
5120
5121 if No (Id)
5122 and then B_Scope = RTU_Entity (System)
5123 and then Present_System_Aux
5124 then
5125 B_Scope := System_Aux_Id;
5126 Id := First_Entity (System_Aux_Id);
5127 end if;
5128 end loop;
5129 end if;
5130
5131 return Op_List;
5132 end Collect_Primitive_Operations;
5133
5134 -----------------------------------
5135 -- Compile_Time_Constraint_Error --
5136 -----------------------------------
5137
5138 function Compile_Time_Constraint_Error
5139 (N : Node_Id;
5140 Msg : String;
5141 Ent : Entity_Id := Empty;
5142 Loc : Source_Ptr := No_Location;
5143 Warn : Boolean := False) return Node_Id
5144 is
5145 Msgc : String (1 .. Msg'Length + 3);
5146 -- Copy of message, with room for possible ?? or << and ! at end
5147
5148 Msgl : Natural;
5149 Wmsg : Boolean;
5150 Eloc : Source_Ptr;
5151
5152 -- Start of processing for Compile_Time_Constraint_Error
5153
5154 begin
5155 -- If this is a warning, convert it into an error if we are in code
5156 -- subject to SPARK_Mode being set On, unless Warn is True to force a
5157 -- warning. The rationale is that a compile-time constraint error should
5158 -- lead to an error instead of a warning when SPARK_Mode is On, but in
5159 -- a few cases we prefer to issue a warning and generate both a suitable
5160 -- run-time error in GNAT and a suitable check message in GNATprove.
5161 -- Those cases are those that likely correspond to deactivated SPARK
5162 -- code, so that this kind of code can be compiled and analyzed instead
5163 -- of being rejected.
5164
5165 Error_Msg_Warn := Warn or SPARK_Mode /= On;
5166
5167 -- A static constraint error in an instance body is not a fatal error.
5168 -- we choose to inhibit the message altogether, because there is no
5169 -- obvious node (for now) on which to post it. On the other hand the
5170 -- offending node must be replaced with a constraint_error in any case.
5171
5172 -- No messages are generated if we already posted an error on this node
5173
5174 if not Error_Posted (N) then
5175 if Loc /= No_Location then
5176 Eloc := Loc;
5177 else
5178 Eloc := Sloc (N);
5179 end if;
5180
5181 -- Copy message to Msgc, converting any ? in the message into <
5182 -- instead, so that we have an error in GNATprove mode.
5183
5184 Msgl := Msg'Length;
5185
5186 for J in 1 .. Msgl loop
5187 if Msg (J) = '?' and then (J = 1 or else Msg (J - 1) /= ''') then
5188 Msgc (J) := '<';
5189 else
5190 Msgc (J) := Msg (J);
5191 end if;
5192 end loop;
5193
5194 -- Message is a warning, even in Ada 95 case
5195
5196 if Msg (Msg'Last) = '?' or else Msg (Msg'Last) = '<' then
5197 Wmsg := True;
5198
5199 -- In Ada 83, all messages are warnings. In the private part and the
5200 -- body of an instance, constraint_checks are only warnings. We also
5201 -- make this a warning if the Warn parameter is set.
5202
5203 elsif Warn
5204 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
5205 or else In_Instance_Not_Visible
5206 then
5207 Msgl := Msgl + 1;
5208 Msgc (Msgl) := '<';
5209 Msgl := Msgl + 1;
5210 Msgc (Msgl) := '<';
5211 Wmsg := True;
5212
5213 -- Otherwise we have a real error message (Ada 95 static case) and we
5214 -- make this an unconditional message. Note that in the warning case
5215 -- we do not make the message unconditional, it seems reasonable to
5216 -- delete messages like this (about exceptions that will be raised)
5217 -- in dead code.
5218
5219 else
5220 Wmsg := False;
5221 Msgl := Msgl + 1;
5222 Msgc (Msgl) := '!';
5223 end if;
5224
5225 -- One more test, skip the warning if the related expression is
5226 -- statically unevaluated, since we don't want to warn about what
5227 -- will happen when something is evaluated if it never will be
5228 -- evaluated.
5229
5230 if not Is_Statically_Unevaluated (N) then
5231 if Present (Ent) then
5232 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
5233 else
5234 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
5235 end if;
5236
5237 if Wmsg then
5238
5239 -- Check whether the context is an Init_Proc
5240
5241 if Inside_Init_Proc then
5242 declare
5243 Conc_Typ : constant Entity_Id :=
5244 Corresponding_Concurrent_Type
5245 (Entity (Parameter_Type (First
5246 (Parameter_Specifications
5247 (Parent (Current_Scope))))));
5248
5249 begin
5250 -- Don't complain if the corresponding concurrent type
5251 -- doesn't come from source (i.e. a single task/protected
5252 -- object).
5253
5254 if Present (Conc_Typ)
5255 and then not Comes_From_Source (Conc_Typ)
5256 then
5257 Error_Msg_NEL
5258 ("\& [<<", N, Standard_Constraint_Error, Eloc);
5259
5260 else
5261 if GNATprove_Mode then
5262 Error_Msg_NEL
5263 ("\& would have been raised for objects of this "
5264 & "type", N, Standard_Constraint_Error, Eloc);
5265 else
5266 Error_Msg_NEL
5267 ("\& will be raised for objects of this type??",
5268 N, Standard_Constraint_Error, Eloc);
5269 end if;
5270 end if;
5271 end;
5272
5273 else
5274 Error_Msg_NEL ("\& [<<", N, Standard_Constraint_Error, Eloc);
5275 end if;
5276
5277 else
5278 Error_Msg ("\static expression fails Constraint_Check", Eloc);
5279 Set_Error_Posted (N);
5280 end if;
5281 end if;
5282 end if;
5283
5284 return N;
5285 end Compile_Time_Constraint_Error;
5286
5287 -----------------------
5288 -- Conditional_Delay --
5289 -----------------------
5290
5291 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
5292 begin
5293 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
5294 Set_Has_Delayed_Freeze (New_Ent);
5295 end if;
5296 end Conditional_Delay;
5297
5298 ----------------------------
5299 -- Contains_Refined_State --
5300 ----------------------------
5301
5302 function Contains_Refined_State (Prag : Node_Id) return Boolean is
5303 function Has_State_In_Dependency (List : Node_Id) return Boolean;
5304 -- Determine whether a dependency list mentions a state with a visible
5305 -- refinement.
5306
5307 function Has_State_In_Global (List : Node_Id) return Boolean;
5308 -- Determine whether a global list mentions a state with a visible
5309 -- refinement.
5310
5311 function Is_Refined_State (Item : Node_Id) return Boolean;
5312 -- Determine whether Item is a reference to an abstract state with a
5313 -- visible refinement.
5314
5315 -----------------------------
5316 -- Has_State_In_Dependency --
5317 -----------------------------
5318
5319 function Has_State_In_Dependency (List : Node_Id) return Boolean is
5320 Clause : Node_Id;
5321 Output : Node_Id;
5322
5323 begin
5324 -- A null dependency list does not mention any states
5325
5326 if Nkind (List) = N_Null then
5327 return False;
5328
5329 -- Dependency clauses appear as component associations of an
5330 -- aggregate.
5331
5332 elsif Nkind (List) = N_Aggregate
5333 and then Present (Component_Associations (List))
5334 then
5335 Clause := First (Component_Associations (List));
5336 while Present (Clause) loop
5337
5338 -- Inspect the outputs of a dependency clause
5339
5340 Output := First (Choices (Clause));
5341 while Present (Output) loop
5342 if Is_Refined_State (Output) then
5343 return True;
5344 end if;
5345
5346 Next (Output);
5347 end loop;
5348
5349 -- Inspect the outputs of a dependency clause
5350
5351 if Is_Refined_State (Expression (Clause)) then
5352 return True;
5353 end if;
5354
5355 Next (Clause);
5356 end loop;
5357
5358 -- If we get here, then none of the dependency clauses mention a
5359 -- state with visible refinement.
5360
5361 return False;
5362
5363 -- An illegal pragma managed to sneak in
5364
5365 else
5366 raise Program_Error;
5367 end if;
5368 end Has_State_In_Dependency;
5369
5370 -------------------------
5371 -- Has_State_In_Global --
5372 -------------------------
5373
5374 function Has_State_In_Global (List : Node_Id) return Boolean is
5375 Item : Node_Id;
5376
5377 begin
5378 -- A null global list does not mention any states
5379
5380 if Nkind (List) = N_Null then
5381 return False;
5382
5383 -- Simple global list or moded global list declaration
5384
5385 elsif Nkind (List) = N_Aggregate then
5386
5387 -- The declaration of a simple global list appear as a collection
5388 -- of expressions.
5389
5390 if Present (Expressions (List)) then
5391 Item := First (Expressions (List));
5392 while Present (Item) loop
5393 if Is_Refined_State (Item) then
5394 return True;
5395 end if;
5396
5397 Next (Item);
5398 end loop;
5399
5400 -- The declaration of a moded global list appears as a collection
5401 -- of component associations where individual choices denote
5402 -- modes.
5403
5404 else
5405 Item := First (Component_Associations (List));
5406 while Present (Item) loop
5407 if Has_State_In_Global (Expression (Item)) then
5408 return True;
5409 end if;
5410
5411 Next (Item);
5412 end loop;
5413 end if;
5414
5415 -- If we get here, then the simple/moded global list did not
5416 -- mention any states with a visible refinement.
5417
5418 return False;
5419
5420 -- Single global item declaration
5421
5422 elsif Is_Entity_Name (List) then
5423 return Is_Refined_State (List);
5424
5425 -- An illegal pragma managed to sneak in
5426
5427 else
5428 raise Program_Error;
5429 end if;
5430 end Has_State_In_Global;
5431
5432 ----------------------
5433 -- Is_Refined_State --
5434 ----------------------
5435
5436 function Is_Refined_State (Item : Node_Id) return Boolean is
5437 Elmt : Node_Id;
5438 Item_Id : Entity_Id;
5439
5440 begin
5441 if Nkind (Item) = N_Null then
5442 return False;
5443
5444 -- States cannot be subject to attribute 'Result. This case arises
5445 -- in dependency relations.
5446
5447 elsif Nkind (Item) = N_Attribute_Reference
5448 and then Attribute_Name (Item) = Name_Result
5449 then
5450 return False;
5451
5452 -- Multiple items appear as an aggregate. This case arises in
5453 -- dependency relations.
5454
5455 elsif Nkind (Item) = N_Aggregate
5456 and then Present (Expressions (Item))
5457 then
5458 Elmt := First (Expressions (Item));
5459 while Present (Elmt) loop
5460 if Is_Refined_State (Elmt) then
5461 return True;
5462 end if;
5463
5464 Next (Elmt);
5465 end loop;
5466
5467 -- If we get here, then none of the inputs or outputs reference a
5468 -- state with visible refinement.
5469
5470 return False;
5471
5472 -- Single item
5473
5474 else
5475 Item_Id := Entity_Of (Item);
5476
5477 return
5478 Present (Item_Id)
5479 and then Ekind (Item_Id) = E_Abstract_State
5480 and then Has_Visible_Refinement (Item_Id);
5481 end if;
5482 end Is_Refined_State;
5483
5484 -- Local variables
5485
5486 Arg : constant Node_Id :=
5487 Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
5488 Nam : constant Name_Id := Pragma_Name (Prag);
5489
5490 -- Start of processing for Contains_Refined_State
5491
5492 begin
5493 if Nam = Name_Depends then
5494 return Has_State_In_Dependency (Arg);
5495
5496 else pragma Assert (Nam = Name_Global);
5497 return Has_State_In_Global (Arg);
5498 end if;
5499 end Contains_Refined_State;
5500
5501 -------------------------
5502 -- Copy_Component_List --
5503 -------------------------
5504
5505 function Copy_Component_List
5506 (R_Typ : Entity_Id;
5507 Loc : Source_Ptr) return List_Id
5508 is
5509 Comp : Node_Id;
5510 Comps : constant List_Id := New_List;
5511
5512 begin
5513 Comp := First_Component (Underlying_Type (R_Typ));
5514 while Present (Comp) loop
5515 if Comes_From_Source (Comp) then
5516 declare
5517 Comp_Decl : constant Node_Id := Declaration_Node (Comp);
5518 begin
5519 Append_To (Comps,
5520 Make_Component_Declaration (Loc,
5521 Defining_Identifier =>
5522 Make_Defining_Identifier (Loc, Chars (Comp)),
5523 Component_Definition =>
5524 New_Copy_Tree
5525 (Component_Definition (Comp_Decl), New_Sloc => Loc)));
5526 end;
5527 end if;
5528
5529 Next_Component (Comp);
5530 end loop;
5531
5532 return Comps;
5533 end Copy_Component_List;
5534
5535 -------------------------
5536 -- Copy_Parameter_List --
5537 -------------------------
5538
5539 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
5540 Loc : constant Source_Ptr := Sloc (Subp_Id);
5541 Plist : List_Id;
5542 Formal : Entity_Id;
5543
5544 begin
5545 if No (First_Formal (Subp_Id)) then
5546 return No_List;
5547 else
5548 Plist := New_List;
5549 Formal := First_Formal (Subp_Id);
5550 while Present (Formal) loop
5551 Append_To (Plist,
5552 Make_Parameter_Specification (Loc,
5553 Defining_Identifier =>
5554 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)),
5555 In_Present => In_Present (Parent (Formal)),
5556 Out_Present => Out_Present (Parent (Formal)),
5557 Parameter_Type =>
5558 New_Occurrence_Of (Etype (Formal), Loc),
5559 Expression =>
5560 New_Copy_Tree (Expression (Parent (Formal)))));
5561
5562 Next_Formal (Formal);
5563 end loop;
5564 end if;
5565
5566 return Plist;
5567 end Copy_Parameter_List;
5568
5569 ----------------------------
5570 -- Copy_SPARK_Mode_Aspect --
5571 ----------------------------
5572
5573 procedure Copy_SPARK_Mode_Aspect (From : Node_Id; To : Node_Id) is
5574 pragma Assert (not Has_Aspects (To));
5575 Asp : Node_Id;
5576
5577 begin
5578 if Has_Aspects (From) then
5579 Asp := Find_Aspect (Defining_Entity (From), Aspect_SPARK_Mode);
5580
5581 if Present (Asp) then
5582 Set_Aspect_Specifications (To, New_List (New_Copy_Tree (Asp)));
5583 Set_Has_Aspects (To, True);
5584 end if;
5585 end if;
5586 end Copy_SPARK_Mode_Aspect;
5587
5588 --------------------------
5589 -- Copy_Subprogram_Spec --
5590 --------------------------
5591
5592 function Copy_Subprogram_Spec (Spec : Node_Id) return Node_Id is
5593 Def_Id : Node_Id;
5594 Formal_Spec : Node_Id;
5595 Result : Node_Id;
5596
5597 begin
5598 -- The structure of the original tree must be replicated without any
5599 -- alterations. Use New_Copy_Tree for this purpose.
5600
5601 Result := New_Copy_Tree (Spec);
5602
5603 -- However, the spec of a null procedure carries the corresponding null
5604 -- statement of the body (created by the parser), and this cannot be
5605 -- shared with the new subprogram spec.
5606
5607 if Nkind (Result) = N_Procedure_Specification then
5608 Set_Null_Statement (Result, Empty);
5609 end if;
5610
5611 -- Create a new entity for the defining unit name
5612
5613 Def_Id := Defining_Unit_Name (Result);
5614 Set_Defining_Unit_Name (Result,
5615 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
5616
5617 -- Create new entities for the formal parameters
5618
5619 if Present (Parameter_Specifications (Result)) then
5620 Formal_Spec := First (Parameter_Specifications (Result));
5621 while Present (Formal_Spec) loop
5622 Def_Id := Defining_Identifier (Formal_Spec);
5623 Set_Defining_Identifier (Formal_Spec,
5624 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
5625
5626 Next (Formal_Spec);
5627 end loop;
5628 end if;
5629
5630 return Result;
5631 end Copy_Subprogram_Spec;
5632
5633 --------------------------------
5634 -- Corresponding_Generic_Type --
5635 --------------------------------
5636
5637 function Corresponding_Generic_Type (T : Entity_Id) return Entity_Id is
5638 Inst : Entity_Id;
5639 Gen : Entity_Id;
5640 Typ : Entity_Id;
5641
5642 begin
5643 if not Is_Generic_Actual_Type (T) then
5644 return Any_Type;
5645
5646 -- If the actual is the actual of an enclosing instance, resolution
5647 -- was correct in the generic.
5648
5649 elsif Nkind (Parent (T)) = N_Subtype_Declaration
5650 and then Is_Entity_Name (Subtype_Indication (Parent (T)))
5651 and then
5652 Is_Generic_Actual_Type (Entity (Subtype_Indication (Parent (T))))
5653 then
5654 return Any_Type;
5655
5656 else
5657 Inst := Scope (T);
5658
5659 if Is_Wrapper_Package (Inst) then
5660 Inst := Related_Instance (Inst);
5661 end if;
5662
5663 Gen :=
5664 Generic_Parent
5665 (Specification (Unit_Declaration_Node (Inst)));
5666
5667 -- Generic actual has the same name as the corresponding formal
5668
5669 Typ := First_Entity (Gen);
5670 while Present (Typ) loop
5671 if Chars (Typ) = Chars (T) then
5672 return Typ;
5673 end if;
5674
5675 Next_Entity (Typ);
5676 end loop;
5677
5678 return Any_Type;
5679 end if;
5680 end Corresponding_Generic_Type;
5681
5682 --------------------
5683 -- Current_Entity --
5684 --------------------
5685
5686 -- The currently visible definition for a given identifier is the
5687 -- one most chained at the start of the visibility chain, i.e. the
5688 -- one that is referenced by the Node_Id value of the name of the
5689 -- given identifier.
5690
5691 function Current_Entity (N : Node_Id) return Entity_Id is
5692 begin
5693 return Get_Name_Entity_Id (Chars (N));
5694 end Current_Entity;
5695
5696 -----------------------------
5697 -- Current_Entity_In_Scope --
5698 -----------------------------
5699
5700 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
5701 E : Entity_Id;
5702 CS : constant Entity_Id := Current_Scope;
5703
5704 Transient_Case : constant Boolean := Scope_Is_Transient;
5705
5706 begin
5707 E := Get_Name_Entity_Id (Chars (N));
5708 while Present (E)
5709 and then Scope (E) /= CS
5710 and then (not Transient_Case or else Scope (E) /= Scope (CS))
5711 loop
5712 E := Homonym (E);
5713 end loop;
5714
5715 return E;
5716 end Current_Entity_In_Scope;
5717
5718 -------------------
5719 -- Current_Scope --
5720 -------------------
5721
5722 function Current_Scope return Entity_Id is
5723 begin
5724 if Scope_Stack.Last = -1 then
5725 return Standard_Standard;
5726 else
5727 declare
5728 C : constant Entity_Id :=
5729 Scope_Stack.Table (Scope_Stack.Last).Entity;
5730 begin
5731 if Present (C) then
5732 return C;
5733 else
5734 return Standard_Standard;
5735 end if;
5736 end;
5737 end if;
5738 end Current_Scope;
5739
5740 ----------------------------
5741 -- Current_Scope_No_Loops --
5742 ----------------------------
5743
5744 function Current_Scope_No_Loops return Entity_Id is
5745 S : Entity_Id;
5746
5747 begin
5748 -- Examine the scope stack starting from the current scope and skip any
5749 -- internally generated loops.
5750
5751 S := Current_Scope;
5752 while Present (S) and then S /= Standard_Standard loop
5753 if Ekind (S) = E_Loop and then not Comes_From_Source (S) then
5754 S := Scope (S);
5755 else
5756 exit;
5757 end if;
5758 end loop;
5759
5760 return S;
5761 end Current_Scope_No_Loops;
5762
5763 ------------------------
5764 -- Current_Subprogram --
5765 ------------------------
5766
5767 function Current_Subprogram return Entity_Id is
5768 Scop : constant Entity_Id := Current_Scope;
5769 begin
5770 if Is_Subprogram_Or_Generic_Subprogram (Scop) then
5771 return Scop;
5772 else
5773 return Enclosing_Subprogram (Scop);
5774 end if;
5775 end Current_Subprogram;
5776
5777 ----------------------------------
5778 -- Deepest_Type_Access_Level --
5779 ----------------------------------
5780
5781 function Deepest_Type_Access_Level (Typ : Entity_Id) return Uint is
5782 begin
5783 if Ekind (Typ) = E_Anonymous_Access_Type
5784 and then not Is_Local_Anonymous_Access (Typ)
5785 and then Nkind (Associated_Node_For_Itype (Typ)) = N_Object_Declaration
5786 then
5787 -- Typ is the type of an Ada 2012 stand-alone object of an anonymous
5788 -- access type.
5789
5790 return
5791 Scope_Depth (Enclosing_Dynamic_Scope
5792 (Defining_Identifier
5793 (Associated_Node_For_Itype (Typ))));
5794
5795 -- For generic formal type, return Int'Last (infinite).
5796 -- See comment preceding Is_Generic_Type call in Type_Access_Level.
5797
5798 elsif Is_Generic_Type (Root_Type (Typ)) then
5799 return UI_From_Int (Int'Last);
5800
5801 else
5802 return Type_Access_Level (Typ);
5803 end if;
5804 end Deepest_Type_Access_Level;
5805
5806 ---------------------
5807 -- Defining_Entity --
5808 ---------------------
5809
5810 function Defining_Entity
5811 (N : Node_Id;
5812 Empty_On_Errors : Boolean := False;
5813 Concurrent_Subunit : Boolean := False) return Entity_Id
5814 is
5815 begin
5816 case Nkind (N) is
5817 when N_Abstract_Subprogram_Declaration
5818 | N_Expression_Function
5819 | N_Formal_Subprogram_Declaration
5820 | N_Generic_Package_Declaration
5821 | N_Generic_Subprogram_Declaration
5822 | N_Package_Declaration
5823 | N_Subprogram_Body
5824 | N_Subprogram_Body_Stub
5825 | N_Subprogram_Declaration
5826 | N_Subprogram_Renaming_Declaration
5827 =>
5828 return Defining_Entity (Specification (N));
5829
5830 when N_Component_Declaration
5831 | N_Defining_Program_Unit_Name
5832 | N_Discriminant_Specification
5833 | N_Entry_Body
5834 | N_Entry_Declaration
5835 | N_Entry_Index_Specification
5836 | N_Exception_Declaration
5837 | N_Exception_Renaming_Declaration
5838 | N_Formal_Object_Declaration
5839 | N_Formal_Package_Declaration
5840 | N_Formal_Type_Declaration
5841 | N_Full_Type_Declaration
5842 | N_Implicit_Label_Declaration
5843 | N_Incomplete_Type_Declaration
5844 | N_Iterator_Specification
5845 | N_Loop_Parameter_Specification
5846 | N_Number_Declaration
5847 | N_Object_Declaration
5848 | N_Object_Renaming_Declaration
5849 | N_Package_Body_Stub
5850 | N_Parameter_Specification
5851 | N_Private_Extension_Declaration
5852 | N_Private_Type_Declaration
5853 | N_Protected_Body
5854 | N_Protected_Body_Stub
5855 | N_Protected_Type_Declaration
5856 | N_Single_Protected_Declaration
5857 | N_Single_Task_Declaration
5858 | N_Subtype_Declaration
5859 | N_Task_Body
5860 | N_Task_Body_Stub
5861 | N_Task_Type_Declaration
5862 =>
5863 return Defining_Identifier (N);
5864
5865 when N_Subunit =>
5866 declare
5867 Bod : constant Node_Id := Proper_Body (N);
5868 Orig_Bod : constant Node_Id := Original_Node (Bod);
5869
5870 begin
5871 -- Retrieve the entity of the original protected or task body
5872 -- if requested by the caller.
5873
5874 if Concurrent_Subunit
5875 and then Nkind (Bod) = N_Null_Statement
5876 and then Nkind_In (Orig_Bod, N_Protected_Body, N_Task_Body)
5877 then
5878 return Defining_Entity (Orig_Bod);
5879 else
5880 return Defining_Entity (Bod);
5881 end if;
5882 end;
5883
5884 when N_Function_Instantiation
5885 | N_Function_Specification
5886 | N_Generic_Function_Renaming_Declaration
5887 | N_Generic_Package_Renaming_Declaration
5888 | N_Generic_Procedure_Renaming_Declaration
5889 | N_Package_Body
5890 | N_Package_Instantiation
5891 | N_Package_Renaming_Declaration
5892 | N_Package_Specification
5893 | N_Procedure_Instantiation
5894 | N_Procedure_Specification
5895 =>
5896 declare
5897 Nam : constant Node_Id := Defining_Unit_Name (N);
5898 Err : Entity_Id := Empty;
5899
5900 begin
5901 if Nkind (Nam) in N_Entity then
5902 return Nam;
5903
5904 -- For Error, make up a name and attach to declaration so we
5905 -- can continue semantic analysis.
5906
5907 elsif Nam = Error then
5908 if Empty_On_Errors then
5909 return Empty;
5910 else
5911 Err := Make_Temporary (Sloc (N), 'T');
5912 Set_Defining_Unit_Name (N, Err);
5913
5914 return Err;
5915 end if;
5916
5917 -- If not an entity, get defining identifier
5918
5919 else
5920 return Defining_Identifier (Nam);
5921 end if;
5922 end;
5923
5924 when N_Block_Statement
5925 | N_Loop_Statement
5926 =>
5927 return Entity (Identifier (N));
5928
5929 when others =>
5930 if Empty_On_Errors then
5931 return Empty;
5932 else
5933 raise Program_Error;
5934 end if;
5935 end case;
5936 end Defining_Entity;
5937
5938 --------------------------
5939 -- Denotes_Discriminant --
5940 --------------------------
5941
5942 function Denotes_Discriminant
5943 (N : Node_Id;
5944 Check_Concurrent : Boolean := False) return Boolean
5945 is
5946 E : Entity_Id;
5947
5948 begin
5949 if not Is_Entity_Name (N) or else No (Entity (N)) then
5950 return False;
5951 else
5952 E := Entity (N);
5953 end if;
5954
5955 -- If we are checking for a protected type, the discriminant may have
5956 -- been rewritten as the corresponding discriminal of the original type
5957 -- or of the corresponding concurrent record, depending on whether we
5958 -- are in the spec or body of the protected type.
5959
5960 return Ekind (E) = E_Discriminant
5961 or else
5962 (Check_Concurrent
5963 and then Ekind (E) = E_In_Parameter
5964 and then Present (Discriminal_Link (E))
5965 and then
5966 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
5967 or else
5968 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
5969 end Denotes_Discriminant;
5970
5971 -------------------------
5972 -- Denotes_Same_Object --
5973 -------------------------
5974
5975 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
5976 Obj1 : Node_Id := A1;
5977 Obj2 : Node_Id := A2;
5978
5979 function Has_Prefix (N : Node_Id) return Boolean;
5980 -- Return True if N has attribute Prefix
5981
5982 function Is_Renaming (N : Node_Id) return Boolean;
5983 -- Return true if N names a renaming entity
5984
5985 function Is_Valid_Renaming (N : Node_Id) return Boolean;
5986 -- For renamings, return False if the prefix of any dereference within
5987 -- the renamed object_name is a variable, or any expression within the
5988 -- renamed object_name contains references to variables or calls on
5989 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
5990
5991 ----------------
5992 -- Has_Prefix --
5993 ----------------
5994
5995 function Has_Prefix (N : Node_Id) return Boolean is
5996 begin
5997 return
5998 Nkind_In (N,
5999 N_Attribute_Reference,
6000 N_Expanded_Name,
6001 N_Explicit_Dereference,
6002 N_Indexed_Component,
6003 N_Reference,
6004 N_Selected_Component,
6005 N_Slice);
6006 end Has_Prefix;
6007
6008 -----------------
6009 -- Is_Renaming --
6010 -----------------
6011
6012 function Is_Renaming (N : Node_Id) return Boolean is
6013 begin
6014 return Is_Entity_Name (N)
6015 and then Present (Renamed_Entity (Entity (N)));
6016 end Is_Renaming;
6017
6018 -----------------------
6019 -- Is_Valid_Renaming --
6020 -----------------------
6021
6022 function Is_Valid_Renaming (N : Node_Id) return Boolean is
6023
6024 function Check_Renaming (N : Node_Id) return Boolean;
6025 -- Recursive function used to traverse all the prefixes of N
6026
6027 function Check_Renaming (N : Node_Id) return Boolean is
6028 begin
6029 if Is_Renaming (N)
6030 and then not Check_Renaming (Renamed_Entity (Entity (N)))
6031 then
6032 return False;
6033 end if;
6034
6035 if Nkind (N) = N_Indexed_Component then
6036 declare
6037 Indx : Node_Id;
6038
6039 begin
6040 Indx := First (Expressions (N));
6041 while Present (Indx) loop
6042 if not Is_OK_Static_Expression (Indx) then
6043 return False;
6044 end if;
6045
6046 Next_Index (Indx);
6047 end loop;
6048 end;
6049 end if;
6050
6051 if Has_Prefix (N) then
6052 declare
6053 P : constant Node_Id := Prefix (N);
6054
6055 begin
6056 if Nkind (N) = N_Explicit_Dereference
6057 and then Is_Variable (P)
6058 then
6059 return False;
6060
6061 elsif Is_Entity_Name (P)
6062 and then Ekind (Entity (P)) = E_Function
6063 then
6064 return False;
6065
6066 elsif Nkind (P) = N_Function_Call then
6067 return False;
6068 end if;
6069
6070 -- Recursion to continue traversing the prefix of the
6071 -- renaming expression
6072
6073 return Check_Renaming (P);
6074 end;
6075 end if;
6076
6077 return True;
6078 end Check_Renaming;
6079
6080 -- Start of processing for Is_Valid_Renaming
6081
6082 begin
6083 return Check_Renaming (N);
6084 end Is_Valid_Renaming;
6085
6086 -- Start of processing for Denotes_Same_Object
6087
6088 begin
6089 -- Both names statically denote the same stand-alone object or parameter
6090 -- (RM 6.4.1(6.5/3))
6091
6092 if Is_Entity_Name (Obj1)
6093 and then Is_Entity_Name (Obj2)
6094 and then Entity (Obj1) = Entity (Obj2)
6095 then
6096 return True;
6097 end if;
6098
6099 -- For renamings, the prefix of any dereference within the renamed
6100 -- object_name is not a variable, and any expression within the
6101 -- renamed object_name contains no references to variables nor
6102 -- calls on nonstatic functions (RM 6.4.1(6.10/3)).
6103
6104 if Is_Renaming (Obj1) then
6105 if Is_Valid_Renaming (Obj1) then
6106 Obj1 := Renamed_Entity (Entity (Obj1));
6107 else
6108 return False;
6109 end if;
6110 end if;
6111
6112 if Is_Renaming (Obj2) then
6113 if Is_Valid_Renaming (Obj2) then
6114 Obj2 := Renamed_Entity (Entity (Obj2));
6115 else
6116 return False;
6117 end if;
6118 end if;
6119
6120 -- No match if not same node kind (such cases are handled by
6121 -- Denotes_Same_Prefix)
6122
6123 if Nkind (Obj1) /= Nkind (Obj2) then
6124 return False;
6125
6126 -- After handling valid renamings, one of the two names statically
6127 -- denoted a renaming declaration whose renamed object_name is known
6128 -- to denote the same object as the other (RM 6.4.1(6.10/3))
6129
6130 elsif Is_Entity_Name (Obj1) then
6131 if Is_Entity_Name (Obj2) then
6132 return Entity (Obj1) = Entity (Obj2);
6133 else
6134 return False;
6135 end if;
6136
6137 -- Both names are selected_components, their prefixes are known to
6138 -- denote the same object, and their selector_names denote the same
6139 -- component (RM 6.4.1(6.6/3)).
6140
6141 elsif Nkind (Obj1) = N_Selected_Component then
6142 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
6143 and then
6144 Entity (Selector_Name (Obj1)) = Entity (Selector_Name (Obj2));
6145
6146 -- Both names are dereferences and the dereferenced names are known to
6147 -- denote the same object (RM 6.4.1(6.7/3))
6148
6149 elsif Nkind (Obj1) = N_Explicit_Dereference then
6150 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2));
6151
6152 -- Both names are indexed_components, their prefixes are known to denote
6153 -- the same object, and each of the pairs of corresponding index values
6154 -- are either both static expressions with the same static value or both
6155 -- names that are known to denote the same object (RM 6.4.1(6.8/3))
6156
6157 elsif Nkind (Obj1) = N_Indexed_Component then
6158 if not Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2)) then
6159 return False;
6160 else
6161 declare
6162 Indx1 : Node_Id;
6163 Indx2 : Node_Id;
6164
6165 begin
6166 Indx1 := First (Expressions (Obj1));
6167 Indx2 := First (Expressions (Obj2));
6168 while Present (Indx1) loop
6169
6170 -- Indexes must denote the same static value or same object
6171
6172 if Is_OK_Static_Expression (Indx1) then
6173 if not Is_OK_Static_Expression (Indx2) then
6174 return False;
6175
6176 elsif Expr_Value (Indx1) /= Expr_Value (Indx2) then
6177 return False;
6178 end if;
6179
6180 elsif not Denotes_Same_Object (Indx1, Indx2) then
6181 return False;
6182 end if;
6183
6184 Next (Indx1);
6185 Next (Indx2);
6186 end loop;
6187
6188 return True;
6189 end;
6190 end if;
6191
6192 -- Both names are slices, their prefixes are known to denote the same
6193 -- object, and the two slices have statically matching index constraints
6194 -- (RM 6.4.1(6.9/3))
6195
6196 elsif Nkind (Obj1) = N_Slice
6197 and then Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
6198 then
6199 declare
6200 Lo1, Lo2, Hi1, Hi2 : Node_Id;
6201
6202 begin
6203 Get_Index_Bounds (Etype (Obj1), Lo1, Hi1);
6204 Get_Index_Bounds (Etype (Obj2), Lo2, Hi2);
6205
6206 -- Check whether bounds are statically identical. There is no
6207 -- attempt to detect partial overlap of slices.
6208
6209 return Denotes_Same_Object (Lo1, Lo2)
6210 and then
6211 Denotes_Same_Object (Hi1, Hi2);
6212 end;
6213
6214 -- In the recursion, literals appear as indexes
6215
6216 elsif Nkind (Obj1) = N_Integer_Literal
6217 and then
6218 Nkind (Obj2) = N_Integer_Literal
6219 then
6220 return Intval (Obj1) = Intval (Obj2);
6221
6222 else
6223 return False;
6224 end if;
6225 end Denotes_Same_Object;
6226
6227 -------------------------
6228 -- Denotes_Same_Prefix --
6229 -------------------------
6230
6231 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
6232 begin
6233 if Is_Entity_Name (A1) then
6234 if Nkind_In (A2, N_Selected_Component, N_Indexed_Component)
6235 and then not Is_Access_Type (Etype (A1))
6236 then
6237 return Denotes_Same_Object (A1, Prefix (A2))
6238 or else Denotes_Same_Prefix (A1, Prefix (A2));
6239 else
6240 return False;
6241 end if;
6242
6243 elsif Is_Entity_Name (A2) then
6244 return Denotes_Same_Prefix (A1 => A2, A2 => A1);
6245
6246 elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
6247 and then
6248 Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
6249 then
6250 declare
6251 Root1, Root2 : Node_Id;
6252 Depth1, Depth2 : Nat := 0;
6253
6254 begin
6255 Root1 := Prefix (A1);
6256 while not Is_Entity_Name (Root1) loop
6257 if not Nkind_In
6258 (Root1, N_Selected_Component, N_Indexed_Component)
6259 then
6260 return False;
6261 else
6262 Root1 := Prefix (Root1);
6263 end if;
6264
6265 Depth1 := Depth1 + 1;
6266 end loop;
6267
6268 Root2 := Prefix (A2);
6269 while not Is_Entity_Name (Root2) loop
6270 if not Nkind_In (Root2, N_Selected_Component,
6271 N_Indexed_Component)
6272 then
6273 return False;
6274 else
6275 Root2 := Prefix (Root2);
6276 end if;
6277
6278 Depth2 := Depth2 + 1;
6279 end loop;
6280
6281 -- If both have the same depth and they do not denote the same
6282 -- object, they are disjoint and no warning is needed.
6283
6284 if Depth1 = Depth2 then
6285 return False;
6286
6287 elsif Depth1 > Depth2 then
6288 Root1 := Prefix (A1);
6289 for J in 1 .. Depth1 - Depth2 - 1 loop
6290 Root1 := Prefix (Root1);
6291 end loop;
6292
6293 return Denotes_Same_Object (Root1, A2);
6294
6295 else
6296 Root2 := Prefix (A2);
6297 for J in 1 .. Depth2 - Depth1 - 1 loop
6298 Root2 := Prefix (Root2);
6299 end loop;
6300
6301 return Denotes_Same_Object (A1, Root2);
6302 end if;
6303 end;
6304
6305 else
6306 return False;
6307 end if;
6308 end Denotes_Same_Prefix;
6309
6310 ----------------------
6311 -- Denotes_Variable --
6312 ----------------------
6313
6314 function Denotes_Variable (N : Node_Id) return Boolean is
6315 begin
6316 return Is_Variable (N) and then Paren_Count (N) = 0;
6317 end Denotes_Variable;
6318
6319 -----------------------------
6320 -- Depends_On_Discriminant --
6321 -----------------------------
6322
6323 function Depends_On_Discriminant (N : Node_Id) return Boolean is
6324 L : Node_Id;
6325 H : Node_Id;
6326
6327 begin
6328 Get_Index_Bounds (N, L, H);
6329 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
6330 end Depends_On_Discriminant;
6331
6332 -------------------------
6333 -- Designate_Same_Unit --
6334 -------------------------
6335
6336 function Designate_Same_Unit
6337 (Name1 : Node_Id;
6338 Name2 : Node_Id) return Boolean
6339 is
6340 K1 : constant Node_Kind := Nkind (Name1);
6341 K2 : constant Node_Kind := Nkind (Name2);
6342
6343 function Prefix_Node (N : Node_Id) return Node_Id;
6344 -- Returns the parent unit name node of a defining program unit name
6345 -- or the prefix if N is a selected component or an expanded name.
6346
6347 function Select_Node (N : Node_Id) return Node_Id;
6348 -- Returns the defining identifier node of a defining program unit
6349 -- name or the selector node if N is a selected component or an
6350 -- expanded name.
6351
6352 -----------------
6353 -- Prefix_Node --
6354 -----------------
6355
6356 function Prefix_Node (N : Node_Id) return Node_Id is
6357 begin
6358 if Nkind (N) = N_Defining_Program_Unit_Name then
6359 return Name (N);
6360 else
6361 return Prefix (N);
6362 end if;
6363 end Prefix_Node;
6364
6365 -----------------
6366 -- Select_Node --
6367 -----------------
6368
6369 function Select_Node (N : Node_Id) return Node_Id is
6370 begin
6371 if Nkind (N) = N_Defining_Program_Unit_Name then
6372 return Defining_Identifier (N);
6373 else
6374 return Selector_Name (N);
6375 end if;
6376 end Select_Node;
6377
6378 -- Start of processing for Designate_Same_Unit
6379
6380 begin
6381 if Nkind_In (K1, N_Identifier, N_Defining_Identifier)
6382 and then
6383 Nkind_In (K2, N_Identifier, N_Defining_Identifier)
6384 then
6385 return Chars (Name1) = Chars (Name2);
6386
6387 elsif Nkind_In (K1, N_Expanded_Name,
6388 N_Selected_Component,
6389 N_Defining_Program_Unit_Name)
6390 and then
6391 Nkind_In (K2, N_Expanded_Name,
6392 N_Selected_Component,
6393 N_Defining_Program_Unit_Name)
6394 then
6395 return
6396 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
6397 and then
6398 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
6399
6400 else
6401 return False;
6402 end if;
6403 end Designate_Same_Unit;
6404
6405 ---------------------------------------------
6406 -- Diagnose_Iterated_Component_Association --
6407 ---------------------------------------------
6408
6409 procedure Diagnose_Iterated_Component_Association (N : Node_Id) is
6410 Def_Id : constant Entity_Id := Defining_Identifier (N);
6411 Aggr : Node_Id;
6412
6413 begin
6414 -- Determine whether the iterated component association appears within
6415 -- an aggregate. If this is the case, raise Program_Error because the
6416 -- iterated component association cannot be left in the tree as is and
6417 -- must always be processed by the related aggregate.
6418
6419 Aggr := N;
6420 while Present (Aggr) loop
6421 if Nkind (Aggr) = N_Aggregate then
6422 raise Program_Error;
6423
6424 -- Prevent the search from going too far
6425
6426 elsif Is_Body_Or_Package_Declaration (Aggr) then
6427 exit;
6428 end if;
6429
6430 Aggr := Parent (Aggr);
6431 end loop;
6432
6433 -- At this point it is known that the iterated component association is
6434 -- not within an aggregate. This is really a quantified expression with
6435 -- a missing "all" or "some" quantifier.
6436
6437 Error_Msg_N ("missing quantifier", Def_Id);
6438
6439 -- Rewrite the iterated component association as True to prevent any
6440 -- cascaded errors.
6441
6442 Rewrite (N, New_Occurrence_Of (Standard_True, Sloc (N)));
6443 Analyze (N);
6444 end Diagnose_Iterated_Component_Association;
6445
6446 ---------------------------------
6447 -- Dynamic_Accessibility_Level --
6448 ---------------------------------
6449
6450 function Dynamic_Accessibility_Level (Expr : Node_Id) return Node_Id is
6451 Loc : constant Source_Ptr := Sloc (Expr);
6452
6453 function Make_Level_Literal (Level : Uint) return Node_Id;
6454 -- Construct an integer literal representing an accessibility level
6455 -- with its type set to Natural.
6456
6457 ------------------------
6458 -- Make_Level_Literal --
6459 ------------------------
6460
6461 function Make_Level_Literal (Level : Uint) return Node_Id is
6462 Result : constant Node_Id := Make_Integer_Literal (Loc, Level);
6463
6464 begin
6465 Set_Etype (Result, Standard_Natural);
6466 return Result;
6467 end Make_Level_Literal;
6468
6469 -- Local variables
6470
6471 E : Entity_Id;
6472
6473 -- Start of processing for Dynamic_Accessibility_Level
6474
6475 begin
6476 if Is_Entity_Name (Expr) then
6477 E := Entity (Expr);
6478
6479 if Present (Renamed_Object (E)) then
6480 return Dynamic_Accessibility_Level (Renamed_Object (E));
6481 end if;
6482
6483 if Is_Formal (E) or else Ekind_In (E, E_Variable, E_Constant) then
6484 if Present (Extra_Accessibility (E)) then
6485 return New_Occurrence_Of (Extra_Accessibility (E), Loc);
6486 end if;
6487 end if;
6488 end if;
6489
6490 -- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
6491
6492 case Nkind (Expr) is
6493
6494 -- For access discriminant, the level of the enclosing object
6495
6496 when N_Selected_Component =>
6497 if Ekind (Entity (Selector_Name (Expr))) = E_Discriminant
6498 and then Ekind (Etype (Entity (Selector_Name (Expr)))) =
6499 E_Anonymous_Access_Type
6500 then
6501 return Make_Level_Literal (Object_Access_Level (Expr));
6502 end if;
6503
6504 when N_Attribute_Reference =>
6505 case Get_Attribute_Id (Attribute_Name (Expr)) is
6506
6507 -- For X'Access, the level of the prefix X
6508
6509 when Attribute_Access =>
6510 return Make_Level_Literal
6511 (Object_Access_Level (Prefix (Expr)));
6512
6513 -- Treat the unchecked attributes as library-level
6514
6515 when Attribute_Unchecked_Access
6516 | Attribute_Unrestricted_Access
6517 =>
6518 return Make_Level_Literal (Scope_Depth (Standard_Standard));
6519
6520 -- No other access-valued attributes
6521
6522 when others =>
6523 raise Program_Error;
6524 end case;
6525
6526 when N_Allocator =>
6527
6528 -- Unimplemented: depends on context. As an actual parameter where
6529 -- formal type is anonymous, use
6530 -- Scope_Depth (Current_Scope) + 1.
6531 -- For other cases, see 3.10.2(14/3) and following. ???
6532
6533 null;
6534
6535 when N_Type_Conversion =>
6536 if not Is_Local_Anonymous_Access (Etype (Expr)) then
6537
6538 -- Handle type conversions introduced for a rename of an
6539 -- Ada 2012 stand-alone object of an anonymous access type.
6540
6541 return Dynamic_Accessibility_Level (Expression (Expr));
6542 end if;
6543
6544 when others =>
6545 null;
6546 end case;
6547
6548 return Make_Level_Literal (Type_Access_Level (Etype (Expr)));
6549 end Dynamic_Accessibility_Level;
6550
6551 ------------------------
6552 -- Discriminated_Size --
6553 ------------------------
6554
6555 function Discriminated_Size (Comp : Entity_Id) return Boolean is
6556 function Non_Static_Bound (Bound : Node_Id) return Boolean;
6557 -- Check whether the bound of an index is non-static and does denote
6558 -- a discriminant, in which case any object of the type (protected or
6559 -- otherwise) will have a non-static size.
6560
6561 ----------------------
6562 -- Non_Static_Bound --
6563 ----------------------
6564
6565 function Non_Static_Bound (Bound : Node_Id) return Boolean is
6566 begin
6567 if Is_OK_Static_Expression (Bound) then
6568 return False;
6569
6570 -- If the bound is given by a discriminant it is non-static
6571 -- (A static constraint replaces the reference with the value).
6572 -- In an protected object the discriminant has been replaced by
6573 -- the corresponding discriminal within the protected operation.
6574
6575 elsif Is_Entity_Name (Bound)
6576 and then
6577 (Ekind (Entity (Bound)) = E_Discriminant
6578 or else Present (Discriminal_Link (Entity (Bound))))
6579 then
6580 return False;
6581
6582 else
6583 return True;
6584 end if;
6585 end Non_Static_Bound;
6586
6587 -- Local variables
6588
6589 Typ : constant Entity_Id := Etype (Comp);
6590 Index : Node_Id;
6591
6592 -- Start of processing for Discriminated_Size
6593
6594 begin
6595 if not Is_Array_Type (Typ) then
6596 return False;
6597 end if;
6598
6599 if Ekind (Typ) = E_Array_Subtype then
6600 Index := First_Index (Typ);
6601 while Present (Index) loop
6602 if Non_Static_Bound (Low_Bound (Index))
6603 or else Non_Static_Bound (High_Bound (Index))
6604 then
6605 return False;
6606 end if;
6607
6608 Next_Index (Index);
6609 end loop;
6610
6611 return True;
6612 end if;
6613
6614 return False;
6615 end Discriminated_Size;
6616
6617 -----------------------------------
6618 -- Effective_Extra_Accessibility --
6619 -----------------------------------
6620
6621 function Effective_Extra_Accessibility (Id : Entity_Id) return Entity_Id is
6622 begin
6623 if Present (Renamed_Object (Id))
6624 and then Is_Entity_Name (Renamed_Object (Id))
6625 then
6626 return Effective_Extra_Accessibility (Entity (Renamed_Object (Id)));
6627 else
6628 return Extra_Accessibility (Id);
6629 end if;
6630 end Effective_Extra_Accessibility;
6631
6632 -----------------------------
6633 -- Effective_Reads_Enabled --
6634 -----------------------------
6635
6636 function Effective_Reads_Enabled (Id : Entity_Id) return Boolean is
6637 begin
6638 return Has_Enabled_Property (Id, Name_Effective_Reads);
6639 end Effective_Reads_Enabled;
6640
6641 ------------------------------
6642 -- Effective_Writes_Enabled --
6643 ------------------------------
6644
6645 function Effective_Writes_Enabled (Id : Entity_Id) return Boolean is
6646 begin
6647 return Has_Enabled_Property (Id, Name_Effective_Writes);
6648 end Effective_Writes_Enabled;
6649
6650 ------------------------------
6651 -- Enclosing_Comp_Unit_Node --
6652 ------------------------------
6653
6654 function Enclosing_Comp_Unit_Node (N : Node_Id) return Node_Id is
6655 Current_Node : Node_Id;
6656
6657 begin
6658 Current_Node := N;
6659 while Present (Current_Node)
6660 and then Nkind (Current_Node) /= N_Compilation_Unit
6661 loop
6662 Current_Node := Parent (Current_Node);
6663 end loop;
6664
6665 if Nkind (Current_Node) /= N_Compilation_Unit then
6666 return Empty;
6667 else
6668 return Current_Node;
6669 end if;
6670 end Enclosing_Comp_Unit_Node;
6671
6672 --------------------------
6673 -- Enclosing_CPP_Parent --
6674 --------------------------
6675
6676 function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is
6677 Parent_Typ : Entity_Id := Typ;
6678
6679 begin
6680 while not Is_CPP_Class (Parent_Typ)
6681 and then Etype (Parent_Typ) /= Parent_Typ
6682 loop
6683 Parent_Typ := Etype (Parent_Typ);
6684
6685 if Is_Private_Type (Parent_Typ) then
6686 Parent_Typ := Full_View (Base_Type (Parent_Typ));
6687 end if;
6688 end loop;
6689
6690 pragma Assert (Is_CPP_Class (Parent_Typ));
6691 return Parent_Typ;
6692 end Enclosing_CPP_Parent;
6693
6694 ---------------------------
6695 -- Enclosing_Declaration --
6696 ---------------------------
6697
6698 function Enclosing_Declaration (N : Node_Id) return Node_Id is
6699 Decl : Node_Id := N;
6700
6701 begin
6702 while Present (Decl)
6703 and then not (Nkind (Decl) in N_Declaration
6704 or else
6705 Nkind (Decl) in N_Later_Decl_Item)
6706 loop
6707 Decl := Parent (Decl);
6708 end loop;
6709
6710 return Decl;
6711 end Enclosing_Declaration;
6712
6713 ----------------------------
6714 -- Enclosing_Generic_Body --
6715 ----------------------------
6716
6717 function Enclosing_Generic_Body
6718 (N : Node_Id) return Node_Id
6719 is
6720 P : Node_Id;
6721 Decl : Node_Id;
6722 Spec : Node_Id;
6723
6724 begin
6725 P := Parent (N);
6726 while Present (P) loop
6727 if Nkind (P) = N_Package_Body
6728 or else Nkind (P) = N_Subprogram_Body
6729 then
6730 Spec := Corresponding_Spec (P);
6731
6732 if Present (Spec) then
6733 Decl := Unit_Declaration_Node (Spec);
6734
6735 if Nkind (Decl) = N_Generic_Package_Declaration
6736 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
6737 then
6738 return P;
6739 end if;
6740 end if;
6741 end if;
6742
6743 P := Parent (P);
6744 end loop;
6745
6746 return Empty;
6747 end Enclosing_Generic_Body;
6748
6749 ----------------------------
6750 -- Enclosing_Generic_Unit --
6751 ----------------------------
6752
6753 function Enclosing_Generic_Unit
6754 (N : Node_Id) return Node_Id
6755 is
6756 P : Node_Id;
6757 Decl : Node_Id;
6758 Spec : Node_Id;
6759
6760 begin
6761 P := Parent (N);
6762 while Present (P) loop
6763 if Nkind (P) = N_Generic_Package_Declaration
6764 or else Nkind (P) = N_Generic_Subprogram_Declaration
6765 then
6766 return P;
6767
6768 elsif Nkind (P) = N_Package_Body
6769 or else Nkind (P) = N_Subprogram_Body
6770 then
6771 Spec := Corresponding_Spec (P);
6772
6773 if Present (Spec) then
6774 Decl := Unit_Declaration_Node (Spec);
6775
6776 if Nkind (Decl) = N_Generic_Package_Declaration
6777 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
6778 then
6779 return Decl;
6780 end if;
6781 end if;
6782 end if;
6783
6784 P := Parent (P);
6785 end loop;
6786
6787 return Empty;
6788 end Enclosing_Generic_Unit;
6789
6790 -------------------------------
6791 -- Enclosing_Lib_Unit_Entity --
6792 -------------------------------
6793
6794 function Enclosing_Lib_Unit_Entity
6795 (E : Entity_Id := Current_Scope) return Entity_Id
6796 is
6797 Unit_Entity : Entity_Id;
6798
6799 begin
6800 -- Look for enclosing library unit entity by following scope links.
6801 -- Equivalent to, but faster than indexing through the scope stack.
6802
6803 Unit_Entity := E;
6804 while (Present (Scope (Unit_Entity))
6805 and then Scope (Unit_Entity) /= Standard_Standard)
6806 and not Is_Child_Unit (Unit_Entity)
6807 loop
6808 Unit_Entity := Scope (Unit_Entity);
6809 end loop;
6810
6811 return Unit_Entity;
6812 end Enclosing_Lib_Unit_Entity;
6813
6814 -----------------------------
6815 -- Enclosing_Lib_Unit_Node --
6816 -----------------------------
6817
6818 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
6819 Encl_Unit : Node_Id;
6820
6821 begin
6822 Encl_Unit := Enclosing_Comp_Unit_Node (N);
6823 while Present (Encl_Unit)
6824 and then Nkind (Unit (Encl_Unit)) = N_Subunit
6825 loop
6826 Encl_Unit := Library_Unit (Encl_Unit);
6827 end loop;
6828
6829 pragma Assert (Nkind (Encl_Unit) = N_Compilation_Unit);
6830 return Encl_Unit;
6831 end Enclosing_Lib_Unit_Node;
6832
6833 -----------------------
6834 -- Enclosing_Package --
6835 -----------------------
6836
6837 function Enclosing_Package (E : Entity_Id) return Entity_Id is
6838 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
6839
6840 begin
6841 if Dynamic_Scope = Standard_Standard then
6842 return Standard_Standard;
6843
6844 elsif Dynamic_Scope = Empty then
6845 return Empty;
6846
6847 elsif Ekind_In (Dynamic_Scope, E_Package, E_Package_Body,
6848 E_Generic_Package)
6849 then
6850 return Dynamic_Scope;
6851
6852 else
6853 return Enclosing_Package (Dynamic_Scope);
6854 end if;
6855 end Enclosing_Package;
6856
6857 -------------------------------------
6858 -- Enclosing_Package_Or_Subprogram --
6859 -------------------------------------
6860
6861 function Enclosing_Package_Or_Subprogram (E : Entity_Id) return Entity_Id is
6862 S : Entity_Id;
6863
6864 begin
6865 S := Scope (E);
6866 while Present (S) loop
6867 if Is_Package_Or_Generic_Package (S)
6868 or else Ekind (S) = E_Package_Body
6869 then
6870 return S;
6871
6872 elsif Is_Subprogram_Or_Generic_Subprogram (S)
6873 or else Ekind (S) = E_Subprogram_Body
6874 then
6875 return S;
6876
6877 else
6878 S := Scope (S);
6879 end if;
6880 end loop;
6881
6882 return Empty;
6883 end Enclosing_Package_Or_Subprogram;
6884
6885 --------------------------
6886 -- Enclosing_Subprogram --
6887 --------------------------
6888
6889 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
6890 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
6891
6892 begin
6893 if Dynamic_Scope = Standard_Standard then
6894 return Empty;
6895
6896 elsif Dynamic_Scope = Empty then
6897 return Empty;
6898
6899 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
6900 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
6901
6902 elsif Ekind (Dynamic_Scope) = E_Block
6903 or else Ekind (Dynamic_Scope) = E_Return_Statement
6904 then
6905 return Enclosing_Subprogram (Dynamic_Scope);
6906
6907 elsif Ekind (Dynamic_Scope) = E_Task_Type then
6908 return Get_Task_Body_Procedure (Dynamic_Scope);
6909
6910 elsif Ekind (Dynamic_Scope) = E_Limited_Private_Type
6911 and then Present (Full_View (Dynamic_Scope))
6912 and then Ekind (Full_View (Dynamic_Scope)) = E_Task_Type
6913 then
6914 return Get_Task_Body_Procedure (Full_View (Dynamic_Scope));
6915
6916 -- No body is generated if the protected operation is eliminated
6917
6918 elsif Convention (Dynamic_Scope) = Convention_Protected
6919 and then not Is_Eliminated (Dynamic_Scope)
6920 and then Present (Protected_Body_Subprogram (Dynamic_Scope))
6921 then
6922 return Protected_Body_Subprogram (Dynamic_Scope);
6923
6924 else
6925 return Dynamic_Scope;
6926 end if;
6927 end Enclosing_Subprogram;
6928
6929 --------------------------
6930 -- End_Keyword_Location --
6931 --------------------------
6932
6933 function End_Keyword_Location (N : Node_Id) return Source_Ptr is
6934 function End_Label_Loc (Nod : Node_Id) return Source_Ptr;
6935 -- Return the source location of Nod's end label according to the
6936 -- following precedence rules:
6937 --
6938 -- 1) If the end label exists, return its location
6939 -- 2) If Nod exists, return its location
6940 -- 3) Return the location of N
6941
6942 -------------------
6943 -- End_Label_Loc --
6944 -------------------
6945
6946 function End_Label_Loc (Nod : Node_Id) return Source_Ptr is
6947 Label : Node_Id;
6948
6949 begin
6950 if Present (Nod) then
6951 Label := End_Label (Nod);
6952
6953 if Present (Label) then
6954 return Sloc (Label);
6955 else
6956 return Sloc (Nod);
6957 end if;
6958
6959 else
6960 return Sloc (N);
6961 end if;
6962 end End_Label_Loc;
6963
6964 -- Local variables
6965
6966 Owner : Node_Id;
6967
6968 -- Start of processing for End_Keyword_Location
6969
6970 begin
6971 if Nkind_In (N, N_Block_Statement,
6972 N_Entry_Body,
6973 N_Package_Body,
6974 N_Subprogram_Body,
6975 N_Task_Body)
6976 then
6977 Owner := Handled_Statement_Sequence (N);
6978
6979 elsif Nkind (N) = N_Package_Declaration then
6980 Owner := Specification (N);
6981
6982 elsif Nkind (N) = N_Protected_Body then
6983 Owner := N;
6984
6985 elsif Nkind_In (N, N_Protected_Type_Declaration,
6986 N_Single_Protected_Declaration)
6987 then
6988 Owner := Protected_Definition (N);
6989
6990 elsif Nkind_In (N, N_Single_Task_Declaration,
6991 N_Task_Type_Declaration)
6992 then
6993 Owner := Task_Definition (N);
6994
6995 -- This routine should not be called with other contexts
6996
6997 else
6998 pragma Assert (False);
6999 null;
7000 end if;
7001
7002 return End_Label_Loc (Owner);
7003 end End_Keyword_Location;
7004
7005 ------------------------
7006 -- Ensure_Freeze_Node --
7007 ------------------------
7008
7009 procedure Ensure_Freeze_Node (E : Entity_Id) is
7010 FN : Node_Id;
7011 begin
7012 if No (Freeze_Node (E)) then
7013 FN := Make_Freeze_Entity (Sloc (E));
7014 Set_Has_Delayed_Freeze (E);
7015 Set_Freeze_Node (E, FN);
7016 Set_Access_Types_To_Process (FN, No_Elist);
7017 Set_TSS_Elist (FN, No_Elist);
7018 Set_Entity (FN, E);
7019 end if;
7020 end Ensure_Freeze_Node;
7021
7022 ----------------
7023 -- Enter_Name --
7024 ----------------
7025
7026 procedure Enter_Name (Def_Id : Entity_Id) is
7027 C : constant Entity_Id := Current_Entity (Def_Id);
7028 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
7029 S : constant Entity_Id := Current_Scope;
7030
7031 begin
7032 Generate_Definition (Def_Id);
7033
7034 -- Add new name to current scope declarations. Check for duplicate
7035 -- declaration, which may or may not be a genuine error.
7036
7037 if Present (E) then
7038
7039 -- Case of previous entity entered because of a missing declaration
7040 -- or else a bad subtype indication. Best is to use the new entity,
7041 -- and make the previous one invisible.
7042
7043 if Etype (E) = Any_Type then
7044 Set_Is_Immediately_Visible (E, False);
7045
7046 -- Case of renaming declaration constructed for package instances.
7047 -- if there is an explicit declaration with the same identifier,
7048 -- the renaming is not immediately visible any longer, but remains
7049 -- visible through selected component notation.
7050
7051 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
7052 and then not Comes_From_Source (E)
7053 then
7054 Set_Is_Immediately_Visible (E, False);
7055
7056 -- The new entity may be the package renaming, which has the same
7057 -- same name as a generic formal which has been seen already.
7058
7059 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
7060 and then not Comes_From_Source (Def_Id)
7061 then
7062 Set_Is_Immediately_Visible (E, False);
7063
7064 -- For a fat pointer corresponding to a remote access to subprogram,
7065 -- we use the same identifier as the RAS type, so that the proper
7066 -- name appears in the stub. This type is only retrieved through
7067 -- the RAS type and never by visibility, and is not added to the
7068 -- visibility list (see below).
7069
7070 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
7071 and then Ekind (Def_Id) = E_Record_Type
7072 and then Present (Corresponding_Remote_Type (Def_Id))
7073 then
7074 null;
7075
7076 -- Case of an implicit operation or derived literal. The new entity
7077 -- hides the implicit one, which is removed from all visibility,
7078 -- i.e. the entity list of its scope, and homonym chain of its name.
7079
7080 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
7081 or else Is_Internal (E)
7082 then
7083 declare
7084 Decl : constant Node_Id := Parent (E);
7085 Prev : Entity_Id;
7086 Prev_Vis : Entity_Id;
7087
7088 begin
7089 -- If E is an implicit declaration, it cannot be the first
7090 -- entity in the scope.
7091
7092 Prev := First_Entity (Current_Scope);
7093 while Present (Prev) and then Next_Entity (Prev) /= E loop
7094 Next_Entity (Prev);
7095 end loop;
7096
7097 if No (Prev) then
7098
7099 -- If E is not on the entity chain of the current scope,
7100 -- it is an implicit declaration in the generic formal
7101 -- part of a generic subprogram. When analyzing the body,
7102 -- the generic formals are visible but not on the entity
7103 -- chain of the subprogram. The new entity will become
7104 -- the visible one in the body.
7105
7106 pragma Assert
7107 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
7108 null;
7109
7110 else
7111 Set_Next_Entity (Prev, Next_Entity (E));
7112
7113 if No (Next_Entity (Prev)) then
7114 Set_Last_Entity (Current_Scope, Prev);
7115 end if;
7116
7117 if E = Current_Entity (E) then
7118 Prev_Vis := Empty;
7119
7120 else
7121 Prev_Vis := Current_Entity (E);
7122 while Homonym (Prev_Vis) /= E loop
7123 Prev_Vis := Homonym (Prev_Vis);
7124 end loop;
7125 end if;
7126
7127 if Present (Prev_Vis) then
7128
7129 -- Skip E in the visibility chain
7130
7131 Set_Homonym (Prev_Vis, Homonym (E));
7132
7133 else
7134 Set_Name_Entity_Id (Chars (E), Homonym (E));
7135 end if;
7136 end if;
7137 end;
7138
7139 -- This section of code could use a comment ???
7140
7141 elsif Present (Etype (E))
7142 and then Is_Concurrent_Type (Etype (E))
7143 and then E = Def_Id
7144 then
7145 return;
7146
7147 -- If the homograph is a protected component renaming, it should not
7148 -- be hiding the current entity. Such renamings are treated as weak
7149 -- declarations.
7150
7151 elsif Is_Prival (E) then
7152 Set_Is_Immediately_Visible (E, False);
7153
7154 -- In this case the current entity is a protected component renaming.
7155 -- Perform minimal decoration by setting the scope and return since
7156 -- the prival should not be hiding other visible entities.
7157
7158 elsif Is_Prival (Def_Id) then
7159 Set_Scope (Def_Id, Current_Scope);
7160 return;
7161
7162 -- Analogous to privals, the discriminal generated for an entry index
7163 -- parameter acts as a weak declaration. Perform minimal decoration
7164 -- to avoid bogus errors.
7165
7166 elsif Is_Discriminal (Def_Id)
7167 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
7168 then
7169 Set_Scope (Def_Id, Current_Scope);
7170 return;
7171
7172 -- In the body or private part of an instance, a type extension may
7173 -- introduce a component with the same name as that of an actual. The
7174 -- legality rule is not enforced, but the semantics of the full type
7175 -- with two components of same name are not clear at this point???
7176
7177 elsif In_Instance_Not_Visible then
7178 null;
7179
7180 -- When compiling a package body, some child units may have become
7181 -- visible. They cannot conflict with local entities that hide them.
7182
7183 elsif Is_Child_Unit (E)
7184 and then In_Open_Scopes (Scope (E))
7185 and then not Is_Immediately_Visible (E)
7186 then
7187 null;
7188
7189 -- Conversely, with front-end inlining we may compile the parent body
7190 -- first, and a child unit subsequently. The context is now the
7191 -- parent spec, and body entities are not visible.
7192
7193 elsif Is_Child_Unit (Def_Id)
7194 and then Is_Package_Body_Entity (E)
7195 and then not In_Package_Body (Current_Scope)
7196 then
7197 null;
7198
7199 -- Case of genuine duplicate declaration
7200
7201 else
7202 Error_Msg_Sloc := Sloc (E);
7203
7204 -- If the previous declaration is an incomplete type declaration
7205 -- this may be an attempt to complete it with a private type. The
7206 -- following avoids confusing cascaded errors.
7207
7208 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
7209 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
7210 then
7211 Error_Msg_N
7212 ("incomplete type cannot be completed with a private " &
7213 "declaration", Parent (Def_Id));
7214 Set_Is_Immediately_Visible (E, False);
7215 Set_Full_View (E, Def_Id);
7216
7217 -- An inherited component of a record conflicts with a new
7218 -- discriminant. The discriminant is inserted first in the scope,
7219 -- but the error should be posted on it, not on the component.
7220
7221 elsif Ekind (E) = E_Discriminant
7222 and then Present (Scope (Def_Id))
7223 and then Scope (Def_Id) /= Current_Scope
7224 then
7225 Error_Msg_Sloc := Sloc (Def_Id);
7226 Error_Msg_N ("& conflicts with declaration#", E);
7227 return;
7228
7229 -- If the name of the unit appears in its own context clause, a
7230 -- dummy package with the name has already been created, and the
7231 -- error emitted. Try to continue quietly.
7232
7233 elsif Error_Posted (E)
7234 and then Sloc (E) = No_Location
7235 and then Nkind (Parent (E)) = N_Package_Specification
7236 and then Current_Scope = Standard_Standard
7237 then
7238 Set_Scope (Def_Id, Current_Scope);
7239 return;
7240
7241 else
7242 Error_Msg_N ("& conflicts with declaration#", Def_Id);
7243
7244 -- Avoid cascaded messages with duplicate components in
7245 -- derived types.
7246
7247 if Ekind_In (E, E_Component, E_Discriminant) then
7248 return;
7249 end if;
7250 end if;
7251
7252 if Nkind (Parent (Parent (Def_Id))) =
7253 N_Generic_Subprogram_Declaration
7254 and then Def_Id =
7255 Defining_Entity (Specification (Parent (Parent (Def_Id))))
7256 then
7257 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
7258 end if;
7259
7260 -- If entity is in standard, then we are in trouble, because it
7261 -- means that we have a library package with a duplicated name.
7262 -- That's hard to recover from, so abort.
7263
7264 if S = Standard_Standard then
7265 raise Unrecoverable_Error;
7266
7267 -- Otherwise we continue with the declaration. Having two
7268 -- identical declarations should not cause us too much trouble.
7269
7270 else
7271 null;
7272 end if;
7273 end if;
7274 end if;
7275
7276 -- If we fall through, declaration is OK, at least OK enough to continue
7277
7278 -- If Def_Id is a discriminant or a record component we are in the midst
7279 -- of inheriting components in a derived record definition. Preserve
7280 -- their Ekind and Etype.
7281
7282 if Ekind_In (Def_Id, E_Discriminant, E_Component) then
7283 null;
7284
7285 -- If a type is already set, leave it alone (happens when a type
7286 -- declaration is reanalyzed following a call to the optimizer).
7287
7288 elsif Present (Etype (Def_Id)) then
7289 null;
7290
7291 -- Otherwise, the kind E_Void insures that premature uses of the entity
7292 -- will be detected. Any_Type insures that no cascaded errors will occur
7293
7294 else
7295 Set_Ekind (Def_Id, E_Void);
7296 Set_Etype (Def_Id, Any_Type);
7297 end if;
7298
7299 -- Inherited discriminants and components in derived record types are
7300 -- immediately visible. Itypes are not.
7301
7302 -- Unless the Itype is for a record type with a corresponding remote
7303 -- type (what is that about, it was not commented ???)
7304
7305 if Ekind_In (Def_Id, E_Discriminant, E_Component)
7306 or else
7307 ((not Is_Record_Type (Def_Id)
7308 or else No (Corresponding_Remote_Type (Def_Id)))
7309 and then not Is_Itype (Def_Id))
7310 then
7311 Set_Is_Immediately_Visible (Def_Id);
7312 Set_Current_Entity (Def_Id);
7313 end if;
7314
7315 Set_Homonym (Def_Id, C);
7316 Append_Entity (Def_Id, S);
7317 Set_Public_Status (Def_Id);
7318
7319 -- Declaring a homonym is not allowed in SPARK ...
7320
7321 if Present (C) and then Restriction_Check_Required (SPARK_05) then
7322 declare
7323 Enclosing_Subp : constant Node_Id := Enclosing_Subprogram (Def_Id);
7324 Enclosing_Pack : constant Node_Id := Enclosing_Package (Def_Id);
7325 Other_Scope : constant Node_Id := Enclosing_Dynamic_Scope (C);
7326
7327 begin
7328 -- ... unless the new declaration is in a subprogram, and the
7329 -- visible declaration is a variable declaration or a parameter
7330 -- specification outside that subprogram.
7331
7332 if Present (Enclosing_Subp)
7333 and then Nkind_In (Parent (C), N_Object_Declaration,
7334 N_Parameter_Specification)
7335 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Subp)
7336 then
7337 null;
7338
7339 -- ... or the new declaration is in a package, and the visible
7340 -- declaration occurs outside that package.
7341
7342 elsif Present (Enclosing_Pack)
7343 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Pack)
7344 then
7345 null;
7346
7347 -- ... or the new declaration is a component declaration in a
7348 -- record type definition.
7349
7350 elsif Nkind (Parent (Def_Id)) = N_Component_Declaration then
7351 null;
7352
7353 -- Don't issue error for non-source entities
7354
7355 elsif Comes_From_Source (Def_Id)
7356 and then Comes_From_Source (C)
7357 then
7358 Error_Msg_Sloc := Sloc (C);
7359 Check_SPARK_05_Restriction
7360 ("redeclaration of identifier &#", Def_Id);
7361 end if;
7362 end;
7363 end if;
7364
7365 -- Warn if new entity hides an old one
7366
7367 if Warn_On_Hiding and then Present (C)
7368
7369 -- Don't warn for record components since they always have a well
7370 -- defined scope which does not confuse other uses. Note that in
7371 -- some cases, Ekind has not been set yet.
7372
7373 and then Ekind (C) /= E_Component
7374 and then Ekind (C) /= E_Discriminant
7375 and then Nkind (Parent (C)) /= N_Component_Declaration
7376 and then Ekind (Def_Id) /= E_Component
7377 and then Ekind (Def_Id) /= E_Discriminant
7378 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
7379
7380 -- Don't warn for one character variables. It is too common to use
7381 -- such variables as locals and will just cause too many false hits.
7382
7383 and then Length_Of_Name (Chars (C)) /= 1
7384
7385 -- Don't warn for non-source entities
7386
7387 and then Comes_From_Source (C)
7388 and then Comes_From_Source (Def_Id)
7389
7390 -- Don't warn unless entity in question is in extended main source
7391
7392 and then In_Extended_Main_Source_Unit (Def_Id)
7393
7394 -- Finally, the hidden entity must be either immediately visible or
7395 -- use visible (i.e. from a used package).
7396
7397 and then
7398 (Is_Immediately_Visible (C)
7399 or else
7400 Is_Potentially_Use_Visible (C))
7401 then
7402 Error_Msg_Sloc := Sloc (C);
7403 Error_Msg_N ("declaration hides &#?h?", Def_Id);
7404 end if;
7405 end Enter_Name;
7406
7407 ---------------
7408 -- Entity_Of --
7409 ---------------
7410
7411 function Entity_Of (N : Node_Id) return Entity_Id is
7412 Id : Entity_Id;
7413 Ren : Node_Id;
7414
7415 begin
7416 -- Assume that the arbitrary node does not have an entity
7417
7418 Id := Empty;
7419
7420 if Is_Entity_Name (N) then
7421 Id := Entity (N);
7422
7423 -- Follow a possible chain of renamings to reach the earliest renamed
7424 -- source object.
7425
7426 while Present (Id)
7427 and then Is_Object (Id)
7428 and then Present (Renamed_Object (Id))
7429 loop
7430 Ren := Renamed_Object (Id);
7431
7432 -- The reference renames an abstract state or a whole object
7433
7434 -- Obj : ...;
7435 -- Ren : ... renames Obj;
7436
7437 if Is_Entity_Name (Ren) then
7438 Id := Entity (Ren);
7439
7440 -- The reference renames a function result. Check the original
7441 -- node in case expansion relocates the function call.
7442
7443 -- Ren : ... renames Func_Call;
7444
7445 elsif Nkind (Original_Node (Ren)) = N_Function_Call then
7446 exit;
7447
7448 -- Otherwise the reference renames something which does not yield
7449 -- an abstract state or a whole object. Treat the reference as not
7450 -- having a proper entity for SPARK legality purposes.
7451
7452 else
7453 Id := Empty;
7454 exit;
7455 end if;
7456 end loop;
7457 end if;
7458
7459 return Id;
7460 end Entity_Of;
7461
7462 --------------------------
7463 -- Explain_Limited_Type --
7464 --------------------------
7465
7466 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
7467 C : Entity_Id;
7468
7469 begin
7470 -- For array, component type must be limited
7471
7472 if Is_Array_Type (T) then
7473 Error_Msg_Node_2 := T;
7474 Error_Msg_NE
7475 ("\component type& of type& is limited", N, Component_Type (T));
7476 Explain_Limited_Type (Component_Type (T), N);
7477
7478 elsif Is_Record_Type (T) then
7479
7480 -- No need for extra messages if explicit limited record
7481
7482 if Is_Limited_Record (Base_Type (T)) then
7483 return;
7484 end if;
7485
7486 -- Otherwise find a limited component. Check only components that
7487 -- come from source, or inherited components that appear in the
7488 -- source of the ancestor.
7489
7490 C := First_Component (T);
7491 while Present (C) loop
7492 if Is_Limited_Type (Etype (C))
7493 and then
7494 (Comes_From_Source (C)
7495 or else
7496 (Present (Original_Record_Component (C))
7497 and then
7498 Comes_From_Source (Original_Record_Component (C))))
7499 then
7500 Error_Msg_Node_2 := T;
7501 Error_Msg_NE ("\component& of type& has limited type", N, C);
7502 Explain_Limited_Type (Etype (C), N);
7503 return;
7504 end if;
7505
7506 Next_Component (C);
7507 end loop;
7508
7509 -- The type may be declared explicitly limited, even if no component
7510 -- of it is limited, in which case we fall out of the loop.
7511 return;
7512 end if;
7513 end Explain_Limited_Type;
7514
7515 ---------------------------------------
7516 -- Expression_Of_Expression_Function --
7517 ---------------------------------------
7518
7519 function Expression_Of_Expression_Function
7520 (Subp : Entity_Id) return Node_Id
7521 is
7522 Expr_Func : Node_Id;
7523
7524 begin
7525 pragma Assert (Is_Expression_Function_Or_Completion (Subp));
7526
7527 if Nkind (Original_Node (Subprogram_Spec (Subp))) =
7528 N_Expression_Function
7529 then
7530 Expr_Func := Original_Node (Subprogram_Spec (Subp));
7531
7532 elsif Nkind (Original_Node (Subprogram_Body (Subp))) =
7533 N_Expression_Function
7534 then
7535 Expr_Func := Original_Node (Subprogram_Body (Subp));
7536
7537 else
7538 pragma Assert (False);
7539 null;
7540 end if;
7541
7542 return Original_Node (Expression (Expr_Func));
7543 end Expression_Of_Expression_Function;
7544
7545 -------------------------------
7546 -- Extensions_Visible_Status --
7547 -------------------------------
7548
7549 function Extensions_Visible_Status
7550 (Id : Entity_Id) return Extensions_Visible_Mode
7551 is
7552 Arg : Node_Id;
7553 Decl : Node_Id;
7554 Expr : Node_Id;
7555 Prag : Node_Id;
7556 Subp : Entity_Id;
7557
7558 begin
7559 -- When a formal parameter is subject to Extensions_Visible, the pragma
7560 -- is stored in the contract of related subprogram.
7561
7562 if Is_Formal (Id) then
7563 Subp := Scope (Id);
7564
7565 elsif Is_Subprogram_Or_Generic_Subprogram (Id) then
7566 Subp := Id;
7567
7568 -- No other construct carries this pragma
7569
7570 else
7571 return Extensions_Visible_None;
7572 end if;
7573
7574 Prag := Get_Pragma (Subp, Pragma_Extensions_Visible);
7575
7576 -- In certain cases analysis may request the Extensions_Visible status
7577 -- of an expression function before the pragma has been analyzed yet.
7578 -- Inspect the declarative items after the expression function looking
7579 -- for the pragma (if any).
7580
7581 if No (Prag) and then Is_Expression_Function (Subp) then
7582 Decl := Next (Unit_Declaration_Node (Subp));
7583 while Present (Decl) loop
7584 if Nkind (Decl) = N_Pragma
7585 and then Pragma_Name (Decl) = Name_Extensions_Visible
7586 then
7587 Prag := Decl;
7588 exit;
7589
7590 -- A source construct ends the region where Extensions_Visible may
7591 -- appear, stop the traversal. An expanded expression function is
7592 -- no longer a source construct, but it must still be recognized.
7593
7594 elsif Comes_From_Source (Decl)
7595 or else
7596 (Nkind_In (Decl, N_Subprogram_Body,
7597 N_Subprogram_Declaration)
7598 and then Is_Expression_Function (Defining_Entity (Decl)))
7599 then
7600 exit;
7601 end if;
7602
7603 Next (Decl);
7604 end loop;
7605 end if;
7606
7607 -- Extract the value from the Boolean expression (if any)
7608
7609 if Present (Prag) then
7610 Arg := First (Pragma_Argument_Associations (Prag));
7611
7612 if Present (Arg) then
7613 Expr := Get_Pragma_Arg (Arg);
7614
7615 -- When the associated subprogram is an expression function, the
7616 -- argument of the pragma may not have been analyzed.
7617
7618 if not Analyzed (Expr) then
7619 Preanalyze_And_Resolve (Expr, Standard_Boolean);
7620 end if;
7621
7622 -- Guard against cascading errors when the argument of pragma
7623 -- Extensions_Visible is not a valid static Boolean expression.
7624
7625 if Error_Posted (Expr) then
7626 return Extensions_Visible_None;
7627
7628 elsif Is_True (Expr_Value (Expr)) then
7629 return Extensions_Visible_True;
7630
7631 else
7632 return Extensions_Visible_False;
7633 end if;
7634
7635 -- Otherwise the aspect or pragma defaults to True
7636
7637 else
7638 return Extensions_Visible_True;
7639 end if;
7640
7641 -- Otherwise aspect or pragma Extensions_Visible is not inherited or
7642 -- directly specified. In SPARK code, its value defaults to "False".
7643
7644 elsif SPARK_Mode = On then
7645 return Extensions_Visible_False;
7646
7647 -- In non-SPARK code, aspect or pragma Extensions_Visible defaults to
7648 -- "True".
7649
7650 else
7651 return Extensions_Visible_True;
7652 end if;
7653 end Extensions_Visible_Status;
7654
7655 -----------------
7656 -- Find_Actual --
7657 -----------------
7658
7659 procedure Find_Actual
7660 (N : Node_Id;
7661 Formal : out Entity_Id;
7662 Call : out Node_Id)
7663 is
7664 Context : constant Node_Id := Parent (N);
7665 Actual : Node_Id;
7666 Call_Nam : Node_Id;
7667
7668 begin
7669 if Nkind_In (Context, N_Indexed_Component, N_Selected_Component)
7670 and then N = Prefix (Context)
7671 then
7672 Find_Actual (Context, Formal, Call);
7673 return;
7674
7675 elsif Nkind (Context) = N_Parameter_Association
7676 and then N = Explicit_Actual_Parameter (Context)
7677 then
7678 Call := Parent (Context);
7679
7680 elsif Nkind_In (Context, N_Entry_Call_Statement,
7681 N_Function_Call,
7682 N_Procedure_Call_Statement)
7683 then
7684 Call := Context;
7685
7686 else
7687 Formal := Empty;
7688 Call := Empty;
7689 return;
7690 end if;
7691
7692 -- If we have a call to a subprogram look for the parameter. Note that
7693 -- we exclude overloaded calls, since we don't know enough to be sure
7694 -- of giving the right answer in this case.
7695
7696 if Nkind_In (Call, N_Entry_Call_Statement,
7697 N_Function_Call,
7698 N_Procedure_Call_Statement)
7699 then
7700 Call_Nam := Name (Call);
7701
7702 -- A call to a protected or task entry appears as a selected
7703 -- component rather than an expanded name.
7704
7705 if Nkind (Call_Nam) = N_Selected_Component then
7706 Call_Nam := Selector_Name (Call_Nam);
7707 end if;
7708
7709 if Is_Entity_Name (Call_Nam)
7710 and then Present (Entity (Call_Nam))
7711 and then Is_Overloadable (Entity (Call_Nam))
7712 and then not Is_Overloaded (Call_Nam)
7713 then
7714 -- If node is name in call it is not an actual
7715
7716 if N = Call_Nam then
7717 Formal := Empty;
7718 Call := Empty;
7719 return;
7720 end if;
7721
7722 -- Fall here if we are definitely a parameter
7723
7724 Actual := First_Actual (Call);
7725 Formal := First_Formal (Entity (Call_Nam));
7726 while Present (Formal) and then Present (Actual) loop
7727 if Actual = N then
7728 return;
7729
7730 -- An actual that is the prefix in a prefixed call may have
7731 -- been rewritten in the call, after the deferred reference
7732 -- was collected. Check if sloc and kinds and names match.
7733
7734 elsif Sloc (Actual) = Sloc (N)
7735 and then Nkind (Actual) = N_Identifier
7736 and then Nkind (Actual) = Nkind (N)
7737 and then Chars (Actual) = Chars (N)
7738 then
7739 return;
7740
7741 else
7742 Actual := Next_Actual (Actual);
7743 Formal := Next_Formal (Formal);
7744 end if;
7745 end loop;
7746 end if;
7747 end if;
7748
7749 -- Fall through here if we did not find matching actual
7750
7751 Formal := Empty;
7752 Call := Empty;
7753 end Find_Actual;
7754
7755 ---------------------------
7756 -- Find_Body_Discriminal --
7757 ---------------------------
7758
7759 function Find_Body_Discriminal
7760 (Spec_Discriminant : Entity_Id) return Entity_Id
7761 is
7762 Tsk : Entity_Id;
7763 Disc : Entity_Id;
7764
7765 begin
7766 -- If expansion is suppressed, then the scope can be the concurrent type
7767 -- itself rather than a corresponding concurrent record type.
7768
7769 if Is_Concurrent_Type (Scope (Spec_Discriminant)) then
7770 Tsk := Scope (Spec_Discriminant);
7771
7772 else
7773 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
7774
7775 Tsk := Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
7776 end if;
7777
7778 -- Find discriminant of original concurrent type, and use its current
7779 -- discriminal, which is the renaming within the task/protected body.
7780
7781 Disc := First_Discriminant (Tsk);
7782 while Present (Disc) loop
7783 if Chars (Disc) = Chars (Spec_Discriminant) then
7784 return Discriminal (Disc);
7785 end if;
7786
7787 Next_Discriminant (Disc);
7788 end loop;
7789
7790 -- That loop should always succeed in finding a matching entry and
7791 -- returning. Fatal error if not.
7792
7793 raise Program_Error;
7794 end Find_Body_Discriminal;
7795
7796 -------------------------------------
7797 -- Find_Corresponding_Discriminant --
7798 -------------------------------------
7799
7800 function Find_Corresponding_Discriminant
7801 (Id : Node_Id;
7802 Typ : Entity_Id) return Entity_Id
7803 is
7804 Par_Disc : Entity_Id;
7805 Old_Disc : Entity_Id;
7806 New_Disc : Entity_Id;
7807
7808 begin
7809 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
7810
7811 -- The original type may currently be private, and the discriminant
7812 -- only appear on its full view.
7813
7814 if Is_Private_Type (Scope (Par_Disc))
7815 and then not Has_Discriminants (Scope (Par_Disc))
7816 and then Present (Full_View (Scope (Par_Disc)))
7817 then
7818 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
7819 else
7820 Old_Disc := First_Discriminant (Scope (Par_Disc));
7821 end if;
7822
7823 if Is_Class_Wide_Type (Typ) then
7824 New_Disc := First_Discriminant (Root_Type (Typ));
7825 else
7826 New_Disc := First_Discriminant (Typ);
7827 end if;
7828
7829 while Present (Old_Disc) and then Present (New_Disc) loop
7830 if Old_Disc = Par_Disc then
7831 return New_Disc;
7832 end if;
7833
7834 Next_Discriminant (Old_Disc);
7835 Next_Discriminant (New_Disc);
7836 end loop;
7837
7838 -- Should always find it
7839
7840 raise Program_Error;
7841 end Find_Corresponding_Discriminant;
7842
7843 ----------------------------------
7844 -- Find_Enclosing_Iterator_Loop --
7845 ----------------------------------
7846
7847 function Find_Enclosing_Iterator_Loop (Id : Entity_Id) return Entity_Id is
7848 Constr : Node_Id;
7849 S : Entity_Id;
7850
7851 begin
7852 -- Traverse the scope chain looking for an iterator loop. Such loops are
7853 -- usually transformed into blocks, hence the use of Original_Node.
7854
7855 S := Id;
7856 while Present (S) and then S /= Standard_Standard loop
7857 if Ekind (S) = E_Loop
7858 and then Nkind (Parent (S)) = N_Implicit_Label_Declaration
7859 then
7860 Constr := Original_Node (Label_Construct (Parent (S)));
7861
7862 if Nkind (Constr) = N_Loop_Statement
7863 and then Present (Iteration_Scheme (Constr))
7864 and then Nkind (Iterator_Specification
7865 (Iteration_Scheme (Constr))) =
7866 N_Iterator_Specification
7867 then
7868 return S;
7869 end if;
7870 end if;
7871
7872 S := Scope (S);
7873 end loop;
7874
7875 return Empty;
7876 end Find_Enclosing_Iterator_Loop;
7877
7878 --------------------------
7879 -- Find_Enclosing_Scope --
7880 --------------------------
7881
7882 function Find_Enclosing_Scope (N : Node_Id) return Entity_Id is
7883 Par : Node_Id;
7884 Spec_Id : Entity_Id;
7885
7886 begin
7887 -- Examine the parent chain looking for a construct which defines a
7888 -- scope.
7889
7890 Par := Parent (N);
7891 while Present (Par) loop
7892 case Nkind (Par) is
7893
7894 -- The construct denotes a declaration, the proper scope is its
7895 -- entity.
7896
7897 when N_Entry_Declaration
7898 | N_Expression_Function
7899 | N_Full_Type_Declaration
7900 | N_Generic_Package_Declaration
7901 | N_Generic_Subprogram_Declaration
7902 | N_Package_Declaration
7903 | N_Private_Extension_Declaration
7904 | N_Protected_Type_Declaration
7905 | N_Single_Protected_Declaration
7906 | N_Single_Task_Declaration
7907 | N_Subprogram_Declaration
7908 | N_Task_Type_Declaration
7909 =>
7910 return Defining_Entity (Par);
7911
7912 -- The construct denotes a body, the proper scope is the entity of
7913 -- the corresponding spec.
7914
7915 when N_Entry_Body
7916 | N_Package_Body
7917 | N_Protected_Body
7918 | N_Subprogram_Body
7919 | N_Task_Body
7920 =>
7921 Spec_Id := Corresponding_Spec (Par);
7922
7923 -- The defining entity of a stand-alone subprogram body defines
7924 -- a scope.
7925
7926 if Nkind (Par) = N_Subprogram_Body and then No (Spec_Id) then
7927 return Defining_Entity (Par);
7928
7929 -- Otherwise there should be corresponding spec which defines a
7930 -- scope.
7931
7932 else
7933 pragma Assert (Present (Spec_Id));
7934
7935 return Spec_Id;
7936 end if;
7937
7938 -- Special cases
7939
7940 -- Blocks carry either a source or an internally-generated scope,
7941 -- unless the block is a byproduct of exception handling.
7942
7943 when N_Block_Statement =>
7944 if not Exception_Junk (Par) then
7945 return Entity (Identifier (Par));
7946 end if;
7947
7948 -- Loops carry an internally-generated scope
7949
7950 when N_Loop_Statement =>
7951 return Entity (Identifier (Par));
7952
7953 -- Extended return statements carry an internally-generated scope
7954
7955 when N_Extended_Return_Statement =>
7956 return Return_Statement_Entity (Par);
7957
7958 -- A traversal from a subunit continues via the corresponding stub
7959
7960 when N_Subunit =>
7961 Par := Corresponding_Stub (Par);
7962
7963 when others =>
7964 null;
7965 end case;
7966
7967 Par := Parent (Par);
7968 end loop;
7969
7970 return Standard_Standard;
7971 end Find_Enclosing_Scope;
7972
7973 ------------------------------------
7974 -- Find_Loop_In_Conditional_Block --
7975 ------------------------------------
7976
7977 function Find_Loop_In_Conditional_Block (N : Node_Id) return Node_Id is
7978 Stmt : Node_Id;
7979
7980 begin
7981 Stmt := N;
7982
7983 if Nkind (Stmt) = N_If_Statement then
7984 Stmt := First (Then_Statements (Stmt));
7985 end if;
7986
7987 pragma Assert (Nkind (Stmt) = N_Block_Statement);
7988
7989 -- Inspect the statements of the conditional block. In general the loop
7990 -- should be the first statement in the statement sequence of the block,
7991 -- but the finalization machinery may have introduced extra object
7992 -- declarations.
7993
7994 Stmt := First (Statements (Handled_Statement_Sequence (Stmt)));
7995 while Present (Stmt) loop
7996 if Nkind (Stmt) = N_Loop_Statement then
7997 return Stmt;
7998 end if;
7999
8000 Next (Stmt);
8001 end loop;
8002
8003 -- The expansion of attribute 'Loop_Entry produced a malformed block
8004
8005 raise Program_Error;
8006 end Find_Loop_In_Conditional_Block;
8007
8008 --------------------------
8009 -- Find_Overlaid_Entity --
8010 --------------------------
8011
8012 procedure Find_Overlaid_Entity
8013 (N : Node_Id;
8014 Ent : out Entity_Id;
8015 Off : out Boolean)
8016 is
8017 Expr : Node_Id;
8018
8019 begin
8020 -- We are looking for one of the two following forms:
8021
8022 -- for X'Address use Y'Address
8023
8024 -- or
8025
8026 -- Const : constant Address := expr;
8027 -- ...
8028 -- for X'Address use Const;
8029
8030 -- In the second case, the expr is either Y'Address, or recursively a
8031 -- constant that eventually references Y'Address.
8032
8033 Ent := Empty;
8034 Off := False;
8035
8036 if Nkind (N) = N_Attribute_Definition_Clause
8037 and then Chars (N) = Name_Address
8038 then
8039 Expr := Expression (N);
8040
8041 -- This loop checks the form of the expression for Y'Address,
8042 -- using recursion to deal with intermediate constants.
8043
8044 loop
8045 -- Check for Y'Address
8046
8047 if Nkind (Expr) = N_Attribute_Reference
8048 and then Attribute_Name (Expr) = Name_Address
8049 then
8050 Expr := Prefix (Expr);
8051 exit;
8052
8053 -- Check for Const where Const is a constant entity
8054
8055 elsif Is_Entity_Name (Expr)
8056 and then Ekind (Entity (Expr)) = E_Constant
8057 then
8058 Expr := Constant_Value (Entity (Expr));
8059
8060 -- Anything else does not need checking
8061
8062 else
8063 return;
8064 end if;
8065 end loop;
8066
8067 -- This loop checks the form of the prefix for an entity, using
8068 -- recursion to deal with intermediate components.
8069
8070 loop
8071 -- Check for Y where Y is an entity
8072
8073 if Is_Entity_Name (Expr) then
8074 Ent := Entity (Expr);
8075 return;
8076
8077 -- Check for components
8078
8079 elsif
8080 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component)
8081 then
8082 Expr := Prefix (Expr);
8083 Off := True;
8084
8085 -- Anything else does not need checking
8086
8087 else
8088 return;
8089 end if;
8090 end loop;
8091 end if;
8092 end Find_Overlaid_Entity;
8093
8094 -------------------------
8095 -- Find_Parameter_Type --
8096 -------------------------
8097
8098 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
8099 begin
8100 if Nkind (Param) /= N_Parameter_Specification then
8101 return Empty;
8102
8103 -- For an access parameter, obtain the type from the formal entity
8104 -- itself, because access to subprogram nodes do not carry a type.
8105 -- Shouldn't we always use the formal entity ???
8106
8107 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
8108 return Etype (Defining_Identifier (Param));
8109
8110 else
8111 return Etype (Parameter_Type (Param));
8112 end if;
8113 end Find_Parameter_Type;
8114
8115 -----------------------------------
8116 -- Find_Placement_In_State_Space --
8117 -----------------------------------
8118
8119 procedure Find_Placement_In_State_Space
8120 (Item_Id : Entity_Id;
8121 Placement : out State_Space_Kind;
8122 Pack_Id : out Entity_Id)
8123 is
8124 Context : Entity_Id;
8125
8126 begin
8127 -- Assume that the item does not appear in the state space of a package
8128
8129 Placement := Not_In_Package;
8130 Pack_Id := Empty;
8131
8132 -- Climb the scope stack and examine the enclosing context
8133
8134 Context := Scope (Item_Id);
8135 while Present (Context) and then Context /= Standard_Standard loop
8136 if Is_Package_Or_Generic_Package (Context) then
8137 Pack_Id := Context;
8138
8139 -- A package body is a cut off point for the traversal as the item
8140 -- cannot be visible to the outside from this point on. Note that
8141 -- this test must be done first as a body is also classified as a
8142 -- private part.
8143
8144 if In_Package_Body (Context) then
8145 Placement := Body_State_Space;
8146 return;
8147
8148 -- The private part of a package is a cut off point for the
8149 -- traversal as the item cannot be visible to the outside from
8150 -- this point on.
8151
8152 elsif In_Private_Part (Context) then
8153 Placement := Private_State_Space;
8154 return;
8155
8156 -- When the item appears in the visible state space of a package,
8157 -- continue to climb the scope stack as this may not be the final
8158 -- state space.
8159
8160 else
8161 Placement := Visible_State_Space;
8162
8163 -- The visible state space of a child unit acts as the proper
8164 -- placement of an item.
8165
8166 if Is_Child_Unit (Context) then
8167 return;
8168 end if;
8169 end if;
8170
8171 -- The item or its enclosing package appear in a construct that has
8172 -- no state space.
8173
8174 else
8175 Placement := Not_In_Package;
8176 return;
8177 end if;
8178
8179 Context := Scope (Context);
8180 end loop;
8181 end Find_Placement_In_State_Space;
8182
8183 ------------------------
8184 -- Find_Specific_Type --
8185 ------------------------
8186
8187 function Find_Specific_Type (CW : Entity_Id) return Entity_Id is
8188 Typ : Entity_Id := Root_Type (CW);
8189
8190 begin
8191 if Ekind (Typ) = E_Incomplete_Type then
8192 if From_Limited_With (Typ) then
8193 Typ := Non_Limited_View (Typ);
8194 else
8195 Typ := Full_View (Typ);
8196 end if;
8197 end if;
8198
8199 if Is_Private_Type (Typ)
8200 and then not Is_Tagged_Type (Typ)
8201 and then Present (Full_View (Typ))
8202 then
8203 return Full_View (Typ);
8204 else
8205 return Typ;
8206 end if;
8207 end Find_Specific_Type;
8208
8209 -----------------------------
8210 -- Find_Static_Alternative --
8211 -----------------------------
8212
8213 function Find_Static_Alternative (N : Node_Id) return Node_Id is
8214 Expr : constant Node_Id := Expression (N);
8215 Val : constant Uint := Expr_Value (Expr);
8216 Alt : Node_Id;
8217 Choice : Node_Id;
8218
8219 begin
8220 Alt := First (Alternatives (N));
8221
8222 Search : loop
8223 if Nkind (Alt) /= N_Pragma then
8224 Choice := First (Discrete_Choices (Alt));
8225 while Present (Choice) loop
8226
8227 -- Others choice, always matches
8228
8229 if Nkind (Choice) = N_Others_Choice then
8230 exit Search;
8231
8232 -- Range, check if value is in the range
8233
8234 elsif Nkind (Choice) = N_Range then
8235 exit Search when
8236 Val >= Expr_Value (Low_Bound (Choice))
8237 and then
8238 Val <= Expr_Value (High_Bound (Choice));
8239
8240 -- Choice is a subtype name. Note that we know it must
8241 -- be a static subtype, since otherwise it would have
8242 -- been diagnosed as illegal.
8243
8244 elsif Is_Entity_Name (Choice)
8245 and then Is_Type (Entity (Choice))
8246 then
8247 exit Search when Is_In_Range (Expr, Etype (Choice),
8248 Assume_Valid => False);
8249
8250 -- Choice is a subtype indication
8251
8252 elsif Nkind (Choice) = N_Subtype_Indication then
8253 declare
8254 C : constant Node_Id := Constraint (Choice);
8255 R : constant Node_Id := Range_Expression (C);
8256
8257 begin
8258 exit Search when
8259 Val >= Expr_Value (Low_Bound (R))
8260 and then
8261 Val <= Expr_Value (High_Bound (R));
8262 end;
8263
8264 -- Choice is a simple expression
8265
8266 else
8267 exit Search when Val = Expr_Value (Choice);
8268 end if;
8269
8270 Next (Choice);
8271 end loop;
8272 end if;
8273
8274 Next (Alt);
8275 pragma Assert (Present (Alt));
8276 end loop Search;
8277
8278 -- The above loop *must* terminate by finding a match, since we know the
8279 -- case statement is valid, and the value of the expression is known at
8280 -- compile time. When we fall out of the loop, Alt points to the
8281 -- alternative that we know will be selected at run time.
8282
8283 return Alt;
8284 end Find_Static_Alternative;
8285
8286 ------------------
8287 -- First_Actual --
8288 ------------------
8289
8290 function First_Actual (Node : Node_Id) return Node_Id is
8291 N : Node_Id;
8292
8293 begin
8294 if No (Parameter_Associations (Node)) then
8295 return Empty;
8296 end if;
8297
8298 N := First (Parameter_Associations (Node));
8299
8300 if Nkind (N) = N_Parameter_Association then
8301 return First_Named_Actual (Node);
8302 else
8303 return N;
8304 end if;
8305 end First_Actual;
8306
8307 ------------------
8308 -- First_Global --
8309 ------------------
8310
8311 function First_Global
8312 (Subp : Entity_Id;
8313 Global_Mode : Name_Id;
8314 Refined : Boolean := False) return Node_Id
8315 is
8316 function First_From_Global_List
8317 (List : Node_Id;
8318 Global_Mode : Name_Id := Name_Input) return Entity_Id;
8319 -- Get the first item with suitable mode from List
8320
8321 ----------------------------
8322 -- First_From_Global_List --
8323 ----------------------------
8324
8325 function First_From_Global_List
8326 (List : Node_Id;
8327 Global_Mode : Name_Id := Name_Input) return Entity_Id
8328 is
8329 Assoc : Node_Id;
8330
8331 begin
8332 -- Empty list (no global items)
8333
8334 if Nkind (List) = N_Null then
8335 return Empty;
8336
8337 -- Single global item declaration (only input items)
8338
8339 elsif Nkind_In (List, N_Expanded_Name,
8340 N_Identifier,
8341 N_Selected_Component)
8342 then
8343 if Global_Mode = Name_Input then
8344 return List;
8345 else
8346 return Empty;
8347 end if;
8348
8349 -- Simple global list (only input items) or moded global list
8350 -- declaration.
8351
8352 elsif Nkind (List) = N_Aggregate then
8353 if Present (Expressions (List)) then
8354 if Global_Mode = Name_Input then
8355 return First (Expressions (List));
8356 else
8357 return Empty;
8358 end if;
8359
8360 else
8361 Assoc := First (Component_Associations (List));
8362 while Present (Assoc) loop
8363
8364 -- When we find the desired mode in an association, call
8365 -- recursively First_From_Global_List as if the mode was
8366 -- Name_Input, in order to reuse the existing machinery
8367 -- for the other cases.
8368
8369 if Chars (First (Choices (Assoc))) = Global_Mode then
8370 return First_From_Global_List (Expression (Assoc));
8371 end if;
8372
8373 Next (Assoc);
8374 end loop;
8375
8376 return Empty;
8377 end if;
8378
8379 -- To accommodate partial decoration of disabled SPARK features,
8380 -- this routine may be called with illegal input. If this is the
8381 -- case, do not raise Program_Error.
8382
8383 else
8384 return Empty;
8385 end if;
8386 end First_From_Global_List;
8387
8388 -- Local variables
8389
8390 Global : Node_Id := Empty;
8391 Body_Id : Entity_Id;
8392
8393 begin
8394 pragma Assert (Global_Mode = Name_Input
8395 or else Global_Mode = Name_Output
8396 or else Global_Mode = Name_In_Out
8397 or else Global_Mode = Name_Proof_In);
8398
8399 -- Retrieve the suitable pragma Global or Refined_Global. In the second
8400 -- case, it can only be located on the body entity.
8401
8402 if Refined then
8403 Body_Id := Subprogram_Body_Entity (Subp);
8404 if Present (Body_Id) then
8405 Global := Get_Pragma (Body_Id, Pragma_Refined_Global);
8406 end if;
8407 else
8408 Global := Get_Pragma (Subp, Pragma_Global);
8409 end if;
8410
8411 -- No corresponding global if pragma is not present
8412
8413 if No (Global) then
8414 return Empty;
8415
8416 -- Otherwise retrieve the corresponding list of items depending on the
8417 -- Global_Mode.
8418
8419 else
8420 return First_From_Global_List
8421 (Expression (Get_Argument (Global, Subp)), Global_Mode);
8422 end if;
8423 end First_Global;
8424
8425 -------------
8426 -- Fix_Msg --
8427 -------------
8428
8429 function Fix_Msg (Id : Entity_Id; Msg : String) return String is
8430 Is_Task : constant Boolean :=
8431 Ekind_In (Id, E_Task_Body, E_Task_Type)
8432 or else Is_Single_Task_Object (Id);
8433 Msg_Last : constant Natural := Msg'Last;
8434 Msg_Index : Natural;
8435 Res : String (Msg'Range) := (others => ' ');
8436 Res_Index : Natural;
8437
8438 begin
8439 -- Copy all characters from the input message Msg to result Res with
8440 -- suitable replacements.
8441
8442 Msg_Index := Msg'First;
8443 Res_Index := Res'First;
8444 while Msg_Index <= Msg_Last loop
8445
8446 -- Replace "subprogram" with a different word
8447
8448 if Msg_Index <= Msg_Last - 10
8449 and then Msg (Msg_Index .. Msg_Index + 9) = "subprogram"
8450 then
8451 if Ekind_In (Id, E_Entry, E_Entry_Family) then
8452 Res (Res_Index .. Res_Index + 4) := "entry";
8453 Res_Index := Res_Index + 5;
8454
8455 elsif Is_Task then
8456 Res (Res_Index .. Res_Index + 8) := "task type";
8457 Res_Index := Res_Index + 9;
8458
8459 else
8460 Res (Res_Index .. Res_Index + 9) := "subprogram";
8461 Res_Index := Res_Index + 10;
8462 end if;
8463
8464 Msg_Index := Msg_Index + 10;
8465
8466 -- Replace "protected" with a different word
8467
8468 elsif Msg_Index <= Msg_Last - 9
8469 and then Msg (Msg_Index .. Msg_Index + 8) = "protected"
8470 and then Is_Task
8471 then
8472 Res (Res_Index .. Res_Index + 3) := "task";
8473 Res_Index := Res_Index + 4;
8474 Msg_Index := Msg_Index + 9;
8475
8476 -- Otherwise copy the character
8477
8478 else
8479 Res (Res_Index) := Msg (Msg_Index);
8480 Msg_Index := Msg_Index + 1;
8481 Res_Index := Res_Index + 1;
8482 end if;
8483 end loop;
8484
8485 return Res (Res'First .. Res_Index - 1);
8486 end Fix_Msg;
8487
8488 -------------------------
8489 -- From_Nested_Package --
8490 -------------------------
8491
8492 function From_Nested_Package (T : Entity_Id) return Boolean is
8493 Pack : constant Entity_Id := Scope (T);
8494
8495 begin
8496 return
8497 Ekind (Pack) = E_Package
8498 and then not Is_Frozen (Pack)
8499 and then not Scope_Within_Or_Same (Current_Scope, Pack)
8500 and then In_Open_Scopes (Scope (Pack));
8501 end From_Nested_Package;
8502
8503 -----------------------
8504 -- Gather_Components --
8505 -----------------------
8506
8507 procedure Gather_Components
8508 (Typ : Entity_Id;
8509 Comp_List : Node_Id;
8510 Governed_By : List_Id;
8511 Into : Elist_Id;
8512 Report_Errors : out Boolean)
8513 is
8514 Assoc : Node_Id;
8515 Variant : Node_Id;
8516 Discrete_Choice : Node_Id;
8517 Comp_Item : Node_Id;
8518
8519 Discrim : Entity_Id;
8520 Discrim_Name : Node_Id;
8521 Discrim_Value : Node_Id;
8522
8523 begin
8524 Report_Errors := False;
8525
8526 if No (Comp_List) or else Null_Present (Comp_List) then
8527 return;
8528
8529 elsif Present (Component_Items (Comp_List)) then
8530 Comp_Item := First (Component_Items (Comp_List));
8531
8532 else
8533 Comp_Item := Empty;
8534 end if;
8535
8536 while Present (Comp_Item) loop
8537
8538 -- Skip the tag of a tagged record, the interface tags, as well
8539 -- as all items that are not user components (anonymous types,
8540 -- rep clauses, Parent field, controller field).
8541
8542 if Nkind (Comp_Item) = N_Component_Declaration then
8543 declare
8544 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
8545 begin
8546 if not Is_Tag (Comp) and then Chars (Comp) /= Name_uParent then
8547 Append_Elmt (Comp, Into);
8548 end if;
8549 end;
8550 end if;
8551
8552 Next (Comp_Item);
8553 end loop;
8554
8555 if No (Variant_Part (Comp_List)) then
8556 return;
8557 else
8558 Discrim_Name := Name (Variant_Part (Comp_List));
8559 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
8560 end if;
8561
8562 -- Look for the discriminant that governs this variant part.
8563 -- The discriminant *must* be in the Governed_By List
8564
8565 Assoc := First (Governed_By);
8566 Find_Constraint : loop
8567 Discrim := First (Choices (Assoc));
8568 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
8569 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
8570 and then
8571 Chars (Corresponding_Discriminant (Entity (Discrim))) =
8572 Chars (Discrim_Name))
8573 or else Chars (Original_Record_Component (Entity (Discrim)))
8574 = Chars (Discrim_Name);
8575
8576 if No (Next (Assoc)) then
8577 if not Is_Constrained (Typ)
8578 and then Is_Derived_Type (Typ)
8579 and then Present (Stored_Constraint (Typ))
8580 then
8581 -- If the type is a tagged type with inherited discriminants,
8582 -- use the stored constraint on the parent in order to find
8583 -- the values of discriminants that are otherwise hidden by an
8584 -- explicit constraint. Renamed discriminants are handled in
8585 -- the code above.
8586
8587 -- If several parent discriminants are renamed by a single
8588 -- discriminant of the derived type, the call to obtain the
8589 -- Corresponding_Discriminant field only retrieves the last
8590 -- of them. We recover the constraint on the others from the
8591 -- Stored_Constraint as well.
8592
8593 declare
8594 D : Entity_Id;
8595 C : Elmt_Id;
8596
8597 begin
8598 D := First_Discriminant (Etype (Typ));
8599 C := First_Elmt (Stored_Constraint (Typ));
8600 while Present (D) and then Present (C) loop
8601 if Chars (Discrim_Name) = Chars (D) then
8602 if Is_Entity_Name (Node (C))
8603 and then Entity (Node (C)) = Entity (Discrim)
8604 then
8605 -- D is renamed by Discrim, whose value is given in
8606 -- Assoc.
8607
8608 null;
8609
8610 else
8611 Assoc :=
8612 Make_Component_Association (Sloc (Typ),
8613 New_List
8614 (New_Occurrence_Of (D, Sloc (Typ))),
8615 Duplicate_Subexpr_No_Checks (Node (C)));
8616 end if;
8617 exit Find_Constraint;
8618 end if;
8619
8620 Next_Discriminant (D);
8621 Next_Elmt (C);
8622 end loop;
8623 end;
8624 end if;
8625 end if;
8626
8627 if No (Next (Assoc)) then
8628 Error_Msg_NE (" missing value for discriminant&",
8629 First (Governed_By), Discrim_Name);
8630 Report_Errors := True;
8631 return;
8632 end if;
8633
8634 Next (Assoc);
8635 end loop Find_Constraint;
8636
8637 Discrim_Value := Expression (Assoc);
8638
8639 if not Is_OK_Static_Expression (Discrim_Value) then
8640
8641 -- If the variant part is governed by a discriminant of the type
8642 -- this is an error. If the variant part and the discriminant are
8643 -- inherited from an ancestor this is legal (AI05-120) unless the
8644 -- components are being gathered for an aggregate, in which case
8645 -- the caller must check Report_Errors.
8646
8647 if Scope (Original_Record_Component
8648 ((Entity (First (Choices (Assoc)))))) = Typ
8649 then
8650 Error_Msg_FE
8651 ("value for discriminant & must be static!",
8652 Discrim_Value, Discrim);
8653 Why_Not_Static (Discrim_Value);
8654 end if;
8655
8656 Report_Errors := True;
8657 return;
8658 end if;
8659
8660 Search_For_Discriminant_Value : declare
8661 Low : Node_Id;
8662 High : Node_Id;
8663
8664 UI_High : Uint;
8665 UI_Low : Uint;
8666 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
8667
8668 begin
8669 Find_Discrete_Value : while Present (Variant) loop
8670 Discrete_Choice := First (Discrete_Choices (Variant));
8671 while Present (Discrete_Choice) loop
8672 exit Find_Discrete_Value when
8673 Nkind (Discrete_Choice) = N_Others_Choice;
8674
8675 Get_Index_Bounds (Discrete_Choice, Low, High);
8676
8677 UI_Low := Expr_Value (Low);
8678 UI_High := Expr_Value (High);
8679
8680 exit Find_Discrete_Value when
8681 UI_Low <= UI_Discrim_Value
8682 and then
8683 UI_High >= UI_Discrim_Value;
8684
8685 Next (Discrete_Choice);
8686 end loop;
8687
8688 Next_Non_Pragma (Variant);
8689 end loop Find_Discrete_Value;
8690 end Search_For_Discriminant_Value;
8691
8692 -- The case statement must include a variant that corresponds to the
8693 -- value of the discriminant, unless the discriminant type has a
8694 -- static predicate. In that case the absence of an others_choice that
8695 -- would cover this value becomes a run-time error (3.8,1 (21.1/2)).
8696
8697 if No (Variant)
8698 and then not Has_Static_Predicate (Etype (Discrim_Name))
8699 then
8700 Error_Msg_NE
8701 ("value of discriminant & is out of range", Discrim_Value, Discrim);
8702 Report_Errors := True;
8703 return;
8704 end if;
8705
8706 -- If we have found the corresponding choice, recursively add its
8707 -- components to the Into list. The nested components are part of
8708 -- the same record type.
8709
8710 if Present (Variant) then
8711 Gather_Components
8712 (Typ, Component_List (Variant), Governed_By, Into, Report_Errors);
8713 end if;
8714 end Gather_Components;
8715
8716 ------------------------
8717 -- Get_Actual_Subtype --
8718 ------------------------
8719
8720 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
8721 Typ : constant Entity_Id := Etype (N);
8722 Utyp : Entity_Id := Underlying_Type (Typ);
8723 Decl : Node_Id;
8724 Atyp : Entity_Id;
8725
8726 begin
8727 if No (Utyp) then
8728 Utyp := Typ;
8729 end if;
8730
8731 -- If what we have is an identifier that references a subprogram
8732 -- formal, or a variable or constant object, then we get the actual
8733 -- subtype from the referenced entity if one has been built.
8734
8735 if Nkind (N) = N_Identifier
8736 and then
8737 (Is_Formal (Entity (N))
8738 or else Ekind (Entity (N)) = E_Constant
8739 or else Ekind (Entity (N)) = E_Variable)
8740 and then Present (Actual_Subtype (Entity (N)))
8741 then
8742 return Actual_Subtype (Entity (N));
8743
8744 -- Actual subtype of unchecked union is always itself. We never need
8745 -- the "real" actual subtype. If we did, we couldn't get it anyway
8746 -- because the discriminant is not available. The restrictions on
8747 -- Unchecked_Union are designed to make sure that this is OK.
8748
8749 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
8750 return Typ;
8751
8752 -- Here for the unconstrained case, we must find actual subtype
8753 -- No actual subtype is available, so we must build it on the fly.
8754
8755 -- Checking the type, not the underlying type, for constrainedness
8756 -- seems to be necessary. Maybe all the tests should be on the type???
8757
8758 elsif (not Is_Constrained (Typ))
8759 and then (Is_Array_Type (Utyp)
8760 or else (Is_Record_Type (Utyp)
8761 and then Has_Discriminants (Utyp)))
8762 and then not Has_Unknown_Discriminants (Utyp)
8763 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
8764 then
8765 -- Nothing to do if in spec expression (why not???)
8766
8767 if In_Spec_Expression then
8768 return Typ;
8769
8770 elsif Is_Private_Type (Typ) and then not Has_Discriminants (Typ) then
8771
8772 -- If the type has no discriminants, there is no subtype to
8773 -- build, even if the underlying type is discriminated.
8774
8775 return Typ;
8776
8777 -- Else build the actual subtype
8778
8779 else
8780 Decl := Build_Actual_Subtype (Typ, N);
8781 Atyp := Defining_Identifier (Decl);
8782
8783 -- If Build_Actual_Subtype generated a new declaration then use it
8784
8785 if Atyp /= Typ then
8786
8787 -- The actual subtype is an Itype, so analyze the declaration,
8788 -- but do not attach it to the tree, to get the type defined.
8789
8790 Set_Parent (Decl, N);
8791 Set_Is_Itype (Atyp);
8792 Analyze (Decl, Suppress => All_Checks);
8793 Set_Associated_Node_For_Itype (Atyp, N);
8794 Set_Has_Delayed_Freeze (Atyp, False);
8795
8796 -- We need to freeze the actual subtype immediately. This is
8797 -- needed, because otherwise this Itype will not get frozen
8798 -- at all, and it is always safe to freeze on creation because
8799 -- any associated types must be frozen at this point.
8800
8801 Freeze_Itype (Atyp, N);
8802 return Atyp;
8803
8804 -- Otherwise we did not build a declaration, so return original
8805
8806 else
8807 return Typ;
8808 end if;
8809 end if;
8810
8811 -- For all remaining cases, the actual subtype is the same as
8812 -- the nominal type.
8813
8814 else
8815 return Typ;
8816 end if;
8817 end Get_Actual_Subtype;
8818
8819 -------------------------------------
8820 -- Get_Actual_Subtype_If_Available --
8821 -------------------------------------
8822
8823 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
8824 Typ : constant Entity_Id := Etype (N);
8825
8826 begin
8827 -- If what we have is an identifier that references a subprogram
8828 -- formal, or a variable or constant object, then we get the actual
8829 -- subtype from the referenced entity if one has been built.
8830
8831 if Nkind (N) = N_Identifier
8832 and then
8833 (Is_Formal (Entity (N))
8834 or else Ekind (Entity (N)) = E_Constant
8835 or else Ekind (Entity (N)) = E_Variable)
8836 and then Present (Actual_Subtype (Entity (N)))
8837 then
8838 return Actual_Subtype (Entity (N));
8839
8840 -- Otherwise the Etype of N is returned unchanged
8841
8842 else
8843 return Typ;
8844 end if;
8845 end Get_Actual_Subtype_If_Available;
8846
8847 ------------------------
8848 -- Get_Body_From_Stub --
8849 ------------------------
8850
8851 function Get_Body_From_Stub (N : Node_Id) return Node_Id is
8852 begin
8853 return Proper_Body (Unit (Library_Unit (N)));
8854 end Get_Body_From_Stub;
8855
8856 ---------------------
8857 -- Get_Cursor_Type --
8858 ---------------------
8859
8860 function Get_Cursor_Type
8861 (Aspect : Node_Id;
8862 Typ : Entity_Id) return Entity_Id
8863 is
8864 Assoc : Node_Id;
8865 Func : Entity_Id;
8866 First_Op : Entity_Id;
8867 Cursor : Entity_Id;
8868
8869 begin
8870 -- If error already detected, return
8871
8872 if Error_Posted (Aspect) then
8873 return Any_Type;
8874 end if;
8875
8876 -- The cursor type for an Iterable aspect is the return type of a
8877 -- non-overloaded First primitive operation. Locate association for
8878 -- First.
8879
8880 Assoc := First (Component_Associations (Expression (Aspect)));
8881 First_Op := Any_Id;
8882 while Present (Assoc) loop
8883 if Chars (First (Choices (Assoc))) = Name_First then
8884 First_Op := Expression (Assoc);
8885 exit;
8886 end if;
8887
8888 Next (Assoc);
8889 end loop;
8890
8891 if First_Op = Any_Id then
8892 Error_Msg_N ("aspect Iterable must specify First operation", Aspect);
8893 return Any_Type;
8894 end if;
8895
8896 Cursor := Any_Type;
8897
8898 -- Locate function with desired name and profile in scope of type
8899 -- In the rare case where the type is an integer type, a base type
8900 -- is created for it, check that the base type of the first formal
8901 -- of First matches the base type of the domain.
8902
8903 Func := First_Entity (Scope (Typ));
8904 while Present (Func) loop
8905 if Chars (Func) = Chars (First_Op)
8906 and then Ekind (Func) = E_Function
8907 and then Present (First_Formal (Func))
8908 and then Base_Type (Etype (First_Formal (Func))) = Base_Type (Typ)
8909 and then No (Next_Formal (First_Formal (Func)))
8910 then
8911 if Cursor /= Any_Type then
8912 Error_Msg_N
8913 ("Operation First for iterable type must be unique", Aspect);
8914 return Any_Type;
8915 else
8916 Cursor := Etype (Func);
8917 end if;
8918 end if;
8919
8920 Next_Entity (Func);
8921 end loop;
8922
8923 -- If not found, no way to resolve remaining primitives.
8924
8925 if Cursor = Any_Type then
8926 Error_Msg_N
8927 ("No legal primitive operation First for Iterable type", Aspect);
8928 end if;
8929
8930 return Cursor;
8931 end Get_Cursor_Type;
8932
8933 function Get_Cursor_Type (Typ : Entity_Id) return Entity_Id is
8934 begin
8935 return Etype (Get_Iterable_Type_Primitive (Typ, Name_First));
8936 end Get_Cursor_Type;
8937
8938 -------------------------------
8939 -- Get_Default_External_Name --
8940 -------------------------------
8941
8942 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
8943 begin
8944 Get_Decoded_Name_String (Chars (E));
8945
8946 if Opt.External_Name_Imp_Casing = Uppercase then
8947 Set_Casing (All_Upper_Case);
8948 else
8949 Set_Casing (All_Lower_Case);
8950 end if;
8951
8952 return
8953 Make_String_Literal (Sloc (E),
8954 Strval => String_From_Name_Buffer);
8955 end Get_Default_External_Name;
8956
8957 --------------------------
8958 -- Get_Enclosing_Object --
8959 --------------------------
8960
8961 function Get_Enclosing_Object (N : Node_Id) return Entity_Id is
8962 begin
8963 if Is_Entity_Name (N) then
8964 return Entity (N);
8965 else
8966 case Nkind (N) is
8967 when N_Indexed_Component
8968 | N_Selected_Component
8969 | N_Slice
8970 =>
8971 -- If not generating code, a dereference may be left implicit.
8972 -- In thoses cases, return Empty.
8973
8974 if Is_Access_Type (Etype (Prefix (N))) then
8975 return Empty;
8976 else
8977 return Get_Enclosing_Object (Prefix (N));
8978 end if;
8979
8980 when N_Type_Conversion =>
8981 return Get_Enclosing_Object (Expression (N));
8982
8983 when others =>
8984 return Empty;
8985 end case;
8986 end if;
8987 end Get_Enclosing_Object;
8988
8989 ---------------------------
8990 -- Get_Enum_Lit_From_Pos --
8991 ---------------------------
8992
8993 function Get_Enum_Lit_From_Pos
8994 (T : Entity_Id;
8995 Pos : Uint;
8996 Loc : Source_Ptr) return Node_Id
8997 is
8998 Btyp : Entity_Id := Base_Type (T);
8999 Lit : Node_Id;
9000 LLoc : Source_Ptr;
9001
9002 begin
9003 -- In the case where the literal is of type Character, Wide_Character
9004 -- or Wide_Wide_Character or of a type derived from them, there needs
9005 -- to be some special handling since there is no explicit chain of
9006 -- literals to search. Instead, an N_Character_Literal node is created
9007 -- with the appropriate Char_Code and Chars fields.
9008
9009 if Is_Standard_Character_Type (T) then
9010 Set_Character_Literal_Name (UI_To_CC (Pos));
9011
9012 return
9013 Make_Character_Literal (Loc,
9014 Chars => Name_Find,
9015 Char_Literal_Value => Pos);
9016
9017 -- For all other cases, we have a complete table of literals, and
9018 -- we simply iterate through the chain of literal until the one
9019 -- with the desired position value is found.
9020
9021 else
9022 if Is_Private_Type (Btyp) and then Present (Full_View (Btyp)) then
9023 Btyp := Full_View (Btyp);
9024 end if;
9025
9026 Lit := First_Literal (Btyp);
9027 for J in 1 .. UI_To_Int (Pos) loop
9028 Next_Literal (Lit);
9029
9030 -- If Lit is Empty, Pos is not in range, so raise Constraint_Error
9031 -- inside the loop to avoid calling Next_Literal on Empty.
9032
9033 if No (Lit) then
9034 raise Constraint_Error;
9035 end if;
9036 end loop;
9037
9038 -- Create a new node from Lit, with source location provided by Loc
9039 -- if not equal to No_Location, or by copying the source location of
9040 -- Lit otherwise.
9041
9042 LLoc := Loc;
9043
9044 if LLoc = No_Location then
9045 LLoc := Sloc (Lit);
9046 end if;
9047
9048 return New_Occurrence_Of (Lit, LLoc);
9049 end if;
9050 end Get_Enum_Lit_From_Pos;
9051
9052 ------------------------
9053 -- Get_Generic_Entity --
9054 ------------------------
9055
9056 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
9057 Ent : constant Entity_Id := Entity (Name (N));
9058 begin
9059 if Present (Renamed_Object (Ent)) then
9060 return Renamed_Object (Ent);
9061 else
9062 return Ent;
9063 end if;
9064 end Get_Generic_Entity;
9065
9066 -------------------------------------
9067 -- Get_Incomplete_View_Of_Ancestor --
9068 -------------------------------------
9069
9070 function Get_Incomplete_View_Of_Ancestor (E : Entity_Id) return Entity_Id is
9071 Cur_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
9072 Par_Scope : Entity_Id;
9073 Par_Type : Entity_Id;
9074
9075 begin
9076 -- The incomplete view of an ancestor is only relevant for private
9077 -- derived types in child units.
9078
9079 if not Is_Derived_Type (E)
9080 or else not Is_Child_Unit (Cur_Unit)
9081 then
9082 return Empty;
9083
9084 else
9085 Par_Scope := Scope (Cur_Unit);
9086 if No (Par_Scope) then
9087 return Empty;
9088 end if;
9089
9090 Par_Type := Etype (Base_Type (E));
9091
9092 -- Traverse list of ancestor types until we find one declared in
9093 -- a parent or grandparent unit (two levels seem sufficient).
9094
9095 while Present (Par_Type) loop
9096 if Scope (Par_Type) = Par_Scope
9097 or else Scope (Par_Type) = Scope (Par_Scope)
9098 then
9099 return Par_Type;
9100
9101 elsif not Is_Derived_Type (Par_Type) then
9102 return Empty;
9103
9104 else
9105 Par_Type := Etype (Base_Type (Par_Type));
9106 end if;
9107 end loop;
9108
9109 -- If none found, there is no relevant ancestor type.
9110
9111 return Empty;
9112 end if;
9113 end Get_Incomplete_View_Of_Ancestor;
9114
9115 ----------------------
9116 -- Get_Index_Bounds --
9117 ----------------------
9118
9119 procedure Get_Index_Bounds
9120 (N : Node_Id;
9121 L : out Node_Id;
9122 H : out Node_Id;
9123 Use_Full_View : Boolean := False)
9124 is
9125 function Scalar_Range_Of_Type (Typ : Entity_Id) return Node_Id;
9126 -- Obtain the scalar range of type Typ. If flag Use_Full_View is set and
9127 -- Typ qualifies, the scalar range is obtained from the full view of the
9128 -- type.
9129
9130 --------------------------
9131 -- Scalar_Range_Of_Type --
9132 --------------------------
9133
9134 function Scalar_Range_Of_Type (Typ : Entity_Id) return Node_Id is
9135 T : Entity_Id := Typ;
9136
9137 begin
9138 if Use_Full_View and then Present (Full_View (T)) then
9139 T := Full_View (T);
9140 end if;
9141
9142 return Scalar_Range (T);
9143 end Scalar_Range_Of_Type;
9144
9145 -- Local variables
9146
9147 Kind : constant Node_Kind := Nkind (N);
9148 Rng : Node_Id;
9149
9150 -- Start of processing for Get_Index_Bounds
9151
9152 begin
9153 if Kind = N_Range then
9154 L := Low_Bound (N);
9155 H := High_Bound (N);
9156
9157 elsif Kind = N_Subtype_Indication then
9158 Rng := Range_Expression (Constraint (N));
9159
9160 if Rng = Error then
9161 L := Error;
9162 H := Error;
9163 return;
9164
9165 else
9166 L := Low_Bound (Range_Expression (Constraint (N)));
9167 H := High_Bound (Range_Expression (Constraint (N)));
9168 end if;
9169
9170 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
9171 Rng := Scalar_Range_Of_Type (Entity (N));
9172
9173 if Error_Posted (Rng) then
9174 L := Error;
9175 H := Error;
9176
9177 elsif Nkind (Rng) = N_Subtype_Indication then
9178 Get_Index_Bounds (Rng, L, H);
9179
9180 else
9181 L := Low_Bound (Rng);
9182 H := High_Bound (Rng);
9183 end if;
9184
9185 else
9186 -- N is an expression, indicating a range with one value
9187
9188 L := N;
9189 H := N;
9190 end if;
9191 end Get_Index_Bounds;
9192
9193 -----------------------------
9194 -- Get_Interfacing_Aspects --
9195 -----------------------------
9196
9197 procedure Get_Interfacing_Aspects
9198 (Iface_Asp : Node_Id;
9199 Conv_Asp : out Node_Id;
9200 EN_Asp : out Node_Id;
9201 Expo_Asp : out Node_Id;
9202 Imp_Asp : out Node_Id;
9203 LN_Asp : out Node_Id;
9204 Do_Checks : Boolean := False)
9205 is
9206 procedure Save_Or_Duplication_Error
9207 (Asp : Node_Id;
9208 To : in out Node_Id);
9209 -- Save the value of aspect Asp in node To. If To already has a value,
9210 -- then this is considered a duplicate use of aspect. Emit an error if
9211 -- flag Do_Checks is set.
9212
9213 -------------------------------
9214 -- Save_Or_Duplication_Error --
9215 -------------------------------
9216
9217 procedure Save_Or_Duplication_Error
9218 (Asp : Node_Id;
9219 To : in out Node_Id)
9220 is
9221 begin
9222 -- Detect an extra aspect and issue an error
9223
9224 if Present (To) then
9225 if Do_Checks then
9226 Error_Msg_Name_1 := Chars (Identifier (Asp));
9227 Error_Msg_Sloc := Sloc (To);
9228 Error_Msg_N ("aspect % previously given #", Asp);
9229 end if;
9230
9231 -- Otherwise capture the aspect
9232
9233 else
9234 To := Asp;
9235 end if;
9236 end Save_Or_Duplication_Error;
9237
9238 -- Local variables
9239
9240 Asp : Node_Id;
9241 Asp_Id : Aspect_Id;
9242
9243 -- The following variables capture each individual aspect
9244
9245 Conv : Node_Id := Empty;
9246 EN : Node_Id := Empty;
9247 Expo : Node_Id := Empty;
9248 Imp : Node_Id := Empty;
9249 LN : Node_Id := Empty;
9250
9251 -- Start of processing for Get_Interfacing_Aspects
9252
9253 begin
9254 -- The input interfacing aspect should reside in an aspect specification
9255 -- list.
9256
9257 pragma Assert (Is_List_Member (Iface_Asp));
9258
9259 -- Examine the aspect specifications of the related entity. Find and
9260 -- capture all interfacing aspects. Detect duplicates and emit errors
9261 -- if applicable.
9262
9263 Asp := First (List_Containing (Iface_Asp));
9264 while Present (Asp) loop
9265 Asp_Id := Get_Aspect_Id (Asp);
9266
9267 if Asp_Id = Aspect_Convention then
9268 Save_Or_Duplication_Error (Asp, Conv);
9269
9270 elsif Asp_Id = Aspect_External_Name then
9271 Save_Or_Duplication_Error (Asp, EN);
9272
9273 elsif Asp_Id = Aspect_Export then
9274 Save_Or_Duplication_Error (Asp, Expo);
9275
9276 elsif Asp_Id = Aspect_Import then
9277 Save_Or_Duplication_Error (Asp, Imp);
9278
9279 elsif Asp_Id = Aspect_Link_Name then
9280 Save_Or_Duplication_Error (Asp, LN);
9281 end if;
9282
9283 Next (Asp);
9284 end loop;
9285
9286 Conv_Asp := Conv;
9287 EN_Asp := EN;
9288 Expo_Asp := Expo;
9289 Imp_Asp := Imp;
9290 LN_Asp := LN;
9291 end Get_Interfacing_Aspects;
9292
9293 ---------------------------------
9294 -- Get_Iterable_Type_Primitive --
9295 ---------------------------------
9296
9297 function Get_Iterable_Type_Primitive
9298 (Typ : Entity_Id;
9299 Nam : Name_Id) return Entity_Id
9300 is
9301 Funcs : constant Node_Id := Find_Value_Of_Aspect (Typ, Aspect_Iterable);
9302 Assoc : Node_Id;
9303
9304 begin
9305 if No (Funcs) then
9306 return Empty;
9307
9308 else
9309 Assoc := First (Component_Associations (Funcs));
9310 while Present (Assoc) loop
9311 if Chars (First (Choices (Assoc))) = Nam then
9312 return Entity (Expression (Assoc));
9313 end if;
9314
9315 Assoc := Next (Assoc);
9316 end loop;
9317
9318 return Empty;
9319 end if;
9320 end Get_Iterable_Type_Primitive;
9321
9322 ----------------------------------
9323 -- Get_Library_Unit_Name_string --
9324 ----------------------------------
9325
9326 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
9327 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
9328
9329 begin
9330 Get_Unit_Name_String (Unit_Name_Id);
9331
9332 -- Remove seven last character (" (spec)" or " (body)")
9333
9334 Name_Len := Name_Len - 7;
9335 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
9336 end Get_Library_Unit_Name_String;
9337
9338 --------------------------
9339 -- Get_Max_Queue_Length --
9340 --------------------------
9341
9342 function Get_Max_Queue_Length (Id : Entity_Id) return Uint is
9343 pragma Assert (Is_Entry (Id));
9344 Prag : constant Entity_Id := Get_Pragma (Id, Pragma_Max_Queue_Length);
9345
9346 begin
9347 -- A value of 0 represents no maximum specified, and entries and entry
9348 -- families with no Max_Queue_Length aspect or pragma default to it.
9349
9350 if not Present (Prag) then
9351 return Uint_0;
9352 end if;
9353
9354 return Intval (Expression (First (Pragma_Argument_Associations (Prag))));
9355 end Get_Max_Queue_Length;
9356
9357 ------------------------
9358 -- Get_Name_Entity_Id --
9359 ------------------------
9360
9361 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
9362 begin
9363 return Entity_Id (Get_Name_Table_Int (Id));
9364 end Get_Name_Entity_Id;
9365
9366 ------------------------------
9367 -- Get_Name_From_CTC_Pragma --
9368 ------------------------------
9369
9370 function Get_Name_From_CTC_Pragma (N : Node_Id) return String_Id is
9371 Arg : constant Node_Id :=
9372 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
9373 begin
9374 return Strval (Expr_Value_S (Arg));
9375 end Get_Name_From_CTC_Pragma;
9376
9377 -----------------------
9378 -- Get_Parent_Entity --
9379 -----------------------
9380
9381 function Get_Parent_Entity (Unit : Node_Id) return Entity_Id is
9382 begin
9383 if Nkind (Unit) = N_Package_Body
9384 and then Nkind (Original_Node (Unit)) = N_Package_Instantiation
9385 then
9386 return Defining_Entity
9387 (Specification (Instance_Spec (Original_Node (Unit))));
9388 elsif Nkind (Unit) = N_Package_Instantiation then
9389 return Defining_Entity (Specification (Instance_Spec (Unit)));
9390 else
9391 return Defining_Entity (Unit);
9392 end if;
9393 end Get_Parent_Entity;
9394
9395 -------------------
9396 -- Get_Pragma_Id --
9397 -------------------
9398
9399 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
9400 begin
9401 return Get_Pragma_Id (Pragma_Name_Unmapped (N));
9402 end Get_Pragma_Id;
9403
9404 ------------------------
9405 -- Get_Qualified_Name --
9406 ------------------------
9407
9408 function Get_Qualified_Name
9409 (Id : Entity_Id;
9410 Suffix : Entity_Id := Empty) return Name_Id
9411 is
9412 Suffix_Nam : Name_Id := No_Name;
9413
9414 begin
9415 if Present (Suffix) then
9416 Suffix_Nam := Chars (Suffix);
9417 end if;
9418
9419 return Get_Qualified_Name (Chars (Id), Suffix_Nam, Scope (Id));
9420 end Get_Qualified_Name;
9421
9422 function Get_Qualified_Name
9423 (Nam : Name_Id;
9424 Suffix : Name_Id := No_Name;
9425 Scop : Entity_Id := Current_Scope) return Name_Id
9426 is
9427 procedure Add_Scope (S : Entity_Id);
9428 -- Add the fully qualified form of scope S to the name buffer. The
9429 -- format is:
9430 -- s-1__s__
9431
9432 ---------------
9433 -- Add_Scope --
9434 ---------------
9435
9436 procedure Add_Scope (S : Entity_Id) is
9437 begin
9438 if S = Empty then
9439 null;
9440
9441 elsif S = Standard_Standard then
9442 null;
9443
9444 else
9445 Add_Scope (Scope (S));
9446 Get_Name_String_And_Append (Chars (S));
9447 Add_Str_To_Name_Buffer ("__");
9448 end if;
9449 end Add_Scope;
9450
9451 -- Start of processing for Get_Qualified_Name
9452
9453 begin
9454 Name_Len := 0;
9455 Add_Scope (Scop);
9456
9457 -- Append the base name after all scopes have been chained
9458
9459 Get_Name_String_And_Append (Nam);
9460
9461 -- Append the suffix (if present)
9462
9463 if Suffix /= No_Name then
9464 Add_Str_To_Name_Buffer ("__");
9465 Get_Name_String_And_Append (Suffix);
9466 end if;
9467
9468 return Name_Find;
9469 end Get_Qualified_Name;
9470
9471 -----------------------
9472 -- Get_Reason_String --
9473 -----------------------
9474
9475 procedure Get_Reason_String (N : Node_Id) is
9476 begin
9477 if Nkind (N) = N_String_Literal then
9478 Store_String_Chars (Strval (N));
9479
9480 elsif Nkind (N) = N_Op_Concat then
9481 Get_Reason_String (Left_Opnd (N));
9482 Get_Reason_String (Right_Opnd (N));
9483
9484 -- If not of required form, error
9485
9486 else
9487 Error_Msg_N
9488 ("Reason for pragma Warnings has wrong form", N);
9489 Error_Msg_N
9490 ("\must be string literal or concatenation of string literals", N);
9491 return;
9492 end if;
9493 end Get_Reason_String;
9494
9495 --------------------------------
9496 -- Get_Reference_Discriminant --
9497 --------------------------------
9498
9499 function Get_Reference_Discriminant (Typ : Entity_Id) return Entity_Id is
9500 D : Entity_Id;
9501
9502 begin
9503 D := First_Discriminant (Typ);
9504 while Present (D) loop
9505 if Has_Implicit_Dereference (D) then
9506 return D;
9507 end if;
9508 Next_Discriminant (D);
9509 end loop;
9510
9511 return Empty;
9512 end Get_Reference_Discriminant;
9513
9514 ---------------------------
9515 -- Get_Referenced_Object --
9516 ---------------------------
9517
9518 function Get_Referenced_Object (N : Node_Id) return Node_Id is
9519 R : Node_Id;
9520
9521 begin
9522 R := N;
9523 while Is_Entity_Name (R)
9524 and then Present (Renamed_Object (Entity (R)))
9525 loop
9526 R := Renamed_Object (Entity (R));
9527 end loop;
9528
9529 return R;
9530 end Get_Referenced_Object;
9531
9532 ------------------------
9533 -- Get_Renamed_Entity --
9534 ------------------------
9535
9536 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
9537 R : Entity_Id;
9538
9539 begin
9540 R := E;
9541 while Present (Renamed_Entity (R)) loop
9542 R := Renamed_Entity (R);
9543 end loop;
9544
9545 return R;
9546 end Get_Renamed_Entity;
9547
9548 -----------------------
9549 -- Get_Return_Object --
9550 -----------------------
9551
9552 function Get_Return_Object (N : Node_Id) return Entity_Id is
9553 Decl : Node_Id;
9554
9555 begin
9556 Decl := First (Return_Object_Declarations (N));
9557 while Present (Decl) loop
9558 exit when Nkind (Decl) = N_Object_Declaration
9559 and then Is_Return_Object (Defining_Identifier (Decl));
9560 Next (Decl);
9561 end loop;
9562
9563 pragma Assert (Present (Decl));
9564 return Defining_Identifier (Decl);
9565 end Get_Return_Object;
9566
9567 ---------------------------
9568 -- Get_Subprogram_Entity --
9569 ---------------------------
9570
9571 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
9572 Subp : Node_Id;
9573 Subp_Id : Entity_Id;
9574
9575 begin
9576 if Nkind (Nod) = N_Accept_Statement then
9577 Subp := Entry_Direct_Name (Nod);
9578
9579 elsif Nkind (Nod) = N_Slice then
9580 Subp := Prefix (Nod);
9581
9582 else
9583 Subp := Name (Nod);
9584 end if;
9585
9586 -- Strip the subprogram call
9587
9588 loop
9589 if Nkind_In (Subp, N_Explicit_Dereference,
9590 N_Indexed_Component,
9591 N_Selected_Component)
9592 then
9593 Subp := Prefix (Subp);
9594
9595 elsif Nkind_In (Subp, N_Type_Conversion,
9596 N_Unchecked_Type_Conversion)
9597 then
9598 Subp := Expression (Subp);
9599
9600 else
9601 exit;
9602 end if;
9603 end loop;
9604
9605 -- Extract the entity of the subprogram call
9606
9607 if Is_Entity_Name (Subp) then
9608 Subp_Id := Entity (Subp);
9609
9610 if Ekind (Subp_Id) = E_Access_Subprogram_Type then
9611 Subp_Id := Directly_Designated_Type (Subp_Id);
9612 end if;
9613
9614 if Is_Subprogram (Subp_Id) then
9615 return Subp_Id;
9616 else
9617 return Empty;
9618 end if;
9619
9620 -- The search did not find a construct that denotes a subprogram
9621
9622 else
9623 return Empty;
9624 end if;
9625 end Get_Subprogram_Entity;
9626
9627 -----------------------------
9628 -- Get_Task_Body_Procedure --
9629 -----------------------------
9630
9631 function Get_Task_Body_Procedure (E : Entity_Id) return Entity_Id is
9632 begin
9633 -- Note: A task type may be the completion of a private type with
9634 -- discriminants. When performing elaboration checks on a task
9635 -- declaration, the current view of the type may be the private one,
9636 -- and the procedure that holds the body of the task is held in its
9637 -- underlying type.
9638
9639 -- This is an odd function, why not have Task_Body_Procedure do
9640 -- the following digging???
9641
9642 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
9643 end Get_Task_Body_Procedure;
9644
9645 -------------------------
9646 -- Get_User_Defined_Eq --
9647 -------------------------
9648
9649 function Get_User_Defined_Eq (E : Entity_Id) return Entity_Id is
9650 Prim : Elmt_Id;
9651 Op : Entity_Id;
9652
9653 begin
9654 Prim := First_Elmt (Collect_Primitive_Operations (E));
9655 while Present (Prim) loop
9656 Op := Node (Prim);
9657
9658 if Chars (Op) = Name_Op_Eq
9659 and then Etype (Op) = Standard_Boolean
9660 and then Etype (First_Formal (Op)) = E
9661 and then Etype (Next_Formal (First_Formal (Op))) = E
9662 then
9663 return Op;
9664 end if;
9665
9666 Next_Elmt (Prim);
9667 end loop;
9668
9669 return Empty;
9670 end Get_User_Defined_Eq;
9671
9672 ---------------
9673 -- Get_Views --
9674 ---------------
9675
9676 procedure Get_Views
9677 (Typ : Entity_Id;
9678 Priv_Typ : out Entity_Id;
9679 Full_Typ : out Entity_Id;
9680 Full_Base : out Entity_Id;
9681 CRec_Typ : out Entity_Id)
9682 is
9683 IP_View : Entity_Id;
9684
9685 begin
9686 -- Assume that none of the views can be recovered
9687
9688 Priv_Typ := Empty;
9689 Full_Typ := Empty;
9690 Full_Base := Empty;
9691 CRec_Typ := Empty;
9692
9693 -- The input type is the corresponding record type of a protected or a
9694 -- task type.
9695
9696 if Ekind (Typ) = E_Record_Type
9697 and then Is_Concurrent_Record_Type (Typ)
9698 then
9699 CRec_Typ := Typ;
9700 Full_Typ := Corresponding_Concurrent_Type (CRec_Typ);
9701 Full_Base := Base_Type (Full_Typ);
9702 Priv_Typ := Incomplete_Or_Partial_View (Full_Typ);
9703
9704 -- Otherwise the input type denotes an arbitrary type
9705
9706 else
9707 IP_View := Incomplete_Or_Partial_View (Typ);
9708
9709 -- The input type denotes the full view of a private type
9710
9711 if Present (IP_View) then
9712 Priv_Typ := IP_View;
9713 Full_Typ := Typ;
9714
9715 -- The input type is a private type
9716
9717 elsif Is_Private_Type (Typ) then
9718 Priv_Typ := Typ;
9719 Full_Typ := Full_View (Priv_Typ);
9720
9721 -- Otherwise the input type does not have any views
9722
9723 else
9724 Full_Typ := Typ;
9725 end if;
9726
9727 if Present (Full_Typ) then
9728 Full_Base := Base_Type (Full_Typ);
9729
9730 if Ekind_In (Full_Typ, E_Protected_Type, E_Task_Type) then
9731 CRec_Typ := Corresponding_Record_Type (Full_Typ);
9732 end if;
9733 end if;
9734 end if;
9735 end Get_Views;
9736
9737 -----------------------
9738 -- Has_Access_Values --
9739 -----------------------
9740
9741 function Has_Access_Values (T : Entity_Id) return Boolean is
9742 Typ : constant Entity_Id := Underlying_Type (T);
9743
9744 begin
9745 -- Case of a private type which is not completed yet. This can only
9746 -- happen in the case of a generic format type appearing directly, or
9747 -- as a component of the type to which this function is being applied
9748 -- at the top level. Return False in this case, since we certainly do
9749 -- not know that the type contains access types.
9750
9751 if No (Typ) then
9752 return False;
9753
9754 elsif Is_Access_Type (Typ) then
9755 return True;
9756
9757 elsif Is_Array_Type (Typ) then
9758 return Has_Access_Values (Component_Type (Typ));
9759
9760 elsif Is_Record_Type (Typ) then
9761 declare
9762 Comp : Entity_Id;
9763
9764 begin
9765 -- Loop to Check components
9766
9767 Comp := First_Component_Or_Discriminant (Typ);
9768 while Present (Comp) loop
9769
9770 -- Check for access component, tag field does not count, even
9771 -- though it is implemented internally using an access type.
9772
9773 if Has_Access_Values (Etype (Comp))
9774 and then Chars (Comp) /= Name_uTag
9775 then
9776 return True;
9777 end if;
9778
9779 Next_Component_Or_Discriminant (Comp);
9780 end loop;
9781 end;
9782
9783 return False;
9784
9785 else
9786 return False;
9787 end if;
9788 end Has_Access_Values;
9789
9790 ------------------------------
9791 -- Has_Compatible_Alignment --
9792 ------------------------------
9793
9794 function Has_Compatible_Alignment
9795 (Obj : Entity_Id;
9796 Expr : Node_Id;
9797 Layout_Done : Boolean) return Alignment_Result
9798 is
9799 function Has_Compatible_Alignment_Internal
9800 (Obj : Entity_Id;
9801 Expr : Node_Id;
9802 Layout_Done : Boolean;
9803 Default : Alignment_Result) return Alignment_Result;
9804 -- This is the internal recursive function that actually does the work.
9805 -- There is one additional parameter, which says what the result should
9806 -- be if no alignment information is found, and there is no definite
9807 -- indication of compatible alignments. At the outer level, this is set
9808 -- to Unknown, but for internal recursive calls in the case where types
9809 -- are known to be correct, it is set to Known_Compatible.
9810
9811 ---------------------------------------
9812 -- Has_Compatible_Alignment_Internal --
9813 ---------------------------------------
9814
9815 function Has_Compatible_Alignment_Internal
9816 (Obj : Entity_Id;
9817 Expr : Node_Id;
9818 Layout_Done : Boolean;
9819 Default : Alignment_Result) return Alignment_Result
9820 is
9821 Result : Alignment_Result := Known_Compatible;
9822 -- Holds the current status of the result. Note that once a value of
9823 -- Known_Incompatible is set, it is sticky and does not get changed
9824 -- to Unknown (the value in Result only gets worse as we go along,
9825 -- never better).
9826
9827 Offs : Uint := No_Uint;
9828 -- Set to a factor of the offset from the base object when Expr is a
9829 -- selected or indexed component, based on Component_Bit_Offset and
9830 -- Component_Size respectively. A negative value is used to represent
9831 -- a value which is not known at compile time.
9832
9833 procedure Check_Prefix;
9834 -- Checks the prefix recursively in the case where the expression
9835 -- is an indexed or selected component.
9836
9837 procedure Set_Result (R : Alignment_Result);
9838 -- If R represents a worse outcome (unknown instead of known
9839 -- compatible, or known incompatible), then set Result to R.
9840
9841 ------------------
9842 -- Check_Prefix --
9843 ------------------
9844
9845 procedure Check_Prefix is
9846 begin
9847 -- The subtlety here is that in doing a recursive call to check
9848 -- the prefix, we have to decide what to do in the case where we
9849 -- don't find any specific indication of an alignment problem.
9850
9851 -- At the outer level, we normally set Unknown as the result in
9852 -- this case, since we can only set Known_Compatible if we really
9853 -- know that the alignment value is OK, but for the recursive
9854 -- call, in the case where the types match, and we have not
9855 -- specified a peculiar alignment for the object, we are only
9856 -- concerned about suspicious rep clauses, the default case does
9857 -- not affect us, since the compiler will, in the absence of such
9858 -- rep clauses, ensure that the alignment is correct.
9859
9860 if Default = Known_Compatible
9861 or else
9862 (Etype (Obj) = Etype (Expr)
9863 and then (Unknown_Alignment (Obj)
9864 or else
9865 Alignment (Obj) = Alignment (Etype (Obj))))
9866 then
9867 Set_Result
9868 (Has_Compatible_Alignment_Internal
9869 (Obj, Prefix (Expr), Layout_Done, Known_Compatible));
9870
9871 -- In all other cases, we need a full check on the prefix
9872
9873 else
9874 Set_Result
9875 (Has_Compatible_Alignment_Internal
9876 (Obj, Prefix (Expr), Layout_Done, Unknown));
9877 end if;
9878 end Check_Prefix;
9879
9880 ----------------
9881 -- Set_Result --
9882 ----------------
9883
9884 procedure Set_Result (R : Alignment_Result) is
9885 begin
9886 if R > Result then
9887 Result := R;
9888 end if;
9889 end Set_Result;
9890
9891 -- Start of processing for Has_Compatible_Alignment_Internal
9892
9893 begin
9894 -- If Expr is a selected component, we must make sure there is no
9895 -- potentially troublesome component clause and that the record is
9896 -- not packed if the layout is not done.
9897
9898 if Nkind (Expr) = N_Selected_Component then
9899
9900 -- Packing generates unknown alignment if layout is not done
9901
9902 if Is_Packed (Etype (Prefix (Expr))) and then not Layout_Done then
9903 Set_Result (Unknown);
9904 end if;
9905
9906 -- Check prefix and component offset
9907
9908 Check_Prefix;
9909 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
9910
9911 -- If Expr is an indexed component, we must make sure there is no
9912 -- potentially troublesome Component_Size clause and that the array
9913 -- is not bit-packed if the layout is not done.
9914
9915 elsif Nkind (Expr) = N_Indexed_Component then
9916 declare
9917 Typ : constant Entity_Id := Etype (Prefix (Expr));
9918
9919 begin
9920 -- Packing generates unknown alignment if layout is not done
9921
9922 if Is_Bit_Packed_Array (Typ) and then not Layout_Done then
9923 Set_Result (Unknown);
9924 end if;
9925
9926 -- Check prefix and component offset (or at least size)
9927
9928 Check_Prefix;
9929 Offs := Indexed_Component_Bit_Offset (Expr);
9930 if Offs = No_Uint then
9931 Offs := Component_Size (Typ);
9932 end if;
9933 end;
9934 end if;
9935
9936 -- If we have a null offset, the result is entirely determined by
9937 -- the base object and has already been computed recursively.
9938
9939 if Offs = Uint_0 then
9940 null;
9941
9942 -- Case where we know the alignment of the object
9943
9944 elsif Known_Alignment (Obj) then
9945 declare
9946 ObjA : constant Uint := Alignment (Obj);
9947 ExpA : Uint := No_Uint;
9948 SizA : Uint := No_Uint;
9949
9950 begin
9951 -- If alignment of Obj is 1, then we are always OK
9952
9953 if ObjA = 1 then
9954 Set_Result (Known_Compatible);
9955
9956 -- Alignment of Obj is greater than 1, so we need to check
9957
9958 else
9959 -- If we have an offset, see if it is compatible
9960
9961 if Offs /= No_Uint and Offs > Uint_0 then
9962 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
9963 Set_Result (Known_Incompatible);
9964 end if;
9965
9966 -- See if Expr is an object with known alignment
9967
9968 elsif Is_Entity_Name (Expr)
9969 and then Known_Alignment (Entity (Expr))
9970 then
9971 ExpA := Alignment (Entity (Expr));
9972
9973 -- Otherwise, we can use the alignment of the type of
9974 -- Expr given that we already checked for
9975 -- discombobulating rep clauses for the cases of indexed
9976 -- and selected components above.
9977
9978 elsif Known_Alignment (Etype (Expr)) then
9979 ExpA := Alignment (Etype (Expr));
9980
9981 -- Otherwise the alignment is unknown
9982
9983 else
9984 Set_Result (Default);
9985 end if;
9986
9987 -- If we got an alignment, see if it is acceptable
9988
9989 if ExpA /= No_Uint and then ExpA < ObjA then
9990 Set_Result (Known_Incompatible);
9991 end if;
9992
9993 -- If Expr is not a piece of a larger object, see if size
9994 -- is given. If so, check that it is not too small for the
9995 -- required alignment.
9996
9997 if Offs /= No_Uint then
9998 null;
9999
10000 -- See if Expr is an object with known size
10001
10002 elsif Is_Entity_Name (Expr)
10003 and then Known_Static_Esize (Entity (Expr))
10004 then
10005 SizA := Esize (Entity (Expr));
10006
10007 -- Otherwise, we check the object size of the Expr type
10008
10009 elsif Known_Static_Esize (Etype (Expr)) then
10010 SizA := Esize (Etype (Expr));
10011 end if;
10012
10013 -- If we got a size, see if it is a multiple of the Obj
10014 -- alignment, if not, then the alignment cannot be
10015 -- acceptable, since the size is always a multiple of the
10016 -- alignment.
10017
10018 if SizA /= No_Uint then
10019 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
10020 Set_Result (Known_Incompatible);
10021 end if;
10022 end if;
10023 end if;
10024 end;
10025
10026 -- If we do not know required alignment, any non-zero offset is a
10027 -- potential problem (but certainly may be OK, so result is unknown).
10028
10029 elsif Offs /= No_Uint then
10030 Set_Result (Unknown);
10031
10032 -- If we can't find the result by direct comparison of alignment
10033 -- values, then there is still one case that we can determine known
10034 -- result, and that is when we can determine that the types are the
10035 -- same, and no alignments are specified. Then we known that the
10036 -- alignments are compatible, even if we don't know the alignment
10037 -- value in the front end.
10038
10039 elsif Etype (Obj) = Etype (Expr) then
10040
10041 -- Types are the same, but we have to check for possible size
10042 -- and alignments on the Expr object that may make the alignment
10043 -- different, even though the types are the same.
10044
10045 if Is_Entity_Name (Expr) then
10046
10047 -- First check alignment of the Expr object. Any alignment less
10048 -- than Maximum_Alignment is worrisome since this is the case
10049 -- where we do not know the alignment of Obj.
10050
10051 if Known_Alignment (Entity (Expr))
10052 and then UI_To_Int (Alignment (Entity (Expr))) <
10053 Ttypes.Maximum_Alignment
10054 then
10055 Set_Result (Unknown);
10056
10057 -- Now check size of Expr object. Any size that is not an
10058 -- even multiple of Maximum_Alignment is also worrisome
10059 -- since it may cause the alignment of the object to be less
10060 -- than the alignment of the type.
10061
10062 elsif Known_Static_Esize (Entity (Expr))
10063 and then
10064 (UI_To_Int (Esize (Entity (Expr))) mod
10065 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
10066 /= 0
10067 then
10068 Set_Result (Unknown);
10069
10070 -- Otherwise same type is decisive
10071
10072 else
10073 Set_Result (Known_Compatible);
10074 end if;
10075 end if;
10076
10077 -- Another case to deal with is when there is an explicit size or
10078 -- alignment clause when the types are not the same. If so, then the
10079 -- result is Unknown. We don't need to do this test if the Default is
10080 -- Unknown, since that result will be set in any case.
10081
10082 elsif Default /= Unknown
10083 and then (Has_Size_Clause (Etype (Expr))
10084 or else
10085 Has_Alignment_Clause (Etype (Expr)))
10086 then
10087 Set_Result (Unknown);
10088
10089 -- If no indication found, set default
10090
10091 else
10092 Set_Result (Default);
10093 end if;
10094
10095 -- Return worst result found
10096
10097 return Result;
10098 end Has_Compatible_Alignment_Internal;
10099
10100 -- Start of processing for Has_Compatible_Alignment
10101
10102 begin
10103 -- If Obj has no specified alignment, then set alignment from the type
10104 -- alignment. Perhaps we should always do this, but for sure we should
10105 -- do it when there is an address clause since we can do more if the
10106 -- alignment is known.
10107
10108 if Unknown_Alignment (Obj) then
10109 Set_Alignment (Obj, Alignment (Etype (Obj)));
10110 end if;
10111
10112 -- Now do the internal call that does all the work
10113
10114 return
10115 Has_Compatible_Alignment_Internal (Obj, Expr, Layout_Done, Unknown);
10116 end Has_Compatible_Alignment;
10117
10118 ----------------------
10119 -- Has_Declarations --
10120 ----------------------
10121
10122 function Has_Declarations (N : Node_Id) return Boolean is
10123 begin
10124 return Nkind_In (Nkind (N), N_Accept_Statement,
10125 N_Block_Statement,
10126 N_Compilation_Unit_Aux,
10127 N_Entry_Body,
10128 N_Package_Body,
10129 N_Protected_Body,
10130 N_Subprogram_Body,
10131 N_Task_Body,
10132 N_Package_Specification);
10133 end Has_Declarations;
10134
10135 ---------------------------------
10136 -- Has_Defaulted_Discriminants --
10137 ---------------------------------
10138
10139 function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean is
10140 begin
10141 return Has_Discriminants (Typ)
10142 and then Present (First_Discriminant (Typ))
10143 and then Present (Discriminant_Default_Value
10144 (First_Discriminant (Typ)));
10145 end Has_Defaulted_Discriminants;
10146
10147 -------------------
10148 -- Has_Denormals --
10149 -------------------
10150
10151 function Has_Denormals (E : Entity_Id) return Boolean is
10152 begin
10153 return Is_Floating_Point_Type (E) and then Denorm_On_Target;
10154 end Has_Denormals;
10155
10156 -------------------------------------------
10157 -- Has_Discriminant_Dependent_Constraint --
10158 -------------------------------------------
10159
10160 function Has_Discriminant_Dependent_Constraint
10161 (Comp : Entity_Id) return Boolean
10162 is
10163 Comp_Decl : constant Node_Id := Parent (Comp);
10164 Subt_Indic : Node_Id;
10165 Constr : Node_Id;
10166 Assn : Node_Id;
10167
10168 begin
10169 -- Discriminants can't depend on discriminants
10170
10171 if Ekind (Comp) = E_Discriminant then
10172 return False;
10173
10174 else
10175 Subt_Indic := Subtype_Indication (Component_Definition (Comp_Decl));
10176
10177 if Nkind (Subt_Indic) = N_Subtype_Indication then
10178 Constr := Constraint (Subt_Indic);
10179
10180 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
10181 Assn := First (Constraints (Constr));
10182 while Present (Assn) loop
10183 case Nkind (Assn) is
10184 when N_Identifier
10185 | N_Range
10186 | N_Subtype_Indication
10187 =>
10188 if Depends_On_Discriminant (Assn) then
10189 return True;
10190 end if;
10191
10192 when N_Discriminant_Association =>
10193 if Depends_On_Discriminant (Expression (Assn)) then
10194 return True;
10195 end if;
10196
10197 when others =>
10198 null;
10199 end case;
10200
10201 Next (Assn);
10202 end loop;
10203 end if;
10204 end if;
10205 end if;
10206
10207 return False;
10208 end Has_Discriminant_Dependent_Constraint;
10209
10210 --------------------------------------
10211 -- Has_Effectively_Volatile_Profile --
10212 --------------------------------------
10213
10214 function Has_Effectively_Volatile_Profile
10215 (Subp_Id : Entity_Id) return Boolean
10216 is
10217 Formal : Entity_Id;
10218
10219 begin
10220 -- Inspect the formal parameters looking for an effectively volatile
10221 -- type.
10222
10223 Formal := First_Formal (Subp_Id);
10224 while Present (Formal) loop
10225 if Is_Effectively_Volatile (Etype (Formal)) then
10226 return True;
10227 end if;
10228
10229 Next_Formal (Formal);
10230 end loop;
10231
10232 -- Inspect the return type of functions
10233
10234 if Ekind_In (Subp_Id, E_Function, E_Generic_Function)
10235 and then Is_Effectively_Volatile (Etype (Subp_Id))
10236 then
10237 return True;
10238 end if;
10239
10240 return False;
10241 end Has_Effectively_Volatile_Profile;
10242
10243 --------------------------
10244 -- Has_Enabled_Property --
10245 --------------------------
10246
10247 function Has_Enabled_Property
10248 (Item_Id : Entity_Id;
10249 Property : Name_Id) return Boolean
10250 is
10251 function Protected_Object_Has_Enabled_Property return Boolean;
10252 -- Determine whether a protected object denoted by Item_Id has the
10253 -- property enabled.
10254
10255 function State_Has_Enabled_Property return Boolean;
10256 -- Determine whether a state denoted by Item_Id has the property enabled
10257
10258 function Variable_Has_Enabled_Property return Boolean;
10259 -- Determine whether a variable denoted by Item_Id has the property
10260 -- enabled.
10261
10262 -------------------------------------------
10263 -- Protected_Object_Has_Enabled_Property --
10264 -------------------------------------------
10265
10266 function Protected_Object_Has_Enabled_Property return Boolean is
10267 Constits : constant Elist_Id := Part_Of_Constituents (Item_Id);
10268 Constit_Elmt : Elmt_Id;
10269 Constit_Id : Entity_Id;
10270
10271 begin
10272 -- Protected objects always have the properties Async_Readers and
10273 -- Async_Writers (SPARK RM 7.1.2(16)).
10274
10275 if Property = Name_Async_Readers
10276 or else Property = Name_Async_Writers
10277 then
10278 return True;
10279
10280 -- Protected objects that have Part_Of components also inherit their
10281 -- properties Effective_Reads and Effective_Writes
10282 -- (SPARK RM 7.1.2(16)).
10283
10284 elsif Present (Constits) then
10285 Constit_Elmt := First_Elmt (Constits);
10286 while Present (Constit_Elmt) loop
10287 Constit_Id := Node (Constit_Elmt);
10288
10289 if Has_Enabled_Property (Constit_Id, Property) then
10290 return True;
10291 end if;
10292
10293 Next_Elmt (Constit_Elmt);
10294 end loop;
10295 end if;
10296
10297 return False;
10298 end Protected_Object_Has_Enabled_Property;
10299
10300 --------------------------------
10301 -- State_Has_Enabled_Property --
10302 --------------------------------
10303
10304 function State_Has_Enabled_Property return Boolean is
10305 Decl : constant Node_Id := Parent (Item_Id);
10306 Opt : Node_Id;
10307 Opt_Nam : Node_Id;
10308 Prop : Node_Id;
10309 Prop_Nam : Node_Id;
10310 Props : Node_Id;
10311
10312 begin
10313 -- The declaration of an external abstract state appears as an
10314 -- extension aggregate. If this is not the case, properties can never
10315 -- be set.
10316
10317 if Nkind (Decl) /= N_Extension_Aggregate then
10318 return False;
10319 end if;
10320
10321 -- When External appears as a simple option, it automatically enables
10322 -- all properties.
10323
10324 Opt := First (Expressions (Decl));
10325 while Present (Opt) loop
10326 if Nkind (Opt) = N_Identifier
10327 and then Chars (Opt) = Name_External
10328 then
10329 return True;
10330 end if;
10331
10332 Next (Opt);
10333 end loop;
10334
10335 -- When External specifies particular properties, inspect those and
10336 -- find the desired one (if any).
10337
10338 Opt := First (Component_Associations (Decl));
10339 while Present (Opt) loop
10340 Opt_Nam := First (Choices (Opt));
10341
10342 if Nkind (Opt_Nam) = N_Identifier
10343 and then Chars (Opt_Nam) = Name_External
10344 then
10345 Props := Expression (Opt);
10346
10347 -- Multiple properties appear as an aggregate
10348
10349 if Nkind (Props) = N_Aggregate then
10350
10351 -- Simple property form
10352
10353 Prop := First (Expressions (Props));
10354 while Present (Prop) loop
10355 if Chars (Prop) = Property then
10356 return True;
10357 end if;
10358
10359 Next (Prop);
10360 end loop;
10361
10362 -- Property with expression form
10363
10364 Prop := First (Component_Associations (Props));
10365 while Present (Prop) loop
10366 Prop_Nam := First (Choices (Prop));
10367
10368 -- The property can be represented in two ways:
10369 -- others => <value>
10370 -- <property> => <value>
10371
10372 if Nkind (Prop_Nam) = N_Others_Choice
10373 or else (Nkind (Prop_Nam) = N_Identifier
10374 and then Chars (Prop_Nam) = Property)
10375 then
10376 return Is_True (Expr_Value (Expression (Prop)));
10377 end if;
10378
10379 Next (Prop);
10380 end loop;
10381
10382 -- Single property
10383
10384 else
10385 return Chars (Props) = Property;
10386 end if;
10387 end if;
10388
10389 Next (Opt);
10390 end loop;
10391
10392 return False;
10393 end State_Has_Enabled_Property;
10394
10395 -----------------------------------
10396 -- Variable_Has_Enabled_Property --
10397 -----------------------------------
10398
10399 function Variable_Has_Enabled_Property return Boolean is
10400 function Is_Enabled (Prag : Node_Id) return Boolean;
10401 -- Determine whether property pragma Prag (if present) denotes an
10402 -- enabled property.
10403
10404 ----------------
10405 -- Is_Enabled --
10406 ----------------
10407
10408 function Is_Enabled (Prag : Node_Id) return Boolean is
10409 Arg1 : Node_Id;
10410
10411 begin
10412 if Present (Prag) then
10413 Arg1 := First (Pragma_Argument_Associations (Prag));
10414
10415 -- The pragma has an optional Boolean expression, the related
10416 -- property is enabled only when the expression evaluates to
10417 -- True.
10418
10419 if Present (Arg1) then
10420 return Is_True (Expr_Value (Get_Pragma_Arg (Arg1)));
10421
10422 -- Otherwise the lack of expression enables the property by
10423 -- default.
10424
10425 else
10426 return True;
10427 end if;
10428
10429 -- The property was never set in the first place
10430
10431 else
10432 return False;
10433 end if;
10434 end Is_Enabled;
10435
10436 -- Local variables
10437
10438 AR : constant Node_Id :=
10439 Get_Pragma (Item_Id, Pragma_Async_Readers);
10440 AW : constant Node_Id :=
10441 Get_Pragma (Item_Id, Pragma_Async_Writers);
10442 ER : constant Node_Id :=
10443 Get_Pragma (Item_Id, Pragma_Effective_Reads);
10444 EW : constant Node_Id :=
10445 Get_Pragma (Item_Id, Pragma_Effective_Writes);
10446
10447 -- Start of processing for Variable_Has_Enabled_Property
10448
10449 begin
10450 -- A non-effectively volatile object can never possess external
10451 -- properties.
10452
10453 if not Is_Effectively_Volatile (Item_Id) then
10454 return False;
10455
10456 -- External properties related to variables come in two flavors -
10457 -- explicit and implicit. The explicit case is characterized by the
10458 -- presence of a property pragma with an optional Boolean flag. The
10459 -- property is enabled when the flag evaluates to True or the flag is
10460 -- missing altogether.
10461
10462 elsif Property = Name_Async_Readers and then Is_Enabled (AR) then
10463 return True;
10464
10465 elsif Property = Name_Async_Writers and then Is_Enabled (AW) then
10466 return True;
10467
10468 elsif Property = Name_Effective_Reads and then Is_Enabled (ER) then
10469 return True;
10470
10471 elsif Property = Name_Effective_Writes and then Is_Enabled (EW) then
10472 return True;
10473
10474 -- The implicit case lacks all property pragmas
10475
10476 elsif No (AR) and then No (AW) and then No (ER) and then No (EW) then
10477 if Is_Protected_Type (Etype (Item_Id)) then
10478 return Protected_Object_Has_Enabled_Property;
10479 else
10480 return True;
10481 end if;
10482
10483 else
10484 return False;
10485 end if;
10486 end Variable_Has_Enabled_Property;
10487
10488 -- Start of processing for Has_Enabled_Property
10489
10490 begin
10491 -- Abstract states and variables have a flexible scheme of specifying
10492 -- external properties.
10493
10494 if Ekind (Item_Id) = E_Abstract_State then
10495 return State_Has_Enabled_Property;
10496
10497 elsif Ekind (Item_Id) = E_Variable then
10498 return Variable_Has_Enabled_Property;
10499
10500 -- By default, protected objects only have the properties Async_Readers
10501 -- and Async_Writers. If they have Part_Of components, they also inherit
10502 -- their properties Effective_Reads and Effective_Writes
10503 -- (SPARK RM 7.1.2(16)).
10504
10505 elsif Ekind (Item_Id) = E_Protected_Object then
10506 return Protected_Object_Has_Enabled_Property;
10507
10508 -- Otherwise a property is enabled when the related item is effectively
10509 -- volatile.
10510
10511 else
10512 return Is_Effectively_Volatile (Item_Id);
10513 end if;
10514 end Has_Enabled_Property;
10515
10516 -------------------------------------
10517 -- Has_Full_Default_Initialization --
10518 -------------------------------------
10519
10520 function Has_Full_Default_Initialization (Typ : Entity_Id) return Boolean is
10521 Comp : Entity_Id;
10522 Prag : Node_Id;
10523
10524 begin
10525 -- A type subject to pragma Default_Initial_Condition is fully default
10526 -- initialized when the pragma appears with a non-null argument. Since
10527 -- any type may act as the full view of a private type, this check must
10528 -- be performed prior to the specialized tests below.
10529
10530 if Has_DIC (Typ) then
10531 Prag := Get_Pragma (Typ, Pragma_Default_Initial_Condition);
10532 pragma Assert (Present (Prag));
10533
10534 return Is_Verifiable_DIC_Pragma (Prag);
10535 end if;
10536
10537 -- A scalar type is fully default initialized if it is subject to aspect
10538 -- Default_Value.
10539
10540 if Is_Scalar_Type (Typ) then
10541 return Has_Default_Aspect (Typ);
10542
10543 -- An array type is fully default initialized if its element type is
10544 -- scalar and the array type carries aspect Default_Component_Value or
10545 -- the element type is fully default initialized.
10546
10547 elsif Is_Array_Type (Typ) then
10548 return
10549 Has_Default_Aspect (Typ)
10550 or else Has_Full_Default_Initialization (Component_Type (Typ));
10551
10552 -- A protected type, record type, or type extension is fully default
10553 -- initialized if all its components either carry an initialization
10554 -- expression or have a type that is fully default initialized. The
10555 -- parent type of a type extension must be fully default initialized.
10556
10557 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
10558
10559 -- Inspect all entities defined in the scope of the type, looking for
10560 -- uninitialized components.
10561
10562 Comp := First_Entity (Typ);
10563 while Present (Comp) loop
10564 if Ekind (Comp) = E_Component
10565 and then Comes_From_Source (Comp)
10566 and then No (Expression (Parent (Comp)))
10567 and then not Has_Full_Default_Initialization (Etype (Comp))
10568 then
10569 return False;
10570 end if;
10571
10572 Next_Entity (Comp);
10573 end loop;
10574
10575 -- Ensure that the parent type of a type extension is fully default
10576 -- initialized.
10577
10578 if Etype (Typ) /= Typ
10579 and then not Has_Full_Default_Initialization (Etype (Typ))
10580 then
10581 return False;
10582 end if;
10583
10584 -- If we get here, then all components and parent portion are fully
10585 -- default initialized.
10586
10587 return True;
10588
10589 -- A task type is fully default initialized by default
10590
10591 elsif Is_Task_Type (Typ) then
10592 return True;
10593
10594 -- Otherwise the type is not fully default initialized
10595
10596 else
10597 return False;
10598 end if;
10599 end Has_Full_Default_Initialization;
10600
10601 --------------------
10602 -- Has_Infinities --
10603 --------------------
10604
10605 function Has_Infinities (E : Entity_Id) return Boolean is
10606 begin
10607 return
10608 Is_Floating_Point_Type (E)
10609 and then Nkind (Scalar_Range (E)) = N_Range
10610 and then Includes_Infinities (Scalar_Range (E));
10611 end Has_Infinities;
10612
10613 --------------------
10614 -- Has_Interfaces --
10615 --------------------
10616
10617 function Has_Interfaces
10618 (T : Entity_Id;
10619 Use_Full_View : Boolean := True) return Boolean
10620 is
10621 Typ : Entity_Id := Base_Type (T);
10622
10623 begin
10624 -- Handle concurrent types
10625
10626 if Is_Concurrent_Type (Typ) then
10627 Typ := Corresponding_Record_Type (Typ);
10628 end if;
10629
10630 if not Present (Typ)
10631 or else not Is_Record_Type (Typ)
10632 or else not Is_Tagged_Type (Typ)
10633 then
10634 return False;
10635 end if;
10636
10637 -- Handle private types
10638
10639 if Use_Full_View and then Present (Full_View (Typ)) then
10640 Typ := Full_View (Typ);
10641 end if;
10642
10643 -- Handle concurrent record types
10644
10645 if Is_Concurrent_Record_Type (Typ)
10646 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
10647 then
10648 return True;
10649 end if;
10650
10651 loop
10652 if Is_Interface (Typ)
10653 or else
10654 (Is_Record_Type (Typ)
10655 and then Present (Interfaces (Typ))
10656 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
10657 then
10658 return True;
10659 end if;
10660
10661 exit when Etype (Typ) = Typ
10662
10663 -- Handle private types
10664
10665 or else (Present (Full_View (Etype (Typ)))
10666 and then Full_View (Etype (Typ)) = Typ)
10667
10668 -- Protect frontend against wrong sources with cyclic derivations
10669
10670 or else Etype (Typ) = T;
10671
10672 -- Climb to the ancestor type handling private types
10673
10674 if Present (Full_View (Etype (Typ))) then
10675 Typ := Full_View (Etype (Typ));
10676 else
10677 Typ := Etype (Typ);
10678 end if;
10679 end loop;
10680
10681 return False;
10682 end Has_Interfaces;
10683
10684 --------------------------
10685 -- Has_Max_Queue_Length --
10686 --------------------------
10687
10688 function Has_Max_Queue_Length (Id : Entity_Id) return Boolean is
10689 begin
10690 return
10691 Ekind (Id) = E_Entry
10692 and then Present (Get_Pragma (Id, Pragma_Max_Queue_Length));
10693 end Has_Max_Queue_Length;
10694
10695 ---------------------------------
10696 -- Has_No_Obvious_Side_Effects --
10697 ---------------------------------
10698
10699 function Has_No_Obvious_Side_Effects (N : Node_Id) return Boolean is
10700 begin
10701 -- For now handle literals, constants, and non-volatile variables and
10702 -- expressions combining these with operators or short circuit forms.
10703
10704 if Nkind (N) in N_Numeric_Or_String_Literal then
10705 return True;
10706
10707 elsif Nkind (N) = N_Character_Literal then
10708 return True;
10709
10710 elsif Nkind (N) in N_Unary_Op then
10711 return Has_No_Obvious_Side_Effects (Right_Opnd (N));
10712
10713 elsif Nkind (N) in N_Binary_Op or else Nkind (N) in N_Short_Circuit then
10714 return Has_No_Obvious_Side_Effects (Left_Opnd (N))
10715 and then
10716 Has_No_Obvious_Side_Effects (Right_Opnd (N));
10717
10718 elsif Nkind (N) = N_Expression_With_Actions
10719 and then Is_Empty_List (Actions (N))
10720 then
10721 return Has_No_Obvious_Side_Effects (Expression (N));
10722
10723 elsif Nkind (N) in N_Has_Entity then
10724 return Present (Entity (N))
10725 and then Ekind_In (Entity (N), E_Variable,
10726 E_Constant,
10727 E_Enumeration_Literal,
10728 E_In_Parameter,
10729 E_Out_Parameter,
10730 E_In_Out_Parameter)
10731 and then not Is_Volatile (Entity (N));
10732
10733 else
10734 return False;
10735 end if;
10736 end Has_No_Obvious_Side_Effects;
10737
10738 -----------------------------
10739 -- Has_Non_Null_Refinement --
10740 -----------------------------
10741
10742 function Has_Non_Null_Refinement (Id : Entity_Id) return Boolean is
10743 Constits : Elist_Id;
10744
10745 begin
10746 pragma Assert (Ekind (Id) = E_Abstract_State);
10747 Constits := Refinement_Constituents (Id);
10748
10749 -- For a refinement to be non-null, the first constituent must be
10750 -- anything other than null.
10751
10752 return
10753 Present (Constits)
10754 and then Nkind (Node (First_Elmt (Constits))) /= N_Null;
10755 end Has_Non_Null_Refinement;
10756
10757 ----------------------------------
10758 -- Has_Non_Trivial_Precondition --
10759 ----------------------------------
10760
10761 function Has_Non_Trivial_Precondition (Subp : Entity_Id) return Boolean is
10762 Pre : constant Node_Id := Find_Aspect (Subp, Aspect_Pre);
10763
10764 begin
10765 return
10766 Present (Pre)
10767 and then Class_Present (Pre)
10768 and then not Is_Entity_Name (Expression (Pre));
10769 end Has_Non_Trivial_Precondition;
10770
10771 -------------------
10772 -- Has_Null_Body --
10773 -------------------
10774
10775 function Has_Null_Body (Proc_Id : Entity_Id) return Boolean is
10776 Body_Id : Entity_Id;
10777 Decl : Node_Id;
10778 Spec : Node_Id;
10779 Stmt1 : Node_Id;
10780 Stmt2 : Node_Id;
10781
10782 begin
10783 Spec := Parent (Proc_Id);
10784 Decl := Parent (Spec);
10785
10786 -- Retrieve the entity of the procedure body (e.g. invariant proc).
10787
10788 if Nkind (Spec) = N_Procedure_Specification
10789 and then Nkind (Decl) = N_Subprogram_Declaration
10790 then
10791 Body_Id := Corresponding_Body (Decl);
10792
10793 -- The body acts as a spec
10794
10795 else
10796 Body_Id := Proc_Id;
10797 end if;
10798
10799 -- The body will be generated later
10800
10801 if No (Body_Id) then
10802 return False;
10803 end if;
10804
10805 Spec := Parent (Body_Id);
10806 Decl := Parent (Spec);
10807
10808 pragma Assert
10809 (Nkind (Spec) = N_Procedure_Specification
10810 and then Nkind (Decl) = N_Subprogram_Body);
10811
10812 Stmt1 := First (Statements (Handled_Statement_Sequence (Decl)));
10813
10814 -- Look for a null statement followed by an optional return
10815 -- statement.
10816
10817 if Nkind (Stmt1) = N_Null_Statement then
10818 Stmt2 := Next (Stmt1);
10819
10820 if Present (Stmt2) then
10821 return Nkind (Stmt2) = N_Simple_Return_Statement;
10822 else
10823 return True;
10824 end if;
10825 end if;
10826
10827 return False;
10828 end Has_Null_Body;
10829
10830 ------------------------
10831 -- Has_Null_Exclusion --
10832 ------------------------
10833
10834 function Has_Null_Exclusion (N : Node_Id) return Boolean is
10835 begin
10836 case Nkind (N) is
10837 when N_Access_Definition
10838 | N_Access_Function_Definition
10839 | N_Access_Procedure_Definition
10840 | N_Access_To_Object_Definition
10841 | N_Allocator
10842 | N_Derived_Type_Definition
10843 | N_Function_Specification
10844 | N_Subtype_Declaration
10845 =>
10846 return Null_Exclusion_Present (N);
10847
10848 when N_Component_Definition
10849 | N_Formal_Object_Declaration
10850 | N_Object_Renaming_Declaration
10851 =>
10852 if Present (Subtype_Mark (N)) then
10853 return Null_Exclusion_Present (N);
10854 else pragma Assert (Present (Access_Definition (N)));
10855 return Null_Exclusion_Present (Access_Definition (N));
10856 end if;
10857
10858 when N_Discriminant_Specification =>
10859 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
10860 return Null_Exclusion_Present (Discriminant_Type (N));
10861 else
10862 return Null_Exclusion_Present (N);
10863 end if;
10864
10865 when N_Object_Declaration =>
10866 if Nkind (Object_Definition (N)) = N_Access_Definition then
10867 return Null_Exclusion_Present (Object_Definition (N));
10868 else
10869 return Null_Exclusion_Present (N);
10870 end if;
10871
10872 when N_Parameter_Specification =>
10873 if Nkind (Parameter_Type (N)) = N_Access_Definition then
10874 return Null_Exclusion_Present (Parameter_Type (N));
10875 else
10876 return Null_Exclusion_Present (N);
10877 end if;
10878
10879 when others =>
10880 return False;
10881 end case;
10882 end Has_Null_Exclusion;
10883
10884 ------------------------
10885 -- Has_Null_Extension --
10886 ------------------------
10887
10888 function Has_Null_Extension (T : Entity_Id) return Boolean is
10889 B : constant Entity_Id := Base_Type (T);
10890 Comps : Node_Id;
10891 Ext : Node_Id;
10892
10893 begin
10894 if Nkind (Parent (B)) = N_Full_Type_Declaration
10895 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
10896 then
10897 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
10898
10899 if Present (Ext) then
10900 if Null_Present (Ext) then
10901 return True;
10902 else
10903 Comps := Component_List (Ext);
10904
10905 -- The null component list is rewritten during analysis to
10906 -- include the parent component. Any other component indicates
10907 -- that the extension was not originally null.
10908
10909 return Null_Present (Comps)
10910 or else No (Next (First (Component_Items (Comps))));
10911 end if;
10912 else
10913 return False;
10914 end if;
10915
10916 else
10917 return False;
10918 end if;
10919 end Has_Null_Extension;
10920
10921 -------------------------
10922 -- Has_Null_Refinement --
10923 -------------------------
10924
10925 function Has_Null_Refinement (Id : Entity_Id) return Boolean is
10926 Constits : Elist_Id;
10927
10928 begin
10929 pragma Assert (Ekind (Id) = E_Abstract_State);
10930 Constits := Refinement_Constituents (Id);
10931
10932 -- For a refinement to be null, the state's sole constituent must be a
10933 -- null.
10934
10935 return
10936 Present (Constits)
10937 and then Nkind (Node (First_Elmt (Constits))) = N_Null;
10938 end Has_Null_Refinement;
10939
10940 -------------------------------
10941 -- Has_Overriding_Initialize --
10942 -------------------------------
10943
10944 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
10945 BT : constant Entity_Id := Base_Type (T);
10946 P : Elmt_Id;
10947
10948 begin
10949 if Is_Controlled (BT) then
10950 if Is_RTU (Scope (BT), Ada_Finalization) then
10951 return False;
10952
10953 elsif Present (Primitive_Operations (BT)) then
10954 P := First_Elmt (Primitive_Operations (BT));
10955 while Present (P) loop
10956 declare
10957 Init : constant Entity_Id := Node (P);
10958 Formal : constant Entity_Id := First_Formal (Init);
10959 begin
10960 if Ekind (Init) = E_Procedure
10961 and then Chars (Init) = Name_Initialize
10962 and then Comes_From_Source (Init)
10963 and then Present (Formal)
10964 and then Etype (Formal) = BT
10965 and then No (Next_Formal (Formal))
10966 and then (Ada_Version < Ada_2012
10967 or else not Null_Present (Parent (Init)))
10968 then
10969 return True;
10970 end if;
10971 end;
10972
10973 Next_Elmt (P);
10974 end loop;
10975 end if;
10976
10977 -- Here if type itself does not have a non-null Initialize operation:
10978 -- check immediate ancestor.
10979
10980 if Is_Derived_Type (BT)
10981 and then Has_Overriding_Initialize (Etype (BT))
10982 then
10983 return True;
10984 end if;
10985 end if;
10986
10987 return False;
10988 end Has_Overriding_Initialize;
10989
10990 --------------------------------------
10991 -- Has_Preelaborable_Initialization --
10992 --------------------------------------
10993
10994 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
10995 Has_PE : Boolean;
10996
10997 procedure Check_Components (E : Entity_Id);
10998 -- Check component/discriminant chain, sets Has_PE False if a component
10999 -- or discriminant does not meet the preelaborable initialization rules.
11000
11001 ----------------------
11002 -- Check_Components --
11003 ----------------------
11004
11005 procedure Check_Components (E : Entity_Id) is
11006 Ent : Entity_Id;
11007 Exp : Node_Id;
11008
11009 begin
11010 -- Loop through entities of record or protected type
11011
11012 Ent := E;
11013 while Present (Ent) loop
11014
11015 -- We are interested only in components and discriminants
11016
11017 Exp := Empty;
11018
11019 case Ekind (Ent) is
11020 when E_Component =>
11021
11022 -- Get default expression if any. If there is no declaration
11023 -- node, it means we have an internal entity. The parent and
11024 -- tag fields are examples of such entities. For such cases,
11025 -- we just test the type of the entity.
11026
11027 if Present (Declaration_Node (Ent)) then
11028 Exp := Expression (Declaration_Node (Ent));
11029 end if;
11030
11031 when E_Discriminant =>
11032
11033 -- Note: for a renamed discriminant, the Declaration_Node
11034 -- may point to the one from the ancestor, and have a
11035 -- different expression, so use the proper attribute to
11036 -- retrieve the expression from the derived constraint.
11037
11038 Exp := Discriminant_Default_Value (Ent);
11039
11040 when others =>
11041 goto Check_Next_Entity;
11042 end case;
11043
11044 -- A component has PI if it has no default expression and the
11045 -- component type has PI.
11046
11047 if No (Exp) then
11048 if not Has_Preelaborable_Initialization (Etype (Ent)) then
11049 Has_PE := False;
11050 exit;
11051 end if;
11052
11053 -- Require the default expression to be preelaborable
11054
11055 elsif not Is_Preelaborable_Construct (Exp) then
11056 Has_PE := False;
11057 exit;
11058 end if;
11059
11060 <<Check_Next_Entity>>
11061 Next_Entity (Ent);
11062 end loop;
11063 end Check_Components;
11064
11065 -- Start of processing for Has_Preelaborable_Initialization
11066
11067 begin
11068 -- Immediate return if already marked as known preelaborable init. This
11069 -- covers types for which this function has already been called once
11070 -- and returned True (in which case the result is cached), and also
11071 -- types to which a pragma Preelaborable_Initialization applies.
11072
11073 if Known_To_Have_Preelab_Init (E) then
11074 return True;
11075 end if;
11076
11077 -- If the type is a subtype representing a generic actual type, then
11078 -- test whether its base type has preelaborable initialization since
11079 -- the subtype representing the actual does not inherit this attribute
11080 -- from the actual or formal. (but maybe it should???)
11081
11082 if Is_Generic_Actual_Type (E) then
11083 return Has_Preelaborable_Initialization (Base_Type (E));
11084 end if;
11085
11086 -- All elementary types have preelaborable initialization
11087
11088 if Is_Elementary_Type (E) then
11089 Has_PE := True;
11090
11091 -- Array types have PI if the component type has PI
11092
11093 elsif Is_Array_Type (E) then
11094 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
11095
11096 -- A derived type has preelaborable initialization if its parent type
11097 -- has preelaborable initialization and (in the case of a derived record
11098 -- extension) if the non-inherited components all have preelaborable
11099 -- initialization. However, a user-defined controlled type with an
11100 -- overriding Initialize procedure does not have preelaborable
11101 -- initialization.
11102
11103 elsif Is_Derived_Type (E) then
11104
11105 -- If the derived type is a private extension then it doesn't have
11106 -- preelaborable initialization.
11107
11108 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
11109 return False;
11110 end if;
11111
11112 -- First check whether ancestor type has preelaborable initialization
11113
11114 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
11115
11116 -- If OK, check extension components (if any)
11117
11118 if Has_PE and then Is_Record_Type (E) then
11119 Check_Components (First_Entity (E));
11120 end if;
11121
11122 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
11123 -- with a user defined Initialize procedure does not have PI. If
11124 -- the type is untagged, the control primitives come from a component
11125 -- that has already been checked.
11126
11127 if Has_PE
11128 and then Is_Controlled (E)
11129 and then Is_Tagged_Type (E)
11130 and then Has_Overriding_Initialize (E)
11131 then
11132 Has_PE := False;
11133 end if;
11134
11135 -- Private types not derived from a type having preelaborable init and
11136 -- that are not marked with pragma Preelaborable_Initialization do not
11137 -- have preelaborable initialization.
11138
11139 elsif Is_Private_Type (E) then
11140 return False;
11141
11142 -- Record type has PI if it is non private and all components have PI
11143
11144 elsif Is_Record_Type (E) then
11145 Has_PE := True;
11146 Check_Components (First_Entity (E));
11147
11148 -- Protected types must not have entries, and components must meet
11149 -- same set of rules as for record components.
11150
11151 elsif Is_Protected_Type (E) then
11152 if Has_Entries (E) then
11153 Has_PE := False;
11154 else
11155 Has_PE := True;
11156 Check_Components (First_Entity (E));
11157 Check_Components (First_Private_Entity (E));
11158 end if;
11159
11160 -- Type System.Address always has preelaborable initialization
11161
11162 elsif Is_RTE (E, RE_Address) then
11163 Has_PE := True;
11164
11165 -- In all other cases, type does not have preelaborable initialization
11166
11167 else
11168 return False;
11169 end if;
11170
11171 -- If type has preelaborable initialization, cache result
11172
11173 if Has_PE then
11174 Set_Known_To_Have_Preelab_Init (E);
11175 end if;
11176
11177 return Has_PE;
11178 end Has_Preelaborable_Initialization;
11179
11180 ---------------------------
11181 -- Has_Private_Component --
11182 ---------------------------
11183
11184 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
11185 Btype : Entity_Id := Base_Type (Type_Id);
11186 Component : Entity_Id;
11187
11188 begin
11189 if Error_Posted (Type_Id)
11190 or else Error_Posted (Btype)
11191 then
11192 return False;
11193 end if;
11194
11195 if Is_Class_Wide_Type (Btype) then
11196 Btype := Root_Type (Btype);
11197 end if;
11198
11199 if Is_Private_Type (Btype) then
11200 declare
11201 UT : constant Entity_Id := Underlying_Type (Btype);
11202 begin
11203 if No (UT) then
11204 if No (Full_View (Btype)) then
11205 return not Is_Generic_Type (Btype)
11206 and then
11207 not Is_Generic_Type (Root_Type (Btype));
11208 else
11209 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
11210 end if;
11211 else
11212 return not Is_Frozen (UT) and then Has_Private_Component (UT);
11213 end if;
11214 end;
11215
11216 elsif Is_Array_Type (Btype) then
11217 return Has_Private_Component (Component_Type (Btype));
11218
11219 elsif Is_Record_Type (Btype) then
11220 Component := First_Component (Btype);
11221 while Present (Component) loop
11222 if Has_Private_Component (Etype (Component)) then
11223 return True;
11224 end if;
11225
11226 Next_Component (Component);
11227 end loop;
11228
11229 return False;
11230
11231 elsif Is_Protected_Type (Btype)
11232 and then Present (Corresponding_Record_Type (Btype))
11233 then
11234 return Has_Private_Component (Corresponding_Record_Type (Btype));
11235
11236 else
11237 return False;
11238 end if;
11239 end Has_Private_Component;
11240
11241 ----------------------
11242 -- Has_Signed_Zeros --
11243 ----------------------
11244
11245 function Has_Signed_Zeros (E : Entity_Id) return Boolean is
11246 begin
11247 return Is_Floating_Point_Type (E) and then Signed_Zeros_On_Target;
11248 end Has_Signed_Zeros;
11249
11250 ------------------------------
11251 -- Has_Significant_Contract --
11252 ------------------------------
11253
11254 function Has_Significant_Contract (Subp_Id : Entity_Id) return Boolean is
11255 Subp_Nam : constant Name_Id := Chars (Subp_Id);
11256
11257 begin
11258 -- _Finalizer procedure
11259
11260 if Subp_Nam = Name_uFinalizer then
11261 return False;
11262
11263 -- _Postconditions procedure
11264
11265 elsif Subp_Nam = Name_uPostconditions then
11266 return False;
11267
11268 -- Predicate function
11269
11270 elsif Ekind (Subp_Id) = E_Function
11271 and then Is_Predicate_Function (Subp_Id)
11272 then
11273 return False;
11274
11275 -- TSS subprogram
11276
11277 elsif Get_TSS_Name (Subp_Id) /= TSS_Null then
11278 return False;
11279
11280 else
11281 return True;
11282 end if;
11283 end Has_Significant_Contract;
11284
11285 -----------------------------
11286 -- Has_Static_Array_Bounds --
11287 -----------------------------
11288
11289 function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is
11290 Ndims : constant Nat := Number_Dimensions (Typ);
11291
11292 Index : Node_Id;
11293 Low : Node_Id;
11294 High : Node_Id;
11295
11296 begin
11297 -- Unconstrained types do not have static bounds
11298
11299 if not Is_Constrained (Typ) then
11300 return False;
11301 end if;
11302
11303 -- First treat string literals specially, as the lower bound and length
11304 -- of string literals are not stored like those of arrays.
11305
11306 -- A string literal always has static bounds
11307
11308 if Ekind (Typ) = E_String_Literal_Subtype then
11309 return True;
11310 end if;
11311
11312 -- Treat all dimensions in turn
11313
11314 Index := First_Index (Typ);
11315 for Indx in 1 .. Ndims loop
11316
11317 -- In case of an illegal index which is not a discrete type, return
11318 -- that the type is not static.
11319
11320 if not Is_Discrete_Type (Etype (Index))
11321 or else Etype (Index) = Any_Type
11322 then
11323 return False;
11324 end if;
11325
11326 Get_Index_Bounds (Index, Low, High);
11327
11328 if Error_Posted (Low) or else Error_Posted (High) then
11329 return False;
11330 end if;
11331
11332 if Is_OK_Static_Expression (Low)
11333 and then
11334 Is_OK_Static_Expression (High)
11335 then
11336 null;
11337 else
11338 return False;
11339 end if;
11340
11341 Next (Index);
11342 end loop;
11343
11344 -- If we fall through the loop, all indexes matched
11345
11346 return True;
11347 end Has_Static_Array_Bounds;
11348
11349 ----------------
11350 -- Has_Stream --
11351 ----------------
11352
11353 function Has_Stream (T : Entity_Id) return Boolean is
11354 E : Entity_Id;
11355
11356 begin
11357 if No (T) then
11358 return False;
11359
11360 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
11361 return True;
11362
11363 elsif Is_Array_Type (T) then
11364 return Has_Stream (Component_Type (T));
11365
11366 elsif Is_Record_Type (T) then
11367 E := First_Component (T);
11368 while Present (E) loop
11369 if Has_Stream (Etype (E)) then
11370 return True;
11371 else
11372 Next_Component (E);
11373 end if;
11374 end loop;
11375
11376 return False;
11377
11378 elsif Is_Private_Type (T) then
11379 return Has_Stream (Underlying_Type (T));
11380
11381 else
11382 return False;
11383 end if;
11384 end Has_Stream;
11385
11386 ----------------
11387 -- Has_Suffix --
11388 ----------------
11389
11390 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
11391 begin
11392 Get_Name_String (Chars (E));
11393 return Name_Buffer (Name_Len) = Suffix;
11394 end Has_Suffix;
11395
11396 ----------------
11397 -- Add_Suffix --
11398 ----------------
11399
11400 function Add_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
11401 begin
11402 Get_Name_String (Chars (E));
11403 Add_Char_To_Name_Buffer (Suffix);
11404 return Name_Find;
11405 end Add_Suffix;
11406
11407 -------------------
11408 -- Remove_Suffix --
11409 -------------------
11410
11411 function Remove_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
11412 begin
11413 pragma Assert (Has_Suffix (E, Suffix));
11414 Get_Name_String (Chars (E));
11415 Name_Len := Name_Len - 1;
11416 return Name_Find;
11417 end Remove_Suffix;
11418
11419 ----------------------------------
11420 -- Replace_Null_By_Null_Address --
11421 ----------------------------------
11422
11423 procedure Replace_Null_By_Null_Address (N : Node_Id) is
11424 procedure Replace_Null_Operand (Op : Node_Id; Other_Op : Node_Id);
11425 -- Replace operand Op with a reference to Null_Address when the operand
11426 -- denotes a null Address. Other_Op denotes the other operand.
11427
11428 --------------------------
11429 -- Replace_Null_Operand --
11430 --------------------------
11431
11432 procedure Replace_Null_Operand (Op : Node_Id; Other_Op : Node_Id) is
11433 begin
11434 -- Check the type of the complementary operand since the N_Null node
11435 -- has not been decorated yet.
11436
11437 if Nkind (Op) = N_Null
11438 and then Is_Descendant_Of_Address (Etype (Other_Op))
11439 then
11440 Rewrite (Op, New_Occurrence_Of (RTE (RE_Null_Address), Sloc (Op)));
11441 end if;
11442 end Replace_Null_Operand;
11443
11444 -- Start of processing for Replace_Null_By_Null_Address
11445
11446 begin
11447 pragma Assert (Relaxed_RM_Semantics);
11448 pragma Assert (Nkind_In (N, N_Null,
11449 N_Op_Eq,
11450 N_Op_Ge,
11451 N_Op_Gt,
11452 N_Op_Le,
11453 N_Op_Lt,
11454 N_Op_Ne));
11455
11456 if Nkind (N) = N_Null then
11457 Rewrite (N, New_Occurrence_Of (RTE (RE_Null_Address), Sloc (N)));
11458
11459 else
11460 declare
11461 L : constant Node_Id := Left_Opnd (N);
11462 R : constant Node_Id := Right_Opnd (N);
11463
11464 begin
11465 Replace_Null_Operand (L, Other_Op => R);
11466 Replace_Null_Operand (R, Other_Op => L);
11467 end;
11468 end if;
11469 end Replace_Null_By_Null_Address;
11470
11471 --------------------------
11472 -- Has_Tagged_Component --
11473 --------------------------
11474
11475 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
11476 Comp : Entity_Id;
11477
11478 begin
11479 if Is_Private_Type (Typ) and then Present (Underlying_Type (Typ)) then
11480 return Has_Tagged_Component (Underlying_Type (Typ));
11481
11482 elsif Is_Array_Type (Typ) then
11483 return Has_Tagged_Component (Component_Type (Typ));
11484
11485 elsif Is_Tagged_Type (Typ) then
11486 return True;
11487
11488 elsif Is_Record_Type (Typ) then
11489 Comp := First_Component (Typ);
11490 while Present (Comp) loop
11491 if Has_Tagged_Component (Etype (Comp)) then
11492 return True;
11493 end if;
11494
11495 Next_Component (Comp);
11496 end loop;
11497
11498 return False;
11499
11500 else
11501 return False;
11502 end if;
11503 end Has_Tagged_Component;
11504
11505 -----------------------------
11506 -- Has_Undefined_Reference --
11507 -----------------------------
11508
11509 function Has_Undefined_Reference (Expr : Node_Id) return Boolean is
11510 Has_Undef_Ref : Boolean := False;
11511 -- Flag set when expression Expr contains at least one undefined
11512 -- reference.
11513
11514 function Is_Undefined_Reference (N : Node_Id) return Traverse_Result;
11515 -- Determine whether N denotes a reference and if it does, whether it is
11516 -- undefined.
11517
11518 ----------------------------
11519 -- Is_Undefined_Reference --
11520 ----------------------------
11521
11522 function Is_Undefined_Reference (N : Node_Id) return Traverse_Result is
11523 begin
11524 if Is_Entity_Name (N)
11525 and then Present (Entity (N))
11526 and then Entity (N) = Any_Id
11527 then
11528 Has_Undef_Ref := True;
11529 return Abandon;
11530 end if;
11531
11532 return OK;
11533 end Is_Undefined_Reference;
11534
11535 procedure Find_Undefined_References is
11536 new Traverse_Proc (Is_Undefined_Reference);
11537
11538 -- Start of processing for Has_Undefined_Reference
11539
11540 begin
11541 Find_Undefined_References (Expr);
11542
11543 return Has_Undef_Ref;
11544 end Has_Undefined_Reference;
11545
11546 ----------------------------
11547 -- Has_Volatile_Component --
11548 ----------------------------
11549
11550 function Has_Volatile_Component (Typ : Entity_Id) return Boolean is
11551 Comp : Entity_Id;
11552
11553 begin
11554 if Has_Volatile_Components (Typ) then
11555 return True;
11556
11557 elsif Is_Array_Type (Typ) then
11558 return Is_Volatile (Component_Type (Typ));
11559
11560 elsif Is_Record_Type (Typ) then
11561 Comp := First_Component (Typ);
11562 while Present (Comp) loop
11563 if Is_Volatile_Object (Comp) then
11564 return True;
11565 end if;
11566
11567 Comp := Next_Component (Comp);
11568 end loop;
11569 end if;
11570
11571 return False;
11572 end Has_Volatile_Component;
11573
11574 -------------------------
11575 -- Implementation_Kind --
11576 -------------------------
11577
11578 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
11579 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
11580 Arg : Node_Id;
11581 begin
11582 pragma Assert (Present (Impl_Prag));
11583 Arg := Last (Pragma_Argument_Associations (Impl_Prag));
11584 return Chars (Get_Pragma_Arg (Arg));
11585 end Implementation_Kind;
11586
11587 --------------------------
11588 -- Implements_Interface --
11589 --------------------------
11590
11591 function Implements_Interface
11592 (Typ_Ent : Entity_Id;
11593 Iface_Ent : Entity_Id;
11594 Exclude_Parents : Boolean := False) return Boolean
11595 is
11596 Ifaces_List : Elist_Id;
11597 Elmt : Elmt_Id;
11598 Iface : Entity_Id := Base_Type (Iface_Ent);
11599 Typ : Entity_Id := Base_Type (Typ_Ent);
11600
11601 begin
11602 if Is_Class_Wide_Type (Typ) then
11603 Typ := Root_Type (Typ);
11604 end if;
11605
11606 if not Has_Interfaces (Typ) then
11607 return False;
11608 end if;
11609
11610 if Is_Class_Wide_Type (Iface) then
11611 Iface := Root_Type (Iface);
11612 end if;
11613
11614 Collect_Interfaces (Typ, Ifaces_List);
11615
11616 Elmt := First_Elmt (Ifaces_List);
11617 while Present (Elmt) loop
11618 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
11619 and then Exclude_Parents
11620 then
11621 null;
11622
11623 elsif Node (Elmt) = Iface then
11624 return True;
11625 end if;
11626
11627 Next_Elmt (Elmt);
11628 end loop;
11629
11630 return False;
11631 end Implements_Interface;
11632
11633 ------------------------------------
11634 -- In_Assertion_Expression_Pragma --
11635 ------------------------------------
11636
11637 function In_Assertion_Expression_Pragma (N : Node_Id) return Boolean is
11638 Par : Node_Id;
11639 Prag : Node_Id := Empty;
11640
11641 begin
11642 -- Climb the parent chain looking for an enclosing pragma
11643
11644 Par := N;
11645 while Present (Par) loop
11646 if Nkind (Par) = N_Pragma then
11647 Prag := Par;
11648 exit;
11649
11650 -- Precondition-like pragmas are expanded into if statements, check
11651 -- the original node instead.
11652
11653 elsif Nkind (Original_Node (Par)) = N_Pragma then
11654 Prag := Original_Node (Par);
11655 exit;
11656
11657 -- The expansion of attribute 'Old generates a constant to capture
11658 -- the result of the prefix. If the parent traversal reaches
11659 -- one of these constants, then the node technically came from a
11660 -- postcondition-like pragma. Note that the Ekind is not tested here
11661 -- because N may be the expression of an object declaration which is
11662 -- currently being analyzed. Such objects carry Ekind of E_Void.
11663
11664 elsif Nkind (Par) = N_Object_Declaration
11665 and then Constant_Present (Par)
11666 and then Stores_Attribute_Old_Prefix (Defining_Entity (Par))
11667 then
11668 return True;
11669
11670 -- Prevent the search from going too far
11671
11672 elsif Is_Body_Or_Package_Declaration (Par) then
11673 return False;
11674 end if;
11675
11676 Par := Parent (Par);
11677 end loop;
11678
11679 return
11680 Present (Prag)
11681 and then Assertion_Expression_Pragma (Get_Pragma_Id (Prag));
11682 end In_Assertion_Expression_Pragma;
11683
11684 ----------------------
11685 -- In_Generic_Scope --
11686 ----------------------
11687
11688 function In_Generic_Scope (E : Entity_Id) return Boolean is
11689 S : Entity_Id;
11690
11691 begin
11692 S := Scope (E);
11693 while Present (S) and then S /= Standard_Standard loop
11694 if Is_Generic_Unit (S) then
11695 return True;
11696 end if;
11697
11698 S := Scope (S);
11699 end loop;
11700
11701 return False;
11702 end In_Generic_Scope;
11703
11704 -----------------
11705 -- In_Instance --
11706 -----------------
11707
11708 function In_Instance return Boolean is
11709 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
11710 S : Entity_Id;
11711
11712 begin
11713 S := Current_Scope;
11714 while Present (S) and then S /= Standard_Standard loop
11715 if Is_Generic_Instance (S) then
11716
11717 -- A child instance is always compiled in the context of a parent
11718 -- instance. Nevertheless, the actuals are not analyzed in an
11719 -- instance context. We detect this case by examining the current
11720 -- compilation unit, which must be a child instance, and checking
11721 -- that it is not currently on the scope stack.
11722
11723 if Is_Child_Unit (Curr_Unit)
11724 and then Nkind (Unit (Cunit (Current_Sem_Unit))) =
11725 N_Package_Instantiation
11726 and then not In_Open_Scopes (Curr_Unit)
11727 then
11728 return False;
11729 else
11730 return True;
11731 end if;
11732 end if;
11733
11734 S := Scope (S);
11735 end loop;
11736
11737 return False;
11738 end In_Instance;
11739
11740 ----------------------
11741 -- In_Instance_Body --
11742 ----------------------
11743
11744 function In_Instance_Body return Boolean is
11745 S : Entity_Id;
11746
11747 begin
11748 S := Current_Scope;
11749 while Present (S) and then S /= Standard_Standard loop
11750 if Ekind_In (S, E_Function, E_Procedure)
11751 and then Is_Generic_Instance (S)
11752 then
11753 return True;
11754
11755 elsif Ekind (S) = E_Package
11756 and then In_Package_Body (S)
11757 and then Is_Generic_Instance (S)
11758 then
11759 return True;
11760 end if;
11761
11762 S := Scope (S);
11763 end loop;
11764
11765 return False;
11766 end In_Instance_Body;
11767
11768 -----------------------------
11769 -- In_Instance_Not_Visible --
11770 -----------------------------
11771
11772 function In_Instance_Not_Visible return Boolean is
11773 S : Entity_Id;
11774
11775 begin
11776 S := Current_Scope;
11777 while Present (S) and then S /= Standard_Standard loop
11778 if Ekind_In (S, E_Function, E_Procedure)
11779 and then Is_Generic_Instance (S)
11780 then
11781 return True;
11782
11783 elsif Ekind (S) = E_Package
11784 and then (In_Package_Body (S) or else In_Private_Part (S))
11785 and then Is_Generic_Instance (S)
11786 then
11787 return True;
11788 end if;
11789
11790 S := Scope (S);
11791 end loop;
11792
11793 return False;
11794 end In_Instance_Not_Visible;
11795
11796 ------------------------------
11797 -- In_Instance_Visible_Part --
11798 ------------------------------
11799
11800 function In_Instance_Visible_Part
11801 (Id : Entity_Id := Current_Scope) return Boolean
11802 is
11803 Inst : Entity_Id;
11804
11805 begin
11806 Inst := Id;
11807 while Present (Inst) and then Inst /= Standard_Standard loop
11808 if Ekind (Inst) = E_Package
11809 and then Is_Generic_Instance (Inst)
11810 and then not In_Package_Body (Inst)
11811 and then not In_Private_Part (Inst)
11812 then
11813 return True;
11814 end if;
11815
11816 Inst := Scope (Inst);
11817 end loop;
11818
11819 return False;
11820 end In_Instance_Visible_Part;
11821
11822 ---------------------
11823 -- In_Package_Body --
11824 ---------------------
11825
11826 function In_Package_Body return Boolean is
11827 S : Entity_Id;
11828
11829 begin
11830 S := Current_Scope;
11831 while Present (S) and then S /= Standard_Standard loop
11832 if Ekind (S) = E_Package and then In_Package_Body (S) then
11833 return True;
11834 else
11835 S := Scope (S);
11836 end if;
11837 end loop;
11838
11839 return False;
11840 end In_Package_Body;
11841
11842 --------------------------
11843 -- In_Pragma_Expression --
11844 --------------------------
11845
11846 function In_Pragma_Expression (N : Node_Id; Nam : Name_Id) return Boolean is
11847 P : Node_Id;
11848 begin
11849 P := Parent (N);
11850 loop
11851 if No (P) then
11852 return False;
11853 elsif Nkind (P) = N_Pragma and then Pragma_Name (P) = Nam then
11854 return True;
11855 else
11856 P := Parent (P);
11857 end if;
11858 end loop;
11859 end In_Pragma_Expression;
11860
11861 ---------------------------
11862 -- In_Pre_Post_Condition --
11863 ---------------------------
11864
11865 function In_Pre_Post_Condition (N : Node_Id) return Boolean is
11866 Par : Node_Id;
11867 Prag : Node_Id := Empty;
11868 Prag_Id : Pragma_Id;
11869
11870 begin
11871 -- Climb the parent chain looking for an enclosing pragma
11872
11873 Par := N;
11874 while Present (Par) loop
11875 if Nkind (Par) = N_Pragma then
11876 Prag := Par;
11877 exit;
11878
11879 -- Prevent the search from going too far
11880
11881 elsif Is_Body_Or_Package_Declaration (Par) then
11882 exit;
11883 end if;
11884
11885 Par := Parent (Par);
11886 end loop;
11887
11888 if Present (Prag) then
11889 Prag_Id := Get_Pragma_Id (Prag);
11890
11891 return
11892 Prag_Id = Pragma_Post
11893 or else Prag_Id = Pragma_Post_Class
11894 or else Prag_Id = Pragma_Postcondition
11895 or else Prag_Id = Pragma_Pre
11896 or else Prag_Id = Pragma_Pre_Class
11897 or else Prag_Id = Pragma_Precondition;
11898
11899 -- Otherwise the node is not enclosed by a pre/postcondition pragma
11900
11901 else
11902 return False;
11903 end if;
11904 end In_Pre_Post_Condition;
11905
11906 -------------------------------------
11907 -- In_Reverse_Storage_Order_Object --
11908 -------------------------------------
11909
11910 function In_Reverse_Storage_Order_Object (N : Node_Id) return Boolean is
11911 Pref : Node_Id;
11912 Btyp : Entity_Id := Empty;
11913
11914 begin
11915 -- Climb up indexed components
11916
11917 Pref := N;
11918 loop
11919 case Nkind (Pref) is
11920 when N_Selected_Component =>
11921 Pref := Prefix (Pref);
11922 exit;
11923
11924 when N_Indexed_Component =>
11925 Pref := Prefix (Pref);
11926
11927 when others =>
11928 Pref := Empty;
11929 exit;
11930 end case;
11931 end loop;
11932
11933 if Present (Pref) then
11934 Btyp := Base_Type (Etype (Pref));
11935 end if;
11936
11937 return Present (Btyp)
11938 and then (Is_Record_Type (Btyp) or else Is_Array_Type (Btyp))
11939 and then Reverse_Storage_Order (Btyp);
11940 end In_Reverse_Storage_Order_Object;
11941
11942 --------------------------------------
11943 -- In_Subprogram_Or_Concurrent_Unit --
11944 --------------------------------------
11945
11946 function In_Subprogram_Or_Concurrent_Unit return Boolean is
11947 E : Entity_Id;
11948 K : Entity_Kind;
11949
11950 begin
11951 -- Use scope chain to check successively outer scopes
11952
11953 E := Current_Scope;
11954 loop
11955 K := Ekind (E);
11956
11957 if K in Subprogram_Kind
11958 or else K in Concurrent_Kind
11959 or else K in Generic_Subprogram_Kind
11960 then
11961 return True;
11962
11963 elsif E = Standard_Standard then
11964 return False;
11965 end if;
11966
11967 E := Scope (E);
11968 end loop;
11969 end In_Subprogram_Or_Concurrent_Unit;
11970
11971 ----------------
11972 -- In_Subtree --
11973 ----------------
11974
11975 function In_Subtree (N : Node_Id; Root : Node_Id) return Boolean is
11976 Curr : Node_Id;
11977
11978 begin
11979 Curr := N;
11980 while Present (Curr) loop
11981 if Curr = Root then
11982 return True;
11983 end if;
11984
11985 Curr := Parent (Curr);
11986 end loop;
11987
11988 return False;
11989 end In_Subtree;
11990
11991 ----------------
11992 -- In_Subtree --
11993 ----------------
11994
11995 function In_Subtree
11996 (N : Node_Id;
11997 Root1 : Node_Id;
11998 Root2 : Node_Id) return Boolean
11999 is
12000 Curr : Node_Id;
12001
12002 begin
12003 Curr := N;
12004 while Present (Curr) loop
12005 if Curr = Root1 or else Curr = Root2 then
12006 return True;
12007 end if;
12008
12009 Curr := Parent (Curr);
12010 end loop;
12011
12012 return False;
12013 end In_Subtree;
12014
12015 ---------------------
12016 -- In_Visible_Part --
12017 ---------------------
12018
12019 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
12020 begin
12021 return Is_Package_Or_Generic_Package (Scope_Id)
12022 and then In_Open_Scopes (Scope_Id)
12023 and then not In_Package_Body (Scope_Id)
12024 and then not In_Private_Part (Scope_Id);
12025 end In_Visible_Part;
12026
12027 --------------------------------
12028 -- Incomplete_Or_Partial_View --
12029 --------------------------------
12030
12031 function Incomplete_Or_Partial_View (Id : Entity_Id) return Entity_Id is
12032 function Inspect_Decls
12033 (Decls : List_Id;
12034 Taft : Boolean := False) return Entity_Id;
12035 -- Check whether a declarative region contains the incomplete or partial
12036 -- view of Id.
12037
12038 -------------------
12039 -- Inspect_Decls --
12040 -------------------
12041
12042 function Inspect_Decls
12043 (Decls : List_Id;
12044 Taft : Boolean := False) return Entity_Id
12045 is
12046 Decl : Node_Id;
12047 Match : Node_Id;
12048
12049 begin
12050 Decl := First (Decls);
12051 while Present (Decl) loop
12052 Match := Empty;
12053
12054 -- The partial view of a Taft-amendment type is an incomplete
12055 -- type.
12056
12057 if Taft then
12058 if Nkind (Decl) = N_Incomplete_Type_Declaration then
12059 Match := Defining_Identifier (Decl);
12060 end if;
12061
12062 -- Otherwise look for a private type whose full view matches the
12063 -- input type. Note that this checks full_type_declaration nodes
12064 -- to account for derivations from a private type where the type
12065 -- declaration hold the partial view and the full view is an
12066 -- itype.
12067
12068 elsif Nkind_In (Decl, N_Full_Type_Declaration,
12069 N_Private_Extension_Declaration,
12070 N_Private_Type_Declaration)
12071 then
12072 Match := Defining_Identifier (Decl);
12073 end if;
12074
12075 -- Guard against unanalyzed entities
12076
12077 if Present (Match)
12078 and then Is_Type (Match)
12079 and then Present (Full_View (Match))
12080 and then Full_View (Match) = Id
12081 then
12082 return Match;
12083 end if;
12084
12085 Next (Decl);
12086 end loop;
12087
12088 return Empty;
12089 end Inspect_Decls;
12090
12091 -- Local variables
12092
12093 Prev : Entity_Id;
12094
12095 -- Start of processing for Incomplete_Or_Partial_View
12096
12097 begin
12098 -- Deferred constant or incomplete type case
12099
12100 Prev := Current_Entity_In_Scope (Id);
12101
12102 if Present (Prev)
12103 and then (Is_Incomplete_Type (Prev) or else Ekind (Prev) = E_Constant)
12104 and then Present (Full_View (Prev))
12105 and then Full_View (Prev) = Id
12106 then
12107 return Prev;
12108 end if;
12109
12110 -- Private or Taft amendment type case
12111
12112 declare
12113 Pkg : constant Entity_Id := Scope (Id);
12114 Pkg_Decl : Node_Id := Pkg;
12115
12116 begin
12117 if Present (Pkg)
12118 and then Ekind_In (Pkg, E_Generic_Package, E_Package)
12119 then
12120 while Nkind (Pkg_Decl) /= N_Package_Specification loop
12121 Pkg_Decl := Parent (Pkg_Decl);
12122 end loop;
12123
12124 -- It is knows that Typ has a private view, look for it in the
12125 -- visible declarations of the enclosing scope. A special case
12126 -- of this is when the two views have been exchanged - the full
12127 -- appears earlier than the private.
12128
12129 if Has_Private_Declaration (Id) then
12130 Prev := Inspect_Decls (Visible_Declarations (Pkg_Decl));
12131
12132 -- Exchanged view case, look in the private declarations
12133
12134 if No (Prev) then
12135 Prev := Inspect_Decls (Private_Declarations (Pkg_Decl));
12136 end if;
12137
12138 return Prev;
12139
12140 -- Otherwise if this is the package body, then Typ is a potential
12141 -- Taft amendment type. The incomplete view should be located in
12142 -- the private declarations of the enclosing scope.
12143
12144 elsif In_Package_Body (Pkg) then
12145 return Inspect_Decls (Private_Declarations (Pkg_Decl), True);
12146 end if;
12147 end if;
12148 end;
12149
12150 -- The type has no incomplete or private view
12151
12152 return Empty;
12153 end Incomplete_Or_Partial_View;
12154
12155 ----------------------------------
12156 -- Indexed_Component_Bit_Offset --
12157 ----------------------------------
12158
12159 function Indexed_Component_Bit_Offset (N : Node_Id) return Uint is
12160 Exp : constant Node_Id := First (Expressions (N));
12161 Typ : constant Entity_Id := Etype (Prefix (N));
12162 Off : constant Uint := Component_Size (Typ);
12163 Ind : Node_Id;
12164
12165 begin
12166 -- Return early if the component size is not known or variable
12167
12168 if Off = No_Uint or else Off < Uint_0 then
12169 return No_Uint;
12170 end if;
12171
12172 -- Deal with the degenerate case of an empty component
12173
12174 if Off = Uint_0 then
12175 return Off;
12176 end if;
12177
12178 -- Check that both the index value and the low bound are known
12179
12180 if not Compile_Time_Known_Value (Exp) then
12181 return No_Uint;
12182 end if;
12183
12184 Ind := First_Index (Typ);
12185 if No (Ind) then
12186 return No_Uint;
12187 end if;
12188
12189 if Nkind (Ind) = N_Subtype_Indication then
12190 Ind := Constraint (Ind);
12191
12192 if Nkind (Ind) = N_Range_Constraint then
12193 Ind := Range_Expression (Ind);
12194 end if;
12195 end if;
12196
12197 if Nkind (Ind) /= N_Range
12198 or else not Compile_Time_Known_Value (Low_Bound (Ind))
12199 then
12200 return No_Uint;
12201 end if;
12202
12203 -- Return the scaled offset
12204
12205 return Off * (Expr_Value (Exp) - Expr_Value (Low_Bound ((Ind))));
12206 end Indexed_Component_Bit_Offset;
12207
12208 ----------------------------
12209 -- Inherit_Rep_Item_Chain --
12210 ----------------------------
12211
12212 procedure Inherit_Rep_Item_Chain (Typ : Entity_Id; From_Typ : Entity_Id) is
12213 Item : Node_Id;
12214 Next_Item : Node_Id;
12215
12216 begin
12217 -- There are several inheritance scenarios to consider depending on
12218 -- whether both types have rep item chains and whether the destination
12219 -- type already inherits part of the source type's rep item chain.
12220
12221 -- 1) The source type lacks a rep item chain
12222 -- From_Typ ---> Empty
12223 --
12224 -- Typ --------> Item (or Empty)
12225
12226 -- In this case inheritance cannot take place because there are no items
12227 -- to inherit.
12228
12229 -- 2) The destination type lacks a rep item chain
12230 -- From_Typ ---> Item ---> ...
12231 --
12232 -- Typ --------> Empty
12233
12234 -- Inheritance takes place by setting the First_Rep_Item of the
12235 -- destination type to the First_Rep_Item of the source type.
12236 -- From_Typ ---> Item ---> ...
12237 -- ^
12238 -- Typ -----------+
12239
12240 -- 3.1) Both source and destination types have at least one rep item.
12241 -- The destination type does NOT inherit a rep item from the source
12242 -- type.
12243 -- From_Typ ---> Item ---> Item
12244 --
12245 -- Typ --------> Item ---> Item
12246
12247 -- Inheritance takes place by setting the Next_Rep_Item of the last item
12248 -- of the destination type to the First_Rep_Item of the source type.
12249 -- From_Typ -------------------> Item ---> Item
12250 -- ^
12251 -- Typ --------> Item ---> Item --+
12252
12253 -- 3.2) Both source and destination types have at least one rep item.
12254 -- The destination type DOES inherit part of the rep item chain of the
12255 -- source type.
12256 -- From_Typ ---> Item ---> Item ---> Item
12257 -- ^
12258 -- Typ --------> Item ------+
12259
12260 -- This rare case arises when the full view of a private extension must
12261 -- inherit the rep item chain from the full view of its parent type and
12262 -- the full view of the parent type contains extra rep items. Currently
12263 -- only invariants may lead to such form of inheritance.
12264
12265 -- type From_Typ is tagged private
12266 -- with Type_Invariant'Class => Item_2;
12267
12268 -- type Typ is new From_Typ with private
12269 -- with Type_Invariant => Item_4;
12270
12271 -- At this point the rep item chains contain the following items
12272
12273 -- From_Typ -----------> Item_2 ---> Item_3
12274 -- ^
12275 -- Typ --------> Item_4 --+
12276
12277 -- The full views of both types may introduce extra invariants
12278
12279 -- type From_Typ is tagged null record
12280 -- with Type_Invariant => Item_1;
12281
12282 -- type Typ is new From_Typ with null record;
12283
12284 -- The full view of Typ would have to inherit any new rep items added to
12285 -- the full view of From_Typ.
12286
12287 -- From_Typ -----------> Item_1 ---> Item_2 ---> Item_3
12288 -- ^
12289 -- Typ --------> Item_4 --+
12290
12291 -- To achieve this form of inheritance, the destination type must first
12292 -- sever the link between its own rep chain and that of the source type,
12293 -- then inheritance 3.1 takes place.
12294
12295 -- Case 1: The source type lacks a rep item chain
12296
12297 if No (First_Rep_Item (From_Typ)) then
12298 return;
12299
12300 -- Case 2: The destination type lacks a rep item chain
12301
12302 elsif No (First_Rep_Item (Typ)) then
12303 Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ));
12304
12305 -- Case 3: Both the source and destination types have at least one rep
12306 -- item. Traverse the rep item chain of the destination type to find the
12307 -- last rep item.
12308
12309 else
12310 Item := Empty;
12311 Next_Item := First_Rep_Item (Typ);
12312 while Present (Next_Item) loop
12313
12314 -- Detect a link between the destination type's rep chain and that
12315 -- of the source type. There are two possibilities:
12316
12317 -- Variant 1
12318 -- Next_Item
12319 -- V
12320 -- From_Typ ---> Item_1 --->
12321 -- ^
12322 -- Typ -----------+
12323 --
12324 -- Item is Empty
12325
12326 -- Variant 2
12327 -- Next_Item
12328 -- V
12329 -- From_Typ ---> Item_1 ---> Item_2 --->
12330 -- ^
12331 -- Typ --------> Item_3 ------+
12332 -- ^
12333 -- Item
12334
12335 if Has_Rep_Item (From_Typ, Next_Item) then
12336 exit;
12337 end if;
12338
12339 Item := Next_Item;
12340 Next_Item := Next_Rep_Item (Next_Item);
12341 end loop;
12342
12343 -- Inherit the source type's rep item chain
12344
12345 if Present (Item) then
12346 Set_Next_Rep_Item (Item, First_Rep_Item (From_Typ));
12347 else
12348 Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ));
12349 end if;
12350 end if;
12351 end Inherit_Rep_Item_Chain;
12352
12353 ---------------------------------
12354 -- Insert_Explicit_Dereference --
12355 ---------------------------------
12356
12357 procedure Insert_Explicit_Dereference (N : Node_Id) is
12358 New_Prefix : constant Node_Id := Relocate_Node (N);
12359 Ent : Entity_Id := Empty;
12360 Pref : Node_Id;
12361 I : Interp_Index;
12362 It : Interp;
12363 T : Entity_Id;
12364
12365 begin
12366 Save_Interps (N, New_Prefix);
12367
12368 Rewrite (N,
12369 Make_Explicit_Dereference (Sloc (Parent (N)),
12370 Prefix => New_Prefix));
12371
12372 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
12373
12374 if Is_Overloaded (New_Prefix) then
12375
12376 -- The dereference is also overloaded, and its interpretations are
12377 -- the designated types of the interpretations of the original node.
12378
12379 Set_Etype (N, Any_Type);
12380
12381 Get_First_Interp (New_Prefix, I, It);
12382 while Present (It.Nam) loop
12383 T := It.Typ;
12384
12385 if Is_Access_Type (T) then
12386 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
12387 end if;
12388
12389 Get_Next_Interp (I, It);
12390 end loop;
12391
12392 End_Interp_List;
12393
12394 else
12395 -- Prefix is unambiguous: mark the original prefix (which might
12396 -- Come_From_Source) as a reference, since the new (relocated) one
12397 -- won't be taken into account.
12398
12399 if Is_Entity_Name (New_Prefix) then
12400 Ent := Entity (New_Prefix);
12401 Pref := New_Prefix;
12402
12403 -- For a retrieval of a subcomponent of some composite object,
12404 -- retrieve the ultimate entity if there is one.
12405
12406 elsif Nkind_In (New_Prefix, N_Selected_Component,
12407 N_Indexed_Component)
12408 then
12409 Pref := Prefix (New_Prefix);
12410 while Present (Pref)
12411 and then Nkind_In (Pref, N_Selected_Component,
12412 N_Indexed_Component)
12413 loop
12414 Pref := Prefix (Pref);
12415 end loop;
12416
12417 if Present (Pref) and then Is_Entity_Name (Pref) then
12418 Ent := Entity (Pref);
12419 end if;
12420 end if;
12421
12422 -- Place the reference on the entity node
12423
12424 if Present (Ent) then
12425 Generate_Reference (Ent, Pref);
12426 end if;
12427 end if;
12428 end Insert_Explicit_Dereference;
12429
12430 ------------------------------------------
12431 -- Inspect_Deferred_Constant_Completion --
12432 ------------------------------------------
12433
12434 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
12435 Decl : Node_Id;
12436
12437 begin
12438 Decl := First (Decls);
12439 while Present (Decl) loop
12440
12441 -- Deferred constant signature
12442
12443 if Nkind (Decl) = N_Object_Declaration
12444 and then Constant_Present (Decl)
12445 and then No (Expression (Decl))
12446
12447 -- No need to check internally generated constants
12448
12449 and then Comes_From_Source (Decl)
12450
12451 -- The constant is not completed. A full object declaration or a
12452 -- pragma Import complete a deferred constant.
12453
12454 and then not Has_Completion (Defining_Identifier (Decl))
12455 then
12456 Error_Msg_N
12457 ("constant declaration requires initialization expression",
12458 Defining_Identifier (Decl));
12459 end if;
12460
12461 Decl := Next (Decl);
12462 end loop;
12463 end Inspect_Deferred_Constant_Completion;
12464
12465 -----------------------------
12466 -- Install_Generic_Formals --
12467 -----------------------------
12468
12469 procedure Install_Generic_Formals (Subp_Id : Entity_Id) is
12470 E : Entity_Id;
12471
12472 begin
12473 pragma Assert (Is_Generic_Subprogram (Subp_Id));
12474
12475 E := First_Entity (Subp_Id);
12476 while Present (E) loop
12477 Install_Entity (E);
12478 Next_Entity (E);
12479 end loop;
12480 end Install_Generic_Formals;
12481
12482 ------------------------
12483 -- Install_SPARK_Mode --
12484 ------------------------
12485
12486 procedure Install_SPARK_Mode (Mode : SPARK_Mode_Type; Prag : Node_Id) is
12487 begin
12488 SPARK_Mode := Mode;
12489 SPARK_Mode_Pragma := Prag;
12490 end Install_SPARK_Mode;
12491
12492 -----------------------------
12493 -- Is_Actual_Out_Parameter --
12494 -----------------------------
12495
12496 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
12497 Formal : Entity_Id;
12498 Call : Node_Id;
12499 begin
12500 Find_Actual (N, Formal, Call);
12501 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
12502 end Is_Actual_Out_Parameter;
12503
12504 -------------------------
12505 -- Is_Actual_Parameter --
12506 -------------------------
12507
12508 function Is_Actual_Parameter (N : Node_Id) return Boolean is
12509 PK : constant Node_Kind := Nkind (Parent (N));
12510
12511 begin
12512 case PK is
12513 when N_Parameter_Association =>
12514 return N = Explicit_Actual_Parameter (Parent (N));
12515
12516 when N_Subprogram_Call =>
12517 return Is_List_Member (N)
12518 and then
12519 List_Containing (N) = Parameter_Associations (Parent (N));
12520
12521 when others =>
12522 return False;
12523 end case;
12524 end Is_Actual_Parameter;
12525
12526 --------------------------------
12527 -- Is_Actual_Tagged_Parameter --
12528 --------------------------------
12529
12530 function Is_Actual_Tagged_Parameter (N : Node_Id) return Boolean is
12531 Formal : Entity_Id;
12532 Call : Node_Id;
12533 begin
12534 Find_Actual (N, Formal, Call);
12535 return Present (Formal) and then Is_Tagged_Type (Etype (Formal));
12536 end Is_Actual_Tagged_Parameter;
12537
12538 ---------------------
12539 -- Is_Aliased_View --
12540 ---------------------
12541
12542 function Is_Aliased_View (Obj : Node_Id) return Boolean is
12543 E : Entity_Id;
12544
12545 begin
12546 if Is_Entity_Name (Obj) then
12547 E := Entity (Obj);
12548
12549 return
12550 (Is_Object (E)
12551 and then
12552 (Is_Aliased (E)
12553 or else (Present (Renamed_Object (E))
12554 and then Is_Aliased_View (Renamed_Object (E)))))
12555
12556 or else ((Is_Formal (E) or else Is_Formal_Object (E))
12557 and then Is_Tagged_Type (Etype (E)))
12558
12559 or else (Is_Concurrent_Type (E) and then In_Open_Scopes (E))
12560
12561 -- Current instance of type, either directly or as rewritten
12562 -- reference to the current object.
12563
12564 or else (Is_Entity_Name (Original_Node (Obj))
12565 and then Present (Entity (Original_Node (Obj)))
12566 and then Is_Type (Entity (Original_Node (Obj))))
12567
12568 or else (Is_Type (E) and then E = Current_Scope)
12569
12570 or else (Is_Incomplete_Or_Private_Type (E)
12571 and then Full_View (E) = Current_Scope)
12572
12573 -- Ada 2012 AI05-0053: the return object of an extended return
12574 -- statement is aliased if its type is immutably limited.
12575
12576 or else (Is_Return_Object (E)
12577 and then Is_Limited_View (Etype (E)));
12578
12579 elsif Nkind (Obj) = N_Selected_Component then
12580 return Is_Aliased (Entity (Selector_Name (Obj)));
12581
12582 elsif Nkind (Obj) = N_Indexed_Component then
12583 return Has_Aliased_Components (Etype (Prefix (Obj)))
12584 or else
12585 (Is_Access_Type (Etype (Prefix (Obj)))
12586 and then Has_Aliased_Components
12587 (Designated_Type (Etype (Prefix (Obj)))));
12588
12589 elsif Nkind_In (Obj, N_Unchecked_Type_Conversion, N_Type_Conversion) then
12590 return Is_Tagged_Type (Etype (Obj))
12591 and then Is_Aliased_View (Expression (Obj));
12592
12593 elsif Nkind (Obj) = N_Explicit_Dereference then
12594 return Nkind (Original_Node (Obj)) /= N_Function_Call;
12595
12596 else
12597 return False;
12598 end if;
12599 end Is_Aliased_View;
12600
12601 -------------------------
12602 -- Is_Ancestor_Package --
12603 -------------------------
12604
12605 function Is_Ancestor_Package
12606 (E1 : Entity_Id;
12607 E2 : Entity_Id) return Boolean
12608 is
12609 Par : Entity_Id;
12610
12611 begin
12612 Par := E2;
12613 while Present (Par) and then Par /= Standard_Standard loop
12614 if Par = E1 then
12615 return True;
12616 end if;
12617
12618 Par := Scope (Par);
12619 end loop;
12620
12621 return False;
12622 end Is_Ancestor_Package;
12623
12624 ----------------------
12625 -- Is_Atomic_Object --
12626 ----------------------
12627
12628 function Is_Atomic_Object (N : Node_Id) return Boolean is
12629
12630 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
12631 -- Determines if given object has atomic components
12632
12633 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
12634 -- If prefix is an implicit dereference, examine designated type
12635
12636 ----------------------
12637 -- Is_Atomic_Prefix --
12638 ----------------------
12639
12640 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
12641 begin
12642 if Is_Access_Type (Etype (N)) then
12643 return
12644 Has_Atomic_Components (Designated_Type (Etype (N)));
12645 else
12646 return Object_Has_Atomic_Components (N);
12647 end if;
12648 end Is_Atomic_Prefix;
12649
12650 ----------------------------------
12651 -- Object_Has_Atomic_Components --
12652 ----------------------------------
12653
12654 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
12655 begin
12656 if Has_Atomic_Components (Etype (N))
12657 or else Is_Atomic (Etype (N))
12658 then
12659 return True;
12660
12661 elsif Is_Entity_Name (N)
12662 and then (Has_Atomic_Components (Entity (N))
12663 or else Is_Atomic (Entity (N)))
12664 then
12665 return True;
12666
12667 elsif Nkind (N) = N_Selected_Component
12668 and then Is_Atomic (Entity (Selector_Name (N)))
12669 then
12670 return True;
12671
12672 elsif Nkind (N) = N_Indexed_Component
12673 or else Nkind (N) = N_Selected_Component
12674 then
12675 return Is_Atomic_Prefix (Prefix (N));
12676
12677 else
12678 return False;
12679 end if;
12680 end Object_Has_Atomic_Components;
12681
12682 -- Start of processing for Is_Atomic_Object
12683
12684 begin
12685 -- Predicate is not relevant to subprograms
12686
12687 if Is_Entity_Name (N) and then Is_Overloadable (Entity (N)) then
12688 return False;
12689
12690 elsif Is_Atomic (Etype (N))
12691 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
12692 then
12693 return True;
12694
12695 elsif Nkind (N) = N_Selected_Component
12696 and then Is_Atomic (Entity (Selector_Name (N)))
12697 then
12698 return True;
12699
12700 elsif Nkind (N) = N_Indexed_Component
12701 or else Nkind (N) = N_Selected_Component
12702 then
12703 return Is_Atomic_Prefix (Prefix (N));
12704
12705 else
12706 return False;
12707 end if;
12708 end Is_Atomic_Object;
12709
12710 -----------------------------
12711 -- Is_Atomic_Or_VFA_Object --
12712 -----------------------------
12713
12714 function Is_Atomic_Or_VFA_Object (N : Node_Id) return Boolean is
12715 begin
12716 return Is_Atomic_Object (N)
12717 or else (Is_Object_Reference (N)
12718 and then Is_Entity_Name (N)
12719 and then (Is_Volatile_Full_Access (Entity (N))
12720 or else
12721 Is_Volatile_Full_Access (Etype (Entity (N)))));
12722 end Is_Atomic_Or_VFA_Object;
12723
12724 -------------------------
12725 -- Is_Attribute_Result --
12726 -------------------------
12727
12728 function Is_Attribute_Result (N : Node_Id) return Boolean is
12729 begin
12730 return Nkind (N) = N_Attribute_Reference
12731 and then Attribute_Name (N) = Name_Result;
12732 end Is_Attribute_Result;
12733
12734 -------------------------
12735 -- Is_Attribute_Update --
12736 -------------------------
12737
12738 function Is_Attribute_Update (N : Node_Id) return Boolean is
12739 begin
12740 return Nkind (N) = N_Attribute_Reference
12741 and then Attribute_Name (N) = Name_Update;
12742 end Is_Attribute_Update;
12743
12744 ------------------------------------
12745 -- Is_Body_Or_Package_Declaration --
12746 ------------------------------------
12747
12748 function Is_Body_Or_Package_Declaration (N : Node_Id) return Boolean is
12749 begin
12750 return Nkind_In (N, N_Entry_Body,
12751 N_Package_Body,
12752 N_Package_Declaration,
12753 N_Protected_Body,
12754 N_Subprogram_Body,
12755 N_Task_Body);
12756 end Is_Body_Or_Package_Declaration;
12757
12758 -----------------------
12759 -- Is_Bounded_String --
12760 -----------------------
12761
12762 function Is_Bounded_String (T : Entity_Id) return Boolean is
12763 Under : constant Entity_Id := Underlying_Type (Root_Type (T));
12764
12765 begin
12766 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
12767 -- Super_String, or one of the [Wide_]Wide_ versions. This will
12768 -- be True for all the Bounded_String types in instances of the
12769 -- Generic_Bounded_Length generics, and for types derived from those.
12770
12771 return Present (Under)
12772 and then (Is_RTE (Root_Type (Under), RO_SU_Super_String) or else
12773 Is_RTE (Root_Type (Under), RO_WI_Super_String) or else
12774 Is_RTE (Root_Type (Under), RO_WW_Super_String));
12775 end Is_Bounded_String;
12776
12777 ---------------------
12778 -- Is_CCT_Instance --
12779 ---------------------
12780
12781 function Is_CCT_Instance
12782 (Ref_Id : Entity_Id;
12783 Context_Id : Entity_Id) return Boolean
12784 is
12785 begin
12786 pragma Assert (Ekind_In (Ref_Id, E_Protected_Type, E_Task_Type));
12787
12788 if Is_Single_Task_Object (Context_Id) then
12789 return Scope_Within_Or_Same (Etype (Context_Id), Ref_Id);
12790
12791 else
12792 pragma Assert (Ekind_In (Context_Id, E_Entry,
12793 E_Entry_Family,
12794 E_Function,
12795 E_Package,
12796 E_Procedure,
12797 E_Protected_Type,
12798 E_Task_Type));
12799
12800 return Scope_Within_Or_Same (Context_Id, Ref_Id);
12801 end if;
12802 end Is_CCT_Instance;
12803
12804 -------------------------
12805 -- Is_Child_Or_Sibling --
12806 -------------------------
12807
12808 function Is_Child_Or_Sibling
12809 (Pack_1 : Entity_Id;
12810 Pack_2 : Entity_Id) return Boolean
12811 is
12812 function Distance_From_Standard (Pack : Entity_Id) return Nat;
12813 -- Given an arbitrary package, return the number of "climbs" necessary
12814 -- to reach scope Standard_Standard.
12815
12816 procedure Equalize_Depths
12817 (Pack : in out Entity_Id;
12818 Depth : in out Nat;
12819 Depth_To_Reach : Nat);
12820 -- Given an arbitrary package, its depth and a target depth to reach,
12821 -- climb the scope chain until the said depth is reached. The pointer
12822 -- to the package and its depth a modified during the climb.
12823
12824 ----------------------------
12825 -- Distance_From_Standard --
12826 ----------------------------
12827
12828 function Distance_From_Standard (Pack : Entity_Id) return Nat is
12829 Dist : Nat;
12830 Scop : Entity_Id;
12831
12832 begin
12833 Dist := 0;
12834 Scop := Pack;
12835 while Present (Scop) and then Scop /= Standard_Standard loop
12836 Dist := Dist + 1;
12837 Scop := Scope (Scop);
12838 end loop;
12839
12840 return Dist;
12841 end Distance_From_Standard;
12842
12843 ---------------------
12844 -- Equalize_Depths --
12845 ---------------------
12846
12847 procedure Equalize_Depths
12848 (Pack : in out Entity_Id;
12849 Depth : in out Nat;
12850 Depth_To_Reach : Nat)
12851 is
12852 begin
12853 -- The package must be at a greater or equal depth
12854
12855 if Depth < Depth_To_Reach then
12856 raise Program_Error;
12857 end if;
12858
12859 -- Climb the scope chain until the desired depth is reached
12860
12861 while Present (Pack) and then Depth /= Depth_To_Reach loop
12862 Pack := Scope (Pack);
12863 Depth := Depth - 1;
12864 end loop;
12865 end Equalize_Depths;
12866
12867 -- Local variables
12868
12869 P_1 : Entity_Id := Pack_1;
12870 P_1_Child : Boolean := False;
12871 P_1_Depth : Nat := Distance_From_Standard (P_1);
12872 P_2 : Entity_Id := Pack_2;
12873 P_2_Child : Boolean := False;
12874 P_2_Depth : Nat := Distance_From_Standard (P_2);
12875
12876 -- Start of processing for Is_Child_Or_Sibling
12877
12878 begin
12879 pragma Assert
12880 (Ekind (Pack_1) = E_Package and then Ekind (Pack_2) = E_Package);
12881
12882 -- Both packages denote the same entity, therefore they cannot be
12883 -- children or siblings.
12884
12885 if P_1 = P_2 then
12886 return False;
12887
12888 -- One of the packages is at a deeper level than the other. Note that
12889 -- both may still come from different hierarchies.
12890
12891 -- (root) P_2
12892 -- / \ :
12893 -- X P_2 or X
12894 -- : :
12895 -- P_1 P_1
12896
12897 elsif P_1_Depth > P_2_Depth then
12898 Equalize_Depths
12899 (Pack => P_1,
12900 Depth => P_1_Depth,
12901 Depth_To_Reach => P_2_Depth);
12902 P_1_Child := True;
12903
12904 -- (root) P_1
12905 -- / \ :
12906 -- P_1 X or X
12907 -- : :
12908 -- P_2 P_2
12909
12910 elsif P_2_Depth > P_1_Depth then
12911 Equalize_Depths
12912 (Pack => P_2,
12913 Depth => P_2_Depth,
12914 Depth_To_Reach => P_1_Depth);
12915 P_2_Child := True;
12916 end if;
12917
12918 -- At this stage the package pointers have been elevated to the same
12919 -- depth. If the related entities are the same, then one package is a
12920 -- potential child of the other:
12921
12922 -- P_1
12923 -- :
12924 -- X became P_1 P_2 or vice versa
12925 -- :
12926 -- P_2
12927
12928 if P_1 = P_2 then
12929 if P_1_Child then
12930 return Is_Child_Unit (Pack_1);
12931
12932 else pragma Assert (P_2_Child);
12933 return Is_Child_Unit (Pack_2);
12934 end if;
12935
12936 -- The packages may come from the same package chain or from entirely
12937 -- different hierarcies. To determine this, climb the scope stack until
12938 -- a common root is found.
12939
12940 -- (root) (root 1) (root 2)
12941 -- / \ | |
12942 -- P_1 P_2 P_1 P_2
12943
12944 else
12945 while Present (P_1) and then Present (P_2) loop
12946
12947 -- The two packages may be siblings
12948
12949 if P_1 = P_2 then
12950 return Is_Child_Unit (Pack_1) and then Is_Child_Unit (Pack_2);
12951 end if;
12952
12953 P_1 := Scope (P_1);
12954 P_2 := Scope (P_2);
12955 end loop;
12956 end if;
12957
12958 return False;
12959 end Is_Child_Or_Sibling;
12960
12961 -----------------------------
12962 -- Is_Concurrent_Interface --
12963 -----------------------------
12964
12965 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
12966 begin
12967 return Is_Interface (T)
12968 and then
12969 (Is_Protected_Interface (T)
12970 or else Is_Synchronized_Interface (T)
12971 or else Is_Task_Interface (T));
12972 end Is_Concurrent_Interface;
12973
12974 -----------------------
12975 -- Is_Constant_Bound --
12976 -----------------------
12977
12978 function Is_Constant_Bound (Exp : Node_Id) return Boolean is
12979 begin
12980 if Compile_Time_Known_Value (Exp) then
12981 return True;
12982
12983 elsif Is_Entity_Name (Exp) and then Present (Entity (Exp)) then
12984 return Is_Constant_Object (Entity (Exp))
12985 or else Ekind (Entity (Exp)) = E_Enumeration_Literal;
12986
12987 elsif Nkind (Exp) in N_Binary_Op then
12988 return Is_Constant_Bound (Left_Opnd (Exp))
12989 and then Is_Constant_Bound (Right_Opnd (Exp))
12990 and then Scope (Entity (Exp)) = Standard_Standard;
12991
12992 else
12993 return False;
12994 end if;
12995 end Is_Constant_Bound;
12996
12997 ---------------------------
12998 -- Is_Container_Element --
12999 ---------------------------
13000
13001 function Is_Container_Element (Exp : Node_Id) return Boolean is
13002 Loc : constant Source_Ptr := Sloc (Exp);
13003 Pref : constant Node_Id := Prefix (Exp);
13004
13005 Call : Node_Id;
13006 -- Call to an indexing aspect
13007
13008 Cont_Typ : Entity_Id;
13009 -- The type of the container being accessed
13010
13011 Elem_Typ : Entity_Id;
13012 -- Its element type
13013
13014 Indexing : Entity_Id;
13015 Is_Const : Boolean;
13016 -- Indicates that constant indexing is used, and the element is thus
13017 -- a constant.
13018
13019 Ref_Typ : Entity_Id;
13020 -- The reference type returned by the indexing operation
13021
13022 begin
13023 -- If C is a container, in a context that imposes the element type of
13024 -- that container, the indexing notation C (X) is rewritten as:
13025
13026 -- Indexing (C, X).Discr.all
13027
13028 -- where Indexing is one of the indexing aspects of the container.
13029 -- If the context does not require a reference, the construct can be
13030 -- rewritten as
13031
13032 -- Element (C, X)
13033
13034 -- First, verify that the construct has the proper form
13035
13036 if not Expander_Active then
13037 return False;
13038
13039 elsif Nkind (Pref) /= N_Selected_Component then
13040 return False;
13041
13042 elsif Nkind (Prefix (Pref)) /= N_Function_Call then
13043 return False;
13044
13045 else
13046 Call := Prefix (Pref);
13047 Ref_Typ := Etype (Call);
13048 end if;
13049
13050 if not Has_Implicit_Dereference (Ref_Typ)
13051 or else No (First (Parameter_Associations (Call)))
13052 or else not Is_Entity_Name (Name (Call))
13053 then
13054 return False;
13055 end if;
13056
13057 -- Retrieve type of container object, and its iterator aspects
13058
13059 Cont_Typ := Etype (First (Parameter_Associations (Call)));
13060 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Constant_Indexing);
13061 Is_Const := False;
13062
13063 if No (Indexing) then
13064
13065 -- Container should have at least one indexing operation
13066
13067 return False;
13068
13069 elsif Entity (Name (Call)) /= Entity (Indexing) then
13070
13071 -- This may be a variable indexing operation
13072
13073 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Variable_Indexing);
13074
13075 if No (Indexing)
13076 or else Entity (Name (Call)) /= Entity (Indexing)
13077 then
13078 return False;
13079 end if;
13080
13081 else
13082 Is_Const := True;
13083 end if;
13084
13085 Elem_Typ := Find_Value_Of_Aspect (Cont_Typ, Aspect_Iterator_Element);
13086
13087 if No (Elem_Typ) or else Entity (Elem_Typ) /= Etype (Exp) then
13088 return False;
13089 end if;
13090
13091 -- Check that the expression is not the target of an assignment, in
13092 -- which case the rewriting is not possible.
13093
13094 if not Is_Const then
13095 declare
13096 Par : Node_Id;
13097
13098 begin
13099 Par := Exp;
13100 while Present (Par)
13101 loop
13102 if Nkind (Parent (Par)) = N_Assignment_Statement
13103 and then Par = Name (Parent (Par))
13104 then
13105 return False;
13106
13107 -- A renaming produces a reference, and the transformation
13108 -- does not apply.
13109
13110 elsif Nkind (Parent (Par)) = N_Object_Renaming_Declaration then
13111 return False;
13112
13113 elsif Nkind_In
13114 (Nkind (Parent (Par)), N_Function_Call,
13115 N_Procedure_Call_Statement,
13116 N_Entry_Call_Statement)
13117 then
13118 -- Check that the element is not part of an actual for an
13119 -- in-out parameter.
13120
13121 declare
13122 F : Entity_Id;
13123 A : Node_Id;
13124
13125 begin
13126 F := First_Formal (Entity (Name (Parent (Par))));
13127 A := First (Parameter_Associations (Parent (Par)));
13128 while Present (F) loop
13129 if A = Par and then Ekind (F) /= E_In_Parameter then
13130 return False;
13131 end if;
13132
13133 Next_Formal (F);
13134 Next (A);
13135 end loop;
13136 end;
13137
13138 -- E_In_Parameter in a call: element is not modified.
13139
13140 exit;
13141 end if;
13142
13143 Par := Parent (Par);
13144 end loop;
13145 end;
13146 end if;
13147
13148 -- The expression has the proper form and the context requires the
13149 -- element type. Retrieve the Element function of the container and
13150 -- rewrite the construct as a call to it.
13151
13152 declare
13153 Op : Elmt_Id;
13154
13155 begin
13156 Op := First_Elmt (Primitive_Operations (Cont_Typ));
13157 while Present (Op) loop
13158 exit when Chars (Node (Op)) = Name_Element;
13159 Next_Elmt (Op);
13160 end loop;
13161
13162 if No (Op) then
13163 return False;
13164
13165 else
13166 Rewrite (Exp,
13167 Make_Function_Call (Loc,
13168 Name => New_Occurrence_Of (Node (Op), Loc),
13169 Parameter_Associations => Parameter_Associations (Call)));
13170 Analyze_And_Resolve (Exp, Entity (Elem_Typ));
13171 return True;
13172 end if;
13173 end;
13174 end Is_Container_Element;
13175
13176 ----------------------------
13177 -- Is_Contract_Annotation --
13178 ----------------------------
13179
13180 function Is_Contract_Annotation (Item : Node_Id) return Boolean is
13181 begin
13182 return Is_Package_Contract_Annotation (Item)
13183 or else
13184 Is_Subprogram_Contract_Annotation (Item);
13185 end Is_Contract_Annotation;
13186
13187 --------------------------------------
13188 -- Is_Controlling_Limited_Procedure --
13189 --------------------------------------
13190
13191 function Is_Controlling_Limited_Procedure
13192 (Proc_Nam : Entity_Id) return Boolean
13193 is
13194 Param : Node_Id;
13195 Param_Typ : Entity_Id := Empty;
13196
13197 begin
13198 if Ekind (Proc_Nam) = E_Procedure
13199 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
13200 then
13201 Param := Parameter_Type (First (
13202 Parameter_Specifications (Parent (Proc_Nam))));
13203
13204 -- The formal may be an anonymous access type.
13205
13206 if Nkind (Param) = N_Access_Definition then
13207 Param_Typ := Entity (Subtype_Mark (Param));
13208
13209 else
13210 Param_Typ := Etype (Param);
13211 end if;
13212
13213 -- In the case where an Itype was created for a dispatchin call, the
13214 -- procedure call has been rewritten. The actual may be an access to
13215 -- interface type in which case it is the designated type that is the
13216 -- controlling type.
13217
13218 elsif Present (Associated_Node_For_Itype (Proc_Nam))
13219 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
13220 and then
13221 Present (Parameter_Associations
13222 (Associated_Node_For_Itype (Proc_Nam)))
13223 then
13224 Param_Typ :=
13225 Etype (First (Parameter_Associations
13226 (Associated_Node_For_Itype (Proc_Nam))));
13227
13228 if Ekind (Param_Typ) = E_Anonymous_Access_Type then
13229 Param_Typ := Directly_Designated_Type (Param_Typ);
13230 end if;
13231 end if;
13232
13233 if Present (Param_Typ) then
13234 return
13235 Is_Interface (Param_Typ)
13236 and then Is_Limited_Record (Param_Typ);
13237 end if;
13238
13239 return False;
13240 end Is_Controlling_Limited_Procedure;
13241
13242 -----------------------------
13243 -- Is_CPP_Constructor_Call --
13244 -----------------------------
13245
13246 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
13247 begin
13248 return Nkind (N) = N_Function_Call
13249 and then Is_CPP_Class (Etype (Etype (N)))
13250 and then Is_Constructor (Entity (Name (N)))
13251 and then Is_Imported (Entity (Name (N)));
13252 end Is_CPP_Constructor_Call;
13253
13254 -------------------------
13255 -- Is_Current_Instance --
13256 -------------------------
13257
13258 function Is_Current_Instance (N : Node_Id) return Boolean is
13259 Typ : constant Entity_Id := Entity (N);
13260 P : Node_Id;
13261
13262 begin
13263 -- Simplest case: entity is a concurrent type and we are currently
13264 -- inside the body. This will eventually be expanded into a
13265 -- call to Self (for tasks) or _object (for protected objects).
13266
13267 if Is_Concurrent_Type (Typ) and then In_Open_Scopes (Typ) then
13268 return True;
13269
13270 else
13271 -- Check whether the context is a (sub)type declaration for the
13272 -- type entity.
13273
13274 P := Parent (N);
13275 while Present (P) loop
13276 if Nkind_In (P, N_Full_Type_Declaration,
13277 N_Private_Type_Declaration,
13278 N_Subtype_Declaration)
13279 and then Comes_From_Source (P)
13280 and then Defining_Entity (P) = Typ
13281 then
13282 return True;
13283
13284 -- A subtype name may appear in an aspect specification for a
13285 -- Predicate_Failure aspect, for which we do not construct a
13286 -- wrapper procedure. The subtype will be replaced by the
13287 -- expression being tested when the corresponding predicate
13288 -- check is expanded.
13289
13290 elsif Nkind (P) = N_Aspect_Specification
13291 and then Nkind (Parent (P)) = N_Subtype_Declaration
13292 then
13293 return True;
13294
13295 elsif Nkind (P) = N_Pragma
13296 and then
13297 Get_Pragma_Id (P) = Pragma_Predicate_Failure
13298 then
13299 return True;
13300 end if;
13301
13302 P := Parent (P);
13303 end loop;
13304 end if;
13305
13306 -- In any other context this is not a current occurrence
13307
13308 return False;
13309 end Is_Current_Instance;
13310
13311 --------------------
13312 -- Is_Declaration --
13313 --------------------
13314
13315 function Is_Declaration (N : Node_Id) return Boolean is
13316 begin
13317 return
13318 Is_Declaration_Other_Than_Renaming (N)
13319 or else Is_Renaming_Declaration (N);
13320 end Is_Declaration;
13321
13322 ----------------------------------------
13323 -- Is_Declaration_Other_Than_Renaming --
13324 ----------------------------------------
13325
13326 function Is_Declaration_Other_Than_Renaming (N : Node_Id) return Boolean is
13327 begin
13328 case Nkind (N) is
13329 when N_Abstract_Subprogram_Declaration
13330 | N_Exception_Declaration
13331 | N_Expression_Function
13332 | N_Full_Type_Declaration
13333 | N_Generic_Package_Declaration
13334 | N_Generic_Subprogram_Declaration
13335 | N_Number_Declaration
13336 | N_Object_Declaration
13337 | N_Package_Declaration
13338 | N_Private_Extension_Declaration
13339 | N_Private_Type_Declaration
13340 | N_Subprogram_Declaration
13341 | N_Subtype_Declaration
13342 =>
13343 return True;
13344
13345 when others =>
13346 return False;
13347 end case;
13348 end Is_Declaration_Other_Than_Renaming;
13349
13350 --------------------------------
13351 -- Is_Declared_Within_Variant --
13352 --------------------------------
13353
13354 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
13355 Comp_Decl : constant Node_Id := Parent (Comp);
13356 Comp_List : constant Node_Id := Parent (Comp_Decl);
13357 begin
13358 return Nkind (Parent (Comp_List)) = N_Variant;
13359 end Is_Declared_Within_Variant;
13360
13361 ----------------------------------------------
13362 -- Is_Dependent_Component_Of_Mutable_Object --
13363 ----------------------------------------------
13364
13365 function Is_Dependent_Component_Of_Mutable_Object
13366 (Object : Node_Id) return Boolean
13367 is
13368 P : Node_Id;
13369 Prefix_Type : Entity_Id;
13370 P_Aliased : Boolean := False;
13371 Comp : Entity_Id;
13372
13373 Deref : Node_Id := Object;
13374 -- Dereference node, in something like X.all.Y(2)
13375
13376 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
13377
13378 begin
13379 -- Find the dereference node if any
13380
13381 while Nkind_In (Deref, N_Indexed_Component,
13382 N_Selected_Component,
13383 N_Slice)
13384 loop
13385 Deref := Prefix (Deref);
13386 end loop;
13387
13388 -- Ada 2005: If we have a component or slice of a dereference,
13389 -- something like X.all.Y (2), and the type of X is access-to-constant,
13390 -- Is_Variable will return False, because it is indeed a constant
13391 -- view. But it might be a view of a variable object, so we want the
13392 -- following condition to be True in that case.
13393
13394 if Is_Variable (Object)
13395 or else (Ada_Version >= Ada_2005
13396 and then Nkind (Deref) = N_Explicit_Dereference)
13397 then
13398 if Nkind (Object) = N_Selected_Component then
13399 P := Prefix (Object);
13400 Prefix_Type := Etype (P);
13401
13402 if Is_Entity_Name (P) then
13403 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
13404 Prefix_Type := Base_Type (Prefix_Type);
13405 end if;
13406
13407 if Is_Aliased (Entity (P)) then
13408 P_Aliased := True;
13409 end if;
13410
13411 -- A discriminant check on a selected component may be expanded
13412 -- into a dereference when removing side effects. Recover the
13413 -- original node and its type, which may be unconstrained.
13414
13415 elsif Nkind (P) = N_Explicit_Dereference
13416 and then not (Comes_From_Source (P))
13417 then
13418 P := Original_Node (P);
13419 Prefix_Type := Etype (P);
13420
13421 else
13422 -- Check for prefix being an aliased component???
13423
13424 null;
13425
13426 end if;
13427
13428 -- A heap object is constrained by its initial value
13429
13430 -- Ada 2005 (AI-363): Always assume the object could be mutable in
13431 -- the dereferenced case, since the access value might denote an
13432 -- unconstrained aliased object, whereas in Ada 95 the designated
13433 -- object is guaranteed to be constrained. A worst-case assumption
13434 -- has to apply in Ada 2005 because we can't tell at compile
13435 -- time whether the object is "constrained by its initial value",
13436 -- despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are semantic
13437 -- rules (these rules are acknowledged to need fixing). We don't
13438 -- impose this more stringent checking for earlier Ada versions or
13439 -- when Relaxed_RM_Semantics applies (the latter for CodePeer's
13440 -- benefit, though it's unclear on why using -gnat95 would not be
13441 -- sufficient???).
13442
13443 if Ada_Version < Ada_2005 or else Relaxed_RM_Semantics then
13444 if Is_Access_Type (Prefix_Type)
13445 or else Nkind (P) = N_Explicit_Dereference
13446 then
13447 return False;
13448 end if;
13449
13450 else pragma Assert (Ada_Version >= Ada_2005);
13451 if Is_Access_Type (Prefix_Type) then
13452
13453 -- If the access type is pool-specific, and there is no
13454 -- constrained partial view of the designated type, then the
13455 -- designated object is known to be constrained.
13456
13457 if Ekind (Prefix_Type) = E_Access_Type
13458 and then not Object_Type_Has_Constrained_Partial_View
13459 (Typ => Designated_Type (Prefix_Type),
13460 Scop => Current_Scope)
13461 then
13462 return False;
13463
13464 -- Otherwise (general access type, or there is a constrained
13465 -- partial view of the designated type), we need to check
13466 -- based on the designated type.
13467
13468 else
13469 Prefix_Type := Designated_Type (Prefix_Type);
13470 end if;
13471 end if;
13472 end if;
13473
13474 Comp :=
13475 Original_Record_Component (Entity (Selector_Name (Object)));
13476
13477 -- As per AI-0017, the renaming is illegal in a generic body, even
13478 -- if the subtype is indefinite.
13479
13480 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
13481
13482 if not Is_Constrained (Prefix_Type)
13483 and then (Is_Definite_Subtype (Prefix_Type)
13484 or else
13485 (Is_Generic_Type (Prefix_Type)
13486 and then Ekind (Current_Scope) = E_Generic_Package
13487 and then In_Package_Body (Current_Scope)))
13488
13489 and then (Is_Declared_Within_Variant (Comp)
13490 or else Has_Discriminant_Dependent_Constraint (Comp))
13491 and then (not P_Aliased or else Ada_Version >= Ada_2005)
13492 then
13493 return True;
13494
13495 -- If the prefix is of an access type at this point, then we want
13496 -- to return False, rather than calling this function recursively
13497 -- on the access object (which itself might be a discriminant-
13498 -- dependent component of some other object, but that isn't
13499 -- relevant to checking the object passed to us). This avoids
13500 -- issuing wrong errors when compiling with -gnatc, where there
13501 -- can be implicit dereferences that have not been expanded.
13502
13503 elsif Is_Access_Type (Etype (Prefix (Object))) then
13504 return False;
13505
13506 else
13507 return
13508 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
13509 end if;
13510
13511 elsif Nkind (Object) = N_Indexed_Component
13512 or else Nkind (Object) = N_Slice
13513 then
13514 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
13515
13516 -- A type conversion that Is_Variable is a view conversion:
13517 -- go back to the denoted object.
13518
13519 elsif Nkind (Object) = N_Type_Conversion then
13520 return
13521 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
13522 end if;
13523 end if;
13524
13525 return False;
13526 end Is_Dependent_Component_Of_Mutable_Object;
13527
13528 ---------------------
13529 -- Is_Dereferenced --
13530 ---------------------
13531
13532 function Is_Dereferenced (N : Node_Id) return Boolean is
13533 P : constant Node_Id := Parent (N);
13534 begin
13535 return Nkind_In (P, N_Selected_Component,
13536 N_Explicit_Dereference,
13537 N_Indexed_Component,
13538 N_Slice)
13539 and then Prefix (P) = N;
13540 end Is_Dereferenced;
13541
13542 ----------------------
13543 -- Is_Descendant_Of --
13544 ----------------------
13545
13546 function Is_Descendant_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
13547 T : Entity_Id;
13548 Etyp : Entity_Id;
13549
13550 begin
13551 pragma Assert (Nkind (T1) in N_Entity);
13552 pragma Assert (Nkind (T2) in N_Entity);
13553
13554 T := Base_Type (T1);
13555
13556 -- Immediate return if the types match
13557
13558 if T = T2 then
13559 return True;
13560
13561 -- Comment needed here ???
13562
13563 elsif Ekind (T) = E_Class_Wide_Type then
13564 return Etype (T) = T2;
13565
13566 -- All other cases
13567
13568 else
13569 loop
13570 Etyp := Etype (T);
13571
13572 -- Done if we found the type we are looking for
13573
13574 if Etyp = T2 then
13575 return True;
13576
13577 -- Done if no more derivations to check
13578
13579 elsif T = T1
13580 or else T = Etyp
13581 then
13582 return False;
13583
13584 -- Following test catches error cases resulting from prev errors
13585
13586 elsif No (Etyp) then
13587 return False;
13588
13589 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
13590 return False;
13591
13592 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
13593 return False;
13594 end if;
13595
13596 T := Base_Type (Etyp);
13597 end loop;
13598 end if;
13599 end Is_Descendant_Of;
13600
13601 ----------------------------------------
13602 -- Is_Descendant_Of_Suspension_Object --
13603 ----------------------------------------
13604
13605 function Is_Descendant_Of_Suspension_Object
13606 (Typ : Entity_Id) return Boolean
13607 is
13608 Cur_Typ : Entity_Id;
13609 Par_Typ : Entity_Id;
13610
13611 begin
13612 -- Climb the type derivation chain checking each parent type against
13613 -- Suspension_Object.
13614
13615 Cur_Typ := Base_Type (Typ);
13616 while Present (Cur_Typ) loop
13617 Par_Typ := Etype (Cur_Typ);
13618
13619 -- The current type is a match
13620
13621 if Is_Suspension_Object (Cur_Typ) then
13622 return True;
13623
13624 -- Stop the traversal once the root of the derivation chain has been
13625 -- reached. In that case the current type is its own base type.
13626
13627 elsif Cur_Typ = Par_Typ then
13628 exit;
13629 end if;
13630
13631 Cur_Typ := Base_Type (Par_Typ);
13632 end loop;
13633
13634 return False;
13635 end Is_Descendant_Of_Suspension_Object;
13636
13637 ---------------------------------------------
13638 -- Is_Double_Precision_Floating_Point_Type --
13639 ---------------------------------------------
13640
13641 function Is_Double_Precision_Floating_Point_Type
13642 (E : Entity_Id) return Boolean is
13643 begin
13644 return Is_Floating_Point_Type (E)
13645 and then Machine_Radix_Value (E) = Uint_2
13646 and then Machine_Mantissa_Value (E) = UI_From_Int (53)
13647 and then Machine_Emax_Value (E) = Uint_2 ** Uint_10
13648 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_10);
13649 end Is_Double_Precision_Floating_Point_Type;
13650
13651 -----------------------------
13652 -- Is_Effectively_Volatile --
13653 -----------------------------
13654
13655 function Is_Effectively_Volatile (Id : Entity_Id) return Boolean is
13656 begin
13657 if Is_Type (Id) then
13658
13659 -- An arbitrary type is effectively volatile when it is subject to
13660 -- pragma Atomic or Volatile.
13661
13662 if Is_Volatile (Id) then
13663 return True;
13664
13665 -- An array type is effectively volatile when it is subject to pragma
13666 -- Atomic_Components or Volatile_Components or its component type is
13667 -- effectively volatile.
13668
13669 elsif Is_Array_Type (Id) then
13670 declare
13671 Anc : Entity_Id := Base_Type (Id);
13672 begin
13673 if Is_Private_Type (Anc) then
13674 Anc := Full_View (Anc);
13675 end if;
13676
13677 -- Test for presence of ancestor, as the full view of a private
13678 -- type may be missing in case of error.
13679
13680 return
13681 Has_Volatile_Components (Id)
13682 or else
13683 (Present (Anc)
13684 and then Is_Effectively_Volatile (Component_Type (Anc)));
13685 end;
13686
13687 -- A protected type is always volatile
13688
13689 elsif Is_Protected_Type (Id) then
13690 return True;
13691
13692 -- A descendant of Ada.Synchronous_Task_Control.Suspension_Object is
13693 -- automatically volatile.
13694
13695 elsif Is_Descendant_Of_Suspension_Object (Id) then
13696 return True;
13697
13698 -- Otherwise the type is not effectively volatile
13699
13700 else
13701 return False;
13702 end if;
13703
13704 -- Otherwise Id denotes an object
13705
13706 else
13707 return
13708 Is_Volatile (Id)
13709 or else Has_Volatile_Components (Id)
13710 or else Is_Effectively_Volatile (Etype (Id));
13711 end if;
13712 end Is_Effectively_Volatile;
13713
13714 ------------------------------------
13715 -- Is_Effectively_Volatile_Object --
13716 ------------------------------------
13717
13718 function Is_Effectively_Volatile_Object (N : Node_Id) return Boolean is
13719 begin
13720 if Is_Entity_Name (N) then
13721 return Is_Effectively_Volatile (Entity (N));
13722
13723 elsif Nkind (N) = N_Indexed_Component then
13724 return Is_Effectively_Volatile_Object (Prefix (N));
13725
13726 elsif Nkind (N) = N_Selected_Component then
13727 return
13728 Is_Effectively_Volatile_Object (Prefix (N))
13729 or else
13730 Is_Effectively_Volatile_Object (Selector_Name (N));
13731
13732 else
13733 return False;
13734 end if;
13735 end Is_Effectively_Volatile_Object;
13736
13737 -------------------
13738 -- Is_Entry_Body --
13739 -------------------
13740
13741 function Is_Entry_Body (Id : Entity_Id) return Boolean is
13742 begin
13743 return
13744 Ekind_In (Id, E_Entry, E_Entry_Family)
13745 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Body;
13746 end Is_Entry_Body;
13747
13748 --------------------------
13749 -- Is_Entry_Declaration --
13750 --------------------------
13751
13752 function Is_Entry_Declaration (Id : Entity_Id) return Boolean is
13753 begin
13754 return
13755 Ekind_In (Id, E_Entry, E_Entry_Family)
13756 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Declaration;
13757 end Is_Entry_Declaration;
13758
13759 ------------------------------------
13760 -- Is_Expanded_Priority_Attribute --
13761 ------------------------------------
13762
13763 function Is_Expanded_Priority_Attribute (E : Entity_Id) return Boolean is
13764 begin
13765 return
13766 Nkind (E) = N_Function_Call
13767 and then not Configurable_Run_Time_Mode
13768 and then (Entity (Name (E)) = RTE (RE_Get_Ceiling)
13769 or else Entity (Name (E)) = RTE (RO_PE_Get_Ceiling));
13770 end Is_Expanded_Priority_Attribute;
13771
13772 ----------------------------
13773 -- Is_Expression_Function --
13774 ----------------------------
13775
13776 function Is_Expression_Function (Subp : Entity_Id) return Boolean is
13777 begin
13778 if Ekind_In (Subp, E_Function, E_Subprogram_Body) then
13779 return
13780 Nkind (Original_Node (Unit_Declaration_Node (Subp))) =
13781 N_Expression_Function;
13782 else
13783 return False;
13784 end if;
13785 end Is_Expression_Function;
13786
13787 ------------------------------------------
13788 -- Is_Expression_Function_Or_Completion --
13789 ------------------------------------------
13790
13791 function Is_Expression_Function_Or_Completion
13792 (Subp : Entity_Id) return Boolean
13793 is
13794 Subp_Decl : Node_Id;
13795
13796 begin
13797 if Ekind (Subp) = E_Function then
13798 Subp_Decl := Unit_Declaration_Node (Subp);
13799
13800 -- The function declaration is either an expression function or is
13801 -- completed by an expression function body.
13802
13803 return
13804 Is_Expression_Function (Subp)
13805 or else (Nkind (Subp_Decl) = N_Subprogram_Declaration
13806 and then Present (Corresponding_Body (Subp_Decl))
13807 and then Is_Expression_Function
13808 (Corresponding_Body (Subp_Decl)));
13809
13810 elsif Ekind (Subp) = E_Subprogram_Body then
13811 return Is_Expression_Function (Subp);
13812
13813 else
13814 return False;
13815 end if;
13816 end Is_Expression_Function_Or_Completion;
13817
13818 -----------------------
13819 -- Is_EVF_Expression --
13820 -----------------------
13821
13822 function Is_EVF_Expression (N : Node_Id) return Boolean is
13823 Orig_N : constant Node_Id := Original_Node (N);
13824 Alt : Node_Id;
13825 Expr : Node_Id;
13826 Id : Entity_Id;
13827
13828 begin
13829 -- Detect a reference to a formal parameter of a specific tagged type
13830 -- whose related subprogram is subject to pragma Expresions_Visible with
13831 -- value "False".
13832
13833 if Is_Entity_Name (N) and then Present (Entity (N)) then
13834 Id := Entity (N);
13835
13836 return
13837 Is_Formal (Id)
13838 and then Is_Specific_Tagged_Type (Etype (Id))
13839 and then Extensions_Visible_Status (Id) =
13840 Extensions_Visible_False;
13841
13842 -- A case expression is an EVF expression when it contains at least one
13843 -- EVF dependent_expression. Note that a case expression may have been
13844 -- expanded, hence the use of Original_Node.
13845
13846 elsif Nkind (Orig_N) = N_Case_Expression then
13847 Alt := First (Alternatives (Orig_N));
13848 while Present (Alt) loop
13849 if Is_EVF_Expression (Expression (Alt)) then
13850 return True;
13851 end if;
13852
13853 Next (Alt);
13854 end loop;
13855
13856 -- An if expression is an EVF expression when it contains at least one
13857 -- EVF dependent_expression. Note that an if expression may have been
13858 -- expanded, hence the use of Original_Node.
13859
13860 elsif Nkind (Orig_N) = N_If_Expression then
13861 Expr := Next (First (Expressions (Orig_N)));
13862 while Present (Expr) loop
13863 if Is_EVF_Expression (Expr) then
13864 return True;
13865 end if;
13866
13867 Next (Expr);
13868 end loop;
13869
13870 -- A qualified expression or a type conversion is an EVF expression when
13871 -- its operand is an EVF expression.
13872
13873 elsif Nkind_In (N, N_Qualified_Expression,
13874 N_Unchecked_Type_Conversion,
13875 N_Type_Conversion)
13876 then
13877 return Is_EVF_Expression (Expression (N));
13878
13879 -- Attributes 'Loop_Entry, 'Old, and 'Update are EVF expressions when
13880 -- their prefix denotes an EVF expression.
13881
13882 elsif Nkind (N) = N_Attribute_Reference
13883 and then Nam_In (Attribute_Name (N), Name_Loop_Entry,
13884 Name_Old,
13885 Name_Update)
13886 then
13887 return Is_EVF_Expression (Prefix (N));
13888 end if;
13889
13890 return False;
13891 end Is_EVF_Expression;
13892
13893 --------------
13894 -- Is_False --
13895 --------------
13896
13897 function Is_False (U : Uint) return Boolean is
13898 begin
13899 return (U = 0);
13900 end Is_False;
13901
13902 ---------------------------
13903 -- Is_Fixed_Model_Number --
13904 ---------------------------
13905
13906 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
13907 S : constant Ureal := Small_Value (T);
13908 M : Urealp.Save_Mark;
13909 R : Boolean;
13910
13911 begin
13912 M := Urealp.Mark;
13913 R := (U = UR_Trunc (U / S) * S);
13914 Urealp.Release (M);
13915 return R;
13916 end Is_Fixed_Model_Number;
13917
13918 -------------------------------
13919 -- Is_Fully_Initialized_Type --
13920 -------------------------------
13921
13922 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
13923 begin
13924 -- Scalar types
13925
13926 if Is_Scalar_Type (Typ) then
13927
13928 -- A scalar type with an aspect Default_Value is fully initialized
13929
13930 -- Note: Iniitalize/Normalize_Scalars also ensure full initialization
13931 -- of a scalar type, but we don't take that into account here, since
13932 -- we don't want these to affect warnings.
13933
13934 return Has_Default_Aspect (Typ);
13935
13936 elsif Is_Access_Type (Typ) then
13937 return True;
13938
13939 elsif Is_Array_Type (Typ) then
13940 if Is_Fully_Initialized_Type (Component_Type (Typ))
13941 or else (Ada_Version >= Ada_2012 and then Has_Default_Aspect (Typ))
13942 then
13943 return True;
13944 end if;
13945
13946 -- An interesting case, if we have a constrained type one of whose
13947 -- bounds is known to be null, then there are no elements to be
13948 -- initialized, so all the elements are initialized.
13949
13950 if Is_Constrained (Typ) then
13951 declare
13952 Indx : Node_Id;
13953 Indx_Typ : Entity_Id;
13954 Lbd, Hbd : Node_Id;
13955
13956 begin
13957 Indx := First_Index (Typ);
13958 while Present (Indx) loop
13959 if Etype (Indx) = Any_Type then
13960 return False;
13961
13962 -- If index is a range, use directly
13963
13964 elsif Nkind (Indx) = N_Range then
13965 Lbd := Low_Bound (Indx);
13966 Hbd := High_Bound (Indx);
13967
13968 else
13969 Indx_Typ := Etype (Indx);
13970
13971 if Is_Private_Type (Indx_Typ) then
13972 Indx_Typ := Full_View (Indx_Typ);
13973 end if;
13974
13975 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
13976 return False;
13977 else
13978 Lbd := Type_Low_Bound (Indx_Typ);
13979 Hbd := Type_High_Bound (Indx_Typ);
13980 end if;
13981 end if;
13982
13983 if Compile_Time_Known_Value (Lbd)
13984 and then
13985 Compile_Time_Known_Value (Hbd)
13986 then
13987 if Expr_Value (Hbd) < Expr_Value (Lbd) then
13988 return True;
13989 end if;
13990 end if;
13991
13992 Next_Index (Indx);
13993 end loop;
13994 end;
13995 end if;
13996
13997 -- If no null indexes, then type is not fully initialized
13998
13999 return False;
14000
14001 -- Record types
14002
14003 elsif Is_Record_Type (Typ) then
14004 if Has_Discriminants (Typ)
14005 and then
14006 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
14007 and then Is_Fully_Initialized_Variant (Typ)
14008 then
14009 return True;
14010 end if;
14011
14012 -- We consider bounded string types to be fully initialized, because
14013 -- otherwise we get false alarms when the Data component is not
14014 -- default-initialized.
14015
14016 if Is_Bounded_String (Typ) then
14017 return True;
14018 end if;
14019
14020 -- Controlled records are considered to be fully initialized if
14021 -- there is a user defined Initialize routine. This may not be
14022 -- entirely correct, but as the spec notes, we are guessing here
14023 -- what is best from the point of view of issuing warnings.
14024
14025 if Is_Controlled (Typ) then
14026 declare
14027 Utyp : constant Entity_Id := Underlying_Type (Typ);
14028
14029 begin
14030 if Present (Utyp) then
14031 declare
14032 Init : constant Entity_Id :=
14033 (Find_Optional_Prim_Op
14034 (Underlying_Type (Typ), Name_Initialize));
14035
14036 begin
14037 if Present (Init)
14038 and then Comes_From_Source (Init)
14039 and then not In_Predefined_Unit (Init)
14040 then
14041 return True;
14042
14043 elsif Has_Null_Extension (Typ)
14044 and then
14045 Is_Fully_Initialized_Type
14046 (Etype (Base_Type (Typ)))
14047 then
14048 return True;
14049 end if;
14050 end;
14051 end if;
14052 end;
14053 end if;
14054
14055 -- Otherwise see if all record components are initialized
14056
14057 declare
14058 Ent : Entity_Id;
14059
14060 begin
14061 Ent := First_Entity (Typ);
14062 while Present (Ent) loop
14063 if Ekind (Ent) = E_Component
14064 and then (No (Parent (Ent))
14065 or else No (Expression (Parent (Ent))))
14066 and then not Is_Fully_Initialized_Type (Etype (Ent))
14067
14068 -- Special VM case for tag components, which need to be
14069 -- defined in this case, but are never initialized as VMs
14070 -- are using other dispatching mechanisms. Ignore this
14071 -- uninitialized case. Note that this applies both to the
14072 -- uTag entry and the main vtable pointer (CPP_Class case).
14073
14074 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
14075 then
14076 return False;
14077 end if;
14078
14079 Next_Entity (Ent);
14080 end loop;
14081 end;
14082
14083 -- No uninitialized components, so type is fully initialized.
14084 -- Note that this catches the case of no components as well.
14085
14086 return True;
14087
14088 elsif Is_Concurrent_Type (Typ) then
14089 return True;
14090
14091 elsif Is_Private_Type (Typ) then
14092 declare
14093 U : constant Entity_Id := Underlying_Type (Typ);
14094
14095 begin
14096 if No (U) then
14097 return False;
14098 else
14099 return Is_Fully_Initialized_Type (U);
14100 end if;
14101 end;
14102
14103 else
14104 return False;
14105 end if;
14106 end Is_Fully_Initialized_Type;
14107
14108 ----------------------------------
14109 -- Is_Fully_Initialized_Variant --
14110 ----------------------------------
14111
14112 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
14113 Loc : constant Source_Ptr := Sloc (Typ);
14114 Constraints : constant List_Id := New_List;
14115 Components : constant Elist_Id := New_Elmt_List;
14116 Comp_Elmt : Elmt_Id;
14117 Comp_Id : Node_Id;
14118 Comp_List : Node_Id;
14119 Discr : Entity_Id;
14120 Discr_Val : Node_Id;
14121
14122 Report_Errors : Boolean;
14123 pragma Warnings (Off, Report_Errors);
14124
14125 begin
14126 if Serious_Errors_Detected > 0 then
14127 return False;
14128 end if;
14129
14130 if Is_Record_Type (Typ)
14131 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
14132 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
14133 then
14134 Comp_List := Component_List (Type_Definition (Parent (Typ)));
14135
14136 Discr := First_Discriminant (Typ);
14137 while Present (Discr) loop
14138 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
14139 Discr_Val := Expression (Parent (Discr));
14140
14141 if Present (Discr_Val)
14142 and then Is_OK_Static_Expression (Discr_Val)
14143 then
14144 Append_To (Constraints,
14145 Make_Component_Association (Loc,
14146 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
14147 Expression => New_Copy (Discr_Val)));
14148 else
14149 return False;
14150 end if;
14151 else
14152 return False;
14153 end if;
14154
14155 Next_Discriminant (Discr);
14156 end loop;
14157
14158 Gather_Components
14159 (Typ => Typ,
14160 Comp_List => Comp_List,
14161 Governed_By => Constraints,
14162 Into => Components,
14163 Report_Errors => Report_Errors);
14164
14165 -- Check that each component present is fully initialized
14166
14167 Comp_Elmt := First_Elmt (Components);
14168 while Present (Comp_Elmt) loop
14169 Comp_Id := Node (Comp_Elmt);
14170
14171 if Ekind (Comp_Id) = E_Component
14172 and then (No (Parent (Comp_Id))
14173 or else No (Expression (Parent (Comp_Id))))
14174 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
14175 then
14176 return False;
14177 end if;
14178
14179 Next_Elmt (Comp_Elmt);
14180 end loop;
14181
14182 return True;
14183
14184 elsif Is_Private_Type (Typ) then
14185 declare
14186 U : constant Entity_Id := Underlying_Type (Typ);
14187
14188 begin
14189 if No (U) then
14190 return False;
14191 else
14192 return Is_Fully_Initialized_Variant (U);
14193 end if;
14194 end;
14195
14196 else
14197 return False;
14198 end if;
14199 end Is_Fully_Initialized_Variant;
14200
14201 ------------------------------------
14202 -- Is_Generic_Declaration_Or_Body --
14203 ------------------------------------
14204
14205 function Is_Generic_Declaration_Or_Body (Decl : Node_Id) return Boolean is
14206 Spec_Decl : Node_Id;
14207
14208 begin
14209 -- Package/subprogram body
14210
14211 if Nkind_In (Decl, N_Package_Body, N_Subprogram_Body)
14212 and then Present (Corresponding_Spec (Decl))
14213 then
14214 Spec_Decl := Unit_Declaration_Node (Corresponding_Spec (Decl));
14215
14216 -- Package/subprogram body stub
14217
14218 elsif Nkind_In (Decl, N_Package_Body_Stub, N_Subprogram_Body_Stub)
14219 and then Present (Corresponding_Spec_Of_Stub (Decl))
14220 then
14221 Spec_Decl :=
14222 Unit_Declaration_Node (Corresponding_Spec_Of_Stub (Decl));
14223
14224 -- All other cases
14225
14226 else
14227 Spec_Decl := Decl;
14228 end if;
14229
14230 -- Rather than inspecting the defining entity of the spec declaration,
14231 -- look at its Nkind. This takes care of the case where the analysis of
14232 -- a generic body modifies the Ekind of its spec to allow for recursive
14233 -- calls.
14234
14235 return
14236 Nkind_In (Spec_Decl, N_Generic_Package_Declaration,
14237 N_Generic_Subprogram_Declaration);
14238 end Is_Generic_Declaration_Or_Body;
14239
14240 ----------------------------
14241 -- Is_Inherited_Operation --
14242 ----------------------------
14243
14244 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
14245 pragma Assert (Is_Overloadable (E));
14246 Kind : constant Node_Kind := Nkind (Parent (E));
14247 begin
14248 return Kind = N_Full_Type_Declaration
14249 or else Kind = N_Private_Extension_Declaration
14250 or else Kind = N_Subtype_Declaration
14251 or else (Ekind (E) = E_Enumeration_Literal
14252 and then Is_Derived_Type (Etype (E)));
14253 end Is_Inherited_Operation;
14254
14255 -------------------------------------
14256 -- Is_Inherited_Operation_For_Type --
14257 -------------------------------------
14258
14259 function Is_Inherited_Operation_For_Type
14260 (E : Entity_Id;
14261 Typ : Entity_Id) return Boolean
14262 is
14263 begin
14264 -- Check that the operation has been created by the type declaration
14265
14266 return Is_Inherited_Operation (E)
14267 and then Defining_Identifier (Parent (E)) = Typ;
14268 end Is_Inherited_Operation_For_Type;
14269
14270 --------------------------------------
14271 -- Is_Inlinable_Expression_Function --
14272 --------------------------------------
14273
14274 function Is_Inlinable_Expression_Function
14275 (Subp : Entity_Id) return Boolean
14276 is
14277 Return_Expr : Node_Id;
14278
14279 begin
14280 if Is_Expression_Function_Or_Completion (Subp)
14281 and then Has_Pragma_Inline_Always (Subp)
14282 and then Needs_No_Actuals (Subp)
14283 and then No (Contract (Subp))
14284 and then not Is_Dispatching_Operation (Subp)
14285 and then Needs_Finalization (Etype (Subp))
14286 and then not Is_Class_Wide_Type (Etype (Subp))
14287 and then not (Has_Invariants (Etype (Subp)))
14288 and then Present (Subprogram_Body (Subp))
14289 and then Was_Expression_Function (Subprogram_Body (Subp))
14290 then
14291 Return_Expr := Expression_Of_Expression_Function (Subp);
14292
14293 -- The returned object must not have a qualified expression and its
14294 -- nominal subtype must be statically compatible with the result
14295 -- subtype of the expression function.
14296
14297 return
14298 Nkind (Return_Expr) = N_Identifier
14299 and then Etype (Return_Expr) = Etype (Subp);
14300 end if;
14301
14302 return False;
14303 end Is_Inlinable_Expression_Function;
14304
14305 -----------------
14306 -- Is_Iterator --
14307 -----------------
14308
14309 function Is_Iterator (Typ : Entity_Id) return Boolean is
14310 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean;
14311 -- Determine whether type Iter_Typ is a predefined forward or reversible
14312 -- iterator.
14313
14314 ----------------------
14315 -- Denotes_Iterator --
14316 ----------------------
14317
14318 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean is
14319 begin
14320 -- Check that the name matches, and that the ultimate ancestor is in
14321 -- a predefined unit, i.e the one that declares iterator interfaces.
14322
14323 return
14324 Nam_In (Chars (Iter_Typ), Name_Forward_Iterator,
14325 Name_Reversible_Iterator)
14326 and then In_Predefined_Unit (Root_Type (Iter_Typ));
14327 end Denotes_Iterator;
14328
14329 -- Local variables
14330
14331 Iface_Elmt : Elmt_Id;
14332 Ifaces : Elist_Id;
14333
14334 -- Start of processing for Is_Iterator
14335
14336 begin
14337 -- The type may be a subtype of a descendant of the proper instance of
14338 -- the predefined interface type, so we must use the root type of the
14339 -- given type. The same is done for Is_Reversible_Iterator.
14340
14341 if Is_Class_Wide_Type (Typ)
14342 and then Denotes_Iterator (Root_Type (Typ))
14343 then
14344 return True;
14345
14346 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
14347 return False;
14348
14349 elsif Present (Find_Value_Of_Aspect (Typ, Aspect_Iterable)) then
14350 return True;
14351
14352 else
14353 Collect_Interfaces (Typ, Ifaces);
14354
14355 Iface_Elmt := First_Elmt (Ifaces);
14356 while Present (Iface_Elmt) loop
14357 if Denotes_Iterator (Node (Iface_Elmt)) then
14358 return True;
14359 end if;
14360
14361 Next_Elmt (Iface_Elmt);
14362 end loop;
14363
14364 return False;
14365 end if;
14366 end Is_Iterator;
14367
14368 ----------------------------
14369 -- Is_Iterator_Over_Array --
14370 ----------------------------
14371
14372 function Is_Iterator_Over_Array (N : Node_Id) return Boolean is
14373 Container : constant Node_Id := Name (N);
14374 Container_Typ : constant Entity_Id := Base_Type (Etype (Container));
14375 begin
14376 return Is_Array_Type (Container_Typ);
14377 end Is_Iterator_Over_Array;
14378
14379 ------------
14380 -- Is_LHS --
14381 ------------
14382
14383 -- We seem to have a lot of overlapping functions that do similar things
14384 -- (testing for left hand sides or lvalues???).
14385
14386 function Is_LHS (N : Node_Id) return Is_LHS_Result is
14387 P : constant Node_Id := Parent (N);
14388
14389 begin
14390 -- Return True if we are the left hand side of an assignment statement
14391
14392 if Nkind (P) = N_Assignment_Statement then
14393 if Name (P) = N then
14394 return Yes;
14395 else
14396 return No;
14397 end if;
14398
14399 -- Case of prefix of indexed or selected component or slice
14400
14401 elsif Nkind_In (P, N_Indexed_Component, N_Selected_Component, N_Slice)
14402 and then N = Prefix (P)
14403 then
14404 -- Here we have the case where the parent P is N.Q or N(Q .. R).
14405 -- If P is an LHS, then N is also effectively an LHS, but there
14406 -- is an important exception. If N is of an access type, then
14407 -- what we really have is N.all.Q (or N.all(Q .. R)). In either
14408 -- case this makes N.all a left hand side but not N itself.
14409
14410 -- If we don't know the type yet, this is the case where we return
14411 -- Unknown, since the answer depends on the type which is unknown.
14412
14413 if No (Etype (N)) then
14414 return Unknown;
14415
14416 -- We have an Etype set, so we can check it
14417
14418 elsif Is_Access_Type (Etype (N)) then
14419 return No;
14420
14421 -- OK, not access type case, so just test whole expression
14422
14423 else
14424 return Is_LHS (P);
14425 end if;
14426
14427 -- All other cases are not left hand sides
14428
14429 else
14430 return No;
14431 end if;
14432 end Is_LHS;
14433
14434 -----------------------------
14435 -- Is_Library_Level_Entity --
14436 -----------------------------
14437
14438 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
14439 begin
14440 -- The following is a small optimization, and it also properly handles
14441 -- discriminals, which in task bodies might appear in expressions before
14442 -- the corresponding procedure has been created, and which therefore do
14443 -- not have an assigned scope.
14444
14445 if Is_Formal (E) then
14446 return False;
14447 end if;
14448
14449 -- Normal test is simply that the enclosing dynamic scope is Standard
14450
14451 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
14452 end Is_Library_Level_Entity;
14453
14454 --------------------------------
14455 -- Is_Limited_Class_Wide_Type --
14456 --------------------------------
14457
14458 function Is_Limited_Class_Wide_Type (Typ : Entity_Id) return Boolean is
14459 begin
14460 return
14461 Is_Class_Wide_Type (Typ)
14462 and then (Is_Limited_Type (Typ) or else From_Limited_With (Typ));
14463 end Is_Limited_Class_Wide_Type;
14464
14465 ---------------------------------
14466 -- Is_Local_Variable_Reference --
14467 ---------------------------------
14468
14469 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
14470 begin
14471 if not Is_Entity_Name (Expr) then
14472 return False;
14473
14474 else
14475 declare
14476 Ent : constant Entity_Id := Entity (Expr);
14477 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
14478 begin
14479 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
14480 return False;
14481 else
14482 return Present (Sub) and then Sub = Current_Subprogram;
14483 end if;
14484 end;
14485 end if;
14486 end Is_Local_Variable_Reference;
14487
14488 -----------------------
14489 -- Is_Name_Reference --
14490 -----------------------
14491
14492 function Is_Name_Reference (N : Node_Id) return Boolean is
14493 begin
14494 if Is_Entity_Name (N) then
14495 return Present (Entity (N)) and then Is_Object (Entity (N));
14496 end if;
14497
14498 case Nkind (N) is
14499 when N_Indexed_Component
14500 | N_Slice
14501 =>
14502 return
14503 Is_Name_Reference (Prefix (N))
14504 or else Is_Access_Type (Etype (Prefix (N)));
14505
14506 -- Attributes 'Input, 'Old and 'Result produce objects
14507
14508 when N_Attribute_Reference =>
14509 return
14510 Nam_In (Attribute_Name (N), Name_Input, Name_Old, Name_Result);
14511
14512 when N_Selected_Component =>
14513 return
14514 Is_Name_Reference (Selector_Name (N))
14515 and then
14516 (Is_Name_Reference (Prefix (N))
14517 or else Is_Access_Type (Etype (Prefix (N))));
14518
14519 when N_Explicit_Dereference =>
14520 return True;
14521
14522 -- A view conversion of a tagged name is a name reference
14523
14524 when N_Type_Conversion =>
14525 return
14526 Is_Tagged_Type (Etype (Subtype_Mark (N)))
14527 and then Is_Tagged_Type (Etype (Expression (N)))
14528 and then Is_Name_Reference (Expression (N));
14529
14530 -- An unchecked type conversion is considered to be a name if the
14531 -- operand is a name (this construction arises only as a result of
14532 -- expansion activities).
14533
14534 when N_Unchecked_Type_Conversion =>
14535 return Is_Name_Reference (Expression (N));
14536
14537 when others =>
14538 return False;
14539 end case;
14540 end Is_Name_Reference;
14541
14542 ---------------------------------
14543 -- Is_Nontrivial_DIC_Procedure --
14544 ---------------------------------
14545
14546 function Is_Nontrivial_DIC_Procedure (Id : Entity_Id) return Boolean is
14547 Body_Decl : Node_Id;
14548 Stmt : Node_Id;
14549
14550 begin
14551 if Ekind (Id) = E_Procedure and then Is_DIC_Procedure (Id) then
14552 Body_Decl :=
14553 Unit_Declaration_Node
14554 (Corresponding_Body (Unit_Declaration_Node (Id)));
14555
14556 -- The body of the Default_Initial_Condition procedure must contain
14557 -- at least one statement, otherwise the generation of the subprogram
14558 -- body failed.
14559
14560 pragma Assert (Present (Handled_Statement_Sequence (Body_Decl)));
14561
14562 -- To qualify as nontrivial, the first statement of the procedure
14563 -- must be a check in the form of an if statement. If the original
14564 -- Default_Initial_Condition expression was folded, then the first
14565 -- statement is not a check.
14566
14567 Stmt := First (Statements (Handled_Statement_Sequence (Body_Decl)));
14568
14569 return
14570 Nkind (Stmt) = N_If_Statement
14571 and then Nkind (Original_Node (Stmt)) = N_Pragma;
14572 end if;
14573
14574 return False;
14575 end Is_Nontrivial_DIC_Procedure;
14576
14577 -------------------------
14578 -- Is_Null_Record_Type --
14579 -------------------------
14580
14581 function Is_Null_Record_Type (T : Entity_Id) return Boolean is
14582 Decl : constant Node_Id := Parent (T);
14583 begin
14584 return Nkind (Decl) = N_Full_Type_Declaration
14585 and then Nkind (Type_Definition (Decl)) = N_Record_Definition
14586 and then
14587 (No (Component_List (Type_Definition (Decl)))
14588 or else Null_Present (Component_List (Type_Definition (Decl))));
14589 end Is_Null_Record_Type;
14590
14591 ---------------------
14592 -- Is_Object_Image --
14593 ---------------------
14594
14595 function Is_Object_Image (Prefix : Node_Id) return Boolean is
14596 begin
14597 -- When the type of the prefix is not scalar, then the prefix is not
14598 -- valid in any scenario.
14599
14600 if not Is_Scalar_Type (Etype (Prefix)) then
14601 return False;
14602 end if;
14603
14604 -- Here we test for the case that the prefix is not a type and assume
14605 -- if it is not then it must be a named value or an object reference.
14606 -- This is because the parser always checks that prefixes of attributes
14607 -- are named.
14608
14609 return not (Is_Entity_Name (Prefix) and then Is_Type (Entity (Prefix)));
14610 end Is_Object_Image;
14611
14612 -------------------------
14613 -- Is_Object_Reference --
14614 -------------------------
14615
14616 function Is_Object_Reference (N : Node_Id) return Boolean is
14617 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean;
14618 -- Determine whether N is the name of an internally-generated renaming
14619
14620 --------------------------------------
14621 -- Is_Internally_Generated_Renaming --
14622 --------------------------------------
14623
14624 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean is
14625 P : Node_Id;
14626
14627 begin
14628 P := N;
14629 while Present (P) loop
14630 if Nkind (P) = N_Object_Renaming_Declaration then
14631 return not Comes_From_Source (P);
14632 elsif Is_List_Member (P) then
14633 return False;
14634 end if;
14635
14636 P := Parent (P);
14637 end loop;
14638
14639 return False;
14640 end Is_Internally_Generated_Renaming;
14641
14642 -- Start of processing for Is_Object_Reference
14643
14644 begin
14645 if Is_Entity_Name (N) then
14646 return Present (Entity (N)) and then Is_Object (Entity (N));
14647
14648 else
14649 case Nkind (N) is
14650 when N_Indexed_Component
14651 | N_Slice
14652 =>
14653 return
14654 Is_Object_Reference (Prefix (N))
14655 or else Is_Access_Type (Etype (Prefix (N)));
14656
14657 -- In Ada 95, a function call is a constant object; a procedure
14658 -- call is not.
14659
14660 -- Note that predefined operators are functions as well, and so
14661 -- are attributes that are (can be renamed as) functions.
14662
14663 when N_Binary_Op
14664 | N_Function_Call
14665 | N_Unary_Op
14666 =>
14667 return Etype (N) /= Standard_Void_Type;
14668
14669 -- Attributes references 'Loop_Entry, 'Old, and 'Result yield
14670 -- objects, even though they are not functions.
14671
14672 when N_Attribute_Reference =>
14673 return
14674 Nam_In (Attribute_Name (N), Name_Loop_Entry,
14675 Name_Old,
14676 Name_Result)
14677 or else Is_Function_Attribute_Name (Attribute_Name (N));
14678
14679 when N_Selected_Component =>
14680 return
14681 Is_Object_Reference (Selector_Name (N))
14682 and then
14683 (Is_Object_Reference (Prefix (N))
14684 or else Is_Access_Type (Etype (Prefix (N))));
14685
14686 -- An explicit dereference denotes an object, except that a
14687 -- conditional expression gets turned into an explicit dereference
14688 -- in some cases, and conditional expressions are not object
14689 -- names.
14690
14691 when N_Explicit_Dereference =>
14692 return not Nkind_In (Original_Node (N), N_Case_Expression,
14693 N_If_Expression);
14694
14695 -- A view conversion of a tagged object is an object reference
14696
14697 when N_Type_Conversion =>
14698 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
14699 and then Is_Tagged_Type (Etype (Expression (N)))
14700 and then Is_Object_Reference (Expression (N));
14701
14702 -- An unchecked type conversion is considered to be an object if
14703 -- the operand is an object (this construction arises only as a
14704 -- result of expansion activities).
14705
14706 when N_Unchecked_Type_Conversion =>
14707 return True;
14708
14709 -- Allow string literals to act as objects as long as they appear
14710 -- in internally-generated renamings. The expansion of iterators
14711 -- may generate such renamings when the range involves a string
14712 -- literal.
14713
14714 when N_String_Literal =>
14715 return Is_Internally_Generated_Renaming (Parent (N));
14716
14717 -- AI05-0003: In Ada 2012 a qualified expression is a name.
14718 -- This allows disambiguation of function calls and the use
14719 -- of aggregates in more contexts.
14720
14721 when N_Qualified_Expression =>
14722 if Ada_Version < Ada_2012 then
14723 return False;
14724 else
14725 return Is_Object_Reference (Expression (N))
14726 or else Nkind (Expression (N)) = N_Aggregate;
14727 end if;
14728
14729 when others =>
14730 return False;
14731 end case;
14732 end if;
14733 end Is_Object_Reference;
14734
14735 -----------------------------------
14736 -- Is_OK_Variable_For_Out_Formal --
14737 -----------------------------------
14738
14739 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
14740 begin
14741 Note_Possible_Modification (AV, Sure => True);
14742
14743 -- We must reject parenthesized variable names. Comes_From_Source is
14744 -- checked because there are currently cases where the compiler violates
14745 -- this rule (e.g. passing a task object to its controlled Initialize
14746 -- routine). This should be properly documented in sinfo???
14747
14748 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
14749 return False;
14750
14751 -- A variable is always allowed
14752
14753 elsif Is_Variable (AV) then
14754 return True;
14755
14756 -- Generalized indexing operations are rewritten as explicit
14757 -- dereferences, and it is only during resolution that we can
14758 -- check whether the context requires an access_to_variable type.
14759
14760 elsif Nkind (AV) = N_Explicit_Dereference
14761 and then Ada_Version >= Ada_2012
14762 and then Nkind (Original_Node (AV)) = N_Indexed_Component
14763 and then Present (Etype (Original_Node (AV)))
14764 and then Has_Implicit_Dereference (Etype (Original_Node (AV)))
14765 then
14766 return not Is_Access_Constant (Etype (Prefix (AV)));
14767
14768 -- Unchecked conversions are allowed only if they come from the
14769 -- generated code, which sometimes uses unchecked conversions for out
14770 -- parameters in cases where code generation is unaffected. We tell
14771 -- source unchecked conversions by seeing if they are rewrites of
14772 -- an original Unchecked_Conversion function call, or of an explicit
14773 -- conversion of a function call or an aggregate (as may happen in the
14774 -- expansion of a packed array aggregate).
14775
14776 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
14777 if Nkind_In (Original_Node (AV), N_Function_Call, N_Aggregate) then
14778 return False;
14779
14780 elsif Comes_From_Source (AV)
14781 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
14782 then
14783 return False;
14784
14785 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
14786 return Is_OK_Variable_For_Out_Formal (Expression (AV));
14787
14788 else
14789 return True;
14790 end if;
14791
14792 -- Normal type conversions are allowed if argument is a variable
14793
14794 elsif Nkind (AV) = N_Type_Conversion then
14795 if Is_Variable (Expression (AV))
14796 and then Paren_Count (Expression (AV)) = 0
14797 then
14798 Note_Possible_Modification (Expression (AV), Sure => True);
14799 return True;
14800
14801 -- We also allow a non-parenthesized expression that raises
14802 -- constraint error if it rewrites what used to be a variable
14803
14804 elsif Raises_Constraint_Error (Expression (AV))
14805 and then Paren_Count (Expression (AV)) = 0
14806 and then Is_Variable (Original_Node (Expression (AV)))
14807 then
14808 return True;
14809
14810 -- Type conversion of something other than a variable
14811
14812 else
14813 return False;
14814 end if;
14815
14816 -- If this node is rewritten, then test the original form, if that is
14817 -- OK, then we consider the rewritten node OK (for example, if the
14818 -- original node is a conversion, then Is_Variable will not be true
14819 -- but we still want to allow the conversion if it converts a variable).
14820
14821 elsif Original_Node (AV) /= AV then
14822
14823 -- In Ada 2012, the explicit dereference may be a rewritten call to a
14824 -- Reference function.
14825
14826 if Ada_Version >= Ada_2012
14827 and then Nkind (Original_Node (AV)) = N_Function_Call
14828 and then
14829 Has_Implicit_Dereference (Etype (Name (Original_Node (AV))))
14830 then
14831
14832 -- Check that this is not a constant reference.
14833
14834 return not Is_Access_Constant (Etype (Prefix (AV)));
14835
14836 elsif Has_Implicit_Dereference (Etype (Original_Node (AV))) then
14837 return
14838 not Is_Access_Constant (Etype
14839 (Get_Reference_Discriminant (Etype (Original_Node (AV)))));
14840
14841 else
14842 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
14843 end if;
14844
14845 -- All other non-variables are rejected
14846
14847 else
14848 return False;
14849 end if;
14850 end Is_OK_Variable_For_Out_Formal;
14851
14852 ----------------------------
14853 -- Is_OK_Volatile_Context --
14854 ----------------------------
14855
14856 function Is_OK_Volatile_Context
14857 (Context : Node_Id;
14858 Obj_Ref : Node_Id) return Boolean
14859 is
14860 function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean;
14861 -- Determine whether an arbitrary node denotes a call to a protected
14862 -- entry, function, or procedure in prefixed form where the prefix is
14863 -- Obj_Ref.
14864
14865 function Within_Check (Nod : Node_Id) return Boolean;
14866 -- Determine whether an arbitrary node appears in a check node
14867
14868 function Within_Volatile_Function (Id : Entity_Id) return Boolean;
14869 -- Determine whether an arbitrary entity appears in a volatile function
14870
14871 ---------------------------------
14872 -- Is_Protected_Operation_Call --
14873 ---------------------------------
14874
14875 function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean is
14876 Pref : Node_Id;
14877 Subp : Node_Id;
14878
14879 begin
14880 -- A call to a protected operations retains its selected component
14881 -- form as opposed to other prefixed calls that are transformed in
14882 -- expanded names.
14883
14884 if Nkind (Nod) = N_Selected_Component then
14885 Pref := Prefix (Nod);
14886 Subp := Selector_Name (Nod);
14887
14888 return
14889 Pref = Obj_Ref
14890 and then Present (Etype (Pref))
14891 and then Is_Protected_Type (Etype (Pref))
14892 and then Is_Entity_Name (Subp)
14893 and then Present (Entity (Subp))
14894 and then Ekind_In (Entity (Subp), E_Entry,
14895 E_Entry_Family,
14896 E_Function,
14897 E_Procedure);
14898 else
14899 return False;
14900 end if;
14901 end Is_Protected_Operation_Call;
14902
14903 ------------------
14904 -- Within_Check --
14905 ------------------
14906
14907 function Within_Check (Nod : Node_Id) return Boolean is
14908 Par : Node_Id;
14909
14910 begin
14911 -- Climb the parent chain looking for a check node
14912
14913 Par := Nod;
14914 while Present (Par) loop
14915 if Nkind (Par) in N_Raise_xxx_Error then
14916 return True;
14917
14918 -- Prevent the search from going too far
14919
14920 elsif Is_Body_Or_Package_Declaration (Par) then
14921 exit;
14922 end if;
14923
14924 Par := Parent (Par);
14925 end loop;
14926
14927 return False;
14928 end Within_Check;
14929
14930 ------------------------------
14931 -- Within_Volatile_Function --
14932 ------------------------------
14933
14934 function Within_Volatile_Function (Id : Entity_Id) return Boolean is
14935 Func_Id : Entity_Id;
14936
14937 begin
14938 -- Traverse the scope stack looking for a [generic] function
14939
14940 Func_Id := Id;
14941 while Present (Func_Id) and then Func_Id /= Standard_Standard loop
14942 if Ekind_In (Func_Id, E_Function, E_Generic_Function) then
14943 return Is_Volatile_Function (Func_Id);
14944 end if;
14945
14946 Func_Id := Scope (Func_Id);
14947 end loop;
14948
14949 return False;
14950 end Within_Volatile_Function;
14951
14952 -- Local variables
14953
14954 Obj_Id : Entity_Id;
14955
14956 -- Start of processing for Is_OK_Volatile_Context
14957
14958 begin
14959 -- The volatile object appears on either side of an assignment
14960
14961 if Nkind (Context) = N_Assignment_Statement then
14962 return True;
14963
14964 -- The volatile object is part of the initialization expression of
14965 -- another object.
14966
14967 elsif Nkind (Context) = N_Object_Declaration
14968 and then Present (Expression (Context))
14969 and then Expression (Context) = Obj_Ref
14970 then
14971 Obj_Id := Defining_Entity (Context);
14972
14973 -- The volatile object acts as the initialization expression of an
14974 -- extended return statement. This is valid context as long as the
14975 -- function is volatile.
14976
14977 if Is_Return_Object (Obj_Id) then
14978 return Within_Volatile_Function (Obj_Id);
14979
14980 -- Otherwise this is a normal object initialization
14981
14982 else
14983 return True;
14984 end if;
14985
14986 -- The volatile object acts as the name of a renaming declaration
14987
14988 elsif Nkind (Context) = N_Object_Renaming_Declaration
14989 and then Name (Context) = Obj_Ref
14990 then
14991 return True;
14992
14993 -- The volatile object appears as an actual parameter in a call to an
14994 -- instance of Unchecked_Conversion whose result is renamed.
14995
14996 elsif Nkind (Context) = N_Function_Call
14997 and then Is_Entity_Name (Name (Context))
14998 and then Is_Unchecked_Conversion_Instance (Entity (Name (Context)))
14999 and then Nkind (Parent (Context)) = N_Object_Renaming_Declaration
15000 then
15001 return True;
15002
15003 -- The volatile object is actually the prefix in a protected entry,
15004 -- function, or procedure call.
15005
15006 elsif Is_Protected_Operation_Call (Context) then
15007 return True;
15008
15009 -- The volatile object appears as the expression of a simple return
15010 -- statement that applies to a volatile function.
15011
15012 elsif Nkind (Context) = N_Simple_Return_Statement
15013 and then Expression (Context) = Obj_Ref
15014 then
15015 return
15016 Within_Volatile_Function (Return_Statement_Entity (Context));
15017
15018 -- The volatile object appears as the prefix of a name occurring in a
15019 -- non-interfering context.
15020
15021 elsif Nkind_In (Context, N_Attribute_Reference,
15022 N_Explicit_Dereference,
15023 N_Indexed_Component,
15024 N_Selected_Component,
15025 N_Slice)
15026 and then Prefix (Context) = Obj_Ref
15027 and then Is_OK_Volatile_Context
15028 (Context => Parent (Context),
15029 Obj_Ref => Context)
15030 then
15031 return True;
15032
15033 -- The volatile object appears as the prefix of attributes Address,
15034 -- Alignment, Component_Size, First_Bit, Last_Bit, Position, Size,
15035 -- Storage_Size.
15036
15037 elsif Nkind (Context) = N_Attribute_Reference
15038 and then Prefix (Context) = Obj_Ref
15039 and then Nam_In (Attribute_Name (Context), Name_Address,
15040 Name_Alignment,
15041 Name_Component_Size,
15042 Name_First_Bit,
15043 Name_Last_Bit,
15044 Name_Position,
15045 Name_Size,
15046 Name_Storage_Size)
15047 then
15048 return True;
15049
15050 -- The volatile object appears as the expression of a type conversion
15051 -- occurring in a non-interfering context.
15052
15053 elsif Nkind_In (Context, N_Type_Conversion,
15054 N_Unchecked_Type_Conversion)
15055 and then Expression (Context) = Obj_Ref
15056 and then Is_OK_Volatile_Context
15057 (Context => Parent (Context),
15058 Obj_Ref => Context)
15059 then
15060 return True;
15061
15062 -- The volatile object appears as the expression in a delay statement
15063
15064 elsif Nkind (Context) in N_Delay_Statement then
15065 return True;
15066
15067 -- Allow references to volatile objects in various checks. This is not a
15068 -- direct SPARK 2014 requirement.
15069
15070 elsif Within_Check (Context) then
15071 return True;
15072
15073 -- Assume that references to effectively volatile objects that appear
15074 -- as actual parameters in a subprogram call are always legal. A full
15075 -- legality check is done when the actuals are resolved (see routine
15076 -- Resolve_Actuals).
15077
15078 elsif Within_Subprogram_Call (Context) then
15079 return True;
15080
15081 -- Otherwise the context is not suitable for an effectively volatile
15082 -- object.
15083
15084 else
15085 return False;
15086 end if;
15087 end Is_OK_Volatile_Context;
15088
15089 ------------------------------------
15090 -- Is_Package_Contract_Annotation --
15091 ------------------------------------
15092
15093 function Is_Package_Contract_Annotation (Item : Node_Id) return Boolean is
15094 Nam : Name_Id;
15095
15096 begin
15097 if Nkind (Item) = N_Aspect_Specification then
15098 Nam := Chars (Identifier (Item));
15099
15100 else pragma Assert (Nkind (Item) = N_Pragma);
15101 Nam := Pragma_Name (Item);
15102 end if;
15103
15104 return Nam = Name_Abstract_State
15105 or else Nam = Name_Initial_Condition
15106 or else Nam = Name_Initializes
15107 or else Nam = Name_Refined_State;
15108 end Is_Package_Contract_Annotation;
15109
15110 -----------------------------------
15111 -- Is_Partially_Initialized_Type --
15112 -----------------------------------
15113
15114 function Is_Partially_Initialized_Type
15115 (Typ : Entity_Id;
15116 Include_Implicit : Boolean := True) return Boolean
15117 is
15118 begin
15119 if Is_Scalar_Type (Typ) then
15120 return False;
15121
15122 elsif Is_Access_Type (Typ) then
15123 return Include_Implicit;
15124
15125 elsif Is_Array_Type (Typ) then
15126
15127 -- If component type is partially initialized, so is array type
15128
15129 if Is_Partially_Initialized_Type
15130 (Component_Type (Typ), Include_Implicit)
15131 then
15132 return True;
15133
15134 -- Otherwise we are only partially initialized if we are fully
15135 -- initialized (this is the empty array case, no point in us
15136 -- duplicating that code here).
15137
15138 else
15139 return Is_Fully_Initialized_Type (Typ);
15140 end if;
15141
15142 elsif Is_Record_Type (Typ) then
15143
15144 -- A discriminated type is always partially initialized if in
15145 -- all mode
15146
15147 if Has_Discriminants (Typ) and then Include_Implicit then
15148 return True;
15149
15150 -- A tagged type is always partially initialized
15151
15152 elsif Is_Tagged_Type (Typ) then
15153 return True;
15154
15155 -- Case of non-discriminated record
15156
15157 else
15158 declare
15159 Ent : Entity_Id;
15160
15161 Component_Present : Boolean := False;
15162 -- Set True if at least one component is present. If no
15163 -- components are present, then record type is fully
15164 -- initialized (another odd case, like the null array).
15165
15166 begin
15167 -- Loop through components
15168
15169 Ent := First_Entity (Typ);
15170 while Present (Ent) loop
15171 if Ekind (Ent) = E_Component then
15172 Component_Present := True;
15173
15174 -- If a component has an initialization expression then
15175 -- the enclosing record type is partially initialized
15176
15177 if Present (Parent (Ent))
15178 and then Present (Expression (Parent (Ent)))
15179 then
15180 return True;
15181
15182 -- If a component is of a type which is itself partially
15183 -- initialized, then the enclosing record type is also.
15184
15185 elsif Is_Partially_Initialized_Type
15186 (Etype (Ent), Include_Implicit)
15187 then
15188 return True;
15189 end if;
15190 end if;
15191
15192 Next_Entity (Ent);
15193 end loop;
15194
15195 -- No initialized components found. If we found any components
15196 -- they were all uninitialized so the result is false.
15197
15198 if Component_Present then
15199 return False;
15200
15201 -- But if we found no components, then all the components are
15202 -- initialized so we consider the type to be initialized.
15203
15204 else
15205 return True;
15206 end if;
15207 end;
15208 end if;
15209
15210 -- Concurrent types are always fully initialized
15211
15212 elsif Is_Concurrent_Type (Typ) then
15213 return True;
15214
15215 -- For a private type, go to underlying type. If there is no underlying
15216 -- type then just assume this partially initialized. Not clear if this
15217 -- can happen in a non-error case, but no harm in testing for this.
15218
15219 elsif Is_Private_Type (Typ) then
15220 declare
15221 U : constant Entity_Id := Underlying_Type (Typ);
15222 begin
15223 if No (U) then
15224 return True;
15225 else
15226 return Is_Partially_Initialized_Type (U, Include_Implicit);
15227 end if;
15228 end;
15229
15230 -- For any other type (are there any?) assume partially initialized
15231
15232 else
15233 return True;
15234 end if;
15235 end Is_Partially_Initialized_Type;
15236
15237 ------------------------------------
15238 -- Is_Potentially_Persistent_Type --
15239 ------------------------------------
15240
15241 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
15242 Comp : Entity_Id;
15243 Indx : Node_Id;
15244
15245 begin
15246 -- For private type, test corresponding full type
15247
15248 if Is_Private_Type (T) then
15249 return Is_Potentially_Persistent_Type (Full_View (T));
15250
15251 -- Scalar types are potentially persistent
15252
15253 elsif Is_Scalar_Type (T) then
15254 return True;
15255
15256 -- Record type is potentially persistent if not tagged and the types of
15257 -- all it components are potentially persistent, and no component has
15258 -- an initialization expression.
15259
15260 elsif Is_Record_Type (T)
15261 and then not Is_Tagged_Type (T)
15262 and then not Is_Partially_Initialized_Type (T)
15263 then
15264 Comp := First_Component (T);
15265 while Present (Comp) loop
15266 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
15267 return False;
15268 else
15269 Next_Entity (Comp);
15270 end if;
15271 end loop;
15272
15273 return True;
15274
15275 -- Array type is potentially persistent if its component type is
15276 -- potentially persistent and if all its constraints are static.
15277
15278 elsif Is_Array_Type (T) then
15279 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
15280 return False;
15281 end if;
15282
15283 Indx := First_Index (T);
15284 while Present (Indx) loop
15285 if not Is_OK_Static_Subtype (Etype (Indx)) then
15286 return False;
15287 else
15288 Next_Index (Indx);
15289 end if;
15290 end loop;
15291
15292 return True;
15293
15294 -- All other types are not potentially persistent
15295
15296 else
15297 return False;
15298 end if;
15299 end Is_Potentially_Persistent_Type;
15300
15301 --------------------------------
15302 -- Is_Potentially_Unevaluated --
15303 --------------------------------
15304
15305 function Is_Potentially_Unevaluated (N : Node_Id) return Boolean is
15306 Par : Node_Id;
15307 Expr : Node_Id;
15308
15309 begin
15310 Expr := N;
15311 Par := Parent (N);
15312
15313 -- A postcondition whose expression is a short-circuit is broken down
15314 -- into individual aspects for better exception reporting. The original
15315 -- short-circuit expression is rewritten as the second operand, and an
15316 -- occurrence of 'Old in that operand is potentially unevaluated.
15317 -- See Sem_ch13.adb for details of this transformation.
15318
15319 if Nkind (Original_Node (Par)) = N_And_Then then
15320 return True;
15321 end if;
15322
15323 while not Nkind_In (Par, N_If_Expression,
15324 N_Case_Expression,
15325 N_And_Then,
15326 N_Or_Else,
15327 N_In,
15328 N_Not_In,
15329 N_Quantified_Expression)
15330 loop
15331 Expr := Par;
15332 Par := Parent (Par);
15333
15334 -- If the context is not an expression, or if is the result of
15335 -- expansion of an enclosing construct (such as another attribute)
15336 -- the predicate does not apply.
15337
15338 if Nkind (Par) = N_Case_Expression_Alternative then
15339 null;
15340
15341 elsif Nkind (Par) not in N_Subexpr
15342 or else not Comes_From_Source (Par)
15343 then
15344 return False;
15345 end if;
15346 end loop;
15347
15348 if Nkind (Par) = N_If_Expression then
15349 return Is_Elsif (Par) or else Expr /= First (Expressions (Par));
15350
15351 elsif Nkind (Par) = N_Case_Expression then
15352 return Expr /= Expression (Par);
15353
15354 elsif Nkind_In (Par, N_And_Then, N_Or_Else) then
15355 return Expr = Right_Opnd (Par);
15356
15357 elsif Nkind_In (Par, N_In, N_Not_In) then
15358
15359 -- If the membership includes several alternatives, only the first is
15360 -- definitely evaluated.
15361
15362 if Present (Alternatives (Par)) then
15363 return Expr /= First (Alternatives (Par));
15364
15365 -- If this is a range membership both bounds are evaluated
15366
15367 else
15368 return False;
15369 end if;
15370
15371 elsif Nkind (Par) = N_Quantified_Expression then
15372 return Expr = Condition (Par);
15373
15374 else
15375 return False;
15376 end if;
15377 end Is_Potentially_Unevaluated;
15378
15379 --------------------------------
15380 -- Is_Preelaborable_Aggregate --
15381 --------------------------------
15382
15383 function Is_Preelaborable_Aggregate (Aggr : Node_Id) return Boolean is
15384 Aggr_Typ : constant Entity_Id := Etype (Aggr);
15385 Array_Aggr : constant Boolean := Is_Array_Type (Aggr_Typ);
15386
15387 Anc_Part : Node_Id;
15388 Assoc : Node_Id;
15389 Choice : Node_Id;
15390 Comp_Typ : Entity_Id;
15391 Expr : Node_Id;
15392
15393 begin
15394 if Array_Aggr then
15395 Comp_Typ := Component_Type (Aggr_Typ);
15396 end if;
15397
15398 -- Inspect the ancestor part
15399
15400 if Nkind (Aggr) = N_Extension_Aggregate then
15401 Anc_Part := Ancestor_Part (Aggr);
15402
15403 -- The ancestor denotes a subtype mark
15404
15405 if Is_Entity_Name (Anc_Part)
15406 and then Is_Type (Entity (Anc_Part))
15407 then
15408 if not Has_Preelaborable_Initialization (Entity (Anc_Part)) then
15409 return False;
15410 end if;
15411
15412 -- Otherwise the ancestor denotes an expression
15413
15414 elsif not Is_Preelaborable_Construct (Anc_Part) then
15415 return False;
15416 end if;
15417 end if;
15418
15419 -- Inspect the positional associations
15420
15421 Expr := First (Expressions (Aggr));
15422 while Present (Expr) loop
15423 if not Is_Preelaborable_Construct (Expr) then
15424 return False;
15425 end if;
15426
15427 Next (Expr);
15428 end loop;
15429
15430 -- Inspect the named associations
15431
15432 Assoc := First (Component_Associations (Aggr));
15433 while Present (Assoc) loop
15434
15435 -- Inspect the choices of the current named association
15436
15437 Choice := First (Choices (Assoc));
15438 while Present (Choice) loop
15439 if Array_Aggr then
15440
15441 -- For a choice to be preelaborable, it must denote either a
15442 -- static range or a static expression.
15443
15444 if Nkind (Choice) = N_Others_Choice then
15445 null;
15446
15447 elsif Nkind (Choice) = N_Range then
15448 if not Is_OK_Static_Range (Choice) then
15449 return False;
15450 end if;
15451
15452 elsif not Is_OK_Static_Expression (Choice) then
15453 return False;
15454 end if;
15455
15456 else
15457 Comp_Typ := Etype (Choice);
15458 end if;
15459
15460 Next (Choice);
15461 end loop;
15462
15463 -- The type of the choice must have preelaborable initialization if
15464 -- the association carries a <>.
15465
15466 if Box_Present (Assoc) then
15467 if not Has_Preelaborable_Initialization (Comp_Typ) then
15468 return False;
15469 end if;
15470
15471 -- The type of the expression must have preelaborable initialization
15472
15473 elsif not Is_Preelaborable_Construct (Expression (Assoc)) then
15474 return False;
15475 end if;
15476
15477 Next (Assoc);
15478 end loop;
15479
15480 -- At this point the aggregate is preelaborable
15481
15482 return True;
15483 end Is_Preelaborable_Aggregate;
15484
15485 --------------------------------
15486 -- Is_Preelaborable_Construct --
15487 --------------------------------
15488
15489 function Is_Preelaborable_Construct (N : Node_Id) return Boolean is
15490 begin
15491 -- Aggregates
15492
15493 if Nkind_In (N, N_Aggregate, N_Extension_Aggregate) then
15494 return Is_Preelaborable_Aggregate (N);
15495
15496 -- Attributes are allowed in general, even if their prefix is a formal
15497 -- type. It seems that certain attributes known not to be static might
15498 -- not be allowed, but there are no rules to prevent them.
15499
15500 elsif Nkind (N) = N_Attribute_Reference then
15501 return True;
15502
15503 -- Expressions
15504
15505 elsif Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then
15506 return True;
15507
15508 elsif Nkind (N) = N_Qualified_Expression then
15509 return Is_Preelaborable_Construct (Expression (N));
15510
15511 -- Names are preelaborable when they denote a discriminant of an
15512 -- enclosing type. Discriminals are also considered for this check.
15513
15514 elsif Is_Entity_Name (N)
15515 and then Present (Entity (N))
15516 and then
15517 (Ekind (Entity (N)) = E_Discriminant
15518 or else (Ekind_In (Entity (N), E_Constant, E_In_Parameter)
15519 and then Present (Discriminal_Link (Entity (N)))))
15520 then
15521 return True;
15522
15523 -- Statements
15524
15525 elsif Nkind (N) = N_Null then
15526 return True;
15527
15528 -- Otherwise the construct is not preelaborable
15529
15530 else
15531 return False;
15532 end if;
15533 end Is_Preelaborable_Construct;
15534
15535 ---------------------------------
15536 -- Is_Protected_Self_Reference --
15537 ---------------------------------
15538
15539 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
15540
15541 function In_Access_Definition (N : Node_Id) return Boolean;
15542 -- Returns true if N belongs to an access definition
15543
15544 --------------------------
15545 -- In_Access_Definition --
15546 --------------------------
15547
15548 function In_Access_Definition (N : Node_Id) return Boolean is
15549 P : Node_Id;
15550
15551 begin
15552 P := Parent (N);
15553 while Present (P) loop
15554 if Nkind (P) = N_Access_Definition then
15555 return True;
15556 end if;
15557
15558 P := Parent (P);
15559 end loop;
15560
15561 return False;
15562 end In_Access_Definition;
15563
15564 -- Start of processing for Is_Protected_Self_Reference
15565
15566 begin
15567 -- Verify that prefix is analyzed and has the proper form. Note that
15568 -- the attributes Elab_Spec, Elab_Body, and Elab_Subp_Body, which also
15569 -- produce the address of an entity, do not analyze their prefix
15570 -- because they denote entities that are not necessarily visible.
15571 -- Neither of them can apply to a protected type.
15572
15573 return Ada_Version >= Ada_2005
15574 and then Is_Entity_Name (N)
15575 and then Present (Entity (N))
15576 and then Is_Protected_Type (Entity (N))
15577 and then In_Open_Scopes (Entity (N))
15578 and then not In_Access_Definition (N);
15579 end Is_Protected_Self_Reference;
15580
15581 -----------------------------
15582 -- Is_RCI_Pkg_Spec_Or_Body --
15583 -----------------------------
15584
15585 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
15586
15587 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
15588 -- Return True if the unit of Cunit is an RCI package declaration
15589
15590 ---------------------------
15591 -- Is_RCI_Pkg_Decl_Cunit --
15592 ---------------------------
15593
15594 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
15595 The_Unit : constant Node_Id := Unit (Cunit);
15596
15597 begin
15598 if Nkind (The_Unit) /= N_Package_Declaration then
15599 return False;
15600 end if;
15601
15602 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
15603 end Is_RCI_Pkg_Decl_Cunit;
15604
15605 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
15606
15607 begin
15608 return Is_RCI_Pkg_Decl_Cunit (Cunit)
15609 or else
15610 (Nkind (Unit (Cunit)) = N_Package_Body
15611 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
15612 end Is_RCI_Pkg_Spec_Or_Body;
15613
15614 -----------------------------------------
15615 -- Is_Remote_Access_To_Class_Wide_Type --
15616 -----------------------------------------
15617
15618 function Is_Remote_Access_To_Class_Wide_Type
15619 (E : Entity_Id) return Boolean
15620 is
15621 begin
15622 -- A remote access to class-wide type is a general access to object type
15623 -- declared in the visible part of a Remote_Types or Remote_Call_
15624 -- Interface unit.
15625
15626 return Ekind (E) = E_General_Access_Type
15627 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
15628 end Is_Remote_Access_To_Class_Wide_Type;
15629
15630 -----------------------------------------
15631 -- Is_Remote_Access_To_Subprogram_Type --
15632 -----------------------------------------
15633
15634 function Is_Remote_Access_To_Subprogram_Type
15635 (E : Entity_Id) return Boolean
15636 is
15637 begin
15638 return (Ekind (E) = E_Access_Subprogram_Type
15639 or else (Ekind (E) = E_Record_Type
15640 and then Present (Corresponding_Remote_Type (E))))
15641 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
15642 end Is_Remote_Access_To_Subprogram_Type;
15643
15644 --------------------
15645 -- Is_Remote_Call --
15646 --------------------
15647
15648 function Is_Remote_Call (N : Node_Id) return Boolean is
15649 begin
15650 if Nkind (N) not in N_Subprogram_Call then
15651
15652 -- An entry call cannot be remote
15653
15654 return False;
15655
15656 elsif Nkind (Name (N)) in N_Has_Entity
15657 and then Is_Remote_Call_Interface (Entity (Name (N)))
15658 then
15659 -- A subprogram declared in the spec of a RCI package is remote
15660
15661 return True;
15662
15663 elsif Nkind (Name (N)) = N_Explicit_Dereference
15664 and then Is_Remote_Access_To_Subprogram_Type
15665 (Etype (Prefix (Name (N))))
15666 then
15667 -- The dereference of a RAS is a remote call
15668
15669 return True;
15670
15671 elsif Present (Controlling_Argument (N))
15672 and then Is_Remote_Access_To_Class_Wide_Type
15673 (Etype (Controlling_Argument (N)))
15674 then
15675 -- Any primitive operation call with a controlling argument of
15676 -- a RACW type is a remote call.
15677
15678 return True;
15679 end if;
15680
15681 -- All other calls are local calls
15682
15683 return False;
15684 end Is_Remote_Call;
15685
15686 ----------------------
15687 -- Is_Renamed_Entry --
15688 ----------------------
15689
15690 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
15691 Orig_Node : Node_Id := Empty;
15692 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
15693
15694 function Is_Entry (Nam : Node_Id) return Boolean;
15695 -- Determine whether Nam is an entry. Traverse selectors if there are
15696 -- nested selected components.
15697
15698 --------------
15699 -- Is_Entry --
15700 --------------
15701
15702 function Is_Entry (Nam : Node_Id) return Boolean is
15703 begin
15704 if Nkind (Nam) = N_Selected_Component then
15705 return Is_Entry (Selector_Name (Nam));
15706 end if;
15707
15708 return Ekind (Entity (Nam)) = E_Entry;
15709 end Is_Entry;
15710
15711 -- Start of processing for Is_Renamed_Entry
15712
15713 begin
15714 if Present (Alias (Proc_Nam)) then
15715 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
15716 end if;
15717
15718 -- Look for a rewritten subprogram renaming declaration
15719
15720 if Nkind (Subp_Decl) = N_Subprogram_Declaration
15721 and then Present (Original_Node (Subp_Decl))
15722 then
15723 Orig_Node := Original_Node (Subp_Decl);
15724 end if;
15725
15726 -- The rewritten subprogram is actually an entry
15727
15728 if Present (Orig_Node)
15729 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
15730 and then Is_Entry (Name (Orig_Node))
15731 then
15732 return True;
15733 end if;
15734
15735 return False;
15736 end Is_Renamed_Entry;
15737
15738 -----------------------------
15739 -- Is_Renaming_Declaration --
15740 -----------------------------
15741
15742 function Is_Renaming_Declaration (N : Node_Id) return Boolean is
15743 begin
15744 case Nkind (N) is
15745 when N_Exception_Renaming_Declaration
15746 | N_Generic_Function_Renaming_Declaration
15747 | N_Generic_Package_Renaming_Declaration
15748 | N_Generic_Procedure_Renaming_Declaration
15749 | N_Object_Renaming_Declaration
15750 | N_Package_Renaming_Declaration
15751 | N_Subprogram_Renaming_Declaration
15752 =>
15753 return True;
15754
15755 when others =>
15756 return False;
15757 end case;
15758 end Is_Renaming_Declaration;
15759
15760 ----------------------------
15761 -- Is_Reversible_Iterator --
15762 ----------------------------
15763
15764 function Is_Reversible_Iterator (Typ : Entity_Id) return Boolean is
15765 Ifaces_List : Elist_Id;
15766 Iface_Elmt : Elmt_Id;
15767 Iface : Entity_Id;
15768
15769 begin
15770 if Is_Class_Wide_Type (Typ)
15771 and then Chars (Root_Type (Typ)) = Name_Reversible_Iterator
15772 and then In_Predefined_Unit (Root_Type (Typ))
15773 then
15774 return True;
15775
15776 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
15777 return False;
15778
15779 else
15780 Collect_Interfaces (Typ, Ifaces_List);
15781
15782 Iface_Elmt := First_Elmt (Ifaces_List);
15783 while Present (Iface_Elmt) loop
15784 Iface := Node (Iface_Elmt);
15785 if Chars (Iface) = Name_Reversible_Iterator
15786 and then In_Predefined_Unit (Iface)
15787 then
15788 return True;
15789 end if;
15790
15791 Next_Elmt (Iface_Elmt);
15792 end loop;
15793 end if;
15794
15795 return False;
15796 end Is_Reversible_Iterator;
15797
15798 ----------------------
15799 -- Is_Selector_Name --
15800 ----------------------
15801
15802 function Is_Selector_Name (N : Node_Id) return Boolean is
15803 begin
15804 if not Is_List_Member (N) then
15805 declare
15806 P : constant Node_Id := Parent (N);
15807 begin
15808 return Nkind_In (P, N_Expanded_Name,
15809 N_Generic_Association,
15810 N_Parameter_Association,
15811 N_Selected_Component)
15812 and then Selector_Name (P) = N;
15813 end;
15814
15815 else
15816 declare
15817 L : constant List_Id := List_Containing (N);
15818 P : constant Node_Id := Parent (L);
15819 begin
15820 return (Nkind (P) = N_Discriminant_Association
15821 and then Selector_Names (P) = L)
15822 or else
15823 (Nkind (P) = N_Component_Association
15824 and then Choices (P) = L);
15825 end;
15826 end if;
15827 end Is_Selector_Name;
15828
15829 ---------------------------------
15830 -- Is_Single_Concurrent_Object --
15831 ---------------------------------
15832
15833 function Is_Single_Concurrent_Object (Id : Entity_Id) return Boolean is
15834 begin
15835 return
15836 Is_Single_Protected_Object (Id) or else Is_Single_Task_Object (Id);
15837 end Is_Single_Concurrent_Object;
15838
15839 -------------------------------
15840 -- Is_Single_Concurrent_Type --
15841 -------------------------------
15842
15843 function Is_Single_Concurrent_Type (Id : Entity_Id) return Boolean is
15844 begin
15845 return
15846 Ekind_In (Id, E_Protected_Type, E_Task_Type)
15847 and then Is_Single_Concurrent_Type_Declaration
15848 (Declaration_Node (Id));
15849 end Is_Single_Concurrent_Type;
15850
15851 -------------------------------------------
15852 -- Is_Single_Concurrent_Type_Declaration --
15853 -------------------------------------------
15854
15855 function Is_Single_Concurrent_Type_Declaration
15856 (N : Node_Id) return Boolean
15857 is
15858 begin
15859 return Nkind_In (Original_Node (N), N_Single_Protected_Declaration,
15860 N_Single_Task_Declaration);
15861 end Is_Single_Concurrent_Type_Declaration;
15862
15863 ---------------------------------------------
15864 -- Is_Single_Precision_Floating_Point_Type --
15865 ---------------------------------------------
15866
15867 function Is_Single_Precision_Floating_Point_Type
15868 (E : Entity_Id) return Boolean is
15869 begin
15870 return Is_Floating_Point_Type (E)
15871 and then Machine_Radix_Value (E) = Uint_2
15872 and then Machine_Mantissa_Value (E) = Uint_24
15873 and then Machine_Emax_Value (E) = Uint_2 ** Uint_7
15874 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_7);
15875 end Is_Single_Precision_Floating_Point_Type;
15876
15877 --------------------------------
15878 -- Is_Single_Protected_Object --
15879 --------------------------------
15880
15881 function Is_Single_Protected_Object (Id : Entity_Id) return Boolean is
15882 begin
15883 return
15884 Ekind (Id) = E_Variable
15885 and then Ekind (Etype (Id)) = E_Protected_Type
15886 and then Is_Single_Concurrent_Type (Etype (Id));
15887 end Is_Single_Protected_Object;
15888
15889 ---------------------------
15890 -- Is_Single_Task_Object --
15891 ---------------------------
15892
15893 function Is_Single_Task_Object (Id : Entity_Id) return Boolean is
15894 begin
15895 return
15896 Ekind (Id) = E_Variable
15897 and then Ekind (Etype (Id)) = E_Task_Type
15898 and then Is_Single_Concurrent_Type (Etype (Id));
15899 end Is_Single_Task_Object;
15900
15901 -------------------------------------
15902 -- Is_SPARK_05_Initialization_Expr --
15903 -------------------------------------
15904
15905 function Is_SPARK_05_Initialization_Expr (N : Node_Id) return Boolean is
15906 Is_Ok : Boolean;
15907 Expr : Node_Id;
15908 Comp_Assn : Node_Id;
15909 Orig_N : constant Node_Id := Original_Node (N);
15910
15911 begin
15912 Is_Ok := True;
15913
15914 if not Comes_From_Source (Orig_N) then
15915 goto Done;
15916 end if;
15917
15918 pragma Assert (Nkind (Orig_N) in N_Subexpr);
15919
15920 case Nkind (Orig_N) is
15921 when N_Character_Literal
15922 | N_Integer_Literal
15923 | N_Real_Literal
15924 | N_String_Literal
15925 =>
15926 null;
15927
15928 when N_Expanded_Name
15929 | N_Identifier
15930 =>
15931 if Is_Entity_Name (Orig_N)
15932 and then Present (Entity (Orig_N)) -- needed in some cases
15933 then
15934 case Ekind (Entity (Orig_N)) is
15935 when E_Constant
15936 | E_Enumeration_Literal
15937 | E_Named_Integer
15938 | E_Named_Real
15939 =>
15940 null;
15941
15942 when others =>
15943 if Is_Type (Entity (Orig_N)) then
15944 null;
15945 else
15946 Is_Ok := False;
15947 end if;
15948 end case;
15949 end if;
15950
15951 when N_Qualified_Expression
15952 | N_Type_Conversion
15953 =>
15954 Is_Ok := Is_SPARK_05_Initialization_Expr (Expression (Orig_N));
15955
15956 when N_Unary_Op =>
15957 Is_Ok := Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
15958
15959 when N_Binary_Op
15960 | N_Membership_Test
15961 | N_Short_Circuit
15962 =>
15963 Is_Ok := Is_SPARK_05_Initialization_Expr (Left_Opnd (Orig_N))
15964 and then
15965 Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
15966
15967 when N_Aggregate
15968 | N_Extension_Aggregate
15969 =>
15970 if Nkind (Orig_N) = N_Extension_Aggregate then
15971 Is_Ok :=
15972 Is_SPARK_05_Initialization_Expr (Ancestor_Part (Orig_N));
15973 end if;
15974
15975 Expr := First (Expressions (Orig_N));
15976 while Present (Expr) loop
15977 if not Is_SPARK_05_Initialization_Expr (Expr) then
15978 Is_Ok := False;
15979 goto Done;
15980 end if;
15981
15982 Next (Expr);
15983 end loop;
15984
15985 Comp_Assn := First (Component_Associations (Orig_N));
15986 while Present (Comp_Assn) loop
15987 Expr := Expression (Comp_Assn);
15988
15989 -- Note: test for Present here needed for box assocation
15990
15991 if Present (Expr)
15992 and then not Is_SPARK_05_Initialization_Expr (Expr)
15993 then
15994 Is_Ok := False;
15995 goto Done;
15996 end if;
15997
15998 Next (Comp_Assn);
15999 end loop;
16000
16001 when N_Attribute_Reference =>
16002 if Nkind (Prefix (Orig_N)) in N_Subexpr then
16003 Is_Ok := Is_SPARK_05_Initialization_Expr (Prefix (Orig_N));
16004 end if;
16005
16006 Expr := First (Expressions (Orig_N));
16007 while Present (Expr) loop
16008 if not Is_SPARK_05_Initialization_Expr (Expr) then
16009 Is_Ok := False;
16010 goto Done;
16011 end if;
16012
16013 Next (Expr);
16014 end loop;
16015
16016 -- Selected components might be expanded named not yet resolved, so
16017 -- default on the safe side. (Eg on sparklex.ads)
16018
16019 when N_Selected_Component =>
16020 null;
16021
16022 when others =>
16023 Is_Ok := False;
16024 end case;
16025
16026 <<Done>>
16027 return Is_Ok;
16028 end Is_SPARK_05_Initialization_Expr;
16029
16030 ----------------------------------
16031 -- Is_SPARK_05_Object_Reference --
16032 ----------------------------------
16033
16034 function Is_SPARK_05_Object_Reference (N : Node_Id) return Boolean is
16035 begin
16036 if Is_Entity_Name (N) then
16037 return Present (Entity (N))
16038 and then
16039 (Ekind_In (Entity (N), E_Constant, E_Variable)
16040 or else Ekind (Entity (N)) in Formal_Kind);
16041
16042 else
16043 case Nkind (N) is
16044 when N_Selected_Component =>
16045 return Is_SPARK_05_Object_Reference (Prefix (N));
16046
16047 when others =>
16048 return False;
16049 end case;
16050 end if;
16051 end Is_SPARK_05_Object_Reference;
16052
16053 -----------------------------
16054 -- Is_Specific_Tagged_Type --
16055 -----------------------------
16056
16057 function Is_Specific_Tagged_Type (Typ : Entity_Id) return Boolean is
16058 Full_Typ : Entity_Id;
16059
16060 begin
16061 -- Handle private types
16062
16063 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
16064 Full_Typ := Full_View (Typ);
16065 else
16066 Full_Typ := Typ;
16067 end if;
16068
16069 -- A specific tagged type is a non-class-wide tagged type
16070
16071 return Is_Tagged_Type (Full_Typ) and not Is_Class_Wide_Type (Full_Typ);
16072 end Is_Specific_Tagged_Type;
16073
16074 ------------------
16075 -- Is_Statement --
16076 ------------------
16077
16078 function Is_Statement (N : Node_Id) return Boolean is
16079 begin
16080 return
16081 Nkind (N) in N_Statement_Other_Than_Procedure_Call
16082 or else Nkind (N) = N_Procedure_Call_Statement;
16083 end Is_Statement;
16084
16085 ---------------------------------------
16086 -- Is_Subprogram_Contract_Annotation --
16087 ---------------------------------------
16088
16089 function Is_Subprogram_Contract_Annotation
16090 (Item : Node_Id) return Boolean
16091 is
16092 Nam : Name_Id;
16093
16094 begin
16095 if Nkind (Item) = N_Aspect_Specification then
16096 Nam := Chars (Identifier (Item));
16097
16098 else pragma Assert (Nkind (Item) = N_Pragma);
16099 Nam := Pragma_Name (Item);
16100 end if;
16101
16102 return Nam = Name_Contract_Cases
16103 or else Nam = Name_Depends
16104 or else Nam = Name_Extensions_Visible
16105 or else Nam = Name_Global
16106 or else Nam = Name_Post
16107 or else Nam = Name_Post_Class
16108 or else Nam = Name_Postcondition
16109 or else Nam = Name_Pre
16110 or else Nam = Name_Pre_Class
16111 or else Nam = Name_Precondition
16112 or else Nam = Name_Refined_Depends
16113 or else Nam = Name_Refined_Global
16114 or else Nam = Name_Refined_Post
16115 or else Nam = Name_Test_Case;
16116 end Is_Subprogram_Contract_Annotation;
16117
16118 --------------------------------------------------
16119 -- Is_Subprogram_Stub_Without_Prior_Declaration --
16120 --------------------------------------------------
16121
16122 function Is_Subprogram_Stub_Without_Prior_Declaration
16123 (N : Node_Id) return Boolean
16124 is
16125 begin
16126 -- A subprogram stub without prior declaration serves as declaration for
16127 -- the actual subprogram body. As such, it has an attached defining
16128 -- entity of E_[Generic_]Function or E_[Generic_]Procedure.
16129
16130 return Nkind (N) = N_Subprogram_Body_Stub
16131 and then Ekind (Defining_Entity (N)) /= E_Subprogram_Body;
16132 end Is_Subprogram_Stub_Without_Prior_Declaration;
16133
16134 --------------------------
16135 -- Is_Suspension_Object --
16136 --------------------------
16137
16138 function Is_Suspension_Object (Id : Entity_Id) return Boolean is
16139 begin
16140 -- This approach does an exact name match rather than to rely on
16141 -- RTSfind. Routine Is_Effectively_Volatile is used by clients of the
16142 -- front end at point where all auxiliary tables are locked and any
16143 -- modifications to them are treated as violations. Do not tamper with
16144 -- the tables, instead examine the Chars fields of all the scopes of Id.
16145
16146 return
16147 Chars (Id) = Name_Suspension_Object
16148 and then Present (Scope (Id))
16149 and then Chars (Scope (Id)) = Name_Synchronous_Task_Control
16150 and then Present (Scope (Scope (Id)))
16151 and then Chars (Scope (Scope (Id))) = Name_Ada
16152 and then Present (Scope (Scope (Scope (Id))))
16153 and then Scope (Scope (Scope (Id))) = Standard_Standard;
16154 end Is_Suspension_Object;
16155
16156 ----------------------------
16157 -- Is_Synchronized_Object --
16158 ----------------------------
16159
16160 function Is_Synchronized_Object (Id : Entity_Id) return Boolean is
16161 Prag : Node_Id;
16162
16163 begin
16164 if Is_Object (Id) then
16165
16166 -- The object is synchronized if it is of a type that yields a
16167 -- synchronized object.
16168
16169 if Yields_Synchronized_Object (Etype (Id)) then
16170 return True;
16171
16172 -- The object is synchronized if it is atomic and Async_Writers is
16173 -- enabled.
16174
16175 elsif Is_Atomic (Id) and then Async_Writers_Enabled (Id) then
16176 return True;
16177
16178 -- A constant is a synchronized object by default
16179
16180 elsif Ekind (Id) = E_Constant then
16181 return True;
16182
16183 -- A variable is a synchronized object if it is subject to pragma
16184 -- Constant_After_Elaboration.
16185
16186 elsif Ekind (Id) = E_Variable then
16187 Prag := Get_Pragma (Id, Pragma_Constant_After_Elaboration);
16188
16189 return Present (Prag) and then Is_Enabled_Pragma (Prag);
16190 end if;
16191 end if;
16192
16193 -- Otherwise the input is not an object or it does not qualify as a
16194 -- synchronized object.
16195
16196 return False;
16197 end Is_Synchronized_Object;
16198
16199 ---------------------------------
16200 -- Is_Synchronized_Tagged_Type --
16201 ---------------------------------
16202
16203 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
16204 Kind : constant Entity_Kind := Ekind (Base_Type (E));
16205
16206 begin
16207 -- A task or protected type derived from an interface is a tagged type.
16208 -- Such a tagged type is called a synchronized tagged type, as are
16209 -- synchronized interfaces and private extensions whose declaration
16210 -- includes the reserved word synchronized.
16211
16212 return (Is_Tagged_Type (E)
16213 and then (Kind = E_Task_Type
16214 or else
16215 Kind = E_Protected_Type))
16216 or else
16217 (Is_Interface (E)
16218 and then Is_Synchronized_Interface (E))
16219 or else
16220 (Ekind (E) = E_Record_Type_With_Private
16221 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
16222 and then (Synchronized_Present (Parent (E))
16223 or else Is_Synchronized_Interface (Etype (E))));
16224 end Is_Synchronized_Tagged_Type;
16225
16226 -----------------
16227 -- Is_Transfer --
16228 -----------------
16229
16230 function Is_Transfer (N : Node_Id) return Boolean is
16231 Kind : constant Node_Kind := Nkind (N);
16232
16233 begin
16234 if Kind = N_Simple_Return_Statement
16235 or else
16236 Kind = N_Extended_Return_Statement
16237 or else
16238 Kind = N_Goto_Statement
16239 or else
16240 Kind = N_Raise_Statement
16241 or else
16242 Kind = N_Requeue_Statement
16243 then
16244 return True;
16245
16246 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
16247 and then No (Condition (N))
16248 then
16249 return True;
16250
16251 elsif Kind = N_Procedure_Call_Statement
16252 and then Is_Entity_Name (Name (N))
16253 and then Present (Entity (Name (N)))
16254 and then No_Return (Entity (Name (N)))
16255 then
16256 return True;
16257
16258 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
16259 return True;
16260
16261 else
16262 return False;
16263 end if;
16264 end Is_Transfer;
16265
16266 -------------
16267 -- Is_True --
16268 -------------
16269
16270 function Is_True (U : Uint) return Boolean is
16271 begin
16272 return (U /= 0);
16273 end Is_True;
16274
16275 --------------------------------------
16276 -- Is_Unchecked_Conversion_Instance --
16277 --------------------------------------
16278
16279 function Is_Unchecked_Conversion_Instance (Id : Entity_Id) return Boolean is
16280 Par : Node_Id;
16281
16282 begin
16283 -- Look for a function whose generic parent is the predefined intrinsic
16284 -- function Unchecked_Conversion, or for one that renames such an
16285 -- instance.
16286
16287 if Ekind (Id) = E_Function then
16288 Par := Parent (Id);
16289
16290 if Nkind (Par) = N_Function_Specification then
16291 Par := Generic_Parent (Par);
16292
16293 if Present (Par) then
16294 return
16295 Chars (Par) = Name_Unchecked_Conversion
16296 and then Is_Intrinsic_Subprogram (Par)
16297 and then In_Predefined_Unit (Par);
16298 else
16299 return
16300 Present (Alias (Id))
16301 and then Is_Unchecked_Conversion_Instance (Alias (Id));
16302 end if;
16303 end if;
16304 end if;
16305
16306 return False;
16307 end Is_Unchecked_Conversion_Instance;
16308
16309 -------------------------------
16310 -- Is_Universal_Numeric_Type --
16311 -------------------------------
16312
16313 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
16314 begin
16315 return T = Universal_Integer or else T = Universal_Real;
16316 end Is_Universal_Numeric_Type;
16317
16318 ------------------------------
16319 -- Is_User_Defined_Equality --
16320 ------------------------------
16321
16322 function Is_User_Defined_Equality (Id : Entity_Id) return Boolean is
16323 begin
16324 return Ekind (Id) = E_Function
16325 and then Chars (Id) = Name_Op_Eq
16326 and then Comes_From_Source (Id)
16327
16328 -- Internally generated equalities have a full type declaration
16329 -- as their parent.
16330
16331 and then Nkind (Parent (Id)) = N_Function_Specification;
16332 end Is_User_Defined_Equality;
16333
16334 --------------------------------------
16335 -- Is_Validation_Variable_Reference --
16336 --------------------------------------
16337
16338 function Is_Validation_Variable_Reference (N : Node_Id) return Boolean is
16339 Var : constant Node_Id := Unqual_Conv (N);
16340 Var_Id : Entity_Id;
16341
16342 begin
16343 Var_Id := Empty;
16344
16345 if Is_Entity_Name (Var) then
16346 Var_Id := Entity (Var);
16347 end if;
16348
16349 return
16350 Present (Var_Id)
16351 and then Ekind (Var_Id) = E_Variable
16352 and then Present (Validated_Object (Var_Id));
16353 end Is_Validation_Variable_Reference;
16354
16355 ----------------------------
16356 -- Is_Variable_Size_Array --
16357 ----------------------------
16358
16359 function Is_Variable_Size_Array (E : Entity_Id) return Boolean is
16360 Idx : Node_Id;
16361
16362 begin
16363 pragma Assert (Is_Array_Type (E));
16364
16365 -- Check if some index is initialized with a non-constant value
16366
16367 Idx := First_Index (E);
16368 while Present (Idx) loop
16369 if Nkind (Idx) = N_Range then
16370 if not Is_Constant_Bound (Low_Bound (Idx))
16371 or else not Is_Constant_Bound (High_Bound (Idx))
16372 then
16373 return True;
16374 end if;
16375 end if;
16376
16377 Idx := Next_Index (Idx);
16378 end loop;
16379
16380 return False;
16381 end Is_Variable_Size_Array;
16382
16383 -----------------------------
16384 -- Is_Variable_Size_Record --
16385 -----------------------------
16386
16387 function Is_Variable_Size_Record (E : Entity_Id) return Boolean is
16388 Comp : Entity_Id;
16389 Comp_Typ : Entity_Id;
16390
16391 begin
16392 pragma Assert (Is_Record_Type (E));
16393
16394 Comp := First_Entity (E);
16395 while Present (Comp) loop
16396 Comp_Typ := Etype (Comp);
16397
16398 -- Recursive call if the record type has discriminants
16399
16400 if Is_Record_Type (Comp_Typ)
16401 and then Has_Discriminants (Comp_Typ)
16402 and then Is_Variable_Size_Record (Comp_Typ)
16403 then
16404 return True;
16405
16406 elsif Is_Array_Type (Comp_Typ)
16407 and then Is_Variable_Size_Array (Comp_Typ)
16408 then
16409 return True;
16410 end if;
16411
16412 Next_Entity (Comp);
16413 end loop;
16414
16415 return False;
16416 end Is_Variable_Size_Record;
16417
16418 -----------------
16419 -- Is_Variable --
16420 -----------------
16421
16422 function Is_Variable
16423 (N : Node_Id;
16424 Use_Original_Node : Boolean := True) return Boolean
16425 is
16426 Orig_Node : Node_Id;
16427
16428 function In_Protected_Function (E : Entity_Id) return Boolean;
16429 -- Within a protected function, the private components of the enclosing
16430 -- protected type are constants. A function nested within a (protected)
16431 -- procedure is not itself protected. Within the body of a protected
16432 -- function the current instance of the protected type is a constant.
16433
16434 function Is_Variable_Prefix (P : Node_Id) return Boolean;
16435 -- Prefixes can involve implicit dereferences, in which case we must
16436 -- test for the case of a reference of a constant access type, which can
16437 -- can never be a variable.
16438
16439 ---------------------------
16440 -- In_Protected_Function --
16441 ---------------------------
16442
16443 function In_Protected_Function (E : Entity_Id) return Boolean is
16444 Prot : Entity_Id;
16445 S : Entity_Id;
16446
16447 begin
16448 -- E is the current instance of a type
16449
16450 if Is_Type (E) then
16451 Prot := E;
16452
16453 -- E is an object
16454
16455 else
16456 Prot := Scope (E);
16457 end if;
16458
16459 if not Is_Protected_Type (Prot) then
16460 return False;
16461
16462 else
16463 S := Current_Scope;
16464 while Present (S) and then S /= Prot loop
16465 if Ekind (S) = E_Function and then Scope (S) = Prot then
16466 return True;
16467 end if;
16468
16469 S := Scope (S);
16470 end loop;
16471
16472 return False;
16473 end if;
16474 end In_Protected_Function;
16475
16476 ------------------------
16477 -- Is_Variable_Prefix --
16478 ------------------------
16479
16480 function Is_Variable_Prefix (P : Node_Id) return Boolean is
16481 begin
16482 if Is_Access_Type (Etype (P)) then
16483 return not Is_Access_Constant (Root_Type (Etype (P)));
16484
16485 -- For the case of an indexed component whose prefix has a packed
16486 -- array type, the prefix has been rewritten into a type conversion.
16487 -- Determine variable-ness from the converted expression.
16488
16489 elsif Nkind (P) = N_Type_Conversion
16490 and then not Comes_From_Source (P)
16491 and then Is_Array_Type (Etype (P))
16492 and then Is_Packed (Etype (P))
16493 then
16494 return Is_Variable (Expression (P));
16495
16496 else
16497 return Is_Variable (P);
16498 end if;
16499 end Is_Variable_Prefix;
16500
16501 -- Start of processing for Is_Variable
16502
16503 begin
16504 -- Special check, allow x'Deref(expr) as a variable
16505
16506 if Nkind (N) = N_Attribute_Reference
16507 and then Attribute_Name (N) = Name_Deref
16508 then
16509 return True;
16510 end if;
16511
16512 -- Check if we perform the test on the original node since this may be a
16513 -- test of syntactic categories which must not be disturbed by whatever
16514 -- rewriting might have occurred. For example, an aggregate, which is
16515 -- certainly NOT a variable, could be turned into a variable by
16516 -- expansion.
16517
16518 if Use_Original_Node then
16519 Orig_Node := Original_Node (N);
16520 else
16521 Orig_Node := N;
16522 end if;
16523
16524 -- Definitely OK if Assignment_OK is set. Since this is something that
16525 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
16526
16527 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
16528 return True;
16529
16530 -- Normally we go to the original node, but there is one exception where
16531 -- we use the rewritten node, namely when it is an explicit dereference.
16532 -- The generated code may rewrite a prefix which is an access type with
16533 -- an explicit dereference. The dereference is a variable, even though
16534 -- the original node may not be (since it could be a constant of the
16535 -- access type).
16536
16537 -- In Ada 2005 we have a further case to consider: the prefix may be a
16538 -- function call given in prefix notation. The original node appears to
16539 -- be a selected component, but we need to examine the call.
16540
16541 elsif Nkind (N) = N_Explicit_Dereference
16542 and then Nkind (Orig_Node) /= N_Explicit_Dereference
16543 and then Present (Etype (Orig_Node))
16544 and then Is_Access_Type (Etype (Orig_Node))
16545 then
16546 -- Note that if the prefix is an explicit dereference that does not
16547 -- come from source, we must check for a rewritten function call in
16548 -- prefixed notation before other forms of rewriting, to prevent a
16549 -- compiler crash.
16550
16551 return
16552 (Nkind (Orig_Node) = N_Function_Call
16553 and then not Is_Access_Constant (Etype (Prefix (N))))
16554 or else
16555 Is_Variable_Prefix (Original_Node (Prefix (N)));
16556
16557 -- in Ada 2012, the dereference may have been added for a type with
16558 -- a declared implicit dereference aspect. Check that it is not an
16559 -- access to constant.
16560
16561 elsif Nkind (N) = N_Explicit_Dereference
16562 and then Present (Etype (Orig_Node))
16563 and then Ada_Version >= Ada_2012
16564 and then Has_Implicit_Dereference (Etype (Orig_Node))
16565 then
16566 return not Is_Access_Constant (Etype (Prefix (N)));
16567
16568 -- A function call is never a variable
16569
16570 elsif Nkind (N) = N_Function_Call then
16571 return False;
16572
16573 -- All remaining checks use the original node
16574
16575 elsif Is_Entity_Name (Orig_Node)
16576 and then Present (Entity (Orig_Node))
16577 then
16578 declare
16579 E : constant Entity_Id := Entity (Orig_Node);
16580 K : constant Entity_Kind := Ekind (E);
16581
16582 begin
16583 return (K = E_Variable
16584 and then Nkind (Parent (E)) /= N_Exception_Handler)
16585 or else (K = E_Component
16586 and then not In_Protected_Function (E))
16587 or else K = E_Out_Parameter
16588 or else K = E_In_Out_Parameter
16589 or else K = E_Generic_In_Out_Parameter
16590
16591 -- Current instance of type. If this is a protected type, check
16592 -- we are not within the body of one of its protected functions.
16593
16594 or else (Is_Type (E)
16595 and then In_Open_Scopes (E)
16596 and then not In_Protected_Function (E))
16597
16598 or else (Is_Incomplete_Or_Private_Type (E)
16599 and then In_Open_Scopes (Full_View (E)));
16600 end;
16601
16602 else
16603 case Nkind (Orig_Node) is
16604 when N_Indexed_Component
16605 | N_Slice
16606 =>
16607 return Is_Variable_Prefix (Prefix (Orig_Node));
16608
16609 when N_Selected_Component =>
16610 return (Is_Variable (Selector_Name (Orig_Node))
16611 and then Is_Variable_Prefix (Prefix (Orig_Node)))
16612 or else
16613 (Nkind (N) = N_Expanded_Name
16614 and then Scope (Entity (N)) = Entity (Prefix (N)));
16615
16616 -- For an explicit dereference, the type of the prefix cannot
16617 -- be an access to constant or an access to subprogram.
16618
16619 when N_Explicit_Dereference =>
16620 declare
16621 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
16622 begin
16623 return Is_Access_Type (Typ)
16624 and then not Is_Access_Constant (Root_Type (Typ))
16625 and then Ekind (Typ) /= E_Access_Subprogram_Type;
16626 end;
16627
16628 -- The type conversion is the case where we do not deal with the
16629 -- context dependent special case of an actual parameter. Thus
16630 -- the type conversion is only considered a variable for the
16631 -- purposes of this routine if the target type is tagged. However,
16632 -- a type conversion is considered to be a variable if it does not
16633 -- come from source (this deals for example with the conversions
16634 -- of expressions to their actual subtypes).
16635
16636 when N_Type_Conversion =>
16637 return Is_Variable (Expression (Orig_Node))
16638 and then
16639 (not Comes_From_Source (Orig_Node)
16640 or else
16641 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
16642 and then
16643 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
16644
16645 -- GNAT allows an unchecked type conversion as a variable. This
16646 -- only affects the generation of internal expanded code, since
16647 -- calls to instantiations of Unchecked_Conversion are never
16648 -- considered variables (since they are function calls).
16649
16650 when N_Unchecked_Type_Conversion =>
16651 return Is_Variable (Expression (Orig_Node));
16652
16653 when others =>
16654 return False;
16655 end case;
16656 end if;
16657 end Is_Variable;
16658
16659 ------------------------------
16660 -- Is_Verifiable_DIC_Pragma --
16661 ------------------------------
16662
16663 function Is_Verifiable_DIC_Pragma (Prag : Node_Id) return Boolean is
16664 Args : constant List_Id := Pragma_Argument_Associations (Prag);
16665
16666 begin
16667 -- To qualify as verifiable, a DIC pragma must have a non-null argument
16668
16669 return
16670 Present (Args)
16671 and then Nkind (Get_Pragma_Arg (First (Args))) /= N_Null;
16672 end Is_Verifiable_DIC_Pragma;
16673
16674 ---------------------------
16675 -- Is_Visibly_Controlled --
16676 ---------------------------
16677
16678 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
16679 Root : constant Entity_Id := Root_Type (T);
16680 begin
16681 return Chars (Scope (Root)) = Name_Finalization
16682 and then Chars (Scope (Scope (Root))) = Name_Ada
16683 and then Scope (Scope (Scope (Root))) = Standard_Standard;
16684 end Is_Visibly_Controlled;
16685
16686 --------------------------
16687 -- Is_Volatile_Function --
16688 --------------------------
16689
16690 function Is_Volatile_Function (Func_Id : Entity_Id) return Boolean is
16691 begin
16692 pragma Assert (Ekind_In (Func_Id, E_Function, E_Generic_Function));
16693
16694 -- A function declared within a protected type is volatile
16695
16696 if Is_Protected_Type (Scope (Func_Id)) then
16697 return True;
16698
16699 -- An instance of Ada.Unchecked_Conversion is a volatile function if
16700 -- either the source or the target are effectively volatile.
16701
16702 elsif Is_Unchecked_Conversion_Instance (Func_Id)
16703 and then Has_Effectively_Volatile_Profile (Func_Id)
16704 then
16705 return True;
16706
16707 -- Otherwise the function is treated as volatile if it is subject to
16708 -- enabled pragma Volatile_Function.
16709
16710 else
16711 return
16712 Is_Enabled_Pragma (Get_Pragma (Func_Id, Pragma_Volatile_Function));
16713 end if;
16714 end Is_Volatile_Function;
16715
16716 ------------------------
16717 -- Is_Volatile_Object --
16718 ------------------------
16719
16720 function Is_Volatile_Object (N : Node_Id) return Boolean is
16721 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
16722 -- If prefix is an implicit dereference, examine designated type
16723
16724 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
16725 -- Determines if given object has volatile components
16726
16727 ------------------------
16728 -- Is_Volatile_Prefix --
16729 ------------------------
16730
16731 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
16732 Typ : constant Entity_Id := Etype (N);
16733
16734 begin
16735 if Is_Access_Type (Typ) then
16736 declare
16737 Dtyp : constant Entity_Id := Designated_Type (Typ);
16738
16739 begin
16740 return Is_Volatile (Dtyp)
16741 or else Has_Volatile_Components (Dtyp);
16742 end;
16743
16744 else
16745 return Object_Has_Volatile_Components (N);
16746 end if;
16747 end Is_Volatile_Prefix;
16748
16749 ------------------------------------
16750 -- Object_Has_Volatile_Components --
16751 ------------------------------------
16752
16753 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
16754 Typ : constant Entity_Id := Etype (N);
16755
16756 begin
16757 if Is_Volatile (Typ)
16758 or else Has_Volatile_Components (Typ)
16759 then
16760 return True;
16761
16762 elsif Is_Entity_Name (N)
16763 and then (Has_Volatile_Components (Entity (N))
16764 or else Is_Volatile (Entity (N)))
16765 then
16766 return True;
16767
16768 elsif Nkind (N) = N_Indexed_Component
16769 or else Nkind (N) = N_Selected_Component
16770 then
16771 return Is_Volatile_Prefix (Prefix (N));
16772
16773 else
16774 return False;
16775 end if;
16776 end Object_Has_Volatile_Components;
16777
16778 -- Start of processing for Is_Volatile_Object
16779
16780 begin
16781 if Nkind (N) = N_Defining_Identifier then
16782 return Is_Volatile (N) or else Is_Volatile (Etype (N));
16783
16784 elsif Nkind (N) = N_Expanded_Name then
16785 return Is_Volatile_Object (Entity (N));
16786
16787 elsif Is_Volatile (Etype (N))
16788 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
16789 then
16790 return True;
16791
16792 elsif Nkind_In (N, N_Indexed_Component, N_Selected_Component)
16793 and then Is_Volatile_Prefix (Prefix (N))
16794 then
16795 return True;
16796
16797 elsif Nkind (N) = N_Selected_Component
16798 and then Is_Volatile (Entity (Selector_Name (N)))
16799 then
16800 return True;
16801
16802 else
16803 return False;
16804 end if;
16805 end Is_Volatile_Object;
16806
16807 -----------------------------
16808 -- Iterate_Call_Parameters --
16809 -----------------------------
16810
16811 procedure Iterate_Call_Parameters (Call : Node_Id) is
16812 Formal : Entity_Id := First_Formal (Get_Called_Entity (Call));
16813 Actual : Node_Id := First_Actual (Call);
16814
16815 begin
16816 while Present (Formal) and then Present (Actual) loop
16817 Handle_Parameter (Formal, Actual);
16818 Formal := Next_Formal (Formal);
16819 Actual := Next_Actual (Actual);
16820 end loop;
16821 end Iterate_Call_Parameters;
16822
16823 ---------------------------
16824 -- Itype_Has_Declaration --
16825 ---------------------------
16826
16827 function Itype_Has_Declaration (Id : Entity_Id) return Boolean is
16828 begin
16829 pragma Assert (Is_Itype (Id));
16830 return Present (Parent (Id))
16831 and then Nkind_In (Parent (Id), N_Full_Type_Declaration,
16832 N_Subtype_Declaration)
16833 and then Defining_Entity (Parent (Id)) = Id;
16834 end Itype_Has_Declaration;
16835
16836 -------------------------
16837 -- Kill_Current_Values --
16838 -------------------------
16839
16840 procedure Kill_Current_Values
16841 (Ent : Entity_Id;
16842 Last_Assignment_Only : Boolean := False)
16843 is
16844 begin
16845 if Is_Assignable (Ent) then
16846 Set_Last_Assignment (Ent, Empty);
16847 end if;
16848
16849 if Is_Object (Ent) then
16850 if not Last_Assignment_Only then
16851 Kill_Checks (Ent);
16852 Set_Current_Value (Ent, Empty);
16853
16854 -- Do not reset the Is_Known_[Non_]Null and Is_Known_Valid flags
16855 -- for a constant. Once the constant is elaborated, its value is
16856 -- not changed, therefore the associated flags that describe the
16857 -- value should not be modified either.
16858
16859 if Ekind (Ent) = E_Constant then
16860 null;
16861
16862 -- Non-constant entities
16863
16864 else
16865 if not Can_Never_Be_Null (Ent) then
16866 Set_Is_Known_Non_Null (Ent, False);
16867 end if;
16868
16869 Set_Is_Known_Null (Ent, False);
16870
16871 -- Reset the Is_Known_Valid flag unless the type is always
16872 -- valid. This does not apply to a loop parameter because its
16873 -- bounds are defined by the loop header and therefore always
16874 -- valid.
16875
16876 if not Is_Known_Valid (Etype (Ent))
16877 and then Ekind (Ent) /= E_Loop_Parameter
16878 then
16879 Set_Is_Known_Valid (Ent, False);
16880 end if;
16881 end if;
16882 end if;
16883 end if;
16884 end Kill_Current_Values;
16885
16886 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
16887 S : Entity_Id;
16888
16889 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
16890 -- Clear current value for entity E and all entities chained to E
16891
16892 ------------------------------------------
16893 -- Kill_Current_Values_For_Entity_Chain --
16894 ------------------------------------------
16895
16896 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
16897 Ent : Entity_Id;
16898 begin
16899 Ent := E;
16900 while Present (Ent) loop
16901 Kill_Current_Values (Ent, Last_Assignment_Only);
16902 Next_Entity (Ent);
16903 end loop;
16904 end Kill_Current_Values_For_Entity_Chain;
16905
16906 -- Start of processing for Kill_Current_Values
16907
16908 begin
16909 -- Kill all saved checks, a special case of killing saved values
16910
16911 if not Last_Assignment_Only then
16912 Kill_All_Checks;
16913 end if;
16914
16915 -- Loop through relevant scopes, which includes the current scope and
16916 -- any parent scopes if the current scope is a block or a package.
16917
16918 S := Current_Scope;
16919 Scope_Loop : loop
16920
16921 -- Clear current values of all entities in current scope
16922
16923 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
16924
16925 -- If scope is a package, also clear current values of all private
16926 -- entities in the scope.
16927
16928 if Is_Package_Or_Generic_Package (S)
16929 or else Is_Concurrent_Type (S)
16930 then
16931 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
16932 end if;
16933
16934 -- If this is a not a subprogram, deal with parents
16935
16936 if not Is_Subprogram (S) then
16937 S := Scope (S);
16938 exit Scope_Loop when S = Standard_Standard;
16939 else
16940 exit Scope_Loop;
16941 end if;
16942 end loop Scope_Loop;
16943 end Kill_Current_Values;
16944
16945 --------------------------
16946 -- Kill_Size_Check_Code --
16947 --------------------------
16948
16949 procedure Kill_Size_Check_Code (E : Entity_Id) is
16950 begin
16951 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
16952 and then Present (Size_Check_Code (E))
16953 then
16954 Remove (Size_Check_Code (E));
16955 Set_Size_Check_Code (E, Empty);
16956 end if;
16957 end Kill_Size_Check_Code;
16958
16959 --------------------
16960 -- Known_Non_Null --
16961 --------------------
16962
16963 function Known_Non_Null (N : Node_Id) return Boolean is
16964 Status : constant Null_Status_Kind := Null_Status (N);
16965
16966 Id : Entity_Id;
16967 Op : Node_Kind;
16968 Val : Node_Id;
16969
16970 begin
16971 -- The expression yields a non-null value ignoring simple flow analysis
16972
16973 if Status = Is_Non_Null then
16974 return True;
16975
16976 -- Otherwise check whether N is a reference to an entity that appears
16977 -- within a conditional construct.
16978
16979 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
16980
16981 -- First check if we are in decisive conditional
16982
16983 Get_Current_Value_Condition (N, Op, Val);
16984
16985 if Known_Null (Val) then
16986 if Op = N_Op_Eq then
16987 return False;
16988 elsif Op = N_Op_Ne then
16989 return True;
16990 end if;
16991 end if;
16992
16993 -- If OK to do replacement, test Is_Known_Non_Null flag
16994
16995 Id := Entity (N);
16996
16997 if OK_To_Do_Constant_Replacement (Id) then
16998 return Is_Known_Non_Null (Id);
16999 end if;
17000 end if;
17001
17002 -- Otherwise it is not possible to determine whether N yields a non-null
17003 -- value.
17004
17005 return False;
17006 end Known_Non_Null;
17007
17008 ----------------
17009 -- Known_Null --
17010 ----------------
17011
17012 function Known_Null (N : Node_Id) return Boolean is
17013 Status : constant Null_Status_Kind := Null_Status (N);
17014
17015 Id : Entity_Id;
17016 Op : Node_Kind;
17017 Val : Node_Id;
17018
17019 begin
17020 -- The expression yields a null value ignoring simple flow analysis
17021
17022 if Status = Is_Null then
17023 return True;
17024
17025 -- Otherwise check whether N is a reference to an entity that appears
17026 -- within a conditional construct.
17027
17028 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
17029
17030 -- First check if we are in decisive conditional
17031
17032 Get_Current_Value_Condition (N, Op, Val);
17033
17034 if Known_Null (Val) then
17035 if Op = N_Op_Eq then
17036 return True;
17037 elsif Op = N_Op_Ne then
17038 return False;
17039 end if;
17040 end if;
17041
17042 -- If OK to do replacement, test Is_Known_Null flag
17043
17044 Id := Entity (N);
17045
17046 if OK_To_Do_Constant_Replacement (Id) then
17047 return Is_Known_Null (Id);
17048 end if;
17049 end if;
17050
17051 -- Otherwise it is not possible to determine whether N yields a null
17052 -- value.
17053
17054 return False;
17055 end Known_Null;
17056
17057 --------------------------
17058 -- Known_To_Be_Assigned --
17059 --------------------------
17060
17061 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
17062 P : constant Node_Id := Parent (N);
17063
17064 begin
17065 case Nkind (P) is
17066
17067 -- Test left side of assignment
17068
17069 when N_Assignment_Statement =>
17070 return N = Name (P);
17071
17072 -- Function call arguments are never lvalues
17073
17074 when N_Function_Call =>
17075 return False;
17076
17077 -- Positional parameter for procedure or accept call
17078
17079 when N_Accept_Statement
17080 | N_Procedure_Call_Statement
17081 =>
17082 declare
17083 Proc : Entity_Id;
17084 Form : Entity_Id;
17085 Act : Node_Id;
17086
17087 begin
17088 Proc := Get_Subprogram_Entity (P);
17089
17090 if No (Proc) then
17091 return False;
17092 end if;
17093
17094 -- If we are not a list member, something is strange, so
17095 -- be conservative and return False.
17096
17097 if not Is_List_Member (N) then
17098 return False;
17099 end if;
17100
17101 -- We are going to find the right formal by stepping forward
17102 -- through the formals, as we step backwards in the actuals.
17103
17104 Form := First_Formal (Proc);
17105 Act := N;
17106 loop
17107 -- If no formal, something is weird, so be conservative
17108 -- and return False.
17109
17110 if No (Form) then
17111 return False;
17112 end if;
17113
17114 Prev (Act);
17115 exit when No (Act);
17116 Next_Formal (Form);
17117 end loop;
17118
17119 return Ekind (Form) /= E_In_Parameter;
17120 end;
17121
17122 -- Named parameter for procedure or accept call
17123
17124 when N_Parameter_Association =>
17125 declare
17126 Proc : Entity_Id;
17127 Form : Entity_Id;
17128
17129 begin
17130 Proc := Get_Subprogram_Entity (Parent (P));
17131
17132 if No (Proc) then
17133 return False;
17134 end if;
17135
17136 -- Loop through formals to find the one that matches
17137
17138 Form := First_Formal (Proc);
17139 loop
17140 -- If no matching formal, that's peculiar, some kind of
17141 -- previous error, so return False to be conservative.
17142 -- Actually this also happens in legal code in the case
17143 -- where P is a parameter association for an Extra_Formal???
17144
17145 if No (Form) then
17146 return False;
17147 end if;
17148
17149 -- Else test for match
17150
17151 if Chars (Form) = Chars (Selector_Name (P)) then
17152 return Ekind (Form) /= E_In_Parameter;
17153 end if;
17154
17155 Next_Formal (Form);
17156 end loop;
17157 end;
17158
17159 -- Test for appearing in a conversion that itself appears
17160 -- in an lvalue context, since this should be an lvalue.
17161
17162 when N_Type_Conversion =>
17163 return Known_To_Be_Assigned (P);
17164
17165 -- All other references are definitely not known to be modifications
17166
17167 when others =>
17168 return False;
17169 end case;
17170 end Known_To_Be_Assigned;
17171
17172 ---------------------------
17173 -- Last_Source_Statement --
17174 ---------------------------
17175
17176 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
17177 N : Node_Id;
17178
17179 begin
17180 N := Last (Statements (HSS));
17181 while Present (N) loop
17182 exit when Comes_From_Source (N);
17183 Prev (N);
17184 end loop;
17185
17186 return N;
17187 end Last_Source_Statement;
17188
17189 -----------------------
17190 -- Mark_Coextensions --
17191 -----------------------
17192
17193 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
17194 Is_Dynamic : Boolean;
17195 -- Indicates whether the context causes nested coextensions to be
17196 -- dynamic or static
17197
17198 function Mark_Allocator (N : Node_Id) return Traverse_Result;
17199 -- Recognize an allocator node and label it as a dynamic coextension
17200
17201 --------------------
17202 -- Mark_Allocator --
17203 --------------------
17204
17205 function Mark_Allocator (N : Node_Id) return Traverse_Result is
17206 begin
17207 if Nkind (N) = N_Allocator then
17208 if Is_Dynamic then
17209 Set_Is_Dynamic_Coextension (N);
17210
17211 -- If the allocator expression is potentially dynamic, it may
17212 -- be expanded out of order and require dynamic allocation
17213 -- anyway, so we treat the coextension itself as dynamic.
17214 -- Potential optimization ???
17215
17216 elsif Nkind (Expression (N)) = N_Qualified_Expression
17217 and then Nkind (Expression (Expression (N))) = N_Op_Concat
17218 then
17219 Set_Is_Dynamic_Coextension (N);
17220 else
17221 Set_Is_Static_Coextension (N);
17222 end if;
17223 end if;
17224
17225 return OK;
17226 end Mark_Allocator;
17227
17228 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
17229
17230 -- Start of processing for Mark_Coextensions
17231
17232 begin
17233 -- An allocator that appears on the right-hand side of an assignment is
17234 -- treated as a potentially dynamic coextension when the right-hand side
17235 -- is an allocator or a qualified expression.
17236
17237 -- Obj := new ...'(new Coextension ...);
17238
17239 if Nkind (Context_Nod) = N_Assignment_Statement then
17240 Is_Dynamic :=
17241 Nkind_In (Expression (Context_Nod), N_Allocator,
17242 N_Qualified_Expression);
17243
17244 -- An allocator that appears within the expression of a simple return
17245 -- statement is treated as a potentially dynamic coextension when the
17246 -- expression is either aggregate, allocator, or qualified expression.
17247
17248 -- return (new Coextension ...);
17249 -- return new ...'(new Coextension ...);
17250
17251 elsif Nkind (Context_Nod) = N_Simple_Return_Statement then
17252 Is_Dynamic :=
17253 Nkind_In (Expression (Context_Nod), N_Aggregate,
17254 N_Allocator,
17255 N_Qualified_Expression);
17256
17257 -- An alloctor that appears within the initialization expression of an
17258 -- object declaration is considered a potentially dynamic coextension
17259 -- when the initialization expression is an allocator or a qualified
17260 -- expression.
17261
17262 -- Obj : ... := new ...'(new Coextension ...);
17263
17264 -- A similar case arises when the object declaration is part of an
17265 -- extended return statement.
17266
17267 -- return Obj : ... := new ...'(new Coextension ...);
17268 -- return Obj : ... := (new Coextension ...);
17269
17270 elsif Nkind (Context_Nod) = N_Object_Declaration then
17271 Is_Dynamic :=
17272 Nkind_In (Root_Nod, N_Allocator, N_Qualified_Expression)
17273 or else
17274 Nkind (Parent (Context_Nod)) = N_Extended_Return_Statement;
17275
17276 -- This routine should not be called with constructs that cannot contain
17277 -- coextensions.
17278
17279 else
17280 raise Program_Error;
17281 end if;
17282
17283 Mark_Allocators (Root_Nod);
17284 end Mark_Coextensions;
17285
17286 ---------------------------------
17287 -- Mark_Elaboration_Attributes --
17288 ---------------------------------
17289
17290 procedure Mark_Elaboration_Attributes
17291 (N_Id : Node_Or_Entity_Id;
17292 Checks : Boolean := False;
17293 Level : Boolean := False;
17294 Modes : Boolean := False)
17295 is
17296 function Elaboration_Checks_OK
17297 (Target_Id : Entity_Id;
17298 Context_Id : Entity_Id) return Boolean;
17299 -- Determine whether elaboration checks are enabled for target Target_Id
17300 -- which resides within context Context_Id.
17301
17302 procedure Mark_Elaboration_Attributes_Id (Id : Entity_Id);
17303 -- Preserve relevant attributes of the context in arbitrary entity Id
17304
17305 procedure Mark_Elaboration_Attributes_Node (N : Node_Id);
17306 -- Preserve relevant attributes of the context in arbitrary node N
17307
17308 ---------------------------
17309 -- Elaboration_Checks_OK --
17310 ---------------------------
17311
17312 function Elaboration_Checks_OK
17313 (Target_Id : Entity_Id;
17314 Context_Id : Entity_Id) return Boolean
17315 is
17316 Encl_Scop : Entity_Id;
17317
17318 begin
17319 -- Elaboration checks are suppressed for the target
17320
17321 if Elaboration_Checks_Suppressed (Target_Id) then
17322 return False;
17323 end if;
17324
17325 -- Otherwise elaboration checks are OK for the target, but may be
17326 -- suppressed for the context where the target is declared.
17327
17328 Encl_Scop := Context_Id;
17329 while Present (Encl_Scop) and then Encl_Scop /= Standard_Standard loop
17330 if Elaboration_Checks_Suppressed (Encl_Scop) then
17331 return False;
17332 end if;
17333
17334 Encl_Scop := Scope (Encl_Scop);
17335 end loop;
17336
17337 -- Neither the target nor its declarative context have elaboration
17338 -- checks suppressed.
17339
17340 return True;
17341 end Elaboration_Checks_OK;
17342
17343 ------------------------------------
17344 -- Mark_Elaboration_Attributes_Id --
17345 ------------------------------------
17346
17347 procedure Mark_Elaboration_Attributes_Id (Id : Entity_Id) is
17348 begin
17349 -- Mark the status of elaboration checks in effect. Do not reset the
17350 -- status in case the entity is reanalyzed with checks suppressed.
17351
17352 if Checks and then not Is_Elaboration_Checks_OK_Id (Id) then
17353 Set_Is_Elaboration_Checks_OK_Id (Id,
17354 Elaboration_Checks_OK
17355 (Target_Id => Id,
17356 Context_Id => Scope (Id)));
17357
17358 -- Entities do not need to capture their enclosing level. The Ghost
17359 -- and SPARK modes in effect are already marked during analysis.
17360
17361 else
17362 null;
17363 end if;
17364 end Mark_Elaboration_Attributes_Id;
17365
17366 --------------------------------------
17367 -- Mark_Elaboration_Attributes_Node --
17368 --------------------------------------
17369
17370 procedure Mark_Elaboration_Attributes_Node (N : Node_Id) is
17371 function Extract_Name (N : Node_Id) return Node_Id;
17372 -- Obtain the Name attribute of call or instantiation N
17373
17374 ------------------
17375 -- Extract_Name --
17376 ------------------
17377
17378 function Extract_Name (N : Node_Id) return Node_Id is
17379 Nam : Node_Id;
17380
17381 begin
17382 Nam := Name (N);
17383
17384 -- A call to an entry family appears in indexed form
17385
17386 if Nkind (Nam) = N_Indexed_Component then
17387 Nam := Prefix (Nam);
17388 end if;
17389
17390 -- The name may also appear in qualified form
17391
17392 if Nkind (Nam) = N_Selected_Component then
17393 Nam := Selector_Name (Nam);
17394 end if;
17395
17396 return Nam;
17397 end Extract_Name;
17398
17399 -- Local variables
17400
17401 Context_Id : Entity_Id;
17402 Nam : Node_Id;
17403
17404 -- Start of processing for Mark_Elaboration_Attributes_Node
17405
17406 begin
17407 -- Mark the status of elaboration checks in effect. Do not reset the
17408 -- status in case the node is reanalyzed with checks suppressed.
17409
17410 if Checks and then not Is_Elaboration_Checks_OK_Node (N) then
17411
17412 -- Assignments, attribute references, and variable references do
17413 -- not have a "declarative" context.
17414
17415 Context_Id := Empty;
17416
17417 -- The status of elaboration checks for calls and instantiations
17418 -- depends on the most recent pragma Suppress/Unsuppress, as well
17419 -- as the suppression status of the context where the target is
17420 -- defined.
17421
17422 -- package Pack is
17423 -- function Func ...;
17424 -- end Pack;
17425
17426 -- with Pack;
17427 -- procedure Main is
17428 -- pragma Suppress (Elaboration_Checks, Pack);
17429 -- X : ... := Pack.Func;
17430 -- ...
17431
17432 -- In the example above, the call to Func has elaboration checks
17433 -- enabled because there is no active general purpose suppression
17434 -- pragma, however the elaboration checks of Pack are explicitly
17435 -- suppressed. As a result the elaboration checks of the call must
17436 -- be disabled in order to preserve this dependency.
17437
17438 if Nkind_In (N, N_Entry_Call_Statement,
17439 N_Function_Call,
17440 N_Function_Instantiation,
17441 N_Package_Instantiation,
17442 N_Procedure_Call_Statement,
17443 N_Procedure_Instantiation)
17444 then
17445 Nam := Extract_Name (N);
17446
17447 if Is_Entity_Name (Nam) and then Present (Entity (Nam)) then
17448 Context_Id := Scope (Entity (Nam));
17449 end if;
17450 end if;
17451
17452 Set_Is_Elaboration_Checks_OK_Node (N,
17453 Elaboration_Checks_OK
17454 (Target_Id => Empty,
17455 Context_Id => Context_Id));
17456 end if;
17457
17458 -- Mark the enclosing level of the node. Do not reset the status in
17459 -- case the node is relocated and reanalyzed.
17460
17461 if Level and then not Is_Declaration_Level_Node (N) then
17462 Set_Is_Declaration_Level_Node (N,
17463 Find_Enclosing_Level (N) = Declaration_Level);
17464 end if;
17465
17466 -- Mark the Ghost and SPARK mode in effect
17467
17468 if Modes then
17469 if Ghost_Mode = Ignore then
17470 Set_Is_Ignored_Ghost_Node (N);
17471 end if;
17472
17473 if SPARK_Mode = On then
17474 Set_Is_SPARK_Mode_On_Node (N);
17475 end if;
17476 end if;
17477 end Mark_Elaboration_Attributes_Node;
17478
17479 -- Start of processing for Mark_Elaboration_Attributes
17480
17481 begin
17482 if Nkind (N_Id) in N_Entity then
17483 Mark_Elaboration_Attributes_Id (N_Id);
17484 else
17485 Mark_Elaboration_Attributes_Node (N_Id);
17486 end if;
17487 end Mark_Elaboration_Attributes;
17488
17489 ----------------------------------
17490 -- Matching_Static_Array_Bounds --
17491 ----------------------------------
17492
17493 function Matching_Static_Array_Bounds
17494 (L_Typ : Node_Id;
17495 R_Typ : Node_Id) return Boolean
17496 is
17497 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
17498 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
17499
17500 L_Index : Node_Id;
17501 R_Index : Node_Id;
17502 L_Low : Node_Id;
17503 L_High : Node_Id;
17504 L_Len : Uint;
17505 R_Low : Node_Id;
17506 R_High : Node_Id;
17507 R_Len : Uint;
17508
17509 begin
17510 if L_Ndims /= R_Ndims then
17511 return False;
17512 end if;
17513
17514 -- Unconstrained types do not have static bounds
17515
17516 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
17517 return False;
17518 end if;
17519
17520 -- First treat specially the first dimension, as the lower bound and
17521 -- length of string literals are not stored like those of arrays.
17522
17523 if Ekind (L_Typ) = E_String_Literal_Subtype then
17524 L_Low := String_Literal_Low_Bound (L_Typ);
17525 L_Len := String_Literal_Length (L_Typ);
17526 else
17527 L_Index := First_Index (L_Typ);
17528 Get_Index_Bounds (L_Index, L_Low, L_High);
17529
17530 if Is_OK_Static_Expression (L_Low)
17531 and then
17532 Is_OK_Static_Expression (L_High)
17533 then
17534 if Expr_Value (L_High) < Expr_Value (L_Low) then
17535 L_Len := Uint_0;
17536 else
17537 L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
17538 end if;
17539 else
17540 return False;
17541 end if;
17542 end if;
17543
17544 if Ekind (R_Typ) = E_String_Literal_Subtype then
17545 R_Low := String_Literal_Low_Bound (R_Typ);
17546 R_Len := String_Literal_Length (R_Typ);
17547 else
17548 R_Index := First_Index (R_Typ);
17549 Get_Index_Bounds (R_Index, R_Low, R_High);
17550
17551 if Is_OK_Static_Expression (R_Low)
17552 and then
17553 Is_OK_Static_Expression (R_High)
17554 then
17555 if Expr_Value (R_High) < Expr_Value (R_Low) then
17556 R_Len := Uint_0;
17557 else
17558 R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
17559 end if;
17560 else
17561 return False;
17562 end if;
17563 end if;
17564
17565 if (Is_OK_Static_Expression (L_Low)
17566 and then
17567 Is_OK_Static_Expression (R_Low))
17568 and then Expr_Value (L_Low) = Expr_Value (R_Low)
17569 and then L_Len = R_Len
17570 then
17571 null;
17572 else
17573 return False;
17574 end if;
17575
17576 -- Then treat all other dimensions
17577
17578 for Indx in 2 .. L_Ndims loop
17579 Next (L_Index);
17580 Next (R_Index);
17581
17582 Get_Index_Bounds (L_Index, L_Low, L_High);
17583 Get_Index_Bounds (R_Index, R_Low, R_High);
17584
17585 if (Is_OK_Static_Expression (L_Low) and then
17586 Is_OK_Static_Expression (L_High) and then
17587 Is_OK_Static_Expression (R_Low) and then
17588 Is_OK_Static_Expression (R_High))
17589 and then (Expr_Value (L_Low) = Expr_Value (R_Low)
17590 and then
17591 Expr_Value (L_High) = Expr_Value (R_High))
17592 then
17593 null;
17594 else
17595 return False;
17596 end if;
17597 end loop;
17598
17599 -- If we fall through the loop, all indexes matched
17600
17601 return True;
17602 end Matching_Static_Array_Bounds;
17603
17604 -------------------
17605 -- May_Be_Lvalue --
17606 -------------------
17607
17608 function May_Be_Lvalue (N : Node_Id) return Boolean is
17609 P : constant Node_Id := Parent (N);
17610
17611 begin
17612 case Nkind (P) is
17613
17614 -- Test left side of assignment
17615
17616 when N_Assignment_Statement =>
17617 return N = Name (P);
17618
17619 -- Test prefix of component or attribute. Note that the prefix of an
17620 -- explicit or implicit dereference cannot be an l-value. In the case
17621 -- of a 'Read attribute, the reference can be an actual in the
17622 -- argument list of the attribute.
17623
17624 when N_Attribute_Reference =>
17625 return (N = Prefix (P)
17626 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P)))
17627 or else
17628 Attribute_Name (P) = Name_Read;
17629
17630 -- For an expanded name, the name is an lvalue if the expanded name
17631 -- is an lvalue, but the prefix is never an lvalue, since it is just
17632 -- the scope where the name is found.
17633
17634 when N_Expanded_Name =>
17635 if N = Prefix (P) then
17636 return May_Be_Lvalue (P);
17637 else
17638 return False;
17639 end if;
17640
17641 -- For a selected component A.B, A is certainly an lvalue if A.B is.
17642 -- B is a little interesting, if we have A.B := 3, there is some
17643 -- discussion as to whether B is an lvalue or not, we choose to say
17644 -- it is. Note however that A is not an lvalue if it is of an access
17645 -- type since this is an implicit dereference.
17646
17647 when N_Selected_Component =>
17648 if N = Prefix (P)
17649 and then Present (Etype (N))
17650 and then Is_Access_Type (Etype (N))
17651 then
17652 return False;
17653 else
17654 return May_Be_Lvalue (P);
17655 end if;
17656
17657 -- For an indexed component or slice, the index or slice bounds is
17658 -- never an lvalue. The prefix is an lvalue if the indexed component
17659 -- or slice is an lvalue, except if it is an access type, where we
17660 -- have an implicit dereference.
17661
17662 when N_Indexed_Component
17663 | N_Slice
17664 =>
17665 if N /= Prefix (P)
17666 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
17667 then
17668 return False;
17669 else
17670 return May_Be_Lvalue (P);
17671 end if;
17672
17673 -- Prefix of a reference is an lvalue if the reference is an lvalue
17674
17675 when N_Reference =>
17676 return May_Be_Lvalue (P);
17677
17678 -- Prefix of explicit dereference is never an lvalue
17679
17680 when N_Explicit_Dereference =>
17681 return False;
17682
17683 -- Positional parameter for subprogram, entry, or accept call.
17684 -- In older versions of Ada function call arguments are never
17685 -- lvalues. In Ada 2012 functions can have in-out parameters.
17686
17687 when N_Accept_Statement
17688 | N_Entry_Call_Statement
17689 | N_Subprogram_Call
17690 =>
17691 if Nkind (P) = N_Function_Call and then Ada_Version < Ada_2012 then
17692 return False;
17693 end if;
17694
17695 -- The following mechanism is clumsy and fragile. A single flag
17696 -- set in Resolve_Actuals would be preferable ???
17697
17698 declare
17699 Proc : Entity_Id;
17700 Form : Entity_Id;
17701 Act : Node_Id;
17702
17703 begin
17704 Proc := Get_Subprogram_Entity (P);
17705
17706 if No (Proc) then
17707 return True;
17708 end if;
17709
17710 -- If we are not a list member, something is strange, so be
17711 -- conservative and return True.
17712
17713 if not Is_List_Member (N) then
17714 return True;
17715 end if;
17716
17717 -- We are going to find the right formal by stepping forward
17718 -- through the formals, as we step backwards in the actuals.
17719
17720 Form := First_Formal (Proc);
17721 Act := N;
17722 loop
17723 -- If no formal, something is weird, so be conservative and
17724 -- return True.
17725
17726 if No (Form) then
17727 return True;
17728 end if;
17729
17730 Prev (Act);
17731 exit when No (Act);
17732 Next_Formal (Form);
17733 end loop;
17734
17735 return Ekind (Form) /= E_In_Parameter;
17736 end;
17737
17738 -- Named parameter for procedure or accept call
17739
17740 when N_Parameter_Association =>
17741 declare
17742 Proc : Entity_Id;
17743 Form : Entity_Id;
17744
17745 begin
17746 Proc := Get_Subprogram_Entity (Parent (P));
17747
17748 if No (Proc) then
17749 return True;
17750 end if;
17751
17752 -- Loop through formals to find the one that matches
17753
17754 Form := First_Formal (Proc);
17755 loop
17756 -- If no matching formal, that's peculiar, some kind of
17757 -- previous error, so return True to be conservative.
17758 -- Actually happens with legal code for an unresolved call
17759 -- where we may get the wrong homonym???
17760
17761 if No (Form) then
17762 return True;
17763 end if;
17764
17765 -- Else test for match
17766
17767 if Chars (Form) = Chars (Selector_Name (P)) then
17768 return Ekind (Form) /= E_In_Parameter;
17769 end if;
17770
17771 Next_Formal (Form);
17772 end loop;
17773 end;
17774
17775 -- Test for appearing in a conversion that itself appears in an
17776 -- lvalue context, since this should be an lvalue.
17777
17778 when N_Type_Conversion =>
17779 return May_Be_Lvalue (P);
17780
17781 -- Test for appearance in object renaming declaration
17782
17783 when N_Object_Renaming_Declaration =>
17784 return True;
17785
17786 -- All other references are definitely not lvalues
17787
17788 when others =>
17789 return False;
17790 end case;
17791 end May_Be_Lvalue;
17792
17793 -----------------
17794 -- Might_Raise --
17795 -----------------
17796
17797 function Might_Raise (N : Node_Id) return Boolean is
17798 Result : Boolean := False;
17799
17800 function Process (N : Node_Id) return Traverse_Result;
17801 -- Set Result to True if we find something that could raise an exception
17802
17803 -------------
17804 -- Process --
17805 -------------
17806
17807 function Process (N : Node_Id) return Traverse_Result is
17808 begin
17809 if Nkind_In (N, N_Procedure_Call_Statement,
17810 N_Function_Call,
17811 N_Raise_Statement,
17812 N_Raise_Constraint_Error,
17813 N_Raise_Program_Error,
17814 N_Raise_Storage_Error)
17815 then
17816 Result := True;
17817 return Abandon;
17818 else
17819 return OK;
17820 end if;
17821 end Process;
17822
17823 procedure Set_Result is new Traverse_Proc (Process);
17824
17825 -- Start of processing for Might_Raise
17826
17827 begin
17828 -- False if exceptions can't be propagated
17829
17830 if No_Exception_Handlers_Set then
17831 return False;
17832 end if;
17833
17834 -- If the checks handled by the back end are not disabled, we cannot
17835 -- ensure that no exception will be raised.
17836
17837 if not Access_Checks_Suppressed (Empty)
17838 or else not Discriminant_Checks_Suppressed (Empty)
17839 or else not Range_Checks_Suppressed (Empty)
17840 or else not Index_Checks_Suppressed (Empty)
17841 or else Opt.Stack_Checking_Enabled
17842 then
17843 return True;
17844 end if;
17845
17846 Set_Result (N);
17847 return Result;
17848 end Might_Raise;
17849
17850 --------------------------------
17851 -- Nearest_Enclosing_Instance --
17852 --------------------------------
17853
17854 function Nearest_Enclosing_Instance (E : Entity_Id) return Entity_Id is
17855 Inst : Entity_Id;
17856
17857 begin
17858 Inst := Scope (E);
17859 while Present (Inst) and then Inst /= Standard_Standard loop
17860 if Is_Generic_Instance (Inst) then
17861 return Inst;
17862 end if;
17863
17864 Inst := Scope (Inst);
17865 end loop;
17866
17867 return Empty;
17868 end Nearest_Enclosing_Instance;
17869
17870 ----------------------
17871 -- Needs_One_Actual --
17872 ----------------------
17873
17874 function Needs_One_Actual (E : Entity_Id) return Boolean is
17875 Formal : Entity_Id;
17876
17877 begin
17878 -- Ada 2005 or later, and formals present. The first formal must be
17879 -- of a type that supports prefix notation: a controlling argument,
17880 -- a class-wide type, or an access to such.
17881
17882 if Ada_Version >= Ada_2005
17883 and then Present (First_Formal (E))
17884 and then No (Default_Value (First_Formal (E)))
17885 and then
17886 (Is_Controlling_Formal (First_Formal (E))
17887 or else Is_Class_Wide_Type (Etype (First_Formal (E)))
17888 or else Is_Anonymous_Access_Type (Etype (First_Formal (E))))
17889 then
17890 Formal := Next_Formal (First_Formal (E));
17891 while Present (Formal) loop
17892 if No (Default_Value (Formal)) then
17893 return False;
17894 end if;
17895
17896 Next_Formal (Formal);
17897 end loop;
17898
17899 return True;
17900
17901 -- Ada 83/95 or no formals
17902
17903 else
17904 return False;
17905 end if;
17906 end Needs_One_Actual;
17907
17908 ------------------------
17909 -- New_Copy_List_Tree --
17910 ------------------------
17911
17912 function New_Copy_List_Tree (List : List_Id) return List_Id is
17913 NL : List_Id;
17914 E : Node_Id;
17915
17916 begin
17917 if List = No_List then
17918 return No_List;
17919
17920 else
17921 NL := New_List;
17922 E := First (List);
17923
17924 while Present (E) loop
17925 Append (New_Copy_Tree (E), NL);
17926 E := Next (E);
17927 end loop;
17928
17929 return NL;
17930 end if;
17931 end New_Copy_List_Tree;
17932
17933 -------------------
17934 -- New_Copy_Tree --
17935 -------------------
17936
17937 -- The following tables play a key role in replicating entities and Itypes.
17938 -- They are intentionally declared at the library level rather than within
17939 -- New_Copy_Tree to avoid elaborating them on each call. This performance
17940 -- optimization saves up to 2% of the entire compilation time spent in the
17941 -- front end. Care should be taken to reset the tables on each new call to
17942 -- New_Copy_Tree.
17943
17944 NCT_Table_Max : constant := 511;
17945
17946 subtype NCT_Table_Index is Nat range 0 .. NCT_Table_Max - 1;
17947
17948 function NCT_Table_Hash (Key : Node_Or_Entity_Id) return NCT_Table_Index;
17949 -- Obtain the hash value of node or entity Key
17950
17951 --------------------
17952 -- NCT_Table_Hash --
17953 --------------------
17954
17955 function NCT_Table_Hash (Key : Node_Or_Entity_Id) return NCT_Table_Index is
17956 begin
17957 return NCT_Table_Index (Key mod NCT_Table_Max);
17958 end NCT_Table_Hash;
17959
17960 ----------------------
17961 -- NCT_New_Entities --
17962 ----------------------
17963
17964 -- The following table maps old entities and Itypes to their corresponding
17965 -- new entities and Itypes.
17966
17967 -- Aaa -> Xxx
17968
17969 package NCT_New_Entities is new Simple_HTable (
17970 Header_Num => NCT_Table_Index,
17971 Element => Entity_Id,
17972 No_Element => Empty,
17973 Key => Entity_Id,
17974 Hash => NCT_Table_Hash,
17975 Equal => "=");
17976
17977 ------------------------
17978 -- NCT_Pending_Itypes --
17979 ------------------------
17980
17981 -- The following table maps old Associated_Node_For_Itype nodes to a set of
17982 -- new itypes. Given a set of old Itypes Aaa, Bbb, and Ccc, where all three
17983 -- have the same Associated_Node_For_Itype Ppp, and their corresponding new
17984 -- Itypes Xxx, Yyy, Zzz, the table contains the following mapping:
17985
17986 -- Ppp -> (Xxx, Yyy, Zzz)
17987
17988 -- The set is expressed as an Elist
17989
17990 package NCT_Pending_Itypes is new Simple_HTable (
17991 Header_Num => NCT_Table_Index,
17992 Element => Elist_Id,
17993 No_Element => No_Elist,
17994 Key => Node_Id,
17995 Hash => NCT_Table_Hash,
17996 Equal => "=");
17997
17998 NCT_Tables_In_Use : Boolean := False;
17999 -- This flag keeps track of whether the two tables NCT_New_Entities and
18000 -- NCT_Pending_Itypes are in use. The flag is part of an optimization
18001 -- where certain operations are not performed if the tables are not in
18002 -- use. This saves up to 8% of the entire compilation time spent in the
18003 -- front end.
18004
18005 -------------------
18006 -- New_Copy_Tree --
18007 -------------------
18008
18009 function New_Copy_Tree
18010 (Source : Node_Id;
18011 Map : Elist_Id := No_Elist;
18012 New_Sloc : Source_Ptr := No_Location;
18013 New_Scope : Entity_Id := Empty) return Node_Id
18014 is
18015 -- This routine performs low-level tree manipulations and needs access
18016 -- to the internals of the tree.
18017
18018 use Atree.Unchecked_Access;
18019 use Atree_Private_Part;
18020
18021 EWA_Level : Nat := 0;
18022 -- This counter keeps track of how many N_Expression_With_Actions nodes
18023 -- are encountered during a depth-first traversal of the subtree. These
18024 -- nodes may define new entities in their Actions lists and thus require
18025 -- special processing.
18026
18027 EWA_Inner_Scope_Level : Nat := 0;
18028 -- This counter keeps track of how many scoping constructs appear within
18029 -- an N_Expression_With_Actions node.
18030
18031 procedure Add_New_Entity (Old_Id : Entity_Id; New_Id : Entity_Id);
18032 pragma Inline (Add_New_Entity);
18033 -- Add an entry in the NCT_New_Entities table which maps key Old_Id to
18034 -- value New_Id. Old_Id is an entity which appears within the Actions
18035 -- list of an N_Expression_With_Actions node, or within an entity map.
18036 -- New_Id is the corresponding new entity generated during Phase 1.
18037
18038 procedure Add_Pending_Itype (Assoc_Nod : Node_Id; Itype : Entity_Id);
18039 pragma Inline (Add_New_Entity);
18040 -- Add an entry in the NCT_Pending_Itypes which maps key Assoc_Nod to
18041 -- value Itype. Assoc_Nod is the associated node of an itype. Itype is
18042 -- an itype.
18043
18044 procedure Build_NCT_Tables (Entity_Map : Elist_Id);
18045 pragma Inline (Build_NCT_Tables);
18046 -- Populate tables NCT_New_Entities and NCT_Pending_Itypes with the
18047 -- information supplied in entity map Entity_Map. The format of the
18048 -- entity map must be as follows:
18049 --
18050 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
18051
18052 function Copy_Any_Node_With_Replacement
18053 (N : Node_Or_Entity_Id) return Node_Or_Entity_Id;
18054 pragma Inline (Copy_Any_Node_With_Replacement);
18055 -- Replicate entity or node N by invoking one of the following routines:
18056 --
18057 -- Copy_Node_With_Replacement
18058 -- Corresponding_Entity
18059
18060 function Copy_Elist_With_Replacement (List : Elist_Id) return Elist_Id;
18061 -- Replicate the elements of entity list List
18062
18063 function Copy_Field_With_Replacement
18064 (Field : Union_Id;
18065 Old_Par : Node_Id := Empty;
18066 New_Par : Node_Id := Empty;
18067 Semantic : Boolean := False) return Union_Id;
18068 -- Replicate field Field by invoking one of the following routines:
18069 --
18070 -- Copy_Elist_With_Replacement
18071 -- Copy_List_With_Replacement
18072 -- Copy_Node_With_Replacement
18073 -- Corresponding_Entity
18074 --
18075 -- If the field is not an entity list, entity, itype, syntactic list,
18076 -- or node, then the field is returned unchanged. The routine always
18077 -- replicates entities, itypes, and valid syntactic fields. Old_Par is
18078 -- the expected parent of a syntactic field. New_Par is the new parent
18079 -- associated with a replicated syntactic field. Flag Semantic should
18080 -- be set when the input is a semantic field.
18081
18082 function Copy_List_With_Replacement (List : List_Id) return List_Id;
18083 -- Replicate the elements of syntactic list List
18084
18085 function Copy_Node_With_Replacement (N : Node_Id) return Node_Id;
18086 -- Replicate node N
18087
18088 function Corresponding_Entity (Id : Entity_Id) return Entity_Id;
18089 pragma Inline (Corresponding_Entity);
18090 -- Return the corresponding new entity of Id generated during Phase 1.
18091 -- If there is no such entity, return Id.
18092
18093 function In_Entity_Map
18094 (Id : Entity_Id;
18095 Entity_Map : Elist_Id) return Boolean;
18096 pragma Inline (In_Entity_Map);
18097 -- Determine whether entity Id is one of the old ids specified in entity
18098 -- map Entity_Map. The format of the entity map must be as follows:
18099 --
18100 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
18101
18102 procedure Update_CFS_Sloc (N : Node_Or_Entity_Id);
18103 pragma Inline (Update_CFS_Sloc);
18104 -- Update the Comes_From_Source and Sloc attributes of node or entity N
18105
18106 procedure Update_First_Real_Statement
18107 (Old_HSS : Node_Id;
18108 New_HSS : Node_Id);
18109 pragma Inline (Update_First_Real_Statement);
18110 -- Update semantic attribute First_Real_Statement of handled sequence of
18111 -- statements New_HSS based on handled sequence of statements Old_HSS.
18112
18113 procedure Update_Named_Associations
18114 (Old_Call : Node_Id;
18115 New_Call : Node_Id);
18116 pragma Inline (Update_Named_Associations);
18117 -- Update semantic chain First/Next_Named_Association of call New_call
18118 -- based on call Old_Call.
18119
18120 procedure Update_New_Entities (Entity_Map : Elist_Id);
18121 pragma Inline (Update_New_Entities);
18122 -- Update the semantic attributes of all new entities generated during
18123 -- Phase 1 that do not appear in entity map Entity_Map. The format of
18124 -- the entity map must be as follows:
18125 --
18126 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
18127
18128 procedure Update_Pending_Itypes
18129 (Old_Assoc : Node_Id;
18130 New_Assoc : Node_Id);
18131 pragma Inline (Update_Pending_Itypes);
18132 -- Update semantic attribute Associated_Node_For_Itype to refer to node
18133 -- New_Assoc for all itypes whose associated node is Old_Assoc.
18134
18135 procedure Update_Semantic_Fields (Id : Entity_Id);
18136 pragma Inline (Update_Semantic_Fields);
18137 -- Subsidiary to Update_New_Entities. Update semantic fields of entity
18138 -- or itype Id.
18139
18140 procedure Visit_Any_Node (N : Node_Or_Entity_Id);
18141 pragma Inline (Visit_Any_Node);
18142 -- Visit entity of node N by invoking one of the following routines:
18143 --
18144 -- Visit_Entity
18145 -- Visit_Itype
18146 -- Visit_Node
18147
18148 procedure Visit_Elist (List : Elist_Id);
18149 -- Visit the elements of entity list List
18150
18151 procedure Visit_Entity (Id : Entity_Id);
18152 -- Visit entity Id. This action may create a new entity of Id and save
18153 -- it in table NCT_New_Entities.
18154
18155 procedure Visit_Field
18156 (Field : Union_Id;
18157 Par_Nod : Node_Id := Empty;
18158 Semantic : Boolean := False);
18159 -- Visit field Field by invoking one of the following routines:
18160 --
18161 -- Visit_Elist
18162 -- Visit_Entity
18163 -- Visit_Itype
18164 -- Visit_List
18165 -- Visit_Node
18166 --
18167 -- If the field is not an entity list, entity, itype, syntactic list,
18168 -- or node, then the field is not visited. The routine always visits
18169 -- valid syntactic fields. Par_Nod is the expected parent of the
18170 -- syntactic field. Flag Semantic should be set when the input is a
18171 -- semantic field.
18172
18173 procedure Visit_Itype (Itype : Entity_Id);
18174 -- Visit itype Itype. This action may create a new entity for Itype and
18175 -- save it in table NCT_New_Entities. In addition, the routine may map
18176 -- the associated node of Itype to the new itype in NCT_Pending_Itypes.
18177
18178 procedure Visit_List (List : List_Id);
18179 -- Visit the elements of syntactic list List
18180
18181 procedure Visit_Node (N : Node_Id);
18182 -- Visit node N
18183
18184 procedure Visit_Semantic_Fields (Id : Entity_Id);
18185 pragma Inline (Visit_Semantic_Fields);
18186 -- Subsidiary to Visit_Entity and Visit_Itype. Visit common semantic
18187 -- fields of entity or itype Id.
18188
18189 --------------------
18190 -- Add_New_Entity --
18191 --------------------
18192
18193 procedure Add_New_Entity (Old_Id : Entity_Id; New_Id : Entity_Id) is
18194 begin
18195 pragma Assert (Present (Old_Id));
18196 pragma Assert (Present (New_Id));
18197 pragma Assert (Nkind (Old_Id) in N_Entity);
18198 pragma Assert (Nkind (New_Id) in N_Entity);
18199
18200 NCT_Tables_In_Use := True;
18201
18202 -- Sanity check the NCT_New_Entities table. No previous mapping with
18203 -- key Old_Id should exist.
18204
18205 pragma Assert (No (NCT_New_Entities.Get (Old_Id)));
18206
18207 -- Establish the mapping
18208
18209 -- Old_Id -> New_Id
18210
18211 NCT_New_Entities.Set (Old_Id, New_Id);
18212 end Add_New_Entity;
18213
18214 -----------------------
18215 -- Add_Pending_Itype --
18216 -----------------------
18217
18218 procedure Add_Pending_Itype (Assoc_Nod : Node_Id; Itype : Entity_Id) is
18219 Itypes : Elist_Id;
18220
18221 begin
18222 pragma Assert (Present (Assoc_Nod));
18223 pragma Assert (Present (Itype));
18224 pragma Assert (Nkind (Itype) in N_Entity);
18225 pragma Assert (Is_Itype (Itype));
18226
18227 NCT_Tables_In_Use := True;
18228
18229 -- It is not possible to sanity check the NCT_Pendint_Itypes table
18230 -- directly because a single node may act as the associated node for
18231 -- multiple itypes.
18232
18233 Itypes := NCT_Pending_Itypes.Get (Assoc_Nod);
18234
18235 if No (Itypes) then
18236 Itypes := New_Elmt_List;
18237 NCT_Pending_Itypes.Set (Assoc_Nod, Itypes);
18238 end if;
18239
18240 -- Establish the mapping
18241
18242 -- Assoc_Nod -> (Itype, ...)
18243
18244 -- Avoid inserting the same itype multiple times. This involves a
18245 -- linear search, however the set of itypes with the same associated
18246 -- node is very small.
18247
18248 Append_Unique_Elmt (Itype, Itypes);
18249 end Add_Pending_Itype;
18250
18251 ----------------------
18252 -- Build_NCT_Tables --
18253 ----------------------
18254
18255 procedure Build_NCT_Tables (Entity_Map : Elist_Id) is
18256 Elmt : Elmt_Id;
18257 Old_Id : Entity_Id;
18258 New_Id : Entity_Id;
18259
18260 begin
18261 -- Nothing to do when there is no entity map
18262
18263 if No (Entity_Map) then
18264 return;
18265 end if;
18266
18267 Elmt := First_Elmt (Entity_Map);
18268 while Present (Elmt) loop
18269
18270 -- Extract the (Old_Id, New_Id) pair from the entity map
18271
18272 Old_Id := Node (Elmt);
18273 Next_Elmt (Elmt);
18274
18275 New_Id := Node (Elmt);
18276 Next_Elmt (Elmt);
18277
18278 -- Establish the following mapping within table NCT_New_Entities
18279
18280 -- Old_Id -> New_Id
18281
18282 Add_New_Entity (Old_Id, New_Id);
18283
18284 -- Establish the following mapping within table NCT_Pending_Itypes
18285 -- when the new entity is an itype.
18286
18287 -- Assoc_Nod -> (New_Id, ...)
18288
18289 -- IMPORTANT: the associated node is that of the old itype because
18290 -- the node will be replicated in Phase 2.
18291
18292 if Is_Itype (Old_Id) then
18293 Add_Pending_Itype
18294 (Assoc_Nod => Associated_Node_For_Itype (Old_Id),
18295 Itype => New_Id);
18296 end if;
18297 end loop;
18298 end Build_NCT_Tables;
18299
18300 ------------------------------------
18301 -- Copy_Any_Node_With_Replacement --
18302 ------------------------------------
18303
18304 function Copy_Any_Node_With_Replacement
18305 (N : Node_Or_Entity_Id) return Node_Or_Entity_Id
18306 is
18307 begin
18308 if Nkind (N) in N_Entity then
18309 return Corresponding_Entity (N);
18310 else
18311 return Copy_Node_With_Replacement (N);
18312 end if;
18313 end Copy_Any_Node_With_Replacement;
18314
18315 ---------------------------------
18316 -- Copy_Elist_With_Replacement --
18317 ---------------------------------
18318
18319 function Copy_Elist_With_Replacement (List : Elist_Id) return Elist_Id is
18320 Elmt : Elmt_Id;
18321 Result : Elist_Id;
18322
18323 begin
18324 -- Copy the contents of the old list. Note that the list itself may
18325 -- be empty, in which case the routine returns a new empty list. This
18326 -- avoids sharing lists between subtrees. The element of an entity
18327 -- list could be an entity or a node, hence the invocation of routine
18328 -- Copy_Any_Node_With_Replacement.
18329
18330 if Present (List) then
18331 Result := New_Elmt_List;
18332
18333 Elmt := First_Elmt (List);
18334 while Present (Elmt) loop
18335 Append_Elmt
18336 (Copy_Any_Node_With_Replacement (Node (Elmt)), Result);
18337
18338 Next_Elmt (Elmt);
18339 end loop;
18340
18341 -- Otherwise the list does not exist
18342
18343 else
18344 Result := No_Elist;
18345 end if;
18346
18347 return Result;
18348 end Copy_Elist_With_Replacement;
18349
18350 ---------------------------------
18351 -- Copy_Field_With_Replacement --
18352 ---------------------------------
18353
18354 function Copy_Field_With_Replacement
18355 (Field : Union_Id;
18356 Old_Par : Node_Id := Empty;
18357 New_Par : Node_Id := Empty;
18358 Semantic : Boolean := False) return Union_Id
18359 is
18360 begin
18361 -- The field is empty
18362
18363 if Field = Union_Id (Empty) then
18364 return Field;
18365
18366 -- The field is an entity/itype/node
18367
18368 elsif Field in Node_Range then
18369 declare
18370 Old_N : constant Node_Id := Node_Id (Field);
18371 Syntactic : constant Boolean := Parent (Old_N) = Old_Par;
18372
18373 New_N : Node_Id;
18374
18375 begin
18376 -- The field is an entity/itype
18377
18378 if Nkind (Old_N) in N_Entity then
18379
18380 -- An entity/itype is always replicated
18381
18382 New_N := Corresponding_Entity (Old_N);
18383
18384 -- Update the parent pointer when the entity is a syntactic
18385 -- field. Note that itypes do not have parent pointers.
18386
18387 if Syntactic and then New_N /= Old_N then
18388 Set_Parent (New_N, New_Par);
18389 end if;
18390
18391 -- The field is a node
18392
18393 else
18394 -- A node is replicated when it is either a syntactic field
18395 -- or when the caller treats it as a semantic attribute.
18396
18397 if Syntactic or else Semantic then
18398 New_N := Copy_Node_With_Replacement (Old_N);
18399
18400 -- Update the parent pointer when the node is a syntactic
18401 -- field.
18402
18403 if Syntactic and then New_N /= Old_N then
18404 Set_Parent (New_N, New_Par);
18405 end if;
18406
18407 -- Otherwise the node is returned unchanged
18408
18409 else
18410 New_N := Old_N;
18411 end if;
18412 end if;
18413
18414 return Union_Id (New_N);
18415 end;
18416
18417 -- The field is an entity list
18418
18419 elsif Field in Elist_Range then
18420 return Union_Id (Copy_Elist_With_Replacement (Elist_Id (Field)));
18421
18422 -- The field is a syntactic list
18423
18424 elsif Field in List_Range then
18425 declare
18426 Old_List : constant List_Id := List_Id (Field);
18427 Syntactic : constant Boolean := Parent (Old_List) = Old_Par;
18428
18429 New_List : List_Id;
18430
18431 begin
18432 -- A list is replicated when it is either a syntactic field or
18433 -- when the caller treats it as a semantic attribute.
18434
18435 if Syntactic or else Semantic then
18436 New_List := Copy_List_With_Replacement (Old_List);
18437
18438 -- Update the parent pointer when the list is a syntactic
18439 -- field.
18440
18441 if Syntactic and then New_List /= Old_List then
18442 Set_Parent (New_List, New_Par);
18443 end if;
18444
18445 -- Otherwise the list is returned unchanged
18446
18447 else
18448 New_List := Old_List;
18449 end if;
18450
18451 return Union_Id (New_List);
18452 end;
18453
18454 -- Otherwise the field denotes an attribute that does not need to be
18455 -- replicated (Chars, literals, etc).
18456
18457 else
18458 return Field;
18459 end if;
18460 end Copy_Field_With_Replacement;
18461
18462 --------------------------------
18463 -- Copy_List_With_Replacement --
18464 --------------------------------
18465
18466 function Copy_List_With_Replacement (List : List_Id) return List_Id is
18467 Elmt : Node_Id;
18468 Result : List_Id;
18469
18470 begin
18471 -- Copy the contents of the old list. Note that the list itself may
18472 -- be empty, in which case the routine returns a new empty list. This
18473 -- avoids sharing lists between subtrees. The element of a syntactic
18474 -- list is always a node, never an entity or itype, hence the call to
18475 -- routine Copy_Node_With_Replacement.
18476
18477 if Present (List) then
18478 Result := New_List;
18479
18480 Elmt := First (List);
18481 while Present (Elmt) loop
18482 Append (Copy_Node_With_Replacement (Elmt), Result);
18483
18484 Next (Elmt);
18485 end loop;
18486
18487 -- Otherwise the list does not exist
18488
18489 else
18490 Result := No_List;
18491 end if;
18492
18493 return Result;
18494 end Copy_List_With_Replacement;
18495
18496 --------------------------------
18497 -- Copy_Node_With_Replacement --
18498 --------------------------------
18499
18500 function Copy_Node_With_Replacement (N : Node_Id) return Node_Id is
18501 Result : Node_Id;
18502
18503 begin
18504 -- Assume that the node must be returned unchanged
18505
18506 Result := N;
18507
18508 if N > Empty_Or_Error then
18509 pragma Assert (Nkind (N) not in N_Entity);
18510
18511 Result := New_Copy (N);
18512
18513 Set_Field1 (Result,
18514 Copy_Field_With_Replacement
18515 (Field => Field1 (Result),
18516 Old_Par => N,
18517 New_Par => Result));
18518
18519 Set_Field2 (Result,
18520 Copy_Field_With_Replacement
18521 (Field => Field2 (Result),
18522 Old_Par => N,
18523 New_Par => Result));
18524
18525 Set_Field3 (Result,
18526 Copy_Field_With_Replacement
18527 (Field => Field3 (Result),
18528 Old_Par => N,
18529 New_Par => Result));
18530
18531 Set_Field4 (Result,
18532 Copy_Field_With_Replacement
18533 (Field => Field4 (Result),
18534 Old_Par => N,
18535 New_Par => Result));
18536
18537 Set_Field5 (Result,
18538 Copy_Field_With_Replacement
18539 (Field => Field5 (Result),
18540 Old_Par => N,
18541 New_Par => Result));
18542
18543 -- Update the Comes_From_Source and Sloc attributes of the node
18544 -- in case the caller has supplied new values.
18545
18546 Update_CFS_Sloc (Result);
18547
18548 -- Update the Associated_Node_For_Itype attribute of all itypes
18549 -- created during Phase 1 whose associated node is N. As a result
18550 -- the Associated_Node_For_Itype refers to the replicated node.
18551 -- No action needs to be taken when the Associated_Node_For_Itype
18552 -- refers to an entity because this was already handled during
18553 -- Phase 1, in Visit_Itype.
18554
18555 Update_Pending_Itypes
18556 (Old_Assoc => N,
18557 New_Assoc => Result);
18558
18559 -- Update the First/Next_Named_Association chain for a replicated
18560 -- call.
18561
18562 if Nkind_In (N, N_Entry_Call_Statement,
18563 N_Function_Call,
18564 N_Procedure_Call_Statement)
18565 then
18566 Update_Named_Associations
18567 (Old_Call => N,
18568 New_Call => Result);
18569
18570 -- Update the Renamed_Object attribute of a replicated object
18571 -- declaration.
18572
18573 elsif Nkind (N) = N_Object_Renaming_Declaration then
18574 Set_Renamed_Object (Defining_Entity (Result), Name (Result));
18575
18576 -- Update the First_Real_Statement attribute of a replicated
18577 -- handled sequence of statements.
18578
18579 elsif Nkind (N) = N_Handled_Sequence_Of_Statements then
18580 Update_First_Real_Statement
18581 (Old_HSS => N,
18582 New_HSS => Result);
18583 end if;
18584 end if;
18585
18586 return Result;
18587 end Copy_Node_With_Replacement;
18588
18589 --------------------------
18590 -- Corresponding_Entity --
18591 --------------------------
18592
18593 function Corresponding_Entity (Id : Entity_Id) return Entity_Id is
18594 New_Id : Entity_Id;
18595 Result : Entity_Id;
18596
18597 begin
18598 -- Assume that the entity must be returned unchanged
18599
18600 Result := Id;
18601
18602 if Id > Empty_Or_Error then
18603 pragma Assert (Nkind (Id) in N_Entity);
18604
18605 -- Determine whether the entity has a corresponding new entity
18606 -- generated during Phase 1 and if it does, use it.
18607
18608 if NCT_Tables_In_Use then
18609 New_Id := NCT_New_Entities.Get (Id);
18610
18611 if Present (New_Id) then
18612 Result := New_Id;
18613 end if;
18614 end if;
18615 end if;
18616
18617 return Result;
18618 end Corresponding_Entity;
18619
18620 -------------------
18621 -- In_Entity_Map --
18622 -------------------
18623
18624 function In_Entity_Map
18625 (Id : Entity_Id;
18626 Entity_Map : Elist_Id) return Boolean
18627 is
18628 Elmt : Elmt_Id;
18629 Old_Id : Entity_Id;
18630
18631 begin
18632 -- The entity map contains pairs (Old_Id, New_Id). The advancement
18633 -- step always skips the New_Id portion of the pair.
18634
18635 if Present (Entity_Map) then
18636 Elmt := First_Elmt (Entity_Map);
18637 while Present (Elmt) loop
18638 Old_Id := Node (Elmt);
18639
18640 if Old_Id = Id then
18641 return True;
18642 end if;
18643
18644 Next_Elmt (Elmt);
18645 Next_Elmt (Elmt);
18646 end loop;
18647 end if;
18648
18649 return False;
18650 end In_Entity_Map;
18651
18652 ---------------------
18653 -- Update_CFS_Sloc --
18654 ---------------------
18655
18656 procedure Update_CFS_Sloc (N : Node_Or_Entity_Id) is
18657 begin
18658 -- A new source location defaults the Comes_From_Source attribute
18659
18660 if New_Sloc /= No_Location then
18661 Set_Comes_From_Source (N, Default_Node.Comes_From_Source);
18662 Set_Sloc (N, New_Sloc);
18663 end if;
18664 end Update_CFS_Sloc;
18665
18666 ---------------------------------
18667 -- Update_First_Real_Statement --
18668 ---------------------------------
18669
18670 procedure Update_First_Real_Statement
18671 (Old_HSS : Node_Id;
18672 New_HSS : Node_Id)
18673 is
18674 Old_First_Stmt : constant Node_Id := First_Real_Statement (Old_HSS);
18675
18676 New_Stmt : Node_Id;
18677 Old_Stmt : Node_Id;
18678
18679 begin
18680 -- Recreate the First_Real_Statement attribute of a handled sequence
18681 -- of statements by traversing the statement lists of both sequences
18682 -- in parallel.
18683
18684 if Present (Old_First_Stmt) then
18685 New_Stmt := First (Statements (New_HSS));
18686 Old_Stmt := First (Statements (Old_HSS));
18687 while Present (Old_Stmt) and then Old_Stmt /= Old_First_Stmt loop
18688 Next (New_Stmt);
18689 Next (Old_Stmt);
18690 end loop;
18691
18692 pragma Assert (Present (New_Stmt));
18693 pragma Assert (Present (Old_Stmt));
18694
18695 Set_First_Real_Statement (New_HSS, New_Stmt);
18696 end if;
18697 end Update_First_Real_Statement;
18698
18699 -------------------------------
18700 -- Update_Named_Associations --
18701 -------------------------------
18702
18703 procedure Update_Named_Associations
18704 (Old_Call : Node_Id;
18705 New_Call : Node_Id)
18706 is
18707 New_Act : Node_Id;
18708 New_Next : Node_Id;
18709 Old_Act : Node_Id;
18710 Old_Next : Node_Id;
18711
18712 begin
18713 -- Recreate the First/Next_Named_Actual chain of a call by traversing
18714 -- the chains of both the old and new calls in parallel.
18715
18716 New_Act := First (Parameter_Associations (New_Call));
18717 Old_Act := First (Parameter_Associations (Old_Call));
18718 while Present (Old_Act) loop
18719 if Nkind (Old_Act) = N_Parameter_Association
18720 and then Present (Next_Named_Actual (Old_Act))
18721 then
18722 if First_Named_Actual (Old_Call) =
18723 Explicit_Actual_Parameter (Old_Act)
18724 then
18725 Set_First_Named_Actual (New_Call,
18726 Explicit_Actual_Parameter (New_Act));
18727 end if;
18728
18729 -- Scan the actual parameter list to find the next suitable
18730 -- named actual. Note that the list may be out of order.
18731
18732 New_Next := First (Parameter_Associations (New_Call));
18733 Old_Next := First (Parameter_Associations (Old_Call));
18734 while Nkind (Old_Next) /= N_Parameter_Association
18735 or else Explicit_Actual_Parameter (Old_Next) /=
18736 Next_Named_Actual (Old_Act)
18737 loop
18738 Next (New_Next);
18739 Next (Old_Next);
18740 end loop;
18741
18742 Set_Next_Named_Actual (New_Act,
18743 Explicit_Actual_Parameter (New_Next));
18744 end if;
18745
18746 Next (New_Act);
18747 Next (Old_Act);
18748 end loop;
18749 end Update_Named_Associations;
18750
18751 -------------------------
18752 -- Update_New_Entities --
18753 -------------------------
18754
18755 procedure Update_New_Entities (Entity_Map : Elist_Id) is
18756 New_Id : Entity_Id := Empty;
18757 Old_Id : Entity_Id := Empty;
18758
18759 begin
18760 if NCT_Tables_In_Use then
18761 NCT_New_Entities.Get_First (Old_Id, New_Id);
18762
18763 -- Update the semantic fields of all new entities created during
18764 -- Phase 1 which were not supplied via an entity map.
18765 -- ??? Is there a better way of distinguishing those?
18766
18767 while Present (Old_Id) and then Present (New_Id) loop
18768 if not (Present (Entity_Map)
18769 and then In_Entity_Map (Old_Id, Entity_Map))
18770 then
18771 Update_Semantic_Fields (New_Id);
18772 end if;
18773
18774 NCT_New_Entities.Get_Next (Old_Id, New_Id);
18775 end loop;
18776 end if;
18777 end Update_New_Entities;
18778
18779 ---------------------------
18780 -- Update_Pending_Itypes --
18781 ---------------------------
18782
18783 procedure Update_Pending_Itypes
18784 (Old_Assoc : Node_Id;
18785 New_Assoc : Node_Id)
18786 is
18787 Item : Elmt_Id;
18788 Itypes : Elist_Id;
18789
18790 begin
18791 if NCT_Tables_In_Use then
18792 Itypes := NCT_Pending_Itypes.Get (Old_Assoc);
18793
18794 -- Update the Associated_Node_For_Itype attribute for all itypes
18795 -- which originally refer to Old_Assoc to designate New_Assoc.
18796
18797 if Present (Itypes) then
18798 Item := First_Elmt (Itypes);
18799 while Present (Item) loop
18800 Set_Associated_Node_For_Itype (Node (Item), New_Assoc);
18801
18802 Next_Elmt (Item);
18803 end loop;
18804 end if;
18805 end if;
18806 end Update_Pending_Itypes;
18807
18808 ----------------------------
18809 -- Update_Semantic_Fields --
18810 ----------------------------
18811
18812 procedure Update_Semantic_Fields (Id : Entity_Id) is
18813 begin
18814 -- Discriminant_Constraint
18815
18816 if Has_Discriminants (Base_Type (Id)) then
18817 Set_Discriminant_Constraint (Id, Elist_Id (
18818 Copy_Field_With_Replacement
18819 (Field => Union_Id (Discriminant_Constraint (Id)),
18820 Semantic => True)));
18821 end if;
18822
18823 -- Etype
18824
18825 Set_Etype (Id, Node_Id (
18826 Copy_Field_With_Replacement
18827 (Field => Union_Id (Etype (Id)),
18828 Semantic => True)));
18829
18830 -- First_Index
18831 -- Packed_Array_Impl_Type
18832
18833 if Is_Array_Type (Id) then
18834 if Present (First_Index (Id)) then
18835 Set_First_Index (Id, First (List_Id (
18836 Copy_Field_With_Replacement
18837 (Field => Union_Id (List_Containing (First_Index (Id))),
18838 Semantic => True))));
18839 end if;
18840
18841 if Is_Packed (Id) then
18842 Set_Packed_Array_Impl_Type (Id, Node_Id (
18843 Copy_Field_With_Replacement
18844 (Field => Union_Id (Packed_Array_Impl_Type (Id)),
18845 Semantic => True)));
18846 end if;
18847 end if;
18848
18849 -- Next_Entity
18850
18851 Set_Next_Entity (Id, Node_Id (
18852 Copy_Field_With_Replacement
18853 (Field => Union_Id (Next_Entity (Id)),
18854 Semantic => True)));
18855
18856 -- Scalar_Range
18857
18858 if Is_Discrete_Type (Id) then
18859 Set_Scalar_Range (Id, Node_Id (
18860 Copy_Field_With_Replacement
18861 (Field => Union_Id (Scalar_Range (Id)),
18862 Semantic => True)));
18863 end if;
18864
18865 -- Scope
18866
18867 -- Update the scope when the caller specified an explicit one
18868
18869 if Present (New_Scope) then
18870 Set_Scope (Id, New_Scope);
18871 else
18872 Set_Scope (Id, Node_Id (
18873 Copy_Field_With_Replacement
18874 (Field => Union_Id (Scope (Id)),
18875 Semantic => True)));
18876 end if;
18877 end Update_Semantic_Fields;
18878
18879 --------------------
18880 -- Visit_Any_Node --
18881 --------------------
18882
18883 procedure Visit_Any_Node (N : Node_Or_Entity_Id) is
18884 begin
18885 if Nkind (N) in N_Entity then
18886 if Is_Itype (N) then
18887 Visit_Itype (N);
18888 else
18889 Visit_Entity (N);
18890 end if;
18891 else
18892 Visit_Node (N);
18893 end if;
18894 end Visit_Any_Node;
18895
18896 -----------------
18897 -- Visit_Elist --
18898 -----------------
18899
18900 procedure Visit_Elist (List : Elist_Id) is
18901 Elmt : Elmt_Id;
18902
18903 begin
18904 -- The element of an entity list could be an entity, itype, or a
18905 -- node, hence the call to Visit_Any_Node.
18906
18907 if Present (List) then
18908 Elmt := First_Elmt (List);
18909 while Present (Elmt) loop
18910 Visit_Any_Node (Node (Elmt));
18911
18912 Next_Elmt (Elmt);
18913 end loop;
18914 end if;
18915 end Visit_Elist;
18916
18917 ------------------
18918 -- Visit_Entity --
18919 ------------------
18920
18921 procedure Visit_Entity (Id : Entity_Id) is
18922 New_Id : Entity_Id;
18923
18924 begin
18925 pragma Assert (Nkind (Id) in N_Entity);
18926 pragma Assert (not Is_Itype (Id));
18927
18928 -- Nothing to do if the entity is not defined in the Actions list of
18929 -- an N_Expression_With_Actions node.
18930
18931 if EWA_Level = 0 then
18932 return;
18933
18934 -- Nothing to do if the entity is defined within a scoping construct
18935 -- of an N_Expression_With_Actions node.
18936
18937 elsif EWA_Inner_Scope_Level > 0 then
18938 return;
18939
18940 -- Nothing to do if the entity is not an object or a type. Relaxing
18941 -- this restriction leads to a performance penalty.
18942
18943 elsif not Ekind_In (Id, E_Constant, E_Variable)
18944 and then not Is_Type (Id)
18945 then
18946 return;
18947
18948 -- Nothing to do if the entity was already visited
18949
18950 elsif NCT_Tables_In_Use
18951 and then Present (NCT_New_Entities.Get (Id))
18952 then
18953 return;
18954
18955 -- Nothing to do if the declaration node of the entity is not within
18956 -- the subtree being replicated.
18957
18958 elsif not In_Subtree
18959 (N => Declaration_Node (Id),
18960 Root => Source)
18961 then
18962 return;
18963 end if;
18964
18965 -- Create a new entity by directly copying the old entity. This
18966 -- action causes all attributes of the old entity to be inherited.
18967
18968 New_Id := New_Copy (Id);
18969
18970 -- Create a new name for the new entity because the back end needs
18971 -- distinct names for debugging purposes.
18972
18973 Set_Chars (New_Id, New_Internal_Name ('T'));
18974
18975 -- Update the Comes_From_Source and Sloc attributes of the entity in
18976 -- case the caller has supplied new values.
18977
18978 Update_CFS_Sloc (New_Id);
18979
18980 -- Establish the following mapping within table NCT_New_Entities:
18981
18982 -- Id -> New_Id
18983
18984 Add_New_Entity (Id, New_Id);
18985
18986 -- Deal with the semantic fields of entities. The fields are visited
18987 -- because they may mention entities which reside within the subtree
18988 -- being copied.
18989
18990 Visit_Semantic_Fields (Id);
18991 end Visit_Entity;
18992
18993 -----------------
18994 -- Visit_Field --
18995 -----------------
18996
18997 procedure Visit_Field
18998 (Field : Union_Id;
18999 Par_Nod : Node_Id := Empty;
19000 Semantic : Boolean := False)
19001 is
19002 begin
19003 -- The field is empty
19004
19005 if Field = Union_Id (Empty) then
19006 return;
19007
19008 -- The field is an entity/itype/node
19009
19010 elsif Field in Node_Range then
19011 declare
19012 N : constant Node_Id := Node_Id (Field);
19013
19014 begin
19015 -- The field is an entity/itype
19016
19017 if Nkind (N) in N_Entity then
19018
19019 -- Itypes are always visited
19020
19021 if Is_Itype (N) then
19022 Visit_Itype (N);
19023
19024 -- An entity is visited when it is either a syntactic field
19025 -- or when the caller treats it as a semantic attribute.
19026
19027 elsif Parent (N) = Par_Nod or else Semantic then
19028 Visit_Entity (N);
19029 end if;
19030
19031 -- The field is a node
19032
19033 else
19034 -- A node is visited when it is either a syntactic field or
19035 -- when the caller treats it as a semantic attribute.
19036
19037 if Parent (N) = Par_Nod or else Semantic then
19038 Visit_Node (N);
19039 end if;
19040 end if;
19041 end;
19042
19043 -- The field is an entity list
19044
19045 elsif Field in Elist_Range then
19046 Visit_Elist (Elist_Id (Field));
19047
19048 -- The field is a syntax list
19049
19050 elsif Field in List_Range then
19051 declare
19052 List : constant List_Id := List_Id (Field);
19053
19054 begin
19055 -- A syntax list is visited when it is either a syntactic field
19056 -- or when the caller treats it as a semantic attribute.
19057
19058 if Parent (List) = Par_Nod or else Semantic then
19059 Visit_List (List);
19060 end if;
19061 end;
19062
19063 -- Otherwise the field denotes information which does not need to be
19064 -- visited (chars, literals, etc.).
19065
19066 else
19067 null;
19068 end if;
19069 end Visit_Field;
19070
19071 -----------------
19072 -- Visit_Itype --
19073 -----------------
19074
19075 procedure Visit_Itype (Itype : Entity_Id) is
19076 New_Assoc : Node_Id;
19077 New_Itype : Entity_Id;
19078 Old_Assoc : Node_Id;
19079
19080 begin
19081 pragma Assert (Nkind (Itype) in N_Entity);
19082 pragma Assert (Is_Itype (Itype));
19083
19084 -- Itypes that describe the designated type of access to subprograms
19085 -- have the structure of subprogram declarations, with signatures,
19086 -- etc. Either we duplicate the signatures completely, or choose to
19087 -- share such itypes, which is fine because their elaboration will
19088 -- have no side effects.
19089
19090 if Ekind (Itype) = E_Subprogram_Type then
19091 return;
19092
19093 -- Nothing to do if the itype was already visited
19094
19095 elsif NCT_Tables_In_Use
19096 and then Present (NCT_New_Entities.Get (Itype))
19097 then
19098 return;
19099
19100 -- Nothing to do if the associated node of the itype is not within
19101 -- the subtree being replicated.
19102
19103 elsif not In_Subtree
19104 (N => Associated_Node_For_Itype (Itype),
19105 Root => Source)
19106 then
19107 return;
19108 end if;
19109
19110 -- Create a new itype by directly copying the old itype. This action
19111 -- causes all attributes of the old itype to be inherited.
19112
19113 New_Itype := New_Copy (Itype);
19114
19115 -- Create a new name for the new itype because the back end requires
19116 -- distinct names for debugging purposes.
19117
19118 Set_Chars (New_Itype, New_Internal_Name ('T'));
19119
19120 -- Update the Comes_From_Source and Sloc attributes of the itype in
19121 -- case the caller has supplied new values.
19122
19123 Update_CFS_Sloc (New_Itype);
19124
19125 -- Establish the following mapping within table NCT_New_Entities:
19126
19127 -- Itype -> New_Itype
19128
19129 Add_New_Entity (Itype, New_Itype);
19130
19131 -- The new itype must be unfrozen because the resulting subtree may
19132 -- be inserted anywhere and cause an earlier or later freezing.
19133
19134 if Present (Freeze_Node (New_Itype)) then
19135 Set_Freeze_Node (New_Itype, Empty);
19136 Set_Is_Frozen (New_Itype, False);
19137 end if;
19138
19139 -- If a record subtype is simply copied, the entity list will be
19140 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
19141 -- ??? What does this do?
19142
19143 if Ekind_In (Itype, E_Class_Wide_Subtype, E_Record_Subtype) then
19144 Set_Cloned_Subtype (New_Itype, Itype);
19145 end if;
19146
19147 -- The associated node may denote an entity, in which case it may
19148 -- already have a new corresponding entity created during a prior
19149 -- call to Visit_Entity or Visit_Itype for the same subtree.
19150
19151 -- Given
19152 -- Old_Assoc ---------> New_Assoc
19153
19154 -- Created by Visit_Itype
19155 -- Itype -------------> New_Itype
19156 -- ANFI = Old_Assoc ANFI = Old_Assoc < must be updated
19157
19158 -- In the example above, Old_Assoc is an arbitrary entity that was
19159 -- already visited for the same subtree and has a corresponding new
19160 -- entity New_Assoc. Old_Assoc was inherited by New_Itype by virtue
19161 -- of copying entities, however it must be updated to New_Assoc.
19162
19163 Old_Assoc := Associated_Node_For_Itype (Itype);
19164
19165 if Nkind (Old_Assoc) in N_Entity then
19166 if NCT_Tables_In_Use then
19167 New_Assoc := NCT_New_Entities.Get (Old_Assoc);
19168
19169 if Present (New_Assoc) then
19170 Set_Associated_Node_For_Itype (New_Itype, New_Assoc);
19171 end if;
19172 end if;
19173
19174 -- Otherwise the associated node denotes a node. Postpone the update
19175 -- until Phase 2 when the node is replicated. Establish the following
19176 -- mapping within table NCT_Pending_Itypes:
19177
19178 -- Old_Assoc -> (New_Type, ...)
19179
19180 else
19181 Add_Pending_Itype (Old_Assoc, New_Itype);
19182 end if;
19183
19184 -- Deal with the semantic fields of itypes. The fields are visited
19185 -- because they may mention entities that reside within the subtree
19186 -- being copied.
19187
19188 Visit_Semantic_Fields (Itype);
19189 end Visit_Itype;
19190
19191 ----------------
19192 -- Visit_List --
19193 ----------------
19194
19195 procedure Visit_List (List : List_Id) is
19196 Elmt : Node_Id;
19197
19198 begin
19199 -- Note that the element of a syntactic list is always a node, never
19200 -- an entity or itype, hence the call to Visit_Node.
19201
19202 if Present (List) then
19203 Elmt := First (List);
19204 while Present (Elmt) loop
19205 Visit_Node (Elmt);
19206
19207 Next (Elmt);
19208 end loop;
19209 end if;
19210 end Visit_List;
19211
19212 ----------------
19213 -- Visit_Node --
19214 ----------------
19215
19216 procedure Visit_Node (N : Node_Or_Entity_Id) is
19217 begin
19218 pragma Assert (Nkind (N) not in N_Entity);
19219
19220 if Nkind (N) = N_Expression_With_Actions then
19221 EWA_Level := EWA_Level + 1;
19222
19223 elsif EWA_Level > 0
19224 and then Nkind_In (N, N_Block_Statement,
19225 N_Subprogram_Body,
19226 N_Subprogram_Declaration)
19227 then
19228 EWA_Inner_Scope_Level := EWA_Inner_Scope_Level + 1;
19229 end if;
19230
19231 Visit_Field
19232 (Field => Field1 (N),
19233 Par_Nod => N);
19234
19235 Visit_Field
19236 (Field => Field2 (N),
19237 Par_Nod => N);
19238
19239 Visit_Field
19240 (Field => Field3 (N),
19241 Par_Nod => N);
19242
19243 Visit_Field
19244 (Field => Field4 (N),
19245 Par_Nod => N);
19246
19247 Visit_Field
19248 (Field => Field5 (N),
19249 Par_Nod => N);
19250
19251 if EWA_Level > 0
19252 and then Nkind_In (N, N_Block_Statement,
19253 N_Subprogram_Body,
19254 N_Subprogram_Declaration)
19255 then
19256 EWA_Inner_Scope_Level := EWA_Inner_Scope_Level - 1;
19257
19258 elsif Nkind (N) = N_Expression_With_Actions then
19259 EWA_Level := EWA_Level - 1;
19260 end if;
19261 end Visit_Node;
19262
19263 ---------------------------
19264 -- Visit_Semantic_Fields --
19265 ---------------------------
19266
19267 procedure Visit_Semantic_Fields (Id : Entity_Id) is
19268 begin
19269 pragma Assert (Nkind (Id) in N_Entity);
19270
19271 -- Discriminant_Constraint
19272
19273 if Has_Discriminants (Base_Type (Id)) then
19274 Visit_Field
19275 (Field => Union_Id (Discriminant_Constraint (Id)),
19276 Semantic => True);
19277 end if;
19278
19279 -- Etype
19280
19281 Visit_Field
19282 (Field => Union_Id (Etype (Id)),
19283 Semantic => True);
19284
19285 -- First_Index
19286 -- Packed_Array_Impl_Type
19287
19288 if Is_Array_Type (Id) then
19289 if Present (First_Index (Id)) then
19290 Visit_Field
19291 (Field => Union_Id (List_Containing (First_Index (Id))),
19292 Semantic => True);
19293 end if;
19294
19295 if Is_Packed (Id) then
19296 Visit_Field
19297 (Field => Union_Id (Packed_Array_Impl_Type (Id)),
19298 Semantic => True);
19299 end if;
19300 end if;
19301
19302 -- Scalar_Range
19303
19304 if Is_Discrete_Type (Id) then
19305 Visit_Field
19306 (Field => Union_Id (Scalar_Range (Id)),
19307 Semantic => True);
19308 end if;
19309 end Visit_Semantic_Fields;
19310
19311 -- Start of processing for New_Copy_Tree
19312
19313 begin
19314 -- Routine New_Copy_Tree performs a deep copy of a subtree by creating
19315 -- shallow copies for each node within, and then updating the child and
19316 -- parent pointers accordingly. This process is straightforward, however
19317 -- the routine must deal with the following complications:
19318
19319 -- * Entities defined within N_Expression_With_Actions nodes must be
19320 -- replicated rather than shared to avoid introducing two identical
19321 -- symbols within the same scope. Note that no other expression can
19322 -- currently define entities.
19323
19324 -- do
19325 -- Source_Low : ...;
19326 -- Source_High : ...;
19327
19328 -- <reference to Source_Low>
19329 -- <reference to Source_High>
19330 -- in ... end;
19331
19332 -- New_Copy_Tree handles this case by first creating new entities
19333 -- and then updating all existing references to point to these new
19334 -- entities.
19335
19336 -- do
19337 -- New_Low : ...;
19338 -- New_High : ...;
19339
19340 -- <reference to New_Low>
19341 -- <reference to New_High>
19342 -- in ... end;
19343
19344 -- * Itypes defined within the subtree must be replicated to avoid any
19345 -- dependencies on invalid or inaccessible data.
19346
19347 -- subtype Source_Itype is ... range Source_Low .. Source_High;
19348
19349 -- New_Copy_Tree handles this case by first creating a new itype in
19350 -- the same fashion as entities, and then updating various relevant
19351 -- constraints.
19352
19353 -- subtype New_Itype is ... range New_Low .. New_High;
19354
19355 -- * The Associated_Node_For_Itype field of itypes must be updated to
19356 -- reference the proper replicated entity or node.
19357
19358 -- * Semantic fields of entities such as Etype and Scope must be
19359 -- updated to reference the proper replicated entities.
19360
19361 -- * Semantic fields of nodes such as First_Real_Statement must be
19362 -- updated to reference the proper replicated nodes.
19363
19364 -- To meet all these demands, routine New_Copy_Tree is split into two
19365 -- phases.
19366
19367 -- Phase 1 traverses the tree in order to locate entities and itypes
19368 -- defined within the subtree. New entities are generated and saved in
19369 -- table NCT_New_Entities. The semantic fields of all new entities and
19370 -- itypes are then updated accordingly.
19371
19372 -- Phase 2 traverses the tree in order to replicate each node. Various
19373 -- semantic fields of nodes and entities are updated accordingly.
19374
19375 -- Preparatory phase. Clear the contents of tables NCT_New_Entities and
19376 -- NCT_Pending_Itypes in case a previous call to New_Copy_Tree left some
19377 -- data inside.
19378
19379 if NCT_Tables_In_Use then
19380 NCT_Tables_In_Use := False;
19381
19382 NCT_New_Entities.Reset;
19383 NCT_Pending_Itypes.Reset;
19384 end if;
19385
19386 -- Populate tables NCT_New_Entities and NCT_Pending_Itypes with data
19387 -- supplied by a linear entity map. The tables offer faster access to
19388 -- the same data.
19389
19390 Build_NCT_Tables (Map);
19391
19392 -- Execute Phase 1. Traverse the subtree and generate new entities for
19393 -- the following cases:
19394
19395 -- * An entity defined within an N_Expression_With_Actions node
19396
19397 -- * An itype referenced within the subtree where the associated node
19398 -- is also in the subtree.
19399
19400 -- All new entities are accessible via table NCT_New_Entities, which
19401 -- contains mappings of the form:
19402
19403 -- Old_Entity -> New_Entity
19404 -- Old_Itype -> New_Itype
19405
19406 -- In addition, the associated nodes of all new itypes are mapped in
19407 -- table NCT_Pending_Itypes:
19408
19409 -- Assoc_Nod -> (New_Itype1, New_Itype2, .., New_ItypeN)
19410
19411 Visit_Any_Node (Source);
19412
19413 -- Update the semantic attributes of all new entities generated during
19414 -- Phase 1 before starting Phase 2. The updates could be performed in
19415 -- routine Corresponding_Entity, however this may cause the same entity
19416 -- to be updated multiple times, effectively generating useless nodes.
19417 -- Keeping the updates separates from Phase 2 ensures that only one set
19418 -- of attributes is generated for an entity at any one time.
19419
19420 Update_New_Entities (Map);
19421
19422 -- Execute Phase 2. Replicate the source subtree one node at a time.
19423 -- The following transformations take place:
19424
19425 -- * References to entities and itypes are updated to refer to the
19426 -- new entities and itypes generated during Phase 1.
19427
19428 -- * All Associated_Node_For_Itype attributes of itypes are updated
19429 -- to refer to the new replicated Associated_Node_For_Itype.
19430
19431 return Copy_Node_With_Replacement (Source);
19432 end New_Copy_Tree;
19433
19434 -------------------------
19435 -- New_External_Entity --
19436 -------------------------
19437
19438 function New_External_Entity
19439 (Kind : Entity_Kind;
19440 Scope_Id : Entity_Id;
19441 Sloc_Value : Source_Ptr;
19442 Related_Id : Entity_Id;
19443 Suffix : Character;
19444 Suffix_Index : Nat := 0;
19445 Prefix : Character := ' ') return Entity_Id
19446 is
19447 N : constant Entity_Id :=
19448 Make_Defining_Identifier (Sloc_Value,
19449 New_External_Name
19450 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
19451
19452 begin
19453 Set_Ekind (N, Kind);
19454 Set_Is_Internal (N, True);
19455 Append_Entity (N, Scope_Id);
19456 Set_Public_Status (N);
19457
19458 if Kind in Type_Kind then
19459 Init_Size_Align (N);
19460 end if;
19461
19462 return N;
19463 end New_External_Entity;
19464
19465 -------------------------
19466 -- New_Internal_Entity --
19467 -------------------------
19468
19469 function New_Internal_Entity
19470 (Kind : Entity_Kind;
19471 Scope_Id : Entity_Id;
19472 Sloc_Value : Source_Ptr;
19473 Id_Char : Character) return Entity_Id
19474 is
19475 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
19476
19477 begin
19478 Set_Ekind (N, Kind);
19479 Set_Is_Internal (N, True);
19480 Append_Entity (N, Scope_Id);
19481
19482 if Kind in Type_Kind then
19483 Init_Size_Align (N);
19484 end if;
19485
19486 return N;
19487 end New_Internal_Entity;
19488
19489 -----------------
19490 -- Next_Actual --
19491 -----------------
19492
19493 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
19494 N : Node_Id;
19495
19496 begin
19497 -- If we are pointing at a positional parameter, it is a member of a
19498 -- node list (the list of parameters), and the next parameter is the
19499 -- next node on the list, unless we hit a parameter association, then
19500 -- we shift to using the chain whose head is the First_Named_Actual in
19501 -- the parent, and then is threaded using the Next_Named_Actual of the
19502 -- Parameter_Association. All this fiddling is because the original node
19503 -- list is in the textual call order, and what we need is the
19504 -- declaration order.
19505
19506 if Is_List_Member (Actual_Id) then
19507 N := Next (Actual_Id);
19508
19509 if Nkind (N) = N_Parameter_Association then
19510
19511 -- In case of a build-in-place call, the call will no longer be a
19512 -- call; it will have been rewritten.
19513
19514 if Nkind_In (Parent (Actual_Id), N_Entry_Call_Statement,
19515 N_Function_Call,
19516 N_Procedure_Call_Statement)
19517 then
19518 return First_Named_Actual (Parent (Actual_Id));
19519 else
19520 return Empty;
19521 end if;
19522 else
19523 return N;
19524 end if;
19525
19526 else
19527 return Next_Named_Actual (Parent (Actual_Id));
19528 end if;
19529 end Next_Actual;
19530
19531 procedure Next_Actual (Actual_Id : in out Node_Id) is
19532 begin
19533 Actual_Id := Next_Actual (Actual_Id);
19534 end Next_Actual;
19535
19536 -----------------
19537 -- Next_Global --
19538 -----------------
19539
19540 function Next_Global (Node : Node_Id) return Node_Id is
19541 begin
19542 -- The global item may either be in a list, or by itself, in which case
19543 -- there is no next global item with the same mode.
19544
19545 if Is_List_Member (Node) then
19546 return Next (Node);
19547 else
19548 return Empty;
19549 end if;
19550 end Next_Global;
19551
19552 procedure Next_Global (Node : in out Node_Id) is
19553 begin
19554 Node := Next_Global (Node);
19555 end Next_Global;
19556
19557 ----------------------------------
19558 -- New_Requires_Transient_Scope --
19559 ----------------------------------
19560
19561 function New_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
19562 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean;
19563 -- This is called for untagged records and protected types, with
19564 -- nondefaulted discriminants. Returns True if the size of function
19565 -- results is known at the call site, False otherwise. Returns False
19566 -- if there is a variant part that depends on the discriminants of
19567 -- this type, or if there is an array constrained by the discriminants
19568 -- of this type. ???Currently, this is overly conservative (the array
19569 -- could be nested inside some other record that is constrained by
19570 -- nondiscriminants). That is, the recursive calls are too conservative.
19571
19572 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean;
19573 -- Returns True if Typ is a nonlimited record with defaulted
19574 -- discriminants whose max size makes it unsuitable for allocating on
19575 -- the primary stack.
19576
19577 ------------------------------
19578 -- Caller_Known_Size_Record --
19579 ------------------------------
19580
19581 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean is
19582 pragma Assert (Typ = Underlying_Type (Typ));
19583
19584 begin
19585 if Has_Variant_Part (Typ) and then not Is_Definite_Subtype (Typ) then
19586 return False;
19587 end if;
19588
19589 declare
19590 Comp : Entity_Id;
19591
19592 begin
19593 Comp := First_Entity (Typ);
19594 while Present (Comp) loop
19595
19596 -- Only look at E_Component entities. No need to look at
19597 -- E_Discriminant entities, and we must ignore internal
19598 -- subtypes generated for constrained components.
19599
19600 if Ekind (Comp) = E_Component then
19601 declare
19602 Comp_Type : constant Entity_Id :=
19603 Underlying_Type (Etype (Comp));
19604
19605 begin
19606 if Is_Record_Type (Comp_Type)
19607 or else
19608 Is_Protected_Type (Comp_Type)
19609 then
19610 if not Caller_Known_Size_Record (Comp_Type) then
19611 return False;
19612 end if;
19613
19614 elsif Is_Array_Type (Comp_Type) then
19615 if Size_Depends_On_Discriminant (Comp_Type) then
19616 return False;
19617 end if;
19618 end if;
19619 end;
19620 end if;
19621
19622 Next_Entity (Comp);
19623 end loop;
19624 end;
19625
19626 return True;
19627 end Caller_Known_Size_Record;
19628
19629 ------------------------------
19630 -- Large_Max_Size_Mutable --
19631 ------------------------------
19632
19633 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean is
19634 pragma Assert (Typ = Underlying_Type (Typ));
19635
19636 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean;
19637 -- Returns true if the discrete type T has a large range
19638
19639 ----------------------------
19640 -- Is_Large_Discrete_Type --
19641 ----------------------------
19642
19643 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean is
19644 Threshold : constant Int := 16;
19645 -- Arbitrary threshold above which we consider it "large". We want
19646 -- a fairly large threshold, because these large types really
19647 -- shouldn't have default discriminants in the first place, in
19648 -- most cases.
19649
19650 begin
19651 return UI_To_Int (RM_Size (T)) > Threshold;
19652 end Is_Large_Discrete_Type;
19653
19654 -- Start of processing for Large_Max_Size_Mutable
19655
19656 begin
19657 if Is_Record_Type (Typ)
19658 and then not Is_Limited_View (Typ)
19659 and then Has_Defaulted_Discriminants (Typ)
19660 then
19661 -- Loop through the components, looking for an array whose upper
19662 -- bound(s) depends on discriminants, where both the subtype of
19663 -- the discriminant and the index subtype are too large.
19664
19665 declare
19666 Comp : Entity_Id;
19667
19668 begin
19669 Comp := First_Entity (Typ);
19670 while Present (Comp) loop
19671 if Ekind (Comp) = E_Component then
19672 declare
19673 Comp_Type : constant Entity_Id :=
19674 Underlying_Type (Etype (Comp));
19675
19676 Hi : Node_Id;
19677 Indx : Node_Id;
19678 Ityp : Entity_Id;
19679
19680 begin
19681 if Is_Array_Type (Comp_Type) then
19682 Indx := First_Index (Comp_Type);
19683
19684 while Present (Indx) loop
19685 Ityp := Etype (Indx);
19686 Hi := Type_High_Bound (Ityp);
19687
19688 if Nkind (Hi) = N_Identifier
19689 and then Ekind (Entity (Hi)) = E_Discriminant
19690 and then Is_Large_Discrete_Type (Ityp)
19691 and then Is_Large_Discrete_Type
19692 (Etype (Entity (Hi)))
19693 then
19694 return True;
19695 end if;
19696
19697 Next_Index (Indx);
19698 end loop;
19699 end if;
19700 end;
19701 end if;
19702
19703 Next_Entity (Comp);
19704 end loop;
19705 end;
19706 end if;
19707
19708 return False;
19709 end Large_Max_Size_Mutable;
19710
19711 -- Local declarations
19712
19713 Typ : constant Entity_Id := Underlying_Type (Id);
19714
19715 -- Start of processing for New_Requires_Transient_Scope
19716
19717 begin
19718 -- This is a private type which is not completed yet. This can only
19719 -- happen in a default expression (of a formal parameter or of a
19720 -- record component). Do not expand transient scope in this case.
19721
19722 if No (Typ) then
19723 return False;
19724
19725 -- Do not expand transient scope for non-existent procedure return or
19726 -- string literal types.
19727
19728 elsif Typ = Standard_Void_Type
19729 or else Ekind (Typ) = E_String_Literal_Subtype
19730 then
19731 return False;
19732
19733 -- If Typ is a generic formal incomplete type, then we want to look at
19734 -- the actual type.
19735
19736 elsif Ekind (Typ) = E_Record_Subtype
19737 and then Present (Cloned_Subtype (Typ))
19738 then
19739 return New_Requires_Transient_Scope (Cloned_Subtype (Typ));
19740
19741 -- Functions returning specific tagged types may dispatch on result, so
19742 -- their returned value is allocated on the secondary stack, even in the
19743 -- definite case. We must treat nondispatching functions the same way,
19744 -- because access-to-function types can point at both, so the calling
19745 -- conventions must be compatible. Is_Tagged_Type includes controlled
19746 -- types and class-wide types. Controlled type temporaries need
19747 -- finalization.
19748
19749 -- ???It's not clear why we need to return noncontrolled types with
19750 -- controlled components on the secondary stack.
19751
19752 elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
19753 return True;
19754
19755 -- Untagged definite subtypes are known size. This includes all
19756 -- elementary [sub]types. Tasks are known size even if they have
19757 -- discriminants. So we return False here, with one exception:
19758 -- For a type like:
19759 -- type T (Last : Natural := 0) is
19760 -- X : String (1 .. Last);
19761 -- end record;
19762 -- we return True. That's because for "P(F(...));", where F returns T,
19763 -- we don't know the size of the result at the call site, so if we
19764 -- allocated it on the primary stack, we would have to allocate the
19765 -- maximum size, which is way too big.
19766
19767 elsif Is_Definite_Subtype (Typ) or else Is_Task_Type (Typ) then
19768 return Large_Max_Size_Mutable (Typ);
19769
19770 -- Indefinite (discriminated) untagged record or protected type
19771
19772 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
19773 return not Caller_Known_Size_Record (Typ);
19774
19775 -- Unconstrained array
19776
19777 else
19778 pragma Assert (Is_Array_Type (Typ) and not Is_Definite_Subtype (Typ));
19779 return True;
19780 end if;
19781 end New_Requires_Transient_Scope;
19782
19783 --------------------------
19784 -- No_Heap_Finalization --
19785 --------------------------
19786
19787 function No_Heap_Finalization (Typ : Entity_Id) return Boolean is
19788 begin
19789 if Ekind_In (Typ, E_Access_Type, E_General_Access_Type)
19790 and then Is_Library_Level_Entity (Typ)
19791 then
19792 -- A global No_Heap_Finalization pragma applies to all library-level
19793 -- named access-to-object types.
19794
19795 if Present (No_Heap_Finalization_Pragma) then
19796 return True;
19797
19798 -- The library-level named access-to-object type itself is subject to
19799 -- pragma No_Heap_Finalization.
19800
19801 elsif Present (Get_Pragma (Typ, Pragma_No_Heap_Finalization)) then
19802 return True;
19803 end if;
19804 end if;
19805
19806 return False;
19807 end No_Heap_Finalization;
19808
19809 -----------------------
19810 -- Normalize_Actuals --
19811 -----------------------
19812
19813 -- Chain actuals according to formals of subprogram. If there are no named
19814 -- associations, the chain is simply the list of Parameter Associations,
19815 -- since the order is the same as the declaration order. If there are named
19816 -- associations, then the First_Named_Actual field in the N_Function_Call
19817 -- or N_Procedure_Call_Statement node points to the Parameter_Association
19818 -- node for the parameter that comes first in declaration order. The
19819 -- remaining named parameters are then chained in declaration order using
19820 -- Next_Named_Actual.
19821
19822 -- This routine also verifies that the number of actuals is compatible with
19823 -- the number and default values of formals, but performs no type checking
19824 -- (type checking is done by the caller).
19825
19826 -- If the matching succeeds, Success is set to True and the caller proceeds
19827 -- with type-checking. If the match is unsuccessful, then Success is set to
19828 -- False, and the caller attempts a different interpretation, if there is
19829 -- one.
19830
19831 -- If the flag Report is on, the call is not overloaded, and a failure to
19832 -- match can be reported here, rather than in the caller.
19833
19834 procedure Normalize_Actuals
19835 (N : Node_Id;
19836 S : Entity_Id;
19837 Report : Boolean;
19838 Success : out Boolean)
19839 is
19840 Actuals : constant List_Id := Parameter_Associations (N);
19841 Actual : Node_Id := Empty;
19842 Formal : Entity_Id;
19843 Last : Node_Id := Empty;
19844 First_Named : Node_Id := Empty;
19845 Found : Boolean;
19846
19847 Formals_To_Match : Integer := 0;
19848 Actuals_To_Match : Integer := 0;
19849
19850 procedure Chain (A : Node_Id);
19851 -- Add named actual at the proper place in the list, using the
19852 -- Next_Named_Actual link.
19853
19854 function Reporting return Boolean;
19855 -- Determines if an error is to be reported. To report an error, we
19856 -- need Report to be True, and also we do not report errors caused
19857 -- by calls to init procs that occur within other init procs. Such
19858 -- errors must always be cascaded errors, since if all the types are
19859 -- declared correctly, the compiler will certainly build decent calls.
19860
19861 -----------
19862 -- Chain --
19863 -----------
19864
19865 procedure Chain (A : Node_Id) is
19866 begin
19867 if No (Last) then
19868
19869 -- Call node points to first actual in list
19870
19871 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
19872
19873 else
19874 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
19875 end if;
19876
19877 Last := A;
19878 Set_Next_Named_Actual (Last, Empty);
19879 end Chain;
19880
19881 ---------------
19882 -- Reporting --
19883 ---------------
19884
19885 function Reporting return Boolean is
19886 begin
19887 if not Report then
19888 return False;
19889
19890 elsif not Within_Init_Proc then
19891 return True;
19892
19893 elsif Is_Init_Proc (Entity (Name (N))) then
19894 return False;
19895
19896 else
19897 return True;
19898 end if;
19899 end Reporting;
19900
19901 -- Start of processing for Normalize_Actuals
19902
19903 begin
19904 if Is_Access_Type (S) then
19905
19906 -- The name in the call is a function call that returns an access
19907 -- to subprogram. The designated type has the list of formals.
19908
19909 Formal := First_Formal (Designated_Type (S));
19910 else
19911 Formal := First_Formal (S);
19912 end if;
19913
19914 while Present (Formal) loop
19915 Formals_To_Match := Formals_To_Match + 1;
19916 Next_Formal (Formal);
19917 end loop;
19918
19919 -- Find if there is a named association, and verify that no positional
19920 -- associations appear after named ones.
19921
19922 if Present (Actuals) then
19923 Actual := First (Actuals);
19924 end if;
19925
19926 while Present (Actual)
19927 and then Nkind (Actual) /= N_Parameter_Association
19928 loop
19929 Actuals_To_Match := Actuals_To_Match + 1;
19930 Next (Actual);
19931 end loop;
19932
19933 if No (Actual) and Actuals_To_Match = Formals_To_Match then
19934
19935 -- Most common case: positional notation, no defaults
19936
19937 Success := True;
19938 return;
19939
19940 elsif Actuals_To_Match > Formals_To_Match then
19941
19942 -- Too many actuals: will not work
19943
19944 if Reporting then
19945 if Is_Entity_Name (Name (N)) then
19946 Error_Msg_N ("too many arguments in call to&", Name (N));
19947 else
19948 Error_Msg_N ("too many arguments in call", N);
19949 end if;
19950 end if;
19951
19952 Success := False;
19953 return;
19954 end if;
19955
19956 First_Named := Actual;
19957
19958 while Present (Actual) loop
19959 if Nkind (Actual) /= N_Parameter_Association then
19960 Error_Msg_N
19961 ("positional parameters not allowed after named ones", Actual);
19962 Success := False;
19963 return;
19964
19965 else
19966 Actuals_To_Match := Actuals_To_Match + 1;
19967 end if;
19968
19969 Next (Actual);
19970 end loop;
19971
19972 if Present (Actuals) then
19973 Actual := First (Actuals);
19974 end if;
19975
19976 Formal := First_Formal (S);
19977 while Present (Formal) loop
19978
19979 -- Match the formals in order. If the corresponding actual is
19980 -- positional, nothing to do. Else scan the list of named actuals
19981 -- to find the one with the right name.
19982
19983 if Present (Actual)
19984 and then Nkind (Actual) /= N_Parameter_Association
19985 then
19986 Next (Actual);
19987 Actuals_To_Match := Actuals_To_Match - 1;
19988 Formals_To_Match := Formals_To_Match - 1;
19989
19990 else
19991 -- For named parameters, search the list of actuals to find
19992 -- one that matches the next formal name.
19993
19994 Actual := First_Named;
19995 Found := False;
19996 while Present (Actual) loop
19997 if Chars (Selector_Name (Actual)) = Chars (Formal) then
19998 Found := True;
19999 Chain (Actual);
20000 Actuals_To_Match := Actuals_To_Match - 1;
20001 Formals_To_Match := Formals_To_Match - 1;
20002 exit;
20003 end if;
20004
20005 Next (Actual);
20006 end loop;
20007
20008 if not Found then
20009 if Ekind (Formal) /= E_In_Parameter
20010 or else No (Default_Value (Formal))
20011 then
20012 if Reporting then
20013 if (Comes_From_Source (S)
20014 or else Sloc (S) = Standard_Location)
20015 and then Is_Overloadable (S)
20016 then
20017 if No (Actuals)
20018 and then
20019 Nkind_In (Parent (N), N_Procedure_Call_Statement,
20020 N_Function_Call,
20021 N_Parameter_Association)
20022 and then Ekind (S) /= E_Function
20023 then
20024 Set_Etype (N, Etype (S));
20025
20026 else
20027 Error_Msg_Name_1 := Chars (S);
20028 Error_Msg_Sloc := Sloc (S);
20029 Error_Msg_NE
20030 ("missing argument for parameter & "
20031 & "in call to % declared #", N, Formal);
20032 end if;
20033
20034 elsif Is_Overloadable (S) then
20035 Error_Msg_Name_1 := Chars (S);
20036
20037 -- Point to type derivation that generated the
20038 -- operation.
20039
20040 Error_Msg_Sloc := Sloc (Parent (S));
20041
20042 Error_Msg_NE
20043 ("missing argument for parameter & "
20044 & "in call to % (inherited) #", N, Formal);
20045
20046 else
20047 Error_Msg_NE
20048 ("missing argument for parameter &", N, Formal);
20049 end if;
20050 end if;
20051
20052 Success := False;
20053 return;
20054
20055 else
20056 Formals_To_Match := Formals_To_Match - 1;
20057 end if;
20058 end if;
20059 end if;
20060
20061 Next_Formal (Formal);
20062 end loop;
20063
20064 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
20065 Success := True;
20066 return;
20067
20068 else
20069 if Reporting then
20070
20071 -- Find some superfluous named actual that did not get
20072 -- attached to the list of associations.
20073
20074 Actual := First (Actuals);
20075 while Present (Actual) loop
20076 if Nkind (Actual) = N_Parameter_Association
20077 and then Actual /= Last
20078 and then No (Next_Named_Actual (Actual))
20079 then
20080 -- A validity check may introduce a copy of a call that
20081 -- includes an extra actual (for example for an unrelated
20082 -- accessibility check). Check that the extra actual matches
20083 -- some extra formal, which must exist already because
20084 -- subprogram must be frozen at this point.
20085
20086 if Present (Extra_Formals (S))
20087 and then not Comes_From_Source (Actual)
20088 and then Nkind (Actual) = N_Parameter_Association
20089 and then Chars (Extra_Formals (S)) =
20090 Chars (Selector_Name (Actual))
20091 then
20092 null;
20093 else
20094 Error_Msg_N
20095 ("unmatched actual & in call", Selector_Name (Actual));
20096 exit;
20097 end if;
20098 end if;
20099
20100 Next (Actual);
20101 end loop;
20102 end if;
20103
20104 Success := False;
20105 return;
20106 end if;
20107 end Normalize_Actuals;
20108
20109 --------------------------------
20110 -- Note_Possible_Modification --
20111 --------------------------------
20112
20113 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
20114 Modification_Comes_From_Source : constant Boolean :=
20115 Comes_From_Source (Parent (N));
20116
20117 Ent : Entity_Id;
20118 Exp : Node_Id;
20119
20120 begin
20121 -- Loop to find referenced entity, if there is one
20122
20123 Exp := N;
20124 loop
20125 Ent := Empty;
20126
20127 if Is_Entity_Name (Exp) then
20128 Ent := Entity (Exp);
20129
20130 -- If the entity is missing, it is an undeclared identifier,
20131 -- and there is nothing to annotate.
20132
20133 if No (Ent) then
20134 return;
20135 end if;
20136
20137 elsif Nkind (Exp) = N_Explicit_Dereference then
20138 declare
20139 P : constant Node_Id := Prefix (Exp);
20140
20141 begin
20142 -- In formal verification mode, keep track of all reads and
20143 -- writes through explicit dereferences.
20144
20145 if GNATprove_Mode then
20146 SPARK_Specific.Generate_Dereference (N, 'm');
20147 end if;
20148
20149 if Nkind (P) = N_Selected_Component
20150 and then Present (Entry_Formal (Entity (Selector_Name (P))))
20151 then
20152 -- Case of a reference to an entry formal
20153
20154 Ent := Entry_Formal (Entity (Selector_Name (P)));
20155
20156 elsif Nkind (P) = N_Identifier
20157 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
20158 and then Present (Expression (Parent (Entity (P))))
20159 and then Nkind (Expression (Parent (Entity (P)))) =
20160 N_Reference
20161 then
20162 -- Case of a reference to a value on which side effects have
20163 -- been removed.
20164
20165 Exp := Prefix (Expression (Parent (Entity (P))));
20166 goto Continue;
20167
20168 else
20169 return;
20170 end if;
20171 end;
20172
20173 elsif Nkind_In (Exp, N_Type_Conversion,
20174 N_Unchecked_Type_Conversion)
20175 then
20176 Exp := Expression (Exp);
20177 goto Continue;
20178
20179 elsif Nkind_In (Exp, N_Slice,
20180 N_Indexed_Component,
20181 N_Selected_Component)
20182 then
20183 -- Special check, if the prefix is an access type, then return
20184 -- since we are modifying the thing pointed to, not the prefix.
20185 -- When we are expanding, most usually the prefix is replaced
20186 -- by an explicit dereference, and this test is not needed, but
20187 -- in some cases (notably -gnatc mode and generics) when we do
20188 -- not do full expansion, we need this special test.
20189
20190 if Is_Access_Type (Etype (Prefix (Exp))) then
20191 return;
20192
20193 -- Otherwise go to prefix and keep going
20194
20195 else
20196 Exp := Prefix (Exp);
20197 goto Continue;
20198 end if;
20199
20200 -- All other cases, not a modification
20201
20202 else
20203 return;
20204 end if;
20205
20206 -- Now look for entity being referenced
20207
20208 if Present (Ent) then
20209 if Is_Object (Ent) then
20210 if Comes_From_Source (Exp)
20211 or else Modification_Comes_From_Source
20212 then
20213 -- Give warning if pragma unmodified is given and we are
20214 -- sure this is a modification.
20215
20216 if Has_Pragma_Unmodified (Ent) and then Sure then
20217
20218 -- Note that the entity may be present only as a result
20219 -- of pragma Unused.
20220
20221 if Has_Pragma_Unused (Ent) then
20222 Error_Msg_NE ("??pragma Unused given for &!", N, Ent);
20223 else
20224 Error_Msg_NE
20225 ("??pragma Unmodified given for &!", N, Ent);
20226 end if;
20227 end if;
20228
20229 Set_Never_Set_In_Source (Ent, False);
20230 end if;
20231
20232 Set_Is_True_Constant (Ent, False);
20233 Set_Current_Value (Ent, Empty);
20234 Set_Is_Known_Null (Ent, False);
20235
20236 if not Can_Never_Be_Null (Ent) then
20237 Set_Is_Known_Non_Null (Ent, False);
20238 end if;
20239
20240 -- Follow renaming chain
20241
20242 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
20243 and then Present (Renamed_Object (Ent))
20244 then
20245 Exp := Renamed_Object (Ent);
20246
20247 -- If the entity is the loop variable in an iteration over
20248 -- a container, retrieve container expression to indicate
20249 -- possible modification.
20250
20251 if Present (Related_Expression (Ent))
20252 and then Nkind (Parent (Related_Expression (Ent))) =
20253 N_Iterator_Specification
20254 then
20255 Exp := Original_Node (Related_Expression (Ent));
20256 end if;
20257
20258 goto Continue;
20259
20260 -- The expression may be the renaming of a subcomponent of an
20261 -- array or container. The assignment to the subcomponent is
20262 -- a modification of the container.
20263
20264 elsif Comes_From_Source (Original_Node (Exp))
20265 and then Nkind_In (Original_Node (Exp), N_Selected_Component,
20266 N_Indexed_Component)
20267 then
20268 Exp := Prefix (Original_Node (Exp));
20269 goto Continue;
20270 end if;
20271
20272 -- Generate a reference only if the assignment comes from
20273 -- source. This excludes, for example, calls to a dispatching
20274 -- assignment operation when the left-hand side is tagged. In
20275 -- GNATprove mode, we need those references also on generated
20276 -- code, as these are used to compute the local effects of
20277 -- subprograms.
20278
20279 if Modification_Comes_From_Source or GNATprove_Mode then
20280 Generate_Reference (Ent, Exp, 'm');
20281
20282 -- If the target of the assignment is the bound variable
20283 -- in an iterator, indicate that the corresponding array
20284 -- or container is also modified.
20285
20286 if Ada_Version >= Ada_2012
20287 and then Nkind (Parent (Ent)) = N_Iterator_Specification
20288 then
20289 declare
20290 Domain : constant Node_Id := Name (Parent (Ent));
20291
20292 begin
20293 -- TBD : in the full version of the construct, the
20294 -- domain of iteration can be given by an expression.
20295
20296 if Is_Entity_Name (Domain) then
20297 Generate_Reference (Entity (Domain), Exp, 'm');
20298 Set_Is_True_Constant (Entity (Domain), False);
20299 Set_Never_Set_In_Source (Entity (Domain), False);
20300 end if;
20301 end;
20302 end if;
20303 end if;
20304 end if;
20305
20306 Kill_Checks (Ent);
20307
20308 -- If we are sure this is a modification from source, and we know
20309 -- this modifies a constant, then give an appropriate warning.
20310
20311 if Sure
20312 and then Modification_Comes_From_Source
20313 and then Overlays_Constant (Ent)
20314 and then Address_Clause_Overlay_Warnings
20315 then
20316 declare
20317 Addr : constant Node_Id := Address_Clause (Ent);
20318 O_Ent : Entity_Id;
20319 Off : Boolean;
20320
20321 begin
20322 Find_Overlaid_Entity (Addr, O_Ent, Off);
20323
20324 Error_Msg_Sloc := Sloc (Addr);
20325 Error_Msg_NE
20326 ("??constant& may be modified via address clause#",
20327 N, O_Ent);
20328 end;
20329 end if;
20330
20331 return;
20332 end if;
20333
20334 <<Continue>>
20335 null;
20336 end loop;
20337 end Note_Possible_Modification;
20338
20339 -----------------
20340 -- Null_Status --
20341 -----------------
20342
20343 function Null_Status (N : Node_Id) return Null_Status_Kind is
20344 function Is_Null_Excluding_Def (Def : Node_Id) return Boolean;
20345 -- Determine whether definition Def carries a null exclusion
20346
20347 function Null_Status_Of_Entity (Id : Entity_Id) return Null_Status_Kind;
20348 -- Determine the null status of arbitrary entity Id
20349
20350 function Null_Status_Of_Type (Typ : Entity_Id) return Null_Status_Kind;
20351 -- Determine the null status of type Typ
20352
20353 ---------------------------
20354 -- Is_Null_Excluding_Def --
20355 ---------------------------
20356
20357 function Is_Null_Excluding_Def (Def : Node_Id) return Boolean is
20358 begin
20359 return
20360 Nkind_In (Def, N_Access_Definition,
20361 N_Access_Function_Definition,
20362 N_Access_Procedure_Definition,
20363 N_Access_To_Object_Definition,
20364 N_Component_Definition,
20365 N_Derived_Type_Definition)
20366 and then Null_Exclusion_Present (Def);
20367 end Is_Null_Excluding_Def;
20368
20369 ---------------------------
20370 -- Null_Status_Of_Entity --
20371 ---------------------------
20372
20373 function Null_Status_Of_Entity
20374 (Id : Entity_Id) return Null_Status_Kind
20375 is
20376 Decl : constant Node_Id := Declaration_Node (Id);
20377 Def : Node_Id;
20378
20379 begin
20380 -- The value of an imported or exported entity may be set externally
20381 -- regardless of a null exclusion. As a result, the value cannot be
20382 -- determined statically.
20383
20384 if Is_Imported (Id) or else Is_Exported (Id) then
20385 return Unknown;
20386
20387 elsif Nkind_In (Decl, N_Component_Declaration,
20388 N_Discriminant_Specification,
20389 N_Formal_Object_Declaration,
20390 N_Object_Declaration,
20391 N_Object_Renaming_Declaration,
20392 N_Parameter_Specification)
20393 then
20394 -- A component declaration yields a non-null value when either
20395 -- its component definition or access definition carries a null
20396 -- exclusion.
20397
20398 if Nkind (Decl) = N_Component_Declaration then
20399 Def := Component_Definition (Decl);
20400
20401 if Is_Null_Excluding_Def (Def) then
20402 return Is_Non_Null;
20403 end if;
20404
20405 Def := Access_Definition (Def);
20406
20407 if Present (Def) and then Is_Null_Excluding_Def (Def) then
20408 return Is_Non_Null;
20409 end if;
20410
20411 -- A formal object declaration yields a non-null value if its
20412 -- access definition carries a null exclusion. If the object is
20413 -- default initialized, then the value depends on the expression.
20414
20415 elsif Nkind (Decl) = N_Formal_Object_Declaration then
20416 Def := Access_Definition (Decl);
20417
20418 if Present (Def) and then Is_Null_Excluding_Def (Def) then
20419 return Is_Non_Null;
20420 end if;
20421
20422 -- A constant may yield a null or non-null value depending on its
20423 -- initialization expression.
20424
20425 elsif Ekind (Id) = E_Constant then
20426 return Null_Status (Constant_Value (Id));
20427
20428 -- The construct yields a non-null value when it has a null
20429 -- exclusion.
20430
20431 elsif Null_Exclusion_Present (Decl) then
20432 return Is_Non_Null;
20433
20434 -- An object renaming declaration yields a non-null value if its
20435 -- access definition carries a null exclusion. Otherwise the value
20436 -- depends on the renamed name.
20437
20438 elsif Nkind (Decl) = N_Object_Renaming_Declaration then
20439 Def := Access_Definition (Decl);
20440
20441 if Present (Def) and then Is_Null_Excluding_Def (Def) then
20442 return Is_Non_Null;
20443
20444 else
20445 return Null_Status (Name (Decl));
20446 end if;
20447 end if;
20448 end if;
20449
20450 -- At this point the declaration of the entity does not carry a null
20451 -- exclusion and lacks an initialization expression. Check the status
20452 -- of its type.
20453
20454 return Null_Status_Of_Type (Etype (Id));
20455 end Null_Status_Of_Entity;
20456
20457 -------------------------
20458 -- Null_Status_Of_Type --
20459 -------------------------
20460
20461 function Null_Status_Of_Type (Typ : Entity_Id) return Null_Status_Kind is
20462 Curr : Entity_Id;
20463 Decl : Node_Id;
20464
20465 begin
20466 -- Traverse the type chain looking for types with null exclusion
20467
20468 Curr := Typ;
20469 while Present (Curr) and then Etype (Curr) /= Curr loop
20470 Decl := Parent (Curr);
20471
20472 -- Guard against itypes which do not always have declarations. A
20473 -- type yields a non-null value if it carries a null exclusion.
20474
20475 if Present (Decl) then
20476 if Nkind (Decl) = N_Full_Type_Declaration
20477 and then Is_Null_Excluding_Def (Type_Definition (Decl))
20478 then
20479 return Is_Non_Null;
20480
20481 elsif Nkind (Decl) = N_Subtype_Declaration
20482 and then Null_Exclusion_Present (Decl)
20483 then
20484 return Is_Non_Null;
20485 end if;
20486 end if;
20487
20488 Curr := Etype (Curr);
20489 end loop;
20490
20491 -- The type chain does not contain any null excluding types
20492
20493 return Unknown;
20494 end Null_Status_Of_Type;
20495
20496 -- Start of processing for Null_Status
20497
20498 begin
20499 -- An allocator always creates a non-null value
20500
20501 if Nkind (N) = N_Allocator then
20502 return Is_Non_Null;
20503
20504 -- Taking the 'Access of something yields a non-null value
20505
20506 elsif Nkind (N) = N_Attribute_Reference
20507 and then Nam_In (Attribute_Name (N), Name_Access,
20508 Name_Unchecked_Access,
20509 Name_Unrestricted_Access)
20510 then
20511 return Is_Non_Null;
20512
20513 -- "null" yields null
20514
20515 elsif Nkind (N) = N_Null then
20516 return Is_Null;
20517
20518 -- Check the status of the operand of a type conversion
20519
20520 elsif Nkind (N) = N_Type_Conversion then
20521 return Null_Status (Expression (N));
20522
20523 -- The input denotes a reference to an entity. Determine whether the
20524 -- entity or its type yields a null or non-null value.
20525
20526 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
20527 return Null_Status_Of_Entity (Entity (N));
20528 end if;
20529
20530 -- Otherwise it is not possible to determine the null status of the
20531 -- subexpression at compile time without resorting to simple flow
20532 -- analysis.
20533
20534 return Unknown;
20535 end Null_Status;
20536
20537 --------------------------------------
20538 -- Null_To_Null_Address_Convert_OK --
20539 --------------------------------------
20540
20541 function Null_To_Null_Address_Convert_OK
20542 (N : Node_Id;
20543 Typ : Entity_Id := Empty) return Boolean
20544 is
20545 begin
20546 if not Relaxed_RM_Semantics then
20547 return False;
20548 end if;
20549
20550 if Nkind (N) = N_Null then
20551 return Present (Typ) and then Is_Descendant_Of_Address (Typ);
20552
20553 elsif Nkind_In (N, N_Op_Eq, N_Op_Ge, N_Op_Gt, N_Op_Le, N_Op_Lt, N_Op_Ne)
20554 then
20555 declare
20556 L : constant Node_Id := Left_Opnd (N);
20557 R : constant Node_Id := Right_Opnd (N);
20558
20559 begin
20560 -- We check the Etype of the complementary operand since the
20561 -- N_Null node is not decorated at this stage.
20562
20563 return
20564 ((Nkind (L) = N_Null
20565 and then Is_Descendant_Of_Address (Etype (R)))
20566 or else
20567 (Nkind (R) = N_Null
20568 and then Is_Descendant_Of_Address (Etype (L))));
20569 end;
20570 end if;
20571
20572 return False;
20573 end Null_To_Null_Address_Convert_OK;
20574
20575 ---------------------------------
20576 -- Number_Of_Elements_In_Array --
20577 ---------------------------------
20578
20579 function Number_Of_Elements_In_Array (T : Entity_Id) return Int is
20580 Indx : Node_Id;
20581 Typ : Entity_Id;
20582 Low : Node_Id;
20583 High : Node_Id;
20584 Num : Int := 1;
20585
20586 begin
20587 pragma Assert (Is_Array_Type (T));
20588
20589 Indx := First_Index (T);
20590 while Present (Indx) loop
20591 Typ := Underlying_Type (Etype (Indx));
20592
20593 -- Never look at junk bounds of a generic type
20594
20595 if Is_Generic_Type (Typ) then
20596 return 0;
20597 end if;
20598
20599 -- Check the array bounds are known at compile time and return zero
20600 -- if they are not.
20601
20602 Low := Type_Low_Bound (Typ);
20603 High := Type_High_Bound (Typ);
20604
20605 if not Compile_Time_Known_Value (Low) then
20606 return 0;
20607 elsif not Compile_Time_Known_Value (High) then
20608 return 0;
20609 else
20610 Num :=
20611 Num * UI_To_Int ((Expr_Value (High) - Expr_Value (Low) + 1));
20612 end if;
20613
20614 Next_Index (Indx);
20615 end loop;
20616
20617 return Num;
20618 end Number_Of_Elements_In_Array;
20619
20620 -------------------------
20621 -- Object_Access_Level --
20622 -------------------------
20623
20624 -- Returns the static accessibility level of the view denoted by Obj. Note
20625 -- that the value returned is the result of a call to Scope_Depth. Only
20626 -- scope depths associated with dynamic scopes can actually be returned.
20627 -- Since only relative levels matter for accessibility checking, the fact
20628 -- that the distance between successive levels of accessibility is not
20629 -- always one is immaterial (invariant: if level(E2) is deeper than
20630 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
20631
20632 function Object_Access_Level (Obj : Node_Id) return Uint is
20633 function Is_Interface_Conversion (N : Node_Id) return Boolean;
20634 -- Determine whether N is a construct of the form
20635 -- Some_Type (Operand._tag'Address)
20636 -- This construct appears in the context of dispatching calls.
20637
20638 function Reference_To (Obj : Node_Id) return Node_Id;
20639 -- An explicit dereference is created when removing side effects from
20640 -- expressions for constraint checking purposes. In this case a local
20641 -- access type is created for it. The correct access level is that of
20642 -- the original source node. We detect this case by noting that the
20643 -- prefix of the dereference is created by an object declaration whose
20644 -- initial expression is a reference.
20645
20646 -----------------------------
20647 -- Is_Interface_Conversion --
20648 -----------------------------
20649
20650 function Is_Interface_Conversion (N : Node_Id) return Boolean is
20651 begin
20652 return Nkind (N) = N_Unchecked_Type_Conversion
20653 and then Nkind (Expression (N)) = N_Attribute_Reference
20654 and then Attribute_Name (Expression (N)) = Name_Address;
20655 end Is_Interface_Conversion;
20656
20657 ------------------
20658 -- Reference_To --
20659 ------------------
20660
20661 function Reference_To (Obj : Node_Id) return Node_Id is
20662 Pref : constant Node_Id := Prefix (Obj);
20663 begin
20664 if Is_Entity_Name (Pref)
20665 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
20666 and then Present (Expression (Parent (Entity (Pref))))
20667 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
20668 then
20669 return (Prefix (Expression (Parent (Entity (Pref)))));
20670 else
20671 return Empty;
20672 end if;
20673 end Reference_To;
20674
20675 -- Local variables
20676
20677 E : Entity_Id;
20678
20679 -- Start of processing for Object_Access_Level
20680
20681 begin
20682 if Nkind (Obj) = N_Defining_Identifier
20683 or else Is_Entity_Name (Obj)
20684 then
20685 if Nkind (Obj) = N_Defining_Identifier then
20686 E := Obj;
20687 else
20688 E := Entity (Obj);
20689 end if;
20690
20691 if Is_Prival (E) then
20692 E := Prival_Link (E);
20693 end if;
20694
20695 -- If E is a type then it denotes a current instance. For this case
20696 -- we add one to the normal accessibility level of the type to ensure
20697 -- that current instances are treated as always being deeper than
20698 -- than the level of any visible named access type (see 3.10.2(21)).
20699
20700 if Is_Type (E) then
20701 return Type_Access_Level (E) + 1;
20702
20703 elsif Present (Renamed_Object (E)) then
20704 return Object_Access_Level (Renamed_Object (E));
20705
20706 -- Similarly, if E is a component of the current instance of a
20707 -- protected type, any instance of it is assumed to be at a deeper
20708 -- level than the type. For a protected object (whose type is an
20709 -- anonymous protected type) its components are at the same level
20710 -- as the type itself.
20711
20712 elsif not Is_Overloadable (E)
20713 and then Ekind (Scope (E)) = E_Protected_Type
20714 and then Comes_From_Source (Scope (E))
20715 then
20716 return Type_Access_Level (Scope (E)) + 1;
20717
20718 else
20719 -- Aliased formals of functions take their access level from the
20720 -- point of call, i.e. require a dynamic check. For static check
20721 -- purposes, this is smaller than the level of the subprogram
20722 -- itself. For procedures the aliased makes no difference.
20723
20724 if Is_Formal (E)
20725 and then Is_Aliased (E)
20726 and then Ekind (Scope (E)) = E_Function
20727 then
20728 return Type_Access_Level (Etype (E));
20729
20730 else
20731 return Scope_Depth (Enclosing_Dynamic_Scope (E));
20732 end if;
20733 end if;
20734
20735 elsif Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
20736 if Is_Access_Type (Etype (Prefix (Obj))) then
20737 return Type_Access_Level (Etype (Prefix (Obj)));
20738 else
20739 return Object_Access_Level (Prefix (Obj));
20740 end if;
20741
20742 elsif Nkind (Obj) = N_Explicit_Dereference then
20743
20744 -- If the prefix is a selected access discriminant then we make a
20745 -- recursive call on the prefix, which will in turn check the level
20746 -- of the prefix object of the selected discriminant.
20747
20748 -- In Ada 2012, if the discriminant has implicit dereference and
20749 -- the context is a selected component, treat this as an object of
20750 -- unknown scope (see below). This is necessary in compile-only mode;
20751 -- otherwise expansion will already have transformed the prefix into
20752 -- a temporary.
20753
20754 if Nkind (Prefix (Obj)) = N_Selected_Component
20755 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
20756 and then
20757 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
20758 and then
20759 (not Has_Implicit_Dereference
20760 (Entity (Selector_Name (Prefix (Obj))))
20761 or else Nkind (Parent (Obj)) /= N_Selected_Component)
20762 then
20763 return Object_Access_Level (Prefix (Obj));
20764
20765 -- Detect an interface conversion in the context of a dispatching
20766 -- call. Use the original form of the conversion to find the access
20767 -- level of the operand.
20768
20769 elsif Is_Interface (Etype (Obj))
20770 and then Is_Interface_Conversion (Prefix (Obj))
20771 and then Nkind (Original_Node (Obj)) = N_Type_Conversion
20772 then
20773 return Object_Access_Level (Original_Node (Obj));
20774
20775 elsif not Comes_From_Source (Obj) then
20776 declare
20777 Ref : constant Node_Id := Reference_To (Obj);
20778 begin
20779 if Present (Ref) then
20780 return Object_Access_Level (Ref);
20781 else
20782 return Type_Access_Level (Etype (Prefix (Obj)));
20783 end if;
20784 end;
20785
20786 else
20787 return Type_Access_Level (Etype (Prefix (Obj)));
20788 end if;
20789
20790 elsif Nkind_In (Obj, N_Type_Conversion, N_Unchecked_Type_Conversion) then
20791 return Object_Access_Level (Expression (Obj));
20792
20793 elsif Nkind (Obj) = N_Function_Call then
20794
20795 -- Function results are objects, so we get either the access level of
20796 -- the function or, in the case of an indirect call, the level of the
20797 -- access-to-subprogram type. (This code is used for Ada 95, but it
20798 -- looks wrong, because it seems that we should be checking the level
20799 -- of the call itself, even for Ada 95. However, using the Ada 2005
20800 -- version of the code causes regressions in several tests that are
20801 -- compiled with -gnat95. ???)
20802
20803 if Ada_Version < Ada_2005 then
20804 if Is_Entity_Name (Name (Obj)) then
20805 return Subprogram_Access_Level (Entity (Name (Obj)));
20806 else
20807 return Type_Access_Level (Etype (Prefix (Name (Obj))));
20808 end if;
20809
20810 -- For Ada 2005, the level of the result object of a function call is
20811 -- defined to be the level of the call's innermost enclosing master.
20812 -- We determine that by querying the depth of the innermost enclosing
20813 -- dynamic scope.
20814
20815 else
20816 Return_Master_Scope_Depth_Of_Call : declare
20817 function Innermost_Master_Scope_Depth
20818 (N : Node_Id) return Uint;
20819 -- Returns the scope depth of the given node's innermost
20820 -- enclosing dynamic scope (effectively the accessibility
20821 -- level of the innermost enclosing master).
20822
20823 ----------------------------------
20824 -- Innermost_Master_Scope_Depth --
20825 ----------------------------------
20826
20827 function Innermost_Master_Scope_Depth
20828 (N : Node_Id) return Uint
20829 is
20830 Node_Par : Node_Id := Parent (N);
20831
20832 begin
20833 -- Locate the nearest enclosing node (by traversing Parents)
20834 -- that Defining_Entity can be applied to, and return the
20835 -- depth of that entity's nearest enclosing dynamic scope.
20836
20837 while Present (Node_Par) loop
20838 case Nkind (Node_Par) is
20839 when N_Abstract_Subprogram_Declaration
20840 | N_Block_Statement
20841 | N_Body_Stub
20842 | N_Component_Declaration
20843 | N_Entry_Body
20844 | N_Entry_Declaration
20845 | N_Exception_Declaration
20846 | N_Formal_Object_Declaration
20847 | N_Formal_Package_Declaration
20848 | N_Formal_Subprogram_Declaration
20849 | N_Formal_Type_Declaration
20850 | N_Full_Type_Declaration
20851 | N_Function_Specification
20852 | N_Generic_Declaration
20853 | N_Generic_Instantiation
20854 | N_Implicit_Label_Declaration
20855 | N_Incomplete_Type_Declaration
20856 | N_Loop_Parameter_Specification
20857 | N_Number_Declaration
20858 | N_Object_Declaration
20859 | N_Package_Declaration
20860 | N_Package_Specification
20861 | N_Parameter_Specification
20862 | N_Private_Extension_Declaration
20863 | N_Private_Type_Declaration
20864 | N_Procedure_Specification
20865 | N_Proper_Body
20866 | N_Protected_Type_Declaration
20867 | N_Renaming_Declaration
20868 | N_Single_Protected_Declaration
20869 | N_Single_Task_Declaration
20870 | N_Subprogram_Declaration
20871 | N_Subtype_Declaration
20872 | N_Subunit
20873 | N_Task_Type_Declaration
20874 =>
20875 return Scope_Depth
20876 (Nearest_Dynamic_Scope
20877 (Defining_Entity (Node_Par)));
20878
20879 -- For a return statement within a function, return
20880 -- the depth of the function itself. This is not just
20881 -- a small optimization, but matters when analyzing
20882 -- the expression in an expression function before
20883 -- the body is created.
20884
20885 when N_Simple_Return_Statement =>
20886 if Ekind (Current_Scope) = E_Function then
20887 return Scope_Depth (Current_Scope);
20888 end if;
20889
20890 when others =>
20891 null;
20892 end case;
20893
20894 Node_Par := Parent (Node_Par);
20895 end loop;
20896
20897 pragma Assert (False);
20898
20899 -- Should never reach the following return
20900
20901 return Scope_Depth (Current_Scope) + 1;
20902 end Innermost_Master_Scope_Depth;
20903
20904 -- Start of processing for Return_Master_Scope_Depth_Of_Call
20905
20906 begin
20907 return Innermost_Master_Scope_Depth (Obj);
20908 end Return_Master_Scope_Depth_Of_Call;
20909 end if;
20910
20911 -- For convenience we handle qualified expressions, even though they
20912 -- aren't technically object names.
20913
20914 elsif Nkind (Obj) = N_Qualified_Expression then
20915 return Object_Access_Level (Expression (Obj));
20916
20917 -- Ditto for aggregates. They have the level of the temporary that
20918 -- will hold their value.
20919
20920 elsif Nkind (Obj) = N_Aggregate then
20921 return Object_Access_Level (Current_Scope);
20922
20923 -- Otherwise return the scope level of Standard. (If there are cases
20924 -- that fall through to this point they will be treated as having
20925 -- global accessibility for now. ???)
20926
20927 else
20928 return Scope_Depth (Standard_Standard);
20929 end if;
20930 end Object_Access_Level;
20931
20932 ----------------------------------
20933 -- Old_Requires_Transient_Scope --
20934 ----------------------------------
20935
20936 function Old_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
20937 Typ : constant Entity_Id := Underlying_Type (Id);
20938
20939 begin
20940 -- This is a private type which is not completed yet. This can only
20941 -- happen in a default expression (of a formal parameter or of a
20942 -- record component). Do not expand transient scope in this case.
20943
20944 if No (Typ) then
20945 return False;
20946
20947 -- Do not expand transient scope for non-existent procedure return
20948
20949 elsif Typ = Standard_Void_Type then
20950 return False;
20951
20952 -- Elementary types do not require a transient scope
20953
20954 elsif Is_Elementary_Type (Typ) then
20955 return False;
20956
20957 -- Generally, indefinite subtypes require a transient scope, since the
20958 -- back end cannot generate temporaries, since this is not a valid type
20959 -- for declaring an object. It might be possible to relax this in the
20960 -- future, e.g. by declaring the maximum possible space for the type.
20961
20962 elsif not Is_Definite_Subtype (Typ) then
20963 return True;
20964
20965 -- Functions returning tagged types may dispatch on result so their
20966 -- returned value is allocated on the secondary stack. Controlled
20967 -- type temporaries need finalization.
20968
20969 elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
20970 return True;
20971
20972 -- Record type
20973
20974 elsif Is_Record_Type (Typ) then
20975 declare
20976 Comp : Entity_Id;
20977
20978 begin
20979 Comp := First_Entity (Typ);
20980 while Present (Comp) loop
20981 if Ekind (Comp) = E_Component then
20982
20983 -- ???It's not clear we need a full recursive call to
20984 -- Old_Requires_Transient_Scope here. Note that the
20985 -- following can't happen.
20986
20987 pragma Assert (Is_Definite_Subtype (Etype (Comp)));
20988 pragma Assert (not Has_Controlled_Component (Etype (Comp)));
20989
20990 if Old_Requires_Transient_Scope (Etype (Comp)) then
20991 return True;
20992 end if;
20993 end if;
20994
20995 Next_Entity (Comp);
20996 end loop;
20997 end;
20998
20999 return False;
21000
21001 -- String literal types never require transient scope
21002
21003 elsif Ekind (Typ) = E_String_Literal_Subtype then
21004 return False;
21005
21006 -- Array type. Note that we already know that this is a constrained
21007 -- array, since unconstrained arrays will fail the indefinite test.
21008
21009 elsif Is_Array_Type (Typ) then
21010
21011 -- If component type requires a transient scope, the array does too
21012
21013 if Old_Requires_Transient_Scope (Component_Type (Typ)) then
21014 return True;
21015
21016 -- Otherwise, we only need a transient scope if the size depends on
21017 -- the value of one or more discriminants.
21018
21019 else
21020 return Size_Depends_On_Discriminant (Typ);
21021 end if;
21022
21023 -- All other cases do not require a transient scope
21024
21025 else
21026 pragma Assert (Is_Protected_Type (Typ) or else Is_Task_Type (Typ));
21027 return False;
21028 end if;
21029 end Old_Requires_Transient_Scope;
21030
21031 ---------------------------------
21032 -- Original_Aspect_Pragma_Name --
21033 ---------------------------------
21034
21035 function Original_Aspect_Pragma_Name (N : Node_Id) return Name_Id is
21036 Item : Node_Id;
21037 Item_Nam : Name_Id;
21038
21039 begin
21040 pragma Assert (Nkind_In (N, N_Aspect_Specification, N_Pragma));
21041
21042 Item := N;
21043
21044 -- The pragma was generated to emulate an aspect, use the original
21045 -- aspect specification.
21046
21047 if Nkind (Item) = N_Pragma and then From_Aspect_Specification (Item) then
21048 Item := Corresponding_Aspect (Item);
21049 end if;
21050
21051 -- Retrieve the name of the aspect/pragma. Note that Pre, Pre_Class,
21052 -- Post and Post_Class rewrite their pragma identifier to preserve the
21053 -- original name.
21054 -- ??? this is kludgey
21055
21056 if Nkind (Item) = N_Pragma then
21057 Item_Nam := Chars (Original_Node (Pragma_Identifier (Item)));
21058
21059 else
21060 pragma Assert (Nkind (Item) = N_Aspect_Specification);
21061 Item_Nam := Chars (Identifier (Item));
21062 end if;
21063
21064 -- Deal with 'Class by converting the name to its _XXX form
21065
21066 if Class_Present (Item) then
21067 if Item_Nam = Name_Invariant then
21068 Item_Nam := Name_uInvariant;
21069
21070 elsif Item_Nam = Name_Post then
21071 Item_Nam := Name_uPost;
21072
21073 elsif Item_Nam = Name_Pre then
21074 Item_Nam := Name_uPre;
21075
21076 elsif Nam_In (Item_Nam, Name_Type_Invariant,
21077 Name_Type_Invariant_Class)
21078 then
21079 Item_Nam := Name_uType_Invariant;
21080
21081 -- Nothing to do for other cases (e.g. a Check that derived from
21082 -- Pre_Class and has the flag set). Also we do nothing if the name
21083 -- is already in special _xxx form.
21084
21085 end if;
21086 end if;
21087
21088 return Item_Nam;
21089 end Original_Aspect_Pragma_Name;
21090
21091 --------------------------------------
21092 -- Original_Corresponding_Operation --
21093 --------------------------------------
21094
21095 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
21096 is
21097 Typ : constant Entity_Id := Find_Dispatching_Type (S);
21098
21099 begin
21100 -- If S is an inherited primitive S2 the original corresponding
21101 -- operation of S is the original corresponding operation of S2
21102
21103 if Present (Alias (S))
21104 and then Find_Dispatching_Type (Alias (S)) /= Typ
21105 then
21106 return Original_Corresponding_Operation (Alias (S));
21107
21108 -- If S overrides an inherited subprogram S2 the original corresponding
21109 -- operation of S is the original corresponding operation of S2
21110
21111 elsif Present (Overridden_Operation (S)) then
21112 return Original_Corresponding_Operation (Overridden_Operation (S));
21113
21114 -- otherwise it is S itself
21115
21116 else
21117 return S;
21118 end if;
21119 end Original_Corresponding_Operation;
21120
21121 -------------------
21122 -- Output_Entity --
21123 -------------------
21124
21125 procedure Output_Entity (Id : Entity_Id) is
21126 Scop : Entity_Id;
21127
21128 begin
21129 Scop := Scope (Id);
21130
21131 -- The entity may lack a scope when it is in the process of being
21132 -- analyzed. Use the current scope as an approximation.
21133
21134 if No (Scop) then
21135 Scop := Current_Scope;
21136 end if;
21137
21138 Output_Name (Chars (Id), Scop);
21139 end Output_Entity;
21140
21141 -----------------
21142 -- Output_Name --
21143 -----------------
21144
21145 procedure Output_Name (Nam : Name_Id; Scop : Entity_Id := Current_Scope) is
21146 begin
21147 Write_Str
21148 (Get_Name_String
21149 (Get_Qualified_Name
21150 (Nam => Nam,
21151 Suffix => No_Name,
21152 Scop => Scop)));
21153 Write_Eol;
21154 end Output_Name;
21155
21156 ----------------------
21157 -- Policy_In_Effect --
21158 ----------------------
21159
21160 function Policy_In_Effect (Policy : Name_Id) return Name_Id is
21161 function Policy_In_List (List : Node_Id) return Name_Id;
21162 -- Determine the mode of a policy in a N_Pragma list
21163
21164 --------------------
21165 -- Policy_In_List --
21166 --------------------
21167
21168 function Policy_In_List (List : Node_Id) return Name_Id is
21169 Arg1 : Node_Id;
21170 Arg2 : Node_Id;
21171 Prag : Node_Id;
21172
21173 begin
21174 Prag := List;
21175 while Present (Prag) loop
21176 Arg1 := First (Pragma_Argument_Associations (Prag));
21177 Arg2 := Next (Arg1);
21178
21179 Arg1 := Get_Pragma_Arg (Arg1);
21180 Arg2 := Get_Pragma_Arg (Arg2);
21181
21182 -- The current Check_Policy pragma matches the requested policy or
21183 -- appears in the single argument form (Assertion, policy_id).
21184
21185 if Nam_In (Chars (Arg1), Name_Assertion, Policy) then
21186 return Chars (Arg2);
21187 end if;
21188
21189 Prag := Next_Pragma (Prag);
21190 end loop;
21191
21192 return No_Name;
21193 end Policy_In_List;
21194
21195 -- Local variables
21196
21197 Kind : Name_Id;
21198
21199 -- Start of processing for Policy_In_Effect
21200
21201 begin
21202 if not Is_Valid_Assertion_Kind (Policy) then
21203 raise Program_Error;
21204 end if;
21205
21206 -- Inspect all policy pragmas that appear within scopes (if any)
21207
21208 Kind := Policy_In_List (Check_Policy_List);
21209
21210 -- Inspect all configuration policy pragmas (if any)
21211
21212 if Kind = No_Name then
21213 Kind := Policy_In_List (Check_Policy_List_Config);
21214 end if;
21215
21216 -- The context lacks policy pragmas, determine the mode based on whether
21217 -- assertions are enabled at the configuration level. This ensures that
21218 -- the policy is preserved when analyzing generics.
21219
21220 if Kind = No_Name then
21221 if Assertions_Enabled_Config then
21222 Kind := Name_Check;
21223 else
21224 Kind := Name_Ignore;
21225 end if;
21226 end if;
21227
21228 return Kind;
21229 end Policy_In_Effect;
21230
21231 ----------------------------------
21232 -- Predicate_Tests_On_Arguments --
21233 ----------------------------------
21234
21235 function Predicate_Tests_On_Arguments (Subp : Entity_Id) return Boolean is
21236 begin
21237 -- Always test predicates on indirect call
21238
21239 if Ekind (Subp) = E_Subprogram_Type then
21240 return True;
21241
21242 -- Do not test predicates on call to generated default Finalize, since
21243 -- we are not interested in whether something we are finalizing (and
21244 -- typically destroying) satisfies its predicates.
21245
21246 elsif Chars (Subp) = Name_Finalize
21247 and then not Comes_From_Source (Subp)
21248 then
21249 return False;
21250
21251 -- Do not test predicates on any internally generated routines
21252
21253 elsif Is_Internal_Name (Chars (Subp)) then
21254 return False;
21255
21256 -- Do not test predicates on call to Init_Proc, since if needed the
21257 -- predicate test will occur at some other point.
21258
21259 elsif Is_Init_Proc (Subp) then
21260 return False;
21261
21262 -- Do not test predicates on call to predicate function, since this
21263 -- would cause infinite recursion.
21264
21265 elsif Ekind (Subp) = E_Function
21266 and then (Is_Predicate_Function (Subp)
21267 or else
21268 Is_Predicate_Function_M (Subp))
21269 then
21270 return False;
21271
21272 -- For now, no other exceptions
21273
21274 else
21275 return True;
21276 end if;
21277 end Predicate_Tests_On_Arguments;
21278
21279 -----------------------
21280 -- Private_Component --
21281 -----------------------
21282
21283 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
21284 Ancestor : constant Entity_Id := Base_Type (Type_Id);
21285
21286 function Trace_Components
21287 (T : Entity_Id;
21288 Check : Boolean) return Entity_Id;
21289 -- Recursive function that does the work, and checks against circular
21290 -- definition for each subcomponent type.
21291
21292 ----------------------
21293 -- Trace_Components --
21294 ----------------------
21295
21296 function Trace_Components
21297 (T : Entity_Id;
21298 Check : Boolean) return Entity_Id
21299 is
21300 Btype : constant Entity_Id := Base_Type (T);
21301 Component : Entity_Id;
21302 P : Entity_Id;
21303 Candidate : Entity_Id := Empty;
21304
21305 begin
21306 if Check and then Btype = Ancestor then
21307 Error_Msg_N ("circular type definition", Type_Id);
21308 return Any_Type;
21309 end if;
21310
21311 if Is_Private_Type (Btype) and then not Is_Generic_Type (Btype) then
21312 if Present (Full_View (Btype))
21313 and then Is_Record_Type (Full_View (Btype))
21314 and then not Is_Frozen (Btype)
21315 then
21316 -- To indicate that the ancestor depends on a private type, the
21317 -- current Btype is sufficient. However, to check for circular
21318 -- definition we must recurse on the full view.
21319
21320 Candidate := Trace_Components (Full_View (Btype), True);
21321
21322 if Candidate = Any_Type then
21323 return Any_Type;
21324 else
21325 return Btype;
21326 end if;
21327
21328 else
21329 return Btype;
21330 end if;
21331
21332 elsif Is_Array_Type (Btype) then
21333 return Trace_Components (Component_Type (Btype), True);
21334
21335 elsif Is_Record_Type (Btype) then
21336 Component := First_Entity (Btype);
21337 while Present (Component)
21338 and then Comes_From_Source (Component)
21339 loop
21340 -- Skip anonymous types generated by constrained components
21341
21342 if not Is_Type (Component) then
21343 P := Trace_Components (Etype (Component), True);
21344
21345 if Present (P) then
21346 if P = Any_Type then
21347 return P;
21348 else
21349 Candidate := P;
21350 end if;
21351 end if;
21352 end if;
21353
21354 Next_Entity (Component);
21355 end loop;
21356
21357 return Candidate;
21358
21359 else
21360 return Empty;
21361 end if;
21362 end Trace_Components;
21363
21364 -- Start of processing for Private_Component
21365
21366 begin
21367 return Trace_Components (Type_Id, False);
21368 end Private_Component;
21369
21370 ---------------------------
21371 -- Primitive_Names_Match --
21372 ---------------------------
21373
21374 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
21375 function Non_Internal_Name (E : Entity_Id) return Name_Id;
21376 -- Given an internal name, returns the corresponding non-internal name
21377
21378 ------------------------
21379 -- Non_Internal_Name --
21380 ------------------------
21381
21382 function Non_Internal_Name (E : Entity_Id) return Name_Id is
21383 begin
21384 Get_Name_String (Chars (E));
21385 Name_Len := Name_Len - 1;
21386 return Name_Find;
21387 end Non_Internal_Name;
21388
21389 -- Start of processing for Primitive_Names_Match
21390
21391 begin
21392 pragma Assert (Present (E1) and then Present (E2));
21393
21394 return Chars (E1) = Chars (E2)
21395 or else
21396 (not Is_Internal_Name (Chars (E1))
21397 and then Is_Internal_Name (Chars (E2))
21398 and then Non_Internal_Name (E2) = Chars (E1))
21399 or else
21400 (not Is_Internal_Name (Chars (E2))
21401 and then Is_Internal_Name (Chars (E1))
21402 and then Non_Internal_Name (E1) = Chars (E2))
21403 or else
21404 (Is_Predefined_Dispatching_Operation (E1)
21405 and then Is_Predefined_Dispatching_Operation (E2)
21406 and then Same_TSS (E1, E2))
21407 or else
21408 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
21409 end Primitive_Names_Match;
21410
21411 -----------------------
21412 -- Process_End_Label --
21413 -----------------------
21414
21415 procedure Process_End_Label
21416 (N : Node_Id;
21417 Typ : Character;
21418 Ent : Entity_Id)
21419 is
21420 Loc : Source_Ptr;
21421 Nam : Node_Id;
21422 Scop : Entity_Id;
21423
21424 Label_Ref : Boolean;
21425 -- Set True if reference to end label itself is required
21426
21427 Endl : Node_Id;
21428 -- Gets set to the operator symbol or identifier that references the
21429 -- entity Ent. For the child unit case, this is the identifier from the
21430 -- designator. For other cases, this is simply Endl.
21431
21432 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
21433 -- N is an identifier node that appears as a parent unit reference in
21434 -- the case where Ent is a child unit. This procedure generates an
21435 -- appropriate cross-reference entry. E is the corresponding entity.
21436
21437 -------------------------
21438 -- Generate_Parent_Ref --
21439 -------------------------
21440
21441 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
21442 begin
21443 -- If names do not match, something weird, skip reference
21444
21445 if Chars (E) = Chars (N) then
21446
21447 -- Generate the reference. We do NOT consider this as a reference
21448 -- for unreferenced symbol purposes.
21449
21450 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
21451
21452 if Style_Check then
21453 Style.Check_Identifier (N, E);
21454 end if;
21455 end if;
21456 end Generate_Parent_Ref;
21457
21458 -- Start of processing for Process_End_Label
21459
21460 begin
21461 -- If no node, ignore. This happens in some error situations, and
21462 -- also for some internally generated structures where no end label
21463 -- references are required in any case.
21464
21465 if No (N) then
21466 return;
21467 end if;
21468
21469 -- Nothing to do if no End_Label, happens for internally generated
21470 -- constructs where we don't want an end label reference anyway. Also
21471 -- nothing to do if Endl is a string literal, which means there was
21472 -- some prior error (bad operator symbol)
21473
21474 Endl := End_Label (N);
21475
21476 if No (Endl) or else Nkind (Endl) = N_String_Literal then
21477 return;
21478 end if;
21479
21480 -- Reference node is not in extended main source unit
21481
21482 if not In_Extended_Main_Source_Unit (N) then
21483
21484 -- Generally we do not collect references except for the extended
21485 -- main source unit. The one exception is the 'e' entry for a
21486 -- package spec, where it is useful for a client to have the
21487 -- ending information to define scopes.
21488
21489 if Typ /= 'e' then
21490 return;
21491
21492 else
21493 Label_Ref := False;
21494
21495 -- For this case, we can ignore any parent references, but we
21496 -- need the package name itself for the 'e' entry.
21497
21498 if Nkind (Endl) = N_Designator then
21499 Endl := Identifier (Endl);
21500 end if;
21501 end if;
21502
21503 -- Reference is in extended main source unit
21504
21505 else
21506 Label_Ref := True;
21507
21508 -- For designator, generate references for the parent entries
21509
21510 if Nkind (Endl) = N_Designator then
21511
21512 -- Generate references for the prefix if the END line comes from
21513 -- source (otherwise we do not need these references) We climb the
21514 -- scope stack to find the expected entities.
21515
21516 if Comes_From_Source (Endl) then
21517 Nam := Name (Endl);
21518 Scop := Current_Scope;
21519 while Nkind (Nam) = N_Selected_Component loop
21520 Scop := Scope (Scop);
21521 exit when No (Scop);
21522 Generate_Parent_Ref (Selector_Name (Nam), Scop);
21523 Nam := Prefix (Nam);
21524 end loop;
21525
21526 if Present (Scop) then
21527 Generate_Parent_Ref (Nam, Scope (Scop));
21528 end if;
21529 end if;
21530
21531 Endl := Identifier (Endl);
21532 end if;
21533 end if;
21534
21535 -- If the end label is not for the given entity, then either we have
21536 -- some previous error, or this is a generic instantiation for which
21537 -- we do not need to make a cross-reference in this case anyway. In
21538 -- either case we simply ignore the call.
21539
21540 if Chars (Ent) /= Chars (Endl) then
21541 return;
21542 end if;
21543
21544 -- If label was really there, then generate a normal reference and then
21545 -- adjust the location in the end label to point past the name (which
21546 -- should almost always be the semicolon).
21547
21548 Loc := Sloc (Endl);
21549
21550 if Comes_From_Source (Endl) then
21551
21552 -- If a label reference is required, then do the style check and
21553 -- generate an l-type cross-reference entry for the label
21554
21555 if Label_Ref then
21556 if Style_Check then
21557 Style.Check_Identifier (Endl, Ent);
21558 end if;
21559
21560 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
21561 end if;
21562
21563 -- Set the location to point past the label (normally this will
21564 -- mean the semicolon immediately following the label). This is
21565 -- done for the sake of the 'e' or 't' entry generated below.
21566
21567 Get_Decoded_Name_String (Chars (Endl));
21568 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
21569
21570 else
21571 -- In SPARK mode, no missing label is allowed for packages and
21572 -- subprogram bodies. Detect those cases by testing whether
21573 -- Process_End_Label was called for a body (Typ = 't') or a package.
21574
21575 if Restriction_Check_Required (SPARK_05)
21576 and then (Typ = 't' or else Ekind (Ent) = E_Package)
21577 then
21578 Error_Msg_Node_1 := Endl;
21579 Check_SPARK_05_Restriction
21580 ("`END &` required", Endl, Force => True);
21581 end if;
21582 end if;
21583
21584 -- Now generate the e/t reference
21585
21586 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
21587
21588 -- Restore Sloc, in case modified above, since we have an identifier
21589 -- and the normal Sloc should be left set in the tree.
21590
21591 Set_Sloc (Endl, Loc);
21592 end Process_End_Label;
21593
21594 --------------------------------
21595 -- Propagate_Concurrent_Flags --
21596 --------------------------------
21597
21598 procedure Propagate_Concurrent_Flags
21599 (Typ : Entity_Id;
21600 Comp_Typ : Entity_Id)
21601 is
21602 begin
21603 if Has_Task (Comp_Typ) then
21604 Set_Has_Task (Typ);
21605 end if;
21606
21607 if Has_Protected (Comp_Typ) then
21608 Set_Has_Protected (Typ);
21609 end if;
21610
21611 if Has_Timing_Event (Comp_Typ) then
21612 Set_Has_Timing_Event (Typ);
21613 end if;
21614 end Propagate_Concurrent_Flags;
21615
21616 ------------------------------
21617 -- Propagate_DIC_Attributes --
21618 ------------------------------
21619
21620 procedure Propagate_DIC_Attributes
21621 (Typ : Entity_Id;
21622 From_Typ : Entity_Id)
21623 is
21624 DIC_Proc : Entity_Id;
21625
21626 begin
21627 if Present (Typ) and then Present (From_Typ) then
21628 pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
21629
21630 -- Nothing to do if both the source and the destination denote the
21631 -- same type.
21632
21633 if From_Typ = Typ then
21634 return;
21635 end if;
21636
21637 DIC_Proc := DIC_Procedure (From_Typ);
21638
21639 -- The setting of the attributes is intentionally conservative. This
21640 -- prevents accidental clobbering of enabled attributes.
21641
21642 if Has_Inherited_DIC (From_Typ)
21643 and then not Has_Inherited_DIC (Typ)
21644 then
21645 Set_Has_Inherited_DIC (Typ);
21646 end if;
21647
21648 if Has_Own_DIC (From_Typ) and then not Has_Own_DIC (Typ) then
21649 Set_Has_Own_DIC (Typ);
21650 end if;
21651
21652 if Present (DIC_Proc) and then No (DIC_Procedure (Typ)) then
21653 Set_DIC_Procedure (Typ, DIC_Proc);
21654 end if;
21655 end if;
21656 end Propagate_DIC_Attributes;
21657
21658 ------------------------------------
21659 -- Propagate_Invariant_Attributes --
21660 ------------------------------------
21661
21662 procedure Propagate_Invariant_Attributes
21663 (Typ : Entity_Id;
21664 From_Typ : Entity_Id)
21665 is
21666 Full_IP : Entity_Id;
21667 Part_IP : Entity_Id;
21668
21669 begin
21670 if Present (Typ) and then Present (From_Typ) then
21671 pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
21672
21673 -- Nothing to do if both the source and the destination denote the
21674 -- same type.
21675
21676 if From_Typ = Typ then
21677 return;
21678 end if;
21679
21680 Full_IP := Invariant_Procedure (From_Typ);
21681 Part_IP := Partial_Invariant_Procedure (From_Typ);
21682
21683 -- The setting of the attributes is intentionally conservative. This
21684 -- prevents accidental clobbering of enabled attributes.
21685
21686 if Has_Inheritable_Invariants (From_Typ)
21687 and then not Has_Inheritable_Invariants (Typ)
21688 then
21689 Set_Has_Inheritable_Invariants (Typ, True);
21690 end if;
21691
21692 if Has_Inherited_Invariants (From_Typ)
21693 and then not Has_Inherited_Invariants (Typ)
21694 then
21695 Set_Has_Inherited_Invariants (Typ, True);
21696 end if;
21697
21698 if Has_Own_Invariants (From_Typ)
21699 and then not Has_Own_Invariants (Typ)
21700 then
21701 Set_Has_Own_Invariants (Typ, True);
21702 end if;
21703
21704 if Present (Full_IP) and then No (Invariant_Procedure (Typ)) then
21705 Set_Invariant_Procedure (Typ, Full_IP);
21706 end if;
21707
21708 if Present (Part_IP) and then No (Partial_Invariant_Procedure (Typ))
21709 then
21710 Set_Partial_Invariant_Procedure (Typ, Part_IP);
21711 end if;
21712 end if;
21713 end Propagate_Invariant_Attributes;
21714
21715 ---------------------------------------
21716 -- Record_Possible_Part_Of_Reference --
21717 ---------------------------------------
21718
21719 procedure Record_Possible_Part_Of_Reference
21720 (Var_Id : Entity_Id;
21721 Ref : Node_Id)
21722 is
21723 Encap : constant Entity_Id := Encapsulating_State (Var_Id);
21724 Refs : Elist_Id;
21725
21726 begin
21727 -- The variable is a constituent of a single protected/task type. Such
21728 -- a variable acts as a component of the type and must appear within a
21729 -- specific region (SPARK RM 9.3). Instead of recording the reference,
21730 -- verify its legality now.
21731
21732 if Present (Encap) and then Is_Single_Concurrent_Object (Encap) then
21733 Check_Part_Of_Reference (Var_Id, Ref);
21734
21735 -- The variable is subject to pragma Part_Of and may eventually become a
21736 -- constituent of a single protected/task type. Record the reference to
21737 -- verify its placement when the contract of the variable is analyzed.
21738
21739 elsif Present (Get_Pragma (Var_Id, Pragma_Part_Of)) then
21740 Refs := Part_Of_References (Var_Id);
21741
21742 if No (Refs) then
21743 Refs := New_Elmt_List;
21744 Set_Part_Of_References (Var_Id, Refs);
21745 end if;
21746
21747 Append_Elmt (Ref, Refs);
21748 end if;
21749 end Record_Possible_Part_Of_Reference;
21750
21751 ----------------
21752 -- Referenced --
21753 ----------------
21754
21755 function Referenced (Id : Entity_Id; Expr : Node_Id) return Boolean is
21756 Seen : Boolean := False;
21757
21758 function Is_Reference (N : Node_Id) return Traverse_Result;
21759 -- Determine whether node N denotes a reference to Id. If this is the
21760 -- case, set global flag Seen to True and stop the traversal.
21761
21762 ------------------
21763 -- Is_Reference --
21764 ------------------
21765
21766 function Is_Reference (N : Node_Id) return Traverse_Result is
21767 begin
21768 if Is_Entity_Name (N)
21769 and then Present (Entity (N))
21770 and then Entity (N) = Id
21771 then
21772 Seen := True;
21773 return Abandon;
21774 else
21775 return OK;
21776 end if;
21777 end Is_Reference;
21778
21779 procedure Inspect_Expression is new Traverse_Proc (Is_Reference);
21780
21781 -- Start of processing for Referenced
21782
21783 begin
21784 Inspect_Expression (Expr);
21785 return Seen;
21786 end Referenced;
21787
21788 ------------------------------------
21789 -- References_Generic_Formal_Type --
21790 ------------------------------------
21791
21792 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
21793
21794 function Process (N : Node_Id) return Traverse_Result;
21795 -- Process one node in search for generic formal type
21796
21797 -------------
21798 -- Process --
21799 -------------
21800
21801 function Process (N : Node_Id) return Traverse_Result is
21802 begin
21803 if Nkind (N) in N_Has_Entity then
21804 declare
21805 E : constant Entity_Id := Entity (N);
21806 begin
21807 if Present (E) then
21808 if Is_Generic_Type (E) then
21809 return Abandon;
21810 elsif Present (Etype (E))
21811 and then Is_Generic_Type (Etype (E))
21812 then
21813 return Abandon;
21814 end if;
21815 end if;
21816 end;
21817 end if;
21818
21819 return Atree.OK;
21820 end Process;
21821
21822 function Traverse is new Traverse_Func (Process);
21823 -- Traverse tree to look for generic type
21824
21825 begin
21826 if Inside_A_Generic then
21827 return Traverse (N) = Abandon;
21828 else
21829 return False;
21830 end if;
21831 end References_Generic_Formal_Type;
21832
21833 -------------------
21834 -- Remove_Entity --
21835 -------------------
21836
21837 procedure Remove_Entity (Id : Entity_Id) is
21838 Scop : constant Entity_Id := Scope (Id);
21839 Prev_Id : Entity_Id;
21840
21841 begin
21842 -- Remove the entity from the homonym chain. When the entity is the
21843 -- head of the chain, associate the entry in the name table with its
21844 -- homonym effectively making it the new head of the chain.
21845
21846 if Current_Entity (Id) = Id then
21847 Set_Name_Entity_Id (Chars (Id), Homonym (Id));
21848
21849 -- Otherwise link the previous and next homonyms
21850
21851 else
21852 Prev_Id := Current_Entity (Id);
21853 while Present (Prev_Id) and then Homonym (Prev_Id) /= Id loop
21854 Prev_Id := Homonym (Prev_Id);
21855 end loop;
21856
21857 Set_Homonym (Prev_Id, Homonym (Id));
21858 end if;
21859
21860 -- Remove the entity from the scope entity chain. When the entity is
21861 -- the head of the chain, set the next entity as the new head of the
21862 -- chain.
21863
21864 if First_Entity (Scop) = Id then
21865 Prev_Id := Empty;
21866 Set_First_Entity (Scop, Next_Entity (Id));
21867
21868 -- Otherwise the entity is either in the middle of the chain or it acts
21869 -- as its tail. Traverse and link the previous and next entities.
21870
21871 else
21872 Prev_Id := First_Entity (Scop);
21873 while Present (Prev_Id) and then Next_Entity (Prev_Id) /= Id loop
21874 Next_Entity (Prev_Id);
21875 end loop;
21876
21877 Set_Next_Entity (Prev_Id, Next_Entity (Id));
21878 end if;
21879
21880 -- Handle the case where the entity acts as the tail of the scope entity
21881 -- chain.
21882
21883 if Last_Entity (Scop) = Id then
21884 Set_Last_Entity (Scop, Prev_Id);
21885 end if;
21886 end Remove_Entity;
21887
21888 --------------------
21889 -- Remove_Homonym --
21890 --------------------
21891
21892 procedure Remove_Homonym (E : Entity_Id) is
21893 Prev : Entity_Id := Empty;
21894 H : Entity_Id;
21895
21896 begin
21897 if E = Current_Entity (E) then
21898 if Present (Homonym (E)) then
21899 Set_Current_Entity (Homonym (E));
21900 else
21901 Set_Name_Entity_Id (Chars (E), Empty);
21902 end if;
21903
21904 else
21905 H := Current_Entity (E);
21906 while Present (H) and then H /= E loop
21907 Prev := H;
21908 H := Homonym (H);
21909 end loop;
21910
21911 -- If E is not on the homonym chain, nothing to do
21912
21913 if Present (H) then
21914 Set_Homonym (Prev, Homonym (E));
21915 end if;
21916 end if;
21917 end Remove_Homonym;
21918
21919 ------------------------------
21920 -- Remove_Overloaded_Entity --
21921 ------------------------------
21922
21923 procedure Remove_Overloaded_Entity (Id : Entity_Id) is
21924 procedure Remove_Primitive_Of (Typ : Entity_Id);
21925 -- Remove primitive subprogram Id from the list of primitives that
21926 -- belong to type Typ.
21927
21928 -------------------------
21929 -- Remove_Primitive_Of --
21930 -------------------------
21931
21932 procedure Remove_Primitive_Of (Typ : Entity_Id) is
21933 Prims : Elist_Id;
21934
21935 begin
21936 if Is_Tagged_Type (Typ) then
21937 Prims := Direct_Primitive_Operations (Typ);
21938
21939 if Present (Prims) then
21940 Remove (Prims, Id);
21941 end if;
21942 end if;
21943 end Remove_Primitive_Of;
21944
21945 -- Local variables
21946
21947 Formal : Entity_Id;
21948
21949 -- Start of processing for Remove_Overloaded_Entity
21950
21951 begin
21952 -- Remove the entity from both the homonym and scope chains
21953
21954 Remove_Entity (Id);
21955
21956 -- The entity denotes a primitive subprogram. Remove it from the list of
21957 -- primitives of the associated controlling type.
21958
21959 if Ekind_In (Id, E_Function, E_Procedure) and then Is_Primitive (Id) then
21960 Formal := First_Formal (Id);
21961 while Present (Formal) loop
21962 if Is_Controlling_Formal (Formal) then
21963 Remove_Primitive_Of (Etype (Formal));
21964 exit;
21965 end if;
21966
21967 Next_Formal (Formal);
21968 end loop;
21969
21970 if Ekind (Id) = E_Function and then Has_Controlling_Result (Id) then
21971 Remove_Primitive_Of (Etype (Id));
21972 end if;
21973 end if;
21974 end Remove_Overloaded_Entity;
21975
21976 ---------------------
21977 -- Rep_To_Pos_Flag --
21978 ---------------------
21979
21980 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
21981 begin
21982 return New_Occurrence_Of
21983 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
21984 end Rep_To_Pos_Flag;
21985
21986 --------------------
21987 -- Require_Entity --
21988 --------------------
21989
21990 procedure Require_Entity (N : Node_Id) is
21991 begin
21992 if Is_Entity_Name (N) and then No (Entity (N)) then
21993 if Total_Errors_Detected /= 0 then
21994 Set_Entity (N, Any_Id);
21995 else
21996 raise Program_Error;
21997 end if;
21998 end if;
21999 end Require_Entity;
22000
22001 ------------------------------
22002 -- Requires_Transient_Scope --
22003 ------------------------------
22004
22005 -- A transient scope is required when variable-sized temporaries are
22006 -- allocated on the secondary stack, or when finalization actions must be
22007 -- generated before the next instruction.
22008
22009 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
22010 Old_Result : constant Boolean := Old_Requires_Transient_Scope (Id);
22011
22012 begin
22013 if Debug_Flag_QQ then
22014 return Old_Result;
22015 end if;
22016
22017 declare
22018 New_Result : constant Boolean := New_Requires_Transient_Scope (Id);
22019
22020 begin
22021 -- Assert that we're not putting things on the secondary stack if we
22022 -- didn't before; we are trying to AVOID secondary stack when
22023 -- possible.
22024
22025 if not Old_Result then
22026 pragma Assert (not New_Result);
22027 null;
22028 end if;
22029
22030 if New_Result /= Old_Result then
22031 Results_Differ (Id, Old_Result, New_Result);
22032 end if;
22033
22034 return New_Result;
22035 end;
22036 end Requires_Transient_Scope;
22037
22038 --------------------
22039 -- Results_Differ --
22040 --------------------
22041
22042 procedure Results_Differ
22043 (Id : Entity_Id;
22044 Old_Val : Boolean;
22045 New_Val : Boolean)
22046 is
22047 begin
22048 if False then -- False to disable; True for debugging
22049 Treepr.Print_Tree_Node (Id);
22050
22051 if Old_Val = New_Val then
22052 raise Program_Error;
22053 end if;
22054 end if;
22055 end Results_Differ;
22056
22057 --------------------------
22058 -- Reset_Analyzed_Flags --
22059 --------------------------
22060
22061 procedure Reset_Analyzed_Flags (N : Node_Id) is
22062 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
22063 -- Function used to reset Analyzed flags in tree. Note that we do
22064 -- not reset Analyzed flags in entities, since there is no need to
22065 -- reanalyze entities, and indeed, it is wrong to do so, since it
22066 -- can result in generating auxiliary stuff more than once.
22067
22068 --------------------
22069 -- Clear_Analyzed --
22070 --------------------
22071
22072 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
22073 begin
22074 if Nkind (N) not in N_Entity then
22075 Set_Analyzed (N, False);
22076 end if;
22077
22078 return OK;
22079 end Clear_Analyzed;
22080
22081 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
22082
22083 -- Start of processing for Reset_Analyzed_Flags
22084
22085 begin
22086 Reset_Analyzed (N);
22087 end Reset_Analyzed_Flags;
22088
22089 ------------------------
22090 -- Restore_SPARK_Mode --
22091 ------------------------
22092
22093 procedure Restore_SPARK_Mode
22094 (Mode : SPARK_Mode_Type;
22095 Prag : Node_Id)
22096 is
22097 begin
22098 SPARK_Mode := Mode;
22099 SPARK_Mode_Pragma := Prag;
22100 end Restore_SPARK_Mode;
22101
22102 --------------------------------
22103 -- Returns_Unconstrained_Type --
22104 --------------------------------
22105
22106 function Returns_Unconstrained_Type (Subp : Entity_Id) return Boolean is
22107 begin
22108 return Ekind (Subp) = E_Function
22109 and then not Is_Scalar_Type (Etype (Subp))
22110 and then not Is_Access_Type (Etype (Subp))
22111 and then not Is_Constrained (Etype (Subp));
22112 end Returns_Unconstrained_Type;
22113
22114 ----------------------------
22115 -- Root_Type_Of_Full_View --
22116 ----------------------------
22117
22118 function Root_Type_Of_Full_View (T : Entity_Id) return Entity_Id is
22119 Rtyp : constant Entity_Id := Root_Type (T);
22120
22121 begin
22122 -- The root type of the full view may itself be a private type. Keep
22123 -- looking for the ultimate derivation parent.
22124
22125 if Is_Private_Type (Rtyp) and then Present (Full_View (Rtyp)) then
22126 return Root_Type_Of_Full_View (Full_View (Rtyp));
22127 else
22128 return Rtyp;
22129 end if;
22130 end Root_Type_Of_Full_View;
22131
22132 ---------------------------
22133 -- Safe_To_Capture_Value --
22134 ---------------------------
22135
22136 function Safe_To_Capture_Value
22137 (N : Node_Id;
22138 Ent : Entity_Id;
22139 Cond : Boolean := False) return Boolean
22140 is
22141 begin
22142 -- The only entities for which we track constant values are variables
22143 -- which are not renamings, constants, out parameters, and in out
22144 -- parameters, so check if we have this case.
22145
22146 -- Note: it may seem odd to track constant values for constants, but in
22147 -- fact this routine is used for other purposes than simply capturing
22148 -- the value. In particular, the setting of Known[_Non]_Null.
22149
22150 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
22151 or else
22152 Ekind_In (Ent, E_Constant, E_Out_Parameter, E_In_Out_Parameter)
22153 then
22154 null;
22155
22156 -- For conditionals, we also allow loop parameters and all formals,
22157 -- including in parameters.
22158
22159 elsif Cond and then Ekind_In (Ent, E_Loop_Parameter, E_In_Parameter) then
22160 null;
22161
22162 -- For all other cases, not just unsafe, but impossible to capture
22163 -- Current_Value, since the above are the only entities which have
22164 -- Current_Value fields.
22165
22166 else
22167 return False;
22168 end if;
22169
22170 -- Skip if volatile or aliased, since funny things might be going on in
22171 -- these cases which we cannot necessarily track. Also skip any variable
22172 -- for which an address clause is given, or whose address is taken. Also
22173 -- never capture value of library level variables (an attempt to do so
22174 -- can occur in the case of package elaboration code).
22175
22176 if Treat_As_Volatile (Ent)
22177 or else Is_Aliased (Ent)
22178 or else Present (Address_Clause (Ent))
22179 or else Address_Taken (Ent)
22180 or else (Is_Library_Level_Entity (Ent)
22181 and then Ekind (Ent) = E_Variable)
22182 then
22183 return False;
22184 end if;
22185
22186 -- OK, all above conditions are met. We also require that the scope of
22187 -- the reference be the same as the scope of the entity, not counting
22188 -- packages and blocks and loops.
22189
22190 declare
22191 E_Scope : constant Entity_Id := Scope (Ent);
22192 R_Scope : Entity_Id;
22193
22194 begin
22195 R_Scope := Current_Scope;
22196 while R_Scope /= Standard_Standard loop
22197 exit when R_Scope = E_Scope;
22198
22199 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
22200 return False;
22201 else
22202 R_Scope := Scope (R_Scope);
22203 end if;
22204 end loop;
22205 end;
22206
22207 -- We also require that the reference does not appear in a context
22208 -- where it is not sure to be executed (i.e. a conditional context
22209 -- or an exception handler). We skip this if Cond is True, since the
22210 -- capturing of values from conditional tests handles this ok.
22211
22212 if Cond then
22213 return True;
22214 end if;
22215
22216 declare
22217 Desc : Node_Id;
22218 P : Node_Id;
22219
22220 begin
22221 Desc := N;
22222
22223 -- Seems dubious that case expressions are not handled here ???
22224
22225 P := Parent (N);
22226 while Present (P) loop
22227 if Nkind (P) = N_If_Statement
22228 or else Nkind (P) = N_Case_Statement
22229 or else (Nkind (P) in N_Short_Circuit
22230 and then Desc = Right_Opnd (P))
22231 or else (Nkind (P) = N_If_Expression
22232 and then Desc /= First (Expressions (P)))
22233 or else Nkind (P) = N_Exception_Handler
22234 or else Nkind (P) = N_Selective_Accept
22235 or else Nkind (P) = N_Conditional_Entry_Call
22236 or else Nkind (P) = N_Timed_Entry_Call
22237 or else Nkind (P) = N_Asynchronous_Select
22238 then
22239 return False;
22240
22241 else
22242 Desc := P;
22243 P := Parent (P);
22244
22245 -- A special Ada 2012 case: the original node may be part
22246 -- of the else_actions of a conditional expression, in which
22247 -- case it might not have been expanded yet, and appears in
22248 -- a non-syntactic list of actions. In that case it is clearly
22249 -- not safe to save a value.
22250
22251 if No (P)
22252 and then Is_List_Member (Desc)
22253 and then No (Parent (List_Containing (Desc)))
22254 then
22255 return False;
22256 end if;
22257 end if;
22258 end loop;
22259 end;
22260
22261 -- OK, looks safe to set value
22262
22263 return True;
22264 end Safe_To_Capture_Value;
22265
22266 ---------------
22267 -- Same_Name --
22268 ---------------
22269
22270 function Same_Name (N1, N2 : Node_Id) return Boolean is
22271 K1 : constant Node_Kind := Nkind (N1);
22272 K2 : constant Node_Kind := Nkind (N2);
22273
22274 begin
22275 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
22276 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
22277 then
22278 return Chars (N1) = Chars (N2);
22279
22280 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
22281 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
22282 then
22283 return Same_Name (Selector_Name (N1), Selector_Name (N2))
22284 and then Same_Name (Prefix (N1), Prefix (N2));
22285
22286 else
22287 return False;
22288 end if;
22289 end Same_Name;
22290
22291 -----------------
22292 -- Same_Object --
22293 -----------------
22294
22295 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
22296 N1 : constant Node_Id := Original_Node (Node1);
22297 N2 : constant Node_Id := Original_Node (Node2);
22298 -- We do the tests on original nodes, since we are most interested
22299 -- in the original source, not any expansion that got in the way.
22300
22301 K1 : constant Node_Kind := Nkind (N1);
22302 K2 : constant Node_Kind := Nkind (N2);
22303
22304 begin
22305 -- First case, both are entities with same entity
22306
22307 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
22308 declare
22309 EN1 : constant Entity_Id := Entity (N1);
22310 EN2 : constant Entity_Id := Entity (N2);
22311 begin
22312 if Present (EN1) and then Present (EN2)
22313 and then (Ekind_In (EN1, E_Variable, E_Constant)
22314 or else Is_Formal (EN1))
22315 and then EN1 = EN2
22316 then
22317 return True;
22318 end if;
22319 end;
22320 end if;
22321
22322 -- Second case, selected component with same selector, same record
22323
22324 if K1 = N_Selected_Component
22325 and then K2 = N_Selected_Component
22326 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
22327 then
22328 return Same_Object (Prefix (N1), Prefix (N2));
22329
22330 -- Third case, indexed component with same subscripts, same array
22331
22332 elsif K1 = N_Indexed_Component
22333 and then K2 = N_Indexed_Component
22334 and then Same_Object (Prefix (N1), Prefix (N2))
22335 then
22336 declare
22337 E1, E2 : Node_Id;
22338 begin
22339 E1 := First (Expressions (N1));
22340 E2 := First (Expressions (N2));
22341 while Present (E1) loop
22342 if not Same_Value (E1, E2) then
22343 return False;
22344 else
22345 Next (E1);
22346 Next (E2);
22347 end if;
22348 end loop;
22349
22350 return True;
22351 end;
22352
22353 -- Fourth case, slice of same array with same bounds
22354
22355 elsif K1 = N_Slice
22356 and then K2 = N_Slice
22357 and then Nkind (Discrete_Range (N1)) = N_Range
22358 and then Nkind (Discrete_Range (N2)) = N_Range
22359 and then Same_Value (Low_Bound (Discrete_Range (N1)),
22360 Low_Bound (Discrete_Range (N2)))
22361 and then Same_Value (High_Bound (Discrete_Range (N1)),
22362 High_Bound (Discrete_Range (N2)))
22363 then
22364 return Same_Name (Prefix (N1), Prefix (N2));
22365
22366 -- All other cases, not clearly the same object
22367
22368 else
22369 return False;
22370 end if;
22371 end Same_Object;
22372
22373 ---------------
22374 -- Same_Type --
22375 ---------------
22376
22377 function Same_Type (T1, T2 : Entity_Id) return Boolean is
22378 begin
22379 if T1 = T2 then
22380 return True;
22381
22382 elsif not Is_Constrained (T1)
22383 and then not Is_Constrained (T2)
22384 and then Base_Type (T1) = Base_Type (T2)
22385 then
22386 return True;
22387
22388 -- For now don't bother with case of identical constraints, to be
22389 -- fiddled with later on perhaps (this is only used for optimization
22390 -- purposes, so it is not critical to do a best possible job)
22391
22392 else
22393 return False;
22394 end if;
22395 end Same_Type;
22396
22397 ----------------
22398 -- Same_Value --
22399 ----------------
22400
22401 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
22402 begin
22403 if Compile_Time_Known_Value (Node1)
22404 and then Compile_Time_Known_Value (Node2)
22405 then
22406 -- Handle properly compile-time expressions that are not
22407 -- scalar.
22408
22409 if Is_String_Type (Etype (Node1)) then
22410 return Expr_Value_S (Node1) = Expr_Value_S (Node2);
22411
22412 else
22413 return Expr_Value (Node1) = Expr_Value (Node2);
22414 end if;
22415
22416 elsif Same_Object (Node1, Node2) then
22417 return True;
22418 else
22419 return False;
22420 end if;
22421 end Same_Value;
22422
22423 --------------------
22424 -- Set_SPARK_Mode --
22425 --------------------
22426
22427 procedure Set_SPARK_Mode (Context : Entity_Id) is
22428 begin
22429 -- Do not consider illegal or partially decorated constructs
22430
22431 if Ekind (Context) = E_Void or else Error_Posted (Context) then
22432 null;
22433
22434 elsif Present (SPARK_Pragma (Context)) then
22435 Install_SPARK_Mode
22436 (Mode => Get_SPARK_Mode_From_Annotation (SPARK_Pragma (Context)),
22437 Prag => SPARK_Pragma (Context));
22438 end if;
22439 end Set_SPARK_Mode;
22440
22441 -------------------------
22442 -- Scalar_Part_Present --
22443 -------------------------
22444
22445 function Scalar_Part_Present (T : Entity_Id) return Boolean is
22446 C : Entity_Id;
22447
22448 begin
22449 if Is_Scalar_Type (T) then
22450 return True;
22451
22452 elsif Is_Array_Type (T) then
22453 return Scalar_Part_Present (Component_Type (T));
22454
22455 elsif Is_Record_Type (T) or else Has_Discriminants (T) then
22456 C := First_Component_Or_Discriminant (T);
22457 while Present (C) loop
22458 if Scalar_Part_Present (Etype (C)) then
22459 return True;
22460 else
22461 Next_Component_Or_Discriminant (C);
22462 end if;
22463 end loop;
22464 end if;
22465
22466 return False;
22467 end Scalar_Part_Present;
22468
22469 ------------------------
22470 -- Scope_Is_Transient --
22471 ------------------------
22472
22473 function Scope_Is_Transient return Boolean is
22474 begin
22475 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
22476 end Scope_Is_Transient;
22477
22478 ------------------
22479 -- Scope_Within --
22480 ------------------
22481
22482 function Scope_Within
22483 (Inner : Entity_Id;
22484 Outer : Entity_Id) return Boolean
22485 is
22486 Curr : Entity_Id;
22487
22488 begin
22489 Curr := Inner;
22490 while Present (Curr) and then Curr /= Standard_Standard loop
22491 Curr := Scope (Curr);
22492
22493 if Curr = Outer then
22494 return True;
22495 end if;
22496 end loop;
22497
22498 return False;
22499 end Scope_Within;
22500
22501 --------------------------
22502 -- Scope_Within_Or_Same --
22503 --------------------------
22504
22505 function Scope_Within_Or_Same
22506 (Inner : Entity_Id;
22507 Outer : Entity_Id) return Boolean
22508 is
22509 Curr : Entity_Id;
22510
22511 begin
22512 Curr := Inner;
22513 while Present (Curr) and then Curr /= Standard_Standard loop
22514 if Curr = Outer then
22515 return True;
22516 end if;
22517
22518 Curr := Scope (Curr);
22519 end loop;
22520
22521 return False;
22522 end Scope_Within_Or_Same;
22523
22524 --------------------
22525 -- Set_Convention --
22526 --------------------
22527
22528 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
22529 begin
22530 Basic_Set_Convention (E, Val);
22531
22532 if Is_Type (E)
22533 and then Is_Access_Subprogram_Type (Base_Type (E))
22534 and then Has_Foreign_Convention (E)
22535 then
22536
22537 -- A pragma Convention in an instance may apply to the subtype
22538 -- created for a formal, in which case we have already verified
22539 -- that conventions of actual and formal match and there is nothing
22540 -- to flag on the subtype.
22541
22542 if In_Instance then
22543 null;
22544 else
22545 Set_Can_Use_Internal_Rep (E, False);
22546 end if;
22547 end if;
22548
22549 -- If E is an object, including a component, and the type of E is an
22550 -- anonymous access type with no convention set, then also set the
22551 -- convention of the anonymous access type. We do not do this for
22552 -- anonymous protected types, since protected types always have the
22553 -- default convention.
22554
22555 if Present (Etype (E))
22556 and then (Is_Object (E)
22557
22558 -- Allow E_Void (happens for pragma Convention appearing
22559 -- in the middle of a record applying to a component)
22560
22561 or else Ekind (E) = E_Void)
22562 then
22563 declare
22564 Typ : constant Entity_Id := Etype (E);
22565
22566 begin
22567 if Ekind_In (Typ, E_Anonymous_Access_Type,
22568 E_Anonymous_Access_Subprogram_Type)
22569 and then not Has_Convention_Pragma (Typ)
22570 then
22571 Basic_Set_Convention (Typ, Val);
22572 Set_Has_Convention_Pragma (Typ);
22573
22574 -- And for the access subprogram type, deal similarly with the
22575 -- designated E_Subprogram_Type, which is always internal.
22576
22577 if Ekind (Typ) = E_Anonymous_Access_Subprogram_Type then
22578 declare
22579 Dtype : constant Entity_Id := Designated_Type (Typ);
22580 begin
22581 if Ekind (Dtype) = E_Subprogram_Type
22582 and then not Has_Convention_Pragma (Dtype)
22583 then
22584 Basic_Set_Convention (Dtype, Val);
22585 Set_Has_Convention_Pragma (Dtype);
22586 end if;
22587 end;
22588 end if;
22589 end if;
22590 end;
22591 end if;
22592 end Set_Convention;
22593
22594 ------------------------
22595 -- Set_Current_Entity --
22596 ------------------------
22597
22598 -- The given entity is to be set as the currently visible definition of its
22599 -- associated name (i.e. the Node_Id associated with its name). All we have
22600 -- to do is to get the name from the identifier, and then set the
22601 -- associated Node_Id to point to the given entity.
22602
22603 procedure Set_Current_Entity (E : Entity_Id) is
22604 begin
22605 Set_Name_Entity_Id (Chars (E), E);
22606 end Set_Current_Entity;
22607
22608 ---------------------------
22609 -- Set_Debug_Info_Needed --
22610 ---------------------------
22611
22612 procedure Set_Debug_Info_Needed (T : Entity_Id) is
22613
22614 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
22615 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
22616 -- Used to set debug info in a related node if not set already
22617
22618 --------------------------------------
22619 -- Set_Debug_Info_Needed_If_Not_Set --
22620 --------------------------------------
22621
22622 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
22623 begin
22624 if Present (E) and then not Needs_Debug_Info (E) then
22625 Set_Debug_Info_Needed (E);
22626
22627 -- For a private type, indicate that the full view also needs
22628 -- debug information.
22629
22630 if Is_Type (E)
22631 and then Is_Private_Type (E)
22632 and then Present (Full_View (E))
22633 then
22634 Set_Debug_Info_Needed (Full_View (E));
22635 end if;
22636 end if;
22637 end Set_Debug_Info_Needed_If_Not_Set;
22638
22639 -- Start of processing for Set_Debug_Info_Needed
22640
22641 begin
22642 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
22643 -- indicates that Debug_Info_Needed is never required for the entity.
22644 -- Nothing to do if entity comes from a predefined file. Library files
22645 -- are compiled without debug information, but inlined bodies of these
22646 -- routines may appear in user code, and debug information on them ends
22647 -- up complicating debugging the user code.
22648
22649 if No (T)
22650 or else Debug_Info_Off (T)
22651 then
22652 return;
22653
22654 elsif In_Inlined_Body and then In_Predefined_Unit (T) then
22655 Set_Needs_Debug_Info (T, False);
22656 end if;
22657
22658 -- Set flag in entity itself. Note that we will go through the following
22659 -- circuitry even if the flag is already set on T. That's intentional,
22660 -- it makes sure that the flag will be set in subsidiary entities.
22661
22662 Set_Needs_Debug_Info (T);
22663
22664 -- Set flag on subsidiary entities if not set already
22665
22666 if Is_Object (T) then
22667 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
22668
22669 elsif Is_Type (T) then
22670 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
22671
22672 if Is_Record_Type (T) then
22673 declare
22674 Ent : Entity_Id := First_Entity (T);
22675 begin
22676 while Present (Ent) loop
22677 Set_Debug_Info_Needed_If_Not_Set (Ent);
22678 Next_Entity (Ent);
22679 end loop;
22680 end;
22681
22682 -- For a class wide subtype, we also need debug information
22683 -- for the equivalent type.
22684
22685 if Ekind (T) = E_Class_Wide_Subtype then
22686 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
22687 end if;
22688
22689 elsif Is_Array_Type (T) then
22690 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
22691
22692 declare
22693 Indx : Node_Id := First_Index (T);
22694 begin
22695 while Present (Indx) loop
22696 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
22697 Indx := Next_Index (Indx);
22698 end loop;
22699 end;
22700
22701 -- For a packed array type, we also need debug information for
22702 -- the type used to represent the packed array. Conversely, we
22703 -- also need it for the former if we need it for the latter.
22704
22705 if Is_Packed (T) then
22706 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Impl_Type (T));
22707 end if;
22708
22709 if Is_Packed_Array_Impl_Type (T) then
22710 Set_Debug_Info_Needed_If_Not_Set (Original_Array_Type (T));
22711 end if;
22712
22713 elsif Is_Access_Type (T) then
22714 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
22715
22716 elsif Is_Private_Type (T) then
22717 declare
22718 FV : constant Entity_Id := Full_View (T);
22719
22720 begin
22721 Set_Debug_Info_Needed_If_Not_Set (FV);
22722
22723 -- If the full view is itself a derived private type, we need
22724 -- debug information on its underlying type.
22725
22726 if Present (FV)
22727 and then Is_Private_Type (FV)
22728 and then Present (Underlying_Full_View (FV))
22729 then
22730 Set_Needs_Debug_Info (Underlying_Full_View (FV));
22731 end if;
22732 end;
22733
22734 elsif Is_Protected_Type (T) then
22735 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
22736
22737 elsif Is_Scalar_Type (T) then
22738
22739 -- If the subrange bounds are materialized by dedicated constant
22740 -- objects, also include them in the debug info to make sure the
22741 -- debugger can properly use them.
22742
22743 if Present (Scalar_Range (T))
22744 and then Nkind (Scalar_Range (T)) = N_Range
22745 then
22746 declare
22747 Low_Bnd : constant Node_Id := Type_Low_Bound (T);
22748 High_Bnd : constant Node_Id := Type_High_Bound (T);
22749
22750 begin
22751 if Is_Entity_Name (Low_Bnd) then
22752 Set_Debug_Info_Needed_If_Not_Set (Entity (Low_Bnd));
22753 end if;
22754
22755 if Is_Entity_Name (High_Bnd) then
22756 Set_Debug_Info_Needed_If_Not_Set (Entity (High_Bnd));
22757 end if;
22758 end;
22759 end if;
22760 end if;
22761 end if;
22762 end Set_Debug_Info_Needed;
22763
22764 ----------------------------
22765 -- Set_Entity_With_Checks --
22766 ----------------------------
22767
22768 procedure Set_Entity_With_Checks (N : Node_Id; Val : Entity_Id) is
22769 Val_Actual : Entity_Id;
22770 Nod : Node_Id;
22771 Post_Node : Node_Id;
22772
22773 begin
22774 -- Unconditionally set the entity
22775
22776 Set_Entity (N, Val);
22777
22778 -- The node to post on is the selector in the case of an expanded name,
22779 -- and otherwise the node itself.
22780
22781 if Nkind (N) = N_Expanded_Name then
22782 Post_Node := Selector_Name (N);
22783 else
22784 Post_Node := N;
22785 end if;
22786
22787 -- Check for violation of No_Fixed_IO
22788
22789 if Restriction_Check_Required (No_Fixed_IO)
22790 and then
22791 ((RTU_Loaded (Ada_Text_IO)
22792 and then (Is_RTE (Val, RE_Decimal_IO)
22793 or else
22794 Is_RTE (Val, RE_Fixed_IO)))
22795
22796 or else
22797 (RTU_Loaded (Ada_Wide_Text_IO)
22798 and then (Is_RTE (Val, RO_WT_Decimal_IO)
22799 or else
22800 Is_RTE (Val, RO_WT_Fixed_IO)))
22801
22802 or else
22803 (RTU_Loaded (Ada_Wide_Wide_Text_IO)
22804 and then (Is_RTE (Val, RO_WW_Decimal_IO)
22805 or else
22806 Is_RTE (Val, RO_WW_Fixed_IO))))
22807
22808 -- A special extra check, don't complain about a reference from within
22809 -- the Ada.Interrupts package itself!
22810
22811 and then not In_Same_Extended_Unit (N, Val)
22812 then
22813 Check_Restriction (No_Fixed_IO, Post_Node);
22814 end if;
22815
22816 -- Remaining checks are only done on source nodes. Note that we test
22817 -- for violation of No_Fixed_IO even on non-source nodes, because the
22818 -- cases for checking violations of this restriction are instantiations
22819 -- where the reference in the instance has Comes_From_Source False.
22820
22821 if not Comes_From_Source (N) then
22822 return;
22823 end if;
22824
22825 -- Check for violation of No_Abort_Statements, which is triggered by
22826 -- call to Ada.Task_Identification.Abort_Task.
22827
22828 if Restriction_Check_Required (No_Abort_Statements)
22829 and then (Is_RTE (Val, RE_Abort_Task))
22830
22831 -- A special extra check, don't complain about a reference from within
22832 -- the Ada.Task_Identification package itself!
22833
22834 and then not In_Same_Extended_Unit (N, Val)
22835 then
22836 Check_Restriction (No_Abort_Statements, Post_Node);
22837 end if;
22838
22839 if Val = Standard_Long_Long_Integer then
22840 Check_Restriction (No_Long_Long_Integers, Post_Node);
22841 end if;
22842
22843 -- Check for violation of No_Dynamic_Attachment
22844
22845 if Restriction_Check_Required (No_Dynamic_Attachment)
22846 and then RTU_Loaded (Ada_Interrupts)
22847 and then (Is_RTE (Val, RE_Is_Reserved) or else
22848 Is_RTE (Val, RE_Is_Attached) or else
22849 Is_RTE (Val, RE_Current_Handler) or else
22850 Is_RTE (Val, RE_Attach_Handler) or else
22851 Is_RTE (Val, RE_Exchange_Handler) or else
22852 Is_RTE (Val, RE_Detach_Handler) or else
22853 Is_RTE (Val, RE_Reference))
22854
22855 -- A special extra check, don't complain about a reference from within
22856 -- the Ada.Interrupts package itself!
22857
22858 and then not In_Same_Extended_Unit (N, Val)
22859 then
22860 Check_Restriction (No_Dynamic_Attachment, Post_Node);
22861 end if;
22862
22863 -- Check for No_Implementation_Identifiers
22864
22865 if Restriction_Check_Required (No_Implementation_Identifiers) then
22866
22867 -- We have an implementation defined entity if it is marked as
22868 -- implementation defined, or is defined in a package marked as
22869 -- implementation defined. However, library packages themselves
22870 -- are excluded (we don't want to flag Interfaces itself, just
22871 -- the entities within it).
22872
22873 if (Is_Implementation_Defined (Val)
22874 or else
22875 (Present (Scope (Val))
22876 and then Is_Implementation_Defined (Scope (Val))))
22877 and then not (Ekind_In (Val, E_Package, E_Generic_Package)
22878 and then Is_Library_Level_Entity (Val))
22879 then
22880 Check_Restriction (No_Implementation_Identifiers, Post_Node);
22881 end if;
22882 end if;
22883
22884 -- Do the style check
22885
22886 if Style_Check
22887 and then not Suppress_Style_Checks (Val)
22888 and then not In_Instance
22889 then
22890 if Nkind (N) = N_Identifier then
22891 Nod := N;
22892 elsif Nkind (N) = N_Expanded_Name then
22893 Nod := Selector_Name (N);
22894 else
22895 return;
22896 end if;
22897
22898 -- A special situation arises for derived operations, where we want
22899 -- to do the check against the parent (since the Sloc of the derived
22900 -- operation points to the derived type declaration itself).
22901
22902 Val_Actual := Val;
22903 while not Comes_From_Source (Val_Actual)
22904 and then Nkind (Val_Actual) in N_Entity
22905 and then (Ekind (Val_Actual) = E_Enumeration_Literal
22906 or else Is_Subprogram_Or_Generic_Subprogram (Val_Actual))
22907 and then Present (Alias (Val_Actual))
22908 loop
22909 Val_Actual := Alias (Val_Actual);
22910 end loop;
22911
22912 -- Renaming declarations for generic actuals do not come from source,
22913 -- and have a different name from that of the entity they rename, so
22914 -- there is no style check to perform here.
22915
22916 if Chars (Nod) = Chars (Val_Actual) then
22917 Style.Check_Identifier (Nod, Val_Actual);
22918 end if;
22919 end if;
22920
22921 Set_Entity (N, Val);
22922 end Set_Entity_With_Checks;
22923
22924 ------------------------
22925 -- Set_Name_Entity_Id --
22926 ------------------------
22927
22928 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
22929 begin
22930 Set_Name_Table_Int (Id, Int (Val));
22931 end Set_Name_Entity_Id;
22932
22933 ---------------------
22934 -- Set_Next_Actual --
22935 ---------------------
22936
22937 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
22938 begin
22939 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
22940 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
22941 end if;
22942 end Set_Next_Actual;
22943
22944 ----------------------------------
22945 -- Set_Optimize_Alignment_Flags --
22946 ----------------------------------
22947
22948 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
22949 begin
22950 if Optimize_Alignment = 'S' then
22951 Set_Optimize_Alignment_Space (E);
22952 elsif Optimize_Alignment = 'T' then
22953 Set_Optimize_Alignment_Time (E);
22954 end if;
22955 end Set_Optimize_Alignment_Flags;
22956
22957 -----------------------
22958 -- Set_Public_Status --
22959 -----------------------
22960
22961 procedure Set_Public_Status (Id : Entity_Id) is
22962 S : constant Entity_Id := Current_Scope;
22963
22964 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
22965 -- Determines if E is defined within handled statement sequence or
22966 -- an if statement, returns True if so, False otherwise.
22967
22968 ----------------------
22969 -- Within_HSS_Or_If --
22970 ----------------------
22971
22972 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
22973 N : Node_Id;
22974 begin
22975 N := Declaration_Node (E);
22976 loop
22977 N := Parent (N);
22978
22979 if No (N) then
22980 return False;
22981
22982 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
22983 N_If_Statement)
22984 then
22985 return True;
22986 end if;
22987 end loop;
22988 end Within_HSS_Or_If;
22989
22990 -- Start of processing for Set_Public_Status
22991
22992 begin
22993 -- Everything in the scope of Standard is public
22994
22995 if S = Standard_Standard then
22996 Set_Is_Public (Id);
22997
22998 -- Entity is definitely not public if enclosing scope is not public
22999
23000 elsif not Is_Public (S) then
23001 return;
23002
23003 -- An object or function declaration that occurs in a handled sequence
23004 -- of statements or within an if statement is the declaration for a
23005 -- temporary object or local subprogram generated by the expander. It
23006 -- never needs to be made public and furthermore, making it public can
23007 -- cause back end problems.
23008
23009 elsif Nkind_In (Parent (Id), N_Object_Declaration,
23010 N_Function_Specification)
23011 and then Within_HSS_Or_If (Id)
23012 then
23013 return;
23014
23015 -- Entities in public packages or records are public
23016
23017 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
23018 Set_Is_Public (Id);
23019
23020 -- The bounds of an entry family declaration can generate object
23021 -- declarations that are visible to the back-end, e.g. in the
23022 -- the declaration of a composite type that contains tasks.
23023
23024 elsif Is_Concurrent_Type (S)
23025 and then not Has_Completion (S)
23026 and then Nkind (Parent (Id)) = N_Object_Declaration
23027 then
23028 Set_Is_Public (Id);
23029 end if;
23030 end Set_Public_Status;
23031
23032 -----------------------------
23033 -- Set_Referenced_Modified --
23034 -----------------------------
23035
23036 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
23037 Pref : Node_Id;
23038
23039 begin
23040 -- Deal with indexed or selected component where prefix is modified
23041
23042 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
23043 Pref := Prefix (N);
23044
23045 -- If prefix is access type, then it is the designated object that is
23046 -- being modified, which means we have no entity to set the flag on.
23047
23048 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
23049 return;
23050
23051 -- Otherwise chase the prefix
23052
23053 else
23054 Set_Referenced_Modified (Pref, Out_Param);
23055 end if;
23056
23057 -- Otherwise see if we have an entity name (only other case to process)
23058
23059 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
23060 Set_Referenced_As_LHS (Entity (N), not Out_Param);
23061 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
23062 end if;
23063 end Set_Referenced_Modified;
23064
23065 ------------------
23066 -- Set_Rep_Info --
23067 ------------------
23068
23069 procedure Set_Rep_Info (T1 : Entity_Id; T2 : Entity_Id) is
23070 begin
23071 Set_Is_Atomic (T1, Is_Atomic (T2));
23072 Set_Is_Independent (T1, Is_Independent (T2));
23073 Set_Is_Volatile_Full_Access (T1, Is_Volatile_Full_Access (T2));
23074
23075 if Is_Base_Type (T1) then
23076 Set_Is_Volatile (T1, Is_Volatile (T2));
23077 end if;
23078 end Set_Rep_Info;
23079
23080 ----------------------------
23081 -- Set_Scope_Is_Transient --
23082 ----------------------------
23083
23084 procedure Set_Scope_Is_Transient (V : Boolean := True) is
23085 begin
23086 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
23087 end Set_Scope_Is_Transient;
23088
23089 -------------------
23090 -- Set_Size_Info --
23091 -------------------
23092
23093 procedure Set_Size_Info (T1, T2 : Entity_Id) is
23094 begin
23095 -- We copy Esize, but not RM_Size, since in general RM_Size is
23096 -- subtype specific and does not get inherited by all subtypes.
23097
23098 Set_Esize (T1, Esize (T2));
23099 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
23100
23101 if Is_Discrete_Or_Fixed_Point_Type (T1)
23102 and then
23103 Is_Discrete_Or_Fixed_Point_Type (T2)
23104 then
23105 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
23106 end if;
23107
23108 Set_Alignment (T1, Alignment (T2));
23109 end Set_Size_Info;
23110
23111 ------------------------------
23112 -- Should_Ignore_Pragma_Par --
23113 ------------------------------
23114
23115 function Should_Ignore_Pragma_Par (Prag_Name : Name_Id) return Boolean is
23116 pragma Assert (Compiler_State = Parsing);
23117 -- This one can't work during semantic analysis, because we don't have a
23118 -- correct Current_Source_File.
23119
23120 Result : constant Boolean :=
23121 Get_Name_Table_Boolean3 (Prag_Name)
23122 and then not Is_Internal_File_Name
23123 (File_Name (Current_Source_File));
23124 begin
23125 return Result;
23126 end Should_Ignore_Pragma_Par;
23127
23128 ------------------------------
23129 -- Should_Ignore_Pragma_Sem --
23130 ------------------------------
23131
23132 function Should_Ignore_Pragma_Sem (N : Node_Id) return Boolean is
23133 pragma Assert (Compiler_State = Analyzing);
23134 Prag_Name : constant Name_Id := Pragma_Name (N);
23135 Result : constant Boolean :=
23136 Get_Name_Table_Boolean3 (Prag_Name)
23137 and then not In_Internal_Unit (N);
23138
23139 begin
23140 return Result;
23141 end Should_Ignore_Pragma_Sem;
23142
23143 --------------------
23144 -- Static_Boolean --
23145 --------------------
23146
23147 function Static_Boolean (N : Node_Id) return Uint is
23148 begin
23149 Analyze_And_Resolve (N, Standard_Boolean);
23150
23151 if N = Error
23152 or else Error_Posted (N)
23153 or else Etype (N) = Any_Type
23154 then
23155 return No_Uint;
23156 end if;
23157
23158 if Is_OK_Static_Expression (N) then
23159 if not Raises_Constraint_Error (N) then
23160 return Expr_Value (N);
23161 else
23162 return No_Uint;
23163 end if;
23164
23165 elsif Etype (N) = Any_Type then
23166 return No_Uint;
23167
23168 else
23169 Flag_Non_Static_Expr
23170 ("static boolean expression required here", N);
23171 return No_Uint;
23172 end if;
23173 end Static_Boolean;
23174
23175 --------------------
23176 -- Static_Integer --
23177 --------------------
23178
23179 function Static_Integer (N : Node_Id) return Uint is
23180 begin
23181 Analyze_And_Resolve (N, Any_Integer);
23182
23183 if N = Error
23184 or else Error_Posted (N)
23185 or else Etype (N) = Any_Type
23186 then
23187 return No_Uint;
23188 end if;
23189
23190 if Is_OK_Static_Expression (N) then
23191 if not Raises_Constraint_Error (N) then
23192 return Expr_Value (N);
23193 else
23194 return No_Uint;
23195 end if;
23196
23197 elsif Etype (N) = Any_Type then
23198 return No_Uint;
23199
23200 else
23201 Flag_Non_Static_Expr
23202 ("static integer expression required here", N);
23203 return No_Uint;
23204 end if;
23205 end Static_Integer;
23206
23207 --------------------------
23208 -- Statically_Different --
23209 --------------------------
23210
23211 function Statically_Different (E1, E2 : Node_Id) return Boolean is
23212 R1 : constant Node_Id := Get_Referenced_Object (E1);
23213 R2 : constant Node_Id := Get_Referenced_Object (E2);
23214 begin
23215 return Is_Entity_Name (R1)
23216 and then Is_Entity_Name (R2)
23217 and then Entity (R1) /= Entity (R2)
23218 and then not Is_Formal (Entity (R1))
23219 and then not Is_Formal (Entity (R2));
23220 end Statically_Different;
23221
23222 --------------------------------------
23223 -- Subject_To_Loop_Entry_Attributes --
23224 --------------------------------------
23225
23226 function Subject_To_Loop_Entry_Attributes (N : Node_Id) return Boolean is
23227 Stmt : Node_Id;
23228
23229 begin
23230 Stmt := N;
23231
23232 -- The expansion mechanism transform a loop subject to at least one
23233 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
23234 -- the conditional part.
23235
23236 if Nkind_In (Stmt, N_Block_Statement, N_If_Statement)
23237 and then Nkind (Original_Node (N)) = N_Loop_Statement
23238 then
23239 Stmt := Original_Node (N);
23240 end if;
23241
23242 return
23243 Nkind (Stmt) = N_Loop_Statement
23244 and then Present (Identifier (Stmt))
23245 and then Present (Entity (Identifier (Stmt)))
23246 and then Has_Loop_Entry_Attributes (Entity (Identifier (Stmt)));
23247 end Subject_To_Loop_Entry_Attributes;
23248
23249 -----------------------------
23250 -- Subprogram_Access_Level --
23251 -----------------------------
23252
23253 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
23254 begin
23255 if Present (Alias (Subp)) then
23256 return Subprogram_Access_Level (Alias (Subp));
23257 else
23258 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
23259 end if;
23260 end Subprogram_Access_Level;
23261
23262 ---------------------
23263 -- Subprogram_Name --
23264 ---------------------
23265
23266 function Subprogram_Name (N : Node_Id) return String is
23267 Buf : Bounded_String;
23268 Ent : Node_Id := N;
23269 Nod : Node_Id;
23270
23271 begin
23272 while Present (Ent) loop
23273 case Nkind (Ent) is
23274 when N_Subprogram_Body =>
23275 Ent := Defining_Unit_Name (Specification (Ent));
23276 exit;
23277
23278 when N_Subprogram_Declaration =>
23279 Nod := Corresponding_Body (Ent);
23280
23281 if Present (Nod) then
23282 Ent := Nod;
23283 else
23284 Ent := Defining_Unit_Name (Specification (Ent));
23285 end if;
23286
23287 exit;
23288
23289 when N_Subprogram_Instantiation
23290 | N_Package_Body
23291 | N_Package_Specification
23292 =>
23293 Ent := Defining_Unit_Name (Ent);
23294 exit;
23295
23296 when N_Protected_Type_Declaration =>
23297 Ent := Corresponding_Body (Ent);
23298 exit;
23299
23300 when N_Protected_Body
23301 | N_Task_Body
23302 =>
23303 Ent := Defining_Identifier (Ent);
23304 exit;
23305
23306 when others =>
23307 null;
23308 end case;
23309
23310 Ent := Parent (Ent);
23311 end loop;
23312
23313 if No (Ent) then
23314 return "unknown subprogram:unknown file:0:0";
23315 end if;
23316
23317 -- If the subprogram is a child unit, use its simple name to start the
23318 -- construction of the fully qualified name.
23319
23320 if Nkind (Ent) = N_Defining_Program_Unit_Name then
23321 Ent := Defining_Identifier (Ent);
23322 end if;
23323
23324 Append_Entity_Name (Buf, Ent);
23325
23326 -- Append homonym number if needed
23327
23328 if Nkind (N) in N_Entity and then Has_Homonym (N) then
23329 declare
23330 H : Entity_Id := Homonym (N);
23331 Nr : Nat := 1;
23332 begin
23333 while Present (H) loop
23334 if Scope (H) = Scope (N) then
23335 Nr := Nr + 1;
23336 end if;
23337
23338 H := Homonym (H);
23339 end loop;
23340
23341 if Nr > 1 then
23342 Append (Buf, '#');
23343 Append (Buf, Nr);
23344 end if;
23345 end;
23346 end if;
23347
23348 -- Append source location of Ent to Buf so that the string will
23349 -- look like "subp:file:line:col".
23350
23351 declare
23352 Loc : constant Source_Ptr := Sloc (Ent);
23353 begin
23354 Append (Buf, ':');
23355 Append (Buf, Reference_Name (Get_Source_File_Index (Loc)));
23356 Append (Buf, ':');
23357 Append (Buf, Nat (Get_Logical_Line_Number (Loc)));
23358 Append (Buf, ':');
23359 Append (Buf, Nat (Get_Column_Number (Loc)));
23360 end;
23361
23362 return +Buf;
23363 end Subprogram_Name;
23364
23365 -------------------------------
23366 -- Support_Atomic_Primitives --
23367 -------------------------------
23368
23369 function Support_Atomic_Primitives (Typ : Entity_Id) return Boolean is
23370 Size : Int;
23371
23372 begin
23373 -- Verify the alignment of Typ is known
23374
23375 if not Known_Alignment (Typ) then
23376 return False;
23377 end if;
23378
23379 if Known_Static_Esize (Typ) then
23380 Size := UI_To_Int (Esize (Typ));
23381
23382 -- If the Esize (Object_Size) is unknown at compile time, look at the
23383 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
23384
23385 elsif Known_Static_RM_Size (Typ) then
23386 Size := UI_To_Int (RM_Size (Typ));
23387
23388 -- Otherwise, the size is considered to be unknown.
23389
23390 else
23391 return False;
23392 end if;
23393
23394 -- Check that the size of the component is 8, 16, 32, or 64 bits and
23395 -- that Typ is properly aligned.
23396
23397 case Size is
23398 when 8 | 16 | 32 | 64 =>
23399 return Size = UI_To_Int (Alignment (Typ)) * 8;
23400
23401 when others =>
23402 return False;
23403 end case;
23404 end Support_Atomic_Primitives;
23405
23406 -----------------
23407 -- Trace_Scope --
23408 -----------------
23409
23410 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
23411 begin
23412 if Debug_Flag_W then
23413 for J in 0 .. Scope_Stack.Last loop
23414 Write_Str (" ");
23415 end loop;
23416
23417 Write_Str (Msg);
23418 Write_Name (Chars (E));
23419 Write_Str (" from ");
23420 Write_Location (Sloc (N));
23421 Write_Eol;
23422 end if;
23423 end Trace_Scope;
23424
23425 -----------------------
23426 -- Transfer_Entities --
23427 -----------------------
23428
23429 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
23430 procedure Set_Public_Status_Of (Id : Entity_Id);
23431 -- Set the Is_Public attribute of arbitrary entity Id by calling routine
23432 -- Set_Public_Status. If successful and Id denotes a record type, set
23433 -- the Is_Public attribute of its fields.
23434
23435 --------------------------
23436 -- Set_Public_Status_Of --
23437 --------------------------
23438
23439 procedure Set_Public_Status_Of (Id : Entity_Id) is
23440 Field : Entity_Id;
23441
23442 begin
23443 if not Is_Public (Id) then
23444 Set_Public_Status (Id);
23445
23446 -- When the input entity is a public record type, ensure that all
23447 -- its internal fields are also exposed to the linker. The fields
23448 -- of a class-wide type are never made public.
23449
23450 if Is_Public (Id)
23451 and then Is_Record_Type (Id)
23452 and then not Is_Class_Wide_Type (Id)
23453 then
23454 Field := First_Entity (Id);
23455 while Present (Field) loop
23456 Set_Is_Public (Field);
23457 Next_Entity (Field);
23458 end loop;
23459 end if;
23460 end if;
23461 end Set_Public_Status_Of;
23462
23463 -- Local variables
23464
23465 Full_Id : Entity_Id;
23466 Id : Entity_Id;
23467
23468 -- Start of processing for Transfer_Entities
23469
23470 begin
23471 Id := First_Entity (From);
23472
23473 if Present (Id) then
23474
23475 -- Merge the entity chain of the source scope with that of the
23476 -- destination scope.
23477
23478 if Present (Last_Entity (To)) then
23479 Set_Next_Entity (Last_Entity (To), Id);
23480 else
23481 Set_First_Entity (To, Id);
23482 end if;
23483
23484 Set_Last_Entity (To, Last_Entity (From));
23485
23486 -- Inspect the entities of the source scope and update their Scope
23487 -- attribute.
23488
23489 while Present (Id) loop
23490 Set_Scope (Id, To);
23491 Set_Public_Status_Of (Id);
23492
23493 -- Handle an internally generated full view for a private type
23494
23495 if Is_Private_Type (Id)
23496 and then Present (Full_View (Id))
23497 and then Is_Itype (Full_View (Id))
23498 then
23499 Full_Id := Full_View (Id);
23500
23501 Set_Scope (Full_Id, To);
23502 Set_Public_Status_Of (Full_Id);
23503 end if;
23504
23505 Next_Entity (Id);
23506 end loop;
23507
23508 Set_First_Entity (From, Empty);
23509 Set_Last_Entity (From, Empty);
23510 end if;
23511 end Transfer_Entities;
23512
23513 -----------------------
23514 -- Type_Access_Level --
23515 -----------------------
23516
23517 function Type_Access_Level (Typ : Entity_Id) return Uint is
23518 Btyp : Entity_Id;
23519
23520 begin
23521 Btyp := Base_Type (Typ);
23522
23523 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
23524 -- simply use the level where the type is declared. This is true for
23525 -- stand-alone object declarations, and for anonymous access types
23526 -- associated with components the level is the same as that of the
23527 -- enclosing composite type. However, special treatment is needed for
23528 -- the cases of access parameters, return objects of an anonymous access
23529 -- type, and, in Ada 95, access discriminants of limited types.
23530
23531 if Is_Access_Type (Btyp) then
23532 if Ekind (Btyp) = E_Anonymous_Access_Type then
23533
23534 -- If the type is a nonlocal anonymous access type (such as for
23535 -- an access parameter) we treat it as being declared at the
23536 -- library level to ensure that names such as X.all'access don't
23537 -- fail static accessibility checks.
23538
23539 if not Is_Local_Anonymous_Access (Typ) then
23540 return Scope_Depth (Standard_Standard);
23541
23542 -- If this is a return object, the accessibility level is that of
23543 -- the result subtype of the enclosing function. The test here is
23544 -- little complicated, because we have to account for extended
23545 -- return statements that have been rewritten as blocks, in which
23546 -- case we have to find and the Is_Return_Object attribute of the
23547 -- itype's associated object. It would be nice to find a way to
23548 -- simplify this test, but it doesn't seem worthwhile to add a new
23549 -- flag just for purposes of this test. ???
23550
23551 elsif Ekind (Scope (Btyp)) = E_Return_Statement
23552 or else
23553 (Is_Itype (Btyp)
23554 and then Nkind (Associated_Node_For_Itype (Btyp)) =
23555 N_Object_Declaration
23556 and then Is_Return_Object
23557 (Defining_Identifier
23558 (Associated_Node_For_Itype (Btyp))))
23559 then
23560 declare
23561 Scop : Entity_Id;
23562
23563 begin
23564 Scop := Scope (Scope (Btyp));
23565 while Present (Scop) loop
23566 exit when Ekind (Scop) = E_Function;
23567 Scop := Scope (Scop);
23568 end loop;
23569
23570 -- Treat the return object's type as having the level of the
23571 -- function's result subtype (as per RM05-6.5(5.3/2)).
23572
23573 return Type_Access_Level (Etype (Scop));
23574 end;
23575 end if;
23576 end if;
23577
23578 Btyp := Root_Type (Btyp);
23579
23580 -- The accessibility level of anonymous access types associated with
23581 -- discriminants is that of the current instance of the type, and
23582 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
23583
23584 -- AI-402: access discriminants have accessibility based on the
23585 -- object rather than the type in Ada 2005, so the above paragraph
23586 -- doesn't apply.
23587
23588 -- ??? Needs completion with rules from AI-416
23589
23590 if Ada_Version <= Ada_95
23591 and then Ekind (Typ) = E_Anonymous_Access_Type
23592 and then Present (Associated_Node_For_Itype (Typ))
23593 and then Nkind (Associated_Node_For_Itype (Typ)) =
23594 N_Discriminant_Specification
23595 then
23596 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
23597 end if;
23598 end if;
23599
23600 -- Return library level for a generic formal type. This is done because
23601 -- RM(10.3.2) says that "The statically deeper relationship does not
23602 -- apply to ... a descendant of a generic formal type". Rather than
23603 -- checking at each point where a static accessibility check is
23604 -- performed to see if we are dealing with a formal type, this rule is
23605 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
23606 -- return extreme values for a formal type; Deepest_Type_Access_Level
23607 -- returns Int'Last. By calling the appropriate function from among the
23608 -- two, we ensure that the static accessibility check will pass if we
23609 -- happen to run into a formal type. More specifically, we should call
23610 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
23611 -- call occurs as part of a static accessibility check and the error
23612 -- case is the case where the type's level is too shallow (as opposed
23613 -- to too deep).
23614
23615 if Is_Generic_Type (Root_Type (Btyp)) then
23616 return Scope_Depth (Standard_Standard);
23617 end if;
23618
23619 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
23620 end Type_Access_Level;
23621
23622 ------------------------------------
23623 -- Type_Without_Stream_Operation --
23624 ------------------------------------
23625
23626 function Type_Without_Stream_Operation
23627 (T : Entity_Id;
23628 Op : TSS_Name_Type := TSS_Null) return Entity_Id
23629 is
23630 BT : constant Entity_Id := Base_Type (T);
23631 Op_Missing : Boolean;
23632
23633 begin
23634 if not Restriction_Active (No_Default_Stream_Attributes) then
23635 return Empty;
23636 end if;
23637
23638 if Is_Elementary_Type (T) then
23639 if Op = TSS_Null then
23640 Op_Missing :=
23641 No (TSS (BT, TSS_Stream_Read))
23642 or else No (TSS (BT, TSS_Stream_Write));
23643
23644 else
23645 Op_Missing := No (TSS (BT, Op));
23646 end if;
23647
23648 if Op_Missing then
23649 return T;
23650 else
23651 return Empty;
23652 end if;
23653
23654 elsif Is_Array_Type (T) then
23655 return Type_Without_Stream_Operation (Component_Type (T), Op);
23656
23657 elsif Is_Record_Type (T) then
23658 declare
23659 Comp : Entity_Id;
23660 C_Typ : Entity_Id;
23661
23662 begin
23663 Comp := First_Component (T);
23664 while Present (Comp) loop
23665 C_Typ := Type_Without_Stream_Operation (Etype (Comp), Op);
23666
23667 if Present (C_Typ) then
23668 return C_Typ;
23669 end if;
23670
23671 Next_Component (Comp);
23672 end loop;
23673
23674 return Empty;
23675 end;
23676
23677 elsif Is_Private_Type (T) and then Present (Full_View (T)) then
23678 return Type_Without_Stream_Operation (Full_View (T), Op);
23679 else
23680 return Empty;
23681 end if;
23682 end Type_Without_Stream_Operation;
23683
23684 ----------------------------
23685 -- Unique_Defining_Entity --
23686 ----------------------------
23687
23688 function Unique_Defining_Entity (N : Node_Id) return Entity_Id is
23689 begin
23690 return Unique_Entity (Defining_Entity (N));
23691 end Unique_Defining_Entity;
23692
23693 -------------------
23694 -- Unique_Entity --
23695 -------------------
23696
23697 function Unique_Entity (E : Entity_Id) return Entity_Id is
23698 U : Entity_Id := E;
23699 P : Node_Id;
23700
23701 begin
23702 case Ekind (E) is
23703 when E_Constant =>
23704 if Present (Full_View (E)) then
23705 U := Full_View (E);
23706 end if;
23707
23708 when Entry_Kind =>
23709 if Nkind (Parent (E)) = N_Entry_Body then
23710 declare
23711 Prot_Item : Entity_Id;
23712 Prot_Type : Entity_Id;
23713
23714 begin
23715 if Ekind (E) = E_Entry then
23716 Prot_Type := Scope (E);
23717
23718 -- Bodies of entry families are nested within an extra scope
23719 -- that contains an entry index declaration.
23720
23721 else
23722 Prot_Type := Scope (Scope (E));
23723 end if;
23724
23725 -- A protected type may be declared as a private type, in
23726 -- which case we need to get its full view.
23727
23728 if Is_Private_Type (Prot_Type) then
23729 Prot_Type := Full_View (Prot_Type);
23730 end if;
23731
23732 -- Full view may not be present on error, in which case
23733 -- return E by default.
23734
23735 if Present (Prot_Type) then
23736 pragma Assert (Ekind (Prot_Type) = E_Protected_Type);
23737
23738 -- Traverse the entity list of the protected type and
23739 -- locate an entry declaration which matches the entry
23740 -- body.
23741
23742 Prot_Item := First_Entity (Prot_Type);
23743 while Present (Prot_Item) loop
23744 if Ekind (Prot_Item) in Entry_Kind
23745 and then Corresponding_Body (Parent (Prot_Item)) = E
23746 then
23747 U := Prot_Item;
23748 exit;
23749 end if;
23750
23751 Next_Entity (Prot_Item);
23752 end loop;
23753 end if;
23754 end;
23755 end if;
23756
23757 when Formal_Kind =>
23758 if Present (Spec_Entity (E)) then
23759 U := Spec_Entity (E);
23760 end if;
23761
23762 when E_Package_Body =>
23763 P := Parent (E);
23764
23765 if Nkind (P) = N_Defining_Program_Unit_Name then
23766 P := Parent (P);
23767 end if;
23768
23769 if Nkind (P) = N_Package_Body
23770 and then Present (Corresponding_Spec (P))
23771 then
23772 U := Corresponding_Spec (P);
23773
23774 elsif Nkind (P) = N_Package_Body_Stub
23775 and then Present (Corresponding_Spec_Of_Stub (P))
23776 then
23777 U := Corresponding_Spec_Of_Stub (P);
23778 end if;
23779
23780 when E_Protected_Body =>
23781 P := Parent (E);
23782
23783 if Nkind (P) = N_Protected_Body
23784 and then Present (Corresponding_Spec (P))
23785 then
23786 U := Corresponding_Spec (P);
23787
23788 elsif Nkind (P) = N_Protected_Body_Stub
23789 and then Present (Corresponding_Spec_Of_Stub (P))
23790 then
23791 U := Corresponding_Spec_Of_Stub (P);
23792
23793 if Is_Single_Protected_Object (U) then
23794 U := Etype (U);
23795 end if;
23796 end if;
23797
23798 if Is_Private_Type (U) then
23799 U := Full_View (U);
23800 end if;
23801
23802 when E_Subprogram_Body =>
23803 P := Parent (E);
23804
23805 if Nkind (P) = N_Defining_Program_Unit_Name then
23806 P := Parent (P);
23807 end if;
23808
23809 P := Parent (P);
23810
23811 if Nkind (P) = N_Subprogram_Body
23812 and then Present (Corresponding_Spec (P))
23813 then
23814 U := Corresponding_Spec (P);
23815
23816 elsif Nkind (P) = N_Subprogram_Body_Stub
23817 and then Present (Corresponding_Spec_Of_Stub (P))
23818 then
23819 U := Corresponding_Spec_Of_Stub (P);
23820
23821 elsif Nkind (P) = N_Subprogram_Renaming_Declaration then
23822 U := Corresponding_Spec (P);
23823 end if;
23824
23825 when E_Task_Body =>
23826 P := Parent (E);
23827
23828 if Nkind (P) = N_Task_Body
23829 and then Present (Corresponding_Spec (P))
23830 then
23831 U := Corresponding_Spec (P);
23832
23833 elsif Nkind (P) = N_Task_Body_Stub
23834 and then Present (Corresponding_Spec_Of_Stub (P))
23835 then
23836 U := Corresponding_Spec_Of_Stub (P);
23837
23838 if Is_Single_Task_Object (U) then
23839 U := Etype (U);
23840 end if;
23841 end if;
23842
23843 if Is_Private_Type (U) then
23844 U := Full_View (U);
23845 end if;
23846
23847 when Type_Kind =>
23848 if Present (Full_View (E)) then
23849 U := Full_View (E);
23850 end if;
23851
23852 when others =>
23853 null;
23854 end case;
23855
23856 return U;
23857 end Unique_Entity;
23858
23859 -----------------
23860 -- Unique_Name --
23861 -----------------
23862
23863 function Unique_Name (E : Entity_Id) return String is
23864
23865 -- Names in E_Subprogram_Body or E_Package_Body entities are not
23866 -- reliable, as they may not include the overloading suffix. Instead,
23867 -- when looking for the name of E or one of its enclosing scope, we get
23868 -- the name of the corresponding Unique_Entity.
23869
23870 U : constant Entity_Id := Unique_Entity (E);
23871
23872 function This_Name return String;
23873
23874 ---------------
23875 -- This_Name --
23876 ---------------
23877
23878 function This_Name return String is
23879 begin
23880 return Get_Name_String (Chars (U));
23881 end This_Name;
23882
23883 -- Start of processing for Unique_Name
23884
23885 begin
23886 if E = Standard_Standard
23887 or else Has_Fully_Qualified_Name (E)
23888 then
23889 return This_Name;
23890
23891 elsif Ekind (E) = E_Enumeration_Literal then
23892 return Unique_Name (Etype (E)) & "__" & This_Name;
23893
23894 else
23895 declare
23896 S : constant Entity_Id := Scope (U);
23897 pragma Assert (Present (S));
23898
23899 begin
23900 -- Prefix names of predefined types with standard__, but leave
23901 -- names of user-defined packages and subprograms without prefix
23902 -- (even if technically they are nested in the Standard package).
23903
23904 if S = Standard_Standard then
23905 if Ekind (U) = E_Package or else Is_Subprogram (U) then
23906 return This_Name;
23907 else
23908 return Unique_Name (S) & "__" & This_Name;
23909 end if;
23910
23911 -- For intances of generic subprograms use the name of the related
23912 -- instace and skip the scope of its wrapper package.
23913
23914 elsif Is_Wrapper_Package (S) then
23915 pragma Assert (Scope (S) = Scope (Related_Instance (S)));
23916 -- Wrapper package and the instantiation are in the same scope
23917
23918 declare
23919 Enclosing_Name : constant String :=
23920 Unique_Name (Scope (S)) & "__" &
23921 Get_Name_String (Chars (Related_Instance (S)));
23922
23923 begin
23924 if Is_Subprogram (U)
23925 and then not Is_Generic_Actual_Subprogram (U)
23926 then
23927 return Enclosing_Name;
23928 else
23929 return Enclosing_Name & "__" & This_Name;
23930 end if;
23931 end;
23932
23933 else
23934 return Unique_Name (S) & "__" & This_Name;
23935 end if;
23936 end;
23937 end if;
23938 end Unique_Name;
23939
23940 ---------------------
23941 -- Unit_Is_Visible --
23942 ---------------------
23943
23944 function Unit_Is_Visible (U : Entity_Id) return Boolean is
23945 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
23946 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
23947
23948 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
23949 -- For a child unit, check whether unit appears in a with_clause
23950 -- of a parent.
23951
23952 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
23953 -- Scan the context clause of one compilation unit looking for a
23954 -- with_clause for the unit in question.
23955
23956 ----------------------------
23957 -- Unit_In_Parent_Context --
23958 ----------------------------
23959
23960 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
23961 begin
23962 if Unit_In_Context (Par_Unit) then
23963 return True;
23964
23965 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
23966 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
23967
23968 else
23969 return False;
23970 end if;
23971 end Unit_In_Parent_Context;
23972
23973 ---------------------
23974 -- Unit_In_Context --
23975 ---------------------
23976
23977 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
23978 Clause : Node_Id;
23979
23980 begin
23981 Clause := First (Context_Items (Comp_Unit));
23982 while Present (Clause) loop
23983 if Nkind (Clause) = N_With_Clause then
23984 if Library_Unit (Clause) = U then
23985 return True;
23986
23987 -- The with_clause may denote a renaming of the unit we are
23988 -- looking for, eg. Text_IO which renames Ada.Text_IO.
23989
23990 elsif
23991 Renamed_Entity (Entity (Name (Clause))) =
23992 Defining_Entity (Unit (U))
23993 then
23994 return True;
23995 end if;
23996 end if;
23997
23998 Next (Clause);
23999 end loop;
24000
24001 return False;
24002 end Unit_In_Context;
24003
24004 -- Start of processing for Unit_Is_Visible
24005
24006 begin
24007 -- The currrent unit is directly visible
24008
24009 if Curr = U then
24010 return True;
24011
24012 elsif Unit_In_Context (Curr) then
24013 return True;
24014
24015 -- If the current unit is a body, check the context of the spec
24016
24017 elsif Nkind (Unit (Curr)) = N_Package_Body
24018 or else
24019 (Nkind (Unit (Curr)) = N_Subprogram_Body
24020 and then not Acts_As_Spec (Unit (Curr)))
24021 then
24022 if Unit_In_Context (Library_Unit (Curr)) then
24023 return True;
24024 end if;
24025 end if;
24026
24027 -- If the spec is a child unit, examine the parents
24028
24029 if Is_Child_Unit (Curr_Entity) then
24030 if Nkind (Unit (Curr)) in N_Unit_Body then
24031 return
24032 Unit_In_Parent_Context
24033 (Parent_Spec (Unit (Library_Unit (Curr))));
24034 else
24035 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
24036 end if;
24037
24038 else
24039 return False;
24040 end if;
24041 end Unit_Is_Visible;
24042
24043 ------------------------------
24044 -- Universal_Interpretation --
24045 ------------------------------
24046
24047 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
24048 Index : Interp_Index;
24049 It : Interp;
24050
24051 begin
24052 -- The argument may be a formal parameter of an operator or subprogram
24053 -- with multiple interpretations, or else an expression for an actual.
24054
24055 if Nkind (Opnd) = N_Defining_Identifier
24056 or else not Is_Overloaded (Opnd)
24057 then
24058 if Etype (Opnd) = Universal_Integer
24059 or else Etype (Opnd) = Universal_Real
24060 then
24061 return Etype (Opnd);
24062 else
24063 return Empty;
24064 end if;
24065
24066 else
24067 Get_First_Interp (Opnd, Index, It);
24068 while Present (It.Typ) loop
24069 if It.Typ = Universal_Integer
24070 or else It.Typ = Universal_Real
24071 then
24072 return It.Typ;
24073 end if;
24074
24075 Get_Next_Interp (Index, It);
24076 end loop;
24077
24078 return Empty;
24079 end if;
24080 end Universal_Interpretation;
24081
24082 ---------------
24083 -- Unqualify --
24084 ---------------
24085
24086 function Unqualify (Expr : Node_Id) return Node_Id is
24087 begin
24088 -- Recurse to handle unlikely case of multiple levels of qualification
24089
24090 if Nkind (Expr) = N_Qualified_Expression then
24091 return Unqualify (Expression (Expr));
24092
24093 -- Normal case, not a qualified expression
24094
24095 else
24096 return Expr;
24097 end if;
24098 end Unqualify;
24099
24100 -----------------
24101 -- Unqual_Conv --
24102 -----------------
24103
24104 function Unqual_Conv (Expr : Node_Id) return Node_Id is
24105 begin
24106 -- Recurse to handle unlikely case of multiple levels of qualification
24107 -- and/or conversion.
24108
24109 if Nkind_In (Expr, N_Qualified_Expression,
24110 N_Type_Conversion,
24111 N_Unchecked_Type_Conversion)
24112 then
24113 return Unqual_Conv (Expression (Expr));
24114
24115 -- Normal case, not a qualified expression
24116
24117 else
24118 return Expr;
24119 end if;
24120 end Unqual_Conv;
24121
24122 -----------------------
24123 -- Visible_Ancestors --
24124 -----------------------
24125
24126 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
24127 List_1 : Elist_Id;
24128 List_2 : Elist_Id;
24129 Elmt : Elmt_Id;
24130
24131 begin
24132 pragma Assert (Is_Record_Type (Typ) and then Is_Tagged_Type (Typ));
24133
24134 -- Collect all the parents and progenitors of Typ. If the full-view of
24135 -- private parents and progenitors is available then it is used to
24136 -- generate the list of visible ancestors; otherwise their partial
24137 -- view is added to the resulting list.
24138
24139 Collect_Parents
24140 (T => Typ,
24141 List => List_1,
24142 Use_Full_View => True);
24143
24144 Collect_Interfaces
24145 (T => Typ,
24146 Ifaces_List => List_2,
24147 Exclude_Parents => True,
24148 Use_Full_View => True);
24149
24150 -- Join the two lists. Avoid duplications because an interface may
24151 -- simultaneously be parent and progenitor of a type.
24152
24153 Elmt := First_Elmt (List_2);
24154 while Present (Elmt) loop
24155 Append_Unique_Elmt (Node (Elmt), List_1);
24156 Next_Elmt (Elmt);
24157 end loop;
24158
24159 return List_1;
24160 end Visible_Ancestors;
24161
24162 ----------------------
24163 -- Within_Init_Proc --
24164 ----------------------
24165
24166 function Within_Init_Proc return Boolean is
24167 S : Entity_Id;
24168
24169 begin
24170 S := Current_Scope;
24171 while not Is_Overloadable (S) loop
24172 if S = Standard_Standard then
24173 return False;
24174 else
24175 S := Scope (S);
24176 end if;
24177 end loop;
24178
24179 return Is_Init_Proc (S);
24180 end Within_Init_Proc;
24181
24182 ---------------------------
24183 -- Within_Protected_Type --
24184 ---------------------------
24185
24186 function Within_Protected_Type (E : Entity_Id) return Boolean is
24187 Scop : Entity_Id := Scope (E);
24188
24189 begin
24190 while Present (Scop) loop
24191 if Ekind (Scop) = E_Protected_Type then
24192 return True;
24193 end if;
24194
24195 Scop := Scope (Scop);
24196 end loop;
24197
24198 return False;
24199 end Within_Protected_Type;
24200
24201 ------------------
24202 -- Within_Scope --
24203 ------------------
24204
24205 function Within_Scope (E : Entity_Id; S : Entity_Id) return Boolean is
24206 begin
24207 return Scope_Within_Or_Same (Scope (E), S);
24208 end Within_Scope;
24209
24210 ----------------------------
24211 -- Within_Subprogram_Call --
24212 ----------------------------
24213
24214 function Within_Subprogram_Call (N : Node_Id) return Boolean is
24215 Par : Node_Id;
24216
24217 begin
24218 -- Climb the parent chain looking for a function or procedure call
24219
24220 Par := N;
24221 while Present (Par) loop
24222 if Nkind_In (Par, N_Entry_Call_Statement,
24223 N_Function_Call,
24224 N_Procedure_Call_Statement)
24225 then
24226 return True;
24227
24228 -- Prevent the search from going too far
24229
24230 elsif Is_Body_Or_Package_Declaration (Par) then
24231 exit;
24232 end if;
24233
24234 Par := Parent (Par);
24235 end loop;
24236
24237 return False;
24238 end Within_Subprogram_Call;
24239
24240 ----------------
24241 -- Wrong_Type --
24242 ----------------
24243
24244 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
24245 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
24246 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
24247
24248 Matching_Field : Entity_Id;
24249 -- Entity to give a more precise suggestion on how to write a one-
24250 -- element positional aggregate.
24251
24252 function Has_One_Matching_Field return Boolean;
24253 -- Determines if Expec_Type is a record type with a single component or
24254 -- discriminant whose type matches the found type or is one dimensional
24255 -- array whose component type matches the found type. In the case of
24256 -- one discriminant, we ignore the variant parts. That's not accurate,
24257 -- but good enough for the warning.
24258
24259 ----------------------------
24260 -- Has_One_Matching_Field --
24261 ----------------------------
24262
24263 function Has_One_Matching_Field return Boolean is
24264 E : Entity_Id;
24265
24266 begin
24267 Matching_Field := Empty;
24268
24269 if Is_Array_Type (Expec_Type)
24270 and then Number_Dimensions (Expec_Type) = 1
24271 and then Covers (Etype (Component_Type (Expec_Type)), Found_Type)
24272 then
24273 -- Use type name if available. This excludes multidimensional
24274 -- arrays and anonymous arrays.
24275
24276 if Comes_From_Source (Expec_Type) then
24277 Matching_Field := Expec_Type;
24278
24279 -- For an assignment, use name of target
24280
24281 elsif Nkind (Parent (Expr)) = N_Assignment_Statement
24282 and then Is_Entity_Name (Name (Parent (Expr)))
24283 then
24284 Matching_Field := Entity (Name (Parent (Expr)));
24285 end if;
24286
24287 return True;
24288
24289 elsif not Is_Record_Type (Expec_Type) then
24290 return False;
24291
24292 else
24293 E := First_Entity (Expec_Type);
24294 loop
24295 if No (E) then
24296 return False;
24297
24298 elsif not Ekind_In (E, E_Discriminant, E_Component)
24299 or else Nam_In (Chars (E), Name_uTag, Name_uParent)
24300 then
24301 Next_Entity (E);
24302
24303 else
24304 exit;
24305 end if;
24306 end loop;
24307
24308 if not Covers (Etype (E), Found_Type) then
24309 return False;
24310
24311 elsif Present (Next_Entity (E))
24312 and then (Ekind (E) = E_Component
24313 or else Ekind (Next_Entity (E)) = E_Discriminant)
24314 then
24315 return False;
24316
24317 else
24318 Matching_Field := E;
24319 return True;
24320 end if;
24321 end if;
24322 end Has_One_Matching_Field;
24323
24324 -- Start of processing for Wrong_Type
24325
24326 begin
24327 -- Don't output message if either type is Any_Type, or if a message
24328 -- has already been posted for this node. We need to do the latter
24329 -- check explicitly (it is ordinarily done in Errout), because we
24330 -- are using ! to force the output of the error messages.
24331
24332 if Expec_Type = Any_Type
24333 or else Found_Type = Any_Type
24334 or else Error_Posted (Expr)
24335 then
24336 return;
24337
24338 -- If one of the types is a Taft-Amendment type and the other it its
24339 -- completion, it must be an illegal use of a TAT in the spec, for
24340 -- which an error was already emitted. Avoid cascaded errors.
24341
24342 elsif Is_Incomplete_Type (Expec_Type)
24343 and then Has_Completion_In_Body (Expec_Type)
24344 and then Full_View (Expec_Type) = Etype (Expr)
24345 then
24346 return;
24347
24348 elsif Is_Incomplete_Type (Etype (Expr))
24349 and then Has_Completion_In_Body (Etype (Expr))
24350 and then Full_View (Etype (Expr)) = Expec_Type
24351 then
24352 return;
24353
24354 -- In an instance, there is an ongoing problem with completion of
24355 -- type derived from private types. Their structure is what Gigi
24356 -- expects, but the Etype is the parent type rather than the
24357 -- derived private type itself. Do not flag error in this case. The
24358 -- private completion is an entity without a parent, like an Itype.
24359 -- Similarly, full and partial views may be incorrect in the instance.
24360 -- There is no simple way to insure that it is consistent ???
24361
24362 -- A similar view discrepancy can happen in an inlined body, for the
24363 -- same reason: inserted body may be outside of the original package
24364 -- and only partial views are visible at the point of insertion.
24365
24366 elsif In_Instance or else In_Inlined_Body then
24367 if Etype (Etype (Expr)) = Etype (Expected_Type)
24368 and then
24369 (Has_Private_Declaration (Expected_Type)
24370 or else Has_Private_Declaration (Etype (Expr)))
24371 and then No (Parent (Expected_Type))
24372 then
24373 return;
24374
24375 elsif Nkind (Parent (Expr)) = N_Qualified_Expression
24376 and then Entity (Subtype_Mark (Parent (Expr))) = Expected_Type
24377 then
24378 return;
24379
24380 elsif Is_Private_Type (Expected_Type)
24381 and then Present (Full_View (Expected_Type))
24382 and then Covers (Full_View (Expected_Type), Etype (Expr))
24383 then
24384 return;
24385
24386 -- Conversely, type of expression may be the private one
24387
24388 elsif Is_Private_Type (Base_Type (Etype (Expr)))
24389 and then Full_View (Base_Type (Etype (Expr))) = Expected_Type
24390 then
24391 return;
24392 end if;
24393 end if;
24394
24395 -- An interesting special check. If the expression is parenthesized
24396 -- and its type corresponds to the type of the sole component of the
24397 -- expected record type, or to the component type of the expected one
24398 -- dimensional array type, then assume we have a bad aggregate attempt.
24399
24400 if Nkind (Expr) in N_Subexpr
24401 and then Paren_Count (Expr) /= 0
24402 and then Has_One_Matching_Field
24403 then
24404 Error_Msg_N ("positional aggregate cannot have one component", Expr);
24405
24406 if Present (Matching_Field) then
24407 if Is_Array_Type (Expec_Type) then
24408 Error_Msg_NE
24409 ("\write instead `&''First ='> ...`", Expr, Matching_Field);
24410 else
24411 Error_Msg_NE
24412 ("\write instead `& ='> ...`", Expr, Matching_Field);
24413 end if;
24414 end if;
24415
24416 -- Another special check, if we are looking for a pool-specific access
24417 -- type and we found an E_Access_Attribute_Type, then we have the case
24418 -- of an Access attribute being used in a context which needs a pool-
24419 -- specific type, which is never allowed. The one extra check we make
24420 -- is that the expected designated type covers the Found_Type.
24421
24422 elsif Is_Access_Type (Expec_Type)
24423 and then Ekind (Found_Type) = E_Access_Attribute_Type
24424 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
24425 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
24426 and then Covers
24427 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
24428 then
24429 Error_Msg_N -- CODEFIX
24430 ("result must be general access type!", Expr);
24431 Error_Msg_NE -- CODEFIX
24432 ("add ALL to }!", Expr, Expec_Type);
24433
24434 -- Another special check, if the expected type is an integer type,
24435 -- but the expression is of type System.Address, and the parent is
24436 -- an addition or subtraction operation whose left operand is the
24437 -- expression in question and whose right operand is of an integral
24438 -- type, then this is an attempt at address arithmetic, so give
24439 -- appropriate message.
24440
24441 elsif Is_Integer_Type (Expec_Type)
24442 and then Is_RTE (Found_Type, RE_Address)
24443 and then Nkind_In (Parent (Expr), N_Op_Add, N_Op_Subtract)
24444 and then Expr = Left_Opnd (Parent (Expr))
24445 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
24446 then
24447 Error_Msg_N
24448 ("address arithmetic not predefined in package System",
24449 Parent (Expr));
24450 Error_Msg_N
24451 ("\possible missing with/use of System.Storage_Elements",
24452 Parent (Expr));
24453 return;
24454
24455 -- If the expected type is an anonymous access type, as for access
24456 -- parameters and discriminants, the error is on the designated types.
24457
24458 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
24459 if Comes_From_Source (Expec_Type) then
24460 Error_Msg_NE ("expected}!", Expr, Expec_Type);
24461 else
24462 Error_Msg_NE
24463 ("expected an access type with designated}",
24464 Expr, Designated_Type (Expec_Type));
24465 end if;
24466
24467 if Is_Access_Type (Found_Type)
24468 and then not Comes_From_Source (Found_Type)
24469 then
24470 Error_Msg_NE
24471 ("\\found an access type with designated}!",
24472 Expr, Designated_Type (Found_Type));
24473 else
24474 if From_Limited_With (Found_Type) then
24475 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
24476 Error_Msg_Qual_Level := 99;
24477 Error_Msg_NE -- CODEFIX
24478 ("\\missing `WITH &;", Expr, Scope (Found_Type));
24479 Error_Msg_Qual_Level := 0;
24480 else
24481 Error_Msg_NE ("found}!", Expr, Found_Type);
24482 end if;
24483 end if;
24484
24485 -- Normal case of one type found, some other type expected
24486
24487 else
24488 -- If the names of the two types are the same, see if some number
24489 -- of levels of qualification will help. Don't try more than three
24490 -- levels, and if we get to standard, it's no use (and probably
24491 -- represents an error in the compiler) Also do not bother with
24492 -- internal scope names.
24493
24494 declare
24495 Expec_Scope : Entity_Id;
24496 Found_Scope : Entity_Id;
24497
24498 begin
24499 Expec_Scope := Expec_Type;
24500 Found_Scope := Found_Type;
24501
24502 for Levels in Nat range 0 .. 3 loop
24503 if Chars (Expec_Scope) /= Chars (Found_Scope) then
24504 Error_Msg_Qual_Level := Levels;
24505 exit;
24506 end if;
24507
24508 Expec_Scope := Scope (Expec_Scope);
24509 Found_Scope := Scope (Found_Scope);
24510
24511 exit when Expec_Scope = Standard_Standard
24512 or else Found_Scope = Standard_Standard
24513 or else not Comes_From_Source (Expec_Scope)
24514 or else not Comes_From_Source (Found_Scope);
24515 end loop;
24516 end;
24517
24518 if Is_Record_Type (Expec_Type)
24519 and then Present (Corresponding_Remote_Type (Expec_Type))
24520 then
24521 Error_Msg_NE ("expected}!", Expr,
24522 Corresponding_Remote_Type (Expec_Type));
24523 else
24524 Error_Msg_NE ("expected}!", Expr, Expec_Type);
24525 end if;
24526
24527 if Is_Entity_Name (Expr)
24528 and then Is_Package_Or_Generic_Package (Entity (Expr))
24529 then
24530 Error_Msg_N ("\\found package name!", Expr);
24531
24532 elsif Is_Entity_Name (Expr)
24533 and then Ekind_In (Entity (Expr), E_Procedure, E_Generic_Procedure)
24534 then
24535 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
24536 Error_Msg_N
24537 ("found procedure name, possibly missing Access attribute!",
24538 Expr);
24539 else
24540 Error_Msg_N
24541 ("\\found procedure name instead of function!", Expr);
24542 end if;
24543
24544 elsif Nkind (Expr) = N_Function_Call
24545 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
24546 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
24547 and then No (Parameter_Associations (Expr))
24548 then
24549 Error_Msg_N
24550 ("found function name, possibly missing Access attribute!",
24551 Expr);
24552
24553 -- Catch common error: a prefix or infix operator which is not
24554 -- directly visible because the type isn't.
24555
24556 elsif Nkind (Expr) in N_Op
24557 and then Is_Overloaded (Expr)
24558 and then not Is_Immediately_Visible (Expec_Type)
24559 and then not Is_Potentially_Use_Visible (Expec_Type)
24560 and then not In_Use (Expec_Type)
24561 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
24562 then
24563 Error_Msg_N
24564 ("operator of the type is not directly visible!", Expr);
24565
24566 elsif Ekind (Found_Type) = E_Void
24567 and then Present (Parent (Found_Type))
24568 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
24569 then
24570 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
24571
24572 else
24573 Error_Msg_NE ("\\found}!", Expr, Found_Type);
24574 end if;
24575
24576 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
24577 -- of the same modular type, and (M1 and M2) = 0 was intended.
24578
24579 if Expec_Type = Standard_Boolean
24580 and then Is_Modular_Integer_Type (Found_Type)
24581 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
24582 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
24583 then
24584 declare
24585 Op : constant Node_Id := Right_Opnd (Parent (Expr));
24586 L : constant Node_Id := Left_Opnd (Op);
24587 R : constant Node_Id := Right_Opnd (Op);
24588
24589 begin
24590 -- The case for the message is when the left operand of the
24591 -- comparison is the same modular type, or when it is an
24592 -- integer literal (or other universal integer expression),
24593 -- which would have been typed as the modular type if the
24594 -- parens had been there.
24595
24596 if (Etype (L) = Found_Type
24597 or else
24598 Etype (L) = Universal_Integer)
24599 and then Is_Integer_Type (Etype (R))
24600 then
24601 Error_Msg_N
24602 ("\\possible missing parens for modular operation", Expr);
24603 end if;
24604 end;
24605 end if;
24606
24607 -- Reset error message qualification indication
24608
24609 Error_Msg_Qual_Level := 0;
24610 end if;
24611 end Wrong_Type;
24612
24613 --------------------------------
24614 -- Yields_Synchronized_Object --
24615 --------------------------------
24616
24617 function Yields_Synchronized_Object (Typ : Entity_Id) return Boolean is
24618 Has_Sync_Comp : Boolean := False;
24619 Id : Entity_Id;
24620
24621 begin
24622 -- An array type yields a synchronized object if its component type
24623 -- yields a synchronized object.
24624
24625 if Is_Array_Type (Typ) then
24626 return Yields_Synchronized_Object (Component_Type (Typ));
24627
24628 -- A descendant of type Ada.Synchronous_Task_Control.Suspension_Object
24629 -- yields a synchronized object by default.
24630
24631 elsif Is_Descendant_Of_Suspension_Object (Typ) then
24632 return True;
24633
24634 -- A protected type yields a synchronized object by default
24635
24636 elsif Is_Protected_Type (Typ) then
24637 return True;
24638
24639 -- A record type or type extension yields a synchronized object when its
24640 -- discriminants (if any) lack default values and all components are of
24641 -- a type that yelds a synchronized object.
24642
24643 elsif Is_Record_Type (Typ) then
24644
24645 -- Inspect all entities defined in the scope of the type, looking for
24646 -- components of a type that does not yeld a synchronized object or
24647 -- for discriminants with default values.
24648
24649 Id := First_Entity (Typ);
24650 while Present (Id) loop
24651 if Comes_From_Source (Id) then
24652 if Ekind (Id) = E_Component then
24653 if Yields_Synchronized_Object (Etype (Id)) then
24654 Has_Sync_Comp := True;
24655
24656 -- The component does not yield a synchronized object
24657
24658 else
24659 return False;
24660 end if;
24661
24662 elsif Ekind (Id) = E_Discriminant
24663 and then Present (Expression (Parent (Id)))
24664 then
24665 return False;
24666 end if;
24667 end if;
24668
24669 Next_Entity (Id);
24670 end loop;
24671
24672 -- Ensure that the parent type of a type extension yields a
24673 -- synchronized object.
24674
24675 if Etype (Typ) /= Typ
24676 and then not Yields_Synchronized_Object (Etype (Typ))
24677 then
24678 return False;
24679 end if;
24680
24681 -- If we get here, then all discriminants lack default values and all
24682 -- components are of a type that yields a synchronized object.
24683
24684 return Has_Sync_Comp;
24685
24686 -- A synchronized interface type yields a synchronized object by default
24687
24688 elsif Is_Synchronized_Interface (Typ) then
24689 return True;
24690
24691 -- A task type yelds a synchronized object by default
24692
24693 elsif Is_Task_Type (Typ) then
24694 return True;
24695
24696 -- Otherwise the type does not yield a synchronized object
24697
24698 else
24699 return False;
24700 end if;
24701 end Yields_Synchronized_Object;
24702
24703 ---------------------------
24704 -- Yields_Universal_Type --
24705 ---------------------------
24706
24707 function Yields_Universal_Type (N : Node_Id) return Boolean is
24708 begin
24709 -- Integer and real literals are of a universal type
24710
24711 if Nkind_In (N, N_Integer_Literal, N_Real_Literal) then
24712 return True;
24713
24714 -- The values of certain attributes are of a universal type
24715
24716 elsif Nkind (N) = N_Attribute_Reference then
24717 return
24718 Universal_Type_Attribute (Get_Attribute_Id (Attribute_Name (N)));
24719
24720 -- ??? There are possibly other cases to consider
24721
24722 else
24723 return False;
24724 end if;
24725 end Yields_Universal_Type;
24726
24727 begin
24728 Erroutc.Subprogram_Name_Ptr := Subprogram_Name'Access;
24729 end Sem_Util;
This page took 1.000584 seconds and 6 git commands to generate.