54ac0a416152f487cc3e7b89003332ae0c028916
[gcc.git] / gcc / ada / sem_util.adb
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S E M _ U T I L --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2019, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
25
26 with Treepr; -- ???For debugging code below
27
28 with Aspects; use Aspects;
29 with Casing; use Casing;
30 with Checks; use Checks;
31 with Debug; use Debug;
32 with Elists; use Elists;
33 with Errout; use Errout;
34 with Erroutc; use Erroutc;
35 with Exp_Ch11; use Exp_Ch11;
36 with Exp_Util; use Exp_Util;
37 with Fname; use Fname;
38 with Freeze; use Freeze;
39 with Lib; use Lib;
40 with Lib.Xref; use Lib.Xref;
41 with Namet.Sp; use Namet.Sp;
42 with Nlists; use Nlists;
43 with Nmake; use Nmake;
44 with Output; use Output;
45 with Restrict; use Restrict;
46 with Rident; use Rident;
47 with Rtsfind; use Rtsfind;
48 with Sem; use Sem;
49 with Sem_Aux; use Sem_Aux;
50 with Sem_Attr; use Sem_Attr;
51 with Sem_Ch6; use Sem_Ch6;
52 with Sem_Ch8; use Sem_Ch8;
53 with Sem_Disp; use Sem_Disp;
54 with Sem_Elab; use Sem_Elab;
55 with Sem_Eval; use Sem_Eval;
56 with Sem_Prag; use Sem_Prag;
57 with Sem_Res; use Sem_Res;
58 with Sem_Warn; use Sem_Warn;
59 with Sem_Type; use Sem_Type;
60 with Sinfo; use Sinfo;
61 with Sinput; use Sinput;
62 with Stand; use Stand;
63 with Style;
64 with Stringt; use Stringt;
65 with Targparm; use Targparm;
66 with Tbuild; use Tbuild;
67 with Ttypes; use Ttypes;
68 with Uname; use Uname;
69
70 with GNAT.HTable; use GNAT.HTable;
71
72 package body Sem_Util is
73
74 ---------------------------
75 -- Local Data Structures --
76 ---------------------------
77
78 Invalid_Binder_Values : array (Scalar_Id) of Entity_Id := (others => Empty);
79 -- A collection to hold the entities of the variables declared in package
80 -- System.Scalar_Values which describe the invalid values of scalar types.
81
82 Invalid_Binder_Values_Set : Boolean := False;
83 -- This flag prevents multiple attempts to initialize Invalid_Binder_Values
84
85 Invalid_Floats : array (Float_Scalar_Id) of Ureal := (others => No_Ureal);
86 -- A collection to hold the invalid values of float types as specified by
87 -- pragma Initialize_Scalars.
88
89 Invalid_Integers : array (Integer_Scalar_Id) of Uint := (others => No_Uint);
90 -- A collection to hold the invalid values of integer types as specified
91 -- by pragma Initialize_Scalars.
92
93 -----------------------
94 -- Local Subprograms --
95 -----------------------
96
97 function Build_Component_Subtype
98 (C : List_Id;
99 Loc : Source_Ptr;
100 T : Entity_Id) return Node_Id;
101 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
102 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
103 -- Loc is the source location, T is the original subtype.
104
105 procedure Examine_Array_Bounds
106 (Typ : Entity_Id;
107 All_Static : out Boolean;
108 Has_Empty : out Boolean);
109 -- Inspect the index constraints of array type Typ. Flag All_Static is set
110 -- when all ranges are static. Flag Has_Empty is set only when All_Static
111 -- is set and indicates that at least one range is empty.
112
113 function Has_Enabled_Property
114 (Item_Id : Entity_Id;
115 Property : Name_Id) return Boolean;
116 -- Subsidiary to routines Async_xxx_Enabled and Effective_xxx_Enabled.
117 -- Determine whether an abstract state or a variable denoted by entity
118 -- Item_Id has enabled property Property.
119
120 function Has_Null_Extension (T : Entity_Id) return Boolean;
121 -- T is a derived tagged type. Check whether the type extension is null.
122 -- If the parent type is fully initialized, T can be treated as such.
123
124 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
125 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
126 -- with discriminants whose default values are static, examine only the
127 -- components in the selected variant to determine whether all of them
128 -- have a default.
129
130 type Null_Status_Kind is
131 (Is_Null,
132 -- This value indicates that a subexpression is known to have a null
133 -- value at compile time.
134
135 Is_Non_Null,
136 -- This value indicates that a subexpression is known to have a non-null
137 -- value at compile time.
138
139 Unknown);
140 -- This value indicates that it cannot be determined at compile time
141 -- whether a subexpression yields a null or non-null value.
142
143 function Null_Status (N : Node_Id) return Null_Status_Kind;
144 -- Determine whether subexpression N of an access type yields a null value,
145 -- a non-null value, or the value cannot be determined at compile time. The
146 -- routine does not take simple flow diagnostics into account, it relies on
147 -- static facts such as the presence of null exclusions.
148
149 function Old_Requires_Transient_Scope (Id : Entity_Id) return Boolean;
150 function New_Requires_Transient_Scope (Id : Entity_Id) return Boolean;
151 -- ???We retain the old and new algorithms for Requires_Transient_Scope for
152 -- the time being. New_Requires_Transient_Scope is used by default; the
153 -- debug switch -gnatdQ can be used to do Old_Requires_Transient_Scope
154 -- instead. The intent is to use this temporarily to measure before/after
155 -- efficiency. Note: when this temporary code is removed, the documentation
156 -- of dQ in debug.adb should be removed.
157
158 procedure Results_Differ
159 (Id : Entity_Id;
160 Old_Val : Boolean;
161 New_Val : Boolean);
162 -- ???Debugging code. Called when the Old_Val and New_Val differ. This
163 -- routine will be removed eventially when New_Requires_Transient_Scope
164 -- becomes Requires_Transient_Scope and Old_Requires_Transient_Scope is
165 -- eliminated.
166
167 function Subprogram_Name (N : Node_Id) return String;
168 -- Return the fully qualified name of the enclosing subprogram for the
169 -- given node N, with file:line:col information appended, e.g.
170 -- "subp:file:line:col", corresponding to the source location of the
171 -- body of the subprogram.
172
173 ------------------------------
174 -- Abstract_Interface_List --
175 ------------------------------
176
177 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
178 Nod : Node_Id;
179
180 begin
181 if Is_Concurrent_Type (Typ) then
182
183 -- If we are dealing with a synchronized subtype, go to the base
184 -- type, whose declaration has the interface list.
185
186 Nod := Declaration_Node (Base_Type (Typ));
187
188 if Nkind_In (Nod, N_Full_Type_Declaration,
189 N_Private_Type_Declaration)
190 then
191 return Empty_List;
192 end if;
193
194 elsif Ekind (Typ) = E_Record_Type_With_Private then
195 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
196 Nod := Type_Definition (Parent (Typ));
197
198 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
199 if Present (Full_View (Typ))
200 and then
201 Nkind (Parent (Full_View (Typ))) = N_Full_Type_Declaration
202 then
203 Nod := Type_Definition (Parent (Full_View (Typ)));
204
205 -- If the full-view is not available we cannot do anything else
206 -- here (the source has errors).
207
208 else
209 return Empty_List;
210 end if;
211
212 -- Support for generic formals with interfaces is still missing ???
213
214 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
215 return Empty_List;
216
217 else
218 pragma Assert
219 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
220 Nod := Parent (Typ);
221 end if;
222
223 elsif Ekind (Typ) = E_Record_Subtype then
224 Nod := Type_Definition (Parent (Etype (Typ)));
225
226 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
227
228 -- Recurse, because parent may still be a private extension. Also
229 -- note that the full view of the subtype or the full view of its
230 -- base type may (both) be unavailable.
231
232 return Abstract_Interface_List (Etype (Typ));
233
234 elsif Ekind (Typ) = E_Record_Type then
235 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
236 Nod := Formal_Type_Definition (Parent (Typ));
237 else
238 Nod := Type_Definition (Parent (Typ));
239 end if;
240
241 -- Otherwise the type is of a kind which does not implement interfaces
242
243 else
244 return Empty_List;
245 end if;
246
247 return Interface_List (Nod);
248 end Abstract_Interface_List;
249
250 --------------------------------
251 -- Add_Access_Type_To_Process --
252 --------------------------------
253
254 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
255 L : Elist_Id;
256
257 begin
258 Ensure_Freeze_Node (E);
259 L := Access_Types_To_Process (Freeze_Node (E));
260
261 if No (L) then
262 L := New_Elmt_List;
263 Set_Access_Types_To_Process (Freeze_Node (E), L);
264 end if;
265
266 Append_Elmt (A, L);
267 end Add_Access_Type_To_Process;
268
269 --------------------------
270 -- Add_Block_Identifier --
271 --------------------------
272
273 procedure Add_Block_Identifier (N : Node_Id; Id : out Entity_Id) is
274 Loc : constant Source_Ptr := Sloc (N);
275
276 begin
277 pragma Assert (Nkind (N) = N_Block_Statement);
278
279 -- The block already has a label, return its entity
280
281 if Present (Identifier (N)) then
282 Id := Entity (Identifier (N));
283
284 -- Create a new block label and set its attributes
285
286 else
287 Id := New_Internal_Entity (E_Block, Current_Scope, Loc, 'B');
288 Set_Etype (Id, Standard_Void_Type);
289 Set_Parent (Id, N);
290
291 Set_Identifier (N, New_Occurrence_Of (Id, Loc));
292 Set_Block_Node (Id, Identifier (N));
293 end if;
294 end Add_Block_Identifier;
295
296 ----------------------------
297 -- Add_Global_Declaration --
298 ----------------------------
299
300 procedure Add_Global_Declaration (N : Node_Id) is
301 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
302
303 begin
304 if No (Declarations (Aux_Node)) then
305 Set_Declarations (Aux_Node, New_List);
306 end if;
307
308 Append_To (Declarations (Aux_Node), N);
309 Analyze (N);
310 end Add_Global_Declaration;
311
312 --------------------------------
313 -- Address_Integer_Convert_OK --
314 --------------------------------
315
316 function Address_Integer_Convert_OK (T1, T2 : Entity_Id) return Boolean is
317 begin
318 if Allow_Integer_Address
319 and then ((Is_Descendant_Of_Address (T1)
320 and then Is_Private_Type (T1)
321 and then Is_Integer_Type (T2))
322 or else
323 (Is_Descendant_Of_Address (T2)
324 and then Is_Private_Type (T2)
325 and then Is_Integer_Type (T1)))
326 then
327 return True;
328 else
329 return False;
330 end if;
331 end Address_Integer_Convert_OK;
332
333 -------------------
334 -- Address_Value --
335 -------------------
336
337 function Address_Value (N : Node_Id) return Node_Id is
338 Expr : Node_Id := N;
339
340 begin
341 loop
342 -- For constant, get constant expression
343
344 if Is_Entity_Name (Expr)
345 and then Ekind (Entity (Expr)) = E_Constant
346 then
347 Expr := Constant_Value (Entity (Expr));
348
349 -- For unchecked conversion, get result to convert
350
351 elsif Nkind (Expr) = N_Unchecked_Type_Conversion then
352 Expr := Expression (Expr);
353
354 -- For (common case) of To_Address call, get argument
355
356 elsif Nkind (Expr) = N_Function_Call
357 and then Is_Entity_Name (Name (Expr))
358 and then Is_RTE (Entity (Name (Expr)), RE_To_Address)
359 then
360 Expr := First (Parameter_Associations (Expr));
361
362 if Nkind (Expr) = N_Parameter_Association then
363 Expr := Explicit_Actual_Parameter (Expr);
364 end if;
365
366 -- We finally have the real expression
367
368 else
369 exit;
370 end if;
371 end loop;
372
373 return Expr;
374 end Address_Value;
375
376 -----------------
377 -- Addressable --
378 -----------------
379
380 -- For now, just 8/16/32/64
381
382 function Addressable (V : Uint) return Boolean is
383 begin
384 return V = Uint_8 or else
385 V = Uint_16 or else
386 V = Uint_32 or else
387 V = Uint_64;
388 end Addressable;
389
390 function Addressable (V : Int) return Boolean is
391 begin
392 return V = 8 or else
393 V = 16 or else
394 V = 32 or else
395 V = 64;
396 end Addressable;
397
398 ---------------------------------
399 -- Aggregate_Constraint_Checks --
400 ---------------------------------
401
402 procedure Aggregate_Constraint_Checks
403 (Exp : Node_Id;
404 Check_Typ : Entity_Id)
405 is
406 Exp_Typ : constant Entity_Id := Etype (Exp);
407
408 begin
409 if Raises_Constraint_Error (Exp) then
410 return;
411 end if;
412
413 -- Ada 2005 (AI-230): Generate a conversion to an anonymous access
414 -- component's type to force the appropriate accessibility checks.
415
416 -- Ada 2005 (AI-231): Generate conversion to the null-excluding type to
417 -- force the corresponding run-time check
418
419 if Is_Access_Type (Check_Typ)
420 and then Is_Local_Anonymous_Access (Check_Typ)
421 then
422 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
423 Analyze_And_Resolve (Exp, Check_Typ);
424 Check_Unset_Reference (Exp);
425 end if;
426
427 -- What follows is really expansion activity, so check that expansion
428 -- is on and is allowed. In GNATprove mode, we also want check flags to
429 -- be added in the tree, so that the formal verification can rely on
430 -- those to be present. In GNATprove mode for formal verification, some
431 -- treatment typically only done during expansion needs to be performed
432 -- on the tree, but it should not be applied inside generics. Otherwise,
433 -- this breaks the name resolution mechanism for generic instances.
434
435 if not Expander_Active
436 and (Inside_A_Generic or not Full_Analysis or not GNATprove_Mode)
437 then
438 return;
439 end if;
440
441 if Is_Access_Type (Check_Typ)
442 and then Can_Never_Be_Null (Check_Typ)
443 and then not Can_Never_Be_Null (Exp_Typ)
444 then
445 Install_Null_Excluding_Check (Exp);
446 end if;
447
448 -- First check if we have to insert discriminant checks
449
450 if Has_Discriminants (Exp_Typ) then
451 Apply_Discriminant_Check (Exp, Check_Typ);
452
453 -- Next emit length checks for array aggregates
454
455 elsif Is_Array_Type (Exp_Typ) then
456 Apply_Length_Check (Exp, Check_Typ);
457
458 -- Finally emit scalar and string checks. If we are dealing with a
459 -- scalar literal we need to check by hand because the Etype of
460 -- literals is not necessarily correct.
461
462 elsif Is_Scalar_Type (Exp_Typ)
463 and then Compile_Time_Known_Value (Exp)
464 then
465 if Is_Out_Of_Range (Exp, Base_Type (Check_Typ)) then
466 Apply_Compile_Time_Constraint_Error
467 (Exp, "value not in range of}??", CE_Range_Check_Failed,
468 Ent => Base_Type (Check_Typ),
469 Typ => Base_Type (Check_Typ));
470
471 elsif Is_Out_Of_Range (Exp, Check_Typ) then
472 Apply_Compile_Time_Constraint_Error
473 (Exp, "value not in range of}??", CE_Range_Check_Failed,
474 Ent => Check_Typ,
475 Typ => Check_Typ);
476
477 elsif not Range_Checks_Suppressed (Check_Typ) then
478 Apply_Scalar_Range_Check (Exp, Check_Typ);
479 end if;
480
481 -- Verify that target type is also scalar, to prevent view anomalies
482 -- in instantiations.
483
484 elsif (Is_Scalar_Type (Exp_Typ)
485 or else Nkind (Exp) = N_String_Literal)
486 and then Is_Scalar_Type (Check_Typ)
487 and then Exp_Typ /= Check_Typ
488 then
489 if Is_Entity_Name (Exp)
490 and then Ekind (Entity (Exp)) = E_Constant
491 then
492 -- If expression is a constant, it is worthwhile checking whether
493 -- it is a bound of the type.
494
495 if (Is_Entity_Name (Type_Low_Bound (Check_Typ))
496 and then Entity (Exp) = Entity (Type_Low_Bound (Check_Typ)))
497 or else
498 (Is_Entity_Name (Type_High_Bound (Check_Typ))
499 and then Entity (Exp) = Entity (Type_High_Bound (Check_Typ)))
500 then
501 return;
502
503 else
504 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
505 Analyze_And_Resolve (Exp, Check_Typ);
506 Check_Unset_Reference (Exp);
507 end if;
508
509 -- Could use a comment on this case ???
510
511 else
512 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
513 Analyze_And_Resolve (Exp, Check_Typ);
514 Check_Unset_Reference (Exp);
515 end if;
516
517 end if;
518 end Aggregate_Constraint_Checks;
519
520 -----------------------
521 -- Alignment_In_Bits --
522 -----------------------
523
524 function Alignment_In_Bits (E : Entity_Id) return Uint is
525 begin
526 return Alignment (E) * System_Storage_Unit;
527 end Alignment_In_Bits;
528
529 --------------------------------------
530 -- All_Composite_Constraints_Static --
531 --------------------------------------
532
533 function All_Composite_Constraints_Static
534 (Constr : Node_Id) return Boolean
535 is
536 begin
537 if No (Constr) or else Error_Posted (Constr) then
538 return True;
539 end if;
540
541 case Nkind (Constr) is
542 when N_Subexpr =>
543 if Nkind (Constr) in N_Has_Entity
544 and then Present (Entity (Constr))
545 then
546 if Is_Type (Entity (Constr)) then
547 return
548 not Is_Discrete_Type (Entity (Constr))
549 or else Is_OK_Static_Subtype (Entity (Constr));
550 end if;
551
552 elsif Nkind (Constr) = N_Range then
553 return
554 Is_OK_Static_Expression (Low_Bound (Constr))
555 and then
556 Is_OK_Static_Expression (High_Bound (Constr));
557
558 elsif Nkind (Constr) = N_Attribute_Reference
559 and then Attribute_Name (Constr) = Name_Range
560 then
561 return
562 Is_OK_Static_Expression
563 (Type_Low_Bound (Etype (Prefix (Constr))))
564 and then
565 Is_OK_Static_Expression
566 (Type_High_Bound (Etype (Prefix (Constr))));
567 end if;
568
569 return
570 not Present (Etype (Constr)) -- previous error
571 or else not Is_Discrete_Type (Etype (Constr))
572 or else Is_OK_Static_Expression (Constr);
573
574 when N_Discriminant_Association =>
575 return All_Composite_Constraints_Static (Expression (Constr));
576
577 when N_Range_Constraint =>
578 return
579 All_Composite_Constraints_Static (Range_Expression (Constr));
580
581 when N_Index_Or_Discriminant_Constraint =>
582 declare
583 One_Cstr : Entity_Id;
584 begin
585 One_Cstr := First (Constraints (Constr));
586 while Present (One_Cstr) loop
587 if not All_Composite_Constraints_Static (One_Cstr) then
588 return False;
589 end if;
590
591 Next (One_Cstr);
592 end loop;
593 end;
594
595 return True;
596
597 when N_Subtype_Indication =>
598 return
599 All_Composite_Constraints_Static (Subtype_Mark (Constr))
600 and then
601 All_Composite_Constraints_Static (Constraint (Constr));
602
603 when others =>
604 raise Program_Error;
605 end case;
606 end All_Composite_Constraints_Static;
607
608 ------------------------
609 -- Append_Entity_Name --
610 ------------------------
611
612 procedure Append_Entity_Name (Buf : in out Bounded_String; E : Entity_Id) is
613 Temp : Bounded_String;
614
615 procedure Inner (E : Entity_Id);
616 -- Inner recursive routine, keep outer routine nonrecursive to ease
617 -- debugging when we get strange results from this routine.
618
619 -----------
620 -- Inner --
621 -----------
622
623 procedure Inner (E : Entity_Id) is
624 Scop : Node_Id;
625
626 begin
627 -- If entity has an internal name, skip by it, and print its scope.
628 -- Note that we strip a final R from the name before the test; this
629 -- is needed for some cases of instantiations.
630
631 declare
632 E_Name : Bounded_String;
633
634 begin
635 Append (E_Name, Chars (E));
636
637 if E_Name.Chars (E_Name.Length) = 'R' then
638 E_Name.Length := E_Name.Length - 1;
639 end if;
640
641 if Is_Internal_Name (E_Name) then
642 Inner (Scope (E));
643 return;
644 end if;
645 end;
646
647 Scop := Scope (E);
648
649 -- Just print entity name if its scope is at the outer level
650
651 if Scop = Standard_Standard then
652 null;
653
654 -- If scope comes from source, write scope and entity
655
656 elsif Comes_From_Source (Scop) then
657 Append_Entity_Name (Temp, Scop);
658 Append (Temp, '.');
659
660 -- If in wrapper package skip past it
661
662 elsif Present (Scop) and then Is_Wrapper_Package (Scop) then
663 Append_Entity_Name (Temp, Scope (Scop));
664 Append (Temp, '.');
665
666 -- Otherwise nothing to output (happens in unnamed block statements)
667
668 else
669 null;
670 end if;
671
672 -- Output the name
673
674 declare
675 E_Name : Bounded_String;
676
677 begin
678 Append_Unqualified_Decoded (E_Name, Chars (E));
679
680 -- Remove trailing upper-case letters from the name (useful for
681 -- dealing with some cases of internal names generated in the case
682 -- of references from within a generic).
683
684 while E_Name.Length > 1
685 and then E_Name.Chars (E_Name.Length) in 'A' .. 'Z'
686 loop
687 E_Name.Length := E_Name.Length - 1;
688 end loop;
689
690 -- Adjust casing appropriately (gets name from source if possible)
691
692 Adjust_Name_Case (E_Name, Sloc (E));
693 Append (Temp, E_Name);
694 end;
695 end Inner;
696
697 -- Start of processing for Append_Entity_Name
698
699 begin
700 Inner (E);
701 Append (Buf, Temp);
702 end Append_Entity_Name;
703
704 ---------------------------------
705 -- Append_Inherited_Subprogram --
706 ---------------------------------
707
708 procedure Append_Inherited_Subprogram (S : Entity_Id) is
709 Par : constant Entity_Id := Alias (S);
710 -- The parent subprogram
711
712 Scop : constant Entity_Id := Scope (Par);
713 -- The scope of definition of the parent subprogram
714
715 Typ : constant Entity_Id := Defining_Entity (Parent (S));
716 -- The derived type of which S is a primitive operation
717
718 Decl : Node_Id;
719 Next_E : Entity_Id;
720
721 begin
722 if Ekind (Current_Scope) = E_Package
723 and then In_Private_Part (Current_Scope)
724 and then Has_Private_Declaration (Typ)
725 and then Is_Tagged_Type (Typ)
726 and then Scop = Current_Scope
727 then
728 -- The inherited operation is available at the earliest place after
729 -- the derived type declaration (RM 7.3.1 (6/1)). This is only
730 -- relevant for type extensions. If the parent operation appears
731 -- after the type extension, the operation is not visible.
732
733 Decl := First
734 (Visible_Declarations
735 (Package_Specification (Current_Scope)));
736 while Present (Decl) loop
737 if Nkind (Decl) = N_Private_Extension_Declaration
738 and then Defining_Entity (Decl) = Typ
739 then
740 if Sloc (Decl) > Sloc (Par) then
741 Next_E := Next_Entity (Par);
742 Link_Entities (Par, S);
743 Link_Entities (S, Next_E);
744 return;
745
746 else
747 exit;
748 end if;
749 end if;
750
751 Next (Decl);
752 end loop;
753 end if;
754
755 -- If partial view is not a type extension, or it appears before the
756 -- subprogram declaration, insert normally at end of entity list.
757
758 Append_Entity (S, Current_Scope);
759 end Append_Inherited_Subprogram;
760
761 -----------------------------------------
762 -- Apply_Compile_Time_Constraint_Error --
763 -----------------------------------------
764
765 procedure Apply_Compile_Time_Constraint_Error
766 (N : Node_Id;
767 Msg : String;
768 Reason : RT_Exception_Code;
769 Ent : Entity_Id := Empty;
770 Typ : Entity_Id := Empty;
771 Loc : Source_Ptr := No_Location;
772 Rep : Boolean := True;
773 Warn : Boolean := False)
774 is
775 Stat : constant Boolean := Is_Static_Expression (N);
776 R_Stat : constant Node_Id :=
777 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
778 Rtyp : Entity_Id;
779
780 begin
781 if No (Typ) then
782 Rtyp := Etype (N);
783 else
784 Rtyp := Typ;
785 end if;
786
787 Discard_Node
788 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
789
790 -- In GNATprove mode, do not replace the node with an exception raised.
791 -- In such a case, either the call to Compile_Time_Constraint_Error
792 -- issues an error which stops analysis, or it issues a warning in
793 -- a few cases where a suitable check flag is set for GNATprove to
794 -- generate a check message.
795
796 if not Rep or GNATprove_Mode then
797 return;
798 end if;
799
800 -- Now we replace the node by an N_Raise_Constraint_Error node
801 -- This does not need reanalyzing, so set it as analyzed now.
802
803 Rewrite (N, R_Stat);
804 Set_Analyzed (N, True);
805
806 Set_Etype (N, Rtyp);
807 Set_Raises_Constraint_Error (N);
808
809 -- Now deal with possible local raise handling
810
811 Possible_Local_Raise (N, Standard_Constraint_Error);
812
813 -- If the original expression was marked as static, the result is
814 -- still marked as static, but the Raises_Constraint_Error flag is
815 -- always set so that further static evaluation is not attempted.
816
817 if Stat then
818 Set_Is_Static_Expression (N);
819 end if;
820 end Apply_Compile_Time_Constraint_Error;
821
822 ---------------------------
823 -- Async_Readers_Enabled --
824 ---------------------------
825
826 function Async_Readers_Enabled (Id : Entity_Id) return Boolean is
827 begin
828 return Has_Enabled_Property (Id, Name_Async_Readers);
829 end Async_Readers_Enabled;
830
831 ---------------------------
832 -- Async_Writers_Enabled --
833 ---------------------------
834
835 function Async_Writers_Enabled (Id : Entity_Id) return Boolean is
836 begin
837 return Has_Enabled_Property (Id, Name_Async_Writers);
838 end Async_Writers_Enabled;
839
840 --------------------------------------
841 -- Available_Full_View_Of_Component --
842 --------------------------------------
843
844 function Available_Full_View_Of_Component (T : Entity_Id) return Boolean is
845 ST : constant Entity_Id := Scope (T);
846 SCT : constant Entity_Id := Scope (Component_Type (T));
847 begin
848 return In_Open_Scopes (ST)
849 and then In_Open_Scopes (SCT)
850 and then Scope_Depth (ST) >= Scope_Depth (SCT);
851 end Available_Full_View_Of_Component;
852
853 -------------------
854 -- Bad_Attribute --
855 -------------------
856
857 procedure Bad_Attribute
858 (N : Node_Id;
859 Nam : Name_Id;
860 Warn : Boolean := False)
861 is
862 begin
863 Error_Msg_Warn := Warn;
864 Error_Msg_N ("unrecognized attribute&<<", N);
865
866 -- Check for possible misspelling
867
868 Error_Msg_Name_1 := First_Attribute_Name;
869 while Error_Msg_Name_1 <= Last_Attribute_Name loop
870 if Is_Bad_Spelling_Of (Nam, Error_Msg_Name_1) then
871 Error_Msg_N -- CODEFIX
872 ("\possible misspelling of %<<", N);
873 exit;
874 end if;
875
876 Error_Msg_Name_1 := Error_Msg_Name_1 + 1;
877 end loop;
878 end Bad_Attribute;
879
880 --------------------------------
881 -- Bad_Predicated_Subtype_Use --
882 --------------------------------
883
884 procedure Bad_Predicated_Subtype_Use
885 (Msg : String;
886 N : Node_Id;
887 Typ : Entity_Id;
888 Suggest_Static : Boolean := False)
889 is
890 Gen : Entity_Id;
891
892 begin
893 -- Avoid cascaded errors
894
895 if Error_Posted (N) then
896 return;
897 end if;
898
899 if Inside_A_Generic then
900 Gen := Current_Scope;
901 while Present (Gen) and then Ekind (Gen) /= E_Generic_Package loop
902 Gen := Scope (Gen);
903 end loop;
904
905 if No (Gen) then
906 return;
907 end if;
908
909 if Is_Generic_Formal (Typ) and then Is_Discrete_Type (Typ) then
910 Set_No_Predicate_On_Actual (Typ);
911 end if;
912
913 elsif Has_Predicates (Typ) then
914 if Is_Generic_Actual_Type (Typ) then
915
916 -- The restriction on loop parameters is only that the type
917 -- should have no dynamic predicates.
918
919 if Nkind (Parent (N)) = N_Loop_Parameter_Specification
920 and then not Has_Dynamic_Predicate_Aspect (Typ)
921 and then Is_OK_Static_Subtype (Typ)
922 then
923 return;
924 end if;
925
926 Gen := Current_Scope;
927 while not Is_Generic_Instance (Gen) loop
928 Gen := Scope (Gen);
929 end loop;
930
931 pragma Assert (Present (Gen));
932
933 if Ekind (Gen) = E_Package and then In_Package_Body (Gen) then
934 Error_Msg_Warn := SPARK_Mode /= On;
935 Error_Msg_FE (Msg & "<<", N, Typ);
936 Error_Msg_F ("\Program_Error [<<", N);
937
938 Insert_Action (N,
939 Make_Raise_Program_Error (Sloc (N),
940 Reason => PE_Bad_Predicated_Generic_Type));
941
942 else
943 Error_Msg_FE (Msg & "<<", N, Typ);
944 end if;
945
946 else
947 Error_Msg_FE (Msg, N, Typ);
948 end if;
949
950 -- Emit an optional suggestion on how to remedy the error if the
951 -- context warrants it.
952
953 if Suggest_Static and then Has_Static_Predicate (Typ) then
954 Error_Msg_FE ("\predicate of & should be marked static", N, Typ);
955 end if;
956 end if;
957 end Bad_Predicated_Subtype_Use;
958
959 -----------------------------------------
960 -- Bad_Unordered_Enumeration_Reference --
961 -----------------------------------------
962
963 function Bad_Unordered_Enumeration_Reference
964 (N : Node_Id;
965 T : Entity_Id) return Boolean
966 is
967 begin
968 return Is_Enumeration_Type (T)
969 and then Warn_On_Unordered_Enumeration_Type
970 and then not Is_Generic_Type (T)
971 and then Comes_From_Source (N)
972 and then not Has_Pragma_Ordered (T)
973 and then not In_Same_Extended_Unit (N, T);
974 end Bad_Unordered_Enumeration_Reference;
975
976 ----------------------------
977 -- Begin_Keyword_Location --
978 ----------------------------
979
980 function Begin_Keyword_Location (N : Node_Id) return Source_Ptr is
981 HSS : Node_Id;
982
983 begin
984 pragma Assert (Nkind_In (N, N_Block_Statement,
985 N_Entry_Body,
986 N_Package_Body,
987 N_Subprogram_Body,
988 N_Task_Body));
989
990 HSS := Handled_Statement_Sequence (N);
991
992 -- When the handled sequence of statements comes from source, the
993 -- location of the "begin" keyword is that of the sequence itself.
994 -- Note that an internal construct may inherit a source sequence.
995
996 if Comes_From_Source (HSS) then
997 return Sloc (HSS);
998
999 -- The parser generates an internal handled sequence of statements to
1000 -- capture the location of the "begin" keyword if present in the source.
1001 -- Since there are no source statements, the location of the "begin"
1002 -- keyword is effectively that of the "end" keyword.
1003
1004 elsif Comes_From_Source (N) then
1005 return Sloc (HSS);
1006
1007 -- Otherwise the construct is internal and should carry the location of
1008 -- the original construct which prompted its creation.
1009
1010 else
1011 return Sloc (N);
1012 end if;
1013 end Begin_Keyword_Location;
1014
1015 --------------------------
1016 -- Build_Actual_Subtype --
1017 --------------------------
1018
1019 function Build_Actual_Subtype
1020 (T : Entity_Id;
1021 N : Node_Or_Entity_Id) return Node_Id
1022 is
1023 Loc : Source_Ptr;
1024 -- Normally Sloc (N), but may point to corresponding body in some cases
1025
1026 Constraints : List_Id;
1027 Decl : Node_Id;
1028 Discr : Entity_Id;
1029 Hi : Node_Id;
1030 Lo : Node_Id;
1031 Subt : Entity_Id;
1032 Disc_Type : Entity_Id;
1033 Obj : Node_Id;
1034
1035 begin
1036 Loc := Sloc (N);
1037
1038 if Nkind (N) = N_Defining_Identifier then
1039 Obj := New_Occurrence_Of (N, Loc);
1040
1041 -- If this is a formal parameter of a subprogram declaration, and
1042 -- we are compiling the body, we want the declaration for the
1043 -- actual subtype to carry the source position of the body, to
1044 -- prevent anomalies in gdb when stepping through the code.
1045
1046 if Is_Formal (N) then
1047 declare
1048 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
1049 begin
1050 if Nkind (Decl) = N_Subprogram_Declaration
1051 and then Present (Corresponding_Body (Decl))
1052 then
1053 Loc := Sloc (Corresponding_Body (Decl));
1054 end if;
1055 end;
1056 end if;
1057
1058 else
1059 Obj := N;
1060 end if;
1061
1062 if Is_Array_Type (T) then
1063 Constraints := New_List;
1064 for J in 1 .. Number_Dimensions (T) loop
1065
1066 -- Build an array subtype declaration with the nominal subtype and
1067 -- the bounds of the actual. Add the declaration in front of the
1068 -- local declarations for the subprogram, for analysis before any
1069 -- reference to the formal in the body.
1070
1071 Lo :=
1072 Make_Attribute_Reference (Loc,
1073 Prefix =>
1074 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
1075 Attribute_Name => Name_First,
1076 Expressions => New_List (
1077 Make_Integer_Literal (Loc, J)));
1078
1079 Hi :=
1080 Make_Attribute_Reference (Loc,
1081 Prefix =>
1082 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
1083 Attribute_Name => Name_Last,
1084 Expressions => New_List (
1085 Make_Integer_Literal (Loc, J)));
1086
1087 Append (Make_Range (Loc, Lo, Hi), Constraints);
1088 end loop;
1089
1090 -- If the type has unknown discriminants there is no constrained
1091 -- subtype to build. This is never called for a formal or for a
1092 -- lhs, so returning the type is ok ???
1093
1094 elsif Has_Unknown_Discriminants (T) then
1095 return T;
1096
1097 else
1098 Constraints := New_List;
1099
1100 -- Type T is a generic derived type, inherit the discriminants from
1101 -- the parent type.
1102
1103 if Is_Private_Type (T)
1104 and then No (Full_View (T))
1105
1106 -- T was flagged as an error if it was declared as a formal
1107 -- derived type with known discriminants. In this case there
1108 -- is no need to look at the parent type since T already carries
1109 -- its own discriminants.
1110
1111 and then not Error_Posted (T)
1112 then
1113 Disc_Type := Etype (Base_Type (T));
1114 else
1115 Disc_Type := T;
1116 end if;
1117
1118 Discr := First_Discriminant (Disc_Type);
1119 while Present (Discr) loop
1120 Append_To (Constraints,
1121 Make_Selected_Component (Loc,
1122 Prefix =>
1123 Duplicate_Subexpr_No_Checks (Obj),
1124 Selector_Name => New_Occurrence_Of (Discr, Loc)));
1125 Next_Discriminant (Discr);
1126 end loop;
1127 end if;
1128
1129 Subt := Make_Temporary (Loc, 'S', Related_Node => N);
1130 Set_Is_Internal (Subt);
1131
1132 Decl :=
1133 Make_Subtype_Declaration (Loc,
1134 Defining_Identifier => Subt,
1135 Subtype_Indication =>
1136 Make_Subtype_Indication (Loc,
1137 Subtype_Mark => New_Occurrence_Of (T, Loc),
1138 Constraint =>
1139 Make_Index_Or_Discriminant_Constraint (Loc,
1140 Constraints => Constraints)));
1141
1142 Mark_Rewrite_Insertion (Decl);
1143 return Decl;
1144 end Build_Actual_Subtype;
1145
1146 ---------------------------------------
1147 -- Build_Actual_Subtype_Of_Component --
1148 ---------------------------------------
1149
1150 function Build_Actual_Subtype_Of_Component
1151 (T : Entity_Id;
1152 N : Node_Id) return Node_Id
1153 is
1154 Loc : constant Source_Ptr := Sloc (N);
1155 P : constant Node_Id := Prefix (N);
1156 D : Elmt_Id;
1157 Id : Node_Id;
1158 Index_Typ : Entity_Id;
1159
1160 Desig_Typ : Entity_Id;
1161 -- This is either a copy of T, or if T is an access type, then it is
1162 -- the directly designated type of this access type.
1163
1164 function Build_Actual_Array_Constraint return List_Id;
1165 -- If one or more of the bounds of the component depends on
1166 -- discriminants, build actual constraint using the discriminants
1167 -- of the prefix.
1168
1169 function Build_Actual_Record_Constraint return List_Id;
1170 -- Similar to previous one, for discriminated components constrained
1171 -- by the discriminant of the enclosing object.
1172
1173 -----------------------------------
1174 -- Build_Actual_Array_Constraint --
1175 -----------------------------------
1176
1177 function Build_Actual_Array_Constraint return List_Id is
1178 Constraints : constant List_Id := New_List;
1179 Indx : Node_Id;
1180 Hi : Node_Id;
1181 Lo : Node_Id;
1182 Old_Hi : Node_Id;
1183 Old_Lo : Node_Id;
1184
1185 begin
1186 Indx := First_Index (Desig_Typ);
1187 while Present (Indx) loop
1188 Old_Lo := Type_Low_Bound (Etype (Indx));
1189 Old_Hi := Type_High_Bound (Etype (Indx));
1190
1191 if Denotes_Discriminant (Old_Lo) then
1192 Lo :=
1193 Make_Selected_Component (Loc,
1194 Prefix => New_Copy_Tree (P),
1195 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
1196
1197 else
1198 Lo := New_Copy_Tree (Old_Lo);
1199
1200 -- The new bound will be reanalyzed in the enclosing
1201 -- declaration. For literal bounds that come from a type
1202 -- declaration, the type of the context must be imposed, so
1203 -- insure that analysis will take place. For non-universal
1204 -- types this is not strictly necessary.
1205
1206 Set_Analyzed (Lo, False);
1207 end if;
1208
1209 if Denotes_Discriminant (Old_Hi) then
1210 Hi :=
1211 Make_Selected_Component (Loc,
1212 Prefix => New_Copy_Tree (P),
1213 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
1214
1215 else
1216 Hi := New_Copy_Tree (Old_Hi);
1217 Set_Analyzed (Hi, False);
1218 end if;
1219
1220 Append (Make_Range (Loc, Lo, Hi), Constraints);
1221 Next_Index (Indx);
1222 end loop;
1223
1224 return Constraints;
1225 end Build_Actual_Array_Constraint;
1226
1227 ------------------------------------
1228 -- Build_Actual_Record_Constraint --
1229 ------------------------------------
1230
1231 function Build_Actual_Record_Constraint return List_Id is
1232 Constraints : constant List_Id := New_List;
1233 D : Elmt_Id;
1234 D_Val : Node_Id;
1235
1236 begin
1237 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1238 while Present (D) loop
1239 if Denotes_Discriminant (Node (D)) then
1240 D_Val := Make_Selected_Component (Loc,
1241 Prefix => New_Copy_Tree (P),
1242 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
1243
1244 else
1245 D_Val := New_Copy_Tree (Node (D));
1246 end if;
1247
1248 Append (D_Val, Constraints);
1249 Next_Elmt (D);
1250 end loop;
1251
1252 return Constraints;
1253 end Build_Actual_Record_Constraint;
1254
1255 -- Start of processing for Build_Actual_Subtype_Of_Component
1256
1257 begin
1258 -- Why the test for Spec_Expression mode here???
1259
1260 if In_Spec_Expression then
1261 return Empty;
1262
1263 -- More comments for the rest of this body would be good ???
1264
1265 elsif Nkind (N) = N_Explicit_Dereference then
1266 if Is_Composite_Type (T)
1267 and then not Is_Constrained (T)
1268 and then not (Is_Class_Wide_Type (T)
1269 and then Is_Constrained (Root_Type (T)))
1270 and then not Has_Unknown_Discriminants (T)
1271 then
1272 -- If the type of the dereference is already constrained, it is an
1273 -- actual subtype.
1274
1275 if Is_Array_Type (Etype (N))
1276 and then Is_Constrained (Etype (N))
1277 then
1278 return Empty;
1279 else
1280 Remove_Side_Effects (P);
1281 return Build_Actual_Subtype (T, N);
1282 end if;
1283 else
1284 return Empty;
1285 end if;
1286 end if;
1287
1288 if Ekind (T) = E_Access_Subtype then
1289 Desig_Typ := Designated_Type (T);
1290 else
1291 Desig_Typ := T;
1292 end if;
1293
1294 if Ekind (Desig_Typ) = E_Array_Subtype then
1295 Id := First_Index (Desig_Typ);
1296 while Present (Id) loop
1297 Index_Typ := Underlying_Type (Etype (Id));
1298
1299 if Denotes_Discriminant (Type_Low_Bound (Index_Typ))
1300 or else
1301 Denotes_Discriminant (Type_High_Bound (Index_Typ))
1302 then
1303 Remove_Side_Effects (P);
1304 return
1305 Build_Component_Subtype
1306 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
1307 end if;
1308
1309 Next_Index (Id);
1310 end loop;
1311
1312 elsif Is_Composite_Type (Desig_Typ)
1313 and then Has_Discriminants (Desig_Typ)
1314 and then not Has_Unknown_Discriminants (Desig_Typ)
1315 then
1316 if Is_Private_Type (Desig_Typ)
1317 and then No (Discriminant_Constraint (Desig_Typ))
1318 then
1319 Desig_Typ := Full_View (Desig_Typ);
1320 end if;
1321
1322 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1323 while Present (D) loop
1324 if Denotes_Discriminant (Node (D)) then
1325 Remove_Side_Effects (P);
1326 return
1327 Build_Component_Subtype (
1328 Build_Actual_Record_Constraint, Loc, Base_Type (T));
1329 end if;
1330
1331 Next_Elmt (D);
1332 end loop;
1333 end if;
1334
1335 -- If none of the above, the actual and nominal subtypes are the same
1336
1337 return Empty;
1338 end Build_Actual_Subtype_Of_Component;
1339
1340 ---------------------------------
1341 -- Build_Class_Wide_Clone_Body --
1342 ---------------------------------
1343
1344 procedure Build_Class_Wide_Clone_Body
1345 (Spec_Id : Entity_Id;
1346 Bod : Node_Id)
1347 is
1348 Loc : constant Source_Ptr := Sloc (Bod);
1349 Clone_Id : constant Entity_Id := Class_Wide_Clone (Spec_Id);
1350 Clone_Body : Node_Id;
1351
1352 begin
1353 -- The declaration of the class-wide clone was created when the
1354 -- corresponding class-wide condition was analyzed.
1355
1356 Clone_Body :=
1357 Make_Subprogram_Body (Loc,
1358 Specification =>
1359 Copy_Subprogram_Spec (Parent (Clone_Id)),
1360 Declarations => Declarations (Bod),
1361 Handled_Statement_Sequence => Handled_Statement_Sequence (Bod));
1362
1363 -- The new operation is internal and overriding indicators do not apply
1364 -- (the original primitive may have carried one).
1365
1366 Set_Must_Override (Specification (Clone_Body), False);
1367
1368 -- If the subprogram body is the proper body of a stub, insert the
1369 -- subprogram after the stub, i.e. the same declarative region as
1370 -- the original sugprogram.
1371
1372 if Nkind (Parent (Bod)) = N_Subunit then
1373 Insert_After (Corresponding_Stub (Parent (Bod)), Clone_Body);
1374
1375 else
1376 Insert_Before (Bod, Clone_Body);
1377 end if;
1378
1379 Analyze (Clone_Body);
1380 end Build_Class_Wide_Clone_Body;
1381
1382 ---------------------------------
1383 -- Build_Class_Wide_Clone_Call --
1384 ---------------------------------
1385
1386 function Build_Class_Wide_Clone_Call
1387 (Loc : Source_Ptr;
1388 Decls : List_Id;
1389 Spec_Id : Entity_Id;
1390 Spec : Node_Id) return Node_Id
1391 is
1392 Clone_Id : constant Entity_Id := Class_Wide_Clone (Spec_Id);
1393 Par_Type : constant Entity_Id := Find_Dispatching_Type (Spec_Id);
1394
1395 Actuals : List_Id;
1396 Call : Node_Id;
1397 Formal : Entity_Id;
1398 New_Body : Node_Id;
1399 New_F_Spec : Entity_Id;
1400 New_Formal : Entity_Id;
1401
1402 begin
1403 Actuals := Empty_List;
1404 Formal := First_Formal (Spec_Id);
1405 New_F_Spec := First (Parameter_Specifications (Spec));
1406
1407 -- Build parameter association for call to class-wide clone.
1408
1409 while Present (Formal) loop
1410 New_Formal := Defining_Identifier (New_F_Spec);
1411
1412 -- If controlling argument and operation is inherited, add conversion
1413 -- to parent type for the call.
1414
1415 if Etype (Formal) = Par_Type
1416 and then not Is_Empty_List (Decls)
1417 then
1418 Append_To (Actuals,
1419 Make_Type_Conversion (Loc,
1420 New_Occurrence_Of (Par_Type, Loc),
1421 New_Occurrence_Of (New_Formal, Loc)));
1422
1423 else
1424 Append_To (Actuals, New_Occurrence_Of (New_Formal, Loc));
1425 end if;
1426
1427 Next_Formal (Formal);
1428 Next (New_F_Spec);
1429 end loop;
1430
1431 if Ekind (Spec_Id) = E_Procedure then
1432 Call :=
1433 Make_Procedure_Call_Statement (Loc,
1434 Name => New_Occurrence_Of (Clone_Id, Loc),
1435 Parameter_Associations => Actuals);
1436 else
1437 Call :=
1438 Make_Simple_Return_Statement (Loc,
1439 Expression =>
1440 Make_Function_Call (Loc,
1441 Name => New_Occurrence_Of (Clone_Id, Loc),
1442 Parameter_Associations => Actuals));
1443 end if;
1444
1445 New_Body :=
1446 Make_Subprogram_Body (Loc,
1447 Specification =>
1448 Copy_Subprogram_Spec (Spec),
1449 Declarations => Decls,
1450 Handled_Statement_Sequence =>
1451 Make_Handled_Sequence_Of_Statements (Loc,
1452 Statements => New_List (Call),
1453 End_Label => Make_Identifier (Loc, Chars (Spec_Id))));
1454
1455 return New_Body;
1456 end Build_Class_Wide_Clone_Call;
1457
1458 ---------------------------------
1459 -- Build_Class_Wide_Clone_Decl --
1460 ---------------------------------
1461
1462 procedure Build_Class_Wide_Clone_Decl (Spec_Id : Entity_Id) is
1463 Loc : constant Source_Ptr := Sloc (Spec_Id);
1464 Clone_Id : constant Entity_Id :=
1465 Make_Defining_Identifier (Loc,
1466 New_External_Name (Chars (Spec_Id), Suffix => "CL"));
1467
1468 Decl : Node_Id;
1469 Spec : Node_Id;
1470
1471 begin
1472 Spec := Copy_Subprogram_Spec (Parent (Spec_Id));
1473 Set_Must_Override (Spec, False);
1474 Set_Must_Not_Override (Spec, False);
1475 Set_Defining_Unit_Name (Spec, Clone_Id);
1476
1477 Decl := Make_Subprogram_Declaration (Loc, Spec);
1478 Append (Decl, List_Containing (Unit_Declaration_Node (Spec_Id)));
1479
1480 -- Link clone to original subprogram, for use when building body and
1481 -- wrapper call to inherited operation.
1482
1483 Set_Class_Wide_Clone (Spec_Id, Clone_Id);
1484 end Build_Class_Wide_Clone_Decl;
1485
1486 -----------------------------
1487 -- Build_Component_Subtype --
1488 -----------------------------
1489
1490 function Build_Component_Subtype
1491 (C : List_Id;
1492 Loc : Source_Ptr;
1493 T : Entity_Id) return Node_Id
1494 is
1495 Subt : Entity_Id;
1496 Decl : Node_Id;
1497
1498 begin
1499 -- Unchecked_Union components do not require component subtypes
1500
1501 if Is_Unchecked_Union (T) then
1502 return Empty;
1503 end if;
1504
1505 Subt := Make_Temporary (Loc, 'S');
1506 Set_Is_Internal (Subt);
1507
1508 Decl :=
1509 Make_Subtype_Declaration (Loc,
1510 Defining_Identifier => Subt,
1511 Subtype_Indication =>
1512 Make_Subtype_Indication (Loc,
1513 Subtype_Mark => New_Occurrence_Of (Base_Type (T), Loc),
1514 Constraint =>
1515 Make_Index_Or_Discriminant_Constraint (Loc,
1516 Constraints => C)));
1517
1518 Mark_Rewrite_Insertion (Decl);
1519 return Decl;
1520 end Build_Component_Subtype;
1521
1522 ---------------------------
1523 -- Build_Default_Subtype --
1524 ---------------------------
1525
1526 function Build_Default_Subtype
1527 (T : Entity_Id;
1528 N : Node_Id) return Entity_Id
1529 is
1530 Loc : constant Source_Ptr := Sloc (N);
1531 Disc : Entity_Id;
1532
1533 Bas : Entity_Id;
1534 -- The base type that is to be constrained by the defaults
1535
1536 begin
1537 if not Has_Discriminants (T) or else Is_Constrained (T) then
1538 return T;
1539 end if;
1540
1541 Bas := Base_Type (T);
1542
1543 -- If T is non-private but its base type is private, this is the
1544 -- completion of a subtype declaration whose parent type is private
1545 -- (see Complete_Private_Subtype in Sem_Ch3). The proper discriminants
1546 -- are to be found in the full view of the base. Check that the private
1547 -- status of T and its base differ.
1548
1549 if Is_Private_Type (Bas)
1550 and then not Is_Private_Type (T)
1551 and then Present (Full_View (Bas))
1552 then
1553 Bas := Full_View (Bas);
1554 end if;
1555
1556 Disc := First_Discriminant (T);
1557
1558 if No (Discriminant_Default_Value (Disc)) then
1559 return T;
1560 end if;
1561
1562 declare
1563 Act : constant Entity_Id := Make_Temporary (Loc, 'S');
1564 Constraints : constant List_Id := New_List;
1565 Decl : Node_Id;
1566
1567 begin
1568 while Present (Disc) loop
1569 Append_To (Constraints,
1570 New_Copy_Tree (Discriminant_Default_Value (Disc)));
1571 Next_Discriminant (Disc);
1572 end loop;
1573
1574 Decl :=
1575 Make_Subtype_Declaration (Loc,
1576 Defining_Identifier => Act,
1577 Subtype_Indication =>
1578 Make_Subtype_Indication (Loc,
1579 Subtype_Mark => New_Occurrence_Of (Bas, Loc),
1580 Constraint =>
1581 Make_Index_Or_Discriminant_Constraint (Loc,
1582 Constraints => Constraints)));
1583
1584 Insert_Action (N, Decl);
1585
1586 -- If the context is a component declaration the subtype declaration
1587 -- will be analyzed when the enclosing type is frozen, otherwise do
1588 -- it now.
1589
1590 if Ekind (Current_Scope) /= E_Record_Type then
1591 Analyze (Decl);
1592 end if;
1593
1594 return Act;
1595 end;
1596 end Build_Default_Subtype;
1597
1598 --------------------------------------------
1599 -- Build_Discriminal_Subtype_Of_Component --
1600 --------------------------------------------
1601
1602 function Build_Discriminal_Subtype_Of_Component
1603 (T : Entity_Id) return Node_Id
1604 is
1605 Loc : constant Source_Ptr := Sloc (T);
1606 D : Elmt_Id;
1607 Id : Node_Id;
1608
1609 function Build_Discriminal_Array_Constraint return List_Id;
1610 -- If one or more of the bounds of the component depends on
1611 -- discriminants, build actual constraint using the discriminants
1612 -- of the prefix.
1613
1614 function Build_Discriminal_Record_Constraint return List_Id;
1615 -- Similar to previous one, for discriminated components constrained by
1616 -- the discriminant of the enclosing object.
1617
1618 ----------------------------------------
1619 -- Build_Discriminal_Array_Constraint --
1620 ----------------------------------------
1621
1622 function Build_Discriminal_Array_Constraint return List_Id is
1623 Constraints : constant List_Id := New_List;
1624 Indx : Node_Id;
1625 Hi : Node_Id;
1626 Lo : Node_Id;
1627 Old_Hi : Node_Id;
1628 Old_Lo : Node_Id;
1629
1630 begin
1631 Indx := First_Index (T);
1632 while Present (Indx) loop
1633 Old_Lo := Type_Low_Bound (Etype (Indx));
1634 Old_Hi := Type_High_Bound (Etype (Indx));
1635
1636 if Denotes_Discriminant (Old_Lo) then
1637 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
1638
1639 else
1640 Lo := New_Copy_Tree (Old_Lo);
1641 end if;
1642
1643 if Denotes_Discriminant (Old_Hi) then
1644 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
1645
1646 else
1647 Hi := New_Copy_Tree (Old_Hi);
1648 end if;
1649
1650 Append (Make_Range (Loc, Lo, Hi), Constraints);
1651 Next_Index (Indx);
1652 end loop;
1653
1654 return Constraints;
1655 end Build_Discriminal_Array_Constraint;
1656
1657 -----------------------------------------
1658 -- Build_Discriminal_Record_Constraint --
1659 -----------------------------------------
1660
1661 function Build_Discriminal_Record_Constraint return List_Id is
1662 Constraints : constant List_Id := New_List;
1663 D : Elmt_Id;
1664 D_Val : Node_Id;
1665
1666 begin
1667 D := First_Elmt (Discriminant_Constraint (T));
1668 while Present (D) loop
1669 if Denotes_Discriminant (Node (D)) then
1670 D_Val :=
1671 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
1672 else
1673 D_Val := New_Copy_Tree (Node (D));
1674 end if;
1675
1676 Append (D_Val, Constraints);
1677 Next_Elmt (D);
1678 end loop;
1679
1680 return Constraints;
1681 end Build_Discriminal_Record_Constraint;
1682
1683 -- Start of processing for Build_Discriminal_Subtype_Of_Component
1684
1685 begin
1686 if Ekind (T) = E_Array_Subtype then
1687 Id := First_Index (T);
1688 while Present (Id) loop
1689 if Denotes_Discriminant (Type_Low_Bound (Etype (Id)))
1690 or else
1691 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
1692 then
1693 return Build_Component_Subtype
1694 (Build_Discriminal_Array_Constraint, Loc, T);
1695 end if;
1696
1697 Next_Index (Id);
1698 end loop;
1699
1700 elsif Ekind (T) = E_Record_Subtype
1701 and then Has_Discriminants (T)
1702 and then not Has_Unknown_Discriminants (T)
1703 then
1704 D := First_Elmt (Discriminant_Constraint (T));
1705 while Present (D) loop
1706 if Denotes_Discriminant (Node (D)) then
1707 return Build_Component_Subtype
1708 (Build_Discriminal_Record_Constraint, Loc, T);
1709 end if;
1710
1711 Next_Elmt (D);
1712 end loop;
1713 end if;
1714
1715 -- If none of the above, the actual and nominal subtypes are the same
1716
1717 return Empty;
1718 end Build_Discriminal_Subtype_Of_Component;
1719
1720 ------------------------------
1721 -- Build_Elaboration_Entity --
1722 ------------------------------
1723
1724 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
1725 Loc : constant Source_Ptr := Sloc (N);
1726 Decl : Node_Id;
1727 Elab_Ent : Entity_Id;
1728
1729 procedure Set_Package_Name (Ent : Entity_Id);
1730 -- Given an entity, sets the fully qualified name of the entity in
1731 -- Name_Buffer, with components separated by double underscores. This
1732 -- is a recursive routine that climbs the scope chain to Standard.
1733
1734 ----------------------
1735 -- Set_Package_Name --
1736 ----------------------
1737
1738 procedure Set_Package_Name (Ent : Entity_Id) is
1739 begin
1740 if Scope (Ent) /= Standard_Standard then
1741 Set_Package_Name (Scope (Ent));
1742
1743 declare
1744 Nam : constant String := Get_Name_String (Chars (Ent));
1745 begin
1746 Name_Buffer (Name_Len + 1) := '_';
1747 Name_Buffer (Name_Len + 2) := '_';
1748 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
1749 Name_Len := Name_Len + Nam'Length + 2;
1750 end;
1751
1752 else
1753 Get_Name_String (Chars (Ent));
1754 end if;
1755 end Set_Package_Name;
1756
1757 -- Start of processing for Build_Elaboration_Entity
1758
1759 begin
1760 -- Ignore call if already constructed
1761
1762 if Present (Elaboration_Entity (Spec_Id)) then
1763 return;
1764
1765 -- Ignore in ASIS mode, elaboration entity is not in source and plays
1766 -- no role in analysis.
1767
1768 elsif ASIS_Mode then
1769 return;
1770
1771 -- Do not generate an elaboration entity in GNATprove move because the
1772 -- elaboration counter is a form of expansion.
1773
1774 elsif GNATprove_Mode then
1775 return;
1776
1777 -- See if we need elaboration entity
1778
1779 -- We always need an elaboration entity when preserving control flow, as
1780 -- we want to remain explicit about the unit's elaboration order.
1781
1782 elsif Opt.Suppress_Control_Flow_Optimizations then
1783 null;
1784
1785 -- We always need an elaboration entity for the dynamic elaboration
1786 -- model, since it is needed to properly generate the PE exception for
1787 -- access before elaboration.
1788
1789 elsif Dynamic_Elaboration_Checks then
1790 null;
1791
1792 -- For the static model, we don't need the elaboration counter if this
1793 -- unit is sure to have no elaboration code, since that means there
1794 -- is no elaboration unit to be called. Note that we can't just decide
1795 -- after the fact by looking to see whether there was elaboration code,
1796 -- because that's too late to make this decision.
1797
1798 elsif Restriction_Active (No_Elaboration_Code) then
1799 return;
1800
1801 -- Similarly, for the static model, we can skip the elaboration counter
1802 -- if we have the No_Multiple_Elaboration restriction, since for the
1803 -- static model, that's the only purpose of the counter (to avoid
1804 -- multiple elaboration).
1805
1806 elsif Restriction_Active (No_Multiple_Elaboration) then
1807 return;
1808 end if;
1809
1810 -- Here we need the elaboration entity
1811
1812 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
1813 -- name with dots replaced by double underscore. We have to manually
1814 -- construct this name, since it will be elaborated in the outer scope,
1815 -- and thus will not have the unit name automatically prepended.
1816
1817 Set_Package_Name (Spec_Id);
1818 Add_Str_To_Name_Buffer ("_E");
1819
1820 -- Create elaboration counter
1821
1822 Elab_Ent := Make_Defining_Identifier (Loc, Chars => Name_Find);
1823 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
1824
1825 Decl :=
1826 Make_Object_Declaration (Loc,
1827 Defining_Identifier => Elab_Ent,
1828 Object_Definition =>
1829 New_Occurrence_Of (Standard_Short_Integer, Loc),
1830 Expression => Make_Integer_Literal (Loc, Uint_0));
1831
1832 Push_Scope (Standard_Standard);
1833 Add_Global_Declaration (Decl);
1834 Pop_Scope;
1835
1836 -- Reset True_Constant indication, since we will indeed assign a value
1837 -- to the variable in the binder main. We also kill the Current_Value
1838 -- and Last_Assignment fields for the same reason.
1839
1840 Set_Is_True_Constant (Elab_Ent, False);
1841 Set_Current_Value (Elab_Ent, Empty);
1842 Set_Last_Assignment (Elab_Ent, Empty);
1843
1844 -- We do not want any further qualification of the name (if we did not
1845 -- do this, we would pick up the name of the generic package in the case
1846 -- of a library level generic instantiation).
1847
1848 Set_Has_Qualified_Name (Elab_Ent);
1849 Set_Has_Fully_Qualified_Name (Elab_Ent);
1850 end Build_Elaboration_Entity;
1851
1852 --------------------------------
1853 -- Build_Explicit_Dereference --
1854 --------------------------------
1855
1856 procedure Build_Explicit_Dereference
1857 (Expr : Node_Id;
1858 Disc : Entity_Id)
1859 is
1860 Loc : constant Source_Ptr := Sloc (Expr);
1861 I : Interp_Index;
1862 It : Interp;
1863
1864 begin
1865 -- An entity of a type with a reference aspect is overloaded with
1866 -- both interpretations: with and without the dereference. Now that
1867 -- the dereference is made explicit, set the type of the node properly,
1868 -- to prevent anomalies in the backend. Same if the expression is an
1869 -- overloaded function call whose return type has a reference aspect.
1870
1871 if Is_Entity_Name (Expr) then
1872 Set_Etype (Expr, Etype (Entity (Expr)));
1873
1874 -- The designated entity will not be examined again when resolving
1875 -- the dereference, so generate a reference to it now.
1876
1877 Generate_Reference (Entity (Expr), Expr);
1878
1879 elsif Nkind (Expr) = N_Function_Call then
1880
1881 -- If the name of the indexing function is overloaded, locate the one
1882 -- whose return type has an implicit dereference on the desired
1883 -- discriminant, and set entity and type of function call.
1884
1885 if Is_Overloaded (Name (Expr)) then
1886 Get_First_Interp (Name (Expr), I, It);
1887
1888 while Present (It.Nam) loop
1889 if Ekind ((It.Typ)) = E_Record_Type
1890 and then First_Entity ((It.Typ)) = Disc
1891 then
1892 Set_Entity (Name (Expr), It.Nam);
1893 Set_Etype (Name (Expr), Etype (It.Nam));
1894 exit;
1895 end if;
1896
1897 Get_Next_Interp (I, It);
1898 end loop;
1899 end if;
1900
1901 -- Set type of call from resolved function name.
1902
1903 Set_Etype (Expr, Etype (Name (Expr)));
1904 end if;
1905
1906 Set_Is_Overloaded (Expr, False);
1907
1908 -- The expression will often be a generalized indexing that yields a
1909 -- container element that is then dereferenced, in which case the
1910 -- generalized indexing call is also non-overloaded.
1911
1912 if Nkind (Expr) = N_Indexed_Component
1913 and then Present (Generalized_Indexing (Expr))
1914 then
1915 Set_Is_Overloaded (Generalized_Indexing (Expr), False);
1916 end if;
1917
1918 Rewrite (Expr,
1919 Make_Explicit_Dereference (Loc,
1920 Prefix =>
1921 Make_Selected_Component (Loc,
1922 Prefix => Relocate_Node (Expr),
1923 Selector_Name => New_Occurrence_Of (Disc, Loc))));
1924 Set_Etype (Prefix (Expr), Etype (Disc));
1925 Set_Etype (Expr, Designated_Type (Etype (Disc)));
1926 end Build_Explicit_Dereference;
1927
1928 ---------------------------
1929 -- Build_Overriding_Spec --
1930 ---------------------------
1931
1932 function Build_Overriding_Spec
1933 (Op : Entity_Id;
1934 Typ : Entity_Id) return Node_Id
1935 is
1936 Loc : constant Source_Ptr := Sloc (Typ);
1937 Par_Typ : constant Entity_Id := Find_Dispatching_Type (Op);
1938 Spec : constant Node_Id := Specification (Unit_Declaration_Node (Op));
1939
1940 Formal_Spec : Node_Id;
1941 Formal_Type : Node_Id;
1942 New_Spec : Node_Id;
1943
1944 begin
1945 New_Spec := Copy_Subprogram_Spec (Spec);
1946
1947 Formal_Spec := First (Parameter_Specifications (New_Spec));
1948 while Present (Formal_Spec) loop
1949 Formal_Type := Parameter_Type (Formal_Spec);
1950
1951 if Is_Entity_Name (Formal_Type)
1952 and then Entity (Formal_Type) = Par_Typ
1953 then
1954 Rewrite (Formal_Type, New_Occurrence_Of (Typ, Loc));
1955 end if;
1956
1957 -- Nothing needs to be done for access parameters
1958
1959 Next (Formal_Spec);
1960 end loop;
1961
1962 return New_Spec;
1963 end Build_Overriding_Spec;
1964
1965 -----------------------------------
1966 -- Cannot_Raise_Constraint_Error --
1967 -----------------------------------
1968
1969 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
1970 begin
1971 if Compile_Time_Known_Value (Expr) then
1972 return True;
1973
1974 elsif Do_Range_Check (Expr) then
1975 return False;
1976
1977 elsif Raises_Constraint_Error (Expr) then
1978 return False;
1979
1980 else
1981 case Nkind (Expr) is
1982 when N_Identifier =>
1983 return True;
1984
1985 when N_Expanded_Name =>
1986 return True;
1987
1988 when N_Selected_Component =>
1989 return not Do_Discriminant_Check (Expr);
1990
1991 when N_Attribute_Reference =>
1992 if Do_Overflow_Check (Expr) then
1993 return False;
1994
1995 elsif No (Expressions (Expr)) then
1996 return True;
1997
1998 else
1999 declare
2000 N : Node_Id;
2001
2002 begin
2003 N := First (Expressions (Expr));
2004 while Present (N) loop
2005 if Cannot_Raise_Constraint_Error (N) then
2006 Next (N);
2007 else
2008 return False;
2009 end if;
2010 end loop;
2011
2012 return True;
2013 end;
2014 end if;
2015
2016 when N_Type_Conversion =>
2017 if Do_Overflow_Check (Expr)
2018 or else Do_Length_Check (Expr)
2019 or else Do_Tag_Check (Expr)
2020 then
2021 return False;
2022 else
2023 return Cannot_Raise_Constraint_Error (Expression (Expr));
2024 end if;
2025
2026 when N_Unchecked_Type_Conversion =>
2027 return Cannot_Raise_Constraint_Error (Expression (Expr));
2028
2029 when N_Unary_Op =>
2030 if Do_Overflow_Check (Expr) then
2031 return False;
2032 else
2033 return Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
2034 end if;
2035
2036 when N_Op_Divide
2037 | N_Op_Mod
2038 | N_Op_Rem
2039 =>
2040 if Do_Division_Check (Expr)
2041 or else
2042 Do_Overflow_Check (Expr)
2043 then
2044 return False;
2045 else
2046 return
2047 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
2048 and then
2049 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
2050 end if;
2051
2052 when N_Op_Add
2053 | N_Op_And
2054 | N_Op_Concat
2055 | N_Op_Eq
2056 | N_Op_Expon
2057 | N_Op_Ge
2058 | N_Op_Gt
2059 | N_Op_Le
2060 | N_Op_Lt
2061 | N_Op_Multiply
2062 | N_Op_Ne
2063 | N_Op_Or
2064 | N_Op_Rotate_Left
2065 | N_Op_Rotate_Right
2066 | N_Op_Shift_Left
2067 | N_Op_Shift_Right
2068 | N_Op_Shift_Right_Arithmetic
2069 | N_Op_Subtract
2070 | N_Op_Xor
2071 =>
2072 if Do_Overflow_Check (Expr) then
2073 return False;
2074 else
2075 return
2076 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
2077 and then
2078 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
2079 end if;
2080
2081 when others =>
2082 return False;
2083 end case;
2084 end if;
2085 end Cannot_Raise_Constraint_Error;
2086
2087 -----------------------------------------
2088 -- Check_Dynamically_Tagged_Expression --
2089 -----------------------------------------
2090
2091 procedure Check_Dynamically_Tagged_Expression
2092 (Expr : Node_Id;
2093 Typ : Entity_Id;
2094 Related_Nod : Node_Id)
2095 is
2096 begin
2097 pragma Assert (Is_Tagged_Type (Typ));
2098
2099 -- In order to avoid spurious errors when analyzing the expanded code,
2100 -- this check is done only for nodes that come from source and for
2101 -- actuals of generic instantiations.
2102
2103 if (Comes_From_Source (Related_Nod)
2104 or else In_Generic_Actual (Expr))
2105 and then (Is_Class_Wide_Type (Etype (Expr))
2106 or else Is_Dynamically_Tagged (Expr))
2107 and then not Is_Class_Wide_Type (Typ)
2108 then
2109 Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
2110 end if;
2111 end Check_Dynamically_Tagged_Expression;
2112
2113 --------------------------
2114 -- Check_Fully_Declared --
2115 --------------------------
2116
2117 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
2118 begin
2119 if Ekind (T) = E_Incomplete_Type then
2120
2121 -- Ada 2005 (AI-50217): If the type is available through a limited
2122 -- with_clause, verify that its full view has been analyzed.
2123
2124 if From_Limited_With (T)
2125 and then Present (Non_Limited_View (T))
2126 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
2127 then
2128 -- The non-limited view is fully declared
2129
2130 null;
2131
2132 else
2133 Error_Msg_NE
2134 ("premature usage of incomplete}", N, First_Subtype (T));
2135 end if;
2136
2137 -- Need comments for these tests ???
2138
2139 elsif Has_Private_Component (T)
2140 and then not Is_Generic_Type (Root_Type (T))
2141 and then not In_Spec_Expression
2142 then
2143 -- Special case: if T is the anonymous type created for a single
2144 -- task or protected object, use the name of the source object.
2145
2146 if Is_Concurrent_Type (T)
2147 and then not Comes_From_Source (T)
2148 and then Nkind (N) = N_Object_Declaration
2149 then
2150 Error_Msg_NE
2151 ("type of& has incomplete component",
2152 N, Defining_Identifier (N));
2153 else
2154 Error_Msg_NE
2155 ("premature usage of incomplete}",
2156 N, First_Subtype (T));
2157 end if;
2158 end if;
2159 end Check_Fully_Declared;
2160
2161 -------------------------------------------
2162 -- Check_Function_With_Address_Parameter --
2163 -------------------------------------------
2164
2165 procedure Check_Function_With_Address_Parameter (Subp_Id : Entity_Id) is
2166 F : Entity_Id;
2167 T : Entity_Id;
2168
2169 begin
2170 F := First_Formal (Subp_Id);
2171 while Present (F) loop
2172 T := Etype (F);
2173
2174 if Is_Private_Type (T) and then Present (Full_View (T)) then
2175 T := Full_View (T);
2176 end if;
2177
2178 if Is_Descendant_Of_Address (T) or else Is_Limited_Type (T) then
2179 Set_Is_Pure (Subp_Id, False);
2180 exit;
2181 end if;
2182
2183 Next_Formal (F);
2184 end loop;
2185 end Check_Function_With_Address_Parameter;
2186
2187 -------------------------------------
2188 -- Check_Function_Writable_Actuals --
2189 -------------------------------------
2190
2191 procedure Check_Function_Writable_Actuals (N : Node_Id) is
2192 Writable_Actuals_List : Elist_Id := No_Elist;
2193 Identifiers_List : Elist_Id := No_Elist;
2194 Aggr_Error_Node : Node_Id := Empty;
2195 Error_Node : Node_Id := Empty;
2196
2197 procedure Collect_Identifiers (N : Node_Id);
2198 -- In a single traversal of subtree N collect in Writable_Actuals_List
2199 -- all the actuals of functions with writable actuals, and in the list
2200 -- Identifiers_List collect all the identifiers that are not actuals of
2201 -- functions with writable actuals. If a writable actual is referenced
2202 -- twice as writable actual then Error_Node is set to reference its
2203 -- second occurrence, the error is reported, and the tree traversal
2204 -- is abandoned.
2205
2206 procedure Preanalyze_Without_Errors (N : Node_Id);
2207 -- Preanalyze N without reporting errors. Very dubious, you can't just
2208 -- go analyzing things more than once???
2209
2210 -------------------------
2211 -- Collect_Identifiers --
2212 -------------------------
2213
2214 procedure Collect_Identifiers (N : Node_Id) is
2215
2216 function Check_Node (N : Node_Id) return Traverse_Result;
2217 -- Process a single node during the tree traversal to collect the
2218 -- writable actuals of functions and all the identifiers which are
2219 -- not writable actuals of functions.
2220
2221 function Contains (List : Elist_Id; N : Node_Id) return Boolean;
2222 -- Returns True if List has a node whose Entity is Entity (N)
2223
2224 ----------------
2225 -- Check_Node --
2226 ----------------
2227
2228 function Check_Node (N : Node_Id) return Traverse_Result is
2229 Is_Writable_Actual : Boolean := False;
2230 Id : Entity_Id;
2231
2232 begin
2233 if Nkind (N) = N_Identifier then
2234
2235 -- No analysis possible if the entity is not decorated
2236
2237 if No (Entity (N)) then
2238 return Skip;
2239
2240 -- Don't collect identifiers of packages, called functions, etc
2241
2242 elsif Ekind_In (Entity (N), E_Package,
2243 E_Function,
2244 E_Procedure,
2245 E_Entry)
2246 then
2247 return Skip;
2248
2249 -- For rewritten nodes, continue the traversal in the original
2250 -- subtree. Needed to handle aggregates in original expressions
2251 -- extracted from the tree by Remove_Side_Effects.
2252
2253 elsif Is_Rewrite_Substitution (N) then
2254 Collect_Identifiers (Original_Node (N));
2255 return Skip;
2256
2257 -- For now we skip aggregate discriminants, since they require
2258 -- performing the analysis in two phases to identify conflicts:
2259 -- first one analyzing discriminants and second one analyzing
2260 -- the rest of components (since at run time, discriminants are
2261 -- evaluated prior to components): too much computation cost
2262 -- to identify a corner case???
2263
2264 elsif Nkind (Parent (N)) = N_Component_Association
2265 and then Nkind_In (Parent (Parent (N)),
2266 N_Aggregate,
2267 N_Extension_Aggregate)
2268 then
2269 declare
2270 Choice : constant Node_Id := First (Choices (Parent (N)));
2271
2272 begin
2273 if Ekind (Entity (N)) = E_Discriminant then
2274 return Skip;
2275
2276 elsif Expression (Parent (N)) = N
2277 and then Nkind (Choice) = N_Identifier
2278 and then Ekind (Entity (Choice)) = E_Discriminant
2279 then
2280 return Skip;
2281 end if;
2282 end;
2283
2284 -- Analyze if N is a writable actual of a function
2285
2286 elsif Nkind (Parent (N)) = N_Function_Call then
2287 declare
2288 Call : constant Node_Id := Parent (N);
2289 Actual : Node_Id;
2290 Formal : Node_Id;
2291
2292 begin
2293 Id := Get_Called_Entity (Call);
2294
2295 -- In case of previous error, no check is possible
2296
2297 if No (Id) then
2298 return Abandon;
2299 end if;
2300
2301 if Ekind_In (Id, E_Function, E_Generic_Function)
2302 and then Has_Out_Or_In_Out_Parameter (Id)
2303 then
2304 Formal := First_Formal (Id);
2305 Actual := First_Actual (Call);
2306 while Present (Actual) and then Present (Formal) loop
2307 if Actual = N then
2308 if Ekind_In (Formal, E_Out_Parameter,
2309 E_In_Out_Parameter)
2310 then
2311 Is_Writable_Actual := True;
2312 end if;
2313
2314 exit;
2315 end if;
2316
2317 Next_Formal (Formal);
2318 Next_Actual (Actual);
2319 end loop;
2320 end if;
2321 end;
2322 end if;
2323
2324 if Is_Writable_Actual then
2325
2326 -- Skip checking the error in non-elementary types since
2327 -- RM 6.4.1(6.15/3) is restricted to elementary types, but
2328 -- store this actual in Writable_Actuals_List since it is
2329 -- needed to perform checks on other constructs that have
2330 -- arbitrary order of evaluation (for example, aggregates).
2331
2332 if not Is_Elementary_Type (Etype (N)) then
2333 if not Contains (Writable_Actuals_List, N) then
2334 Append_New_Elmt (N, To => Writable_Actuals_List);
2335 end if;
2336
2337 -- Second occurrence of an elementary type writable actual
2338
2339 elsif Contains (Writable_Actuals_List, N) then
2340
2341 -- Report the error on the second occurrence of the
2342 -- identifier. We cannot assume that N is the second
2343 -- occurrence (according to their location in the
2344 -- sources), since Traverse_Func walks through Field2
2345 -- last (see comment in the body of Traverse_Func).
2346
2347 declare
2348 Elmt : Elmt_Id;
2349
2350 begin
2351 Elmt := First_Elmt (Writable_Actuals_List);
2352 while Present (Elmt)
2353 and then Entity (Node (Elmt)) /= Entity (N)
2354 loop
2355 Next_Elmt (Elmt);
2356 end loop;
2357
2358 if Sloc (N) > Sloc (Node (Elmt)) then
2359 Error_Node := N;
2360 else
2361 Error_Node := Node (Elmt);
2362 end if;
2363
2364 Error_Msg_NE
2365 ("value may be affected by call to & "
2366 & "because order of evaluation is arbitrary",
2367 Error_Node, Id);
2368 return Abandon;
2369 end;
2370
2371 -- First occurrence of a elementary type writable actual
2372
2373 else
2374 Append_New_Elmt (N, To => Writable_Actuals_List);
2375 end if;
2376
2377 else
2378 if Identifiers_List = No_Elist then
2379 Identifiers_List := New_Elmt_List;
2380 end if;
2381
2382 Append_Unique_Elmt (N, Identifiers_List);
2383 end if;
2384 end if;
2385
2386 return OK;
2387 end Check_Node;
2388
2389 --------------
2390 -- Contains --
2391 --------------
2392
2393 function Contains
2394 (List : Elist_Id;
2395 N : Node_Id) return Boolean
2396 is
2397 pragma Assert (Nkind (N) in N_Has_Entity);
2398
2399 Elmt : Elmt_Id;
2400
2401 begin
2402 if List = No_Elist then
2403 return False;
2404 end if;
2405
2406 Elmt := First_Elmt (List);
2407 while Present (Elmt) loop
2408 if Entity (Node (Elmt)) = Entity (N) then
2409 return True;
2410 else
2411 Next_Elmt (Elmt);
2412 end if;
2413 end loop;
2414
2415 return False;
2416 end Contains;
2417
2418 ------------------
2419 -- Do_Traversal --
2420 ------------------
2421
2422 procedure Do_Traversal is new Traverse_Proc (Check_Node);
2423 -- The traversal procedure
2424
2425 -- Start of processing for Collect_Identifiers
2426
2427 begin
2428 if Present (Error_Node) then
2429 return;
2430 end if;
2431
2432 if Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then
2433 return;
2434 end if;
2435
2436 Do_Traversal (N);
2437 end Collect_Identifiers;
2438
2439 -------------------------------
2440 -- Preanalyze_Without_Errors --
2441 -------------------------------
2442
2443 procedure Preanalyze_Without_Errors (N : Node_Id) is
2444 Status : constant Boolean := Get_Ignore_Errors;
2445 begin
2446 Set_Ignore_Errors (True);
2447 Preanalyze (N);
2448 Set_Ignore_Errors (Status);
2449 end Preanalyze_Without_Errors;
2450
2451 -- Start of processing for Check_Function_Writable_Actuals
2452
2453 begin
2454 -- The check only applies to Ada 2012 code on which Check_Actuals has
2455 -- been set, and only to constructs that have multiple constituents
2456 -- whose order of evaluation is not specified by the language.
2457
2458 if Ada_Version < Ada_2012
2459 or else not Check_Actuals (N)
2460 or else (not (Nkind (N) in N_Op)
2461 and then not (Nkind (N) in N_Membership_Test)
2462 and then not Nkind_In (N, N_Range,
2463 N_Aggregate,
2464 N_Extension_Aggregate,
2465 N_Full_Type_Declaration,
2466 N_Function_Call,
2467 N_Procedure_Call_Statement,
2468 N_Entry_Call_Statement))
2469 or else (Nkind (N) = N_Full_Type_Declaration
2470 and then not Is_Record_Type (Defining_Identifier (N)))
2471
2472 -- In addition, this check only applies to source code, not to code
2473 -- generated by constraint checks.
2474
2475 or else not Comes_From_Source (N)
2476 then
2477 return;
2478 end if;
2479
2480 -- If a construct C has two or more direct constituents that are names
2481 -- or expressions whose evaluation may occur in an arbitrary order, at
2482 -- least one of which contains a function call with an in out or out
2483 -- parameter, then the construct is legal only if: for each name N that
2484 -- is passed as a parameter of mode in out or out to some inner function
2485 -- call C2 (not including the construct C itself), there is no other
2486 -- name anywhere within a direct constituent of the construct C other
2487 -- than the one containing C2, that is known to refer to the same
2488 -- object (RM 6.4.1(6.17/3)).
2489
2490 case Nkind (N) is
2491 when N_Range =>
2492 Collect_Identifiers (Low_Bound (N));
2493 Collect_Identifiers (High_Bound (N));
2494
2495 when N_Membership_Test
2496 | N_Op
2497 =>
2498 declare
2499 Expr : Node_Id;
2500
2501 begin
2502 Collect_Identifiers (Left_Opnd (N));
2503
2504 if Present (Right_Opnd (N)) then
2505 Collect_Identifiers (Right_Opnd (N));
2506 end if;
2507
2508 if Nkind_In (N, N_In, N_Not_In)
2509 and then Present (Alternatives (N))
2510 then
2511 Expr := First (Alternatives (N));
2512 while Present (Expr) loop
2513 Collect_Identifiers (Expr);
2514
2515 Next (Expr);
2516 end loop;
2517 end if;
2518 end;
2519
2520 when N_Full_Type_Declaration =>
2521 declare
2522 function Get_Record_Part (N : Node_Id) return Node_Id;
2523 -- Return the record part of this record type definition
2524
2525 function Get_Record_Part (N : Node_Id) return Node_Id is
2526 Type_Def : constant Node_Id := Type_Definition (N);
2527 begin
2528 if Nkind (Type_Def) = N_Derived_Type_Definition then
2529 return Record_Extension_Part (Type_Def);
2530 else
2531 return Type_Def;
2532 end if;
2533 end Get_Record_Part;
2534
2535 Comp : Node_Id;
2536 Def_Id : Entity_Id := Defining_Identifier (N);
2537 Rec : Node_Id := Get_Record_Part (N);
2538
2539 begin
2540 -- No need to perform any analysis if the record has no
2541 -- components
2542
2543 if No (Rec) or else No (Component_List (Rec)) then
2544 return;
2545 end if;
2546
2547 -- Collect the identifiers starting from the deepest
2548 -- derivation. Done to report the error in the deepest
2549 -- derivation.
2550
2551 loop
2552 if Present (Component_List (Rec)) then
2553 Comp := First (Component_Items (Component_List (Rec)));
2554 while Present (Comp) loop
2555 if Nkind (Comp) = N_Component_Declaration
2556 and then Present (Expression (Comp))
2557 then
2558 Collect_Identifiers (Expression (Comp));
2559 end if;
2560
2561 Next (Comp);
2562 end loop;
2563 end if;
2564
2565 exit when No (Underlying_Type (Etype (Def_Id)))
2566 or else Base_Type (Underlying_Type (Etype (Def_Id)))
2567 = Def_Id;
2568
2569 Def_Id := Base_Type (Underlying_Type (Etype (Def_Id)));
2570 Rec := Get_Record_Part (Parent (Def_Id));
2571 end loop;
2572 end;
2573
2574 when N_Entry_Call_Statement
2575 | N_Subprogram_Call
2576 =>
2577 declare
2578 Id : constant Entity_Id := Get_Called_Entity (N);
2579 Formal : Node_Id;
2580 Actual : Node_Id;
2581
2582 begin
2583 Formal := First_Formal (Id);
2584 Actual := First_Actual (N);
2585 while Present (Actual) and then Present (Formal) loop
2586 if Ekind_In (Formal, E_Out_Parameter,
2587 E_In_Out_Parameter)
2588 then
2589 Collect_Identifiers (Actual);
2590 end if;
2591
2592 Next_Formal (Formal);
2593 Next_Actual (Actual);
2594 end loop;
2595 end;
2596
2597 when N_Aggregate
2598 | N_Extension_Aggregate
2599 =>
2600 declare
2601 Assoc : Node_Id;
2602 Choice : Node_Id;
2603 Comp_Expr : Node_Id;
2604
2605 begin
2606 -- Handle the N_Others_Choice of array aggregates with static
2607 -- bounds. There is no need to perform this analysis in
2608 -- aggregates without static bounds since we cannot evaluate
2609 -- if the N_Others_Choice covers several elements. There is
2610 -- no need to handle the N_Others choice of record aggregates
2611 -- since at this stage it has been already expanded by
2612 -- Resolve_Record_Aggregate.
2613
2614 if Is_Array_Type (Etype (N))
2615 and then Nkind (N) = N_Aggregate
2616 and then Present (Aggregate_Bounds (N))
2617 and then Compile_Time_Known_Bounds (Etype (N))
2618 and then Expr_Value (High_Bound (Aggregate_Bounds (N)))
2619 >
2620 Expr_Value (Low_Bound (Aggregate_Bounds (N)))
2621 then
2622 declare
2623 Count_Components : Uint := Uint_0;
2624 Num_Components : Uint;
2625 Others_Assoc : Node_Id;
2626 Others_Choice : Node_Id := Empty;
2627 Others_Box_Present : Boolean := False;
2628
2629 begin
2630 -- Count positional associations
2631
2632 if Present (Expressions (N)) then
2633 Comp_Expr := First (Expressions (N));
2634 while Present (Comp_Expr) loop
2635 Count_Components := Count_Components + 1;
2636 Next (Comp_Expr);
2637 end loop;
2638 end if;
2639
2640 -- Count the rest of elements and locate the N_Others
2641 -- choice (if any)
2642
2643 Assoc := First (Component_Associations (N));
2644 while Present (Assoc) loop
2645 Choice := First (Choices (Assoc));
2646 while Present (Choice) loop
2647 if Nkind (Choice) = N_Others_Choice then
2648 Others_Assoc := Assoc;
2649 Others_Choice := Choice;
2650 Others_Box_Present := Box_Present (Assoc);
2651
2652 -- Count several components
2653
2654 elsif Nkind_In (Choice, N_Range,
2655 N_Subtype_Indication)
2656 or else (Is_Entity_Name (Choice)
2657 and then Is_Type (Entity (Choice)))
2658 then
2659 declare
2660 L, H : Node_Id;
2661 begin
2662 Get_Index_Bounds (Choice, L, H);
2663 pragma Assert
2664 (Compile_Time_Known_Value (L)
2665 and then Compile_Time_Known_Value (H));
2666 Count_Components :=
2667 Count_Components
2668 + Expr_Value (H) - Expr_Value (L) + 1;
2669 end;
2670
2671 -- Count single component. No other case available
2672 -- since we are handling an aggregate with static
2673 -- bounds.
2674
2675 else
2676 pragma Assert (Is_OK_Static_Expression (Choice)
2677 or else Nkind (Choice) = N_Identifier
2678 or else Nkind (Choice) = N_Integer_Literal);
2679
2680 Count_Components := Count_Components + 1;
2681 end if;
2682
2683 Next (Choice);
2684 end loop;
2685
2686 Next (Assoc);
2687 end loop;
2688
2689 Num_Components :=
2690 Expr_Value (High_Bound (Aggregate_Bounds (N))) -
2691 Expr_Value (Low_Bound (Aggregate_Bounds (N))) + 1;
2692
2693 pragma Assert (Count_Components <= Num_Components);
2694
2695 -- Handle the N_Others choice if it covers several
2696 -- components
2697
2698 if Present (Others_Choice)
2699 and then (Num_Components - Count_Components) > 1
2700 then
2701 if not Others_Box_Present then
2702
2703 -- At this stage, if expansion is active, the
2704 -- expression of the others choice has not been
2705 -- analyzed. Hence we generate a duplicate and
2706 -- we analyze it silently to have available the
2707 -- minimum decoration required to collect the
2708 -- identifiers.
2709
2710 if not Expander_Active then
2711 Comp_Expr := Expression (Others_Assoc);
2712 else
2713 Comp_Expr :=
2714 New_Copy_Tree (Expression (Others_Assoc));
2715 Preanalyze_Without_Errors (Comp_Expr);
2716 end if;
2717
2718 Collect_Identifiers (Comp_Expr);
2719
2720 if Writable_Actuals_List /= No_Elist then
2721
2722 -- As suggested by Robert, at current stage we
2723 -- report occurrences of this case as warnings.
2724
2725 Error_Msg_N
2726 ("writable function parameter may affect "
2727 & "value in other component because order "
2728 & "of evaluation is unspecified??",
2729 Node (First_Elmt (Writable_Actuals_List)));
2730 end if;
2731 end if;
2732 end if;
2733 end;
2734
2735 -- For an array aggregate, a discrete_choice_list that has
2736 -- a nonstatic range is considered as two or more separate
2737 -- occurrences of the expression (RM 6.4.1(20/3)).
2738
2739 elsif Is_Array_Type (Etype (N))
2740 and then Nkind (N) = N_Aggregate
2741 and then Present (Aggregate_Bounds (N))
2742 and then not Compile_Time_Known_Bounds (Etype (N))
2743 then
2744 -- Collect identifiers found in the dynamic bounds
2745
2746 declare
2747 Count_Components : Natural := 0;
2748 Low, High : Node_Id;
2749
2750 begin
2751 Assoc := First (Component_Associations (N));
2752 while Present (Assoc) loop
2753 Choice := First (Choices (Assoc));
2754 while Present (Choice) loop
2755 if Nkind_In (Choice, N_Range,
2756 N_Subtype_Indication)
2757 or else (Is_Entity_Name (Choice)
2758 and then Is_Type (Entity (Choice)))
2759 then
2760 Get_Index_Bounds (Choice, Low, High);
2761
2762 if not Compile_Time_Known_Value (Low) then
2763 Collect_Identifiers (Low);
2764
2765 if No (Aggr_Error_Node) then
2766 Aggr_Error_Node := Low;
2767 end if;
2768 end if;
2769
2770 if not Compile_Time_Known_Value (High) then
2771 Collect_Identifiers (High);
2772
2773 if No (Aggr_Error_Node) then
2774 Aggr_Error_Node := High;
2775 end if;
2776 end if;
2777
2778 -- The RM rule is violated if there is more than
2779 -- a single choice in a component association.
2780
2781 else
2782 Count_Components := Count_Components + 1;
2783
2784 if No (Aggr_Error_Node)
2785 and then Count_Components > 1
2786 then
2787 Aggr_Error_Node := Choice;
2788 end if;
2789
2790 if not Compile_Time_Known_Value (Choice) then
2791 Collect_Identifiers (Choice);
2792 end if;
2793 end if;
2794
2795 Next (Choice);
2796 end loop;
2797
2798 Next (Assoc);
2799 end loop;
2800 end;
2801 end if;
2802
2803 -- Handle ancestor part of extension aggregates
2804
2805 if Nkind (N) = N_Extension_Aggregate then
2806 Collect_Identifiers (Ancestor_Part (N));
2807 end if;
2808
2809 -- Handle positional associations
2810
2811 if Present (Expressions (N)) then
2812 Comp_Expr := First (Expressions (N));
2813 while Present (Comp_Expr) loop
2814 if not Is_OK_Static_Expression (Comp_Expr) then
2815 Collect_Identifiers (Comp_Expr);
2816 end if;
2817
2818 Next (Comp_Expr);
2819 end loop;
2820 end if;
2821
2822 -- Handle discrete associations
2823
2824 if Present (Component_Associations (N)) then
2825 Assoc := First (Component_Associations (N));
2826 while Present (Assoc) loop
2827
2828 if not Box_Present (Assoc) then
2829 Choice := First (Choices (Assoc));
2830 while Present (Choice) loop
2831
2832 -- For now we skip discriminants since it requires
2833 -- performing the analysis in two phases: first one
2834 -- analyzing discriminants and second one analyzing
2835 -- the rest of components since discriminants are
2836 -- evaluated prior to components: too much extra
2837 -- work to detect a corner case???
2838
2839 if Nkind (Choice) in N_Has_Entity
2840 and then Present (Entity (Choice))
2841 and then Ekind (Entity (Choice)) = E_Discriminant
2842 then
2843 null;
2844
2845 elsif Box_Present (Assoc) then
2846 null;
2847
2848 else
2849 if not Analyzed (Expression (Assoc)) then
2850 Comp_Expr :=
2851 New_Copy_Tree (Expression (Assoc));
2852 Set_Parent (Comp_Expr, Parent (N));
2853 Preanalyze_Without_Errors (Comp_Expr);
2854 else
2855 Comp_Expr := Expression (Assoc);
2856 end if;
2857
2858 Collect_Identifiers (Comp_Expr);
2859 end if;
2860
2861 Next (Choice);
2862 end loop;
2863 end if;
2864
2865 Next (Assoc);
2866 end loop;
2867 end if;
2868 end;
2869
2870 when others =>
2871 return;
2872 end case;
2873
2874 -- No further action needed if we already reported an error
2875
2876 if Present (Error_Node) then
2877 return;
2878 end if;
2879
2880 -- Check violation of RM 6.20/3 in aggregates
2881
2882 if Present (Aggr_Error_Node)
2883 and then Writable_Actuals_List /= No_Elist
2884 then
2885 Error_Msg_N
2886 ("value may be affected by call in other component because they "
2887 & "are evaluated in unspecified order",
2888 Node (First_Elmt (Writable_Actuals_List)));
2889 return;
2890 end if;
2891
2892 -- Check if some writable argument of a function is referenced
2893
2894 if Writable_Actuals_List /= No_Elist
2895 and then Identifiers_List /= No_Elist
2896 then
2897 declare
2898 Elmt_1 : Elmt_Id;
2899 Elmt_2 : Elmt_Id;
2900
2901 begin
2902 Elmt_1 := First_Elmt (Writable_Actuals_List);
2903 while Present (Elmt_1) loop
2904 Elmt_2 := First_Elmt (Identifiers_List);
2905 while Present (Elmt_2) loop
2906 if Entity (Node (Elmt_1)) = Entity (Node (Elmt_2)) then
2907 case Nkind (Parent (Node (Elmt_2))) is
2908 when N_Aggregate
2909 | N_Component_Association
2910 | N_Component_Declaration
2911 =>
2912 Error_Msg_N
2913 ("value may be affected by call in other "
2914 & "component because they are evaluated "
2915 & "in unspecified order",
2916 Node (Elmt_2));
2917
2918 when N_In
2919 | N_Not_In
2920 =>
2921 Error_Msg_N
2922 ("value may be affected by call in other "
2923 & "alternative because they are evaluated "
2924 & "in unspecified order",
2925 Node (Elmt_2));
2926
2927 when others =>
2928 Error_Msg_N
2929 ("value of actual may be affected by call in "
2930 & "other actual because they are evaluated "
2931 & "in unspecified order",
2932 Node (Elmt_2));
2933 end case;
2934 end if;
2935
2936 Next_Elmt (Elmt_2);
2937 end loop;
2938
2939 Next_Elmt (Elmt_1);
2940 end loop;
2941 end;
2942 end if;
2943 end Check_Function_Writable_Actuals;
2944
2945 --------------------------------
2946 -- Check_Implicit_Dereference --
2947 --------------------------------
2948
2949 procedure Check_Implicit_Dereference (N : Node_Id; Typ : Entity_Id) is
2950 Disc : Entity_Id;
2951 Desig : Entity_Id;
2952 Nam : Node_Id;
2953
2954 begin
2955 if Nkind (N) = N_Indexed_Component
2956 and then Present (Generalized_Indexing (N))
2957 then
2958 Nam := Generalized_Indexing (N);
2959 else
2960 Nam := N;
2961 end if;
2962
2963 if Ada_Version < Ada_2012
2964 or else not Has_Implicit_Dereference (Base_Type (Typ))
2965 then
2966 return;
2967
2968 elsif not Comes_From_Source (N)
2969 and then Nkind (N) /= N_Indexed_Component
2970 then
2971 return;
2972
2973 elsif Is_Entity_Name (Nam) and then Is_Type (Entity (Nam)) then
2974 null;
2975
2976 else
2977 Disc := First_Discriminant (Typ);
2978 while Present (Disc) loop
2979 if Has_Implicit_Dereference (Disc) then
2980 Desig := Designated_Type (Etype (Disc));
2981 Add_One_Interp (Nam, Disc, Desig);
2982
2983 -- If the node is a generalized indexing, add interpretation
2984 -- to that node as well, for subsequent resolution.
2985
2986 if Nkind (N) = N_Indexed_Component then
2987 Add_One_Interp (N, Disc, Desig);
2988 end if;
2989
2990 -- If the operation comes from a generic unit and the context
2991 -- is a selected component, the selector name may be global
2992 -- and set in the instance already. Remove the entity to
2993 -- force resolution of the selected component, and the
2994 -- generation of an explicit dereference if needed.
2995
2996 if In_Instance
2997 and then Nkind (Parent (Nam)) = N_Selected_Component
2998 then
2999 Set_Entity (Selector_Name (Parent (Nam)), Empty);
3000 end if;
3001
3002 exit;
3003 end if;
3004
3005 Next_Discriminant (Disc);
3006 end loop;
3007 end if;
3008 end Check_Implicit_Dereference;
3009
3010 ----------------------------------
3011 -- Check_Internal_Protected_Use --
3012 ----------------------------------
3013
3014 procedure Check_Internal_Protected_Use (N : Node_Id; Nam : Entity_Id) is
3015 S : Entity_Id;
3016 Prot : Entity_Id;
3017
3018 begin
3019 Prot := Empty;
3020
3021 S := Current_Scope;
3022 while Present (S) loop
3023 if S = Standard_Standard then
3024 exit;
3025
3026 elsif Ekind (S) = E_Function
3027 and then Ekind (Scope (S)) = E_Protected_Type
3028 then
3029 Prot := Scope (S);
3030 exit;
3031 end if;
3032
3033 S := Scope (S);
3034 end loop;
3035
3036 if Present (Prot)
3037 and then Scope (Nam) = Prot
3038 and then Ekind (Nam) /= E_Function
3039 then
3040 -- An indirect function call (e.g. a callback within a protected
3041 -- function body) is not statically illegal. If the access type is
3042 -- anonymous and is the type of an access parameter, the scope of Nam
3043 -- will be the protected type, but it is not a protected operation.
3044
3045 if Ekind (Nam) = E_Subprogram_Type
3046 and then Nkind (Associated_Node_For_Itype (Nam)) =
3047 N_Function_Specification
3048 then
3049 null;
3050
3051 elsif Nkind (N) = N_Subprogram_Renaming_Declaration then
3052 Error_Msg_N
3053 ("within protected function cannot use protected procedure in "
3054 & "renaming or as generic actual", N);
3055
3056 elsif Nkind (N) = N_Attribute_Reference then
3057 Error_Msg_N
3058 ("within protected function cannot take access of protected "
3059 & "procedure", N);
3060
3061 else
3062 Error_Msg_N
3063 ("within protected function, protected object is constant", N);
3064 Error_Msg_N
3065 ("\cannot call operation that may modify it", N);
3066 end if;
3067 end if;
3068
3069 -- Verify that an internal call does not appear within a precondition
3070 -- of a protected operation. This implements AI12-0166.
3071 -- The precondition aspect has been rewritten as a pragma Precondition
3072 -- and we check whether the scope of the called subprogram is the same
3073 -- as that of the entity to which the aspect applies.
3074
3075 if Convention (Nam) = Convention_Protected then
3076 declare
3077 P : Node_Id;
3078
3079 begin
3080 P := Parent (N);
3081 while Present (P) loop
3082 if Nkind (P) = N_Pragma
3083 and then Chars (Pragma_Identifier (P)) = Name_Precondition
3084 and then From_Aspect_Specification (P)
3085 and then
3086 Scope (Entity (Corresponding_Aspect (P))) = Scope (Nam)
3087 then
3088 Error_Msg_N
3089 ("internal call cannot appear in precondition of "
3090 & "protected operation", N);
3091 return;
3092
3093 elsif Nkind (P) = N_Pragma
3094 and then Chars (Pragma_Identifier (P)) = Name_Contract_Cases
3095 then
3096 -- Check whether call is in a case guard. It is legal in a
3097 -- consequence.
3098
3099 P := N;
3100 while Present (P) loop
3101 if Nkind (Parent (P)) = N_Component_Association
3102 and then P /= Expression (Parent (P))
3103 then
3104 Error_Msg_N
3105 ("internal call cannot appear in case guard in a "
3106 & "contract case", N);
3107 end if;
3108
3109 P := Parent (P);
3110 end loop;
3111
3112 return;
3113
3114 elsif Nkind (P) = N_Parameter_Specification
3115 and then Scope (Current_Scope) = Scope (Nam)
3116 and then Nkind_In (Parent (P), N_Entry_Declaration,
3117 N_Subprogram_Declaration)
3118 then
3119 Error_Msg_N
3120 ("internal call cannot appear in default for formal of "
3121 & "protected operation", N);
3122 return;
3123 end if;
3124
3125 P := Parent (P);
3126 end loop;
3127 end;
3128 end if;
3129 end Check_Internal_Protected_Use;
3130
3131 ---------------------------------------
3132 -- Check_Later_Vs_Basic_Declarations --
3133 ---------------------------------------
3134
3135 procedure Check_Later_Vs_Basic_Declarations
3136 (Decls : List_Id;
3137 During_Parsing : Boolean)
3138 is
3139 Body_Sloc : Source_Ptr;
3140 Decl : Node_Id;
3141
3142 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean;
3143 -- Return whether Decl is considered as a declarative item.
3144 -- When During_Parsing is True, the semantics of Ada 83 is followed.
3145 -- When During_Parsing is False, the semantics of SPARK is followed.
3146
3147 -------------------------------
3148 -- Is_Later_Declarative_Item --
3149 -------------------------------
3150
3151 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean is
3152 begin
3153 if Nkind (Decl) in N_Later_Decl_Item then
3154 return True;
3155
3156 elsif Nkind (Decl) = N_Pragma then
3157 return True;
3158
3159 elsif During_Parsing then
3160 return False;
3161
3162 -- In SPARK, a package declaration is not considered as a later
3163 -- declarative item.
3164
3165 elsif Nkind (Decl) = N_Package_Declaration then
3166 return False;
3167
3168 -- In SPARK, a renaming is considered as a later declarative item
3169
3170 elsif Nkind (Decl) in N_Renaming_Declaration then
3171 return True;
3172
3173 else
3174 return False;
3175 end if;
3176 end Is_Later_Declarative_Item;
3177
3178 -- Start of processing for Check_Later_Vs_Basic_Declarations
3179
3180 begin
3181 Decl := First (Decls);
3182
3183 -- Loop through sequence of basic declarative items
3184
3185 Outer : while Present (Decl) loop
3186 if not Nkind_In (Decl, N_Subprogram_Body, N_Package_Body, N_Task_Body)
3187 and then Nkind (Decl) not in N_Body_Stub
3188 then
3189 Next (Decl);
3190
3191 -- Once a body is encountered, we only allow later declarative
3192 -- items. The inner loop checks the rest of the list.
3193
3194 else
3195 Body_Sloc := Sloc (Decl);
3196
3197 Inner : while Present (Decl) loop
3198 if not Is_Later_Declarative_Item (Decl) then
3199 if During_Parsing then
3200 if Ada_Version = Ada_83 then
3201 Error_Msg_Sloc := Body_Sloc;
3202 Error_Msg_N
3203 ("(Ada 83) decl cannot appear after body#", Decl);
3204 end if;
3205 else
3206 Error_Msg_Sloc := Body_Sloc;
3207 Check_SPARK_05_Restriction
3208 ("decl cannot appear after body#", Decl);
3209 end if;
3210 end if;
3211
3212 Next (Decl);
3213 end loop Inner;
3214 end if;
3215 end loop Outer;
3216 end Check_Later_Vs_Basic_Declarations;
3217
3218 ---------------------------
3219 -- Check_No_Hidden_State --
3220 ---------------------------
3221
3222 procedure Check_No_Hidden_State (Id : Entity_Id) is
3223 Context : Entity_Id := Empty;
3224 Not_Visible : Boolean := False;
3225 Scop : Entity_Id;
3226
3227 begin
3228 pragma Assert (Ekind_In (Id, E_Abstract_State, E_Variable));
3229
3230 -- Nothing to do for internally-generated abstract states and variables
3231 -- because they do not represent the hidden state of the source unit.
3232
3233 if not Comes_From_Source (Id) then
3234 return;
3235 end if;
3236
3237 -- Find the proper context where the object or state appears
3238
3239 Scop := Scope (Id);
3240 while Present (Scop) loop
3241 Context := Scop;
3242
3243 -- Keep track of the context's visibility
3244
3245 Not_Visible := Not_Visible or else In_Private_Part (Context);
3246
3247 -- Prevent the search from going too far
3248
3249 if Context = Standard_Standard then
3250 return;
3251
3252 -- Objects and states that appear immediately within a subprogram or
3253 -- inside a construct nested within a subprogram do not introduce a
3254 -- hidden state. They behave as local variable declarations.
3255
3256 elsif Is_Subprogram (Context) then
3257 return;
3258
3259 -- When examining a package body, use the entity of the spec as it
3260 -- carries the abstract state declarations.
3261
3262 elsif Ekind (Context) = E_Package_Body then
3263 Context := Spec_Entity (Context);
3264 end if;
3265
3266 -- Stop the traversal when a package subject to a null abstract state
3267 -- has been found.
3268
3269 if Ekind_In (Context, E_Generic_Package, E_Package)
3270 and then Has_Null_Abstract_State (Context)
3271 then
3272 exit;
3273 end if;
3274
3275 Scop := Scope (Scop);
3276 end loop;
3277
3278 -- At this point we know that there is at least one package with a null
3279 -- abstract state in visibility. Emit an error message unconditionally
3280 -- if the entity being processed is a state because the placement of the
3281 -- related package is irrelevant. This is not the case for objects as
3282 -- the intermediate context matters.
3283
3284 if Present (Context)
3285 and then (Ekind (Id) = E_Abstract_State or else Not_Visible)
3286 then
3287 Error_Msg_N ("cannot introduce hidden state &", Id);
3288 Error_Msg_NE ("\package & has null abstract state", Id, Context);
3289 end if;
3290 end Check_No_Hidden_State;
3291
3292 ----------------------------------------
3293 -- Check_Nonvolatile_Function_Profile --
3294 ----------------------------------------
3295
3296 procedure Check_Nonvolatile_Function_Profile (Func_Id : Entity_Id) is
3297 Formal : Entity_Id;
3298
3299 begin
3300 -- Inspect all formal parameters
3301
3302 Formal := First_Formal (Func_Id);
3303 while Present (Formal) loop
3304 if Is_Effectively_Volatile (Etype (Formal)) then
3305 Error_Msg_NE
3306 ("nonvolatile function & cannot have a volatile parameter",
3307 Formal, Func_Id);
3308 end if;
3309
3310 Next_Formal (Formal);
3311 end loop;
3312
3313 -- Inspect the return type
3314
3315 if Is_Effectively_Volatile (Etype (Func_Id)) then
3316 Error_Msg_NE
3317 ("nonvolatile function & cannot have a volatile return type",
3318 Result_Definition (Parent (Func_Id)), Func_Id);
3319 end if;
3320 end Check_Nonvolatile_Function_Profile;
3321
3322 -----------------------------
3323 -- Check_Part_Of_Reference --
3324 -----------------------------
3325
3326 procedure Check_Part_Of_Reference (Var_Id : Entity_Id; Ref : Node_Id) is
3327 function Is_Enclosing_Package_Body
3328 (Body_Decl : Node_Id;
3329 Obj_Id : Entity_Id) return Boolean;
3330 pragma Inline (Is_Enclosing_Package_Body);
3331 -- Determine whether package body Body_Decl or its corresponding spec
3332 -- immediately encloses the declaration of object Obj_Id.
3333
3334 function Is_Internal_Declaration_Or_Body
3335 (Decl : Node_Id) return Boolean;
3336 pragma Inline (Is_Internal_Declaration_Or_Body);
3337 -- Determine whether declaration or body denoted by Decl is internal
3338
3339 function Is_Single_Declaration_Or_Body
3340 (Decl : Node_Id;
3341 Conc_Typ : Entity_Id) return Boolean;
3342 pragma Inline (Is_Single_Declaration_Or_Body);
3343 -- Determine whether protected/task declaration or body denoted by Decl
3344 -- belongs to single concurrent type Conc_Typ.
3345
3346 function Is_Single_Task_Pragma
3347 (Prag : Node_Id;
3348 Task_Typ : Entity_Id) return Boolean;
3349 pragma Inline (Is_Single_Task_Pragma);
3350 -- Determine whether pragma Prag belongs to single task type Task_Typ
3351
3352 -------------------------------
3353 -- Is_Enclosing_Package_Body --
3354 -------------------------------
3355
3356 function Is_Enclosing_Package_Body
3357 (Body_Decl : Node_Id;
3358 Obj_Id : Entity_Id) return Boolean
3359 is
3360 Obj_Context : Node_Id;
3361
3362 begin
3363 -- Find the context of the object declaration
3364
3365 Obj_Context := Parent (Declaration_Node (Obj_Id));
3366
3367 if Nkind (Obj_Context) = N_Package_Specification then
3368 Obj_Context := Parent (Obj_Context);
3369 end if;
3370
3371 -- The object appears immediately within the package body
3372
3373 if Obj_Context = Body_Decl then
3374 return True;
3375
3376 -- The object appears immediately within the corresponding spec
3377
3378 elsif Nkind (Obj_Context) = N_Package_Declaration
3379 and then Unit_Declaration_Node (Corresponding_Spec (Body_Decl)) =
3380 Obj_Context
3381 then
3382 return True;
3383 end if;
3384
3385 return False;
3386 end Is_Enclosing_Package_Body;
3387
3388 -------------------------------------
3389 -- Is_Internal_Declaration_Or_Body --
3390 -------------------------------------
3391
3392 function Is_Internal_Declaration_Or_Body
3393 (Decl : Node_Id) return Boolean
3394 is
3395 begin
3396 if Comes_From_Source (Decl) then
3397 return False;
3398
3399 -- A body generated for an expression function which has not been
3400 -- inserted into the tree yet (In_Spec_Expression is True) is not
3401 -- considered internal.
3402
3403 elsif Nkind (Decl) = N_Subprogram_Body
3404 and then Was_Expression_Function (Decl)
3405 and then not In_Spec_Expression
3406 then
3407 return False;
3408 end if;
3409
3410 return True;
3411 end Is_Internal_Declaration_Or_Body;
3412
3413 -----------------------------------
3414 -- Is_Single_Declaration_Or_Body --
3415 -----------------------------------
3416
3417 function Is_Single_Declaration_Or_Body
3418 (Decl : Node_Id;
3419 Conc_Typ : Entity_Id) return Boolean
3420 is
3421 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Decl);
3422
3423 begin
3424 return
3425 Present (Anonymous_Object (Spec_Id))
3426 and then Anonymous_Object (Spec_Id) = Conc_Typ;
3427 end Is_Single_Declaration_Or_Body;
3428
3429 ---------------------------
3430 -- Is_Single_Task_Pragma --
3431 ---------------------------
3432
3433 function Is_Single_Task_Pragma
3434 (Prag : Node_Id;
3435 Task_Typ : Entity_Id) return Boolean
3436 is
3437 Decl : constant Node_Id := Find_Related_Declaration_Or_Body (Prag);
3438
3439 begin
3440 -- To qualify, the pragma must be associated with single task type
3441 -- Task_Typ.
3442
3443 return
3444 Is_Single_Task_Object (Task_Typ)
3445 and then Nkind (Decl) = N_Object_Declaration
3446 and then Defining_Entity (Decl) = Task_Typ;
3447 end Is_Single_Task_Pragma;
3448
3449 -- Local variables
3450
3451 Conc_Obj : constant Entity_Id := Encapsulating_State (Var_Id);
3452 Par : Node_Id;
3453 Prag_Nam : Name_Id;
3454 Prev : Node_Id;
3455
3456 -- Start of processing for Check_Part_Of_Reference
3457
3458 begin
3459 -- Nothing to do when the variable was recorded, but did not become a
3460 -- constituent of a single concurrent type.
3461
3462 if No (Conc_Obj) then
3463 return;
3464 end if;
3465
3466 -- Traverse the parent chain looking for a suitable context for the
3467 -- reference to the concurrent constituent.
3468
3469 Prev := Ref;
3470 Par := Parent (Prev);
3471 while Present (Par) loop
3472 if Nkind (Par) = N_Pragma then
3473 Prag_Nam := Pragma_Name (Par);
3474
3475 -- A concurrent constituent is allowed to appear in pragmas
3476 -- Initial_Condition and Initializes as this is part of the
3477 -- elaboration checks for the constituent (SPARK RM 9(3)).
3478
3479 if Nam_In (Prag_Nam, Name_Initial_Condition, Name_Initializes) then
3480 return;
3481
3482 -- When the reference appears within pragma Depends or Global,
3483 -- check whether the pragma applies to a single task type. Note
3484 -- that the pragma may not encapsulated by the type definition,
3485 -- but this is still a valid context.
3486
3487 elsif Nam_In (Prag_Nam, Name_Depends, Name_Global)
3488 and then Is_Single_Task_Pragma (Par, Conc_Obj)
3489 then
3490 return;
3491 end if;
3492
3493 -- The reference appears somewhere in the definition of a single
3494 -- concurrent type (SPARK RM 9(3)).
3495
3496 elsif Nkind_In (Par, N_Single_Protected_Declaration,
3497 N_Single_Task_Declaration)
3498 and then Defining_Entity (Par) = Conc_Obj
3499 then
3500 return;
3501
3502 -- The reference appears within the declaration or body of a single
3503 -- concurrent type (SPARK RM 9(3)).
3504
3505 elsif Nkind_In (Par, N_Protected_Body,
3506 N_Protected_Type_Declaration,
3507 N_Task_Body,
3508 N_Task_Type_Declaration)
3509 and then Is_Single_Declaration_Or_Body (Par, Conc_Obj)
3510 then
3511 return;
3512
3513 -- The reference appears within the statement list of the object's
3514 -- immediately enclosing package (SPARK RM 9(3)).
3515
3516 elsif Nkind (Par) = N_Package_Body
3517 and then Nkind (Prev) = N_Handled_Sequence_Of_Statements
3518 and then Is_Enclosing_Package_Body (Par, Var_Id)
3519 then
3520 return;
3521
3522 -- The reference has been relocated within an internally generated
3523 -- package or subprogram. Assume that the reference is legal as the
3524 -- real check was already performed in the original context of the
3525 -- reference.
3526
3527 elsif Nkind_In (Par, N_Package_Body,
3528 N_Package_Declaration,
3529 N_Subprogram_Body,
3530 N_Subprogram_Declaration)
3531 and then Is_Internal_Declaration_Or_Body (Par)
3532 then
3533 return;
3534
3535 -- The reference has been relocated to an inlined body for GNATprove.
3536 -- Assume that the reference is legal as the real check was already
3537 -- performed in the original context of the reference.
3538
3539 elsif GNATprove_Mode
3540 and then Nkind (Par) = N_Subprogram_Body
3541 and then Chars (Defining_Entity (Par)) = Name_uParent
3542 then
3543 return;
3544 end if;
3545
3546 Prev := Par;
3547 Par := Parent (Prev);
3548 end loop;
3549
3550 -- At this point it is known that the reference does not appear within a
3551 -- legal context.
3552
3553 Error_Msg_NE
3554 ("reference to variable & cannot appear in this context", Ref, Var_Id);
3555 Error_Msg_Name_1 := Chars (Var_Id);
3556
3557 if Is_Single_Protected_Object (Conc_Obj) then
3558 Error_Msg_NE
3559 ("\% is constituent of single protected type &", Ref, Conc_Obj);
3560
3561 else
3562 Error_Msg_NE
3563 ("\% is constituent of single task type &", Ref, Conc_Obj);
3564 end if;
3565 end Check_Part_Of_Reference;
3566
3567 ------------------------------------------
3568 -- Check_Potentially_Blocking_Operation --
3569 ------------------------------------------
3570
3571 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
3572 S : Entity_Id;
3573
3574 begin
3575 -- N is one of the potentially blocking operations listed in 9.5.1(8).
3576 -- When pragma Detect_Blocking is active, the run time will raise
3577 -- Program_Error. Here we only issue a warning, since we generally
3578 -- support the use of potentially blocking operations in the absence
3579 -- of the pragma.
3580
3581 -- Indirect blocking through a subprogram call cannot be diagnosed
3582 -- statically without interprocedural analysis, so we do not attempt
3583 -- to do it here.
3584
3585 S := Scope (Current_Scope);
3586 while Present (S) and then S /= Standard_Standard loop
3587 if Is_Protected_Type (S) then
3588 Error_Msg_N
3589 ("potentially blocking operation in protected operation??", N);
3590 return;
3591 end if;
3592
3593 S := Scope (S);
3594 end loop;
3595 end Check_Potentially_Blocking_Operation;
3596
3597 ------------------------------------
3598 -- Check_Previous_Null_Procedure --
3599 ------------------------------------
3600
3601 procedure Check_Previous_Null_Procedure
3602 (Decl : Node_Id;
3603 Prev : Entity_Id)
3604 is
3605 begin
3606 if Ekind (Prev) = E_Procedure
3607 and then Nkind (Parent (Prev)) = N_Procedure_Specification
3608 and then Null_Present (Parent (Prev))
3609 then
3610 Error_Msg_Sloc := Sloc (Prev);
3611 Error_Msg_N
3612 ("declaration cannot complete previous null procedure#", Decl);
3613 end if;
3614 end Check_Previous_Null_Procedure;
3615
3616 ---------------------------------
3617 -- Check_Result_And_Post_State --
3618 ---------------------------------
3619
3620 procedure Check_Result_And_Post_State (Subp_Id : Entity_Id) is
3621 procedure Check_Result_And_Post_State_In_Pragma
3622 (Prag : Node_Id;
3623 Result_Seen : in out Boolean);
3624 -- Determine whether pragma Prag mentions attribute 'Result and whether
3625 -- the pragma contains an expression that evaluates differently in pre-
3626 -- and post-state. Prag is a [refined] postcondition or a contract-cases
3627 -- pragma. Result_Seen is set when the pragma mentions attribute 'Result
3628
3629 function Has_In_Out_Parameter (Subp_Id : Entity_Id) return Boolean;
3630 -- Determine whether subprogram Subp_Id contains at least one IN OUT
3631 -- formal parameter.
3632
3633 -------------------------------------------
3634 -- Check_Result_And_Post_State_In_Pragma --
3635 -------------------------------------------
3636
3637 procedure Check_Result_And_Post_State_In_Pragma
3638 (Prag : Node_Id;
3639 Result_Seen : in out Boolean)
3640 is
3641 procedure Check_Conjunct (Expr : Node_Id);
3642 -- Check an individual conjunct in a conjunction of Boolean
3643 -- expressions, connected by "and" or "and then" operators.
3644
3645 procedure Check_Conjuncts (Expr : Node_Id);
3646 -- Apply the post-state check to every conjunct in an expression, in
3647 -- case this is a conjunction of Boolean expressions. Otherwise apply
3648 -- it to the expression as a whole.
3649
3650 procedure Check_Expression (Expr : Node_Id);
3651 -- Perform the 'Result and post-state checks on a given expression
3652
3653 function Is_Function_Result (N : Node_Id) return Traverse_Result;
3654 -- Attempt to find attribute 'Result in a subtree denoted by N
3655
3656 function Is_Trivial_Boolean (N : Node_Id) return Boolean;
3657 -- Determine whether source node N denotes "True" or "False"
3658
3659 function Mentions_Post_State (N : Node_Id) return Boolean;
3660 -- Determine whether a subtree denoted by N mentions any construct
3661 -- that denotes a post-state.
3662
3663 procedure Check_Function_Result is
3664 new Traverse_Proc (Is_Function_Result);
3665
3666 --------------------
3667 -- Check_Conjunct --
3668 --------------------
3669
3670 procedure Check_Conjunct (Expr : Node_Id) is
3671 function Adjust_Message (Msg : String) return String;
3672 -- Prepend a prefix to the input message Msg denoting that the
3673 -- message applies to a conjunct in the expression, when this
3674 -- is the case.
3675
3676 function Applied_On_Conjunct return Boolean;
3677 -- Returns True if the message applies to a conjunct in the
3678 -- expression, instead of the whole expression.
3679
3680 function Has_Global_Output (Subp : Entity_Id) return Boolean;
3681 -- Returns True if Subp has an output in its Global contract
3682
3683 function Has_No_Output (Subp : Entity_Id) return Boolean;
3684 -- Returns True if Subp has no declared output: no function
3685 -- result, no output parameter, and no output in its Global
3686 -- contract.
3687
3688 --------------------
3689 -- Adjust_Message --
3690 --------------------
3691
3692 function Adjust_Message (Msg : String) return String is
3693 begin
3694 if Applied_On_Conjunct then
3695 return "conjunct in " & Msg;
3696 else
3697 return Msg;
3698 end if;
3699 end Adjust_Message;
3700
3701 -------------------------
3702 -- Applied_On_Conjunct --
3703 -------------------------
3704
3705 function Applied_On_Conjunct return Boolean is
3706 begin
3707 -- Expr is the conjunct of an enclosing "and" expression
3708
3709 return Nkind (Parent (Expr)) in N_Subexpr
3710
3711 -- or Expr is a conjunct of an enclosing "and then"
3712 -- expression in a postcondition aspect that was split into
3713 -- multiple pragmas. The first conjunct has the "and then"
3714 -- expression as Original_Node, and other conjuncts have
3715 -- Split_PCC set to True.
3716
3717 or else Nkind (Original_Node (Expr)) = N_And_Then
3718 or else Split_PPC (Prag);
3719 end Applied_On_Conjunct;
3720
3721 -----------------------
3722 -- Has_Global_Output --
3723 -----------------------
3724
3725 function Has_Global_Output (Subp : Entity_Id) return Boolean is
3726 Global : constant Node_Id := Get_Pragma (Subp, Pragma_Global);
3727 List : Node_Id;
3728 Assoc : Node_Id;
3729
3730 begin
3731 if No (Global) then
3732 return False;
3733 end if;
3734
3735 List := Expression (Get_Argument (Global, Subp));
3736
3737 -- Empty list (no global items) or single global item
3738 -- declaration (only input items).
3739
3740 if Nkind_In (List, N_Null,
3741 N_Expanded_Name,
3742 N_Identifier,
3743 N_Selected_Component)
3744 then
3745 return False;
3746
3747 -- Simple global list (only input items) or moded global list
3748 -- declaration.
3749
3750 elsif Nkind (List) = N_Aggregate then
3751 if Present (Expressions (List)) then
3752 return False;
3753
3754 else
3755 Assoc := First (Component_Associations (List));
3756 while Present (Assoc) loop
3757 if Chars (First (Choices (Assoc))) /= Name_Input then
3758 return True;
3759 end if;
3760
3761 Next (Assoc);
3762 end loop;
3763
3764 return False;
3765 end if;
3766
3767 -- To accommodate partial decoration of disabled SPARK
3768 -- features, this routine may be called with illegal input.
3769 -- If this is the case, do not raise Program_Error.
3770
3771 else
3772 return False;
3773 end if;
3774 end Has_Global_Output;
3775
3776 -------------------
3777 -- Has_No_Output --
3778 -------------------
3779
3780 function Has_No_Output (Subp : Entity_Id) return Boolean is
3781 Param : Node_Id;
3782
3783 begin
3784 -- A function has its result as output
3785
3786 if Ekind (Subp) = E_Function then
3787 return False;
3788 end if;
3789
3790 -- An OUT or IN OUT parameter is an output
3791
3792 Param := First_Formal (Subp);
3793 while Present (Param) loop
3794 if Ekind_In (Param, E_Out_Parameter, E_In_Out_Parameter) then
3795 return False;
3796 end if;
3797
3798 Next_Formal (Param);
3799 end loop;
3800
3801 -- An item of mode Output or In_Out in the Global contract is
3802 -- an output.
3803
3804 if Has_Global_Output (Subp) then
3805 return False;
3806 end if;
3807
3808 return True;
3809 end Has_No_Output;
3810
3811 -- Local variables
3812
3813 Err_Node : Node_Id;
3814 -- Error node when reporting a warning on a (refined)
3815 -- postcondition.
3816
3817 -- Start of processing for Check_Conjunct
3818
3819 begin
3820 if Applied_On_Conjunct then
3821 Err_Node := Expr;
3822 else
3823 Err_Node := Prag;
3824 end if;
3825
3826 -- Do not report missing reference to outcome in postcondition if
3827 -- either the postcondition is trivially True or False, or if the
3828 -- subprogram is ghost and has no declared output.
3829
3830 if not Is_Trivial_Boolean (Expr)
3831 and then not Mentions_Post_State (Expr)
3832 and then not (Is_Ghost_Entity (Subp_Id)
3833 and then Has_No_Output (Subp_Id))
3834 then
3835 if Pragma_Name (Prag) = Name_Contract_Cases then
3836 Error_Msg_NE (Adjust_Message
3837 ("contract case does not check the outcome of calling "
3838 & "&?T?"), Expr, Subp_Id);
3839
3840 elsif Pragma_Name (Prag) = Name_Refined_Post then
3841 Error_Msg_NE (Adjust_Message
3842 ("refined postcondition does not check the outcome of "
3843 & "calling &?T?"), Err_Node, Subp_Id);
3844
3845 else
3846 Error_Msg_NE (Adjust_Message
3847 ("postcondition does not check the outcome of calling "
3848 & "&?T?"), Err_Node, Subp_Id);
3849 end if;
3850 end if;
3851 end Check_Conjunct;
3852
3853 ---------------------
3854 -- Check_Conjuncts --
3855 ---------------------
3856
3857 procedure Check_Conjuncts (Expr : Node_Id) is
3858 begin
3859 if Nkind_In (Expr, N_Op_And, N_And_Then) then
3860 Check_Conjuncts (Left_Opnd (Expr));
3861 Check_Conjuncts (Right_Opnd (Expr));
3862 else
3863 Check_Conjunct (Expr);
3864 end if;
3865 end Check_Conjuncts;
3866
3867 ----------------------
3868 -- Check_Expression --
3869 ----------------------
3870
3871 procedure Check_Expression (Expr : Node_Id) is
3872 begin
3873 if not Is_Trivial_Boolean (Expr) then
3874 Check_Function_Result (Expr);
3875 Check_Conjuncts (Expr);
3876 end if;
3877 end Check_Expression;
3878
3879 ------------------------
3880 -- Is_Function_Result --
3881 ------------------------
3882
3883 function Is_Function_Result (N : Node_Id) return Traverse_Result is
3884 begin
3885 if Is_Attribute_Result (N) then
3886 Result_Seen := True;
3887 return Abandon;
3888
3889 -- Warn on infinite recursion if call is to current function
3890
3891 elsif Nkind (N) = N_Function_Call
3892 and then Is_Entity_Name (Name (N))
3893 and then Entity (Name (N)) = Subp_Id
3894 and then not Is_Potentially_Unevaluated (N)
3895 then
3896 Error_Msg_NE
3897 ("call to & within its postcondition will lead to infinite "
3898 & "recursion?", N, Subp_Id);
3899 return OK;
3900
3901 -- Continue the traversal
3902
3903 else
3904 return OK;
3905 end if;
3906 end Is_Function_Result;
3907
3908 ------------------------
3909 -- Is_Trivial_Boolean --
3910 ------------------------
3911
3912 function Is_Trivial_Boolean (N : Node_Id) return Boolean is
3913 begin
3914 return
3915 Comes_From_Source (N)
3916 and then Is_Entity_Name (N)
3917 and then (Entity (N) = Standard_True
3918 or else
3919 Entity (N) = Standard_False);
3920 end Is_Trivial_Boolean;
3921
3922 -------------------------
3923 -- Mentions_Post_State --
3924 -------------------------
3925
3926 function Mentions_Post_State (N : Node_Id) return Boolean is
3927 Post_State_Seen : Boolean := False;
3928
3929 function Is_Post_State (N : Node_Id) return Traverse_Result;
3930 -- Attempt to find a construct that denotes a post-state. If this
3931 -- is the case, set flag Post_State_Seen.
3932
3933 -------------------
3934 -- Is_Post_State --
3935 -------------------
3936
3937 function Is_Post_State (N : Node_Id) return Traverse_Result is
3938 Ent : Entity_Id;
3939
3940 begin
3941 if Nkind_In (N, N_Explicit_Dereference, N_Function_Call) then
3942 Post_State_Seen := True;
3943 return Abandon;
3944
3945 elsif Nkind_In (N, N_Expanded_Name, N_Identifier) then
3946 Ent := Entity (N);
3947
3948 -- Treat an undecorated reference as OK
3949
3950 if No (Ent)
3951
3952 -- A reference to an assignable entity is considered a
3953 -- change in the post-state of a subprogram.
3954
3955 or else Ekind_In (Ent, E_Generic_In_Out_Parameter,
3956 E_In_Out_Parameter,
3957 E_Out_Parameter,
3958 E_Variable)
3959
3960 -- The reference may be modified through a dereference
3961
3962 or else (Is_Access_Type (Etype (Ent))
3963 and then Nkind (Parent (N)) =
3964 N_Selected_Component)
3965 then
3966 Post_State_Seen := True;
3967 return Abandon;
3968 end if;
3969
3970 elsif Nkind (N) = N_Attribute_Reference then
3971 if Attribute_Name (N) = Name_Old then
3972 return Skip;
3973
3974 elsif Attribute_Name (N) = Name_Result then
3975 Post_State_Seen := True;
3976 return Abandon;
3977 end if;
3978 end if;
3979
3980 return OK;
3981 end Is_Post_State;
3982
3983 procedure Find_Post_State is new Traverse_Proc (Is_Post_State);
3984
3985 -- Start of processing for Mentions_Post_State
3986
3987 begin
3988 Find_Post_State (N);
3989
3990 return Post_State_Seen;
3991 end Mentions_Post_State;
3992
3993 -- Local variables
3994
3995 Expr : constant Node_Id :=
3996 Get_Pragma_Arg
3997 (First (Pragma_Argument_Associations (Prag)));
3998 Nam : constant Name_Id := Pragma_Name (Prag);
3999 CCase : Node_Id;
4000
4001 -- Start of processing for Check_Result_And_Post_State_In_Pragma
4002
4003 begin
4004 -- Examine all consequences
4005
4006 if Nam = Name_Contract_Cases then
4007 CCase := First (Component_Associations (Expr));
4008 while Present (CCase) loop
4009 Check_Expression (Expression (CCase));
4010
4011 Next (CCase);
4012 end loop;
4013
4014 -- Examine the expression of a postcondition
4015
4016 else pragma Assert (Nam_In (Nam, Name_Postcondition,
4017 Name_Refined_Post));
4018 Check_Expression (Expr);
4019 end if;
4020 end Check_Result_And_Post_State_In_Pragma;
4021
4022 --------------------------
4023 -- Has_In_Out_Parameter --
4024 --------------------------
4025
4026 function Has_In_Out_Parameter (Subp_Id : Entity_Id) return Boolean is
4027 Formal : Entity_Id;
4028
4029 begin
4030 -- Traverse the formals looking for an IN OUT parameter
4031
4032 Formal := First_Formal (Subp_Id);
4033 while Present (Formal) loop
4034 if Ekind (Formal) = E_In_Out_Parameter then
4035 return True;
4036 end if;
4037
4038 Next_Formal (Formal);
4039 end loop;
4040
4041 return False;
4042 end Has_In_Out_Parameter;
4043
4044 -- Local variables
4045
4046 Items : constant Node_Id := Contract (Subp_Id);
4047 Subp_Decl : constant Node_Id := Unit_Declaration_Node (Subp_Id);
4048 Case_Prag : Node_Id := Empty;
4049 Post_Prag : Node_Id := Empty;
4050 Prag : Node_Id;
4051 Seen_In_Case : Boolean := False;
4052 Seen_In_Post : Boolean := False;
4053 Spec_Id : Entity_Id;
4054
4055 -- Start of processing for Check_Result_And_Post_State
4056
4057 begin
4058 -- The lack of attribute 'Result or a post-state is classified as a
4059 -- suspicious contract. Do not perform the check if the corresponding
4060 -- swich is not set.
4061
4062 if not Warn_On_Suspicious_Contract then
4063 return;
4064
4065 -- Nothing to do if there is no contract
4066
4067 elsif No (Items) then
4068 return;
4069 end if;
4070
4071 -- Retrieve the entity of the subprogram spec (if any)
4072
4073 if Nkind (Subp_Decl) = N_Subprogram_Body
4074 and then Present (Corresponding_Spec (Subp_Decl))
4075 then
4076 Spec_Id := Corresponding_Spec (Subp_Decl);
4077
4078 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
4079 and then Present (Corresponding_Spec_Of_Stub (Subp_Decl))
4080 then
4081 Spec_Id := Corresponding_Spec_Of_Stub (Subp_Decl);
4082
4083 else
4084 Spec_Id := Subp_Id;
4085 end if;
4086
4087 -- Examine all postconditions for attribute 'Result and a post-state
4088
4089 Prag := Pre_Post_Conditions (Items);
4090 while Present (Prag) loop
4091 if Nam_In (Pragma_Name_Unmapped (Prag),
4092 Name_Postcondition, Name_Refined_Post)
4093 and then not Error_Posted (Prag)
4094 then
4095 Post_Prag := Prag;
4096 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Post);
4097 end if;
4098
4099 Prag := Next_Pragma (Prag);
4100 end loop;
4101
4102 -- Examine the contract cases of the subprogram for attribute 'Result
4103 -- and a post-state.
4104
4105 Prag := Contract_Test_Cases (Items);
4106 while Present (Prag) loop
4107 if Pragma_Name (Prag) = Name_Contract_Cases
4108 and then not Error_Posted (Prag)
4109 then
4110 Case_Prag := Prag;
4111 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Case);
4112 end if;
4113
4114 Prag := Next_Pragma (Prag);
4115 end loop;
4116
4117 -- Do not emit any errors if the subprogram is not a function
4118
4119 if not Ekind_In (Spec_Id, E_Function, E_Generic_Function) then
4120 null;
4121
4122 -- Regardless of whether the function has postconditions or contract
4123 -- cases, or whether they mention attribute 'Result, an IN OUT formal
4124 -- parameter is always treated as a result.
4125
4126 elsif Has_In_Out_Parameter (Spec_Id) then
4127 null;
4128
4129 -- The function has both a postcondition and contract cases and they do
4130 -- not mention attribute 'Result.
4131
4132 elsif Present (Case_Prag)
4133 and then not Seen_In_Case
4134 and then Present (Post_Prag)
4135 and then not Seen_In_Post
4136 then
4137 Error_Msg_N
4138 ("neither postcondition nor contract cases mention function "
4139 & "result?T?", Post_Prag);
4140
4141 -- The function has contract cases only and they do not mention
4142 -- attribute 'Result.
4143
4144 elsif Present (Case_Prag) and then not Seen_In_Case then
4145 Error_Msg_N ("contract cases do not mention result?T?", Case_Prag);
4146
4147 -- The function has postconditions only and they do not mention
4148 -- attribute 'Result.
4149
4150 elsif Present (Post_Prag) and then not Seen_In_Post then
4151 Error_Msg_N
4152 ("postcondition does not mention function result?T?", Post_Prag);
4153 end if;
4154 end Check_Result_And_Post_State;
4155
4156 -----------------------------
4157 -- Check_State_Refinements --
4158 -----------------------------
4159
4160 procedure Check_State_Refinements
4161 (Context : Node_Id;
4162 Is_Main_Unit : Boolean := False)
4163 is
4164 procedure Check_Package (Pack : Node_Id);
4165 -- Verify that all abstract states of a [generic] package denoted by its
4166 -- declarative node Pack have proper refinement. Recursively verify the
4167 -- visible and private declarations of the [generic] package for other
4168 -- nested packages.
4169
4170 procedure Check_Packages_In (Decls : List_Id);
4171 -- Seek out [generic] package declarations within declarative list Decls
4172 -- and verify the status of their abstract state refinement.
4173
4174 function SPARK_Mode_Is_Off (N : Node_Id) return Boolean;
4175 -- Determine whether construct N is subject to pragma SPARK_Mode Off
4176
4177 -------------------
4178 -- Check_Package --
4179 -------------------
4180
4181 procedure Check_Package (Pack : Node_Id) is
4182 Body_Id : constant Entity_Id := Corresponding_Body (Pack);
4183 Spec : constant Node_Id := Specification (Pack);
4184 States : constant Elist_Id :=
4185 Abstract_States (Defining_Entity (Pack));
4186
4187 State_Elmt : Elmt_Id;
4188 State_Id : Entity_Id;
4189
4190 begin
4191 -- Do not verify proper state refinement when the package is subject
4192 -- to pragma SPARK_Mode Off because this disables the requirement for
4193 -- state refinement.
4194
4195 if SPARK_Mode_Is_Off (Pack) then
4196 null;
4197
4198 -- State refinement can only occur in a completing package body. Do
4199 -- not verify proper state refinement when the body is subject to
4200 -- pragma SPARK_Mode Off because this disables the requirement for
4201 -- state refinement.
4202
4203 elsif Present (Body_Id)
4204 and then SPARK_Mode_Is_Off (Unit_Declaration_Node (Body_Id))
4205 then
4206 null;
4207
4208 -- Do not verify proper state refinement when the package is an
4209 -- instance as this check was already performed in the generic.
4210
4211 elsif Present (Generic_Parent (Spec)) then
4212 null;
4213
4214 -- Otherwise examine the contents of the package
4215
4216 else
4217 if Present (States) then
4218 State_Elmt := First_Elmt (States);
4219 while Present (State_Elmt) loop
4220 State_Id := Node (State_Elmt);
4221
4222 -- Emit an error when a non-null state lacks any form of
4223 -- refinement.
4224
4225 if not Is_Null_State (State_Id)
4226 and then not Has_Null_Refinement (State_Id)
4227 and then not Has_Non_Null_Refinement (State_Id)
4228 then
4229 Error_Msg_N ("state & requires refinement", State_Id);
4230 end if;
4231
4232 Next_Elmt (State_Elmt);
4233 end loop;
4234 end if;
4235
4236 Check_Packages_In (Visible_Declarations (Spec));
4237 Check_Packages_In (Private_Declarations (Spec));
4238 end if;
4239 end Check_Package;
4240
4241 -----------------------
4242 -- Check_Packages_In --
4243 -----------------------
4244
4245 procedure Check_Packages_In (Decls : List_Id) is
4246 Decl : Node_Id;
4247
4248 begin
4249 if Present (Decls) then
4250 Decl := First (Decls);
4251 while Present (Decl) loop
4252 if Nkind_In (Decl, N_Generic_Package_Declaration,
4253 N_Package_Declaration)
4254 then
4255 Check_Package (Decl);
4256 end if;
4257
4258 Next (Decl);
4259 end loop;
4260 end if;
4261 end Check_Packages_In;
4262
4263 -----------------------
4264 -- SPARK_Mode_Is_Off --
4265 -----------------------
4266
4267 function SPARK_Mode_Is_Off (N : Node_Id) return Boolean is
4268 Id : constant Entity_Id := Defining_Entity (N);
4269 Prag : constant Node_Id := SPARK_Pragma (Id);
4270
4271 begin
4272 -- Default the mode to "off" when the context is an instance and all
4273 -- SPARK_Mode pragmas found within are to be ignored.
4274
4275 if Ignore_SPARK_Mode_Pragmas (Id) then
4276 return True;
4277
4278 else
4279 return
4280 Present (Prag)
4281 and then Get_SPARK_Mode_From_Annotation (Prag) = Off;
4282 end if;
4283 end SPARK_Mode_Is_Off;
4284
4285 -- Start of processing for Check_State_Refinements
4286
4287 begin
4288 -- A block may declare a nested package
4289
4290 if Nkind (Context) = N_Block_Statement then
4291 Check_Packages_In (Declarations (Context));
4292
4293 -- An entry, protected, subprogram, or task body may declare a nested
4294 -- package.
4295
4296 elsif Nkind_In (Context, N_Entry_Body,
4297 N_Protected_Body,
4298 N_Subprogram_Body,
4299 N_Task_Body)
4300 then
4301 -- Do not verify proper state refinement when the body is subject to
4302 -- pragma SPARK_Mode Off because this disables the requirement for
4303 -- state refinement.
4304
4305 if not SPARK_Mode_Is_Off (Context) then
4306 Check_Packages_In (Declarations (Context));
4307 end if;
4308
4309 -- A package body may declare a nested package
4310
4311 elsif Nkind (Context) = N_Package_Body then
4312 Check_Package (Unit_Declaration_Node (Corresponding_Spec (Context)));
4313
4314 -- Do not verify proper state refinement when the body is subject to
4315 -- pragma SPARK_Mode Off because this disables the requirement for
4316 -- state refinement.
4317
4318 if not SPARK_Mode_Is_Off (Context) then
4319 Check_Packages_In (Declarations (Context));
4320 end if;
4321
4322 -- A library level [generic] package may declare a nested package
4323
4324 elsif Nkind_In (Context, N_Generic_Package_Declaration,
4325 N_Package_Declaration)
4326 and then Is_Main_Unit
4327 then
4328 Check_Package (Context);
4329 end if;
4330 end Check_State_Refinements;
4331
4332 ------------------------------
4333 -- Check_Unprotected_Access --
4334 ------------------------------
4335
4336 procedure Check_Unprotected_Access
4337 (Context : Node_Id;
4338 Expr : Node_Id)
4339 is
4340 Cont_Encl_Typ : Entity_Id;
4341 Pref_Encl_Typ : Entity_Id;
4342
4343 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
4344 -- Check whether Obj is a private component of a protected object.
4345 -- Return the protected type where the component resides, Empty
4346 -- otherwise.
4347
4348 function Is_Public_Operation return Boolean;
4349 -- Verify that the enclosing operation is callable from outside the
4350 -- protected object, to minimize false positives.
4351
4352 ------------------------------
4353 -- Enclosing_Protected_Type --
4354 ------------------------------
4355
4356 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
4357 begin
4358 if Is_Entity_Name (Obj) then
4359 declare
4360 Ent : Entity_Id := Entity (Obj);
4361
4362 begin
4363 -- The object can be a renaming of a private component, use
4364 -- the original record component.
4365
4366 if Is_Prival (Ent) then
4367 Ent := Prival_Link (Ent);
4368 end if;
4369
4370 if Is_Protected_Type (Scope (Ent)) then
4371 return Scope (Ent);
4372 end if;
4373 end;
4374 end if;
4375
4376 -- For indexed and selected components, recursively check the prefix
4377
4378 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
4379 return Enclosing_Protected_Type (Prefix (Obj));
4380
4381 -- The object does not denote a protected component
4382
4383 else
4384 return Empty;
4385 end if;
4386 end Enclosing_Protected_Type;
4387
4388 -------------------------
4389 -- Is_Public_Operation --
4390 -------------------------
4391
4392 function Is_Public_Operation return Boolean is
4393 S : Entity_Id;
4394 E : Entity_Id;
4395
4396 begin
4397 S := Current_Scope;
4398 while Present (S) and then S /= Pref_Encl_Typ loop
4399 if Scope (S) = Pref_Encl_Typ then
4400 E := First_Entity (Pref_Encl_Typ);
4401 while Present (E)
4402 and then E /= First_Private_Entity (Pref_Encl_Typ)
4403 loop
4404 if E = S then
4405 return True;
4406 end if;
4407
4408 Next_Entity (E);
4409 end loop;
4410 end if;
4411
4412 S := Scope (S);
4413 end loop;
4414
4415 return False;
4416 end Is_Public_Operation;
4417
4418 -- Start of processing for Check_Unprotected_Access
4419
4420 begin
4421 if Nkind (Expr) = N_Attribute_Reference
4422 and then Attribute_Name (Expr) = Name_Unchecked_Access
4423 then
4424 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
4425 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
4426
4427 -- Check whether we are trying to export a protected component to a
4428 -- context with an equal or lower access level.
4429
4430 if Present (Pref_Encl_Typ)
4431 and then No (Cont_Encl_Typ)
4432 and then Is_Public_Operation
4433 and then Scope_Depth (Pref_Encl_Typ) >=
4434 Object_Access_Level (Context)
4435 then
4436 Error_Msg_N
4437 ("??possible unprotected access to protected data", Expr);
4438 end if;
4439 end if;
4440 end Check_Unprotected_Access;
4441
4442 ------------------------------
4443 -- Check_Unused_Body_States --
4444 ------------------------------
4445
4446 procedure Check_Unused_Body_States (Body_Id : Entity_Id) is
4447 procedure Process_Refinement_Clause
4448 (Clause : Node_Id;
4449 States : Elist_Id);
4450 -- Inspect all constituents of refinement clause Clause and remove any
4451 -- matches from body state list States.
4452
4453 procedure Report_Unused_Body_States (States : Elist_Id);
4454 -- Emit errors for each abstract state or object found in list States
4455
4456 -------------------------------
4457 -- Process_Refinement_Clause --
4458 -------------------------------
4459
4460 procedure Process_Refinement_Clause
4461 (Clause : Node_Id;
4462 States : Elist_Id)
4463 is
4464 procedure Process_Constituent (Constit : Node_Id);
4465 -- Remove constituent Constit from body state list States
4466
4467 -------------------------
4468 -- Process_Constituent --
4469 -------------------------
4470
4471 procedure Process_Constituent (Constit : Node_Id) is
4472 Constit_Id : Entity_Id;
4473
4474 begin
4475 -- Guard against illegal constituents. Only abstract states and
4476 -- objects can appear on the right hand side of a refinement.
4477
4478 if Is_Entity_Name (Constit) then
4479 Constit_Id := Entity_Of (Constit);
4480
4481 if Present (Constit_Id)
4482 and then Ekind_In (Constit_Id, E_Abstract_State,
4483 E_Constant,
4484 E_Variable)
4485 then
4486 Remove (States, Constit_Id);
4487 end if;
4488 end if;
4489 end Process_Constituent;
4490
4491 -- Local variables
4492
4493 Constit : Node_Id;
4494
4495 -- Start of processing for Process_Refinement_Clause
4496
4497 begin
4498 if Nkind (Clause) = N_Component_Association then
4499 Constit := Expression (Clause);
4500
4501 -- Multiple constituents appear as an aggregate
4502
4503 if Nkind (Constit) = N_Aggregate then
4504 Constit := First (Expressions (Constit));
4505 while Present (Constit) loop
4506 Process_Constituent (Constit);
4507 Next (Constit);
4508 end loop;
4509
4510 -- Various forms of a single constituent
4511
4512 else
4513 Process_Constituent (Constit);
4514 end if;
4515 end if;
4516 end Process_Refinement_Clause;
4517
4518 -------------------------------
4519 -- Report_Unused_Body_States --
4520 -------------------------------
4521
4522 procedure Report_Unused_Body_States (States : Elist_Id) is
4523 Posted : Boolean := False;
4524 State_Elmt : Elmt_Id;
4525 State_Id : Entity_Id;
4526
4527 begin
4528 if Present (States) then
4529 State_Elmt := First_Elmt (States);
4530 while Present (State_Elmt) loop
4531 State_Id := Node (State_Elmt);
4532
4533 -- Constants are part of the hidden state of a package, but the
4534 -- compiler cannot determine whether they have variable input
4535 -- (SPARK RM 7.1.1(2)) and cannot classify them properly as a
4536 -- hidden state. Do not emit an error when a constant does not
4537 -- participate in a state refinement, even though it acts as a
4538 -- hidden state.
4539
4540 if Ekind (State_Id) = E_Constant then
4541 null;
4542
4543 -- Generate an error message of the form:
4544
4545 -- body of package ... has unused hidden states
4546 -- abstract state ... defined at ...
4547 -- variable ... defined at ...
4548
4549 else
4550 if not Posted then
4551 Posted := True;
4552 SPARK_Msg_N
4553 ("body of package & has unused hidden states", Body_Id);
4554 end if;
4555
4556 Error_Msg_Sloc := Sloc (State_Id);
4557
4558 if Ekind (State_Id) = E_Abstract_State then
4559 SPARK_Msg_NE
4560 ("\abstract state & defined #", Body_Id, State_Id);
4561
4562 else
4563 SPARK_Msg_NE ("\variable & defined #", Body_Id, State_Id);
4564 end if;
4565 end if;
4566
4567 Next_Elmt (State_Elmt);
4568 end loop;
4569 end if;
4570 end Report_Unused_Body_States;
4571
4572 -- Local variables
4573
4574 Prag : constant Node_Id := Get_Pragma (Body_Id, Pragma_Refined_State);
4575 Spec_Id : constant Entity_Id := Spec_Entity (Body_Id);
4576 Clause : Node_Id;
4577 States : Elist_Id;
4578
4579 -- Start of processing for Check_Unused_Body_States
4580
4581 begin
4582 -- Inspect the clauses of pragma Refined_State and determine whether all
4583 -- visible states declared within the package body participate in the
4584 -- refinement.
4585
4586 if Present (Prag) then
4587 Clause := Expression (Get_Argument (Prag, Spec_Id));
4588 States := Collect_Body_States (Body_Id);
4589
4590 -- Multiple non-null state refinements appear as an aggregate
4591
4592 if Nkind (Clause) = N_Aggregate then
4593 Clause := First (Component_Associations (Clause));
4594 while Present (Clause) loop
4595 Process_Refinement_Clause (Clause, States);
4596 Next (Clause);
4597 end loop;
4598
4599 -- Various forms of a single state refinement
4600
4601 else
4602 Process_Refinement_Clause (Clause, States);
4603 end if;
4604
4605 -- Ensure that all abstract states and objects declared in the
4606 -- package body state space are utilized as constituents.
4607
4608 Report_Unused_Body_States (States);
4609 end if;
4610 end Check_Unused_Body_States;
4611
4612 -----------------
4613 -- Choice_List --
4614 -----------------
4615
4616 function Choice_List (N : Node_Id) return List_Id is
4617 begin
4618 if Nkind (N) = N_Iterated_Component_Association then
4619 return Discrete_Choices (N);
4620 else
4621 return Choices (N);
4622 end if;
4623 end Choice_List;
4624
4625 -------------------------
4626 -- Collect_Body_States --
4627 -------------------------
4628
4629 function Collect_Body_States (Body_Id : Entity_Id) return Elist_Id is
4630 function Is_Visible_Object (Obj_Id : Entity_Id) return Boolean;
4631 -- Determine whether object Obj_Id is a suitable visible state of a
4632 -- package body.
4633
4634 procedure Collect_Visible_States
4635 (Pack_Id : Entity_Id;
4636 States : in out Elist_Id);
4637 -- Gather the entities of all abstract states and objects declared in
4638 -- the visible state space of package Pack_Id.
4639
4640 ----------------------------
4641 -- Collect_Visible_States --
4642 ----------------------------
4643
4644 procedure Collect_Visible_States
4645 (Pack_Id : Entity_Id;
4646 States : in out Elist_Id)
4647 is
4648 Item_Id : Entity_Id;
4649
4650 begin
4651 -- Traverse the entity chain of the package and inspect all visible
4652 -- items.
4653
4654 Item_Id := First_Entity (Pack_Id);
4655 while Present (Item_Id) and then not In_Private_Part (Item_Id) loop
4656
4657 -- Do not consider internally generated items as those cannot be
4658 -- named and participate in refinement.
4659
4660 if not Comes_From_Source (Item_Id) then
4661 null;
4662
4663 elsif Ekind (Item_Id) = E_Abstract_State then
4664 Append_New_Elmt (Item_Id, States);
4665
4666 elsif Ekind_In (Item_Id, E_Constant, E_Variable)
4667 and then Is_Visible_Object (Item_Id)
4668 then
4669 Append_New_Elmt (Item_Id, States);
4670
4671 -- Recursively gather the visible states of a nested package
4672
4673 elsif Ekind (Item_Id) = E_Package then
4674 Collect_Visible_States (Item_Id, States);
4675 end if;
4676
4677 Next_Entity (Item_Id);
4678 end loop;
4679 end Collect_Visible_States;
4680
4681 -----------------------
4682 -- Is_Visible_Object --
4683 -----------------------
4684
4685 function Is_Visible_Object (Obj_Id : Entity_Id) return Boolean is
4686 begin
4687 -- Objects that map generic formals to their actuals are not visible
4688 -- from outside the generic instantiation.
4689
4690 if Present (Corresponding_Generic_Association
4691 (Declaration_Node (Obj_Id)))
4692 then
4693 return False;
4694
4695 -- Constituents of a single protected/task type act as components of
4696 -- the type and are not visible from outside the type.
4697
4698 elsif Ekind (Obj_Id) = E_Variable
4699 and then Present (Encapsulating_State (Obj_Id))
4700 and then Is_Single_Concurrent_Object (Encapsulating_State (Obj_Id))
4701 then
4702 return False;
4703
4704 else
4705 return True;
4706 end if;
4707 end Is_Visible_Object;
4708
4709 -- Local variables
4710
4711 Body_Decl : constant Node_Id := Unit_Declaration_Node (Body_Id);
4712 Decl : Node_Id;
4713 Item_Id : Entity_Id;
4714 States : Elist_Id := No_Elist;
4715
4716 -- Start of processing for Collect_Body_States
4717
4718 begin
4719 -- Inspect the declarations of the body looking for source objects,
4720 -- packages and package instantiations. Note that even though this
4721 -- processing is very similar to Collect_Visible_States, a package
4722 -- body does not have a First/Next_Entity list.
4723
4724 Decl := First (Declarations (Body_Decl));
4725 while Present (Decl) loop
4726
4727 -- Capture source objects as internally generated temporaries cannot
4728 -- be named and participate in refinement.
4729
4730 if Nkind (Decl) = N_Object_Declaration then
4731 Item_Id := Defining_Entity (Decl);
4732
4733 if Comes_From_Source (Item_Id)
4734 and then Is_Visible_Object (Item_Id)
4735 then
4736 Append_New_Elmt (Item_Id, States);
4737 end if;
4738
4739 -- Capture the visible abstract states and objects of a source
4740 -- package [instantiation].
4741
4742 elsif Nkind (Decl) = N_Package_Declaration then
4743 Item_Id := Defining_Entity (Decl);
4744
4745 if Comes_From_Source (Item_Id) then
4746 Collect_Visible_States (Item_Id, States);
4747 end if;
4748 end if;
4749
4750 Next (Decl);
4751 end loop;
4752
4753 return States;
4754 end Collect_Body_States;
4755
4756 ------------------------
4757 -- Collect_Interfaces --
4758 ------------------------
4759
4760 procedure Collect_Interfaces
4761 (T : Entity_Id;
4762 Ifaces_List : out Elist_Id;
4763 Exclude_Parents : Boolean := False;
4764 Use_Full_View : Boolean := True)
4765 is
4766 procedure Collect (Typ : Entity_Id);
4767 -- Subsidiary subprogram used to traverse the whole list
4768 -- of directly and indirectly implemented interfaces
4769
4770 -------------
4771 -- Collect --
4772 -------------
4773
4774 procedure Collect (Typ : Entity_Id) is
4775 Ancestor : Entity_Id;
4776 Full_T : Entity_Id;
4777 Id : Node_Id;
4778 Iface : Entity_Id;
4779
4780 begin
4781 Full_T := Typ;
4782
4783 -- Handle private types and subtypes
4784
4785 if Use_Full_View
4786 and then Is_Private_Type (Typ)
4787 and then Present (Full_View (Typ))
4788 then
4789 Full_T := Full_View (Typ);
4790
4791 if Ekind (Full_T) = E_Record_Subtype then
4792 Full_T := Etype (Typ);
4793
4794 if Present (Full_View (Full_T)) then
4795 Full_T := Full_View (Full_T);
4796 end if;
4797 end if;
4798 end if;
4799
4800 -- Include the ancestor if we are generating the whole list of
4801 -- abstract interfaces.
4802
4803 if Etype (Full_T) /= Typ
4804
4805 -- Protect the frontend against wrong sources. For example:
4806
4807 -- package P is
4808 -- type A is tagged null record;
4809 -- type B is new A with private;
4810 -- type C is new A with private;
4811 -- private
4812 -- type B is new C with null record;
4813 -- type C is new B with null record;
4814 -- end P;
4815
4816 and then Etype (Full_T) /= T
4817 then
4818 Ancestor := Etype (Full_T);
4819 Collect (Ancestor);
4820
4821 if Is_Interface (Ancestor) and then not Exclude_Parents then
4822 Append_Unique_Elmt (Ancestor, Ifaces_List);
4823 end if;
4824 end if;
4825
4826 -- Traverse the graph of ancestor interfaces
4827
4828 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
4829 Id := First (Abstract_Interface_List (Full_T));
4830 while Present (Id) loop
4831 Iface := Etype (Id);
4832
4833 -- Protect against wrong uses. For example:
4834 -- type I is interface;
4835 -- type O is tagged null record;
4836 -- type Wrong is new I and O with null record; -- ERROR
4837
4838 if Is_Interface (Iface) then
4839 if Exclude_Parents
4840 and then Etype (T) /= T
4841 and then Interface_Present_In_Ancestor (Etype (T), Iface)
4842 then
4843 null;
4844 else
4845 Collect (Iface);
4846 Append_Unique_Elmt (Iface, Ifaces_List);
4847 end if;
4848 end if;
4849
4850 Next (Id);
4851 end loop;
4852 end if;
4853 end Collect;
4854
4855 -- Start of processing for Collect_Interfaces
4856
4857 begin
4858 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
4859 Ifaces_List := New_Elmt_List;
4860 Collect (T);
4861 end Collect_Interfaces;
4862
4863 ----------------------------------
4864 -- Collect_Interface_Components --
4865 ----------------------------------
4866
4867 procedure Collect_Interface_Components
4868 (Tagged_Type : Entity_Id;
4869 Components_List : out Elist_Id)
4870 is
4871 procedure Collect (Typ : Entity_Id);
4872 -- Subsidiary subprogram used to climb to the parents
4873
4874 -------------
4875 -- Collect --
4876 -------------
4877
4878 procedure Collect (Typ : Entity_Id) is
4879 Tag_Comp : Entity_Id;
4880 Parent_Typ : Entity_Id;
4881
4882 begin
4883 -- Handle private types
4884
4885 if Present (Full_View (Etype (Typ))) then
4886 Parent_Typ := Full_View (Etype (Typ));
4887 else
4888 Parent_Typ := Etype (Typ);
4889 end if;
4890
4891 if Parent_Typ /= Typ
4892
4893 -- Protect the frontend against wrong sources. For example:
4894
4895 -- package P is
4896 -- type A is tagged null record;
4897 -- type B is new A with private;
4898 -- type C is new A with private;
4899 -- private
4900 -- type B is new C with null record;
4901 -- type C is new B with null record;
4902 -- end P;
4903
4904 and then Parent_Typ /= Tagged_Type
4905 then
4906 Collect (Parent_Typ);
4907 end if;
4908
4909 -- Collect the components containing tags of secondary dispatch
4910 -- tables.
4911
4912 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
4913 while Present (Tag_Comp) loop
4914 pragma Assert (Present (Related_Type (Tag_Comp)));
4915 Append_Elmt (Tag_Comp, Components_List);
4916
4917 Tag_Comp := Next_Tag_Component (Tag_Comp);
4918 end loop;
4919 end Collect;
4920
4921 -- Start of processing for Collect_Interface_Components
4922
4923 begin
4924 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
4925 and then Is_Tagged_Type (Tagged_Type));
4926
4927 Components_List := New_Elmt_List;
4928 Collect (Tagged_Type);
4929 end Collect_Interface_Components;
4930
4931 -----------------------------
4932 -- Collect_Interfaces_Info --
4933 -----------------------------
4934
4935 procedure Collect_Interfaces_Info
4936 (T : Entity_Id;
4937 Ifaces_List : out Elist_Id;
4938 Components_List : out Elist_Id;
4939 Tags_List : out Elist_Id)
4940 is
4941 Comps_List : Elist_Id;
4942 Comp_Elmt : Elmt_Id;
4943 Comp_Iface : Entity_Id;
4944 Iface_Elmt : Elmt_Id;
4945 Iface : Entity_Id;
4946
4947 function Search_Tag (Iface : Entity_Id) return Entity_Id;
4948 -- Search for the secondary tag associated with the interface type
4949 -- Iface that is implemented by T.
4950
4951 ----------------
4952 -- Search_Tag --
4953 ----------------
4954
4955 function Search_Tag (Iface : Entity_Id) return Entity_Id is
4956 ADT : Elmt_Id;
4957 begin
4958 if not Is_CPP_Class (T) then
4959 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
4960 else
4961 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
4962 end if;
4963
4964 while Present (ADT)
4965 and then Is_Tag (Node (ADT))
4966 and then Related_Type (Node (ADT)) /= Iface
4967 loop
4968 -- Skip secondary dispatch table referencing thunks to user
4969 -- defined primitives covered by this interface.
4970
4971 pragma Assert (Has_Suffix (Node (ADT), 'P'));
4972 Next_Elmt (ADT);
4973
4974 -- Skip secondary dispatch tables of Ada types
4975
4976 if not Is_CPP_Class (T) then
4977
4978 -- Skip secondary dispatch table referencing thunks to
4979 -- predefined primitives.
4980
4981 pragma Assert (Has_Suffix (Node (ADT), 'Y'));
4982 Next_Elmt (ADT);
4983
4984 -- Skip secondary dispatch table referencing user-defined
4985 -- primitives covered by this interface.
4986
4987 pragma Assert (Has_Suffix (Node (ADT), 'D'));
4988 Next_Elmt (ADT);
4989
4990 -- Skip secondary dispatch table referencing predefined
4991 -- primitives.
4992
4993 pragma Assert (Has_Suffix (Node (ADT), 'Z'));
4994 Next_Elmt (ADT);
4995 end if;
4996 end loop;
4997
4998 pragma Assert (Is_Tag (Node (ADT)));
4999 return Node (ADT);
5000 end Search_Tag;
5001
5002 -- Start of processing for Collect_Interfaces_Info
5003
5004 begin
5005 Collect_Interfaces (T, Ifaces_List);
5006 Collect_Interface_Components (T, Comps_List);
5007
5008 -- Search for the record component and tag associated with each
5009 -- interface type of T.
5010
5011 Components_List := New_Elmt_List;
5012 Tags_List := New_Elmt_List;
5013
5014 Iface_Elmt := First_Elmt (Ifaces_List);
5015 while Present (Iface_Elmt) loop
5016 Iface := Node (Iface_Elmt);
5017
5018 -- Associate the primary tag component and the primary dispatch table
5019 -- with all the interfaces that are parents of T
5020
5021 if Is_Ancestor (Iface, T, Use_Full_View => True) then
5022 Append_Elmt (First_Tag_Component (T), Components_List);
5023 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
5024
5025 -- Otherwise search for the tag component and secondary dispatch
5026 -- table of Iface
5027
5028 else
5029 Comp_Elmt := First_Elmt (Comps_List);
5030 while Present (Comp_Elmt) loop
5031 Comp_Iface := Related_Type (Node (Comp_Elmt));
5032
5033 if Comp_Iface = Iface
5034 or else Is_Ancestor (Iface, Comp_Iface, Use_Full_View => True)
5035 then
5036 Append_Elmt (Node (Comp_Elmt), Components_List);
5037 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
5038 exit;
5039 end if;
5040
5041 Next_Elmt (Comp_Elmt);
5042 end loop;
5043 pragma Assert (Present (Comp_Elmt));
5044 end if;
5045
5046 Next_Elmt (Iface_Elmt);
5047 end loop;
5048 end Collect_Interfaces_Info;
5049
5050 ---------------------
5051 -- Collect_Parents --
5052 ---------------------
5053
5054 procedure Collect_Parents
5055 (T : Entity_Id;
5056 List : out Elist_Id;
5057 Use_Full_View : Boolean := True)
5058 is
5059 Current_Typ : Entity_Id := T;
5060 Parent_Typ : Entity_Id;
5061
5062 begin
5063 List := New_Elmt_List;
5064
5065 -- No action if the if the type has no parents
5066
5067 if T = Etype (T) then
5068 return;
5069 end if;
5070
5071 loop
5072 Parent_Typ := Etype (Current_Typ);
5073
5074 if Is_Private_Type (Parent_Typ)
5075 and then Present (Full_View (Parent_Typ))
5076 and then Use_Full_View
5077 then
5078 Parent_Typ := Full_View (Base_Type (Parent_Typ));
5079 end if;
5080
5081 Append_Elmt (Parent_Typ, List);
5082
5083 exit when Parent_Typ = Current_Typ;
5084 Current_Typ := Parent_Typ;
5085 end loop;
5086 end Collect_Parents;
5087
5088 ----------------------------------
5089 -- Collect_Primitive_Operations --
5090 ----------------------------------
5091
5092 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
5093 B_Type : constant Entity_Id := Base_Type (T);
5094
5095 function Match (E : Entity_Id) return Boolean;
5096 -- True if E's base type is B_Type, or E is of an anonymous access type
5097 -- and the base type of its designated type is B_Type.
5098
5099 -----------
5100 -- Match --
5101 -----------
5102
5103 function Match (E : Entity_Id) return Boolean is
5104 Etyp : Entity_Id := Etype (E);
5105
5106 begin
5107 if Ekind (Etyp) = E_Anonymous_Access_Type then
5108 Etyp := Designated_Type (Etyp);
5109 end if;
5110
5111 -- In Ada 2012 a primitive operation may have a formal of an
5112 -- incomplete view of the parent type.
5113
5114 return Base_Type (Etyp) = B_Type
5115 or else
5116 (Ada_Version >= Ada_2012
5117 and then Ekind (Etyp) = E_Incomplete_Type
5118 and then Full_View (Etyp) = B_Type);
5119 end Match;
5120
5121 -- Local variables
5122
5123 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
5124 B_Scope : Entity_Id := Scope (B_Type);
5125 Op_List : Elist_Id;
5126 Eq_Prims_List : Elist_Id := No_Elist;
5127 Formal : Entity_Id;
5128 Is_Prim : Boolean;
5129 Is_Type_In_Pkg : Boolean;
5130 Formal_Derived : Boolean := False;
5131 Id : Entity_Id;
5132
5133 -- Start of processing for Collect_Primitive_Operations
5134
5135 begin
5136 -- For tagged types, the primitive operations are collected as they
5137 -- are declared, and held in an explicit list which is simply returned.
5138
5139 if Is_Tagged_Type (B_Type) then
5140 return Primitive_Operations (B_Type);
5141
5142 -- An untagged generic type that is a derived type inherits the
5143 -- primitive operations of its parent type. Other formal types only
5144 -- have predefined operators, which are not explicitly represented.
5145
5146 elsif Is_Generic_Type (B_Type) then
5147 if Nkind (B_Decl) = N_Formal_Type_Declaration
5148 and then Nkind (Formal_Type_Definition (B_Decl)) =
5149 N_Formal_Derived_Type_Definition
5150 then
5151 Formal_Derived := True;
5152 else
5153 return New_Elmt_List;
5154 end if;
5155 end if;
5156
5157 Op_List := New_Elmt_List;
5158
5159 if B_Scope = Standard_Standard then
5160 if B_Type = Standard_String then
5161 Append_Elmt (Standard_Op_Concat, Op_List);
5162
5163 elsif B_Type = Standard_Wide_String then
5164 Append_Elmt (Standard_Op_Concatw, Op_List);
5165
5166 else
5167 null;
5168 end if;
5169
5170 -- Locate the primitive subprograms of the type
5171
5172 else
5173 -- The primitive operations appear after the base type, except if the
5174 -- derivation happens within the private part of B_Scope and the type
5175 -- is a private type, in which case both the type and some primitive
5176 -- operations may appear before the base type, and the list of
5177 -- candidates starts after the type.
5178
5179 if In_Open_Scopes (B_Scope)
5180 and then Scope (T) = B_Scope
5181 and then In_Private_Part (B_Scope)
5182 then
5183 Id := Next_Entity (T);
5184
5185 -- In Ada 2012, If the type has an incomplete partial view, there may
5186 -- be primitive operations declared before the full view, so we need
5187 -- to start scanning from the incomplete view, which is earlier on
5188 -- the entity chain.
5189
5190 elsif Nkind (Parent (B_Type)) = N_Full_Type_Declaration
5191 and then Present (Incomplete_View (Parent (B_Type)))
5192 then
5193 Id := Defining_Entity (Incomplete_View (Parent (B_Type)));
5194
5195 -- If T is a derived from a type with an incomplete view declared
5196 -- elsewhere, that incomplete view is irrelevant, we want the
5197 -- operations in the scope of T.
5198
5199 if Scope (Id) /= Scope (B_Type) then
5200 Id := Next_Entity (B_Type);
5201 end if;
5202
5203 else
5204 Id := Next_Entity (B_Type);
5205 end if;
5206
5207 -- Set flag if this is a type in a package spec
5208
5209 Is_Type_In_Pkg :=
5210 Is_Package_Or_Generic_Package (B_Scope)
5211 and then
5212 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
5213 N_Package_Body;
5214
5215 while Present (Id) loop
5216
5217 -- Test whether the result type or any of the parameter types of
5218 -- each subprogram following the type match that type when the
5219 -- type is declared in a package spec, is a derived type, or the
5220 -- subprogram is marked as primitive. (The Is_Primitive test is
5221 -- needed to find primitives of nonderived types in declarative
5222 -- parts that happen to override the predefined "=" operator.)
5223
5224 -- Note that generic formal subprograms are not considered to be
5225 -- primitive operations and thus are never inherited.
5226
5227 if Is_Overloadable (Id)
5228 and then (Is_Type_In_Pkg
5229 or else Is_Derived_Type (B_Type)
5230 or else Is_Primitive (Id))
5231 and then Nkind (Parent (Parent (Id)))
5232 not in N_Formal_Subprogram_Declaration
5233 then
5234 Is_Prim := False;
5235
5236 if Match (Id) then
5237 Is_Prim := True;
5238
5239 else
5240 Formal := First_Formal (Id);
5241 while Present (Formal) loop
5242 if Match (Formal) then
5243 Is_Prim := True;
5244 exit;
5245 end if;
5246
5247 Next_Formal (Formal);
5248 end loop;
5249 end if;
5250
5251 -- For a formal derived type, the only primitives are the ones
5252 -- inherited from the parent type. Operations appearing in the
5253 -- package declaration are not primitive for it.
5254
5255 if Is_Prim
5256 and then (not Formal_Derived or else Present (Alias (Id)))
5257 then
5258 -- In the special case of an equality operator aliased to
5259 -- an overriding dispatching equality belonging to the same
5260 -- type, we don't include it in the list of primitives.
5261 -- This avoids inheriting multiple equality operators when
5262 -- deriving from untagged private types whose full type is
5263 -- tagged, which can otherwise cause ambiguities. Note that
5264 -- this should only happen for this kind of untagged parent
5265 -- type, since normally dispatching operations are inherited
5266 -- using the type's Primitive_Operations list.
5267
5268 if Chars (Id) = Name_Op_Eq
5269 and then Is_Dispatching_Operation (Id)
5270 and then Present (Alias (Id))
5271 and then Present (Overridden_Operation (Alias (Id)))
5272 and then Base_Type (Etype (First_Entity (Id))) =
5273 Base_Type (Etype (First_Entity (Alias (Id))))
5274 then
5275 null;
5276
5277 -- Include the subprogram in the list of primitives
5278
5279 else
5280 Append_Elmt (Id, Op_List);
5281
5282 -- Save collected equality primitives for later filtering
5283 -- (if we are processing a private type for which we can
5284 -- collect several candidates).
5285
5286 if Inherits_From_Tagged_Full_View (T)
5287 and then Chars (Id) = Name_Op_Eq
5288 and then Etype (First_Formal (Id)) =
5289 Etype (Next_Formal (First_Formal (Id)))
5290 then
5291 if No (Eq_Prims_List) then
5292 Eq_Prims_List := New_Elmt_List;
5293 end if;
5294
5295 Append_Elmt (Id, Eq_Prims_List);
5296 end if;
5297 end if;
5298 end if;
5299 end if;
5300
5301 Next_Entity (Id);
5302
5303 -- For a type declared in System, some of its operations may
5304 -- appear in the target-specific extension to System.
5305
5306 if No (Id)
5307 and then B_Scope = RTU_Entity (System)
5308 and then Present_System_Aux
5309 then
5310 B_Scope := System_Aux_Id;
5311 Id := First_Entity (System_Aux_Id);
5312 end if;
5313 end loop;
5314
5315 -- Filter collected equality primitives
5316
5317 if Inherits_From_Tagged_Full_View (T)
5318 and then Present (Eq_Prims_List)
5319 then
5320 declare
5321 First : constant Elmt_Id := First_Elmt (Eq_Prims_List);
5322 Second : Elmt_Id;
5323
5324 begin
5325 pragma Assert (No (Next_Elmt (First))
5326 or else No (Next_Elmt (Next_Elmt (First))));
5327
5328 -- No action needed if we have collected a single equality
5329 -- primitive
5330
5331 if Present (Next_Elmt (First)) then
5332 Second := Next_Elmt (First);
5333
5334 if Is_Dispatching_Operation
5335 (Ultimate_Alias (Node (First)))
5336 then
5337 Remove (Op_List, Node (First));
5338
5339 elsif Is_Dispatching_Operation
5340 (Ultimate_Alias (Node (Second)))
5341 then
5342 Remove (Op_List, Node (Second));
5343
5344 else
5345 pragma Assert (False);
5346 raise Program_Error;
5347 end if;
5348 end if;
5349 end;
5350 end if;
5351 end if;
5352
5353 return Op_List;
5354 end Collect_Primitive_Operations;
5355
5356 -----------------------------------
5357 -- Compile_Time_Constraint_Error --
5358 -----------------------------------
5359
5360 function Compile_Time_Constraint_Error
5361 (N : Node_Id;
5362 Msg : String;
5363 Ent : Entity_Id := Empty;
5364 Loc : Source_Ptr := No_Location;
5365 Warn : Boolean := False) return Node_Id
5366 is
5367 Msgc : String (1 .. Msg'Length + 3);
5368 -- Copy of message, with room for possible ?? or << and ! at end
5369
5370 Msgl : Natural;
5371 Wmsg : Boolean;
5372 Eloc : Source_Ptr;
5373
5374 -- Start of processing for Compile_Time_Constraint_Error
5375
5376 begin
5377 -- If this is a warning, convert it into an error if we are in code
5378 -- subject to SPARK_Mode being set On, unless Warn is True to force a
5379 -- warning. The rationale is that a compile-time constraint error should
5380 -- lead to an error instead of a warning when SPARK_Mode is On, but in
5381 -- a few cases we prefer to issue a warning and generate both a suitable
5382 -- run-time error in GNAT and a suitable check message in GNATprove.
5383 -- Those cases are those that likely correspond to deactivated SPARK
5384 -- code, so that this kind of code can be compiled and analyzed instead
5385 -- of being rejected.
5386
5387 Error_Msg_Warn := Warn or SPARK_Mode /= On;
5388
5389 -- A static constraint error in an instance body is not a fatal error.
5390 -- we choose to inhibit the message altogether, because there is no
5391 -- obvious node (for now) on which to post it. On the other hand the
5392 -- offending node must be replaced with a constraint_error in any case.
5393
5394 -- No messages are generated if we already posted an error on this node
5395
5396 if not Error_Posted (N) then
5397 if Loc /= No_Location then
5398 Eloc := Loc;
5399 else
5400 Eloc := Sloc (N);
5401 end if;
5402
5403 -- Copy message to Msgc, converting any ? in the message into <
5404 -- instead, so that we have an error in GNATprove mode.
5405
5406 Msgl := Msg'Length;
5407
5408 for J in 1 .. Msgl loop
5409 if Msg (J) = '?' and then (J = 1 or else Msg (J - 1) /= ''') then
5410 Msgc (J) := '<';
5411 else
5412 Msgc (J) := Msg (J);
5413 end if;
5414 end loop;
5415
5416 -- Message is a warning, even in Ada 95 case
5417
5418 if Msg (Msg'Last) = '?' or else Msg (Msg'Last) = '<' then
5419 Wmsg := True;
5420
5421 -- In Ada 83, all messages are warnings. In the private part and the
5422 -- body of an instance, constraint_checks are only warnings. We also
5423 -- make this a warning if the Warn parameter is set.
5424
5425 elsif Warn
5426 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
5427 or else In_Instance_Not_Visible
5428 then
5429 Msgl := Msgl + 1;
5430 Msgc (Msgl) := '<';
5431 Msgl := Msgl + 1;
5432 Msgc (Msgl) := '<';
5433 Wmsg := True;
5434
5435 -- Otherwise we have a real error message (Ada 95 static case) and we
5436 -- make this an unconditional message. Note that in the warning case
5437 -- we do not make the message unconditional, it seems reasonable to
5438 -- delete messages like this (about exceptions that will be raised)
5439 -- in dead code.
5440
5441 else
5442 Wmsg := False;
5443 Msgl := Msgl + 1;
5444 Msgc (Msgl) := '!';
5445 end if;
5446
5447 -- One more test, skip the warning if the related expression is
5448 -- statically unevaluated, since we don't want to warn about what
5449 -- will happen when something is evaluated if it never will be
5450 -- evaluated.
5451
5452 if not Is_Statically_Unevaluated (N) then
5453 if Present (Ent) then
5454 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
5455 else
5456 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
5457 end if;
5458
5459 if Wmsg then
5460
5461 -- Check whether the context is an Init_Proc
5462
5463 if Inside_Init_Proc then
5464 declare
5465 Conc_Typ : constant Entity_Id :=
5466 Corresponding_Concurrent_Type
5467 (Entity (Parameter_Type (First
5468 (Parameter_Specifications
5469 (Parent (Current_Scope))))));
5470
5471 begin
5472 -- Don't complain if the corresponding concurrent type
5473 -- doesn't come from source (i.e. a single task/protected
5474 -- object).
5475
5476 if Present (Conc_Typ)
5477 and then not Comes_From_Source (Conc_Typ)
5478 then
5479 Error_Msg_NEL
5480 ("\& [<<", N, Standard_Constraint_Error, Eloc);
5481
5482 else
5483 if GNATprove_Mode then
5484 Error_Msg_NEL
5485 ("\& would have been raised for objects of this "
5486 & "type", N, Standard_Constraint_Error, Eloc);
5487 else
5488 Error_Msg_NEL
5489 ("\& will be raised for objects of this type??",
5490 N, Standard_Constraint_Error, Eloc);
5491 end if;
5492 end if;
5493 end;
5494
5495 else
5496 Error_Msg_NEL ("\& [<<", N, Standard_Constraint_Error, Eloc);
5497 end if;
5498
5499 else
5500 Error_Msg ("\static expression fails Constraint_Check", Eloc);
5501 Set_Error_Posted (N);
5502 end if;
5503 end if;
5504 end if;
5505
5506 return N;
5507 end Compile_Time_Constraint_Error;
5508
5509 -----------------------
5510 -- Conditional_Delay --
5511 -----------------------
5512
5513 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
5514 begin
5515 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
5516 Set_Has_Delayed_Freeze (New_Ent);
5517 end if;
5518 end Conditional_Delay;
5519
5520 -------------------------
5521 -- Copy_Component_List --
5522 -------------------------
5523
5524 function Copy_Component_List
5525 (R_Typ : Entity_Id;
5526 Loc : Source_Ptr) return List_Id
5527 is
5528 Comp : Node_Id;
5529 Comps : constant List_Id := New_List;
5530
5531 begin
5532 Comp := First_Component (Underlying_Type (R_Typ));
5533 while Present (Comp) loop
5534 if Comes_From_Source (Comp) then
5535 declare
5536 Comp_Decl : constant Node_Id := Declaration_Node (Comp);
5537 begin
5538 Append_To (Comps,
5539 Make_Component_Declaration (Loc,
5540 Defining_Identifier =>
5541 Make_Defining_Identifier (Loc, Chars (Comp)),
5542 Component_Definition =>
5543 New_Copy_Tree
5544 (Component_Definition (Comp_Decl), New_Sloc => Loc)));
5545 end;
5546 end if;
5547
5548 Next_Component (Comp);
5549 end loop;
5550
5551 return Comps;
5552 end Copy_Component_List;
5553
5554 -------------------------
5555 -- Copy_Parameter_List --
5556 -------------------------
5557
5558 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
5559 Loc : constant Source_Ptr := Sloc (Subp_Id);
5560 Plist : List_Id;
5561 Formal : Entity_Id;
5562
5563 begin
5564 if No (First_Formal (Subp_Id)) then
5565 return No_List;
5566 else
5567 Plist := New_List;
5568 Formal := First_Formal (Subp_Id);
5569 while Present (Formal) loop
5570 Append_To (Plist,
5571 Make_Parameter_Specification (Loc,
5572 Defining_Identifier =>
5573 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)),
5574 In_Present => In_Present (Parent (Formal)),
5575 Out_Present => Out_Present (Parent (Formal)),
5576 Parameter_Type =>
5577 New_Occurrence_Of (Etype (Formal), Loc),
5578 Expression =>
5579 New_Copy_Tree (Expression (Parent (Formal)))));
5580
5581 Next_Formal (Formal);
5582 end loop;
5583 end if;
5584
5585 return Plist;
5586 end Copy_Parameter_List;
5587
5588 ----------------------------
5589 -- Copy_SPARK_Mode_Aspect --
5590 ----------------------------
5591
5592 procedure Copy_SPARK_Mode_Aspect (From : Node_Id; To : Node_Id) is
5593 pragma Assert (not Has_Aspects (To));
5594 Asp : Node_Id;
5595
5596 begin
5597 if Has_Aspects (From) then
5598 Asp := Find_Aspect (Defining_Entity (From), Aspect_SPARK_Mode);
5599
5600 if Present (Asp) then
5601 Set_Aspect_Specifications (To, New_List (New_Copy_Tree (Asp)));
5602 Set_Has_Aspects (To, True);
5603 end if;
5604 end if;
5605 end Copy_SPARK_Mode_Aspect;
5606
5607 --------------------------
5608 -- Copy_Subprogram_Spec --
5609 --------------------------
5610
5611 function Copy_Subprogram_Spec (Spec : Node_Id) return Node_Id is
5612 Def_Id : Node_Id;
5613 Formal_Spec : Node_Id;
5614 Result : Node_Id;
5615
5616 begin
5617 -- The structure of the original tree must be replicated without any
5618 -- alterations. Use New_Copy_Tree for this purpose.
5619
5620 Result := New_Copy_Tree (Spec);
5621
5622 -- However, the spec of a null procedure carries the corresponding null
5623 -- statement of the body (created by the parser), and this cannot be
5624 -- shared with the new subprogram spec.
5625
5626 if Nkind (Result) = N_Procedure_Specification then
5627 Set_Null_Statement (Result, Empty);
5628 end if;
5629
5630 -- Create a new entity for the defining unit name
5631
5632 Def_Id := Defining_Unit_Name (Result);
5633 Set_Defining_Unit_Name (Result,
5634 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
5635
5636 -- Create new entities for the formal parameters
5637
5638 if Present (Parameter_Specifications (Result)) then
5639 Formal_Spec := First (Parameter_Specifications (Result));
5640 while Present (Formal_Spec) loop
5641 Def_Id := Defining_Identifier (Formal_Spec);
5642 Set_Defining_Identifier (Formal_Spec,
5643 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
5644
5645 Next (Formal_Spec);
5646 end loop;
5647 end if;
5648
5649 return Result;
5650 end Copy_Subprogram_Spec;
5651
5652 --------------------------------
5653 -- Corresponding_Generic_Type --
5654 --------------------------------
5655
5656 function Corresponding_Generic_Type (T : Entity_Id) return Entity_Id is
5657 Inst : Entity_Id;
5658 Gen : Entity_Id;
5659 Typ : Entity_Id;
5660
5661 begin
5662 if not Is_Generic_Actual_Type (T) then
5663 return Any_Type;
5664
5665 -- If the actual is the actual of an enclosing instance, resolution
5666 -- was correct in the generic.
5667
5668 elsif Nkind (Parent (T)) = N_Subtype_Declaration
5669 and then Is_Entity_Name (Subtype_Indication (Parent (T)))
5670 and then
5671 Is_Generic_Actual_Type (Entity (Subtype_Indication (Parent (T))))
5672 then
5673 return Any_Type;
5674
5675 else
5676 Inst := Scope (T);
5677
5678 if Is_Wrapper_Package (Inst) then
5679 Inst := Related_Instance (Inst);
5680 end if;
5681
5682 Gen :=
5683 Generic_Parent
5684 (Specification (Unit_Declaration_Node (Inst)));
5685
5686 -- Generic actual has the same name as the corresponding formal
5687
5688 Typ := First_Entity (Gen);
5689 while Present (Typ) loop
5690 if Chars (Typ) = Chars (T) then
5691 return Typ;
5692 end if;
5693
5694 Next_Entity (Typ);
5695 end loop;
5696
5697 return Any_Type;
5698 end if;
5699 end Corresponding_Generic_Type;
5700
5701 --------------------
5702 -- Current_Entity --
5703 --------------------
5704
5705 -- The currently visible definition for a given identifier is the
5706 -- one most chained at the start of the visibility chain, i.e. the
5707 -- one that is referenced by the Node_Id value of the name of the
5708 -- given identifier.
5709
5710 function Current_Entity (N : Node_Id) return Entity_Id is
5711 begin
5712 return Get_Name_Entity_Id (Chars (N));
5713 end Current_Entity;
5714
5715 -----------------------------
5716 -- Current_Entity_In_Scope --
5717 -----------------------------
5718
5719 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
5720 E : Entity_Id;
5721 CS : constant Entity_Id := Current_Scope;
5722
5723 Transient_Case : constant Boolean := Scope_Is_Transient;
5724
5725 begin
5726 E := Get_Name_Entity_Id (Chars (N));
5727 while Present (E)
5728 and then Scope (E) /= CS
5729 and then (not Transient_Case or else Scope (E) /= Scope (CS))
5730 loop
5731 E := Homonym (E);
5732 end loop;
5733
5734 return E;
5735 end Current_Entity_In_Scope;
5736
5737 -------------------
5738 -- Current_Scope --
5739 -------------------
5740
5741 function Current_Scope return Entity_Id is
5742 begin
5743 if Scope_Stack.Last = -1 then
5744 return Standard_Standard;
5745 else
5746 declare
5747 C : constant Entity_Id :=
5748 Scope_Stack.Table (Scope_Stack.Last).Entity;
5749 begin
5750 if Present (C) then
5751 return C;
5752 else
5753 return Standard_Standard;
5754 end if;
5755 end;
5756 end if;
5757 end Current_Scope;
5758
5759 ----------------------------
5760 -- Current_Scope_No_Loops --
5761 ----------------------------
5762
5763 function Current_Scope_No_Loops return Entity_Id is
5764 S : Entity_Id;
5765
5766 begin
5767 -- Examine the scope stack starting from the current scope and skip any
5768 -- internally generated loops.
5769
5770 S := Current_Scope;
5771 while Present (S) and then S /= Standard_Standard loop
5772 if Ekind (S) = E_Loop and then not Comes_From_Source (S) then
5773 S := Scope (S);
5774 else
5775 exit;
5776 end if;
5777 end loop;
5778
5779 return S;
5780 end Current_Scope_No_Loops;
5781
5782 ------------------------
5783 -- Current_Subprogram --
5784 ------------------------
5785
5786 function Current_Subprogram return Entity_Id is
5787 Scop : constant Entity_Id := Current_Scope;
5788 begin
5789 if Is_Subprogram_Or_Generic_Subprogram (Scop) then
5790 return Scop;
5791 else
5792 return Enclosing_Subprogram (Scop);
5793 end if;
5794 end Current_Subprogram;
5795
5796 ----------------------------------
5797 -- Deepest_Type_Access_Level --
5798 ----------------------------------
5799
5800 function Deepest_Type_Access_Level (Typ : Entity_Id) return Uint is
5801 begin
5802 if Ekind (Typ) = E_Anonymous_Access_Type
5803 and then not Is_Local_Anonymous_Access (Typ)
5804 and then Nkind (Associated_Node_For_Itype (Typ)) = N_Object_Declaration
5805 then
5806 -- Typ is the type of an Ada 2012 stand-alone object of an anonymous
5807 -- access type.
5808
5809 return
5810 Scope_Depth (Enclosing_Dynamic_Scope
5811 (Defining_Identifier
5812 (Associated_Node_For_Itype (Typ))));
5813
5814 -- For generic formal type, return Int'Last (infinite).
5815 -- See comment preceding Is_Generic_Type call in Type_Access_Level.
5816
5817 elsif Is_Generic_Type (Root_Type (Typ)) then
5818 return UI_From_Int (Int'Last);
5819
5820 else
5821 return Type_Access_Level (Typ);
5822 end if;
5823 end Deepest_Type_Access_Level;
5824
5825 ---------------------
5826 -- Defining_Entity --
5827 ---------------------
5828
5829 function Defining_Entity
5830 (N : Node_Id;
5831 Empty_On_Errors : Boolean := False;
5832 Concurrent_Subunit : Boolean := False) return Entity_Id
5833 is
5834 begin
5835 case Nkind (N) is
5836 when N_Abstract_Subprogram_Declaration
5837 | N_Expression_Function
5838 | N_Formal_Subprogram_Declaration
5839 | N_Generic_Package_Declaration
5840 | N_Generic_Subprogram_Declaration
5841 | N_Package_Declaration
5842 | N_Subprogram_Body
5843 | N_Subprogram_Body_Stub
5844 | N_Subprogram_Declaration
5845 | N_Subprogram_Renaming_Declaration
5846 =>
5847 return Defining_Entity (Specification (N));
5848
5849 when N_Component_Declaration
5850 | N_Defining_Program_Unit_Name
5851 | N_Discriminant_Specification
5852 | N_Entry_Body
5853 | N_Entry_Declaration
5854 | N_Entry_Index_Specification
5855 | N_Exception_Declaration
5856 | N_Exception_Renaming_Declaration
5857 | N_Formal_Object_Declaration
5858 | N_Formal_Package_Declaration
5859 | N_Formal_Type_Declaration
5860 | N_Full_Type_Declaration
5861 | N_Implicit_Label_Declaration
5862 | N_Incomplete_Type_Declaration
5863 | N_Iterator_Specification
5864 | N_Loop_Parameter_Specification
5865 | N_Number_Declaration
5866 | N_Object_Declaration
5867 | N_Object_Renaming_Declaration
5868 | N_Package_Body_Stub
5869 | N_Parameter_Specification
5870 | N_Private_Extension_Declaration
5871 | N_Private_Type_Declaration
5872 | N_Protected_Body
5873 | N_Protected_Body_Stub
5874 | N_Protected_Type_Declaration
5875 | N_Single_Protected_Declaration
5876 | N_Single_Task_Declaration
5877 | N_Subtype_Declaration
5878 | N_Task_Body
5879 | N_Task_Body_Stub
5880 | N_Task_Type_Declaration
5881 =>
5882 return Defining_Identifier (N);
5883
5884 when N_Subunit =>
5885 declare
5886 Bod : constant Node_Id := Proper_Body (N);
5887 Orig_Bod : constant Node_Id := Original_Node (Bod);
5888
5889 begin
5890 -- Retrieve the entity of the original protected or task body
5891 -- if requested by the caller.
5892
5893 if Concurrent_Subunit
5894 and then Nkind (Bod) = N_Null_Statement
5895 and then Nkind_In (Orig_Bod, N_Protected_Body, N_Task_Body)
5896 then
5897 return Defining_Entity (Orig_Bod);
5898 else
5899 return Defining_Entity (Bod);
5900 end if;
5901 end;
5902
5903 when N_Function_Instantiation
5904 | N_Function_Specification
5905 | N_Generic_Function_Renaming_Declaration
5906 | N_Generic_Package_Renaming_Declaration
5907 | N_Generic_Procedure_Renaming_Declaration
5908 | N_Package_Body
5909 | N_Package_Instantiation
5910 | N_Package_Renaming_Declaration
5911 | N_Package_Specification
5912 | N_Procedure_Instantiation
5913 | N_Procedure_Specification
5914 =>
5915 declare
5916 Nam : constant Node_Id := Defining_Unit_Name (N);
5917 Err : Entity_Id := Empty;
5918
5919 begin
5920 if Nkind (Nam) in N_Entity then
5921 return Nam;
5922
5923 -- For Error, make up a name and attach to declaration so we
5924 -- can continue semantic analysis.
5925
5926 elsif Nam = Error then
5927 if Empty_On_Errors then
5928 return Empty;
5929 else
5930 Err := Make_Temporary (Sloc (N), 'T');
5931 Set_Defining_Unit_Name (N, Err);
5932
5933 return Err;
5934 end if;
5935
5936 -- If not an entity, get defining identifier
5937
5938 else
5939 return Defining_Identifier (Nam);
5940 end if;
5941 end;
5942
5943 when N_Block_Statement
5944 | N_Loop_Statement
5945 =>
5946 return Entity (Identifier (N));
5947
5948 when others =>
5949 if Empty_On_Errors then
5950 return Empty;
5951 else
5952 raise Program_Error;
5953 end if;
5954 end case;
5955 end Defining_Entity;
5956
5957 --------------------------
5958 -- Denotes_Discriminant --
5959 --------------------------
5960
5961 function Denotes_Discriminant
5962 (N : Node_Id;
5963 Check_Concurrent : Boolean := False) return Boolean
5964 is
5965 E : Entity_Id;
5966
5967 begin
5968 if not Is_Entity_Name (N) or else No (Entity (N)) then
5969 return False;
5970 else
5971 E := Entity (N);
5972 end if;
5973
5974 -- If we are checking for a protected type, the discriminant may have
5975 -- been rewritten as the corresponding discriminal of the original type
5976 -- or of the corresponding concurrent record, depending on whether we
5977 -- are in the spec or body of the protected type.
5978
5979 return Ekind (E) = E_Discriminant
5980 or else
5981 (Check_Concurrent
5982 and then Ekind (E) = E_In_Parameter
5983 and then Present (Discriminal_Link (E))
5984 and then
5985 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
5986 or else
5987 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
5988 end Denotes_Discriminant;
5989
5990 -------------------------
5991 -- Denotes_Same_Object --
5992 -------------------------
5993
5994 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
5995 function Is_Renaming (N : Node_Id) return Boolean;
5996 -- Return true if N names a renaming entity
5997
5998 function Is_Valid_Renaming (N : Node_Id) return Boolean;
5999 -- For renamings, return False if the prefix of any dereference within
6000 -- the renamed object_name is a variable, or any expression within the
6001 -- renamed object_name contains references to variables or calls on
6002 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
6003
6004 -----------------
6005 -- Is_Renaming --
6006 -----------------
6007
6008 function Is_Renaming (N : Node_Id) return Boolean is
6009 begin
6010 return
6011 Is_Entity_Name (N) and then Present (Renamed_Entity (Entity (N)));
6012 end Is_Renaming;
6013
6014 -----------------------
6015 -- Is_Valid_Renaming --
6016 -----------------------
6017
6018 function Is_Valid_Renaming (N : Node_Id) return Boolean is
6019 function Check_Renaming (N : Node_Id) return Boolean;
6020 -- Recursive function used to traverse all the prefixes of N
6021
6022 --------------------
6023 -- Check_Renaming --
6024 --------------------
6025
6026 function Check_Renaming (N : Node_Id) return Boolean is
6027 begin
6028 if Is_Renaming (N)
6029 and then not Check_Renaming (Renamed_Entity (Entity (N)))
6030 then
6031 return False;
6032 end if;
6033
6034 if Nkind (N) = N_Indexed_Component then
6035 declare
6036 Indx : Node_Id;
6037
6038 begin
6039 Indx := First (Expressions (N));
6040 while Present (Indx) loop
6041 if not Is_OK_Static_Expression (Indx) then
6042 return False;
6043 end if;
6044
6045 Next_Index (Indx);
6046 end loop;
6047 end;
6048 end if;
6049
6050 if Has_Prefix (N) then
6051 declare
6052 P : constant Node_Id := Prefix (N);
6053
6054 begin
6055 if Nkind (N) = N_Explicit_Dereference
6056 and then Is_Variable (P)
6057 then
6058 return False;
6059
6060 elsif Is_Entity_Name (P)
6061 and then Ekind (Entity (P)) = E_Function
6062 then
6063 return False;
6064
6065 elsif Nkind (P) = N_Function_Call then
6066 return False;
6067 end if;
6068
6069 -- Recursion to continue traversing the prefix of the
6070 -- renaming expression
6071
6072 return Check_Renaming (P);
6073 end;
6074 end if;
6075
6076 return True;
6077 end Check_Renaming;
6078
6079 -- Start of processing for Is_Valid_Renaming
6080
6081 begin
6082 return Check_Renaming (N);
6083 end Is_Valid_Renaming;
6084
6085 -- Local variables
6086
6087 Obj1 : Node_Id := A1;
6088 Obj2 : Node_Id := A2;
6089
6090 -- Start of processing for Denotes_Same_Object
6091
6092 begin
6093 -- Both names statically denote the same stand-alone object or parameter
6094 -- (RM 6.4.1(6.5/3))
6095
6096 if Is_Entity_Name (Obj1)
6097 and then Is_Entity_Name (Obj2)
6098 and then Entity (Obj1) = Entity (Obj2)
6099 then
6100 return True;
6101 end if;
6102
6103 -- For renamings, the prefix of any dereference within the renamed
6104 -- object_name is not a variable, and any expression within the
6105 -- renamed object_name contains no references to variables nor
6106 -- calls on nonstatic functions (RM 6.4.1(6.10/3)).
6107
6108 if Is_Renaming (Obj1) then
6109 if Is_Valid_Renaming (Obj1) then
6110 Obj1 := Renamed_Entity (Entity (Obj1));
6111 else
6112 return False;
6113 end if;
6114 end if;
6115
6116 if Is_Renaming (Obj2) then
6117 if Is_Valid_Renaming (Obj2) then
6118 Obj2 := Renamed_Entity (Entity (Obj2));
6119 else
6120 return False;
6121 end if;
6122 end if;
6123
6124 -- No match if not same node kind (such cases are handled by
6125 -- Denotes_Same_Prefix)
6126
6127 if Nkind (Obj1) /= Nkind (Obj2) then
6128 return False;
6129
6130 -- After handling valid renamings, one of the two names statically
6131 -- denoted a renaming declaration whose renamed object_name is known
6132 -- to denote the same object as the other (RM 6.4.1(6.10/3))
6133
6134 elsif Is_Entity_Name (Obj1) then
6135 if Is_Entity_Name (Obj2) then
6136 return Entity (Obj1) = Entity (Obj2);
6137 else
6138 return False;
6139 end if;
6140
6141 -- Both names are selected_components, their prefixes are known to
6142 -- denote the same object, and their selector_names denote the same
6143 -- component (RM 6.4.1(6.6/3)).
6144
6145 elsif Nkind (Obj1) = N_Selected_Component then
6146 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
6147 and then
6148 Entity (Selector_Name (Obj1)) = Entity (Selector_Name (Obj2));
6149
6150 -- Both names are dereferences and the dereferenced names are known to
6151 -- denote the same object (RM 6.4.1(6.7/3))
6152
6153 elsif Nkind (Obj1) = N_Explicit_Dereference then
6154 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2));
6155
6156 -- Both names are indexed_components, their prefixes are known to denote
6157 -- the same object, and each of the pairs of corresponding index values
6158 -- are either both static expressions with the same static value or both
6159 -- names that are known to denote the same object (RM 6.4.1(6.8/3))
6160
6161 elsif Nkind (Obj1) = N_Indexed_Component then
6162 if not Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2)) then
6163 return False;
6164 else
6165 declare
6166 Indx1 : Node_Id;
6167 Indx2 : Node_Id;
6168
6169 begin
6170 Indx1 := First (Expressions (Obj1));
6171 Indx2 := First (Expressions (Obj2));
6172 while Present (Indx1) loop
6173
6174 -- Indexes must denote the same static value or same object
6175
6176 if Is_OK_Static_Expression (Indx1) then
6177 if not Is_OK_Static_Expression (Indx2) then
6178 return False;
6179
6180 elsif Expr_Value (Indx1) /= Expr_Value (Indx2) then
6181 return False;
6182 end if;
6183
6184 elsif not Denotes_Same_Object (Indx1, Indx2) then
6185 return False;
6186 end if;
6187
6188 Next (Indx1);
6189 Next (Indx2);
6190 end loop;
6191
6192 return True;
6193 end;
6194 end if;
6195
6196 -- Both names are slices, their prefixes are known to denote the same
6197 -- object, and the two slices have statically matching index constraints
6198 -- (RM 6.4.1(6.9/3))
6199
6200 elsif Nkind (Obj1) = N_Slice
6201 and then Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
6202 then
6203 declare
6204 Lo1, Lo2, Hi1, Hi2 : Node_Id;
6205
6206 begin
6207 Get_Index_Bounds (Etype (Obj1), Lo1, Hi1);
6208 Get_Index_Bounds (Etype (Obj2), Lo2, Hi2);
6209
6210 -- Check whether bounds are statically identical. There is no
6211 -- attempt to detect partial overlap of slices.
6212
6213 return Denotes_Same_Object (Lo1, Lo2)
6214 and then
6215 Denotes_Same_Object (Hi1, Hi2);
6216 end;
6217
6218 -- In the recursion, literals appear as indexes
6219
6220 elsif Nkind (Obj1) = N_Integer_Literal
6221 and then
6222 Nkind (Obj2) = N_Integer_Literal
6223 then
6224 return Intval (Obj1) = Intval (Obj2);
6225
6226 else
6227 return False;
6228 end if;
6229 end Denotes_Same_Object;
6230
6231 -------------------------
6232 -- Denotes_Same_Prefix --
6233 -------------------------
6234
6235 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
6236 begin
6237 if Is_Entity_Name (A1) then
6238 if Nkind_In (A2, N_Selected_Component, N_Indexed_Component)
6239 and then not Is_Access_Type (Etype (A1))
6240 then
6241 return Denotes_Same_Object (A1, Prefix (A2))
6242 or else Denotes_Same_Prefix (A1, Prefix (A2));
6243 else
6244 return False;
6245 end if;
6246
6247 elsif Is_Entity_Name (A2) then
6248 return Denotes_Same_Prefix (A1 => A2, A2 => A1);
6249
6250 elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
6251 and then
6252 Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
6253 then
6254 declare
6255 Root1, Root2 : Node_Id;
6256 Depth1, Depth2 : Nat := 0;
6257
6258 begin
6259 Root1 := Prefix (A1);
6260 while not Is_Entity_Name (Root1) loop
6261 if not Nkind_In
6262 (Root1, N_Selected_Component, N_Indexed_Component)
6263 then
6264 return False;
6265 else
6266 Root1 := Prefix (Root1);
6267 end if;
6268
6269 Depth1 := Depth1 + 1;
6270 end loop;
6271
6272 Root2 := Prefix (A2);
6273 while not Is_Entity_Name (Root2) loop
6274 if not Nkind_In (Root2, N_Selected_Component,
6275 N_Indexed_Component)
6276 then
6277 return False;
6278 else
6279 Root2 := Prefix (Root2);
6280 end if;
6281
6282 Depth2 := Depth2 + 1;
6283 end loop;
6284
6285 -- If both have the same depth and they do not denote the same
6286 -- object, they are disjoint and no warning is needed.
6287
6288 if Depth1 = Depth2 then
6289 return False;
6290
6291 elsif Depth1 > Depth2 then
6292 Root1 := Prefix (A1);
6293 for J in 1 .. Depth1 - Depth2 - 1 loop
6294 Root1 := Prefix (Root1);
6295 end loop;
6296
6297 return Denotes_Same_Object (Root1, A2);
6298
6299 else
6300 Root2 := Prefix (A2);
6301 for J in 1 .. Depth2 - Depth1 - 1 loop
6302 Root2 := Prefix (Root2);
6303 end loop;
6304
6305 return Denotes_Same_Object (A1, Root2);
6306 end if;
6307 end;
6308
6309 else
6310 return False;
6311 end if;
6312 end Denotes_Same_Prefix;
6313
6314 ----------------------
6315 -- Denotes_Variable --
6316 ----------------------
6317
6318 function Denotes_Variable (N : Node_Id) return Boolean is
6319 begin
6320 return Is_Variable (N) and then Paren_Count (N) = 0;
6321 end Denotes_Variable;
6322
6323 -----------------------------
6324 -- Depends_On_Discriminant --
6325 -----------------------------
6326
6327 function Depends_On_Discriminant (N : Node_Id) return Boolean is
6328 L : Node_Id;
6329 H : Node_Id;
6330
6331 begin
6332 Get_Index_Bounds (N, L, H);
6333 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
6334 end Depends_On_Discriminant;
6335
6336 -------------------------
6337 -- Designate_Same_Unit --
6338 -------------------------
6339
6340 function Designate_Same_Unit
6341 (Name1 : Node_Id;
6342 Name2 : Node_Id) return Boolean
6343 is
6344 K1 : constant Node_Kind := Nkind (Name1);
6345 K2 : constant Node_Kind := Nkind (Name2);
6346
6347 function Prefix_Node (N : Node_Id) return Node_Id;
6348 -- Returns the parent unit name node of a defining program unit name
6349 -- or the prefix if N is a selected component or an expanded name.
6350
6351 function Select_Node (N : Node_Id) return Node_Id;
6352 -- Returns the defining identifier node of a defining program unit
6353 -- name or the selector node if N is a selected component or an
6354 -- expanded name.
6355
6356 -----------------
6357 -- Prefix_Node --
6358 -----------------
6359
6360 function Prefix_Node (N : Node_Id) return Node_Id is
6361 begin
6362 if Nkind (N) = N_Defining_Program_Unit_Name then
6363 return Name (N);
6364 else
6365 return Prefix (N);
6366 end if;
6367 end Prefix_Node;
6368
6369 -----------------
6370 -- Select_Node --
6371 -----------------
6372
6373 function Select_Node (N : Node_Id) return Node_Id is
6374 begin
6375 if Nkind (N) = N_Defining_Program_Unit_Name then
6376 return Defining_Identifier (N);
6377 else
6378 return Selector_Name (N);
6379 end if;
6380 end Select_Node;
6381
6382 -- Start of processing for Designate_Same_Unit
6383
6384 begin
6385 if Nkind_In (K1, N_Identifier, N_Defining_Identifier)
6386 and then
6387 Nkind_In (K2, N_Identifier, N_Defining_Identifier)
6388 then
6389 return Chars (Name1) = Chars (Name2);
6390
6391 elsif Nkind_In (K1, N_Expanded_Name,
6392 N_Selected_Component,
6393 N_Defining_Program_Unit_Name)
6394 and then
6395 Nkind_In (K2, N_Expanded_Name,
6396 N_Selected_Component,
6397 N_Defining_Program_Unit_Name)
6398 then
6399 return
6400 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
6401 and then
6402 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
6403
6404 else
6405 return False;
6406 end if;
6407 end Designate_Same_Unit;
6408
6409 ---------------------------------------------
6410 -- Diagnose_Iterated_Component_Association --
6411 ---------------------------------------------
6412
6413 procedure Diagnose_Iterated_Component_Association (N : Node_Id) is
6414 Def_Id : constant Entity_Id := Defining_Identifier (N);
6415 Aggr : Node_Id;
6416
6417 begin
6418 -- Determine whether the iterated component association appears within
6419 -- an aggregate. If this is the case, raise Program_Error because the
6420 -- iterated component association cannot be left in the tree as is and
6421 -- must always be processed by the related aggregate.
6422
6423 Aggr := N;
6424 while Present (Aggr) loop
6425 if Nkind (Aggr) = N_Aggregate then
6426 raise Program_Error;
6427
6428 -- Prevent the search from going too far
6429
6430 elsif Is_Body_Or_Package_Declaration (Aggr) then
6431 exit;
6432 end if;
6433
6434 Aggr := Parent (Aggr);
6435 end loop;
6436
6437 -- At this point it is known that the iterated component association is
6438 -- not within an aggregate. This is really a quantified expression with
6439 -- a missing "all" or "some" quantifier.
6440
6441 Error_Msg_N ("missing quantifier", Def_Id);
6442
6443 -- Rewrite the iterated component association as True to prevent any
6444 -- cascaded errors.
6445
6446 Rewrite (N, New_Occurrence_Of (Standard_True, Sloc (N)));
6447 Analyze (N);
6448 end Diagnose_Iterated_Component_Association;
6449
6450 ---------------------------------
6451 -- Dynamic_Accessibility_Level --
6452 ---------------------------------
6453
6454 function Dynamic_Accessibility_Level (N : Node_Id) return Node_Id is
6455 Loc : constant Source_Ptr := Sloc (N);
6456
6457 function Make_Level_Literal (Level : Uint) return Node_Id;
6458 -- Construct an integer literal representing an accessibility level
6459 -- with its type set to Natural.
6460
6461 ------------------------
6462 -- Make_Level_Literal --
6463 ------------------------
6464
6465 function Make_Level_Literal (Level : Uint) return Node_Id is
6466 Result : constant Node_Id := Make_Integer_Literal (Loc, Level);
6467
6468 begin
6469 Set_Etype (Result, Standard_Natural);
6470 return Result;
6471 end Make_Level_Literal;
6472
6473 -- Local variables
6474
6475 Expr : constant Node_Id := Original_Node (N);
6476 -- Expr references the original node because at this stage N may be the
6477 -- reference to a variable internally created by the frontend to remove
6478 -- side effects of an expression.
6479
6480 E : Entity_Id;
6481
6482 -- Start of processing for Dynamic_Accessibility_Level
6483
6484 begin
6485 if Is_Entity_Name (Expr) then
6486 E := Entity (Expr);
6487
6488 if Present (Renamed_Object (E)) then
6489 return Dynamic_Accessibility_Level (Renamed_Object (E));
6490 end if;
6491
6492 if Is_Formal (E) or else Ekind_In (E, E_Variable, E_Constant) then
6493 if Present (Extra_Accessibility (E)) then
6494 return New_Occurrence_Of (Extra_Accessibility (E), Loc);
6495 end if;
6496 end if;
6497 end if;
6498
6499 -- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
6500
6501 case Nkind (Expr) is
6502
6503 -- For access discriminant, the level of the enclosing object
6504
6505 when N_Selected_Component =>
6506 if Ekind (Entity (Selector_Name (Expr))) = E_Discriminant
6507 and then Ekind (Etype (Entity (Selector_Name (Expr)))) =
6508 E_Anonymous_Access_Type
6509 then
6510 return Make_Level_Literal (Object_Access_Level (Expr));
6511 end if;
6512
6513 when N_Attribute_Reference =>
6514 case Get_Attribute_Id (Attribute_Name (Expr)) is
6515
6516 -- For X'Access, the level of the prefix X
6517
6518 when Attribute_Access =>
6519 return Make_Level_Literal
6520 (Object_Access_Level (Prefix (Expr)));
6521
6522 -- Treat the unchecked attributes as library-level
6523
6524 when Attribute_Unchecked_Access
6525 | Attribute_Unrestricted_Access
6526 =>
6527 return Make_Level_Literal (Scope_Depth (Standard_Standard));
6528
6529 -- No other access-valued attributes
6530
6531 when others =>
6532 raise Program_Error;
6533 end case;
6534
6535 when N_Allocator =>
6536
6537 -- This is not fully implemented since it depends on context (see
6538 -- 3.10.2(14/3-14.2/3). More work is needed in the following cases
6539 --
6540 -- 1) For an anonymous allocator defining the value of an access
6541 -- parameter, the accessibility level is that of the innermost
6542 -- master of the call; however currently we pass the level of
6543 -- execution of the called subprogram, which is one greater
6544 -- than the current scope level (see Expand_Call_Helper).
6545 --
6546 -- For example, a statement is a master and a declaration is
6547 -- not a master; so we should not pass in the same level for
6548 -- the following cases:
6549 --
6550 -- function F (X : access Integer) return T is ... ;
6551 -- Decl : T := F (new Integer); -- level is off by one
6552 -- begin
6553 -- Decl := F (new Integer); -- we get this case right
6554 --
6555 -- 2) For an anonymous allocator that defines the result of a
6556 -- function with an access result, the accessibility level is
6557 -- determined as though the allocator were in place of the call
6558 -- of the function. In the special case of a call that is the
6559 -- operand of a type conversion the level is that of the target
6560 -- access type of the conversion.
6561 --
6562 -- 3) For an anonymous allocator defining an access discriminant
6563 -- the accessibility level is determined as follows:
6564 -- * for an allocator used to define the discriminant of an
6565 -- object, the level of the object
6566 -- * for an allocator used to define the constraint in a
6567 -- subtype_indication in any other context, the level of
6568 -- the master that elaborates the subtype_indication.
6569
6570 case Nkind (Parent (N)) is
6571 when N_Object_Declaration =>
6572
6573 -- For an anonymous allocator whose type is that of a
6574 -- stand-alone object of an anonymous access-to-object type,
6575 -- the accessibility level is that of the declaration of the
6576 -- stand-alone object.
6577
6578 return
6579 Make_Level_Literal
6580 (Object_Access_Level
6581 (Defining_Identifier (Parent (N))));
6582
6583 when N_Assignment_Statement =>
6584 return
6585 Make_Level_Literal
6586 (Object_Access_Level (Name (Parent (N))));
6587
6588 when others =>
6589 declare
6590 S : constant String :=
6591 Node_Kind'Image (Nkind (Parent (N)));
6592 begin
6593 Error_Msg_Strlen := S'Length;
6594 Error_Msg_String (1 .. Error_Msg_Strlen) := S;
6595 Error_Msg_N
6596 ("unsupported context for anonymous allocator (~)",
6597 Parent (N));
6598 end;
6599 end case;
6600
6601 when N_Type_Conversion =>
6602 if not Is_Local_Anonymous_Access (Etype (Expr)) then
6603
6604 -- Handle type conversions introduced for a rename of an
6605 -- Ada 2012 stand-alone object of an anonymous access type.
6606
6607 return Dynamic_Accessibility_Level (Expression (Expr));
6608 end if;
6609
6610 when others =>
6611 null;
6612 end case;
6613
6614 return Make_Level_Literal (Type_Access_Level (Etype (Expr)));
6615 end Dynamic_Accessibility_Level;
6616
6617 ------------------------
6618 -- Discriminated_Size --
6619 ------------------------
6620
6621 function Discriminated_Size (Comp : Entity_Id) return Boolean is
6622 function Non_Static_Bound (Bound : Node_Id) return Boolean;
6623 -- Check whether the bound of an index is non-static and does denote
6624 -- a discriminant, in which case any object of the type (protected or
6625 -- otherwise) will have a non-static size.
6626
6627 ----------------------
6628 -- Non_Static_Bound --
6629 ----------------------
6630
6631 function Non_Static_Bound (Bound : Node_Id) return Boolean is
6632 begin
6633 if Is_OK_Static_Expression (Bound) then
6634 return False;
6635
6636 -- If the bound is given by a discriminant it is non-static
6637 -- (A static constraint replaces the reference with the value).
6638 -- In an protected object the discriminant has been replaced by
6639 -- the corresponding discriminal within the protected operation.
6640
6641 elsif Is_Entity_Name (Bound)
6642 and then
6643 (Ekind (Entity (Bound)) = E_Discriminant
6644 or else Present (Discriminal_Link (Entity (Bound))))
6645 then
6646 return False;
6647
6648 else
6649 return True;
6650 end if;
6651 end Non_Static_Bound;
6652
6653 -- Local variables
6654
6655 Typ : constant Entity_Id := Etype (Comp);
6656 Index : Node_Id;
6657
6658 -- Start of processing for Discriminated_Size
6659
6660 begin
6661 if not Is_Array_Type (Typ) then
6662 return False;
6663 end if;
6664
6665 if Ekind (Typ) = E_Array_Subtype then
6666 Index := First_Index (Typ);
6667 while Present (Index) loop
6668 if Non_Static_Bound (Low_Bound (Index))
6669 or else Non_Static_Bound (High_Bound (Index))
6670 then
6671 return False;
6672 end if;
6673
6674 Next_Index (Index);
6675 end loop;
6676
6677 return True;
6678 end if;
6679
6680 return False;
6681 end Discriminated_Size;
6682
6683 -----------------------------------
6684 -- Effective_Extra_Accessibility --
6685 -----------------------------------
6686
6687 function Effective_Extra_Accessibility (Id : Entity_Id) return Entity_Id is
6688 begin
6689 if Present (Renamed_Object (Id))
6690 and then Is_Entity_Name (Renamed_Object (Id))
6691 then
6692 return Effective_Extra_Accessibility (Entity (Renamed_Object (Id)));
6693 else
6694 return Extra_Accessibility (Id);
6695 end if;
6696 end Effective_Extra_Accessibility;
6697
6698 -----------------------------
6699 -- Effective_Reads_Enabled --
6700 -----------------------------
6701
6702 function Effective_Reads_Enabled (Id : Entity_Id) return Boolean is
6703 begin
6704 return Has_Enabled_Property (Id, Name_Effective_Reads);
6705 end Effective_Reads_Enabled;
6706
6707 ------------------------------
6708 -- Effective_Writes_Enabled --
6709 ------------------------------
6710
6711 function Effective_Writes_Enabled (Id : Entity_Id) return Boolean is
6712 begin
6713 return Has_Enabled_Property (Id, Name_Effective_Writes);
6714 end Effective_Writes_Enabled;
6715
6716 ------------------------------
6717 -- Enclosing_Comp_Unit_Node --
6718 ------------------------------
6719
6720 function Enclosing_Comp_Unit_Node (N : Node_Id) return Node_Id is
6721 Current_Node : Node_Id;
6722
6723 begin
6724 Current_Node := N;
6725 while Present (Current_Node)
6726 and then Nkind (Current_Node) /= N_Compilation_Unit
6727 loop
6728 Current_Node := Parent (Current_Node);
6729 end loop;
6730
6731 if Nkind (Current_Node) /= N_Compilation_Unit then
6732 return Empty;
6733 else
6734 return Current_Node;
6735 end if;
6736 end Enclosing_Comp_Unit_Node;
6737
6738 --------------------------
6739 -- Enclosing_CPP_Parent --
6740 --------------------------
6741
6742 function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is
6743 Parent_Typ : Entity_Id := Typ;
6744
6745 begin
6746 while not Is_CPP_Class (Parent_Typ)
6747 and then Etype (Parent_Typ) /= Parent_Typ
6748 loop
6749 Parent_Typ := Etype (Parent_Typ);
6750
6751 if Is_Private_Type (Parent_Typ) then
6752 Parent_Typ := Full_View (Base_Type (Parent_Typ));
6753 end if;
6754 end loop;
6755
6756 pragma Assert (Is_CPP_Class (Parent_Typ));
6757 return Parent_Typ;
6758 end Enclosing_CPP_Parent;
6759
6760 ---------------------------
6761 -- Enclosing_Declaration --
6762 ---------------------------
6763
6764 function Enclosing_Declaration (N : Node_Id) return Node_Id is
6765 Decl : Node_Id := N;
6766
6767 begin
6768 while Present (Decl)
6769 and then not (Nkind (Decl) in N_Declaration
6770 or else
6771 Nkind (Decl) in N_Later_Decl_Item
6772 or else
6773 Nkind (Decl) = N_Number_Declaration)
6774 loop
6775 Decl := Parent (Decl);
6776 end loop;
6777
6778 return Decl;
6779 end Enclosing_Declaration;
6780
6781 ----------------------------
6782 -- Enclosing_Generic_Body --
6783 ----------------------------
6784
6785 function Enclosing_Generic_Body (N : Node_Id) return Node_Id is
6786 Par : Node_Id;
6787 Spec_Id : Entity_Id;
6788
6789 begin
6790 Par := Parent (N);
6791 while Present (Par) loop
6792 if Nkind_In (Par, N_Package_Body, N_Subprogram_Body) then
6793 Spec_Id := Corresponding_Spec (Par);
6794
6795 if Present (Spec_Id)
6796 and then Nkind_In (Unit_Declaration_Node (Spec_Id),
6797 N_Generic_Package_Declaration,
6798 N_Generic_Subprogram_Declaration)
6799 then
6800 return Par;
6801 end if;
6802 end if;
6803
6804 Par := Parent (Par);
6805 end loop;
6806
6807 return Empty;
6808 end Enclosing_Generic_Body;
6809
6810 ----------------------------
6811 -- Enclosing_Generic_Unit --
6812 ----------------------------
6813
6814 function Enclosing_Generic_Unit (N : Node_Id) return Node_Id is
6815 Par : Node_Id;
6816 Spec_Decl : Node_Id;
6817 Spec_Id : Entity_Id;
6818
6819 begin
6820 Par := Parent (N);
6821 while Present (Par) loop
6822 if Nkind_In (Par, N_Generic_Package_Declaration,
6823 N_Generic_Subprogram_Declaration)
6824 then
6825 return Par;
6826
6827 elsif Nkind_In (Par, N_Package_Body, N_Subprogram_Body) then
6828 Spec_Id := Corresponding_Spec (Par);
6829
6830 if Present (Spec_Id) then
6831 Spec_Decl := Unit_Declaration_Node (Spec_Id);
6832
6833 if Nkind_In (Spec_Decl, N_Generic_Package_Declaration,
6834 N_Generic_Subprogram_Declaration)
6835 then
6836 return Spec_Decl;
6837 end if;
6838 end if;
6839 end if;
6840
6841 Par := Parent (Par);
6842 end loop;
6843
6844 return Empty;
6845 end Enclosing_Generic_Unit;
6846
6847 -------------------------------
6848 -- Enclosing_Lib_Unit_Entity --
6849 -------------------------------
6850
6851 function Enclosing_Lib_Unit_Entity
6852 (E : Entity_Id := Current_Scope) return Entity_Id
6853 is
6854 Unit_Entity : Entity_Id;
6855
6856 begin
6857 -- Look for enclosing library unit entity by following scope links.
6858 -- Equivalent to, but faster than indexing through the scope stack.
6859
6860 Unit_Entity := E;
6861 while (Present (Scope (Unit_Entity))
6862 and then Scope (Unit_Entity) /= Standard_Standard)
6863 and not Is_Child_Unit (Unit_Entity)
6864 loop
6865 Unit_Entity := Scope (Unit_Entity);
6866 end loop;
6867
6868 return Unit_Entity;
6869 end Enclosing_Lib_Unit_Entity;
6870
6871 -----------------------------
6872 -- Enclosing_Lib_Unit_Node --
6873 -----------------------------
6874
6875 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
6876 Encl_Unit : Node_Id;
6877
6878 begin
6879 Encl_Unit := Enclosing_Comp_Unit_Node (N);
6880 while Present (Encl_Unit)
6881 and then Nkind (Unit (Encl_Unit)) = N_Subunit
6882 loop
6883 Encl_Unit := Library_Unit (Encl_Unit);
6884 end loop;
6885
6886 pragma Assert (Nkind (Encl_Unit) = N_Compilation_Unit);
6887 return Encl_Unit;
6888 end Enclosing_Lib_Unit_Node;
6889
6890 -----------------------
6891 -- Enclosing_Package --
6892 -----------------------
6893
6894 function Enclosing_Package (E : Entity_Id) return Entity_Id is
6895 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
6896
6897 begin
6898 if Dynamic_Scope = Standard_Standard then
6899 return Standard_Standard;
6900
6901 elsif Dynamic_Scope = Empty then
6902 return Empty;
6903
6904 elsif Ekind_In (Dynamic_Scope, E_Generic_Package,
6905 E_Package,
6906 E_Package_Body)
6907 then
6908 return Dynamic_Scope;
6909
6910 else
6911 return Enclosing_Package (Dynamic_Scope);
6912 end if;
6913 end Enclosing_Package;
6914
6915 -------------------------------------
6916 -- Enclosing_Package_Or_Subprogram --
6917 -------------------------------------
6918
6919 function Enclosing_Package_Or_Subprogram (E : Entity_Id) return Entity_Id is
6920 S : Entity_Id;
6921
6922 begin
6923 S := Scope (E);
6924 while Present (S) loop
6925 if Is_Package_Or_Generic_Package (S)
6926 or else Is_Subprogram_Or_Generic_Subprogram (S)
6927 then
6928 return S;
6929
6930 else
6931 S := Scope (S);
6932 end if;
6933 end loop;
6934
6935 return Empty;
6936 end Enclosing_Package_Or_Subprogram;
6937
6938 --------------------------
6939 -- Enclosing_Subprogram --
6940 --------------------------
6941
6942 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
6943 Dyn_Scop : constant Entity_Id := Enclosing_Dynamic_Scope (E);
6944
6945 begin
6946 if Dyn_Scop = Standard_Standard then
6947 return Empty;
6948
6949 elsif Dyn_Scop = Empty then
6950 return Empty;
6951
6952 elsif Ekind (Dyn_Scop) = E_Subprogram_Body then
6953 return Corresponding_Spec (Parent (Parent (Dyn_Scop)));
6954
6955 elsif Ekind_In (Dyn_Scop, E_Block, E_Loop, E_Return_Statement) then
6956 return Enclosing_Subprogram (Dyn_Scop);
6957
6958 elsif Ekind (Dyn_Scop) = E_Entry then
6959
6960 -- For a task entry, return the enclosing subprogram of the
6961 -- task itself.
6962
6963 if Ekind (Scope (Dyn_Scop)) = E_Task_Type then
6964 return Enclosing_Subprogram (Dyn_Scop);
6965
6966 -- A protected entry is rewritten as a protected procedure which is
6967 -- the desired enclosing subprogram. This is relevant when unnesting
6968 -- a procedure local to an entry body.
6969
6970 else
6971 return Protected_Body_Subprogram (Dyn_Scop);
6972 end if;
6973
6974 elsif Ekind (Dyn_Scop) = E_Task_Type then
6975 return Get_Task_Body_Procedure (Dyn_Scop);
6976
6977 -- The scope may appear as a private type or as a private extension
6978 -- whose completion is a task or protected type.
6979
6980 elsif Ekind_In (Dyn_Scop, E_Limited_Private_Type,
6981 E_Record_Type_With_Private)
6982 and then Present (Full_View (Dyn_Scop))
6983 and then Ekind_In (Full_View (Dyn_Scop), E_Task_Type, E_Protected_Type)
6984 then
6985 return Get_Task_Body_Procedure (Full_View (Dyn_Scop));
6986
6987 -- No body is generated if the protected operation is eliminated
6988
6989 elsif Convention (Dyn_Scop) = Convention_Protected
6990 and then not Is_Eliminated (Dyn_Scop)
6991 and then Present (Protected_Body_Subprogram (Dyn_Scop))
6992 then
6993 return Protected_Body_Subprogram (Dyn_Scop);
6994
6995 else
6996 return Dyn_Scop;
6997 end if;
6998 end Enclosing_Subprogram;
6999
7000 --------------------------
7001 -- End_Keyword_Location --
7002 --------------------------
7003
7004 function End_Keyword_Location (N : Node_Id) return Source_Ptr is
7005 function End_Label_Loc (Nod : Node_Id) return Source_Ptr;
7006 -- Return the source location of Nod's end label according to the
7007 -- following precedence rules:
7008 --
7009 -- 1) If the end label exists, return its location
7010 -- 2) If Nod exists, return its location
7011 -- 3) Return the location of N
7012
7013 -------------------
7014 -- End_Label_Loc --
7015 -------------------
7016
7017 function End_Label_Loc (Nod : Node_Id) return Source_Ptr is
7018 Label : Node_Id;
7019
7020 begin
7021 if Present (Nod) then
7022 Label := End_Label (Nod);
7023
7024 if Present (Label) then
7025 return Sloc (Label);
7026 else
7027 return Sloc (Nod);
7028 end if;
7029
7030 else
7031 return Sloc (N);
7032 end if;
7033 end End_Label_Loc;
7034
7035 -- Local variables
7036
7037 Owner : Node_Id;
7038
7039 -- Start of processing for End_Keyword_Location
7040
7041 begin
7042 if Nkind_In (N, N_Block_Statement,
7043 N_Entry_Body,
7044 N_Package_Body,
7045 N_Subprogram_Body,
7046 N_Task_Body)
7047 then
7048 Owner := Handled_Statement_Sequence (N);
7049
7050 elsif Nkind (N) = N_Package_Declaration then
7051 Owner := Specification (N);
7052
7053 elsif Nkind (N) = N_Protected_Body then
7054 Owner := N;
7055
7056 elsif Nkind_In (N, N_Protected_Type_Declaration,
7057 N_Single_Protected_Declaration)
7058 then
7059 Owner := Protected_Definition (N);
7060
7061 elsif Nkind_In (N, N_Single_Task_Declaration,
7062 N_Task_Type_Declaration)
7063 then
7064 Owner := Task_Definition (N);
7065
7066 -- This routine should not be called with other contexts
7067
7068 else
7069 pragma Assert (False);
7070 null;
7071 end if;
7072
7073 return End_Label_Loc (Owner);
7074 end End_Keyword_Location;
7075
7076 ------------------------
7077 -- Ensure_Freeze_Node --
7078 ------------------------
7079
7080 procedure Ensure_Freeze_Node (E : Entity_Id) is
7081 FN : Node_Id;
7082 begin
7083 if No (Freeze_Node (E)) then
7084 FN := Make_Freeze_Entity (Sloc (E));
7085 Set_Has_Delayed_Freeze (E);
7086 Set_Freeze_Node (E, FN);
7087 Set_Access_Types_To_Process (FN, No_Elist);
7088 Set_TSS_Elist (FN, No_Elist);
7089 Set_Entity (FN, E);
7090 end if;
7091 end Ensure_Freeze_Node;
7092
7093 ----------------
7094 -- Enter_Name --
7095 ----------------
7096
7097 procedure Enter_Name (Def_Id : Entity_Id) is
7098 C : constant Entity_Id := Current_Entity (Def_Id);
7099 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
7100 S : constant Entity_Id := Current_Scope;
7101
7102 begin
7103 Generate_Definition (Def_Id);
7104
7105 -- Add new name to current scope declarations. Check for duplicate
7106 -- declaration, which may or may not be a genuine error.
7107
7108 if Present (E) then
7109
7110 -- Case of previous entity entered because of a missing declaration
7111 -- or else a bad subtype indication. Best is to use the new entity,
7112 -- and make the previous one invisible.
7113
7114 if Etype (E) = Any_Type then
7115 Set_Is_Immediately_Visible (E, False);
7116
7117 -- Case of renaming declaration constructed for package instances.
7118 -- if there is an explicit declaration with the same identifier,
7119 -- the renaming is not immediately visible any longer, but remains
7120 -- visible through selected component notation.
7121
7122 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
7123 and then not Comes_From_Source (E)
7124 then
7125 Set_Is_Immediately_Visible (E, False);
7126
7127 -- The new entity may be the package renaming, which has the same
7128 -- same name as a generic formal which has been seen already.
7129
7130 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
7131 and then not Comes_From_Source (Def_Id)
7132 then
7133 Set_Is_Immediately_Visible (E, False);
7134
7135 -- For a fat pointer corresponding to a remote access to subprogram,
7136 -- we use the same identifier as the RAS type, so that the proper
7137 -- name appears in the stub. This type is only retrieved through
7138 -- the RAS type and never by visibility, and is not added to the
7139 -- visibility list (see below).
7140
7141 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
7142 and then Ekind (Def_Id) = E_Record_Type
7143 and then Present (Corresponding_Remote_Type (Def_Id))
7144 then
7145 null;
7146
7147 -- Case of an implicit operation or derived literal. The new entity
7148 -- hides the implicit one, which is removed from all visibility,
7149 -- i.e. the entity list of its scope, and homonym chain of its name.
7150
7151 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
7152 or else Is_Internal (E)
7153 then
7154 declare
7155 Decl : constant Node_Id := Parent (E);
7156 Prev : Entity_Id;
7157 Prev_Vis : Entity_Id;
7158
7159 begin
7160 -- If E is an implicit declaration, it cannot be the first
7161 -- entity in the scope.
7162
7163 Prev := First_Entity (Current_Scope);
7164 while Present (Prev) and then Next_Entity (Prev) /= E loop
7165 Next_Entity (Prev);
7166 end loop;
7167
7168 if No (Prev) then
7169
7170 -- If E is not on the entity chain of the current scope,
7171 -- it is an implicit declaration in the generic formal
7172 -- part of a generic subprogram. When analyzing the body,
7173 -- the generic formals are visible but not on the entity
7174 -- chain of the subprogram. The new entity will become
7175 -- the visible one in the body.
7176
7177 pragma Assert
7178 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
7179 null;
7180
7181 else
7182 Link_Entities (Prev, Next_Entity (E));
7183
7184 if No (Next_Entity (Prev)) then
7185 Set_Last_Entity (Current_Scope, Prev);
7186 end if;
7187
7188 if E = Current_Entity (E) then
7189 Prev_Vis := Empty;
7190
7191 else
7192 Prev_Vis := Current_Entity (E);
7193 while Homonym (Prev_Vis) /= E loop
7194 Prev_Vis := Homonym (Prev_Vis);
7195 end loop;
7196 end if;
7197
7198 if Present (Prev_Vis) then
7199
7200 -- Skip E in the visibility chain
7201
7202 Set_Homonym (Prev_Vis, Homonym (E));
7203
7204 else
7205 Set_Name_Entity_Id (Chars (E), Homonym (E));
7206 end if;
7207 end if;
7208 end;
7209
7210 -- This section of code could use a comment ???
7211
7212 elsif Present (Etype (E))
7213 and then Is_Concurrent_Type (Etype (E))
7214 and then E = Def_Id
7215 then
7216 return;
7217
7218 -- If the homograph is a protected component renaming, it should not
7219 -- be hiding the current entity. Such renamings are treated as weak
7220 -- declarations.
7221
7222 elsif Is_Prival (E) then
7223 Set_Is_Immediately_Visible (E, False);
7224
7225 -- In this case the current entity is a protected component renaming.
7226 -- Perform minimal decoration by setting the scope and return since
7227 -- the prival should not be hiding other visible entities.
7228
7229 elsif Is_Prival (Def_Id) then
7230 Set_Scope (Def_Id, Current_Scope);
7231 return;
7232
7233 -- Analogous to privals, the discriminal generated for an entry index
7234 -- parameter acts as a weak declaration. Perform minimal decoration
7235 -- to avoid bogus errors.
7236
7237 elsif Is_Discriminal (Def_Id)
7238 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
7239 then
7240 Set_Scope (Def_Id, Current_Scope);
7241 return;
7242
7243 -- In the body or private part of an instance, a type extension may
7244 -- introduce a component with the same name as that of an actual. The
7245 -- legality rule is not enforced, but the semantics of the full type
7246 -- with two components of same name are not clear at this point???
7247
7248 elsif In_Instance_Not_Visible then
7249 null;
7250
7251 -- When compiling a package body, some child units may have become
7252 -- visible. They cannot conflict with local entities that hide them.
7253
7254 elsif Is_Child_Unit (E)
7255 and then In_Open_Scopes (Scope (E))
7256 and then not Is_Immediately_Visible (E)
7257 then
7258 null;
7259
7260 -- Conversely, with front-end inlining we may compile the parent body
7261 -- first, and a child unit subsequently. The context is now the
7262 -- parent spec, and body entities are not visible.
7263
7264 elsif Is_Child_Unit (Def_Id)
7265 and then Is_Package_Body_Entity (E)
7266 and then not In_Package_Body (Current_Scope)
7267 then
7268 null;
7269
7270 -- Case of genuine duplicate declaration
7271
7272 else
7273 Error_Msg_Sloc := Sloc (E);
7274
7275 -- If the previous declaration is an incomplete type declaration
7276 -- this may be an attempt to complete it with a private type. The
7277 -- following avoids confusing cascaded errors.
7278
7279 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
7280 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
7281 then
7282 Error_Msg_N
7283 ("incomplete type cannot be completed with a private " &
7284 "declaration", Parent (Def_Id));
7285 Set_Is_Immediately_Visible (E, False);
7286 Set_Full_View (E, Def_Id);
7287
7288 -- An inherited component of a record conflicts with a new
7289 -- discriminant. The discriminant is inserted first in the scope,
7290 -- but the error should be posted on it, not on the component.
7291
7292 elsif Ekind (E) = E_Discriminant
7293 and then Present (Scope (Def_Id))
7294 and then Scope (Def_Id) /= Current_Scope
7295 then
7296 Error_Msg_Sloc := Sloc (Def_Id);
7297 Error_Msg_N ("& conflicts with declaration#", E);
7298 return;
7299
7300 -- If the name of the unit appears in its own context clause, a
7301 -- dummy package with the name has already been created, and the
7302 -- error emitted. Try to continue quietly.
7303
7304 elsif Error_Posted (E)
7305 and then Sloc (E) = No_Location
7306 and then Nkind (Parent (E)) = N_Package_Specification
7307 and then Current_Scope = Standard_Standard
7308 then
7309 Set_Scope (Def_Id, Current_Scope);
7310 return;
7311
7312 else
7313 Error_Msg_N ("& conflicts with declaration#", Def_Id);
7314
7315 -- Avoid cascaded messages with duplicate components in
7316 -- derived types.
7317
7318 if Ekind_In (E, E_Component, E_Discriminant) then
7319 return;
7320 end if;
7321 end if;
7322
7323 if Nkind (Parent (Parent (Def_Id))) =
7324 N_Generic_Subprogram_Declaration
7325 and then Def_Id =
7326 Defining_Entity (Specification (Parent (Parent (Def_Id))))
7327 then
7328 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
7329 end if;
7330
7331 -- If entity is in standard, then we are in trouble, because it
7332 -- means that we have a library package with a duplicated name.
7333 -- That's hard to recover from, so abort.
7334
7335 if S = Standard_Standard then
7336 raise Unrecoverable_Error;
7337
7338 -- Otherwise we continue with the declaration. Having two
7339 -- identical declarations should not cause us too much trouble.
7340
7341 else
7342 null;
7343 end if;
7344 end if;
7345 end if;
7346
7347 -- If we fall through, declaration is OK, at least OK enough to continue
7348
7349 -- If Def_Id is a discriminant or a record component we are in the midst
7350 -- of inheriting components in a derived record definition. Preserve
7351 -- their Ekind and Etype.
7352
7353 if Ekind_In (Def_Id, E_Discriminant, E_Component) then
7354 null;
7355
7356 -- If a type is already set, leave it alone (happens when a type
7357 -- declaration is reanalyzed following a call to the optimizer).
7358
7359 elsif Present (Etype (Def_Id)) then
7360 null;
7361
7362 -- Otherwise, the kind E_Void insures that premature uses of the entity
7363 -- will be detected. Any_Type insures that no cascaded errors will occur
7364
7365 else
7366 Set_Ekind (Def_Id, E_Void);
7367 Set_Etype (Def_Id, Any_Type);
7368 end if;
7369
7370 -- Inherited discriminants and components in derived record types are
7371 -- immediately visible. Itypes are not.
7372
7373 -- Unless the Itype is for a record type with a corresponding remote
7374 -- type (what is that about, it was not commented ???)
7375
7376 if Ekind_In (Def_Id, E_Discriminant, E_Component)
7377 or else
7378 ((not Is_Record_Type (Def_Id)
7379 or else No (Corresponding_Remote_Type (Def_Id)))
7380 and then not Is_Itype (Def_Id))
7381 then
7382 Set_Is_Immediately_Visible (Def_Id);
7383 Set_Current_Entity (Def_Id);
7384 end if;
7385
7386 Set_Homonym (Def_Id, C);
7387 Append_Entity (Def_Id, S);
7388 Set_Public_Status (Def_Id);
7389
7390 -- Declaring a homonym is not allowed in SPARK ...
7391
7392 if Present (C) and then Restriction_Check_Required (SPARK_05) then
7393 declare
7394 Enclosing_Subp : constant Node_Id := Enclosing_Subprogram (Def_Id);
7395 Enclosing_Pack : constant Node_Id := Enclosing_Package (Def_Id);
7396 Other_Scope : constant Node_Id := Enclosing_Dynamic_Scope (C);
7397
7398 begin
7399 -- ... unless the new declaration is in a subprogram, and the
7400 -- visible declaration is a variable declaration or a parameter
7401 -- specification outside that subprogram.
7402
7403 if Present (Enclosing_Subp)
7404 and then Nkind_In (Parent (C), N_Object_Declaration,
7405 N_Parameter_Specification)
7406 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Subp)
7407 then
7408 null;
7409
7410 -- ... or the new declaration is in a package, and the visible
7411 -- declaration occurs outside that package.
7412
7413 elsif Present (Enclosing_Pack)
7414 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Pack)
7415 then
7416 null;
7417
7418 -- ... or the new declaration is a component declaration in a
7419 -- record type definition.
7420
7421 elsif Nkind (Parent (Def_Id)) = N_Component_Declaration then
7422 null;
7423
7424 -- Don't issue error for non-source entities
7425
7426 elsif Comes_From_Source (Def_Id)
7427 and then Comes_From_Source (C)
7428 then
7429 Error_Msg_Sloc := Sloc (C);
7430 Check_SPARK_05_Restriction
7431 ("redeclaration of identifier &#", Def_Id);
7432 end if;
7433 end;
7434 end if;
7435
7436 -- Warn if new entity hides an old one
7437
7438 if Warn_On_Hiding and then Present (C)
7439
7440 -- Don't warn for record components since they always have a well
7441 -- defined scope which does not confuse other uses. Note that in
7442 -- some cases, Ekind has not been set yet.
7443
7444 and then Ekind (C) /= E_Component
7445 and then Ekind (C) /= E_Discriminant
7446 and then Nkind (Parent (C)) /= N_Component_Declaration
7447 and then Ekind (Def_Id) /= E_Component
7448 and then Ekind (Def_Id) /= E_Discriminant
7449 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
7450
7451 -- Don't warn for one character variables. It is too common to use
7452 -- such variables as locals and will just cause too many false hits.
7453
7454 and then Length_Of_Name (Chars (C)) /= 1
7455
7456 -- Don't warn for non-source entities
7457
7458 and then Comes_From_Source (C)
7459 and then Comes_From_Source (Def_Id)
7460
7461 -- Don't warn unless entity in question is in extended main source
7462
7463 and then In_Extended_Main_Source_Unit (Def_Id)
7464
7465 -- Finally, the hidden entity must be either immediately visible or
7466 -- use visible (i.e. from a used package).
7467
7468 and then
7469 (Is_Immediately_Visible (C)
7470 or else
7471 Is_Potentially_Use_Visible (C))
7472 then
7473 Error_Msg_Sloc := Sloc (C);
7474 Error_Msg_N ("declaration hides &#?h?", Def_Id);
7475 end if;
7476 end Enter_Name;
7477
7478 ---------------
7479 -- Entity_Of --
7480 ---------------
7481
7482 function Entity_Of (N : Node_Id) return Entity_Id is
7483 Id : Entity_Id;
7484 Ren : Node_Id;
7485
7486 begin
7487 -- Assume that the arbitrary node does not have an entity
7488
7489 Id := Empty;
7490
7491 if Is_Entity_Name (N) then
7492 Id := Entity (N);
7493
7494 -- Follow a possible chain of renamings to reach the earliest renamed
7495 -- source object.
7496
7497 while Present (Id)
7498 and then Is_Object (Id)
7499 and then Present (Renamed_Object (Id))
7500 loop
7501 Ren := Renamed_Object (Id);
7502
7503 -- The reference renames an abstract state or a whole object
7504
7505 -- Obj : ...;
7506 -- Ren : ... renames Obj;
7507
7508 if Is_Entity_Name (Ren) then
7509
7510 -- Do not follow a renaming that goes through a generic formal,
7511 -- because these entities are hidden and must not be referenced
7512 -- from outside the generic.
7513
7514 if Is_Hidden (Entity (Ren)) then
7515 exit;
7516
7517 else
7518 Id := Entity (Ren);
7519 end if;
7520
7521 -- The reference renames a function result. Check the original
7522 -- node in case expansion relocates the function call.
7523
7524 -- Ren : ... renames Func_Call;
7525
7526 elsif Nkind (Original_Node (Ren)) = N_Function_Call then
7527 exit;
7528
7529 -- Otherwise the reference renames something which does not yield
7530 -- an abstract state or a whole object. Treat the reference as not
7531 -- having a proper entity for SPARK legality purposes.
7532
7533 else
7534 Id := Empty;
7535 exit;
7536 end if;
7537 end loop;
7538 end if;
7539
7540 return Id;
7541 end Entity_Of;
7542
7543 --------------------------
7544 -- Examine_Array_Bounds --
7545 --------------------------
7546
7547 procedure Examine_Array_Bounds
7548 (Typ : Entity_Id;
7549 All_Static : out Boolean;
7550 Has_Empty : out Boolean)
7551 is
7552 function Is_OK_Static_Bound (Bound : Node_Id) return Boolean;
7553 -- Determine whether bound Bound is a suitable static bound
7554
7555 ------------------------
7556 -- Is_OK_Static_Bound --
7557 ------------------------
7558
7559 function Is_OK_Static_Bound (Bound : Node_Id) return Boolean is
7560 begin
7561 return
7562 not Error_Posted (Bound)
7563 and then Is_OK_Static_Expression (Bound);
7564 end Is_OK_Static_Bound;
7565
7566 -- Local variables
7567
7568 Hi_Bound : Node_Id;
7569 Index : Node_Id;
7570 Lo_Bound : Node_Id;
7571
7572 -- Start of processing for Examine_Array_Bounds
7573
7574 begin
7575 -- An unconstrained array type does not have static bounds, and it is
7576 -- not known whether they are empty or not.
7577
7578 if not Is_Constrained (Typ) then
7579 All_Static := False;
7580 Has_Empty := False;
7581
7582 -- A string literal has static bounds, and is not empty as long as it
7583 -- contains at least one character.
7584
7585 elsif Ekind (Typ) = E_String_Literal_Subtype then
7586 All_Static := True;
7587 Has_Empty := String_Literal_Length (Typ) > 0;
7588 end if;
7589
7590 -- Assume that all bounds are static and not empty
7591
7592 All_Static := True;
7593 Has_Empty := False;
7594
7595 -- Examine each index
7596
7597 Index := First_Index (Typ);
7598 while Present (Index) loop
7599 if Is_Discrete_Type (Etype (Index)) then
7600 Get_Index_Bounds (Index, Lo_Bound, Hi_Bound);
7601
7602 if Is_OK_Static_Bound (Lo_Bound)
7603 and then
7604 Is_OK_Static_Bound (Hi_Bound)
7605 then
7606 -- The static bounds produce an empty range
7607
7608 if Is_Null_Range (Lo_Bound, Hi_Bound) then
7609 Has_Empty := True;
7610 end if;
7611
7612 -- Otherwise at least one of the bounds is not static
7613
7614 else
7615 All_Static := False;
7616 end if;
7617
7618 -- Otherwise the index is non-discrete, therefore not static
7619
7620 else
7621 All_Static := False;
7622 end if;
7623
7624 Next_Index (Index);
7625 end loop;
7626 end Examine_Array_Bounds;
7627
7628 -------------------
7629 -- Exceptions_OK --
7630 -------------------
7631
7632 function Exceptions_OK return Boolean is
7633 begin
7634 return
7635 not (Restriction_Active (No_Exception_Handlers) or else
7636 Restriction_Active (No_Exception_Propagation) or else
7637 Restriction_Active (No_Exceptions));
7638 end Exceptions_OK;
7639
7640 --------------------------
7641 -- Explain_Limited_Type --
7642 --------------------------
7643
7644 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
7645 C : Entity_Id;
7646
7647 begin
7648 -- For array, component type must be limited
7649
7650 if Is_Array_Type (T) then
7651 Error_Msg_Node_2 := T;
7652 Error_Msg_NE
7653 ("\component type& of type& is limited", N, Component_Type (T));
7654 Explain_Limited_Type (Component_Type (T), N);
7655
7656 elsif Is_Record_Type (T) then
7657
7658 -- No need for extra messages if explicit limited record
7659
7660 if Is_Limited_Record (Base_Type (T)) then
7661 return;
7662 end if;
7663
7664 -- Otherwise find a limited component. Check only components that
7665 -- come from source, or inherited components that appear in the
7666 -- source of the ancestor.
7667
7668 C := First_Component (T);
7669 while Present (C) loop
7670 if Is_Limited_Type (Etype (C))
7671 and then
7672 (Comes_From_Source (C)
7673 or else
7674 (Present (Original_Record_Component (C))
7675 and then
7676 Comes_From_Source (Original_Record_Component (C))))
7677 then
7678 Error_Msg_Node_2 := T;
7679 Error_Msg_NE ("\component& of type& has limited type", N, C);
7680 Explain_Limited_Type (Etype (C), N);
7681 return;
7682 end if;
7683
7684 Next_Component (C);
7685 end loop;
7686
7687 -- The type may be declared explicitly limited, even if no component
7688 -- of it is limited, in which case we fall out of the loop.
7689 return;
7690 end if;
7691 end Explain_Limited_Type;
7692
7693 ---------------------------------------
7694 -- Expression_Of_Expression_Function --
7695 ---------------------------------------
7696
7697 function Expression_Of_Expression_Function
7698 (Subp : Entity_Id) return Node_Id
7699 is
7700 Expr_Func : Node_Id;
7701
7702 begin
7703 pragma Assert (Is_Expression_Function_Or_Completion (Subp));
7704
7705 if Nkind (Original_Node (Subprogram_Spec (Subp))) =
7706 N_Expression_Function
7707 then
7708 Expr_Func := Original_Node (Subprogram_Spec (Subp));
7709
7710 elsif Nkind (Original_Node (Subprogram_Body (Subp))) =
7711 N_Expression_Function
7712 then
7713 Expr_Func := Original_Node (Subprogram_Body (Subp));
7714
7715 else
7716 pragma Assert (False);
7717 null;
7718 end if;
7719
7720 return Original_Node (Expression (Expr_Func));
7721 end Expression_Of_Expression_Function;
7722
7723 -------------------------------
7724 -- Extensions_Visible_Status --
7725 -------------------------------
7726
7727 function Extensions_Visible_Status
7728 (Id : Entity_Id) return Extensions_Visible_Mode
7729 is
7730 Arg : Node_Id;
7731 Decl : Node_Id;
7732 Expr : Node_Id;
7733 Prag : Node_Id;
7734 Subp : Entity_Id;
7735
7736 begin
7737 -- When a formal parameter is subject to Extensions_Visible, the pragma
7738 -- is stored in the contract of related subprogram.
7739
7740 if Is_Formal (Id) then
7741 Subp := Scope (Id);
7742
7743 elsif Is_Subprogram_Or_Generic_Subprogram (Id) then
7744 Subp := Id;
7745
7746 -- No other construct carries this pragma
7747
7748 else
7749 return Extensions_Visible_None;
7750 end if;
7751
7752 Prag := Get_Pragma (Subp, Pragma_Extensions_Visible);
7753
7754 -- In certain cases analysis may request the Extensions_Visible status
7755 -- of an expression function before the pragma has been analyzed yet.
7756 -- Inspect the declarative items after the expression function looking
7757 -- for the pragma (if any).
7758
7759 if No (Prag) and then Is_Expression_Function (Subp) then
7760 Decl := Next (Unit_Declaration_Node (Subp));
7761 while Present (Decl) loop
7762 if Nkind (Decl) = N_Pragma
7763 and then Pragma_Name (Decl) = Name_Extensions_Visible
7764 then
7765 Prag := Decl;
7766 exit;
7767
7768 -- A source construct ends the region where Extensions_Visible may
7769 -- appear, stop the traversal. An expanded expression function is
7770 -- no longer a source construct, but it must still be recognized.
7771
7772 elsif Comes_From_Source (Decl)
7773 or else
7774 (Nkind_In (Decl, N_Subprogram_Body,
7775 N_Subprogram_Declaration)
7776 and then Is_Expression_Function (Defining_Entity (Decl)))
7777 then
7778 exit;
7779 end if;
7780
7781 Next (Decl);
7782 end loop;
7783 end if;
7784
7785 -- Extract the value from the Boolean expression (if any)
7786
7787 if Present (Prag) then
7788 Arg := First (Pragma_Argument_Associations (Prag));
7789
7790 if Present (Arg) then
7791 Expr := Get_Pragma_Arg (Arg);
7792
7793 -- When the associated subprogram is an expression function, the
7794 -- argument of the pragma may not have been analyzed.
7795
7796 if not Analyzed (Expr) then
7797 Preanalyze_And_Resolve (Expr, Standard_Boolean);
7798 end if;
7799
7800 -- Guard against cascading errors when the argument of pragma
7801 -- Extensions_Visible is not a valid static Boolean expression.
7802
7803 if Error_Posted (Expr) then
7804 return Extensions_Visible_None;
7805
7806 elsif Is_True (Expr_Value (Expr)) then
7807 return Extensions_Visible_True;
7808
7809 else
7810 return Extensions_Visible_False;
7811 end if;
7812
7813 -- Otherwise the aspect or pragma defaults to True
7814
7815 else
7816 return Extensions_Visible_True;
7817 end if;
7818
7819 -- Otherwise aspect or pragma Extensions_Visible is not inherited or
7820 -- directly specified. In SPARK code, its value defaults to "False".
7821
7822 elsif SPARK_Mode = On then
7823 return Extensions_Visible_False;
7824
7825 -- In non-SPARK code, aspect or pragma Extensions_Visible defaults to
7826 -- "True".
7827
7828 else
7829 return Extensions_Visible_True;
7830 end if;
7831 end Extensions_Visible_Status;
7832
7833 -----------------
7834 -- Find_Actual --
7835 -----------------
7836
7837 procedure Find_Actual
7838 (N : Node_Id;
7839 Formal : out Entity_Id;
7840 Call : out Node_Id)
7841 is
7842 Context : constant Node_Id := Parent (N);
7843 Actual : Node_Id;
7844 Call_Nam : Node_Id;
7845
7846 begin
7847 if Nkind_In (Context, N_Indexed_Component, N_Selected_Component)
7848 and then N = Prefix (Context)
7849 then
7850 Find_Actual (Context, Formal, Call);
7851 return;
7852
7853 elsif Nkind (Context) = N_Parameter_Association
7854 and then N = Explicit_Actual_Parameter (Context)
7855 then
7856 Call := Parent (Context);
7857
7858 elsif Nkind_In (Context, N_Entry_Call_Statement,
7859 N_Function_Call,
7860 N_Procedure_Call_Statement)
7861 then
7862 Call := Context;
7863
7864 else
7865 Formal := Empty;
7866 Call := Empty;
7867 return;
7868 end if;
7869
7870 -- If we have a call to a subprogram look for the parameter. Note that
7871 -- we exclude overloaded calls, since we don't know enough to be sure
7872 -- of giving the right answer in this case.
7873
7874 if Nkind_In (Call, N_Entry_Call_Statement,
7875 N_Function_Call,
7876 N_Procedure_Call_Statement)
7877 then
7878 Call_Nam := Name (Call);
7879
7880 -- A call to a protected or task entry appears as a selected
7881 -- component rather than an expanded name.
7882
7883 if Nkind (Call_Nam) = N_Selected_Component then
7884 Call_Nam := Selector_Name (Call_Nam);
7885 end if;
7886
7887 if Is_Entity_Name (Call_Nam)
7888 and then Present (Entity (Call_Nam))
7889 and then Is_Overloadable (Entity (Call_Nam))
7890 and then not Is_Overloaded (Call_Nam)
7891 then
7892 -- If node is name in call it is not an actual
7893
7894 if N = Call_Nam then
7895 Formal := Empty;
7896 Call := Empty;
7897 return;
7898 end if;
7899
7900 -- Fall here if we are definitely a parameter
7901
7902 Actual := First_Actual (Call);
7903 Formal := First_Formal (Entity (Call_Nam));
7904 while Present (Formal) and then Present (Actual) loop
7905 if Actual = N then
7906 return;
7907
7908 -- An actual that is the prefix in a prefixed call may have
7909 -- been rewritten in the call, after the deferred reference
7910 -- was collected. Check if sloc and kinds and names match.
7911
7912 elsif Sloc (Actual) = Sloc (N)
7913 and then Nkind (Actual) = N_Identifier
7914 and then Nkind (Actual) = Nkind (N)
7915 and then Chars (Actual) = Chars (N)
7916 then
7917 return;
7918
7919 else
7920 Actual := Next_Actual (Actual);
7921 Formal := Next_Formal (Formal);
7922 end if;
7923 end loop;
7924 end if;
7925 end if;
7926
7927 -- Fall through here if we did not find matching actual
7928
7929 Formal := Empty;
7930 Call := Empty;
7931 end Find_Actual;
7932
7933 ---------------------------
7934 -- Find_Body_Discriminal --
7935 ---------------------------
7936
7937 function Find_Body_Discriminal
7938 (Spec_Discriminant : Entity_Id) return Entity_Id
7939 is
7940 Tsk : Entity_Id;
7941 Disc : Entity_Id;
7942
7943 begin
7944 -- If expansion is suppressed, then the scope can be the concurrent type
7945 -- itself rather than a corresponding concurrent record type.
7946
7947 if Is_Concurrent_Type (Scope (Spec_Discriminant)) then
7948 Tsk := Scope (Spec_Discriminant);
7949
7950 else
7951 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
7952
7953 Tsk := Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
7954 end if;
7955
7956 -- Find discriminant of original concurrent type, and use its current
7957 -- discriminal, which is the renaming within the task/protected body.
7958
7959 Disc := First_Discriminant (Tsk);
7960 while Present (Disc) loop
7961 if Chars (Disc) = Chars (Spec_Discriminant) then
7962 return Discriminal (Disc);
7963 end if;
7964
7965 Next_Discriminant (Disc);
7966 end loop;
7967
7968 -- That loop should always succeed in finding a matching entry and
7969 -- returning. Fatal error if not.
7970
7971 raise Program_Error;
7972 end Find_Body_Discriminal;
7973
7974 -------------------------------------
7975 -- Find_Corresponding_Discriminant --
7976 -------------------------------------
7977
7978 function Find_Corresponding_Discriminant
7979 (Id : Node_Id;
7980 Typ : Entity_Id) return Entity_Id
7981 is
7982 Par_Disc : Entity_Id;
7983 Old_Disc : Entity_Id;
7984 New_Disc : Entity_Id;
7985
7986 begin
7987 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
7988
7989 -- The original type may currently be private, and the discriminant
7990 -- only appear on its full view.
7991
7992 if Is_Private_Type (Scope (Par_Disc))
7993 and then not Has_Discriminants (Scope (Par_Disc))
7994 and then Present (Full_View (Scope (Par_Disc)))
7995 then
7996 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
7997 else
7998 Old_Disc := First_Discriminant (Scope (Par_Disc));
7999 end if;
8000
8001 if Is_Class_Wide_Type (Typ) then
8002 New_Disc := First_Discriminant (Root_Type (Typ));
8003 else
8004 New_Disc := First_Discriminant (Typ);
8005 end if;
8006
8007 while Present (Old_Disc) and then Present (New_Disc) loop
8008 if Old_Disc = Par_Disc then
8009 return New_Disc;
8010 end if;
8011
8012 Next_Discriminant (Old_Disc);
8013 Next_Discriminant (New_Disc);
8014 end loop;
8015
8016 -- Should always find it
8017
8018 raise Program_Error;
8019 end Find_Corresponding_Discriminant;
8020
8021 -------------------
8022 -- Find_DIC_Type --
8023 -------------------
8024
8025 function Find_DIC_Type (Typ : Entity_Id) return Entity_Id is
8026 Curr_Typ : Entity_Id;
8027 -- The current type being examined in the parent hierarchy traversal
8028
8029 DIC_Typ : Entity_Id;
8030 -- The type which carries the DIC pragma. This variable denotes the
8031 -- partial view when private types are involved.
8032
8033 Par_Typ : Entity_Id;
8034 -- The parent type of the current type. This variable denotes the full
8035 -- view when private types are involved.
8036
8037 begin
8038 -- The input type defines its own DIC pragma, therefore it is the owner
8039
8040 if Has_Own_DIC (Typ) then
8041 DIC_Typ := Typ;
8042
8043 -- Otherwise the DIC pragma is inherited from a parent type
8044
8045 else
8046 pragma Assert (Has_Inherited_DIC (Typ));
8047
8048 -- Climb the parent chain
8049
8050 Curr_Typ := Typ;
8051 loop
8052 -- Inspect the parent type. Do not consider subtypes as they
8053 -- inherit the DIC attributes from their base types.
8054
8055 DIC_Typ := Base_Type (Etype (Curr_Typ));
8056
8057 -- Look at the full view of a private type because the type may
8058 -- have a hidden parent introduced in the full view.
8059
8060 Par_Typ := DIC_Typ;
8061
8062 if Is_Private_Type (Par_Typ)
8063 and then Present (Full_View (Par_Typ))
8064 then
8065 Par_Typ := Full_View (Par_Typ);
8066 end if;
8067
8068 -- Stop the climb once the nearest parent type which defines a DIC
8069 -- pragma of its own is encountered or when the root of the parent
8070 -- chain is reached.
8071
8072 exit when Has_Own_DIC (DIC_Typ) or else Curr_Typ = Par_Typ;
8073
8074 Curr_Typ := Par_Typ;
8075 end loop;
8076 end if;
8077
8078 return DIC_Typ;
8079 end Find_DIC_Type;
8080
8081 ----------------------------------
8082 -- Find_Enclosing_Iterator_Loop --
8083 ----------------------------------
8084
8085 function Find_Enclosing_Iterator_Loop (Id : Entity_Id) return Entity_Id is
8086 Constr : Node_Id;
8087 S : Entity_Id;
8088
8089 begin
8090 -- Traverse the scope chain looking for an iterator loop. Such loops are
8091 -- usually transformed into blocks, hence the use of Original_Node.
8092
8093 S := Id;
8094 while Present (S) and then S /= Standard_Standard loop
8095 if Ekind (S) = E_Loop
8096 and then Nkind (Parent (S)) = N_Implicit_Label_Declaration
8097 then
8098 Constr := Original_Node (Label_Construct (Parent (S)));
8099
8100 if Nkind (Constr) = N_Loop_Statement
8101 and then Present (Iteration_Scheme (Constr))
8102 and then Nkind (Iterator_Specification
8103 (Iteration_Scheme (Constr))) =
8104 N_Iterator_Specification
8105 then
8106 return S;
8107 end if;
8108 end if;
8109
8110 S := Scope (S);
8111 end loop;
8112
8113 return Empty;
8114 end Find_Enclosing_Iterator_Loop;
8115
8116 --------------------------
8117 -- Find_Enclosing_Scope --
8118 --------------------------
8119
8120 function Find_Enclosing_Scope (N : Node_Id) return Entity_Id is
8121 Par : Node_Id;
8122
8123 begin
8124 -- Examine the parent chain looking for a construct which defines a
8125 -- scope.
8126
8127 Par := Parent (N);
8128 while Present (Par) loop
8129 case Nkind (Par) is
8130
8131 -- The construct denotes a declaration, the proper scope is its
8132 -- entity.
8133
8134 when N_Entry_Declaration
8135 | N_Expression_Function
8136 | N_Full_Type_Declaration
8137 | N_Generic_Package_Declaration
8138 | N_Generic_Subprogram_Declaration
8139 | N_Package_Declaration
8140 | N_Private_Extension_Declaration
8141 | N_Protected_Type_Declaration
8142 | N_Single_Protected_Declaration
8143 | N_Single_Task_Declaration
8144 | N_Subprogram_Declaration
8145 | N_Task_Type_Declaration
8146 =>
8147 return Defining_Entity (Par);
8148
8149 -- The construct denotes a body, the proper scope is the entity of
8150 -- the corresponding spec or that of the body if the body does not
8151 -- complete a previous declaration.
8152
8153 when N_Entry_Body
8154 | N_Package_Body
8155 | N_Protected_Body
8156 | N_Subprogram_Body
8157 | N_Task_Body
8158 =>
8159 return Unique_Defining_Entity (Par);
8160
8161 -- Special cases
8162
8163 -- Blocks carry either a source or an internally-generated scope,
8164 -- unless the block is a byproduct of exception handling.
8165
8166 when N_Block_Statement =>
8167 if not Exception_Junk (Par) then
8168 return Entity (Identifier (Par));
8169 end if;
8170
8171 -- Loops carry an internally-generated scope
8172
8173 when N_Loop_Statement =>
8174 return Entity (Identifier (Par));
8175
8176 -- Extended return statements carry an internally-generated scope
8177
8178 when N_Extended_Return_Statement =>
8179 return Return_Statement_Entity (Par);
8180
8181 -- A traversal from a subunit continues via the corresponding stub
8182
8183 when N_Subunit =>
8184 Par := Corresponding_Stub (Par);
8185
8186 when others =>
8187 null;
8188 end case;
8189
8190 Par := Parent (Par);
8191 end loop;
8192
8193 return Standard_Standard;
8194 end Find_Enclosing_Scope;
8195
8196 ------------------------------------
8197 -- Find_Loop_In_Conditional_Block --
8198 ------------------------------------
8199
8200 function Find_Loop_In_Conditional_Block (N : Node_Id) return Node_Id is
8201 Stmt : Node_Id;
8202
8203 begin
8204 Stmt := N;
8205
8206 if Nkind (Stmt) = N_If_Statement then
8207 Stmt := First (Then_Statements (Stmt));
8208 end if;
8209
8210 pragma Assert (Nkind (Stmt) = N_Block_Statement);
8211
8212 -- Inspect the statements of the conditional block. In general the loop
8213 -- should be the first statement in the statement sequence of the block,
8214 -- but the finalization machinery may have introduced extra object
8215 -- declarations.
8216
8217 Stmt := First (Statements (Handled_Statement_Sequence (Stmt)));
8218 while Present (Stmt) loop
8219 if Nkind (Stmt) = N_Loop_Statement then
8220 return Stmt;
8221 end if;
8222
8223 Next (Stmt);
8224 end loop;
8225
8226 -- The expansion of attribute 'Loop_Entry produced a malformed block
8227
8228 raise Program_Error;
8229 end Find_Loop_In_Conditional_Block;
8230
8231 --------------------------
8232 -- Find_Overlaid_Entity --
8233 --------------------------
8234
8235 procedure Find_Overlaid_Entity
8236 (N : Node_Id;
8237 Ent : out Entity_Id;
8238 Off : out Boolean)
8239 is
8240 Expr : Node_Id;
8241
8242 begin
8243 -- We are looking for one of the two following forms:
8244
8245 -- for X'Address use Y'Address
8246
8247 -- or
8248
8249 -- Const : constant Address := expr;
8250 -- ...
8251 -- for X'Address use Const;
8252
8253 -- In the second case, the expr is either Y'Address, or recursively a
8254 -- constant that eventually references Y'Address.
8255
8256 Ent := Empty;
8257 Off := False;
8258
8259 if Nkind (N) = N_Attribute_Definition_Clause
8260 and then Chars (N) = Name_Address
8261 then
8262 Expr := Expression (N);
8263
8264 -- This loop checks the form of the expression for Y'Address,
8265 -- using recursion to deal with intermediate constants.
8266
8267 loop
8268 -- Check for Y'Address
8269
8270 if Nkind (Expr) = N_Attribute_Reference
8271 and then Attribute_Name (Expr) = Name_Address
8272 then
8273 Expr := Prefix (Expr);
8274 exit;
8275
8276 -- Check for Const where Const is a constant entity
8277
8278 elsif Is_Entity_Name (Expr)
8279 and then Ekind (Entity (Expr)) = E_Constant
8280 then
8281 Expr := Constant_Value (Entity (Expr));
8282
8283 -- Anything else does not need checking
8284
8285 else
8286 return;
8287 end if;
8288 end loop;
8289
8290 -- This loop checks the form of the prefix for an entity, using
8291 -- recursion to deal with intermediate components.
8292
8293 loop
8294 -- Check for Y where Y is an entity
8295
8296 if Is_Entity_Name (Expr) then
8297 Ent := Entity (Expr);
8298 return;
8299
8300 -- Check for components
8301
8302 elsif
8303 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component)
8304 then
8305 Expr := Prefix (Expr);
8306 Off := True;
8307
8308 -- Anything else does not need checking
8309
8310 else
8311 return;
8312 end if;
8313 end loop;
8314 end if;
8315 end Find_Overlaid_Entity;
8316
8317 -------------------------
8318 -- Find_Parameter_Type --
8319 -------------------------
8320
8321 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
8322 begin
8323 if Nkind (Param) /= N_Parameter_Specification then
8324 return Empty;
8325
8326 -- For an access parameter, obtain the type from the formal entity
8327 -- itself, because access to subprogram nodes do not carry a type.
8328 -- Shouldn't we always use the formal entity ???
8329
8330 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
8331 return Etype (Defining_Identifier (Param));
8332
8333 else
8334 return Etype (Parameter_Type (Param));
8335 end if;
8336 end Find_Parameter_Type;
8337
8338 -----------------------------------
8339 -- Find_Placement_In_State_Space --
8340 -----------------------------------
8341
8342 procedure Find_Placement_In_State_Space
8343 (Item_Id : Entity_Id;
8344 Placement : out State_Space_Kind;
8345 Pack_Id : out Entity_Id)
8346 is
8347 Context : Entity_Id;
8348
8349 begin
8350 -- Assume that the item does not appear in the state space of a package
8351
8352 Placement := Not_In_Package;
8353 Pack_Id := Empty;
8354
8355 -- Climb the scope stack and examine the enclosing context
8356
8357 Context := Scope (Item_Id);
8358 while Present (Context) and then Context /= Standard_Standard loop
8359 if Is_Package_Or_Generic_Package (Context) then
8360 Pack_Id := Context;
8361
8362 -- A package body is a cut off point for the traversal as the item
8363 -- cannot be visible to the outside from this point on. Note that
8364 -- this test must be done first as a body is also classified as a
8365 -- private part.
8366
8367 if In_Package_Body (Context) then
8368 Placement := Body_State_Space;
8369 return;
8370
8371 -- The private part of a package is a cut off point for the
8372 -- traversal as the item cannot be visible to the outside from
8373 -- this point on.
8374
8375 elsif In_Private_Part (Context) then
8376 Placement := Private_State_Space;
8377 return;
8378
8379 -- When the item appears in the visible state space of a package,
8380 -- continue to climb the scope stack as this may not be the final
8381 -- state space.
8382
8383 else
8384 Placement := Visible_State_Space;
8385
8386 -- The visible state space of a child unit acts as the proper
8387 -- placement of an item.
8388
8389 if Is_Child_Unit (Context) then
8390 return;
8391 end if;
8392 end if;
8393
8394 -- The item or its enclosing package appear in a construct that has
8395 -- no state space.
8396
8397 else
8398 Placement := Not_In_Package;
8399 return;
8400 end if;
8401
8402 Context := Scope (Context);
8403 end loop;
8404 end Find_Placement_In_State_Space;
8405
8406 -----------------------
8407 -- Find_Primitive_Eq --
8408 -----------------------
8409
8410 function Find_Primitive_Eq (Typ : Entity_Id) return Entity_Id is
8411 function Find_Eq_Prim (Prims_List : Elist_Id) return Entity_Id;
8412 -- Search for the equality primitive; return Empty if the primitive is
8413 -- not found.
8414
8415 ------------------
8416 -- Find_Eq_Prim --
8417 ------------------
8418
8419 function Find_Eq_Prim (Prims_List : Elist_Id) return Entity_Id is
8420 Prim : Entity_Id;
8421 Prim_Elmt : Elmt_Id;
8422
8423 begin
8424 Prim_Elmt := First_Elmt (Prims_List);
8425 while Present (Prim_Elmt) loop
8426 Prim := Node (Prim_Elmt);
8427
8428 -- Locate primitive equality with the right signature
8429
8430 if Chars (Prim) = Name_Op_Eq
8431 and then Etype (First_Formal (Prim)) =
8432 Etype (Next_Formal (First_Formal (Prim)))
8433 and then Base_Type (Etype (Prim)) = Standard_Boolean
8434 then
8435 return Prim;
8436 end if;
8437
8438 Next_Elmt (Prim_Elmt);
8439 end loop;
8440
8441 return Empty;
8442 end Find_Eq_Prim;
8443
8444 -- Local Variables
8445
8446 Eq_Prim : Entity_Id;
8447 Full_Type : Entity_Id;
8448
8449 -- Start of processing for Find_Primitive_Eq
8450
8451 begin
8452 if Is_Private_Type (Typ) then
8453 Full_Type := Underlying_Type (Typ);
8454 else
8455 Full_Type := Typ;
8456 end if;
8457
8458 if No (Full_Type) then
8459 return Empty;
8460 end if;
8461
8462 Full_Type := Base_Type (Full_Type);
8463
8464 -- When the base type itself is private, use the full view
8465
8466 if Is_Private_Type (Full_Type) then
8467 Full_Type := Underlying_Type (Full_Type);
8468 end if;
8469
8470 if Is_Class_Wide_Type (Full_Type) then
8471 Full_Type := Root_Type (Full_Type);
8472 end if;
8473
8474 if not Is_Tagged_Type (Full_Type) then
8475 Eq_Prim := Find_Eq_Prim (Collect_Primitive_Operations (Typ));
8476
8477 -- If this is an untagged private type completed with a derivation of
8478 -- an untagged private type whose full view is a tagged type, we use
8479 -- the primitive operations of the private parent type (since it does
8480 -- not have a full view, and also because its equality primitive may
8481 -- have been overridden in its untagged full view). If no equality was
8482 -- defined for it then take its dispatching equality primitive.
8483
8484 elsif Inherits_From_Tagged_Full_View (Typ) then
8485 Eq_Prim := Find_Eq_Prim (Collect_Primitive_Operations (Typ));
8486
8487 if No (Eq_Prim) then
8488 Eq_Prim := Find_Eq_Prim (Primitive_Operations (Full_Type));
8489 end if;
8490
8491 else
8492 Eq_Prim := Find_Eq_Prim (Primitive_Operations (Full_Type));
8493 end if;
8494
8495 return Eq_Prim;
8496 end Find_Primitive_Eq;
8497
8498 ------------------------
8499 -- Find_Specific_Type --
8500 ------------------------
8501
8502 function Find_Specific_Type (CW : Entity_Id) return Entity_Id is
8503 Typ : Entity_Id := Root_Type (CW);
8504
8505 begin
8506 if Ekind (Typ) = E_Incomplete_Type then
8507 if From_Limited_With (Typ) then
8508 Typ := Non_Limited_View (Typ);
8509 else
8510 Typ := Full_View (Typ);
8511 end if;
8512 end if;
8513
8514 if Is_Private_Type (Typ)
8515 and then not Is_Tagged_Type (Typ)
8516 and then Present (Full_View (Typ))
8517 then
8518 return Full_View (Typ);
8519 else
8520 return Typ;
8521 end if;
8522 end Find_Specific_Type;
8523
8524 -----------------------------
8525 -- Find_Static_Alternative --
8526 -----------------------------
8527
8528 function Find_Static_Alternative (N : Node_Id) return Node_Id is
8529 Expr : constant Node_Id := Expression (N);
8530 Val : constant Uint := Expr_Value (Expr);
8531 Alt : Node_Id;
8532 Choice : Node_Id;
8533
8534 begin
8535 Alt := First (Alternatives (N));
8536
8537 Search : loop
8538 if Nkind (Alt) /= N_Pragma then
8539 Choice := First (Discrete_Choices (Alt));
8540 while Present (Choice) loop
8541
8542 -- Others choice, always matches
8543
8544 if Nkind (Choice) = N_Others_Choice then
8545 exit Search;
8546
8547 -- Range, check if value is in the range
8548
8549 elsif Nkind (Choice) = N_Range then
8550 exit Search when
8551 Val >= Expr_Value (Low_Bound (Choice))
8552 and then
8553 Val <= Expr_Value (High_Bound (Choice));
8554
8555 -- Choice is a subtype name. Note that we know it must
8556 -- be a static subtype, since otherwise it would have
8557 -- been diagnosed as illegal.
8558
8559 elsif Is_Entity_Name (Choice)
8560 and then Is_Type (Entity (Choice))
8561 then
8562 exit Search when Is_In_Range (Expr, Etype (Choice),
8563 Assume_Valid => False);
8564
8565 -- Choice is a subtype indication
8566
8567 elsif Nkind (Choice) = N_Subtype_Indication then
8568 declare
8569 C : constant Node_Id := Constraint (Choice);
8570 R : constant Node_Id := Range_Expression (C);
8571
8572 begin
8573 exit Search when
8574 Val >= Expr_Value (Low_Bound (R))
8575 and then
8576 Val <= Expr_Value (High_Bound (R));
8577 end;
8578
8579 -- Choice is a simple expression
8580
8581 else
8582 exit Search when Val = Expr_Value (Choice);
8583 end if;
8584
8585 Next (Choice);
8586 end loop;
8587 end if;
8588
8589 Next (Alt);
8590 pragma Assert (Present (Alt));
8591 end loop Search;
8592
8593 -- The above loop *must* terminate by finding a match, since we know the
8594 -- case statement is valid, and the value of the expression is known at
8595 -- compile time. When we fall out of the loop, Alt points to the
8596 -- alternative that we know will be selected at run time.
8597
8598 return Alt;
8599 end Find_Static_Alternative;
8600
8601 ------------------
8602 -- First_Actual --
8603 ------------------
8604
8605 function First_Actual (Node : Node_Id) return Node_Id is
8606 N : Node_Id;
8607
8608 begin
8609 if No (Parameter_Associations (Node)) then
8610 return Empty;
8611 end if;
8612
8613 N := First (Parameter_Associations (Node));
8614
8615 if Nkind (N) = N_Parameter_Association then
8616 return First_Named_Actual (Node);
8617 else
8618 return N;
8619 end if;
8620 end First_Actual;
8621
8622 ------------------
8623 -- First_Global --
8624 ------------------
8625
8626 function First_Global
8627 (Subp : Entity_Id;
8628 Global_Mode : Name_Id;
8629 Refined : Boolean := False) return Node_Id
8630 is
8631 function First_From_Global_List
8632 (List : Node_Id;
8633 Global_Mode : Name_Id := Name_Input) return Entity_Id;
8634 -- Get the first item with suitable mode from List
8635
8636 ----------------------------
8637 -- First_From_Global_List --
8638 ----------------------------
8639
8640 function First_From_Global_List
8641 (List : Node_Id;
8642 Global_Mode : Name_Id := Name_Input) return Entity_Id
8643 is
8644 Assoc : Node_Id;
8645
8646 begin
8647 -- Empty list (no global items)
8648
8649 if Nkind (List) = N_Null then
8650 return Empty;
8651
8652 -- Single global item declaration (only input items)
8653
8654 elsif Nkind_In (List, N_Expanded_Name, N_Identifier) then
8655 if Global_Mode = Name_Input then
8656 return List;
8657 else
8658 return Empty;
8659 end if;
8660
8661 -- Simple global list (only input items) or moded global list
8662 -- declaration.
8663
8664 elsif Nkind (List) = N_Aggregate then
8665 if Present (Expressions (List)) then
8666 if Global_Mode = Name_Input then
8667 return First (Expressions (List));
8668 else
8669 return Empty;
8670 end if;
8671
8672 else
8673 Assoc := First (Component_Associations (List));
8674 while Present (Assoc) loop
8675
8676 -- When we find the desired mode in an association, call
8677 -- recursively First_From_Global_List as if the mode was
8678 -- Name_Input, in order to reuse the existing machinery
8679 -- for the other cases.
8680
8681 if Chars (First (Choices (Assoc))) = Global_Mode then
8682 return First_From_Global_List (Expression (Assoc));
8683 end if;
8684
8685 Next (Assoc);
8686 end loop;
8687
8688 return Empty;
8689 end if;
8690
8691 -- To accommodate partial decoration of disabled SPARK features,
8692 -- this routine may be called with illegal input. If this is the
8693 -- case, do not raise Program_Error.
8694
8695 else
8696 return Empty;
8697 end if;
8698 end First_From_Global_List;
8699
8700 -- Local variables
8701
8702 Global : Node_Id := Empty;
8703 Body_Id : Entity_Id;
8704
8705 -- Start of processing for First_Global
8706
8707 begin
8708 pragma Assert (Nam_In (Global_Mode, Name_In_Out,
8709 Name_Input,
8710 Name_Output,
8711 Name_Proof_In));
8712
8713 -- Retrieve the suitable pragma Global or Refined_Global. In the second
8714 -- case, it can only be located on the body entity.
8715
8716 if Refined then
8717 if Is_Subprogram_Or_Generic_Subprogram (Subp) then
8718 Body_Id := Subprogram_Body_Entity (Subp);
8719
8720 elsif Is_Entry (Subp) or else Is_Task_Type (Subp) then
8721 Body_Id := Corresponding_Body (Parent (Subp));
8722
8723 -- ??? It should be possible to retrieve the Refined_Global on the
8724 -- task body associated to the task object. This is not yet possible.
8725
8726 elsif Is_Single_Task_Object (Subp) then
8727 Body_Id := Empty;
8728
8729 else
8730 Body_Id := Empty;
8731 end if;
8732
8733 if Present (Body_Id) then
8734 Global := Get_Pragma (Body_Id, Pragma_Refined_Global);
8735 end if;
8736 else
8737 Global := Get_Pragma (Subp, Pragma_Global);
8738 end if;
8739
8740 -- No corresponding global if pragma is not present
8741
8742 if No (Global) then
8743 return Empty;
8744
8745 -- Otherwise retrieve the corresponding list of items depending on the
8746 -- Global_Mode.
8747
8748 else
8749 return First_From_Global_List
8750 (Expression (Get_Argument (Global, Subp)), Global_Mode);
8751 end if;
8752 end First_Global;
8753
8754 -------------
8755 -- Fix_Msg --
8756 -------------
8757
8758 function Fix_Msg (Id : Entity_Id; Msg : String) return String is
8759 Is_Task : constant Boolean :=
8760 Ekind_In (Id, E_Task_Body, E_Task_Type)
8761 or else Is_Single_Task_Object (Id);
8762 Msg_Last : constant Natural := Msg'Last;
8763 Msg_Index : Natural;
8764 Res : String (Msg'Range) := (others => ' ');
8765 Res_Index : Natural;
8766
8767 begin
8768 -- Copy all characters from the input message Msg to result Res with
8769 -- suitable replacements.
8770
8771 Msg_Index := Msg'First;
8772 Res_Index := Res'First;
8773 while Msg_Index <= Msg_Last loop
8774
8775 -- Replace "subprogram" with a different word
8776
8777 if Msg_Index <= Msg_Last - 10
8778 and then Msg (Msg_Index .. Msg_Index + 9) = "subprogram"
8779 then
8780 if Ekind_In (Id, E_Entry, E_Entry_Family) then
8781 Res (Res_Index .. Res_Index + 4) := "entry";
8782 Res_Index := Res_Index + 5;
8783
8784 elsif Is_Task then
8785 Res (Res_Index .. Res_Index + 8) := "task type";
8786 Res_Index := Res_Index + 9;
8787
8788 else
8789 Res (Res_Index .. Res_Index + 9) := "subprogram";
8790 Res_Index := Res_Index + 10;
8791 end if;
8792
8793 Msg_Index := Msg_Index + 10;
8794
8795 -- Replace "protected" with a different word
8796
8797 elsif Msg_Index <= Msg_Last - 9
8798 and then Msg (Msg_Index .. Msg_Index + 8) = "protected"
8799 and then Is_Task
8800 then
8801 Res (Res_Index .. Res_Index + 3) := "task";
8802 Res_Index := Res_Index + 4;
8803 Msg_Index := Msg_Index + 9;
8804
8805 -- Otherwise copy the character
8806
8807 else
8808 Res (Res_Index) := Msg (Msg_Index);
8809 Msg_Index := Msg_Index + 1;
8810 Res_Index := Res_Index + 1;
8811 end if;
8812 end loop;
8813
8814 return Res (Res'First .. Res_Index - 1);
8815 end Fix_Msg;
8816
8817 -------------------------
8818 -- From_Nested_Package --
8819 -------------------------
8820
8821 function From_Nested_Package (T : Entity_Id) return Boolean is
8822 Pack : constant Entity_Id := Scope (T);
8823
8824 begin
8825 return
8826 Ekind (Pack) = E_Package
8827 and then not Is_Frozen (Pack)
8828 and then not Scope_Within_Or_Same (Current_Scope, Pack)
8829 and then In_Open_Scopes (Scope (Pack));
8830 end From_Nested_Package;
8831
8832 -----------------------
8833 -- Gather_Components --
8834 -----------------------
8835
8836 procedure Gather_Components
8837 (Typ : Entity_Id;
8838 Comp_List : Node_Id;
8839 Governed_By : List_Id;
8840 Into : Elist_Id;
8841 Report_Errors : out Boolean)
8842 is
8843 Assoc : Node_Id;
8844 Variant : Node_Id;
8845 Discrete_Choice : Node_Id;
8846 Comp_Item : Node_Id;
8847
8848 Discrim : Entity_Id;
8849 Discrim_Name : Node_Id;
8850 Discrim_Value : Node_Id;
8851
8852 begin
8853 Report_Errors := False;
8854
8855 if No (Comp_List) or else Null_Present (Comp_List) then
8856 return;
8857
8858 elsif Present (Component_Items (Comp_List)) then
8859 Comp_Item := First (Component_Items (Comp_List));
8860
8861 else
8862 Comp_Item := Empty;
8863 end if;
8864
8865 while Present (Comp_Item) loop
8866
8867 -- Skip the tag of a tagged record, the interface tags, as well
8868 -- as all items that are not user components (anonymous types,
8869 -- rep clauses, Parent field, controller field).
8870
8871 if Nkind (Comp_Item) = N_Component_Declaration then
8872 declare
8873 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
8874 begin
8875 if not Is_Tag (Comp) and then Chars (Comp) /= Name_uParent then
8876 Append_Elmt (Comp, Into);
8877 end if;
8878 end;
8879 end if;
8880
8881 Next (Comp_Item);
8882 end loop;
8883
8884 if No (Variant_Part (Comp_List)) then
8885 return;
8886 else
8887 Discrim_Name := Name (Variant_Part (Comp_List));
8888 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
8889 end if;
8890
8891 -- Look for the discriminant that governs this variant part.
8892 -- The discriminant *must* be in the Governed_By List
8893
8894 Assoc := First (Governed_By);
8895 Find_Constraint : loop
8896 Discrim := First (Choices (Assoc));
8897 exit Find_Constraint when
8898 Chars (Discrim_Name) = Chars (Discrim)
8899 or else
8900 (Present (Corresponding_Discriminant (Entity (Discrim)))
8901 and then Chars (Corresponding_Discriminant
8902 (Entity (Discrim))) = Chars (Discrim_Name))
8903 or else
8904 Chars (Original_Record_Component (Entity (Discrim))) =
8905 Chars (Discrim_Name);
8906
8907 if No (Next (Assoc)) then
8908 if not Is_Constrained (Typ) and then Is_Derived_Type (Typ) then
8909
8910 -- If the type is a tagged type with inherited discriminants,
8911 -- use the stored constraint on the parent in order to find
8912 -- the values of discriminants that are otherwise hidden by an
8913 -- explicit constraint. Renamed discriminants are handled in
8914 -- the code above.
8915
8916 -- If several parent discriminants are renamed by a single
8917 -- discriminant of the derived type, the call to obtain the
8918 -- Corresponding_Discriminant field only retrieves the last
8919 -- of them. We recover the constraint on the others from the
8920 -- Stored_Constraint as well.
8921
8922 -- An inherited discriminant may have been constrained in a
8923 -- later ancestor (not the immediate parent) so we must examine
8924 -- the stored constraint of all of them to locate the inherited
8925 -- value.
8926
8927 declare
8928 C : Elmt_Id;
8929 D : Entity_Id;
8930 T : Entity_Id := Typ;
8931
8932 begin
8933 while Is_Derived_Type (T) loop
8934 if Present (Stored_Constraint (T)) then
8935 D := First_Discriminant (Etype (T));
8936 C := First_Elmt (Stored_Constraint (T));
8937 while Present (D) and then Present (C) loop
8938 if Chars (Discrim_Name) = Chars (D) then
8939 if Is_Entity_Name (Node (C))
8940 and then Entity (Node (C)) = Entity (Discrim)
8941 then
8942 -- D is renamed by Discrim, whose value is
8943 -- given in Assoc.
8944
8945 null;
8946
8947 else
8948 Assoc :=
8949 Make_Component_Association (Sloc (Typ),
8950 New_List
8951 (New_Occurrence_Of (D, Sloc (Typ))),
8952 Duplicate_Subexpr_No_Checks (Node (C)));
8953 end if;
8954
8955 exit Find_Constraint;
8956 end if;
8957
8958 Next_Discriminant (D);
8959 Next_Elmt (C);
8960 end loop;
8961 end if;
8962
8963 -- Discriminant may be inherited from ancestor
8964
8965 T := Etype (T);
8966 end loop;
8967 end;
8968 end if;
8969 end if;
8970
8971 if No (Next (Assoc)) then
8972 Error_Msg_NE
8973 (" missing value for discriminant&",
8974 First (Governed_By), Discrim_Name);
8975
8976 Report_Errors := True;
8977 return;
8978 end if;
8979
8980 Next (Assoc);
8981 end loop Find_Constraint;
8982
8983 Discrim_Value := Expression (Assoc);
8984
8985 if not Is_OK_Static_Expression (Discrim_Value) then
8986
8987 -- If the variant part is governed by a discriminant of the type
8988 -- this is an error. If the variant part and the discriminant are
8989 -- inherited from an ancestor this is legal (AI05-120) unless the
8990 -- components are being gathered for an aggregate, in which case
8991 -- the caller must check Report_Errors.
8992
8993 if Scope (Original_Record_Component
8994 ((Entity (First (Choices (Assoc)))))) = Typ
8995 then
8996 Error_Msg_FE
8997 ("value for discriminant & must be static!",
8998 Discrim_Value, Discrim);
8999 Why_Not_Static (Discrim_Value);
9000 end if;
9001
9002 Report_Errors := True;
9003 return;
9004 end if;
9005
9006 Search_For_Discriminant_Value : declare
9007 Low : Node_Id;
9008 High : Node_Id;
9009
9010 UI_High : Uint;
9011 UI_Low : Uint;
9012 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
9013
9014 begin
9015 Find_Discrete_Value : while Present (Variant) loop
9016
9017 -- If a choice is a subtype with a static predicate, it must
9018 -- be rewritten as an explicit list of non-predicated choices.
9019
9020 Expand_Static_Predicates_In_Choices (Variant);
9021
9022 Discrete_Choice := First (Discrete_Choices (Variant));
9023 while Present (Discrete_Choice) loop
9024 exit Find_Discrete_Value when
9025 Nkind (Discrete_Choice) = N_Others_Choice;
9026
9027 Get_Index_Bounds (Discrete_Choice, Low, High);
9028
9029 UI_Low := Expr_Value (Low);
9030 UI_High := Expr_Value (High);
9031
9032 exit Find_Discrete_Value when
9033 UI_Low <= UI_Discrim_Value
9034 and then
9035 UI_High >= UI_Discrim_Value;
9036
9037 Next (Discrete_Choice);
9038 end loop;
9039
9040 Next_Non_Pragma (Variant);
9041 end loop Find_Discrete_Value;
9042 end Search_For_Discriminant_Value;
9043
9044 -- The case statement must include a variant that corresponds to the
9045 -- value of the discriminant, unless the discriminant type has a
9046 -- static predicate. In that case the absence of an others_choice that
9047 -- would cover this value becomes a run-time error (3.8,1 (21.1/2)).
9048
9049 if No (Variant)
9050 and then not Has_Static_Predicate (Etype (Discrim_Name))
9051 then
9052 Error_Msg_NE
9053 ("value of discriminant & is out of range", Discrim_Value, Discrim);
9054 Report_Errors := True;
9055 return;
9056 end if;
9057
9058 -- If we have found the corresponding choice, recursively add its
9059 -- components to the Into list. The nested components are part of
9060 -- the same record type.
9061
9062 if Present (Variant) then
9063 Gather_Components
9064 (Typ, Component_List (Variant), Governed_By, Into, Report_Errors);
9065 end if;
9066 end Gather_Components;
9067
9068 ------------------------
9069 -- Get_Actual_Subtype --
9070 ------------------------
9071
9072 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
9073 Typ : constant Entity_Id := Etype (N);
9074 Utyp : Entity_Id := Underlying_Type (Typ);
9075 Decl : Node_Id;
9076 Atyp : Entity_Id;
9077
9078 begin
9079 if No (Utyp) then
9080 Utyp := Typ;
9081 end if;
9082
9083 -- If what we have is an identifier that references a subprogram
9084 -- formal, or a variable or constant object, then we get the actual
9085 -- subtype from the referenced entity if one has been built.
9086
9087 if Nkind (N) = N_Identifier
9088 and then
9089 (Is_Formal (Entity (N))
9090 or else Ekind (Entity (N)) = E_Constant
9091 or else Ekind (Entity (N)) = E_Variable)
9092 and then Present (Actual_Subtype (Entity (N)))
9093 then
9094 return Actual_Subtype (Entity (N));
9095
9096 -- Actual subtype of unchecked union is always itself. We never need
9097 -- the "real" actual subtype. If we did, we couldn't get it anyway
9098 -- because the discriminant is not available. The restrictions on
9099 -- Unchecked_Union are designed to make sure that this is OK.
9100
9101 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
9102 return Typ;
9103
9104 -- Here for the unconstrained case, we must find actual subtype
9105 -- No actual subtype is available, so we must build it on the fly.
9106
9107 -- Checking the type, not the underlying type, for constrainedness
9108 -- seems to be necessary. Maybe all the tests should be on the type???
9109
9110 elsif (not Is_Constrained (Typ))
9111 and then (Is_Array_Type (Utyp)
9112 or else (Is_Record_Type (Utyp)
9113 and then Has_Discriminants (Utyp)))
9114 and then not Has_Unknown_Discriminants (Utyp)
9115 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
9116 then
9117 -- Nothing to do if in spec expression (why not???)
9118
9119 if In_Spec_Expression then
9120 return Typ;
9121
9122 elsif Is_Private_Type (Typ) and then not Has_Discriminants (Typ) then
9123
9124 -- If the type has no discriminants, there is no subtype to
9125 -- build, even if the underlying type is discriminated.
9126
9127 return Typ;
9128
9129 -- Else build the actual subtype
9130
9131 else
9132 Decl := Build_Actual_Subtype (Typ, N);
9133
9134 -- The call may yield a declaration, or just return the entity
9135
9136 if Decl = Typ then
9137 return Typ;
9138 end if;
9139
9140 Atyp := Defining_Identifier (Decl);
9141
9142 -- If Build_Actual_Subtype generated a new declaration then use it
9143
9144 if Atyp /= Typ then
9145
9146 -- The actual subtype is an Itype, so analyze the declaration,
9147 -- but do not attach it to the tree, to get the type defined.
9148
9149 Set_Parent (Decl, N);
9150 Set_Is_Itype (Atyp);
9151 Analyze (Decl, Suppress => All_Checks);
9152 Set_Associated_Node_For_Itype (Atyp, N);
9153 Set_Has_Delayed_Freeze (Atyp, False);
9154
9155 -- We need to freeze the actual subtype immediately. This is
9156 -- needed, because otherwise this Itype will not get frozen
9157 -- at all, and it is always safe to freeze on creation because
9158 -- any associated types must be frozen at this point.
9159
9160 Freeze_Itype (Atyp, N);
9161 return Atyp;
9162
9163 -- Otherwise we did not build a declaration, so return original
9164
9165 else
9166 return Typ;
9167 end if;
9168 end if;
9169
9170 -- For all remaining cases, the actual subtype is the same as
9171 -- the nominal type.
9172
9173 else
9174 return Typ;
9175 end if;
9176 end Get_Actual_Subtype;
9177
9178 -------------------------------------
9179 -- Get_Actual_Subtype_If_Available --
9180 -------------------------------------
9181
9182 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
9183 Typ : constant Entity_Id := Etype (N);
9184
9185 begin
9186 -- If what we have is an identifier that references a subprogram
9187 -- formal, or a variable or constant object, then we get the actual
9188 -- subtype from the referenced entity if one has been built.
9189
9190 if Nkind (N) = N_Identifier
9191 and then
9192 (Is_Formal (Entity (N))
9193 or else Ekind (Entity (N)) = E_Constant
9194 or else Ekind (Entity (N)) = E_Variable)
9195 and then Present (Actual_Subtype (Entity (N)))
9196 then
9197 return Actual_Subtype (Entity (N));
9198
9199 -- Otherwise the Etype of N is returned unchanged
9200
9201 else
9202 return Typ;
9203 end if;
9204 end Get_Actual_Subtype_If_Available;
9205
9206 ------------------------
9207 -- Get_Body_From_Stub --
9208 ------------------------
9209
9210 function Get_Body_From_Stub (N : Node_Id) return Node_Id is
9211 begin
9212 return Proper_Body (Unit (Library_Unit (N)));
9213 end Get_Body_From_Stub;
9214
9215 ---------------------
9216 -- Get_Cursor_Type --
9217 ---------------------
9218
9219 function Get_Cursor_Type
9220 (Aspect : Node_Id;
9221 Typ : Entity_Id) return Entity_Id
9222 is
9223 Assoc : Node_Id;
9224 Func : Entity_Id;
9225 First_Op : Entity_Id;
9226 Cursor : Entity_Id;
9227
9228 begin
9229 -- If error already detected, return
9230
9231 if Error_Posted (Aspect) then
9232 return Any_Type;
9233 end if;
9234
9235 -- The cursor type for an Iterable aspect is the return type of a
9236 -- non-overloaded First primitive operation. Locate association for
9237 -- First.
9238
9239 Assoc := First (Component_Associations (Expression (Aspect)));
9240 First_Op := Any_Id;
9241 while Present (Assoc) loop
9242 if Chars (First (Choices (Assoc))) = Name_First then
9243 First_Op := Expression (Assoc);
9244 exit;
9245 end if;
9246
9247 Next (Assoc);
9248 end loop;
9249
9250 if First_Op = Any_Id then
9251 Error_Msg_N ("aspect Iterable must specify First operation", Aspect);
9252 return Any_Type;
9253
9254 elsif not Analyzed (First_Op) then
9255 Analyze (First_Op);
9256 end if;
9257
9258 Cursor := Any_Type;
9259
9260 -- Locate function with desired name and profile in scope of type
9261 -- In the rare case where the type is an integer type, a base type
9262 -- is created for it, check that the base type of the first formal
9263 -- of First matches the base type of the domain.
9264
9265 Func := First_Entity (Scope (Typ));
9266 while Present (Func) loop
9267 if Chars (Func) = Chars (First_Op)
9268 and then Ekind (Func) = E_Function
9269 and then Present (First_Formal (Func))
9270 and then Base_Type (Etype (First_Formal (Func))) = Base_Type (Typ)
9271 and then No (Next_Formal (First_Formal (Func)))
9272 then
9273 if Cursor /= Any_Type then
9274 Error_Msg_N
9275 ("Operation First for iterable type must be unique", Aspect);
9276 return Any_Type;
9277 else
9278 Cursor := Etype (Func);
9279 end if;
9280 end if;
9281
9282 Next_Entity (Func);
9283 end loop;
9284
9285 -- If not found, no way to resolve remaining primitives
9286
9287 if Cursor = Any_Type then
9288 Error_Msg_N
9289 ("primitive operation for Iterable type must appear in the same "
9290 & "list of declarations as the type", Aspect);
9291 end if;
9292
9293 return Cursor;
9294 end Get_Cursor_Type;
9295
9296 function Get_Cursor_Type (Typ : Entity_Id) return Entity_Id is
9297 begin
9298 return Etype (Get_Iterable_Type_Primitive (Typ, Name_First));
9299 end Get_Cursor_Type;
9300
9301 -------------------------------
9302 -- Get_Default_External_Name --
9303 -------------------------------
9304
9305 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
9306 begin
9307 Get_Decoded_Name_String (Chars (E));
9308
9309 if Opt.External_Name_Imp_Casing = Uppercase then
9310 Set_Casing (All_Upper_Case);
9311 else
9312 Set_Casing (All_Lower_Case);
9313 end if;
9314
9315 return
9316 Make_String_Literal (Sloc (E),
9317 Strval => String_From_Name_Buffer);
9318 end Get_Default_External_Name;
9319
9320 --------------------------
9321 -- Get_Enclosing_Object --
9322 --------------------------
9323
9324 function Get_Enclosing_Object (N : Node_Id) return Entity_Id is
9325 begin
9326 if Is_Entity_Name (N) then
9327 return Entity (N);
9328 else
9329 case Nkind (N) is
9330 when N_Indexed_Component
9331 | N_Selected_Component
9332 | N_Slice
9333 =>
9334 -- If not generating code, a dereference may be left implicit.
9335 -- In thoses cases, return Empty.
9336
9337 if Is_Access_Type (Etype (Prefix (N))) then
9338 return Empty;
9339 else
9340 return Get_Enclosing_Object (Prefix (N));
9341 end if;
9342
9343 when N_Type_Conversion =>
9344 return Get_Enclosing_Object (Expression (N));
9345
9346 when others =>
9347 return Empty;
9348 end case;
9349 end if;
9350 end Get_Enclosing_Object;
9351
9352 ---------------------------
9353 -- Get_Enum_Lit_From_Pos --
9354 ---------------------------
9355
9356 function Get_Enum_Lit_From_Pos
9357 (T : Entity_Id;
9358 Pos : Uint;
9359 Loc : Source_Ptr) return Node_Id
9360 is
9361 Btyp : Entity_Id := Base_Type (T);
9362 Lit : Node_Id;
9363 LLoc : Source_Ptr;
9364
9365 begin
9366 -- In the case where the literal is of type Character, Wide_Character
9367 -- or Wide_Wide_Character or of a type derived from them, there needs
9368 -- to be some special handling since there is no explicit chain of
9369 -- literals to search. Instead, an N_Character_Literal node is created
9370 -- with the appropriate Char_Code and Chars fields.
9371
9372 if Is_Standard_Character_Type (T) then
9373 Set_Character_Literal_Name (UI_To_CC (Pos));
9374
9375 return
9376 Make_Character_Literal (Loc,
9377 Chars => Name_Find,
9378 Char_Literal_Value => Pos);
9379
9380 -- For all other cases, we have a complete table of literals, and
9381 -- we simply iterate through the chain of literal until the one
9382 -- with the desired position value is found.
9383
9384 else
9385 if Is_Private_Type (Btyp) and then Present (Full_View (Btyp)) then
9386 Btyp := Full_View (Btyp);
9387 end if;
9388
9389 Lit := First_Literal (Btyp);
9390
9391 -- Position in the enumeration type starts at 0
9392
9393 if UI_To_Int (Pos) < 0 then
9394 raise Constraint_Error;
9395 end if;
9396
9397 for J in 1 .. UI_To_Int (Pos) loop
9398 Next_Literal (Lit);
9399
9400 -- If Lit is Empty, Pos is not in range, so raise Constraint_Error
9401 -- inside the loop to avoid calling Next_Literal on Empty.
9402
9403 if No (Lit) then
9404 raise Constraint_Error;
9405 end if;
9406 end loop;
9407
9408 -- Create a new node from Lit, with source location provided by Loc
9409 -- if not equal to No_Location, or by copying the source location of
9410 -- Lit otherwise.
9411
9412 LLoc := Loc;
9413
9414 if LLoc = No_Location then
9415 LLoc := Sloc (Lit);
9416 end if;
9417
9418 return New_Occurrence_Of (Lit, LLoc);
9419 end if;
9420 end Get_Enum_Lit_From_Pos;
9421
9422 ------------------------
9423 -- Get_Generic_Entity --
9424 ------------------------
9425
9426 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
9427 Ent : constant Entity_Id := Entity (Name (N));
9428 begin
9429 if Present (Renamed_Object (Ent)) then
9430 return Renamed_Object (Ent);
9431 else
9432 return Ent;
9433 end if;
9434 end Get_Generic_Entity;
9435
9436 -------------------------------------
9437 -- Get_Incomplete_View_Of_Ancestor --
9438 -------------------------------------
9439
9440 function Get_Incomplete_View_Of_Ancestor (E : Entity_Id) return Entity_Id is
9441 Cur_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
9442 Par_Scope : Entity_Id;
9443 Par_Type : Entity_Id;
9444
9445 begin
9446 -- The incomplete view of an ancestor is only relevant for private
9447 -- derived types in child units.
9448
9449 if not Is_Derived_Type (E)
9450 or else not Is_Child_Unit (Cur_Unit)
9451 then
9452 return Empty;
9453
9454 else
9455 Par_Scope := Scope (Cur_Unit);
9456 if No (Par_Scope) then
9457 return Empty;
9458 end if;
9459
9460 Par_Type := Etype (Base_Type (E));
9461
9462 -- Traverse list of ancestor types until we find one declared in
9463 -- a parent or grandparent unit (two levels seem sufficient).
9464
9465 while Present (Par_Type) loop
9466 if Scope (Par_Type) = Par_Scope
9467 or else Scope (Par_Type) = Scope (Par_Scope)
9468 then
9469 return Par_Type;
9470
9471 elsif not Is_Derived_Type (Par_Type) then
9472 return Empty;
9473
9474 else
9475 Par_Type := Etype (Base_Type (Par_Type));
9476 end if;
9477 end loop;
9478
9479 -- If none found, there is no relevant ancestor type.
9480
9481 return Empty;
9482 end if;
9483 end Get_Incomplete_View_Of_Ancestor;
9484
9485 ----------------------
9486 -- Get_Index_Bounds --
9487 ----------------------
9488
9489 procedure Get_Index_Bounds
9490 (N : Node_Id;
9491 L : out Node_Id;
9492 H : out Node_Id;
9493 Use_Full_View : Boolean := False)
9494 is
9495 function Scalar_Range_Of_Type (Typ : Entity_Id) return Node_Id;
9496 -- Obtain the scalar range of type Typ. If flag Use_Full_View is set and
9497 -- Typ qualifies, the scalar range is obtained from the full view of the
9498 -- type.
9499
9500 --------------------------
9501 -- Scalar_Range_Of_Type --
9502 --------------------------
9503
9504 function Scalar_Range_Of_Type (Typ : Entity_Id) return Node_Id is
9505 T : Entity_Id := Typ;
9506
9507 begin
9508 if Use_Full_View and then Present (Full_View (T)) then
9509 T := Full_View (T);
9510 end if;
9511
9512 return Scalar_Range (T);
9513 end Scalar_Range_Of_Type;
9514
9515 -- Local variables
9516
9517 Kind : constant Node_Kind := Nkind (N);
9518 Rng : Node_Id;
9519
9520 -- Start of processing for Get_Index_Bounds
9521
9522 begin
9523 if Kind = N_Range then
9524 L := Low_Bound (N);
9525 H := High_Bound (N);
9526
9527 elsif Kind = N_Subtype_Indication then
9528 Rng := Range_Expression (Constraint (N));
9529
9530 if Rng = Error then
9531 L := Error;
9532 H := Error;
9533 return;
9534
9535 else
9536 L := Low_Bound (Range_Expression (Constraint (N)));
9537 H := High_Bound (Range_Expression (Constraint (N)));
9538 end if;
9539
9540 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
9541 Rng := Scalar_Range_Of_Type (Entity (N));
9542
9543 if Error_Posted (Rng) then
9544 L := Error;
9545 H := Error;
9546
9547 elsif Nkind (Rng) = N_Subtype_Indication then
9548 Get_Index_Bounds (Rng, L, H);
9549
9550 else
9551 L := Low_Bound (Rng);
9552 H := High_Bound (Rng);
9553 end if;
9554
9555 else
9556 -- N is an expression, indicating a range with one value
9557
9558 L := N;
9559 H := N;
9560 end if;
9561 end Get_Index_Bounds;
9562
9563 -----------------------------
9564 -- Get_Interfacing_Aspects --
9565 -----------------------------
9566
9567 procedure Get_Interfacing_Aspects
9568 (Iface_Asp : Node_Id;
9569 Conv_Asp : out Node_Id;
9570 EN_Asp : out Node_Id;
9571 Expo_Asp : out Node_Id;
9572 Imp_Asp : out Node_Id;
9573 LN_Asp : out Node_Id;
9574 Do_Checks : Boolean := False)
9575 is
9576 procedure Save_Or_Duplication_Error
9577 (Asp : Node_Id;
9578 To : in out Node_Id);
9579 -- Save the value of aspect Asp in node To. If To already has a value,
9580 -- then this is considered a duplicate use of aspect. Emit an error if
9581 -- flag Do_Checks is set.
9582
9583 -------------------------------
9584 -- Save_Or_Duplication_Error --
9585 -------------------------------
9586
9587 procedure Save_Or_Duplication_Error
9588 (Asp : Node_Id;
9589 To : in out Node_Id)
9590 is
9591 begin
9592 -- Detect an extra aspect and issue an error
9593
9594 if Present (To) then
9595 if Do_Checks then
9596 Error_Msg_Name_1 := Chars (Identifier (Asp));
9597 Error_Msg_Sloc := Sloc (To);
9598 Error_Msg_N ("aspect % previously given #", Asp);
9599 end if;
9600
9601 -- Otherwise capture the aspect
9602
9603 else
9604 To := Asp;
9605 end if;
9606 end Save_Or_Duplication_Error;
9607
9608 -- Local variables
9609
9610 Asp : Node_Id;
9611 Asp_Id : Aspect_Id;
9612
9613 -- The following variables capture each individual aspect
9614
9615 Conv : Node_Id := Empty;
9616 EN : Node_Id := Empty;
9617 Expo : Node_Id := Empty;
9618 Imp : Node_Id := Empty;
9619 LN : Node_Id := Empty;
9620
9621 -- Start of processing for Get_Interfacing_Aspects
9622
9623 begin
9624 -- The input interfacing aspect should reside in an aspect specification
9625 -- list.
9626
9627 pragma Assert (Is_List_Member (Iface_Asp));
9628
9629 -- Examine the aspect specifications of the related entity. Find and
9630 -- capture all interfacing aspects. Detect duplicates and emit errors
9631 -- if applicable.
9632
9633 Asp := First (List_Containing (Iface_Asp));
9634 while Present (Asp) loop
9635 Asp_Id := Get_Aspect_Id (Asp);
9636
9637 if Asp_Id = Aspect_Convention then
9638 Save_Or_Duplication_Error (Asp, Conv);
9639
9640 elsif Asp_Id = Aspect_External_Name then
9641 Save_Or_Duplication_Error (Asp, EN);
9642
9643 elsif Asp_Id = Aspect_Export then
9644 Save_Or_Duplication_Error (Asp, Expo);
9645
9646 elsif Asp_Id = Aspect_Import then
9647 Save_Or_Duplication_Error (Asp, Imp);
9648
9649 elsif Asp_Id = Aspect_Link_Name then
9650 Save_Or_Duplication_Error (Asp, LN);
9651 end if;
9652
9653 Next (Asp);
9654 end loop;
9655
9656 Conv_Asp := Conv;
9657 EN_Asp := EN;
9658 Expo_Asp := Expo;
9659 Imp_Asp := Imp;
9660 LN_Asp := LN;
9661 end Get_Interfacing_Aspects;
9662
9663 ---------------------------------
9664 -- Get_Iterable_Type_Primitive --
9665 ---------------------------------
9666
9667 function Get_Iterable_Type_Primitive
9668 (Typ : Entity_Id;
9669 Nam : Name_Id) return Entity_Id
9670 is
9671 Funcs : constant Node_Id := Find_Value_Of_Aspect (Typ, Aspect_Iterable);
9672 Assoc : Node_Id;
9673
9674 begin
9675 if No (Funcs) then
9676 return Empty;
9677
9678 else
9679 Assoc := First (Component_Associations (Funcs));
9680 while Present (Assoc) loop
9681 if Chars (First (Choices (Assoc))) = Nam then
9682 return Entity (Expression (Assoc));
9683 end if;
9684
9685 Assoc := Next (Assoc);
9686 end loop;
9687
9688 return Empty;
9689 end if;
9690 end Get_Iterable_Type_Primitive;
9691
9692 ----------------------------------
9693 -- Get_Library_Unit_Name_String --
9694 ----------------------------------
9695
9696 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
9697 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
9698
9699 begin
9700 Get_Unit_Name_String (Unit_Name_Id);
9701
9702 -- Remove seven last character (" (spec)" or " (body)")
9703
9704 Name_Len := Name_Len - 7;
9705 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
9706 end Get_Library_Unit_Name_String;
9707
9708 --------------------------
9709 -- Get_Max_Queue_Length --
9710 --------------------------
9711
9712 function Get_Max_Queue_Length (Id : Entity_Id) return Uint is
9713 pragma Assert (Is_Entry (Id));
9714 Prag : constant Entity_Id := Get_Pragma (Id, Pragma_Max_Queue_Length);
9715
9716 begin
9717 -- A value of 0 represents no maximum specified, and entries and entry
9718 -- families with no Max_Queue_Length aspect or pragma default to it.
9719
9720 if not Present (Prag) then
9721 return Uint_0;
9722 end if;
9723
9724 return Intval (Expression (First (Pragma_Argument_Associations (Prag))));
9725 end Get_Max_Queue_Length;
9726
9727 ------------------------
9728 -- Get_Name_Entity_Id --
9729 ------------------------
9730
9731 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
9732 begin
9733 return Entity_Id (Get_Name_Table_Int (Id));
9734 end Get_Name_Entity_Id;
9735
9736 ------------------------------
9737 -- Get_Name_From_CTC_Pragma --
9738 ------------------------------
9739
9740 function Get_Name_From_CTC_Pragma (N : Node_Id) return String_Id is
9741 Arg : constant Node_Id :=
9742 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
9743 begin
9744 return Strval (Expr_Value_S (Arg));
9745 end Get_Name_From_CTC_Pragma;
9746
9747 -----------------------
9748 -- Get_Parent_Entity --
9749 -----------------------
9750
9751 function Get_Parent_Entity (Unit : Node_Id) return Entity_Id is
9752 begin
9753 if Nkind (Unit) = N_Package_Body
9754 and then Nkind (Original_Node (Unit)) = N_Package_Instantiation
9755 then
9756 return Defining_Entity
9757 (Specification (Instance_Spec (Original_Node (Unit))));
9758 elsif Nkind (Unit) = N_Package_Instantiation then
9759 return Defining_Entity (Specification (Instance_Spec (Unit)));
9760 else
9761 return Defining_Entity (Unit);
9762 end if;
9763 end Get_Parent_Entity;
9764
9765 -------------------
9766 -- Get_Pragma_Id --
9767 -------------------
9768
9769 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
9770 begin
9771 return Get_Pragma_Id (Pragma_Name_Unmapped (N));
9772 end Get_Pragma_Id;
9773
9774 ------------------------
9775 -- Get_Qualified_Name --
9776 ------------------------
9777
9778 function Get_Qualified_Name
9779 (Id : Entity_Id;
9780 Suffix : Entity_Id := Empty) return Name_Id
9781 is
9782 Suffix_Nam : Name_Id := No_Name;
9783
9784 begin
9785 if Present (Suffix) then
9786 Suffix_Nam := Chars (Suffix);
9787 end if;
9788
9789 return Get_Qualified_Name (Chars (Id), Suffix_Nam, Scope (Id));
9790 end Get_Qualified_Name;
9791
9792 function Get_Qualified_Name
9793 (Nam : Name_Id;
9794 Suffix : Name_Id := No_Name;
9795 Scop : Entity_Id := Current_Scope) return Name_Id
9796 is
9797 procedure Add_Scope (S : Entity_Id);
9798 -- Add the fully qualified form of scope S to the name buffer. The
9799 -- format is:
9800 -- s-1__s__
9801
9802 ---------------
9803 -- Add_Scope --
9804 ---------------
9805
9806 procedure Add_Scope (S : Entity_Id) is
9807 begin
9808 if S = Empty then
9809 null;
9810
9811 elsif S = Standard_Standard then
9812 null;
9813
9814 else
9815 Add_Scope (Scope (S));
9816 Get_Name_String_And_Append (Chars (S));
9817 Add_Str_To_Name_Buffer ("__");
9818 end if;
9819 end Add_Scope;
9820
9821 -- Start of processing for Get_Qualified_Name
9822
9823 begin
9824 Name_Len := 0;
9825 Add_Scope (Scop);
9826
9827 -- Append the base name after all scopes have been chained
9828
9829 Get_Name_String_And_Append (Nam);
9830
9831 -- Append the suffix (if present)
9832
9833 if Suffix /= No_Name then
9834 Add_Str_To_Name_Buffer ("__");
9835 Get_Name_String_And_Append (Suffix);
9836 end if;
9837
9838 return Name_Find;
9839 end Get_Qualified_Name;
9840
9841 -----------------------
9842 -- Get_Reason_String --
9843 -----------------------
9844
9845 procedure Get_Reason_String (N : Node_Id) is
9846 begin
9847 if Nkind (N) = N_String_Literal then
9848 Store_String_Chars (Strval (N));
9849
9850 elsif Nkind (N) = N_Op_Concat then
9851 Get_Reason_String (Left_Opnd (N));
9852 Get_Reason_String (Right_Opnd (N));
9853
9854 -- If not of required form, error
9855
9856 else
9857 Error_Msg_N
9858 ("Reason for pragma Warnings has wrong form", N);
9859 Error_Msg_N
9860 ("\must be string literal or concatenation of string literals", N);
9861 return;
9862 end if;
9863 end Get_Reason_String;
9864
9865 --------------------------------
9866 -- Get_Reference_Discriminant --
9867 --------------------------------
9868
9869 function Get_Reference_Discriminant (Typ : Entity_Id) return Entity_Id is
9870 D : Entity_Id;
9871
9872 begin
9873 D := First_Discriminant (Typ);
9874 while Present (D) loop
9875 if Has_Implicit_Dereference (D) then
9876 return D;
9877 end if;
9878 Next_Discriminant (D);
9879 end loop;
9880
9881 return Empty;
9882 end Get_Reference_Discriminant;
9883
9884 ---------------------------
9885 -- Get_Referenced_Object --
9886 ---------------------------
9887
9888 function Get_Referenced_Object (N : Node_Id) return Node_Id is
9889 R : Node_Id;
9890
9891 begin
9892 R := N;
9893 while Is_Entity_Name (R)
9894 and then Present (Renamed_Object (Entity (R)))
9895 loop
9896 R := Renamed_Object (Entity (R));
9897 end loop;
9898
9899 return R;
9900 end Get_Referenced_Object;
9901
9902 ------------------------
9903 -- Get_Renamed_Entity --
9904 ------------------------
9905
9906 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
9907 R : Entity_Id;
9908
9909 begin
9910 R := E;
9911 while Present (Renamed_Entity (R)) loop
9912 R := Renamed_Entity (R);
9913 end loop;
9914
9915 return R;
9916 end Get_Renamed_Entity;
9917
9918 -----------------------
9919 -- Get_Return_Object --
9920 -----------------------
9921
9922 function Get_Return_Object (N : Node_Id) return Entity_Id is
9923 Decl : Node_Id;
9924
9925 begin
9926 Decl := First (Return_Object_Declarations (N));
9927 while Present (Decl) loop
9928 exit when Nkind (Decl) = N_Object_Declaration
9929 and then Is_Return_Object (Defining_Identifier (Decl));
9930 Next (Decl);
9931 end loop;
9932
9933 pragma Assert (Present (Decl));
9934 return Defining_Identifier (Decl);
9935 end Get_Return_Object;
9936
9937 ---------------------------
9938 -- Get_Subprogram_Entity --
9939 ---------------------------
9940
9941 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
9942 Subp : Node_Id;
9943 Subp_Id : Entity_Id;
9944
9945 begin
9946 if Nkind (Nod) = N_Accept_Statement then
9947 Subp := Entry_Direct_Name (Nod);
9948
9949 elsif Nkind (Nod) = N_Slice then
9950 Subp := Prefix (Nod);
9951
9952 else
9953 Subp := Name (Nod);
9954 end if;
9955
9956 -- Strip the subprogram call
9957
9958 loop
9959 if Nkind_In (Subp, N_Explicit_Dereference,
9960 N_Indexed_Component,
9961 N_Selected_Component)
9962 then
9963 Subp := Prefix (Subp);
9964
9965 elsif Nkind_In (Subp, N_Type_Conversion,
9966 N_Unchecked_Type_Conversion)
9967 then
9968 Subp := Expression (Subp);
9969
9970 else
9971 exit;
9972 end if;
9973 end loop;
9974
9975 -- Extract the entity of the subprogram call
9976
9977 if Is_Entity_Name (Subp) then
9978 Subp_Id := Entity (Subp);
9979
9980 if Ekind (Subp_Id) = E_Access_Subprogram_Type then
9981 Subp_Id := Directly_Designated_Type (Subp_Id);
9982 end if;
9983
9984 if Is_Subprogram (Subp_Id) then
9985 return Subp_Id;
9986 else
9987 return Empty;
9988 end if;
9989
9990 -- The search did not find a construct that denotes a subprogram
9991
9992 else
9993 return Empty;
9994 end if;
9995 end Get_Subprogram_Entity;
9996
9997 -----------------------------
9998 -- Get_Task_Body_Procedure --
9999 -----------------------------
10000
10001 function Get_Task_Body_Procedure (E : Entity_Id) return Entity_Id is
10002 begin
10003 -- Note: A task type may be the completion of a private type with
10004 -- discriminants. When performing elaboration checks on a task
10005 -- declaration, the current view of the type may be the private one,
10006 -- and the procedure that holds the body of the task is held in its
10007 -- underlying type.
10008
10009 -- This is an odd function, why not have Task_Body_Procedure do
10010 -- the following digging???
10011
10012 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
10013 end Get_Task_Body_Procedure;
10014
10015 -------------------------
10016 -- Get_User_Defined_Eq --
10017 -------------------------
10018
10019 function Get_User_Defined_Eq (E : Entity_Id) return Entity_Id is
10020 Prim : Elmt_Id;
10021 Op : Entity_Id;
10022
10023 begin
10024 Prim := First_Elmt (Collect_Primitive_Operations (E));
10025 while Present (Prim) loop
10026 Op := Node (Prim);
10027
10028 if Chars (Op) = Name_Op_Eq
10029 and then Etype (Op) = Standard_Boolean
10030 and then Etype (First_Formal (Op)) = E
10031 and then Etype (Next_Formal (First_Formal (Op))) = E
10032 then
10033 return Op;
10034 end if;
10035
10036 Next_Elmt (Prim);
10037 end loop;
10038
10039 return Empty;
10040 end Get_User_Defined_Eq;
10041
10042 ---------------
10043 -- Get_Views --
10044 ---------------
10045
10046 procedure Get_Views
10047 (Typ : Entity_Id;
10048 Priv_Typ : out Entity_Id;
10049 Full_Typ : out Entity_Id;
10050 Full_Base : out Entity_Id;
10051 CRec_Typ : out Entity_Id)
10052 is
10053 IP_View : Entity_Id;
10054
10055 begin
10056 -- Assume that none of the views can be recovered
10057
10058 Priv_Typ := Empty;
10059 Full_Typ := Empty;
10060 Full_Base := Empty;
10061 CRec_Typ := Empty;
10062
10063 -- The input type is the corresponding record type of a protected or a
10064 -- task type.
10065
10066 if Ekind (Typ) = E_Record_Type
10067 and then Is_Concurrent_Record_Type (Typ)
10068 then
10069 CRec_Typ := Typ;
10070 Full_Typ := Corresponding_Concurrent_Type (CRec_Typ);
10071 Full_Base := Base_Type (Full_Typ);
10072 Priv_Typ := Incomplete_Or_Partial_View (Full_Typ);
10073
10074 -- Otherwise the input type denotes an arbitrary type
10075
10076 else
10077 IP_View := Incomplete_Or_Partial_View (Typ);
10078
10079 -- The input type denotes the full view of a private type
10080
10081 if Present (IP_View) then
10082 Priv_Typ := IP_View;
10083 Full_Typ := Typ;
10084
10085 -- The input type is a private type
10086
10087 elsif Is_Private_Type (Typ) then
10088 Priv_Typ := Typ;
10089 Full_Typ := Full_View (Priv_Typ);
10090
10091 -- Otherwise the input type does not have any views
10092
10093 else
10094 Full_Typ := Typ;
10095 end if;
10096
10097 if Present (Full_Typ) then
10098 Full_Base := Base_Type (Full_Typ);
10099
10100 if Ekind_In (Full_Typ, E_Protected_Type, E_Task_Type) then
10101 CRec_Typ := Corresponding_Record_Type (Full_Typ);
10102 end if;
10103 end if;
10104 end if;
10105 end Get_Views;
10106
10107 -----------------------
10108 -- Has_Access_Values --
10109 -----------------------
10110
10111 function Has_Access_Values (T : Entity_Id) return Boolean is
10112 Typ : constant Entity_Id := Underlying_Type (T);
10113
10114 begin
10115 -- Case of a private type which is not completed yet. This can only
10116 -- happen in the case of a generic format type appearing directly, or
10117 -- as a component of the type to which this function is being applied
10118 -- at the top level. Return False in this case, since we certainly do
10119 -- not know that the type contains access types.
10120
10121 if No (Typ) then
10122 return False;
10123
10124 elsif Is_Access_Type (Typ) then
10125 return True;
10126
10127 elsif Is_Array_Type (Typ) then
10128 return Has_Access_Values (Component_Type (Typ));
10129
10130 elsif Is_Record_Type (Typ) then
10131 declare
10132 Comp : Entity_Id;
10133
10134 begin
10135 -- Loop to Check components
10136
10137 Comp := First_Component_Or_Discriminant (Typ);
10138 while Present (Comp) loop
10139
10140 -- Check for access component, tag field does not count, even
10141 -- though it is implemented internally using an access type.
10142
10143 if Has_Access_Values (Etype (Comp))
10144 and then Chars (Comp) /= Name_uTag
10145 then
10146 return True;
10147 end if;
10148
10149 Next_Component_Or_Discriminant (Comp);
10150 end loop;
10151 end;
10152
10153 return False;
10154
10155 else
10156 return False;
10157 end if;
10158 end Has_Access_Values;
10159
10160 ------------------------------
10161 -- Has_Compatible_Alignment --
10162 ------------------------------
10163
10164 function Has_Compatible_Alignment
10165 (Obj : Entity_Id;
10166 Expr : Node_Id;
10167 Layout_Done : Boolean) return Alignment_Result
10168 is
10169 function Has_Compatible_Alignment_Internal
10170 (Obj : Entity_Id;
10171 Expr : Node_Id;
10172 Layout_Done : Boolean;
10173 Default : Alignment_Result) return Alignment_Result;
10174 -- This is the internal recursive function that actually does the work.
10175 -- There is one additional parameter, which says what the result should
10176 -- be if no alignment information is found, and there is no definite
10177 -- indication of compatible alignments. At the outer level, this is set
10178 -- to Unknown, but for internal recursive calls in the case where types
10179 -- are known to be correct, it is set to Known_Compatible.
10180
10181 ---------------------------------------
10182 -- Has_Compatible_Alignment_Internal --
10183 ---------------------------------------
10184
10185 function Has_Compatible_Alignment_Internal
10186 (Obj : Entity_Id;
10187 Expr : Node_Id;
10188 Layout_Done : Boolean;
10189 Default : Alignment_Result) return Alignment_Result
10190 is
10191 Result : Alignment_Result := Known_Compatible;
10192 -- Holds the current status of the result. Note that once a value of
10193 -- Known_Incompatible is set, it is sticky and does not get changed
10194 -- to Unknown (the value in Result only gets worse as we go along,
10195 -- never better).
10196
10197 Offs : Uint := No_Uint;
10198 -- Set to a factor of the offset from the base object when Expr is a
10199 -- selected or indexed component, based on Component_Bit_Offset and
10200 -- Component_Size respectively. A negative value is used to represent
10201 -- a value which is not known at compile time.
10202
10203 procedure Check_Prefix;
10204 -- Checks the prefix recursively in the case where the expression
10205 -- is an indexed or selected component.
10206
10207 procedure Set_Result (R : Alignment_Result);
10208 -- If R represents a worse outcome (unknown instead of known
10209 -- compatible, or known incompatible), then set Result to R.
10210
10211 ------------------
10212 -- Check_Prefix --
10213 ------------------
10214
10215 procedure Check_Prefix is
10216 begin
10217 -- The subtlety here is that in doing a recursive call to check
10218 -- the prefix, we have to decide what to do in the case where we
10219 -- don't find any specific indication of an alignment problem.
10220
10221 -- At the outer level, we normally set Unknown as the result in
10222 -- this case, since we can only set Known_Compatible if we really
10223 -- know that the alignment value is OK, but for the recursive
10224 -- call, in the case where the types match, and we have not
10225 -- specified a peculiar alignment for the object, we are only
10226 -- concerned about suspicious rep clauses, the default case does
10227 -- not affect us, since the compiler will, in the absence of such
10228 -- rep clauses, ensure that the alignment is correct.
10229
10230 if Default = Known_Compatible
10231 or else
10232 (Etype (Obj) = Etype (Expr)
10233 and then (Unknown_Alignment (Obj)
10234 or else
10235 Alignment (Obj) = Alignment (Etype (Obj))))
10236 then
10237 Set_Result
10238 (Has_Compatible_Alignment_Internal
10239 (Obj, Prefix (Expr), Layout_Done, Known_Compatible));
10240
10241 -- In all other cases, we need a full check on the prefix
10242
10243 else
10244 Set_Result
10245 (Has_Compatible_Alignment_Internal
10246 (Obj, Prefix (Expr), Layout_Done, Unknown));
10247 end if;
10248 end Check_Prefix;
10249
10250 ----------------
10251 -- Set_Result --
10252 ----------------
10253
10254 procedure Set_Result (R : Alignment_Result) is
10255 begin
10256 if R > Result then
10257 Result := R;
10258 end if;
10259 end Set_Result;
10260
10261 -- Start of processing for Has_Compatible_Alignment_Internal
10262
10263 begin
10264 -- If Expr is a selected component, we must make sure there is no
10265 -- potentially troublesome component clause and that the record is
10266 -- not packed if the layout is not done.
10267
10268 if Nkind (Expr) = N_Selected_Component then
10269
10270 -- Packing generates unknown alignment if layout is not done
10271
10272 if Is_Packed (Etype (Prefix (Expr))) and then not Layout_Done then
10273 Set_Result (Unknown);
10274 end if;
10275
10276 -- Check prefix and component offset
10277
10278 Check_Prefix;
10279 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
10280
10281 -- If Expr is an indexed component, we must make sure there is no
10282 -- potentially troublesome Component_Size clause and that the array
10283 -- is not bit-packed if the layout is not done.
10284
10285 elsif Nkind (Expr) = N_Indexed_Component then
10286 declare
10287 Typ : constant Entity_Id := Etype (Prefix (Expr));
10288
10289 begin
10290 -- Packing generates unknown alignment if layout is not done
10291
10292 if Is_Bit_Packed_Array (Typ) and then not Layout_Done then
10293 Set_Result (Unknown);
10294 end if;
10295
10296 -- Check prefix and component offset (or at least size)
10297
10298 Check_Prefix;
10299 Offs := Indexed_Component_Bit_Offset (Expr);
10300 if Offs = No_Uint then
10301 Offs := Component_Size (Typ);
10302 end if;
10303 end;
10304 end if;
10305
10306 -- If we have a null offset, the result is entirely determined by
10307 -- the base object and has already been computed recursively.
10308
10309 if Offs = Uint_0 then
10310 null;
10311
10312 -- Case where we know the alignment of the object
10313
10314 elsif Known_Alignment (Obj) then
10315 declare
10316 ObjA : constant Uint := Alignment (Obj);
10317 ExpA : Uint := No_Uint;
10318 SizA : Uint := No_Uint;
10319
10320 begin
10321 -- If alignment of Obj is 1, then we are always OK
10322
10323 if ObjA = 1 then
10324 Set_Result (Known_Compatible);
10325
10326 -- Alignment of Obj is greater than 1, so we need to check
10327
10328 else
10329 -- If we have an offset, see if it is compatible
10330
10331 if Offs /= No_Uint and Offs > Uint_0 then
10332 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
10333 Set_Result (Known_Incompatible);
10334 end if;
10335
10336 -- See if Expr is an object with known alignment
10337
10338 elsif Is_Entity_Name (Expr)
10339 and then Known_Alignment (Entity (Expr))
10340 then
10341 ExpA := Alignment (Entity (Expr));
10342
10343 -- Otherwise, we can use the alignment of the type of
10344 -- Expr given that we already checked for
10345 -- discombobulating rep clauses for the cases of indexed
10346 -- and selected components above.
10347
10348 elsif Known_Alignment (Etype (Expr)) then
10349 ExpA := Alignment (Etype (Expr));
10350
10351 -- Otherwise the alignment is unknown
10352
10353 else
10354 Set_Result (Default);
10355 end if;
10356
10357 -- If we got an alignment, see if it is acceptable
10358
10359 if ExpA /= No_Uint and then ExpA < ObjA then
10360 Set_Result (Known_Incompatible);
10361 end if;
10362
10363 -- If Expr is not a piece of a larger object, see if size
10364 -- is given. If so, check that it is not too small for the
10365 -- required alignment.
10366
10367 if Offs /= No_Uint then
10368 null;
10369
10370 -- See if Expr is an object with known size
10371
10372 elsif Is_Entity_Name (Expr)
10373 and then Known_Static_Esize (Entity (Expr))
10374 then
10375 SizA := Esize (Entity (Expr));
10376
10377 -- Otherwise, we check the object size of the Expr type
10378
10379 elsif Known_Static_Esize (Etype (Expr)) then
10380 SizA := Esize (Etype (Expr));
10381 end if;
10382
10383 -- If we got a size, see if it is a multiple of the Obj
10384 -- alignment, if not, then the alignment cannot be
10385 -- acceptable, since the size is always a multiple of the
10386 -- alignment.
10387
10388 if SizA /= No_Uint then
10389 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
10390 Set_Result (Known_Incompatible);
10391 end if;
10392 end if;
10393 end if;
10394 end;
10395
10396 -- If we do not know required alignment, any non-zero offset is a
10397 -- potential problem (but certainly may be OK, so result is unknown).
10398
10399 elsif Offs /= No_Uint then
10400 Set_Result (Unknown);
10401
10402 -- If we can't find the result by direct comparison of alignment
10403 -- values, then there is still one case that we can determine known
10404 -- result, and that is when we can determine that the types are the
10405 -- same, and no alignments are specified. Then we known that the
10406 -- alignments are compatible, even if we don't know the alignment
10407 -- value in the front end.
10408
10409 elsif Etype (Obj) = Etype (Expr) then
10410
10411 -- Types are the same, but we have to check for possible size
10412 -- and alignments on the Expr object that may make the alignment
10413 -- different, even though the types are the same.
10414
10415 if Is_Entity_Name (Expr) then
10416
10417 -- First check alignment of the Expr object. Any alignment less
10418 -- than Maximum_Alignment is worrisome since this is the case
10419 -- where we do not know the alignment of Obj.
10420
10421 if Known_Alignment (Entity (Expr))
10422 and then UI_To_Int (Alignment (Entity (Expr))) <
10423 Ttypes.Maximum_Alignment
10424 then
10425 Set_Result (Unknown);
10426
10427 -- Now check size of Expr object. Any size that is not an
10428 -- even multiple of Maximum_Alignment is also worrisome
10429 -- since it may cause the alignment of the object to be less
10430 -- than the alignment of the type.
10431
10432 elsif Known_Static_Esize (Entity (Expr))
10433 and then
10434 (UI_To_Int (Esize (Entity (Expr))) mod
10435 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
10436 /= 0
10437 then
10438 Set_Result (Unknown);
10439
10440 -- Otherwise same type is decisive
10441
10442 else
10443 Set_Result (Known_Compatible);
10444 end if;
10445 end if;
10446
10447 -- Another case to deal with is when there is an explicit size or
10448 -- alignment clause when the types are not the same. If so, then the
10449 -- result is Unknown. We don't need to do this test if the Default is
10450 -- Unknown, since that result will be set in any case.
10451
10452 elsif Default /= Unknown
10453 and then (Has_Size_Clause (Etype (Expr))
10454 or else
10455 Has_Alignment_Clause (Etype (Expr)))
10456 then
10457 Set_Result (Unknown);
10458
10459 -- If no indication found, set default
10460
10461 else
10462 Set_Result (Default);
10463 end if;
10464
10465 -- Return worst result found
10466
10467 return Result;
10468 end Has_Compatible_Alignment_Internal;
10469
10470 -- Start of processing for Has_Compatible_Alignment
10471
10472 begin
10473 -- If Obj has no specified alignment, then set alignment from the type
10474 -- alignment. Perhaps we should always do this, but for sure we should
10475 -- do it when there is an address clause since we can do more if the
10476 -- alignment is known.
10477
10478 if Unknown_Alignment (Obj) then
10479 Set_Alignment (Obj, Alignment (Etype (Obj)));
10480 end if;
10481
10482 -- Now do the internal call that does all the work
10483
10484 return
10485 Has_Compatible_Alignment_Internal (Obj, Expr, Layout_Done, Unknown);
10486 end Has_Compatible_Alignment;
10487
10488 ----------------------
10489 -- Has_Declarations --
10490 ----------------------
10491
10492 function Has_Declarations (N : Node_Id) return Boolean is
10493 begin
10494 return Nkind_In (Nkind (N), N_Accept_Statement,
10495 N_Block_Statement,
10496 N_Compilation_Unit_Aux,
10497 N_Entry_Body,
10498 N_Package_Body,
10499 N_Protected_Body,
10500 N_Subprogram_Body,
10501 N_Task_Body,
10502 N_Package_Specification);
10503 end Has_Declarations;
10504
10505 ---------------------------------
10506 -- Has_Defaulted_Discriminants --
10507 ---------------------------------
10508
10509 function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean is
10510 begin
10511 return Has_Discriminants (Typ)
10512 and then Present (First_Discriminant (Typ))
10513 and then Present (Discriminant_Default_Value
10514 (First_Discriminant (Typ)));
10515 end Has_Defaulted_Discriminants;
10516
10517 -------------------
10518 -- Has_Denormals --
10519 -------------------
10520
10521 function Has_Denormals (E : Entity_Id) return Boolean is
10522 begin
10523 return Is_Floating_Point_Type (E) and then Denorm_On_Target;
10524 end Has_Denormals;
10525
10526 -------------------------------------------
10527 -- Has_Discriminant_Dependent_Constraint --
10528 -------------------------------------------
10529
10530 function Has_Discriminant_Dependent_Constraint
10531 (Comp : Entity_Id) return Boolean
10532 is
10533 Comp_Decl : constant Node_Id := Parent (Comp);
10534 Subt_Indic : Node_Id;
10535 Constr : Node_Id;
10536 Assn : Node_Id;
10537
10538 begin
10539 -- Discriminants can't depend on discriminants
10540
10541 if Ekind (Comp) = E_Discriminant then
10542 return False;
10543
10544 else
10545 Subt_Indic := Subtype_Indication (Component_Definition (Comp_Decl));
10546
10547 if Nkind (Subt_Indic) = N_Subtype_Indication then
10548 Constr := Constraint (Subt_Indic);
10549
10550 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
10551 Assn := First (Constraints (Constr));
10552 while Present (Assn) loop
10553 case Nkind (Assn) is
10554 when N_Identifier
10555 | N_Range
10556 | N_Subtype_Indication
10557 =>
10558 if Depends_On_Discriminant (Assn) then
10559 return True;
10560 end if;
10561
10562 when N_Discriminant_Association =>
10563 if Depends_On_Discriminant (Expression (Assn)) then
10564 return True;
10565 end if;
10566
10567 when others =>
10568 null;
10569 end case;
10570
10571 Next (Assn);
10572 end loop;
10573 end if;
10574 end if;
10575 end if;
10576
10577 return False;
10578 end Has_Discriminant_Dependent_Constraint;
10579
10580 --------------------------------------
10581 -- Has_Effectively_Volatile_Profile --
10582 --------------------------------------
10583
10584 function Has_Effectively_Volatile_Profile
10585 (Subp_Id : Entity_Id) return Boolean
10586 is
10587 Formal : Entity_Id;
10588
10589 begin
10590 -- Inspect the formal parameters looking for an effectively volatile
10591 -- type.
10592
10593 Formal := First_Formal (Subp_Id);
10594 while Present (Formal) loop
10595 if Is_Effectively_Volatile (Etype (Formal)) then
10596 return True;
10597 end if;
10598
10599 Next_Formal (Formal);
10600 end loop;
10601
10602 -- Inspect the return type of functions
10603
10604 if Ekind_In (Subp_Id, E_Function, E_Generic_Function)
10605 and then Is_Effectively_Volatile (Etype (Subp_Id))
10606 then
10607 return True;
10608 end if;
10609
10610 return False;
10611 end Has_Effectively_Volatile_Profile;
10612
10613 --------------------------
10614 -- Has_Enabled_Property --
10615 --------------------------
10616
10617 function Has_Enabled_Property
10618 (Item_Id : Entity_Id;
10619 Property : Name_Id) return Boolean
10620 is
10621 function Protected_Object_Has_Enabled_Property return Boolean;
10622 -- Determine whether a protected object denoted by Item_Id has the
10623 -- property enabled.
10624
10625 function State_Has_Enabled_Property return Boolean;
10626 -- Determine whether a state denoted by Item_Id has the property enabled
10627
10628 function Variable_Has_Enabled_Property return Boolean;
10629 -- Determine whether a variable denoted by Item_Id has the property
10630 -- enabled.
10631
10632 -------------------------------------------
10633 -- Protected_Object_Has_Enabled_Property --
10634 -------------------------------------------
10635
10636 function Protected_Object_Has_Enabled_Property return Boolean is
10637 Constits : constant Elist_Id := Part_Of_Constituents (Item_Id);
10638 Constit_Elmt : Elmt_Id;
10639 Constit_Id : Entity_Id;
10640
10641 begin
10642 -- Protected objects always have the properties Async_Readers and
10643 -- Async_Writers (SPARK RM 7.1.2(16)).
10644
10645 if Property = Name_Async_Readers
10646 or else Property = Name_Async_Writers
10647 then
10648 return True;
10649
10650 -- Protected objects that have Part_Of components also inherit their
10651 -- properties Effective_Reads and Effective_Writes
10652 -- (SPARK RM 7.1.2(16)).
10653
10654 elsif Present (Constits) then
10655 Constit_Elmt := First_Elmt (Constits);
10656 while Present (Constit_Elmt) loop
10657 Constit_Id := Node (Constit_Elmt);
10658
10659 if Has_Enabled_Property (Constit_Id, Property) then
10660 return True;
10661 end if;
10662
10663 Next_Elmt (Constit_Elmt);
10664 end loop;
10665 end if;
10666
10667 return False;
10668 end Protected_Object_Has_Enabled_Property;
10669
10670 --------------------------------
10671 -- State_Has_Enabled_Property --
10672 --------------------------------
10673
10674 function State_Has_Enabled_Property return Boolean is
10675 Decl : constant Node_Id := Parent (Item_Id);
10676
10677 procedure Find_Simple_Properties
10678 (Has_External : out Boolean;
10679 Has_Synchronous : out Boolean);
10680 -- Extract the simple properties associated with declaration Decl
10681
10682 function Is_Enabled_External_Property return Boolean;
10683 -- Determine whether property Property appears within the external
10684 -- property list of declaration Decl, and return its status.
10685
10686 ----------------------------
10687 -- Find_Simple_Properties --
10688 ----------------------------
10689
10690 procedure Find_Simple_Properties
10691 (Has_External : out Boolean;
10692 Has_Synchronous : out Boolean)
10693 is
10694 Opt : Node_Id;
10695
10696 begin
10697 -- Assume that none of the properties are available
10698
10699 Has_External := False;
10700 Has_Synchronous := False;
10701
10702 Opt := First (Expressions (Decl));
10703 while Present (Opt) loop
10704 if Nkind (Opt) = N_Identifier then
10705 if Chars (Opt) = Name_External then
10706 Has_External := True;
10707
10708 elsif Chars (Opt) = Name_Synchronous then
10709 Has_Synchronous := True;
10710 end if;
10711 end if;
10712
10713 Next (Opt);
10714 end loop;
10715 end Find_Simple_Properties;
10716
10717 ----------------------------------
10718 -- Is_Enabled_External_Property --
10719 ----------------------------------
10720
10721 function Is_Enabled_External_Property return Boolean is
10722 Opt : Node_Id;
10723 Opt_Nam : Node_Id;
10724 Prop : Node_Id;
10725 Prop_Nam : Node_Id;
10726 Props : Node_Id;
10727
10728 begin
10729 Opt := First (Component_Associations (Decl));
10730 while Present (Opt) loop
10731 Opt_Nam := First (Choices (Opt));
10732
10733 if Nkind (Opt_Nam) = N_Identifier
10734 and then Chars (Opt_Nam) = Name_External
10735 then
10736 Props := Expression (Opt);
10737
10738 -- Multiple properties appear as an aggregate
10739
10740 if Nkind (Props) = N_Aggregate then
10741
10742 -- Simple property form
10743
10744 Prop := First (Expressions (Props));
10745 while Present (Prop) loop
10746 if Chars (Prop) = Property then
10747 return True;
10748 end if;
10749
10750 Next (Prop);
10751 end loop;
10752
10753 -- Property with expression form
10754
10755 Prop := First (Component_Associations (Props));
10756 while Present (Prop) loop
10757 Prop_Nam := First (Choices (Prop));
10758
10759 -- The property can be represented in two ways:
10760 -- others => <value>
10761 -- <property> => <value>
10762
10763 if Nkind (Prop_Nam) = N_Others_Choice
10764 or else (Nkind (Prop_Nam) = N_Identifier
10765 and then Chars (Prop_Nam) = Property)
10766 then
10767 return Is_True (Expr_Value (Expression (Prop)));
10768 end if;
10769
10770 Next (Prop);
10771 end loop;
10772
10773 -- Single property
10774
10775 else
10776 return Chars (Props) = Property;
10777 end if;
10778 end if;
10779
10780 Next (Opt);
10781 end loop;
10782
10783 return False;
10784 end Is_Enabled_External_Property;
10785
10786 -- Local variables
10787
10788 Has_External : Boolean;
10789 Has_Synchronous : Boolean;
10790
10791 -- Start of processing for State_Has_Enabled_Property
10792
10793 begin
10794 -- The declaration of an external abstract state appears as an
10795 -- extension aggregate. If this is not the case, properties can
10796 -- never be set.
10797
10798 if Nkind (Decl) /= N_Extension_Aggregate then
10799 return False;
10800 end if;
10801
10802 Find_Simple_Properties (Has_External, Has_Synchronous);
10803
10804 -- Simple option External enables all properties (SPARK RM 7.1.2(2))
10805
10806 if Has_External then
10807 return True;
10808
10809 -- Option External may enable or disable specific properties
10810
10811 elsif Is_Enabled_External_Property then
10812 return True;
10813
10814 -- Simple option Synchronous
10815 --
10816 -- enables disables
10817 -- Async_Readers Effective_Reads
10818 -- Async_Writers Effective_Writes
10819 --
10820 -- Note that both forms of External have higher precedence than
10821 -- Synchronous (SPARK RM 7.1.4(9)).
10822
10823 elsif Has_Synchronous then
10824 return Nam_In (Property, Name_Async_Readers, Name_Async_Writers);
10825 end if;
10826
10827 return False;
10828 end State_Has_Enabled_Property;
10829
10830 -----------------------------------
10831 -- Variable_Has_Enabled_Property --
10832 -----------------------------------
10833
10834 function Variable_Has_Enabled_Property return Boolean is
10835 function Is_Enabled (Prag : Node_Id) return Boolean;
10836 -- Determine whether property pragma Prag (if present) denotes an
10837 -- enabled property.
10838
10839 ----------------
10840 -- Is_Enabled --
10841 ----------------
10842
10843 function Is_Enabled (Prag : Node_Id) return Boolean is
10844 Arg1 : Node_Id;
10845
10846 begin
10847 if Present (Prag) then
10848 Arg1 := First (Pragma_Argument_Associations (Prag));
10849
10850 -- The pragma has an optional Boolean expression, the related
10851 -- property is enabled only when the expression evaluates to
10852 -- True.
10853
10854 if Present (Arg1) then
10855 return Is_True (Expr_Value (Get_Pragma_Arg (Arg1)));
10856
10857 -- Otherwise the lack of expression enables the property by
10858 -- default.
10859
10860 else
10861 return True;
10862 end if;
10863
10864 -- The property was never set in the first place
10865
10866 else
10867 return False;
10868 end if;
10869 end Is_Enabled;
10870
10871 -- Local variables
10872
10873 AR : constant Node_Id :=
10874 Get_Pragma (Item_Id, Pragma_Async_Readers);
10875 AW : constant Node_Id :=
10876 Get_Pragma (Item_Id, Pragma_Async_Writers);
10877 ER : constant Node_Id :=
10878 Get_Pragma (Item_Id, Pragma_Effective_Reads);
10879 EW : constant Node_Id :=
10880 Get_Pragma (Item_Id, Pragma_Effective_Writes);
10881
10882 -- Start of processing for Variable_Has_Enabled_Property
10883
10884 begin
10885 -- A non-effectively volatile object can never possess external
10886 -- properties.
10887
10888 if not Is_Effectively_Volatile (Item_Id) then
10889 return False;
10890
10891 -- External properties related to variables come in two flavors -
10892 -- explicit and implicit. The explicit case is characterized by the
10893 -- presence of a property pragma with an optional Boolean flag. The
10894 -- property is enabled when the flag evaluates to True or the flag is
10895 -- missing altogether.
10896
10897 elsif Property = Name_Async_Readers and then Is_Enabled (AR) then
10898 return True;
10899
10900 elsif Property = Name_Async_Writers and then Is_Enabled (AW) then
10901 return True;
10902
10903 elsif Property = Name_Effective_Reads and then Is_Enabled (ER) then
10904 return True;
10905
10906 elsif Property = Name_Effective_Writes and then Is_Enabled (EW) then
10907 return True;
10908
10909 -- The implicit case lacks all property pragmas
10910
10911 elsif No (AR) and then No (AW) and then No (ER) and then No (EW) then
10912 if Is_Protected_Type (Etype (Item_Id)) then
10913 return Protected_Object_Has_Enabled_Property;
10914 else
10915 return True;
10916 end if;
10917
10918 else
10919 return False;
10920 end if;
10921 end Variable_Has_Enabled_Property;
10922
10923 -- Start of processing for Has_Enabled_Property
10924
10925 begin
10926 -- Abstract states and variables have a flexible scheme of specifying
10927 -- external properties.
10928
10929 if Ekind (Item_Id) = E_Abstract_State then
10930 return State_Has_Enabled_Property;
10931
10932 elsif Ekind (Item_Id) = E_Variable then
10933 return Variable_Has_Enabled_Property;
10934
10935 -- By default, protected objects only have the properties Async_Readers
10936 -- and Async_Writers. If they have Part_Of components, they also inherit
10937 -- their properties Effective_Reads and Effective_Writes
10938 -- (SPARK RM 7.1.2(16)).
10939
10940 elsif Ekind (Item_Id) = E_Protected_Object then
10941 return Protected_Object_Has_Enabled_Property;
10942
10943 -- Otherwise a property is enabled when the related item is effectively
10944 -- volatile.
10945
10946 else
10947 return Is_Effectively_Volatile (Item_Id);
10948 end if;
10949 end Has_Enabled_Property;
10950
10951 -------------------------------------
10952 -- Has_Full_Default_Initialization --
10953 -------------------------------------
10954
10955 function Has_Full_Default_Initialization (Typ : Entity_Id) return Boolean is
10956 Comp : Entity_Id;
10957
10958 begin
10959 -- A type subject to pragma Default_Initial_Condition may be fully
10960 -- default initialized depending on inheritance and the argument of
10961 -- the pragma. Since any type may act as the full view of a private
10962 -- type, this check must be performed prior to the specialized tests
10963 -- below.
10964
10965 if Has_Fully_Default_Initializing_DIC_Pragma (Typ) then
10966 return True;
10967 end if;
10968
10969 -- A scalar type is fully default initialized if it is subject to aspect
10970 -- Default_Value.
10971
10972 if Is_Scalar_Type (Typ) then
10973 return Has_Default_Aspect (Typ);
10974
10975 -- An access type is fully default initialized by default
10976
10977 elsif Is_Access_Type (Typ) then
10978 return True;
10979
10980 -- An array type is fully default initialized if its element type is
10981 -- scalar and the array type carries aspect Default_Component_Value or
10982 -- the element type is fully default initialized.
10983
10984 elsif Is_Array_Type (Typ) then
10985 return
10986 Has_Default_Aspect (Typ)
10987 or else Has_Full_Default_Initialization (Component_Type (Typ));
10988
10989 -- A protected type, record type, or type extension is fully default
10990 -- initialized if all its components either carry an initialization
10991 -- expression or have a type that is fully default initialized. The
10992 -- parent type of a type extension must be fully default initialized.
10993
10994 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
10995
10996 -- Inspect all entities defined in the scope of the type, looking for
10997 -- uninitialized components.
10998
10999 Comp := First_Entity (Typ);
11000 while Present (Comp) loop
11001 if Ekind (Comp) = E_Component
11002 and then Comes_From_Source (Comp)
11003 and then No (Expression (Parent (Comp)))
11004 and then not Has_Full_Default_Initialization (Etype (Comp))
11005 then
11006 return False;
11007 end if;
11008
11009 Next_Entity (Comp);
11010 end loop;
11011
11012 -- Ensure that the parent type of a type extension is fully default
11013 -- initialized.
11014
11015 if Etype (Typ) /= Typ
11016 and then not Has_Full_Default_Initialization (Etype (Typ))
11017 then
11018 return False;
11019 end if;
11020
11021 -- If we get here, then all components and parent portion are fully
11022 -- default initialized.
11023
11024 return True;
11025
11026 -- A task type is fully default initialized by default
11027
11028 elsif Is_Task_Type (Typ) then
11029 return True;
11030
11031 -- Otherwise the type is not fully default initialized
11032
11033 else
11034 return False;
11035 end if;
11036 end Has_Full_Default_Initialization;
11037
11038 -----------------------------------------------
11039 -- Has_Fully_Default_Initializing_DIC_Pragma --
11040 -----------------------------------------------
11041
11042 function Has_Fully_Default_Initializing_DIC_Pragma
11043 (Typ : Entity_Id) return Boolean
11044 is
11045 Args : List_Id;
11046 Prag : Node_Id;
11047
11048 begin
11049 -- A type that inherits pragma Default_Initial_Condition from a parent
11050 -- type is automatically fully default initialized.
11051
11052 if Has_Inherited_DIC (Typ) then
11053 return True;
11054
11055 -- Otherwise the type is fully default initialized only when the pragma
11056 -- appears without an argument, or the argument is non-null.
11057
11058 elsif Has_Own_DIC (Typ) then
11059 Prag := Get_Pragma (Typ, Pragma_Default_Initial_Condition);
11060 pragma Assert (Present (Prag));
11061 Args := Pragma_Argument_Associations (Prag);
11062
11063 -- The pragma appears without an argument in which case it defaults
11064 -- to True.
11065
11066 if No (Args) then
11067 return True;
11068
11069 -- The pragma appears with a non-null expression
11070
11071 elsif Nkind (Get_Pragma_Arg (First (Args))) /= N_Null then
11072 return True;
11073 end if;
11074 end if;
11075
11076 return False;
11077 end Has_Fully_Default_Initializing_DIC_Pragma;
11078
11079 --------------------
11080 -- Has_Infinities --
11081 --------------------
11082
11083 function Has_Infinities (E : Entity_Id) return Boolean is
11084 begin
11085 return
11086 Is_Floating_Point_Type (E)
11087 and then Nkind (Scalar_Range (E)) = N_Range
11088 and then Includes_Infinities (Scalar_Range (E));
11089 end Has_Infinities;
11090
11091 --------------------
11092 -- Has_Interfaces --
11093 --------------------
11094
11095 function Has_Interfaces
11096 (T : Entity_Id;
11097 Use_Full_View : Boolean := True) return Boolean
11098 is
11099 Typ : Entity_Id := Base_Type (T);
11100
11101 begin
11102 -- Handle concurrent types
11103
11104 if Is_Concurrent_Type (Typ) then
11105 Typ := Corresponding_Record_Type (Typ);
11106 end if;
11107
11108 if not Present (Typ)
11109 or else not Is_Record_Type (Typ)
11110 or else not Is_Tagged_Type (Typ)
11111 then
11112 return False;
11113 end if;
11114
11115 -- Handle private types
11116
11117 if Use_Full_View and then Present (Full_View (Typ)) then
11118 Typ := Full_View (Typ);
11119 end if;
11120
11121 -- Handle concurrent record types
11122
11123 if Is_Concurrent_Record_Type (Typ)
11124 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
11125 then
11126 return True;
11127 end if;
11128
11129 loop
11130 if Is_Interface (Typ)
11131 or else
11132 (Is_Record_Type (Typ)
11133 and then Present (Interfaces (Typ))
11134 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
11135 then
11136 return True;
11137 end if;
11138
11139 exit when Etype (Typ) = Typ
11140
11141 -- Handle private types
11142
11143 or else (Present (Full_View (Etype (Typ)))
11144 and then Full_View (Etype (Typ)) = Typ)
11145
11146 -- Protect frontend against wrong sources with cyclic derivations
11147
11148 or else Etype (Typ) = T;
11149
11150 -- Climb to the ancestor type handling private types
11151
11152 if Present (Full_View (Etype (Typ))) then
11153 Typ := Full_View (Etype (Typ));
11154 else
11155 Typ := Etype (Typ);
11156 end if;
11157 end loop;
11158
11159 return False;
11160 end Has_Interfaces;
11161
11162 --------------------------
11163 -- Has_Max_Queue_Length --
11164 --------------------------
11165
11166 function Has_Max_Queue_Length (Id : Entity_Id) return Boolean is
11167 begin
11168 return
11169 Ekind (Id) = E_Entry
11170 and then Present (Get_Pragma (Id, Pragma_Max_Queue_Length));
11171 end Has_Max_Queue_Length;
11172
11173 ---------------------------------
11174 -- Has_No_Obvious_Side_Effects --
11175 ---------------------------------
11176
11177 function Has_No_Obvious_Side_Effects (N : Node_Id) return Boolean is
11178 begin
11179 -- For now handle literals, constants, and non-volatile variables and
11180 -- expressions combining these with operators or short circuit forms.
11181
11182 if Nkind (N) in N_Numeric_Or_String_Literal then
11183 return True;
11184
11185 elsif Nkind (N) = N_Character_Literal then
11186 return True;
11187
11188 elsif Nkind (N) in N_Unary_Op then
11189 return Has_No_Obvious_Side_Effects (Right_Opnd (N));
11190
11191 elsif Nkind (N) in N_Binary_Op or else Nkind (N) in N_Short_Circuit then
11192 return Has_No_Obvious_Side_Effects (Left_Opnd (N))
11193 and then
11194 Has_No_Obvious_Side_Effects (Right_Opnd (N));
11195
11196 elsif Nkind (N) = N_Expression_With_Actions
11197 and then Is_Empty_List (Actions (N))
11198 then
11199 return Has_No_Obvious_Side_Effects (Expression (N));
11200
11201 elsif Nkind (N) in N_Has_Entity then
11202 return Present (Entity (N))
11203 and then Ekind_In (Entity (N), E_Variable,
11204 E_Constant,
11205 E_Enumeration_Literal,
11206 E_In_Parameter,
11207 E_Out_Parameter,
11208 E_In_Out_Parameter)
11209 and then not Is_Volatile (Entity (N));
11210
11211 else
11212 return False;
11213 end if;
11214 end Has_No_Obvious_Side_Effects;
11215
11216 -----------------------------
11217 -- Has_Non_Null_Refinement --
11218 -----------------------------
11219
11220 function Has_Non_Null_Refinement (Id : Entity_Id) return Boolean is
11221 Constits : Elist_Id;
11222
11223 begin
11224 pragma Assert (Ekind (Id) = E_Abstract_State);
11225 Constits := Refinement_Constituents (Id);
11226
11227 -- For a refinement to be non-null, the first constituent must be
11228 -- anything other than null.
11229
11230 return
11231 Present (Constits)
11232 and then Nkind (Node (First_Elmt (Constits))) /= N_Null;
11233 end Has_Non_Null_Refinement;
11234
11235 -----------------------------
11236 -- Has_Non_Null_Statements --
11237 -----------------------------
11238
11239 function Has_Non_Null_Statements (L : List_Id) return Boolean is
11240 Node : Node_Id;
11241
11242 begin
11243 if Is_Non_Empty_List (L) then
11244 Node := First (L);
11245
11246 loop
11247 if Nkind (Node) /= N_Null_Statement then
11248 return True;
11249 end if;
11250
11251 Next (Node);
11252 exit when Node = Empty;
11253 end loop;
11254 end if;
11255
11256 return False;
11257 end Has_Non_Null_Statements;
11258
11259 ----------------------------------
11260 -- Has_Non_Trivial_Precondition --
11261 ----------------------------------
11262
11263 function Has_Non_Trivial_Precondition (Subp : Entity_Id) return Boolean is
11264 Pre : constant Node_Id := Find_Aspect (Subp, Aspect_Pre);
11265
11266 begin
11267 return
11268 Present (Pre)
11269 and then Class_Present (Pre)
11270 and then not Is_Entity_Name (Expression (Pre));
11271 end Has_Non_Trivial_Precondition;
11272
11273 -------------------
11274 -- Has_Null_Body --
11275 -------------------
11276
11277 function Has_Null_Body (Proc_Id : Entity_Id) return Boolean is
11278 Body_Id : Entity_Id;
11279 Decl : Node_Id;
11280 Spec : Node_Id;
11281 Stmt1 : Node_Id;
11282 Stmt2 : Node_Id;
11283
11284 begin
11285 Spec := Parent (Proc_Id);
11286 Decl := Parent (Spec);
11287
11288 -- Retrieve the entity of the procedure body (e.g. invariant proc).
11289
11290 if Nkind (Spec) = N_Procedure_Specification
11291 and then Nkind (Decl) = N_Subprogram_Declaration
11292 then
11293 Body_Id := Corresponding_Body (Decl);
11294
11295 -- The body acts as a spec
11296
11297 else
11298 Body_Id := Proc_Id;
11299 end if;
11300
11301 -- The body will be generated later
11302
11303 if No (Body_Id) then
11304 return False;
11305 end if;
11306
11307 Spec := Parent (Body_Id);
11308 Decl := Parent (Spec);
11309
11310 pragma Assert
11311 (Nkind (Spec) = N_Procedure_Specification
11312 and then Nkind (Decl) = N_Subprogram_Body);
11313
11314 Stmt1 := First (Statements (Handled_Statement_Sequence (Decl)));
11315
11316 -- Look for a null statement followed by an optional return
11317 -- statement.
11318
11319 if Nkind (Stmt1) = N_Null_Statement then
11320 Stmt2 := Next (Stmt1);
11321
11322 if Present (Stmt2) then
11323 return Nkind (Stmt2) = N_Simple_Return_Statement;
11324 else
11325 return True;
11326 end if;
11327 end if;
11328
11329 return False;
11330 end Has_Null_Body;
11331
11332 ------------------------
11333 -- Has_Null_Exclusion --
11334 ------------------------
11335
11336 function Has_Null_Exclusion (N : Node_Id) return Boolean is
11337 begin
11338 case Nkind (N) is
11339 when N_Access_Definition
11340 | N_Access_Function_Definition
11341 | N_Access_Procedure_Definition
11342 | N_Access_To_Object_Definition
11343 | N_Allocator
11344 | N_Derived_Type_Definition
11345 | N_Function_Specification
11346 | N_Subtype_Declaration
11347 =>
11348 return Null_Exclusion_Present (N);
11349
11350 when N_Component_Definition
11351 | N_Formal_Object_Declaration
11352 | N_Object_Renaming_Declaration
11353 =>
11354 if Present (Subtype_Mark (N)) then
11355 return Null_Exclusion_Present (N);
11356 else pragma Assert (Present (Access_Definition (N)));
11357 return Null_Exclusion_Present (Access_Definition (N));
11358 end if;
11359
11360 when N_Discriminant_Specification =>
11361 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
11362 return Null_Exclusion_Present (Discriminant_Type (N));
11363 else
11364 return Null_Exclusion_Present (N);
11365 end if;
11366
11367 when N_Object_Declaration =>
11368 if Nkind (Object_Definition (N)) = N_Access_Definition then
11369 return Null_Exclusion_Present (Object_Definition (N));
11370 else
11371 return Null_Exclusion_Present (N);
11372 end if;
11373
11374 when N_Parameter_Specification =>
11375 if Nkind (Parameter_Type (N)) = N_Access_Definition then
11376 return Null_Exclusion_Present (Parameter_Type (N));
11377 else
11378 return Null_Exclusion_Present (N);
11379 end if;
11380
11381 when others =>
11382 return False;
11383 end case;
11384 end Has_Null_Exclusion;
11385
11386 ------------------------
11387 -- Has_Null_Extension --
11388 ------------------------
11389
11390 function Has_Null_Extension (T : Entity_Id) return Boolean is
11391 B : constant Entity_Id := Base_Type (T);
11392 Comps : Node_Id;
11393 Ext : Node_Id;
11394
11395 begin
11396 if Nkind (Parent (B)) = N_Full_Type_Declaration
11397 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
11398 then
11399 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
11400
11401 if Present (Ext) then
11402 if Null_Present (Ext) then
11403 return True;
11404 else
11405 Comps := Component_List (Ext);
11406
11407 -- The null component list is rewritten during analysis to
11408 -- include the parent component. Any other component indicates
11409 -- that the extension was not originally null.
11410
11411 return Null_Present (Comps)
11412 or else No (Next (First (Component_Items (Comps))));
11413 end if;
11414 else
11415 return False;
11416 end if;
11417
11418 else
11419 return False;
11420 end if;
11421 end Has_Null_Extension;
11422
11423 -------------------------
11424 -- Has_Null_Refinement --
11425 -------------------------
11426
11427 function Has_Null_Refinement (Id : Entity_Id) return Boolean is
11428 Constits : Elist_Id;
11429
11430 begin
11431 pragma Assert (Ekind (Id) = E_Abstract_State);
11432 Constits := Refinement_Constituents (Id);
11433
11434 -- For a refinement to be null, the state's sole constituent must be a
11435 -- null.
11436
11437 return
11438 Present (Constits)
11439 and then Nkind (Node (First_Elmt (Constits))) = N_Null;
11440 end Has_Null_Refinement;
11441
11442 -------------------------------
11443 -- Has_Overriding_Initialize --
11444 -------------------------------
11445
11446 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
11447 BT : constant Entity_Id := Base_Type (T);
11448 P : Elmt_Id;
11449
11450 begin
11451 if Is_Controlled (BT) then
11452 if Is_RTU (Scope (BT), Ada_Finalization) then
11453 return False;
11454
11455 elsif Present (Primitive_Operations (BT)) then
11456 P := First_Elmt (Primitive_Operations (BT));
11457 while Present (P) loop
11458 declare
11459 Init : constant Entity_Id := Node (P);
11460 Formal : constant Entity_Id := First_Formal (Init);
11461 begin
11462 if Ekind (Init) = E_Procedure
11463 and then Chars (Init) = Name_Initialize
11464 and then Comes_From_Source (Init)
11465 and then Present (Formal)
11466 and then Etype (Formal) = BT
11467 and then No (Next_Formal (Formal))
11468 and then (Ada_Version < Ada_2012
11469 or else not Null_Present (Parent (Init)))
11470 then
11471 return True;
11472 end if;
11473 end;
11474
11475 Next_Elmt (P);
11476 end loop;
11477 end if;
11478
11479 -- Here if type itself does not have a non-null Initialize operation:
11480 -- check immediate ancestor.
11481
11482 if Is_Derived_Type (BT)
11483 and then Has_Overriding_Initialize (Etype (BT))
11484 then
11485 return True;
11486 end if;
11487 end if;
11488
11489 return False;
11490 end Has_Overriding_Initialize;
11491
11492 --------------------------------------
11493 -- Has_Preelaborable_Initialization --
11494 --------------------------------------
11495
11496 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
11497 Has_PE : Boolean;
11498
11499 procedure Check_Components (E : Entity_Id);
11500 -- Check component/discriminant chain, sets Has_PE False if a component
11501 -- or discriminant does not meet the preelaborable initialization rules.
11502
11503 ----------------------
11504 -- Check_Components --
11505 ----------------------
11506
11507 procedure Check_Components (E : Entity_Id) is
11508 Ent : Entity_Id;
11509 Exp : Node_Id;
11510
11511 begin
11512 -- Loop through entities of record or protected type
11513
11514 Ent := E;
11515 while Present (Ent) loop
11516
11517 -- We are interested only in components and discriminants
11518
11519 Exp := Empty;
11520
11521 case Ekind (Ent) is
11522 when E_Component =>
11523
11524 -- Get default expression if any. If there is no declaration
11525 -- node, it means we have an internal entity. The parent and
11526 -- tag fields are examples of such entities. For such cases,
11527 -- we just test the type of the entity.
11528
11529 if Present (Declaration_Node (Ent)) then
11530 Exp := Expression (Declaration_Node (Ent));
11531 end if;
11532
11533 when E_Discriminant =>
11534
11535 -- Note: for a renamed discriminant, the Declaration_Node
11536 -- may point to the one from the ancestor, and have a
11537 -- different expression, so use the proper attribute to
11538 -- retrieve the expression from the derived constraint.
11539
11540 Exp := Discriminant_Default_Value (Ent);
11541
11542 when others =>
11543 goto Check_Next_Entity;
11544 end case;
11545
11546 -- A component has PI if it has no default expression and the
11547 -- component type has PI.
11548
11549 if No (Exp) then
11550 if not Has_Preelaborable_Initialization (Etype (Ent)) then
11551 Has_PE := False;
11552 exit;
11553 end if;
11554
11555 -- Require the default expression to be preelaborable
11556
11557 elsif not Is_Preelaborable_Construct (Exp) then
11558 Has_PE := False;
11559 exit;
11560 end if;
11561
11562 <<Check_Next_Entity>>
11563 Next_Entity (Ent);
11564 end loop;
11565 end Check_Components;
11566
11567 -- Start of processing for Has_Preelaborable_Initialization
11568
11569 begin
11570 -- Immediate return if already marked as known preelaborable init. This
11571 -- covers types for which this function has already been called once
11572 -- and returned True (in which case the result is cached), and also
11573 -- types to which a pragma Preelaborable_Initialization applies.
11574
11575 if Known_To_Have_Preelab_Init (E) then
11576 return True;
11577 end if;
11578
11579 -- If the type is a subtype representing a generic actual type, then
11580 -- test whether its base type has preelaborable initialization since
11581 -- the subtype representing the actual does not inherit this attribute
11582 -- from the actual or formal. (but maybe it should???)
11583
11584 if Is_Generic_Actual_Type (E) then
11585 return Has_Preelaborable_Initialization (Base_Type (E));
11586 end if;
11587
11588 -- All elementary types have preelaborable initialization
11589
11590 if Is_Elementary_Type (E) then
11591 Has_PE := True;
11592
11593 -- Array types have PI if the component type has PI
11594
11595 elsif Is_Array_Type (E) then
11596 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
11597
11598 -- A derived type has preelaborable initialization if its parent type
11599 -- has preelaborable initialization and (in the case of a derived record
11600 -- extension) if the non-inherited components all have preelaborable
11601 -- initialization. However, a user-defined controlled type with an
11602 -- overriding Initialize procedure does not have preelaborable
11603 -- initialization.
11604
11605 elsif Is_Derived_Type (E) then
11606
11607 -- If the derived type is a private extension then it doesn't have
11608 -- preelaborable initialization.
11609
11610 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
11611 return False;
11612 end if;
11613
11614 -- First check whether ancestor type has preelaborable initialization
11615
11616 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
11617
11618 -- If OK, check extension components (if any)
11619
11620 if Has_PE and then Is_Record_Type (E) then
11621 Check_Components (First_Entity (E));
11622 end if;
11623
11624 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
11625 -- with a user defined Initialize procedure does not have PI. If
11626 -- the type is untagged, the control primitives come from a component
11627 -- that has already been checked.
11628
11629 if Has_PE
11630 and then Is_Controlled (E)
11631 and then Is_Tagged_Type (E)
11632 and then Has_Overriding_Initialize (E)
11633 then
11634 Has_PE := False;
11635 end if;
11636
11637 -- Private types not derived from a type having preelaborable init and
11638 -- that are not marked with pragma Preelaborable_Initialization do not
11639 -- have preelaborable initialization.
11640
11641 elsif Is_Private_Type (E) then
11642 return False;
11643
11644 -- Record type has PI if it is non private and all components have PI
11645
11646 elsif Is_Record_Type (E) then
11647 Has_PE := True;
11648 Check_Components (First_Entity (E));
11649
11650 -- Protected types must not have entries, and components must meet
11651 -- same set of rules as for record components.
11652
11653 elsif Is_Protected_Type (E) then
11654 if Has_Entries (E) then
11655 Has_PE := False;
11656 else
11657 Has_PE := True;
11658 Check_Components (First_Entity (E));
11659 Check_Components (First_Private_Entity (E));
11660 end if;
11661
11662 -- Type System.Address always has preelaborable initialization
11663
11664 elsif Is_RTE (E, RE_Address) then
11665 Has_PE := True;
11666
11667 -- In all other cases, type does not have preelaborable initialization
11668
11669 else
11670 return False;
11671 end if;
11672
11673 -- If type has preelaborable initialization, cache result
11674
11675 if Has_PE then
11676 Set_Known_To_Have_Preelab_Init (E);
11677 end if;
11678
11679 return Has_PE;
11680 end Has_Preelaborable_Initialization;
11681
11682 ----------------
11683 -- Has_Prefix --
11684 ----------------
11685
11686 function Has_Prefix (N : Node_Id) return Boolean is
11687 begin
11688 return
11689 Nkind_In (N, N_Attribute_Reference,
11690 N_Expanded_Name,
11691 N_Explicit_Dereference,
11692 N_Indexed_Component,
11693 N_Reference,
11694 N_Selected_Component,
11695 N_Slice);
11696 end Has_Prefix;
11697
11698 ---------------------------
11699 -- Has_Private_Component --
11700 ---------------------------
11701
11702 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
11703 Btype : Entity_Id := Base_Type (Type_Id);
11704 Component : Entity_Id;
11705
11706 begin
11707 if Error_Posted (Type_Id)
11708 or else Error_Posted (Btype)
11709 then
11710 return False;
11711 end if;
11712
11713 if Is_Class_Wide_Type (Btype) then
11714 Btype := Root_Type (Btype);
11715 end if;
11716
11717 if Is_Private_Type (Btype) then
11718 declare
11719 UT : constant Entity_Id := Underlying_Type (Btype);
11720 begin
11721 if No (UT) then
11722 if No (Full_View (Btype)) then
11723 return not Is_Generic_Type (Btype)
11724 and then
11725 not Is_Generic_Type (Root_Type (Btype));
11726 else
11727 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
11728 end if;
11729 else
11730 return not Is_Frozen (UT) and then Has_Private_Component (UT);
11731 end if;
11732 end;
11733
11734 elsif Is_Array_Type (Btype) then
11735 return Has_Private_Component (Component_Type (Btype));
11736
11737 elsif Is_Record_Type (Btype) then
11738 Component := First_Component (Btype);
11739 while Present (Component) loop
11740 if Has_Private_Component (Etype (Component)) then
11741 return True;
11742 end if;
11743
11744 Next_Component (Component);
11745 end loop;
11746
11747 return False;
11748
11749 elsif Is_Protected_Type (Btype)
11750 and then Present (Corresponding_Record_Type (Btype))
11751 then
11752 return Has_Private_Component (Corresponding_Record_Type (Btype));
11753
11754 else
11755 return False;
11756 end if;
11757 end Has_Private_Component;
11758
11759 ----------------------
11760 -- Has_Signed_Zeros --
11761 ----------------------
11762
11763 function Has_Signed_Zeros (E : Entity_Id) return Boolean is
11764 begin
11765 return Is_Floating_Point_Type (E) and then Signed_Zeros_On_Target;
11766 end Has_Signed_Zeros;
11767
11768 ------------------------------
11769 -- Has_Significant_Contract --
11770 ------------------------------
11771
11772 function Has_Significant_Contract (Subp_Id : Entity_Id) return Boolean is
11773 Subp_Nam : constant Name_Id := Chars (Subp_Id);
11774
11775 begin
11776 -- _Finalizer procedure
11777
11778 if Subp_Nam = Name_uFinalizer then
11779 return False;
11780
11781 -- _Postconditions procedure
11782
11783 elsif Subp_Nam = Name_uPostconditions then
11784 return False;
11785
11786 -- Predicate function
11787
11788 elsif Ekind (Subp_Id) = E_Function
11789 and then Is_Predicate_Function (Subp_Id)
11790 then
11791 return False;
11792
11793 -- TSS subprogram
11794
11795 elsif Get_TSS_Name (Subp_Id) /= TSS_Null then
11796 return False;
11797
11798 else
11799 return True;
11800 end if;
11801 end Has_Significant_Contract;
11802
11803 -----------------------------
11804 -- Has_Static_Array_Bounds --
11805 -----------------------------
11806
11807 function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is
11808 All_Static : Boolean;
11809 Dummy : Boolean;
11810
11811 begin
11812 Examine_Array_Bounds (Typ, All_Static, Dummy);
11813
11814 return All_Static;
11815 end Has_Static_Array_Bounds;
11816
11817 ---------------------------------------
11818 -- Has_Static_Non_Empty_Array_Bounds --
11819 ---------------------------------------
11820
11821 function Has_Static_Non_Empty_Array_Bounds (Typ : Node_Id) return Boolean is
11822 All_Static : Boolean;
11823 Has_Empty : Boolean;
11824
11825 begin
11826 Examine_Array_Bounds (Typ, All_Static, Has_Empty);
11827
11828 return All_Static and not Has_Empty;
11829 end Has_Static_Non_Empty_Array_Bounds;
11830
11831 ----------------
11832 -- Has_Stream --
11833 ----------------
11834
11835 function Has_Stream (T : Entity_Id) return Boolean is
11836 E : Entity_Id;
11837
11838 begin
11839 if No (T) then
11840 return False;
11841
11842 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
11843 return True;
11844
11845 elsif Is_Array_Type (T) then
11846 return Has_Stream (Component_Type (T));
11847
11848 elsif Is_Record_Type (T) then
11849 E := First_Component (T);
11850 while Present (E) loop
11851 if Has_Stream (Etype (E)) then
11852 return True;
11853 else
11854 Next_Component (E);
11855 end if;
11856 end loop;
11857
11858 return False;
11859
11860 elsif Is_Private_Type (T) then
11861 return Has_Stream (Underlying_Type (T));
11862
11863 else
11864 return False;
11865 end if;
11866 end Has_Stream;
11867
11868 ----------------
11869 -- Has_Suffix --
11870 ----------------
11871
11872 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
11873 begin
11874 Get_Name_String (Chars (E));
11875 return Name_Buffer (Name_Len) = Suffix;
11876 end Has_Suffix;
11877
11878 ----------------
11879 -- Add_Suffix --
11880 ----------------
11881
11882 function Add_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
11883 begin
11884 Get_Name_String (Chars (E));
11885 Add_Char_To_Name_Buffer (Suffix);
11886 return Name_Find;
11887 end Add_Suffix;
11888
11889 -------------------
11890 -- Remove_Suffix --
11891 -------------------
11892
11893 function Remove_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
11894 begin
11895 pragma Assert (Has_Suffix (E, Suffix));
11896 Get_Name_String (Chars (E));
11897 Name_Len := Name_Len - 1;
11898 return Name_Find;
11899 end Remove_Suffix;
11900
11901 ----------------------------------
11902 -- Replace_Null_By_Null_Address --
11903 ----------------------------------
11904
11905 procedure Replace_Null_By_Null_Address (N : Node_Id) is
11906 procedure Replace_Null_Operand (Op : Node_Id; Other_Op : Node_Id);
11907 -- Replace operand Op with a reference to Null_Address when the operand
11908 -- denotes a null Address. Other_Op denotes the other operand.
11909
11910 --------------------------
11911 -- Replace_Null_Operand --
11912 --------------------------
11913
11914 procedure Replace_Null_Operand (Op : Node_Id; Other_Op : Node_Id) is
11915 begin
11916 -- Check the type of the complementary operand since the N_Null node
11917 -- has not been decorated yet.
11918
11919 if Nkind (Op) = N_Null
11920 and then Is_Descendant_Of_Address (Etype (Other_Op))
11921 then
11922 Rewrite (Op, New_Occurrence_Of (RTE (RE_Null_Address), Sloc (Op)));
11923 end if;
11924 end Replace_Null_Operand;
11925
11926 -- Start of processing for Replace_Null_By_Null_Address
11927
11928 begin
11929 pragma Assert (Relaxed_RM_Semantics);
11930 pragma Assert (Nkind_In (N, N_Null,
11931 N_Op_Eq,
11932 N_Op_Ge,
11933 N_Op_Gt,
11934 N_Op_Le,
11935 N_Op_Lt,
11936 N_Op_Ne));
11937
11938 if Nkind (N) = N_Null then
11939 Rewrite (N, New_Occurrence_Of (RTE (RE_Null_Address), Sloc (N)));
11940
11941 else
11942 declare
11943 L : constant Node_Id := Left_Opnd (N);
11944 R : constant Node_Id := Right_Opnd (N);
11945
11946 begin
11947 Replace_Null_Operand (L, Other_Op => R);
11948 Replace_Null_Operand (R, Other_Op => L);
11949 end;
11950 end if;
11951 end Replace_Null_By_Null_Address;
11952
11953 --------------------------
11954 -- Has_Tagged_Component --
11955 --------------------------
11956
11957 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
11958 Comp : Entity_Id;
11959
11960 begin
11961 if Is_Private_Type (Typ) and then Present (Underlying_Type (Typ)) then
11962 return Has_Tagged_Component (Underlying_Type (Typ));
11963
11964 elsif Is_Array_Type (Typ) then
11965 return Has_Tagged_Component (Component_Type (Typ));
11966
11967 elsif Is_Tagged_Type (Typ) then
11968 return True;
11969
11970 elsif Is_Record_Type (Typ) then
11971 Comp := First_Component (Typ);
11972 while Present (Comp) loop
11973 if Has_Tagged_Component (Etype (Comp)) then
11974 return True;
11975 end if;
11976
11977 Next_Component (Comp);
11978 end loop;
11979
11980 return False;
11981
11982 else
11983 return False;
11984 end if;
11985 end Has_Tagged_Component;
11986
11987 -----------------------------
11988 -- Has_Undefined_Reference --
11989 -----------------------------
11990
11991 function Has_Undefined_Reference (Expr : Node_Id) return Boolean is
11992 Has_Undef_Ref : Boolean := False;
11993 -- Flag set when expression Expr contains at least one undefined
11994 -- reference.
11995
11996 function Is_Undefined_Reference (N : Node_Id) return Traverse_Result;
11997 -- Determine whether N denotes a reference and if it does, whether it is
11998 -- undefined.
11999
12000 ----------------------------
12001 -- Is_Undefined_Reference --
12002 ----------------------------
12003
12004 function Is_Undefined_Reference (N : Node_Id) return Traverse_Result is
12005 begin
12006 if Is_Entity_Name (N)
12007 and then Present (Entity (N))
12008 and then Entity (N) = Any_Id
12009 then
12010 Has_Undef_Ref := True;
12011 return Abandon;
12012 end if;
12013
12014 return OK;
12015 end Is_Undefined_Reference;
12016
12017 procedure Find_Undefined_References is
12018 new Traverse_Proc (Is_Undefined_Reference);
12019
12020 -- Start of processing for Has_Undefined_Reference
12021
12022 begin
12023 Find_Undefined_References (Expr);
12024
12025 return Has_Undef_Ref;
12026 end Has_Undefined_Reference;
12027
12028 ----------------------------
12029 -- Has_Volatile_Component --
12030 ----------------------------
12031
12032 function Has_Volatile_Component (Typ : Entity_Id) return Boolean is
12033 Comp : Entity_Id;
12034
12035 begin
12036 if Has_Volatile_Components (Typ) then
12037 return True;
12038
12039 elsif Is_Array_Type (Typ) then
12040 return Is_Volatile (Component_Type (Typ));
12041
12042 elsif Is_Record_Type (Typ) then
12043 Comp := First_Component (Typ);
12044 while Present (Comp) loop
12045 if Is_Volatile_Object (Comp) then
12046 return True;
12047 end if;
12048
12049 Comp := Next_Component (Comp);
12050 end loop;
12051 end if;
12052
12053 return False;
12054 end Has_Volatile_Component;
12055
12056 -------------------------
12057 -- Implementation_Kind --
12058 -------------------------
12059
12060 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
12061 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
12062 Arg : Node_Id;
12063 begin
12064 pragma Assert (Present (Impl_Prag));
12065 Arg := Last (Pragma_Argument_Associations (Impl_Prag));
12066 return Chars (Get_Pragma_Arg (Arg));
12067 end Implementation_Kind;
12068
12069 --------------------------
12070 -- Implements_Interface --
12071 --------------------------
12072
12073 function Implements_Interface
12074 (Typ_Ent : Entity_Id;
12075 Iface_Ent : Entity_Id;
12076 Exclude_Parents : Boolean := False) return Boolean
12077 is
12078 Ifaces_List : Elist_Id;
12079 Elmt : Elmt_Id;
12080 Iface : Entity_Id := Base_Type (Iface_Ent);
12081 Typ : Entity_Id := Base_Type (Typ_Ent);
12082
12083 begin
12084 if Is_Class_Wide_Type (Typ) then
12085 Typ := Root_Type (Typ);
12086 end if;
12087
12088 if not Has_Interfaces (Typ) then
12089 return False;
12090 end if;
12091
12092 if Is_Class_Wide_Type (Iface) then
12093 Iface := Root_Type (Iface);
12094 end if;
12095
12096 Collect_Interfaces (Typ, Ifaces_List);
12097
12098 Elmt := First_Elmt (Ifaces_List);
12099 while Present (Elmt) loop
12100 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
12101 and then Exclude_Parents
12102 then
12103 null;
12104
12105 elsif Node (Elmt) = Iface then
12106 return True;
12107 end if;
12108
12109 Next_Elmt (Elmt);
12110 end loop;
12111
12112 return False;
12113 end Implements_Interface;
12114
12115 ------------------------------------
12116 -- In_Assertion_Expression_Pragma --
12117 ------------------------------------
12118
12119 function In_Assertion_Expression_Pragma (N : Node_Id) return Boolean is
12120 Par : Node_Id;
12121 Prag : Node_Id := Empty;
12122
12123 begin
12124 -- Climb the parent chain looking for an enclosing pragma
12125
12126 Par := N;
12127 while Present (Par) loop
12128 if Nkind (Par) = N_Pragma then
12129 Prag := Par;
12130 exit;
12131
12132 -- Precondition-like pragmas are expanded into if statements, check
12133 -- the original node instead.
12134
12135 elsif Nkind (Original_Node (Par)) = N_Pragma then
12136 Prag := Original_Node (Par);
12137 exit;
12138
12139 -- The expansion of attribute 'Old generates a constant to capture
12140 -- the result of the prefix. If the parent traversal reaches
12141 -- one of these constants, then the node technically came from a
12142 -- postcondition-like pragma. Note that the Ekind is not tested here
12143 -- because N may be the expression of an object declaration which is
12144 -- currently being analyzed. Such objects carry Ekind of E_Void.
12145
12146 elsif Nkind (Par) = N_Object_Declaration
12147 and then Constant_Present (Par)
12148 and then Stores_Attribute_Old_Prefix (Defining_Entity (Par))
12149 then
12150 return True;
12151
12152 -- Prevent the search from going too far
12153
12154 elsif Is_Body_Or_Package_Declaration (Par) then
12155 return False;
12156 end if;
12157
12158 Par := Parent (Par);
12159 end loop;
12160
12161 return
12162 Present (Prag)
12163 and then Assertion_Expression_Pragma (Get_Pragma_Id (Prag));
12164 end In_Assertion_Expression_Pragma;
12165
12166 ----------------------
12167 -- In_Generic_Scope --
12168 ----------------------
12169
12170 function In_Generic_Scope (E : Entity_Id) return Boolean is
12171 S : Entity_Id;
12172
12173 begin
12174 S := Scope (E);
12175 while Present (S) and then S /= Standard_Standard loop
12176 if Is_Generic_Unit (S) then
12177 return True;
12178 end if;
12179
12180 S := Scope (S);
12181 end loop;
12182
12183 return False;
12184 end In_Generic_Scope;
12185
12186 -----------------
12187 -- In_Instance --
12188 -----------------
12189
12190 function In_Instance return Boolean is
12191 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
12192 S : Entity_Id;
12193
12194 begin
12195 S := Current_Scope;
12196 while Present (S) and then S /= Standard_Standard loop
12197 if Is_Generic_Instance (S) then
12198
12199 -- A child instance is always compiled in the context of a parent
12200 -- instance. Nevertheless, the actuals are not analyzed in an
12201 -- instance context. We detect this case by examining the current
12202 -- compilation unit, which must be a child instance, and checking
12203 -- that it is not currently on the scope stack.
12204
12205 if Is_Child_Unit (Curr_Unit)
12206 and then Nkind (Unit (Cunit (Current_Sem_Unit))) =
12207 N_Package_Instantiation
12208 and then not In_Open_Scopes (Curr_Unit)
12209 then
12210 return False;
12211 else
12212 return True;
12213 end if;
12214 end if;
12215
12216 S := Scope (S);
12217 end loop;
12218
12219 return False;
12220 end In_Instance;
12221
12222 ----------------------
12223 -- In_Instance_Body --
12224 ----------------------
12225
12226 function In_Instance_Body return Boolean is
12227 S : Entity_Id;
12228
12229 begin
12230 S := Current_Scope;
12231 while Present (S) and then S /= Standard_Standard loop
12232 if Ekind_In (S, E_Function, E_Procedure)
12233 and then Is_Generic_Instance (S)
12234 then
12235 return True;
12236
12237 elsif Ekind (S) = E_Package
12238 and then In_Package_Body (S)
12239 and then Is_Generic_Instance (S)
12240 then
12241 return True;
12242 end if;
12243
12244 S := Scope (S);
12245 end loop;
12246
12247 return False;
12248 end In_Instance_Body;
12249
12250 -----------------------------
12251 -- In_Instance_Not_Visible --
12252 -----------------------------
12253
12254 function In_Instance_Not_Visible return Boolean is
12255 S : Entity_Id;
12256
12257 begin
12258 S := Current_Scope;
12259 while Present (S) and then S /= Standard_Standard loop
12260 if Ekind_In (S, E_Function, E_Procedure)
12261 and then Is_Generic_Instance (S)
12262 then
12263 return True;
12264
12265 elsif Ekind (S) = E_Package
12266 and then (In_Package_Body (S) or else In_Private_Part (S))
12267 and then Is_Generic_Instance (S)
12268 then
12269 return True;
12270 end if;
12271
12272 S := Scope (S);
12273 end loop;
12274
12275 return False;
12276 end In_Instance_Not_Visible;
12277
12278 ------------------------------
12279 -- In_Instance_Visible_Part --
12280 ------------------------------
12281
12282 function In_Instance_Visible_Part
12283 (Id : Entity_Id := Current_Scope) return Boolean
12284 is
12285 Inst : Entity_Id;
12286
12287 begin
12288 Inst := Id;
12289 while Present (Inst) and then Inst /= Standard_Standard loop
12290 if Ekind (Inst) = E_Package
12291 and then Is_Generic_Instance (Inst)
12292 and then not In_Package_Body (Inst)
12293 and then not In_Private_Part (Inst)
12294 then
12295 return True;
12296 end if;
12297
12298 Inst := Scope (Inst);
12299 end loop;
12300
12301 return False;
12302 end In_Instance_Visible_Part;
12303
12304 ---------------------
12305 -- In_Package_Body --
12306 ---------------------
12307
12308 function In_Package_Body return Boolean is
12309 S : Entity_Id;
12310
12311 begin
12312 S := Current_Scope;
12313 while Present (S) and then S /= Standard_Standard loop
12314 if Ekind (S) = E_Package and then In_Package_Body (S) then
12315 return True;
12316 else
12317 S := Scope (S);
12318 end if;
12319 end loop;
12320
12321 return False;
12322 end In_Package_Body;
12323
12324 --------------------------
12325 -- In_Pragma_Expression --
12326 --------------------------
12327
12328 function In_Pragma_Expression (N : Node_Id; Nam : Name_Id) return Boolean is
12329 P : Node_Id;
12330 begin
12331 P := Parent (N);
12332 loop
12333 if No (P) then
12334 return False;
12335 elsif Nkind (P) = N_Pragma and then Pragma_Name (P) = Nam then
12336 return True;
12337 else
12338 P := Parent (P);
12339 end if;
12340 end loop;
12341 end In_Pragma_Expression;
12342
12343 ---------------------------
12344 -- In_Pre_Post_Condition --
12345 ---------------------------
12346
12347 function In_Pre_Post_Condition (N : Node_Id) return Boolean is
12348 Par : Node_Id;
12349 Prag : Node_Id := Empty;
12350 Prag_Id : Pragma_Id;
12351
12352 begin
12353 -- Climb the parent chain looking for an enclosing pragma
12354
12355 Par := N;
12356 while Present (Par) loop
12357 if Nkind (Par) = N_Pragma then
12358 Prag := Par;
12359 exit;
12360
12361 -- Prevent the search from going too far
12362
12363 elsif Is_Body_Or_Package_Declaration (Par) then
12364 exit;
12365 end if;
12366
12367 Par := Parent (Par);
12368 end loop;
12369
12370 if Present (Prag) then
12371 Prag_Id := Get_Pragma_Id (Prag);
12372
12373 return
12374 Prag_Id = Pragma_Post
12375 or else Prag_Id = Pragma_Post_Class
12376 or else Prag_Id = Pragma_Postcondition
12377 or else Prag_Id = Pragma_Pre
12378 or else Prag_Id = Pragma_Pre_Class
12379 or else Prag_Id = Pragma_Precondition;
12380
12381 -- Otherwise the node is not enclosed by a pre/postcondition pragma
12382
12383 else
12384 return False;
12385 end if;
12386 end In_Pre_Post_Condition;
12387
12388 ------------------------------
12389 -- In_Quantified_Expression --
12390 ------------------------------
12391
12392 function In_Quantified_Expression (N : Node_Id) return Boolean is
12393 P : Node_Id;
12394 begin
12395 P := Parent (N);
12396 loop
12397 if No (P) then
12398 return False;
12399 elsif Nkind (P) = N_Quantified_Expression then
12400 return True;
12401 else
12402 P := Parent (P);
12403 end if;
12404 end loop;
12405 end In_Quantified_Expression;
12406
12407 -------------------------------------
12408 -- In_Reverse_Storage_Order_Object --
12409 -------------------------------------
12410
12411 function In_Reverse_Storage_Order_Object (N : Node_Id) return Boolean is
12412 Pref : Node_Id;
12413 Btyp : Entity_Id := Empty;
12414
12415 begin
12416 -- Climb up indexed components
12417
12418 Pref := N;
12419 loop
12420 case Nkind (Pref) is
12421 when N_Selected_Component =>
12422 Pref := Prefix (Pref);
12423 exit;
12424
12425 when N_Indexed_Component =>
12426 Pref := Prefix (Pref);
12427
12428 when others =>
12429 Pref := Empty;
12430 exit;
12431 end case;
12432 end loop;
12433
12434 if Present (Pref) then
12435 Btyp := Base_Type (Etype (Pref));
12436 end if;
12437
12438 return Present (Btyp)
12439 and then (Is_Record_Type (Btyp) or else Is_Array_Type (Btyp))
12440 and then Reverse_Storage_Order (Btyp);
12441 end In_Reverse_Storage_Order_Object;
12442
12443 ------------------------------
12444 -- In_Same_Declarative_Part --
12445 ------------------------------
12446
12447 function In_Same_Declarative_Part
12448 (Context : Node_Id;
12449 N : Node_Id) return Boolean
12450 is
12451 Cont : Node_Id := Context;
12452 Nod : Node_Id;
12453
12454 begin
12455 if Nkind (Cont) = N_Compilation_Unit_Aux then
12456 Cont := Parent (Cont);
12457 end if;
12458
12459 Nod := Parent (N);
12460 while Present (Nod) loop
12461 if Nod = Cont then
12462 return True;
12463
12464 elsif Nkind_In (Nod, N_Accept_Statement,
12465 N_Block_Statement,
12466 N_Compilation_Unit,
12467 N_Entry_Body,
12468 N_Package_Body,
12469 N_Package_Declaration,
12470 N_Protected_Body,
12471 N_Subprogram_Body,
12472 N_Task_Body)
12473 then
12474 return False;
12475
12476 elsif Nkind (Nod) = N_Subunit then
12477 Nod := Corresponding_Stub (Nod);
12478
12479 else
12480 Nod := Parent (Nod);
12481 end if;
12482 end loop;
12483
12484 return False;
12485 end In_Same_Declarative_Part;
12486
12487 --------------------------------------
12488 -- In_Subprogram_Or_Concurrent_Unit --
12489 --------------------------------------
12490
12491 function In_Subprogram_Or_Concurrent_Unit return Boolean is
12492 E : Entity_Id;
12493 K : Entity_Kind;
12494
12495 begin
12496 -- Use scope chain to check successively outer scopes
12497
12498 E := Current_Scope;
12499 loop
12500 K := Ekind (E);
12501
12502 if K in Subprogram_Kind
12503 or else K in Concurrent_Kind
12504 or else K in Generic_Subprogram_Kind
12505 then
12506 return True;
12507
12508 elsif E = Standard_Standard then
12509 return False;
12510 end if;
12511
12512 E := Scope (E);
12513 end loop;
12514 end In_Subprogram_Or_Concurrent_Unit;
12515
12516 ----------------
12517 -- In_Subtree --
12518 ----------------
12519
12520 function In_Subtree (N : Node_Id; Root : Node_Id) return Boolean is
12521 Curr : Node_Id;
12522
12523 begin
12524 Curr := N;
12525 while Present (Curr) loop
12526 if Curr = Root then
12527 return True;
12528 end if;
12529
12530 Curr := Parent (Curr);
12531 end loop;
12532
12533 return False;
12534 end In_Subtree;
12535
12536 ----------------
12537 -- In_Subtree --
12538 ----------------
12539
12540 function In_Subtree
12541 (N : Node_Id;
12542 Root1 : Node_Id;
12543 Root2 : Node_Id) return Boolean
12544 is
12545 Curr : Node_Id;
12546
12547 begin
12548 Curr := N;
12549 while Present (Curr) loop
12550 if Curr = Root1 or else Curr = Root2 then
12551 return True;
12552 end if;
12553
12554 Curr := Parent (Curr);
12555 end loop;
12556
12557 return False;
12558 end In_Subtree;
12559
12560 ---------------------
12561 -- In_Visible_Part --
12562 ---------------------
12563
12564 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
12565 begin
12566 return Is_Package_Or_Generic_Package (Scope_Id)
12567 and then In_Open_Scopes (Scope_Id)
12568 and then not In_Package_Body (Scope_Id)
12569 and then not In_Private_Part (Scope_Id);
12570 end In_Visible_Part;
12571
12572 --------------------------------
12573 -- Incomplete_Or_Partial_View --
12574 --------------------------------
12575
12576 function Incomplete_Or_Partial_View (Id : Entity_Id) return Entity_Id is
12577 function Inspect_Decls
12578 (Decls : List_Id;
12579 Taft : Boolean := False) return Entity_Id;
12580 -- Check whether a declarative region contains the incomplete or partial
12581 -- view of Id.
12582
12583 -------------------
12584 -- Inspect_Decls --
12585 -------------------
12586
12587 function Inspect_Decls
12588 (Decls : List_Id;
12589 Taft : Boolean := False) return Entity_Id
12590 is
12591 Decl : Node_Id;
12592 Match : Node_Id;
12593
12594 begin
12595 Decl := First (Decls);
12596 while Present (Decl) loop
12597 Match := Empty;
12598
12599 -- The partial view of a Taft-amendment type is an incomplete
12600 -- type.
12601
12602 if Taft then
12603 if Nkind (Decl) = N_Incomplete_Type_Declaration then
12604 Match := Defining_Identifier (Decl);
12605 end if;
12606
12607 -- Otherwise look for a private type whose full view matches the
12608 -- input type. Note that this checks full_type_declaration nodes
12609 -- to account for derivations from a private type where the type
12610 -- declaration hold the partial view and the full view is an
12611 -- itype.
12612
12613 elsif Nkind_In (Decl, N_Full_Type_Declaration,
12614 N_Private_Extension_Declaration,
12615 N_Private_Type_Declaration)
12616 then
12617 Match := Defining_Identifier (Decl);
12618 end if;
12619
12620 -- Guard against unanalyzed entities
12621
12622 if Present (Match)
12623 and then Is_Type (Match)
12624 and then Present (Full_View (Match))
12625 and then Full_View (Match) = Id
12626 then
12627 return Match;
12628 end if;
12629
12630 Next (Decl);
12631 end loop;
12632
12633 return Empty;
12634 end Inspect_Decls;
12635
12636 -- Local variables
12637
12638 Prev : Entity_Id;
12639
12640 -- Start of processing for Incomplete_Or_Partial_View
12641
12642 begin
12643 -- Deferred constant or incomplete type case
12644
12645 Prev := Current_Entity_In_Scope (Id);
12646
12647 if Present (Prev)
12648 and then (Is_Incomplete_Type (Prev) or else Ekind (Prev) = E_Constant)
12649 and then Present (Full_View (Prev))
12650 and then Full_View (Prev) = Id
12651 then
12652 return Prev;
12653 end if;
12654
12655 -- Private or Taft amendment type case
12656
12657 declare
12658 Pkg : constant Entity_Id := Scope (Id);
12659 Pkg_Decl : Node_Id := Pkg;
12660
12661 begin
12662 if Present (Pkg)
12663 and then Ekind_In (Pkg, E_Generic_Package, E_Package)
12664 then
12665 while Nkind (Pkg_Decl) /= N_Package_Specification loop
12666 Pkg_Decl := Parent (Pkg_Decl);
12667 end loop;
12668
12669 -- It is knows that Typ has a private view, look for it in the
12670 -- visible declarations of the enclosing scope. A special case
12671 -- of this is when the two views have been exchanged - the full
12672 -- appears earlier than the private.
12673
12674 if Has_Private_Declaration (Id) then
12675 Prev := Inspect_Decls (Visible_Declarations (Pkg_Decl));
12676
12677 -- Exchanged view case, look in the private declarations
12678
12679 if No (Prev) then
12680 Prev := Inspect_Decls (Private_Declarations (Pkg_Decl));
12681 end if;
12682
12683 return Prev;
12684
12685 -- Otherwise if this is the package body, then Typ is a potential
12686 -- Taft amendment type. The incomplete view should be located in
12687 -- the private declarations of the enclosing scope.
12688
12689 elsif In_Package_Body (Pkg) then
12690 return Inspect_Decls (Private_Declarations (Pkg_Decl), True);
12691 end if;
12692 end if;
12693 end;
12694
12695 -- The type has no incomplete or private view
12696
12697 return Empty;
12698 end Incomplete_Or_Partial_View;
12699
12700 ---------------------------------------
12701 -- Incomplete_View_From_Limited_With --
12702 ---------------------------------------
12703
12704 function Incomplete_View_From_Limited_With
12705 (Typ : Entity_Id) return Entity_Id
12706 is
12707 begin
12708 -- It might make sense to make this an attribute in Einfo, and set it
12709 -- in Sem_Ch10 in Build_Shadow_Entity. However, we're running short on
12710 -- slots for new attributes, and it seems a bit simpler to just search
12711 -- the Limited_View (if it exists) for an incomplete type whose
12712 -- Non_Limited_View is Typ.
12713
12714 if Ekind (Scope (Typ)) = E_Package
12715 and then Present (Limited_View (Scope (Typ)))
12716 then
12717 declare
12718 Ent : Entity_Id := First_Entity (Limited_View (Scope (Typ)));
12719 begin
12720 while Present (Ent) loop
12721 if Ekind (Ent) in Incomplete_Kind
12722 and then Non_Limited_View (Ent) = Typ
12723 then
12724 return Ent;
12725 end if;
12726
12727 Ent := Next_Entity (Ent);
12728 end loop;
12729 end;
12730 end if;
12731
12732 return Typ;
12733 end Incomplete_View_From_Limited_With;
12734
12735 ----------------------------------
12736 -- Indexed_Component_Bit_Offset --
12737 ----------------------------------
12738
12739 function Indexed_Component_Bit_Offset (N : Node_Id) return Uint is
12740 Exp : constant Node_Id := First (Expressions (N));
12741 Typ : constant Entity_Id := Etype (Prefix (N));
12742 Off : constant Uint := Component_Size (Typ);
12743 Ind : Node_Id;
12744
12745 begin
12746 -- Return early if the component size is not known or variable
12747
12748 if Off = No_Uint or else Off < Uint_0 then
12749 return No_Uint;
12750 end if;
12751
12752 -- Deal with the degenerate case of an empty component
12753
12754 if Off = Uint_0 then
12755 return Off;
12756 end if;
12757
12758 -- Check that both the index value and the low bound are known
12759
12760 if not Compile_Time_Known_Value (Exp) then
12761 return No_Uint;
12762 end if;
12763
12764 Ind := First_Index (Typ);
12765 if No (Ind) then
12766 return No_Uint;
12767 end if;
12768
12769 if Nkind (Ind) = N_Subtype_Indication then
12770 Ind := Constraint (Ind);
12771
12772 if Nkind (Ind) = N_Range_Constraint then
12773 Ind := Range_Expression (Ind);
12774 end if;
12775 end if;
12776
12777 if Nkind (Ind) /= N_Range
12778 or else not Compile_Time_Known_Value (Low_Bound (Ind))
12779 then
12780 return No_Uint;
12781 end if;
12782
12783 -- Return the scaled offset
12784
12785 return Off * (Expr_Value (Exp) - Expr_Value (Low_Bound ((Ind))));
12786 end Indexed_Component_Bit_Offset;
12787
12788 ----------------------------
12789 -- Inherit_Rep_Item_Chain --
12790 ----------------------------
12791
12792 procedure Inherit_Rep_Item_Chain (Typ : Entity_Id; From_Typ : Entity_Id) is
12793 Item : Node_Id;
12794 Next_Item : Node_Id;
12795
12796 begin
12797 -- There are several inheritance scenarios to consider depending on
12798 -- whether both types have rep item chains and whether the destination
12799 -- type already inherits part of the source type's rep item chain.
12800
12801 -- 1) The source type lacks a rep item chain
12802 -- From_Typ ---> Empty
12803 --
12804 -- Typ --------> Item (or Empty)
12805
12806 -- In this case inheritance cannot take place because there are no items
12807 -- to inherit.
12808
12809 -- 2) The destination type lacks a rep item chain
12810 -- From_Typ ---> Item ---> ...
12811 --
12812 -- Typ --------> Empty
12813
12814 -- Inheritance takes place by setting the First_Rep_Item of the
12815 -- destination type to the First_Rep_Item of the source type.
12816 -- From_Typ ---> Item ---> ...
12817 -- ^
12818 -- Typ -----------+
12819
12820 -- 3.1) Both source and destination types have at least one rep item.
12821 -- The destination type does NOT inherit a rep item from the source
12822 -- type.
12823 -- From_Typ ---> Item ---> Item
12824 --
12825 -- Typ --------> Item ---> Item
12826
12827 -- Inheritance takes place by setting the Next_Rep_Item of the last item
12828 -- of the destination type to the First_Rep_Item of the source type.
12829 -- From_Typ -------------------> Item ---> Item
12830 -- ^
12831 -- Typ --------> Item ---> Item --+
12832
12833 -- 3.2) Both source and destination types have at least one rep item.
12834 -- The destination type DOES inherit part of the rep item chain of the
12835 -- source type.
12836 -- From_Typ ---> Item ---> Item ---> Item
12837 -- ^
12838 -- Typ --------> Item ------+
12839
12840 -- This rare case arises when the full view of a private extension must
12841 -- inherit the rep item chain from the full view of its parent type and
12842 -- the full view of the parent type contains extra rep items. Currently
12843 -- only invariants may lead to such form of inheritance.
12844
12845 -- type From_Typ is tagged private
12846 -- with Type_Invariant'Class => Item_2;
12847
12848 -- type Typ is new From_Typ with private
12849 -- with Type_Invariant => Item_4;
12850
12851 -- At this point the rep item chains contain the following items
12852
12853 -- From_Typ -----------> Item_2 ---> Item_3
12854 -- ^
12855 -- Typ --------> Item_4 --+
12856
12857 -- The full views of both types may introduce extra invariants
12858
12859 -- type From_Typ is tagged null record
12860 -- with Type_Invariant => Item_1;
12861
12862 -- type Typ is new From_Typ with null record;
12863
12864 -- The full view of Typ would have to inherit any new rep items added to
12865 -- the full view of From_Typ.
12866
12867 -- From_Typ -----------> Item_1 ---> Item_2 ---> Item_3
12868 -- ^
12869 -- Typ --------> Item_4 --+
12870
12871 -- To achieve this form of inheritance, the destination type must first
12872 -- sever the link between its own rep chain and that of the source type,
12873 -- then inheritance 3.1 takes place.
12874
12875 -- Case 1: The source type lacks a rep item chain
12876
12877 if No (First_Rep_Item (From_Typ)) then
12878 return;
12879
12880 -- Case 2: The destination type lacks a rep item chain
12881
12882 elsif No (First_Rep_Item (Typ)) then
12883 Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ));
12884
12885 -- Case 3: Both the source and destination types have at least one rep
12886 -- item. Traverse the rep item chain of the destination type to find the
12887 -- last rep item.
12888
12889 else
12890 Item := Empty;
12891 Next_Item := First_Rep_Item (Typ);
12892 while Present (Next_Item) loop
12893
12894 -- Detect a link between the destination type's rep chain and that
12895 -- of the source type. There are two possibilities:
12896
12897 -- Variant 1
12898 -- Next_Item
12899 -- V
12900 -- From_Typ ---> Item_1 --->
12901 -- ^
12902 -- Typ -----------+
12903 --
12904 -- Item is Empty
12905
12906 -- Variant 2
12907 -- Next_Item
12908 -- V
12909 -- From_Typ ---> Item_1 ---> Item_2 --->
12910 -- ^
12911 -- Typ --------> Item_3 ------+
12912 -- ^
12913 -- Item
12914
12915 if Has_Rep_Item (From_Typ, Next_Item) then
12916 exit;
12917 end if;
12918
12919 Item := Next_Item;
12920 Next_Item := Next_Rep_Item (Next_Item);
12921 end loop;
12922
12923 -- Inherit the source type's rep item chain
12924
12925 if Present (Item) then
12926 Set_Next_Rep_Item (Item, First_Rep_Item (From_Typ));
12927 else
12928 Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ));
12929 end if;
12930 end if;
12931 end Inherit_Rep_Item_Chain;
12932
12933 ------------------------------------
12934 -- Inherits_From_Tagged_Full_View --
12935 ------------------------------------
12936
12937 function Inherits_From_Tagged_Full_View (Typ : Entity_Id) return Boolean is
12938 begin
12939 return Is_Private_Type (Typ)
12940 and then Present (Full_View (Typ))
12941 and then Is_Private_Type (Full_View (Typ))
12942 and then not Is_Tagged_Type (Full_View (Typ))
12943 and then Present (Underlying_Type (Full_View (Typ)))
12944 and then Is_Tagged_Type (Underlying_Type (Full_View (Typ)));
12945 end Inherits_From_Tagged_Full_View;
12946
12947 ---------------------------------
12948 -- Insert_Explicit_Dereference --
12949 ---------------------------------
12950
12951 procedure Insert_Explicit_Dereference (N : Node_Id) is
12952 New_Prefix : constant Node_Id := Relocate_Node (N);
12953 Ent : Entity_Id := Empty;
12954 Pref : Node_Id;
12955 I : Interp_Index;
12956 It : Interp;
12957 T : Entity_Id;
12958
12959 begin
12960 Save_Interps (N, New_Prefix);
12961
12962 Rewrite (N,
12963 Make_Explicit_Dereference (Sloc (Parent (N)),
12964 Prefix => New_Prefix));
12965
12966 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
12967
12968 if Is_Overloaded (New_Prefix) then
12969
12970 -- The dereference is also overloaded, and its interpretations are
12971 -- the designated types of the interpretations of the original node.
12972
12973 Set_Etype (N, Any_Type);
12974
12975 Get_First_Interp (New_Prefix, I, It);
12976 while Present (It.Nam) loop
12977 T := It.Typ;
12978
12979 if Is_Access_Type (T) then
12980 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
12981 end if;
12982
12983 Get_Next_Interp (I, It);
12984 end loop;
12985
12986 End_Interp_List;
12987
12988 else
12989 -- Prefix is unambiguous: mark the original prefix (which might
12990 -- Come_From_Source) as a reference, since the new (relocated) one
12991 -- won't be taken into account.
12992
12993 if Is_Entity_Name (New_Prefix) then
12994 Ent := Entity (New_Prefix);
12995 Pref := New_Prefix;
12996
12997 -- For a retrieval of a subcomponent of some composite object,
12998 -- retrieve the ultimate entity if there is one.
12999
13000 elsif Nkind_In (New_Prefix, N_Selected_Component,
13001 N_Indexed_Component)
13002 then
13003 Pref := Prefix (New_Prefix);
13004 while Present (Pref)
13005 and then Nkind_In (Pref, N_Selected_Component,
13006 N_Indexed_Component)
13007 loop
13008 Pref := Prefix (Pref);
13009 end loop;
13010
13011 if Present (Pref) and then Is_Entity_Name (Pref) then
13012 Ent := Entity (Pref);
13013 end if;
13014 end if;
13015
13016 -- Place the reference on the entity node
13017
13018 if Present (Ent) then
13019 Generate_Reference (Ent, Pref);
13020 end if;
13021 end if;
13022 end Insert_Explicit_Dereference;
13023
13024 ------------------------------------------
13025 -- Inspect_Deferred_Constant_Completion --
13026 ------------------------------------------
13027
13028 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
13029 Decl : Node_Id;
13030
13031 begin
13032 Decl := First (Decls);
13033 while Present (Decl) loop
13034
13035 -- Deferred constant signature
13036
13037 if Nkind (Decl) = N_Object_Declaration
13038 and then Constant_Present (Decl)
13039 and then No (Expression (Decl))
13040
13041 -- No need to check internally generated constants
13042
13043 and then Comes_From_Source (Decl)
13044
13045 -- The constant is not completed. A full object declaration or a
13046 -- pragma Import complete a deferred constant.
13047
13048 and then not Has_Completion (Defining_Identifier (Decl))
13049 then
13050 Error_Msg_N
13051 ("constant declaration requires initialization expression",
13052 Defining_Identifier (Decl));
13053 end if;
13054
13055 Decl := Next (Decl);
13056 end loop;
13057 end Inspect_Deferred_Constant_Completion;
13058
13059 -------------------------------
13060 -- Install_Elaboration_Model --
13061 -------------------------------
13062
13063 procedure Install_Elaboration_Model (Unit_Id : Entity_Id) is
13064 function Find_Elaboration_Checks_Pragma (L : List_Id) return Node_Id;
13065 -- Try to find pragma Elaboration_Checks in arbitrary list L. Return
13066 -- Empty if there is no such pragma.
13067
13068 ------------------------------------
13069 -- Find_Elaboration_Checks_Pragma --
13070 ------------------------------------
13071
13072 function Find_Elaboration_Checks_Pragma (L : List_Id) return Node_Id is
13073 Item : Node_Id;
13074
13075 begin
13076 Item := First (L);
13077 while Present (Item) loop
13078 if Nkind (Item) = N_Pragma
13079 and then Pragma_Name (Item) = Name_Elaboration_Checks
13080 then
13081 return Item;
13082 end if;
13083
13084 Next (Item);
13085 end loop;
13086
13087 return Empty;
13088 end Find_Elaboration_Checks_Pragma;
13089
13090 -- Local variables
13091
13092 Args : List_Id;
13093 Model : Node_Id;
13094 Prag : Node_Id;
13095 Unit : Node_Id;
13096
13097 -- Start of processing for Install_Elaboration_Model
13098
13099 begin
13100 -- Nothing to do when the unit does not exist
13101
13102 if No (Unit_Id) then
13103 return;
13104 end if;
13105
13106 Unit := Parent (Unit_Declaration_Node (Unit_Id));
13107
13108 -- Nothing to do when the unit is not a library unit
13109
13110 if Nkind (Unit) /= N_Compilation_Unit then
13111 return;
13112 end if;
13113
13114 Prag := Find_Elaboration_Checks_Pragma (Context_Items (Unit));
13115
13116 -- The compilation unit is subject to pragma Elaboration_Checks. Set the
13117 -- elaboration model as specified by the pragma.
13118
13119 if Present (Prag) then
13120 Args := Pragma_Argument_Associations (Prag);
13121
13122 -- Guard against an illegal pragma. The sole argument must be an
13123 -- identifier which specifies either Dynamic or Static model.
13124
13125 if Present (Args) then
13126 Model := Get_Pragma_Arg (First (Args));
13127
13128 if Nkind (Model) = N_Identifier then
13129 Dynamic_Elaboration_Checks := Chars (Model) = Name_Dynamic;
13130 end if;
13131 end if;
13132 end if;
13133 end Install_Elaboration_Model;
13134
13135 -----------------------------
13136 -- Install_Generic_Formals --
13137 -----------------------------
13138
13139 procedure Install_Generic_Formals (Subp_Id : Entity_Id) is
13140 E : Entity_Id;
13141
13142 begin
13143 pragma Assert (Is_Generic_Subprogram (Subp_Id));
13144
13145 E := First_Entity (Subp_Id);
13146 while Present (E) loop
13147 Install_Entity (E);
13148 Next_Entity (E);
13149 end loop;
13150 end Install_Generic_Formals;
13151
13152 ------------------------
13153 -- Install_SPARK_Mode --
13154 ------------------------
13155
13156 procedure Install_SPARK_Mode (Mode : SPARK_Mode_Type; Prag : Node_Id) is
13157 begin
13158 SPARK_Mode := Mode;
13159 SPARK_Mode_Pragma := Prag;
13160 end Install_SPARK_Mode;
13161
13162 --------------------------
13163 -- Invalid_Scalar_Value --
13164 --------------------------
13165
13166 function Invalid_Scalar_Value
13167 (Loc : Source_Ptr;
13168 Scal_Typ : Scalar_Id) return Node_Id
13169 is
13170 function Invalid_Binder_Value return Node_Id;
13171 -- Return a reference to the corresponding invalid value for type
13172 -- Scal_Typ as defined in unit System.Scalar_Values.
13173
13174 function Invalid_Float_Value return Node_Id;
13175 -- Return the invalid value of float type Scal_Typ
13176
13177 function Invalid_Integer_Value return Node_Id;
13178 -- Return the invalid value of integer type Scal_Typ
13179
13180 procedure Set_Invalid_Binder_Values;
13181 -- Set the contents of collection Invalid_Binder_Values
13182
13183 --------------------------
13184 -- Invalid_Binder_Value --
13185 --------------------------
13186
13187 function Invalid_Binder_Value return Node_Id is
13188 Val_Id : Entity_Id;
13189
13190 begin
13191 -- Initialize the collection of invalid binder values the first time
13192 -- around.
13193
13194 Set_Invalid_Binder_Values;
13195
13196 -- Obtain the corresponding variable from System.Scalar_Values which
13197 -- holds the invalid value for this type.
13198
13199 Val_Id := Invalid_Binder_Values (Scal_Typ);
13200 pragma Assert (Present (Val_Id));
13201
13202 return New_Occurrence_Of (Val_Id, Loc);
13203 end Invalid_Binder_Value;
13204
13205 -------------------------
13206 -- Invalid_Float_Value --
13207 -------------------------
13208
13209 function Invalid_Float_Value return Node_Id is
13210 Value : constant Ureal := Invalid_Floats (Scal_Typ);
13211
13212 begin
13213 -- Pragma Invalid_Scalars did not specify an invalid value for this
13214 -- type. Fall back to the value provided by the binder.
13215
13216 if Value = No_Ureal then
13217 return Invalid_Binder_Value;
13218 else
13219 return Make_Real_Literal (Loc, Realval => Value);
13220 end if;
13221 end Invalid_Float_Value;
13222
13223 ---------------------------
13224 -- Invalid_Integer_Value --
13225 ---------------------------
13226
13227 function Invalid_Integer_Value return Node_Id is
13228 Value : constant Uint := Invalid_Integers (Scal_Typ);
13229
13230 begin
13231 -- Pragma Invalid_Scalars did not specify an invalid value for this
13232 -- type. Fall back to the value provided by the binder.
13233
13234 if Value = No_Uint then
13235 return Invalid_Binder_Value;
13236 else
13237 return Make_Integer_Literal (Loc, Intval => Value);
13238 end if;
13239 end Invalid_Integer_Value;
13240
13241 -------------------------------
13242 -- Set_Invalid_Binder_Values --
13243 -------------------------------
13244
13245 procedure Set_Invalid_Binder_Values is
13246 begin
13247 if not Invalid_Binder_Values_Set then
13248 Invalid_Binder_Values_Set := True;
13249
13250 -- Initialize the contents of the collection once since RTE calls
13251 -- are not cheap.
13252
13253 Invalid_Binder_Values :=
13254 (Name_Short_Float => RTE (RE_IS_Isf),
13255 Name_Float => RTE (RE_IS_Ifl),
13256 Name_Long_Float => RTE (RE_IS_Ilf),
13257 Name_Long_Long_Float => RTE (RE_IS_Ill),
13258 Name_Signed_8 => RTE (RE_IS_Is1),
13259 Name_Signed_16 => RTE (RE_IS_Is2),
13260 Name_Signed_32 => RTE (RE_IS_Is4),
13261 Name_Signed_64 => RTE (RE_IS_Is8),
13262 Name_Unsigned_8 => RTE (RE_IS_Iu1),
13263 Name_Unsigned_16 => RTE (RE_IS_Iu2),
13264 Name_Unsigned_32 => RTE (RE_IS_Iu4),
13265 Name_Unsigned_64 => RTE (RE_IS_Iu8));
13266 end if;
13267 end Set_Invalid_Binder_Values;
13268
13269 -- Start of processing for Invalid_Scalar_Value
13270
13271 begin
13272 if Scal_Typ in Float_Scalar_Id then
13273 return Invalid_Float_Value;
13274
13275 else pragma Assert (Scal_Typ in Integer_Scalar_Id);
13276 return Invalid_Integer_Value;
13277 end if;
13278 end Invalid_Scalar_Value;
13279
13280 -----------------------------
13281 -- Is_Actual_Out_Parameter --
13282 -----------------------------
13283
13284 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
13285 Formal : Entity_Id;
13286 Call : Node_Id;
13287 begin
13288 Find_Actual (N, Formal, Call);
13289 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
13290 end Is_Actual_Out_Parameter;
13291
13292 -------------------------
13293 -- Is_Actual_Parameter --
13294 -------------------------
13295
13296 function Is_Actual_Parameter (N : Node_Id) return Boolean is
13297 PK : constant Node_Kind := Nkind (Parent (N));
13298
13299 begin
13300 case PK is
13301 when N_Parameter_Association =>
13302 return N = Explicit_Actual_Parameter (Parent (N));
13303
13304 when N_Subprogram_Call =>
13305 return Is_List_Member (N)
13306 and then
13307 List_Containing (N) = Parameter_Associations (Parent (N));
13308
13309 when others =>
13310 return False;
13311 end case;
13312 end Is_Actual_Parameter;
13313
13314 --------------------------------
13315 -- Is_Actual_Tagged_Parameter --
13316 --------------------------------
13317
13318 function Is_Actual_Tagged_Parameter (N : Node_Id) return Boolean is
13319 Formal : Entity_Id;
13320 Call : Node_Id;
13321 begin
13322 Find_Actual (N, Formal, Call);
13323 return Present (Formal) and then Is_Tagged_Type (Etype (Formal));
13324 end Is_Actual_Tagged_Parameter;
13325
13326 ---------------------
13327 -- Is_Aliased_View --
13328 ---------------------
13329
13330 function Is_Aliased_View (Obj : Node_Id) return Boolean is
13331 E : Entity_Id;
13332
13333 begin
13334 if Is_Entity_Name (Obj) then
13335 E := Entity (Obj);
13336
13337 return
13338 (Is_Object (E)
13339 and then
13340 (Is_Aliased (E)
13341 or else (Present (Renamed_Object (E))
13342 and then Is_Aliased_View (Renamed_Object (E)))))
13343
13344 or else ((Is_Formal (E) or else Is_Formal_Object (E))
13345 and then Is_Tagged_Type (Etype (E)))
13346
13347 or else (Is_Concurrent_Type (E) and then In_Open_Scopes (E))
13348
13349 -- Current instance of type, either directly or as rewritten
13350 -- reference to the current object.
13351
13352 or else (Is_Entity_Name (Original_Node (Obj))
13353 and then Present (Entity (Original_Node (Obj)))
13354 and then Is_Type (Entity (Original_Node (Obj))))
13355
13356 or else (Is_Type (E) and then E = Current_Scope)
13357
13358 or else (Is_Incomplete_Or_Private_Type (E)
13359 and then Full_View (E) = Current_Scope)
13360
13361 -- Ada 2012 AI05-0053: the return object of an extended return
13362 -- statement is aliased if its type is immutably limited.
13363
13364 or else (Is_Return_Object (E)
13365 and then Is_Limited_View (Etype (E)));
13366
13367 elsif Nkind (Obj) = N_Selected_Component then
13368 return Is_Aliased (Entity (Selector_Name (Obj)));
13369
13370 elsif Nkind (Obj) = N_Indexed_Component then
13371 return Has_Aliased_Components (Etype (Prefix (Obj)))
13372 or else
13373 (Is_Access_Type (Etype (Prefix (Obj)))
13374 and then Has_Aliased_Components
13375 (Designated_Type (Etype (Prefix (Obj)))));
13376
13377 elsif Nkind_In (Obj, N_Unchecked_Type_Conversion, N_Type_Conversion) then
13378 return Is_Tagged_Type (Etype (Obj))
13379 and then Is_Aliased_View (Expression (Obj));
13380
13381 elsif Nkind (Obj) = N_Explicit_Dereference then
13382 return Nkind (Original_Node (Obj)) /= N_Function_Call;
13383
13384 else
13385 return False;
13386 end if;
13387 end Is_Aliased_View;
13388
13389 -------------------------
13390 -- Is_Ancestor_Package --
13391 -------------------------
13392
13393 function Is_Ancestor_Package
13394 (E1 : Entity_Id;
13395 E2 : Entity_Id) return Boolean
13396 is
13397 Par : Entity_Id;
13398
13399 begin
13400 Par := E2;
13401 while Present (Par) and then Par /= Standard_Standard loop
13402 if Par = E1 then
13403 return True;
13404 end if;
13405
13406 Par := Scope (Par);
13407 end loop;
13408
13409 return False;
13410 end Is_Ancestor_Package;
13411
13412 ----------------------
13413 -- Is_Atomic_Object --
13414 ----------------------
13415
13416 function Is_Atomic_Object (N : Node_Id) return Boolean is
13417 function Is_Atomic_Entity (Id : Entity_Id) return Boolean;
13418 pragma Inline (Is_Atomic_Entity);
13419 -- Determine whether arbitrary entity Id is either atomic or has atomic
13420 -- components.
13421
13422 function Is_Atomic_Prefix (Pref : Node_Id) return Boolean;
13423 -- Determine whether prefix Pref of an indexed or selected component is
13424 -- an atomic object.
13425
13426 ----------------------
13427 -- Is_Atomic_Entity --
13428 ----------------------
13429
13430 function Is_Atomic_Entity (Id : Entity_Id) return Boolean is
13431 begin
13432 return Is_Atomic (Id) or else Has_Atomic_Components (Id);
13433 end Is_Atomic_Entity;
13434
13435 ----------------------
13436 -- Is_Atomic_Prefix --
13437 ----------------------
13438
13439 function Is_Atomic_Prefix (Pref : Node_Id) return Boolean is
13440 Typ : constant Entity_Id := Etype (Pref);
13441
13442 begin
13443 if Is_Access_Type (Typ) then
13444 return Has_Atomic_Components (Designated_Type (Typ));
13445
13446 elsif Is_Atomic_Entity (Typ) then
13447 return True;
13448
13449 elsif Is_Entity_Name (Pref)
13450 and then Is_Atomic_Entity (Entity (Pref))
13451 then
13452 return True;
13453
13454 elsif Nkind (Pref) = N_Indexed_Component then
13455 return Is_Atomic_Prefix (Prefix (Pref));
13456
13457 elsif Nkind (Pref) = N_Selected_Component then
13458 return
13459 Is_Atomic_Prefix (Prefix (Pref))
13460 or else Is_Atomic (Entity (Selector_Name (Pref)));
13461 end if;
13462
13463 return False;
13464 end Is_Atomic_Prefix;
13465
13466 -- Start of processing for Is_Atomic_Object
13467
13468 begin
13469 if Is_Entity_Name (N) then
13470 return Is_Atomic_Object_Entity (Entity (N));
13471
13472 elsif Nkind (N) = N_Indexed_Component then
13473 return Is_Atomic (Etype (N)) or else Is_Atomic_Prefix (Prefix (N));
13474
13475 elsif Nkind (N) = N_Selected_Component then
13476 return
13477 Is_Atomic (Etype (N))
13478 or else Is_Atomic_Prefix (Prefix (N))
13479 or else Is_Atomic (Entity (Selector_Name (N)));
13480 end if;
13481
13482 return False;
13483 end Is_Atomic_Object;
13484
13485 -----------------------------
13486 -- Is_Atomic_Object_Entity --
13487 -----------------------------
13488
13489 function Is_Atomic_Object_Entity (Id : Entity_Id) return Boolean is
13490 begin
13491 return
13492 Is_Object (Id)
13493 and then (Is_Atomic (Id) or else Is_Atomic (Etype (Id)));
13494 end Is_Atomic_Object_Entity;
13495
13496 -----------------------------
13497 -- Is_Atomic_Or_VFA_Object --
13498 -----------------------------
13499
13500 function Is_Atomic_Or_VFA_Object (N : Node_Id) return Boolean is
13501 begin
13502 return Is_Atomic_Object (N)
13503 or else (Is_Object_Reference (N)
13504 and then Is_Entity_Name (N)
13505 and then (Is_Volatile_Full_Access (Entity (N))
13506 or else
13507 Is_Volatile_Full_Access (Etype (Entity (N)))));
13508 end Is_Atomic_Or_VFA_Object;
13509
13510 -------------------------
13511 -- Is_Attribute_Result --
13512 -------------------------
13513
13514 function Is_Attribute_Result (N : Node_Id) return Boolean is
13515 begin
13516 return Nkind (N) = N_Attribute_Reference
13517 and then Attribute_Name (N) = Name_Result;
13518 end Is_Attribute_Result;
13519
13520 -------------------------
13521 -- Is_Attribute_Update --
13522 -------------------------
13523
13524 function Is_Attribute_Update (N : Node_Id) return Boolean is
13525 begin
13526 return Nkind (N) = N_Attribute_Reference
13527 and then Attribute_Name (N) = Name_Update;
13528 end Is_Attribute_Update;
13529
13530 ------------------------------------
13531 -- Is_Body_Or_Package_Declaration --
13532 ------------------------------------
13533
13534 function Is_Body_Or_Package_Declaration (N : Node_Id) return Boolean is
13535 begin
13536 return Is_Body (N) or else Nkind (N) = N_Package_Declaration;
13537 end Is_Body_Or_Package_Declaration;
13538
13539 -----------------------
13540 -- Is_Bounded_String --
13541 -----------------------
13542
13543 function Is_Bounded_String (T : Entity_Id) return Boolean is
13544 Under : constant Entity_Id := Underlying_Type (Root_Type (T));
13545
13546 begin
13547 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
13548 -- Super_String, or one of the [Wide_]Wide_ versions. This will
13549 -- be True for all the Bounded_String types in instances of the
13550 -- Generic_Bounded_Length generics, and for types derived from those.
13551
13552 return Present (Under)
13553 and then (Is_RTE (Root_Type (Under), RO_SU_Super_String) or else
13554 Is_RTE (Root_Type (Under), RO_WI_Super_String) or else
13555 Is_RTE (Root_Type (Under), RO_WW_Super_String));
13556 end Is_Bounded_String;
13557
13558 ---------------------
13559 -- Is_CCT_Instance --
13560 ---------------------
13561
13562 function Is_CCT_Instance
13563 (Ref_Id : Entity_Id;
13564 Context_Id : Entity_Id) return Boolean
13565 is
13566 begin
13567 pragma Assert (Ekind_In (Ref_Id, E_Protected_Type, E_Task_Type));
13568
13569 if Is_Single_Task_Object (Context_Id) then
13570 return Scope_Within_Or_Same (Etype (Context_Id), Ref_Id);
13571
13572 else
13573 pragma Assert (Ekind_In (Context_Id, E_Entry,
13574 E_Entry_Family,
13575 E_Function,
13576 E_Package,
13577 E_Procedure,
13578 E_Protected_Type,
13579 E_Task_Type)
13580 or else
13581 Is_Record_Type (Context_Id));
13582 return Scope_Within_Or_Same (Context_Id, Ref_Id);
13583 end if;
13584 end Is_CCT_Instance;
13585
13586 -------------------------
13587 -- Is_Child_Or_Sibling --
13588 -------------------------
13589
13590 function Is_Child_Or_Sibling
13591 (Pack_1 : Entity_Id;
13592 Pack_2 : Entity_Id) return Boolean
13593 is
13594 function Distance_From_Standard (Pack : Entity_Id) return Nat;
13595 -- Given an arbitrary package, return the number of "climbs" necessary
13596 -- to reach scope Standard_Standard.
13597
13598 procedure Equalize_Depths
13599 (Pack : in out Entity_Id;
13600 Depth : in out Nat;
13601 Depth_To_Reach : Nat);
13602 -- Given an arbitrary package, its depth and a target depth to reach,
13603 -- climb the scope chain until the said depth is reached. The pointer
13604 -- to the package and its depth a modified during the climb.
13605
13606 ----------------------------
13607 -- Distance_From_Standard --
13608 ----------------------------
13609
13610 function Distance_From_Standard (Pack : Entity_Id) return Nat is
13611 Dist : Nat;
13612 Scop : Entity_Id;
13613
13614 begin
13615 Dist := 0;
13616 Scop := Pack;
13617 while Present (Scop) and then Scop /= Standard_Standard loop
13618 Dist := Dist + 1;
13619 Scop := Scope (Scop);
13620 end loop;
13621
13622 return Dist;
13623 end Distance_From_Standard;
13624
13625 ---------------------
13626 -- Equalize_Depths --
13627 ---------------------
13628
13629 procedure Equalize_Depths
13630 (Pack : in out Entity_Id;
13631 Depth : in out Nat;
13632 Depth_To_Reach : Nat)
13633 is
13634 begin
13635 -- The package must be at a greater or equal depth
13636
13637 if Depth < Depth_To_Reach then
13638 raise Program_Error;
13639 end if;
13640
13641 -- Climb the scope chain until the desired depth is reached
13642
13643 while Present (Pack) and then Depth /= Depth_To_Reach loop
13644 Pack := Scope (Pack);
13645 Depth := Depth - 1;
13646 end loop;
13647 end Equalize_Depths;
13648
13649 -- Local variables
13650
13651 P_1 : Entity_Id := Pack_1;
13652 P_1_Child : Boolean := False;
13653 P_1_Depth : Nat := Distance_From_Standard (P_1);
13654 P_2 : Entity_Id := Pack_2;
13655 P_2_Child : Boolean := False;
13656 P_2_Depth : Nat := Distance_From_Standard (P_2);
13657
13658 -- Start of processing for Is_Child_Or_Sibling
13659
13660 begin
13661 pragma Assert
13662 (Ekind (Pack_1) = E_Package and then Ekind (Pack_2) = E_Package);
13663
13664 -- Both packages denote the same entity, therefore they cannot be
13665 -- children or siblings.
13666
13667 if P_1 = P_2 then
13668 return False;
13669
13670 -- One of the packages is at a deeper level than the other. Note that
13671 -- both may still come from different hierarchies.
13672
13673 -- (root) P_2
13674 -- / \ :
13675 -- X P_2 or X
13676 -- : :
13677 -- P_1 P_1
13678
13679 elsif P_1_Depth > P_2_Depth then
13680 Equalize_Depths
13681 (Pack => P_1,
13682 Depth => P_1_Depth,
13683 Depth_To_Reach => P_2_Depth);
13684 P_1_Child := True;
13685
13686 -- (root) P_1
13687 -- / \ :
13688 -- P_1 X or X
13689 -- : :
13690 -- P_2 P_2
13691
13692 elsif P_2_Depth > P_1_Depth then
13693 Equalize_Depths
13694 (Pack => P_2,
13695 Depth => P_2_Depth,
13696 Depth_To_Reach => P_1_Depth);
13697 P_2_Child := True;
13698 end if;
13699
13700 -- At this stage the package pointers have been elevated to the same
13701 -- depth. If the related entities are the same, then one package is a
13702 -- potential child of the other:
13703
13704 -- P_1
13705 -- :
13706 -- X became P_1 P_2 or vice versa
13707 -- :
13708 -- P_2
13709
13710 if P_1 = P_2 then
13711 if P_1_Child then
13712 return Is_Child_Unit (Pack_1);
13713
13714 else pragma Assert (P_2_Child);
13715 return Is_Child_Unit (Pack_2);
13716 end if;
13717
13718 -- The packages may come from the same package chain or from entirely
13719 -- different hierarcies. To determine this, climb the scope stack until
13720 -- a common root is found.
13721
13722 -- (root) (root 1) (root 2)
13723 -- / \ | |
13724 -- P_1 P_2 P_1 P_2
13725
13726 else
13727 while Present (P_1) and then Present (P_2) loop
13728
13729 -- The two packages may be siblings
13730
13731 if P_1 = P_2 then
13732 return Is_Child_Unit (Pack_1) and then Is_Child_Unit (Pack_2);
13733 end if;
13734
13735 P_1 := Scope (P_1);
13736 P_2 := Scope (P_2);
13737 end loop;
13738 end if;
13739
13740 return False;
13741 end Is_Child_Or_Sibling;
13742
13743 -----------------------------
13744 -- Is_Concurrent_Interface --
13745 -----------------------------
13746
13747 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
13748 begin
13749 return Is_Interface (T)
13750 and then
13751 (Is_Protected_Interface (T)
13752 or else Is_Synchronized_Interface (T)
13753 or else Is_Task_Interface (T));
13754 end Is_Concurrent_Interface;
13755
13756 -----------------------
13757 -- Is_Constant_Bound --
13758 -----------------------
13759
13760 function Is_Constant_Bound (Exp : Node_Id) return Boolean is
13761 begin
13762 if Compile_Time_Known_Value (Exp) then
13763 return True;
13764
13765 elsif Is_Entity_Name (Exp) and then Present (Entity (Exp)) then
13766 return Is_Constant_Object (Entity (Exp))
13767 or else Ekind (Entity (Exp)) = E_Enumeration_Literal;
13768
13769 elsif Nkind (Exp) in N_Binary_Op then
13770 return Is_Constant_Bound (Left_Opnd (Exp))
13771 and then Is_Constant_Bound (Right_Opnd (Exp))
13772 and then Scope (Entity (Exp)) = Standard_Standard;
13773
13774 else
13775 return False;
13776 end if;
13777 end Is_Constant_Bound;
13778
13779 ---------------------------
13780 -- Is_Container_Element --
13781 ---------------------------
13782
13783 function Is_Container_Element (Exp : Node_Id) return Boolean is
13784 Loc : constant Source_Ptr := Sloc (Exp);
13785 Pref : constant Node_Id := Prefix (Exp);
13786
13787 Call : Node_Id;
13788 -- Call to an indexing aspect
13789
13790 Cont_Typ : Entity_Id;
13791 -- The type of the container being accessed
13792
13793 Elem_Typ : Entity_Id;
13794 -- Its element type
13795
13796 Indexing : Entity_Id;
13797 Is_Const : Boolean;
13798 -- Indicates that constant indexing is used, and the element is thus
13799 -- a constant.
13800
13801 Ref_Typ : Entity_Id;
13802 -- The reference type returned by the indexing operation
13803
13804 begin
13805 -- If C is a container, in a context that imposes the element type of
13806 -- that container, the indexing notation C (X) is rewritten as:
13807
13808 -- Indexing (C, X).Discr.all
13809
13810 -- where Indexing is one of the indexing aspects of the container.
13811 -- If the context does not require a reference, the construct can be
13812 -- rewritten as
13813
13814 -- Element (C, X)
13815
13816 -- First, verify that the construct has the proper form
13817
13818 if not Expander_Active then
13819 return False;
13820
13821 elsif Nkind (Pref) /= N_Selected_Component then
13822 return False;
13823
13824 elsif Nkind (Prefix (Pref)) /= N_Function_Call then
13825 return False;
13826
13827 else
13828 Call := Prefix (Pref);
13829 Ref_Typ := Etype (Call);
13830 end if;
13831
13832 if not Has_Implicit_Dereference (Ref_Typ)
13833 or else No (First (Parameter_Associations (Call)))
13834 or else not Is_Entity_Name (Name (Call))
13835 then
13836 return False;
13837 end if;
13838
13839 -- Retrieve type of container object, and its iterator aspects
13840
13841 Cont_Typ := Etype (First (Parameter_Associations (Call)));
13842 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Constant_Indexing);
13843 Is_Const := False;
13844
13845 if No (Indexing) then
13846
13847 -- Container should have at least one indexing operation
13848
13849 return False;
13850
13851 elsif Entity (Name (Call)) /= Entity (Indexing) then
13852
13853 -- This may be a variable indexing operation
13854
13855 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Variable_Indexing);
13856
13857 if No (Indexing)
13858 or else Entity (Name (Call)) /= Entity (Indexing)
13859 then
13860 return False;
13861 end if;
13862
13863 else
13864 Is_Const := True;
13865 end if;
13866
13867 Elem_Typ := Find_Value_Of_Aspect (Cont_Typ, Aspect_Iterator_Element);
13868
13869 if No (Elem_Typ) or else Entity (Elem_Typ) /= Etype (Exp) then
13870 return False;
13871 end if;
13872
13873 -- Check that the expression is not the target of an assignment, in
13874 -- which case the rewriting is not possible.
13875
13876 if not Is_Const then
13877 declare
13878 Par : Node_Id;
13879
13880 begin
13881 Par := Exp;
13882 while Present (Par)
13883 loop
13884 if Nkind (Parent (Par)) = N_Assignment_Statement
13885 and then Par = Name (Parent (Par))
13886 then
13887 return False;
13888
13889 -- A renaming produces a reference, and the transformation
13890 -- does not apply.
13891
13892 elsif Nkind (Parent (Par)) = N_Object_Renaming_Declaration then
13893 return False;
13894
13895 elsif Nkind_In
13896 (Nkind (Parent (Par)), N_Function_Call,
13897 N_Procedure_Call_Statement,
13898 N_Entry_Call_Statement)
13899 then
13900 -- Check that the element is not part of an actual for an
13901 -- in-out parameter.
13902
13903 declare
13904 F : Entity_Id;
13905 A : Node_Id;
13906
13907 begin
13908 F := First_Formal (Entity (Name (Parent (Par))));
13909 A := First (Parameter_Associations (Parent (Par)));
13910 while Present (F) loop
13911 if A = Par and then Ekind (F) /= E_In_Parameter then
13912 return False;
13913 end if;
13914
13915 Next_Formal (F);
13916 Next (A);
13917 end loop;
13918 end;
13919
13920 -- E_In_Parameter in a call: element is not modified.
13921
13922 exit;
13923 end if;
13924
13925 Par := Parent (Par);
13926 end loop;
13927 end;
13928 end if;
13929
13930 -- The expression has the proper form and the context requires the
13931 -- element type. Retrieve the Element function of the container and
13932 -- rewrite the construct as a call to it.
13933
13934 declare
13935 Op : Elmt_Id;
13936
13937 begin
13938 Op := First_Elmt (Primitive_Operations (Cont_Typ));
13939 while Present (Op) loop
13940 exit when Chars (Node (Op)) = Name_Element;
13941 Next_Elmt (Op);
13942 end loop;
13943
13944 if No (Op) then
13945 return False;
13946
13947 else
13948 Rewrite (Exp,
13949 Make_Function_Call (Loc,
13950 Name => New_Occurrence_Of (Node (Op), Loc),
13951 Parameter_Associations => Parameter_Associations (Call)));
13952 Analyze_And_Resolve (Exp, Entity (Elem_Typ));
13953 return True;
13954 end if;
13955 end;
13956 end Is_Container_Element;
13957
13958 ----------------------------
13959 -- Is_Contract_Annotation --
13960 ----------------------------
13961
13962 function Is_Contract_Annotation (Item : Node_Id) return Boolean is
13963 begin
13964 return Is_Package_Contract_Annotation (Item)
13965 or else
13966 Is_Subprogram_Contract_Annotation (Item);
13967 end Is_Contract_Annotation;
13968
13969 --------------------------------------
13970 -- Is_Controlling_Limited_Procedure --
13971 --------------------------------------
13972
13973 function Is_Controlling_Limited_Procedure
13974 (Proc_Nam : Entity_Id) return Boolean
13975 is
13976 Param : Node_Id;
13977 Param_Typ : Entity_Id := Empty;
13978
13979 begin
13980 if Ekind (Proc_Nam) = E_Procedure
13981 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
13982 then
13983 Param :=
13984 Parameter_Type
13985 (First (Parameter_Specifications (Parent (Proc_Nam))));
13986
13987 -- The formal may be an anonymous access type
13988
13989 if Nkind (Param) = N_Access_Definition then
13990 Param_Typ := Entity (Subtype_Mark (Param));
13991 else
13992 Param_Typ := Etype (Param);
13993 end if;
13994
13995 -- In the case where an Itype was created for a dispatchin call, the
13996 -- procedure call has been rewritten. The actual may be an access to
13997 -- interface type in which case it is the designated type that is the
13998 -- controlling type.
13999
14000 elsif Present (Associated_Node_For_Itype (Proc_Nam))
14001 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
14002 and then
14003 Present (Parameter_Associations
14004 (Associated_Node_For_Itype (Proc_Nam)))
14005 then
14006 Param_Typ :=
14007 Etype (First (Parameter_Associations
14008 (Associated_Node_For_Itype (Proc_Nam))));
14009
14010 if Ekind (Param_Typ) = E_Anonymous_Access_Type then
14011 Param_Typ := Directly_Designated_Type (Param_Typ);
14012 end if;
14013 end if;
14014
14015 if Present (Param_Typ) then
14016 return
14017 Is_Interface (Param_Typ)
14018 and then Is_Limited_Record (Param_Typ);
14019 end if;
14020
14021 return False;
14022 end Is_Controlling_Limited_Procedure;
14023
14024 -----------------------------
14025 -- Is_CPP_Constructor_Call --
14026 -----------------------------
14027
14028 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
14029 begin
14030 return Nkind (N) = N_Function_Call
14031 and then Is_CPP_Class (Etype (Etype (N)))
14032 and then Is_Constructor (Entity (Name (N)))
14033 and then Is_Imported (Entity (Name (N)));
14034 end Is_CPP_Constructor_Call;
14035
14036 -------------------------
14037 -- Is_Current_Instance --
14038 -------------------------
14039
14040 function Is_Current_Instance (N : Node_Id) return Boolean is
14041 Typ : constant Entity_Id := Entity (N);
14042 P : Node_Id;
14043
14044 begin
14045 -- Simplest case: entity is a concurrent type and we are currently
14046 -- inside the body. This will eventually be expanded into a call to
14047 -- Self (for tasks) or _object (for protected objects).
14048
14049 if Is_Concurrent_Type (Typ) and then In_Open_Scopes (Typ) then
14050 return True;
14051
14052 else
14053 -- Check whether the context is a (sub)type declaration for the
14054 -- type entity.
14055
14056 P := Parent (N);
14057 while Present (P) loop
14058 if Nkind_In (P, N_Full_Type_Declaration,
14059 N_Private_Type_Declaration,
14060 N_Subtype_Declaration)
14061 and then Comes_From_Source (P)
14062 and then Defining_Entity (P) = Typ
14063 then
14064 return True;
14065
14066 -- A subtype name may appear in an aspect specification for a
14067 -- Predicate_Failure aspect, for which we do not construct a
14068 -- wrapper procedure. The subtype will be replaced by the
14069 -- expression being tested when the corresponding predicate
14070 -- check is expanded.
14071
14072 elsif Nkind (P) = N_Aspect_Specification
14073 and then Nkind (Parent (P)) = N_Subtype_Declaration
14074 then
14075 return True;
14076
14077 elsif Nkind (P) = N_Pragma
14078 and then Get_Pragma_Id (P) = Pragma_Predicate_Failure
14079 then
14080 return True;
14081 end if;
14082
14083 P := Parent (P);
14084 end loop;
14085 end if;
14086
14087 -- In any other context this is not a current occurrence
14088
14089 return False;
14090 end Is_Current_Instance;
14091
14092 --------------------
14093 -- Is_Declaration --
14094 --------------------
14095
14096 function Is_Declaration
14097 (N : Node_Id;
14098 Body_OK : Boolean := True;
14099 Concurrent_OK : Boolean := True;
14100 Formal_OK : Boolean := True;
14101 Generic_OK : Boolean := True;
14102 Instantiation_OK : Boolean := True;
14103 Renaming_OK : Boolean := True;
14104 Stub_OK : Boolean := True;
14105 Subprogram_OK : Boolean := True;
14106 Type_OK : Boolean := True) return Boolean
14107 is
14108 begin
14109 case Nkind (N) is
14110
14111 -- Body declarations
14112
14113 when N_Proper_Body =>
14114 return Body_OK;
14115
14116 -- Concurrent type declarations
14117
14118 when N_Protected_Type_Declaration
14119 | N_Single_Protected_Declaration
14120 | N_Single_Task_Declaration
14121 | N_Task_Type_Declaration
14122 =>
14123 return Concurrent_OK or Type_OK;
14124
14125 -- Formal declarations
14126
14127 when N_Formal_Abstract_Subprogram_Declaration
14128 | N_Formal_Concrete_Subprogram_Declaration
14129 | N_Formal_Object_Declaration
14130 | N_Formal_Package_Declaration
14131 | N_Formal_Type_Declaration
14132 =>
14133 return Formal_OK;
14134
14135 -- Generic declarations
14136
14137 when N_Generic_Package_Declaration
14138 | N_Generic_Subprogram_Declaration
14139 =>
14140 return Generic_OK;
14141
14142 -- Generic instantiations
14143
14144 when N_Function_Instantiation
14145 | N_Package_Instantiation
14146 | N_Procedure_Instantiation
14147 =>
14148 return Instantiation_OK;
14149
14150 -- Generic renaming declarations
14151
14152 when N_Generic_Renaming_Declaration =>
14153 return Generic_OK or Renaming_OK;
14154
14155 -- Renaming declarations
14156
14157 when N_Exception_Renaming_Declaration
14158 | N_Object_Renaming_Declaration
14159 | N_Package_Renaming_Declaration
14160 | N_Subprogram_Renaming_Declaration
14161 =>
14162 return Renaming_OK;
14163
14164 -- Stub declarations
14165
14166 when N_Body_Stub =>
14167 return Stub_OK;
14168
14169 -- Subprogram declarations
14170
14171 when N_Abstract_Subprogram_Declaration
14172 | N_Entry_Declaration
14173 | N_Expression_Function
14174 | N_Subprogram_Declaration
14175 =>
14176 return Subprogram_OK;
14177
14178 -- Type declarations
14179
14180 when N_Full_Type_Declaration
14181 | N_Incomplete_Type_Declaration
14182 | N_Private_Extension_Declaration
14183 | N_Private_Type_Declaration
14184 | N_Subtype_Declaration
14185 =>
14186 return Type_OK;
14187
14188 -- Miscellaneous
14189
14190 when N_Component_Declaration
14191 | N_Exception_Declaration
14192 | N_Implicit_Label_Declaration
14193 | N_Number_Declaration
14194 | N_Object_Declaration
14195 | N_Package_Declaration
14196 =>
14197 return True;
14198
14199 when others =>
14200 return False;
14201 end case;
14202 end Is_Declaration;
14203
14204 --------------------------------
14205 -- Is_Declared_Within_Variant --
14206 --------------------------------
14207
14208 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
14209 Comp_Decl : constant Node_Id := Parent (Comp);
14210 Comp_List : constant Node_Id := Parent (Comp_Decl);
14211 begin
14212 return Nkind (Parent (Comp_List)) = N_Variant;
14213 end Is_Declared_Within_Variant;
14214
14215 ----------------------------------------------
14216 -- Is_Dependent_Component_Of_Mutable_Object --
14217 ----------------------------------------------
14218
14219 function Is_Dependent_Component_Of_Mutable_Object
14220 (Object : Node_Id) return Boolean
14221 is
14222 P : Node_Id;
14223 Prefix_Type : Entity_Id;
14224 P_Aliased : Boolean := False;
14225 Comp : Entity_Id;
14226
14227 Deref : Node_Id := Object;
14228 -- Dereference node, in something like X.all.Y(2)
14229
14230 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
14231
14232 begin
14233 -- Find the dereference node if any
14234
14235 while Nkind_In (Deref, N_Indexed_Component,
14236 N_Selected_Component,
14237 N_Slice)
14238 loop
14239 Deref := Prefix (Deref);
14240 end loop;
14241
14242 -- If the prefix is a qualified expression of a variable, then function
14243 -- Is_Variable will return False for that because a qualified expression
14244 -- denotes a constant view, so we need to get the name being qualified
14245 -- so we can test below whether that's a variable (or a dereference).
14246
14247 if Nkind (Deref) = N_Qualified_Expression then
14248 Deref := Expression (Deref);
14249 end if;
14250
14251 -- Ada 2005: If we have a component or slice of a dereference, something
14252 -- like X.all.Y (2) and the type of X is access-to-constant, Is_Variable
14253 -- will return False, because it is indeed a constant view. But it might
14254 -- be a view of a variable object, so we want the following condition to
14255 -- be True in that case.
14256
14257 if Is_Variable (Object)
14258 or else Is_Variable (Deref)
14259 or else (Ada_Version >= Ada_2005
14260 and then (Nkind (Deref) = N_Explicit_Dereference
14261 or else Is_Access_Type (Etype (Deref))))
14262 then
14263 if Nkind (Object) = N_Selected_Component then
14264
14265 -- If the selector is not a component, then we definitely return
14266 -- False (it could be a function selector in a prefix form call
14267 -- occurring in an iterator specification).
14268
14269 if not Ekind_In (Entity (Selector_Name (Object)), E_Component,
14270 E_Discriminant)
14271 then
14272 return False;
14273 end if;
14274
14275 -- Get the original node of the prefix in case it has been
14276 -- rewritten, which can occur, for example, in qualified
14277 -- expression cases. Also, a discriminant check on a selected
14278 -- component may be expanded into a dereference when removing
14279 -- side effects, and the subtype of the original node may be
14280 -- unconstrained.
14281
14282 P := Original_Node (Prefix (Object));
14283 Prefix_Type := Etype (P);
14284
14285 -- If the prefix is a qualified expression, we want to look at its
14286 -- operand.
14287
14288 if Nkind (P) = N_Qualified_Expression then
14289 P := Expression (P);
14290 Prefix_Type := Etype (P);
14291 end if;
14292
14293 if Is_Entity_Name (P) then
14294 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
14295 Prefix_Type := Base_Type (Prefix_Type);
14296 end if;
14297
14298 if Is_Aliased (Entity (P)) then
14299 P_Aliased := True;
14300 end if;
14301
14302 -- For explicit dereferences we get the access prefix so we can
14303 -- treat this similarly to implicit dereferences and examine the
14304 -- kind of the access type and its designated subtype further
14305 -- below.
14306
14307 elsif Nkind (P) = N_Explicit_Dereference then
14308 P := Prefix (P);
14309 Prefix_Type := Etype (P);
14310
14311 else
14312 -- Check for prefix being an aliased component???
14313
14314 null;
14315 end if;
14316
14317 -- A heap object is constrained by its initial value
14318
14319 -- Ada 2005 (AI-363): Always assume the object could be mutable in
14320 -- the dereferenced case, since the access value might denote an
14321 -- unconstrained aliased object, whereas in Ada 95 the designated
14322 -- object is guaranteed to be constrained. A worst-case assumption
14323 -- has to apply in Ada 2005 because we can't tell at compile
14324 -- time whether the object is "constrained by its initial value",
14325 -- despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are semantic
14326 -- rules (these rules are acknowledged to need fixing). We don't
14327 -- impose this more stringent checking for earlier Ada versions or
14328 -- when Relaxed_RM_Semantics applies (the latter for CodePeer's
14329 -- benefit, though it's unclear on why using -gnat95 would not be
14330 -- sufficient???).
14331
14332 if Ada_Version < Ada_2005 or else Relaxed_RM_Semantics then
14333 if Is_Access_Type (Prefix_Type)
14334 or else Nkind (P) = N_Explicit_Dereference
14335 then
14336 return False;
14337 end if;
14338
14339 else pragma Assert (Ada_Version >= Ada_2005);
14340 if Is_Access_Type (Prefix_Type) then
14341 -- We need to make sure we have the base subtype, in case
14342 -- this is actually an access subtype (whose Ekind will be
14343 -- E_Access_Subtype).
14344
14345 Prefix_Type := Etype (Prefix_Type);
14346
14347 -- If the access type is pool-specific, and there is no
14348 -- constrained partial view of the designated type, then the
14349 -- designated object is known to be constrained. If it's a
14350 -- formal access type and the renaming is in the generic
14351 -- spec, we also treat it as pool-specific (known to be
14352 -- constrained), but assume the worst if in the generic body
14353 -- (see RM 3.3(23.3/3)).
14354
14355 if Ekind (Prefix_Type) = E_Access_Type
14356 and then (not Is_Generic_Type (Prefix_Type)
14357 or else not In_Generic_Body (Current_Scope))
14358 and then not Object_Type_Has_Constrained_Partial_View
14359 (Typ => Designated_Type (Prefix_Type),
14360 Scop => Current_Scope)
14361 then
14362 return False;
14363
14364 -- Otherwise (general access type, or there is a constrained
14365 -- partial view of the designated type), we need to check
14366 -- based on the designated type.
14367
14368 else
14369 Prefix_Type := Designated_Type (Prefix_Type);
14370 end if;
14371 end if;
14372 end if;
14373
14374 Comp :=
14375 Original_Record_Component (Entity (Selector_Name (Object)));
14376
14377 -- As per AI-0017, the renaming is illegal in a generic body, even
14378 -- if the subtype is indefinite (only applies to prefixes of an
14379 -- untagged formal type, see RM 3.3 (23.11/3)).
14380
14381 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
14382
14383 if not Is_Constrained (Prefix_Type)
14384 and then (Is_Definite_Subtype (Prefix_Type)
14385 or else
14386 (not Is_Tagged_Type (Prefix_Type)
14387 and then Is_Generic_Type (Prefix_Type)
14388 and then In_Generic_Body (Current_Scope)))
14389
14390 and then (Is_Declared_Within_Variant (Comp)
14391 or else Has_Discriminant_Dependent_Constraint (Comp))
14392 and then (not P_Aliased or else Ada_Version >= Ada_2005)
14393 then
14394 return True;
14395
14396 -- If the prefix is of an access type at this point, then we want
14397 -- to return False, rather than calling this function recursively
14398 -- on the access object (which itself might be a discriminant-
14399 -- dependent component of some other object, but that isn't
14400 -- relevant to checking the object passed to us). This avoids
14401 -- issuing wrong errors when compiling with -gnatc, where there
14402 -- can be implicit dereferences that have not been expanded.
14403
14404 elsif Is_Access_Type (Etype (Prefix (Object))) then
14405 return False;
14406
14407 else
14408 return
14409 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
14410 end if;
14411
14412 elsif Nkind (Object) = N_Indexed_Component
14413 or else Nkind (Object) = N_Slice
14414 then
14415 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
14416
14417 -- A type conversion that Is_Variable is a view conversion:
14418 -- go back to the denoted object.
14419
14420 elsif Nkind (Object) = N_Type_Conversion then
14421 return
14422 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
14423 end if;
14424 end if;
14425
14426 return False;
14427 end Is_Dependent_Component_Of_Mutable_Object;
14428
14429 ---------------------
14430 -- Is_Dereferenced --
14431 ---------------------
14432
14433 function Is_Dereferenced (N : Node_Id) return Boolean is
14434 P : constant Node_Id := Parent (N);
14435 begin
14436 return Nkind_In (P, N_Selected_Component,
14437 N_Explicit_Dereference,
14438 N_Indexed_Component,
14439 N_Slice)
14440 and then Prefix (P) = N;
14441 end Is_Dereferenced;
14442
14443 ----------------------
14444 -- Is_Descendant_Of --
14445 ----------------------
14446
14447 function Is_Descendant_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
14448 T : Entity_Id;
14449 Etyp : Entity_Id;
14450
14451 begin
14452 pragma Assert (Nkind (T1) in N_Entity);
14453 pragma Assert (Nkind (T2) in N_Entity);
14454
14455 T := Base_Type (T1);
14456
14457 -- Immediate return if the types match
14458
14459 if T = T2 then
14460 return True;
14461
14462 -- Comment needed here ???
14463
14464 elsif Ekind (T) = E_Class_Wide_Type then
14465 return Etype (T) = T2;
14466
14467 -- All other cases
14468
14469 else
14470 loop
14471 Etyp := Etype (T);
14472
14473 -- Done if we found the type we are looking for
14474
14475 if Etyp = T2 then
14476 return True;
14477
14478 -- Done if no more derivations to check
14479
14480 elsif T = T1
14481 or else T = Etyp
14482 then
14483 return False;
14484
14485 -- Following test catches error cases resulting from prev errors
14486
14487 elsif No (Etyp) then
14488 return False;
14489
14490 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
14491 return False;
14492
14493 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
14494 return False;
14495 end if;
14496
14497 T := Base_Type (Etyp);
14498 end loop;
14499 end if;
14500 end Is_Descendant_Of;
14501
14502 ----------------------------------------
14503 -- Is_Descendant_Of_Suspension_Object --
14504 ----------------------------------------
14505
14506 function Is_Descendant_Of_Suspension_Object
14507 (Typ : Entity_Id) return Boolean
14508 is
14509 Cur_Typ : Entity_Id;
14510 Par_Typ : Entity_Id;
14511
14512 begin
14513 -- Climb the type derivation chain checking each parent type against
14514 -- Suspension_Object.
14515
14516 Cur_Typ := Base_Type (Typ);
14517 while Present (Cur_Typ) loop
14518 Par_Typ := Etype (Cur_Typ);
14519
14520 -- The current type is a match
14521
14522 if Is_Suspension_Object (Cur_Typ) then
14523 return True;
14524
14525 -- Stop the traversal once the root of the derivation chain has been
14526 -- reached. In that case the current type is its own base type.
14527
14528 elsif Cur_Typ = Par_Typ then
14529 exit;
14530 end if;
14531
14532 Cur_Typ := Base_Type (Par_Typ);
14533 end loop;
14534
14535 return False;
14536 end Is_Descendant_Of_Suspension_Object;
14537
14538 ---------------------------------------------
14539 -- Is_Double_Precision_Floating_Point_Type --
14540 ---------------------------------------------
14541
14542 function Is_Double_Precision_Floating_Point_Type
14543 (E : Entity_Id) return Boolean is
14544 begin
14545 return Is_Floating_Point_Type (E)
14546 and then Machine_Radix_Value (E) = Uint_2
14547 and then Machine_Mantissa_Value (E) = UI_From_Int (53)
14548 and then Machine_Emax_Value (E) = Uint_2 ** Uint_10
14549 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_10);
14550 end Is_Double_Precision_Floating_Point_Type;
14551
14552 -----------------------------
14553 -- Is_Effectively_Volatile --
14554 -----------------------------
14555
14556 function Is_Effectively_Volatile (Id : Entity_Id) return Boolean is
14557 begin
14558 if Is_Type (Id) then
14559
14560 -- An arbitrary type is effectively volatile when it is subject to
14561 -- pragma Atomic or Volatile.
14562
14563 if Is_Volatile (Id) then
14564 return True;
14565
14566 -- An array type is effectively volatile when it is subject to pragma
14567 -- Atomic_Components or Volatile_Components or its component type is
14568 -- effectively volatile.
14569
14570 elsif Is_Array_Type (Id) then
14571 declare
14572 Anc : Entity_Id := Base_Type (Id);
14573 begin
14574 if Is_Private_Type (Anc) then
14575 Anc := Full_View (Anc);
14576 end if;
14577
14578 -- Test for presence of ancestor, as the full view of a private
14579 -- type may be missing in case of error.
14580
14581 return
14582 Has_Volatile_Components (Id)
14583 or else
14584 (Present (Anc)
14585 and then Is_Effectively_Volatile (Component_Type (Anc)));
14586 end;
14587
14588 -- A protected type is always volatile
14589
14590 elsif Is_Protected_Type (Id) then
14591 return True;
14592
14593 -- A descendant of Ada.Synchronous_Task_Control.Suspension_Object is
14594 -- automatically volatile.
14595
14596 elsif Is_Descendant_Of_Suspension_Object (Id) then
14597 return True;
14598
14599 -- Otherwise the type is not effectively volatile
14600
14601 else
14602 return False;
14603 end if;
14604
14605 -- Otherwise Id denotes an object
14606
14607 else
14608 -- A volatile object for which No_Caching is enabled is not
14609 -- effectively volatile.
14610
14611 return
14612 (Is_Volatile (Id) and then not No_Caching_Enabled (Id))
14613 or else Has_Volatile_Components (Id)
14614 or else Is_Effectively_Volatile (Etype (Id));
14615 end if;
14616 end Is_Effectively_Volatile;
14617
14618 ------------------------------------
14619 -- Is_Effectively_Volatile_Object --
14620 ------------------------------------
14621
14622 function Is_Effectively_Volatile_Object (N : Node_Id) return Boolean is
14623 begin
14624 if Is_Entity_Name (N) then
14625 return Is_Effectively_Volatile (Entity (N));
14626
14627 elsif Nkind (N) = N_Indexed_Component then
14628 return Is_Effectively_Volatile_Object (Prefix (N));
14629
14630 elsif Nkind (N) = N_Selected_Component then
14631 return
14632 Is_Effectively_Volatile_Object (Prefix (N))
14633 or else
14634 Is_Effectively_Volatile_Object (Selector_Name (N));
14635
14636 else
14637 return False;
14638 end if;
14639 end Is_Effectively_Volatile_Object;
14640
14641 -------------------
14642 -- Is_Entry_Body --
14643 -------------------
14644
14645 function Is_Entry_Body (Id : Entity_Id) return Boolean is
14646 begin
14647 return
14648 Ekind_In (Id, E_Entry, E_Entry_Family)
14649 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Body;
14650 end Is_Entry_Body;
14651
14652 --------------------------
14653 -- Is_Entry_Declaration --
14654 --------------------------
14655
14656 function Is_Entry_Declaration (Id : Entity_Id) return Boolean is
14657 begin
14658 return
14659 Ekind_In (Id, E_Entry, E_Entry_Family)
14660 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Declaration;
14661 end Is_Entry_Declaration;
14662
14663 ------------------------------------
14664 -- Is_Expanded_Priority_Attribute --
14665 ------------------------------------
14666
14667 function Is_Expanded_Priority_Attribute (E : Entity_Id) return Boolean is
14668 begin
14669 return
14670 Nkind (E) = N_Function_Call
14671 and then not Configurable_Run_Time_Mode
14672 and then Nkind (Original_Node (E)) = N_Attribute_Reference
14673 and then (Entity (Name (E)) = RTE (RE_Get_Ceiling)
14674 or else Entity (Name (E)) = RTE (RO_PE_Get_Ceiling));
14675 end Is_Expanded_Priority_Attribute;
14676
14677 ----------------------------
14678 -- Is_Expression_Function --
14679 ----------------------------
14680
14681 function Is_Expression_Function (Subp : Entity_Id) return Boolean is
14682 begin
14683 if Ekind_In (Subp, E_Function, E_Subprogram_Body) then
14684 return
14685 Nkind (Original_Node (Unit_Declaration_Node (Subp))) =
14686 N_Expression_Function;
14687 else
14688 return False;
14689 end if;
14690 end Is_Expression_Function;
14691
14692 ------------------------------------------
14693 -- Is_Expression_Function_Or_Completion --
14694 ------------------------------------------
14695
14696 function Is_Expression_Function_Or_Completion
14697 (Subp : Entity_Id) return Boolean
14698 is
14699 Subp_Decl : Node_Id;
14700
14701 begin
14702 if Ekind (Subp) = E_Function then
14703 Subp_Decl := Unit_Declaration_Node (Subp);
14704
14705 -- The function declaration is either an expression function or is
14706 -- completed by an expression function body.
14707
14708 return
14709 Is_Expression_Function (Subp)
14710 or else (Nkind (Subp_Decl) = N_Subprogram_Declaration
14711 and then Present (Corresponding_Body (Subp_Decl))
14712 and then Is_Expression_Function
14713 (Corresponding_Body (Subp_Decl)));
14714
14715 elsif Ekind (Subp) = E_Subprogram_Body then
14716 return Is_Expression_Function (Subp);
14717
14718 else
14719 return False;
14720 end if;
14721 end Is_Expression_Function_Or_Completion;
14722
14723 -----------------------
14724 -- Is_EVF_Expression --
14725 -----------------------
14726
14727 function Is_EVF_Expression (N : Node_Id) return Boolean is
14728 Orig_N : constant Node_Id := Original_Node (N);
14729 Alt : Node_Id;
14730 Expr : Node_Id;
14731 Id : Entity_Id;
14732
14733 begin
14734 -- Detect a reference to a formal parameter of a specific tagged type
14735 -- whose related subprogram is subject to pragma Expresions_Visible with
14736 -- value "False".
14737
14738 if Is_Entity_Name (N) and then Present (Entity (N)) then
14739 Id := Entity (N);
14740
14741 return
14742 Is_Formal (Id)
14743 and then Is_Specific_Tagged_Type (Etype (Id))
14744 and then Extensions_Visible_Status (Id) =
14745 Extensions_Visible_False;
14746
14747 -- A case expression is an EVF expression when it contains at least one
14748 -- EVF dependent_expression. Note that a case expression may have been
14749 -- expanded, hence the use of Original_Node.
14750
14751 elsif Nkind (Orig_N) = N_Case_Expression then
14752 Alt := First (Alternatives (Orig_N));
14753 while Present (Alt) loop
14754 if Is_EVF_Expression (Expression (Alt)) then
14755 return True;
14756 end if;
14757
14758 Next (Alt);
14759 end loop;
14760
14761 -- An if expression is an EVF expression when it contains at least one
14762 -- EVF dependent_expression. Note that an if expression may have been
14763 -- expanded, hence the use of Original_Node.
14764
14765 elsif Nkind (Orig_N) = N_If_Expression then
14766 Expr := Next (First (Expressions (Orig_N)));
14767 while Present (Expr) loop
14768 if Is_EVF_Expression (Expr) then
14769 return True;
14770 end if;
14771
14772 Next (Expr);
14773 end loop;
14774
14775 -- A qualified expression or a type conversion is an EVF expression when
14776 -- its operand is an EVF expression.
14777
14778 elsif Nkind_In (N, N_Qualified_Expression,
14779 N_Unchecked_Type_Conversion,
14780 N_Type_Conversion)
14781 then
14782 return Is_EVF_Expression (Expression (N));
14783
14784 -- Attributes 'Loop_Entry, 'Old, and 'Update are EVF expressions when
14785 -- their prefix denotes an EVF expression.
14786
14787 elsif Nkind (N) = N_Attribute_Reference
14788 and then Nam_In (Attribute_Name (N), Name_Loop_Entry,
14789 Name_Old,
14790 Name_Update)
14791 then
14792 return Is_EVF_Expression (Prefix (N));
14793 end if;
14794
14795 return False;
14796 end Is_EVF_Expression;
14797
14798 --------------
14799 -- Is_False --
14800 --------------
14801
14802 function Is_False (U : Uint) return Boolean is
14803 begin
14804 return (U = 0);
14805 end Is_False;
14806
14807 ---------------------------
14808 -- Is_Fixed_Model_Number --
14809 ---------------------------
14810
14811 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
14812 S : constant Ureal := Small_Value (T);
14813 M : Urealp.Save_Mark;
14814 R : Boolean;
14815
14816 begin
14817 M := Urealp.Mark;
14818 R := (U = UR_Trunc (U / S) * S);
14819 Urealp.Release (M);
14820 return R;
14821 end Is_Fixed_Model_Number;
14822
14823 -------------------------------
14824 -- Is_Fully_Initialized_Type --
14825 -------------------------------
14826
14827 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
14828 begin
14829 -- Scalar types
14830
14831 if Is_Scalar_Type (Typ) then
14832
14833 -- A scalar type with an aspect Default_Value is fully initialized
14834
14835 -- Note: Iniitalize/Normalize_Scalars also ensure full initialization
14836 -- of a scalar type, but we don't take that into account here, since
14837 -- we don't want these to affect warnings.
14838
14839 return Has_Default_Aspect (Typ);
14840
14841 elsif Is_Access_Type (Typ) then
14842 return True;
14843
14844 elsif Is_Array_Type (Typ) then
14845 if Is_Fully_Initialized_Type (Component_Type (Typ))
14846 or else (Ada_Version >= Ada_2012 and then Has_Default_Aspect (Typ))
14847 then
14848 return True;
14849 end if;
14850
14851 -- An interesting case, if we have a constrained type one of whose
14852 -- bounds is known to be null, then there are no elements to be
14853 -- initialized, so all the elements are initialized.
14854
14855 if Is_Constrained (Typ) then
14856 declare
14857 Indx : Node_Id;
14858 Indx_Typ : Entity_Id;
14859 Lbd, Hbd : Node_Id;
14860
14861 begin
14862 Indx := First_Index (Typ);
14863 while Present (Indx) loop
14864 if Etype (Indx) = Any_Type then
14865 return False;
14866
14867 -- If index is a range, use directly
14868
14869 elsif Nkind (Indx) = N_Range then
14870 Lbd := Low_Bound (Indx);
14871 Hbd := High_Bound (Indx);
14872
14873 else
14874 Indx_Typ := Etype (Indx);
14875
14876 if Is_Private_Type (Indx_Typ) then
14877 Indx_Typ := Full_View (Indx_Typ);
14878 end if;
14879
14880 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
14881 return False;
14882 else
14883 Lbd := Type_Low_Bound (Indx_Typ);
14884 Hbd := Type_High_Bound (Indx_Typ);
14885 end if;
14886 end if;
14887
14888 if Compile_Time_Known_Value (Lbd)
14889 and then
14890 Compile_Time_Known_Value (Hbd)
14891 then
14892 if Expr_Value (Hbd) < Expr_Value (Lbd) then
14893 return True;
14894 end if;
14895 end if;
14896
14897 Next_Index (Indx);
14898 end loop;
14899 end;
14900 end if;
14901
14902 -- If no null indexes, then type is not fully initialized
14903
14904 return False;
14905
14906 -- Record types
14907
14908 elsif Is_Record_Type (Typ) then
14909 if Has_Discriminants (Typ)
14910 and then
14911 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
14912 and then Is_Fully_Initialized_Variant (Typ)
14913 then
14914 return True;
14915 end if;
14916
14917 -- We consider bounded string types to be fully initialized, because
14918 -- otherwise we get false alarms when the Data component is not
14919 -- default-initialized.
14920
14921 if Is_Bounded_String (Typ) then
14922 return True;
14923 end if;
14924
14925 -- Controlled records are considered to be fully initialized if
14926 -- there is a user defined Initialize routine. This may not be
14927 -- entirely correct, but as the spec notes, we are guessing here
14928 -- what is best from the point of view of issuing warnings.
14929
14930 if Is_Controlled (Typ) then
14931 declare
14932 Utyp : constant Entity_Id := Underlying_Type (Typ);
14933
14934 begin
14935 if Present (Utyp) then
14936 declare
14937 Init : constant Entity_Id :=
14938 (Find_Optional_Prim_Op
14939 (Underlying_Type (Typ), Name_Initialize));
14940
14941 begin
14942 if Present (Init)
14943 and then Comes_From_Source (Init)
14944 and then not In_Predefined_Unit (Init)
14945 then
14946 return True;
14947
14948 elsif Has_Null_Extension (Typ)
14949 and then
14950 Is_Fully_Initialized_Type
14951 (Etype (Base_Type (Typ)))
14952 then
14953 return True;
14954 end if;
14955 end;
14956 end if;
14957 end;
14958 end if;
14959
14960 -- Otherwise see if all record components are initialized
14961
14962 declare
14963 Ent : Entity_Id;
14964
14965 begin
14966 Ent := First_Entity (Typ);
14967 while Present (Ent) loop
14968 if Ekind (Ent) = E_Component
14969 and then (No (Parent (Ent))
14970 or else No (Expression (Parent (Ent))))
14971 and then not Is_Fully_Initialized_Type (Etype (Ent))
14972
14973 -- Special VM case for tag components, which need to be
14974 -- defined in this case, but are never initialized as VMs
14975 -- are using other dispatching mechanisms. Ignore this
14976 -- uninitialized case. Note that this applies both to the
14977 -- uTag entry and the main vtable pointer (CPP_Class case).
14978
14979 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
14980 then
14981 return False;
14982 end if;
14983
14984 Next_Entity (Ent);
14985 end loop;
14986 end;
14987
14988 -- No uninitialized components, so type is fully initialized.
14989 -- Note that this catches the case of no components as well.
14990
14991 return True;
14992
14993 elsif Is_Concurrent_Type (Typ) then
14994 return True;
14995
14996 elsif Is_Private_Type (Typ) then
14997 declare
14998 U : constant Entity_Id := Underlying_Type (Typ);
14999
15000 begin
15001 if No (U) then
15002 return False;
15003 else
15004 return Is_Fully_Initialized_Type (U);
15005 end if;
15006 end;
15007
15008 else
15009 return False;
15010 end if;
15011 end Is_Fully_Initialized_Type;
15012
15013 ----------------------------------
15014 -- Is_Fully_Initialized_Variant --
15015 ----------------------------------
15016
15017 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
15018 Loc : constant Source_Ptr := Sloc (Typ);
15019 Constraints : constant List_Id := New_List;
15020 Components : constant Elist_Id := New_Elmt_List;
15021 Comp_Elmt : Elmt_Id;
15022 Comp_Id : Node_Id;
15023 Comp_List : Node_Id;
15024 Discr : Entity_Id;
15025 Discr_Val : Node_Id;
15026
15027 Report_Errors : Boolean;
15028 pragma Warnings (Off, Report_Errors);
15029
15030 begin
15031 if Serious_Errors_Detected > 0 then
15032 return False;
15033 end if;
15034
15035 if Is_Record_Type (Typ)
15036 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
15037 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
15038 then
15039 Comp_List := Component_List (Type_Definition (Parent (Typ)));
15040
15041 Discr := First_Discriminant (Typ);
15042 while Present (Discr) loop
15043 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
15044 Discr_Val := Expression (Parent (Discr));
15045
15046 if Present (Discr_Val)
15047 and then Is_OK_Static_Expression (Discr_Val)
15048 then
15049 Append_To (Constraints,
15050 Make_Component_Association (Loc,
15051 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
15052 Expression => New_Copy (Discr_Val)));
15053 else
15054 return False;
15055 end if;
15056 else
15057 return False;
15058 end if;
15059
15060 Next_Discriminant (Discr);
15061 end loop;
15062
15063 Gather_Components
15064 (Typ => Typ,
15065 Comp_List => Comp_List,
15066 Governed_By => Constraints,
15067 Into => Components,
15068 Report_Errors => Report_Errors);
15069
15070 -- Check that each component present is fully initialized
15071
15072 Comp_Elmt := First_Elmt (Components);
15073 while Present (Comp_Elmt) loop
15074 Comp_Id := Node (Comp_Elmt);
15075
15076 if Ekind (Comp_Id) = E_Component
15077 and then (No (Parent (Comp_Id))
15078 or else No (Expression (Parent (Comp_Id))))
15079 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
15080 then
15081 return False;
15082 end if;
15083
15084 Next_Elmt (Comp_Elmt);
15085 end loop;
15086
15087 return True;
15088
15089 elsif Is_Private_Type (Typ) then
15090 declare
15091 U : constant Entity_Id := Underlying_Type (Typ);
15092
15093 begin
15094 if No (U) then
15095 return False;
15096 else
15097 return Is_Fully_Initialized_Variant (U);
15098 end if;
15099 end;
15100
15101 else
15102 return False;
15103 end if;
15104 end Is_Fully_Initialized_Variant;
15105
15106 ------------------------------------
15107 -- Is_Generic_Declaration_Or_Body --
15108 ------------------------------------
15109
15110 function Is_Generic_Declaration_Or_Body (Decl : Node_Id) return Boolean is
15111 Spec_Decl : Node_Id;
15112
15113 begin
15114 -- Package/subprogram body
15115
15116 if Nkind_In (Decl, N_Package_Body, N_Subprogram_Body)
15117 and then Present (Corresponding_Spec (Decl))
15118 then
15119 Spec_Decl := Unit_Declaration_Node (Corresponding_Spec (Decl));
15120
15121 -- Package/subprogram body stub
15122
15123 elsif Nkind_In (Decl, N_Package_Body_Stub, N_Subprogram_Body_Stub)
15124 and then Present (Corresponding_Spec_Of_Stub (Decl))
15125 then
15126 Spec_Decl :=
15127 Unit_Declaration_Node (Corresponding_Spec_Of_Stub (Decl));
15128
15129 -- All other cases
15130
15131 else
15132 Spec_Decl := Decl;
15133 end if;
15134
15135 -- Rather than inspecting the defining entity of the spec declaration,
15136 -- look at its Nkind. This takes care of the case where the analysis of
15137 -- a generic body modifies the Ekind of its spec to allow for recursive
15138 -- calls.
15139
15140 return
15141 Nkind_In (Spec_Decl, N_Generic_Package_Declaration,
15142 N_Generic_Subprogram_Declaration);
15143 end Is_Generic_Declaration_Or_Body;
15144
15145 ----------------------------
15146 -- Is_Inherited_Operation --
15147 ----------------------------
15148
15149 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
15150 pragma Assert (Is_Overloadable (E));
15151 Kind : constant Node_Kind := Nkind (Parent (E));
15152 begin
15153 return Kind = N_Full_Type_Declaration
15154 or else Kind = N_Private_Extension_Declaration
15155 or else Kind = N_Subtype_Declaration
15156 or else (Ekind (E) = E_Enumeration_Literal
15157 and then Is_Derived_Type (Etype (E)));
15158 end Is_Inherited_Operation;
15159
15160 -------------------------------------
15161 -- Is_Inherited_Operation_For_Type --
15162 -------------------------------------
15163
15164 function Is_Inherited_Operation_For_Type
15165 (E : Entity_Id;
15166 Typ : Entity_Id) return Boolean
15167 is
15168 begin
15169 -- Check that the operation has been created by the type declaration
15170
15171 return Is_Inherited_Operation (E)
15172 and then Defining_Identifier (Parent (E)) = Typ;
15173 end Is_Inherited_Operation_For_Type;
15174
15175 --------------------------------------
15176 -- Is_Inlinable_Expression_Function --
15177 --------------------------------------
15178
15179 function Is_Inlinable_Expression_Function
15180 (Subp : Entity_Id) return Boolean
15181 is
15182 Return_Expr : Node_Id;
15183
15184 begin
15185 if Is_Expression_Function_Or_Completion (Subp)
15186 and then Has_Pragma_Inline_Always (Subp)
15187 and then Needs_No_Actuals (Subp)
15188 and then No (Contract (Subp))
15189 and then not Is_Dispatching_Operation (Subp)
15190 and then Needs_Finalization (Etype (Subp))
15191 and then not Is_Class_Wide_Type (Etype (Subp))
15192 and then not (Has_Invariants (Etype (Subp)))
15193 and then Present (Subprogram_Body (Subp))
15194 and then Was_Expression_Function (Subprogram_Body (Subp))
15195 then
15196 Return_Expr := Expression_Of_Expression_Function (Subp);
15197
15198 -- The returned object must not have a qualified expression and its
15199 -- nominal subtype must be statically compatible with the result
15200 -- subtype of the expression function.
15201
15202 return
15203 Nkind (Return_Expr) = N_Identifier
15204 and then Etype (Return_Expr) = Etype (Subp);
15205 end if;
15206
15207 return False;
15208 end Is_Inlinable_Expression_Function;
15209
15210 -----------------
15211 -- Is_Iterator --
15212 -----------------
15213
15214 function Is_Iterator (Typ : Entity_Id) return Boolean is
15215 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean;
15216 -- Determine whether type Iter_Typ is a predefined forward or reversible
15217 -- iterator.
15218
15219 ----------------------
15220 -- Denotes_Iterator --
15221 ----------------------
15222
15223 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean is
15224 begin
15225 -- Check that the name matches, and that the ultimate ancestor is in
15226 -- a predefined unit, i.e the one that declares iterator interfaces.
15227
15228 return
15229 Nam_In (Chars (Iter_Typ), Name_Forward_Iterator,
15230 Name_Reversible_Iterator)
15231 and then In_Predefined_Unit (Root_Type (Iter_Typ));
15232 end Denotes_Iterator;
15233
15234 -- Local variables
15235
15236 Iface_Elmt : Elmt_Id;
15237 Ifaces : Elist_Id;
15238
15239 -- Start of processing for Is_Iterator
15240
15241 begin
15242 -- The type may be a subtype of a descendant of the proper instance of
15243 -- the predefined interface type, so we must use the root type of the
15244 -- given type. The same is done for Is_Reversible_Iterator.
15245
15246 if Is_Class_Wide_Type (Typ)
15247 and then Denotes_Iterator (Root_Type (Typ))
15248 then
15249 return True;
15250
15251 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
15252 return False;
15253
15254 elsif Present (Find_Value_Of_Aspect (Typ, Aspect_Iterable)) then
15255 return True;
15256
15257 else
15258 Collect_Interfaces (Typ, Ifaces);
15259
15260 Iface_Elmt := First_Elmt (Ifaces);
15261 while Present (Iface_Elmt) loop
15262 if Denotes_Iterator (Node (Iface_Elmt)) then
15263 return True;
15264 end if;
15265
15266 Next_Elmt (Iface_Elmt);
15267 end loop;
15268
15269 return False;
15270 end if;
15271 end Is_Iterator;
15272
15273 ----------------------------
15274 -- Is_Iterator_Over_Array --
15275 ----------------------------
15276
15277 function Is_Iterator_Over_Array (N : Node_Id) return Boolean is
15278 Container : constant Node_Id := Name (N);
15279 Container_Typ : constant Entity_Id := Base_Type (Etype (Container));
15280 begin
15281 return Is_Array_Type (Container_Typ);
15282 end Is_Iterator_Over_Array;
15283
15284 ------------
15285 -- Is_LHS --
15286 ------------
15287
15288 -- We seem to have a lot of overlapping functions that do similar things
15289 -- (testing for left hand sides or lvalues???).
15290
15291 function Is_LHS (N : Node_Id) return Is_LHS_Result is
15292 P : constant Node_Id := Parent (N);
15293
15294 begin
15295 -- Return True if we are the left hand side of an assignment statement
15296
15297 if Nkind (P) = N_Assignment_Statement then
15298 if Name (P) = N then
15299 return Yes;
15300 else
15301 return No;
15302 end if;
15303
15304 -- Case of prefix of indexed or selected component or slice
15305
15306 elsif Nkind_In (P, N_Indexed_Component, N_Selected_Component, N_Slice)
15307 and then N = Prefix (P)
15308 then
15309 -- Here we have the case where the parent P is N.Q or N(Q .. R).
15310 -- If P is an LHS, then N is also effectively an LHS, but there
15311 -- is an important exception. If N is of an access type, then
15312 -- what we really have is N.all.Q (or N.all(Q .. R)). In either
15313 -- case this makes N.all a left hand side but not N itself.
15314
15315 -- If we don't know the type yet, this is the case where we return
15316 -- Unknown, since the answer depends on the type which is unknown.
15317
15318 if No (Etype (N)) then
15319 return Unknown;
15320
15321 -- We have an Etype set, so we can check it
15322
15323 elsif Is_Access_Type (Etype (N)) then
15324 return No;
15325
15326 -- OK, not access type case, so just test whole expression
15327
15328 else
15329 return Is_LHS (P);
15330 end if;
15331
15332 -- All other cases are not left hand sides
15333
15334 else
15335 return No;
15336 end if;
15337 end Is_LHS;
15338
15339 -----------------------------
15340 -- Is_Library_Level_Entity --
15341 -----------------------------
15342
15343 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
15344 begin
15345 -- The following is a small optimization, and it also properly handles
15346 -- discriminals, which in task bodies might appear in expressions before
15347 -- the corresponding procedure has been created, and which therefore do
15348 -- not have an assigned scope.
15349
15350 if Is_Formal (E) then
15351 return False;
15352 end if;
15353
15354 -- Normal test is simply that the enclosing dynamic scope is Standard
15355
15356 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
15357 end Is_Library_Level_Entity;
15358
15359 --------------------------------
15360 -- Is_Limited_Class_Wide_Type --
15361 --------------------------------
15362
15363 function Is_Limited_Class_Wide_Type (Typ : Entity_Id) return Boolean is
15364 begin
15365 return
15366 Is_Class_Wide_Type (Typ)
15367 and then (Is_Limited_Type (Typ) or else From_Limited_With (Typ));
15368 end Is_Limited_Class_Wide_Type;
15369
15370 ---------------------------------
15371 -- Is_Local_Variable_Reference --
15372 ---------------------------------
15373
15374 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
15375 begin
15376 if not Is_Entity_Name (Expr) then
15377 return False;
15378
15379 else
15380 declare
15381 Ent : constant Entity_Id := Entity (Expr);
15382 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
15383 begin
15384 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
15385 return False;
15386 else
15387 return Present (Sub) and then Sub = Current_Subprogram;
15388 end if;
15389 end;
15390 end if;
15391 end Is_Local_Variable_Reference;
15392
15393 -----------------------
15394 -- Is_Name_Reference --
15395 -----------------------
15396
15397 function Is_Name_Reference (N : Node_Id) return Boolean is
15398 begin
15399 if Is_Entity_Name (N) then
15400 return Present (Entity (N)) and then Is_Object (Entity (N));
15401 end if;
15402
15403 case Nkind (N) is
15404 when N_Indexed_Component
15405 | N_Slice
15406 =>
15407 return
15408 Is_Name_Reference (Prefix (N))
15409 or else Is_Access_Type (Etype (Prefix (N)));
15410
15411 -- Attributes 'Input, 'Old and 'Result produce objects
15412
15413 when N_Attribute_Reference =>
15414 return
15415 Nam_In (Attribute_Name (N), Name_Input, Name_Old, Name_Result);
15416
15417 when N_Selected_Component =>
15418 return
15419 Is_Name_Reference (Selector_Name (N))
15420 and then
15421 (Is_Name_Reference (Prefix (N))
15422 or else Is_Access_Type (Etype (Prefix (N))));
15423
15424 when N_Explicit_Dereference =>
15425 return True;
15426
15427 -- A view conversion of a tagged name is a name reference
15428
15429 when N_Type_Conversion =>
15430 return
15431 Is_Tagged_Type (Etype (Subtype_Mark (N)))
15432 and then Is_Tagged_Type (Etype (Expression (N)))
15433 and then Is_Name_Reference (Expression (N));
15434
15435 -- An unchecked type conversion is considered to be a name if the
15436 -- operand is a name (this construction arises only as a result of
15437 -- expansion activities).
15438
15439 when N_Unchecked_Type_Conversion =>
15440 return Is_Name_Reference (Expression (N));
15441
15442 when others =>
15443 return False;
15444 end case;
15445 end Is_Name_Reference;
15446
15447 ------------------------------------
15448 -- Is_Non_Preelaborable_Construct --
15449 ------------------------------------
15450
15451 function Is_Non_Preelaborable_Construct (N : Node_Id) return Boolean is
15452
15453 -- NOTE: the routines within Is_Non_Preelaborable_Construct are
15454 -- intentionally unnested to avoid deep indentation of code.
15455
15456 Non_Preelaborable : exception;
15457 -- This exception is raised when the construct violates preelaborability
15458 -- to terminate the recursion.
15459
15460 procedure Visit (Nod : Node_Id);
15461 -- Semantically inspect construct Nod to determine whether it violates
15462 -- preelaborability. This routine raises Non_Preelaborable.
15463
15464 procedure Visit_List (List : List_Id);
15465 pragma Inline (Visit_List);
15466 -- Invoke Visit on each element of list List. This routine raises
15467 -- Non_Preelaborable.
15468
15469 procedure Visit_Pragma (Prag : Node_Id);
15470 pragma Inline (Visit_Pragma);
15471 -- Semantically inspect pragma Prag to determine whether it violates
15472 -- preelaborability. This routine raises Non_Preelaborable.
15473
15474 procedure Visit_Subexpression (Expr : Node_Id);
15475 pragma Inline (Visit_Subexpression);
15476 -- Semantically inspect expression Expr to determine whether it violates
15477 -- preelaborability. This routine raises Non_Preelaborable.
15478
15479 -----------
15480 -- Visit --
15481 -----------
15482
15483 procedure Visit (Nod : Node_Id) is
15484 begin
15485 case Nkind (Nod) is
15486
15487 -- Declarations
15488
15489 when N_Component_Declaration =>
15490
15491 -- Defining_Identifier is left out because it is not relevant
15492 -- for preelaborability.
15493
15494 Visit (Component_Definition (Nod));
15495 Visit (Expression (Nod));
15496
15497 when N_Derived_Type_Definition =>
15498
15499 -- Interface_List is left out because it is not relevant for
15500 -- preelaborability.
15501
15502 Visit (Record_Extension_Part (Nod));
15503 Visit (Subtype_Indication (Nod));
15504
15505 when N_Entry_Declaration =>
15506
15507 -- A protected type with at leat one entry is not preelaborable
15508 -- while task types are never preelaborable. This renders entry
15509 -- declarations non-preelaborable.
15510
15511 raise Non_Preelaborable;
15512
15513 when N_Full_Type_Declaration =>
15514
15515 -- Defining_Identifier and Discriminant_Specifications are left
15516 -- out because they are not relevant for preelaborability.
15517
15518 Visit (Type_Definition (Nod));
15519
15520 when N_Function_Instantiation
15521 | N_Package_Instantiation
15522 | N_Procedure_Instantiation
15523 =>
15524 -- Defining_Unit_Name and Name are left out because they are
15525 -- not relevant for preelaborability.
15526
15527 Visit_List (Generic_Associations (Nod));
15528
15529 when N_Object_Declaration =>
15530
15531 -- Defining_Identifier is left out because it is not relevant
15532 -- for preelaborability.
15533
15534 Visit (Object_Definition (Nod));
15535
15536 if Has_Init_Expression (Nod) then
15537 Visit (Expression (Nod));
15538
15539 elsif not Has_Preelaborable_Initialization
15540 (Etype (Defining_Entity (Nod)))
15541 then
15542 raise Non_Preelaborable;
15543 end if;
15544
15545 when N_Private_Extension_Declaration
15546 | N_Subtype_Declaration
15547 =>
15548 -- Defining_Identifier, Discriminant_Specifications, and
15549 -- Interface_List are left out because they are not relevant
15550 -- for preelaborability.
15551
15552 Visit (Subtype_Indication (Nod));
15553
15554 when N_Protected_Type_Declaration
15555 | N_Single_Protected_Declaration
15556 =>
15557 -- Defining_Identifier, Discriminant_Specifications, and
15558 -- Interface_List are left out because they are not relevant
15559 -- for preelaborability.
15560
15561 Visit (Protected_Definition (Nod));
15562
15563 -- A [single] task type is never preelaborable
15564
15565 when N_Single_Task_Declaration
15566 | N_Task_Type_Declaration
15567 =>
15568 raise Non_Preelaborable;
15569
15570 -- Pragmas
15571
15572 when N_Pragma =>
15573 Visit_Pragma (Nod);
15574
15575 -- Statements
15576
15577 when N_Statement_Other_Than_Procedure_Call =>
15578 if Nkind (Nod) /= N_Null_Statement then
15579 raise Non_Preelaborable;
15580 end if;
15581
15582 -- Subexpressions
15583
15584 when N_Subexpr =>
15585 Visit_Subexpression (Nod);
15586
15587 -- Special
15588
15589 when N_Access_To_Object_Definition =>
15590 Visit (Subtype_Indication (Nod));
15591
15592 when N_Case_Expression_Alternative =>
15593 Visit (Expression (Nod));
15594 Visit_List (Discrete_Choices (Nod));
15595
15596 when N_Component_Definition =>
15597 Visit (Access_Definition (Nod));
15598 Visit (Subtype_Indication (Nod));
15599
15600 when N_Component_List =>
15601 Visit_List (Component_Items (Nod));
15602 Visit (Variant_Part (Nod));
15603
15604 when N_Constrained_Array_Definition =>
15605 Visit_List (Discrete_Subtype_Definitions (Nod));
15606 Visit (Component_Definition (Nod));
15607
15608 when N_Delta_Constraint
15609 | N_Digits_Constraint
15610 =>
15611 -- Delta_Expression and Digits_Expression are left out because
15612 -- they are not relevant for preelaborability.
15613
15614 Visit (Range_Constraint (Nod));
15615
15616 when N_Discriminant_Specification =>
15617
15618 -- Defining_Identifier and Expression are left out because they
15619 -- are not relevant for preelaborability.
15620
15621 Visit (Discriminant_Type (Nod));
15622
15623 when N_Generic_Association =>
15624
15625 -- Selector_Name is left out because it is not relevant for
15626 -- preelaborability.
15627
15628 Visit (Explicit_Generic_Actual_Parameter (Nod));
15629
15630 when N_Index_Or_Discriminant_Constraint =>
15631 Visit_List (Constraints (Nod));
15632
15633 when N_Iterator_Specification =>
15634
15635 -- Defining_Identifier is left out because it is not relevant
15636 -- for preelaborability.
15637
15638 Visit (Name (Nod));
15639 Visit (Subtype_Indication (Nod));
15640
15641 when N_Loop_Parameter_Specification =>
15642
15643 -- Defining_Identifier is left out because it is not relevant
15644 -- for preelaborability.
15645
15646 Visit (Discrete_Subtype_Definition (Nod));
15647
15648 when N_Protected_Definition =>
15649
15650 -- End_Label is left out because it is not relevant for
15651 -- preelaborability.
15652
15653 Visit_List (Private_Declarations (Nod));
15654 Visit_List (Visible_Declarations (Nod));
15655
15656 when N_Range_Constraint =>
15657 Visit (Range_Expression (Nod));
15658
15659 when N_Record_Definition
15660 | N_Variant
15661 =>
15662 -- End_Label, Discrete_Choices, and Interface_List are left out
15663 -- because they are not relevant for preelaborability.
15664
15665 Visit (Component_List (Nod));
15666
15667 when N_Subtype_Indication =>
15668
15669 -- Subtype_Mark is left out because it is not relevant for
15670 -- preelaborability.
15671
15672 Visit (Constraint (Nod));
15673
15674 when N_Unconstrained_Array_Definition =>
15675
15676 -- Subtype_Marks is left out because it is not relevant for
15677 -- preelaborability.
15678
15679 Visit (Component_Definition (Nod));
15680
15681 when N_Variant_Part =>
15682
15683 -- Name is left out because it is not relevant for
15684 -- preelaborability.
15685
15686 Visit_List (Variants (Nod));
15687
15688 -- Default
15689
15690 when others =>
15691 null;
15692 end case;
15693 end Visit;
15694
15695 ----------------
15696 -- Visit_List --
15697 ----------------
15698
15699 procedure Visit_List (List : List_Id) is
15700 Nod : Node_Id;
15701
15702 begin
15703 if Present (List) then
15704 Nod := First (List);
15705 while Present (Nod) loop
15706 Visit (Nod);
15707 Next (Nod);
15708 end loop;
15709 end if;
15710 end Visit_List;
15711
15712 ------------------
15713 -- Visit_Pragma --
15714 ------------------
15715
15716 procedure Visit_Pragma (Prag : Node_Id) is
15717 begin
15718 case Get_Pragma_Id (Prag) is
15719 when Pragma_Assert
15720 | Pragma_Assert_And_Cut
15721 | Pragma_Assume
15722 | Pragma_Async_Readers
15723 | Pragma_Async_Writers
15724 | Pragma_Attribute_Definition
15725 | Pragma_Check
15726 | Pragma_Constant_After_Elaboration
15727 | Pragma_CPU
15728 | Pragma_Deadline_Floor
15729 | Pragma_Dispatching_Domain
15730 | Pragma_Effective_Reads
15731 | Pragma_Effective_Writes
15732 | Pragma_Extensions_Visible
15733 | Pragma_Ghost
15734 | Pragma_Secondary_Stack_Size
15735 | Pragma_Task_Name
15736 | Pragma_Volatile_Function
15737 =>
15738 Visit_List (Pragma_Argument_Associations (Prag));
15739
15740 -- Default
15741
15742 when others =>
15743 null;
15744 end case;
15745 end Visit_Pragma;
15746
15747 -------------------------
15748 -- Visit_Subexpression --
15749 -------------------------
15750
15751 procedure Visit_Subexpression (Expr : Node_Id) is
15752 procedure Visit_Aggregate (Aggr : Node_Id);
15753 pragma Inline (Visit_Aggregate);
15754 -- Semantically inspect aggregate Aggr to determine whether it
15755 -- violates preelaborability.
15756
15757 ---------------------
15758 -- Visit_Aggregate --
15759 ---------------------
15760
15761 procedure Visit_Aggregate (Aggr : Node_Id) is
15762 begin
15763 if not Is_Preelaborable_Aggregate (Aggr) then
15764 raise Non_Preelaborable;
15765 end if;
15766 end Visit_Aggregate;
15767
15768 -- Start of processing for Visit_Subexpression
15769
15770 begin
15771 case Nkind (Expr) is
15772 when N_Allocator
15773 | N_Qualified_Expression
15774 | N_Type_Conversion
15775 | N_Unchecked_Expression
15776 | N_Unchecked_Type_Conversion
15777 =>
15778 -- Subpool_Handle_Name and Subtype_Mark are left out because
15779 -- they are not relevant for preelaborability.
15780
15781 Visit (Expression (Expr));
15782
15783 when N_Aggregate
15784 | N_Extension_Aggregate
15785 =>
15786 Visit_Aggregate (Expr);
15787
15788 when N_Attribute_Reference
15789 | N_Explicit_Dereference
15790 | N_Reference
15791 =>
15792 -- Attribute_Name and Expressions are left out because they are
15793 -- not relevant for preelaborability.
15794
15795 Visit (Prefix (Expr));
15796
15797 when N_Case_Expression =>
15798
15799 -- End_Span is left out because it is not relevant for
15800 -- preelaborability.
15801
15802 Visit_List (Alternatives (Expr));
15803 Visit (Expression (Expr));
15804
15805 when N_Delta_Aggregate =>
15806 Visit_Aggregate (Expr);
15807 Visit (Expression (Expr));
15808
15809 when N_Expression_With_Actions =>
15810 Visit_List (Actions (Expr));
15811 Visit (Expression (Expr));
15812
15813 when N_If_Expression =>
15814 Visit_List (Expressions (Expr));
15815
15816 when N_Quantified_Expression =>
15817 Visit (Condition (Expr));
15818 Visit (Iterator_Specification (Expr));
15819 Visit (Loop_Parameter_Specification (Expr));
15820
15821 when N_Range =>
15822 Visit (High_Bound (Expr));
15823 Visit (Low_Bound (Expr));
15824
15825 when N_Slice =>
15826 Visit (Discrete_Range (Expr));
15827 Visit (Prefix (Expr));
15828
15829 -- Default
15830
15831 when others =>
15832
15833 -- The evaluation of an object name is not preelaborable,
15834 -- unless the name is a static expression (checked further
15835 -- below), or statically denotes a discriminant.
15836
15837 if Is_Entity_Name (Expr) then
15838 Object_Name : declare
15839 Id : constant Entity_Id := Entity (Expr);
15840
15841 begin
15842 if Is_Object (Id) then
15843 if Ekind (Id) = E_Discriminant then
15844 null;
15845
15846 elsif Ekind_In (Id, E_Constant, E_In_Parameter)
15847 and then Present (Discriminal_Link (Id))
15848 then
15849 null;
15850
15851 else
15852 raise Non_Preelaborable;
15853 end if;
15854 end if;
15855 end Object_Name;
15856
15857 -- A non-static expression is not preelaborable
15858
15859 elsif not Is_OK_Static_Expression (Expr) then
15860 raise Non_Preelaborable;
15861 end if;
15862 end case;
15863 end Visit_Subexpression;
15864
15865 -- Start of processing for Is_Non_Preelaborable_Construct
15866
15867 begin
15868 Visit (N);
15869
15870 -- At this point it is known that the construct is preelaborable
15871
15872 return False;
15873
15874 exception
15875
15876 -- The elaboration of the construct performs an action which violates
15877 -- preelaborability.
15878
15879 when Non_Preelaborable =>
15880 return True;
15881 end Is_Non_Preelaborable_Construct;
15882
15883 ---------------------------------
15884 -- Is_Nontrivial_DIC_Procedure --
15885 ---------------------------------
15886
15887 function Is_Nontrivial_DIC_Procedure (Id : Entity_Id) return Boolean is
15888 Body_Decl : Node_Id;
15889 Stmt : Node_Id;
15890
15891 begin
15892 if Ekind (Id) = E_Procedure and then Is_DIC_Procedure (Id) then
15893 Body_Decl :=
15894 Unit_Declaration_Node
15895 (Corresponding_Body (Unit_Declaration_Node (Id)));
15896
15897 -- The body of the Default_Initial_Condition procedure must contain
15898 -- at least one statement, otherwise the generation of the subprogram
15899 -- body failed.
15900
15901 pragma Assert (Present (Handled_Statement_Sequence (Body_Decl)));
15902
15903 -- To qualify as nontrivial, the first statement of the procedure
15904 -- must be a check in the form of an if statement. If the original
15905 -- Default_Initial_Condition expression was folded, then the first
15906 -- statement is not a check.
15907
15908 Stmt := First (Statements (Handled_Statement_Sequence (Body_Decl)));
15909
15910 return
15911 Nkind (Stmt) = N_If_Statement
15912 and then Nkind (Original_Node (Stmt)) = N_Pragma;
15913 end if;
15914
15915 return False;
15916 end Is_Nontrivial_DIC_Procedure;
15917
15918 -------------------------
15919 -- Is_Null_Record_Type --
15920 -------------------------
15921
15922 function Is_Null_Record_Type (T : Entity_Id) return Boolean is
15923 Decl : constant Node_Id := Parent (T);
15924 begin
15925 return Nkind (Decl) = N_Full_Type_Declaration
15926 and then Nkind (Type_Definition (Decl)) = N_Record_Definition
15927 and then
15928 (No (Component_List (Type_Definition (Decl)))
15929 or else Null_Present (Component_List (Type_Definition (Decl))));
15930 end Is_Null_Record_Type;
15931
15932 ---------------------
15933 -- Is_Object_Image --
15934 ---------------------
15935
15936 function Is_Object_Image (Prefix : Node_Id) return Boolean is
15937 begin
15938 -- When the type of the prefix is not scalar, then the prefix is not
15939 -- valid in any scenario.
15940
15941 if not Is_Scalar_Type (Etype (Prefix)) then
15942 return False;
15943 end if;
15944
15945 -- Here we test for the case that the prefix is not a type and assume
15946 -- if it is not then it must be a named value or an object reference.
15947 -- This is because the parser always checks that prefixes of attributes
15948 -- are named.
15949
15950 return not (Is_Entity_Name (Prefix) and then Is_Type (Entity (Prefix)));
15951 end Is_Object_Image;
15952
15953 -------------------------
15954 -- Is_Object_Reference --
15955 -------------------------
15956
15957 function Is_Object_Reference (N : Node_Id) return Boolean is
15958 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean;
15959 -- Determine whether N is the name of an internally-generated renaming
15960
15961 --------------------------------------
15962 -- Is_Internally_Generated_Renaming --
15963 --------------------------------------
15964
15965 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean is
15966 P : Node_Id;
15967
15968 begin
15969 P := N;
15970 while Present (P) loop
15971 if Nkind (P) = N_Object_Renaming_Declaration then
15972 return not Comes_From_Source (P);
15973 elsif Is_List_Member (P) then
15974 return False;
15975 end if;
15976
15977 P := Parent (P);
15978 end loop;
15979
15980 return False;
15981 end Is_Internally_Generated_Renaming;
15982
15983 -- Start of processing for Is_Object_Reference
15984
15985 begin
15986 if Is_Entity_Name (N) then
15987 return Present (Entity (N)) and then Is_Object (Entity (N));
15988
15989 else
15990 case Nkind (N) is
15991 when N_Indexed_Component
15992 | N_Slice
15993 =>
15994 return
15995 Is_Object_Reference (Prefix (N))
15996 or else Is_Access_Type (Etype (Prefix (N)));
15997
15998 -- In Ada 95, a function call is a constant object; a procedure
15999 -- call is not.
16000
16001 -- Note that predefined operators are functions as well, and so
16002 -- are attributes that are (can be renamed as) functions.
16003
16004 when N_Binary_Op
16005 | N_Function_Call
16006 | N_Unary_Op
16007 =>
16008 return Etype (N) /= Standard_Void_Type;
16009
16010 -- Attributes references 'Loop_Entry, 'Old, and 'Result yield
16011 -- objects, even though they are not functions.
16012
16013 when N_Attribute_Reference =>
16014 return
16015 Nam_In (Attribute_Name (N), Name_Loop_Entry,
16016 Name_Old,
16017 Name_Result)
16018 or else Is_Function_Attribute_Name (Attribute_Name (N));
16019
16020 when N_Selected_Component =>
16021 return
16022 Is_Object_Reference (Selector_Name (N))
16023 and then
16024 (Is_Object_Reference (Prefix (N))
16025 or else Is_Access_Type (Etype (Prefix (N))));
16026
16027 -- An explicit dereference denotes an object, except that a
16028 -- conditional expression gets turned into an explicit dereference
16029 -- in some cases, and conditional expressions are not object
16030 -- names.
16031
16032 when N_Explicit_Dereference =>
16033 return not Nkind_In (Original_Node (N), N_Case_Expression,
16034 N_If_Expression);
16035
16036 -- A view conversion of a tagged object is an object reference
16037
16038 when N_Type_Conversion =>
16039 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
16040 and then Is_Tagged_Type (Etype (Expression (N)))
16041 and then Is_Object_Reference (Expression (N));
16042
16043 -- An unchecked type conversion is considered to be an object if
16044 -- the operand is an object (this construction arises only as a
16045 -- result of expansion activities).
16046
16047 when N_Unchecked_Type_Conversion =>
16048 return True;
16049
16050 -- Allow string literals to act as objects as long as they appear
16051 -- in internally-generated renamings. The expansion of iterators
16052 -- may generate such renamings when the range involves a string
16053 -- literal.
16054
16055 when N_String_Literal =>
16056 return Is_Internally_Generated_Renaming (Parent (N));
16057
16058 -- AI05-0003: In Ada 2012 a qualified expression is a name.
16059 -- This allows disambiguation of function calls and the use
16060 -- of aggregates in more contexts.
16061
16062 when N_Qualified_Expression =>
16063 if Ada_Version < Ada_2012 then
16064 return False;
16065 else
16066 return Is_Object_Reference (Expression (N))
16067 or else Nkind (Expression (N)) = N_Aggregate;
16068 end if;
16069
16070 when others =>
16071 return False;
16072 end case;
16073 end if;
16074 end Is_Object_Reference;
16075
16076 -----------------------------------
16077 -- Is_OK_Variable_For_Out_Formal --
16078 -----------------------------------
16079
16080 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
16081 begin
16082 Note_Possible_Modification (AV, Sure => True);
16083
16084 -- We must reject parenthesized variable names. Comes_From_Source is
16085 -- checked because there are currently cases where the compiler violates
16086 -- this rule (e.g. passing a task object to its controlled Initialize
16087 -- routine). This should be properly documented in sinfo???
16088
16089 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
16090 return False;
16091
16092 -- A variable is always allowed
16093
16094 elsif Is_Variable (AV) then
16095 return True;
16096
16097 -- Generalized indexing operations are rewritten as explicit
16098 -- dereferences, and it is only during resolution that we can
16099 -- check whether the context requires an access_to_variable type.
16100
16101 elsif Nkind (AV) = N_Explicit_Dereference
16102 and then Ada_Version >= Ada_2012
16103 and then Nkind (Original_Node (AV)) = N_Indexed_Component
16104 and then Present (Etype (Original_Node (AV)))
16105 and then Has_Implicit_Dereference (Etype (Original_Node (AV)))
16106 then
16107 return not Is_Access_Constant (Etype (Prefix (AV)));
16108
16109 -- Unchecked conversions are allowed only if they come from the
16110 -- generated code, which sometimes uses unchecked conversions for out
16111 -- parameters in cases where code generation is unaffected. We tell
16112 -- source unchecked conversions by seeing if they are rewrites of
16113 -- an original Unchecked_Conversion function call, or of an explicit
16114 -- conversion of a function call or an aggregate (as may happen in the
16115 -- expansion of a packed array aggregate).
16116
16117 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
16118 if Nkind_In (Original_Node (AV), N_Function_Call, N_Aggregate) then
16119 return False;
16120
16121 elsif Comes_From_Source (AV)
16122 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
16123 then
16124 return False;
16125
16126 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
16127 return Is_OK_Variable_For_Out_Formal (Expression (AV));
16128
16129 else
16130 return True;
16131 end if;
16132
16133 -- Normal type conversions are allowed if argument is a variable
16134
16135 elsif Nkind (AV) = N_Type_Conversion then
16136 if Is_Variable (Expression (AV))
16137 and then Paren_Count (Expression (AV)) = 0
16138 then
16139 Note_Possible_Modification (Expression (AV), Sure => True);
16140 return True;
16141
16142 -- We also allow a non-parenthesized expression that raises
16143 -- constraint error if it rewrites what used to be a variable
16144
16145 elsif Raises_Constraint_Error (Expression (AV))
16146 and then Paren_Count (Expression (AV)) = 0
16147 and then Is_Variable (Original_Node (Expression (AV)))
16148 then
16149 return True;
16150
16151 -- Type conversion of something other than a variable
16152
16153 else
16154 return False;
16155 end if;
16156
16157 -- If this node is rewritten, then test the original form, if that is
16158 -- OK, then we consider the rewritten node OK (for example, if the
16159 -- original node is a conversion, then Is_Variable will not be true
16160 -- but we still want to allow the conversion if it converts a variable).
16161
16162 elsif Is_Rewrite_Substitution (AV) then
16163
16164 -- In Ada 2012, the explicit dereference may be a rewritten call to a
16165 -- Reference function.
16166
16167 if Ada_Version >= Ada_2012
16168 and then Nkind (Original_Node (AV)) = N_Function_Call
16169 and then
16170 Has_Implicit_Dereference (Etype (Name (Original_Node (AV))))
16171 then
16172
16173 -- Check that this is not a constant reference.
16174
16175 return not Is_Access_Constant (Etype (Prefix (AV)));
16176
16177 elsif Has_Implicit_Dereference (Etype (Original_Node (AV))) then
16178 return
16179 not Is_Access_Constant (Etype
16180 (Get_Reference_Discriminant (Etype (Original_Node (AV)))));
16181
16182 else
16183 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
16184 end if;
16185
16186 -- All other non-variables are rejected
16187
16188 else
16189 return False;
16190 end if;
16191 end Is_OK_Variable_For_Out_Formal;
16192
16193 ----------------------------
16194 -- Is_OK_Volatile_Context --
16195 ----------------------------
16196
16197 function Is_OK_Volatile_Context
16198 (Context : Node_Id;
16199 Obj_Ref : Node_Id) return Boolean
16200 is
16201 function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean;
16202 -- Determine whether an arbitrary node denotes a call to a protected
16203 -- entry, function, or procedure in prefixed form where the prefix is
16204 -- Obj_Ref.
16205
16206 function Within_Check (Nod : Node_Id) return Boolean;
16207 -- Determine whether an arbitrary node appears in a check node
16208
16209 function Within_Volatile_Function (Id : Entity_Id) return Boolean;
16210 -- Determine whether an arbitrary entity appears in a volatile function
16211
16212 ---------------------------------
16213 -- Is_Protected_Operation_Call --
16214 ---------------------------------
16215
16216 function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean is
16217 Pref : Node_Id;
16218 Subp : Node_Id;
16219
16220 begin
16221 -- A call to a protected operations retains its selected component
16222 -- form as opposed to other prefixed calls that are transformed in
16223 -- expanded names.
16224
16225 if Nkind (Nod) = N_Selected_Component then
16226 Pref := Prefix (Nod);
16227 Subp := Selector_Name (Nod);
16228
16229 return
16230 Pref = Obj_Ref
16231 and then Present (Etype (Pref))
16232 and then Is_Protected_Type (Etype (Pref))
16233 and then Is_Entity_Name (Subp)
16234 and then Present (Entity (Subp))
16235 and then Ekind_In (Entity (Subp), E_Entry,
16236 E_Entry_Family,
16237 E_Function,
16238 E_Procedure);
16239 else
16240 return False;
16241 end if;
16242 end Is_Protected_Operation_Call;
16243
16244 ------------------
16245 -- Within_Check --
16246 ------------------
16247
16248 function Within_Check (Nod : Node_Id) return Boolean is
16249 Par : Node_Id;
16250
16251 begin
16252 -- Climb the parent chain looking for a check node
16253
16254 Par := Nod;
16255 while Present (Par) loop
16256 if Nkind (Par) in N_Raise_xxx_Error then
16257 return True;
16258
16259 -- Prevent the search from going too far
16260
16261 elsif Is_Body_Or_Package_Declaration (Par) then
16262 exit;
16263 end if;
16264
16265 Par := Parent (Par);
16266 end loop;
16267
16268 return False;
16269 end Within_Check;
16270
16271 ------------------------------
16272 -- Within_Volatile_Function --
16273 ------------------------------
16274
16275 function Within_Volatile_Function (Id : Entity_Id) return Boolean is
16276 Func_Id : Entity_Id;
16277
16278 begin
16279 -- Traverse the scope stack looking for a [generic] function
16280
16281 Func_Id := Id;
16282 while Present (Func_Id) and then Func_Id /= Standard_Standard loop
16283 if Ekind_In (Func_Id, E_Function, E_Generic_Function) then
16284 return Is_Volatile_Function (Func_Id);
16285 end if;
16286
16287 Func_Id := Scope (Func_Id);
16288 end loop;
16289
16290 return False;
16291 end Within_Volatile_Function;
16292
16293 -- Local variables
16294
16295 Obj_Id : Entity_Id;
16296
16297 -- Start of processing for Is_OK_Volatile_Context
16298
16299 begin
16300 -- The volatile object appears on either side of an assignment
16301
16302 if Nkind (Context) = N_Assignment_Statement then
16303 return True;
16304
16305 -- The volatile object is part of the initialization expression of
16306 -- another object.
16307
16308 elsif Nkind (Context) = N_Object_Declaration
16309 and then Present (Expression (Context))
16310 and then Expression (Context) = Obj_Ref
16311 then
16312 Obj_Id := Defining_Entity (Context);
16313
16314 -- The volatile object acts as the initialization expression of an
16315 -- extended return statement. This is valid context as long as the
16316 -- function is volatile.
16317
16318 if Is_Return_Object (Obj_Id) then
16319 return Within_Volatile_Function (Obj_Id);
16320
16321 -- Otherwise this is a normal object initialization
16322
16323 else
16324 return True;
16325 end if;
16326
16327 -- The volatile object acts as the name of a renaming declaration
16328
16329 elsif Nkind (Context) = N_Object_Renaming_Declaration
16330 and then Name (Context) = Obj_Ref
16331 then
16332 return True;
16333
16334 -- The volatile object appears as an actual parameter in a call to an
16335 -- instance of Unchecked_Conversion whose result is renamed.
16336
16337 elsif Nkind (Context) = N_Function_Call
16338 and then Is_Entity_Name (Name (Context))
16339 and then Is_Unchecked_Conversion_Instance (Entity (Name (Context)))
16340 and then Nkind (Parent (Context)) = N_Object_Renaming_Declaration
16341 then
16342 return True;
16343
16344 -- The volatile object is actually the prefix in a protected entry,
16345 -- function, or procedure call.
16346
16347 elsif Is_Protected_Operation_Call (Context) then
16348 return True;
16349
16350 -- The volatile object appears as the expression of a simple return
16351 -- statement that applies to a volatile function.
16352
16353 elsif Nkind (Context) = N_Simple_Return_Statement
16354 and then Expression (Context) = Obj_Ref
16355 then
16356 return
16357 Within_Volatile_Function (Return_Statement_Entity (Context));
16358
16359 -- The volatile object appears as the prefix of a name occurring in a
16360 -- non-interfering context.
16361
16362 elsif Nkind_In (Context, N_Attribute_Reference,
16363 N_Explicit_Dereference,
16364 N_Indexed_Component,
16365 N_Selected_Component,
16366 N_Slice)
16367 and then Prefix (Context) = Obj_Ref
16368 and then Is_OK_Volatile_Context
16369 (Context => Parent (Context),
16370 Obj_Ref => Context)
16371 then
16372 return True;
16373
16374 -- The volatile object appears as the prefix of attributes Address,
16375 -- Alignment, Component_Size, First, First_Bit, Last, Last_Bit, Length,
16376 -- Position, Size, Storage_Size.
16377
16378 elsif Nkind (Context) = N_Attribute_Reference
16379 and then Prefix (Context) = Obj_Ref
16380 and then Nam_In (Attribute_Name (Context), Name_Address,
16381 Name_Alignment,
16382 Name_Component_Size,
16383 Name_First,
16384 Name_First_Bit,
16385 Name_Last,
16386 Name_Last_Bit,
16387 Name_Length,
16388 Name_Position,
16389 Name_Size,
16390 Name_Storage_Size)
16391 then
16392 return True;
16393
16394 -- The volatile object appears as the expression of a type conversion
16395 -- occurring in a non-interfering context.
16396
16397 elsif Nkind_In (Context, N_Type_Conversion,
16398 N_Unchecked_Type_Conversion)
16399 and then Expression (Context) = Obj_Ref
16400 and then Is_OK_Volatile_Context
16401 (Context => Parent (Context),
16402 Obj_Ref => Context)
16403 then
16404 return True;
16405
16406 -- The volatile object appears as the expression in a delay statement
16407
16408 elsif Nkind (Context) in N_Delay_Statement then
16409 return True;
16410
16411 -- Allow references to volatile objects in various checks. This is not a
16412 -- direct SPARK 2014 requirement.
16413
16414 elsif Within_Check (Context) then
16415 return True;
16416
16417 -- Assume that references to effectively volatile objects that appear
16418 -- as actual parameters in a subprogram call are always legal. A full
16419 -- legality check is done when the actuals are resolved (see routine
16420 -- Resolve_Actuals).
16421
16422 elsif Within_Subprogram_Call (Context) then
16423 return True;
16424
16425 -- Otherwise the context is not suitable for an effectively volatile
16426 -- object.
16427
16428 else
16429 return False;
16430 end if;
16431 end Is_OK_Volatile_Context;
16432
16433 ------------------------------------
16434 -- Is_Package_Contract_Annotation --
16435 ------------------------------------
16436
16437 function Is_Package_Contract_Annotation (Item : Node_Id) return Boolean is
16438 Nam : Name_Id;
16439
16440 begin
16441 if Nkind (Item) = N_Aspect_Specification then
16442 Nam := Chars (Identifier (Item));
16443
16444 else pragma Assert (Nkind (Item) = N_Pragma);
16445 Nam := Pragma_Name (Item);
16446 end if;
16447
16448 return Nam = Name_Abstract_State
16449 or else Nam = Name_Initial_Condition
16450 or else Nam = Name_Initializes
16451 or else Nam = Name_Refined_State;
16452 end Is_Package_Contract_Annotation;
16453
16454 -----------------------------------
16455 -- Is_Partially_Initialized_Type --
16456 -----------------------------------
16457
16458 function Is_Partially_Initialized_Type
16459 (Typ : Entity_Id;
16460 Include_Implicit : Boolean := True) return Boolean
16461 is
16462 begin
16463 if Is_Scalar_Type (Typ) then
16464 return False;
16465
16466 elsif Is_Access_Type (Typ) then
16467 return Include_Implicit;
16468
16469 elsif Is_Array_Type (Typ) then
16470
16471 -- If component type is partially initialized, so is array type
16472
16473 if Is_Partially_Initialized_Type
16474 (Component_Type (Typ), Include_Implicit)
16475 then
16476 return True;
16477
16478 -- Otherwise we are only partially initialized if we are fully
16479 -- initialized (this is the empty array case, no point in us
16480 -- duplicating that code here).
16481
16482 else
16483 return Is_Fully_Initialized_Type (Typ);
16484 end if;
16485
16486 elsif Is_Record_Type (Typ) then
16487
16488 -- A discriminated type is always partially initialized if in
16489 -- all mode
16490
16491 if Has_Discriminants (Typ) and then Include_Implicit then
16492 return True;
16493
16494 -- A tagged type is always partially initialized
16495
16496 elsif Is_Tagged_Type (Typ) then
16497 return True;
16498
16499 -- Case of non-discriminated record
16500
16501 else
16502 declare
16503 Ent : Entity_Id;
16504
16505 Component_Present : Boolean := False;
16506 -- Set True if at least one component is present. If no
16507 -- components are present, then record type is fully
16508 -- initialized (another odd case, like the null array).
16509
16510 begin
16511 -- Loop through components
16512
16513 Ent := First_Entity (Typ);
16514 while Present (Ent) loop
16515 if Ekind (Ent) = E_Component then
16516 Component_Present := True;
16517
16518 -- If a component has an initialization expression then
16519 -- the enclosing record type is partially initialized
16520
16521 if Present (Parent (Ent))
16522 and then Present (Expression (Parent (Ent)))
16523 then
16524 return True;
16525
16526 -- If a component is of a type which is itself partially
16527 -- initialized, then the enclosing record type is also.
16528
16529 elsif Is_Partially_Initialized_Type
16530 (Etype (Ent), Include_Implicit)
16531 then
16532 return True;
16533 end if;
16534 end if;
16535
16536 Next_Entity (Ent);
16537 end loop;
16538
16539 -- No initialized components found. If we found any components
16540 -- they were all uninitialized so the result is false.
16541
16542 if Component_Present then
16543 return False;
16544
16545 -- But if we found no components, then all the components are
16546 -- initialized so we consider the type to be initialized.
16547
16548 else
16549 return True;
16550 end if;
16551 end;
16552 end if;
16553
16554 -- Concurrent types are always fully initialized
16555
16556 elsif Is_Concurrent_Type (Typ) then
16557 return True;
16558
16559 -- For a private type, go to underlying type. If there is no underlying
16560 -- type then just assume this partially initialized. Not clear if this
16561 -- can happen in a non-error case, but no harm in testing for this.
16562
16563 elsif Is_Private_Type (Typ) then
16564 declare
16565 U : constant Entity_Id := Underlying_Type (Typ);
16566 begin
16567 if No (U) then
16568 return True;
16569 else
16570 return Is_Partially_Initialized_Type (U, Include_Implicit);
16571 end if;
16572 end;
16573
16574 -- For any other type (are there any?) assume partially initialized
16575
16576 else
16577 return True;
16578 end if;
16579 end Is_Partially_Initialized_Type;
16580
16581 ------------------------------------
16582 -- Is_Potentially_Persistent_Type --
16583 ------------------------------------
16584
16585 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
16586 Comp : Entity_Id;
16587 Indx : Node_Id;
16588
16589 begin
16590 -- For private type, test corresponding full type
16591
16592 if Is_Private_Type (T) then
16593 return Is_Potentially_Persistent_Type (Full_View (T));
16594
16595 -- Scalar types are potentially persistent
16596
16597 elsif Is_Scalar_Type (T) then
16598 return True;
16599
16600 -- Record type is potentially persistent if not tagged and the types of
16601 -- all it components are potentially persistent, and no component has
16602 -- an initialization expression.
16603
16604 elsif Is_Record_Type (T)
16605 and then not Is_Tagged_Type (T)
16606 and then not Is_Partially_Initialized_Type (T)
16607 then
16608 Comp := First_Component (T);
16609 while Present (Comp) loop
16610 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
16611 return False;
16612 else
16613 Next_Entity (Comp);
16614 end if;
16615 end loop;
16616
16617 return True;
16618
16619 -- Array type is potentially persistent if its component type is
16620 -- potentially persistent and if all its constraints are static.
16621
16622 elsif Is_Array_Type (T) then
16623 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
16624 return False;
16625 end if;
16626
16627 Indx := First_Index (T);
16628 while Present (Indx) loop
16629 if not Is_OK_Static_Subtype (Etype (Indx)) then
16630 return False;
16631 else
16632 Next_Index (Indx);
16633 end if;
16634 end loop;
16635
16636 return True;
16637
16638 -- All other types are not potentially persistent
16639
16640 else
16641 return False;
16642 end if;
16643 end Is_Potentially_Persistent_Type;
16644
16645 --------------------------------
16646 -- Is_Potentially_Unevaluated --
16647 --------------------------------
16648
16649 function Is_Potentially_Unevaluated (N : Node_Id) return Boolean is
16650 Par : Node_Id;
16651 Expr : Node_Id;
16652
16653 begin
16654 Expr := N;
16655 Par := N;
16656
16657 -- A postcondition whose expression is a short-circuit is broken down
16658 -- into individual aspects for better exception reporting. The original
16659 -- short-circuit expression is rewritten as the second operand, and an
16660 -- occurrence of 'Old in that operand is potentially unevaluated.
16661 -- See sem_ch13.adb for details of this transformation. The reference
16662 -- to 'Old may appear within an expression, so we must look for the
16663 -- enclosing pragma argument in the tree that contains the reference.
16664
16665 while Present (Par)
16666 and then Nkind (Par) /= N_Pragma_Argument_Association
16667 loop
16668 if Is_Rewrite_Substitution (Par)
16669 and then Nkind (Original_Node (Par)) = N_And_Then
16670 then
16671 return True;
16672 end if;
16673
16674 Par := Parent (Par);
16675 end loop;
16676
16677 -- Other cases; 'Old appears within other expression (not the top-level
16678 -- conjunct in a postcondition) with a potentially unevaluated operand.
16679
16680 Par := Parent (Expr);
16681 while not Nkind_In (Par, N_And_Then,
16682 N_Case_Expression,
16683 N_If_Expression,
16684 N_In,
16685 N_Not_In,
16686 N_Or_Else,
16687 N_Quantified_Expression)
16688 loop
16689 Expr := Par;
16690 Par := Parent (Par);
16691
16692 -- If the context is not an expression, or if is the result of
16693 -- expansion of an enclosing construct (such as another attribute)
16694 -- the predicate does not apply.
16695
16696 if Nkind (Par) = N_Case_Expression_Alternative then
16697 null;
16698
16699 elsif Nkind (Par) not in N_Subexpr
16700 or else not Comes_From_Source (Par)
16701 then
16702 return False;
16703 end if;
16704 end loop;
16705
16706 if Nkind (Par) = N_If_Expression then
16707 return Is_Elsif (Par) or else Expr /= First (Expressions (Par));
16708
16709 elsif Nkind (Par) = N_Case_Expression then
16710 return Expr /= Expression (Par);
16711
16712 elsif Nkind_In (Par, N_And_Then, N_Or_Else) then
16713 return Expr = Right_Opnd (Par);
16714
16715 elsif Nkind_In (Par, N_In, N_Not_In) then
16716
16717 -- If the membership includes several alternatives, only the first is
16718 -- definitely evaluated.
16719
16720 if Present (Alternatives (Par)) then
16721 return Expr /= First (Alternatives (Par));
16722
16723 -- If this is a range membership both bounds are evaluated
16724
16725 else
16726 return False;
16727 end if;
16728
16729 elsif Nkind (Par) = N_Quantified_Expression then
16730 return Expr = Condition (Par);
16731
16732 else
16733 return False;
16734 end if;
16735 end Is_Potentially_Unevaluated;
16736
16737 -----------------------------------------
16738 -- Is_Predefined_Dispatching_Operation --
16739 -----------------------------------------
16740
16741 function Is_Predefined_Dispatching_Operation
16742 (E : Entity_Id) return Boolean
16743 is
16744 TSS_Name : TSS_Name_Type;
16745
16746 begin
16747 if not Is_Dispatching_Operation (E) then
16748 return False;
16749 end if;
16750
16751 Get_Name_String (Chars (E));
16752
16753 -- Most predefined primitives have internally generated names. Equality
16754 -- must be treated differently; the predefined operation is recognized
16755 -- as a homogeneous binary operator that returns Boolean.
16756
16757 if Name_Len > TSS_Name_Type'Last then
16758 TSS_Name :=
16759 TSS_Name_Type
16760 (Name_Buffer (Name_Len - TSS_Name'Length + 1 .. Name_Len));
16761
16762 if Nam_In (Chars (E), Name_uAssign, Name_uSize)
16763 or else
16764 (Chars (E) = Name_Op_Eq
16765 and then Etype (First_Formal (E)) = Etype (Last_Formal (E)))
16766 or else TSS_Name = TSS_Deep_Adjust
16767 or else TSS_Name = TSS_Deep_Finalize
16768 or else TSS_Name = TSS_Stream_Input
16769 or else TSS_Name = TSS_Stream_Output
16770 or else TSS_Name = TSS_Stream_Read
16771 or else TSS_Name = TSS_Stream_Write
16772 or else Is_Predefined_Interface_Primitive (E)
16773 then
16774 return True;
16775 end if;
16776 end if;
16777
16778 return False;
16779 end Is_Predefined_Dispatching_Operation;
16780
16781 ---------------------------------------
16782 -- Is_Predefined_Interface_Primitive --
16783 ---------------------------------------
16784
16785 function Is_Predefined_Interface_Primitive (E : Entity_Id) return Boolean is
16786 begin
16787 -- In VM targets we don't restrict the functionality of this test to
16788 -- compiling in Ada 2005 mode since in VM targets any tagged type has
16789 -- these primitives.
16790
16791 return (Ada_Version >= Ada_2005 or else not Tagged_Type_Expansion)
16792 and then Nam_In (Chars (E), Name_uDisp_Asynchronous_Select,
16793 Name_uDisp_Conditional_Select,
16794 Name_uDisp_Get_Prim_Op_Kind,
16795 Name_uDisp_Get_Task_Id,
16796 Name_uDisp_Requeue,
16797 Name_uDisp_Timed_Select);
16798 end Is_Predefined_Interface_Primitive;
16799
16800 ---------------------------------------
16801 -- Is_Predefined_Internal_Operation --
16802 ---------------------------------------
16803
16804 function Is_Predefined_Internal_Operation
16805 (E : Entity_Id) return Boolean
16806 is
16807 TSS_Name : TSS_Name_Type;
16808
16809 begin
16810 if not Is_Dispatching_Operation (E) then
16811 return False;
16812 end if;
16813
16814 Get_Name_String (Chars (E));
16815
16816 -- Most predefined primitives have internally generated names. Equality
16817 -- must be treated differently; the predefined operation is recognized
16818 -- as a homogeneous binary operator that returns Boolean.
16819
16820 if Name_Len > TSS_Name_Type'Last then
16821 TSS_Name :=
16822 TSS_Name_Type
16823 (Name_Buffer (Name_Len - TSS_Name'Length + 1 .. Name_Len));
16824
16825 if Nam_In (Chars (E), Name_uSize, Name_uAssign)
16826 or else
16827 (Chars (E) = Name_Op_Eq
16828 and then Etype (First_Formal (E)) = Etype (Last_Formal (E)))
16829 or else TSS_Name = TSS_Deep_Adjust
16830 or else TSS_Name = TSS_Deep_Finalize
16831 or else Is_Predefined_Interface_Primitive (E)
16832 then
16833 return True;
16834 end if;
16835 end if;
16836
16837 return False;
16838 end Is_Predefined_Internal_Operation;
16839
16840 --------------------------------
16841 -- Is_Preelaborable_Aggregate --
16842 --------------------------------
16843
16844 function Is_Preelaborable_Aggregate (Aggr : Node_Id) return Boolean is
16845 Aggr_Typ : constant Entity_Id := Etype (Aggr);
16846 Array_Aggr : constant Boolean := Is_Array_Type (Aggr_Typ);
16847
16848 Anc_Part : Node_Id;
16849 Assoc : Node_Id;
16850 Choice : Node_Id;
16851 Comp_Typ : Entity_Id := Empty; -- init to avoid warning
16852 Expr : Node_Id;
16853
16854 begin
16855 if Array_Aggr then
16856 Comp_Typ := Component_Type (Aggr_Typ);
16857 end if;
16858
16859 -- Inspect the ancestor part
16860
16861 if Nkind (Aggr) = N_Extension_Aggregate then
16862 Anc_Part := Ancestor_Part (Aggr);
16863
16864 -- The ancestor denotes a subtype mark
16865
16866 if Is_Entity_Name (Anc_Part)
16867 and then Is_Type (Entity (Anc_Part))
16868 then
16869 if not Has_Preelaborable_Initialization (Entity (Anc_Part)) then
16870 return False;
16871 end if;
16872
16873 -- Otherwise the ancestor denotes an expression
16874
16875 elsif not Is_Preelaborable_Construct (Anc_Part) then
16876 return False;
16877 end if;
16878 end if;
16879
16880 -- Inspect the positional associations
16881
16882 Expr := First (Expressions (Aggr));
16883 while Present (Expr) loop
16884 if not Is_Preelaborable_Construct (Expr) then
16885 return False;
16886 end if;
16887
16888 Next (Expr);
16889 end loop;
16890
16891 -- Inspect the named associations
16892
16893 Assoc := First (Component_Associations (Aggr));
16894 while Present (Assoc) loop
16895
16896 -- Inspect the choices of the current named association
16897
16898 Choice := First (Choices (Assoc));
16899 while Present (Choice) loop
16900 if Array_Aggr then
16901
16902 -- For a choice to be preelaborable, it must denote either a
16903 -- static range or a static expression.
16904
16905 if Nkind (Choice) = N_Others_Choice then
16906 null;
16907
16908 elsif Nkind (Choice) = N_Range then
16909 if not Is_OK_Static_Range (Choice) then
16910 return False;
16911 end if;
16912
16913 elsif not Is_OK_Static_Expression (Choice) then
16914 return False;
16915 end if;
16916
16917 else
16918 Comp_Typ := Etype (Choice);
16919 end if;
16920
16921 Next (Choice);
16922 end loop;
16923
16924 -- The type of the choice must have preelaborable initialization if
16925 -- the association carries a <>.
16926
16927 pragma Assert (Present (Comp_Typ));
16928 if Box_Present (Assoc) then
16929 if not Has_Preelaborable_Initialization (Comp_Typ) then
16930 return False;
16931 end if;
16932
16933 -- The type of the expression must have preelaborable initialization
16934
16935 elsif not Is_Preelaborable_Construct (Expression (Assoc)) then
16936 return False;
16937 end if;
16938
16939 Next (Assoc);
16940 end loop;
16941
16942 -- At this point the aggregate is preelaborable
16943
16944 return True;
16945 end Is_Preelaborable_Aggregate;
16946
16947 --------------------------------
16948 -- Is_Preelaborable_Construct --
16949 --------------------------------
16950
16951 function Is_Preelaborable_Construct (N : Node_Id) return Boolean is
16952 begin
16953 -- Aggregates
16954
16955 if Nkind_In (N, N_Aggregate, N_Extension_Aggregate) then
16956 return Is_Preelaborable_Aggregate (N);
16957
16958 -- Attributes are allowed in general, even if their prefix is a formal
16959 -- type. It seems that certain attributes known not to be static might
16960 -- not be allowed, but there are no rules to prevent them.
16961
16962 elsif Nkind (N) = N_Attribute_Reference then
16963 return True;
16964
16965 -- Expressions
16966
16967 elsif Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then
16968 return True;
16969
16970 elsif Nkind (N) = N_Qualified_Expression then
16971 return Is_Preelaborable_Construct (Expression (N));
16972
16973 -- Names are preelaborable when they denote a discriminant of an
16974 -- enclosing type. Discriminals are also considered for this check.
16975
16976 elsif Is_Entity_Name (N)
16977 and then Present (Entity (N))
16978 and then
16979 (Ekind (Entity (N)) = E_Discriminant
16980 or else (Ekind_In (Entity (N), E_Constant, E_In_Parameter)
16981 and then Present (Discriminal_Link (Entity (N)))))
16982 then
16983 return True;
16984
16985 -- Statements
16986
16987 elsif Nkind (N) = N_Null then
16988 return True;
16989
16990 -- Otherwise the construct is not preelaborable
16991
16992 else
16993 return False;
16994 end if;
16995 end Is_Preelaborable_Construct;
16996
16997 ---------------------------------
16998 -- Is_Protected_Self_Reference --
16999 ---------------------------------
17000
17001 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
17002
17003 function In_Access_Definition (N : Node_Id) return Boolean;
17004 -- Returns true if N belongs to an access definition
17005
17006 --------------------------
17007 -- In_Access_Definition --
17008 --------------------------
17009
17010 function In_Access_Definition (N : Node_Id) return Boolean is
17011 P : Node_Id;
17012
17013 begin
17014 P := Parent (N);
17015 while Present (P) loop
17016 if Nkind (P) = N_Access_Definition then
17017 return True;
17018 end if;
17019
17020 P := Parent (P);
17021 end loop;
17022
17023 return False;
17024 end In_Access_Definition;
17025
17026 -- Start of processing for Is_Protected_Self_Reference
17027
17028 begin
17029 -- Verify that prefix is analyzed and has the proper form. Note that
17030 -- the attributes Elab_Spec, Elab_Body, and Elab_Subp_Body, which also
17031 -- produce the address of an entity, do not analyze their prefix
17032 -- because they denote entities that are not necessarily visible.
17033 -- Neither of them can apply to a protected type.
17034
17035 return Ada_Version >= Ada_2005
17036 and then Is_Entity_Name (N)
17037 and then Present (Entity (N))
17038 and then Is_Protected_Type (Entity (N))
17039 and then In_Open_Scopes (Entity (N))
17040 and then not In_Access_Definition (N);
17041 end Is_Protected_Self_Reference;
17042
17043 -----------------------------
17044 -- Is_RCI_Pkg_Spec_Or_Body --
17045 -----------------------------
17046
17047 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
17048
17049 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
17050 -- Return True if the unit of Cunit is an RCI package declaration
17051
17052 ---------------------------
17053 -- Is_RCI_Pkg_Decl_Cunit --
17054 ---------------------------
17055
17056 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
17057 The_Unit : constant Node_Id := Unit (Cunit);
17058
17059 begin
17060 if Nkind (The_Unit) /= N_Package_Declaration then
17061 return False;
17062 end if;
17063
17064 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
17065 end Is_RCI_Pkg_Decl_Cunit;
17066
17067 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
17068
17069 begin
17070 return Is_RCI_Pkg_Decl_Cunit (Cunit)
17071 or else
17072 (Nkind (Unit (Cunit)) = N_Package_Body
17073 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
17074 end Is_RCI_Pkg_Spec_Or_Body;
17075
17076 -----------------------------------------
17077 -- Is_Remote_Access_To_Class_Wide_Type --
17078 -----------------------------------------
17079
17080 function Is_Remote_Access_To_Class_Wide_Type
17081 (E : Entity_Id) return Boolean
17082 is
17083 begin
17084 -- A remote access to class-wide type is a general access to object type
17085 -- declared in the visible part of a Remote_Types or Remote_Call_
17086 -- Interface unit.
17087
17088 return Ekind (E) = E_General_Access_Type
17089 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
17090 end Is_Remote_Access_To_Class_Wide_Type;
17091
17092 -----------------------------------------
17093 -- Is_Remote_Access_To_Subprogram_Type --
17094 -----------------------------------------
17095
17096 function Is_Remote_Access_To_Subprogram_Type
17097 (E : Entity_Id) return Boolean
17098 is
17099 begin
17100 return (Ekind (E) = E_Access_Subprogram_Type
17101 or else (Ekind (E) = E_Record_Type
17102 and then Present (Corresponding_Remote_Type (E))))
17103 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
17104 end Is_Remote_Access_To_Subprogram_Type;
17105
17106 --------------------
17107 -- Is_Remote_Call --
17108 --------------------
17109
17110 function Is_Remote_Call (N : Node_Id) return Boolean is
17111 begin
17112 if Nkind (N) not in N_Subprogram_Call then
17113
17114 -- An entry call cannot be remote
17115
17116 return False;
17117
17118 elsif Nkind (Name (N)) in N_Has_Entity
17119 and then Is_Remote_Call_Interface (Entity (Name (N)))
17120 then
17121 -- A subprogram declared in the spec of a RCI package is remote
17122
17123 return True;
17124
17125 elsif Nkind (Name (N)) = N_Explicit_Dereference
17126 and then Is_Remote_Access_To_Subprogram_Type
17127 (Etype (Prefix (Name (N))))
17128 then
17129 -- The dereference of a RAS is a remote call
17130
17131 return True;
17132
17133 elsif Present (Controlling_Argument (N))
17134 and then Is_Remote_Access_To_Class_Wide_Type
17135 (Etype (Controlling_Argument (N)))
17136 then
17137 -- Any primitive operation call with a controlling argument of
17138 -- a RACW type is a remote call.
17139
17140 return True;
17141 end if;
17142
17143 -- All other calls are local calls
17144
17145 return False;
17146 end Is_Remote_Call;
17147
17148 ----------------------
17149 -- Is_Renamed_Entry --
17150 ----------------------
17151
17152 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
17153 Orig_Node : Node_Id := Empty;
17154 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
17155
17156 function Is_Entry (Nam : Node_Id) return Boolean;
17157 -- Determine whether Nam is an entry. Traverse selectors if there are
17158 -- nested selected components.
17159
17160 --------------
17161 -- Is_Entry --
17162 --------------
17163
17164 function Is_Entry (Nam : Node_Id) return Boolean is
17165 begin
17166 if Nkind (Nam) = N_Selected_Component then
17167 return Is_Entry (Selector_Name (Nam));
17168 end if;
17169
17170 return Ekind (Entity (Nam)) = E_Entry;
17171 end Is_Entry;
17172
17173 -- Start of processing for Is_Renamed_Entry
17174
17175 begin
17176 if Present (Alias (Proc_Nam)) then
17177 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
17178 end if;
17179
17180 -- Look for a rewritten subprogram renaming declaration
17181
17182 if Nkind (Subp_Decl) = N_Subprogram_Declaration
17183 and then Present (Original_Node (Subp_Decl))
17184 then
17185 Orig_Node := Original_Node (Subp_Decl);
17186 end if;
17187
17188 -- The rewritten subprogram is actually an entry
17189
17190 if Present (Orig_Node)
17191 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
17192 and then Is_Entry (Name (Orig_Node))
17193 then
17194 return True;
17195 end if;
17196
17197 return False;
17198 end Is_Renamed_Entry;
17199
17200 -----------------------------
17201 -- Is_Renaming_Declaration --
17202 -----------------------------
17203
17204 function Is_Renaming_Declaration (N : Node_Id) return Boolean is
17205 begin
17206 case Nkind (N) is
17207 when N_Exception_Renaming_Declaration
17208 | N_Generic_Function_Renaming_Declaration
17209 | N_Generic_Package_Renaming_Declaration
17210 | N_Generic_Procedure_Renaming_Declaration
17211 | N_Object_Renaming_Declaration
17212 | N_Package_Renaming_Declaration
17213 | N_Subprogram_Renaming_Declaration
17214 =>
17215 return True;
17216
17217 when others =>
17218 return False;
17219 end case;
17220 end Is_Renaming_Declaration;
17221
17222 ----------------------------
17223 -- Is_Reversible_Iterator --
17224 ----------------------------
17225
17226 function Is_Reversible_Iterator (Typ : Entity_Id) return Boolean is
17227 Ifaces_List : Elist_Id;
17228 Iface_Elmt : Elmt_Id;
17229 Iface : Entity_Id;
17230
17231 begin
17232 if Is_Class_Wide_Type (Typ)
17233 and then Chars (Root_Type (Typ)) = Name_Reversible_Iterator
17234 and then In_Predefined_Unit (Root_Type (Typ))
17235 then
17236 return True;
17237
17238 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
17239 return False;
17240
17241 else
17242 Collect_Interfaces (Typ, Ifaces_List);
17243
17244 Iface_Elmt := First_Elmt (Ifaces_List);
17245 while Present (Iface_Elmt) loop
17246 Iface := Node (Iface_Elmt);
17247 if Chars (Iface) = Name_Reversible_Iterator
17248 and then In_Predefined_Unit (Iface)
17249 then
17250 return True;
17251 end if;
17252
17253 Next_Elmt (Iface_Elmt);
17254 end loop;
17255 end if;
17256
17257 return False;
17258 end Is_Reversible_Iterator;
17259
17260 ----------------------
17261 -- Is_Selector_Name --
17262 ----------------------
17263
17264 function Is_Selector_Name (N : Node_Id) return Boolean is
17265 begin
17266 if not Is_List_Member (N) then
17267 declare
17268 P : constant Node_Id := Parent (N);
17269 begin
17270 return Nkind_In (P, N_Expanded_Name,
17271 N_Generic_Association,
17272 N_Parameter_Association,
17273 N_Selected_Component)
17274 and then Selector_Name (P) = N;
17275 end;
17276
17277 else
17278 declare
17279 L : constant List_Id := List_Containing (N);
17280 P : constant Node_Id := Parent (L);
17281 begin
17282 return (Nkind (P) = N_Discriminant_Association
17283 and then Selector_Names (P) = L)
17284 or else
17285 (Nkind (P) = N_Component_Association
17286 and then Choices (P) = L);
17287 end;
17288 end if;
17289 end Is_Selector_Name;
17290
17291 ---------------------------------
17292 -- Is_Single_Concurrent_Object --
17293 ---------------------------------
17294
17295 function Is_Single_Concurrent_Object (Id : Entity_Id) return Boolean is
17296 begin
17297 return
17298 Is_Single_Protected_Object (Id) or else Is_Single_Task_Object (Id);
17299 end Is_Single_Concurrent_Object;
17300
17301 -------------------------------
17302 -- Is_Single_Concurrent_Type --
17303 -------------------------------
17304
17305 function Is_Single_Concurrent_Type (Id : Entity_Id) return Boolean is
17306 begin
17307 return
17308 Ekind_In (Id, E_Protected_Type, E_Task_Type)
17309 and then Is_Single_Concurrent_Type_Declaration
17310 (Declaration_Node (Id));
17311 end Is_Single_Concurrent_Type;
17312
17313 -------------------------------------------
17314 -- Is_Single_Concurrent_Type_Declaration --
17315 -------------------------------------------
17316
17317 function Is_Single_Concurrent_Type_Declaration
17318 (N : Node_Id) return Boolean
17319 is
17320 begin
17321 return Nkind_In (Original_Node (N), N_Single_Protected_Declaration,
17322 N_Single_Task_Declaration);
17323 end Is_Single_Concurrent_Type_Declaration;
17324
17325 ---------------------------------------------
17326 -- Is_Single_Precision_Floating_Point_Type --
17327 ---------------------------------------------
17328
17329 function Is_Single_Precision_Floating_Point_Type
17330 (E : Entity_Id) return Boolean is
17331 begin
17332 return Is_Floating_Point_Type (E)
17333 and then Machine_Radix_Value (E) = Uint_2
17334 and then Machine_Mantissa_Value (E) = Uint_24
17335 and then Machine_Emax_Value (E) = Uint_2 ** Uint_7
17336 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_7);
17337 end Is_Single_Precision_Floating_Point_Type;
17338
17339 --------------------------------
17340 -- Is_Single_Protected_Object --
17341 --------------------------------
17342
17343 function Is_Single_Protected_Object (Id : Entity_Id) return Boolean is
17344 begin
17345 return
17346 Ekind (Id) = E_Variable
17347 and then Ekind (Etype (Id)) = E_Protected_Type
17348 and then Is_Single_Concurrent_Type (Etype (Id));
17349 end Is_Single_Protected_Object;
17350
17351 ---------------------------
17352 -- Is_Single_Task_Object --
17353 ---------------------------
17354
17355 function Is_Single_Task_Object (Id : Entity_Id) return Boolean is
17356 begin
17357 return
17358 Ekind (Id) = E_Variable
17359 and then Ekind (Etype (Id)) = E_Task_Type
17360 and then Is_Single_Concurrent_Type (Etype (Id));
17361 end Is_Single_Task_Object;
17362
17363 -------------------------------------
17364 -- Is_SPARK_05_Initialization_Expr --
17365 -------------------------------------
17366
17367 function Is_SPARK_05_Initialization_Expr (N : Node_Id) return Boolean is
17368 Is_Ok : Boolean;
17369 Expr : Node_Id;
17370 Comp_Assn : Node_Id;
17371 Orig_N : constant Node_Id := Original_Node (N);
17372
17373 begin
17374 Is_Ok := True;
17375
17376 if not Comes_From_Source (Orig_N) then
17377 goto Done;
17378 end if;
17379
17380 pragma Assert (Nkind (Orig_N) in N_Subexpr);
17381
17382 case Nkind (Orig_N) is
17383 when N_Character_Literal
17384 | N_Integer_Literal
17385 | N_Real_Literal
17386 | N_String_Literal
17387 =>
17388 null;
17389
17390 when N_Expanded_Name
17391 | N_Identifier
17392 =>
17393 if Is_Entity_Name (Orig_N)
17394 and then Present (Entity (Orig_N)) -- needed in some cases
17395 then
17396 case Ekind (Entity (Orig_N)) is
17397 when E_Constant
17398 | E_Enumeration_Literal
17399 | E_Named_Integer
17400 | E_Named_Real
17401 =>
17402 null;
17403
17404 when others =>
17405 if Is_Type (Entity (Orig_N)) then
17406 null;
17407 else
17408 Is_Ok := False;
17409 end if;
17410 end case;
17411 end if;
17412
17413 when N_Qualified_Expression
17414 | N_Type_Conversion
17415 =>
17416 Is_Ok := Is_SPARK_05_Initialization_Expr (Expression (Orig_N));
17417
17418 when N_Unary_Op =>
17419 Is_Ok := Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
17420
17421 when N_Binary_Op
17422 | N_Membership_Test
17423 | N_Short_Circuit
17424 =>
17425 Is_Ok := Is_SPARK_05_Initialization_Expr (Left_Opnd (Orig_N))
17426 and then
17427 Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
17428
17429 when N_Aggregate
17430 | N_Extension_Aggregate
17431 =>
17432 if Nkind (Orig_N) = N_Extension_Aggregate then
17433 Is_Ok :=
17434 Is_SPARK_05_Initialization_Expr (Ancestor_Part (Orig_N));
17435 end if;
17436
17437 Expr := First (Expressions (Orig_N));
17438 while Present (Expr) loop
17439 if not Is_SPARK_05_Initialization_Expr (Expr) then
17440 Is_Ok := False;
17441 goto Done;
17442 end if;
17443
17444 Next (Expr);
17445 end loop;
17446
17447 Comp_Assn := First (Component_Associations (Orig_N));
17448 while Present (Comp_Assn) loop
17449 Expr := Expression (Comp_Assn);
17450
17451 -- Note: test for Present here needed for box assocation
17452
17453 if Present (Expr)
17454 and then not Is_SPARK_05_Initialization_Expr (Expr)
17455 then
17456 Is_Ok := False;
17457 goto Done;
17458 end if;
17459
17460 Next (Comp_Assn);
17461 end loop;
17462
17463 when N_Attribute_Reference =>
17464 if Nkind (Prefix (Orig_N)) in N_Subexpr then
17465 Is_Ok := Is_SPARK_05_Initialization_Expr (Prefix (Orig_N));
17466 end if;
17467
17468 Expr := First (Expressions (Orig_N));
17469 while Present (Expr) loop
17470 if not Is_SPARK_05_Initialization_Expr (Expr) then
17471 Is_Ok := False;
17472 goto Done;
17473 end if;
17474
17475 Next (Expr);
17476 end loop;
17477
17478 -- Selected components might be expanded named not yet resolved, so
17479 -- default on the safe side. (Eg on sparklex.ads)
17480
17481 when N_Selected_Component =>
17482 null;
17483
17484 when others =>
17485 Is_Ok := False;
17486 end case;
17487
17488 <<Done>>
17489 return Is_Ok;
17490 end Is_SPARK_05_Initialization_Expr;
17491
17492 ----------------------------------
17493 -- Is_SPARK_05_Object_Reference --
17494 ----------------------------------
17495
17496 function Is_SPARK_05_Object_Reference (N : Node_Id) return Boolean is
17497 begin
17498 if Is_Entity_Name (N) then
17499 return Present (Entity (N))
17500 and then
17501 (Ekind_In (Entity (N), E_Constant, E_Variable)
17502 or else Ekind (Entity (N)) in Formal_Kind);
17503
17504 else
17505 case Nkind (N) is
17506 when N_Selected_Component =>
17507 return Is_SPARK_05_Object_Reference (Prefix (N));
17508
17509 when others =>
17510 return False;
17511 end case;
17512 end if;
17513 end Is_SPARK_05_Object_Reference;
17514
17515 -----------------------------
17516 -- Is_Specific_Tagged_Type --
17517 -----------------------------
17518
17519 function Is_Specific_Tagged_Type (Typ : Entity_Id) return Boolean is
17520 Full_Typ : Entity_Id;
17521
17522 begin
17523 -- Handle private types
17524
17525 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
17526 Full_Typ := Full_View (Typ);
17527 else
17528 Full_Typ := Typ;
17529 end if;
17530
17531 -- A specific tagged type is a non-class-wide tagged type
17532
17533 return Is_Tagged_Type (Full_Typ) and not Is_Class_Wide_Type (Full_Typ);
17534 end Is_Specific_Tagged_Type;
17535
17536 ------------------
17537 -- Is_Statement --
17538 ------------------
17539
17540 function Is_Statement (N : Node_Id) return Boolean is
17541 begin
17542 return
17543 Nkind (N) in N_Statement_Other_Than_Procedure_Call
17544 or else Nkind (N) = N_Procedure_Call_Statement;
17545 end Is_Statement;
17546
17547 ---------------------------------------
17548 -- Is_Subprogram_Contract_Annotation --
17549 ---------------------------------------
17550
17551 function Is_Subprogram_Contract_Annotation
17552 (Item : Node_Id) return Boolean
17553 is
17554 Nam : Name_Id;
17555
17556 begin
17557 if Nkind (Item) = N_Aspect_Specification then
17558 Nam := Chars (Identifier (Item));
17559
17560 else pragma Assert (Nkind (Item) = N_Pragma);
17561 Nam := Pragma_Name (Item);
17562 end if;
17563
17564 return Nam = Name_Contract_Cases
17565 or else Nam = Name_Depends
17566 or else Nam = Name_Extensions_Visible
17567 or else Nam = Name_Global
17568 or else Nam = Name_Post
17569 or else Nam = Name_Post_Class
17570 or else Nam = Name_Postcondition
17571 or else Nam = Name_Pre
17572 or else Nam = Name_Pre_Class
17573 or else Nam = Name_Precondition
17574 or else Nam = Name_Refined_Depends
17575 or else Nam = Name_Refined_Global
17576 or else Nam = Name_Refined_Post
17577 or else Nam = Name_Test_Case;
17578 end Is_Subprogram_Contract_Annotation;
17579
17580 --------------------------------------------------
17581 -- Is_Subprogram_Stub_Without_Prior_Declaration --
17582 --------------------------------------------------
17583
17584 function Is_Subprogram_Stub_Without_Prior_Declaration
17585 (N : Node_Id) return Boolean
17586 is
17587 begin
17588 pragma Assert (Nkind (N) = N_Subprogram_Body_Stub);
17589
17590 case Ekind (Defining_Entity (N)) is
17591
17592 -- A subprogram stub without prior declaration serves as declaration
17593 -- for the actual subprogram body. As such, it has an attached
17594 -- defining entity of E_Function or E_Procedure.
17595
17596 when E_Function
17597 | E_Procedure
17598 =>
17599 return True;
17600
17601 -- Otherwise, it is completes a [generic] subprogram declaration
17602
17603 when E_Generic_Function
17604 | E_Generic_Procedure
17605 | E_Subprogram_Body
17606 =>
17607 return False;
17608
17609 when others =>
17610 raise Program_Error;
17611 end case;
17612 end Is_Subprogram_Stub_Without_Prior_Declaration;
17613
17614 ---------------------------
17615 -- Is_Suitable_Primitive --
17616 ---------------------------
17617
17618 function Is_Suitable_Primitive (Subp_Id : Entity_Id) return Boolean is
17619 begin
17620 -- The Default_Initial_Condition and invariant procedures must not be
17621 -- treated as primitive operations even when they apply to a tagged
17622 -- type. These routines must not act as targets of dispatching calls
17623 -- because they already utilize class-wide-precondition semantics to
17624 -- handle inheritance and overriding.
17625
17626 if Ekind (Subp_Id) = E_Procedure
17627 and then (Is_DIC_Procedure (Subp_Id)
17628 or else
17629 Is_Invariant_Procedure (Subp_Id))
17630 then
17631 return False;
17632 end if;
17633
17634 return True;
17635 end Is_Suitable_Primitive;
17636
17637 --------------------------
17638 -- Is_Suspension_Object --
17639 --------------------------
17640
17641 function Is_Suspension_Object (Id : Entity_Id) return Boolean is
17642 begin
17643 -- This approach does an exact name match rather than to rely on
17644 -- RTSfind. Routine Is_Effectively_Volatile is used by clients of the
17645 -- front end at point where all auxiliary tables are locked and any
17646 -- modifications to them are treated as violations. Do not tamper with
17647 -- the tables, instead examine the Chars fields of all the scopes of Id.
17648
17649 return
17650 Chars (Id) = Name_Suspension_Object
17651 and then Present (Scope (Id))
17652 and then Chars (Scope (Id)) = Name_Synchronous_Task_Control
17653 and then Present (Scope (Scope (Id)))
17654 and then Chars (Scope (Scope (Id))) = Name_Ada
17655 and then Present (Scope (Scope (Scope (Id))))
17656 and then Scope (Scope (Scope (Id))) = Standard_Standard;
17657 end Is_Suspension_Object;
17658
17659 ----------------------------
17660 -- Is_Synchronized_Object --
17661 ----------------------------
17662
17663 function Is_Synchronized_Object (Id : Entity_Id) return Boolean is
17664 Prag : Node_Id;
17665
17666 begin
17667 if Is_Object (Id) then
17668
17669 -- The object is synchronized if it is of a type that yields a
17670 -- synchronized object.
17671
17672 if Yields_Synchronized_Object (Etype (Id)) then
17673 return True;
17674
17675 -- The object is synchronized if it is atomic and Async_Writers is
17676 -- enabled.
17677
17678 elsif Is_Atomic_Object_Entity (Id)
17679 and then Async_Writers_Enabled (Id)
17680 then
17681 return True;
17682
17683 -- A constant is a synchronized object by default
17684
17685 elsif Ekind (Id) = E_Constant then
17686 return True;
17687
17688 -- A variable is a synchronized object if it is subject to pragma
17689 -- Constant_After_Elaboration.
17690
17691 elsif Ekind (Id) = E_Variable then
17692 Prag := Get_Pragma (Id, Pragma_Constant_After_Elaboration);
17693
17694 return Present (Prag) and then Is_Enabled_Pragma (Prag);
17695 end if;
17696 end if;
17697
17698 -- Otherwise the input is not an object or it does not qualify as a
17699 -- synchronized object.
17700
17701 return False;
17702 end Is_Synchronized_Object;
17703
17704 ---------------------------------
17705 -- Is_Synchronized_Tagged_Type --
17706 ---------------------------------
17707
17708 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
17709 Kind : constant Entity_Kind := Ekind (Base_Type (E));
17710
17711 begin
17712 -- A task or protected type derived from an interface is a tagged type.
17713 -- Such a tagged type is called a synchronized tagged type, as are
17714 -- synchronized interfaces and private extensions whose declaration
17715 -- includes the reserved word synchronized.
17716
17717 return (Is_Tagged_Type (E)
17718 and then (Kind = E_Task_Type
17719 or else
17720 Kind = E_Protected_Type))
17721 or else
17722 (Is_Interface (E)
17723 and then Is_Synchronized_Interface (E))
17724 or else
17725 (Ekind (E) = E_Record_Type_With_Private
17726 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
17727 and then (Synchronized_Present (Parent (E))
17728 or else Is_Synchronized_Interface (Etype (E))));
17729 end Is_Synchronized_Tagged_Type;
17730
17731 -----------------
17732 -- Is_Transfer --
17733 -----------------
17734
17735 function Is_Transfer (N : Node_Id) return Boolean is
17736 Kind : constant Node_Kind := Nkind (N);
17737
17738 begin
17739 if Kind = N_Simple_Return_Statement
17740 or else
17741 Kind = N_Extended_Return_Statement
17742 or else
17743 Kind = N_Goto_Statement
17744 or else
17745 Kind = N_Raise_Statement
17746 or else
17747 Kind = N_Requeue_Statement
17748 then
17749 return True;
17750
17751 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
17752 and then No (Condition (N))
17753 then
17754 return True;
17755
17756 elsif Kind = N_Procedure_Call_Statement
17757 and then Is_Entity_Name (Name (N))
17758 and then Present (Entity (Name (N)))
17759 and then No_Return (Entity (Name (N)))
17760 then
17761 return True;
17762
17763 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
17764 return True;
17765
17766 else
17767 return False;
17768 end if;
17769 end Is_Transfer;
17770
17771 -------------
17772 -- Is_True --
17773 -------------
17774
17775 function Is_True (U : Uint) return Boolean is
17776 begin
17777 return (U /= 0);
17778 end Is_True;
17779
17780 --------------------------------------
17781 -- Is_Unchecked_Conversion_Instance --
17782 --------------------------------------
17783
17784 function Is_Unchecked_Conversion_Instance (Id : Entity_Id) return Boolean is
17785 Par : Node_Id;
17786
17787 begin
17788 -- Look for a function whose generic parent is the predefined intrinsic
17789 -- function Unchecked_Conversion, or for one that renames such an
17790 -- instance.
17791
17792 if Ekind (Id) = E_Function then
17793 Par := Parent (Id);
17794
17795 if Nkind (Par) = N_Function_Specification then
17796 Par := Generic_Parent (Par);
17797
17798 if Present (Par) then
17799 return
17800 Chars (Par) = Name_Unchecked_Conversion
17801 and then Is_Intrinsic_Subprogram (Par)
17802 and then In_Predefined_Unit (Par);
17803 else
17804 return
17805 Present (Alias (Id))
17806 and then Is_Unchecked_Conversion_Instance (Alias (Id));
17807 end if;
17808 end if;
17809 end if;
17810
17811 return False;
17812 end Is_Unchecked_Conversion_Instance;
17813
17814 -------------------------------
17815 -- Is_Universal_Numeric_Type --
17816 -------------------------------
17817
17818 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
17819 begin
17820 return T = Universal_Integer or else T = Universal_Real;
17821 end Is_Universal_Numeric_Type;
17822
17823 ------------------------------
17824 -- Is_User_Defined_Equality --
17825 ------------------------------
17826
17827 function Is_User_Defined_Equality (Id : Entity_Id) return Boolean is
17828 begin
17829 return Ekind (Id) = E_Function
17830 and then Chars (Id) = Name_Op_Eq
17831 and then Comes_From_Source (Id)
17832
17833 -- Internally generated equalities have a full type declaration
17834 -- as their parent.
17835
17836 and then Nkind (Parent (Id)) = N_Function_Specification;
17837 end Is_User_Defined_Equality;
17838
17839 --------------------------------------
17840 -- Is_Validation_Variable_Reference --
17841 --------------------------------------
17842
17843 function Is_Validation_Variable_Reference (N : Node_Id) return Boolean is
17844 Var : constant Node_Id := Unqual_Conv (N);
17845 Var_Id : Entity_Id;
17846
17847 begin
17848 Var_Id := Empty;
17849
17850 if Is_Entity_Name (Var) then
17851 Var_Id := Entity (Var);
17852 end if;
17853
17854 return
17855 Present (Var_Id)
17856 and then Ekind (Var_Id) = E_Variable
17857 and then Present (Validated_Object (Var_Id));
17858 end Is_Validation_Variable_Reference;
17859
17860 ----------------------------
17861 -- Is_Variable_Size_Array --
17862 ----------------------------
17863
17864 function Is_Variable_Size_Array (E : Entity_Id) return Boolean is
17865 Idx : Node_Id;
17866
17867 begin
17868 pragma Assert (Is_Array_Type (E));
17869
17870 -- Check if some index is initialized with a non-constant value
17871
17872 Idx := First_Index (E);
17873 while Present (Idx) loop
17874 if Nkind (Idx) = N_Range then
17875 if not Is_Constant_Bound (Low_Bound (Idx))
17876 or else not Is_Constant_Bound (High_Bound (Idx))
17877 then
17878 return True;
17879 end if;
17880 end if;
17881
17882 Idx := Next_Index (Idx);
17883 end loop;
17884
17885 return False;
17886 end Is_Variable_Size_Array;
17887
17888 -----------------------------
17889 -- Is_Variable_Size_Record --
17890 -----------------------------
17891
17892 function Is_Variable_Size_Record (E : Entity_Id) return Boolean is
17893 Comp : Entity_Id;
17894 Comp_Typ : Entity_Id;
17895
17896 begin
17897 pragma Assert (Is_Record_Type (E));
17898
17899 Comp := First_Component (E);
17900 while Present (Comp) loop
17901 Comp_Typ := Underlying_Type (Etype (Comp));
17902
17903 -- Recursive call if the record type has discriminants
17904
17905 if Is_Record_Type (Comp_Typ)
17906 and then Has_Discriminants (Comp_Typ)
17907 and then Is_Variable_Size_Record (Comp_Typ)
17908 then
17909 return True;
17910
17911 elsif Is_Array_Type (Comp_Typ)
17912 and then Is_Variable_Size_Array (Comp_Typ)
17913 then
17914 return True;
17915 end if;
17916
17917 Next_Component (Comp);
17918 end loop;
17919
17920 return False;
17921 end Is_Variable_Size_Record;
17922
17923 -----------------
17924 -- Is_Variable --
17925 -----------------
17926
17927 function Is_Variable
17928 (N : Node_Id;
17929 Use_Original_Node : Boolean := True) return Boolean
17930 is
17931 Orig_Node : Node_Id;
17932
17933 function In_Protected_Function (E : Entity_Id) return Boolean;
17934 -- Within a protected function, the private components of the enclosing
17935 -- protected type are constants. A function nested within a (protected)
17936 -- procedure is not itself protected. Within the body of a protected
17937 -- function the current instance of the protected type is a constant.
17938
17939 function Is_Variable_Prefix (P : Node_Id) return Boolean;
17940 -- Prefixes can involve implicit dereferences, in which case we must
17941 -- test for the case of a reference of a constant access type, which can
17942 -- can never be a variable.
17943
17944 ---------------------------
17945 -- In_Protected_Function --
17946 ---------------------------
17947
17948 function In_Protected_Function (E : Entity_Id) return Boolean is
17949 Prot : Entity_Id;
17950 S : Entity_Id;
17951
17952 begin
17953 -- E is the current instance of a type
17954
17955 if Is_Type (E) then
17956 Prot := E;
17957
17958 -- E is an object
17959
17960 else
17961 Prot := Scope (E);
17962 end if;
17963
17964 if not Is_Protected_Type (Prot) then
17965 return False;
17966
17967 else
17968 S := Current_Scope;
17969 while Present (S) and then S /= Prot loop
17970 if Ekind (S) = E_Function and then Scope (S) = Prot then
17971 return True;
17972 end if;
17973
17974 S := Scope (S);
17975 end loop;
17976
17977 return False;
17978 end if;
17979 end In_Protected_Function;
17980
17981 ------------------------
17982 -- Is_Variable_Prefix --
17983 ------------------------
17984
17985 function Is_Variable_Prefix (P : Node_Id) return Boolean is
17986 begin
17987 if Is_Access_Type (Etype (P)) then
17988 return not Is_Access_Constant (Root_Type (Etype (P)));
17989
17990 -- For the case of an indexed component whose prefix has a packed
17991 -- array type, the prefix has been rewritten into a type conversion.
17992 -- Determine variable-ness from the converted expression.
17993
17994 elsif Nkind (P) = N_Type_Conversion
17995 and then not Comes_From_Source (P)
17996 and then Is_Array_Type (Etype (P))
17997 and then Is_Packed (Etype (P))
17998 then
17999 return Is_Variable (Expression (P));
18000
18001 else
18002 return Is_Variable (P);
18003 end if;
18004 end Is_Variable_Prefix;
18005
18006 -- Start of processing for Is_Variable
18007
18008 begin
18009 -- Special check, allow x'Deref(expr) as a variable
18010
18011 if Nkind (N) = N_Attribute_Reference
18012 and then Attribute_Name (N) = Name_Deref
18013 then
18014 return True;
18015 end if;
18016
18017 -- Check if we perform the test on the original node since this may be a
18018 -- test of syntactic categories which must not be disturbed by whatever
18019 -- rewriting might have occurred. For example, an aggregate, which is
18020 -- certainly NOT a variable, could be turned into a variable by
18021 -- expansion.
18022
18023 if Use_Original_Node then
18024 Orig_Node := Original_Node (N);
18025 else
18026 Orig_Node := N;
18027 end if;
18028
18029 -- Definitely OK if Assignment_OK is set. Since this is something that
18030 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
18031
18032 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
18033 return True;
18034
18035 -- Normally we go to the original node, but there is one exception where
18036 -- we use the rewritten node, namely when it is an explicit dereference.
18037 -- The generated code may rewrite a prefix which is an access type with
18038 -- an explicit dereference. The dereference is a variable, even though
18039 -- the original node may not be (since it could be a constant of the
18040 -- access type).
18041
18042 -- In Ada 2005 we have a further case to consider: the prefix may be a
18043 -- function call given in prefix notation. The original node appears to
18044 -- be a selected component, but we need to examine the call.
18045
18046 elsif Nkind (N) = N_Explicit_Dereference
18047 and then Nkind (Orig_Node) /= N_Explicit_Dereference
18048 and then Present (Etype (Orig_Node))
18049 and then Is_Access_Type (Etype (Orig_Node))
18050 then
18051 -- Note that if the prefix is an explicit dereference that does not
18052 -- come from source, we must check for a rewritten function call in
18053 -- prefixed notation before other forms of rewriting, to prevent a
18054 -- compiler crash.
18055
18056 return
18057 (Nkind (Orig_Node) = N_Function_Call
18058 and then not Is_Access_Constant (Etype (Prefix (N))))
18059 or else
18060 Is_Variable_Prefix (Original_Node (Prefix (N)));
18061
18062 -- in Ada 2012, the dereference may have been added for a type with
18063 -- a declared implicit dereference aspect. Check that it is not an
18064 -- access to constant.
18065
18066 elsif Nkind (N) = N_Explicit_Dereference
18067 and then Present (Etype (Orig_Node))
18068 and then Ada_Version >= Ada_2012
18069 and then Has_Implicit_Dereference (Etype (Orig_Node))
18070 then
18071 return not Is_Access_Constant (Etype (Prefix (N)));
18072
18073 -- A function call is never a variable
18074
18075 elsif Nkind (N) = N_Function_Call then
18076 return False;
18077
18078 -- All remaining checks use the original node
18079
18080 elsif Is_Entity_Name (Orig_Node)
18081 and then Present (Entity (Orig_Node))
18082 then
18083 declare
18084 E : constant Entity_Id := Entity (Orig_Node);
18085 K : constant Entity_Kind := Ekind (E);
18086
18087 begin
18088 if Is_Loop_Parameter (E) then
18089 return False;
18090 end if;
18091
18092 return (K = E_Variable
18093 and then Nkind (Parent (E)) /= N_Exception_Handler)
18094 or else (K = E_Component
18095 and then not In_Protected_Function (E))
18096 or else K = E_Out_Parameter
18097 or else K = E_In_Out_Parameter
18098 or else K = E_Generic_In_Out_Parameter
18099
18100 -- Current instance of type. If this is a protected type, check
18101 -- we are not within the body of one of its protected functions.
18102
18103 or else (Is_Type (E)
18104 and then In_Open_Scopes (E)
18105 and then not In_Protected_Function (E))
18106
18107 or else (Is_Incomplete_Or_Private_Type (E)
18108 and then In_Open_Scopes (Full_View (E)));
18109 end;
18110
18111 else
18112 case Nkind (Orig_Node) is
18113 when N_Indexed_Component
18114 | N_Slice
18115 =>
18116 return Is_Variable_Prefix (Prefix (Orig_Node));
18117
18118 when N_Selected_Component =>
18119 return (Is_Variable (Selector_Name (Orig_Node))
18120 and then Is_Variable_Prefix (Prefix (Orig_Node)))
18121 or else
18122 (Nkind (N) = N_Expanded_Name
18123 and then Scope (Entity (N)) = Entity (Prefix (N)));
18124
18125 -- For an explicit dereference, the type of the prefix cannot
18126 -- be an access to constant or an access to subprogram.
18127
18128 when N_Explicit_Dereference =>
18129 declare
18130 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
18131 begin
18132 return Is_Access_Type (Typ)
18133 and then not Is_Access_Constant (Root_Type (Typ))
18134 and then Ekind (Typ) /= E_Access_Subprogram_Type;
18135 end;
18136
18137 -- The type conversion is the case where we do not deal with the
18138 -- context dependent special case of an actual parameter. Thus
18139 -- the type conversion is only considered a variable for the
18140 -- purposes of this routine if the target type is tagged. However,
18141 -- a type conversion is considered to be a variable if it does not
18142 -- come from source (this deals for example with the conversions
18143 -- of expressions to their actual subtypes).
18144
18145 when N_Type_Conversion =>
18146 return Is_Variable (Expression (Orig_Node))
18147 and then
18148 (not Comes_From_Source (Orig_Node)
18149 or else
18150 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
18151 and then
18152 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
18153
18154 -- GNAT allows an unchecked type conversion as a variable. This
18155 -- only affects the generation of internal expanded code, since
18156 -- calls to instantiations of Unchecked_Conversion are never
18157 -- considered variables (since they are function calls).
18158
18159 when N_Unchecked_Type_Conversion =>
18160 return Is_Variable (Expression (Orig_Node));
18161
18162 when others =>
18163 return False;
18164 end case;
18165 end if;
18166 end Is_Variable;
18167
18168 ---------------------------
18169 -- Is_Visibly_Controlled --
18170 ---------------------------
18171
18172 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
18173 Root : constant Entity_Id := Root_Type (T);
18174 begin
18175 return Chars (Scope (Root)) = Name_Finalization
18176 and then Chars (Scope (Scope (Root))) = Name_Ada
18177 and then Scope (Scope (Scope (Root))) = Standard_Standard;
18178 end Is_Visibly_Controlled;
18179
18180 --------------------------
18181 -- Is_Volatile_Function --
18182 --------------------------
18183
18184 function Is_Volatile_Function (Func_Id : Entity_Id) return Boolean is
18185 begin
18186 pragma Assert (Ekind_In (Func_Id, E_Function, E_Generic_Function));
18187
18188 -- A function declared within a protected type is volatile
18189
18190 if Is_Protected_Type (Scope (Func_Id)) then
18191 return True;
18192
18193 -- An instance of Ada.Unchecked_Conversion is a volatile function if
18194 -- either the source or the target are effectively volatile.
18195
18196 elsif Is_Unchecked_Conversion_Instance (Func_Id)
18197 and then Has_Effectively_Volatile_Profile (Func_Id)
18198 then
18199 return True;
18200
18201 -- Otherwise the function is treated as volatile if it is subject to
18202 -- enabled pragma Volatile_Function.
18203
18204 else
18205 return
18206 Is_Enabled_Pragma (Get_Pragma (Func_Id, Pragma_Volatile_Function));
18207 end if;
18208 end Is_Volatile_Function;
18209
18210 ------------------------
18211 -- Is_Volatile_Object --
18212 ------------------------
18213
18214 function Is_Volatile_Object (N : Node_Id) return Boolean is
18215 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
18216 -- If prefix is an implicit dereference, examine designated type
18217
18218 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
18219 -- Determines if given object has volatile components
18220
18221 ------------------------
18222 -- Is_Volatile_Prefix --
18223 ------------------------
18224
18225 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
18226 Typ : constant Entity_Id := Etype (N);
18227
18228 begin
18229 if Is_Access_Type (Typ) then
18230 declare
18231 Dtyp : constant Entity_Id := Designated_Type (Typ);
18232
18233 begin
18234 return Is_Volatile (Dtyp)
18235 or else Has_Volatile_Components (Dtyp);
18236 end;
18237
18238 else
18239 return Object_Has_Volatile_Components (N);
18240 end if;
18241 end Is_Volatile_Prefix;
18242
18243 ------------------------------------
18244 -- Object_Has_Volatile_Components --
18245 ------------------------------------
18246
18247 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
18248 Typ : constant Entity_Id := Etype (N);
18249
18250 begin
18251 if Is_Volatile (Typ)
18252 or else Has_Volatile_Components (Typ)
18253 then
18254 return True;
18255
18256 elsif Is_Entity_Name (N)
18257 and then (Has_Volatile_Components (Entity (N))
18258 or else Is_Volatile (Entity (N)))
18259 then
18260 return True;
18261
18262 elsif Nkind (N) = N_Indexed_Component
18263 or else Nkind (N) = N_Selected_Component
18264 then
18265 return Is_Volatile_Prefix (Prefix (N));
18266
18267 else
18268 return False;
18269 end if;
18270 end Object_Has_Volatile_Components;
18271
18272 -- Start of processing for Is_Volatile_Object
18273
18274 begin
18275 if Nkind (N) = N_Defining_Identifier then
18276 return Is_Volatile (N) or else Is_Volatile (Etype (N));
18277
18278 elsif Nkind (N) = N_Expanded_Name then
18279 return Is_Volatile_Object (Entity (N));
18280
18281 elsif Is_Volatile (Etype (N))
18282 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
18283 then
18284 return True;
18285
18286 elsif Nkind_In (N, N_Indexed_Component, N_Selected_Component)
18287 and then Is_Volatile_Prefix (Prefix (N))
18288 then
18289 return True;
18290
18291 elsif Nkind (N) = N_Selected_Component
18292 and then Is_Volatile (Entity (Selector_Name (N)))
18293 then
18294 return True;
18295
18296 else
18297 return False;
18298 end if;
18299 end Is_Volatile_Object;
18300
18301 -----------------------------
18302 -- Iterate_Call_Parameters --
18303 -----------------------------
18304
18305 procedure Iterate_Call_Parameters (Call : Node_Id) is
18306 Actual : Node_Id := First_Actual (Call);
18307 Formal : Entity_Id := First_Formal (Get_Called_Entity (Call));
18308
18309 begin
18310 while Present (Formal) and then Present (Actual) loop
18311 Handle_Parameter (Formal, Actual);
18312
18313 Next_Formal (Formal);
18314 Next_Actual (Actual);
18315 end loop;
18316
18317 pragma Assert (No (Formal));
18318 pragma Assert (No (Actual));
18319 end Iterate_Call_Parameters;
18320
18321 ---------------------------
18322 -- Itype_Has_Declaration --
18323 ---------------------------
18324
18325 function Itype_Has_Declaration (Id : Entity_Id) return Boolean is
18326 begin
18327 pragma Assert (Is_Itype (Id));
18328 return Present (Parent (Id))
18329 and then Nkind_In (Parent (Id), N_Full_Type_Declaration,
18330 N_Subtype_Declaration)
18331 and then Defining_Entity (Parent (Id)) = Id;
18332 end Itype_Has_Declaration;
18333
18334 -------------------------
18335 -- Kill_Current_Values --
18336 -------------------------
18337
18338 procedure Kill_Current_Values
18339 (Ent : Entity_Id;
18340 Last_Assignment_Only : Boolean := False)
18341 is
18342 begin
18343 if Is_Assignable (Ent) then
18344 Set_Last_Assignment (Ent, Empty);
18345 end if;
18346
18347 if Is_Object (Ent) then
18348 if not Last_Assignment_Only then
18349 Kill_Checks (Ent);
18350 Set_Current_Value (Ent, Empty);
18351
18352 -- Do not reset the Is_Known_[Non_]Null and Is_Known_Valid flags
18353 -- for a constant. Once the constant is elaborated, its value is
18354 -- not changed, therefore the associated flags that describe the
18355 -- value should not be modified either.
18356
18357 if Ekind (Ent) = E_Constant then
18358 null;
18359
18360 -- Non-constant entities
18361
18362 else
18363 if not Can_Never_Be_Null (Ent) then
18364 Set_Is_Known_Non_Null (Ent, False);
18365 end if;
18366
18367 Set_Is_Known_Null (Ent, False);
18368
18369 -- Reset the Is_Known_Valid flag unless the type is always
18370 -- valid. This does not apply to a loop parameter because its
18371 -- bounds are defined by the loop header and therefore always
18372 -- valid.
18373
18374 if not Is_Known_Valid (Etype (Ent))
18375 and then Ekind (Ent) /= E_Loop_Parameter
18376 then
18377 Set_Is_Known_Valid (Ent, False);
18378 end if;
18379 end if;
18380 end if;
18381 end if;
18382 end Kill_Current_Values;
18383
18384 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
18385 S : Entity_Id;
18386
18387 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
18388 -- Clear current value for entity E and all entities chained to E
18389
18390 ------------------------------------------
18391 -- Kill_Current_Values_For_Entity_Chain --
18392 ------------------------------------------
18393
18394 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
18395 Ent : Entity_Id;
18396 begin
18397 Ent := E;
18398 while Present (Ent) loop
18399 Kill_Current_Values (Ent, Last_Assignment_Only);
18400 Next_Entity (Ent);
18401 end loop;
18402 end Kill_Current_Values_For_Entity_Chain;
18403
18404 -- Start of processing for Kill_Current_Values
18405
18406 begin
18407 -- Kill all saved checks, a special case of killing saved values
18408
18409 if not Last_Assignment_Only then
18410 Kill_All_Checks;
18411 end if;
18412
18413 -- Loop through relevant scopes, which includes the current scope and
18414 -- any parent scopes if the current scope is a block or a package.
18415
18416 S := Current_Scope;
18417 Scope_Loop : loop
18418
18419 -- Clear current values of all entities in current scope
18420
18421 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
18422
18423 -- If scope is a package, also clear current values of all private
18424 -- entities in the scope.
18425
18426 if Is_Package_Or_Generic_Package (S)
18427 or else Is_Concurrent_Type (S)
18428 then
18429 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
18430 end if;
18431
18432 -- If this is a not a subprogram, deal with parents
18433
18434 if not Is_Subprogram (S) then
18435 S := Scope (S);
18436 exit Scope_Loop when S = Standard_Standard;
18437 else
18438 exit Scope_Loop;
18439 end if;
18440 end loop Scope_Loop;
18441 end Kill_Current_Values;
18442
18443 --------------------------
18444 -- Kill_Size_Check_Code --
18445 --------------------------
18446
18447 procedure Kill_Size_Check_Code (E : Entity_Id) is
18448 begin
18449 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
18450 and then Present (Size_Check_Code (E))
18451 then
18452 Remove (Size_Check_Code (E));
18453 Set_Size_Check_Code (E, Empty);
18454 end if;
18455 end Kill_Size_Check_Code;
18456
18457 --------------------
18458 -- Known_Non_Null --
18459 --------------------
18460
18461 function Known_Non_Null (N : Node_Id) return Boolean is
18462 Status : constant Null_Status_Kind := Null_Status (N);
18463
18464 Id : Entity_Id;
18465 Op : Node_Kind;
18466 Val : Node_Id;
18467
18468 begin
18469 -- The expression yields a non-null value ignoring simple flow analysis
18470
18471 if Status = Is_Non_Null then
18472 return True;
18473
18474 -- Otherwise check whether N is a reference to an entity that appears
18475 -- within a conditional construct.
18476
18477 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
18478
18479 -- First check if we are in decisive conditional
18480
18481 Get_Current_Value_Condition (N, Op, Val);
18482
18483 if Known_Null (Val) then
18484 if Op = N_Op_Eq then
18485 return False;
18486 elsif Op = N_Op_Ne then
18487 return True;
18488 end if;
18489 end if;
18490
18491 -- If OK to do replacement, test Is_Known_Non_Null flag
18492
18493 Id := Entity (N);
18494
18495 if OK_To_Do_Constant_Replacement (Id) then
18496 return Is_Known_Non_Null (Id);
18497 end if;
18498 end if;
18499
18500 -- Otherwise it is not possible to determine whether N yields a non-null
18501 -- value.
18502
18503 return False;
18504 end Known_Non_Null;
18505
18506 ----------------
18507 -- Known_Null --
18508 ----------------
18509
18510 function Known_Null (N : Node_Id) return Boolean is
18511 Status : constant Null_Status_Kind := Null_Status (N);
18512
18513 Id : Entity_Id;
18514 Op : Node_Kind;
18515 Val : Node_Id;
18516
18517 begin
18518 -- The expression yields a null value ignoring simple flow analysis
18519
18520 if Status = Is_Null then
18521 return True;
18522
18523 -- Otherwise check whether N is a reference to an entity that appears
18524 -- within a conditional construct.
18525
18526 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
18527
18528 -- First check if we are in decisive conditional
18529
18530 Get_Current_Value_Condition (N, Op, Val);
18531
18532 if Known_Null (Val) then
18533 if Op = N_Op_Eq then
18534 return True;
18535 elsif Op = N_Op_Ne then
18536 return False;
18537 end if;
18538 end if;
18539
18540 -- If OK to do replacement, test Is_Known_Null flag
18541
18542 Id := Entity (N);
18543
18544 if OK_To_Do_Constant_Replacement (Id) then
18545 return Is_Known_Null (Id);
18546 end if;
18547 end if;
18548
18549 -- Otherwise it is not possible to determine whether N yields a null
18550 -- value.
18551
18552 return False;
18553 end Known_Null;
18554
18555 --------------------------
18556 -- Known_To_Be_Assigned --
18557 --------------------------
18558
18559 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
18560 P : constant Node_Id := Parent (N);
18561
18562 begin
18563 case Nkind (P) is
18564
18565 -- Test left side of assignment
18566
18567 when N_Assignment_Statement =>
18568 return N = Name (P);
18569
18570 -- Function call arguments are never lvalues
18571
18572 when N_Function_Call =>
18573 return False;
18574
18575 -- Positional parameter for procedure or accept call
18576
18577 when N_Accept_Statement
18578 | N_Procedure_Call_Statement
18579 =>
18580 declare
18581 Proc : Entity_Id;
18582 Form : Entity_Id;
18583 Act : Node_Id;
18584
18585 begin
18586 Proc := Get_Subprogram_Entity (P);
18587
18588 if No (Proc) then
18589 return False;
18590 end if;
18591
18592 -- If we are not a list member, something is strange, so
18593 -- be conservative and return False.
18594
18595 if not Is_List_Member (N) then
18596 return False;
18597 end if;
18598
18599 -- We are going to find the right formal by stepping forward
18600 -- through the formals, as we step backwards in the actuals.
18601
18602 Form := First_Formal (Proc);
18603 Act := N;
18604 loop
18605 -- If no formal, something is weird, so be conservative
18606 -- and return False.
18607
18608 if No (Form) then
18609 return False;
18610 end if;
18611
18612 Prev (Act);
18613 exit when No (Act);
18614 Next_Formal (Form);
18615 end loop;
18616
18617 return Ekind (Form) /= E_In_Parameter;
18618 end;
18619
18620 -- Named parameter for procedure or accept call
18621
18622 when N_Parameter_Association =>
18623 declare
18624 Proc : Entity_Id;
18625 Form : Entity_Id;
18626
18627 begin
18628 Proc := Get_Subprogram_Entity (Parent (P));
18629
18630 if No (Proc) then
18631 return False;
18632 end if;
18633
18634 -- Loop through formals to find the one that matches
18635
18636 Form := First_Formal (Proc);
18637 loop
18638 -- If no matching formal, that's peculiar, some kind of
18639 -- previous error, so return False to be conservative.
18640 -- Actually this also happens in legal code in the case
18641 -- where P is a parameter association for an Extra_Formal???
18642
18643 if No (Form) then
18644 return False;
18645 end if;
18646
18647 -- Else test for match
18648
18649 if Chars (Form) = Chars (Selector_Name (P)) then
18650 return Ekind (Form) /= E_In_Parameter;
18651 end if;
18652
18653 Next_Formal (Form);
18654 end loop;
18655 end;
18656
18657 -- Test for appearing in a conversion that itself appears
18658 -- in an lvalue context, since this should be an lvalue.
18659
18660 when N_Type_Conversion =>
18661 return Known_To_Be_Assigned (P);
18662
18663 -- All other references are definitely not known to be modifications
18664
18665 when others =>
18666 return False;
18667 end case;
18668 end Known_To_Be_Assigned;
18669
18670 ---------------------------
18671 -- Last_Source_Statement --
18672 ---------------------------
18673
18674 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
18675 N : Node_Id;
18676
18677 begin
18678 N := Last (Statements (HSS));
18679 while Present (N) loop
18680 exit when Comes_From_Source (N);
18681 Prev (N);
18682 end loop;
18683
18684 return N;
18685 end Last_Source_Statement;
18686
18687 -----------------------
18688 -- Mark_Coextensions --
18689 -----------------------
18690
18691 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
18692 Is_Dynamic : Boolean;
18693 -- Indicates whether the context causes nested coextensions to be
18694 -- dynamic or static
18695
18696 function Mark_Allocator (N : Node_Id) return Traverse_Result;
18697 -- Recognize an allocator node and label it as a dynamic coextension
18698
18699 --------------------
18700 -- Mark_Allocator --
18701 --------------------
18702
18703 function Mark_Allocator (N : Node_Id) return Traverse_Result is
18704 begin
18705 if Nkind (N) = N_Allocator then
18706 if Is_Dynamic then
18707 Set_Is_Static_Coextension (N, False);
18708 Set_Is_Dynamic_Coextension (N);
18709
18710 -- If the allocator expression is potentially dynamic, it may
18711 -- be expanded out of order and require dynamic allocation
18712 -- anyway, so we treat the coextension itself as dynamic.
18713 -- Potential optimization ???
18714
18715 elsif Nkind (Expression (N)) = N_Qualified_Expression
18716 and then Nkind (Expression (Expression (N))) = N_Op_Concat
18717 then
18718 Set_Is_Static_Coextension (N, False);
18719 Set_Is_Dynamic_Coextension (N);
18720 else
18721 Set_Is_Dynamic_Coextension (N, False);
18722 Set_Is_Static_Coextension (N);
18723 end if;
18724 end if;
18725
18726 return OK;
18727 end Mark_Allocator;
18728
18729 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
18730
18731 -- Start of processing for Mark_Coextensions
18732
18733 begin
18734 -- An allocator that appears on the right-hand side of an assignment is
18735 -- treated as a potentially dynamic coextension when the right-hand side
18736 -- is an allocator or a qualified expression.
18737
18738 -- Obj := new ...'(new Coextension ...);
18739
18740 if Nkind (Context_Nod) = N_Assignment_Statement then
18741 Is_Dynamic :=
18742 Nkind_In (Expression (Context_Nod), N_Allocator,
18743 N_Qualified_Expression);
18744
18745 -- An allocator that appears within the expression of a simple return
18746 -- statement is treated as a potentially dynamic coextension when the
18747 -- expression is either aggregate, allocator, or qualified expression.
18748
18749 -- return (new Coextension ...);
18750 -- return new ...'(new Coextension ...);
18751
18752 elsif Nkind (Context_Nod) = N_Simple_Return_Statement then
18753 Is_Dynamic :=
18754 Nkind_In (Expression (Context_Nod), N_Aggregate,
18755 N_Allocator,
18756 N_Qualified_Expression);
18757
18758 -- An alloctor that appears within the initialization expression of an
18759 -- object declaration is considered a potentially dynamic coextension
18760 -- when the initialization expression is an allocator or a qualified
18761 -- expression.
18762
18763 -- Obj : ... := new ...'(new Coextension ...);
18764
18765 -- A similar case arises when the object declaration is part of an
18766 -- extended return statement.
18767
18768 -- return Obj : ... := new ...'(new Coextension ...);
18769 -- return Obj : ... := (new Coextension ...);
18770
18771 elsif Nkind (Context_Nod) = N_Object_Declaration then
18772 Is_Dynamic :=
18773 Nkind_In (Root_Nod, N_Allocator, N_Qualified_Expression)
18774 or else
18775 Nkind (Parent (Context_Nod)) = N_Extended_Return_Statement;
18776
18777 -- This routine should not be called with constructs that cannot contain
18778 -- coextensions.
18779
18780 else
18781 raise Program_Error;
18782 end if;
18783
18784 Mark_Allocators (Root_Nod);
18785 end Mark_Coextensions;
18786
18787 ---------------------------------
18788 -- Mark_Elaboration_Attributes --
18789 ---------------------------------
18790
18791 procedure Mark_Elaboration_Attributes
18792 (N_Id : Node_Or_Entity_Id;
18793 Checks : Boolean := False;
18794 Level : Boolean := False;
18795 Modes : Boolean := False;
18796 Warnings : Boolean := False)
18797 is
18798 function Elaboration_Checks_OK
18799 (Target_Id : Entity_Id;
18800 Context_Id : Entity_Id) return Boolean;
18801 -- Determine whether elaboration checks are enabled for target Target_Id
18802 -- which resides within context Context_Id.
18803
18804 procedure Mark_Elaboration_Attributes_Id (Id : Entity_Id);
18805 -- Preserve relevant attributes of the context in arbitrary entity Id
18806
18807 procedure Mark_Elaboration_Attributes_Node (N : Node_Id);
18808 -- Preserve relevant attributes of the context in arbitrary node N
18809
18810 ---------------------------
18811 -- Elaboration_Checks_OK --
18812 ---------------------------
18813
18814 function Elaboration_Checks_OK
18815 (Target_Id : Entity_Id;
18816 Context_Id : Entity_Id) return Boolean
18817 is
18818 Encl_Scop : Entity_Id;
18819
18820 begin
18821 -- Elaboration checks are suppressed for the target
18822
18823 if Elaboration_Checks_Suppressed (Target_Id) then
18824 return False;
18825 end if;
18826
18827 -- Otherwise elaboration checks are OK for the target, but may be
18828 -- suppressed for the context where the target is declared.
18829
18830 Encl_Scop := Context_Id;
18831 while Present (Encl_Scop) and then Encl_Scop /= Standard_Standard loop
18832 if Elaboration_Checks_Suppressed (Encl_Scop) then
18833 return False;
18834 end if;
18835
18836 Encl_Scop := Scope (Encl_Scop);
18837 end loop;
18838
18839 -- Neither the target nor its declarative context have elaboration
18840 -- checks suppressed.
18841
18842 return True;
18843 end Elaboration_Checks_OK;
18844
18845 ------------------------------------
18846 -- Mark_Elaboration_Attributes_Id --
18847 ------------------------------------
18848
18849 procedure Mark_Elaboration_Attributes_Id (Id : Entity_Id) is
18850 begin
18851 -- Mark the status of elaboration checks in effect. Do not reset the
18852 -- status in case the entity is reanalyzed with checks suppressed.
18853
18854 if Checks and then not Is_Elaboration_Checks_OK_Id (Id) then
18855 Set_Is_Elaboration_Checks_OK_Id (Id,
18856 Elaboration_Checks_OK
18857 (Target_Id => Id,
18858 Context_Id => Scope (Id)));
18859 end if;
18860
18861 -- Mark the status of elaboration warnings in effect. Do not reset
18862 -- the status in case the entity is reanalyzed with warnings off.
18863
18864 if Warnings and then not Is_Elaboration_Warnings_OK_Id (Id) then
18865 Set_Is_Elaboration_Warnings_OK_Id (Id, Elab_Warnings);
18866 end if;
18867 end Mark_Elaboration_Attributes_Id;
18868
18869 --------------------------------------
18870 -- Mark_Elaboration_Attributes_Node --
18871 --------------------------------------
18872
18873 procedure Mark_Elaboration_Attributes_Node (N : Node_Id) is
18874 function Extract_Name (N : Node_Id) return Node_Id;
18875 -- Obtain the Name attribute of call or instantiation N
18876
18877 ------------------
18878 -- Extract_Name --
18879 ------------------
18880
18881 function Extract_Name (N : Node_Id) return Node_Id is
18882 Nam : Node_Id;
18883
18884 begin
18885 Nam := Name (N);
18886
18887 -- A call to an entry family appears in indexed form
18888
18889 if Nkind (Nam) = N_Indexed_Component then
18890 Nam := Prefix (Nam);
18891 end if;
18892
18893 -- The name may also appear in qualified form
18894
18895 if Nkind (Nam) = N_Selected_Component then
18896 Nam := Selector_Name (Nam);
18897 end if;
18898
18899 return Nam;
18900 end Extract_Name;
18901
18902 -- Local variables
18903
18904 Context_Id : Entity_Id;
18905 Nam : Node_Id;
18906
18907 -- Start of processing for Mark_Elaboration_Attributes_Node
18908
18909 begin
18910 -- Mark the status of elaboration checks in effect. Do not reset the
18911 -- status in case the node is reanalyzed with checks suppressed.
18912
18913 if Checks and then not Is_Elaboration_Checks_OK_Node (N) then
18914
18915 -- Assignments, attribute references, and variable references do
18916 -- not have a "declarative" context.
18917
18918 Context_Id := Empty;
18919
18920 -- The status of elaboration checks for calls and instantiations
18921 -- depends on the most recent pragma Suppress/Unsuppress, as well
18922 -- as the suppression status of the context where the target is
18923 -- defined.
18924
18925 -- package Pack is
18926 -- function Func ...;
18927 -- end Pack;
18928
18929 -- with Pack;
18930 -- procedure Main is
18931 -- pragma Suppress (Elaboration_Checks, Pack);
18932 -- X : ... := Pack.Func;
18933 -- ...
18934
18935 -- In the example above, the call to Func has elaboration checks
18936 -- enabled because there is no active general purpose suppression
18937 -- pragma, however the elaboration checks of Pack are explicitly
18938 -- suppressed. As a result the elaboration checks of the call must
18939 -- be disabled in order to preserve this dependency.
18940
18941 if Nkind_In (N, N_Entry_Call_Statement,
18942 N_Function_Call,
18943 N_Function_Instantiation,
18944 N_Package_Instantiation,
18945 N_Procedure_Call_Statement,
18946 N_Procedure_Instantiation)
18947 then
18948 Nam := Extract_Name (N);
18949
18950 if Is_Entity_Name (Nam) and then Present (Entity (Nam)) then
18951 Context_Id := Scope (Entity (Nam));
18952 end if;
18953 end if;
18954
18955 Set_Is_Elaboration_Checks_OK_Node (N,
18956 Elaboration_Checks_OK
18957 (Target_Id => Empty,
18958 Context_Id => Context_Id));
18959 end if;
18960
18961 -- Mark the enclosing level of the node. Do not reset the status in
18962 -- case the node is relocated and reanalyzed.
18963
18964 if Level and then not Is_Declaration_Level_Node (N) then
18965 Set_Is_Declaration_Level_Node (N,
18966 Find_Enclosing_Level (N) = Declaration_Level);
18967 end if;
18968
18969 -- Mark the Ghost and SPARK mode in effect
18970
18971 if Modes then
18972 if Ghost_Mode = Ignore then
18973 Set_Is_Ignored_Ghost_Node (N);
18974 end if;
18975
18976 if SPARK_Mode = On then
18977 Set_Is_SPARK_Mode_On_Node (N);
18978 end if;
18979 end if;
18980
18981 -- Mark the status of elaboration warnings in effect. Do not reset
18982 -- the status in case the node is reanalyzed with warnings off.
18983
18984 if Warnings and then not Is_Elaboration_Warnings_OK_Node (N) then
18985 Set_Is_Elaboration_Warnings_OK_Node (N, Elab_Warnings);
18986 end if;
18987 end Mark_Elaboration_Attributes_Node;
18988
18989 -- Start of processing for Mark_Elaboration_Attributes
18990
18991 begin
18992 -- Do not capture any elaboration-related attributes when switch -gnatH
18993 -- (legacy elaboration checking mode enabled) is in effect because the
18994 -- attributes are useless to the legacy model.
18995
18996 if Legacy_Elaboration_Checks then
18997 return;
18998 end if;
18999
19000 if Nkind (N_Id) in N_Entity then
19001 Mark_Elaboration_Attributes_Id (N_Id);
19002 else
19003 Mark_Elaboration_Attributes_Node (N_Id);
19004 end if;
19005 end Mark_Elaboration_Attributes;
19006
19007 ----------------------------------------
19008 -- Mark_Save_Invocation_Graph_Of_Body --
19009 ----------------------------------------
19010
19011 procedure Mark_Save_Invocation_Graph_Of_Body is
19012 Main : constant Node_Id := Cunit (Main_Unit);
19013 Main_Unit : constant Node_Id := Unit (Main);
19014 Aux_Id : Entity_Id;
19015
19016 begin
19017 Set_Save_Invocation_Graph_Of_Body (Main);
19018
19019 -- Assume that the main unit does not have a complimentary unit
19020
19021 Aux_Id := Empty;
19022
19023 -- Obtain the complimentary unit of the main unit
19024
19025 if Nkind_In (Main_Unit, N_Generic_Package_Declaration,
19026 N_Generic_Subprogram_Declaration,
19027 N_Package_Declaration,
19028 N_Subprogram_Declaration)
19029 then
19030 Aux_Id := Corresponding_Body (Main_Unit);
19031
19032 elsif Nkind_In (Main_Unit, N_Package_Body,
19033 N_Subprogram_Body,
19034 N_Subprogram_Renaming_Declaration)
19035 then
19036 Aux_Id := Corresponding_Spec (Main_Unit);
19037 end if;
19038
19039 if Present (Aux_Id) then
19040 Set_Save_Invocation_Graph_Of_Body
19041 (Parent (Unit_Declaration_Node (Aux_Id)));
19042 end if;
19043 end Mark_Save_Invocation_Graph_Of_Body;
19044
19045 ----------------------------------
19046 -- Matching_Static_Array_Bounds --
19047 ----------------------------------
19048
19049 function Matching_Static_Array_Bounds
19050 (L_Typ : Node_Id;
19051 R_Typ : Node_Id) return Boolean
19052 is
19053 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
19054 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
19055
19056 L_Index : Node_Id := Empty; -- init to ...
19057 R_Index : Node_Id := Empty; -- ...avoid warnings
19058 L_Low : Node_Id;
19059 L_High : Node_Id;
19060 L_Len : Uint;
19061 R_Low : Node_Id;
19062 R_High : Node_Id;
19063 R_Len : Uint;
19064
19065 begin
19066 if L_Ndims /= R_Ndims then
19067 return False;
19068 end if;
19069
19070 -- Unconstrained types do not have static bounds
19071
19072 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
19073 return False;
19074 end if;
19075
19076 -- First treat specially the first dimension, as the lower bound and
19077 -- length of string literals are not stored like those of arrays.
19078
19079 if Ekind (L_Typ) = E_String_Literal_Subtype then
19080 L_Low := String_Literal_Low_Bound (L_Typ);
19081 L_Len := String_Literal_Length (L_Typ);
19082 else
19083 L_Index := First_Index (L_Typ);
19084 Get_Index_Bounds (L_Index, L_Low, L_High);
19085
19086 if Is_OK_Static_Expression (L_Low)
19087 and then
19088 Is_OK_Static_Expression (L_High)
19089 then
19090 if Expr_Value (L_High) < Expr_Value (L_Low) then
19091 L_Len := Uint_0;
19092 else
19093 L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
19094 end if;
19095 else
19096 return False;
19097 end if;
19098 end if;
19099
19100 if Ekind (R_Typ) = E_String_Literal_Subtype then
19101 R_Low := String_Literal_Low_Bound (R_Typ);
19102 R_Len := String_Literal_Length (R_Typ);
19103 else
19104 R_Index := First_Index (R_Typ);
19105 Get_Index_Bounds (R_Index, R_Low, R_High);
19106
19107 if Is_OK_Static_Expression (R_Low)
19108 and then
19109 Is_OK_Static_Expression (R_High)
19110 then
19111 if Expr_Value (R_High) < Expr_Value (R_Low) then
19112 R_Len := Uint_0;
19113 else
19114 R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
19115 end if;
19116 else
19117 return False;
19118 end if;
19119 end if;
19120
19121 if (Is_OK_Static_Expression (L_Low)
19122 and then
19123 Is_OK_Static_Expression (R_Low))
19124 and then Expr_Value (L_Low) = Expr_Value (R_Low)
19125 and then L_Len = R_Len
19126 then
19127 null;
19128 else
19129 return False;
19130 end if;
19131
19132 -- Then treat all other dimensions
19133
19134 for Indx in 2 .. L_Ndims loop
19135 Next (L_Index);
19136 Next (R_Index);
19137
19138 Get_Index_Bounds (L_Index, L_Low, L_High);
19139 Get_Index_Bounds (R_Index, R_Low, R_High);
19140
19141 if (Is_OK_Static_Expression (L_Low) and then
19142 Is_OK_Static_Expression (L_High) and then
19143 Is_OK_Static_Expression (R_Low) and then
19144 Is_OK_Static_Expression (R_High))
19145 and then (Expr_Value (L_Low) = Expr_Value (R_Low)
19146 and then
19147 Expr_Value (L_High) = Expr_Value (R_High))
19148 then
19149 null;
19150 else
19151 return False;
19152 end if;
19153 end loop;
19154
19155 -- If we fall through the loop, all indexes matched
19156
19157 return True;
19158 end Matching_Static_Array_Bounds;
19159
19160 -------------------
19161 -- May_Be_Lvalue --
19162 -------------------
19163
19164 function May_Be_Lvalue (N : Node_Id) return Boolean is
19165 P : constant Node_Id := Parent (N);
19166
19167 begin
19168 case Nkind (P) is
19169
19170 -- Test left side of assignment
19171
19172 when N_Assignment_Statement =>
19173 return N = Name (P);
19174
19175 -- Test prefix of component or attribute. Note that the prefix of an
19176 -- explicit or implicit dereference cannot be an l-value. In the case
19177 -- of a 'Read attribute, the reference can be an actual in the
19178 -- argument list of the attribute.
19179
19180 when N_Attribute_Reference =>
19181 return (N = Prefix (P)
19182 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P)))
19183 or else
19184 Attribute_Name (P) = Name_Read;
19185
19186 -- For an expanded name, the name is an lvalue if the expanded name
19187 -- is an lvalue, but the prefix is never an lvalue, since it is just
19188 -- the scope where the name is found.
19189
19190 when N_Expanded_Name =>
19191 if N = Prefix (P) then
19192 return May_Be_Lvalue (P);
19193 else
19194 return False;
19195 end if;
19196
19197 -- For a selected component A.B, A is certainly an lvalue if A.B is.
19198 -- B is a little interesting, if we have A.B := 3, there is some
19199 -- discussion as to whether B is an lvalue or not, we choose to say
19200 -- it is. Note however that A is not an lvalue if it is of an access
19201 -- type since this is an implicit dereference.
19202
19203 when N_Selected_Component =>
19204 if N = Prefix (P)
19205 and then Present (Etype (N))
19206 and then Is_Access_Type (Etype (N))
19207 then
19208 return False;
19209 else
19210 return May_Be_Lvalue (P);
19211 end if;
19212
19213 -- For an indexed component or slice, the index or slice bounds is
19214 -- never an lvalue. The prefix is an lvalue if the indexed component
19215 -- or slice is an lvalue, except if it is an access type, where we
19216 -- have an implicit dereference.
19217
19218 when N_Indexed_Component
19219 | N_Slice
19220 =>
19221 if N /= Prefix (P)
19222 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
19223 then
19224 return False;
19225 else
19226 return May_Be_Lvalue (P);
19227 end if;
19228
19229 -- Prefix of a reference is an lvalue if the reference is an lvalue
19230
19231 when N_Reference =>
19232 return May_Be_Lvalue (P);
19233
19234 -- Prefix of explicit dereference is never an lvalue
19235
19236 when N_Explicit_Dereference =>
19237 return False;
19238
19239 -- Positional parameter for subprogram, entry, or accept call.
19240 -- In older versions of Ada function call arguments are never
19241 -- lvalues. In Ada 2012 functions can have in-out parameters.
19242
19243 when N_Accept_Statement
19244 | N_Entry_Call_Statement
19245 | N_Subprogram_Call
19246 =>
19247 if Nkind (P) = N_Function_Call and then Ada_Version < Ada_2012 then
19248 return False;
19249 end if;
19250
19251 -- The following mechanism is clumsy and fragile. A single flag
19252 -- set in Resolve_Actuals would be preferable ???
19253
19254 declare
19255 Proc : Entity_Id;
19256 Form : Entity_Id;
19257 Act : Node_Id;
19258
19259 begin
19260 Proc := Get_Subprogram_Entity (P);
19261
19262 if No (Proc) then
19263 return True;
19264 end if;
19265
19266 -- If we are not a list member, something is strange, so be
19267 -- conservative and return True.
19268
19269 if not Is_List_Member (N) then
19270 return True;
19271 end if;
19272
19273 -- We are going to find the right formal by stepping forward
19274 -- through the formals, as we step backwards in the actuals.
19275
19276 Form := First_Formal (Proc);
19277 Act := N;
19278 loop
19279 -- If no formal, something is weird, so be conservative and
19280 -- return True.
19281
19282 if No (Form) then
19283 return True;
19284 end if;
19285
19286 Prev (Act);
19287 exit when No (Act);
19288 Next_Formal (Form);
19289 end loop;
19290
19291 return Ekind (Form) /= E_In_Parameter;
19292 end;
19293
19294 -- Named parameter for procedure or accept call
19295
19296 when N_Parameter_Association =>
19297 declare
19298 Proc : Entity_Id;
19299 Form : Entity_Id;
19300
19301 begin
19302 Proc := Get_Subprogram_Entity (Parent (P));
19303
19304 if No (Proc) then
19305 return True;
19306 end if;
19307
19308 -- Loop through formals to find the one that matches
19309
19310 Form := First_Formal (Proc);
19311 loop
19312 -- If no matching formal, that's peculiar, some kind of
19313 -- previous error, so return True to be conservative.
19314 -- Actually happens with legal code for an unresolved call
19315 -- where we may get the wrong homonym???
19316
19317 if No (Form) then
19318 return True;
19319 end if;
19320
19321 -- Else test for match
19322
19323 if Chars (Form) = Chars (Selector_Name (P)) then
19324 return Ekind (Form) /= E_In_Parameter;
19325 end if;
19326
19327 Next_Formal (Form);
19328 end loop;
19329 end;
19330
19331 -- Test for appearing in a conversion that itself appears in an
19332 -- lvalue context, since this should be an lvalue.
19333
19334 when N_Type_Conversion =>
19335 return May_Be_Lvalue (P);
19336
19337 -- Test for appearance in object renaming declaration
19338
19339 when N_Object_Renaming_Declaration =>
19340 return True;
19341
19342 -- All other references are definitely not lvalues
19343
19344 when others =>
19345 return False;
19346 end case;
19347 end May_Be_Lvalue;
19348
19349 -----------------
19350 -- Might_Raise --
19351 -----------------
19352
19353 function Might_Raise (N : Node_Id) return Boolean is
19354 Result : Boolean := False;
19355
19356 function Process (N : Node_Id) return Traverse_Result;
19357 -- Set Result to True if we find something that could raise an exception
19358
19359 -------------
19360 -- Process --
19361 -------------
19362
19363 function Process (N : Node_Id) return Traverse_Result is
19364 begin
19365 if Nkind_In (N, N_Procedure_Call_Statement,
19366 N_Function_Call,
19367 N_Raise_Statement,
19368 N_Raise_Constraint_Error,
19369 N_Raise_Program_Error,
19370 N_Raise_Storage_Error)
19371 then
19372 Result := True;
19373 return Abandon;
19374 else
19375 return OK;
19376 end if;
19377 end Process;
19378
19379 procedure Set_Result is new Traverse_Proc (Process);
19380
19381 -- Start of processing for Might_Raise
19382
19383 begin
19384 -- False if exceptions can't be propagated
19385
19386 if No_Exception_Handlers_Set then
19387 return False;
19388 end if;
19389
19390 -- If the checks handled by the back end are not disabled, we cannot
19391 -- ensure that no exception will be raised.
19392
19393 if not Access_Checks_Suppressed (Empty)
19394 or else not Discriminant_Checks_Suppressed (Empty)
19395 or else not Range_Checks_Suppressed (Empty)
19396 or else not Index_Checks_Suppressed (Empty)
19397 or else Opt.Stack_Checking_Enabled
19398 then
19399 return True;
19400 end if;
19401
19402 Set_Result (N);
19403 return Result;
19404 end Might_Raise;
19405
19406 --------------------------------
19407 -- Nearest_Enclosing_Instance --
19408 --------------------------------
19409
19410 function Nearest_Enclosing_Instance (E : Entity_Id) return Entity_Id is
19411 Inst : Entity_Id;
19412
19413 begin
19414 Inst := Scope (E);
19415 while Present (Inst) and then Inst /= Standard_Standard loop
19416 if Is_Generic_Instance (Inst) then
19417 return Inst;
19418 end if;
19419
19420 Inst := Scope (Inst);
19421 end loop;
19422
19423 return Empty;
19424 end Nearest_Enclosing_Instance;
19425
19426 ------------------------
19427 -- Needs_Finalization --
19428 ------------------------
19429
19430 function Needs_Finalization (Typ : Entity_Id) return Boolean is
19431 function Has_Some_Controlled_Component
19432 (Input_Typ : Entity_Id) return Boolean;
19433 -- Determine whether type Input_Typ has at least one controlled
19434 -- component.
19435
19436 -----------------------------------
19437 -- Has_Some_Controlled_Component --
19438 -----------------------------------
19439
19440 function Has_Some_Controlled_Component
19441 (Input_Typ : Entity_Id) return Boolean
19442 is
19443 Comp : Entity_Id;
19444
19445 begin
19446 -- When a type is already frozen and has at least one controlled
19447 -- component, or is manually decorated, it is sufficient to inspect
19448 -- flag Has_Controlled_Component.
19449
19450 if Has_Controlled_Component (Input_Typ) then
19451 return True;
19452
19453 -- Otherwise inspect the internals of the type
19454
19455 elsif not Is_Frozen (Input_Typ) then
19456 if Is_Array_Type (Input_Typ) then
19457 return Needs_Finalization (Component_Type (Input_Typ));
19458
19459 elsif Is_Record_Type (Input_Typ) then
19460 Comp := First_Component (Input_Typ);
19461 while Present (Comp) loop
19462 if Needs_Finalization (Etype (Comp)) then
19463 return True;
19464 end if;
19465
19466 Next_Component (Comp);
19467 end loop;
19468 end if;
19469 end if;
19470
19471 return False;
19472 end Has_Some_Controlled_Component;
19473
19474 -- Start of processing for Needs_Finalization
19475
19476 begin
19477 -- Certain run-time configurations and targets do not provide support
19478 -- for controlled types.
19479
19480 if Restriction_Active (No_Finalization) then
19481 return False;
19482
19483 -- C++ types are not considered controlled. It is assumed that the non-
19484 -- Ada side will handle their clean up.
19485
19486 elsif Convention (Typ) = Convention_CPP then
19487 return False;
19488
19489 -- Class-wide types are treated as controlled because derivations from
19490 -- the root type may introduce controlled components.
19491
19492 elsif Is_Class_Wide_Type (Typ) then
19493 return True;
19494
19495 -- Concurrent types are controlled as long as their corresponding record
19496 -- is controlled.
19497
19498 elsif Is_Concurrent_Type (Typ)
19499 and then Present (Corresponding_Record_Type (Typ))
19500 and then Needs_Finalization (Corresponding_Record_Type (Typ))
19501 then
19502 return True;
19503
19504 -- Otherwise the type is controlled when it is either derived from type
19505 -- [Limited_]Controlled and not subject to aspect Disable_Controlled, or
19506 -- contains at least one controlled component.
19507
19508 else
19509 return
19510 Is_Controlled (Typ) or else Has_Some_Controlled_Component (Typ);
19511 end if;
19512 end Needs_Finalization;
19513
19514 ----------------------
19515 -- Needs_One_Actual --
19516 ----------------------
19517
19518 function Needs_One_Actual (E : Entity_Id) return Boolean is
19519 Formal : Entity_Id;
19520
19521 begin
19522 -- Ada 2005 or later, and formals present. The first formal must be
19523 -- of a type that supports prefix notation: a controlling argument,
19524 -- a class-wide type, or an access to such.
19525
19526 if Ada_Version >= Ada_2005
19527 and then Present (First_Formal (E))
19528 and then No (Default_Value (First_Formal (E)))
19529 and then
19530 (Is_Controlling_Formal (First_Formal (E))
19531 or else Is_Class_Wide_Type (Etype (First_Formal (E)))
19532 or else Is_Anonymous_Access_Type (Etype (First_Formal (E))))
19533 then
19534 Formal := Next_Formal (First_Formal (E));
19535 while Present (Formal) loop
19536 if No (Default_Value (Formal)) then
19537 return False;
19538 end if;
19539
19540 Next_Formal (Formal);
19541 end loop;
19542
19543 return True;
19544
19545 -- Ada 83/95 or no formals
19546
19547 else
19548 return False;
19549 end if;
19550 end Needs_One_Actual;
19551
19552 ---------------------------------
19553 -- Needs_Simple_Initialization --
19554 ---------------------------------
19555
19556 function Needs_Simple_Initialization
19557 (Typ : Entity_Id;
19558 Consider_IS : Boolean := True) return Boolean
19559 is
19560 Consider_IS_NS : constant Boolean :=
19561 Normalize_Scalars or (Initialize_Scalars and Consider_IS);
19562
19563 begin
19564 -- Never need initialization if it is suppressed
19565
19566 if Initialization_Suppressed (Typ) then
19567 return False;
19568 end if;
19569
19570 -- Check for private type, in which case test applies to the underlying
19571 -- type of the private type.
19572
19573 if Is_Private_Type (Typ) then
19574 declare
19575 RT : constant Entity_Id := Underlying_Type (Typ);
19576 begin
19577 if Present (RT) then
19578 return Needs_Simple_Initialization (RT);
19579 else
19580 return False;
19581 end if;
19582 end;
19583
19584 -- Scalar type with Default_Value aspect requires initialization
19585
19586 elsif Is_Scalar_Type (Typ) and then Has_Default_Aspect (Typ) then
19587 return True;
19588
19589 -- Cases needing simple initialization are access types, and, if pragma
19590 -- Normalize_Scalars or Initialize_Scalars is in effect, then all scalar
19591 -- types.
19592
19593 elsif Is_Access_Type (Typ)
19594 or else (Consider_IS_NS and then (Is_Scalar_Type (Typ)))
19595 then
19596 return True;
19597
19598 -- If Initialize/Normalize_Scalars is in effect, string objects also
19599 -- need initialization, unless they are created in the course of
19600 -- expanding an aggregate (since in the latter case they will be
19601 -- filled with appropriate initializing values before they are used).
19602
19603 elsif Consider_IS_NS
19604 and then Is_Standard_String_Type (Typ)
19605 and then
19606 (not Is_Itype (Typ)
19607 or else Nkind (Associated_Node_For_Itype (Typ)) /= N_Aggregate)
19608 then
19609 return True;
19610
19611 else
19612 return False;
19613 end if;
19614 end Needs_Simple_Initialization;
19615
19616 -------------------------------------
19617 -- Needs_Variable_Reference_Marker --
19618 -------------------------------------
19619
19620 function Needs_Variable_Reference_Marker
19621 (N : Node_Id;
19622 Calls_OK : Boolean) return Boolean
19623 is
19624 function Within_Suitable_Context (Ref : Node_Id) return Boolean;
19625 -- Deteremine whether variable reference Ref appears within a suitable
19626 -- context that allows the creation of a marker.
19627
19628 -----------------------------
19629 -- Within_Suitable_Context --
19630 -----------------------------
19631
19632 function Within_Suitable_Context (Ref : Node_Id) return Boolean is
19633 Par : Node_Id;
19634
19635 begin
19636 Par := Ref;
19637 while Present (Par) loop
19638
19639 -- The context is not suitable when the reference appears within
19640 -- the formal part of an instantiation which acts as compilation
19641 -- unit because there is no proper list for the insertion of the
19642 -- marker.
19643
19644 if Nkind (Par) = N_Generic_Association
19645 and then Nkind (Parent (Par)) in N_Generic_Instantiation
19646 and then Nkind (Parent (Parent (Par))) = N_Compilation_Unit
19647 then
19648 return False;
19649
19650 -- The context is not suitable when the reference appears within
19651 -- a pragma. If the pragma has run-time semantics, the reference
19652 -- will be reconsidered once the pragma is expanded.
19653
19654 elsif Nkind (Par) = N_Pragma then
19655 return False;
19656
19657 -- The context is not suitable when the reference appears within a
19658 -- subprogram call, and the caller requests this behavior.
19659
19660 elsif not Calls_OK
19661 and then Nkind_In (Par, N_Entry_Call_Statement,
19662 N_Function_Call,
19663 N_Procedure_Call_Statement)
19664 then
19665 return False;
19666
19667 -- Prevent the search from going too far
19668
19669 elsif Is_Body_Or_Package_Declaration (Par) then
19670 exit;
19671 end if;
19672
19673 Par := Parent (Par);
19674 end loop;
19675
19676 return True;
19677 end Within_Suitable_Context;
19678
19679 -- Local variables
19680
19681 Prag : Node_Id;
19682 Var_Id : Entity_Id;
19683
19684 -- Start of processing for Needs_Variable_Reference_Marker
19685
19686 begin
19687 -- No marker needs to be created when switch -gnatH (legacy elaboration
19688 -- checking mode enabled) is in effect because the legacy ABE mechanism
19689 -- does not use markers.
19690
19691 if Legacy_Elaboration_Checks then
19692 return False;
19693
19694 -- No marker needs to be created for ASIS because ABE diagnostics and
19695 -- checks are not performed in this mode.
19696
19697 elsif ASIS_Mode then
19698 return False;
19699
19700 -- No marker needs to be created when the reference is preanalyzed
19701 -- because the marker will be inserted in the wrong place.
19702
19703 elsif Preanalysis_Active then
19704 return False;
19705
19706 -- Only references warrant a marker
19707
19708 elsif not Nkind_In (N, N_Expanded_Name, N_Identifier) then
19709 return False;
19710
19711 -- Only source references warrant a marker
19712
19713 elsif not Comes_From_Source (N) then
19714 return False;
19715
19716 -- No marker needs to be created when the reference is erroneous, left
19717 -- in a bad state, or does not denote a variable.
19718
19719 elsif not (Present (Entity (N))
19720 and then Ekind (Entity (N)) = E_Variable
19721 and then Entity (N) /= Any_Id)
19722 then
19723 return False;
19724 end if;
19725
19726 Var_Id := Entity (N);
19727 Prag := SPARK_Pragma (Var_Id);
19728
19729 -- Both the variable and reference must appear in SPARK_Mode On regions
19730 -- because this elaboration scenario falls under the SPARK rules.
19731
19732 if not (Comes_From_Source (Var_Id)
19733 and then Present (Prag)
19734 and then Get_SPARK_Mode_From_Annotation (Prag) = On
19735 and then Is_SPARK_Mode_On_Node (N))
19736 then
19737 return False;
19738
19739 -- No marker needs to be created when the reference does not appear
19740 -- within a suitable context (see body for details).
19741
19742 -- Performance note: parent traversal
19743
19744 elsif not Within_Suitable_Context (N) then
19745 return False;
19746 end if;
19747
19748 -- At this point it is known that the variable reference will play a
19749 -- role in ABE diagnostics and requires a marker.
19750
19751 return True;
19752 end Needs_Variable_Reference_Marker;
19753
19754 ------------------------
19755 -- New_Copy_List_Tree --
19756 ------------------------
19757
19758 function New_Copy_List_Tree (List : List_Id) return List_Id is
19759 NL : List_Id;
19760 E : Node_Id;
19761
19762 begin
19763 if List = No_List then
19764 return No_List;
19765
19766 else
19767 NL := New_List;
19768 E := First (List);
19769
19770 while Present (E) loop
19771 Append (New_Copy_Tree (E), NL);
19772 E := Next (E);
19773 end loop;
19774
19775 return NL;
19776 end if;
19777 end New_Copy_List_Tree;
19778
19779 -------------------
19780 -- New_Copy_Tree --
19781 -------------------
19782
19783 -- The following tables play a key role in replicating entities and Itypes.
19784 -- They are intentionally declared at the library level rather than within
19785 -- New_Copy_Tree to avoid elaborating them on each call. This performance
19786 -- optimization saves up to 2% of the entire compilation time spent in the
19787 -- front end. Care should be taken to reset the tables on each new call to
19788 -- New_Copy_Tree.
19789
19790 NCT_Table_Max : constant := 511;
19791
19792 subtype NCT_Table_Index is Nat range 0 .. NCT_Table_Max - 1;
19793
19794 function NCT_Table_Hash (Key : Node_Or_Entity_Id) return NCT_Table_Index;
19795 -- Obtain the hash value of node or entity Key
19796
19797 --------------------
19798 -- NCT_Table_Hash --
19799 --------------------
19800
19801 function NCT_Table_Hash (Key : Node_Or_Entity_Id) return NCT_Table_Index is
19802 begin
19803 return NCT_Table_Index (Key mod NCT_Table_Max);
19804 end NCT_Table_Hash;
19805
19806 ----------------------
19807 -- NCT_New_Entities --
19808 ----------------------
19809
19810 -- The following table maps old entities and Itypes to their corresponding
19811 -- new entities and Itypes.
19812
19813 -- Aaa -> Xxx
19814
19815 package NCT_New_Entities is new Simple_HTable (
19816 Header_Num => NCT_Table_Index,
19817 Element => Entity_Id,
19818 No_Element => Empty,
19819 Key => Entity_Id,
19820 Hash => NCT_Table_Hash,
19821 Equal => "=");
19822
19823 ------------------------
19824 -- NCT_Pending_Itypes --
19825 ------------------------
19826
19827 -- The following table maps old Associated_Node_For_Itype nodes to a set of
19828 -- new itypes. Given a set of old Itypes Aaa, Bbb, and Ccc, where all three
19829 -- have the same Associated_Node_For_Itype Ppp, and their corresponding new
19830 -- Itypes Xxx, Yyy, Zzz, the table contains the following mapping:
19831
19832 -- Ppp -> (Xxx, Yyy, Zzz)
19833
19834 -- The set is expressed as an Elist
19835
19836 package NCT_Pending_Itypes is new Simple_HTable (
19837 Header_Num => NCT_Table_Index,
19838 Element => Elist_Id,
19839 No_Element => No_Elist,
19840 Key => Node_Id,
19841 Hash => NCT_Table_Hash,
19842 Equal => "=");
19843
19844 NCT_Tables_In_Use : Boolean := False;
19845 -- This flag keeps track of whether the two tables NCT_New_Entities and
19846 -- NCT_Pending_Itypes are in use. The flag is part of an optimization
19847 -- where certain operations are not performed if the tables are not in
19848 -- use. This saves up to 8% of the entire compilation time spent in the
19849 -- front end.
19850
19851 -------------------
19852 -- New_Copy_Tree --
19853 -------------------
19854
19855 function New_Copy_Tree
19856 (Source : Node_Id;
19857 Map : Elist_Id := No_Elist;
19858 New_Sloc : Source_Ptr := No_Location;
19859 New_Scope : Entity_Id := Empty;
19860 Scopes_In_EWA_OK : Boolean := False) return Node_Id
19861 is
19862 -- This routine performs low-level tree manipulations and needs access
19863 -- to the internals of the tree.
19864
19865 use Atree.Unchecked_Access;
19866 use Atree_Private_Part;
19867
19868 EWA_Level : Nat := 0;
19869 -- This counter keeps track of how many N_Expression_With_Actions nodes
19870 -- are encountered during a depth-first traversal of the subtree. These
19871 -- nodes may define new entities in their Actions lists and thus require
19872 -- special processing.
19873
19874 EWA_Inner_Scope_Level : Nat := 0;
19875 -- This counter keeps track of how many scoping constructs appear within
19876 -- an N_Expression_With_Actions node.
19877
19878 procedure Add_New_Entity (Old_Id : Entity_Id; New_Id : Entity_Id);
19879 pragma Inline (Add_New_Entity);
19880 -- Add an entry in the NCT_New_Entities table which maps key Old_Id to
19881 -- value New_Id. Old_Id is an entity which appears within the Actions
19882 -- list of an N_Expression_With_Actions node, or within an entity map.
19883 -- New_Id is the corresponding new entity generated during Phase 1.
19884
19885 procedure Add_Pending_Itype (Assoc_Nod : Node_Id; Itype : Entity_Id);
19886 pragma Inline (Add_New_Entity);
19887 -- Add an entry in the NCT_Pending_Itypes which maps key Assoc_Nod to
19888 -- value Itype. Assoc_Nod is the associated node of an itype. Itype is
19889 -- an itype.
19890
19891 procedure Build_NCT_Tables (Entity_Map : Elist_Id);
19892 pragma Inline (Build_NCT_Tables);
19893 -- Populate tables NCT_New_Entities and NCT_Pending_Itypes with the
19894 -- information supplied in entity map Entity_Map. The format of the
19895 -- entity map must be as follows:
19896 --
19897 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
19898
19899 function Copy_Any_Node_With_Replacement
19900 (N : Node_Or_Entity_Id) return Node_Or_Entity_Id;
19901 pragma Inline (Copy_Any_Node_With_Replacement);
19902 -- Replicate entity or node N by invoking one of the following routines:
19903 --
19904 -- Copy_Node_With_Replacement
19905 -- Corresponding_Entity
19906
19907 function Copy_Elist_With_Replacement (List : Elist_Id) return Elist_Id;
19908 -- Replicate the elements of entity list List
19909
19910 function Copy_Field_With_Replacement
19911 (Field : Union_Id;
19912 Old_Par : Node_Id := Empty;
19913 New_Par : Node_Id := Empty;
19914 Semantic : Boolean := False) return Union_Id;
19915 -- Replicate field Field by invoking one of the following routines:
19916 --
19917 -- Copy_Elist_With_Replacement
19918 -- Copy_List_With_Replacement
19919 -- Copy_Node_With_Replacement
19920 -- Corresponding_Entity
19921 --
19922 -- If the field is not an entity list, entity, itype, syntactic list,
19923 -- or node, then the field is returned unchanged. The routine always
19924 -- replicates entities, itypes, and valid syntactic fields. Old_Par is
19925 -- the expected parent of a syntactic field. New_Par is the new parent
19926 -- associated with a replicated syntactic field. Flag Semantic should
19927 -- be set when the input is a semantic field.
19928
19929 function Copy_List_With_Replacement (List : List_Id) return List_Id;
19930 -- Replicate the elements of syntactic list List
19931
19932 function Copy_Node_With_Replacement (N : Node_Id) return Node_Id;
19933 -- Replicate node N
19934
19935 function Corresponding_Entity (Id : Entity_Id) return Entity_Id;
19936 pragma Inline (Corresponding_Entity);
19937 -- Return the corresponding new entity of Id generated during Phase 1.
19938 -- If there is no such entity, return Id.
19939
19940 function In_Entity_Map
19941 (Id : Entity_Id;
19942 Entity_Map : Elist_Id) return Boolean;
19943 pragma Inline (In_Entity_Map);
19944 -- Determine whether entity Id is one of the old ids specified in entity
19945 -- map Entity_Map. The format of the entity map must be as follows:
19946 --
19947 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
19948
19949 procedure Update_CFS_Sloc (N : Node_Or_Entity_Id);
19950 pragma Inline (Update_CFS_Sloc);
19951 -- Update the Comes_From_Source and Sloc attributes of node or entity N
19952
19953 procedure Update_First_Real_Statement
19954 (Old_HSS : Node_Id;
19955 New_HSS : Node_Id);
19956 pragma Inline (Update_First_Real_Statement);
19957 -- Update semantic attribute First_Real_Statement of handled sequence of
19958 -- statements New_HSS based on handled sequence of statements Old_HSS.
19959
19960 procedure Update_Named_Associations
19961 (Old_Call : Node_Id;
19962 New_Call : Node_Id);
19963 pragma Inline (Update_Named_Associations);
19964 -- Update semantic chain First/Next_Named_Association of call New_call
19965 -- based on call Old_Call.
19966
19967 procedure Update_New_Entities (Entity_Map : Elist_Id);
19968 pragma Inline (Update_New_Entities);
19969 -- Update the semantic attributes of all new entities generated during
19970 -- Phase 1 that do not appear in entity map Entity_Map. The format of
19971 -- the entity map must be as follows:
19972 --
19973 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
19974
19975 procedure Update_Pending_Itypes
19976 (Old_Assoc : Node_Id;
19977 New_Assoc : Node_Id);
19978 pragma Inline (Update_Pending_Itypes);
19979 -- Update semantic attribute Associated_Node_For_Itype to refer to node
19980 -- New_Assoc for all itypes whose associated node is Old_Assoc.
19981
19982 procedure Update_Semantic_Fields (Id : Entity_Id);
19983 pragma Inline (Update_Semantic_Fields);
19984 -- Subsidiary to Update_New_Entities. Update semantic fields of entity
19985 -- or itype Id.
19986
19987 procedure Visit_Any_Node (N : Node_Or_Entity_Id);
19988 pragma Inline (Visit_Any_Node);
19989 -- Visit entity of node N by invoking one of the following routines:
19990 --
19991 -- Visit_Entity
19992 -- Visit_Itype
19993 -- Visit_Node
19994
19995 procedure Visit_Elist (List : Elist_Id);
19996 -- Visit the elements of entity list List
19997
19998 procedure Visit_Entity (Id : Entity_Id);
19999 -- Visit entity Id. This action may create a new entity of Id and save
20000 -- it in table NCT_New_Entities.
20001
20002 procedure Visit_Field
20003 (Field : Union_Id;
20004 Par_Nod : Node_Id := Empty;
20005 Semantic : Boolean := False);
20006 -- Visit field Field by invoking one of the following routines:
20007 --
20008 -- Visit_Elist
20009 -- Visit_Entity
20010 -- Visit_Itype
20011 -- Visit_List
20012 -- Visit_Node
20013 --
20014 -- If the field is not an entity list, entity, itype, syntactic list,
20015 -- or node, then the field is not visited. The routine always visits
20016 -- valid syntactic fields. Par_Nod is the expected parent of the
20017 -- syntactic field. Flag Semantic should be set when the input is a
20018 -- semantic field.
20019
20020 procedure Visit_Itype (Itype : Entity_Id);
20021 -- Visit itype Itype. This action may create a new entity for Itype and
20022 -- save it in table NCT_New_Entities. In addition, the routine may map
20023 -- the associated node of Itype to the new itype in NCT_Pending_Itypes.
20024
20025 procedure Visit_List (List : List_Id);
20026 -- Visit the elements of syntactic list List
20027
20028 procedure Visit_Node (N : Node_Id);
20029 -- Visit node N
20030
20031 procedure Visit_Semantic_Fields (Id : Entity_Id);
20032 pragma Inline (Visit_Semantic_Fields);
20033 -- Subsidiary to Visit_Entity and Visit_Itype. Visit common semantic
20034 -- fields of entity or itype Id.
20035
20036 --------------------
20037 -- Add_New_Entity --
20038 --------------------
20039
20040 procedure Add_New_Entity (Old_Id : Entity_Id; New_Id : Entity_Id) is
20041 begin
20042 pragma Assert (Present (Old_Id));
20043 pragma Assert (Present (New_Id));
20044 pragma Assert (Nkind (Old_Id) in N_Entity);
20045 pragma Assert (Nkind (New_Id) in N_Entity);
20046
20047 NCT_Tables_In_Use := True;
20048
20049 -- Sanity check the NCT_New_Entities table. No previous mapping with
20050 -- key Old_Id should exist.
20051
20052 pragma Assert (No (NCT_New_Entities.Get (Old_Id)));
20053
20054 -- Establish the mapping
20055
20056 -- Old_Id -> New_Id
20057
20058 NCT_New_Entities.Set (Old_Id, New_Id);
20059 end Add_New_Entity;
20060
20061 -----------------------
20062 -- Add_Pending_Itype --
20063 -----------------------
20064
20065 procedure Add_Pending_Itype (Assoc_Nod : Node_Id; Itype : Entity_Id) is
20066 Itypes : Elist_Id;
20067
20068 begin
20069 pragma Assert (Present (Assoc_Nod));
20070 pragma Assert (Present (Itype));
20071 pragma Assert (Nkind (Itype) in N_Entity);
20072 pragma Assert (Is_Itype (Itype));
20073
20074 NCT_Tables_In_Use := True;
20075
20076 -- It is not possible to sanity check the NCT_Pendint_Itypes table
20077 -- directly because a single node may act as the associated node for
20078 -- multiple itypes.
20079
20080 Itypes := NCT_Pending_Itypes.Get (Assoc_Nod);
20081
20082 if No (Itypes) then
20083 Itypes := New_Elmt_List;
20084 NCT_Pending_Itypes.Set (Assoc_Nod, Itypes);
20085 end if;
20086
20087 -- Establish the mapping
20088
20089 -- Assoc_Nod -> (Itype, ...)
20090
20091 -- Avoid inserting the same itype multiple times. This involves a
20092 -- linear search, however the set of itypes with the same associated
20093 -- node is very small.
20094
20095 Append_Unique_Elmt (Itype, Itypes);
20096 end Add_Pending_Itype;
20097
20098 ----------------------
20099 -- Build_NCT_Tables --
20100 ----------------------
20101
20102 procedure Build_NCT_Tables (Entity_Map : Elist_Id) is
20103 Elmt : Elmt_Id;
20104 Old_Id : Entity_Id;
20105 New_Id : Entity_Id;
20106
20107 begin
20108 -- Nothing to do when there is no entity map
20109
20110 if No (Entity_Map) then
20111 return;
20112 end if;
20113
20114 Elmt := First_Elmt (Entity_Map);
20115 while Present (Elmt) loop
20116
20117 -- Extract the (Old_Id, New_Id) pair from the entity map
20118
20119 Old_Id := Node (Elmt);
20120 Next_Elmt (Elmt);
20121
20122 New_Id := Node (Elmt);
20123 Next_Elmt (Elmt);
20124
20125 -- Establish the following mapping within table NCT_New_Entities
20126
20127 -- Old_Id -> New_Id
20128
20129 Add_New_Entity (Old_Id, New_Id);
20130
20131 -- Establish the following mapping within table NCT_Pending_Itypes
20132 -- when the new entity is an itype.
20133
20134 -- Assoc_Nod -> (New_Id, ...)
20135
20136 -- IMPORTANT: the associated node is that of the old itype because
20137 -- the node will be replicated in Phase 2.
20138
20139 if Is_Itype (Old_Id) then
20140 Add_Pending_Itype
20141 (Assoc_Nod => Associated_Node_For_Itype (Old_Id),
20142 Itype => New_Id);
20143 end if;
20144 end loop;
20145 end Build_NCT_Tables;
20146
20147 ------------------------------------
20148 -- Copy_Any_Node_With_Replacement --
20149 ------------------------------------
20150
20151 function Copy_Any_Node_With_Replacement
20152 (N : Node_Or_Entity_Id) return Node_Or_Entity_Id
20153 is
20154 begin
20155 if Nkind (N) in N_Entity then
20156 return Corresponding_Entity (N);
20157 else
20158 return Copy_Node_With_Replacement (N);
20159 end if;
20160 end Copy_Any_Node_With_Replacement;
20161
20162 ---------------------------------
20163 -- Copy_Elist_With_Replacement --
20164 ---------------------------------
20165
20166 function Copy_Elist_With_Replacement (List : Elist_Id) return Elist_Id is
20167 Elmt : Elmt_Id;
20168 Result : Elist_Id;
20169
20170 begin
20171 -- Copy the contents of the old list. Note that the list itself may
20172 -- be empty, in which case the routine returns a new empty list. This
20173 -- avoids sharing lists between subtrees. The element of an entity
20174 -- list could be an entity or a node, hence the invocation of routine
20175 -- Copy_Any_Node_With_Replacement.
20176
20177 if Present (List) then
20178 Result := New_Elmt_List;
20179
20180 Elmt := First_Elmt (List);
20181 while Present (Elmt) loop
20182 Append_Elmt
20183 (Copy_Any_Node_With_Replacement (Node (Elmt)), Result);
20184
20185 Next_Elmt (Elmt);
20186 end loop;
20187
20188 -- Otherwise the list does not exist
20189
20190 else
20191 Result := No_Elist;
20192 end if;
20193
20194 return Result;
20195 end Copy_Elist_With_Replacement;
20196
20197 ---------------------------------
20198 -- Copy_Field_With_Replacement --
20199 ---------------------------------
20200
20201 function Copy_Field_With_Replacement
20202 (Field : Union_Id;
20203 Old_Par : Node_Id := Empty;
20204 New_Par : Node_Id := Empty;
20205 Semantic : Boolean := False) return Union_Id
20206 is
20207 begin
20208 -- The field is empty
20209
20210 if Field = Union_Id (Empty) then
20211 return Field;
20212
20213 -- The field is an entity/itype/node
20214
20215 elsif Field in Node_Range then
20216 declare
20217 Old_N : constant Node_Id := Node_Id (Field);
20218 Syntactic : constant Boolean := Parent (Old_N) = Old_Par;
20219
20220 New_N : Node_Id;
20221
20222 begin
20223 -- The field is an entity/itype
20224
20225 if Nkind (Old_N) in N_Entity then
20226
20227 -- An entity/itype is always replicated
20228
20229 New_N := Corresponding_Entity (Old_N);
20230
20231 -- Update the parent pointer when the entity is a syntactic
20232 -- field. Note that itypes do not have parent pointers.
20233
20234 if Syntactic and then New_N /= Old_N then
20235 Set_Parent (New_N, New_Par);
20236 end if;
20237
20238 -- The field is a node
20239
20240 else
20241 -- A node is replicated when it is either a syntactic field
20242 -- or when the caller treats it as a semantic attribute.
20243
20244 if Syntactic or else Semantic then
20245 New_N := Copy_Node_With_Replacement (Old_N);
20246
20247 -- Update the parent pointer when the node is a syntactic
20248 -- field.
20249
20250 if Syntactic and then New_N /= Old_N then
20251 Set_Parent (New_N, New_Par);
20252 end if;
20253
20254 -- Otherwise the node is returned unchanged
20255
20256 else
20257 New_N := Old_N;
20258 end if;
20259 end if;
20260
20261 return Union_Id (New_N);
20262 end;
20263
20264 -- The field is an entity list
20265
20266 elsif Field in Elist_Range then
20267 return Union_Id (Copy_Elist_With_Replacement (Elist_Id (Field)));
20268
20269 -- The field is a syntactic list
20270
20271 elsif Field in List_Range then
20272 declare
20273 Old_List : constant List_Id := List_Id (Field);
20274 Syntactic : constant Boolean := Parent (Old_List) = Old_Par;
20275
20276 New_List : List_Id;
20277
20278 begin
20279 -- A list is replicated when it is either a syntactic field or
20280 -- when the caller treats it as a semantic attribute.
20281
20282 if Syntactic or else Semantic then
20283 New_List := Copy_List_With_Replacement (Old_List);
20284
20285 -- Update the parent pointer when the list is a syntactic
20286 -- field.
20287
20288 if Syntactic and then New_List /= Old_List then
20289 Set_Parent (New_List, New_Par);
20290 end if;
20291
20292 -- Otherwise the list is returned unchanged
20293
20294 else
20295 New_List := Old_List;
20296 end if;
20297
20298 return Union_Id (New_List);
20299 end;
20300
20301 -- Otherwise the field denotes an attribute that does not need to be
20302 -- replicated (Chars, literals, etc).
20303
20304 else
20305 return Field;
20306 end if;
20307 end Copy_Field_With_Replacement;
20308
20309 --------------------------------
20310 -- Copy_List_With_Replacement --
20311 --------------------------------
20312
20313 function Copy_List_With_Replacement (List : List_Id) return List_Id is
20314 Elmt : Node_Id;
20315 Result : List_Id;
20316
20317 begin
20318 -- Copy the contents of the old list. Note that the list itself may
20319 -- be empty, in which case the routine returns a new empty list. This
20320 -- avoids sharing lists between subtrees. The element of a syntactic
20321 -- list is always a node, never an entity or itype, hence the call to
20322 -- routine Copy_Node_With_Replacement.
20323
20324 if Present (List) then
20325 Result := New_List;
20326
20327 Elmt := First (List);
20328 while Present (Elmt) loop
20329 Append (Copy_Node_With_Replacement (Elmt), Result);
20330
20331 Next (Elmt);
20332 end loop;
20333
20334 -- Otherwise the list does not exist
20335
20336 else
20337 Result := No_List;
20338 end if;
20339
20340 return Result;
20341 end Copy_List_With_Replacement;
20342
20343 --------------------------------
20344 -- Copy_Node_With_Replacement --
20345 --------------------------------
20346
20347 function Copy_Node_With_Replacement (N : Node_Id) return Node_Id is
20348 Result : Node_Id;
20349
20350 begin
20351 -- Assume that the node must be returned unchanged
20352
20353 Result := N;
20354
20355 if N > Empty_Or_Error then
20356 pragma Assert (Nkind (N) not in N_Entity);
20357
20358 Result := New_Copy (N);
20359
20360 Set_Field1 (Result,
20361 Copy_Field_With_Replacement
20362 (Field => Field1 (Result),
20363 Old_Par => N,
20364 New_Par => Result));
20365
20366 Set_Field2 (Result,
20367 Copy_Field_With_Replacement
20368 (Field => Field2 (Result),
20369 Old_Par => N,
20370 New_Par => Result));
20371
20372 Set_Field3 (Result,
20373 Copy_Field_With_Replacement
20374 (Field => Field3 (Result),
20375 Old_Par => N,
20376 New_Par => Result));
20377
20378 Set_Field4 (Result,
20379 Copy_Field_With_Replacement
20380 (Field => Field4 (Result),
20381 Old_Par => N,
20382 New_Par => Result));
20383
20384 Set_Field5 (Result,
20385 Copy_Field_With_Replacement
20386 (Field => Field5 (Result),
20387 Old_Par => N,
20388 New_Par => Result));
20389
20390 -- Update the Comes_From_Source and Sloc attributes of the node
20391 -- in case the caller has supplied new values.
20392
20393 Update_CFS_Sloc (Result);
20394
20395 -- Update the Associated_Node_For_Itype attribute of all itypes
20396 -- created during Phase 1 whose associated node is N. As a result
20397 -- the Associated_Node_For_Itype refers to the replicated node.
20398 -- No action needs to be taken when the Associated_Node_For_Itype
20399 -- refers to an entity because this was already handled during
20400 -- Phase 1, in Visit_Itype.
20401
20402 Update_Pending_Itypes
20403 (Old_Assoc => N,
20404 New_Assoc => Result);
20405
20406 -- Update the First/Next_Named_Association chain for a replicated
20407 -- call.
20408
20409 if Nkind_In (N, N_Entry_Call_Statement,
20410 N_Function_Call,
20411 N_Procedure_Call_Statement)
20412 then
20413 Update_Named_Associations
20414 (Old_Call => N,
20415 New_Call => Result);
20416
20417 -- Update the Renamed_Object attribute of a replicated object
20418 -- declaration.
20419
20420 elsif Nkind (N) = N_Object_Renaming_Declaration then
20421 Set_Renamed_Object (Defining_Entity (Result), Name (Result));
20422
20423 -- Update the First_Real_Statement attribute of a replicated
20424 -- handled sequence of statements.
20425
20426 elsif Nkind (N) = N_Handled_Sequence_Of_Statements then
20427 Update_First_Real_Statement
20428 (Old_HSS => N,
20429 New_HSS => Result);
20430 end if;
20431 end if;
20432
20433 return Result;
20434 end Copy_Node_With_Replacement;
20435
20436 --------------------------
20437 -- Corresponding_Entity --
20438 --------------------------
20439
20440 function Corresponding_Entity (Id : Entity_Id) return Entity_Id is
20441 New_Id : Entity_Id;
20442 Result : Entity_Id;
20443
20444 begin
20445 -- Assume that the entity must be returned unchanged
20446
20447 Result := Id;
20448
20449 if Id > Empty_Or_Error then
20450 pragma Assert (Nkind (Id) in N_Entity);
20451
20452 -- Determine whether the entity has a corresponding new entity
20453 -- generated during Phase 1 and if it does, use it.
20454
20455 if NCT_Tables_In_Use then
20456 New_Id := NCT_New_Entities.Get (Id);
20457
20458 if Present (New_Id) then
20459 Result := New_Id;
20460 end if;
20461 end if;
20462 end if;
20463
20464 return Result;
20465 end Corresponding_Entity;
20466
20467 -------------------
20468 -- In_Entity_Map --
20469 -------------------
20470
20471 function In_Entity_Map
20472 (Id : Entity_Id;
20473 Entity_Map : Elist_Id) return Boolean
20474 is
20475 Elmt : Elmt_Id;
20476 Old_Id : Entity_Id;
20477
20478 begin
20479 -- The entity map contains pairs (Old_Id, New_Id). The advancement
20480 -- step always skips the New_Id portion of the pair.
20481
20482 if Present (Entity_Map) then
20483 Elmt := First_Elmt (Entity_Map);
20484 while Present (Elmt) loop
20485 Old_Id := Node (Elmt);
20486
20487 if Old_Id = Id then
20488 return True;
20489 end if;
20490
20491 Next_Elmt (Elmt);
20492 Next_Elmt (Elmt);
20493 end loop;
20494 end if;
20495
20496 return False;
20497 end In_Entity_Map;
20498
20499 ---------------------
20500 -- Update_CFS_Sloc --
20501 ---------------------
20502
20503 procedure Update_CFS_Sloc (N : Node_Or_Entity_Id) is
20504 begin
20505 -- A new source location defaults the Comes_From_Source attribute
20506
20507 if New_Sloc /= No_Location then
20508 Set_Comes_From_Source (N, Default_Node.Comes_From_Source);
20509 Set_Sloc (N, New_Sloc);
20510 end if;
20511 end Update_CFS_Sloc;
20512
20513 ---------------------------------
20514 -- Update_First_Real_Statement --
20515 ---------------------------------
20516
20517 procedure Update_First_Real_Statement
20518 (Old_HSS : Node_Id;
20519 New_HSS : Node_Id)
20520 is
20521 Old_First_Stmt : constant Node_Id := First_Real_Statement (Old_HSS);
20522
20523 New_Stmt : Node_Id;
20524 Old_Stmt : Node_Id;
20525
20526 begin
20527 -- Recreate the First_Real_Statement attribute of a handled sequence
20528 -- of statements by traversing the statement lists of both sequences
20529 -- in parallel.
20530
20531 if Present (Old_First_Stmt) then
20532 New_Stmt := First (Statements (New_HSS));
20533 Old_Stmt := First (Statements (Old_HSS));
20534 while Present (Old_Stmt) and then Old_Stmt /= Old_First_Stmt loop
20535 Next (New_Stmt);
20536 Next (Old_Stmt);
20537 end loop;
20538
20539 pragma Assert (Present (New_Stmt));
20540 pragma Assert (Present (Old_Stmt));
20541
20542 Set_First_Real_Statement (New_HSS, New_Stmt);
20543 end if;
20544 end Update_First_Real_Statement;
20545
20546 -------------------------------
20547 -- Update_Named_Associations --
20548 -------------------------------
20549
20550 procedure Update_Named_Associations
20551 (Old_Call : Node_Id;
20552 New_Call : Node_Id)
20553 is
20554 New_Act : Node_Id;
20555 New_Next : Node_Id;
20556 Old_Act : Node_Id;
20557 Old_Next : Node_Id;
20558
20559 begin
20560 -- Recreate the First/Next_Named_Actual chain of a call by traversing
20561 -- the chains of both the old and new calls in parallel.
20562
20563 New_Act := First (Parameter_Associations (New_Call));
20564 Old_Act := First (Parameter_Associations (Old_Call));
20565 while Present (Old_Act) loop
20566 if Nkind (Old_Act) = N_Parameter_Association
20567 and then Present (Next_Named_Actual (Old_Act))
20568 then
20569 if First_Named_Actual (Old_Call) =
20570 Explicit_Actual_Parameter (Old_Act)
20571 then
20572 Set_First_Named_Actual (New_Call,
20573 Explicit_Actual_Parameter (New_Act));
20574 end if;
20575
20576 -- Scan the actual parameter list to find the next suitable
20577 -- named actual. Note that the list may be out of order.
20578
20579 New_Next := First (Parameter_Associations (New_Call));
20580 Old_Next := First (Parameter_Associations (Old_Call));
20581 while Nkind (Old_Next) /= N_Parameter_Association
20582 or else Explicit_Actual_Parameter (Old_Next) /=
20583 Next_Named_Actual (Old_Act)
20584 loop
20585 Next (New_Next);
20586 Next (Old_Next);
20587 end loop;
20588
20589 Set_Next_Named_Actual (New_Act,
20590 Explicit_Actual_Parameter (New_Next));
20591 end if;
20592
20593 Next (New_Act);
20594 Next (Old_Act);
20595 end loop;
20596 end Update_Named_Associations;
20597
20598 -------------------------
20599 -- Update_New_Entities --
20600 -------------------------
20601
20602 procedure Update_New_Entities (Entity_Map : Elist_Id) is
20603 New_Id : Entity_Id := Empty;
20604 Old_Id : Entity_Id := Empty;
20605
20606 begin
20607 if NCT_Tables_In_Use then
20608 NCT_New_Entities.Get_First (Old_Id, New_Id);
20609
20610 -- Update the semantic fields of all new entities created during
20611 -- Phase 1 which were not supplied via an entity map.
20612 -- ??? Is there a better way of distinguishing those?
20613
20614 while Present (Old_Id) and then Present (New_Id) loop
20615 if not (Present (Entity_Map)
20616 and then In_Entity_Map (Old_Id, Entity_Map))
20617 then
20618 Update_Semantic_Fields (New_Id);
20619 end if;
20620
20621 NCT_New_Entities.Get_Next (Old_Id, New_Id);
20622 end loop;
20623 end if;
20624 end Update_New_Entities;
20625
20626 ---------------------------
20627 -- Update_Pending_Itypes --
20628 ---------------------------
20629
20630 procedure Update_Pending_Itypes
20631 (Old_Assoc : Node_Id;
20632 New_Assoc : Node_Id)
20633 is
20634 Item : Elmt_Id;
20635 Itypes : Elist_Id;
20636
20637 begin
20638 if NCT_Tables_In_Use then
20639 Itypes := NCT_Pending_Itypes.Get (Old_Assoc);
20640
20641 -- Update the Associated_Node_For_Itype attribute for all itypes
20642 -- which originally refer to Old_Assoc to designate New_Assoc.
20643
20644 if Present (Itypes) then
20645 Item := First_Elmt (Itypes);
20646 while Present (Item) loop
20647 Set_Associated_Node_For_Itype (Node (Item), New_Assoc);
20648
20649 Next_Elmt (Item);
20650 end loop;
20651 end if;
20652 end if;
20653 end Update_Pending_Itypes;
20654
20655 ----------------------------
20656 -- Update_Semantic_Fields --
20657 ----------------------------
20658
20659 procedure Update_Semantic_Fields (Id : Entity_Id) is
20660 begin
20661 -- Discriminant_Constraint
20662
20663 if Is_Type (Id) and then Has_Discriminants (Base_Type (Id)) then
20664 Set_Discriminant_Constraint (Id, Elist_Id (
20665 Copy_Field_With_Replacement
20666 (Field => Union_Id (Discriminant_Constraint (Id)),
20667 Semantic => True)));
20668 end if;
20669
20670 -- Etype
20671
20672 Set_Etype (Id, Node_Id (
20673 Copy_Field_With_Replacement
20674 (Field => Union_Id (Etype (Id)),
20675 Semantic => True)));
20676
20677 -- First_Index
20678 -- Packed_Array_Impl_Type
20679
20680 if Is_Array_Type (Id) then
20681 if Present (First_Index (Id)) then
20682 Set_First_Index (Id, First (List_Id (
20683 Copy_Field_With_Replacement
20684 (Field => Union_Id (List_Containing (First_Index (Id))),
20685 Semantic => True))));
20686 end if;
20687
20688 if Is_Packed (Id) then
20689 Set_Packed_Array_Impl_Type (Id, Node_Id (
20690 Copy_Field_With_Replacement
20691 (Field => Union_Id (Packed_Array_Impl_Type (Id)),
20692 Semantic => True)));
20693 end if;
20694 end if;
20695
20696 -- Prev_Entity
20697
20698 Set_Prev_Entity (Id, Node_Id (
20699 Copy_Field_With_Replacement
20700 (Field => Union_Id (Prev_Entity (Id)),
20701 Semantic => True)));
20702
20703 -- Next_Entity
20704
20705 Set_Next_Entity (Id, Node_Id (
20706 Copy_Field_With_Replacement
20707 (Field => Union_Id (Next_Entity (Id)),
20708 Semantic => True)));
20709
20710 -- Scalar_Range
20711
20712 if Is_Discrete_Type (Id) then
20713 Set_Scalar_Range (Id, Node_Id (
20714 Copy_Field_With_Replacement
20715 (Field => Union_Id (Scalar_Range (Id)),
20716 Semantic => True)));
20717 end if;
20718
20719 -- Scope
20720
20721 -- Update the scope when the caller specified an explicit one
20722
20723 if Present (New_Scope) then
20724 Set_Scope (Id, New_Scope);
20725 else
20726 Set_Scope (Id, Node_Id (
20727 Copy_Field_With_Replacement
20728 (Field => Union_Id (Scope (Id)),
20729 Semantic => True)));
20730 end if;
20731 end Update_Semantic_Fields;
20732
20733 --------------------
20734 -- Visit_Any_Node --
20735 --------------------
20736
20737 procedure Visit_Any_Node (N : Node_Or_Entity_Id) is
20738 begin
20739 if Nkind (N) in N_Entity then
20740 if Is_Itype (N) then
20741 Visit_Itype (N);
20742 else
20743 Visit_Entity (N);
20744 end if;
20745 else
20746 Visit_Node (N);
20747 end if;
20748 end Visit_Any_Node;
20749
20750 -----------------
20751 -- Visit_Elist --
20752 -----------------
20753
20754 procedure Visit_Elist (List : Elist_Id) is
20755 Elmt : Elmt_Id;
20756
20757 begin
20758 -- The element of an entity list could be an entity, itype, or a
20759 -- node, hence the call to Visit_Any_Node.
20760
20761 if Present (List) then
20762 Elmt := First_Elmt (List);
20763 while Present (Elmt) loop
20764 Visit_Any_Node (Node (Elmt));
20765
20766 Next_Elmt (Elmt);
20767 end loop;
20768 end if;
20769 end Visit_Elist;
20770
20771 ------------------
20772 -- Visit_Entity --
20773 ------------------
20774
20775 procedure Visit_Entity (Id : Entity_Id) is
20776 New_Id : Entity_Id;
20777
20778 begin
20779 pragma Assert (Nkind (Id) in N_Entity);
20780 pragma Assert (not Is_Itype (Id));
20781
20782 -- Nothing to do when the entity is not defined in the Actions list
20783 -- of an N_Expression_With_Actions node.
20784
20785 if EWA_Level = 0 then
20786 return;
20787
20788 -- Nothing to do when the entity is defined in a scoping construct
20789 -- within an N_Expression_With_Actions node, unless the caller has
20790 -- requested their replication.
20791
20792 -- ??? should this restriction be eliminated?
20793
20794 elsif EWA_Inner_Scope_Level > 0 and then not Scopes_In_EWA_OK then
20795 return;
20796
20797 -- Nothing to do when the entity does not denote a construct that
20798 -- may appear within an N_Expression_With_Actions node. Relaxing
20799 -- this restriction leads to a performance penalty.
20800
20801 -- ??? this list is flaky, and may hide dormant bugs
20802
20803 elsif not Ekind_In (Id, E_Block,
20804 E_Constant,
20805 E_Label,
20806 E_Procedure,
20807 E_Variable)
20808 and then not Is_Type (Id)
20809 then
20810 return;
20811
20812 -- Nothing to do when the entity was already visited
20813
20814 elsif NCT_Tables_In_Use
20815 and then Present (NCT_New_Entities.Get (Id))
20816 then
20817 return;
20818
20819 -- Nothing to do when the declaration node of the entity is not in
20820 -- the subtree being replicated.
20821
20822 elsif not In_Subtree
20823 (N => Declaration_Node (Id),
20824 Root => Source)
20825 then
20826 return;
20827 end if;
20828
20829 -- Create a new entity by directly copying the old entity. This
20830 -- action causes all attributes of the old entity to be inherited.
20831
20832 New_Id := New_Copy (Id);
20833
20834 -- Create a new name for the new entity because the back end needs
20835 -- distinct names for debugging purposes.
20836
20837 Set_Chars (New_Id, New_Internal_Name ('T'));
20838
20839 -- Update the Comes_From_Source and Sloc attributes of the entity in
20840 -- case the caller has supplied new values.
20841
20842 Update_CFS_Sloc (New_Id);
20843
20844 -- Establish the following mapping within table NCT_New_Entities:
20845
20846 -- Id -> New_Id
20847
20848 Add_New_Entity (Id, New_Id);
20849
20850 -- Deal with the semantic fields of entities. The fields are visited
20851 -- because they may mention entities which reside within the subtree
20852 -- being copied.
20853
20854 Visit_Semantic_Fields (Id);
20855 end Visit_Entity;
20856
20857 -----------------
20858 -- Visit_Field --
20859 -----------------
20860
20861 procedure Visit_Field
20862 (Field : Union_Id;
20863 Par_Nod : Node_Id := Empty;
20864 Semantic : Boolean := False)
20865 is
20866 begin
20867 -- The field is empty
20868
20869 if Field = Union_Id (Empty) then
20870 return;
20871
20872 -- The field is an entity/itype/node
20873
20874 elsif Field in Node_Range then
20875 declare
20876 N : constant Node_Id := Node_Id (Field);
20877
20878 begin
20879 -- The field is an entity/itype
20880
20881 if Nkind (N) in N_Entity then
20882
20883 -- Itypes are always visited
20884
20885 if Is_Itype (N) then
20886 Visit_Itype (N);
20887
20888 -- An entity is visited when it is either a syntactic field
20889 -- or when the caller treats it as a semantic attribute.
20890
20891 elsif Parent (N) = Par_Nod or else Semantic then
20892 Visit_Entity (N);
20893 end if;
20894
20895 -- The field is a node
20896
20897 else
20898 -- A node is visited when it is either a syntactic field or
20899 -- when the caller treats it as a semantic attribute.
20900
20901 if Parent (N) = Par_Nod or else Semantic then
20902 Visit_Node (N);
20903 end if;
20904 end if;
20905 end;
20906
20907 -- The field is an entity list
20908
20909 elsif Field in Elist_Range then
20910 Visit_Elist (Elist_Id (Field));
20911
20912 -- The field is a syntax list
20913
20914 elsif Field in List_Range then
20915 declare
20916 List : constant List_Id := List_Id (Field);
20917
20918 begin
20919 -- A syntax list is visited when it is either a syntactic field
20920 -- or when the caller treats it as a semantic attribute.
20921
20922 if Parent (List) = Par_Nod or else Semantic then
20923 Visit_List (List);
20924 end if;
20925 end;
20926
20927 -- Otherwise the field denotes information which does not need to be
20928 -- visited (chars, literals, etc.).
20929
20930 else
20931 null;
20932 end if;
20933 end Visit_Field;
20934
20935 -----------------
20936 -- Visit_Itype --
20937 -----------------
20938
20939 procedure Visit_Itype (Itype : Entity_Id) is
20940 New_Assoc : Node_Id;
20941 New_Itype : Entity_Id;
20942 Old_Assoc : Node_Id;
20943
20944 begin
20945 pragma Assert (Nkind (Itype) in N_Entity);
20946 pragma Assert (Is_Itype (Itype));
20947
20948 -- Itypes that describe the designated type of access to subprograms
20949 -- have the structure of subprogram declarations, with signatures,
20950 -- etc. Either we duplicate the signatures completely, or choose to
20951 -- share such itypes, which is fine because their elaboration will
20952 -- have no side effects.
20953
20954 if Ekind (Itype) = E_Subprogram_Type then
20955 return;
20956
20957 -- Nothing to do if the itype was already visited
20958
20959 elsif NCT_Tables_In_Use
20960 and then Present (NCT_New_Entities.Get (Itype))
20961 then
20962 return;
20963
20964 -- Nothing to do if the associated node of the itype is not within
20965 -- the subtree being replicated.
20966
20967 elsif not In_Subtree
20968 (N => Associated_Node_For_Itype (Itype),
20969 Root => Source)
20970 then
20971 return;
20972 end if;
20973
20974 -- Create a new itype by directly copying the old itype. This action
20975 -- causes all attributes of the old itype to be inherited.
20976
20977 New_Itype := New_Copy (Itype);
20978
20979 -- Create a new name for the new itype because the back end requires
20980 -- distinct names for debugging purposes.
20981
20982 Set_Chars (New_Itype, New_Internal_Name ('T'));
20983
20984 -- Update the Comes_From_Source and Sloc attributes of the itype in
20985 -- case the caller has supplied new values.
20986
20987 Update_CFS_Sloc (New_Itype);
20988
20989 -- Establish the following mapping within table NCT_New_Entities:
20990
20991 -- Itype -> New_Itype
20992
20993 Add_New_Entity (Itype, New_Itype);
20994
20995 -- The new itype must be unfrozen because the resulting subtree may
20996 -- be inserted anywhere and cause an earlier or later freezing.
20997
20998 if Present (Freeze_Node (New_Itype)) then
20999 Set_Freeze_Node (New_Itype, Empty);
21000 Set_Is_Frozen (New_Itype, False);
21001 end if;
21002
21003 -- If a record subtype is simply copied, the entity list will be
21004 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
21005 -- ??? What does this do?
21006
21007 if Ekind_In (Itype, E_Class_Wide_Subtype, E_Record_Subtype) then
21008 Set_Cloned_Subtype (New_Itype, Itype);
21009 end if;
21010
21011 -- The associated node may denote an entity, in which case it may
21012 -- already have a new corresponding entity created during a prior
21013 -- call to Visit_Entity or Visit_Itype for the same subtree.
21014
21015 -- Given
21016 -- Old_Assoc ---------> New_Assoc
21017
21018 -- Created by Visit_Itype
21019 -- Itype -------------> New_Itype
21020 -- ANFI = Old_Assoc ANFI = Old_Assoc < must be updated
21021
21022 -- In the example above, Old_Assoc is an arbitrary entity that was
21023 -- already visited for the same subtree and has a corresponding new
21024 -- entity New_Assoc. Old_Assoc was inherited by New_Itype by virtue
21025 -- of copying entities, however it must be updated to New_Assoc.
21026
21027 Old_Assoc := Associated_Node_For_Itype (Itype);
21028
21029 if Nkind (Old_Assoc) in N_Entity then
21030 if NCT_Tables_In_Use then
21031 New_Assoc := NCT_New_Entities.Get (Old_Assoc);
21032
21033 if Present (New_Assoc) then
21034 Set_Associated_Node_For_Itype (New_Itype, New_Assoc);
21035 end if;
21036 end if;
21037
21038 -- Otherwise the associated node denotes a node. Postpone the update
21039 -- until Phase 2 when the node is replicated. Establish the following
21040 -- mapping within table NCT_Pending_Itypes:
21041
21042 -- Old_Assoc -> (New_Type, ...)
21043
21044 else
21045 Add_Pending_Itype (Old_Assoc, New_Itype);
21046 end if;
21047
21048 -- Deal with the semantic fields of itypes. The fields are visited
21049 -- because they may mention entities that reside within the subtree
21050 -- being copied.
21051
21052 Visit_Semantic_Fields (Itype);
21053 end Visit_Itype;
21054
21055 ----------------
21056 -- Visit_List --
21057 ----------------
21058
21059 procedure Visit_List (List : List_Id) is
21060 Elmt : Node_Id;
21061
21062 begin
21063 -- Note that the element of a syntactic list is always a node, never
21064 -- an entity or itype, hence the call to Visit_Node.
21065
21066 if Present (List) then
21067 Elmt := First (List);
21068 while Present (Elmt) loop
21069 Visit_Node (Elmt);
21070
21071 Next (Elmt);
21072 end loop;
21073 end if;
21074 end Visit_List;
21075
21076 ----------------
21077 -- Visit_Node --
21078 ----------------
21079
21080 procedure Visit_Node (N : Node_Or_Entity_Id) is
21081 begin
21082 pragma Assert (Nkind (N) not in N_Entity);
21083
21084 if Nkind (N) = N_Expression_With_Actions then
21085 EWA_Level := EWA_Level + 1;
21086
21087 elsif EWA_Level > 0
21088 and then Nkind_In (N, N_Block_Statement,
21089 N_Subprogram_Body,
21090 N_Subprogram_Declaration)
21091 then
21092 EWA_Inner_Scope_Level := EWA_Inner_Scope_Level + 1;
21093 end if;
21094
21095 Visit_Field
21096 (Field => Field1 (N),
21097 Par_Nod => N);
21098
21099 Visit_Field
21100 (Field => Field2 (N),
21101 Par_Nod => N);
21102
21103 Visit_Field
21104 (Field => Field3 (N),
21105 Par_Nod => N);
21106
21107 Visit_Field
21108 (Field => Field4 (N),
21109 Par_Nod => N);
21110
21111 Visit_Field
21112 (Field => Field5 (N),
21113 Par_Nod => N);
21114
21115 if EWA_Level > 0
21116 and then Nkind_In (N, N_Block_Statement,
21117 N_Subprogram_Body,
21118 N_Subprogram_Declaration)
21119 then
21120 EWA_Inner_Scope_Level := EWA_Inner_Scope_Level - 1;
21121
21122 elsif Nkind (N) = N_Expression_With_Actions then
21123 EWA_Level := EWA_Level - 1;
21124 end if;
21125 end Visit_Node;
21126
21127 ---------------------------
21128 -- Visit_Semantic_Fields --
21129 ---------------------------
21130
21131 procedure Visit_Semantic_Fields (Id : Entity_Id) is
21132 begin
21133 pragma Assert (Nkind (Id) in N_Entity);
21134
21135 -- Discriminant_Constraint
21136
21137 if Is_Type (Id) and then Has_Discriminants (Base_Type (Id)) then
21138 Visit_Field
21139 (Field => Union_Id (Discriminant_Constraint (Id)),
21140 Semantic => True);
21141 end if;
21142
21143 -- Etype
21144
21145 Visit_Field
21146 (Field => Union_Id (Etype (Id)),
21147 Semantic => True);
21148
21149 -- First_Index
21150 -- Packed_Array_Impl_Type
21151
21152 if Is_Array_Type (Id) then
21153 if Present (First_Index (Id)) then
21154 Visit_Field
21155 (Field => Union_Id (List_Containing (First_Index (Id))),
21156 Semantic => True);
21157 end if;
21158
21159 if Is_Packed (Id) then
21160 Visit_Field
21161 (Field => Union_Id (Packed_Array_Impl_Type (Id)),
21162 Semantic => True);
21163 end if;
21164 end if;
21165
21166 -- Scalar_Range
21167
21168 if Is_Discrete_Type (Id) then
21169 Visit_Field
21170 (Field => Union_Id (Scalar_Range (Id)),
21171 Semantic => True);
21172 end if;
21173 end Visit_Semantic_Fields;
21174
21175 -- Start of processing for New_Copy_Tree
21176
21177 begin
21178 -- Routine New_Copy_Tree performs a deep copy of a subtree by creating
21179 -- shallow copies for each node within, and then updating the child and
21180 -- parent pointers accordingly. This process is straightforward, however
21181 -- the routine must deal with the following complications:
21182
21183 -- * Entities defined within N_Expression_With_Actions nodes must be
21184 -- replicated rather than shared to avoid introducing two identical
21185 -- symbols within the same scope. Note that no other expression can
21186 -- currently define entities.
21187
21188 -- do
21189 -- Source_Low : ...;
21190 -- Source_High : ...;
21191
21192 -- <reference to Source_Low>
21193 -- <reference to Source_High>
21194 -- in ... end;
21195
21196 -- New_Copy_Tree handles this case by first creating new entities
21197 -- and then updating all existing references to point to these new
21198 -- entities.
21199
21200 -- do
21201 -- New_Low : ...;
21202 -- New_High : ...;
21203
21204 -- <reference to New_Low>
21205 -- <reference to New_High>
21206 -- in ... end;
21207
21208 -- * Itypes defined within the subtree must be replicated to avoid any
21209 -- dependencies on invalid or inaccessible data.
21210
21211 -- subtype Source_Itype is ... range Source_Low .. Source_High;
21212
21213 -- New_Copy_Tree handles this case by first creating a new itype in
21214 -- the same fashion as entities, and then updating various relevant
21215 -- constraints.
21216
21217 -- subtype New_Itype is ... range New_Low .. New_High;
21218
21219 -- * The Associated_Node_For_Itype field of itypes must be updated to
21220 -- reference the proper replicated entity or node.
21221
21222 -- * Semantic fields of entities such as Etype and Scope must be
21223 -- updated to reference the proper replicated entities.
21224
21225 -- * Semantic fields of nodes such as First_Real_Statement must be
21226 -- updated to reference the proper replicated nodes.
21227
21228 -- To meet all these demands, routine New_Copy_Tree is split into two
21229 -- phases.
21230
21231 -- Phase 1 traverses the tree in order to locate entities and itypes
21232 -- defined within the subtree. New entities are generated and saved in
21233 -- table NCT_New_Entities. The semantic fields of all new entities and
21234 -- itypes are then updated accordingly.
21235
21236 -- Phase 2 traverses the tree in order to replicate each node. Various
21237 -- semantic fields of nodes and entities are updated accordingly.
21238
21239 -- Preparatory phase. Clear the contents of tables NCT_New_Entities and
21240 -- NCT_Pending_Itypes in case a previous call to New_Copy_Tree left some
21241 -- data inside.
21242
21243 if NCT_Tables_In_Use then
21244 NCT_Tables_In_Use := False;
21245
21246 NCT_New_Entities.Reset;
21247 NCT_Pending_Itypes.Reset;
21248 end if;
21249
21250 -- Populate tables NCT_New_Entities and NCT_Pending_Itypes with data
21251 -- supplied by a linear entity map. The tables offer faster access to
21252 -- the same data.
21253
21254 Build_NCT_Tables (Map);
21255
21256 -- Execute Phase 1. Traverse the subtree and generate new entities for
21257 -- the following cases:
21258
21259 -- * An entity defined within an N_Expression_With_Actions node
21260
21261 -- * An itype referenced within the subtree where the associated node
21262 -- is also in the subtree.
21263
21264 -- All new entities are accessible via table NCT_New_Entities, which
21265 -- contains mappings of the form:
21266
21267 -- Old_Entity -> New_Entity
21268 -- Old_Itype -> New_Itype
21269
21270 -- In addition, the associated nodes of all new itypes are mapped in
21271 -- table NCT_Pending_Itypes:
21272
21273 -- Assoc_Nod -> (New_Itype1, New_Itype2, .., New_ItypeN)
21274
21275 Visit_Any_Node (Source);
21276
21277 -- Update the semantic attributes of all new entities generated during
21278 -- Phase 1 before starting Phase 2. The updates could be performed in
21279 -- routine Corresponding_Entity, however this may cause the same entity
21280 -- to be updated multiple times, effectively generating useless nodes.
21281 -- Keeping the updates separates from Phase 2 ensures that only one set
21282 -- of attributes is generated for an entity at any one time.
21283
21284 Update_New_Entities (Map);
21285
21286 -- Execute Phase 2. Replicate the source subtree one node at a time.
21287 -- The following transformations take place:
21288
21289 -- * References to entities and itypes are updated to refer to the
21290 -- new entities and itypes generated during Phase 1.
21291
21292 -- * All Associated_Node_For_Itype attributes of itypes are updated
21293 -- to refer to the new replicated Associated_Node_For_Itype.
21294
21295 return Copy_Node_With_Replacement (Source);
21296 end New_Copy_Tree;
21297
21298 -------------------------
21299 -- New_External_Entity --
21300 -------------------------
21301
21302 function New_External_Entity
21303 (Kind : Entity_Kind;
21304 Scope_Id : Entity_Id;
21305 Sloc_Value : Source_Ptr;
21306 Related_Id : Entity_Id;
21307 Suffix : Character;
21308 Suffix_Index : Int := 0;
21309 Prefix : Character := ' ') return Entity_Id
21310 is
21311 N : constant Entity_Id :=
21312 Make_Defining_Identifier (Sloc_Value,
21313 New_External_Name
21314 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
21315
21316 begin
21317 Set_Ekind (N, Kind);
21318 Set_Is_Internal (N, True);
21319 Append_Entity (N, Scope_Id);
21320 Set_Public_Status (N);
21321
21322 if Kind in Type_Kind then
21323 Init_Size_Align (N);
21324 end if;
21325
21326 return N;
21327 end New_External_Entity;
21328
21329 -------------------------
21330 -- New_Internal_Entity --
21331 -------------------------
21332
21333 function New_Internal_Entity
21334 (Kind : Entity_Kind;
21335 Scope_Id : Entity_Id;
21336 Sloc_Value : Source_Ptr;
21337 Id_Char : Character) return Entity_Id
21338 is
21339 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
21340
21341 begin
21342 Set_Ekind (N, Kind);
21343 Set_Is_Internal (N, True);
21344 Append_Entity (N, Scope_Id);
21345
21346 if Kind in Type_Kind then
21347 Init_Size_Align (N);
21348 end if;
21349
21350 return N;
21351 end New_Internal_Entity;
21352
21353 -----------------
21354 -- Next_Actual --
21355 -----------------
21356
21357 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
21358 Par : constant Node_Id := Parent (Actual_Id);
21359 N : Node_Id;
21360
21361 begin
21362 -- If we are pointing at a positional parameter, it is a member of a
21363 -- node list (the list of parameters), and the next parameter is the
21364 -- next node on the list, unless we hit a parameter association, then
21365 -- we shift to using the chain whose head is the First_Named_Actual in
21366 -- the parent, and then is threaded using the Next_Named_Actual of the
21367 -- Parameter_Association. All this fiddling is because the original node
21368 -- list is in the textual call order, and what we need is the
21369 -- declaration order.
21370
21371 if Is_List_Member (Actual_Id) then
21372 N := Next (Actual_Id);
21373
21374 if Nkind (N) = N_Parameter_Association then
21375
21376 -- In case of a build-in-place call, the call will no longer be a
21377 -- call; it will have been rewritten.
21378
21379 if Nkind_In (Par, N_Entry_Call_Statement,
21380 N_Function_Call,
21381 N_Procedure_Call_Statement)
21382 then
21383 return First_Named_Actual (Par);
21384
21385 -- In case of a call rewritten in GNATprove mode while "inlining
21386 -- for proof" go to the original call.
21387
21388 elsif Nkind (Par) = N_Null_Statement then
21389 pragma Assert
21390 (GNATprove_Mode
21391 and then
21392 Nkind (Original_Node (Par)) in N_Subprogram_Call);
21393
21394 return First_Named_Actual (Original_Node (Par));
21395 else
21396 return Empty;
21397 end if;
21398 else
21399 return N;
21400 end if;
21401
21402 else
21403 return Next_Named_Actual (Parent (Actual_Id));
21404 end if;
21405 end Next_Actual;
21406
21407 procedure Next_Actual (Actual_Id : in out Node_Id) is
21408 begin
21409 Actual_Id := Next_Actual (Actual_Id);
21410 end Next_Actual;
21411
21412 -----------------
21413 -- Next_Global --
21414 -----------------
21415
21416 function Next_Global (Node : Node_Id) return Node_Id is
21417 begin
21418 -- The global item may either be in a list, or by itself, in which case
21419 -- there is no next global item with the same mode.
21420
21421 if Is_List_Member (Node) then
21422 return Next (Node);
21423 else
21424 return Empty;
21425 end if;
21426 end Next_Global;
21427
21428 procedure Next_Global (Node : in out Node_Id) is
21429 begin
21430 Node := Next_Global (Node);
21431 end Next_Global;
21432
21433 ----------------------------------
21434 -- New_Requires_Transient_Scope --
21435 ----------------------------------
21436
21437 function New_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
21438 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean;
21439 -- This is called for untagged records and protected types, with
21440 -- nondefaulted discriminants. Returns True if the size of function
21441 -- results is known at the call site, False otherwise. Returns False
21442 -- if there is a variant part that depends on the discriminants of
21443 -- this type, or if there is an array constrained by the discriminants
21444 -- of this type. ???Currently, this is overly conservative (the array
21445 -- could be nested inside some other record that is constrained by
21446 -- nondiscriminants). That is, the recursive calls are too conservative.
21447
21448 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean;
21449 -- Returns True if Typ is a nonlimited record with defaulted
21450 -- discriminants whose max size makes it unsuitable for allocating on
21451 -- the primary stack.
21452
21453 ------------------------------
21454 -- Caller_Known_Size_Record --
21455 ------------------------------
21456
21457 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean is
21458 pragma Assert (Typ = Underlying_Type (Typ));
21459
21460 begin
21461 if Has_Variant_Part (Typ) and then not Is_Definite_Subtype (Typ) then
21462 return False;
21463 end if;
21464
21465 declare
21466 Comp : Entity_Id;
21467
21468 begin
21469 Comp := First_Entity (Typ);
21470 while Present (Comp) loop
21471
21472 -- Only look at E_Component entities. No need to look at
21473 -- E_Discriminant entities, and we must ignore internal
21474 -- subtypes generated for constrained components.
21475
21476 if Ekind (Comp) = E_Component then
21477 declare
21478 Comp_Type : constant Entity_Id :=
21479 Underlying_Type (Etype (Comp));
21480
21481 begin
21482 if Is_Record_Type (Comp_Type)
21483 or else
21484 Is_Protected_Type (Comp_Type)
21485 then
21486 if not Caller_Known_Size_Record (Comp_Type) then
21487 return False;
21488 end if;
21489
21490 elsif Is_Array_Type (Comp_Type) then
21491 if Size_Depends_On_Discriminant (Comp_Type) then
21492 return False;
21493 end if;
21494 end if;
21495 end;
21496 end if;
21497
21498 Next_Entity (Comp);
21499 end loop;
21500 end;
21501
21502 return True;
21503 end Caller_Known_Size_Record;
21504
21505 ------------------------------
21506 -- Large_Max_Size_Mutable --
21507 ------------------------------
21508
21509 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean is
21510 pragma Assert (Typ = Underlying_Type (Typ));
21511
21512 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean;
21513 -- Returns true if the discrete type T has a large range
21514
21515 ----------------------------
21516 -- Is_Large_Discrete_Type --
21517 ----------------------------
21518
21519 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean is
21520 Threshold : constant Int := 16;
21521 -- Arbitrary threshold above which we consider it "large". We want
21522 -- a fairly large threshold, because these large types really
21523 -- shouldn't have default discriminants in the first place, in
21524 -- most cases.
21525
21526 begin
21527 return UI_To_Int (RM_Size (T)) > Threshold;
21528 end Is_Large_Discrete_Type;
21529
21530 -- Start of processing for Large_Max_Size_Mutable
21531
21532 begin
21533 if Is_Record_Type (Typ)
21534 and then not Is_Limited_View (Typ)
21535 and then Has_Defaulted_Discriminants (Typ)
21536 then
21537 -- Loop through the components, looking for an array whose upper
21538 -- bound(s) depends on discriminants, where both the subtype of
21539 -- the discriminant and the index subtype are too large.
21540
21541 declare
21542 Comp : Entity_Id;
21543
21544 begin
21545 Comp := First_Entity (Typ);
21546 while Present (Comp) loop
21547 if Ekind (Comp) = E_Component then
21548 declare
21549 Comp_Type : constant Entity_Id :=
21550 Underlying_Type (Etype (Comp));
21551
21552 Hi : Node_Id;
21553 Indx : Node_Id;
21554 Ityp : Entity_Id;
21555
21556 begin
21557 if Is_Array_Type (Comp_Type) then
21558 Indx := First_Index (Comp_Type);
21559
21560 while Present (Indx) loop
21561 Ityp := Etype (Indx);
21562 Hi := Type_High_Bound (Ityp);
21563
21564 if Nkind (Hi) = N_Identifier
21565 and then Ekind (Entity (Hi)) = E_Discriminant
21566 and then Is_Large_Discrete_Type (Ityp)
21567 and then Is_Large_Discrete_Type
21568 (Etype (Entity (Hi)))
21569 then
21570 return True;
21571 end if;
21572
21573 Next_Index (Indx);
21574 end loop;
21575 end if;
21576 end;
21577 end if;
21578
21579 Next_Entity (Comp);
21580 end loop;
21581 end;
21582 end if;
21583
21584 return False;
21585 end Large_Max_Size_Mutable;
21586
21587 -- Local declarations
21588
21589 Typ : constant Entity_Id := Underlying_Type (Id);
21590
21591 -- Start of processing for New_Requires_Transient_Scope
21592
21593 begin
21594 -- This is a private type which is not completed yet. This can only
21595 -- happen in a default expression (of a formal parameter or of a
21596 -- record component). Do not expand transient scope in this case.
21597
21598 if No (Typ) then
21599 return False;
21600
21601 -- Do not expand transient scope for non-existent procedure return or
21602 -- string literal types.
21603
21604 elsif Typ = Standard_Void_Type
21605 or else Ekind (Typ) = E_String_Literal_Subtype
21606 then
21607 return False;
21608
21609 -- If Typ is a generic formal incomplete type, then we want to look at
21610 -- the actual type.
21611
21612 elsif Ekind (Typ) = E_Record_Subtype
21613 and then Present (Cloned_Subtype (Typ))
21614 then
21615 return New_Requires_Transient_Scope (Cloned_Subtype (Typ));
21616
21617 -- Functions returning specific tagged types may dispatch on result, so
21618 -- their returned value is allocated on the secondary stack, even in the
21619 -- definite case. We must treat nondispatching functions the same way,
21620 -- because access-to-function types can point at both, so the calling
21621 -- conventions must be compatible. Is_Tagged_Type includes controlled
21622 -- types and class-wide types. Controlled type temporaries need
21623 -- finalization.
21624
21625 -- ???It's not clear why we need to return noncontrolled types with
21626 -- controlled components on the secondary stack.
21627
21628 elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
21629 return True;
21630
21631 -- Untagged definite subtypes are known size. This includes all
21632 -- elementary [sub]types. Tasks are known size even if they have
21633 -- discriminants. So we return False here, with one exception:
21634 -- For a type like:
21635 -- type T (Last : Natural := 0) is
21636 -- X : String (1 .. Last);
21637 -- end record;
21638 -- we return True. That's because for "P(F(...));", where F returns T,
21639 -- we don't know the size of the result at the call site, so if we
21640 -- allocated it on the primary stack, we would have to allocate the
21641 -- maximum size, which is way too big.
21642
21643 elsif Is_Definite_Subtype (Typ) or else Is_Task_Type (Typ) then
21644 return Large_Max_Size_Mutable (Typ);
21645
21646 -- Indefinite (discriminated) untagged record or protected type
21647
21648 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
21649 return not Caller_Known_Size_Record (Typ);
21650
21651 -- Unconstrained array
21652
21653 else
21654 pragma Assert (Is_Array_Type (Typ) and not Is_Definite_Subtype (Typ));
21655 return True;
21656 end if;
21657 end New_Requires_Transient_Scope;
21658
21659 ------------------------
21660 -- No_Caching_Enabled --
21661 ------------------------
21662
21663 function No_Caching_Enabled (Id : Entity_Id) return Boolean is
21664 Prag : constant Node_Id := Get_Pragma (Id, Pragma_No_Caching);
21665 Arg1 : Node_Id;
21666
21667 begin
21668 if Present (Prag) then
21669 Arg1 := First (Pragma_Argument_Associations (Prag));
21670
21671 -- The pragma has an optional Boolean expression, the related
21672 -- property is enabled only when the expression evaluates to True.
21673
21674 if Present (Arg1) then
21675 return Is_True (Expr_Value (Get_Pragma_Arg (Arg1)));
21676
21677 -- Otherwise the lack of expression enables the property by
21678 -- default.
21679
21680 else
21681 return True;
21682 end if;
21683
21684 -- The property was never set in the first place
21685
21686 else
21687 return False;
21688 end if;
21689 end No_Caching_Enabled;
21690
21691 --------------------------
21692 -- No_Heap_Finalization --
21693 --------------------------
21694
21695 function No_Heap_Finalization (Typ : Entity_Id) return Boolean is
21696 begin
21697 if Ekind_In (Typ, E_Access_Type, E_General_Access_Type)
21698 and then Is_Library_Level_Entity (Typ)
21699 then
21700 -- A global No_Heap_Finalization pragma applies to all library-level
21701 -- named access-to-object types.
21702
21703 if Present (No_Heap_Finalization_Pragma) then
21704 return True;
21705
21706 -- The library-level named access-to-object type itself is subject to
21707 -- pragma No_Heap_Finalization.
21708
21709 elsif Present (Get_Pragma (Typ, Pragma_No_Heap_Finalization)) then
21710 return True;
21711 end if;
21712 end if;
21713
21714 return False;
21715 end No_Heap_Finalization;
21716
21717 -----------------------
21718 -- Normalize_Actuals --
21719 -----------------------
21720
21721 -- Chain actuals according to formals of subprogram. If there are no named
21722 -- associations, the chain is simply the list of Parameter Associations,
21723 -- since the order is the same as the declaration order. If there are named
21724 -- associations, then the First_Named_Actual field in the N_Function_Call
21725 -- or N_Procedure_Call_Statement node points to the Parameter_Association
21726 -- node for the parameter that comes first in declaration order. The
21727 -- remaining named parameters are then chained in declaration order using
21728 -- Next_Named_Actual.
21729
21730 -- This routine also verifies that the number of actuals is compatible with
21731 -- the number and default values of formals, but performs no type checking
21732 -- (type checking is done by the caller).
21733
21734 -- If the matching succeeds, Success is set to True and the caller proceeds
21735 -- with type-checking. If the match is unsuccessful, then Success is set to
21736 -- False, and the caller attempts a different interpretation, if there is
21737 -- one.
21738
21739 -- If the flag Report is on, the call is not overloaded, and a failure to
21740 -- match can be reported here, rather than in the caller.
21741
21742 procedure Normalize_Actuals
21743 (N : Node_Id;
21744 S : Entity_Id;
21745 Report : Boolean;
21746 Success : out Boolean)
21747 is
21748 Actuals : constant List_Id := Parameter_Associations (N);
21749 Actual : Node_Id := Empty;
21750 Formal : Entity_Id;
21751 Last : Node_Id := Empty;
21752 First_Named : Node_Id := Empty;
21753 Found : Boolean;
21754
21755 Formals_To_Match : Integer := 0;
21756 Actuals_To_Match : Integer := 0;
21757
21758 procedure Chain (A : Node_Id);
21759 -- Add named actual at the proper place in the list, using the
21760 -- Next_Named_Actual link.
21761
21762 function Reporting return Boolean;
21763 -- Determines if an error is to be reported. To report an error, we
21764 -- need Report to be True, and also we do not report errors caused
21765 -- by calls to init procs that occur within other init procs. Such
21766 -- errors must always be cascaded errors, since if all the types are
21767 -- declared correctly, the compiler will certainly build decent calls.
21768
21769 -----------
21770 -- Chain --
21771 -----------
21772
21773 procedure Chain (A : Node_Id) is
21774 begin
21775 if No (Last) then
21776
21777 -- Call node points to first actual in list
21778
21779 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
21780
21781 else
21782 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
21783 end if;
21784
21785 Last := A;
21786 Set_Next_Named_Actual (Last, Empty);
21787 end Chain;
21788
21789 ---------------
21790 -- Reporting --
21791 ---------------
21792
21793 function Reporting return Boolean is
21794 begin
21795 if not Report then
21796 return False;
21797
21798 elsif not Within_Init_Proc then
21799 return True;
21800
21801 elsif Is_Init_Proc (Entity (Name (N))) then
21802 return False;
21803
21804 else
21805 return True;
21806 end if;
21807 end Reporting;
21808
21809 -- Start of processing for Normalize_Actuals
21810
21811 begin
21812 if Is_Access_Type (S) then
21813
21814 -- The name in the call is a function call that returns an access
21815 -- to subprogram. The designated type has the list of formals.
21816
21817 Formal := First_Formal (Designated_Type (S));
21818 else
21819 Formal := First_Formal (S);
21820 end if;
21821
21822 while Present (Formal) loop
21823 Formals_To_Match := Formals_To_Match + 1;
21824 Next_Formal (Formal);
21825 end loop;
21826
21827 -- Find if there is a named association, and verify that no positional
21828 -- associations appear after named ones.
21829
21830 if Present (Actuals) then
21831 Actual := First (Actuals);
21832 end if;
21833
21834 while Present (Actual)
21835 and then Nkind (Actual) /= N_Parameter_Association
21836 loop
21837 Actuals_To_Match := Actuals_To_Match + 1;
21838 Next (Actual);
21839 end loop;
21840
21841 if No (Actual) and Actuals_To_Match = Formals_To_Match then
21842
21843 -- Most common case: positional notation, no defaults
21844
21845 Success := True;
21846 return;
21847
21848 elsif Actuals_To_Match > Formals_To_Match then
21849
21850 -- Too many actuals: will not work
21851
21852 if Reporting then
21853 if Is_Entity_Name (Name (N)) then
21854 Error_Msg_N ("too many arguments in call to&", Name (N));
21855 else
21856 Error_Msg_N ("too many arguments in call", N);
21857 end if;
21858 end if;
21859
21860 Success := False;
21861 return;
21862 end if;
21863
21864 First_Named := Actual;
21865
21866 while Present (Actual) loop
21867 if Nkind (Actual) /= N_Parameter_Association then
21868 Error_Msg_N
21869 ("positional parameters not allowed after named ones", Actual);
21870 Success := False;
21871 return;
21872
21873 else
21874 Actuals_To_Match := Actuals_To_Match + 1;
21875 end if;
21876
21877 Next (Actual);
21878 end loop;
21879
21880 if Present (Actuals) then
21881 Actual := First (Actuals);
21882 end if;
21883
21884 Formal := First_Formal (S);
21885 while Present (Formal) loop
21886
21887 -- Match the formals in order. If the corresponding actual is
21888 -- positional, nothing to do. Else scan the list of named actuals
21889 -- to find the one with the right name.
21890
21891 if Present (Actual)
21892 and then Nkind (Actual) /= N_Parameter_Association
21893 then
21894 Next (Actual);
21895 Actuals_To_Match := Actuals_To_Match - 1;
21896 Formals_To_Match := Formals_To_Match - 1;
21897
21898 else
21899 -- For named parameters, search the list of actuals to find
21900 -- one that matches the next formal name.
21901
21902 Actual := First_Named;
21903 Found := False;
21904 while Present (Actual) loop
21905 if Chars (Selector_Name (Actual)) = Chars (Formal) then
21906 Found := True;
21907 Chain (Actual);
21908 Actuals_To_Match := Actuals_To_Match - 1;
21909 Formals_To_Match := Formals_To_Match - 1;
21910 exit;
21911 end if;
21912
21913 Next (Actual);
21914 end loop;
21915
21916 if not Found then
21917 if Ekind (Formal) /= E_In_Parameter
21918 or else No (Default_Value (Formal))
21919 then
21920 if Reporting then
21921 if (Comes_From_Source (S)
21922 or else Sloc (S) = Standard_Location)
21923 and then Is_Overloadable (S)
21924 then
21925 if No (Actuals)
21926 and then
21927 Nkind_In (Parent (N), N_Procedure_Call_Statement,
21928 N_Function_Call,
21929 N_Parameter_Association)
21930 and then Ekind (S) /= E_Function
21931 then
21932 Set_Etype (N, Etype (S));
21933
21934 else
21935 Error_Msg_Name_1 := Chars (S);
21936 Error_Msg_Sloc := Sloc (S);
21937 Error_Msg_NE
21938 ("missing argument for parameter & "
21939 & "in call to % declared #", N, Formal);
21940 end if;
21941
21942 elsif Is_Overloadable (S) then
21943 Error_Msg_Name_1 := Chars (S);
21944
21945 -- Point to type derivation that generated the
21946 -- operation.
21947
21948 Error_Msg_Sloc := Sloc (Parent (S));
21949
21950 Error_Msg_NE
21951 ("missing argument for parameter & "
21952 & "in call to % (inherited) #", N, Formal);
21953
21954 else
21955 Error_Msg_NE
21956 ("missing argument for parameter &", N, Formal);
21957 end if;
21958 end if;
21959
21960 Success := False;
21961 return;
21962
21963 else
21964 Formals_To_Match := Formals_To_Match - 1;
21965 end if;
21966 end if;
21967 end if;
21968
21969 Next_Formal (Formal);
21970 end loop;
21971
21972 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
21973 Success := True;
21974 return;
21975
21976 else
21977 if Reporting then
21978
21979 -- Find some superfluous named actual that did not get
21980 -- attached to the list of associations.
21981
21982 Actual := First (Actuals);
21983 while Present (Actual) loop
21984 if Nkind (Actual) = N_Parameter_Association
21985 and then Actual /= Last
21986 and then No (Next_Named_Actual (Actual))
21987 then
21988 -- A validity check may introduce a copy of a call that
21989 -- includes an extra actual (for example for an unrelated
21990 -- accessibility check). Check that the extra actual matches
21991 -- some extra formal, which must exist already because
21992 -- subprogram must be frozen at this point.
21993
21994 if Present (Extra_Formals (S))
21995 and then not Comes_From_Source (Actual)
21996 and then Nkind (Actual) = N_Parameter_Association
21997 and then Chars (Extra_Formals (S)) =
21998 Chars (Selector_Name (Actual))
21999 then
22000 null;
22001 else
22002 Error_Msg_N
22003 ("unmatched actual & in call", Selector_Name (Actual));
22004 exit;
22005 end if;
22006 end if;
22007
22008 Next (Actual);
22009 end loop;
22010 end if;
22011
22012 Success := False;
22013 return;
22014 end if;
22015 end Normalize_Actuals;
22016
22017 --------------------------------
22018 -- Note_Possible_Modification --
22019 --------------------------------
22020
22021 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
22022 Modification_Comes_From_Source : constant Boolean :=
22023 Comes_From_Source (Parent (N));
22024
22025 Ent : Entity_Id;
22026 Exp : Node_Id;
22027
22028 begin
22029 -- Loop to find referenced entity, if there is one
22030
22031 Exp := N;
22032 loop
22033 Ent := Empty;
22034
22035 if Is_Entity_Name (Exp) then
22036 Ent := Entity (Exp);
22037
22038 -- If the entity is missing, it is an undeclared identifier,
22039 -- and there is nothing to annotate.
22040
22041 if No (Ent) then
22042 return;
22043 end if;
22044
22045 elsif Nkind (Exp) = N_Explicit_Dereference then
22046 declare
22047 P : constant Node_Id := Prefix (Exp);
22048
22049 begin
22050 -- In formal verification mode, keep track of all reads and
22051 -- writes through explicit dereferences.
22052
22053 if GNATprove_Mode then
22054 SPARK_Specific.Generate_Dereference (N, 'm');
22055 end if;
22056
22057 if Nkind (P) = N_Selected_Component
22058 and then Present (Entry_Formal (Entity (Selector_Name (P))))
22059 then
22060 -- Case of a reference to an entry formal
22061
22062 Ent := Entry_Formal (Entity (Selector_Name (P)));
22063
22064 elsif Nkind (P) = N_Identifier
22065 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
22066 and then Present (Expression (Parent (Entity (P))))
22067 and then Nkind (Expression (Parent (Entity (P)))) =
22068 N_Reference
22069 then
22070 -- Case of a reference to a value on which side effects have
22071 -- been removed.
22072
22073 Exp := Prefix (Expression (Parent (Entity (P))));
22074 goto Continue;
22075
22076 else
22077 return;
22078 end if;
22079 end;
22080
22081 elsif Nkind_In (Exp, N_Type_Conversion,
22082 N_Unchecked_Type_Conversion)
22083 then
22084 Exp := Expression (Exp);
22085 goto Continue;
22086
22087 elsif Nkind_In (Exp, N_Slice,
22088 N_Indexed_Component,
22089 N_Selected_Component)
22090 then
22091 -- Special check, if the prefix is an access type, then return
22092 -- since we are modifying the thing pointed to, not the prefix.
22093 -- When we are expanding, most usually the prefix is replaced
22094 -- by an explicit dereference, and this test is not needed, but
22095 -- in some cases (notably -gnatc mode and generics) when we do
22096 -- not do full expansion, we need this special test.
22097
22098 if Is_Access_Type (Etype (Prefix (Exp))) then
22099 return;
22100
22101 -- Otherwise go to prefix and keep going
22102
22103 else
22104 Exp := Prefix (Exp);
22105 goto Continue;
22106 end if;
22107
22108 -- All other cases, not a modification
22109
22110 else
22111 return;
22112 end if;
22113
22114 -- Now look for entity being referenced
22115
22116 if Present (Ent) then
22117 if Is_Object (Ent) then
22118 if Comes_From_Source (Exp)
22119 or else Modification_Comes_From_Source
22120 then
22121 -- Give warning if pragma unmodified is given and we are
22122 -- sure this is a modification.
22123
22124 if Has_Pragma_Unmodified (Ent) and then Sure then
22125
22126 -- Note that the entity may be present only as a result
22127 -- of pragma Unused.
22128
22129 if Has_Pragma_Unused (Ent) then
22130 Error_Msg_NE ("??pragma Unused given for &!", N, Ent);
22131 else
22132 Error_Msg_NE
22133 ("??pragma Unmodified given for &!", N, Ent);
22134 end if;
22135 end if;
22136
22137 Set_Never_Set_In_Source (Ent, False);
22138 end if;
22139
22140 Set_Is_True_Constant (Ent, False);
22141 Set_Current_Value (Ent, Empty);
22142 Set_Is_Known_Null (Ent, False);
22143
22144 if not Can_Never_Be_Null (Ent) then
22145 Set_Is_Known_Non_Null (Ent, False);
22146 end if;
22147
22148 -- Follow renaming chain
22149
22150 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
22151 and then Present (Renamed_Object (Ent))
22152 then
22153 Exp := Renamed_Object (Ent);
22154
22155 -- If the entity is the loop variable in an iteration over
22156 -- a container, retrieve container expression to indicate
22157 -- possible modification.
22158
22159 if Present (Related_Expression (Ent))
22160 and then Nkind (Parent (Related_Expression (Ent))) =
22161 N_Iterator_Specification
22162 then
22163 Exp := Original_Node (Related_Expression (Ent));
22164 end if;
22165
22166 goto Continue;
22167
22168 -- The expression may be the renaming of a subcomponent of an
22169 -- array or container. The assignment to the subcomponent is
22170 -- a modification of the container.
22171
22172 elsif Comes_From_Source (Original_Node (Exp))
22173 and then Nkind_In (Original_Node (Exp), N_Selected_Component,
22174 N_Indexed_Component)
22175 then
22176 Exp := Prefix (Original_Node (Exp));
22177 goto Continue;
22178 end if;
22179
22180 -- Generate a reference only if the assignment comes from
22181 -- source. This excludes, for example, calls to a dispatching
22182 -- assignment operation when the left-hand side is tagged. In
22183 -- GNATprove mode, we need those references also on generated
22184 -- code, as these are used to compute the local effects of
22185 -- subprograms.
22186
22187 if Modification_Comes_From_Source or GNATprove_Mode then
22188 Generate_Reference (Ent, Exp, 'm');
22189
22190 -- If the target of the assignment is the bound variable
22191 -- in an iterator, indicate that the corresponding array
22192 -- or container is also modified.
22193
22194 if Ada_Version >= Ada_2012
22195 and then Nkind (Parent (Ent)) = N_Iterator_Specification
22196 then
22197 declare
22198 Domain : constant Node_Id := Name (Parent (Ent));
22199
22200 begin
22201 -- TBD : in the full version of the construct, the
22202 -- domain of iteration can be given by an expression.
22203
22204 if Is_Entity_Name (Domain) then
22205 Generate_Reference (Entity (Domain), Exp, 'm');
22206 Set_Is_True_Constant (Entity (Domain), False);
22207 Set_Never_Set_In_Source (Entity (Domain), False);
22208 end if;
22209 end;
22210 end if;
22211 end if;
22212 end if;
22213
22214 Kill_Checks (Ent);
22215
22216 -- If we are sure this is a modification from source, and we know
22217 -- this modifies a constant, then give an appropriate warning.
22218
22219 if Sure
22220 and then Modification_Comes_From_Source
22221 and then Overlays_Constant (Ent)
22222 and then Address_Clause_Overlay_Warnings
22223 then
22224 declare
22225 Addr : constant Node_Id := Address_Clause (Ent);
22226 O_Ent : Entity_Id;
22227 Off : Boolean;
22228
22229 begin
22230 Find_Overlaid_Entity (Addr, O_Ent, Off);
22231
22232 Error_Msg_Sloc := Sloc (Addr);
22233 Error_Msg_NE
22234 ("??constant& may be modified via address clause#",
22235 N, O_Ent);
22236 end;
22237 end if;
22238
22239 return;
22240 end if;
22241
22242 <<Continue>>
22243 null;
22244 end loop;
22245 end Note_Possible_Modification;
22246
22247 -----------------
22248 -- Null_Status --
22249 -----------------
22250
22251 function Null_Status (N : Node_Id) return Null_Status_Kind is
22252 function Is_Null_Excluding_Def (Def : Node_Id) return Boolean;
22253 -- Determine whether definition Def carries a null exclusion
22254
22255 function Null_Status_Of_Entity (Id : Entity_Id) return Null_Status_Kind;
22256 -- Determine the null status of arbitrary entity Id
22257
22258 function Null_Status_Of_Type (Typ : Entity_Id) return Null_Status_Kind;
22259 -- Determine the null status of type Typ
22260
22261 ---------------------------
22262 -- Is_Null_Excluding_Def --
22263 ---------------------------
22264
22265 function Is_Null_Excluding_Def (Def : Node_Id) return Boolean is
22266 begin
22267 return
22268 Nkind_In (Def, N_Access_Definition,
22269 N_Access_Function_Definition,
22270 N_Access_Procedure_Definition,
22271 N_Access_To_Object_Definition,
22272 N_Component_Definition,
22273 N_Derived_Type_Definition)
22274 and then Null_Exclusion_Present (Def);
22275 end Is_Null_Excluding_Def;
22276
22277 ---------------------------
22278 -- Null_Status_Of_Entity --
22279 ---------------------------
22280
22281 function Null_Status_Of_Entity
22282 (Id : Entity_Id) return Null_Status_Kind
22283 is
22284 Decl : constant Node_Id := Declaration_Node (Id);
22285 Def : Node_Id;
22286
22287 begin
22288 -- The value of an imported or exported entity may be set externally
22289 -- regardless of a null exclusion. As a result, the value cannot be
22290 -- determined statically.
22291
22292 if Is_Imported (Id) or else Is_Exported (Id) then
22293 return Unknown;
22294
22295 elsif Nkind_In (Decl, N_Component_Declaration,
22296 N_Discriminant_Specification,
22297 N_Formal_Object_Declaration,
22298 N_Object_Declaration,
22299 N_Object_Renaming_Declaration,
22300 N_Parameter_Specification)
22301 then
22302 -- A component declaration yields a non-null value when either
22303 -- its component definition or access definition carries a null
22304 -- exclusion.
22305
22306 if Nkind (Decl) = N_Component_Declaration then
22307 Def := Component_Definition (Decl);
22308
22309 if Is_Null_Excluding_Def (Def) then
22310 return Is_Non_Null;
22311 end if;
22312
22313 Def := Access_Definition (Def);
22314
22315 if Present (Def) and then Is_Null_Excluding_Def (Def) then
22316 return Is_Non_Null;
22317 end if;
22318
22319 -- A formal object declaration yields a non-null value if its
22320 -- access definition carries a null exclusion. If the object is
22321 -- default initialized, then the value depends on the expression.
22322
22323 elsif Nkind (Decl) = N_Formal_Object_Declaration then
22324 Def := Access_Definition (Decl);
22325
22326 if Present (Def) and then Is_Null_Excluding_Def (Def) then
22327 return Is_Non_Null;
22328 end if;
22329
22330 -- A constant may yield a null or non-null value depending on its
22331 -- initialization expression.
22332
22333 elsif Ekind (Id) = E_Constant then
22334 return Null_Status (Constant_Value (Id));
22335
22336 -- The construct yields a non-null value when it has a null
22337 -- exclusion.
22338
22339 elsif Null_Exclusion_Present (Decl) then
22340 return Is_Non_Null;
22341
22342 -- An object renaming declaration yields a non-null value if its
22343 -- access definition carries a null exclusion. Otherwise the value
22344 -- depends on the renamed name.
22345
22346 elsif Nkind (Decl) = N_Object_Renaming_Declaration then
22347 Def := Access_Definition (Decl);
22348
22349 if Present (Def) and then Is_Null_Excluding_Def (Def) then
22350 return Is_Non_Null;
22351
22352 else
22353 return Null_Status (Name (Decl));
22354 end if;
22355 end if;
22356 end if;
22357
22358 -- At this point the declaration of the entity does not carry a null
22359 -- exclusion and lacks an initialization expression. Check the status
22360 -- of its type.
22361
22362 return Null_Status_Of_Type (Etype (Id));
22363 end Null_Status_Of_Entity;
22364
22365 -------------------------
22366 -- Null_Status_Of_Type --
22367 -------------------------
22368
22369 function Null_Status_Of_Type (Typ : Entity_Id) return Null_Status_Kind is
22370 Curr : Entity_Id;
22371 Decl : Node_Id;
22372
22373 begin
22374 -- Traverse the type chain looking for types with null exclusion
22375
22376 Curr := Typ;
22377 while Present (Curr) and then Etype (Curr) /= Curr loop
22378 Decl := Parent (Curr);
22379
22380 -- Guard against itypes which do not always have declarations. A
22381 -- type yields a non-null value if it carries a null exclusion.
22382
22383 if Present (Decl) then
22384 if Nkind (Decl) = N_Full_Type_Declaration
22385 and then Is_Null_Excluding_Def (Type_Definition (Decl))
22386 then
22387 return Is_Non_Null;
22388
22389 elsif Nkind (Decl) = N_Subtype_Declaration
22390 and then Null_Exclusion_Present (Decl)
22391 then
22392 return Is_Non_Null;
22393 end if;
22394 end if;
22395
22396 Curr := Etype (Curr);
22397 end loop;
22398
22399 -- The type chain does not contain any null excluding types
22400
22401 return Unknown;
22402 end Null_Status_Of_Type;
22403
22404 -- Start of processing for Null_Status
22405
22406 begin
22407 -- Prevent cascaded errors or infinite loops when trying to determine
22408 -- the null status of an erroneous construct.
22409
22410 if Error_Posted (N) then
22411 return Unknown;
22412
22413 -- An allocator always creates a non-null value
22414
22415 elsif Nkind (N) = N_Allocator then
22416 return Is_Non_Null;
22417
22418 -- Taking the 'Access of something yields a non-null value
22419
22420 elsif Nkind (N) = N_Attribute_Reference
22421 and then Nam_In (Attribute_Name (N), Name_Access,
22422 Name_Unchecked_Access,
22423 Name_Unrestricted_Access)
22424 then
22425 return Is_Non_Null;
22426
22427 -- "null" yields null
22428
22429 elsif Nkind (N) = N_Null then
22430 return Is_Null;
22431
22432 -- Check the status of the operand of a type conversion
22433
22434 elsif Nkind (N) = N_Type_Conversion then
22435 return Null_Status (Expression (N));
22436
22437 -- The input denotes a reference to an entity. Determine whether the
22438 -- entity or its type yields a null or non-null value.
22439
22440 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
22441 return Null_Status_Of_Entity (Entity (N));
22442 end if;
22443
22444 -- Otherwise it is not possible to determine the null status of the
22445 -- subexpression at compile time without resorting to simple flow
22446 -- analysis.
22447
22448 return Unknown;
22449 end Null_Status;
22450
22451 --------------------------------------
22452 -- Null_To_Null_Address_Convert_OK --
22453 --------------------------------------
22454
22455 function Null_To_Null_Address_Convert_OK
22456 (N : Node_Id;
22457 Typ : Entity_Id := Empty) return Boolean
22458 is
22459 begin
22460 if not Relaxed_RM_Semantics then
22461 return False;
22462 end if;
22463
22464 if Nkind (N) = N_Null then
22465 return Present (Typ) and then Is_Descendant_Of_Address (Typ);
22466
22467 elsif Nkind_In (N, N_Op_Eq, N_Op_Ge, N_Op_Gt, N_Op_Le, N_Op_Lt, N_Op_Ne)
22468 then
22469 declare
22470 L : constant Node_Id := Left_Opnd (N);
22471 R : constant Node_Id := Right_Opnd (N);
22472
22473 begin
22474 -- We check the Etype of the complementary operand since the
22475 -- N_Null node is not decorated at this stage.
22476
22477 return
22478 ((Nkind (L) = N_Null
22479 and then Is_Descendant_Of_Address (Etype (R)))
22480 or else
22481 (Nkind (R) = N_Null
22482 and then Is_Descendant_Of_Address (Etype (L))));
22483 end;
22484 end if;
22485
22486 return False;
22487 end Null_To_Null_Address_Convert_OK;
22488
22489 ---------------------------------
22490 -- Number_Of_Elements_In_Array --
22491 ---------------------------------
22492
22493 function Number_Of_Elements_In_Array (T : Entity_Id) return Int is
22494 Indx : Node_Id;
22495 Typ : Entity_Id;
22496 Low : Node_Id;
22497 High : Node_Id;
22498 Num : Int := 1;
22499
22500 begin
22501 pragma Assert (Is_Array_Type (T));
22502
22503 Indx := First_Index (T);
22504 while Present (Indx) loop
22505 Typ := Underlying_Type (Etype (Indx));
22506
22507 -- Never look at junk bounds of a generic type
22508
22509 if Is_Generic_Type (Typ) then
22510 return 0;
22511 end if;
22512
22513 -- Check the array bounds are known at compile time and return zero
22514 -- if they are not.
22515
22516 Low := Type_Low_Bound (Typ);
22517 High := Type_High_Bound (Typ);
22518
22519 if not Compile_Time_Known_Value (Low) then
22520 return 0;
22521 elsif not Compile_Time_Known_Value (High) then
22522 return 0;
22523 else
22524 Num :=
22525 Num * UI_To_Int ((Expr_Value (High) - Expr_Value (Low) + 1));
22526 end if;
22527
22528 Next_Index (Indx);
22529 end loop;
22530
22531 return Num;
22532 end Number_Of_Elements_In_Array;
22533
22534 -------------------------
22535 -- Object_Access_Level --
22536 -------------------------
22537
22538 -- Returns the static accessibility level of the view denoted by Obj. Note
22539 -- that the value returned is the result of a call to Scope_Depth. Only
22540 -- scope depths associated with dynamic scopes can actually be returned.
22541 -- Since only relative levels matter for accessibility checking, the fact
22542 -- that the distance between successive levels of accessibility is not
22543 -- always one is immaterial (invariant: if level(E2) is deeper than
22544 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
22545
22546 function Object_Access_Level (Obj : Node_Id) return Uint is
22547 function Is_Interface_Conversion (N : Node_Id) return Boolean;
22548 -- Determine whether N is a construct of the form
22549 -- Some_Type (Operand._tag'Address)
22550 -- This construct appears in the context of dispatching calls.
22551
22552 function Reference_To (Obj : Node_Id) return Node_Id;
22553 -- An explicit dereference is created when removing side effects from
22554 -- expressions for constraint checking purposes. In this case a local
22555 -- access type is created for it. The correct access level is that of
22556 -- the original source node. We detect this case by noting that the
22557 -- prefix of the dereference is created by an object declaration whose
22558 -- initial expression is a reference.
22559
22560 -----------------------------
22561 -- Is_Interface_Conversion --
22562 -----------------------------
22563
22564 function Is_Interface_Conversion (N : Node_Id) return Boolean is
22565 begin
22566 return Nkind (N) = N_Unchecked_Type_Conversion
22567 and then Nkind (Expression (N)) = N_Attribute_Reference
22568 and then Attribute_Name (Expression (N)) = Name_Address;
22569 end Is_Interface_Conversion;
22570
22571 ------------------
22572 -- Reference_To --
22573 ------------------
22574
22575 function Reference_To (Obj : Node_Id) return Node_Id is
22576 Pref : constant Node_Id := Prefix (Obj);
22577 begin
22578 if Is_Entity_Name (Pref)
22579 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
22580 and then Present (Expression (Parent (Entity (Pref))))
22581 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
22582 then
22583 return (Prefix (Expression (Parent (Entity (Pref)))));
22584 else
22585 return Empty;
22586 end if;
22587 end Reference_To;
22588
22589 -- Local variables
22590
22591 E : Entity_Id;
22592
22593 -- Start of processing for Object_Access_Level
22594
22595 begin
22596 if Nkind (Obj) = N_Defining_Identifier
22597 or else Is_Entity_Name (Obj)
22598 then
22599 if Nkind (Obj) = N_Defining_Identifier then
22600 E := Obj;
22601 else
22602 E := Entity (Obj);
22603 end if;
22604
22605 if Is_Prival (E) then
22606 E := Prival_Link (E);
22607 end if;
22608
22609 -- If E is a type then it denotes a current instance. For this case
22610 -- we add one to the normal accessibility level of the type to ensure
22611 -- that current instances are treated as always being deeper than
22612 -- than the level of any visible named access type (see 3.10.2(21)).
22613
22614 if Is_Type (E) then
22615 return Type_Access_Level (E) + 1;
22616
22617 elsif Present (Renamed_Object (E)) then
22618 return Object_Access_Level (Renamed_Object (E));
22619
22620 -- Similarly, if E is a component of the current instance of a
22621 -- protected type, any instance of it is assumed to be at a deeper
22622 -- level than the type. For a protected object (whose type is an
22623 -- anonymous protected type) its components are at the same level
22624 -- as the type itself.
22625
22626 elsif not Is_Overloadable (E)
22627 and then Ekind (Scope (E)) = E_Protected_Type
22628 and then Comes_From_Source (Scope (E))
22629 then
22630 return Type_Access_Level (Scope (E)) + 1;
22631
22632 else
22633 -- Aliased formals of functions take their access level from the
22634 -- point of call, i.e. require a dynamic check. For static check
22635 -- purposes, this is smaller than the level of the subprogram
22636 -- itself. For procedures the aliased makes no difference.
22637
22638 if Is_Formal (E)
22639 and then Is_Aliased (E)
22640 and then Ekind (Scope (E)) = E_Function
22641 then
22642 return Type_Access_Level (Etype (E));
22643
22644 else
22645 return Scope_Depth (Enclosing_Dynamic_Scope (E));
22646 end if;
22647 end if;
22648
22649 elsif Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
22650 if Is_Access_Type (Etype (Prefix (Obj))) then
22651 return Type_Access_Level (Etype (Prefix (Obj)));
22652 else
22653 return Object_Access_Level (Prefix (Obj));
22654 end if;
22655
22656 elsif Nkind (Obj) = N_Explicit_Dereference then
22657
22658 -- If the prefix is a selected access discriminant then we make a
22659 -- recursive call on the prefix, which will in turn check the level
22660 -- of the prefix object of the selected discriminant.
22661
22662 -- In Ada 2012, if the discriminant has implicit dereference and
22663 -- the context is a selected component, treat this as an object of
22664 -- unknown scope (see below). This is necessary in compile-only mode;
22665 -- otherwise expansion will already have transformed the prefix into
22666 -- a temporary.
22667
22668 if Nkind (Prefix (Obj)) = N_Selected_Component
22669 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
22670 and then
22671 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
22672 and then
22673 (not Has_Implicit_Dereference
22674 (Entity (Selector_Name (Prefix (Obj))))
22675 or else Nkind (Parent (Obj)) /= N_Selected_Component)
22676 then
22677 return Object_Access_Level (Prefix (Obj));
22678
22679 -- Detect an interface conversion in the context of a dispatching
22680 -- call. Use the original form of the conversion to find the access
22681 -- level of the operand.
22682
22683 elsif Is_Interface (Etype (Obj))
22684 and then Is_Interface_Conversion (Prefix (Obj))
22685 and then Nkind (Original_Node (Obj)) = N_Type_Conversion
22686 then
22687 return Object_Access_Level (Original_Node (Obj));
22688
22689 elsif not Comes_From_Source (Obj) then
22690 declare
22691 Ref : constant Node_Id := Reference_To (Obj);
22692 begin
22693 if Present (Ref) then
22694 return Object_Access_Level (Ref);
22695 else
22696 return Type_Access_Level (Etype (Prefix (Obj)));
22697 end if;
22698 end;
22699
22700 else
22701 return Type_Access_Level (Etype (Prefix (Obj)));
22702 end if;
22703
22704 elsif Nkind_In (Obj, N_Type_Conversion, N_Unchecked_Type_Conversion) then
22705 return Object_Access_Level (Expression (Obj));
22706
22707 elsif Nkind (Obj) = N_Function_Call then
22708
22709 -- Function results are objects, so we get either the access level of
22710 -- the function or, in the case of an indirect call, the level of the
22711 -- access-to-subprogram type. (This code is used for Ada 95, but it
22712 -- looks wrong, because it seems that we should be checking the level
22713 -- of the call itself, even for Ada 95. However, using the Ada 2005
22714 -- version of the code causes regressions in several tests that are
22715 -- compiled with -gnat95. ???)
22716
22717 if Ada_Version < Ada_2005 then
22718 if Is_Entity_Name (Name (Obj)) then
22719 return Subprogram_Access_Level (Entity (Name (Obj)));
22720 else
22721 return Type_Access_Level (Etype (Prefix (Name (Obj))));
22722 end if;
22723
22724 -- For Ada 2005, the level of the result object of a function call is
22725 -- defined to be the level of the call's innermost enclosing master.
22726 -- We determine that by querying the depth of the innermost enclosing
22727 -- dynamic scope.
22728
22729 else
22730 Return_Master_Scope_Depth_Of_Call : declare
22731 function Innermost_Master_Scope_Depth
22732 (N : Node_Id) return Uint;
22733 -- Returns the scope depth of the given node's innermost
22734 -- enclosing dynamic scope (effectively the accessibility
22735 -- level of the innermost enclosing master).
22736
22737 ----------------------------------
22738 -- Innermost_Master_Scope_Depth --
22739 ----------------------------------
22740
22741 function Innermost_Master_Scope_Depth
22742 (N : Node_Id) return Uint
22743 is
22744 Node_Par : Node_Id := Parent (N);
22745
22746 begin
22747 -- Locate the nearest enclosing node (by traversing Parents)
22748 -- that Defining_Entity can be applied to, and return the
22749 -- depth of that entity's nearest enclosing dynamic scope.
22750
22751 while Present (Node_Par) loop
22752 case Nkind (Node_Par) is
22753 when N_Abstract_Subprogram_Declaration
22754 | N_Block_Statement
22755 | N_Body_Stub
22756 | N_Component_Declaration
22757 | N_Entry_Body
22758 | N_Entry_Declaration
22759 | N_Exception_Declaration
22760 | N_Formal_Object_Declaration
22761 | N_Formal_Package_Declaration
22762 | N_Formal_Subprogram_Declaration
22763 | N_Formal_Type_Declaration
22764 | N_Full_Type_Declaration
22765 | N_Function_Specification
22766 | N_Generic_Declaration
22767 | N_Generic_Instantiation
22768 | N_Implicit_Label_Declaration
22769 | N_Incomplete_Type_Declaration
22770 | N_Loop_Parameter_Specification
22771 | N_Number_Declaration
22772 | N_Object_Declaration
22773 | N_Package_Declaration
22774 | N_Package_Specification
22775 | N_Parameter_Specification
22776 | N_Private_Extension_Declaration
22777 | N_Private_Type_Declaration
22778 | N_Procedure_Specification
22779 | N_Proper_Body
22780 | N_Protected_Type_Declaration
22781 | N_Renaming_Declaration
22782 | N_Single_Protected_Declaration
22783 | N_Single_Task_Declaration
22784 | N_Subprogram_Declaration
22785 | N_Subtype_Declaration
22786 | N_Subunit
22787 | N_Task_Type_Declaration
22788 =>
22789 return Scope_Depth
22790 (Nearest_Dynamic_Scope
22791 (Defining_Entity (Node_Par)));
22792
22793 -- For a return statement within a function, return
22794 -- the depth of the function itself. This is not just
22795 -- a small optimization, but matters when analyzing
22796 -- the expression in an expression function before
22797 -- the body is created.
22798
22799 when N_Simple_Return_Statement =>
22800 if Ekind (Current_Scope) = E_Function then
22801 return Scope_Depth (Current_Scope);
22802 end if;
22803
22804 when others =>
22805 null;
22806 end case;
22807
22808 Node_Par := Parent (Node_Par);
22809 end loop;
22810
22811 pragma Assert (False);
22812
22813 -- Should never reach the following return
22814
22815 return Scope_Depth (Current_Scope) + 1;
22816 end Innermost_Master_Scope_Depth;
22817
22818 -- Start of processing for Return_Master_Scope_Depth_Of_Call
22819
22820 begin
22821 return Innermost_Master_Scope_Depth (Obj);
22822 end Return_Master_Scope_Depth_Of_Call;
22823 end if;
22824
22825 -- For convenience we handle qualified expressions, even though they
22826 -- aren't technically object names.
22827
22828 elsif Nkind (Obj) = N_Qualified_Expression then
22829 return Object_Access_Level (Expression (Obj));
22830
22831 -- Ditto for aggregates. They have the level of the temporary that
22832 -- will hold their value.
22833
22834 elsif Nkind (Obj) = N_Aggregate then
22835 return Object_Access_Level (Current_Scope);
22836
22837 -- Otherwise return the scope level of Standard. (If there are cases
22838 -- that fall through to this point they will be treated as having
22839 -- global accessibility for now. ???)
22840
22841 else
22842 return Scope_Depth (Standard_Standard);
22843 end if;
22844 end Object_Access_Level;
22845
22846 ----------------------------------
22847 -- Old_Requires_Transient_Scope --
22848 ----------------------------------
22849
22850 function Old_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
22851 Typ : constant Entity_Id := Underlying_Type (Id);
22852
22853 begin
22854 -- This is a private type which is not completed yet. This can only
22855 -- happen in a default expression (of a formal parameter or of a
22856 -- record component). Do not expand transient scope in this case.
22857
22858 if No (Typ) then
22859 return False;
22860
22861 -- Do not expand transient scope for non-existent procedure return
22862
22863 elsif Typ = Standard_Void_Type then
22864 return False;
22865
22866 -- Elementary types do not require a transient scope
22867
22868 elsif Is_Elementary_Type (Typ) then
22869 return False;
22870
22871 -- Generally, indefinite subtypes require a transient scope, since the
22872 -- back end cannot generate temporaries, since this is not a valid type
22873 -- for declaring an object. It might be possible to relax this in the
22874 -- future, e.g. by declaring the maximum possible space for the type.
22875
22876 elsif not Is_Definite_Subtype (Typ) then
22877 return True;
22878
22879 -- Functions returning tagged types may dispatch on result so their
22880 -- returned value is allocated on the secondary stack. Controlled
22881 -- type temporaries need finalization.
22882
22883 elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
22884 return True;
22885
22886 -- Record type
22887
22888 elsif Is_Record_Type (Typ) then
22889 declare
22890 Comp : Entity_Id;
22891
22892 begin
22893 Comp := First_Entity (Typ);
22894 while Present (Comp) loop
22895 if Ekind (Comp) = E_Component then
22896
22897 -- ???It's not clear we need a full recursive call to
22898 -- Old_Requires_Transient_Scope here. Note that the
22899 -- following can't happen.
22900
22901 pragma Assert (Is_Definite_Subtype (Etype (Comp)));
22902 pragma Assert (not Has_Controlled_Component (Etype (Comp)));
22903
22904 if Old_Requires_Transient_Scope (Etype (Comp)) then
22905 return True;
22906 end if;
22907 end if;
22908
22909 Next_Entity (Comp);
22910 end loop;
22911 end;
22912
22913 return False;
22914
22915 -- String literal types never require transient scope
22916
22917 elsif Ekind (Typ) = E_String_Literal_Subtype then
22918 return False;
22919
22920 -- Array type. Note that we already know that this is a constrained
22921 -- array, since unconstrained arrays will fail the indefinite test.
22922
22923 elsif Is_Array_Type (Typ) then
22924
22925 -- If component type requires a transient scope, the array does too
22926
22927 if Old_Requires_Transient_Scope (Component_Type (Typ)) then
22928 return True;
22929
22930 -- Otherwise, we only need a transient scope if the size depends on
22931 -- the value of one or more discriminants.
22932
22933 else
22934 return Size_Depends_On_Discriminant (Typ);
22935 end if;
22936
22937 -- All other cases do not require a transient scope
22938
22939 else
22940 pragma Assert (Is_Protected_Type (Typ) or else Is_Task_Type (Typ));
22941 return False;
22942 end if;
22943 end Old_Requires_Transient_Scope;
22944
22945 ---------------------------------
22946 -- Original_Aspect_Pragma_Name --
22947 ---------------------------------
22948
22949 function Original_Aspect_Pragma_Name (N : Node_Id) return Name_Id is
22950 Item : Node_Id;
22951 Item_Nam : Name_Id;
22952
22953 begin
22954 pragma Assert (Nkind_In (N, N_Aspect_Specification, N_Pragma));
22955
22956 Item := N;
22957
22958 -- The pragma was generated to emulate an aspect, use the original
22959 -- aspect specification.
22960
22961 if Nkind (Item) = N_Pragma and then From_Aspect_Specification (Item) then
22962 Item := Corresponding_Aspect (Item);
22963 end if;
22964
22965 -- Retrieve the name of the aspect/pragma. Note that Pre, Pre_Class,
22966 -- Post and Post_Class rewrite their pragma identifier to preserve the
22967 -- original name.
22968 -- ??? this is kludgey
22969
22970 if Nkind (Item) = N_Pragma then
22971 Item_Nam := Chars (Original_Node (Pragma_Identifier (Item)));
22972
22973 else
22974 pragma Assert (Nkind (Item) = N_Aspect_Specification);
22975 Item_Nam := Chars (Identifier (Item));
22976 end if;
22977
22978 -- Deal with 'Class by converting the name to its _XXX form
22979
22980 if Class_Present (Item) then
22981 if Item_Nam = Name_Invariant then
22982 Item_Nam := Name_uInvariant;
22983
22984 elsif Item_Nam = Name_Post then
22985 Item_Nam := Name_uPost;
22986
22987 elsif Item_Nam = Name_Pre then
22988 Item_Nam := Name_uPre;
22989
22990 elsif Nam_In (Item_Nam, Name_Type_Invariant,
22991 Name_Type_Invariant_Class)
22992 then
22993 Item_Nam := Name_uType_Invariant;
22994
22995 -- Nothing to do for other cases (e.g. a Check that derived from
22996 -- Pre_Class and has the flag set). Also we do nothing if the name
22997 -- is already in special _xxx form.
22998
22999 end if;
23000 end if;
23001
23002 return Item_Nam;
23003 end Original_Aspect_Pragma_Name;
23004
23005 --------------------------------------
23006 -- Original_Corresponding_Operation --
23007 --------------------------------------
23008
23009 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
23010 is
23011 Typ : constant Entity_Id := Find_Dispatching_Type (S);
23012
23013 begin
23014 -- If S is an inherited primitive S2 the original corresponding
23015 -- operation of S is the original corresponding operation of S2
23016
23017 if Present (Alias (S))
23018 and then Find_Dispatching_Type (Alias (S)) /= Typ
23019 then
23020 return Original_Corresponding_Operation (Alias (S));
23021
23022 -- If S overrides an inherited subprogram S2 the original corresponding
23023 -- operation of S is the original corresponding operation of S2
23024
23025 elsif Present (Overridden_Operation (S)) then
23026 return Original_Corresponding_Operation (Overridden_Operation (S));
23027
23028 -- otherwise it is S itself
23029
23030 else
23031 return S;
23032 end if;
23033 end Original_Corresponding_Operation;
23034
23035 -------------------
23036 -- Output_Entity --
23037 -------------------
23038
23039 procedure Output_Entity (Id : Entity_Id) is
23040 Scop : Entity_Id;
23041
23042 begin
23043 Scop := Scope (Id);
23044
23045 -- The entity may lack a scope when it is in the process of being
23046 -- analyzed. Use the current scope as an approximation.
23047
23048 if No (Scop) then
23049 Scop := Current_Scope;
23050 end if;
23051
23052 Output_Name (Chars (Id), Scop);
23053 end Output_Entity;
23054
23055 -----------------
23056 -- Output_Name --
23057 -----------------
23058
23059 procedure Output_Name (Nam : Name_Id; Scop : Entity_Id := Current_Scope) is
23060 begin
23061 Write_Str
23062 (Get_Name_String
23063 (Get_Qualified_Name
23064 (Nam => Nam,
23065 Suffix => No_Name,
23066 Scop => Scop)));
23067 Write_Eol;
23068 end Output_Name;
23069
23070 ----------------------
23071 -- Policy_In_Effect --
23072 ----------------------
23073
23074 function Policy_In_Effect (Policy : Name_Id) return Name_Id is
23075 function Policy_In_List (List : Node_Id) return Name_Id;
23076 -- Determine the mode of a policy in a N_Pragma list
23077
23078 --------------------
23079 -- Policy_In_List --
23080 --------------------
23081
23082 function Policy_In_List (List : Node_Id) return Name_Id is
23083 Arg1 : Node_Id;
23084 Arg2 : Node_Id;
23085 Prag : Node_Id;
23086
23087 begin
23088 Prag := List;
23089 while Present (Prag) loop
23090 Arg1 := First (Pragma_Argument_Associations (Prag));
23091 Arg2 := Next (Arg1);
23092
23093 Arg1 := Get_Pragma_Arg (Arg1);
23094 Arg2 := Get_Pragma_Arg (Arg2);
23095
23096 -- The current Check_Policy pragma matches the requested policy or
23097 -- appears in the single argument form (Assertion, policy_id).
23098
23099 if Nam_In (Chars (Arg1), Name_Assertion, Policy) then
23100 return Chars (Arg2);
23101 end if;
23102
23103 Prag := Next_Pragma (Prag);
23104 end loop;
23105
23106 return No_Name;
23107 end Policy_In_List;
23108
23109 -- Local variables
23110
23111 Kind : Name_Id;
23112
23113 -- Start of processing for Policy_In_Effect
23114
23115 begin
23116 if not Is_Valid_Assertion_Kind (Policy) then
23117 raise Program_Error;
23118 end if;
23119
23120 -- Inspect all policy pragmas that appear within scopes (if any)
23121
23122 Kind := Policy_In_List (Check_Policy_List);
23123
23124 -- Inspect all configuration policy pragmas (if any)
23125
23126 if Kind = No_Name then
23127 Kind := Policy_In_List (Check_Policy_List_Config);
23128 end if;
23129
23130 -- The context lacks policy pragmas, determine the mode based on whether
23131 -- assertions are enabled at the configuration level. This ensures that
23132 -- the policy is preserved when analyzing generics.
23133
23134 if Kind = No_Name then
23135 if Assertions_Enabled_Config then
23136 Kind := Name_Check;
23137 else
23138 Kind := Name_Ignore;
23139 end if;
23140 end if;
23141
23142 -- In CodePeer mode and GNATprove mode, we need to consider all
23143 -- assertions, unless they are disabled. Force Name_Check on
23144 -- ignored assertions.
23145
23146 if Nam_In (Kind, Name_Ignore, Name_Off)
23147 and then (CodePeer_Mode or GNATprove_Mode)
23148 then
23149 Kind := Name_Check;
23150 end if;
23151
23152 return Kind;
23153 end Policy_In_Effect;
23154
23155 ----------------------------------
23156 -- Predicate_Tests_On_Arguments --
23157 ----------------------------------
23158
23159 function Predicate_Tests_On_Arguments (Subp : Entity_Id) return Boolean is
23160 begin
23161 -- Always test predicates on indirect call
23162
23163 if Ekind (Subp) = E_Subprogram_Type then
23164 return True;
23165
23166 -- Do not test predicates on call to generated default Finalize, since
23167 -- we are not interested in whether something we are finalizing (and
23168 -- typically destroying) satisfies its predicates.
23169
23170 elsif Chars (Subp) = Name_Finalize
23171 and then not Comes_From_Source (Subp)
23172 then
23173 return False;
23174
23175 -- Do not test predicates on any internally generated routines
23176
23177 elsif Is_Internal_Name (Chars (Subp)) then
23178 return False;
23179
23180 -- Do not test predicates on call to Init_Proc, since if needed the
23181 -- predicate test will occur at some other point.
23182
23183 elsif Is_Init_Proc (Subp) then
23184 return False;
23185
23186 -- Do not test predicates on call to predicate function, since this
23187 -- would cause infinite recursion.
23188
23189 elsif Ekind (Subp) = E_Function
23190 and then (Is_Predicate_Function (Subp)
23191 or else
23192 Is_Predicate_Function_M (Subp))
23193 then
23194 return False;
23195
23196 -- For now, no other exceptions
23197
23198 else
23199 return True;
23200 end if;
23201 end Predicate_Tests_On_Arguments;
23202
23203 -----------------------
23204 -- Private_Component --
23205 -----------------------
23206
23207 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
23208 Ancestor : constant Entity_Id := Base_Type (Type_Id);
23209
23210 function Trace_Components
23211 (T : Entity_Id;
23212 Check : Boolean) return Entity_Id;
23213 -- Recursive function that does the work, and checks against circular
23214 -- definition for each subcomponent type.
23215
23216 ----------------------
23217 -- Trace_Components --
23218 ----------------------
23219
23220 function Trace_Components
23221 (T : Entity_Id;
23222 Check : Boolean) return Entity_Id
23223 is
23224 Btype : constant Entity_Id := Base_Type (T);
23225 Component : Entity_Id;
23226 P : Entity_Id;
23227 Candidate : Entity_Id := Empty;
23228
23229 begin
23230 if Check and then Btype = Ancestor then
23231 Error_Msg_N ("circular type definition", Type_Id);
23232 return Any_Type;
23233 end if;
23234
23235 if Is_Private_Type (Btype) and then not Is_Generic_Type (Btype) then
23236 if Present (Full_View (Btype))
23237 and then Is_Record_Type (Full_View (Btype))
23238 and then not Is_Frozen (Btype)
23239 then
23240 -- To indicate that the ancestor depends on a private type, the
23241 -- current Btype is sufficient. However, to check for circular
23242 -- definition we must recurse on the full view.
23243
23244 Candidate := Trace_Components (Full_View (Btype), True);
23245
23246 if Candidate = Any_Type then
23247 return Any_Type;
23248 else
23249 return Btype;
23250 end if;
23251
23252 else
23253 return Btype;
23254 end if;
23255
23256 elsif Is_Array_Type (Btype) then
23257 return Trace_Components (Component_Type (Btype), True);
23258
23259 elsif Is_Record_Type (Btype) then
23260 Component := First_Entity (Btype);
23261 while Present (Component)
23262 and then Comes_From_Source (Component)
23263 loop
23264 -- Skip anonymous types generated by constrained components
23265
23266 if not Is_Type (Component) then
23267 P := Trace_Components (Etype (Component), True);
23268
23269 if Present (P) then
23270 if P = Any_Type then
23271 return P;
23272 else
23273 Candidate := P;
23274 end if;
23275 end if;
23276 end if;
23277
23278 Next_Entity (Component);
23279 end loop;
23280
23281 return Candidate;
23282
23283 else
23284 return Empty;
23285 end if;
23286 end Trace_Components;
23287
23288 -- Start of processing for Private_Component
23289
23290 begin
23291 return Trace_Components (Type_Id, False);
23292 end Private_Component;
23293
23294 ---------------------------
23295 -- Primitive_Names_Match --
23296 ---------------------------
23297
23298 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
23299 function Non_Internal_Name (E : Entity_Id) return Name_Id;
23300 -- Given an internal name, returns the corresponding non-internal name
23301
23302 ------------------------
23303 -- Non_Internal_Name --
23304 ------------------------
23305
23306 function Non_Internal_Name (E : Entity_Id) return Name_Id is
23307 begin
23308 Get_Name_String (Chars (E));
23309 Name_Len := Name_Len - 1;
23310 return Name_Find;
23311 end Non_Internal_Name;
23312
23313 -- Start of processing for Primitive_Names_Match
23314
23315 begin
23316 pragma Assert (Present (E1) and then Present (E2));
23317
23318 return Chars (E1) = Chars (E2)
23319 or else
23320 (not Is_Internal_Name (Chars (E1))
23321 and then Is_Internal_Name (Chars (E2))
23322 and then Non_Internal_Name (E2) = Chars (E1))
23323 or else
23324 (not Is_Internal_Name (Chars (E2))
23325 and then Is_Internal_Name (Chars (E1))
23326 and then Non_Internal_Name (E1) = Chars (E2))
23327 or else
23328 (Is_Predefined_Dispatching_Operation (E1)
23329 and then Is_Predefined_Dispatching_Operation (E2)
23330 and then Same_TSS (E1, E2))
23331 or else
23332 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
23333 end Primitive_Names_Match;
23334
23335 -----------------------
23336 -- Process_End_Label --
23337 -----------------------
23338
23339 procedure Process_End_Label
23340 (N : Node_Id;
23341 Typ : Character;
23342 Ent : Entity_Id)
23343 is
23344 Loc : Source_Ptr;
23345 Nam : Node_Id;
23346 Scop : Entity_Id;
23347
23348 Label_Ref : Boolean;
23349 -- Set True if reference to end label itself is required
23350
23351 Endl : Node_Id;
23352 -- Gets set to the operator symbol or identifier that references the
23353 -- entity Ent. For the child unit case, this is the identifier from the
23354 -- designator. For other cases, this is simply Endl.
23355
23356 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
23357 -- N is an identifier node that appears as a parent unit reference in
23358 -- the case where Ent is a child unit. This procedure generates an
23359 -- appropriate cross-reference entry. E is the corresponding entity.
23360
23361 -------------------------
23362 -- Generate_Parent_Ref --
23363 -------------------------
23364
23365 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
23366 begin
23367 -- If names do not match, something weird, skip reference
23368
23369 if Chars (E) = Chars (N) then
23370
23371 -- Generate the reference. We do NOT consider this as a reference
23372 -- for unreferenced symbol purposes.
23373
23374 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
23375
23376 if Style_Check then
23377 Style.Check_Identifier (N, E);
23378 end if;
23379 end if;
23380 end Generate_Parent_Ref;
23381
23382 -- Start of processing for Process_End_Label
23383
23384 begin
23385 -- If no node, ignore. This happens in some error situations, and
23386 -- also for some internally generated structures where no end label
23387 -- references are required in any case.
23388
23389 if No (N) then
23390 return;
23391 end if;
23392
23393 -- Nothing to do if no End_Label, happens for internally generated
23394 -- constructs where we don't want an end label reference anyway. Also
23395 -- nothing to do if Endl is a string literal, which means there was
23396 -- some prior error (bad operator symbol)
23397
23398 Endl := End_Label (N);
23399
23400 if No (Endl) or else Nkind (Endl) = N_String_Literal then
23401 return;
23402 end if;
23403
23404 -- Reference node is not in extended main source unit
23405
23406 if not In_Extended_Main_Source_Unit (N) then
23407
23408 -- Generally we do not collect references except for the extended
23409 -- main source unit. The one exception is the 'e' entry for a
23410 -- package spec, where it is useful for a client to have the
23411 -- ending information to define scopes.
23412
23413 if Typ /= 'e' then
23414 return;
23415
23416 else
23417 Label_Ref := False;
23418
23419 -- For this case, we can ignore any parent references, but we
23420 -- need the package name itself for the 'e' entry.
23421
23422 if Nkind (Endl) = N_Designator then
23423 Endl := Identifier (Endl);
23424 end if;
23425 end if;
23426
23427 -- Reference is in extended main source unit
23428
23429 else
23430 Label_Ref := True;
23431
23432 -- For designator, generate references for the parent entries
23433
23434 if Nkind (Endl) = N_Designator then
23435
23436 -- Generate references for the prefix if the END line comes from
23437 -- source (otherwise we do not need these references) We climb the
23438 -- scope stack to find the expected entities.
23439
23440 if Comes_From_Source (Endl) then
23441 Nam := Name (Endl);
23442 Scop := Current_Scope;
23443 while Nkind (Nam) = N_Selected_Component loop
23444 Scop := Scope (Scop);
23445 exit when No (Scop);
23446 Generate_Parent_Ref (Selector_Name (Nam), Scop);
23447 Nam := Prefix (Nam);
23448 end loop;
23449
23450 if Present (Scop) then
23451 Generate_Parent_Ref (Nam, Scope (Scop));
23452 end if;
23453 end if;
23454
23455 Endl := Identifier (Endl);
23456 end if;
23457 end if;
23458
23459 -- If the end label is not for the given entity, then either we have
23460 -- some previous error, or this is a generic instantiation for which
23461 -- we do not need to make a cross-reference in this case anyway. In
23462 -- either case we simply ignore the call.
23463
23464 if Chars (Ent) /= Chars (Endl) then
23465 return;
23466 end if;
23467
23468 -- If label was really there, then generate a normal reference and then
23469 -- adjust the location in the end label to point past the name (which
23470 -- should almost always be the semicolon).
23471
23472 Loc := Sloc (Endl);
23473
23474 if Comes_From_Source (Endl) then
23475
23476 -- If a label reference is required, then do the style check and
23477 -- generate an l-type cross-reference entry for the label
23478
23479 if Label_Ref then
23480 if Style_Check then
23481 Style.Check_Identifier (Endl, Ent);
23482 end if;
23483
23484 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
23485 end if;
23486
23487 -- Set the location to point past the label (normally this will
23488 -- mean the semicolon immediately following the label). This is
23489 -- done for the sake of the 'e' or 't' entry generated below.
23490
23491 Get_Decoded_Name_String (Chars (Endl));
23492 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
23493
23494 else
23495 -- In SPARK mode, no missing label is allowed for packages and
23496 -- subprogram bodies. Detect those cases by testing whether
23497 -- Process_End_Label was called for a body (Typ = 't') or a package.
23498
23499 if Restriction_Check_Required (SPARK_05)
23500 and then (Typ = 't' or else Ekind (Ent) = E_Package)
23501 then
23502 Error_Msg_Node_1 := Endl;
23503 Check_SPARK_05_Restriction
23504 ("`END &` required", Endl, Force => True);
23505 end if;
23506 end if;
23507
23508 -- Now generate the e/t reference
23509
23510 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
23511
23512 -- Restore Sloc, in case modified above, since we have an identifier
23513 -- and the normal Sloc should be left set in the tree.
23514
23515 Set_Sloc (Endl, Loc);
23516 end Process_End_Label;
23517
23518 --------------------------------
23519 -- Propagate_Concurrent_Flags --
23520 --------------------------------
23521
23522 procedure Propagate_Concurrent_Flags
23523 (Typ : Entity_Id;
23524 Comp_Typ : Entity_Id)
23525 is
23526 begin
23527 if Has_Task (Comp_Typ) then
23528 Set_Has_Task (Typ);
23529 end if;
23530
23531 if Has_Protected (Comp_Typ) then
23532 Set_Has_Protected (Typ);
23533 end if;
23534
23535 if Has_Timing_Event (Comp_Typ) then
23536 Set_Has_Timing_Event (Typ);
23537 end if;
23538 end Propagate_Concurrent_Flags;
23539
23540 ------------------------------
23541 -- Propagate_DIC_Attributes --
23542 ------------------------------
23543
23544 procedure Propagate_DIC_Attributes
23545 (Typ : Entity_Id;
23546 From_Typ : Entity_Id)
23547 is
23548 DIC_Proc : Entity_Id;
23549
23550 begin
23551 if Present (Typ) and then Present (From_Typ) then
23552 pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
23553
23554 -- Nothing to do if both the source and the destination denote the
23555 -- same type.
23556
23557 if From_Typ = Typ then
23558 return;
23559
23560 -- Nothing to do when the destination denotes an incomplete type
23561 -- because the DIC is associated with the current instance of a
23562 -- private type, thus it can never apply to an incomplete type.
23563
23564 elsif Is_Incomplete_Type (Typ) then
23565 return;
23566 end if;
23567
23568 DIC_Proc := DIC_Procedure (From_Typ);
23569
23570 -- The setting of the attributes is intentionally conservative. This
23571 -- prevents accidental clobbering of enabled attributes.
23572
23573 if Has_Inherited_DIC (From_Typ)
23574 and then not Has_Inherited_DIC (Typ)
23575 then
23576 Set_Has_Inherited_DIC (Typ);
23577 end if;
23578
23579 if Has_Own_DIC (From_Typ) and then not Has_Own_DIC (Typ) then
23580 Set_Has_Own_DIC (Typ);
23581 end if;
23582
23583 if Present (DIC_Proc) and then No (DIC_Procedure (Typ)) then
23584 Set_DIC_Procedure (Typ, DIC_Proc);
23585 end if;
23586 end if;
23587 end Propagate_DIC_Attributes;
23588
23589 ------------------------------------
23590 -- Propagate_Invariant_Attributes --
23591 ------------------------------------
23592
23593 procedure Propagate_Invariant_Attributes
23594 (Typ : Entity_Id;
23595 From_Typ : Entity_Id)
23596 is
23597 Full_IP : Entity_Id;
23598 Part_IP : Entity_Id;
23599
23600 begin
23601 if Present (Typ) and then Present (From_Typ) then
23602 pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
23603
23604 -- Nothing to do if both the source and the destination denote the
23605 -- same type.
23606
23607 if From_Typ = Typ then
23608 return;
23609 end if;
23610
23611 Full_IP := Invariant_Procedure (From_Typ);
23612 Part_IP := Partial_Invariant_Procedure (From_Typ);
23613
23614 -- The setting of the attributes is intentionally conservative. This
23615 -- prevents accidental clobbering of enabled attributes.
23616
23617 if Has_Inheritable_Invariants (From_Typ)
23618 and then not Has_Inheritable_Invariants (Typ)
23619 then
23620 Set_Has_Inheritable_Invariants (Typ);
23621 end if;
23622
23623 if Has_Inherited_Invariants (From_Typ)
23624 and then not Has_Inherited_Invariants (Typ)
23625 then
23626 Set_Has_Inherited_Invariants (Typ);
23627 end if;
23628
23629 if Has_Own_Invariants (From_Typ)
23630 and then not Has_Own_Invariants (Typ)
23631 then
23632 Set_Has_Own_Invariants (Typ);
23633 end if;
23634
23635 if Present (Full_IP) and then No (Invariant_Procedure (Typ)) then
23636 Set_Invariant_Procedure (Typ, Full_IP);
23637 end if;
23638
23639 if Present (Part_IP) and then No (Partial_Invariant_Procedure (Typ))
23640 then
23641 Set_Partial_Invariant_Procedure (Typ, Part_IP);
23642 end if;
23643 end if;
23644 end Propagate_Invariant_Attributes;
23645
23646 ---------------------------------------
23647 -- Record_Possible_Part_Of_Reference --
23648 ---------------------------------------
23649
23650 procedure Record_Possible_Part_Of_Reference
23651 (Var_Id : Entity_Id;
23652 Ref : Node_Id)
23653 is
23654 Encap : constant Entity_Id := Encapsulating_State (Var_Id);
23655 Refs : Elist_Id;
23656
23657 begin
23658 -- The variable is a constituent of a single protected/task type. Such
23659 -- a variable acts as a component of the type and must appear within a
23660 -- specific region (SPARK RM 9(3)). Instead of recording the reference,
23661 -- verify its legality now.
23662
23663 if Present (Encap) and then Is_Single_Concurrent_Object (Encap) then
23664 Check_Part_Of_Reference (Var_Id, Ref);
23665
23666 -- The variable is subject to pragma Part_Of and may eventually become a
23667 -- constituent of a single protected/task type. Record the reference to
23668 -- verify its placement when the contract of the variable is analyzed.
23669
23670 elsif Present (Get_Pragma (Var_Id, Pragma_Part_Of)) then
23671 Refs := Part_Of_References (Var_Id);
23672
23673 if No (Refs) then
23674 Refs := New_Elmt_List;
23675 Set_Part_Of_References (Var_Id, Refs);
23676 end if;
23677
23678 Append_Elmt (Ref, Refs);
23679 end if;
23680 end Record_Possible_Part_Of_Reference;
23681
23682 ----------------
23683 -- Referenced --
23684 ----------------
23685
23686 function Referenced (Id : Entity_Id; Expr : Node_Id) return Boolean is
23687 Seen : Boolean := False;
23688
23689 function Is_Reference (N : Node_Id) return Traverse_Result;
23690 -- Determine whether node N denotes a reference to Id. If this is the
23691 -- case, set global flag Seen to True and stop the traversal.
23692
23693 ------------------
23694 -- Is_Reference --
23695 ------------------
23696
23697 function Is_Reference (N : Node_Id) return Traverse_Result is
23698 begin
23699 if Is_Entity_Name (N)
23700 and then Present (Entity (N))
23701 and then Entity (N) = Id
23702 then
23703 Seen := True;
23704 return Abandon;
23705 else
23706 return OK;
23707 end if;
23708 end Is_Reference;
23709
23710 procedure Inspect_Expression is new Traverse_Proc (Is_Reference);
23711
23712 -- Start of processing for Referenced
23713
23714 begin
23715 Inspect_Expression (Expr);
23716 return Seen;
23717 end Referenced;
23718
23719 ------------------------------------
23720 -- References_Generic_Formal_Type --
23721 ------------------------------------
23722
23723 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
23724
23725 function Process (N : Node_Id) return Traverse_Result;
23726 -- Process one node in search for generic formal type
23727
23728 -------------
23729 -- Process --
23730 -------------
23731
23732 function Process (N : Node_Id) return Traverse_Result is
23733 begin
23734 if Nkind (N) in N_Has_Entity then
23735 declare
23736 E : constant Entity_Id := Entity (N);
23737 begin
23738 if Present (E) then
23739 if Is_Generic_Type (E) then
23740 return Abandon;
23741 elsif Present (Etype (E))
23742 and then Is_Generic_Type (Etype (E))
23743 then
23744 return Abandon;
23745 end if;
23746 end if;
23747 end;
23748 end if;
23749
23750 return Atree.OK;
23751 end Process;
23752
23753 function Traverse is new Traverse_Func (Process);
23754 -- Traverse tree to look for generic type
23755
23756 begin
23757 if Inside_A_Generic then
23758 return Traverse (N) = Abandon;
23759 else
23760 return False;
23761 end if;
23762 end References_Generic_Formal_Type;
23763
23764 -------------------------------
23765 -- Remove_Entity_And_Homonym --
23766 -------------------------------
23767
23768 procedure Remove_Entity_And_Homonym (Id : Entity_Id) is
23769 begin
23770 Remove_Entity (Id);
23771 Remove_Homonym (Id);
23772 end Remove_Entity_And_Homonym;
23773
23774 --------------------
23775 -- Remove_Homonym --
23776 --------------------
23777
23778 procedure Remove_Homonym (Id : Entity_Id) is
23779 Hom : Entity_Id;
23780 Prev : Entity_Id := Empty;
23781
23782 begin
23783 if Id = Current_Entity (Id) then
23784 if Present (Homonym (Id)) then
23785 Set_Current_Entity (Homonym (Id));
23786 else
23787 Set_Name_Entity_Id (Chars (Id), Empty);
23788 end if;
23789
23790 else
23791 Hom := Current_Entity (Id);
23792 while Present (Hom) and then Hom /= Id loop
23793 Prev := Hom;
23794 Hom := Homonym (Hom);
23795 end loop;
23796
23797 -- If Id is not on the homonym chain, nothing to do
23798
23799 if Present (Hom) then
23800 Set_Homonym (Prev, Homonym (Id));
23801 end if;
23802 end if;
23803 end Remove_Homonym;
23804
23805 ------------------------------
23806 -- Remove_Overloaded_Entity --
23807 ------------------------------
23808
23809 procedure Remove_Overloaded_Entity (Id : Entity_Id) is
23810 procedure Remove_Primitive_Of (Typ : Entity_Id);
23811 -- Remove primitive subprogram Id from the list of primitives that
23812 -- belong to type Typ.
23813
23814 -------------------------
23815 -- Remove_Primitive_Of --
23816 -------------------------
23817
23818 procedure Remove_Primitive_Of (Typ : Entity_Id) is
23819 Prims : Elist_Id;
23820
23821 begin
23822 if Is_Tagged_Type (Typ) then
23823 Prims := Direct_Primitive_Operations (Typ);
23824
23825 if Present (Prims) then
23826 Remove (Prims, Id);
23827 end if;
23828 end if;
23829 end Remove_Primitive_Of;
23830
23831 -- Local variables
23832
23833 Formal : Entity_Id;
23834
23835 -- Start of processing for Remove_Overloaded_Entity
23836
23837 begin
23838 Remove_Entity_And_Homonym (Id);
23839
23840 -- The entity denotes a primitive subprogram. Remove it from the list of
23841 -- primitives of the associated controlling type.
23842
23843 if Ekind_In (Id, E_Function, E_Procedure) and then Is_Primitive (Id) then
23844 Formal := First_Formal (Id);
23845 while Present (Formal) loop
23846 if Is_Controlling_Formal (Formal) then
23847 Remove_Primitive_Of (Etype (Formal));
23848 exit;
23849 end if;
23850
23851 Next_Formal (Formal);
23852 end loop;
23853
23854 if Ekind (Id) = E_Function and then Has_Controlling_Result (Id) then
23855 Remove_Primitive_Of (Etype (Id));
23856 end if;
23857 end if;
23858 end Remove_Overloaded_Entity;
23859
23860 ---------------------
23861 -- Rep_To_Pos_Flag --
23862 ---------------------
23863
23864 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
23865 begin
23866 return New_Occurrence_Of
23867 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
23868 end Rep_To_Pos_Flag;
23869
23870 --------------------
23871 -- Require_Entity --
23872 --------------------
23873
23874 procedure Require_Entity (N : Node_Id) is
23875 begin
23876 if Is_Entity_Name (N) and then No (Entity (N)) then
23877 if Total_Errors_Detected /= 0 then
23878 Set_Entity (N, Any_Id);
23879 else
23880 raise Program_Error;
23881 end if;
23882 end if;
23883 end Require_Entity;
23884
23885 ------------------------------
23886 -- Requires_Transient_Scope --
23887 ------------------------------
23888
23889 -- A transient scope is required when variable-sized temporaries are
23890 -- allocated on the secondary stack, or when finalization actions must be
23891 -- generated before the next instruction.
23892
23893 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
23894 Old_Result : constant Boolean := Old_Requires_Transient_Scope (Id);
23895
23896 begin
23897 if Debug_Flag_QQ then
23898 return Old_Result;
23899 end if;
23900
23901 declare
23902 New_Result : constant Boolean := New_Requires_Transient_Scope (Id);
23903
23904 begin
23905 -- Assert that we're not putting things on the secondary stack if we
23906 -- didn't before; we are trying to AVOID secondary stack when
23907 -- possible.
23908
23909 if not Old_Result then
23910 pragma Assert (not New_Result);
23911 null;
23912 end if;
23913
23914 if New_Result /= Old_Result then
23915 Results_Differ (Id, Old_Result, New_Result);
23916 end if;
23917
23918 return New_Result;
23919 end;
23920 end Requires_Transient_Scope;
23921
23922 --------------------
23923 -- Results_Differ --
23924 --------------------
23925
23926 procedure Results_Differ
23927 (Id : Entity_Id;
23928 Old_Val : Boolean;
23929 New_Val : Boolean)
23930 is
23931 begin
23932 if False then -- False to disable; True for debugging
23933 Treepr.Print_Tree_Node (Id);
23934
23935 if Old_Val = New_Val then
23936 raise Program_Error;
23937 end if;
23938 end if;
23939 end Results_Differ;
23940
23941 --------------------------
23942 -- Reset_Analyzed_Flags --
23943 --------------------------
23944
23945 procedure Reset_Analyzed_Flags (N : Node_Id) is
23946 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
23947 -- Function used to reset Analyzed flags in tree. Note that we do
23948 -- not reset Analyzed flags in entities, since there is no need to
23949 -- reanalyze entities, and indeed, it is wrong to do so, since it
23950 -- can result in generating auxiliary stuff more than once.
23951
23952 --------------------
23953 -- Clear_Analyzed --
23954 --------------------
23955
23956 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
23957 begin
23958 if Nkind (N) not in N_Entity then
23959 Set_Analyzed (N, False);
23960 end if;
23961
23962 return OK;
23963 end Clear_Analyzed;
23964
23965 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
23966
23967 -- Start of processing for Reset_Analyzed_Flags
23968
23969 begin
23970 Reset_Analyzed (N);
23971 end Reset_Analyzed_Flags;
23972
23973 ------------------------
23974 -- Restore_SPARK_Mode --
23975 ------------------------
23976
23977 procedure Restore_SPARK_Mode
23978 (Mode : SPARK_Mode_Type;
23979 Prag : Node_Id)
23980 is
23981 begin
23982 SPARK_Mode := Mode;
23983 SPARK_Mode_Pragma := Prag;
23984 end Restore_SPARK_Mode;
23985
23986 --------------------------------
23987 -- Returns_Unconstrained_Type --
23988 --------------------------------
23989
23990 function Returns_Unconstrained_Type (Subp : Entity_Id) return Boolean is
23991 begin
23992 return Ekind (Subp) = E_Function
23993 and then not Is_Scalar_Type (Etype (Subp))
23994 and then not Is_Access_Type (Etype (Subp))
23995 and then not Is_Constrained (Etype (Subp));
23996 end Returns_Unconstrained_Type;
23997
23998 ----------------------------
23999 -- Root_Type_Of_Full_View --
24000 ----------------------------
24001
24002 function Root_Type_Of_Full_View (T : Entity_Id) return Entity_Id is
24003 Rtyp : constant Entity_Id := Root_Type (T);
24004
24005 begin
24006 -- The root type of the full view may itself be a private type. Keep
24007 -- looking for the ultimate derivation parent.
24008
24009 if Is_Private_Type (Rtyp) and then Present (Full_View (Rtyp)) then
24010 return Root_Type_Of_Full_View (Full_View (Rtyp));
24011 else
24012 return Rtyp;
24013 end if;
24014 end Root_Type_Of_Full_View;
24015
24016 ---------------------------
24017 -- Safe_To_Capture_Value --
24018 ---------------------------
24019
24020 function Safe_To_Capture_Value
24021 (N : Node_Id;
24022 Ent : Entity_Id;
24023 Cond : Boolean := False) return Boolean
24024 is
24025 begin
24026 -- The only entities for which we track constant values are variables
24027 -- which are not renamings, constants, out parameters, and in out
24028 -- parameters, so check if we have this case.
24029
24030 -- Note: it may seem odd to track constant values for constants, but in
24031 -- fact this routine is used for other purposes than simply capturing
24032 -- the value. In particular, the setting of Known[_Non]_Null.
24033
24034 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
24035 or else
24036 Ekind_In (Ent, E_Constant, E_Out_Parameter, E_In_Out_Parameter)
24037 then
24038 null;
24039
24040 -- For conditionals, we also allow loop parameters and all formals,
24041 -- including in parameters.
24042
24043 elsif Cond and then Ekind_In (Ent, E_Loop_Parameter, E_In_Parameter) then
24044 null;
24045
24046 -- For all other cases, not just unsafe, but impossible to capture
24047 -- Current_Value, since the above are the only entities which have
24048 -- Current_Value fields.
24049
24050 else
24051 return False;
24052 end if;
24053
24054 -- Skip if volatile or aliased, since funny things might be going on in
24055 -- these cases which we cannot necessarily track. Also skip any variable
24056 -- for which an address clause is given, or whose address is taken. Also
24057 -- never capture value of library level variables (an attempt to do so
24058 -- can occur in the case of package elaboration code).
24059
24060 if Treat_As_Volatile (Ent)
24061 or else Is_Aliased (Ent)
24062 or else Present (Address_Clause (Ent))
24063 or else Address_Taken (Ent)
24064 or else (Is_Library_Level_Entity (Ent)
24065 and then Ekind (Ent) = E_Variable)
24066 then
24067 return False;
24068 end if;
24069
24070 -- OK, all above conditions are met. We also require that the scope of
24071 -- the reference be the same as the scope of the entity, not counting
24072 -- packages and blocks and loops.
24073
24074 declare
24075 E_Scope : constant Entity_Id := Scope (Ent);
24076 R_Scope : Entity_Id;
24077
24078 begin
24079 R_Scope := Current_Scope;
24080 while R_Scope /= Standard_Standard loop
24081 exit when R_Scope = E_Scope;
24082
24083 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
24084 return False;
24085 else
24086 R_Scope := Scope (R_Scope);
24087 end if;
24088 end loop;
24089 end;
24090
24091 -- We also require that the reference does not appear in a context
24092 -- where it is not sure to be executed (i.e. a conditional context
24093 -- or an exception handler). We skip this if Cond is True, since the
24094 -- capturing of values from conditional tests handles this ok.
24095
24096 if Cond then
24097 return True;
24098 end if;
24099
24100 declare
24101 Desc : Node_Id;
24102 P : Node_Id;
24103
24104 begin
24105 Desc := N;
24106
24107 -- Seems dubious that case expressions are not handled here ???
24108
24109 P := Parent (N);
24110 while Present (P) loop
24111 if Nkind (P) = N_If_Statement
24112 or else Nkind (P) = N_Case_Statement
24113 or else (Nkind (P) in N_Short_Circuit
24114 and then Desc = Right_Opnd (P))
24115 or else (Nkind (P) = N_If_Expression
24116 and then Desc /= First (Expressions (P)))
24117 or else Nkind (P) = N_Exception_Handler
24118 or else Nkind (P) = N_Selective_Accept
24119 or else Nkind (P) = N_Conditional_Entry_Call
24120 or else Nkind (P) = N_Timed_Entry_Call
24121 or else Nkind (P) = N_Asynchronous_Select
24122 then
24123 return False;
24124
24125 else
24126 Desc := P;
24127 P := Parent (P);
24128
24129 -- A special Ada 2012 case: the original node may be part
24130 -- of the else_actions of a conditional expression, in which
24131 -- case it might not have been expanded yet, and appears in
24132 -- a non-syntactic list of actions. In that case it is clearly
24133 -- not safe to save a value.
24134
24135 if No (P)
24136 and then Is_List_Member (Desc)
24137 and then No (Parent (List_Containing (Desc)))
24138 then
24139 return False;
24140 end if;
24141 end if;
24142 end loop;
24143 end;
24144
24145 -- OK, looks safe to set value
24146
24147 return True;
24148 end Safe_To_Capture_Value;
24149
24150 ---------------
24151 -- Same_Name --
24152 ---------------
24153
24154 function Same_Name (N1, N2 : Node_Id) return Boolean is
24155 K1 : constant Node_Kind := Nkind (N1);
24156 K2 : constant Node_Kind := Nkind (N2);
24157
24158 begin
24159 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
24160 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
24161 then
24162 return Chars (N1) = Chars (N2);
24163
24164 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
24165 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
24166 then
24167 return Same_Name (Selector_Name (N1), Selector_Name (N2))
24168 and then Same_Name (Prefix (N1), Prefix (N2));
24169
24170 else
24171 return False;
24172 end if;
24173 end Same_Name;
24174
24175 -----------------
24176 -- Same_Object --
24177 -----------------
24178
24179 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
24180 N1 : constant Node_Id := Original_Node (Node1);
24181 N2 : constant Node_Id := Original_Node (Node2);
24182 -- We do the tests on original nodes, since we are most interested
24183 -- in the original source, not any expansion that got in the way.
24184
24185 K1 : constant Node_Kind := Nkind (N1);
24186 K2 : constant Node_Kind := Nkind (N2);
24187
24188 begin
24189 -- First case, both are entities with same entity
24190
24191 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
24192 declare
24193 EN1 : constant Entity_Id := Entity (N1);
24194 EN2 : constant Entity_Id := Entity (N2);
24195 begin
24196 if Present (EN1) and then Present (EN2)
24197 and then (Ekind_In (EN1, E_Variable, E_Constant)
24198 or else Is_Formal (EN1))
24199 and then EN1 = EN2
24200 then
24201 return True;
24202 end if;
24203 end;
24204 end if;
24205
24206 -- Second case, selected component with same selector, same record
24207
24208 if K1 = N_Selected_Component
24209 and then K2 = N_Selected_Component
24210 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
24211 then
24212 return Same_Object (Prefix (N1), Prefix (N2));
24213
24214 -- Third case, indexed component with same subscripts, same array
24215
24216 elsif K1 = N_Indexed_Component
24217 and then K2 = N_Indexed_Component
24218 and then Same_Object (Prefix (N1), Prefix (N2))
24219 then
24220 declare
24221 E1, E2 : Node_Id;
24222 begin
24223 E1 := First (Expressions (N1));
24224 E2 := First (Expressions (N2));
24225 while Present (E1) loop
24226 if not Same_Value (E1, E2) then
24227 return False;
24228 else
24229 Next (E1);
24230 Next (E2);
24231 end if;
24232 end loop;
24233
24234 return True;
24235 end;
24236
24237 -- Fourth case, slice of same array with same bounds
24238
24239 elsif K1 = N_Slice
24240 and then K2 = N_Slice
24241 and then Nkind (Discrete_Range (N1)) = N_Range
24242 and then Nkind (Discrete_Range (N2)) = N_Range
24243 and then Same_Value (Low_Bound (Discrete_Range (N1)),
24244 Low_Bound (Discrete_Range (N2)))
24245 and then Same_Value (High_Bound (Discrete_Range (N1)),
24246 High_Bound (Discrete_Range (N2)))
24247 then
24248 return Same_Name (Prefix (N1), Prefix (N2));
24249
24250 -- All other cases, not clearly the same object
24251
24252 else
24253 return False;
24254 end if;
24255 end Same_Object;
24256
24257 ---------------
24258 -- Same_Type --
24259 ---------------
24260
24261 function Same_Type (T1, T2 : Entity_Id) return Boolean is
24262 begin
24263 if T1 = T2 then
24264 return True;
24265
24266 elsif not Is_Constrained (T1)
24267 and then not Is_Constrained (T2)
24268 and then Base_Type (T1) = Base_Type (T2)
24269 then
24270 return True;
24271
24272 -- For now don't bother with case of identical constraints, to be
24273 -- fiddled with later on perhaps (this is only used for optimization
24274 -- purposes, so it is not critical to do a best possible job)
24275
24276 else
24277 return False;
24278 end if;
24279 end Same_Type;
24280
24281 ----------------
24282 -- Same_Value --
24283 ----------------
24284
24285 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
24286 begin
24287 if Compile_Time_Known_Value (Node1)
24288 and then Compile_Time_Known_Value (Node2)
24289 then
24290 -- Handle properly compile-time expressions that are not
24291 -- scalar.
24292
24293 if Is_String_Type (Etype (Node1)) then
24294 return Expr_Value_S (Node1) = Expr_Value_S (Node2);
24295
24296 else
24297 return Expr_Value (Node1) = Expr_Value (Node2);
24298 end if;
24299
24300 elsif Same_Object (Node1, Node2) then
24301 return True;
24302 else
24303 return False;
24304 end if;
24305 end Same_Value;
24306
24307 --------------------
24308 -- Set_SPARK_Mode --
24309 --------------------
24310
24311 procedure Set_SPARK_Mode (Context : Entity_Id) is
24312 begin
24313 -- Do not consider illegal or partially decorated constructs
24314
24315 if Ekind (Context) = E_Void or else Error_Posted (Context) then
24316 null;
24317
24318 elsif Present (SPARK_Pragma (Context)) then
24319 Install_SPARK_Mode
24320 (Mode => Get_SPARK_Mode_From_Annotation (SPARK_Pragma (Context)),
24321 Prag => SPARK_Pragma (Context));
24322 end if;
24323 end Set_SPARK_Mode;
24324
24325 -------------------------
24326 -- Scalar_Part_Present --
24327 -------------------------
24328
24329 function Scalar_Part_Present (Typ : Entity_Id) return Boolean is
24330 Val_Typ : constant Entity_Id := Validated_View (Typ);
24331 Field : Entity_Id;
24332
24333 begin
24334 if Is_Scalar_Type (Val_Typ) then
24335 return True;
24336
24337 elsif Is_Array_Type (Val_Typ) then
24338 return Scalar_Part_Present (Component_Type (Val_Typ));
24339
24340 elsif Is_Record_Type (Val_Typ) then
24341 Field := First_Component_Or_Discriminant (Val_Typ);
24342 while Present (Field) loop
24343 if Scalar_Part_Present (Etype (Field)) then
24344 return True;
24345 end if;
24346
24347 Next_Component_Or_Discriminant (Field);
24348 end loop;
24349 end if;
24350
24351 return False;
24352 end Scalar_Part_Present;
24353
24354 ------------------------
24355 -- Scope_Is_Transient --
24356 ------------------------
24357
24358 function Scope_Is_Transient return Boolean is
24359 begin
24360 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
24361 end Scope_Is_Transient;
24362
24363 ------------------
24364 -- Scope_Within --
24365 ------------------
24366
24367 function Scope_Within
24368 (Inner : Entity_Id;
24369 Outer : Entity_Id) return Boolean
24370 is
24371 Curr : Entity_Id;
24372
24373 begin
24374 Curr := Inner;
24375 while Present (Curr) and then Curr /= Standard_Standard loop
24376 Curr := Scope (Curr);
24377
24378 if Curr = Outer then
24379 return True;
24380
24381 -- A selective accept body appears within a task type, but the
24382 -- enclosing subprogram is the procedure of the task body.
24383
24384 elsif Ekind (Curr) = E_Task_Type
24385 and then Outer = Task_Body_Procedure (Curr)
24386 then
24387 return True;
24388
24389 -- Ditto for the body of a protected operation
24390
24391 elsif Is_Subprogram (Curr)
24392 and then Outer = Protected_Body_Subprogram (Curr)
24393 then
24394 return True;
24395
24396 -- Outside of its scope, a synchronized type may just be private
24397
24398 elsif Is_Private_Type (Curr)
24399 and then Present (Full_View (Curr))
24400 and then Is_Concurrent_Type (Full_View (Curr))
24401 then
24402 return Scope_Within (Full_View (Curr), Outer);
24403 end if;
24404 end loop;
24405
24406 return False;
24407 end Scope_Within;
24408
24409 --------------------------
24410 -- Scope_Within_Or_Same --
24411 --------------------------
24412
24413 function Scope_Within_Or_Same
24414 (Inner : Entity_Id;
24415 Outer : Entity_Id) return Boolean
24416 is
24417 Curr : Entity_Id := Inner;
24418
24419 begin
24420 -- Similar to the above, but check for scope identity first
24421
24422 while Present (Curr) and then Curr /= Standard_Standard loop
24423 if Curr = Outer then
24424 return True;
24425
24426 elsif Ekind (Curr) = E_Task_Type
24427 and then Outer = Task_Body_Procedure (Curr)
24428 then
24429 return True;
24430
24431 elsif Is_Subprogram (Curr)
24432 and then Outer = Protected_Body_Subprogram (Curr)
24433 then
24434 return True;
24435
24436 elsif Is_Private_Type (Curr)
24437 and then Present (Full_View (Curr))
24438 then
24439 if Full_View (Curr) = Outer then
24440 return True;
24441 else
24442 return Scope_Within (Full_View (Curr), Outer);
24443 end if;
24444 end if;
24445
24446 Curr := Scope (Curr);
24447 end loop;
24448
24449 return False;
24450 end Scope_Within_Or_Same;
24451
24452 --------------------
24453 -- Set_Convention --
24454 --------------------
24455
24456 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
24457 begin
24458 Basic_Set_Convention (E, Val);
24459
24460 if Is_Type (E)
24461 and then Is_Access_Subprogram_Type (Base_Type (E))
24462 and then Has_Foreign_Convention (E)
24463 then
24464 Set_Can_Use_Internal_Rep (E, False);
24465 end if;
24466
24467 -- If E is an object, including a component, and the type of E is an
24468 -- anonymous access type with no convention set, then also set the
24469 -- convention of the anonymous access type. We do not do this for
24470 -- anonymous protected types, since protected types always have the
24471 -- default convention.
24472
24473 if Present (Etype (E))
24474 and then (Is_Object (E)
24475
24476 -- Allow E_Void (happens for pragma Convention appearing
24477 -- in the middle of a record applying to a component)
24478
24479 or else Ekind (E) = E_Void)
24480 then
24481 declare
24482 Typ : constant Entity_Id := Etype (E);
24483
24484 begin
24485 if Ekind_In (Typ, E_Anonymous_Access_Type,
24486 E_Anonymous_Access_Subprogram_Type)
24487 and then not Has_Convention_Pragma (Typ)
24488 then
24489 Basic_Set_Convention (Typ, Val);
24490 Set_Has_Convention_Pragma (Typ);
24491
24492 -- And for the access subprogram type, deal similarly with the
24493 -- designated E_Subprogram_Type, which is always internal.
24494
24495 if Ekind (Typ) = E_Anonymous_Access_Subprogram_Type then
24496 declare
24497 Dtype : constant Entity_Id := Designated_Type (Typ);
24498 begin
24499 if Ekind (Dtype) = E_Subprogram_Type
24500 and then not Has_Convention_Pragma (Dtype)
24501 then
24502 Basic_Set_Convention (Dtype, Val);
24503 Set_Has_Convention_Pragma (Dtype);
24504 end if;
24505 end;
24506 end if;
24507 end if;
24508 end;
24509 end if;
24510 end Set_Convention;
24511
24512 ------------------------
24513 -- Set_Current_Entity --
24514 ------------------------
24515
24516 -- The given entity is to be set as the currently visible definition of its
24517 -- associated name (i.e. the Node_Id associated with its name). All we have
24518 -- to do is to get the name from the identifier, and then set the
24519 -- associated Node_Id to point to the given entity.
24520
24521 procedure Set_Current_Entity (E : Entity_Id) is
24522 begin
24523 Set_Name_Entity_Id (Chars (E), E);
24524 end Set_Current_Entity;
24525
24526 ---------------------------
24527 -- Set_Debug_Info_Needed --
24528 ---------------------------
24529
24530 procedure Set_Debug_Info_Needed (T : Entity_Id) is
24531
24532 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
24533 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
24534 -- Used to set debug info in a related node if not set already
24535
24536 --------------------------------------
24537 -- Set_Debug_Info_Needed_If_Not_Set --
24538 --------------------------------------
24539
24540 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
24541 begin
24542 if Present (E) and then not Needs_Debug_Info (E) then
24543 Set_Debug_Info_Needed (E);
24544
24545 -- For a private type, indicate that the full view also needs
24546 -- debug information.
24547
24548 if Is_Type (E)
24549 and then Is_Private_Type (E)
24550 and then Present (Full_View (E))
24551 then
24552 Set_Debug_Info_Needed (Full_View (E));
24553 end if;
24554 end if;
24555 end Set_Debug_Info_Needed_If_Not_Set;
24556
24557 -- Start of processing for Set_Debug_Info_Needed
24558
24559 begin
24560 -- Nothing to do if there is no available entity
24561
24562 if No (T) then
24563 return;
24564
24565 -- Nothing to do for an entity with suppressed debug information
24566
24567 elsif Debug_Info_Off (T) then
24568 return;
24569
24570 -- Nothing to do for an ignored Ghost entity because the entity will be
24571 -- eliminated from the tree.
24572
24573 elsif Is_Ignored_Ghost_Entity (T) then
24574 return;
24575
24576 -- Nothing to do if entity comes from a predefined file. Library files
24577 -- are compiled without debug information, but inlined bodies of these
24578 -- routines may appear in user code, and debug information on them ends
24579 -- up complicating debugging the user code.
24580
24581 elsif In_Inlined_Body and then In_Predefined_Unit (T) then
24582 Set_Needs_Debug_Info (T, False);
24583 end if;
24584
24585 -- Set flag in entity itself. Note that we will go through the following
24586 -- circuitry even if the flag is already set on T. That's intentional,
24587 -- it makes sure that the flag will be set in subsidiary entities.
24588
24589 Set_Needs_Debug_Info (T);
24590
24591 -- Set flag on subsidiary entities if not set already
24592
24593 if Is_Object (T) then
24594 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
24595
24596 elsif Is_Type (T) then
24597 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
24598
24599 if Is_Record_Type (T) then
24600 declare
24601 Ent : Entity_Id := First_Entity (T);
24602 begin
24603 while Present (Ent) loop
24604 Set_Debug_Info_Needed_If_Not_Set (Ent);
24605 Next_Entity (Ent);
24606 end loop;
24607 end;
24608
24609 -- For a class wide subtype, we also need debug information
24610 -- for the equivalent type.
24611
24612 if Ekind (T) = E_Class_Wide_Subtype then
24613 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
24614 end if;
24615
24616 elsif Is_Array_Type (T) then
24617 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
24618
24619 declare
24620 Indx : Node_Id := First_Index (T);
24621 begin
24622 while Present (Indx) loop
24623 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
24624 Indx := Next_Index (Indx);
24625 end loop;
24626 end;
24627
24628 -- For a packed array type, we also need debug information for
24629 -- the type used to represent the packed array. Conversely, we
24630 -- also need it for the former if we need it for the latter.
24631
24632 if Is_Packed (T) then
24633 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Impl_Type (T));
24634 end if;
24635
24636 if Is_Packed_Array_Impl_Type (T) then
24637 Set_Debug_Info_Needed_If_Not_Set (Original_Array_Type (T));
24638 end if;
24639
24640 elsif Is_Access_Type (T) then
24641 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
24642
24643 elsif Is_Private_Type (T) then
24644 declare
24645 FV : constant Entity_Id := Full_View (T);
24646
24647 begin
24648 Set_Debug_Info_Needed_If_Not_Set (FV);
24649
24650 -- If the full view is itself a derived private type, we need
24651 -- debug information on its underlying type.
24652
24653 if Present (FV)
24654 and then Is_Private_Type (FV)
24655 and then Present (Underlying_Full_View (FV))
24656 then
24657 Set_Needs_Debug_Info (Underlying_Full_View (FV));
24658 end if;
24659 end;
24660
24661 elsif Is_Protected_Type (T) then
24662 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
24663
24664 elsif Is_Scalar_Type (T) then
24665
24666 -- If the subrange bounds are materialized by dedicated constant
24667 -- objects, also include them in the debug info to make sure the
24668 -- debugger can properly use them.
24669
24670 if Present (Scalar_Range (T))
24671 and then Nkind (Scalar_Range (T)) = N_Range
24672 then
24673 declare
24674 Low_Bnd : constant Node_Id := Type_Low_Bound (T);
24675 High_Bnd : constant Node_Id := Type_High_Bound (T);
24676
24677 begin
24678 if Is_Entity_Name (Low_Bnd) then
24679 Set_Debug_Info_Needed_If_Not_Set (Entity (Low_Bnd));
24680 end if;
24681
24682 if Is_Entity_Name (High_Bnd) then
24683 Set_Debug_Info_Needed_If_Not_Set (Entity (High_Bnd));
24684 end if;
24685 end;
24686 end if;
24687 end if;
24688 end if;
24689 end Set_Debug_Info_Needed;
24690
24691 ----------------------------
24692 -- Set_Entity_With_Checks --
24693 ----------------------------
24694
24695 procedure Set_Entity_With_Checks (N : Node_Id; Val : Entity_Id) is
24696 Val_Actual : Entity_Id;
24697 Nod : Node_Id;
24698 Post_Node : Node_Id;
24699
24700 begin
24701 -- Unconditionally set the entity
24702
24703 Set_Entity (N, Val);
24704
24705 -- The node to post on is the selector in the case of an expanded name,
24706 -- and otherwise the node itself.
24707
24708 if Nkind (N) = N_Expanded_Name then
24709 Post_Node := Selector_Name (N);
24710 else
24711 Post_Node := N;
24712 end if;
24713
24714 -- Check for violation of No_Fixed_IO
24715
24716 if Restriction_Check_Required (No_Fixed_IO)
24717 and then
24718 ((RTU_Loaded (Ada_Text_IO)
24719 and then (Is_RTE (Val, RE_Decimal_IO)
24720 or else
24721 Is_RTE (Val, RE_Fixed_IO)))
24722
24723 or else
24724 (RTU_Loaded (Ada_Wide_Text_IO)
24725 and then (Is_RTE (Val, RO_WT_Decimal_IO)
24726 or else
24727 Is_RTE (Val, RO_WT_Fixed_IO)))
24728
24729 or else
24730 (RTU_Loaded (Ada_Wide_Wide_Text_IO)
24731 and then (Is_RTE (Val, RO_WW_Decimal_IO)
24732 or else
24733 Is_RTE (Val, RO_WW_Fixed_IO))))
24734
24735 -- A special extra check, don't complain about a reference from within
24736 -- the Ada.Interrupts package itself!
24737
24738 and then not In_Same_Extended_Unit (N, Val)
24739 then
24740 Check_Restriction (No_Fixed_IO, Post_Node);
24741 end if;
24742
24743 -- Remaining checks are only done on source nodes. Note that we test
24744 -- for violation of No_Fixed_IO even on non-source nodes, because the
24745 -- cases for checking violations of this restriction are instantiations
24746 -- where the reference in the instance has Comes_From_Source False.
24747
24748 if not Comes_From_Source (N) then
24749 return;
24750 end if;
24751
24752 -- Check for violation of No_Abort_Statements, which is triggered by
24753 -- call to Ada.Task_Identification.Abort_Task.
24754
24755 if Restriction_Check_Required (No_Abort_Statements)
24756 and then (Is_RTE (Val, RE_Abort_Task))
24757
24758 -- A special extra check, don't complain about a reference from within
24759 -- the Ada.Task_Identification package itself!
24760
24761 and then not In_Same_Extended_Unit (N, Val)
24762 then
24763 Check_Restriction (No_Abort_Statements, Post_Node);
24764 end if;
24765
24766 if Val = Standard_Long_Long_Integer then
24767 Check_Restriction (No_Long_Long_Integers, Post_Node);
24768 end if;
24769
24770 -- Check for violation of No_Dynamic_Attachment
24771
24772 if Restriction_Check_Required (No_Dynamic_Attachment)
24773 and then RTU_Loaded (Ada_Interrupts)
24774 and then (Is_RTE (Val, RE_Is_Reserved) or else
24775 Is_RTE (Val, RE_Is_Attached) or else
24776 Is_RTE (Val, RE_Current_Handler) or else
24777 Is_RTE (Val, RE_Attach_Handler) or else
24778 Is_RTE (Val, RE_Exchange_Handler) or else
24779 Is_RTE (Val, RE_Detach_Handler) or else
24780 Is_RTE (Val, RE_Reference))
24781
24782 -- A special extra check, don't complain about a reference from within
24783 -- the Ada.Interrupts package itself!
24784
24785 and then not In_Same_Extended_Unit (N, Val)
24786 then
24787 Check_Restriction (No_Dynamic_Attachment, Post_Node);
24788 end if;
24789
24790 -- Check for No_Implementation_Identifiers
24791
24792 if Restriction_Check_Required (No_Implementation_Identifiers) then
24793
24794 -- We have an implementation defined entity if it is marked as
24795 -- implementation defined, or is defined in a package marked as
24796 -- implementation defined. However, library packages themselves
24797 -- are excluded (we don't want to flag Interfaces itself, just
24798 -- the entities within it).
24799
24800 if (Is_Implementation_Defined (Val)
24801 or else
24802 (Present (Scope (Val))
24803 and then Is_Implementation_Defined (Scope (Val))))
24804 and then not (Ekind_In (Val, E_Package, E_Generic_Package)
24805 and then Is_Library_Level_Entity (Val))
24806 then
24807 Check_Restriction (No_Implementation_Identifiers, Post_Node);
24808 end if;
24809 end if;
24810
24811 -- Do the style check
24812
24813 if Style_Check
24814 and then not Suppress_Style_Checks (Val)
24815 and then not In_Instance
24816 then
24817 if Nkind (N) = N_Identifier then
24818 Nod := N;
24819 elsif Nkind (N) = N_Expanded_Name then
24820 Nod := Selector_Name (N);
24821 else
24822 return;
24823 end if;
24824
24825 -- A special situation arises for derived operations, where we want
24826 -- to do the check against the parent (since the Sloc of the derived
24827 -- operation points to the derived type declaration itself).
24828
24829 Val_Actual := Val;
24830 while not Comes_From_Source (Val_Actual)
24831 and then Nkind (Val_Actual) in N_Entity
24832 and then (Ekind (Val_Actual) = E_Enumeration_Literal
24833 or else Is_Subprogram_Or_Generic_Subprogram (Val_Actual))
24834 and then Present (Alias (Val_Actual))
24835 loop
24836 Val_Actual := Alias (Val_Actual);
24837 end loop;
24838
24839 -- Renaming declarations for generic actuals do not come from source,
24840 -- and have a different name from that of the entity they rename, so
24841 -- there is no style check to perform here.
24842
24843 if Chars (Nod) = Chars (Val_Actual) then
24844 Style.Check_Identifier (Nod, Val_Actual);
24845 end if;
24846 end if;
24847
24848 Set_Entity (N, Val);
24849 end Set_Entity_With_Checks;
24850
24851 ------------------------------
24852 -- Set_Invalid_Scalar_Value --
24853 ------------------------------
24854
24855 procedure Set_Invalid_Scalar_Value
24856 (Scal_Typ : Float_Scalar_Id;
24857 Value : Ureal)
24858 is
24859 Slot : Ureal renames Invalid_Floats (Scal_Typ);
24860
24861 begin
24862 -- Detect an attempt to set a different value for the same scalar type
24863
24864 pragma Assert (Slot = No_Ureal);
24865 Slot := Value;
24866 end Set_Invalid_Scalar_Value;
24867
24868 ------------------------------
24869 -- Set_Invalid_Scalar_Value --
24870 ------------------------------
24871
24872 procedure Set_Invalid_Scalar_Value
24873 (Scal_Typ : Integer_Scalar_Id;
24874 Value : Uint)
24875 is
24876 Slot : Uint renames Invalid_Integers (Scal_Typ);
24877
24878 begin
24879 -- Detect an attempt to set a different value for the same scalar type
24880
24881 pragma Assert (Slot = No_Uint);
24882 Slot := Value;
24883 end Set_Invalid_Scalar_Value;
24884
24885 ------------------------
24886 -- Set_Name_Entity_Id --
24887 ------------------------
24888
24889 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
24890 begin
24891 Set_Name_Table_Int (Id, Int (Val));
24892 end Set_Name_Entity_Id;
24893
24894 ---------------------
24895 -- Set_Next_Actual --
24896 ---------------------
24897
24898 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
24899 begin
24900 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
24901 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
24902 end if;
24903 end Set_Next_Actual;
24904
24905 ----------------------------------
24906 -- Set_Optimize_Alignment_Flags --
24907 ----------------------------------
24908
24909 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
24910 begin
24911 if Optimize_Alignment = 'S' then
24912 Set_Optimize_Alignment_Space (E);
24913 elsif Optimize_Alignment = 'T' then
24914 Set_Optimize_Alignment_Time (E);
24915 end if;
24916 end Set_Optimize_Alignment_Flags;
24917
24918 -----------------------
24919 -- Set_Public_Status --
24920 -----------------------
24921
24922 procedure Set_Public_Status (Id : Entity_Id) is
24923 S : constant Entity_Id := Current_Scope;
24924
24925 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
24926 -- Determines if E is defined within handled statement sequence or
24927 -- an if statement, returns True if so, False otherwise.
24928
24929 ----------------------
24930 -- Within_HSS_Or_If --
24931 ----------------------
24932
24933 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
24934 N : Node_Id;
24935 begin
24936 N := Declaration_Node (E);
24937 loop
24938 N := Parent (N);
24939
24940 if No (N) then
24941 return False;
24942
24943 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
24944 N_If_Statement)
24945 then
24946 return True;
24947 end if;
24948 end loop;
24949 end Within_HSS_Or_If;
24950
24951 -- Start of processing for Set_Public_Status
24952
24953 begin
24954 -- Everything in the scope of Standard is public
24955
24956 if S = Standard_Standard then
24957 Set_Is_Public (Id);
24958
24959 -- Entity is definitely not public if enclosing scope is not public
24960
24961 elsif not Is_Public (S) then
24962 return;
24963
24964 -- An object or function declaration that occurs in a handled sequence
24965 -- of statements or within an if statement is the declaration for a
24966 -- temporary object or local subprogram generated by the expander. It
24967 -- never needs to be made public and furthermore, making it public can
24968 -- cause back end problems.
24969
24970 elsif Nkind_In (Parent (Id), N_Object_Declaration,
24971 N_Function_Specification)
24972 and then Within_HSS_Or_If (Id)
24973 then
24974 return;
24975
24976 -- Entities in public packages or records are public
24977
24978 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
24979 Set_Is_Public (Id);
24980
24981 -- The bounds of an entry family declaration can generate object
24982 -- declarations that are visible to the back-end, e.g. in the
24983 -- the declaration of a composite type that contains tasks.
24984
24985 elsif Is_Concurrent_Type (S)
24986 and then not Has_Completion (S)
24987 and then Nkind (Parent (Id)) = N_Object_Declaration
24988 then
24989 Set_Is_Public (Id);
24990 end if;
24991 end Set_Public_Status;
24992
24993 -----------------------------
24994 -- Set_Referenced_Modified --
24995 -----------------------------
24996
24997 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
24998 Pref : Node_Id;
24999
25000 begin
25001 -- Deal with indexed or selected component where prefix is modified
25002
25003 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
25004 Pref := Prefix (N);
25005
25006 -- If prefix is access type, then it is the designated object that is
25007 -- being modified, which means we have no entity to set the flag on.
25008
25009 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
25010 return;
25011
25012 -- Otherwise chase the prefix
25013
25014 else
25015 Set_Referenced_Modified (Pref, Out_Param);
25016 end if;
25017
25018 -- Otherwise see if we have an entity name (only other case to process)
25019
25020 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
25021 Set_Referenced_As_LHS (Entity (N), not Out_Param);
25022 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
25023 end if;
25024 end Set_Referenced_Modified;
25025
25026 ------------------
25027 -- Set_Rep_Info --
25028 ------------------
25029
25030 procedure Set_Rep_Info (T1 : Entity_Id; T2 : Entity_Id) is
25031 begin
25032 Set_Is_Atomic (T1, Is_Atomic (T2));
25033 Set_Is_Independent (T1, Is_Independent (T2));
25034 Set_Is_Volatile_Full_Access (T1, Is_Volatile_Full_Access (T2));
25035
25036 if Is_Base_Type (T1) then
25037 Set_Is_Volatile (T1, Is_Volatile (T2));
25038 end if;
25039 end Set_Rep_Info;
25040
25041 ----------------------------
25042 -- Set_Scope_Is_Transient --
25043 ----------------------------
25044
25045 procedure Set_Scope_Is_Transient (V : Boolean := True) is
25046 begin
25047 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
25048 end Set_Scope_Is_Transient;
25049
25050 -------------------
25051 -- Set_Size_Info --
25052 -------------------
25053
25054 procedure Set_Size_Info (T1, T2 : Entity_Id) is
25055 begin
25056 -- We copy Esize, but not RM_Size, since in general RM_Size is
25057 -- subtype specific and does not get inherited by all subtypes.
25058
25059 Set_Esize (T1, Esize (T2));
25060 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
25061
25062 if Is_Discrete_Or_Fixed_Point_Type (T1)
25063 and then
25064 Is_Discrete_Or_Fixed_Point_Type (T2)
25065 then
25066 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
25067 end if;
25068
25069 Set_Alignment (T1, Alignment (T2));
25070 end Set_Size_Info;
25071
25072 ------------------------------
25073 -- Should_Ignore_Pragma_Par --
25074 ------------------------------
25075
25076 function Should_Ignore_Pragma_Par (Prag_Name : Name_Id) return Boolean is
25077 pragma Assert (Compiler_State = Parsing);
25078 -- This one can't work during semantic analysis, because we don't have a
25079 -- correct Current_Source_File.
25080
25081 Result : constant Boolean :=
25082 Get_Name_Table_Boolean3 (Prag_Name)
25083 and then not Is_Internal_File_Name
25084 (File_Name (Current_Source_File));
25085 begin
25086 return Result;
25087 end Should_Ignore_Pragma_Par;
25088
25089 ------------------------------
25090 -- Should_Ignore_Pragma_Sem --
25091 ------------------------------
25092
25093 function Should_Ignore_Pragma_Sem (N : Node_Id) return Boolean is
25094 pragma Assert (Compiler_State = Analyzing);
25095 Prag_Name : constant Name_Id := Pragma_Name (N);
25096 Result : constant Boolean :=
25097 Get_Name_Table_Boolean3 (Prag_Name)
25098 and then not In_Internal_Unit (N);
25099
25100 begin
25101 return Result;
25102 end Should_Ignore_Pragma_Sem;
25103
25104 --------------------
25105 -- Static_Boolean --
25106 --------------------
25107
25108 function Static_Boolean (N : Node_Id) return Uint is
25109 begin
25110 Analyze_And_Resolve (N, Standard_Boolean);
25111
25112 if N = Error
25113 or else Error_Posted (N)
25114 or else Etype (N) = Any_Type
25115 then
25116 return No_Uint;
25117 end if;
25118
25119 if Is_OK_Static_Expression (N) then
25120 if not Raises_Constraint_Error (N) then
25121 return Expr_Value (N);
25122 else
25123 return No_Uint;
25124 end if;
25125
25126 elsif Etype (N) = Any_Type then
25127 return No_Uint;
25128
25129 else
25130 Flag_Non_Static_Expr
25131 ("static boolean expression required here", N);
25132 return No_Uint;
25133 end if;
25134 end Static_Boolean;
25135
25136 --------------------
25137 -- Static_Integer --
25138 --------------------
25139
25140 function Static_Integer (N : Node_Id) return Uint is
25141 begin
25142 Analyze_And_Resolve (N, Any_Integer);
25143
25144 if N = Error
25145 or else Error_Posted (N)
25146 or else Etype (N) = Any_Type
25147 then
25148 return No_Uint;
25149 end if;
25150
25151 if Is_OK_Static_Expression (N) then
25152 if not Raises_Constraint_Error (N) then
25153 return Expr_Value (N);
25154 else
25155 return No_Uint;
25156 end if;
25157
25158 elsif Etype (N) = Any_Type then
25159 return No_Uint;
25160
25161 else
25162 Flag_Non_Static_Expr
25163 ("static integer expression required here", N);
25164 return No_Uint;
25165 end if;
25166 end Static_Integer;
25167
25168 --------------------------
25169 -- Statically_Different --
25170 --------------------------
25171
25172 function Statically_Different (E1, E2 : Node_Id) return Boolean is
25173 R1 : constant Node_Id := Get_Referenced_Object (E1);
25174 R2 : constant Node_Id := Get_Referenced_Object (E2);
25175 begin
25176 return Is_Entity_Name (R1)
25177 and then Is_Entity_Name (R2)
25178 and then Entity (R1) /= Entity (R2)
25179 and then not Is_Formal (Entity (R1))
25180 and then not Is_Formal (Entity (R2));
25181 end Statically_Different;
25182
25183 --------------------------------------
25184 -- Subject_To_Loop_Entry_Attributes --
25185 --------------------------------------
25186
25187 function Subject_To_Loop_Entry_Attributes (N : Node_Id) return Boolean is
25188 Stmt : Node_Id;
25189
25190 begin
25191 Stmt := N;
25192
25193 -- The expansion mechanism transform a loop subject to at least one
25194 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
25195 -- the conditional part.
25196
25197 if Nkind_In (Stmt, N_Block_Statement, N_If_Statement)
25198 and then Nkind (Original_Node (N)) = N_Loop_Statement
25199 then
25200 Stmt := Original_Node (N);
25201 end if;
25202
25203 return
25204 Nkind (Stmt) = N_Loop_Statement
25205 and then Present (Identifier (Stmt))
25206 and then Present (Entity (Identifier (Stmt)))
25207 and then Has_Loop_Entry_Attributes (Entity (Identifier (Stmt)));
25208 end Subject_To_Loop_Entry_Attributes;
25209
25210 -----------------------------
25211 -- Subprogram_Access_Level --
25212 -----------------------------
25213
25214 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
25215 begin
25216 if Present (Alias (Subp)) then
25217 return Subprogram_Access_Level (Alias (Subp));
25218 else
25219 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
25220 end if;
25221 end Subprogram_Access_Level;
25222
25223 ---------------------
25224 -- Subprogram_Name --
25225 ---------------------
25226
25227 function Subprogram_Name (N : Node_Id) return String is
25228 Buf : Bounded_String;
25229 Ent : Node_Id := N;
25230 Nod : Node_Id;
25231
25232 begin
25233 while Present (Ent) loop
25234 case Nkind (Ent) is
25235 when N_Subprogram_Body =>
25236 Ent := Defining_Unit_Name (Specification (Ent));
25237 exit;
25238
25239 when N_Subprogram_Declaration =>
25240 Nod := Corresponding_Body (Ent);
25241
25242 if Present (Nod) then
25243 Ent := Nod;
25244 else
25245 Ent := Defining_Unit_Name (Specification (Ent));
25246 end if;
25247
25248 exit;
25249
25250 when N_Subprogram_Instantiation
25251 | N_Package_Body
25252 | N_Package_Specification
25253 =>
25254 Ent := Defining_Unit_Name (Ent);
25255 exit;
25256
25257 when N_Protected_Type_Declaration =>
25258 Ent := Corresponding_Body (Ent);
25259 exit;
25260
25261 when N_Protected_Body
25262 | N_Task_Body
25263 =>
25264 Ent := Defining_Identifier (Ent);
25265 exit;
25266
25267 when others =>
25268 null;
25269 end case;
25270
25271 Ent := Parent (Ent);
25272 end loop;
25273
25274 if No (Ent) then
25275 return "unknown subprogram:unknown file:0:0";
25276 end if;
25277
25278 -- If the subprogram is a child unit, use its simple name to start the
25279 -- construction of the fully qualified name.
25280
25281 if Nkind (Ent) = N_Defining_Program_Unit_Name then
25282 Ent := Defining_Identifier (Ent);
25283 end if;
25284
25285 Append_Entity_Name (Buf, Ent);
25286
25287 -- Append homonym number if needed
25288
25289 if Nkind (N) in N_Entity and then Has_Homonym (N) then
25290 declare
25291 H : Entity_Id := Homonym (N);
25292 Nr : Nat := 1;
25293
25294 begin
25295 while Present (H) loop
25296 if Scope (H) = Scope (N) then
25297 Nr := Nr + 1;
25298 end if;
25299
25300 H := Homonym (H);
25301 end loop;
25302
25303 if Nr > 1 then
25304 Append (Buf, '#');
25305 Append (Buf, Nr);
25306 end if;
25307 end;
25308 end if;
25309
25310 -- Append source location of Ent to Buf so that the string will
25311 -- look like "subp:file:line:col".
25312
25313 declare
25314 Loc : constant Source_Ptr := Sloc (Ent);
25315 begin
25316 Append (Buf, ':');
25317 Append (Buf, Reference_Name (Get_Source_File_Index (Loc)));
25318 Append (Buf, ':');
25319 Append (Buf, Nat (Get_Logical_Line_Number (Loc)));
25320 Append (Buf, ':');
25321 Append (Buf, Nat (Get_Column_Number (Loc)));
25322 end;
25323
25324 return +Buf;
25325 end Subprogram_Name;
25326
25327 -------------------------------
25328 -- Support_Atomic_Primitives --
25329 -------------------------------
25330
25331 function Support_Atomic_Primitives (Typ : Entity_Id) return Boolean is
25332 Size : Int;
25333
25334 begin
25335 -- Verify the alignment of Typ is known
25336
25337 if not Known_Alignment (Typ) then
25338 return False;
25339 end if;
25340
25341 if Known_Static_Esize (Typ) then
25342 Size := UI_To_Int (Esize (Typ));
25343
25344 -- If the Esize (Object_Size) is unknown at compile time, look at the
25345 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
25346
25347 elsif Known_Static_RM_Size (Typ) then
25348 Size := UI_To_Int (RM_Size (Typ));
25349
25350 -- Otherwise, the size is considered to be unknown.
25351
25352 else
25353 return False;
25354 end if;
25355
25356 -- Check that the size of the component is 8, 16, 32, or 64 bits and
25357 -- that Typ is properly aligned.
25358
25359 case Size is
25360 when 8 | 16 | 32 | 64 =>
25361 return Size = UI_To_Int (Alignment (Typ)) * 8;
25362
25363 when others =>
25364 return False;
25365 end case;
25366 end Support_Atomic_Primitives;
25367
25368 -----------------
25369 -- Trace_Scope --
25370 -----------------
25371
25372 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
25373 begin
25374 if Debug_Flag_W then
25375 for J in 0 .. Scope_Stack.Last loop
25376 Write_Str (" ");
25377 end loop;
25378
25379 Write_Str (Msg);
25380 Write_Name (Chars (E));
25381 Write_Str (" from ");
25382 Write_Location (Sloc (N));
25383 Write_Eol;
25384 end if;
25385 end Trace_Scope;
25386
25387 -----------------------
25388 -- Transfer_Entities --
25389 -----------------------
25390
25391 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
25392 procedure Set_Public_Status_Of (Id : Entity_Id);
25393 -- Set the Is_Public attribute of arbitrary entity Id by calling routine
25394 -- Set_Public_Status. If successful and Id denotes a record type, set
25395 -- the Is_Public attribute of its fields.
25396
25397 --------------------------
25398 -- Set_Public_Status_Of --
25399 --------------------------
25400
25401 procedure Set_Public_Status_Of (Id : Entity_Id) is
25402 Field : Entity_Id;
25403
25404 begin
25405 if not Is_Public (Id) then
25406 Set_Public_Status (Id);
25407
25408 -- When the input entity is a public record type, ensure that all
25409 -- its internal fields are also exposed to the linker. The fields
25410 -- of a class-wide type are never made public.
25411
25412 if Is_Public (Id)
25413 and then Is_Record_Type (Id)
25414 and then not Is_Class_Wide_Type (Id)
25415 then
25416 Field := First_Entity (Id);
25417 while Present (Field) loop
25418 Set_Is_Public (Field);
25419 Next_Entity (Field);
25420 end loop;
25421 end if;
25422 end if;
25423 end Set_Public_Status_Of;
25424
25425 -- Local variables
25426
25427 Full_Id : Entity_Id;
25428 Id : Entity_Id;
25429
25430 -- Start of processing for Transfer_Entities
25431
25432 begin
25433 Id := First_Entity (From);
25434
25435 if Present (Id) then
25436
25437 -- Merge the entity chain of the source scope with that of the
25438 -- destination scope.
25439
25440 if Present (Last_Entity (To)) then
25441 Link_Entities (Last_Entity (To), Id);
25442 else
25443 Set_First_Entity (To, Id);
25444 end if;
25445
25446 Set_Last_Entity (To, Last_Entity (From));
25447
25448 -- Inspect the entities of the source scope and update their Scope
25449 -- attribute.
25450
25451 while Present (Id) loop
25452 Set_Scope (Id, To);
25453 Set_Public_Status_Of (Id);
25454
25455 -- Handle an internally generated full view for a private type
25456
25457 if Is_Private_Type (Id)
25458 and then Present (Full_View (Id))
25459 and then Is_Itype (Full_View (Id))
25460 then
25461 Full_Id := Full_View (Id);
25462
25463 Set_Scope (Full_Id, To);
25464 Set_Public_Status_Of (Full_Id);
25465 end if;
25466
25467 Next_Entity (Id);
25468 end loop;
25469
25470 Set_First_Entity (From, Empty);
25471 Set_Last_Entity (From, Empty);
25472 end if;
25473 end Transfer_Entities;
25474
25475 ------------------------
25476 -- Traverse_More_Func --
25477 ------------------------
25478
25479 function Traverse_More_Func (Node : Node_Id) return Traverse_Final_Result is
25480
25481 Processing_Itype : Boolean := False;
25482 -- Set to True while traversing the nodes under an Itype, to prevent
25483 -- looping on Itype handling during that traversal.
25484
25485 function Process_More (N : Node_Id) return Traverse_Result;
25486 -- Wrapper over the Process callback to handle parts of the AST that
25487 -- are not normally traversed as syntactic children.
25488
25489 function Traverse_Rec (N : Node_Id) return Traverse_Final_Result;
25490 -- Main recursive traversal implemented as an instantiation of
25491 -- Traverse_Func over a modified Process callback.
25492
25493 ------------------
25494 -- Process_More --
25495 ------------------
25496
25497 function Process_More (N : Node_Id) return Traverse_Result is
25498
25499 procedure Traverse_More (N : Node_Id;
25500 Res : in out Traverse_Result);
25501 procedure Traverse_More (L : List_Id;
25502 Res : in out Traverse_Result);
25503 -- Traverse a node or list and update the traversal result to value
25504 -- Abandon when needed.
25505
25506 -------------------
25507 -- Traverse_More --
25508 -------------------
25509
25510 procedure Traverse_More (N : Node_Id;
25511 Res : in out Traverse_Result)
25512 is
25513 begin
25514 -- Do not process any more nodes if Abandon was reached
25515
25516 if Res = Abandon then
25517 return;
25518 end if;
25519
25520 if Traverse_Rec (N) = Abandon then
25521 Res := Abandon;
25522 end if;
25523 end Traverse_More;
25524
25525 procedure Traverse_More (L : List_Id;
25526 Res : in out Traverse_Result)
25527 is
25528 N : Node_Id := First (L);
25529
25530 begin
25531 -- Do not process any more nodes if Abandon was reached
25532
25533 if Res = Abandon then
25534 return;
25535 end if;
25536
25537 while Present (N) loop
25538 Traverse_More (N, Res);
25539 Next (N);
25540 end loop;
25541 end Traverse_More;
25542
25543 -- Local variables
25544
25545 Node : Node_Id;
25546 Result : Traverse_Result;
25547
25548 -- Start of processing for Process_More
25549
25550 begin
25551 -- Initial callback to Process. Return immediately on Skip/Abandon.
25552 -- Otherwise update the value of Node for further processing of
25553 -- non-syntactic children.
25554
25555 Result := Process (N);
25556
25557 case Result is
25558 when OK => Node := N;
25559 when OK_Orig => Node := Original_Node (N);
25560 when Skip => return Skip;
25561 when Abandon => return Abandon;
25562 end case;
25563
25564 -- Process the relevant semantic children which are a logical part of
25565 -- the AST under this node before returning for the processing of
25566 -- syntactic children.
25567
25568 -- Start with all non-syntactic lists of action nodes
25569
25570 case Nkind (Node) is
25571 when N_Component_Association =>
25572 Traverse_More (Loop_Actions (Node), Result);
25573
25574 when N_Elsif_Part =>
25575 Traverse_More (Condition_Actions (Node), Result);
25576
25577 when N_Short_Circuit =>
25578 Traverse_More (Actions (Node), Result);
25579
25580 when N_Case_Expression_Alternative =>
25581 Traverse_More (Actions (Node), Result);
25582
25583 when N_Iteration_Scheme =>
25584 Traverse_More (Condition_Actions (Node), Result);
25585
25586 when N_If_Expression =>
25587 Traverse_More (Then_Actions (Node), Result);
25588 Traverse_More (Else_Actions (Node), Result);
25589
25590 -- Various nodes have a field Actions as a syntactic node,
25591 -- so it will be traversed in the regular syntactic traversal.
25592
25593 when N_Compilation_Unit_Aux
25594 | N_Compound_Statement
25595 | N_Expression_With_Actions
25596 | N_Freeze_Entity
25597 =>
25598 null;
25599
25600 when others =>
25601 null;
25602 end case;
25603
25604 -- If Process_Itypes is True, process unattached nodes which come
25605 -- from Itypes. This only concerns currently ranges of scalar
25606 -- (possibly as index) types. This traversal is protected against
25607 -- looping with Processing_Itype.
25608
25609 if Process_Itypes
25610 and then not Processing_Itype
25611 and then Nkind (Node) in N_Has_Etype
25612 and then Present (Etype (Node))
25613 and then Is_Itype (Etype (Node))
25614 then
25615 declare
25616 Typ : constant Entity_Id := Etype (Node);
25617 begin
25618 Processing_Itype := True;
25619
25620 case Ekind (Typ) is
25621 when Scalar_Kind =>
25622 Traverse_More (Scalar_Range (Typ), Result);
25623
25624 when Array_Kind =>
25625 declare
25626 Index : Node_Id := First_Index (Typ);
25627 Rng : Node_Id;
25628 begin
25629 while Present (Index) loop
25630 if Nkind (Index) in N_Has_Entity then
25631 Rng := Scalar_Range (Entity (Index));
25632 else
25633 Rng := Index;
25634 end if;
25635
25636 Traverse_More (Rng, Result);
25637 Next_Index (Index);
25638 end loop;
25639 end;
25640 when others =>
25641 null;
25642 end case;
25643
25644 Processing_Itype := False;
25645 end;
25646 end if;
25647
25648 return Result;
25649 end Process_More;
25650
25651 -- Define Traverse_Rec as a renaming of the instantiation, as an
25652 -- instantiation cannot complete a previous spec.
25653
25654 function Traverse_Recursive is new Traverse_Func (Process_More);
25655 function Traverse_Rec (N : Node_Id) return Traverse_Final_Result
25656 renames Traverse_Recursive;
25657
25658 -- Start of processing for Traverse_More_Func
25659
25660 begin
25661 return Traverse_Rec (Node);
25662 end Traverse_More_Func;
25663
25664 ------------------------
25665 -- Traverse_More_Proc --
25666 ------------------------
25667
25668 procedure Traverse_More_Proc (Node : Node_Id) is
25669 function Traverse is new Traverse_More_Func (Process, Process_Itypes);
25670 Discard : Traverse_Final_Result;
25671 pragma Warnings (Off, Discard);
25672 begin
25673 Discard := Traverse (Node);
25674 end Traverse_More_Proc;
25675
25676 -----------------------
25677 -- Type_Access_Level --
25678 -----------------------
25679
25680 function Type_Access_Level (Typ : Entity_Id) return Uint is
25681 Btyp : Entity_Id;
25682
25683 begin
25684 Btyp := Base_Type (Typ);
25685
25686 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
25687 -- simply use the level where the type is declared. This is true for
25688 -- stand-alone object declarations, and for anonymous access types
25689 -- associated with components the level is the same as that of the
25690 -- enclosing composite type. However, special treatment is needed for
25691 -- the cases of access parameters, return objects of an anonymous access
25692 -- type, and, in Ada 95, access discriminants of limited types.
25693
25694 if Is_Access_Type (Btyp) then
25695 if Ekind (Btyp) = E_Anonymous_Access_Type then
25696
25697 -- If the type is a nonlocal anonymous access type (such as for
25698 -- an access parameter) we treat it as being declared at the
25699 -- library level to ensure that names such as X.all'access don't
25700 -- fail static accessibility checks.
25701
25702 if not Is_Local_Anonymous_Access (Typ) then
25703 return Scope_Depth (Standard_Standard);
25704
25705 -- If this is a return object, the accessibility level is that of
25706 -- the result subtype of the enclosing function. The test here is
25707 -- little complicated, because we have to account for extended
25708 -- return statements that have been rewritten as blocks, in which
25709 -- case we have to find and the Is_Return_Object attribute of the
25710 -- itype's associated object. It would be nice to find a way to
25711 -- simplify this test, but it doesn't seem worthwhile to add a new
25712 -- flag just for purposes of this test. ???
25713
25714 elsif Ekind (Scope (Btyp)) = E_Return_Statement
25715 or else
25716 (Is_Itype (Btyp)
25717 and then Nkind (Associated_Node_For_Itype (Btyp)) =
25718 N_Object_Declaration
25719 and then Is_Return_Object
25720 (Defining_Identifier
25721 (Associated_Node_For_Itype (Btyp))))
25722 then
25723 declare
25724 Scop : Entity_Id;
25725
25726 begin
25727 Scop := Scope (Scope (Btyp));
25728 while Present (Scop) loop
25729 exit when Ekind (Scop) = E_Function;
25730 Scop := Scope (Scop);
25731 end loop;
25732
25733 -- Treat the return object's type as having the level of the
25734 -- function's result subtype (as per RM05-6.5(5.3/2)).
25735
25736 return Type_Access_Level (Etype (Scop));
25737 end;
25738 end if;
25739 end if;
25740
25741 Btyp := Root_Type (Btyp);
25742
25743 -- The accessibility level of anonymous access types associated with
25744 -- discriminants is that of the current instance of the type, and
25745 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
25746
25747 -- AI-402: access discriminants have accessibility based on the
25748 -- object rather than the type in Ada 2005, so the above paragraph
25749 -- doesn't apply.
25750
25751 -- ??? Needs completion with rules from AI-416
25752
25753 if Ada_Version <= Ada_95
25754 and then Ekind (Typ) = E_Anonymous_Access_Type
25755 and then Present (Associated_Node_For_Itype (Typ))
25756 and then Nkind (Associated_Node_For_Itype (Typ)) =
25757 N_Discriminant_Specification
25758 then
25759 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
25760 end if;
25761 end if;
25762
25763 -- Return library level for a generic formal type. This is done because
25764 -- RM(10.3.2) says that "The statically deeper relationship does not
25765 -- apply to ... a descendant of a generic formal type". Rather than
25766 -- checking at each point where a static accessibility check is
25767 -- performed to see if we are dealing with a formal type, this rule is
25768 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
25769 -- return extreme values for a formal type; Deepest_Type_Access_Level
25770 -- returns Int'Last. By calling the appropriate function from among the
25771 -- two, we ensure that the static accessibility check will pass if we
25772 -- happen to run into a formal type. More specifically, we should call
25773 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
25774 -- call occurs as part of a static accessibility check and the error
25775 -- case is the case where the type's level is too shallow (as opposed
25776 -- to too deep).
25777
25778 if Is_Generic_Type (Root_Type (Btyp)) then
25779 return Scope_Depth (Standard_Standard);
25780 end if;
25781
25782 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
25783 end Type_Access_Level;
25784
25785 ------------------------------------
25786 -- Type_Without_Stream_Operation --
25787 ------------------------------------
25788
25789 function Type_Without_Stream_Operation
25790 (T : Entity_Id;
25791 Op : TSS_Name_Type := TSS_Null) return Entity_Id
25792 is
25793 BT : constant Entity_Id := Base_Type (T);
25794 Op_Missing : Boolean;
25795
25796 begin
25797 if not Restriction_Active (No_Default_Stream_Attributes) then
25798 return Empty;
25799 end if;
25800
25801 if Is_Elementary_Type (T) then
25802 if Op = TSS_Null then
25803 Op_Missing :=
25804 No (TSS (BT, TSS_Stream_Read))
25805 or else No (TSS (BT, TSS_Stream_Write));
25806
25807 else
25808 Op_Missing := No (TSS (BT, Op));
25809 end if;
25810
25811 if Op_Missing then
25812 return T;
25813 else
25814 return Empty;
25815 end if;
25816
25817 elsif Is_Array_Type (T) then
25818 return Type_Without_Stream_Operation (Component_Type (T), Op);
25819
25820 elsif Is_Record_Type (T) then
25821 declare
25822 Comp : Entity_Id;
25823 C_Typ : Entity_Id;
25824
25825 begin
25826 Comp := First_Component (T);
25827 while Present (Comp) loop
25828 C_Typ := Type_Without_Stream_Operation (Etype (Comp), Op);
25829
25830 if Present (C_Typ) then
25831 return C_Typ;
25832 end if;
25833
25834 Next_Component (Comp);
25835 end loop;
25836
25837 return Empty;
25838 end;
25839
25840 elsif Is_Private_Type (T) and then Present (Full_View (T)) then
25841 return Type_Without_Stream_Operation (Full_View (T), Op);
25842 else
25843 return Empty;
25844 end if;
25845 end Type_Without_Stream_Operation;
25846
25847 ---------------------
25848 -- Ultimate_Prefix --
25849 ---------------------
25850
25851 function Ultimate_Prefix (N : Node_Id) return Node_Id is
25852 Pref : Node_Id;
25853
25854 begin
25855 Pref := N;
25856 while Nkind_In (Pref, N_Explicit_Dereference,
25857 N_Indexed_Component,
25858 N_Selected_Component,
25859 N_Slice)
25860 loop
25861 Pref := Prefix (Pref);
25862 end loop;
25863
25864 return Pref;
25865 end Ultimate_Prefix;
25866
25867 ----------------------------
25868 -- Unique_Defining_Entity --
25869 ----------------------------
25870
25871 function Unique_Defining_Entity (N : Node_Id) return Entity_Id is
25872 begin
25873 return Unique_Entity (Defining_Entity (N));
25874 end Unique_Defining_Entity;
25875
25876 -------------------
25877 -- Unique_Entity --
25878 -------------------
25879
25880 function Unique_Entity (E : Entity_Id) return Entity_Id is
25881 U : Entity_Id := E;
25882 P : Node_Id;
25883
25884 begin
25885 case Ekind (E) is
25886 when E_Constant =>
25887 if Present (Full_View (E)) then
25888 U := Full_View (E);
25889 end if;
25890
25891 when Entry_Kind =>
25892 if Nkind (Parent (E)) = N_Entry_Body then
25893 declare
25894 Prot_Item : Entity_Id;
25895 Prot_Type : Entity_Id;
25896
25897 begin
25898 if Ekind (E) = E_Entry then
25899 Prot_Type := Scope (E);
25900
25901 -- Bodies of entry families are nested within an extra scope
25902 -- that contains an entry index declaration.
25903
25904 else
25905 Prot_Type := Scope (Scope (E));
25906 end if;
25907
25908 -- A protected type may be declared as a private type, in
25909 -- which case we need to get its full view.
25910
25911 if Is_Private_Type (Prot_Type) then
25912 Prot_Type := Full_View (Prot_Type);
25913 end if;
25914
25915 -- Full view may not be present on error, in which case
25916 -- return E by default.
25917
25918 if Present (Prot_Type) then
25919 pragma Assert (Ekind (Prot_Type) = E_Protected_Type);
25920
25921 -- Traverse the entity list of the protected type and
25922 -- locate an entry declaration which matches the entry
25923 -- body.
25924
25925 Prot_Item := First_Entity (Prot_Type);
25926 while Present (Prot_Item) loop
25927 if Ekind (Prot_Item) in Entry_Kind
25928 and then Corresponding_Body (Parent (Prot_Item)) = E
25929 then
25930 U := Prot_Item;
25931 exit;
25932 end if;
25933
25934 Next_Entity (Prot_Item);
25935 end loop;
25936 end if;
25937 end;
25938 end if;
25939
25940 when Formal_Kind =>
25941 if Present (Spec_Entity (E)) then
25942 U := Spec_Entity (E);
25943 end if;
25944
25945 when E_Package_Body =>
25946 P := Parent (E);
25947
25948 if Nkind (P) = N_Defining_Program_Unit_Name then
25949 P := Parent (P);
25950 end if;
25951
25952 if Nkind (P) = N_Package_Body
25953 and then Present (Corresponding_Spec (P))
25954 then
25955 U := Corresponding_Spec (P);
25956
25957 elsif Nkind (P) = N_Package_Body_Stub
25958 and then Present (Corresponding_Spec_Of_Stub (P))
25959 then
25960 U := Corresponding_Spec_Of_Stub (P);
25961 end if;
25962
25963 when E_Protected_Body =>
25964 P := Parent (E);
25965
25966 if Nkind (P) = N_Protected_Body
25967 and then Present (Corresponding_Spec (P))
25968 then
25969 U := Corresponding_Spec (P);
25970
25971 elsif Nkind (P) = N_Protected_Body_Stub
25972 and then Present (Corresponding_Spec_Of_Stub (P))
25973 then
25974 U := Corresponding_Spec_Of_Stub (P);
25975
25976 if Is_Single_Protected_Object (U) then
25977 U := Etype (U);
25978 end if;
25979 end if;
25980
25981 if Is_Private_Type (U) then
25982 U := Full_View (U);
25983 end if;
25984
25985 when E_Subprogram_Body =>
25986 P := Parent (E);
25987
25988 if Nkind (P) = N_Defining_Program_Unit_Name then
25989 P := Parent (P);
25990 end if;
25991
25992 P := Parent (P);
25993
25994 if Nkind (P) = N_Subprogram_Body
25995 and then Present (Corresponding_Spec (P))
25996 then
25997 U := Corresponding_Spec (P);
25998
25999 elsif Nkind (P) = N_Subprogram_Body_Stub
26000 and then Present (Corresponding_Spec_Of_Stub (P))
26001 then
26002 U := Corresponding_Spec_Of_Stub (P);
26003
26004 elsif Nkind (P) = N_Subprogram_Renaming_Declaration then
26005 U := Corresponding_Spec (P);
26006 end if;
26007
26008 when E_Task_Body =>
26009 P := Parent (E);
26010
26011 if Nkind (P) = N_Task_Body
26012 and then Present (Corresponding_Spec (P))
26013 then
26014 U := Corresponding_Spec (P);
26015
26016 elsif Nkind (P) = N_Task_Body_Stub
26017 and then Present (Corresponding_Spec_Of_Stub (P))
26018 then
26019 U := Corresponding_Spec_Of_Stub (P);
26020
26021 if Is_Single_Task_Object (U) then
26022 U := Etype (U);
26023 end if;
26024 end if;
26025
26026 if Is_Private_Type (U) then
26027 U := Full_View (U);
26028 end if;
26029
26030 when Type_Kind =>
26031 if Present (Full_View (E)) then
26032 U := Full_View (E);
26033 end if;
26034
26035 when others =>
26036 null;
26037 end case;
26038
26039 return U;
26040 end Unique_Entity;
26041
26042 -----------------
26043 -- Unique_Name --
26044 -----------------
26045
26046 function Unique_Name (E : Entity_Id) return String is
26047
26048 -- Names in E_Subprogram_Body or E_Package_Body entities are not
26049 -- reliable, as they may not include the overloading suffix. Instead,
26050 -- when looking for the name of E or one of its enclosing scope, we get
26051 -- the name of the corresponding Unique_Entity.
26052
26053 U : constant Entity_Id := Unique_Entity (E);
26054
26055 function This_Name return String;
26056
26057 ---------------
26058 -- This_Name --
26059 ---------------
26060
26061 function This_Name return String is
26062 begin
26063 return Get_Name_String (Chars (U));
26064 end This_Name;
26065
26066 -- Start of processing for Unique_Name
26067
26068 begin
26069 if E = Standard_Standard
26070 or else Has_Fully_Qualified_Name (E)
26071 then
26072 return This_Name;
26073
26074 elsif Ekind (E) = E_Enumeration_Literal then
26075 return Unique_Name (Etype (E)) & "__" & This_Name;
26076
26077 else
26078 declare
26079 S : constant Entity_Id := Scope (U);
26080 pragma Assert (Present (S));
26081
26082 begin
26083 -- Prefix names of predefined types with standard__, but leave
26084 -- names of user-defined packages and subprograms without prefix
26085 -- (even if technically they are nested in the Standard package).
26086
26087 if S = Standard_Standard then
26088 if Ekind (U) = E_Package or else Is_Subprogram (U) then
26089 return This_Name;
26090 else
26091 return Unique_Name (S) & "__" & This_Name;
26092 end if;
26093
26094 -- For intances of generic subprograms use the name of the related
26095 -- instace and skip the scope of its wrapper package.
26096
26097 elsif Is_Wrapper_Package (S) then
26098 pragma Assert (Scope (S) = Scope (Related_Instance (S)));
26099 -- Wrapper package and the instantiation are in the same scope
26100
26101 declare
26102 Enclosing_Name : constant String :=
26103 Unique_Name (Scope (S)) & "__" &
26104 Get_Name_String (Chars (Related_Instance (S)));
26105
26106 begin
26107 if Is_Subprogram (U)
26108 and then not Is_Generic_Actual_Subprogram (U)
26109 then
26110 return Enclosing_Name;
26111 else
26112 return Enclosing_Name & "__" & This_Name;
26113 end if;
26114 end;
26115
26116 elsif Is_Child_Unit (U) then
26117 return Child_Prefix & Unique_Name (S) & "__" & This_Name;
26118 else
26119 return Unique_Name (S) & "__" & This_Name;
26120 end if;
26121 end;
26122 end if;
26123 end Unique_Name;
26124
26125 ---------------------
26126 -- Unit_Is_Visible --
26127 ---------------------
26128
26129 function Unit_Is_Visible (U : Entity_Id) return Boolean is
26130 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
26131 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
26132
26133 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
26134 -- For a child unit, check whether unit appears in a with_clause
26135 -- of a parent.
26136
26137 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
26138 -- Scan the context clause of one compilation unit looking for a
26139 -- with_clause for the unit in question.
26140
26141 ----------------------------
26142 -- Unit_In_Parent_Context --
26143 ----------------------------
26144
26145 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
26146 begin
26147 if Unit_In_Context (Par_Unit) then
26148 return True;
26149
26150 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
26151 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
26152
26153 else
26154 return False;
26155 end if;
26156 end Unit_In_Parent_Context;
26157
26158 ---------------------
26159 -- Unit_In_Context --
26160 ---------------------
26161
26162 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
26163 Clause : Node_Id;
26164
26165 begin
26166 Clause := First (Context_Items (Comp_Unit));
26167 while Present (Clause) loop
26168 if Nkind (Clause) = N_With_Clause then
26169 if Library_Unit (Clause) = U then
26170 return True;
26171
26172 -- The with_clause may denote a renaming of the unit we are
26173 -- looking for, eg. Text_IO which renames Ada.Text_IO.
26174
26175 elsif
26176 Renamed_Entity (Entity (Name (Clause))) =
26177 Defining_Entity (Unit (U))
26178 then
26179 return True;
26180 end if;
26181 end if;
26182
26183 Next (Clause);
26184 end loop;
26185
26186 return False;
26187 end Unit_In_Context;
26188
26189 -- Start of processing for Unit_Is_Visible
26190
26191 begin
26192 -- The currrent unit is directly visible
26193
26194 if Curr = U then
26195 return True;
26196
26197 elsif Unit_In_Context (Curr) then
26198 return True;
26199
26200 -- If the current unit is a body, check the context of the spec
26201
26202 elsif Nkind (Unit (Curr)) = N_Package_Body
26203 or else
26204 (Nkind (Unit (Curr)) = N_Subprogram_Body
26205 and then not Acts_As_Spec (Unit (Curr)))
26206 then
26207 if Unit_In_Context (Library_Unit (Curr)) then
26208 return True;
26209 end if;
26210 end if;
26211
26212 -- If the spec is a child unit, examine the parents
26213
26214 if Is_Child_Unit (Curr_Entity) then
26215 if Nkind (Unit (Curr)) in N_Unit_Body then
26216 return
26217 Unit_In_Parent_Context
26218 (Parent_Spec (Unit (Library_Unit (Curr))));
26219 else
26220 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
26221 end if;
26222
26223 else
26224 return False;
26225 end if;
26226 end Unit_Is_Visible;
26227
26228 ------------------------------
26229 -- Universal_Interpretation --
26230 ------------------------------
26231
26232 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
26233 Index : Interp_Index;
26234 It : Interp;
26235
26236 begin
26237 -- The argument may be a formal parameter of an operator or subprogram
26238 -- with multiple interpretations, or else an expression for an actual.
26239
26240 if Nkind (Opnd) = N_Defining_Identifier
26241 or else not Is_Overloaded (Opnd)
26242 then
26243 if Etype (Opnd) = Universal_Integer
26244 or else Etype (Opnd) = Universal_Real
26245 then
26246 return Etype (Opnd);
26247 else
26248 return Empty;
26249 end if;
26250
26251 else
26252 Get_First_Interp (Opnd, Index, It);
26253 while Present (It.Typ) loop
26254 if It.Typ = Universal_Integer
26255 or else It.Typ = Universal_Real
26256 then
26257 return It.Typ;
26258 end if;
26259
26260 Get_Next_Interp (Index, It);
26261 end loop;
26262
26263 return Empty;
26264 end if;
26265 end Universal_Interpretation;
26266
26267 ---------------
26268 -- Unqualify --
26269 ---------------
26270
26271 function Unqualify (Expr : Node_Id) return Node_Id is
26272 begin
26273 -- Recurse to handle unlikely case of multiple levels of qualification
26274
26275 if Nkind (Expr) = N_Qualified_Expression then
26276 return Unqualify (Expression (Expr));
26277
26278 -- Normal case, not a qualified expression
26279
26280 else
26281 return Expr;
26282 end if;
26283 end Unqualify;
26284
26285 -----------------
26286 -- Unqual_Conv --
26287 -----------------
26288
26289 function Unqual_Conv (Expr : Node_Id) return Node_Id is
26290 begin
26291 -- Recurse to handle unlikely case of multiple levels of qualification
26292 -- and/or conversion.
26293
26294 if Nkind_In (Expr, N_Qualified_Expression,
26295 N_Type_Conversion,
26296 N_Unchecked_Type_Conversion)
26297 then
26298 return Unqual_Conv (Expression (Expr));
26299
26300 -- Normal case, not a qualified expression
26301
26302 else
26303 return Expr;
26304 end if;
26305 end Unqual_Conv;
26306
26307 --------------------
26308 -- Validated_View --
26309 --------------------
26310
26311 function Validated_View (Typ : Entity_Id) return Entity_Id is
26312 Continue : Boolean;
26313 Val_Typ : Entity_Id;
26314
26315 begin
26316 Continue := True;
26317 Val_Typ := Base_Type (Typ);
26318
26319 -- Obtain the full view of the input type by stripping away concurrency,
26320 -- derivations, and privacy.
26321
26322 while Continue loop
26323 Continue := False;
26324
26325 if Is_Concurrent_Type (Val_Typ) then
26326 if Present (Corresponding_Record_Type (Val_Typ)) then
26327 Continue := True;
26328 Val_Typ := Corresponding_Record_Type (Val_Typ);
26329 end if;
26330
26331 elsif Is_Derived_Type (Val_Typ) then
26332 Continue := True;
26333 Val_Typ := Etype (Val_Typ);
26334
26335 elsif Is_Private_Type (Val_Typ) then
26336 if Present (Underlying_Full_View (Val_Typ)) then
26337 Continue := True;
26338 Val_Typ := Underlying_Full_View (Val_Typ);
26339
26340 elsif Present (Full_View (Val_Typ)) then
26341 Continue := True;
26342 Val_Typ := Full_View (Val_Typ);
26343 end if;
26344 end if;
26345 end loop;
26346
26347 return Val_Typ;
26348 end Validated_View;
26349
26350 -----------------------
26351 -- Visible_Ancestors --
26352 -----------------------
26353
26354 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
26355 List_1 : Elist_Id;
26356 List_2 : Elist_Id;
26357 Elmt : Elmt_Id;
26358
26359 begin
26360 pragma Assert (Is_Record_Type (Typ) and then Is_Tagged_Type (Typ));
26361
26362 -- Collect all the parents and progenitors of Typ. If the full-view of
26363 -- private parents and progenitors is available then it is used to
26364 -- generate the list of visible ancestors; otherwise their partial
26365 -- view is added to the resulting list.
26366
26367 Collect_Parents
26368 (T => Typ,
26369 List => List_1,
26370 Use_Full_View => True);
26371
26372 Collect_Interfaces
26373 (T => Typ,
26374 Ifaces_List => List_2,
26375 Exclude_Parents => True,
26376 Use_Full_View => True);
26377
26378 -- Join the two lists. Avoid duplications because an interface may
26379 -- simultaneously be parent and progenitor of a type.
26380
26381 Elmt := First_Elmt (List_2);
26382 while Present (Elmt) loop
26383 Append_Unique_Elmt (Node (Elmt), List_1);
26384 Next_Elmt (Elmt);
26385 end loop;
26386
26387 return List_1;
26388 end Visible_Ancestors;
26389
26390 ----------------------
26391 -- Within_Init_Proc --
26392 ----------------------
26393
26394 function Within_Init_Proc return Boolean is
26395 S : Entity_Id;
26396
26397 begin
26398 S := Current_Scope;
26399 while not Is_Overloadable (S) loop
26400 if S = Standard_Standard then
26401 return False;
26402 else
26403 S := Scope (S);
26404 end if;
26405 end loop;
26406
26407 return Is_Init_Proc (S);
26408 end Within_Init_Proc;
26409
26410 ---------------------------
26411 -- Within_Protected_Type --
26412 ---------------------------
26413
26414 function Within_Protected_Type (E : Entity_Id) return Boolean is
26415 Scop : Entity_Id := Scope (E);
26416
26417 begin
26418 while Present (Scop) loop
26419 if Ekind (Scop) = E_Protected_Type then
26420 return True;
26421 end if;
26422
26423 Scop := Scope (Scop);
26424 end loop;
26425
26426 return False;
26427 end Within_Protected_Type;
26428
26429 ------------------
26430 -- Within_Scope --
26431 ------------------
26432
26433 function Within_Scope (E : Entity_Id; S : Entity_Id) return Boolean is
26434 begin
26435 return Scope_Within_Or_Same (Scope (E), S);
26436 end Within_Scope;
26437
26438 ----------------------------
26439 -- Within_Subprogram_Call --
26440 ----------------------------
26441
26442 function Within_Subprogram_Call (N : Node_Id) return Boolean is
26443 Par : Node_Id;
26444
26445 begin
26446 -- Climb the parent chain looking for a function or procedure call
26447
26448 Par := N;
26449 while Present (Par) loop
26450 if Nkind_In (Par, N_Entry_Call_Statement,
26451 N_Function_Call,
26452 N_Procedure_Call_Statement)
26453 then
26454 return True;
26455
26456 -- Prevent the search from going too far
26457
26458 elsif Is_Body_Or_Package_Declaration (Par) then
26459 exit;
26460 end if;
26461
26462 Par := Parent (Par);
26463 end loop;
26464
26465 return False;
26466 end Within_Subprogram_Call;
26467
26468 ----------------
26469 -- Wrong_Type --
26470 ----------------
26471
26472 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
26473 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
26474 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
26475
26476 Matching_Field : Entity_Id;
26477 -- Entity to give a more precise suggestion on how to write a one-
26478 -- element positional aggregate.
26479
26480 function Has_One_Matching_Field return Boolean;
26481 -- Determines if Expec_Type is a record type with a single component or
26482 -- discriminant whose type matches the found type or is one dimensional
26483 -- array whose component type matches the found type. In the case of
26484 -- one discriminant, we ignore the variant parts. That's not accurate,
26485 -- but good enough for the warning.
26486
26487 ----------------------------
26488 -- Has_One_Matching_Field --
26489 ----------------------------
26490
26491 function Has_One_Matching_Field return Boolean is
26492 E : Entity_Id;
26493
26494 begin
26495 Matching_Field := Empty;
26496
26497 if Is_Array_Type (Expec_Type)
26498 and then Number_Dimensions (Expec_Type) = 1
26499 and then Covers (Etype (Component_Type (Expec_Type)), Found_Type)
26500 then
26501 -- Use type name if available. This excludes multidimensional
26502 -- arrays and anonymous arrays.
26503
26504 if Comes_From_Source (Expec_Type) then
26505 Matching_Field := Expec_Type;
26506
26507 -- For an assignment, use name of target
26508
26509 elsif Nkind (Parent (Expr)) = N_Assignment_Statement
26510 and then Is_Entity_Name (Name (Parent (Expr)))
26511 then
26512 Matching_Field := Entity (Name (Parent (Expr)));
26513 end if;
26514
26515 return True;
26516
26517 elsif not Is_Record_Type (Expec_Type) then
26518 return False;
26519
26520 else
26521 E := First_Entity (Expec_Type);
26522 loop
26523 if No (E) then
26524 return False;
26525
26526 elsif not Ekind_In (E, E_Discriminant, E_Component)
26527 or else Nam_In (Chars (E), Name_uTag, Name_uParent)
26528 then
26529 Next_Entity (E);
26530
26531 else
26532 exit;
26533 end if;
26534 end loop;
26535
26536 if not Covers (Etype (E), Found_Type) then
26537 return False;
26538
26539 elsif Present (Next_Entity (E))
26540 and then (Ekind (E) = E_Component
26541 or else Ekind (Next_Entity (E)) = E_Discriminant)
26542 then
26543 return False;
26544
26545 else
26546 Matching_Field := E;
26547 return True;
26548 end if;
26549 end if;
26550 end Has_One_Matching_Field;
26551
26552 -- Start of processing for Wrong_Type
26553
26554 begin
26555 -- Don't output message if either type is Any_Type, or if a message
26556 -- has already been posted for this node. We need to do the latter
26557 -- check explicitly (it is ordinarily done in Errout), because we
26558 -- are using ! to force the output of the error messages.
26559
26560 if Expec_Type = Any_Type
26561 or else Found_Type = Any_Type
26562 or else Error_Posted (Expr)
26563 then
26564 return;
26565
26566 -- If one of the types is a Taft-Amendment type and the other it its
26567 -- completion, it must be an illegal use of a TAT in the spec, for
26568 -- which an error was already emitted. Avoid cascaded errors.
26569
26570 elsif Is_Incomplete_Type (Expec_Type)
26571 and then Has_Completion_In_Body (Expec_Type)
26572 and then Full_View (Expec_Type) = Etype (Expr)
26573 then
26574 return;
26575
26576 elsif Is_Incomplete_Type (Etype (Expr))
26577 and then Has_Completion_In_Body (Etype (Expr))
26578 and then Full_View (Etype (Expr)) = Expec_Type
26579 then
26580 return;
26581
26582 -- In an instance, there is an ongoing problem with completion of
26583 -- type derived from private types. Their structure is what Gigi
26584 -- expects, but the Etype is the parent type rather than the
26585 -- derived private type itself. Do not flag error in this case. The
26586 -- private completion is an entity without a parent, like an Itype.
26587 -- Similarly, full and partial views may be incorrect in the instance.
26588 -- There is no simple way to insure that it is consistent ???
26589
26590 -- A similar view discrepancy can happen in an inlined body, for the
26591 -- same reason: inserted body may be outside of the original package
26592 -- and only partial views are visible at the point of insertion.
26593
26594 elsif In_Instance or else In_Inlined_Body then
26595 if Etype (Etype (Expr)) = Etype (Expected_Type)
26596 and then
26597 (Has_Private_Declaration (Expected_Type)
26598 or else Has_Private_Declaration (Etype (Expr)))
26599 and then No (Parent (Expected_Type))
26600 then
26601 return;
26602
26603 elsif Nkind (Parent (Expr)) = N_Qualified_Expression
26604 and then Entity (Subtype_Mark (Parent (Expr))) = Expected_Type
26605 then
26606 return;
26607
26608 elsif Is_Private_Type (Expected_Type)
26609 and then Present (Full_View (Expected_Type))
26610 and then Covers (Full_View (Expected_Type), Etype (Expr))
26611 then
26612 return;
26613
26614 -- Conversely, type of expression may be the private one
26615
26616 elsif Is_Private_Type (Base_Type (Etype (Expr)))
26617 and then Full_View (Base_Type (Etype (Expr))) = Expected_Type
26618 then
26619 return;
26620 end if;
26621 end if;
26622
26623 -- An interesting special check. If the expression is parenthesized
26624 -- and its type corresponds to the type of the sole component of the
26625 -- expected record type, or to the component type of the expected one
26626 -- dimensional array type, then assume we have a bad aggregate attempt.
26627
26628 if Nkind (Expr) in N_Subexpr
26629 and then Paren_Count (Expr) /= 0
26630 and then Has_One_Matching_Field
26631 then
26632 Error_Msg_N ("positional aggregate cannot have one component", Expr);
26633
26634 if Present (Matching_Field) then
26635 if Is_Array_Type (Expec_Type) then
26636 Error_Msg_NE
26637 ("\write instead `&''First ='> ...`", Expr, Matching_Field);
26638 else
26639 Error_Msg_NE
26640 ("\write instead `& ='> ...`", Expr, Matching_Field);
26641 end if;
26642 end if;
26643
26644 -- Another special check, if we are looking for a pool-specific access
26645 -- type and we found an E_Access_Attribute_Type, then we have the case
26646 -- of an Access attribute being used in a context which needs a pool-
26647 -- specific type, which is never allowed. The one extra check we make
26648 -- is that the expected designated type covers the Found_Type.
26649
26650 elsif Is_Access_Type (Expec_Type)
26651 and then Ekind (Found_Type) = E_Access_Attribute_Type
26652 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
26653 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
26654 and then Covers
26655 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
26656 then
26657 Error_Msg_N -- CODEFIX
26658 ("result must be general access type!", Expr);
26659 Error_Msg_NE -- CODEFIX
26660 ("add ALL to }!", Expr, Expec_Type);
26661
26662 -- Another special check, if the expected type is an integer type,
26663 -- but the expression is of type System.Address, and the parent is
26664 -- an addition or subtraction operation whose left operand is the
26665 -- expression in question and whose right operand is of an integral
26666 -- type, then this is an attempt at address arithmetic, so give
26667 -- appropriate message.
26668
26669 elsif Is_Integer_Type (Expec_Type)
26670 and then Is_RTE (Found_Type, RE_Address)
26671 and then Nkind_In (Parent (Expr), N_Op_Add, N_Op_Subtract)
26672 and then Expr = Left_Opnd (Parent (Expr))
26673 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
26674 then
26675 Error_Msg_N
26676 ("address arithmetic not predefined in package System",
26677 Parent (Expr));
26678 Error_Msg_N
26679 ("\possible missing with/use of System.Storage_Elements",
26680 Parent (Expr));
26681 return;
26682
26683 -- If the expected type is an anonymous access type, as for access
26684 -- parameters and discriminants, the error is on the designated types.
26685
26686 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
26687 if Comes_From_Source (Expec_Type) then
26688 Error_Msg_NE ("expected}!", Expr, Expec_Type);
26689 else
26690 Error_Msg_NE
26691 ("expected an access type with designated}",
26692 Expr, Designated_Type (Expec_Type));
26693 end if;
26694
26695 if Is_Access_Type (Found_Type)
26696 and then not Comes_From_Source (Found_Type)
26697 then
26698 Error_Msg_NE
26699 ("\\found an access type with designated}!",
26700 Expr, Designated_Type (Found_Type));
26701 else
26702 if From_Limited_With (Found_Type) then
26703 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
26704 Error_Msg_Qual_Level := 99;
26705 Error_Msg_NE -- CODEFIX
26706 ("\\missing `WITH &;", Expr, Scope (Found_Type));
26707 Error_Msg_Qual_Level := 0;
26708 else
26709 Error_Msg_NE ("found}!", Expr, Found_Type);
26710 end if;
26711 end if;
26712
26713 -- Normal case of one type found, some other type expected
26714
26715 else
26716 -- If the names of the two types are the same, see if some number
26717 -- of levels of qualification will help. Don't try more than three
26718 -- levels, and if we get to standard, it's no use (and probably
26719 -- represents an error in the compiler) Also do not bother with
26720 -- internal scope names.
26721
26722 declare
26723 Expec_Scope : Entity_Id;
26724 Found_Scope : Entity_Id;
26725
26726 begin
26727 Expec_Scope := Expec_Type;
26728 Found_Scope := Found_Type;
26729
26730 for Levels in Nat range 0 .. 3 loop
26731 if Chars (Expec_Scope) /= Chars (Found_Scope) then
26732 Error_Msg_Qual_Level := Levels;
26733 exit;
26734 end if;
26735
26736 Expec_Scope := Scope (Expec_Scope);
26737 Found_Scope := Scope (Found_Scope);
26738
26739 exit when Expec_Scope = Standard_Standard
26740 or else Found_Scope = Standard_Standard
26741 or else not Comes_From_Source (Expec_Scope)
26742 or else not Comes_From_Source (Found_Scope);
26743 end loop;
26744 end;
26745
26746 if Is_Record_Type (Expec_Type)
26747 and then Present (Corresponding_Remote_Type (Expec_Type))
26748 then
26749 Error_Msg_NE ("expected}!", Expr,
26750 Corresponding_Remote_Type (Expec_Type));
26751 else
26752 Error_Msg_NE ("expected}!", Expr, Expec_Type);
26753 end if;
26754
26755 if Is_Entity_Name (Expr)
26756 and then Is_Package_Or_Generic_Package (Entity (Expr))
26757 then
26758 Error_Msg_N ("\\found package name!", Expr);
26759
26760 elsif Is_Entity_Name (Expr)
26761 and then Ekind_In (Entity (Expr), E_Procedure, E_Generic_Procedure)
26762 then
26763 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
26764 Error_Msg_N
26765 ("found procedure name, possibly missing Access attribute!",
26766 Expr);
26767 else
26768 Error_Msg_N
26769 ("\\found procedure name instead of function!", Expr);
26770 end if;
26771
26772 elsif Nkind (Expr) = N_Function_Call
26773 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
26774 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
26775 and then No (Parameter_Associations (Expr))
26776 then
26777 Error_Msg_N
26778 ("found function name, possibly missing Access attribute!",
26779 Expr);
26780
26781 -- Catch common error: a prefix or infix operator which is not
26782 -- directly visible because the type isn't.
26783
26784 elsif Nkind (Expr) in N_Op
26785 and then Is_Overloaded (Expr)
26786 and then not Is_Immediately_Visible (Expec_Type)
26787 and then not Is_Potentially_Use_Visible (Expec_Type)
26788 and then not In_Use (Expec_Type)
26789 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
26790 then
26791 Error_Msg_N
26792 ("operator of the type is not directly visible!", Expr);
26793
26794 elsif Ekind (Found_Type) = E_Void
26795 and then Present (Parent (Found_Type))
26796 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
26797 then
26798 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
26799
26800 else
26801 Error_Msg_NE ("\\found}!", Expr, Found_Type);
26802 end if;
26803
26804 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
26805 -- of the same modular type, and (M1 and M2) = 0 was intended.
26806
26807 if Expec_Type = Standard_Boolean
26808 and then Is_Modular_Integer_Type (Found_Type)
26809 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
26810 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
26811 then
26812 declare
26813 Op : constant Node_Id := Right_Opnd (Parent (Expr));
26814 L : constant Node_Id := Left_Opnd (Op);
26815 R : constant Node_Id := Right_Opnd (Op);
26816
26817 begin
26818 -- The case for the message is when the left operand of the
26819 -- comparison is the same modular type, or when it is an
26820 -- integer literal (or other universal integer expression),
26821 -- which would have been typed as the modular type if the
26822 -- parens had been there.
26823
26824 if (Etype (L) = Found_Type
26825 or else
26826 Etype (L) = Universal_Integer)
26827 and then Is_Integer_Type (Etype (R))
26828 then
26829 Error_Msg_N
26830 ("\\possible missing parens for modular operation", Expr);
26831 end if;
26832 end;
26833 end if;
26834
26835 -- Reset error message qualification indication
26836
26837 Error_Msg_Qual_Level := 0;
26838 end if;
26839 end Wrong_Type;
26840
26841 --------------------------------
26842 -- Yields_Synchronized_Object --
26843 --------------------------------
26844
26845 function Yields_Synchronized_Object (Typ : Entity_Id) return Boolean is
26846 Has_Sync_Comp : Boolean := False;
26847 Id : Entity_Id;
26848
26849 begin
26850 -- An array type yields a synchronized object if its component type
26851 -- yields a synchronized object.
26852
26853 if Is_Array_Type (Typ) then
26854 return Yields_Synchronized_Object (Component_Type (Typ));
26855
26856 -- A descendant of type Ada.Synchronous_Task_Control.Suspension_Object
26857 -- yields a synchronized object by default.
26858
26859 elsif Is_Descendant_Of_Suspension_Object (Typ) then
26860 return True;
26861
26862 -- A protected type yields a synchronized object by default
26863
26864 elsif Is_Protected_Type (Typ) then
26865 return True;
26866
26867 -- A record type or type extension yields a synchronized object when its
26868 -- discriminants (if any) lack default values and all components are of
26869 -- a type that yields a synchronized object.
26870
26871 elsif Is_Record_Type (Typ) then
26872
26873 -- Inspect all entities defined in the scope of the type, looking for
26874 -- components of a type that does not yield a synchronized object or
26875 -- for discriminants with default values.
26876
26877 Id := First_Entity (Typ);
26878 while Present (Id) loop
26879 if Comes_From_Source (Id) then
26880 if Ekind (Id) = E_Component then
26881 if Yields_Synchronized_Object (Etype (Id)) then
26882 Has_Sync_Comp := True;
26883
26884 -- The component does not yield a synchronized object
26885
26886 else
26887 return False;
26888 end if;
26889
26890 elsif Ekind (Id) = E_Discriminant
26891 and then Present (Expression (Parent (Id)))
26892 then
26893 return False;
26894 end if;
26895 end if;
26896
26897 Next_Entity (Id);
26898 end loop;
26899
26900 -- Ensure that the parent type of a type extension yields a
26901 -- synchronized object.
26902
26903 if Etype (Typ) /= Typ
26904 and then not Is_Private_Type (Etype (Typ))
26905 and then not Yields_Synchronized_Object (Etype (Typ))
26906 then
26907 return False;
26908 end if;
26909
26910 -- If we get here, then all discriminants lack default values and all
26911 -- components are of a type that yields a synchronized object.
26912
26913 return Has_Sync_Comp;
26914
26915 -- A synchronized interface type yields a synchronized object by default
26916
26917 elsif Is_Synchronized_Interface (Typ) then
26918 return True;
26919
26920 -- A task type yields a synchronized object by default
26921
26922 elsif Is_Task_Type (Typ) then
26923 return True;
26924
26925 -- A private type yields a synchronized object if its underlying type
26926 -- does.
26927
26928 elsif Is_Private_Type (Typ)
26929 and then Present (Underlying_Type (Typ))
26930 then
26931 return Yields_Synchronized_Object (Underlying_Type (Typ));
26932
26933 -- Otherwise the type does not yield a synchronized object
26934
26935 else
26936 return False;
26937 end if;
26938 end Yields_Synchronized_Object;
26939
26940 ---------------------------
26941 -- Yields_Universal_Type --
26942 ---------------------------
26943
26944 function Yields_Universal_Type (N : Node_Id) return Boolean is
26945 begin
26946 -- Integer and real literals are of a universal type
26947
26948 if Nkind_In (N, N_Integer_Literal, N_Real_Literal) then
26949 return True;
26950
26951 -- The values of certain attributes are of a universal type
26952
26953 elsif Nkind (N) = N_Attribute_Reference then
26954 return
26955 Universal_Type_Attribute (Get_Attribute_Id (Attribute_Name (N)));
26956
26957 -- ??? There are possibly other cases to consider
26958
26959 else
26960 return False;
26961 end if;
26962 end Yields_Universal_Type;
26963
26964 begin
26965 Erroutc.Subprogram_Name_Ptr := Subprogram_Name'Access;
26966 end Sem_Util;