]> gcc.gnu.org Git - gcc.git/blob - gcc/ada/sem_util.adb
exp_attr.adb, [...]: Minor reformatting.
[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-2015, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
25
26 with Treepr; -- ???For debugging code below
27
28 with Aspects; use Aspects;
29 with Atree; use Atree;
30 with Casing; use Casing;
31 with Checks; use Checks;
32 with Debug; use Debug;
33 with Elists; use Elists;
34 with Errout; use Errout;
35 with Exp_Ch11; use Exp_Ch11;
36 with Exp_Disp; use Exp_Disp;
37 with Exp_Util; use Exp_Util;
38 with Fname; use Fname;
39 with Freeze; use Freeze;
40 with Ghost; use Ghost;
41 with Lib; use Lib;
42 with Lib.Xref; use Lib.Xref;
43 with Namet.Sp; use Namet.Sp;
44 with Nlists; use Nlists;
45 with Nmake; use Nmake;
46 with Output; use Output;
47 with Restrict; use Restrict;
48 with Rident; use Rident;
49 with Rtsfind; use Rtsfind;
50 with Sem; use Sem;
51 with Sem_Aux; use Sem_Aux;
52 with Sem_Attr; use Sem_Attr;
53 with Sem_Ch6; use Sem_Ch6;
54 with Sem_Ch8; use Sem_Ch8;
55 with Sem_Ch13; use Sem_Ch13;
56 with Sem_Disp; use Sem_Disp;
57 with Sem_Eval; use Sem_Eval;
58 with Sem_Prag; use Sem_Prag;
59 with Sem_Res; use Sem_Res;
60 with Sem_Warn; use Sem_Warn;
61 with Sem_Type; use Sem_Type;
62 with Sinfo; use Sinfo;
63 with Sinput; use Sinput;
64 with Stand; use Stand;
65 with Style;
66 with Stringt; use Stringt;
67 with Targparm; use Targparm;
68 with Tbuild; use Tbuild;
69 with Ttypes; use Ttypes;
70 with Uname; use Uname;
71
72 with GNAT.HTable; use GNAT.HTable;
73
74 package body Sem_Util is
75
76 ----------------------------------------
77 -- Global Variables for New_Copy_Tree --
78 ----------------------------------------
79
80 -- These global variables are used by New_Copy_Tree. See description of the
81 -- body of this subprogram for details. Global variables can be safely used
82 -- by New_Copy_Tree, since there is no case of a recursive call from the
83 -- processing inside New_Copy_Tree.
84
85 NCT_Hash_Threshold : constant := 20;
86 -- If there are more than this number of pairs of entries in the map, then
87 -- Hash_Tables_Used will be set, and the hash tables will be initialized
88 -- and used for the searches.
89
90 NCT_Hash_Tables_Used : Boolean := False;
91 -- Set to True if hash tables are in use
92
93 NCT_Table_Entries : Nat := 0;
94 -- Count entries in table to see if threshold is reached
95
96 NCT_Hash_Table_Setup : Boolean := False;
97 -- Set to True if hash table contains data. We set this True if we setup
98 -- the hash table with data, and leave it set permanently from then on,
99 -- this is a signal that second and subsequent users of the hash table
100 -- must clear the old entries before reuse.
101
102 subtype NCT_Header_Num is Int range 0 .. 511;
103 -- Defines range of headers in hash tables (512 headers)
104
105 -----------------------
106 -- Local Subprograms --
107 -----------------------
108
109 function Build_Component_Subtype
110 (C : List_Id;
111 Loc : Source_Ptr;
112 T : Entity_Id) return Node_Id;
113 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
114 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
115 -- Loc is the source location, T is the original subtype.
116
117 function Has_Enabled_Property
118 (Item_Id : Entity_Id;
119 Property : Name_Id) return Boolean;
120 -- Subsidiary to routines Async_xxx_Enabled and Effective_xxx_Enabled.
121 -- Determine whether an abstract state or a variable denoted by entity
122 -- Item_Id has enabled property Property.
123
124 function Has_Null_Extension (T : Entity_Id) return Boolean;
125 -- T is a derived tagged type. Check whether the type extension is null.
126 -- If the parent type is fully initialized, T can be treated as such.
127
128 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
129 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
130 -- with discriminants whose default values are static, examine only the
131 -- components in the selected variant to determine whether all of them
132 -- have a default.
133
134 ------------------------------
135 -- Abstract_Interface_List --
136 ------------------------------
137
138 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
139 Nod : Node_Id;
140
141 begin
142 if Is_Concurrent_Type (Typ) then
143
144 -- If we are dealing with a synchronized subtype, go to the base
145 -- type, whose declaration has the interface list.
146
147 -- Shouldn't this be Declaration_Node???
148
149 Nod := Parent (Base_Type (Typ));
150
151 if Nkind (Nod) = N_Full_Type_Declaration then
152 return Empty_List;
153 end if;
154
155 elsif Ekind (Typ) = E_Record_Type_With_Private then
156 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
157 Nod := Type_Definition (Parent (Typ));
158
159 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
160 if Present (Full_View (Typ))
161 and then
162 Nkind (Parent (Full_View (Typ))) = N_Full_Type_Declaration
163 then
164 Nod := Type_Definition (Parent (Full_View (Typ)));
165
166 -- If the full-view is not available we cannot do anything else
167 -- here (the source has errors).
168
169 else
170 return Empty_List;
171 end if;
172
173 -- Support for generic formals with interfaces is still missing ???
174
175 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
176 return Empty_List;
177
178 else
179 pragma Assert
180 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
181 Nod := Parent (Typ);
182 end if;
183
184 elsif Ekind (Typ) = E_Record_Subtype then
185 Nod := Type_Definition (Parent (Etype (Typ)));
186
187 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
188
189 -- Recurse, because parent may still be a private extension. Also
190 -- note that the full view of the subtype or the full view of its
191 -- base type may (both) be unavailable.
192
193 return Abstract_Interface_List (Etype (Typ));
194
195 else pragma Assert ((Ekind (Typ)) = E_Record_Type);
196 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
197 Nod := Formal_Type_Definition (Parent (Typ));
198 else
199 Nod := Type_Definition (Parent (Typ));
200 end if;
201 end if;
202
203 return Interface_List (Nod);
204 end Abstract_Interface_List;
205
206 --------------------------------
207 -- Add_Access_Type_To_Process --
208 --------------------------------
209
210 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
211 L : Elist_Id;
212
213 begin
214 Ensure_Freeze_Node (E);
215 L := Access_Types_To_Process (Freeze_Node (E));
216
217 if No (L) then
218 L := New_Elmt_List;
219 Set_Access_Types_To_Process (Freeze_Node (E), L);
220 end if;
221
222 Append_Elmt (A, L);
223 end Add_Access_Type_To_Process;
224
225 --------------------------
226 -- Add_Block_Identifier --
227 --------------------------
228
229 procedure Add_Block_Identifier (N : Node_Id; Id : out Entity_Id) is
230 Loc : constant Source_Ptr := Sloc (N);
231
232 begin
233 pragma Assert (Nkind (N) = N_Block_Statement);
234
235 -- The block already has a label, return its entity
236
237 if Present (Identifier (N)) then
238 Id := Entity (Identifier (N));
239
240 -- Create a new block label and set its attributes
241
242 else
243 Id := New_Internal_Entity (E_Block, Current_Scope, Loc, 'B');
244 Set_Etype (Id, Standard_Void_Type);
245 Set_Parent (Id, N);
246
247 Set_Identifier (N, New_Occurrence_Of (Id, Loc));
248 Set_Block_Node (Id, Identifier (N));
249 end if;
250 end Add_Block_Identifier;
251
252 ----------------------------
253 -- Add_Global_Declaration --
254 ----------------------------
255
256 procedure Add_Global_Declaration (N : Node_Id) is
257 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
258
259 begin
260 if No (Declarations (Aux_Node)) then
261 Set_Declarations (Aux_Node, New_List);
262 end if;
263
264 Append_To (Declarations (Aux_Node), N);
265 Analyze (N);
266 end Add_Global_Declaration;
267
268 --------------------------------
269 -- Address_Integer_Convert_OK --
270 --------------------------------
271
272 function Address_Integer_Convert_OK (T1, T2 : Entity_Id) return Boolean is
273 begin
274 if Allow_Integer_Address
275 and then ((Is_Descendent_Of_Address (T1)
276 and then Is_Private_Type (T1)
277 and then Is_Integer_Type (T2))
278 or else
279 (Is_Descendent_Of_Address (T2)
280 and then Is_Private_Type (T2)
281 and then Is_Integer_Type (T1)))
282 then
283 return True;
284 else
285 return False;
286 end if;
287 end Address_Integer_Convert_OK;
288
289 -----------------
290 -- Addressable --
291 -----------------
292
293 -- For now, just 8/16/32/64. but analyze later if AAMP is special???
294
295 function Addressable (V : Uint) return Boolean is
296 begin
297 return V = Uint_8 or else
298 V = Uint_16 or else
299 V = Uint_32 or else
300 V = Uint_64;
301 end Addressable;
302
303 function Addressable (V : Int) return Boolean is
304 begin
305 return V = 8 or else
306 V = 16 or else
307 V = 32 or else
308 V = 64;
309 end Addressable;
310
311 ---------------------------------
312 -- Aggregate_Constraint_Checks --
313 ---------------------------------
314
315 procedure Aggregate_Constraint_Checks
316 (Exp : Node_Id;
317 Check_Typ : Entity_Id)
318 is
319 Exp_Typ : constant Entity_Id := Etype (Exp);
320
321 begin
322 if Raises_Constraint_Error (Exp) then
323 return;
324 end if;
325
326 -- Ada 2005 (AI-230): Generate a conversion to an anonymous access
327 -- component's type to force the appropriate accessibility checks.
328
329 -- Ada 2005 (AI-231): Generate conversion to the null-excluding
330 -- type to force the corresponding run-time check
331
332 if Is_Access_Type (Check_Typ)
333 and then ((Is_Local_Anonymous_Access (Check_Typ))
334 or else (Can_Never_Be_Null (Check_Typ)
335 and then not Can_Never_Be_Null (Exp_Typ)))
336 then
337 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
338 Analyze_And_Resolve (Exp, Check_Typ);
339 Check_Unset_Reference (Exp);
340 end if;
341
342 -- This is really expansion activity, so make sure that expansion is
343 -- on and is allowed. In GNATprove mode, we also want check flags to
344 -- be added in the tree, so that the formal verification can rely on
345 -- those to be present. In GNATprove mode for formal verification, some
346 -- treatment typically only done during expansion needs to be performed
347 -- on the tree, but it should not be applied inside generics. Otherwise,
348 -- this breaks the name resolution mechanism for generic instances.
349
350 if not Expander_Active
351 and (Inside_A_Generic or not Full_Analysis or not GNATprove_Mode)
352 then
353 return;
354 end if;
355
356 -- First check if we have to insert discriminant checks
357
358 if Has_Discriminants (Exp_Typ) then
359 Apply_Discriminant_Check (Exp, Check_Typ);
360
361 -- Next emit length checks for array aggregates
362
363 elsif Is_Array_Type (Exp_Typ) then
364 Apply_Length_Check (Exp, Check_Typ);
365
366 -- Finally emit scalar and string checks. If we are dealing with a
367 -- scalar literal we need to check by hand because the Etype of
368 -- literals is not necessarily correct.
369
370 elsif Is_Scalar_Type (Exp_Typ)
371 and then Compile_Time_Known_Value (Exp)
372 then
373 if Is_Out_Of_Range (Exp, Base_Type (Check_Typ)) then
374 Apply_Compile_Time_Constraint_Error
375 (Exp, "value not in range of}??", CE_Range_Check_Failed,
376 Ent => Base_Type (Check_Typ),
377 Typ => Base_Type (Check_Typ));
378
379 elsif Is_Out_Of_Range (Exp, Check_Typ) then
380 Apply_Compile_Time_Constraint_Error
381 (Exp, "value not in range of}??", CE_Range_Check_Failed,
382 Ent => Check_Typ,
383 Typ => Check_Typ);
384
385 elsif not Range_Checks_Suppressed (Check_Typ) then
386 Apply_Scalar_Range_Check (Exp, Check_Typ);
387 end if;
388
389 -- Verify that target type is also scalar, to prevent view anomalies
390 -- in instantiations.
391
392 elsif (Is_Scalar_Type (Exp_Typ)
393 or else Nkind (Exp) = N_String_Literal)
394 and then Is_Scalar_Type (Check_Typ)
395 and then Exp_Typ /= Check_Typ
396 then
397 if Is_Entity_Name (Exp)
398 and then Ekind (Entity (Exp)) = E_Constant
399 then
400 -- If expression is a constant, it is worthwhile checking whether
401 -- it is a bound of the type.
402
403 if (Is_Entity_Name (Type_Low_Bound (Check_Typ))
404 and then Entity (Exp) = Entity (Type_Low_Bound (Check_Typ)))
405 or else
406 (Is_Entity_Name (Type_High_Bound (Check_Typ))
407 and then Entity (Exp) = Entity (Type_High_Bound (Check_Typ)))
408 then
409 return;
410
411 else
412 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
413 Analyze_And_Resolve (Exp, Check_Typ);
414 Check_Unset_Reference (Exp);
415 end if;
416
417 -- Could use a comment on this case ???
418
419 else
420 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
421 Analyze_And_Resolve (Exp, Check_Typ);
422 Check_Unset_Reference (Exp);
423 end if;
424
425 end if;
426 end Aggregate_Constraint_Checks;
427
428 -----------------------
429 -- Alignment_In_Bits --
430 -----------------------
431
432 function Alignment_In_Bits (E : Entity_Id) return Uint is
433 begin
434 return Alignment (E) * System_Storage_Unit;
435 end Alignment_In_Bits;
436
437 --------------------------------------
438 -- All_Composite_Constraints_Static --
439 --------------------------------------
440
441 function All_Composite_Constraints_Static
442 (Constr : Node_Id) return Boolean
443 is
444 begin
445 if No (Constr) or else Error_Posted (Constr) then
446 return True;
447 end if;
448
449 case Nkind (Constr) is
450 when N_Subexpr =>
451 if Nkind (Constr) in N_Has_Entity
452 and then Present (Entity (Constr))
453 then
454 if Is_Type (Entity (Constr)) then
455 return
456 not Is_Discrete_Type (Entity (Constr))
457 or else Is_OK_Static_Subtype (Entity (Constr));
458 end if;
459
460 elsif Nkind (Constr) = N_Range then
461 return
462 Is_OK_Static_Expression (Low_Bound (Constr))
463 and then
464 Is_OK_Static_Expression (High_Bound (Constr));
465
466 elsif Nkind (Constr) = N_Attribute_Reference
467 and then Attribute_Name (Constr) = Name_Range
468 then
469 return
470 Is_OK_Static_Expression
471 (Type_Low_Bound (Etype (Prefix (Constr))))
472 and then
473 Is_OK_Static_Expression
474 (Type_High_Bound (Etype (Prefix (Constr))));
475 end if;
476
477 return
478 not Present (Etype (Constr)) -- previous error
479 or else not Is_Discrete_Type (Etype (Constr))
480 or else Is_OK_Static_Expression (Constr);
481
482 when N_Discriminant_Association =>
483 return All_Composite_Constraints_Static (Expression (Constr));
484
485 when N_Range_Constraint =>
486 return
487 All_Composite_Constraints_Static (Range_Expression (Constr));
488
489 when N_Index_Or_Discriminant_Constraint =>
490 declare
491 One_Cstr : Entity_Id;
492 begin
493 One_Cstr := First (Constraints (Constr));
494 while Present (One_Cstr) loop
495 if not All_Composite_Constraints_Static (One_Cstr) then
496 return False;
497 end if;
498
499 Next (One_Cstr);
500 end loop;
501 end;
502
503 return True;
504
505 when N_Subtype_Indication =>
506 return
507 All_Composite_Constraints_Static (Subtype_Mark (Constr))
508 and then
509 All_Composite_Constraints_Static (Constraint (Constr));
510
511 when others =>
512 raise Program_Error;
513 end case;
514 end All_Composite_Constraints_Static;
515
516 ---------------------------------
517 -- Append_Inherited_Subprogram --
518 ---------------------------------
519
520 procedure Append_Inherited_Subprogram (S : Entity_Id) is
521 Par : constant Entity_Id := Alias (S);
522 -- The parent subprogram
523
524 Scop : constant Entity_Id := Scope (Par);
525 -- The scope of definition of the parent subprogram
526
527 Typ : constant Entity_Id := Defining_Entity (Parent (S));
528 -- The derived type of which S is a primitive operation
529
530 Decl : Node_Id;
531 Next_E : Entity_Id;
532
533 begin
534 if Ekind (Current_Scope) = E_Package
535 and then In_Private_Part (Current_Scope)
536 and then Has_Private_Declaration (Typ)
537 and then Is_Tagged_Type (Typ)
538 and then Scop = Current_Scope
539 then
540 -- The inherited operation is available at the earliest place after
541 -- the derived type declaration ( RM 7.3.1 (6/1)). This is only
542 -- relevant for type extensions. If the parent operation appears
543 -- after the type extension, the operation is not visible.
544
545 Decl := First
546 (Visible_Declarations
547 (Package_Specification (Current_Scope)));
548 while Present (Decl) loop
549 if Nkind (Decl) = N_Private_Extension_Declaration
550 and then Defining_Entity (Decl) = Typ
551 then
552 if Sloc (Decl) > Sloc (Par) then
553 Next_E := Next_Entity (Par);
554 Set_Next_Entity (Par, S);
555 Set_Next_Entity (S, Next_E);
556 return;
557
558 else
559 exit;
560 end if;
561 end if;
562
563 Next (Decl);
564 end loop;
565 end if;
566
567 -- If partial view is not a type extension, or it appears before the
568 -- subprogram declaration, insert normally at end of entity list.
569
570 Append_Entity (S, Current_Scope);
571 end Append_Inherited_Subprogram;
572
573 -----------------------------------------
574 -- Apply_Compile_Time_Constraint_Error --
575 -----------------------------------------
576
577 procedure Apply_Compile_Time_Constraint_Error
578 (N : Node_Id;
579 Msg : String;
580 Reason : RT_Exception_Code;
581 Ent : Entity_Id := Empty;
582 Typ : Entity_Id := Empty;
583 Loc : Source_Ptr := No_Location;
584 Rep : Boolean := True;
585 Warn : Boolean := False)
586 is
587 Stat : constant Boolean := Is_Static_Expression (N);
588 R_Stat : constant Node_Id :=
589 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
590 Rtyp : Entity_Id;
591
592 begin
593 if No (Typ) then
594 Rtyp := Etype (N);
595 else
596 Rtyp := Typ;
597 end if;
598
599 Discard_Node
600 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
601
602 if not Rep then
603 return;
604 end if;
605
606 -- Now we replace the node by an N_Raise_Constraint_Error node
607 -- This does not need reanalyzing, so set it as analyzed now.
608
609 Rewrite (N, R_Stat);
610 Set_Analyzed (N, True);
611
612 Set_Etype (N, Rtyp);
613 Set_Raises_Constraint_Error (N);
614
615 -- Now deal with possible local raise handling
616
617 Possible_Local_Raise (N, Standard_Constraint_Error);
618
619 -- If the original expression was marked as static, the result is
620 -- still marked as static, but the Raises_Constraint_Error flag is
621 -- always set so that further static evaluation is not attempted.
622
623 if Stat then
624 Set_Is_Static_Expression (N);
625 end if;
626 end Apply_Compile_Time_Constraint_Error;
627
628 ---------------------------
629 -- Async_Readers_Enabled --
630 ---------------------------
631
632 function Async_Readers_Enabled (Id : Entity_Id) return Boolean is
633 begin
634 return Has_Enabled_Property (Id, Name_Async_Readers);
635 end Async_Readers_Enabled;
636
637 ---------------------------
638 -- Async_Writers_Enabled --
639 ---------------------------
640
641 function Async_Writers_Enabled (Id : Entity_Id) return Boolean is
642 begin
643 return Has_Enabled_Property (Id, Name_Async_Writers);
644 end Async_Writers_Enabled;
645
646 --------------------------------------
647 -- Available_Full_View_Of_Component --
648 --------------------------------------
649
650 function Available_Full_View_Of_Component (T : Entity_Id) return Boolean is
651 ST : constant Entity_Id := Scope (T);
652 SCT : constant Entity_Id := Scope (Component_Type (T));
653 begin
654 return In_Open_Scopes (ST)
655 and then In_Open_Scopes (SCT)
656 and then Scope_Depth (ST) >= Scope_Depth (SCT);
657 end Available_Full_View_Of_Component;
658
659 -------------------
660 -- Bad_Attribute --
661 -------------------
662
663 procedure Bad_Attribute
664 (N : Node_Id;
665 Nam : Name_Id;
666 Warn : Boolean := False)
667 is
668 begin
669 Error_Msg_Warn := Warn;
670 Error_Msg_N ("unrecognized attribute&<<", N);
671
672 -- Check for possible misspelling
673
674 Error_Msg_Name_1 := First_Attribute_Name;
675 while Error_Msg_Name_1 <= Last_Attribute_Name loop
676 if Is_Bad_Spelling_Of (Nam, Error_Msg_Name_1) then
677 Error_Msg_N -- CODEFIX
678 ("\possible misspelling of %<<", N);
679 exit;
680 end if;
681
682 Error_Msg_Name_1 := Error_Msg_Name_1 + 1;
683 end loop;
684 end Bad_Attribute;
685
686 --------------------------------
687 -- Bad_Predicated_Subtype_Use --
688 --------------------------------
689
690 procedure Bad_Predicated_Subtype_Use
691 (Msg : String;
692 N : Node_Id;
693 Typ : Entity_Id;
694 Suggest_Static : Boolean := False)
695 is
696 Gen : Entity_Id;
697
698 begin
699 -- Avoid cascaded errors
700
701 if Error_Posted (N) then
702 return;
703 end if;
704
705 if Inside_A_Generic then
706 Gen := Current_Scope;
707 while Present (Gen) and then Ekind (Gen) /= E_Generic_Package loop
708 Gen := Scope (Gen);
709 end loop;
710
711 if No (Gen) then
712 return;
713 end if;
714
715 if Is_Generic_Formal (Typ) and then Is_Discrete_Type (Typ) then
716 Set_No_Predicate_On_Actual (Typ);
717 end if;
718
719 elsif Has_Predicates (Typ) then
720 if Is_Generic_Actual_Type (Typ) then
721
722 -- The restriction on loop parameters is only that the type
723 -- should have no dynamic predicates.
724
725 if Nkind (Parent (N)) = N_Loop_Parameter_Specification
726 and then not Has_Dynamic_Predicate_Aspect (Typ)
727 and then Is_OK_Static_Subtype (Typ)
728 then
729 return;
730 end if;
731
732 Gen := Current_Scope;
733 while not Is_Generic_Instance (Gen) loop
734 Gen := Scope (Gen);
735 end loop;
736
737 pragma Assert (Present (Gen));
738
739 if Ekind (Gen) = E_Package and then In_Package_Body (Gen) then
740 Error_Msg_Warn := SPARK_Mode /= On;
741 Error_Msg_FE (Msg & "<<", N, Typ);
742 Error_Msg_F ("\Program_Error [<<", N);
743
744 Insert_Action (N,
745 Make_Raise_Program_Error (Sloc (N),
746 Reason => PE_Bad_Predicated_Generic_Type));
747
748 else
749 Error_Msg_FE (Msg & "<<", N, Typ);
750 end if;
751
752 else
753 Error_Msg_FE (Msg, N, Typ);
754 end if;
755
756 -- Emit an optional suggestion on how to remedy the error if the
757 -- context warrants it.
758
759 if Suggest_Static and then Has_Static_Predicate (Typ) then
760 Error_Msg_FE ("\predicate of & should be marked static", N, Typ);
761 end if;
762 end if;
763 end Bad_Predicated_Subtype_Use;
764
765 -----------------------------------------
766 -- Bad_Unordered_Enumeration_Reference --
767 -----------------------------------------
768
769 function Bad_Unordered_Enumeration_Reference
770 (N : Node_Id;
771 T : Entity_Id) return Boolean
772 is
773 begin
774 return Is_Enumeration_Type (T)
775 and then Warn_On_Unordered_Enumeration_Type
776 and then not Is_Generic_Type (T)
777 and then Comes_From_Source (N)
778 and then not Has_Pragma_Ordered (T)
779 and then not In_Same_Extended_Unit (N, T);
780 end Bad_Unordered_Enumeration_Reference;
781
782 --------------------------
783 -- Build_Actual_Subtype --
784 --------------------------
785
786 function Build_Actual_Subtype
787 (T : Entity_Id;
788 N : Node_Or_Entity_Id) return Node_Id
789 is
790 Loc : Source_Ptr;
791 -- Normally Sloc (N), but may point to corresponding body in some cases
792
793 Constraints : List_Id;
794 Decl : Node_Id;
795 Discr : Entity_Id;
796 Hi : Node_Id;
797 Lo : Node_Id;
798 Subt : Entity_Id;
799 Disc_Type : Entity_Id;
800 Obj : Node_Id;
801
802 begin
803 Loc := Sloc (N);
804
805 if Nkind (N) = N_Defining_Identifier then
806 Obj := New_Occurrence_Of (N, Loc);
807
808 -- If this is a formal parameter of a subprogram declaration, and
809 -- we are compiling the body, we want the declaration for the
810 -- actual subtype to carry the source position of the body, to
811 -- prevent anomalies in gdb when stepping through the code.
812
813 if Is_Formal (N) then
814 declare
815 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
816 begin
817 if Nkind (Decl) = N_Subprogram_Declaration
818 and then Present (Corresponding_Body (Decl))
819 then
820 Loc := Sloc (Corresponding_Body (Decl));
821 end if;
822 end;
823 end if;
824
825 else
826 Obj := N;
827 end if;
828
829 if Is_Array_Type (T) then
830 Constraints := New_List;
831 for J in 1 .. Number_Dimensions (T) loop
832
833 -- Build an array subtype declaration with the nominal subtype and
834 -- the bounds of the actual. Add the declaration in front of the
835 -- local declarations for the subprogram, for analysis before any
836 -- reference to the formal in the body.
837
838 Lo :=
839 Make_Attribute_Reference (Loc,
840 Prefix =>
841 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
842 Attribute_Name => Name_First,
843 Expressions => New_List (
844 Make_Integer_Literal (Loc, J)));
845
846 Hi :=
847 Make_Attribute_Reference (Loc,
848 Prefix =>
849 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
850 Attribute_Name => Name_Last,
851 Expressions => New_List (
852 Make_Integer_Literal (Loc, J)));
853
854 Append (Make_Range (Loc, Lo, Hi), Constraints);
855 end loop;
856
857 -- If the type has unknown discriminants there is no constrained
858 -- subtype to build. This is never called for a formal or for a
859 -- lhs, so returning the type is ok ???
860
861 elsif Has_Unknown_Discriminants (T) then
862 return T;
863
864 else
865 Constraints := New_List;
866
867 -- Type T is a generic derived type, inherit the discriminants from
868 -- the parent type.
869
870 if Is_Private_Type (T)
871 and then No (Full_View (T))
872
873 -- T was flagged as an error if it was declared as a formal
874 -- derived type with known discriminants. In this case there
875 -- is no need to look at the parent type since T already carries
876 -- its own discriminants.
877
878 and then not Error_Posted (T)
879 then
880 Disc_Type := Etype (Base_Type (T));
881 else
882 Disc_Type := T;
883 end if;
884
885 Discr := First_Discriminant (Disc_Type);
886 while Present (Discr) loop
887 Append_To (Constraints,
888 Make_Selected_Component (Loc,
889 Prefix =>
890 Duplicate_Subexpr_No_Checks (Obj),
891 Selector_Name => New_Occurrence_Of (Discr, Loc)));
892 Next_Discriminant (Discr);
893 end loop;
894 end if;
895
896 Subt := Make_Temporary (Loc, 'S', Related_Node => N);
897 Set_Is_Internal (Subt);
898
899 Decl :=
900 Make_Subtype_Declaration (Loc,
901 Defining_Identifier => Subt,
902 Subtype_Indication =>
903 Make_Subtype_Indication (Loc,
904 Subtype_Mark => New_Occurrence_Of (T, Loc),
905 Constraint =>
906 Make_Index_Or_Discriminant_Constraint (Loc,
907 Constraints => Constraints)));
908
909 Mark_Rewrite_Insertion (Decl);
910 return Decl;
911 end Build_Actual_Subtype;
912
913 ---------------------------------------
914 -- Build_Actual_Subtype_Of_Component --
915 ---------------------------------------
916
917 function Build_Actual_Subtype_Of_Component
918 (T : Entity_Id;
919 N : Node_Id) return Node_Id
920 is
921 Loc : constant Source_Ptr := Sloc (N);
922 P : constant Node_Id := Prefix (N);
923 D : Elmt_Id;
924 Id : Node_Id;
925 Index_Typ : Entity_Id;
926
927 Desig_Typ : Entity_Id;
928 -- This is either a copy of T, or if T is an access type, then it is
929 -- the directly designated type of this access type.
930
931 function Build_Actual_Array_Constraint return List_Id;
932 -- If one or more of the bounds of the component depends on
933 -- discriminants, build actual constraint using the discriminants
934 -- of the prefix.
935
936 function Build_Actual_Record_Constraint return List_Id;
937 -- Similar to previous one, for discriminated components constrained
938 -- by the discriminant of the enclosing object.
939
940 -----------------------------------
941 -- Build_Actual_Array_Constraint --
942 -----------------------------------
943
944 function Build_Actual_Array_Constraint return List_Id is
945 Constraints : constant List_Id := New_List;
946 Indx : Node_Id;
947 Hi : Node_Id;
948 Lo : Node_Id;
949 Old_Hi : Node_Id;
950 Old_Lo : Node_Id;
951
952 begin
953 Indx := First_Index (Desig_Typ);
954 while Present (Indx) loop
955 Old_Lo := Type_Low_Bound (Etype (Indx));
956 Old_Hi := Type_High_Bound (Etype (Indx));
957
958 if Denotes_Discriminant (Old_Lo) then
959 Lo :=
960 Make_Selected_Component (Loc,
961 Prefix => New_Copy_Tree (P),
962 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
963
964 else
965 Lo := New_Copy_Tree (Old_Lo);
966
967 -- The new bound will be reanalyzed in the enclosing
968 -- declaration. For literal bounds that come from a type
969 -- declaration, the type of the context must be imposed, so
970 -- insure that analysis will take place. For non-universal
971 -- types this is not strictly necessary.
972
973 Set_Analyzed (Lo, False);
974 end if;
975
976 if Denotes_Discriminant (Old_Hi) then
977 Hi :=
978 Make_Selected_Component (Loc,
979 Prefix => New_Copy_Tree (P),
980 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
981
982 else
983 Hi := New_Copy_Tree (Old_Hi);
984 Set_Analyzed (Hi, False);
985 end if;
986
987 Append (Make_Range (Loc, Lo, Hi), Constraints);
988 Next_Index (Indx);
989 end loop;
990
991 return Constraints;
992 end Build_Actual_Array_Constraint;
993
994 ------------------------------------
995 -- Build_Actual_Record_Constraint --
996 ------------------------------------
997
998 function Build_Actual_Record_Constraint return List_Id is
999 Constraints : constant List_Id := New_List;
1000 D : Elmt_Id;
1001 D_Val : Node_Id;
1002
1003 begin
1004 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1005 while Present (D) loop
1006 if Denotes_Discriminant (Node (D)) then
1007 D_Val := Make_Selected_Component (Loc,
1008 Prefix => New_Copy_Tree (P),
1009 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
1010
1011 else
1012 D_Val := New_Copy_Tree (Node (D));
1013 end if;
1014
1015 Append (D_Val, Constraints);
1016 Next_Elmt (D);
1017 end loop;
1018
1019 return Constraints;
1020 end Build_Actual_Record_Constraint;
1021
1022 -- Start of processing for Build_Actual_Subtype_Of_Component
1023
1024 begin
1025 -- Why the test for Spec_Expression mode here???
1026
1027 if In_Spec_Expression then
1028 return Empty;
1029
1030 -- More comments for the rest of this body would be good ???
1031
1032 elsif Nkind (N) = N_Explicit_Dereference then
1033 if Is_Composite_Type (T)
1034 and then not Is_Constrained (T)
1035 and then not (Is_Class_Wide_Type (T)
1036 and then Is_Constrained (Root_Type (T)))
1037 and then not Has_Unknown_Discriminants (T)
1038 then
1039 -- If the type of the dereference is already constrained, it is an
1040 -- actual subtype.
1041
1042 if Is_Array_Type (Etype (N))
1043 and then Is_Constrained (Etype (N))
1044 then
1045 return Empty;
1046 else
1047 Remove_Side_Effects (P);
1048 return Build_Actual_Subtype (T, N);
1049 end if;
1050 else
1051 return Empty;
1052 end if;
1053 end if;
1054
1055 if Ekind (T) = E_Access_Subtype then
1056 Desig_Typ := Designated_Type (T);
1057 else
1058 Desig_Typ := T;
1059 end if;
1060
1061 if Ekind (Desig_Typ) = E_Array_Subtype then
1062 Id := First_Index (Desig_Typ);
1063 while Present (Id) loop
1064 Index_Typ := Underlying_Type (Etype (Id));
1065
1066 if Denotes_Discriminant (Type_Low_Bound (Index_Typ))
1067 or else
1068 Denotes_Discriminant (Type_High_Bound (Index_Typ))
1069 then
1070 Remove_Side_Effects (P);
1071 return
1072 Build_Component_Subtype
1073 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
1074 end if;
1075
1076 Next_Index (Id);
1077 end loop;
1078
1079 elsif Is_Composite_Type (Desig_Typ)
1080 and then Has_Discriminants (Desig_Typ)
1081 and then not Has_Unknown_Discriminants (Desig_Typ)
1082 then
1083 if Is_Private_Type (Desig_Typ)
1084 and then No (Discriminant_Constraint (Desig_Typ))
1085 then
1086 Desig_Typ := Full_View (Desig_Typ);
1087 end if;
1088
1089 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1090 while Present (D) loop
1091 if Denotes_Discriminant (Node (D)) then
1092 Remove_Side_Effects (P);
1093 return
1094 Build_Component_Subtype (
1095 Build_Actual_Record_Constraint, Loc, Base_Type (T));
1096 end if;
1097
1098 Next_Elmt (D);
1099 end loop;
1100 end if;
1101
1102 -- If none of the above, the actual and nominal subtypes are the same
1103
1104 return Empty;
1105 end Build_Actual_Subtype_Of_Component;
1106
1107 -----------------------------
1108 -- Build_Component_Subtype --
1109 -----------------------------
1110
1111 function Build_Component_Subtype
1112 (C : List_Id;
1113 Loc : Source_Ptr;
1114 T : Entity_Id) return Node_Id
1115 is
1116 Subt : Entity_Id;
1117 Decl : Node_Id;
1118
1119 begin
1120 -- Unchecked_Union components do not require component subtypes
1121
1122 if Is_Unchecked_Union (T) then
1123 return Empty;
1124 end if;
1125
1126 Subt := Make_Temporary (Loc, 'S');
1127 Set_Is_Internal (Subt);
1128
1129 Decl :=
1130 Make_Subtype_Declaration (Loc,
1131 Defining_Identifier => Subt,
1132 Subtype_Indication =>
1133 Make_Subtype_Indication (Loc,
1134 Subtype_Mark => New_Occurrence_Of (Base_Type (T), Loc),
1135 Constraint =>
1136 Make_Index_Or_Discriminant_Constraint (Loc,
1137 Constraints => C)));
1138
1139 Mark_Rewrite_Insertion (Decl);
1140 return Decl;
1141 end Build_Component_Subtype;
1142
1143 ----------------------------------
1144 -- Build_Default_Init_Cond_Call --
1145 ----------------------------------
1146
1147 function Build_Default_Init_Cond_Call
1148 (Loc : Source_Ptr;
1149 Obj_Id : Entity_Id;
1150 Typ : Entity_Id) return Node_Id
1151 is
1152 Proc_Id : constant Entity_Id := Default_Init_Cond_Procedure (Typ);
1153 Formal_Typ : constant Entity_Id := Etype (First_Formal (Proc_Id));
1154
1155 begin
1156 return
1157 Make_Procedure_Call_Statement (Loc,
1158 Name => New_Occurrence_Of (Proc_Id, Loc),
1159 Parameter_Associations => New_List (
1160 Make_Unchecked_Type_Conversion (Loc,
1161 Subtype_Mark => New_Occurrence_Of (Formal_Typ, Loc),
1162 Expression => New_Occurrence_Of (Obj_Id, Loc))));
1163 end Build_Default_Init_Cond_Call;
1164
1165 ----------------------------------------------
1166 -- Build_Default_Init_Cond_Procedure_Bodies --
1167 ----------------------------------------------
1168
1169 procedure Build_Default_Init_Cond_Procedure_Bodies (Priv_Decls : List_Id) is
1170 procedure Build_Default_Init_Cond_Procedure_Body (Typ : Entity_Id);
1171 -- If type Typ is subject to pragma Default_Initial_Condition, build the
1172 -- body of the procedure which verifies the assumption of the pragma at
1173 -- run time. The generated body is added after the type declaration.
1174
1175 --------------------------------------------
1176 -- Build_Default_Init_Cond_Procedure_Body --
1177 --------------------------------------------
1178
1179 procedure Build_Default_Init_Cond_Procedure_Body (Typ : Entity_Id) is
1180 Param_Id : Entity_Id;
1181 -- The entity of the sole formal parameter of the default initial
1182 -- condition procedure.
1183
1184 procedure Replace_Type_Reference (N : Node_Id);
1185 -- Replace a single reference to type Typ with a reference to formal
1186 -- parameter Param_Id.
1187
1188 ----------------------------
1189 -- Replace_Type_Reference --
1190 ----------------------------
1191
1192 procedure Replace_Type_Reference (N : Node_Id) is
1193 begin
1194 Rewrite (N, New_Occurrence_Of (Param_Id, Sloc (N)));
1195 end Replace_Type_Reference;
1196
1197 procedure Replace_Type_References is
1198 new Replace_Type_References_Generic (Replace_Type_Reference);
1199
1200 -- Local variables
1201
1202 Loc : constant Source_Ptr := Sloc (Typ);
1203 Prag : constant Node_Id :=
1204 Get_Pragma (Typ, Pragma_Default_Initial_Condition);
1205 Proc_Id : constant Entity_Id := Default_Init_Cond_Procedure (Typ);
1206 Spec_Decl : constant Node_Id := Unit_Declaration_Node (Proc_Id);
1207 Body_Decl : Node_Id;
1208 Expr : Node_Id;
1209 Stmt : Node_Id;
1210
1211 Save_Ghost_Mode : constant Ghost_Mode_Type := Ghost_Mode;
1212
1213 -- Start of processing for Build_Default_Init_Cond_Procedure_Body
1214
1215 begin
1216 -- The procedure should be generated only for [sub]types subject to
1217 -- pragma Default_Initial_Condition. Types that inherit the pragma do
1218 -- not get this specialized procedure.
1219
1220 pragma Assert (Has_Default_Init_Cond (Typ));
1221 pragma Assert (Present (Prag));
1222 pragma Assert (Present (Proc_Id));
1223
1224 -- Nothing to do if the body was already built
1225
1226 if Present (Corresponding_Body (Spec_Decl)) then
1227 return;
1228 end if;
1229
1230 -- The related type may be subject to pragma Ghost. Set the mode now
1231 -- to ensure that the analysis and expansion produce Ghost nodes.
1232
1233 Set_Ghost_Mode_From_Entity (Typ);
1234
1235 Param_Id := First_Formal (Proc_Id);
1236
1237 -- The pragma has an argument. Note that the argument is analyzed
1238 -- after all references to the current instance of the type are
1239 -- replaced.
1240
1241 if Present (Pragma_Argument_Associations (Prag)) then
1242 Expr :=
1243 Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
1244
1245 if Nkind (Expr) = N_Null then
1246 Stmt := Make_Null_Statement (Loc);
1247
1248 -- Preserve the original argument of the pragma by replicating it.
1249 -- Replace all references to the current instance of the type with
1250 -- references to the formal parameter.
1251
1252 else
1253 Expr := New_Copy_Tree (Expr);
1254 Replace_Type_References (Expr, Typ);
1255
1256 -- Generate:
1257 -- pragma Check (Default_Initial_Condition, <Expr>);
1258
1259 Stmt :=
1260 Make_Pragma (Loc,
1261 Pragma_Identifier =>
1262 Make_Identifier (Loc, Name_Check),
1263
1264 Pragma_Argument_Associations => New_List (
1265 Make_Pragma_Argument_Association (Loc,
1266 Expression =>
1267 Make_Identifier (Loc,
1268 Chars => Name_Default_Initial_Condition)),
1269 Make_Pragma_Argument_Association (Loc,
1270 Expression => Expr)));
1271 end if;
1272
1273 -- Otherwise the pragma appears without an argument
1274
1275 else
1276 Stmt := Make_Null_Statement (Loc);
1277 end if;
1278
1279 -- Generate:
1280 -- procedure <Typ>Default_Init_Cond (I : <Typ>) is
1281 -- begin
1282 -- <Stmt>;
1283 -- end <Typ>Default_Init_Cond;
1284
1285 Body_Decl :=
1286 Make_Subprogram_Body (Loc,
1287 Specification =>
1288 Copy_Separate_Tree (Specification (Spec_Decl)),
1289 Declarations => Empty_List,
1290 Handled_Statement_Sequence =>
1291 Make_Handled_Sequence_Of_Statements (Loc,
1292 Statements => New_List (Stmt)));
1293
1294 -- Link the spec and body of the default initial condition procedure
1295 -- to prevent the generation of a duplicate body.
1296
1297 Set_Corresponding_Body (Spec_Decl, Defining_Entity (Body_Decl));
1298 Set_Corresponding_Spec (Body_Decl, Proc_Id);
1299
1300 Insert_After_And_Analyze (Declaration_Node (Typ), Body_Decl);
1301 Ghost_Mode := Save_Ghost_Mode;
1302 end Build_Default_Init_Cond_Procedure_Body;
1303
1304 -- Local variables
1305
1306 Decl : Node_Id;
1307 Typ : Entity_Id;
1308
1309 -- Start of processing for Build_Default_Init_Cond_Procedure_Bodies
1310
1311 begin
1312 -- Inspect the private declarations looking for [sub]type declarations
1313
1314 Decl := First (Priv_Decls);
1315 while Present (Decl) loop
1316 if Nkind_In (Decl, N_Full_Type_Declaration,
1317 N_Subtype_Declaration)
1318 then
1319 Typ := Defining_Entity (Decl);
1320
1321 -- Guard against partially decorate types due to previous errors
1322
1323 if Is_Type (Typ) then
1324
1325 -- If the type is subject to pragma Default_Initial_Condition,
1326 -- generate the body of the internal procedure which verifies
1327 -- the assertion of the pragma at run time.
1328
1329 if Has_Default_Init_Cond (Typ) then
1330 Build_Default_Init_Cond_Procedure_Body (Typ);
1331
1332 -- A derived type inherits the default initial condition
1333 -- procedure from its parent type.
1334
1335 elsif Has_Inherited_Default_Init_Cond (Typ) then
1336 Inherit_Default_Init_Cond_Procedure (Typ);
1337 end if;
1338 end if;
1339 end if;
1340
1341 Next (Decl);
1342 end loop;
1343 end Build_Default_Init_Cond_Procedure_Bodies;
1344
1345 ---------------------------------------------------
1346 -- Build_Default_Init_Cond_Procedure_Declaration --
1347 ---------------------------------------------------
1348
1349 procedure Build_Default_Init_Cond_Procedure_Declaration (Typ : Entity_Id) is
1350 Loc : constant Source_Ptr := Sloc (Typ);
1351 Prag : constant Node_Id :=
1352 Get_Pragma (Typ, Pragma_Default_Initial_Condition);
1353
1354 Save_Ghost_Mode : constant Ghost_Mode_Type := Ghost_Mode;
1355
1356 Proc_Id : Entity_Id;
1357
1358 begin
1359 -- The procedure should be generated only for types subject to pragma
1360 -- Default_Initial_Condition. Types that inherit the pragma do not get
1361 -- this specialized procedure.
1362
1363 pragma Assert (Has_Default_Init_Cond (Typ));
1364 pragma Assert (Present (Prag));
1365
1366 -- Nothing to do if default initial condition procedure already built
1367
1368 if Present (Default_Init_Cond_Procedure (Typ)) then
1369 return;
1370 end if;
1371
1372 -- The related type may be subject to pragma Ghost. Set the mode now to
1373 -- ensure that the analysis and expansion produce Ghost nodes.
1374
1375 Set_Ghost_Mode_From_Entity (Typ);
1376
1377 Proc_Id :=
1378 Make_Defining_Identifier (Loc,
1379 Chars => New_External_Name (Chars (Typ), "Default_Init_Cond"));
1380
1381 -- Associate default initial condition procedure with the private type
1382
1383 Set_Ekind (Proc_Id, E_Procedure);
1384 Set_Is_Default_Init_Cond_Procedure (Proc_Id);
1385 Set_Default_Init_Cond_Procedure (Typ, Proc_Id);
1386
1387 -- Mark the default initial condition procedure explicitly as Ghost
1388 -- because it does not come from source.
1389
1390 if Ghost_Mode > None then
1391 Set_Is_Ghost_Entity (Proc_Id);
1392 end if;
1393
1394 -- Generate:
1395 -- procedure <Typ>Default_Init_Cond (Inn : <Typ>);
1396
1397 Insert_After_And_Analyze (Prag,
1398 Make_Subprogram_Declaration (Loc,
1399 Specification =>
1400 Make_Procedure_Specification (Loc,
1401 Defining_Unit_Name => Proc_Id,
1402 Parameter_Specifications => New_List (
1403 Make_Parameter_Specification (Loc,
1404 Defining_Identifier => Make_Temporary (Loc, 'I'),
1405 Parameter_Type => New_Occurrence_Of (Typ, Loc))))));
1406
1407 Ghost_Mode := Save_Ghost_Mode;
1408 end Build_Default_Init_Cond_Procedure_Declaration;
1409
1410 ---------------------------
1411 -- Build_Default_Subtype --
1412 ---------------------------
1413
1414 function Build_Default_Subtype
1415 (T : Entity_Id;
1416 N : Node_Id) return Entity_Id
1417 is
1418 Loc : constant Source_Ptr := Sloc (N);
1419 Disc : Entity_Id;
1420
1421 Bas : Entity_Id;
1422 -- The base type that is to be constrained by the defaults
1423
1424 begin
1425 if not Has_Discriminants (T) or else Is_Constrained (T) then
1426 return T;
1427 end if;
1428
1429 Bas := Base_Type (T);
1430
1431 -- If T is non-private but its base type is private, this is the
1432 -- completion of a subtype declaration whose parent type is private
1433 -- (see Complete_Private_Subtype in Sem_Ch3). The proper discriminants
1434 -- are to be found in the full view of the base. Check that the private
1435 -- status of T and its base differ.
1436
1437 if Is_Private_Type (Bas)
1438 and then not Is_Private_Type (T)
1439 and then Present (Full_View (Bas))
1440 then
1441 Bas := Full_View (Bas);
1442 end if;
1443
1444 Disc := First_Discriminant (T);
1445
1446 if No (Discriminant_Default_Value (Disc)) then
1447 return T;
1448 end if;
1449
1450 declare
1451 Act : constant Entity_Id := Make_Temporary (Loc, 'S');
1452 Constraints : constant List_Id := New_List;
1453 Decl : Node_Id;
1454
1455 begin
1456 while Present (Disc) loop
1457 Append_To (Constraints,
1458 New_Copy_Tree (Discriminant_Default_Value (Disc)));
1459 Next_Discriminant (Disc);
1460 end loop;
1461
1462 Decl :=
1463 Make_Subtype_Declaration (Loc,
1464 Defining_Identifier => Act,
1465 Subtype_Indication =>
1466 Make_Subtype_Indication (Loc,
1467 Subtype_Mark => New_Occurrence_Of (Bas, Loc),
1468 Constraint =>
1469 Make_Index_Or_Discriminant_Constraint (Loc,
1470 Constraints => Constraints)));
1471
1472 Insert_Action (N, Decl);
1473
1474 -- If the context is a component declaration the subtype declaration
1475 -- will be analyzed when the enclosing type is frozen, otherwise do
1476 -- it now.
1477
1478 if Ekind (Current_Scope) /= E_Record_Type then
1479 Analyze (Decl);
1480 end if;
1481
1482 return Act;
1483 end;
1484 end Build_Default_Subtype;
1485
1486 --------------------------------------------
1487 -- Build_Discriminal_Subtype_Of_Component --
1488 --------------------------------------------
1489
1490 function Build_Discriminal_Subtype_Of_Component
1491 (T : Entity_Id) return Node_Id
1492 is
1493 Loc : constant Source_Ptr := Sloc (T);
1494 D : Elmt_Id;
1495 Id : Node_Id;
1496
1497 function Build_Discriminal_Array_Constraint return List_Id;
1498 -- If one or more of the bounds of the component depends on
1499 -- discriminants, build actual constraint using the discriminants
1500 -- of the prefix.
1501
1502 function Build_Discriminal_Record_Constraint return List_Id;
1503 -- Similar to previous one, for discriminated components constrained by
1504 -- the discriminant of the enclosing object.
1505
1506 ----------------------------------------
1507 -- Build_Discriminal_Array_Constraint --
1508 ----------------------------------------
1509
1510 function Build_Discriminal_Array_Constraint return List_Id is
1511 Constraints : constant List_Id := New_List;
1512 Indx : Node_Id;
1513 Hi : Node_Id;
1514 Lo : Node_Id;
1515 Old_Hi : Node_Id;
1516 Old_Lo : Node_Id;
1517
1518 begin
1519 Indx := First_Index (T);
1520 while Present (Indx) loop
1521 Old_Lo := Type_Low_Bound (Etype (Indx));
1522 Old_Hi := Type_High_Bound (Etype (Indx));
1523
1524 if Denotes_Discriminant (Old_Lo) then
1525 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
1526
1527 else
1528 Lo := New_Copy_Tree (Old_Lo);
1529 end if;
1530
1531 if Denotes_Discriminant (Old_Hi) then
1532 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
1533
1534 else
1535 Hi := New_Copy_Tree (Old_Hi);
1536 end if;
1537
1538 Append (Make_Range (Loc, Lo, Hi), Constraints);
1539 Next_Index (Indx);
1540 end loop;
1541
1542 return Constraints;
1543 end Build_Discriminal_Array_Constraint;
1544
1545 -----------------------------------------
1546 -- Build_Discriminal_Record_Constraint --
1547 -----------------------------------------
1548
1549 function Build_Discriminal_Record_Constraint return List_Id is
1550 Constraints : constant List_Id := New_List;
1551 D : Elmt_Id;
1552 D_Val : Node_Id;
1553
1554 begin
1555 D := First_Elmt (Discriminant_Constraint (T));
1556 while Present (D) loop
1557 if Denotes_Discriminant (Node (D)) then
1558 D_Val :=
1559 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
1560 else
1561 D_Val := New_Copy_Tree (Node (D));
1562 end if;
1563
1564 Append (D_Val, Constraints);
1565 Next_Elmt (D);
1566 end loop;
1567
1568 return Constraints;
1569 end Build_Discriminal_Record_Constraint;
1570
1571 -- Start of processing for Build_Discriminal_Subtype_Of_Component
1572
1573 begin
1574 if Ekind (T) = E_Array_Subtype then
1575 Id := First_Index (T);
1576 while Present (Id) loop
1577 if Denotes_Discriminant (Type_Low_Bound (Etype (Id)))
1578 or else
1579 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
1580 then
1581 return Build_Component_Subtype
1582 (Build_Discriminal_Array_Constraint, Loc, T);
1583 end if;
1584
1585 Next_Index (Id);
1586 end loop;
1587
1588 elsif Ekind (T) = E_Record_Subtype
1589 and then Has_Discriminants (T)
1590 and then not Has_Unknown_Discriminants (T)
1591 then
1592 D := First_Elmt (Discriminant_Constraint (T));
1593 while Present (D) loop
1594 if Denotes_Discriminant (Node (D)) then
1595 return Build_Component_Subtype
1596 (Build_Discriminal_Record_Constraint, Loc, T);
1597 end if;
1598
1599 Next_Elmt (D);
1600 end loop;
1601 end if;
1602
1603 -- If none of the above, the actual and nominal subtypes are the same
1604
1605 return Empty;
1606 end Build_Discriminal_Subtype_Of_Component;
1607
1608 ------------------------------
1609 -- Build_Elaboration_Entity --
1610 ------------------------------
1611
1612 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
1613 Loc : constant Source_Ptr := Sloc (N);
1614 Decl : Node_Id;
1615 Elab_Ent : Entity_Id;
1616
1617 procedure Set_Package_Name (Ent : Entity_Id);
1618 -- Given an entity, sets the fully qualified name of the entity in
1619 -- Name_Buffer, with components separated by double underscores. This
1620 -- is a recursive routine that climbs the scope chain to Standard.
1621
1622 ----------------------
1623 -- Set_Package_Name --
1624 ----------------------
1625
1626 procedure Set_Package_Name (Ent : Entity_Id) is
1627 begin
1628 if Scope (Ent) /= Standard_Standard then
1629 Set_Package_Name (Scope (Ent));
1630
1631 declare
1632 Nam : constant String := Get_Name_String (Chars (Ent));
1633 begin
1634 Name_Buffer (Name_Len + 1) := '_';
1635 Name_Buffer (Name_Len + 2) := '_';
1636 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
1637 Name_Len := Name_Len + Nam'Length + 2;
1638 end;
1639
1640 else
1641 Get_Name_String (Chars (Ent));
1642 end if;
1643 end Set_Package_Name;
1644
1645 -- Start of processing for Build_Elaboration_Entity
1646
1647 begin
1648 -- Ignore call if already constructed
1649
1650 if Present (Elaboration_Entity (Spec_Id)) then
1651 return;
1652
1653 -- Ignore in ASIS mode, elaboration entity is not in source and plays
1654 -- no role in analysis.
1655
1656 elsif ASIS_Mode then
1657 return;
1658
1659 -- See if we need elaboration entity. We always need it for the dynamic
1660 -- elaboration model, since it is needed to properly generate the PE
1661 -- exception for access before elaboration.
1662
1663 elsif Dynamic_Elaboration_Checks then
1664 null;
1665
1666 -- For the static model, we don't need the elaboration counter if this
1667 -- unit is sure to have no elaboration code, since that means there
1668 -- is no elaboration unit to be called. Note that we can't just decide
1669 -- after the fact by looking to see whether there was elaboration code,
1670 -- because that's too late to make this decision.
1671
1672 elsif Restriction_Active (No_Elaboration_Code) then
1673 return;
1674
1675 -- Similarly, for the static model, we can skip the elaboration counter
1676 -- if we have the No_Multiple_Elaboration restriction, since for the
1677 -- static model, that's the only purpose of the counter (to avoid
1678 -- multiple elaboration).
1679
1680 elsif Restriction_Active (No_Multiple_Elaboration) then
1681 return;
1682 end if;
1683
1684 -- Here we need the elaboration entity
1685
1686 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
1687 -- name with dots replaced by double underscore. We have to manually
1688 -- construct this name, since it will be elaborated in the outer scope,
1689 -- and thus will not have the unit name automatically prepended.
1690
1691 Set_Package_Name (Spec_Id);
1692 Add_Str_To_Name_Buffer ("_E");
1693
1694 -- Create elaboration counter
1695
1696 Elab_Ent := Make_Defining_Identifier (Loc, Chars => Name_Find);
1697 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
1698
1699 Decl :=
1700 Make_Object_Declaration (Loc,
1701 Defining_Identifier => Elab_Ent,
1702 Object_Definition =>
1703 New_Occurrence_Of (Standard_Short_Integer, Loc),
1704 Expression => Make_Integer_Literal (Loc, Uint_0));
1705
1706 Push_Scope (Standard_Standard);
1707 Add_Global_Declaration (Decl);
1708 Pop_Scope;
1709
1710 -- Reset True_Constant indication, since we will indeed assign a value
1711 -- to the variable in the binder main. We also kill the Current_Value
1712 -- and Last_Assignment fields for the same reason.
1713
1714 Set_Is_True_Constant (Elab_Ent, False);
1715 Set_Current_Value (Elab_Ent, Empty);
1716 Set_Last_Assignment (Elab_Ent, Empty);
1717
1718 -- We do not want any further qualification of the name (if we did not
1719 -- do this, we would pick up the name of the generic package in the case
1720 -- of a library level generic instantiation).
1721
1722 Set_Has_Qualified_Name (Elab_Ent);
1723 Set_Has_Fully_Qualified_Name (Elab_Ent);
1724 end Build_Elaboration_Entity;
1725
1726 --------------------------------
1727 -- Build_Explicit_Dereference --
1728 --------------------------------
1729
1730 procedure Build_Explicit_Dereference
1731 (Expr : Node_Id;
1732 Disc : Entity_Id)
1733 is
1734 Loc : constant Source_Ptr := Sloc (Expr);
1735
1736 begin
1737 -- An entity of a type with a reference aspect is overloaded with
1738 -- both interpretations: with and without the dereference. Now that
1739 -- the dereference is made explicit, set the type of the node properly,
1740 -- to prevent anomalies in the backend. Same if the expression is an
1741 -- overloaded function call whose return type has a reference aspect.
1742
1743 if Is_Entity_Name (Expr) then
1744 Set_Etype (Expr, Etype (Entity (Expr)));
1745
1746 elsif Nkind (Expr) = N_Function_Call then
1747 Set_Etype (Expr, Etype (Name (Expr)));
1748 end if;
1749
1750 Set_Is_Overloaded (Expr, False);
1751
1752 -- The expression will often be a generalized indexing that yields a
1753 -- container element that is then dereferenced, in which case the
1754 -- generalized indexing call is also non-overloaded.
1755
1756 if Nkind (Expr) = N_Indexed_Component
1757 and then Present (Generalized_Indexing (Expr))
1758 then
1759 Set_Is_Overloaded (Generalized_Indexing (Expr), False);
1760 end if;
1761
1762 Rewrite (Expr,
1763 Make_Explicit_Dereference (Loc,
1764 Prefix =>
1765 Make_Selected_Component (Loc,
1766 Prefix => Relocate_Node (Expr),
1767 Selector_Name => New_Occurrence_Of (Disc, Loc))));
1768 Set_Etype (Prefix (Expr), Etype (Disc));
1769 Set_Etype (Expr, Designated_Type (Etype (Disc)));
1770 end Build_Explicit_Dereference;
1771
1772 -----------------------------------
1773 -- Cannot_Raise_Constraint_Error --
1774 -----------------------------------
1775
1776 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
1777 begin
1778 if Compile_Time_Known_Value (Expr) then
1779 return True;
1780
1781 elsif Do_Range_Check (Expr) then
1782 return False;
1783
1784 elsif Raises_Constraint_Error (Expr) then
1785 return False;
1786
1787 else
1788 case Nkind (Expr) is
1789 when N_Identifier =>
1790 return True;
1791
1792 when N_Expanded_Name =>
1793 return True;
1794
1795 when N_Selected_Component =>
1796 return not Do_Discriminant_Check (Expr);
1797
1798 when N_Attribute_Reference =>
1799 if Do_Overflow_Check (Expr) then
1800 return False;
1801
1802 elsif No (Expressions (Expr)) then
1803 return True;
1804
1805 else
1806 declare
1807 N : Node_Id;
1808
1809 begin
1810 N := First (Expressions (Expr));
1811 while Present (N) loop
1812 if Cannot_Raise_Constraint_Error (N) then
1813 Next (N);
1814 else
1815 return False;
1816 end if;
1817 end loop;
1818
1819 return True;
1820 end;
1821 end if;
1822
1823 when N_Type_Conversion =>
1824 if Do_Overflow_Check (Expr)
1825 or else Do_Length_Check (Expr)
1826 or else Do_Tag_Check (Expr)
1827 then
1828 return False;
1829 else
1830 return Cannot_Raise_Constraint_Error (Expression (Expr));
1831 end if;
1832
1833 when N_Unchecked_Type_Conversion =>
1834 return Cannot_Raise_Constraint_Error (Expression (Expr));
1835
1836 when N_Unary_Op =>
1837 if Do_Overflow_Check (Expr) then
1838 return False;
1839 else
1840 return Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1841 end if;
1842
1843 when N_Op_Divide |
1844 N_Op_Mod |
1845 N_Op_Rem
1846 =>
1847 if Do_Division_Check (Expr)
1848 or else
1849 Do_Overflow_Check (Expr)
1850 then
1851 return False;
1852 else
1853 return
1854 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1855 and then
1856 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1857 end if;
1858
1859 when N_Op_Add |
1860 N_Op_And |
1861 N_Op_Concat |
1862 N_Op_Eq |
1863 N_Op_Expon |
1864 N_Op_Ge |
1865 N_Op_Gt |
1866 N_Op_Le |
1867 N_Op_Lt |
1868 N_Op_Multiply |
1869 N_Op_Ne |
1870 N_Op_Or |
1871 N_Op_Rotate_Left |
1872 N_Op_Rotate_Right |
1873 N_Op_Shift_Left |
1874 N_Op_Shift_Right |
1875 N_Op_Shift_Right_Arithmetic |
1876 N_Op_Subtract |
1877 N_Op_Xor
1878 =>
1879 if Do_Overflow_Check (Expr) then
1880 return False;
1881 else
1882 return
1883 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1884 and then
1885 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1886 end if;
1887
1888 when others =>
1889 return False;
1890 end case;
1891 end if;
1892 end Cannot_Raise_Constraint_Error;
1893
1894 -----------------------------------------
1895 -- Check_Dynamically_Tagged_Expression --
1896 -----------------------------------------
1897
1898 procedure Check_Dynamically_Tagged_Expression
1899 (Expr : Node_Id;
1900 Typ : Entity_Id;
1901 Related_Nod : Node_Id)
1902 is
1903 begin
1904 pragma Assert (Is_Tagged_Type (Typ));
1905
1906 -- In order to avoid spurious errors when analyzing the expanded code,
1907 -- this check is done only for nodes that come from source and for
1908 -- actuals of generic instantiations.
1909
1910 if (Comes_From_Source (Related_Nod)
1911 or else In_Generic_Actual (Expr))
1912 and then (Is_Class_Wide_Type (Etype (Expr))
1913 or else Is_Dynamically_Tagged (Expr))
1914 and then Is_Tagged_Type (Typ)
1915 and then not Is_Class_Wide_Type (Typ)
1916 then
1917 Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
1918 end if;
1919 end Check_Dynamically_Tagged_Expression;
1920
1921 --------------------------
1922 -- Check_Fully_Declared --
1923 --------------------------
1924
1925 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
1926 begin
1927 if Ekind (T) = E_Incomplete_Type then
1928
1929 -- Ada 2005 (AI-50217): If the type is available through a limited
1930 -- with_clause, verify that its full view has been analyzed.
1931
1932 if From_Limited_With (T)
1933 and then Present (Non_Limited_View (T))
1934 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
1935 then
1936 -- The non-limited view is fully declared
1937
1938 null;
1939
1940 else
1941 Error_Msg_NE
1942 ("premature usage of incomplete}", N, First_Subtype (T));
1943 end if;
1944
1945 -- Need comments for these tests ???
1946
1947 elsif Has_Private_Component (T)
1948 and then not Is_Generic_Type (Root_Type (T))
1949 and then not In_Spec_Expression
1950 then
1951 -- Special case: if T is the anonymous type created for a single
1952 -- task or protected object, use the name of the source object.
1953
1954 if Is_Concurrent_Type (T)
1955 and then not Comes_From_Source (T)
1956 and then Nkind (N) = N_Object_Declaration
1957 then
1958 Error_Msg_NE
1959 ("type of& has incomplete component",
1960 N, Defining_Identifier (N));
1961 else
1962 Error_Msg_NE
1963 ("premature usage of incomplete}",
1964 N, First_Subtype (T));
1965 end if;
1966 end if;
1967 end Check_Fully_Declared;
1968
1969 -------------------------------------------
1970 -- Check_Function_With_Address_Parameter --
1971 -------------------------------------------
1972
1973 procedure Check_Function_With_Address_Parameter (Subp_Id : Entity_Id) is
1974 F : Entity_Id;
1975 T : Entity_Id;
1976
1977 begin
1978 F := First_Formal (Subp_Id);
1979 while Present (F) loop
1980 T := Etype (F);
1981
1982 if Is_Private_Type (T) and then Present (Full_View (T)) then
1983 T := Full_View (T);
1984 end if;
1985
1986 if Is_Descendent_Of_Address (T) or else Is_Limited_Type (T) then
1987 Set_Is_Pure (Subp_Id, False);
1988 exit;
1989 end if;
1990
1991 Next_Formal (F);
1992 end loop;
1993 end Check_Function_With_Address_Parameter;
1994
1995 -------------------------------------
1996 -- Check_Function_Writable_Actuals --
1997 -------------------------------------
1998
1999 procedure Check_Function_Writable_Actuals (N : Node_Id) is
2000 Writable_Actuals_List : Elist_Id := No_Elist;
2001 Identifiers_List : Elist_Id := No_Elist;
2002 Aggr_Error_Node : Node_Id := Empty;
2003 Error_Node : Node_Id := Empty;
2004
2005 procedure Collect_Identifiers (N : Node_Id);
2006 -- In a single traversal of subtree N collect in Writable_Actuals_List
2007 -- all the actuals of functions with writable actuals, and in the list
2008 -- Identifiers_List collect all the identifiers that are not actuals of
2009 -- functions with writable actuals. If a writable actual is referenced
2010 -- twice as writable actual then Error_Node is set to reference its
2011 -- second occurrence, the error is reported, and the tree traversal
2012 -- is abandoned.
2013
2014 function Get_Function_Id (Call : Node_Id) return Entity_Id;
2015 -- Return the entity associated with the function call
2016
2017 procedure Preanalyze_Without_Errors (N : Node_Id);
2018 -- Preanalyze N without reporting errors. Very dubious, you can't just
2019 -- go analyzing things more than once???
2020
2021 -------------------------
2022 -- Collect_Identifiers --
2023 -------------------------
2024
2025 procedure Collect_Identifiers (N : Node_Id) is
2026
2027 function Check_Node (N : Node_Id) return Traverse_Result;
2028 -- Process a single node during the tree traversal to collect the
2029 -- writable actuals of functions and all the identifiers which are
2030 -- not writable actuals of functions.
2031
2032 function Contains (List : Elist_Id; N : Node_Id) return Boolean;
2033 -- Returns True if List has a node whose Entity is Entity (N)
2034
2035 -------------------------
2036 -- Check_Function_Call --
2037 -------------------------
2038
2039 function Check_Node (N : Node_Id) return Traverse_Result is
2040 Is_Writable_Actual : Boolean := False;
2041 Id : Entity_Id;
2042
2043 begin
2044 if Nkind (N) = N_Identifier then
2045
2046 -- No analysis possible if the entity is not decorated
2047
2048 if No (Entity (N)) then
2049 return Skip;
2050
2051 -- Don't collect identifiers of packages, called functions, etc
2052
2053 elsif Ekind_In (Entity (N), E_Package,
2054 E_Function,
2055 E_Procedure,
2056 E_Entry)
2057 then
2058 return Skip;
2059
2060 -- For rewritten nodes, continue the traversal in the original
2061 -- subtree. Needed to handle aggregates in original expressions
2062 -- extracted from the tree by Remove_Side_Effects.
2063
2064 elsif Is_Rewrite_Substitution (N) then
2065 Collect_Identifiers (Original_Node (N));
2066 return Skip;
2067
2068 -- For now we skip aggregate discriminants, since they require
2069 -- performing the analysis in two phases to identify conflicts:
2070 -- first one analyzing discriminants and second one analyzing
2071 -- the rest of components (since at run time, discriminants are
2072 -- evaluated prior to components): too much computation cost
2073 -- to identify a corner case???
2074
2075 elsif Nkind (Parent (N)) = N_Component_Association
2076 and then Nkind_In (Parent (Parent (N)),
2077 N_Aggregate,
2078 N_Extension_Aggregate)
2079 then
2080 declare
2081 Choice : constant Node_Id := First (Choices (Parent (N)));
2082
2083 begin
2084 if Ekind (Entity (N)) = E_Discriminant then
2085 return Skip;
2086
2087 elsif Expression (Parent (N)) = N
2088 and then Nkind (Choice) = N_Identifier
2089 and then Ekind (Entity (Choice)) = E_Discriminant
2090 then
2091 return Skip;
2092 end if;
2093 end;
2094
2095 -- Analyze if N is a writable actual of a function
2096
2097 elsif Nkind (Parent (N)) = N_Function_Call then
2098 declare
2099 Call : constant Node_Id := Parent (N);
2100 Actual : Node_Id;
2101 Formal : Node_Id;
2102
2103 begin
2104 Id := Get_Function_Id (Call);
2105
2106 -- In case of previous error, no check is possible
2107
2108 if No (Id) then
2109 return Abandon;
2110 end if;
2111
2112 if Ekind_In (Id, E_Function, E_Generic_Function)
2113 and then Has_Out_Or_In_Out_Parameter (Id)
2114 then
2115 Formal := First_Formal (Id);
2116 Actual := First_Actual (Call);
2117 while Present (Actual) and then Present (Formal) loop
2118 if Actual = N then
2119 if Ekind_In (Formal, E_Out_Parameter,
2120 E_In_Out_Parameter)
2121 then
2122 Is_Writable_Actual := True;
2123 end if;
2124
2125 exit;
2126 end if;
2127
2128 Next_Formal (Formal);
2129 Next_Actual (Actual);
2130 end loop;
2131 end if;
2132 end;
2133 end if;
2134
2135 if Is_Writable_Actual then
2136
2137 -- Skip checking the error in non-elementary types since
2138 -- RM 6.4.1(6.15/3) is restricted to elementary types, but
2139 -- store this actual in Writable_Actuals_List since it is
2140 -- needed to perform checks on other constructs that have
2141 -- arbitrary order of evaluation (for example, aggregates).
2142
2143 if not Is_Elementary_Type (Etype (N)) then
2144 if not Contains (Writable_Actuals_List, N) then
2145 Append_New_Elmt (N, To => Writable_Actuals_List);
2146 end if;
2147
2148 -- Second occurrence of an elementary type writable actual
2149
2150 elsif Contains (Writable_Actuals_List, N) then
2151
2152 -- Report the error on the second occurrence of the
2153 -- identifier. We cannot assume that N is the second
2154 -- occurrence (according to their location in the
2155 -- sources), since Traverse_Func walks through Field2
2156 -- last (see comment in the body of Traverse_Func).
2157
2158 declare
2159 Elmt : Elmt_Id;
2160
2161 begin
2162 Elmt := First_Elmt (Writable_Actuals_List);
2163 while Present (Elmt)
2164 and then Entity (Node (Elmt)) /= Entity (N)
2165 loop
2166 Next_Elmt (Elmt);
2167 end loop;
2168
2169 if Sloc (N) > Sloc (Node (Elmt)) then
2170 Error_Node := N;
2171 else
2172 Error_Node := Node (Elmt);
2173 end if;
2174
2175 Error_Msg_NE
2176 ("value may be affected by call to & "
2177 & "because order of evaluation is arbitrary",
2178 Error_Node, Id);
2179 return Abandon;
2180 end;
2181
2182 -- First occurrence of a elementary type writable actual
2183
2184 else
2185 Append_New_Elmt (N, To => Writable_Actuals_List);
2186 end if;
2187
2188 else
2189 if Identifiers_List = No_Elist then
2190 Identifiers_List := New_Elmt_List;
2191 end if;
2192
2193 Append_Unique_Elmt (N, Identifiers_List);
2194 end if;
2195 end if;
2196
2197 return OK;
2198 end Check_Node;
2199
2200 --------------
2201 -- Contains --
2202 --------------
2203
2204 function Contains
2205 (List : Elist_Id;
2206 N : Node_Id) return Boolean
2207 is
2208 pragma Assert (Nkind (N) in N_Has_Entity);
2209
2210 Elmt : Elmt_Id;
2211
2212 begin
2213 if List = No_Elist then
2214 return False;
2215 end if;
2216
2217 Elmt := First_Elmt (List);
2218 while Present (Elmt) loop
2219 if Entity (Node (Elmt)) = Entity (N) then
2220 return True;
2221 else
2222 Next_Elmt (Elmt);
2223 end if;
2224 end loop;
2225
2226 return False;
2227 end Contains;
2228
2229 ------------------
2230 -- Do_Traversal --
2231 ------------------
2232
2233 procedure Do_Traversal is new Traverse_Proc (Check_Node);
2234 -- The traversal procedure
2235
2236 -- Start of processing for Collect_Identifiers
2237
2238 begin
2239 if Present (Error_Node) then
2240 return;
2241 end if;
2242
2243 if Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then
2244 return;
2245 end if;
2246
2247 Do_Traversal (N);
2248 end Collect_Identifiers;
2249
2250 ---------------------
2251 -- Get_Function_Id --
2252 ---------------------
2253
2254 function Get_Function_Id (Call : Node_Id) return Entity_Id is
2255 Nam : constant Node_Id := Name (Call);
2256 Id : Entity_Id;
2257
2258 begin
2259 if Nkind (Nam) = N_Explicit_Dereference then
2260 Id := Etype (Nam);
2261 pragma Assert (Ekind (Id) = E_Subprogram_Type);
2262
2263 elsif Nkind (Nam) = N_Selected_Component then
2264 Id := Entity (Selector_Name (Nam));
2265
2266 elsif Nkind (Nam) = N_Indexed_Component then
2267 Id := Entity (Selector_Name (Prefix (Nam)));
2268
2269 else
2270 Id := Entity (Nam);
2271 end if;
2272
2273 return Id;
2274 end Get_Function_Id;
2275
2276 -------------------------------
2277 -- Preanalyze_Without_Errors --
2278 -------------------------------
2279
2280 procedure Preanalyze_Without_Errors (N : Node_Id) is
2281 Status : constant Boolean := Get_Ignore_Errors;
2282 begin
2283 Set_Ignore_Errors (True);
2284 Preanalyze (N);
2285 Set_Ignore_Errors (Status);
2286 end Preanalyze_Without_Errors;
2287
2288 -- Start of processing for Check_Function_Writable_Actuals
2289
2290 begin
2291 -- The check only applies to Ada 2012 code on which Check_Actuals has
2292 -- been set, and only to constructs that have multiple constituents
2293 -- whose order of evaluation is not specified by the language.
2294
2295 if Ada_Version < Ada_2012
2296 or else not Check_Actuals (N)
2297 or else (not (Nkind (N) in N_Op)
2298 and then not (Nkind (N) in N_Membership_Test)
2299 and then not Nkind_In (N, N_Range,
2300 N_Aggregate,
2301 N_Extension_Aggregate,
2302 N_Full_Type_Declaration,
2303 N_Function_Call,
2304 N_Procedure_Call_Statement,
2305 N_Entry_Call_Statement))
2306 or else (Nkind (N) = N_Full_Type_Declaration
2307 and then not Is_Record_Type (Defining_Identifier (N)))
2308
2309 -- In addition, this check only applies to source code, not to code
2310 -- generated by constraint checks.
2311
2312 or else not Comes_From_Source (N)
2313 then
2314 return;
2315 end if;
2316
2317 -- If a construct C has two or more direct constituents that are names
2318 -- or expressions whose evaluation may occur in an arbitrary order, at
2319 -- least one of which contains a function call with an in out or out
2320 -- parameter, then the construct is legal only if: for each name N that
2321 -- is passed as a parameter of mode in out or out to some inner function
2322 -- call C2 (not including the construct C itself), there is no other
2323 -- name anywhere within a direct constituent of the construct C other
2324 -- than the one containing C2, that is known to refer to the same
2325 -- object (RM 6.4.1(6.17/3)).
2326
2327 case Nkind (N) is
2328 when N_Range =>
2329 Collect_Identifiers (Low_Bound (N));
2330 Collect_Identifiers (High_Bound (N));
2331
2332 when N_Op | N_Membership_Test =>
2333 declare
2334 Expr : Node_Id;
2335
2336 begin
2337 Collect_Identifiers (Left_Opnd (N));
2338
2339 if Present (Right_Opnd (N)) then
2340 Collect_Identifiers (Right_Opnd (N));
2341 end if;
2342
2343 if Nkind_In (N, N_In, N_Not_In)
2344 and then Present (Alternatives (N))
2345 then
2346 Expr := First (Alternatives (N));
2347 while Present (Expr) loop
2348 Collect_Identifiers (Expr);
2349
2350 Next (Expr);
2351 end loop;
2352 end if;
2353 end;
2354
2355 when N_Full_Type_Declaration =>
2356 declare
2357 function Get_Record_Part (N : Node_Id) return Node_Id;
2358 -- Return the record part of this record type definition
2359
2360 function Get_Record_Part (N : Node_Id) return Node_Id is
2361 Type_Def : constant Node_Id := Type_Definition (N);
2362 begin
2363 if Nkind (Type_Def) = N_Derived_Type_Definition then
2364 return Record_Extension_Part (Type_Def);
2365 else
2366 return Type_Def;
2367 end if;
2368 end Get_Record_Part;
2369
2370 Comp : Node_Id;
2371 Def_Id : Entity_Id := Defining_Identifier (N);
2372 Rec : Node_Id := Get_Record_Part (N);
2373
2374 begin
2375 -- No need to perform any analysis if the record has no
2376 -- components
2377
2378 if No (Rec) or else No (Component_List (Rec)) then
2379 return;
2380 end if;
2381
2382 -- Collect the identifiers starting from the deepest
2383 -- derivation. Done to report the error in the deepest
2384 -- derivation.
2385
2386 loop
2387 if Present (Component_List (Rec)) then
2388 Comp := First (Component_Items (Component_List (Rec)));
2389 while Present (Comp) loop
2390 if Nkind (Comp) = N_Component_Declaration
2391 and then Present (Expression (Comp))
2392 then
2393 Collect_Identifiers (Expression (Comp));
2394 end if;
2395
2396 Next (Comp);
2397 end loop;
2398 end if;
2399
2400 exit when No (Underlying_Type (Etype (Def_Id)))
2401 or else Base_Type (Underlying_Type (Etype (Def_Id)))
2402 = Def_Id;
2403
2404 Def_Id := Base_Type (Underlying_Type (Etype (Def_Id)));
2405 Rec := Get_Record_Part (Parent (Def_Id));
2406 end loop;
2407 end;
2408
2409 when N_Subprogram_Call |
2410 N_Entry_Call_Statement =>
2411 declare
2412 Id : constant Entity_Id := Get_Function_Id (N);
2413 Formal : Node_Id;
2414 Actual : Node_Id;
2415
2416 begin
2417 Formal := First_Formal (Id);
2418 Actual := First_Actual (N);
2419 while Present (Actual) and then Present (Formal) loop
2420 if Ekind_In (Formal, E_Out_Parameter,
2421 E_In_Out_Parameter)
2422 then
2423 Collect_Identifiers (Actual);
2424 end if;
2425
2426 Next_Formal (Formal);
2427 Next_Actual (Actual);
2428 end loop;
2429 end;
2430
2431 when N_Aggregate |
2432 N_Extension_Aggregate =>
2433 declare
2434 Assoc : Node_Id;
2435 Choice : Node_Id;
2436 Comp_Expr : Node_Id;
2437
2438 begin
2439 -- Handle the N_Others_Choice of array aggregates with static
2440 -- bounds. There is no need to perform this analysis in
2441 -- aggregates without static bounds since we cannot evaluate
2442 -- if the N_Others_Choice covers several elements. There is
2443 -- no need to handle the N_Others choice of record aggregates
2444 -- since at this stage it has been already expanded by
2445 -- Resolve_Record_Aggregate.
2446
2447 if Is_Array_Type (Etype (N))
2448 and then Nkind (N) = N_Aggregate
2449 and then Present (Aggregate_Bounds (N))
2450 and then Compile_Time_Known_Bounds (Etype (N))
2451 and then Expr_Value (High_Bound (Aggregate_Bounds (N)))
2452 >
2453 Expr_Value (Low_Bound (Aggregate_Bounds (N)))
2454 then
2455 declare
2456 Count_Components : Uint := Uint_0;
2457 Num_Components : Uint;
2458 Others_Assoc : Node_Id;
2459 Others_Choice : Node_Id := Empty;
2460 Others_Box_Present : Boolean := False;
2461
2462 begin
2463 -- Count positional associations
2464
2465 if Present (Expressions (N)) then
2466 Comp_Expr := First (Expressions (N));
2467 while Present (Comp_Expr) loop
2468 Count_Components := Count_Components + 1;
2469 Next (Comp_Expr);
2470 end loop;
2471 end if;
2472
2473 -- Count the rest of elements and locate the N_Others
2474 -- choice (if any)
2475
2476 Assoc := First (Component_Associations (N));
2477 while Present (Assoc) loop
2478 Choice := First (Choices (Assoc));
2479 while Present (Choice) loop
2480 if Nkind (Choice) = N_Others_Choice then
2481 Others_Assoc := Assoc;
2482 Others_Choice := Choice;
2483 Others_Box_Present := Box_Present (Assoc);
2484
2485 -- Count several components
2486
2487 elsif Nkind_In (Choice, N_Range,
2488 N_Subtype_Indication)
2489 or else (Is_Entity_Name (Choice)
2490 and then Is_Type (Entity (Choice)))
2491 then
2492 declare
2493 L, H : Node_Id;
2494 begin
2495 Get_Index_Bounds (Choice, L, H);
2496 pragma Assert
2497 (Compile_Time_Known_Value (L)
2498 and then Compile_Time_Known_Value (H));
2499 Count_Components :=
2500 Count_Components
2501 + Expr_Value (H) - Expr_Value (L) + 1;
2502 end;
2503
2504 -- Count single component. No other case available
2505 -- since we are handling an aggregate with static
2506 -- bounds.
2507
2508 else
2509 pragma Assert (Is_OK_Static_Expression (Choice)
2510 or else Nkind (Choice) = N_Identifier
2511 or else Nkind (Choice) = N_Integer_Literal);
2512
2513 Count_Components := Count_Components + 1;
2514 end if;
2515
2516 Next (Choice);
2517 end loop;
2518
2519 Next (Assoc);
2520 end loop;
2521
2522 Num_Components :=
2523 Expr_Value (High_Bound (Aggregate_Bounds (N))) -
2524 Expr_Value (Low_Bound (Aggregate_Bounds (N))) + 1;
2525
2526 pragma Assert (Count_Components <= Num_Components);
2527
2528 -- Handle the N_Others choice if it covers several
2529 -- components
2530
2531 if Present (Others_Choice)
2532 and then (Num_Components - Count_Components) > 1
2533 then
2534 if not Others_Box_Present then
2535
2536 -- At this stage, if expansion is active, the
2537 -- expression of the others choice has not been
2538 -- analyzed. Hence we generate a duplicate and
2539 -- we analyze it silently to have available the
2540 -- minimum decoration required to collect the
2541 -- identifiers.
2542
2543 if not Expander_Active then
2544 Comp_Expr := Expression (Others_Assoc);
2545 else
2546 Comp_Expr :=
2547 New_Copy_Tree (Expression (Others_Assoc));
2548 Preanalyze_Without_Errors (Comp_Expr);
2549 end if;
2550
2551 Collect_Identifiers (Comp_Expr);
2552
2553 if Writable_Actuals_List /= No_Elist then
2554
2555 -- As suggested by Robert, at current stage we
2556 -- report occurrences of this case as warnings.
2557
2558 Error_Msg_N
2559 ("writable function parameter may affect "
2560 & "value in other component because order "
2561 & "of evaluation is unspecified??",
2562 Node (First_Elmt (Writable_Actuals_List)));
2563 end if;
2564 end if;
2565 end if;
2566 end;
2567
2568 -- For an array aggregate, a discrete_choice_list that has
2569 -- a nonstatic range is considered as two or more separate
2570 -- occurrences of the expression (RM 6.4.1(20/3)).
2571
2572 elsif Is_Array_Type (Etype (N))
2573 and then Nkind (N) = N_Aggregate
2574 and then Present (Aggregate_Bounds (N))
2575 and then not Compile_Time_Known_Bounds (Etype (N))
2576 then
2577 -- Collect identifiers found in the dynamic bounds
2578
2579 declare
2580 Count_Components : Natural := 0;
2581 Low, High : Node_Id;
2582
2583 begin
2584 Assoc := First (Component_Associations (N));
2585 while Present (Assoc) loop
2586 Choice := First (Choices (Assoc));
2587 while Present (Choice) loop
2588 if Nkind_In (Choice, N_Range,
2589 N_Subtype_Indication)
2590 or else (Is_Entity_Name (Choice)
2591 and then Is_Type (Entity (Choice)))
2592 then
2593 Get_Index_Bounds (Choice, Low, High);
2594
2595 if not Compile_Time_Known_Value (Low) then
2596 Collect_Identifiers (Low);
2597
2598 if No (Aggr_Error_Node) then
2599 Aggr_Error_Node := Low;
2600 end if;
2601 end if;
2602
2603 if not Compile_Time_Known_Value (High) then
2604 Collect_Identifiers (High);
2605
2606 if No (Aggr_Error_Node) then
2607 Aggr_Error_Node := High;
2608 end if;
2609 end if;
2610
2611 -- The RM rule is violated if there is more than
2612 -- a single choice in a component association.
2613
2614 else
2615 Count_Components := Count_Components + 1;
2616
2617 if No (Aggr_Error_Node)
2618 and then Count_Components > 1
2619 then
2620 Aggr_Error_Node := Choice;
2621 end if;
2622
2623 if not Compile_Time_Known_Value (Choice) then
2624 Collect_Identifiers (Choice);
2625 end if;
2626 end if;
2627
2628 Next (Choice);
2629 end loop;
2630
2631 Next (Assoc);
2632 end loop;
2633 end;
2634 end if;
2635
2636 -- Handle ancestor part of extension aggregates
2637
2638 if Nkind (N) = N_Extension_Aggregate then
2639 Collect_Identifiers (Ancestor_Part (N));
2640 end if;
2641
2642 -- Handle positional associations
2643
2644 if Present (Expressions (N)) then
2645 Comp_Expr := First (Expressions (N));
2646 while Present (Comp_Expr) loop
2647 if not Is_OK_Static_Expression (Comp_Expr) then
2648 Collect_Identifiers (Comp_Expr);
2649 end if;
2650
2651 Next (Comp_Expr);
2652 end loop;
2653 end if;
2654
2655 -- Handle discrete associations
2656
2657 if Present (Component_Associations (N)) then
2658 Assoc := First (Component_Associations (N));
2659 while Present (Assoc) loop
2660
2661 if not Box_Present (Assoc) then
2662 Choice := First (Choices (Assoc));
2663 while Present (Choice) loop
2664
2665 -- For now we skip discriminants since it requires
2666 -- performing the analysis in two phases: first one
2667 -- analyzing discriminants and second one analyzing
2668 -- the rest of components since discriminants are
2669 -- evaluated prior to components: too much extra
2670 -- work to detect a corner case???
2671
2672 if Nkind (Choice) in N_Has_Entity
2673 and then Present (Entity (Choice))
2674 and then Ekind (Entity (Choice)) = E_Discriminant
2675 then
2676 null;
2677
2678 elsif Box_Present (Assoc) then
2679 null;
2680
2681 else
2682 if not Analyzed (Expression (Assoc)) then
2683 Comp_Expr :=
2684 New_Copy_Tree (Expression (Assoc));
2685 Set_Parent (Comp_Expr, Parent (N));
2686 Preanalyze_Without_Errors (Comp_Expr);
2687 else
2688 Comp_Expr := Expression (Assoc);
2689 end if;
2690
2691 Collect_Identifiers (Comp_Expr);
2692 end if;
2693
2694 Next (Choice);
2695 end loop;
2696 end if;
2697
2698 Next (Assoc);
2699 end loop;
2700 end if;
2701 end;
2702
2703 when others =>
2704 return;
2705 end case;
2706
2707 -- No further action needed if we already reported an error
2708
2709 if Present (Error_Node) then
2710 return;
2711 end if;
2712
2713 -- Check violation of RM 6.20/3 in aggregates
2714
2715 if Present (Aggr_Error_Node)
2716 and then Writable_Actuals_List /= No_Elist
2717 then
2718 Error_Msg_N
2719 ("value may be affected by call in other component because they "
2720 & "are evaluated in unspecified order",
2721 Node (First_Elmt (Writable_Actuals_List)));
2722 return;
2723 end if;
2724
2725 -- Check if some writable argument of a function is referenced
2726
2727 if Writable_Actuals_List /= No_Elist
2728 and then Identifiers_List /= No_Elist
2729 then
2730 declare
2731 Elmt_1 : Elmt_Id;
2732 Elmt_2 : Elmt_Id;
2733
2734 begin
2735 Elmt_1 := First_Elmt (Writable_Actuals_List);
2736 while Present (Elmt_1) loop
2737 Elmt_2 := First_Elmt (Identifiers_List);
2738 while Present (Elmt_2) loop
2739 if Entity (Node (Elmt_1)) = Entity (Node (Elmt_2)) then
2740 case Nkind (Parent (Node (Elmt_2))) is
2741 when N_Aggregate |
2742 N_Component_Association |
2743 N_Component_Declaration =>
2744 Error_Msg_N
2745 ("value may be affected by call in other "
2746 & "component because they are evaluated "
2747 & "in unspecified order",
2748 Node (Elmt_2));
2749
2750 when N_In | N_Not_In =>
2751 Error_Msg_N
2752 ("value may be affected by call in other "
2753 & "alternative because they are evaluated "
2754 & "in unspecified order",
2755 Node (Elmt_2));
2756
2757 when others =>
2758 Error_Msg_N
2759 ("value of actual may be affected by call in "
2760 & "other actual because they are evaluated "
2761 & "in unspecified order",
2762 Node (Elmt_2));
2763 end case;
2764 end if;
2765
2766 Next_Elmt (Elmt_2);
2767 end loop;
2768
2769 Next_Elmt (Elmt_1);
2770 end loop;
2771 end;
2772 end if;
2773 end Check_Function_Writable_Actuals;
2774
2775 --------------------------------
2776 -- Check_Implicit_Dereference --
2777 --------------------------------
2778
2779 procedure Check_Implicit_Dereference (N : Node_Id; Typ : Entity_Id) is
2780 Disc : Entity_Id;
2781 Desig : Entity_Id;
2782 Nam : Node_Id;
2783
2784 begin
2785 if Nkind (N) = N_Indexed_Component
2786 and then Present (Generalized_Indexing (N))
2787 then
2788 Nam := Generalized_Indexing (N);
2789 else
2790 Nam := N;
2791 end if;
2792
2793 if Ada_Version < Ada_2012
2794 or else not Has_Implicit_Dereference (Base_Type (Typ))
2795 then
2796 return;
2797
2798 elsif not Comes_From_Source (N)
2799 and then Nkind (N) /= N_Indexed_Component
2800 then
2801 return;
2802
2803 elsif Is_Entity_Name (Nam) and then Is_Type (Entity (Nam)) then
2804 null;
2805
2806 else
2807 Disc := First_Discriminant (Typ);
2808 while Present (Disc) loop
2809 if Has_Implicit_Dereference (Disc) then
2810 Desig := Designated_Type (Etype (Disc));
2811 Add_One_Interp (Nam, Disc, Desig);
2812
2813 -- If the node is a generalized indexing, add interpretation
2814 -- to that node as well, for subsequent resolution.
2815
2816 if Nkind (N) = N_Indexed_Component then
2817 Add_One_Interp (N, Disc, Desig);
2818 end if;
2819
2820 -- If the operation comes from a generic unit and the context
2821 -- is a selected component, the selector name may be global
2822 -- and set in the instance already. Remove the entity to
2823 -- force resolution of the selected component, and the
2824 -- generation of an explicit dereference if needed.
2825
2826 if In_Instance
2827 and then Nkind (Parent (Nam)) = N_Selected_Component
2828 then
2829 Set_Entity (Selector_Name (Parent (Nam)), Empty);
2830 end if;
2831
2832 exit;
2833 end if;
2834
2835 Next_Discriminant (Disc);
2836 end loop;
2837 end if;
2838 end Check_Implicit_Dereference;
2839
2840 ----------------------------------
2841 -- Check_Internal_Protected_Use --
2842 ----------------------------------
2843
2844 procedure Check_Internal_Protected_Use (N : Node_Id; Nam : Entity_Id) is
2845 S : Entity_Id;
2846 Prot : Entity_Id;
2847
2848 begin
2849 S := Current_Scope;
2850 while Present (S) loop
2851 if S = Standard_Standard then
2852 return;
2853
2854 elsif Ekind (S) = E_Function
2855 and then Ekind (Scope (S)) = E_Protected_Type
2856 then
2857 Prot := Scope (S);
2858 exit;
2859 end if;
2860
2861 S := Scope (S);
2862 end loop;
2863
2864 if Scope (Nam) = Prot and then Ekind (Nam) /= E_Function then
2865
2866 -- An indirect function call (e.g. a callback within a protected
2867 -- function body) is not statically illegal. If the access type is
2868 -- anonymous and is the type of an access parameter, the scope of Nam
2869 -- will be the protected type, but it is not a protected operation.
2870
2871 if Ekind (Nam) = E_Subprogram_Type
2872 and then
2873 Nkind (Associated_Node_For_Itype (Nam)) = N_Function_Specification
2874 then
2875 null;
2876
2877 elsif Nkind (N) = N_Subprogram_Renaming_Declaration then
2878 Error_Msg_N
2879 ("within protected function cannot use protected "
2880 & "procedure in renaming or as generic actual", N);
2881
2882 elsif Nkind (N) = N_Attribute_Reference then
2883 Error_Msg_N
2884 ("within protected function cannot take access of "
2885 & " protected procedure", N);
2886
2887 else
2888 Error_Msg_N
2889 ("within protected function, protected object is constant", N);
2890 Error_Msg_N
2891 ("\cannot call operation that may modify it", N);
2892 end if;
2893 end if;
2894 end Check_Internal_Protected_Use;
2895
2896 ---------------------------------------
2897 -- Check_Later_Vs_Basic_Declarations --
2898 ---------------------------------------
2899
2900 procedure Check_Later_Vs_Basic_Declarations
2901 (Decls : List_Id;
2902 During_Parsing : Boolean)
2903 is
2904 Body_Sloc : Source_Ptr;
2905 Decl : Node_Id;
2906
2907 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean;
2908 -- Return whether Decl is considered as a declarative item.
2909 -- When During_Parsing is True, the semantics of Ada 83 is followed.
2910 -- When During_Parsing is False, the semantics of SPARK is followed.
2911
2912 -------------------------------
2913 -- Is_Later_Declarative_Item --
2914 -------------------------------
2915
2916 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean is
2917 begin
2918 if Nkind (Decl) in N_Later_Decl_Item then
2919 return True;
2920
2921 elsif Nkind (Decl) = N_Pragma then
2922 return True;
2923
2924 elsif During_Parsing then
2925 return False;
2926
2927 -- In SPARK, a package declaration is not considered as a later
2928 -- declarative item.
2929
2930 elsif Nkind (Decl) = N_Package_Declaration then
2931 return False;
2932
2933 -- In SPARK, a renaming is considered as a later declarative item
2934
2935 elsif Nkind (Decl) in N_Renaming_Declaration then
2936 return True;
2937
2938 else
2939 return False;
2940 end if;
2941 end Is_Later_Declarative_Item;
2942
2943 -- Start of processing for Check_Later_Vs_Basic_Declarations
2944
2945 begin
2946 Decl := First (Decls);
2947
2948 -- Loop through sequence of basic declarative items
2949
2950 Outer : while Present (Decl) loop
2951 if not Nkind_In (Decl, N_Subprogram_Body, N_Package_Body, N_Task_Body)
2952 and then Nkind (Decl) not in N_Body_Stub
2953 then
2954 Next (Decl);
2955
2956 -- Once a body is encountered, we only allow later declarative
2957 -- items. The inner loop checks the rest of the list.
2958
2959 else
2960 Body_Sloc := Sloc (Decl);
2961
2962 Inner : while Present (Decl) loop
2963 if not Is_Later_Declarative_Item (Decl) then
2964 if During_Parsing then
2965 if Ada_Version = Ada_83 then
2966 Error_Msg_Sloc := Body_Sloc;
2967 Error_Msg_N
2968 ("(Ada 83) decl cannot appear after body#", Decl);
2969 end if;
2970 else
2971 Error_Msg_Sloc := Body_Sloc;
2972 Check_SPARK_05_Restriction
2973 ("decl cannot appear after body#", Decl);
2974 end if;
2975 end if;
2976
2977 Next (Decl);
2978 end loop Inner;
2979 end if;
2980 end loop Outer;
2981 end Check_Later_Vs_Basic_Declarations;
2982
2983 ---------------------------
2984 -- Check_No_Hidden_State --
2985 ---------------------------
2986
2987 procedure Check_No_Hidden_State (Id : Entity_Id) is
2988 function Has_Null_Abstract_State (Pkg : Entity_Id) return Boolean;
2989 -- Determine whether the entity of a package denoted by Pkg has a null
2990 -- abstract state.
2991
2992 -----------------------------
2993 -- Has_Null_Abstract_State --
2994 -----------------------------
2995
2996 function Has_Null_Abstract_State (Pkg : Entity_Id) return Boolean is
2997 States : constant Elist_Id := Abstract_States (Pkg);
2998
2999 begin
3000 -- Check first available state of related package. A null abstract
3001 -- state always appears as the sole element of the state list.
3002
3003 return
3004 Present (States)
3005 and then Is_Null_State (Node (First_Elmt (States)));
3006 end Has_Null_Abstract_State;
3007
3008 -- Local variables
3009
3010 Context : Entity_Id := Empty;
3011 Not_Visible : Boolean := False;
3012 Scop : Entity_Id;
3013
3014 -- Start of processing for Check_No_Hidden_State
3015
3016 begin
3017 pragma Assert (Ekind_In (Id, E_Abstract_State, E_Variable));
3018
3019 -- Find the proper context where the object or state appears
3020
3021 Scop := Scope (Id);
3022 while Present (Scop) loop
3023 Context := Scop;
3024
3025 -- Keep track of the context's visibility
3026
3027 Not_Visible := Not_Visible or else In_Private_Part (Context);
3028
3029 -- Prevent the search from going too far
3030
3031 if Context = Standard_Standard then
3032 return;
3033
3034 -- Objects and states that appear immediately within a subprogram or
3035 -- inside a construct nested within a subprogram do not introduce a
3036 -- hidden state. They behave as local variable declarations.
3037
3038 elsif Is_Subprogram (Context) then
3039 return;
3040
3041 -- When examining a package body, use the entity of the spec as it
3042 -- carries the abstract state declarations.
3043
3044 elsif Ekind (Context) = E_Package_Body then
3045 Context := Spec_Entity (Context);
3046 end if;
3047
3048 -- Stop the traversal when a package subject to a null abstract state
3049 -- has been found.
3050
3051 if Ekind_In (Context, E_Generic_Package, E_Package)
3052 and then Has_Null_Abstract_State (Context)
3053 then
3054 exit;
3055 end if;
3056
3057 Scop := Scope (Scop);
3058 end loop;
3059
3060 -- At this point we know that there is at least one package with a null
3061 -- abstract state in visibility. Emit an error message unconditionally
3062 -- if the entity being processed is a state because the placement of the
3063 -- related package is irrelevant. This is not the case for objects as
3064 -- the intermediate context matters.
3065
3066 if Present (Context)
3067 and then (Ekind (Id) = E_Abstract_State or else Not_Visible)
3068 then
3069 Error_Msg_N ("cannot introduce hidden state &", Id);
3070 Error_Msg_NE ("\package & has null abstract state", Id, Context);
3071 end if;
3072 end Check_No_Hidden_State;
3073
3074 ----------------------------------------
3075 -- Check_Nonvolatile_Function_Profile --
3076 ----------------------------------------
3077
3078 procedure Check_Nonvolatile_Function_Profile (Func_Id : Entity_Id) is
3079 Formal : Entity_Id;
3080
3081 begin
3082 -- Inspect all formal parameters
3083
3084 Formal := First_Formal (Func_Id);
3085 while Present (Formal) loop
3086 if Is_Effectively_Volatile (Etype (Formal)) then
3087 Error_Msg_NE
3088 ("nonvolatile function & cannot have a volatile parameter",
3089 Formal, Func_Id);
3090 end if;
3091
3092 Next_Formal (Formal);
3093 end loop;
3094
3095 -- Inspect the return type
3096
3097 if Is_Effectively_Volatile (Etype (Func_Id)) then
3098 Error_Msg_N
3099 ("nonvolatile function & cannot have a volatile return type",
3100 Func_Id);
3101 end if;
3102 end Check_Nonvolatile_Function_Profile;
3103
3104 ------------------------------------------
3105 -- Check_Potentially_Blocking_Operation --
3106 ------------------------------------------
3107
3108 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
3109 S : Entity_Id;
3110
3111 begin
3112 -- N is one of the potentially blocking operations listed in 9.5.1(8).
3113 -- When pragma Detect_Blocking is active, the run time will raise
3114 -- Program_Error. Here we only issue a warning, since we generally
3115 -- support the use of potentially blocking operations in the absence
3116 -- of the pragma.
3117
3118 -- Indirect blocking through a subprogram call cannot be diagnosed
3119 -- statically without interprocedural analysis, so we do not attempt
3120 -- to do it here.
3121
3122 S := Scope (Current_Scope);
3123 while Present (S) and then S /= Standard_Standard loop
3124 if Is_Protected_Type (S) then
3125 Error_Msg_N
3126 ("potentially blocking operation in protected operation??", N);
3127 return;
3128 end if;
3129
3130 S := Scope (S);
3131 end loop;
3132 end Check_Potentially_Blocking_Operation;
3133
3134 ---------------------------------
3135 -- Check_Result_And_Post_State --
3136 ---------------------------------
3137
3138 procedure Check_Result_And_Post_State (Subp_Id : Entity_Id) is
3139 procedure Check_Result_And_Post_State_In_Pragma
3140 (Prag : Node_Id;
3141 Result_Seen : in out Boolean);
3142 -- Determine whether pragma Prag mentions attribute 'Result and whether
3143 -- the pragma contains an expression that evaluates differently in pre-
3144 -- and post-state. Prag is a [refined] postcondition or a contract-cases
3145 -- pragma. Result_Seen is set when the pragma mentions attribute 'Result
3146
3147 function Has_In_Out_Parameter (Subp_Id : Entity_Id) return Boolean;
3148 -- Determine whether subprogram Subp_Id contains at least one IN OUT
3149 -- formal parameter.
3150
3151 -------------------------------------------
3152 -- Check_Result_And_Post_State_In_Pragma --
3153 -------------------------------------------
3154
3155 procedure Check_Result_And_Post_State_In_Pragma
3156 (Prag : Node_Id;
3157 Result_Seen : in out Boolean)
3158 is
3159 procedure Check_Expression (Expr : Node_Id);
3160 -- Perform the 'Result and post-state checks on a given expression
3161
3162 function Is_Function_Result (N : Node_Id) return Traverse_Result;
3163 -- Attempt to find attribute 'Result in a subtree denoted by N
3164
3165 function Is_Trivial_Boolean (N : Node_Id) return Boolean;
3166 -- Determine whether source node N denotes "True" or "False"
3167
3168 function Mentions_Post_State (N : Node_Id) return Boolean;
3169 -- Determine whether a subtree denoted by N mentions any construct
3170 -- that denotes a post-state.
3171
3172 procedure Check_Function_Result is
3173 new Traverse_Proc (Is_Function_Result);
3174
3175 ----------------------
3176 -- Check_Expression --
3177 ----------------------
3178
3179 procedure Check_Expression (Expr : Node_Id) is
3180 begin
3181 if not Is_Trivial_Boolean (Expr) then
3182 Check_Function_Result (Expr);
3183
3184 if not Mentions_Post_State (Expr) then
3185 if Pragma_Name (Prag) = Name_Contract_Cases then
3186 Error_Msg_NE
3187 ("contract case does not check the outcome of calling "
3188 & "&?T?", Expr, Subp_Id);
3189
3190 elsif Pragma_Name (Prag) = Name_Refined_Post then
3191 Error_Msg_NE
3192 ("refined postcondition does not check the outcome of "
3193 & "calling &?T?", Prag, Subp_Id);
3194
3195 else
3196 Error_Msg_NE
3197 ("postcondition does not check the outcome of calling "
3198 & "&?T?", Prag, Subp_Id);
3199 end if;
3200 end if;
3201 end if;
3202 end Check_Expression;
3203
3204 ------------------------
3205 -- Is_Function_Result --
3206 ------------------------
3207
3208 function Is_Function_Result (N : Node_Id) return Traverse_Result is
3209 begin
3210 if Is_Attribute_Result (N) then
3211 Result_Seen := True;
3212 return Abandon;
3213
3214 -- Continue the traversal
3215
3216 else
3217 return OK;
3218 end if;
3219 end Is_Function_Result;
3220
3221 ------------------------
3222 -- Is_Trivial_Boolean --
3223 ------------------------
3224
3225 function Is_Trivial_Boolean (N : Node_Id) return Boolean is
3226 begin
3227 return
3228 Comes_From_Source (N)
3229 and then Is_Entity_Name (N)
3230 and then (Entity (N) = Standard_True
3231 or else
3232 Entity (N) = Standard_False);
3233 end Is_Trivial_Boolean;
3234
3235 -------------------------
3236 -- Mentions_Post_State --
3237 -------------------------
3238
3239 function Mentions_Post_State (N : Node_Id) return Boolean is
3240 Post_State_Seen : Boolean := False;
3241
3242 function Is_Post_State (N : Node_Id) return Traverse_Result;
3243 -- Attempt to find a construct that denotes a post-state. If this
3244 -- is the case, set flag Post_State_Seen.
3245
3246 -------------------
3247 -- Is_Post_State --
3248 -------------------
3249
3250 function Is_Post_State (N : Node_Id) return Traverse_Result is
3251 Ent : Entity_Id;
3252
3253 begin
3254 if Nkind_In (N, N_Explicit_Dereference, N_Function_Call) then
3255 Post_State_Seen := True;
3256 return Abandon;
3257
3258 elsif Nkind_In (N, N_Expanded_Name, N_Identifier) then
3259 Ent := Entity (N);
3260
3261 -- The entity may be modifiable through an implicit
3262 -- dereference.
3263
3264 if No (Ent)
3265 or else Ekind (Ent) in Assignable_Kind
3266 or else (Is_Access_Type (Etype (Ent))
3267 and then Nkind (Parent (N)) =
3268 N_Selected_Component)
3269 then
3270 Post_State_Seen := True;
3271 return Abandon;
3272 end if;
3273
3274 elsif Nkind (N) = N_Attribute_Reference then
3275 if Attribute_Name (N) = Name_Old then
3276 return Skip;
3277
3278 elsif Attribute_Name (N) = Name_Result then
3279 Post_State_Seen := True;
3280 return Abandon;
3281 end if;
3282 end if;
3283
3284 return OK;
3285 end Is_Post_State;
3286
3287 procedure Find_Post_State is new Traverse_Proc (Is_Post_State);
3288
3289 -- Start of processing for Mentions_Post_State
3290
3291 begin
3292 Find_Post_State (N);
3293
3294 return Post_State_Seen;
3295 end Mentions_Post_State;
3296
3297 -- Local variables
3298
3299 Expr : constant Node_Id :=
3300 Get_Pragma_Arg
3301 (First (Pragma_Argument_Associations (Prag)));
3302 Nam : constant Name_Id := Pragma_Name (Prag);
3303 CCase : Node_Id;
3304
3305 -- Start of processing for Check_Result_And_Post_State_In_Pragma
3306
3307 begin
3308 -- Examine all consequences
3309
3310 if Nam = Name_Contract_Cases then
3311 CCase := First (Component_Associations (Expr));
3312 while Present (CCase) loop
3313 Check_Expression (Expression (CCase));
3314
3315 Next (CCase);
3316 end loop;
3317
3318 -- Examine the expression of a postcondition
3319
3320 else pragma Assert (Nam_In (Nam, Name_Postcondition,
3321 Name_Refined_Post));
3322 Check_Expression (Expr);
3323 end if;
3324 end Check_Result_And_Post_State_In_Pragma;
3325
3326 --------------------------
3327 -- Has_In_Out_Parameter --
3328 --------------------------
3329
3330 function Has_In_Out_Parameter (Subp_Id : Entity_Id) return Boolean is
3331 Formal : Entity_Id;
3332
3333 begin
3334 -- Traverse the formals looking for an IN OUT parameter
3335
3336 Formal := First_Formal (Subp_Id);
3337 while Present (Formal) loop
3338 if Ekind (Formal) = E_In_Out_Parameter then
3339 return True;
3340 end if;
3341
3342 Next_Formal (Formal);
3343 end loop;
3344
3345 return False;
3346 end Has_In_Out_Parameter;
3347
3348 -- Local variables
3349
3350 Items : constant Node_Id := Contract (Subp_Id);
3351 Subp_Decl : constant Node_Id := Unit_Declaration_Node (Subp_Id);
3352 Case_Prag : Node_Id := Empty;
3353 Post_Prag : Node_Id := Empty;
3354 Prag : Node_Id;
3355 Seen_In_Case : Boolean := False;
3356 Seen_In_Post : Boolean := False;
3357 Spec_Id : Entity_Id;
3358
3359 -- Start of processing for Check_Result_And_Post_State
3360
3361 begin
3362 -- The lack of attribute 'Result or a post-state is classified as a
3363 -- suspicious contract. Do not perform the check if the corresponding
3364 -- swich is not set.
3365
3366 if not Warn_On_Suspicious_Contract then
3367 return;
3368
3369 -- Nothing to do if there is no contract
3370
3371 elsif No (Items) then
3372 return;
3373 end if;
3374
3375 -- Retrieve the entity of the subprogram spec (if any)
3376
3377 if Nkind (Subp_Decl) = N_Subprogram_Body
3378 and then Present (Corresponding_Spec (Subp_Decl))
3379 then
3380 Spec_Id := Corresponding_Spec (Subp_Decl);
3381
3382 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
3383 and then Present (Corresponding_Spec_Of_Stub (Subp_Decl))
3384 then
3385 Spec_Id := Corresponding_Spec_Of_Stub (Subp_Decl);
3386
3387 else
3388 Spec_Id := Subp_Id;
3389 end if;
3390
3391 -- Examine all postconditions for attribute 'Result and a post-state
3392
3393 Prag := Pre_Post_Conditions (Items);
3394 while Present (Prag) loop
3395 if Nam_In (Pragma_Name (Prag), Name_Postcondition,
3396 Name_Refined_Post)
3397 and then not Error_Posted (Prag)
3398 then
3399 Post_Prag := Prag;
3400 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Post);
3401 end if;
3402
3403 Prag := Next_Pragma (Prag);
3404 end loop;
3405
3406 -- Examine the contract cases of the subprogram for attribute 'Result
3407 -- and a post-state.
3408
3409 Prag := Contract_Test_Cases (Items);
3410 while Present (Prag) loop
3411 if Pragma_Name (Prag) = Name_Contract_Cases
3412 and then not Error_Posted (Prag)
3413 then
3414 Case_Prag := Prag;
3415 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Case);
3416 end if;
3417
3418 Prag := Next_Pragma (Prag);
3419 end loop;
3420
3421 -- Do not emit any errors if the subprogram is not a function
3422
3423 if not Ekind_In (Spec_Id, E_Function, E_Generic_Function) then
3424 null;
3425
3426 -- Regardless of whether the function has postconditions or contract
3427 -- cases, or whether they mention attribute 'Result, an IN OUT formal
3428 -- parameter is always treated as a result.
3429
3430 elsif Has_In_Out_Parameter (Spec_Id) then
3431 null;
3432
3433 -- The function has both a postcondition and contract cases and they do
3434 -- not mention attribute 'Result.
3435
3436 elsif Present (Case_Prag)
3437 and then not Seen_In_Case
3438 and then Present (Post_Prag)
3439 and then not Seen_In_Post
3440 then
3441 Error_Msg_N
3442 ("neither postcondition nor contract cases mention function "
3443 & "result?T?", Post_Prag);
3444
3445 -- The function has contract cases only and they do not mention
3446 -- attribute 'Result.
3447
3448 elsif Present (Case_Prag) and then not Seen_In_Case then
3449 Error_Msg_N ("contract cases do not mention result?T?", Case_Prag);
3450
3451 -- The function has postconditions only and they do not mention
3452 -- attribute 'Result.
3453
3454 elsif Present (Post_Prag) and then not Seen_In_Post then
3455 Error_Msg_N
3456 ("postcondition does not mention function result?T?", Post_Prag);
3457 end if;
3458 end Check_Result_And_Post_State;
3459
3460 ------------------------------
3461 -- Check_Unprotected_Access --
3462 ------------------------------
3463
3464 procedure Check_Unprotected_Access
3465 (Context : Node_Id;
3466 Expr : Node_Id)
3467 is
3468 Cont_Encl_Typ : Entity_Id;
3469 Pref_Encl_Typ : Entity_Id;
3470
3471 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
3472 -- Check whether Obj is a private component of a protected object.
3473 -- Return the protected type where the component resides, Empty
3474 -- otherwise.
3475
3476 function Is_Public_Operation return Boolean;
3477 -- Verify that the enclosing operation is callable from outside the
3478 -- protected object, to minimize false positives.
3479
3480 ------------------------------
3481 -- Enclosing_Protected_Type --
3482 ------------------------------
3483
3484 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
3485 begin
3486 if Is_Entity_Name (Obj) then
3487 declare
3488 Ent : Entity_Id := Entity (Obj);
3489
3490 begin
3491 -- The object can be a renaming of a private component, use
3492 -- the original record component.
3493
3494 if Is_Prival (Ent) then
3495 Ent := Prival_Link (Ent);
3496 end if;
3497
3498 if Is_Protected_Type (Scope (Ent)) then
3499 return Scope (Ent);
3500 end if;
3501 end;
3502 end if;
3503
3504 -- For indexed and selected components, recursively check the prefix
3505
3506 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
3507 return Enclosing_Protected_Type (Prefix (Obj));
3508
3509 -- The object does not denote a protected component
3510
3511 else
3512 return Empty;
3513 end if;
3514 end Enclosing_Protected_Type;
3515
3516 -------------------------
3517 -- Is_Public_Operation --
3518 -------------------------
3519
3520 function Is_Public_Operation return Boolean is
3521 S : Entity_Id;
3522 E : Entity_Id;
3523
3524 begin
3525 S := Current_Scope;
3526 while Present (S) and then S /= Pref_Encl_Typ loop
3527 if Scope (S) = Pref_Encl_Typ then
3528 E := First_Entity (Pref_Encl_Typ);
3529 while Present (E)
3530 and then E /= First_Private_Entity (Pref_Encl_Typ)
3531 loop
3532 if E = S then
3533 return True;
3534 end if;
3535
3536 Next_Entity (E);
3537 end loop;
3538 end if;
3539
3540 S := Scope (S);
3541 end loop;
3542
3543 return False;
3544 end Is_Public_Operation;
3545
3546 -- Start of processing for Check_Unprotected_Access
3547
3548 begin
3549 if Nkind (Expr) = N_Attribute_Reference
3550 and then Attribute_Name (Expr) = Name_Unchecked_Access
3551 then
3552 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
3553 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
3554
3555 -- Check whether we are trying to export a protected component to a
3556 -- context with an equal or lower access level.
3557
3558 if Present (Pref_Encl_Typ)
3559 and then No (Cont_Encl_Typ)
3560 and then Is_Public_Operation
3561 and then Scope_Depth (Pref_Encl_Typ) >=
3562 Object_Access_Level (Context)
3563 then
3564 Error_Msg_N
3565 ("??possible unprotected access to protected data", Expr);
3566 end if;
3567 end if;
3568 end Check_Unprotected_Access;
3569
3570 ------------------------------
3571 -- Check_Unused_Body_States --
3572 ------------------------------
3573
3574 procedure Check_Unused_Body_States (Body_Id : Entity_Id) is
3575 Legal_Constits : Boolean := True;
3576 -- This flag designates whether all constituents of pragma Refined_State
3577 -- are legal. The flag is used to suppress the generation of potentially
3578 -- misleading error messages due to a malformed pragma.
3579
3580 procedure Process_Refinement_Clause
3581 (Clause : Node_Id;
3582 States : Elist_Id);
3583 -- Inspect all constituents of refinement clause Clause and remove any
3584 -- matches from body state list States.
3585
3586 -------------------------------
3587 -- Process_Refinement_Clause --
3588 -------------------------------
3589
3590 procedure Process_Refinement_Clause
3591 (Clause : Node_Id;
3592 States : Elist_Id)
3593 is
3594 procedure Process_Constituent (Constit : Node_Id);
3595 -- Remove constituent Constit from body state list States
3596
3597 -------------------------
3598 -- Process_Constituent --
3599 -------------------------
3600
3601 procedure Process_Constituent (Constit : Node_Id) is
3602 Constit_Id : Entity_Id;
3603
3604 begin
3605 if Error_Posted (Constit) then
3606 Legal_Constits := False;
3607 end if;
3608
3609 -- Guard against illegal constituents. Only abstract states and
3610 -- objects can appear on the right hand side of a refinement.
3611
3612 if Is_Entity_Name (Constit) then
3613 Constit_Id := Entity_Of (Constit);
3614
3615 if Present (Constit_Id)
3616 and then Ekind_In (Constit_Id, E_Abstract_State,
3617 E_Constant,
3618 E_Variable)
3619 then
3620 Remove (States, Constit_Id);
3621 end if;
3622 end if;
3623 end Process_Constituent;
3624
3625 -- Local variables
3626
3627 Constit : Node_Id;
3628
3629 -- Start of processing for Process_Refinement_Clause
3630
3631 begin
3632 if Nkind (Clause) = N_Component_Association then
3633 Constit := Expression (Clause);
3634
3635 -- Multiple constituents appear as an aggregate
3636
3637 if Nkind (Constit) = N_Aggregate then
3638 Constit := First (Expressions (Constit));
3639 while Present (Constit) loop
3640 Process_Constituent (Constit);
3641 Next (Constit);
3642 end loop;
3643
3644 -- Various forms of a single constituent
3645
3646 else
3647 Process_Constituent (Constit);
3648 end if;
3649 end if;
3650 end Process_Refinement_Clause;
3651
3652 -- Local variables
3653
3654 Prag : constant Node_Id :=
3655 Get_Pragma (Body_Id, Pragma_Refined_State);
3656 Spec_Id : constant Entity_Id := Spec_Entity (Body_Id);
3657 Clause : Node_Id;
3658 States : Elist_Id;
3659
3660 -- Start of processing for Check_Unused_Body_States
3661
3662 begin
3663 -- Inspect the clauses of pragma Refined_State and determine whether all
3664 -- visible states declared within the body of the package participate in
3665 -- the refinement.
3666
3667 if Present (Prag) then
3668 Clause := Expression (Get_Argument (Prag, Spec_Id));
3669 States := Collect_Body_States (Body_Id);
3670
3671 -- Multiple non-null state refinements appear as an aggregate
3672
3673 if Nkind (Clause) = N_Aggregate then
3674 Clause := First (Component_Associations (Clause));
3675 while Present (Clause) loop
3676 Process_Refinement_Clause (Clause, States);
3677 Next (Clause);
3678 end loop;
3679
3680 -- Various forms of a single state refinement
3681
3682 else
3683 Process_Refinement_Clause (Clause, States);
3684 end if;
3685
3686 -- Ensure that all abstract states and objects declared in the body
3687 -- state space of the related package are utilized as constituents.
3688
3689 if Legal_Constits then
3690 Report_Unused_Body_States (Body_Id, States);
3691 end if;
3692 end if;
3693 end Check_Unused_Body_States;
3694
3695 -------------------------
3696 -- Collect_Body_States --
3697 -------------------------
3698
3699 function Collect_Body_States (Body_Id : Entity_Id) return Elist_Id is
3700 procedure Collect_Visible_States
3701 (Pack_Id : Entity_Id;
3702 States : in out Elist_Id);
3703 -- Gather the entities of all abstract states and objects declared in
3704 -- the visible state space of package Pack_Id.
3705
3706 ----------------------------
3707 -- Collect_Visible_States --
3708 ----------------------------
3709
3710 procedure Collect_Visible_States
3711 (Pack_Id : Entity_Id;
3712 States : in out Elist_Id)
3713 is
3714 Item_Id : Entity_Id;
3715
3716 begin
3717 -- Traverse the entity chain of the package and inspect all visible
3718 -- items.
3719
3720 Item_Id := First_Entity (Pack_Id);
3721 while Present (Item_Id) and then not In_Private_Part (Item_Id) loop
3722
3723 -- Do not consider internally generated items as those cannot be
3724 -- named and participate in refinement.
3725
3726 if not Comes_From_Source (Item_Id) then
3727 null;
3728
3729 elsif Ekind (Item_Id) = E_Abstract_State then
3730 Append_New_Elmt (Item_Id, States);
3731
3732 -- Do not consider objects that map generic formals to their
3733 -- actuals, as the formals cannot be named from the outside and
3734 -- participate in refinement.
3735
3736 elsif Ekind_In (Item_Id, E_Constant, E_Variable)
3737 and then No (Corresponding_Generic_Association
3738 (Declaration_Node (Item_Id)))
3739 then
3740 Append_New_Elmt (Item_Id, States);
3741
3742 -- Recursively gather the visible states of a nested package
3743
3744 elsif Ekind (Item_Id) = E_Package then
3745 Collect_Visible_States (Item_Id, States);
3746 end if;
3747
3748 Next_Entity (Item_Id);
3749 end loop;
3750 end Collect_Visible_States;
3751
3752 -- Local variables
3753
3754 Body_Decl : constant Node_Id := Unit_Declaration_Node (Body_Id);
3755 Decl : Node_Id;
3756 Item_Id : Entity_Id;
3757 States : Elist_Id := No_Elist;
3758
3759 -- Start of processing for Collect_Body_States
3760
3761 begin
3762 -- Inspect the declarations of the body looking for source objects,
3763 -- packages and package instantiations.
3764
3765 Decl := First (Declarations (Body_Decl));
3766 while Present (Decl) loop
3767
3768 -- Capture source objects as internally generated temporaries cannot
3769 -- be named and participate in refinement.
3770
3771 if Nkind (Decl) = N_Object_Declaration then
3772 Item_Id := Defining_Entity (Decl);
3773
3774 if Comes_From_Source (Item_Id) then
3775 Append_New_Elmt (Item_Id, States);
3776 end if;
3777
3778 -- Capture the visible abstract states and objects of a source
3779 -- package [instantiation].
3780
3781 elsif Nkind (Decl) = N_Package_Declaration then
3782 Item_Id := Defining_Entity (Decl);
3783
3784 if Comes_From_Source (Item_Id) then
3785 Collect_Visible_States (Item_Id, States);
3786 end if;
3787 end if;
3788
3789 Next (Decl);
3790 end loop;
3791
3792 return States;
3793 end Collect_Body_States;
3794
3795 ------------------------
3796 -- Collect_Interfaces --
3797 ------------------------
3798
3799 procedure Collect_Interfaces
3800 (T : Entity_Id;
3801 Ifaces_List : out Elist_Id;
3802 Exclude_Parents : Boolean := False;
3803 Use_Full_View : Boolean := True)
3804 is
3805 procedure Collect (Typ : Entity_Id);
3806 -- Subsidiary subprogram used to traverse the whole list
3807 -- of directly and indirectly implemented interfaces
3808
3809 -------------
3810 -- Collect --
3811 -------------
3812
3813 procedure Collect (Typ : Entity_Id) is
3814 Ancestor : Entity_Id;
3815 Full_T : Entity_Id;
3816 Id : Node_Id;
3817 Iface : Entity_Id;
3818
3819 begin
3820 Full_T := Typ;
3821
3822 -- Handle private types and subtypes
3823
3824 if Use_Full_View
3825 and then Is_Private_Type (Typ)
3826 and then Present (Full_View (Typ))
3827 then
3828 Full_T := Full_View (Typ);
3829
3830 if Ekind (Full_T) = E_Record_Subtype then
3831 Full_T := Full_View (Etype (Typ));
3832 end if;
3833 end if;
3834
3835 -- Include the ancestor if we are generating the whole list of
3836 -- abstract interfaces.
3837
3838 if Etype (Full_T) /= Typ
3839
3840 -- Protect the frontend against wrong sources. For example:
3841
3842 -- package P is
3843 -- type A is tagged null record;
3844 -- type B is new A with private;
3845 -- type C is new A with private;
3846 -- private
3847 -- type B is new C with null record;
3848 -- type C is new B with null record;
3849 -- end P;
3850
3851 and then Etype (Full_T) /= T
3852 then
3853 Ancestor := Etype (Full_T);
3854 Collect (Ancestor);
3855
3856 if Is_Interface (Ancestor) and then not Exclude_Parents then
3857 Append_Unique_Elmt (Ancestor, Ifaces_List);
3858 end if;
3859 end if;
3860
3861 -- Traverse the graph of ancestor interfaces
3862
3863 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
3864 Id := First (Abstract_Interface_List (Full_T));
3865 while Present (Id) loop
3866 Iface := Etype (Id);
3867
3868 -- Protect against wrong uses. For example:
3869 -- type I is interface;
3870 -- type O is tagged null record;
3871 -- type Wrong is new I and O with null record; -- ERROR
3872
3873 if Is_Interface (Iface) then
3874 if Exclude_Parents
3875 and then Etype (T) /= T
3876 and then Interface_Present_In_Ancestor (Etype (T), Iface)
3877 then
3878 null;
3879 else
3880 Collect (Iface);
3881 Append_Unique_Elmt (Iface, Ifaces_List);
3882 end if;
3883 end if;
3884
3885 Next (Id);
3886 end loop;
3887 end if;
3888 end Collect;
3889
3890 -- Start of processing for Collect_Interfaces
3891
3892 begin
3893 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
3894 Ifaces_List := New_Elmt_List;
3895 Collect (T);
3896 end Collect_Interfaces;
3897
3898 ----------------------------------
3899 -- Collect_Interface_Components --
3900 ----------------------------------
3901
3902 procedure Collect_Interface_Components
3903 (Tagged_Type : Entity_Id;
3904 Components_List : out Elist_Id)
3905 is
3906 procedure Collect (Typ : Entity_Id);
3907 -- Subsidiary subprogram used to climb to the parents
3908
3909 -------------
3910 -- Collect --
3911 -------------
3912
3913 procedure Collect (Typ : Entity_Id) is
3914 Tag_Comp : Entity_Id;
3915 Parent_Typ : Entity_Id;
3916
3917 begin
3918 -- Handle private types
3919
3920 if Present (Full_View (Etype (Typ))) then
3921 Parent_Typ := Full_View (Etype (Typ));
3922 else
3923 Parent_Typ := Etype (Typ);
3924 end if;
3925
3926 if Parent_Typ /= Typ
3927
3928 -- Protect the frontend against wrong sources. For example:
3929
3930 -- package P is
3931 -- type A is tagged null record;
3932 -- type B is new A with private;
3933 -- type C is new A with private;
3934 -- private
3935 -- type B is new C with null record;
3936 -- type C is new B with null record;
3937 -- end P;
3938
3939 and then Parent_Typ /= Tagged_Type
3940 then
3941 Collect (Parent_Typ);
3942 end if;
3943
3944 -- Collect the components containing tags of secondary dispatch
3945 -- tables.
3946
3947 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
3948 while Present (Tag_Comp) loop
3949 pragma Assert (Present (Related_Type (Tag_Comp)));
3950 Append_Elmt (Tag_Comp, Components_List);
3951
3952 Tag_Comp := Next_Tag_Component (Tag_Comp);
3953 end loop;
3954 end Collect;
3955
3956 -- Start of processing for Collect_Interface_Components
3957
3958 begin
3959 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
3960 and then Is_Tagged_Type (Tagged_Type));
3961
3962 Components_List := New_Elmt_List;
3963 Collect (Tagged_Type);
3964 end Collect_Interface_Components;
3965
3966 -----------------------------
3967 -- Collect_Interfaces_Info --
3968 -----------------------------
3969
3970 procedure Collect_Interfaces_Info
3971 (T : Entity_Id;
3972 Ifaces_List : out Elist_Id;
3973 Components_List : out Elist_Id;
3974 Tags_List : out Elist_Id)
3975 is
3976 Comps_List : Elist_Id;
3977 Comp_Elmt : Elmt_Id;
3978 Comp_Iface : Entity_Id;
3979 Iface_Elmt : Elmt_Id;
3980 Iface : Entity_Id;
3981
3982 function Search_Tag (Iface : Entity_Id) return Entity_Id;
3983 -- Search for the secondary tag associated with the interface type
3984 -- Iface that is implemented by T.
3985
3986 ----------------
3987 -- Search_Tag --
3988 ----------------
3989
3990 function Search_Tag (Iface : Entity_Id) return Entity_Id is
3991 ADT : Elmt_Id;
3992 begin
3993 if not Is_CPP_Class (T) then
3994 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
3995 else
3996 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
3997 end if;
3998
3999 while Present (ADT)
4000 and then Is_Tag (Node (ADT))
4001 and then Related_Type (Node (ADT)) /= Iface
4002 loop
4003 -- Skip secondary dispatch table referencing thunks to user
4004 -- defined primitives covered by this interface.
4005
4006 pragma Assert (Has_Suffix (Node (ADT), 'P'));
4007 Next_Elmt (ADT);
4008
4009 -- Skip secondary dispatch tables of Ada types
4010
4011 if not Is_CPP_Class (T) then
4012
4013 -- Skip secondary dispatch table referencing thunks to
4014 -- predefined primitives.
4015
4016 pragma Assert (Has_Suffix (Node (ADT), 'Y'));
4017 Next_Elmt (ADT);
4018
4019 -- Skip secondary dispatch table referencing user-defined
4020 -- primitives covered by this interface.
4021
4022 pragma Assert (Has_Suffix (Node (ADT), 'D'));
4023 Next_Elmt (ADT);
4024
4025 -- Skip secondary dispatch table referencing predefined
4026 -- primitives.
4027
4028 pragma Assert (Has_Suffix (Node (ADT), 'Z'));
4029 Next_Elmt (ADT);
4030 end if;
4031 end loop;
4032
4033 pragma Assert (Is_Tag (Node (ADT)));
4034 return Node (ADT);
4035 end Search_Tag;
4036
4037 -- Start of processing for Collect_Interfaces_Info
4038
4039 begin
4040 Collect_Interfaces (T, Ifaces_List);
4041 Collect_Interface_Components (T, Comps_List);
4042
4043 -- Search for the record component and tag associated with each
4044 -- interface type of T.
4045
4046 Components_List := New_Elmt_List;
4047 Tags_List := New_Elmt_List;
4048
4049 Iface_Elmt := First_Elmt (Ifaces_List);
4050 while Present (Iface_Elmt) loop
4051 Iface := Node (Iface_Elmt);
4052
4053 -- Associate the primary tag component and the primary dispatch table
4054 -- with all the interfaces that are parents of T
4055
4056 if Is_Ancestor (Iface, T, Use_Full_View => True) then
4057 Append_Elmt (First_Tag_Component (T), Components_List);
4058 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
4059
4060 -- Otherwise search for the tag component and secondary dispatch
4061 -- table of Iface
4062
4063 else
4064 Comp_Elmt := First_Elmt (Comps_List);
4065 while Present (Comp_Elmt) loop
4066 Comp_Iface := Related_Type (Node (Comp_Elmt));
4067
4068 if Comp_Iface = Iface
4069 or else Is_Ancestor (Iface, Comp_Iface, Use_Full_View => True)
4070 then
4071 Append_Elmt (Node (Comp_Elmt), Components_List);
4072 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
4073 exit;
4074 end if;
4075
4076 Next_Elmt (Comp_Elmt);
4077 end loop;
4078 pragma Assert (Present (Comp_Elmt));
4079 end if;
4080
4081 Next_Elmt (Iface_Elmt);
4082 end loop;
4083 end Collect_Interfaces_Info;
4084
4085 ---------------------
4086 -- Collect_Parents --
4087 ---------------------
4088
4089 procedure Collect_Parents
4090 (T : Entity_Id;
4091 List : out Elist_Id;
4092 Use_Full_View : Boolean := True)
4093 is
4094 Current_Typ : Entity_Id := T;
4095 Parent_Typ : Entity_Id;
4096
4097 begin
4098 List := New_Elmt_List;
4099
4100 -- No action if the if the type has no parents
4101
4102 if T = Etype (T) then
4103 return;
4104 end if;
4105
4106 loop
4107 Parent_Typ := Etype (Current_Typ);
4108
4109 if Is_Private_Type (Parent_Typ)
4110 and then Present (Full_View (Parent_Typ))
4111 and then Use_Full_View
4112 then
4113 Parent_Typ := Full_View (Base_Type (Parent_Typ));
4114 end if;
4115
4116 Append_Elmt (Parent_Typ, List);
4117
4118 exit when Parent_Typ = Current_Typ;
4119 Current_Typ := Parent_Typ;
4120 end loop;
4121 end Collect_Parents;
4122
4123 ----------------------------------
4124 -- Collect_Primitive_Operations --
4125 ----------------------------------
4126
4127 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
4128 B_Type : constant Entity_Id := Base_Type (T);
4129 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
4130 B_Scope : Entity_Id := Scope (B_Type);
4131 Op_List : Elist_Id;
4132 Formal : Entity_Id;
4133 Is_Prim : Boolean;
4134 Is_Type_In_Pkg : Boolean;
4135 Formal_Derived : Boolean := False;
4136 Id : Entity_Id;
4137
4138 function Match (E : Entity_Id) return Boolean;
4139 -- True if E's base type is B_Type, or E is of an anonymous access type
4140 -- and the base type of its designated type is B_Type.
4141
4142 -----------
4143 -- Match --
4144 -----------
4145
4146 function Match (E : Entity_Id) return Boolean is
4147 Etyp : Entity_Id := Etype (E);
4148
4149 begin
4150 if Ekind (Etyp) = E_Anonymous_Access_Type then
4151 Etyp := Designated_Type (Etyp);
4152 end if;
4153
4154 -- In Ada 2012 a primitive operation may have a formal of an
4155 -- incomplete view of the parent type.
4156
4157 return Base_Type (Etyp) = B_Type
4158 or else
4159 (Ada_Version >= Ada_2012
4160 and then Ekind (Etyp) = E_Incomplete_Type
4161 and then Full_View (Etyp) = B_Type);
4162 end Match;
4163
4164 -- Start of processing for Collect_Primitive_Operations
4165
4166 begin
4167 -- For tagged types, the primitive operations are collected as they
4168 -- are declared, and held in an explicit list which is simply returned.
4169
4170 if Is_Tagged_Type (B_Type) then
4171 return Primitive_Operations (B_Type);
4172
4173 -- An untagged generic type that is a derived type inherits the
4174 -- primitive operations of its parent type. Other formal types only
4175 -- have predefined operators, which are not explicitly represented.
4176
4177 elsif Is_Generic_Type (B_Type) then
4178 if Nkind (B_Decl) = N_Formal_Type_Declaration
4179 and then Nkind (Formal_Type_Definition (B_Decl)) =
4180 N_Formal_Derived_Type_Definition
4181 then
4182 Formal_Derived := True;
4183 else
4184 return New_Elmt_List;
4185 end if;
4186 end if;
4187
4188 Op_List := New_Elmt_List;
4189
4190 if B_Scope = Standard_Standard then
4191 if B_Type = Standard_String then
4192 Append_Elmt (Standard_Op_Concat, Op_List);
4193
4194 elsif B_Type = Standard_Wide_String then
4195 Append_Elmt (Standard_Op_Concatw, Op_List);
4196
4197 else
4198 null;
4199 end if;
4200
4201 -- Locate the primitive subprograms of the type
4202
4203 else
4204 -- The primitive operations appear after the base type, except
4205 -- if the derivation happens within the private part of B_Scope
4206 -- and the type is a private type, in which case both the type
4207 -- and some primitive operations may appear before the base
4208 -- type, and the list of candidates starts after the type.
4209
4210 if In_Open_Scopes (B_Scope)
4211 and then Scope (T) = B_Scope
4212 and then In_Private_Part (B_Scope)
4213 then
4214 Id := Next_Entity (T);
4215
4216 -- In Ada 2012, If the type has an incomplete partial view, there
4217 -- may be primitive operations declared before the full view, so
4218 -- we need to start scanning from the incomplete view, which is
4219 -- earlier on the entity chain.
4220
4221 elsif Nkind (Parent (B_Type)) = N_Full_Type_Declaration
4222 and then Present (Incomplete_View (Parent (B_Type)))
4223 then
4224 Id := Defining_Entity (Incomplete_View (Parent (B_Type)));
4225
4226 else
4227 Id := Next_Entity (B_Type);
4228 end if;
4229
4230 -- Set flag if this is a type in a package spec
4231
4232 Is_Type_In_Pkg :=
4233 Is_Package_Or_Generic_Package (B_Scope)
4234 and then
4235 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
4236 N_Package_Body;
4237
4238 while Present (Id) loop
4239
4240 -- Test whether the result type or any of the parameter types of
4241 -- each subprogram following the type match that type when the
4242 -- type is declared in a package spec, is a derived type, or the
4243 -- subprogram is marked as primitive. (The Is_Primitive test is
4244 -- needed to find primitives of nonderived types in declarative
4245 -- parts that happen to override the predefined "=" operator.)
4246
4247 -- Note that generic formal subprograms are not considered to be
4248 -- primitive operations and thus are never inherited.
4249
4250 if Is_Overloadable (Id)
4251 and then (Is_Type_In_Pkg
4252 or else Is_Derived_Type (B_Type)
4253 or else Is_Primitive (Id))
4254 and then Nkind (Parent (Parent (Id)))
4255 not in N_Formal_Subprogram_Declaration
4256 then
4257 Is_Prim := False;
4258
4259 if Match (Id) then
4260 Is_Prim := True;
4261
4262 else
4263 Formal := First_Formal (Id);
4264 while Present (Formal) loop
4265 if Match (Formal) then
4266 Is_Prim := True;
4267 exit;
4268 end if;
4269
4270 Next_Formal (Formal);
4271 end loop;
4272 end if;
4273
4274 -- For a formal derived type, the only primitives are the ones
4275 -- inherited from the parent type. Operations appearing in the
4276 -- package declaration are not primitive for it.
4277
4278 if Is_Prim
4279 and then (not Formal_Derived or else Present (Alias (Id)))
4280 then
4281 -- In the special case of an equality operator aliased to
4282 -- an overriding dispatching equality belonging to the same
4283 -- type, we don't include it in the list of primitives.
4284 -- This avoids inheriting multiple equality operators when
4285 -- deriving from untagged private types whose full type is
4286 -- tagged, which can otherwise cause ambiguities. Note that
4287 -- this should only happen for this kind of untagged parent
4288 -- type, since normally dispatching operations are inherited
4289 -- using the type's Primitive_Operations list.
4290
4291 if Chars (Id) = Name_Op_Eq
4292 and then Is_Dispatching_Operation (Id)
4293 and then Present (Alias (Id))
4294 and then Present (Overridden_Operation (Alias (Id)))
4295 and then Base_Type (Etype (First_Entity (Id))) =
4296 Base_Type (Etype (First_Entity (Alias (Id))))
4297 then
4298 null;
4299
4300 -- Include the subprogram in the list of primitives
4301
4302 else
4303 Append_Elmt (Id, Op_List);
4304 end if;
4305 end if;
4306 end if;
4307
4308 Next_Entity (Id);
4309
4310 -- For a type declared in System, some of its operations may
4311 -- appear in the target-specific extension to System.
4312
4313 if No (Id)
4314 and then B_Scope = RTU_Entity (System)
4315 and then Present_System_Aux
4316 then
4317 B_Scope := System_Aux_Id;
4318 Id := First_Entity (System_Aux_Id);
4319 end if;
4320 end loop;
4321 end if;
4322
4323 return Op_List;
4324 end Collect_Primitive_Operations;
4325
4326 -----------------------------------
4327 -- Compile_Time_Constraint_Error --
4328 -----------------------------------
4329
4330 function Compile_Time_Constraint_Error
4331 (N : Node_Id;
4332 Msg : String;
4333 Ent : Entity_Id := Empty;
4334 Loc : Source_Ptr := No_Location;
4335 Warn : Boolean := False) return Node_Id
4336 is
4337 Msgc : String (1 .. Msg'Length + 3);
4338 -- Copy of message, with room for possible ?? or << and ! at end
4339
4340 Msgl : Natural;
4341 Wmsg : Boolean;
4342 Eloc : Source_Ptr;
4343
4344 -- Start of processing for Compile_Time_Constraint_Error
4345
4346 begin
4347 -- If this is a warning, convert it into an error if we are in code
4348 -- subject to SPARK_Mode being set ON.
4349
4350 Error_Msg_Warn := SPARK_Mode /= On;
4351
4352 -- A static constraint error in an instance body is not a fatal error.
4353 -- we choose to inhibit the message altogether, because there is no
4354 -- obvious node (for now) on which to post it. On the other hand the
4355 -- offending node must be replaced with a constraint_error in any case.
4356
4357 -- No messages are generated if we already posted an error on this node
4358
4359 if not Error_Posted (N) then
4360 if Loc /= No_Location then
4361 Eloc := Loc;
4362 else
4363 Eloc := Sloc (N);
4364 end if;
4365
4366 -- Copy message to Msgc, converting any ? in the message into
4367 -- < instead, so that we have an error in GNATprove mode.
4368
4369 Msgl := Msg'Length;
4370
4371 for J in 1 .. Msgl loop
4372 if Msg (J) = '?' and then (J = 1 or else Msg (J) /= ''') then
4373 Msgc (J) := '<';
4374 else
4375 Msgc (J) := Msg (J);
4376 end if;
4377 end loop;
4378
4379 -- Message is a warning, even in Ada 95 case
4380
4381 if Msg (Msg'Last) = '?' or else Msg (Msg'Last) = '<' then
4382 Wmsg := True;
4383
4384 -- In Ada 83, all messages are warnings. In the private part and
4385 -- the body of an instance, constraint_checks are only warnings.
4386 -- We also make this a warning if the Warn parameter is set.
4387
4388 elsif Warn
4389 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
4390 then
4391 Msgl := Msgl + 1;
4392 Msgc (Msgl) := '<';
4393 Msgl := Msgl + 1;
4394 Msgc (Msgl) := '<';
4395 Wmsg := True;
4396
4397 elsif In_Instance_Not_Visible then
4398 Msgl := Msgl + 1;
4399 Msgc (Msgl) := '<';
4400 Msgl := Msgl + 1;
4401 Msgc (Msgl) := '<';
4402 Wmsg := True;
4403
4404 -- Otherwise we have a real error message (Ada 95 static case)
4405 -- and we make this an unconditional message. Note that in the
4406 -- warning case we do not make the message unconditional, it seems
4407 -- quite reasonable to delete messages like this (about exceptions
4408 -- that will be raised) in dead code.
4409
4410 else
4411 Wmsg := False;
4412 Msgl := Msgl + 1;
4413 Msgc (Msgl) := '!';
4414 end if;
4415
4416 -- One more test, skip the warning if the related expression is
4417 -- statically unevaluated, since we don't want to warn about what
4418 -- will happen when something is evaluated if it never will be
4419 -- evaluated.
4420
4421 if not Is_Statically_Unevaluated (N) then
4422 Error_Msg_Warn := SPARK_Mode /= On;
4423
4424 if Present (Ent) then
4425 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
4426 else
4427 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
4428 end if;
4429
4430 if Wmsg then
4431
4432 -- Check whether the context is an Init_Proc
4433
4434 if Inside_Init_Proc then
4435 declare
4436 Conc_Typ : constant Entity_Id :=
4437 Corresponding_Concurrent_Type
4438 (Entity (Parameter_Type (First
4439 (Parameter_Specifications
4440 (Parent (Current_Scope))))));
4441
4442 begin
4443 -- Don't complain if the corresponding concurrent type
4444 -- doesn't come from source (i.e. a single task/protected
4445 -- object).
4446
4447 if Present (Conc_Typ)
4448 and then not Comes_From_Source (Conc_Typ)
4449 then
4450 Error_Msg_NEL
4451 ("\& [<<", N, Standard_Constraint_Error, Eloc);
4452
4453 else
4454 if GNATprove_Mode then
4455 Error_Msg_NEL
4456 ("\& would have been raised for objects of this "
4457 & "type", N, Standard_Constraint_Error, Eloc);
4458 else
4459 Error_Msg_NEL
4460 ("\& will be raised for objects of this type??",
4461 N, Standard_Constraint_Error, Eloc);
4462 end if;
4463 end if;
4464 end;
4465
4466 else
4467 Error_Msg_NEL ("\& [<<", N, Standard_Constraint_Error, Eloc);
4468 end if;
4469
4470 else
4471 Error_Msg ("\static expression fails Constraint_Check", Eloc);
4472 Set_Error_Posted (N);
4473 end if;
4474 end if;
4475 end if;
4476
4477 return N;
4478 end Compile_Time_Constraint_Error;
4479
4480 -----------------------
4481 -- Conditional_Delay --
4482 -----------------------
4483
4484 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
4485 begin
4486 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
4487 Set_Has_Delayed_Freeze (New_Ent);
4488 end if;
4489 end Conditional_Delay;
4490
4491 ----------------------------
4492 -- Contains_Refined_State --
4493 ----------------------------
4494
4495 function Contains_Refined_State (Prag : Node_Id) return Boolean is
4496 function Has_State_In_Dependency (List : Node_Id) return Boolean;
4497 -- Determine whether a dependency list mentions a state with a visible
4498 -- refinement.
4499
4500 function Has_State_In_Global (List : Node_Id) return Boolean;
4501 -- Determine whether a global list mentions a state with a visible
4502 -- refinement.
4503
4504 function Is_Refined_State (Item : Node_Id) return Boolean;
4505 -- Determine whether Item is a reference to an abstract state with a
4506 -- visible refinement.
4507
4508 -----------------------------
4509 -- Has_State_In_Dependency --
4510 -----------------------------
4511
4512 function Has_State_In_Dependency (List : Node_Id) return Boolean is
4513 Clause : Node_Id;
4514 Output : Node_Id;
4515
4516 begin
4517 -- A null dependency list does not mention any states
4518
4519 if Nkind (List) = N_Null then
4520 return False;
4521
4522 -- Dependency clauses appear as component associations of an
4523 -- aggregate.
4524
4525 elsif Nkind (List) = N_Aggregate
4526 and then Present (Component_Associations (List))
4527 then
4528 Clause := First (Component_Associations (List));
4529 while Present (Clause) loop
4530
4531 -- Inspect the outputs of a dependency clause
4532
4533 Output := First (Choices (Clause));
4534 while Present (Output) loop
4535 if Is_Refined_State (Output) then
4536 return True;
4537 end if;
4538
4539 Next (Output);
4540 end loop;
4541
4542 -- Inspect the outputs of a dependency clause
4543
4544 if Is_Refined_State (Expression (Clause)) then
4545 return True;
4546 end if;
4547
4548 Next (Clause);
4549 end loop;
4550
4551 -- If we get here, then none of the dependency clauses mention a
4552 -- state with visible refinement.
4553
4554 return False;
4555
4556 -- An illegal pragma managed to sneak in
4557
4558 else
4559 raise Program_Error;
4560 end if;
4561 end Has_State_In_Dependency;
4562
4563 -------------------------
4564 -- Has_State_In_Global --
4565 -------------------------
4566
4567 function Has_State_In_Global (List : Node_Id) return Boolean is
4568 Item : Node_Id;
4569
4570 begin
4571 -- A null global list does not mention any states
4572
4573 if Nkind (List) = N_Null then
4574 return False;
4575
4576 -- Simple global list or moded global list declaration
4577
4578 elsif Nkind (List) = N_Aggregate then
4579
4580 -- The declaration of a simple global list appear as a collection
4581 -- of expressions.
4582
4583 if Present (Expressions (List)) then
4584 Item := First (Expressions (List));
4585 while Present (Item) loop
4586 if Is_Refined_State (Item) then
4587 return True;
4588 end if;
4589
4590 Next (Item);
4591 end loop;
4592
4593 -- The declaration of a moded global list appears as a collection
4594 -- of component associations where individual choices denote
4595 -- modes.
4596
4597 else
4598 Item := First (Component_Associations (List));
4599 while Present (Item) loop
4600 if Has_State_In_Global (Expression (Item)) then
4601 return True;
4602 end if;
4603
4604 Next (Item);
4605 end loop;
4606 end if;
4607
4608 -- If we get here, then the simple/moded global list did not
4609 -- mention any states with a visible refinement.
4610
4611 return False;
4612
4613 -- Single global item declaration
4614
4615 elsif Is_Entity_Name (List) then
4616 return Is_Refined_State (List);
4617
4618 -- An illegal pragma managed to sneak in
4619
4620 else
4621 raise Program_Error;
4622 end if;
4623 end Has_State_In_Global;
4624
4625 ----------------------
4626 -- Is_Refined_State --
4627 ----------------------
4628
4629 function Is_Refined_State (Item : Node_Id) return Boolean is
4630 Elmt : Node_Id;
4631 Item_Id : Entity_Id;
4632
4633 begin
4634 if Nkind (Item) = N_Null then
4635 return False;
4636
4637 -- States cannot be subject to attribute 'Result. This case arises
4638 -- in dependency relations.
4639
4640 elsif Nkind (Item) = N_Attribute_Reference
4641 and then Attribute_Name (Item) = Name_Result
4642 then
4643 return False;
4644
4645 -- Multiple items appear as an aggregate. This case arises in
4646 -- dependency relations.
4647
4648 elsif Nkind (Item) = N_Aggregate
4649 and then Present (Expressions (Item))
4650 then
4651 Elmt := First (Expressions (Item));
4652 while Present (Elmt) loop
4653 if Is_Refined_State (Elmt) then
4654 return True;
4655 end if;
4656
4657 Next (Elmt);
4658 end loop;
4659
4660 -- If we get here, then none of the inputs or outputs reference a
4661 -- state with visible refinement.
4662
4663 return False;
4664
4665 -- Single item
4666
4667 else
4668 Item_Id := Entity_Of (Item);
4669
4670 return
4671 Present (Item_Id)
4672 and then Ekind (Item_Id) = E_Abstract_State
4673 and then Has_Visible_Refinement (Item_Id);
4674 end if;
4675 end Is_Refined_State;
4676
4677 -- Local variables
4678
4679 Arg : constant Node_Id :=
4680 Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
4681 Nam : constant Name_Id := Pragma_Name (Prag);
4682
4683 -- Start of processing for Contains_Refined_State
4684
4685 begin
4686 if Nam = Name_Depends then
4687 return Has_State_In_Dependency (Arg);
4688
4689 else pragma Assert (Nam = Name_Global);
4690 return Has_State_In_Global (Arg);
4691 end if;
4692 end Contains_Refined_State;
4693
4694 -------------------------
4695 -- Copy_Component_List --
4696 -------------------------
4697
4698 function Copy_Component_List
4699 (R_Typ : Entity_Id;
4700 Loc : Source_Ptr) return List_Id
4701 is
4702 Comp : Node_Id;
4703 Comps : constant List_Id := New_List;
4704
4705 begin
4706 Comp := First_Component (Underlying_Type (R_Typ));
4707 while Present (Comp) loop
4708 if Comes_From_Source (Comp) then
4709 declare
4710 Comp_Decl : constant Node_Id := Declaration_Node (Comp);
4711 begin
4712 Append_To (Comps,
4713 Make_Component_Declaration (Loc,
4714 Defining_Identifier =>
4715 Make_Defining_Identifier (Loc, Chars (Comp)),
4716 Component_Definition =>
4717 New_Copy_Tree
4718 (Component_Definition (Comp_Decl), New_Sloc => Loc)));
4719 end;
4720 end if;
4721
4722 Next_Component (Comp);
4723 end loop;
4724
4725 return Comps;
4726 end Copy_Component_List;
4727
4728 -------------------------
4729 -- Copy_Parameter_List --
4730 -------------------------
4731
4732 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
4733 Loc : constant Source_Ptr := Sloc (Subp_Id);
4734 Plist : List_Id;
4735 Formal : Entity_Id;
4736
4737 begin
4738 if No (First_Formal (Subp_Id)) then
4739 return No_List;
4740 else
4741 Plist := New_List;
4742 Formal := First_Formal (Subp_Id);
4743 while Present (Formal) loop
4744 Append_To (Plist,
4745 Make_Parameter_Specification (Loc,
4746 Defining_Identifier =>
4747 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)),
4748 In_Present => In_Present (Parent (Formal)),
4749 Out_Present => Out_Present (Parent (Formal)),
4750 Parameter_Type =>
4751 New_Occurrence_Of (Etype (Formal), Loc),
4752 Expression =>
4753 New_Copy_Tree (Expression (Parent (Formal)))));
4754
4755 Next_Formal (Formal);
4756 end loop;
4757 end if;
4758
4759 return Plist;
4760 end Copy_Parameter_List;
4761
4762 --------------------------
4763 -- Copy_Subprogram_Spec --
4764 --------------------------
4765
4766 function Copy_Subprogram_Spec (Spec : Node_Id) return Node_Id is
4767 Def_Id : Node_Id;
4768 Formal_Spec : Node_Id;
4769 Result : Node_Id;
4770
4771 begin
4772 -- The structure of the original tree must be replicated without any
4773 -- alterations. Use New_Copy_Tree for this purpose.
4774
4775 Result := New_Copy_Tree (Spec);
4776
4777 -- Create a new entity for the defining unit name
4778
4779 Def_Id := Defining_Unit_Name (Result);
4780 Set_Defining_Unit_Name (Result,
4781 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
4782
4783 -- Create new entities for the formal parameters
4784
4785 if Present (Parameter_Specifications (Result)) then
4786 Formal_Spec := First (Parameter_Specifications (Result));
4787 while Present (Formal_Spec) loop
4788 Def_Id := Defining_Identifier (Formal_Spec);
4789 Set_Defining_Identifier (Formal_Spec,
4790 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
4791
4792 Next (Formal_Spec);
4793 end loop;
4794 end if;
4795
4796 return Result;
4797 end Copy_Subprogram_Spec;
4798
4799 --------------------------------
4800 -- Corresponding_Generic_Type --
4801 --------------------------------
4802
4803 function Corresponding_Generic_Type (T : Entity_Id) return Entity_Id is
4804 Inst : Entity_Id;
4805 Gen : Entity_Id;
4806 Typ : Entity_Id;
4807
4808 begin
4809 if not Is_Generic_Actual_Type (T) then
4810 return Any_Type;
4811
4812 -- If the actual is the actual of an enclosing instance, resolution
4813 -- was correct in the generic.
4814
4815 elsif Nkind (Parent (T)) = N_Subtype_Declaration
4816 and then Is_Entity_Name (Subtype_Indication (Parent (T)))
4817 and then
4818 Is_Generic_Actual_Type (Entity (Subtype_Indication (Parent (T))))
4819 then
4820 return Any_Type;
4821
4822 else
4823 Inst := Scope (T);
4824
4825 if Is_Wrapper_Package (Inst) then
4826 Inst := Related_Instance (Inst);
4827 end if;
4828
4829 Gen :=
4830 Generic_Parent
4831 (Specification (Unit_Declaration_Node (Inst)));
4832
4833 -- Generic actual has the same name as the corresponding formal
4834
4835 Typ := First_Entity (Gen);
4836 while Present (Typ) loop
4837 if Chars (Typ) = Chars (T) then
4838 return Typ;
4839 end if;
4840
4841 Next_Entity (Typ);
4842 end loop;
4843
4844 return Any_Type;
4845 end if;
4846 end Corresponding_Generic_Type;
4847
4848 --------------------
4849 -- Current_Entity --
4850 --------------------
4851
4852 -- The currently visible definition for a given identifier is the
4853 -- one most chained at the start of the visibility chain, i.e. the
4854 -- one that is referenced by the Node_Id value of the name of the
4855 -- given identifier.
4856
4857 function Current_Entity (N : Node_Id) return Entity_Id is
4858 begin
4859 return Get_Name_Entity_Id (Chars (N));
4860 end Current_Entity;
4861
4862 -----------------------------
4863 -- Current_Entity_In_Scope --
4864 -----------------------------
4865
4866 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
4867 E : Entity_Id;
4868 CS : constant Entity_Id := Current_Scope;
4869
4870 Transient_Case : constant Boolean := Scope_Is_Transient;
4871
4872 begin
4873 E := Get_Name_Entity_Id (Chars (N));
4874 while Present (E)
4875 and then Scope (E) /= CS
4876 and then (not Transient_Case or else Scope (E) /= Scope (CS))
4877 loop
4878 E := Homonym (E);
4879 end loop;
4880
4881 return E;
4882 end Current_Entity_In_Scope;
4883
4884 -------------------
4885 -- Current_Scope --
4886 -------------------
4887
4888 function Current_Scope return Entity_Id is
4889 begin
4890 if Scope_Stack.Last = -1 then
4891 return Standard_Standard;
4892 else
4893 declare
4894 C : constant Entity_Id :=
4895 Scope_Stack.Table (Scope_Stack.Last).Entity;
4896 begin
4897 if Present (C) then
4898 return C;
4899 else
4900 return Standard_Standard;
4901 end if;
4902 end;
4903 end if;
4904 end Current_Scope;
4905
4906 ------------------------
4907 -- Current_Subprogram --
4908 ------------------------
4909
4910 function Current_Subprogram return Entity_Id is
4911 Scop : constant Entity_Id := Current_Scope;
4912 begin
4913 if Is_Subprogram_Or_Generic_Subprogram (Scop) then
4914 return Scop;
4915 else
4916 return Enclosing_Subprogram (Scop);
4917 end if;
4918 end Current_Subprogram;
4919
4920 ----------------------------------
4921 -- Deepest_Type_Access_Level --
4922 ----------------------------------
4923
4924 function Deepest_Type_Access_Level (Typ : Entity_Id) return Uint is
4925 begin
4926 if Ekind (Typ) = E_Anonymous_Access_Type
4927 and then not Is_Local_Anonymous_Access (Typ)
4928 and then Nkind (Associated_Node_For_Itype (Typ)) = N_Object_Declaration
4929 then
4930 -- Typ is the type of an Ada 2012 stand-alone object of an anonymous
4931 -- access type.
4932
4933 return
4934 Scope_Depth (Enclosing_Dynamic_Scope
4935 (Defining_Identifier
4936 (Associated_Node_For_Itype (Typ))));
4937
4938 -- For generic formal type, return Int'Last (infinite).
4939 -- See comment preceding Is_Generic_Type call in Type_Access_Level.
4940
4941 elsif Is_Generic_Type (Root_Type (Typ)) then
4942 return UI_From_Int (Int'Last);
4943
4944 else
4945 return Type_Access_Level (Typ);
4946 end if;
4947 end Deepest_Type_Access_Level;
4948
4949 ---------------------
4950 -- Defining_Entity --
4951 ---------------------
4952
4953 function Defining_Entity
4954 (N : Node_Id;
4955 Empty_On_Errors : Boolean := False) return Entity_Id
4956 is
4957 Err : Entity_Id := Empty;
4958
4959 begin
4960 case Nkind (N) is
4961 when N_Abstract_Subprogram_Declaration |
4962 N_Expression_Function |
4963 N_Formal_Subprogram_Declaration |
4964 N_Generic_Package_Declaration |
4965 N_Generic_Subprogram_Declaration |
4966 N_Package_Declaration |
4967 N_Subprogram_Body |
4968 N_Subprogram_Body_Stub |
4969 N_Subprogram_Declaration |
4970 N_Subprogram_Renaming_Declaration
4971 =>
4972 return Defining_Entity (Specification (N));
4973
4974 when N_Component_Declaration |
4975 N_Defining_Program_Unit_Name |
4976 N_Discriminant_Specification |
4977 N_Entry_Body |
4978 N_Entry_Declaration |
4979 N_Entry_Index_Specification |
4980 N_Exception_Declaration |
4981 N_Exception_Renaming_Declaration |
4982 N_Formal_Object_Declaration |
4983 N_Formal_Package_Declaration |
4984 N_Formal_Type_Declaration |
4985 N_Full_Type_Declaration |
4986 N_Implicit_Label_Declaration |
4987 N_Incomplete_Type_Declaration |
4988 N_Loop_Parameter_Specification |
4989 N_Number_Declaration |
4990 N_Object_Declaration |
4991 N_Object_Renaming_Declaration |
4992 N_Package_Body_Stub |
4993 N_Parameter_Specification |
4994 N_Private_Extension_Declaration |
4995 N_Private_Type_Declaration |
4996 N_Protected_Body |
4997 N_Protected_Body_Stub |
4998 N_Protected_Type_Declaration |
4999 N_Single_Protected_Declaration |
5000 N_Single_Task_Declaration |
5001 N_Subtype_Declaration |
5002 N_Task_Body |
5003 N_Task_Body_Stub |
5004 N_Task_Type_Declaration
5005 =>
5006 return Defining_Identifier (N);
5007
5008 when N_Subunit =>
5009 return Defining_Entity (Proper_Body (N));
5010
5011 when N_Function_Instantiation |
5012 N_Function_Specification |
5013 N_Generic_Function_Renaming_Declaration |
5014 N_Generic_Package_Renaming_Declaration |
5015 N_Generic_Procedure_Renaming_Declaration |
5016 N_Package_Body |
5017 N_Package_Instantiation |
5018 N_Package_Renaming_Declaration |
5019 N_Package_Specification |
5020 N_Procedure_Instantiation |
5021 N_Procedure_Specification
5022 =>
5023 declare
5024 Nam : constant Node_Id := Defining_Unit_Name (N);
5025
5026 begin
5027 if Nkind (Nam) in N_Entity then
5028 return Nam;
5029
5030 -- For Error, make up a name and attach to declaration so we
5031 -- can continue semantic analysis.
5032
5033 elsif Nam = Error then
5034 if Empty_On_Errors then
5035 return Empty;
5036 else
5037 Err := Make_Temporary (Sloc (N), 'T');
5038 Set_Defining_Unit_Name (N, Err);
5039
5040 return Err;
5041 end if;
5042
5043 -- If not an entity, get defining identifier
5044
5045 else
5046 return Defining_Identifier (Nam);
5047 end if;
5048 end;
5049
5050 when N_Block_Statement |
5051 N_Loop_Statement =>
5052 return Entity (Identifier (N));
5053
5054 when others =>
5055 if Empty_On_Errors then
5056 return Empty;
5057 else
5058 raise Program_Error;
5059 end if;
5060
5061 end case;
5062 end Defining_Entity;
5063
5064 --------------------------
5065 -- Denotes_Discriminant --
5066 --------------------------
5067
5068 function Denotes_Discriminant
5069 (N : Node_Id;
5070 Check_Concurrent : Boolean := False) return Boolean
5071 is
5072 E : Entity_Id;
5073
5074 begin
5075 if not Is_Entity_Name (N) or else No (Entity (N)) then
5076 return False;
5077 else
5078 E := Entity (N);
5079 end if;
5080
5081 -- If we are checking for a protected type, the discriminant may have
5082 -- been rewritten as the corresponding discriminal of the original type
5083 -- or of the corresponding concurrent record, depending on whether we
5084 -- are in the spec or body of the protected type.
5085
5086 return Ekind (E) = E_Discriminant
5087 or else
5088 (Check_Concurrent
5089 and then Ekind (E) = E_In_Parameter
5090 and then Present (Discriminal_Link (E))
5091 and then
5092 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
5093 or else
5094 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
5095 end Denotes_Discriminant;
5096
5097 -------------------------
5098 -- Denotes_Same_Object --
5099 -------------------------
5100
5101 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
5102 Obj1 : Node_Id := A1;
5103 Obj2 : Node_Id := A2;
5104
5105 function Has_Prefix (N : Node_Id) return Boolean;
5106 -- Return True if N has attribute Prefix
5107
5108 function Is_Renaming (N : Node_Id) return Boolean;
5109 -- Return true if N names a renaming entity
5110
5111 function Is_Valid_Renaming (N : Node_Id) return Boolean;
5112 -- For renamings, return False if the prefix of any dereference within
5113 -- the renamed object_name is a variable, or any expression within the
5114 -- renamed object_name contains references to variables or calls on
5115 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
5116
5117 ----------------
5118 -- Has_Prefix --
5119 ----------------
5120
5121 function Has_Prefix (N : Node_Id) return Boolean is
5122 begin
5123 return
5124 Nkind_In (N,
5125 N_Attribute_Reference,
5126 N_Expanded_Name,
5127 N_Explicit_Dereference,
5128 N_Indexed_Component,
5129 N_Reference,
5130 N_Selected_Component,
5131 N_Slice);
5132 end Has_Prefix;
5133
5134 -----------------
5135 -- Is_Renaming --
5136 -----------------
5137
5138 function Is_Renaming (N : Node_Id) return Boolean is
5139 begin
5140 return Is_Entity_Name (N)
5141 and then Present (Renamed_Entity (Entity (N)));
5142 end Is_Renaming;
5143
5144 -----------------------
5145 -- Is_Valid_Renaming --
5146 -----------------------
5147
5148 function Is_Valid_Renaming (N : Node_Id) return Boolean is
5149
5150 function Check_Renaming (N : Node_Id) return Boolean;
5151 -- Recursive function used to traverse all the prefixes of N
5152
5153 function Check_Renaming (N : Node_Id) return Boolean is
5154 begin
5155 if Is_Renaming (N)
5156 and then not Check_Renaming (Renamed_Entity (Entity (N)))
5157 then
5158 return False;
5159 end if;
5160
5161 if Nkind (N) = N_Indexed_Component then
5162 declare
5163 Indx : Node_Id;
5164
5165 begin
5166 Indx := First (Expressions (N));
5167 while Present (Indx) loop
5168 if not Is_OK_Static_Expression (Indx) then
5169 return False;
5170 end if;
5171
5172 Next_Index (Indx);
5173 end loop;
5174 end;
5175 end if;
5176
5177 if Has_Prefix (N) then
5178 declare
5179 P : constant Node_Id := Prefix (N);
5180
5181 begin
5182 if Nkind (N) = N_Explicit_Dereference
5183 and then Is_Variable (P)
5184 then
5185 return False;
5186
5187 elsif Is_Entity_Name (P)
5188 and then Ekind (Entity (P)) = E_Function
5189 then
5190 return False;
5191
5192 elsif Nkind (P) = N_Function_Call then
5193 return False;
5194 end if;
5195
5196 -- Recursion to continue traversing the prefix of the
5197 -- renaming expression
5198
5199 return Check_Renaming (P);
5200 end;
5201 end if;
5202
5203 return True;
5204 end Check_Renaming;
5205
5206 -- Start of processing for Is_Valid_Renaming
5207
5208 begin
5209 return Check_Renaming (N);
5210 end Is_Valid_Renaming;
5211
5212 -- Start of processing for Denotes_Same_Object
5213
5214 begin
5215 -- Both names statically denote the same stand-alone object or parameter
5216 -- (RM 6.4.1(6.5/3))
5217
5218 if Is_Entity_Name (Obj1)
5219 and then Is_Entity_Name (Obj2)
5220 and then Entity (Obj1) = Entity (Obj2)
5221 then
5222 return True;
5223 end if;
5224
5225 -- For renamings, the prefix of any dereference within the renamed
5226 -- object_name is not a variable, and any expression within the
5227 -- renamed object_name contains no references to variables nor
5228 -- calls on nonstatic functions (RM 6.4.1(6.10/3)).
5229
5230 if Is_Renaming (Obj1) then
5231 if Is_Valid_Renaming (Obj1) then
5232 Obj1 := Renamed_Entity (Entity (Obj1));
5233 else
5234 return False;
5235 end if;
5236 end if;
5237
5238 if Is_Renaming (Obj2) then
5239 if Is_Valid_Renaming (Obj2) then
5240 Obj2 := Renamed_Entity (Entity (Obj2));
5241 else
5242 return False;
5243 end if;
5244 end if;
5245
5246 -- No match if not same node kind (such cases are handled by
5247 -- Denotes_Same_Prefix)
5248
5249 if Nkind (Obj1) /= Nkind (Obj2) then
5250 return False;
5251
5252 -- After handling valid renamings, one of the two names statically
5253 -- denoted a renaming declaration whose renamed object_name is known
5254 -- to denote the same object as the other (RM 6.4.1(6.10/3))
5255
5256 elsif Is_Entity_Name (Obj1) then
5257 if Is_Entity_Name (Obj2) then
5258 return Entity (Obj1) = Entity (Obj2);
5259 else
5260 return False;
5261 end if;
5262
5263 -- Both names are selected_components, their prefixes are known to
5264 -- denote the same object, and their selector_names denote the same
5265 -- component (RM 6.4.1(6.6/3)).
5266
5267 elsif Nkind (Obj1) = N_Selected_Component then
5268 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
5269 and then
5270 Entity (Selector_Name (Obj1)) = Entity (Selector_Name (Obj2));
5271
5272 -- Both names are dereferences and the dereferenced names are known to
5273 -- denote the same object (RM 6.4.1(6.7/3))
5274
5275 elsif Nkind (Obj1) = N_Explicit_Dereference then
5276 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2));
5277
5278 -- Both names are indexed_components, their prefixes are known to denote
5279 -- the same object, and each of the pairs of corresponding index values
5280 -- are either both static expressions with the same static value or both
5281 -- names that are known to denote the same object (RM 6.4.1(6.8/3))
5282
5283 elsif Nkind (Obj1) = N_Indexed_Component then
5284 if not Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2)) then
5285 return False;
5286 else
5287 declare
5288 Indx1 : Node_Id;
5289 Indx2 : Node_Id;
5290
5291 begin
5292 Indx1 := First (Expressions (Obj1));
5293 Indx2 := First (Expressions (Obj2));
5294 while Present (Indx1) loop
5295
5296 -- Indexes must denote the same static value or same object
5297
5298 if Is_OK_Static_Expression (Indx1) then
5299 if not Is_OK_Static_Expression (Indx2) then
5300 return False;
5301
5302 elsif Expr_Value (Indx1) /= Expr_Value (Indx2) then
5303 return False;
5304 end if;
5305
5306 elsif not Denotes_Same_Object (Indx1, Indx2) then
5307 return False;
5308 end if;
5309
5310 Next (Indx1);
5311 Next (Indx2);
5312 end loop;
5313
5314 return True;
5315 end;
5316 end if;
5317
5318 -- Both names are slices, their prefixes are known to denote the same
5319 -- object, and the two slices have statically matching index constraints
5320 -- (RM 6.4.1(6.9/3))
5321
5322 elsif Nkind (Obj1) = N_Slice
5323 and then Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
5324 then
5325 declare
5326 Lo1, Lo2, Hi1, Hi2 : Node_Id;
5327
5328 begin
5329 Get_Index_Bounds (Etype (Obj1), Lo1, Hi1);
5330 Get_Index_Bounds (Etype (Obj2), Lo2, Hi2);
5331
5332 -- Check whether bounds are statically identical. There is no
5333 -- attempt to detect partial overlap of slices.
5334
5335 return Denotes_Same_Object (Lo1, Lo2)
5336 and then
5337 Denotes_Same_Object (Hi1, Hi2);
5338 end;
5339
5340 -- In the recursion, literals appear as indexes
5341
5342 elsif Nkind (Obj1) = N_Integer_Literal
5343 and then
5344 Nkind (Obj2) = N_Integer_Literal
5345 then
5346 return Intval (Obj1) = Intval (Obj2);
5347
5348 else
5349 return False;
5350 end if;
5351 end Denotes_Same_Object;
5352
5353 -------------------------
5354 -- Denotes_Same_Prefix --
5355 -------------------------
5356
5357 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
5358 begin
5359 if Is_Entity_Name (A1) then
5360 if Nkind_In (A2, N_Selected_Component, N_Indexed_Component)
5361 and then not Is_Access_Type (Etype (A1))
5362 then
5363 return Denotes_Same_Object (A1, Prefix (A2))
5364 or else Denotes_Same_Prefix (A1, Prefix (A2));
5365 else
5366 return False;
5367 end if;
5368
5369 elsif Is_Entity_Name (A2) then
5370 return Denotes_Same_Prefix (A1 => A2, A2 => A1);
5371
5372 elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
5373 and then
5374 Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
5375 then
5376 declare
5377 Root1, Root2 : Node_Id;
5378 Depth1, Depth2 : Int := 0;
5379
5380 begin
5381 Root1 := Prefix (A1);
5382 while not Is_Entity_Name (Root1) loop
5383 if not Nkind_In
5384 (Root1, N_Selected_Component, N_Indexed_Component)
5385 then
5386 return False;
5387 else
5388 Root1 := Prefix (Root1);
5389 end if;
5390
5391 Depth1 := Depth1 + 1;
5392 end loop;
5393
5394 Root2 := Prefix (A2);
5395 while not Is_Entity_Name (Root2) loop
5396 if not Nkind_In (Root2, N_Selected_Component,
5397 N_Indexed_Component)
5398 then
5399 return False;
5400 else
5401 Root2 := Prefix (Root2);
5402 end if;
5403
5404 Depth2 := Depth2 + 1;
5405 end loop;
5406
5407 -- If both have the same depth and they do not denote the same
5408 -- object, they are disjoint and no warning is needed.
5409
5410 if Depth1 = Depth2 then
5411 return False;
5412
5413 elsif Depth1 > Depth2 then
5414 Root1 := Prefix (A1);
5415 for J in 1 .. Depth1 - Depth2 - 1 loop
5416 Root1 := Prefix (Root1);
5417 end loop;
5418
5419 return Denotes_Same_Object (Root1, A2);
5420
5421 else
5422 Root2 := Prefix (A2);
5423 for J in 1 .. Depth2 - Depth1 - 1 loop
5424 Root2 := Prefix (Root2);
5425 end loop;
5426
5427 return Denotes_Same_Object (A1, Root2);
5428 end if;
5429 end;
5430
5431 else
5432 return False;
5433 end if;
5434 end Denotes_Same_Prefix;
5435
5436 ----------------------
5437 -- Denotes_Variable --
5438 ----------------------
5439
5440 function Denotes_Variable (N : Node_Id) return Boolean is
5441 begin
5442 return Is_Variable (N) and then Paren_Count (N) = 0;
5443 end Denotes_Variable;
5444
5445 -----------------------------
5446 -- Depends_On_Discriminant --
5447 -----------------------------
5448
5449 function Depends_On_Discriminant (N : Node_Id) return Boolean is
5450 L : Node_Id;
5451 H : Node_Id;
5452
5453 begin
5454 Get_Index_Bounds (N, L, H);
5455 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
5456 end Depends_On_Discriminant;
5457
5458 -------------------------
5459 -- Designate_Same_Unit --
5460 -------------------------
5461
5462 function Designate_Same_Unit
5463 (Name1 : Node_Id;
5464 Name2 : Node_Id) return Boolean
5465 is
5466 K1 : constant Node_Kind := Nkind (Name1);
5467 K2 : constant Node_Kind := Nkind (Name2);
5468
5469 function Prefix_Node (N : Node_Id) return Node_Id;
5470 -- Returns the parent unit name node of a defining program unit name
5471 -- or the prefix if N is a selected component or an expanded name.
5472
5473 function Select_Node (N : Node_Id) return Node_Id;
5474 -- Returns the defining identifier node of a defining program unit
5475 -- name or the selector node if N is a selected component or an
5476 -- expanded name.
5477
5478 -----------------
5479 -- Prefix_Node --
5480 -----------------
5481
5482 function Prefix_Node (N : Node_Id) return Node_Id is
5483 begin
5484 if Nkind (N) = N_Defining_Program_Unit_Name then
5485 return Name (N);
5486 else
5487 return Prefix (N);
5488 end if;
5489 end Prefix_Node;
5490
5491 -----------------
5492 -- Select_Node --
5493 -----------------
5494
5495 function Select_Node (N : Node_Id) return Node_Id is
5496 begin
5497 if Nkind (N) = N_Defining_Program_Unit_Name then
5498 return Defining_Identifier (N);
5499 else
5500 return Selector_Name (N);
5501 end if;
5502 end Select_Node;
5503
5504 -- Start of processing for Designate_Same_Unit
5505
5506 begin
5507 if Nkind_In (K1, N_Identifier, N_Defining_Identifier)
5508 and then
5509 Nkind_In (K2, N_Identifier, N_Defining_Identifier)
5510 then
5511 return Chars (Name1) = Chars (Name2);
5512
5513 elsif Nkind_In (K1, N_Expanded_Name,
5514 N_Selected_Component,
5515 N_Defining_Program_Unit_Name)
5516 and then
5517 Nkind_In (K2, N_Expanded_Name,
5518 N_Selected_Component,
5519 N_Defining_Program_Unit_Name)
5520 then
5521 return
5522 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
5523 and then
5524 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
5525
5526 else
5527 return False;
5528 end if;
5529 end Designate_Same_Unit;
5530
5531 ------------------------------------------
5532 -- function Dynamic_Accessibility_Level --
5533 ------------------------------------------
5534
5535 function Dynamic_Accessibility_Level (Expr : Node_Id) return Node_Id is
5536 E : Entity_Id;
5537 Loc : constant Source_Ptr := Sloc (Expr);
5538
5539 function Make_Level_Literal (Level : Uint) return Node_Id;
5540 -- Construct an integer literal representing an accessibility level
5541 -- with its type set to Natural.
5542
5543 ------------------------
5544 -- Make_Level_Literal --
5545 ------------------------
5546
5547 function Make_Level_Literal (Level : Uint) return Node_Id is
5548 Result : constant Node_Id := Make_Integer_Literal (Loc, Level);
5549 begin
5550 Set_Etype (Result, Standard_Natural);
5551 return Result;
5552 end Make_Level_Literal;
5553
5554 -- Start of processing for Dynamic_Accessibility_Level
5555
5556 begin
5557 if Is_Entity_Name (Expr) then
5558 E := Entity (Expr);
5559
5560 if Present (Renamed_Object (E)) then
5561 return Dynamic_Accessibility_Level (Renamed_Object (E));
5562 end if;
5563
5564 if Is_Formal (E) or else Ekind_In (E, E_Variable, E_Constant) then
5565 if Present (Extra_Accessibility (E)) then
5566 return New_Occurrence_Of (Extra_Accessibility (E), Loc);
5567 end if;
5568 end if;
5569 end if;
5570
5571 -- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
5572
5573 case Nkind (Expr) is
5574
5575 -- For access discriminant, the level of the enclosing object
5576
5577 when N_Selected_Component =>
5578 if Ekind (Entity (Selector_Name (Expr))) = E_Discriminant
5579 and then Ekind (Etype (Entity (Selector_Name (Expr)))) =
5580 E_Anonymous_Access_Type
5581 then
5582 return Make_Level_Literal (Object_Access_Level (Expr));
5583 end if;
5584
5585 when N_Attribute_Reference =>
5586 case Get_Attribute_Id (Attribute_Name (Expr)) is
5587
5588 -- For X'Access, the level of the prefix X
5589
5590 when Attribute_Access =>
5591 return Make_Level_Literal
5592 (Object_Access_Level (Prefix (Expr)));
5593
5594 -- Treat the unchecked attributes as library-level
5595
5596 when Attribute_Unchecked_Access |
5597 Attribute_Unrestricted_Access =>
5598 return Make_Level_Literal (Scope_Depth (Standard_Standard));
5599
5600 -- No other access-valued attributes
5601
5602 when others =>
5603 raise Program_Error;
5604 end case;
5605
5606 when N_Allocator =>
5607
5608 -- Unimplemented: depends on context. As an actual parameter where
5609 -- formal type is anonymous, use
5610 -- Scope_Depth (Current_Scope) + 1.
5611 -- For other cases, see 3.10.2(14/3) and following. ???
5612
5613 null;
5614
5615 when N_Type_Conversion =>
5616 if not Is_Local_Anonymous_Access (Etype (Expr)) then
5617
5618 -- Handle type conversions introduced for a rename of an
5619 -- Ada 2012 stand-alone object of an anonymous access type.
5620
5621 return Dynamic_Accessibility_Level (Expression (Expr));
5622 end if;
5623
5624 when others =>
5625 null;
5626 end case;
5627
5628 return Make_Level_Literal (Type_Access_Level (Etype (Expr)));
5629 end Dynamic_Accessibility_Level;
5630
5631 -----------------------------------
5632 -- Effective_Extra_Accessibility --
5633 -----------------------------------
5634
5635 function Effective_Extra_Accessibility (Id : Entity_Id) return Entity_Id is
5636 begin
5637 if Present (Renamed_Object (Id))
5638 and then Is_Entity_Name (Renamed_Object (Id))
5639 then
5640 return Effective_Extra_Accessibility (Entity (Renamed_Object (Id)));
5641 else
5642 return Extra_Accessibility (Id);
5643 end if;
5644 end Effective_Extra_Accessibility;
5645
5646 -----------------------------
5647 -- Effective_Reads_Enabled --
5648 -----------------------------
5649
5650 function Effective_Reads_Enabled (Id : Entity_Id) return Boolean is
5651 begin
5652 return Has_Enabled_Property (Id, Name_Effective_Reads);
5653 end Effective_Reads_Enabled;
5654
5655 ------------------------------
5656 -- Effective_Writes_Enabled --
5657 ------------------------------
5658
5659 function Effective_Writes_Enabled (Id : Entity_Id) return Boolean is
5660 begin
5661 return Has_Enabled_Property (Id, Name_Effective_Writes);
5662 end Effective_Writes_Enabled;
5663
5664 ------------------------------
5665 -- Enclosing_Comp_Unit_Node --
5666 ------------------------------
5667
5668 function Enclosing_Comp_Unit_Node (N : Node_Id) return Node_Id is
5669 Current_Node : Node_Id;
5670
5671 begin
5672 Current_Node := N;
5673 while Present (Current_Node)
5674 and then Nkind (Current_Node) /= N_Compilation_Unit
5675 loop
5676 Current_Node := Parent (Current_Node);
5677 end loop;
5678
5679 if Nkind (Current_Node) /= N_Compilation_Unit then
5680 return Empty;
5681 else
5682 return Current_Node;
5683 end if;
5684 end Enclosing_Comp_Unit_Node;
5685
5686 --------------------------
5687 -- Enclosing_CPP_Parent --
5688 --------------------------
5689
5690 function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is
5691 Parent_Typ : Entity_Id := Typ;
5692
5693 begin
5694 while not Is_CPP_Class (Parent_Typ)
5695 and then Etype (Parent_Typ) /= Parent_Typ
5696 loop
5697 Parent_Typ := Etype (Parent_Typ);
5698
5699 if Is_Private_Type (Parent_Typ) then
5700 Parent_Typ := Full_View (Base_Type (Parent_Typ));
5701 end if;
5702 end loop;
5703
5704 pragma Assert (Is_CPP_Class (Parent_Typ));
5705 return Parent_Typ;
5706 end Enclosing_CPP_Parent;
5707
5708 ---------------------------
5709 -- Enclosing_Declaration --
5710 ---------------------------
5711
5712 function Enclosing_Declaration (N : Node_Id) return Node_Id is
5713 Decl : Node_Id := N;
5714
5715 begin
5716 while Present (Decl)
5717 and then not (Nkind (Decl) in N_Declaration
5718 or else
5719 Nkind (Decl) in N_Later_Decl_Item)
5720 loop
5721 Decl := Parent (Decl);
5722 end loop;
5723
5724 return Decl;
5725 end Enclosing_Declaration;
5726
5727 ----------------------------
5728 -- Enclosing_Generic_Body --
5729 ----------------------------
5730
5731 function Enclosing_Generic_Body
5732 (N : Node_Id) return Node_Id
5733 is
5734 P : Node_Id;
5735 Decl : Node_Id;
5736 Spec : Node_Id;
5737
5738 begin
5739 P := Parent (N);
5740 while Present (P) loop
5741 if Nkind (P) = N_Package_Body
5742 or else Nkind (P) = N_Subprogram_Body
5743 then
5744 Spec := Corresponding_Spec (P);
5745
5746 if Present (Spec) then
5747 Decl := Unit_Declaration_Node (Spec);
5748
5749 if Nkind (Decl) = N_Generic_Package_Declaration
5750 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
5751 then
5752 return P;
5753 end if;
5754 end if;
5755 end if;
5756
5757 P := Parent (P);
5758 end loop;
5759
5760 return Empty;
5761 end Enclosing_Generic_Body;
5762
5763 ----------------------------
5764 -- Enclosing_Generic_Unit --
5765 ----------------------------
5766
5767 function Enclosing_Generic_Unit
5768 (N : Node_Id) return Node_Id
5769 is
5770 P : Node_Id;
5771 Decl : Node_Id;
5772 Spec : Node_Id;
5773
5774 begin
5775 P := Parent (N);
5776 while Present (P) loop
5777 if Nkind (P) = N_Generic_Package_Declaration
5778 or else Nkind (P) = N_Generic_Subprogram_Declaration
5779 then
5780 return P;
5781
5782 elsif Nkind (P) = N_Package_Body
5783 or else Nkind (P) = N_Subprogram_Body
5784 then
5785 Spec := Corresponding_Spec (P);
5786
5787 if Present (Spec) then
5788 Decl := Unit_Declaration_Node (Spec);
5789
5790 if Nkind (Decl) = N_Generic_Package_Declaration
5791 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
5792 then
5793 return Decl;
5794 end if;
5795 end if;
5796 end if;
5797
5798 P := Parent (P);
5799 end loop;
5800
5801 return Empty;
5802 end Enclosing_Generic_Unit;
5803
5804 -------------------------------
5805 -- Enclosing_Lib_Unit_Entity --
5806 -------------------------------
5807
5808 function Enclosing_Lib_Unit_Entity
5809 (E : Entity_Id := Current_Scope) return Entity_Id
5810 is
5811 Unit_Entity : Entity_Id;
5812
5813 begin
5814 -- Look for enclosing library unit entity by following scope links.
5815 -- Equivalent to, but faster than indexing through the scope stack.
5816
5817 Unit_Entity := E;
5818 while (Present (Scope (Unit_Entity))
5819 and then Scope (Unit_Entity) /= Standard_Standard)
5820 and not Is_Child_Unit (Unit_Entity)
5821 loop
5822 Unit_Entity := Scope (Unit_Entity);
5823 end loop;
5824
5825 return Unit_Entity;
5826 end Enclosing_Lib_Unit_Entity;
5827
5828 -----------------------------
5829 -- Enclosing_Lib_Unit_Node --
5830 -----------------------------
5831
5832 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
5833 Encl_Unit : Node_Id;
5834
5835 begin
5836 Encl_Unit := Enclosing_Comp_Unit_Node (N);
5837 while Present (Encl_Unit)
5838 and then Nkind (Unit (Encl_Unit)) = N_Subunit
5839 loop
5840 Encl_Unit := Library_Unit (Encl_Unit);
5841 end loop;
5842
5843 return Encl_Unit;
5844 end Enclosing_Lib_Unit_Node;
5845
5846 -----------------------
5847 -- Enclosing_Package --
5848 -----------------------
5849
5850 function Enclosing_Package (E : Entity_Id) return Entity_Id is
5851 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
5852
5853 begin
5854 if Dynamic_Scope = Standard_Standard then
5855 return Standard_Standard;
5856
5857 elsif Dynamic_Scope = Empty then
5858 return Empty;
5859
5860 elsif Ekind_In (Dynamic_Scope, E_Package, E_Package_Body,
5861 E_Generic_Package)
5862 then
5863 return Dynamic_Scope;
5864
5865 else
5866 return Enclosing_Package (Dynamic_Scope);
5867 end if;
5868 end Enclosing_Package;
5869
5870 -------------------------------------
5871 -- Enclosing_Package_Or_Subprogram --
5872 -------------------------------------
5873
5874 function Enclosing_Package_Or_Subprogram (E : Entity_Id) return Entity_Id is
5875 S : Entity_Id;
5876
5877 begin
5878 S := Scope (E);
5879 while Present (S) loop
5880 if Is_Package_Or_Generic_Package (S)
5881 or else Ekind (S) = E_Package_Body
5882 then
5883 return S;
5884
5885 elsif Is_Subprogram_Or_Generic_Subprogram (S)
5886 or else Ekind (S) = E_Subprogram_Body
5887 then
5888 return S;
5889
5890 else
5891 S := Scope (S);
5892 end if;
5893 end loop;
5894
5895 return Empty;
5896 end Enclosing_Package_Or_Subprogram;
5897
5898 --------------------------
5899 -- Enclosing_Subprogram --
5900 --------------------------
5901
5902 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
5903 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
5904
5905 begin
5906 if Dynamic_Scope = Standard_Standard then
5907 return Empty;
5908
5909 elsif Dynamic_Scope = Empty then
5910 return Empty;
5911
5912 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
5913 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
5914
5915 elsif Ekind (Dynamic_Scope) = E_Block
5916 or else Ekind (Dynamic_Scope) = E_Return_Statement
5917 then
5918 return Enclosing_Subprogram (Dynamic_Scope);
5919
5920 elsif Ekind (Dynamic_Scope) = E_Task_Type then
5921 return Get_Task_Body_Procedure (Dynamic_Scope);
5922
5923 elsif Ekind (Dynamic_Scope) = E_Limited_Private_Type
5924 and then Present (Full_View (Dynamic_Scope))
5925 and then Ekind (Full_View (Dynamic_Scope)) = E_Task_Type
5926 then
5927 return Get_Task_Body_Procedure (Full_View (Dynamic_Scope));
5928
5929 -- No body is generated if the protected operation is eliminated
5930
5931 elsif Convention (Dynamic_Scope) = Convention_Protected
5932 and then not Is_Eliminated (Dynamic_Scope)
5933 and then Present (Protected_Body_Subprogram (Dynamic_Scope))
5934 then
5935 return Protected_Body_Subprogram (Dynamic_Scope);
5936
5937 else
5938 return Dynamic_Scope;
5939 end if;
5940 end Enclosing_Subprogram;
5941
5942 ------------------------
5943 -- Ensure_Freeze_Node --
5944 ------------------------
5945
5946 procedure Ensure_Freeze_Node (E : Entity_Id) is
5947 FN : Node_Id;
5948 begin
5949 if No (Freeze_Node (E)) then
5950 FN := Make_Freeze_Entity (Sloc (E));
5951 Set_Has_Delayed_Freeze (E);
5952 Set_Freeze_Node (E, FN);
5953 Set_Access_Types_To_Process (FN, No_Elist);
5954 Set_TSS_Elist (FN, No_Elist);
5955 Set_Entity (FN, E);
5956 end if;
5957 end Ensure_Freeze_Node;
5958
5959 ----------------
5960 -- Enter_Name --
5961 ----------------
5962
5963 procedure Enter_Name (Def_Id : Entity_Id) is
5964 C : constant Entity_Id := Current_Entity (Def_Id);
5965 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
5966 S : constant Entity_Id := Current_Scope;
5967
5968 begin
5969 Generate_Definition (Def_Id);
5970
5971 -- Add new name to current scope declarations. Check for duplicate
5972 -- declaration, which may or may not be a genuine error.
5973
5974 if Present (E) then
5975
5976 -- Case of previous entity entered because of a missing declaration
5977 -- or else a bad subtype indication. Best is to use the new entity,
5978 -- and make the previous one invisible.
5979
5980 if Etype (E) = Any_Type then
5981 Set_Is_Immediately_Visible (E, False);
5982
5983 -- Case of renaming declaration constructed for package instances.
5984 -- if there is an explicit declaration with the same identifier,
5985 -- the renaming is not immediately visible any longer, but remains
5986 -- visible through selected component notation.
5987
5988 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
5989 and then not Comes_From_Source (E)
5990 then
5991 Set_Is_Immediately_Visible (E, False);
5992
5993 -- The new entity may be the package renaming, which has the same
5994 -- same name as a generic formal which has been seen already.
5995
5996 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
5997 and then not Comes_From_Source (Def_Id)
5998 then
5999 Set_Is_Immediately_Visible (E, False);
6000
6001 -- For a fat pointer corresponding to a remote access to subprogram,
6002 -- we use the same identifier as the RAS type, so that the proper
6003 -- name appears in the stub. This type is only retrieved through
6004 -- the RAS type and never by visibility, and is not added to the
6005 -- visibility list (see below).
6006
6007 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
6008 and then Ekind (Def_Id) = E_Record_Type
6009 and then Present (Corresponding_Remote_Type (Def_Id))
6010 then
6011 null;
6012
6013 -- Case of an implicit operation or derived literal. The new entity
6014 -- hides the implicit one, which is removed from all visibility,
6015 -- i.e. the entity list of its scope, and homonym chain of its name.
6016
6017 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
6018 or else Is_Internal (E)
6019 then
6020 declare
6021 Prev : Entity_Id;
6022 Prev_Vis : Entity_Id;
6023 Decl : constant Node_Id := Parent (E);
6024
6025 begin
6026 -- If E is an implicit declaration, it cannot be the first
6027 -- entity in the scope.
6028
6029 Prev := First_Entity (Current_Scope);
6030 while Present (Prev) and then Next_Entity (Prev) /= E loop
6031 Next_Entity (Prev);
6032 end loop;
6033
6034 if No (Prev) then
6035
6036 -- If E is not on the entity chain of the current scope,
6037 -- it is an implicit declaration in the generic formal
6038 -- part of a generic subprogram. When analyzing the body,
6039 -- the generic formals are visible but not on the entity
6040 -- chain of the subprogram. The new entity will become
6041 -- the visible one in the body.
6042
6043 pragma Assert
6044 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
6045 null;
6046
6047 else
6048 Set_Next_Entity (Prev, Next_Entity (E));
6049
6050 if No (Next_Entity (Prev)) then
6051 Set_Last_Entity (Current_Scope, Prev);
6052 end if;
6053
6054 if E = Current_Entity (E) then
6055 Prev_Vis := Empty;
6056
6057 else
6058 Prev_Vis := Current_Entity (E);
6059 while Homonym (Prev_Vis) /= E loop
6060 Prev_Vis := Homonym (Prev_Vis);
6061 end loop;
6062 end if;
6063
6064 if Present (Prev_Vis) then
6065
6066 -- Skip E in the visibility chain
6067
6068 Set_Homonym (Prev_Vis, Homonym (E));
6069
6070 else
6071 Set_Name_Entity_Id (Chars (E), Homonym (E));
6072 end if;
6073 end if;
6074 end;
6075
6076 -- This section of code could use a comment ???
6077
6078 elsif Present (Etype (E))
6079 and then Is_Concurrent_Type (Etype (E))
6080 and then E = Def_Id
6081 then
6082 return;
6083
6084 -- If the homograph is a protected component renaming, it should not
6085 -- be hiding the current entity. Such renamings are treated as weak
6086 -- declarations.
6087
6088 elsif Is_Prival (E) then
6089 Set_Is_Immediately_Visible (E, False);
6090
6091 -- In this case the current entity is a protected component renaming.
6092 -- Perform minimal decoration by setting the scope and return since
6093 -- the prival should not be hiding other visible entities.
6094
6095 elsif Is_Prival (Def_Id) then
6096 Set_Scope (Def_Id, Current_Scope);
6097 return;
6098
6099 -- Analogous to privals, the discriminal generated for an entry index
6100 -- parameter acts as a weak declaration. Perform minimal decoration
6101 -- to avoid bogus errors.
6102
6103 elsif Is_Discriminal (Def_Id)
6104 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
6105 then
6106 Set_Scope (Def_Id, Current_Scope);
6107 return;
6108
6109 -- In the body or private part of an instance, a type extension may
6110 -- introduce a component with the same name as that of an actual. The
6111 -- legality rule is not enforced, but the semantics of the full type
6112 -- with two components of same name are not clear at this point???
6113
6114 elsif In_Instance_Not_Visible then
6115 null;
6116
6117 -- When compiling a package body, some child units may have become
6118 -- visible. They cannot conflict with local entities that hide them.
6119
6120 elsif Is_Child_Unit (E)
6121 and then In_Open_Scopes (Scope (E))
6122 and then not Is_Immediately_Visible (E)
6123 then
6124 null;
6125
6126 -- Conversely, with front-end inlining we may compile the parent body
6127 -- first, and a child unit subsequently. The context is now the
6128 -- parent spec, and body entities are not visible.
6129
6130 elsif Is_Child_Unit (Def_Id)
6131 and then Is_Package_Body_Entity (E)
6132 and then not In_Package_Body (Current_Scope)
6133 then
6134 null;
6135
6136 -- Case of genuine duplicate declaration
6137
6138 else
6139 Error_Msg_Sloc := Sloc (E);
6140
6141 -- If the previous declaration is an incomplete type declaration
6142 -- this may be an attempt to complete it with a private type. The
6143 -- following avoids confusing cascaded errors.
6144
6145 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
6146 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
6147 then
6148 Error_Msg_N
6149 ("incomplete type cannot be completed with a private " &
6150 "declaration", Parent (Def_Id));
6151 Set_Is_Immediately_Visible (E, False);
6152 Set_Full_View (E, Def_Id);
6153
6154 -- An inherited component of a record conflicts with a new
6155 -- discriminant. The discriminant is inserted first in the scope,
6156 -- but the error should be posted on it, not on the component.
6157
6158 elsif Ekind (E) = E_Discriminant
6159 and then Present (Scope (Def_Id))
6160 and then Scope (Def_Id) /= Current_Scope
6161 then
6162 Error_Msg_Sloc := Sloc (Def_Id);
6163 Error_Msg_N ("& conflicts with declaration#", E);
6164 return;
6165
6166 -- If the name of the unit appears in its own context clause, a
6167 -- dummy package with the name has already been created, and the
6168 -- error emitted. Try to continue quietly.
6169
6170 elsif Error_Posted (E)
6171 and then Sloc (E) = No_Location
6172 and then Nkind (Parent (E)) = N_Package_Specification
6173 and then Current_Scope = Standard_Standard
6174 then
6175 Set_Scope (Def_Id, Current_Scope);
6176 return;
6177
6178 else
6179 Error_Msg_N ("& conflicts with declaration#", Def_Id);
6180
6181 -- Avoid cascaded messages with duplicate components in
6182 -- derived types.
6183
6184 if Ekind_In (E, E_Component, E_Discriminant) then
6185 return;
6186 end if;
6187 end if;
6188
6189 if Nkind (Parent (Parent (Def_Id))) =
6190 N_Generic_Subprogram_Declaration
6191 and then Def_Id =
6192 Defining_Entity (Specification (Parent (Parent (Def_Id))))
6193 then
6194 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
6195 end if;
6196
6197 -- If entity is in standard, then we are in trouble, because it
6198 -- means that we have a library package with a duplicated name.
6199 -- That's hard to recover from, so abort.
6200
6201 if S = Standard_Standard then
6202 raise Unrecoverable_Error;
6203
6204 -- Otherwise we continue with the declaration. Having two
6205 -- identical declarations should not cause us too much trouble.
6206
6207 else
6208 null;
6209 end if;
6210 end if;
6211 end if;
6212
6213 -- If we fall through, declaration is OK, at least OK enough to continue
6214
6215 -- If Def_Id is a discriminant or a record component we are in the midst
6216 -- of inheriting components in a derived record definition. Preserve
6217 -- their Ekind and Etype.
6218
6219 if Ekind_In (Def_Id, E_Discriminant, E_Component) then
6220 null;
6221
6222 -- If a type is already set, leave it alone (happens when a type
6223 -- declaration is reanalyzed following a call to the optimizer).
6224
6225 elsif Present (Etype (Def_Id)) then
6226 null;
6227
6228 -- Otherwise, the kind E_Void insures that premature uses of the entity
6229 -- will be detected. Any_Type insures that no cascaded errors will occur
6230
6231 else
6232 Set_Ekind (Def_Id, E_Void);
6233 Set_Etype (Def_Id, Any_Type);
6234 end if;
6235
6236 -- Inherited discriminants and components in derived record types are
6237 -- immediately visible. Itypes are not.
6238
6239 -- Unless the Itype is for a record type with a corresponding remote
6240 -- type (what is that about, it was not commented ???)
6241
6242 if Ekind_In (Def_Id, E_Discriminant, E_Component)
6243 or else
6244 ((not Is_Record_Type (Def_Id)
6245 or else No (Corresponding_Remote_Type (Def_Id)))
6246 and then not Is_Itype (Def_Id))
6247 then
6248 Set_Is_Immediately_Visible (Def_Id);
6249 Set_Current_Entity (Def_Id);
6250 end if;
6251
6252 Set_Homonym (Def_Id, C);
6253 Append_Entity (Def_Id, S);
6254 Set_Public_Status (Def_Id);
6255
6256 -- Declaring a homonym is not allowed in SPARK ...
6257
6258 if Present (C) and then Restriction_Check_Required (SPARK_05) then
6259 declare
6260 Enclosing_Subp : constant Node_Id := Enclosing_Subprogram (Def_Id);
6261 Enclosing_Pack : constant Node_Id := Enclosing_Package (Def_Id);
6262 Other_Scope : constant Node_Id := Enclosing_Dynamic_Scope (C);
6263
6264 begin
6265 -- ... unless the new declaration is in a subprogram, and the
6266 -- visible declaration is a variable declaration or a parameter
6267 -- specification outside that subprogram.
6268
6269 if Present (Enclosing_Subp)
6270 and then Nkind_In (Parent (C), N_Object_Declaration,
6271 N_Parameter_Specification)
6272 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Subp)
6273 then
6274 null;
6275
6276 -- ... or the new declaration is in a package, and the visible
6277 -- declaration occurs outside that package.
6278
6279 elsif Present (Enclosing_Pack)
6280 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Pack)
6281 then
6282 null;
6283
6284 -- ... or the new declaration is a component declaration in a
6285 -- record type definition.
6286
6287 elsif Nkind (Parent (Def_Id)) = N_Component_Declaration then
6288 null;
6289
6290 -- Don't issue error for non-source entities
6291
6292 elsif Comes_From_Source (Def_Id)
6293 and then Comes_From_Source (C)
6294 then
6295 Error_Msg_Sloc := Sloc (C);
6296 Check_SPARK_05_Restriction
6297 ("redeclaration of identifier &#", Def_Id);
6298 end if;
6299 end;
6300 end if;
6301
6302 -- Warn if new entity hides an old one
6303
6304 if Warn_On_Hiding and then Present (C)
6305
6306 -- Don't warn for record components since they always have a well
6307 -- defined scope which does not confuse other uses. Note that in
6308 -- some cases, Ekind has not been set yet.
6309
6310 and then Ekind (C) /= E_Component
6311 and then Ekind (C) /= E_Discriminant
6312 and then Nkind (Parent (C)) /= N_Component_Declaration
6313 and then Ekind (Def_Id) /= E_Component
6314 and then Ekind (Def_Id) /= E_Discriminant
6315 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
6316
6317 -- Don't warn for one character variables. It is too common to use
6318 -- such variables as locals and will just cause too many false hits.
6319
6320 and then Length_Of_Name (Chars (C)) /= 1
6321
6322 -- Don't warn for non-source entities
6323
6324 and then Comes_From_Source (C)
6325 and then Comes_From_Source (Def_Id)
6326
6327 -- Don't warn unless entity in question is in extended main source
6328
6329 and then In_Extended_Main_Source_Unit (Def_Id)
6330
6331 -- Finally, the hidden entity must be either immediately visible or
6332 -- use visible (i.e. from a used package).
6333
6334 and then
6335 (Is_Immediately_Visible (C)
6336 or else
6337 Is_Potentially_Use_Visible (C))
6338 then
6339 Error_Msg_Sloc := Sloc (C);
6340 Error_Msg_N ("declaration hides &#?h?", Def_Id);
6341 end if;
6342 end Enter_Name;
6343
6344 ---------------
6345 -- Entity_Of --
6346 ---------------
6347
6348 function Entity_Of (N : Node_Id) return Entity_Id is
6349 Id : Entity_Id;
6350
6351 begin
6352 Id := Empty;
6353
6354 if Is_Entity_Name (N) then
6355 Id := Entity (N);
6356
6357 -- Follow a possible chain of renamings to reach the root renamed
6358 -- object.
6359
6360 while Present (Id)
6361 and then Is_Object (Id)
6362 and then Present (Renamed_Object (Id))
6363 loop
6364 if Is_Entity_Name (Renamed_Object (Id)) then
6365 Id := Entity (Renamed_Object (Id));
6366 else
6367 Id := Empty;
6368 exit;
6369 end if;
6370 end loop;
6371 end if;
6372
6373 return Id;
6374 end Entity_Of;
6375
6376 --------------------------
6377 -- Explain_Limited_Type --
6378 --------------------------
6379
6380 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
6381 C : Entity_Id;
6382
6383 begin
6384 -- For array, component type must be limited
6385
6386 if Is_Array_Type (T) then
6387 Error_Msg_Node_2 := T;
6388 Error_Msg_NE
6389 ("\component type& of type& is limited", N, Component_Type (T));
6390 Explain_Limited_Type (Component_Type (T), N);
6391
6392 elsif Is_Record_Type (T) then
6393
6394 -- No need for extra messages if explicit limited record
6395
6396 if Is_Limited_Record (Base_Type (T)) then
6397 return;
6398 end if;
6399
6400 -- Otherwise find a limited component. Check only components that
6401 -- come from source, or inherited components that appear in the
6402 -- source of the ancestor.
6403
6404 C := First_Component (T);
6405 while Present (C) loop
6406 if Is_Limited_Type (Etype (C))
6407 and then
6408 (Comes_From_Source (C)
6409 or else
6410 (Present (Original_Record_Component (C))
6411 and then
6412 Comes_From_Source (Original_Record_Component (C))))
6413 then
6414 Error_Msg_Node_2 := T;
6415 Error_Msg_NE ("\component& of type& has limited type", N, C);
6416 Explain_Limited_Type (Etype (C), N);
6417 return;
6418 end if;
6419
6420 Next_Component (C);
6421 end loop;
6422
6423 -- The type may be declared explicitly limited, even if no component
6424 -- of it is limited, in which case we fall out of the loop.
6425 return;
6426 end if;
6427 end Explain_Limited_Type;
6428
6429 -------------------------------
6430 -- Extensions_Visible_Status --
6431 -------------------------------
6432
6433 function Extensions_Visible_Status
6434 (Id : Entity_Id) return Extensions_Visible_Mode
6435 is
6436 Arg : Node_Id;
6437 Decl : Node_Id;
6438 Expr : Node_Id;
6439 Prag : Node_Id;
6440 Subp : Entity_Id;
6441
6442 begin
6443 -- When a formal parameter is subject to Extensions_Visible, the pragma
6444 -- is stored in the contract of related subprogram.
6445
6446 if Is_Formal (Id) then
6447 Subp := Scope (Id);
6448
6449 elsif Is_Subprogram_Or_Generic_Subprogram (Id) then
6450 Subp := Id;
6451
6452 -- No other construct carries this pragma
6453
6454 else
6455 return Extensions_Visible_None;
6456 end if;
6457
6458 Prag := Get_Pragma (Subp, Pragma_Extensions_Visible);
6459
6460 -- In certain cases analysis may request the Extensions_Visible status
6461 -- of an expression function before the pragma has been analyzed yet.
6462 -- Inspect the declarative items after the expression function looking
6463 -- for the pragma (if any).
6464
6465 if No (Prag) and then Is_Expression_Function (Subp) then
6466 Decl := Next (Unit_Declaration_Node (Subp));
6467 while Present (Decl) loop
6468 if Nkind (Decl) = N_Pragma
6469 and then Pragma_Name (Decl) = Name_Extensions_Visible
6470 then
6471 Prag := Decl;
6472 exit;
6473
6474 -- A source construct ends the region where Extensions_Visible may
6475 -- appear, stop the traversal. An expanded expression function is
6476 -- no longer a source construct, but it must still be recognized.
6477
6478 elsif Comes_From_Source (Decl)
6479 or else
6480 (Nkind_In (Decl, N_Subprogram_Body,
6481 N_Subprogram_Declaration)
6482 and then Is_Expression_Function (Defining_Entity (Decl)))
6483 then
6484 exit;
6485 end if;
6486
6487 Next (Decl);
6488 end loop;
6489 end if;
6490
6491 -- Extract the value from the Boolean expression (if any)
6492
6493 if Present (Prag) then
6494 Arg := First (Pragma_Argument_Associations (Prag));
6495
6496 if Present (Arg) then
6497 Expr := Get_Pragma_Arg (Arg);
6498
6499 -- When the associated subprogram is an expression function, the
6500 -- argument of the pragma may not have been analyzed.
6501
6502 if not Analyzed (Expr) then
6503 Preanalyze_And_Resolve (Expr, Standard_Boolean);
6504 end if;
6505
6506 -- Guard against cascading errors when the argument of pragma
6507 -- Extensions_Visible is not a valid static Boolean expression.
6508
6509 if Error_Posted (Expr) then
6510 return Extensions_Visible_None;
6511
6512 elsif Is_True (Expr_Value (Expr)) then
6513 return Extensions_Visible_True;
6514
6515 else
6516 return Extensions_Visible_False;
6517 end if;
6518
6519 -- Otherwise the aspect or pragma defaults to True
6520
6521 else
6522 return Extensions_Visible_True;
6523 end if;
6524
6525 -- Otherwise aspect or pragma Extensions_Visible is not inherited or
6526 -- directly specified. In SPARK code, its value defaults to "False".
6527
6528 elsif SPARK_Mode = On then
6529 return Extensions_Visible_False;
6530
6531 -- In non-SPARK code, aspect or pragma Extensions_Visible defaults to
6532 -- "True".
6533
6534 else
6535 return Extensions_Visible_True;
6536 end if;
6537 end Extensions_Visible_Status;
6538
6539 -----------------
6540 -- Find_Actual --
6541 -----------------
6542
6543 procedure Find_Actual
6544 (N : Node_Id;
6545 Formal : out Entity_Id;
6546 Call : out Node_Id)
6547 is
6548 Context : constant Node_Id := Parent (N);
6549 Actual : Node_Id;
6550 Call_Nam : Node_Id;
6551
6552 begin
6553 if Nkind_In (Context, N_Indexed_Component, N_Selected_Component)
6554 and then N = Prefix (Context)
6555 then
6556 Find_Actual (Context, Formal, Call);
6557 return;
6558
6559 elsif Nkind (Context) = N_Parameter_Association
6560 and then N = Explicit_Actual_Parameter (Context)
6561 then
6562 Call := Parent (Context);
6563
6564 elsif Nkind_In (Context, N_Entry_Call_Statement,
6565 N_Function_Call,
6566 N_Procedure_Call_Statement)
6567 then
6568 Call := Context;
6569
6570 else
6571 Formal := Empty;
6572 Call := Empty;
6573 return;
6574 end if;
6575
6576 -- If we have a call to a subprogram look for the parameter. Note that
6577 -- we exclude overloaded calls, since we don't know enough to be sure
6578 -- of giving the right answer in this case.
6579
6580 if Nkind_In (Call, N_Entry_Call_Statement,
6581 N_Function_Call,
6582 N_Procedure_Call_Statement)
6583 then
6584 Call_Nam := Name (Call);
6585
6586 -- A call to a protected or task entry appears as a selected
6587 -- component rather than an expanded name.
6588
6589 if Nkind (Call_Nam) = N_Selected_Component then
6590 Call_Nam := Selector_Name (Call_Nam);
6591 end if;
6592
6593 if Is_Entity_Name (Call_Nam)
6594 and then Present (Entity (Call_Nam))
6595 and then Is_Overloadable (Entity (Call_Nam))
6596 and then not Is_Overloaded (Call_Nam)
6597 then
6598 -- If node is name in call it is not an actual
6599
6600 if N = Call_Nam then
6601 Formal := Empty;
6602 Call := Empty;
6603 return;
6604 end if;
6605
6606 -- Fall here if we are definitely a parameter
6607
6608 Actual := First_Actual (Call);
6609 Formal := First_Formal (Entity (Call_Nam));
6610 while Present (Formal) and then Present (Actual) loop
6611 if Actual = N then
6612 return;
6613
6614 -- An actual that is the prefix in a prefixed call may have
6615 -- been rewritten in the call, after the deferred reference
6616 -- was collected. Check if sloc and kinds and names match.
6617
6618 elsif Sloc (Actual) = Sloc (N)
6619 and then Nkind (Actual) = N_Identifier
6620 and then Nkind (Actual) = Nkind (N)
6621 and then Chars (Actual) = Chars (N)
6622 then
6623 return;
6624
6625 else
6626 Actual := Next_Actual (Actual);
6627 Formal := Next_Formal (Formal);
6628 end if;
6629 end loop;
6630 end if;
6631 end if;
6632
6633 -- Fall through here if we did not find matching actual
6634
6635 Formal := Empty;
6636 Call := Empty;
6637 end Find_Actual;
6638
6639 ---------------------------
6640 -- Find_Body_Discriminal --
6641 ---------------------------
6642
6643 function Find_Body_Discriminal
6644 (Spec_Discriminant : Entity_Id) return Entity_Id
6645 is
6646 Tsk : Entity_Id;
6647 Disc : Entity_Id;
6648
6649 begin
6650 -- If expansion is suppressed, then the scope can be the concurrent type
6651 -- itself rather than a corresponding concurrent record type.
6652
6653 if Is_Concurrent_Type (Scope (Spec_Discriminant)) then
6654 Tsk := Scope (Spec_Discriminant);
6655
6656 else
6657 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
6658
6659 Tsk := Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
6660 end if;
6661
6662 -- Find discriminant of original concurrent type, and use its current
6663 -- discriminal, which is the renaming within the task/protected body.
6664
6665 Disc := First_Discriminant (Tsk);
6666 while Present (Disc) loop
6667 if Chars (Disc) = Chars (Spec_Discriminant) then
6668 return Discriminal (Disc);
6669 end if;
6670
6671 Next_Discriminant (Disc);
6672 end loop;
6673
6674 -- That loop should always succeed in finding a matching entry and
6675 -- returning. Fatal error if not.
6676
6677 raise Program_Error;
6678 end Find_Body_Discriminal;
6679
6680 -------------------------------------
6681 -- Find_Corresponding_Discriminant --
6682 -------------------------------------
6683
6684 function Find_Corresponding_Discriminant
6685 (Id : Node_Id;
6686 Typ : Entity_Id) return Entity_Id
6687 is
6688 Par_Disc : Entity_Id;
6689 Old_Disc : Entity_Id;
6690 New_Disc : Entity_Id;
6691
6692 begin
6693 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
6694
6695 -- The original type may currently be private, and the discriminant
6696 -- only appear on its full view.
6697
6698 if Is_Private_Type (Scope (Par_Disc))
6699 and then not Has_Discriminants (Scope (Par_Disc))
6700 and then Present (Full_View (Scope (Par_Disc)))
6701 then
6702 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
6703 else
6704 Old_Disc := First_Discriminant (Scope (Par_Disc));
6705 end if;
6706
6707 if Is_Class_Wide_Type (Typ) then
6708 New_Disc := First_Discriminant (Root_Type (Typ));
6709 else
6710 New_Disc := First_Discriminant (Typ);
6711 end if;
6712
6713 while Present (Old_Disc) and then Present (New_Disc) loop
6714 if Old_Disc = Par_Disc then
6715 return New_Disc;
6716 end if;
6717
6718 Next_Discriminant (Old_Disc);
6719 Next_Discriminant (New_Disc);
6720 end loop;
6721
6722 -- Should always find it
6723
6724 raise Program_Error;
6725 end Find_Corresponding_Discriminant;
6726
6727 ----------------------------------
6728 -- Find_Enclosing_Iterator_Loop --
6729 ----------------------------------
6730
6731 function Find_Enclosing_Iterator_Loop (Id : Entity_Id) return Entity_Id is
6732 Constr : Node_Id;
6733 S : Entity_Id;
6734
6735 begin
6736 -- Traverse the scope chain looking for an iterator loop. Such loops are
6737 -- usually transformed into blocks, hence the use of Original_Node.
6738
6739 S := Id;
6740 while Present (S) and then S /= Standard_Standard loop
6741 if Ekind (S) = E_Loop
6742 and then Nkind (Parent (S)) = N_Implicit_Label_Declaration
6743 then
6744 Constr := Original_Node (Label_Construct (Parent (S)));
6745
6746 if Nkind (Constr) = N_Loop_Statement
6747 and then Present (Iteration_Scheme (Constr))
6748 and then Nkind (Iterator_Specification
6749 (Iteration_Scheme (Constr))) =
6750 N_Iterator_Specification
6751 then
6752 return S;
6753 end if;
6754 end if;
6755
6756 S := Scope (S);
6757 end loop;
6758
6759 return Empty;
6760 end Find_Enclosing_Iterator_Loop;
6761
6762 ------------------------------------
6763 -- Find_Loop_In_Conditional_Block --
6764 ------------------------------------
6765
6766 function Find_Loop_In_Conditional_Block (N : Node_Id) return Node_Id is
6767 Stmt : Node_Id;
6768
6769 begin
6770 Stmt := N;
6771
6772 if Nkind (Stmt) = N_If_Statement then
6773 Stmt := First (Then_Statements (Stmt));
6774 end if;
6775
6776 pragma Assert (Nkind (Stmt) = N_Block_Statement);
6777
6778 -- Inspect the statements of the conditional block. In general the loop
6779 -- should be the first statement in the statement sequence of the block,
6780 -- but the finalization machinery may have introduced extra object
6781 -- declarations.
6782
6783 Stmt := First (Statements (Handled_Statement_Sequence (Stmt)));
6784 while Present (Stmt) loop
6785 if Nkind (Stmt) = N_Loop_Statement then
6786 return Stmt;
6787 end if;
6788
6789 Next (Stmt);
6790 end loop;
6791
6792 -- The expansion of attribute 'Loop_Entry produced a malformed block
6793
6794 raise Program_Error;
6795 end Find_Loop_In_Conditional_Block;
6796
6797 --------------------------
6798 -- Find_Overlaid_Entity --
6799 --------------------------
6800
6801 procedure Find_Overlaid_Entity
6802 (N : Node_Id;
6803 Ent : out Entity_Id;
6804 Off : out Boolean)
6805 is
6806 Expr : Node_Id;
6807
6808 begin
6809 -- We are looking for one of the two following forms:
6810
6811 -- for X'Address use Y'Address
6812
6813 -- or
6814
6815 -- Const : constant Address := expr;
6816 -- ...
6817 -- for X'Address use Const;
6818
6819 -- In the second case, the expr is either Y'Address, or recursively a
6820 -- constant that eventually references Y'Address.
6821
6822 Ent := Empty;
6823 Off := False;
6824
6825 if Nkind (N) = N_Attribute_Definition_Clause
6826 and then Chars (N) = Name_Address
6827 then
6828 Expr := Expression (N);
6829
6830 -- This loop checks the form of the expression for Y'Address,
6831 -- using recursion to deal with intermediate constants.
6832
6833 loop
6834 -- Check for Y'Address
6835
6836 if Nkind (Expr) = N_Attribute_Reference
6837 and then Attribute_Name (Expr) = Name_Address
6838 then
6839 Expr := Prefix (Expr);
6840 exit;
6841
6842 -- Check for Const where Const is a constant entity
6843
6844 elsif Is_Entity_Name (Expr)
6845 and then Ekind (Entity (Expr)) = E_Constant
6846 then
6847 Expr := Constant_Value (Entity (Expr));
6848
6849 -- Anything else does not need checking
6850
6851 else
6852 return;
6853 end if;
6854 end loop;
6855
6856 -- This loop checks the form of the prefix for an entity, using
6857 -- recursion to deal with intermediate components.
6858
6859 loop
6860 -- Check for Y where Y is an entity
6861
6862 if Is_Entity_Name (Expr) then
6863 Ent := Entity (Expr);
6864 return;
6865
6866 -- Check for components
6867
6868 elsif
6869 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component)
6870 then
6871 Expr := Prefix (Expr);
6872 Off := True;
6873
6874 -- Anything else does not need checking
6875
6876 else
6877 return;
6878 end if;
6879 end loop;
6880 end if;
6881 end Find_Overlaid_Entity;
6882
6883 -------------------------
6884 -- Find_Parameter_Type --
6885 -------------------------
6886
6887 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
6888 begin
6889 if Nkind (Param) /= N_Parameter_Specification then
6890 return Empty;
6891
6892 -- For an access parameter, obtain the type from the formal entity
6893 -- itself, because access to subprogram nodes do not carry a type.
6894 -- Shouldn't we always use the formal entity ???
6895
6896 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
6897 return Etype (Defining_Identifier (Param));
6898
6899 else
6900 return Etype (Parameter_Type (Param));
6901 end if;
6902 end Find_Parameter_Type;
6903
6904 -----------------------------------
6905 -- Find_Placement_In_State_Space --
6906 -----------------------------------
6907
6908 procedure Find_Placement_In_State_Space
6909 (Item_Id : Entity_Id;
6910 Placement : out State_Space_Kind;
6911 Pack_Id : out Entity_Id)
6912 is
6913 Context : Entity_Id;
6914
6915 begin
6916 -- Assume that the item does not appear in the state space of a package
6917
6918 Placement := Not_In_Package;
6919 Pack_Id := Empty;
6920
6921 -- Climb the scope stack and examine the enclosing context
6922
6923 Context := Scope (Item_Id);
6924 while Present (Context) and then Context /= Standard_Standard loop
6925 if Ekind (Context) = E_Package then
6926 Pack_Id := Context;
6927
6928 -- A package body is a cut off point for the traversal as the item
6929 -- cannot be visible to the outside from this point on. Note that
6930 -- this test must be done first as a body is also classified as a
6931 -- private part.
6932
6933 if In_Package_Body (Context) then
6934 Placement := Body_State_Space;
6935 return;
6936
6937 -- The private part of a package is a cut off point for the
6938 -- traversal as the item cannot be visible to the outside from
6939 -- this point on.
6940
6941 elsif In_Private_Part (Context) then
6942 Placement := Private_State_Space;
6943 return;
6944
6945 -- When the item appears in the visible state space of a package,
6946 -- continue to climb the scope stack as this may not be the final
6947 -- state space.
6948
6949 else
6950 Placement := Visible_State_Space;
6951
6952 -- The visible state space of a child unit acts as the proper
6953 -- placement of an item.
6954
6955 if Is_Child_Unit (Context) then
6956 return;
6957 end if;
6958 end if;
6959
6960 -- The item or its enclosing package appear in a construct that has
6961 -- no state space.
6962
6963 else
6964 Placement := Not_In_Package;
6965 return;
6966 end if;
6967
6968 Context := Scope (Context);
6969 end loop;
6970 end Find_Placement_In_State_Space;
6971
6972 ------------------------
6973 -- Find_Specific_Type --
6974 ------------------------
6975
6976 function Find_Specific_Type (CW : Entity_Id) return Entity_Id is
6977 Typ : Entity_Id := Root_Type (CW);
6978
6979 begin
6980 if Ekind (Typ) = E_Incomplete_Type then
6981 if From_Limited_With (Typ) then
6982 Typ := Non_Limited_View (Typ);
6983 else
6984 Typ := Full_View (Typ);
6985 end if;
6986 end if;
6987
6988 if Is_Private_Type (Typ)
6989 and then not Is_Tagged_Type (Typ)
6990 and then Present (Full_View (Typ))
6991 then
6992 return Full_View (Typ);
6993 else
6994 return Typ;
6995 end if;
6996 end Find_Specific_Type;
6997
6998 -----------------------------
6999 -- Find_Static_Alternative --
7000 -----------------------------
7001
7002 function Find_Static_Alternative (N : Node_Id) return Node_Id is
7003 Expr : constant Node_Id := Expression (N);
7004 Val : constant Uint := Expr_Value (Expr);
7005 Alt : Node_Id;
7006 Choice : Node_Id;
7007
7008 begin
7009 Alt := First (Alternatives (N));
7010
7011 Search : loop
7012 if Nkind (Alt) /= N_Pragma then
7013 Choice := First (Discrete_Choices (Alt));
7014 while Present (Choice) loop
7015
7016 -- Others choice, always matches
7017
7018 if Nkind (Choice) = N_Others_Choice then
7019 exit Search;
7020
7021 -- Range, check if value is in the range
7022
7023 elsif Nkind (Choice) = N_Range then
7024 exit Search when
7025 Val >= Expr_Value (Low_Bound (Choice))
7026 and then
7027 Val <= Expr_Value (High_Bound (Choice));
7028
7029 -- Choice is a subtype name. Note that we know it must
7030 -- be a static subtype, since otherwise it would have
7031 -- been diagnosed as illegal.
7032
7033 elsif Is_Entity_Name (Choice)
7034 and then Is_Type (Entity (Choice))
7035 then
7036 exit Search when Is_In_Range (Expr, Etype (Choice),
7037 Assume_Valid => False);
7038
7039 -- Choice is a subtype indication
7040
7041 elsif Nkind (Choice) = N_Subtype_Indication then
7042 declare
7043 C : constant Node_Id := Constraint (Choice);
7044 R : constant Node_Id := Range_Expression (C);
7045
7046 begin
7047 exit Search when
7048 Val >= Expr_Value (Low_Bound (R))
7049 and then
7050 Val <= Expr_Value (High_Bound (R));
7051 end;
7052
7053 -- Choice is a simple expression
7054
7055 else
7056 exit Search when Val = Expr_Value (Choice);
7057 end if;
7058
7059 Next (Choice);
7060 end loop;
7061 end if;
7062
7063 Next (Alt);
7064 pragma Assert (Present (Alt));
7065 end loop Search;
7066
7067 -- The above loop *must* terminate by finding a match, since
7068 -- we know the case statement is valid, and the value of the
7069 -- expression is known at compile time. When we fall out of
7070 -- the loop, Alt points to the alternative that we know will
7071 -- be selected at run time.
7072
7073 return Alt;
7074 end Find_Static_Alternative;
7075
7076 ------------------
7077 -- First_Actual --
7078 ------------------
7079
7080 function First_Actual (Node : Node_Id) return Node_Id is
7081 N : Node_Id;
7082
7083 begin
7084 if No (Parameter_Associations (Node)) then
7085 return Empty;
7086 end if;
7087
7088 N := First (Parameter_Associations (Node));
7089
7090 if Nkind (N) = N_Parameter_Association then
7091 return First_Named_Actual (Node);
7092 else
7093 return N;
7094 end if;
7095 end First_Actual;
7096
7097 -------------
7098 -- Fix_Msg --
7099 -------------
7100
7101 function Fix_Msg (Id : Entity_Id; Msg : String) return String is
7102 Is_Task : constant Boolean :=
7103 Ekind_In (Id, E_Task_Body, E_Task_Type)
7104 or else (Is_Single_Concurrent_Object (Id)
7105 and then Ekind (Etype (Id)) = E_Task_Type);
7106 Msg_Last : constant Natural := Msg'Last;
7107 Msg_Index : Natural;
7108 Res : String (Msg'Range) := (others => ' ');
7109 Res_Index : Natural;
7110
7111 begin
7112 -- Copy all characters from the input message Msg to result Res with
7113 -- suitable replacements.
7114
7115 Msg_Index := Msg'First;
7116 Res_Index := Res'First;
7117 while Msg_Index <= Msg_Last loop
7118
7119 -- Replace "subprogram" with a different word
7120
7121 if Msg_Index <= Msg_Last - 10
7122 and then Msg (Msg_Index .. Msg_Index + 9) = "subprogram"
7123 then
7124 if Ekind_In (Id, E_Entry, E_Entry_Family) then
7125 Res (Res_Index .. Res_Index + 4) := "entry";
7126 Res_Index := Res_Index + 5;
7127
7128 elsif Is_Task then
7129 Res (Res_Index .. Res_Index + 8) := "task type";
7130 Res_Index := Res_Index + 9;
7131
7132 else
7133 Res (Res_Index .. Res_Index + 9) := "subprogram";
7134 Res_Index := Res_Index + 10;
7135 end if;
7136
7137 Msg_Index := Msg_Index + 10;
7138
7139 -- Replace "protected" with a different word
7140
7141 elsif Msg_Index <= Msg_Last - 9
7142 and then Msg (Msg_Index .. Msg_Index + 8) = "protected"
7143 and then Is_Task
7144 then
7145 Res (Res_Index .. Res_Index + 3) := "task";
7146 Res_Index := Res_Index + 4;
7147 Msg_Index := Msg_Index + 9;
7148
7149 -- Otherwise copy the character
7150
7151 else
7152 Res (Res_Index) := Msg (Msg_Index);
7153 Msg_Index := Msg_Index + 1;
7154 Res_Index := Res_Index + 1;
7155 end if;
7156 end loop;
7157
7158 return Res (Res'First .. Res_Index - 1);
7159 end Fix_Msg;
7160
7161 -----------------------
7162 -- Gather_Components --
7163 -----------------------
7164
7165 procedure Gather_Components
7166 (Typ : Entity_Id;
7167 Comp_List : Node_Id;
7168 Governed_By : List_Id;
7169 Into : Elist_Id;
7170 Report_Errors : out Boolean)
7171 is
7172 Assoc : Node_Id;
7173 Variant : Node_Id;
7174 Discrete_Choice : Node_Id;
7175 Comp_Item : Node_Id;
7176
7177 Discrim : Entity_Id;
7178 Discrim_Name : Node_Id;
7179 Discrim_Value : Node_Id;
7180
7181 begin
7182 Report_Errors := False;
7183
7184 if No (Comp_List) or else Null_Present (Comp_List) then
7185 return;
7186
7187 elsif Present (Component_Items (Comp_List)) then
7188 Comp_Item := First (Component_Items (Comp_List));
7189
7190 else
7191 Comp_Item := Empty;
7192 end if;
7193
7194 while Present (Comp_Item) loop
7195
7196 -- Skip the tag of a tagged record, the interface tags, as well
7197 -- as all items that are not user components (anonymous types,
7198 -- rep clauses, Parent field, controller field).
7199
7200 if Nkind (Comp_Item) = N_Component_Declaration then
7201 declare
7202 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
7203 begin
7204 if not Is_Tag (Comp) and then Chars (Comp) /= Name_uParent then
7205 Append_Elmt (Comp, Into);
7206 end if;
7207 end;
7208 end if;
7209
7210 Next (Comp_Item);
7211 end loop;
7212
7213 if No (Variant_Part (Comp_List)) then
7214 return;
7215 else
7216 Discrim_Name := Name (Variant_Part (Comp_List));
7217 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
7218 end if;
7219
7220 -- Look for the discriminant that governs this variant part.
7221 -- The discriminant *must* be in the Governed_By List
7222
7223 Assoc := First (Governed_By);
7224 Find_Constraint : loop
7225 Discrim := First (Choices (Assoc));
7226 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
7227 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
7228 and then
7229 Chars (Corresponding_Discriminant (Entity (Discrim))) =
7230 Chars (Discrim_Name))
7231 or else Chars (Original_Record_Component (Entity (Discrim)))
7232 = Chars (Discrim_Name);
7233
7234 if No (Next (Assoc)) then
7235 if not Is_Constrained (Typ)
7236 and then Is_Derived_Type (Typ)
7237 and then Present (Stored_Constraint (Typ))
7238 then
7239 -- If the type is a tagged type with inherited discriminants,
7240 -- use the stored constraint on the parent in order to find
7241 -- the values of discriminants that are otherwise hidden by an
7242 -- explicit constraint. Renamed discriminants are handled in
7243 -- the code above.
7244
7245 -- If several parent discriminants are renamed by a single
7246 -- discriminant of the derived type, the call to obtain the
7247 -- Corresponding_Discriminant field only retrieves the last
7248 -- of them. We recover the constraint on the others from the
7249 -- Stored_Constraint as well.
7250
7251 declare
7252 D : Entity_Id;
7253 C : Elmt_Id;
7254
7255 begin
7256 D := First_Discriminant (Etype (Typ));
7257 C := First_Elmt (Stored_Constraint (Typ));
7258 while Present (D) and then Present (C) loop
7259 if Chars (Discrim_Name) = Chars (D) then
7260 if Is_Entity_Name (Node (C))
7261 and then Entity (Node (C)) = Entity (Discrim)
7262 then
7263 -- D is renamed by Discrim, whose value is given in
7264 -- Assoc.
7265
7266 null;
7267
7268 else
7269 Assoc :=
7270 Make_Component_Association (Sloc (Typ),
7271 New_List
7272 (New_Occurrence_Of (D, Sloc (Typ))),
7273 Duplicate_Subexpr_No_Checks (Node (C)));
7274 end if;
7275 exit Find_Constraint;
7276 end if;
7277
7278 Next_Discriminant (D);
7279 Next_Elmt (C);
7280 end loop;
7281 end;
7282 end if;
7283 end if;
7284
7285 if No (Next (Assoc)) then
7286 Error_Msg_NE (" missing value for discriminant&",
7287 First (Governed_By), Discrim_Name);
7288 Report_Errors := True;
7289 return;
7290 end if;
7291
7292 Next (Assoc);
7293 end loop Find_Constraint;
7294
7295 Discrim_Value := Expression (Assoc);
7296
7297 if not Is_OK_Static_Expression (Discrim_Value) then
7298
7299 -- If the variant part is governed by a discriminant of the type
7300 -- this is an error. If the variant part and the discriminant are
7301 -- inherited from an ancestor this is legal (AI05-120) unless the
7302 -- components are being gathered for an aggregate, in which case
7303 -- the caller must check Report_Errors.
7304
7305 if Scope (Original_Record_Component
7306 ((Entity (First (Choices (Assoc)))))) = Typ
7307 then
7308 Error_Msg_FE
7309 ("value for discriminant & must be static!",
7310 Discrim_Value, Discrim);
7311 Why_Not_Static (Discrim_Value);
7312 end if;
7313
7314 Report_Errors := True;
7315 return;
7316 end if;
7317
7318 Search_For_Discriminant_Value : declare
7319 Low : Node_Id;
7320 High : Node_Id;
7321
7322 UI_High : Uint;
7323 UI_Low : Uint;
7324 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
7325
7326 begin
7327 Find_Discrete_Value : while Present (Variant) loop
7328 Discrete_Choice := First (Discrete_Choices (Variant));
7329 while Present (Discrete_Choice) loop
7330 exit Find_Discrete_Value when
7331 Nkind (Discrete_Choice) = N_Others_Choice;
7332
7333 Get_Index_Bounds (Discrete_Choice, Low, High);
7334
7335 UI_Low := Expr_Value (Low);
7336 UI_High := Expr_Value (High);
7337
7338 exit Find_Discrete_Value when
7339 UI_Low <= UI_Discrim_Value
7340 and then
7341 UI_High >= UI_Discrim_Value;
7342
7343 Next (Discrete_Choice);
7344 end loop;
7345
7346 Next_Non_Pragma (Variant);
7347 end loop Find_Discrete_Value;
7348 end Search_For_Discriminant_Value;
7349
7350 if No (Variant) then
7351 Error_Msg_NE
7352 ("value of discriminant & is out of range", Discrim_Value, Discrim);
7353 Report_Errors := True;
7354 return;
7355 end if;
7356
7357 -- If we have found the corresponding choice, recursively add its
7358 -- components to the Into list. The nested components are part of
7359 -- the same record type.
7360
7361 Gather_Components
7362 (Typ, Component_List (Variant), Governed_By, Into, Report_Errors);
7363 end Gather_Components;
7364
7365 ------------------------
7366 -- Get_Actual_Subtype --
7367 ------------------------
7368
7369 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
7370 Typ : constant Entity_Id := Etype (N);
7371 Utyp : Entity_Id := Underlying_Type (Typ);
7372 Decl : Node_Id;
7373 Atyp : Entity_Id;
7374
7375 begin
7376 if No (Utyp) then
7377 Utyp := Typ;
7378 end if;
7379
7380 -- If what we have is an identifier that references a subprogram
7381 -- formal, or a variable or constant object, then we get the actual
7382 -- subtype from the referenced entity if one has been built.
7383
7384 if Nkind (N) = N_Identifier
7385 and then
7386 (Is_Formal (Entity (N))
7387 or else Ekind (Entity (N)) = E_Constant
7388 or else Ekind (Entity (N)) = E_Variable)
7389 and then Present (Actual_Subtype (Entity (N)))
7390 then
7391 return Actual_Subtype (Entity (N));
7392
7393 -- Actual subtype of unchecked union is always itself. We never need
7394 -- the "real" actual subtype. If we did, we couldn't get it anyway
7395 -- because the discriminant is not available. The restrictions on
7396 -- Unchecked_Union are designed to make sure that this is OK.
7397
7398 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
7399 return Typ;
7400
7401 -- Here for the unconstrained case, we must find actual subtype
7402 -- No actual subtype is available, so we must build it on the fly.
7403
7404 -- Checking the type, not the underlying type, for constrainedness
7405 -- seems to be necessary. Maybe all the tests should be on the type???
7406
7407 elsif (not Is_Constrained (Typ))
7408 and then (Is_Array_Type (Utyp)
7409 or else (Is_Record_Type (Utyp)
7410 and then Has_Discriminants (Utyp)))
7411 and then not Has_Unknown_Discriminants (Utyp)
7412 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
7413 then
7414 -- Nothing to do if in spec expression (why not???)
7415
7416 if In_Spec_Expression then
7417 return Typ;
7418
7419 elsif Is_Private_Type (Typ) and then not Has_Discriminants (Typ) then
7420
7421 -- If the type has no discriminants, there is no subtype to
7422 -- build, even if the underlying type is discriminated.
7423
7424 return Typ;
7425
7426 -- Else build the actual subtype
7427
7428 else
7429 Decl := Build_Actual_Subtype (Typ, N);
7430 Atyp := Defining_Identifier (Decl);
7431
7432 -- If Build_Actual_Subtype generated a new declaration then use it
7433
7434 if Atyp /= Typ then
7435
7436 -- The actual subtype is an Itype, so analyze the declaration,
7437 -- but do not attach it to the tree, to get the type defined.
7438
7439 Set_Parent (Decl, N);
7440 Set_Is_Itype (Atyp);
7441 Analyze (Decl, Suppress => All_Checks);
7442 Set_Associated_Node_For_Itype (Atyp, N);
7443 Set_Has_Delayed_Freeze (Atyp, False);
7444
7445 -- We need to freeze the actual subtype immediately. This is
7446 -- needed, because otherwise this Itype will not get frozen
7447 -- at all, and it is always safe to freeze on creation because
7448 -- any associated types must be frozen at this point.
7449
7450 Freeze_Itype (Atyp, N);
7451 return Atyp;
7452
7453 -- Otherwise we did not build a declaration, so return original
7454
7455 else
7456 return Typ;
7457 end if;
7458 end if;
7459
7460 -- For all remaining cases, the actual subtype is the same as
7461 -- the nominal type.
7462
7463 else
7464 return Typ;
7465 end if;
7466 end Get_Actual_Subtype;
7467
7468 -------------------------------------
7469 -- Get_Actual_Subtype_If_Available --
7470 -------------------------------------
7471
7472 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
7473 Typ : constant Entity_Id := Etype (N);
7474
7475 begin
7476 -- If what we have is an identifier that references a subprogram
7477 -- formal, or a variable or constant object, then we get the actual
7478 -- subtype from the referenced entity if one has been built.
7479
7480 if Nkind (N) = N_Identifier
7481 and then
7482 (Is_Formal (Entity (N))
7483 or else Ekind (Entity (N)) = E_Constant
7484 or else Ekind (Entity (N)) = E_Variable)
7485 and then Present (Actual_Subtype (Entity (N)))
7486 then
7487 return Actual_Subtype (Entity (N));
7488
7489 -- Otherwise the Etype of N is returned unchanged
7490
7491 else
7492 return Typ;
7493 end if;
7494 end Get_Actual_Subtype_If_Available;
7495
7496 ------------------------
7497 -- Get_Body_From_Stub --
7498 ------------------------
7499
7500 function Get_Body_From_Stub (N : Node_Id) return Node_Id is
7501 begin
7502 return Proper_Body (Unit (Library_Unit (N)));
7503 end Get_Body_From_Stub;
7504
7505 ---------------------
7506 -- Get_Cursor_Type --
7507 ---------------------
7508
7509 function Get_Cursor_Type
7510 (Aspect : Node_Id;
7511 Typ : Entity_Id) return Entity_Id
7512 is
7513 Assoc : Node_Id;
7514 Func : Entity_Id;
7515 First_Op : Entity_Id;
7516 Cursor : Entity_Id;
7517
7518 begin
7519 -- If error already detected, return
7520
7521 if Error_Posted (Aspect) then
7522 return Any_Type;
7523 end if;
7524
7525 -- The cursor type for an Iterable aspect is the return type of a
7526 -- non-overloaded First primitive operation. Locate association for
7527 -- First.
7528
7529 Assoc := First (Component_Associations (Expression (Aspect)));
7530 First_Op := Any_Id;
7531 while Present (Assoc) loop
7532 if Chars (First (Choices (Assoc))) = Name_First then
7533 First_Op := Expression (Assoc);
7534 exit;
7535 end if;
7536
7537 Next (Assoc);
7538 end loop;
7539
7540 if First_Op = Any_Id then
7541 Error_Msg_N ("aspect Iterable must specify First operation", Aspect);
7542 return Any_Type;
7543 end if;
7544
7545 Cursor := Any_Type;
7546
7547 -- Locate function with desired name and profile in scope of type
7548
7549 Func := First_Entity (Scope (Typ));
7550 while Present (Func) loop
7551 if Chars (Func) = Chars (First_Op)
7552 and then Ekind (Func) = E_Function
7553 and then Present (First_Formal (Func))
7554 and then Etype (First_Formal (Func)) = Typ
7555 and then No (Next_Formal (First_Formal (Func)))
7556 then
7557 if Cursor /= Any_Type then
7558 Error_Msg_N
7559 ("Operation First for iterable type must be unique", Aspect);
7560 return Any_Type;
7561 else
7562 Cursor := Etype (Func);
7563 end if;
7564 end if;
7565
7566 Next_Entity (Func);
7567 end loop;
7568
7569 -- If not found, no way to resolve remaining primitives.
7570
7571 if Cursor = Any_Type then
7572 Error_Msg_N
7573 ("No legal primitive operation First for Iterable type", Aspect);
7574 end if;
7575
7576 return Cursor;
7577 end Get_Cursor_Type;
7578
7579 function Get_Cursor_Type (Typ : Entity_Id) return Entity_Id is
7580 begin
7581 return Etype (Get_Iterable_Type_Primitive (Typ, Name_First));
7582 end Get_Cursor_Type;
7583
7584 -------------------------------
7585 -- Get_Default_External_Name --
7586 -------------------------------
7587
7588 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
7589 begin
7590 Get_Decoded_Name_String (Chars (E));
7591
7592 if Opt.External_Name_Imp_Casing = Uppercase then
7593 Set_Casing (All_Upper_Case);
7594 else
7595 Set_Casing (All_Lower_Case);
7596 end if;
7597
7598 return
7599 Make_String_Literal (Sloc (E),
7600 Strval => String_From_Name_Buffer);
7601 end Get_Default_External_Name;
7602
7603 --------------------------
7604 -- Get_Enclosing_Object --
7605 --------------------------
7606
7607 function Get_Enclosing_Object (N : Node_Id) return Entity_Id is
7608 begin
7609 if Is_Entity_Name (N) then
7610 return Entity (N);
7611 else
7612 case Nkind (N) is
7613 when N_Indexed_Component |
7614 N_Slice |
7615 N_Selected_Component =>
7616
7617 -- If not generating code, a dereference may be left implicit.
7618 -- In thoses cases, return Empty.
7619
7620 if Is_Access_Type (Etype (Prefix (N))) then
7621 return Empty;
7622 else
7623 return Get_Enclosing_Object (Prefix (N));
7624 end if;
7625
7626 when N_Type_Conversion =>
7627 return Get_Enclosing_Object (Expression (N));
7628
7629 when others =>
7630 return Empty;
7631 end case;
7632 end if;
7633 end Get_Enclosing_Object;
7634
7635 ---------------------------
7636 -- Get_Enum_Lit_From_Pos --
7637 ---------------------------
7638
7639 function Get_Enum_Lit_From_Pos
7640 (T : Entity_Id;
7641 Pos : Uint;
7642 Loc : Source_Ptr) return Node_Id
7643 is
7644 Btyp : Entity_Id := Base_Type (T);
7645 Lit : Node_Id;
7646
7647 begin
7648 -- In the case where the literal is of type Character, Wide_Character
7649 -- or Wide_Wide_Character or of a type derived from them, there needs
7650 -- to be some special handling since there is no explicit chain of
7651 -- literals to search. Instead, an N_Character_Literal node is created
7652 -- with the appropriate Char_Code and Chars fields.
7653
7654 if Is_Standard_Character_Type (T) then
7655 Set_Character_Literal_Name (UI_To_CC (Pos));
7656 return
7657 Make_Character_Literal (Loc,
7658 Chars => Name_Find,
7659 Char_Literal_Value => Pos);
7660
7661 -- For all other cases, we have a complete table of literals, and
7662 -- we simply iterate through the chain of literal until the one
7663 -- with the desired position value is found.
7664
7665 else
7666 if Is_Private_Type (Btyp) and then Present (Full_View (Btyp)) then
7667 Btyp := Full_View (Btyp);
7668 end if;
7669
7670 Lit := First_Literal (Btyp);
7671 for J in 1 .. UI_To_Int (Pos) loop
7672 Next_Literal (Lit);
7673 end loop;
7674
7675 return New_Occurrence_Of (Lit, Loc);
7676 end if;
7677 end Get_Enum_Lit_From_Pos;
7678
7679 ------------------------
7680 -- Get_Generic_Entity --
7681 ------------------------
7682
7683 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
7684 Ent : constant Entity_Id := Entity (Name (N));
7685 begin
7686 if Present (Renamed_Object (Ent)) then
7687 return Renamed_Object (Ent);
7688 else
7689 return Ent;
7690 end if;
7691 end Get_Generic_Entity;
7692
7693 -------------------------------------
7694 -- Get_Incomplete_View_Of_Ancestor --
7695 -------------------------------------
7696
7697 function Get_Incomplete_View_Of_Ancestor (E : Entity_Id) return Entity_Id is
7698 Cur_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
7699 Par_Scope : Entity_Id;
7700 Par_Type : Entity_Id;
7701
7702 begin
7703 -- The incomplete view of an ancestor is only relevant for private
7704 -- derived types in child units.
7705
7706 if not Is_Derived_Type (E)
7707 or else not Is_Child_Unit (Cur_Unit)
7708 then
7709 return Empty;
7710
7711 else
7712 Par_Scope := Scope (Cur_Unit);
7713 if No (Par_Scope) then
7714 return Empty;
7715 end if;
7716
7717 Par_Type := Etype (Base_Type (E));
7718
7719 -- Traverse list of ancestor types until we find one declared in
7720 -- a parent or grandparent unit (two levels seem sufficient).
7721
7722 while Present (Par_Type) loop
7723 if Scope (Par_Type) = Par_Scope
7724 or else Scope (Par_Type) = Scope (Par_Scope)
7725 then
7726 return Par_Type;
7727
7728 elsif not Is_Derived_Type (Par_Type) then
7729 return Empty;
7730
7731 else
7732 Par_Type := Etype (Base_Type (Par_Type));
7733 end if;
7734 end loop;
7735
7736 -- If none found, there is no relevant ancestor type.
7737
7738 return Empty;
7739 end if;
7740 end Get_Incomplete_View_Of_Ancestor;
7741
7742 ----------------------
7743 -- Get_Index_Bounds --
7744 ----------------------
7745
7746 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
7747 Kind : constant Node_Kind := Nkind (N);
7748 R : Node_Id;
7749
7750 begin
7751 if Kind = N_Range then
7752 L := Low_Bound (N);
7753 H := High_Bound (N);
7754
7755 elsif Kind = N_Subtype_Indication then
7756 R := Range_Expression (Constraint (N));
7757
7758 if R = Error then
7759 L := Error;
7760 H := Error;
7761 return;
7762
7763 else
7764 L := Low_Bound (Range_Expression (Constraint (N)));
7765 H := High_Bound (Range_Expression (Constraint (N)));
7766 end if;
7767
7768 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
7769 if Error_Posted (Scalar_Range (Entity (N))) then
7770 L := Error;
7771 H := Error;
7772
7773 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
7774 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
7775
7776 else
7777 L := Low_Bound (Scalar_Range (Entity (N)));
7778 H := High_Bound (Scalar_Range (Entity (N)));
7779 end if;
7780
7781 else
7782 -- N is an expression, indicating a range with one value
7783
7784 L := N;
7785 H := N;
7786 end if;
7787 end Get_Index_Bounds;
7788
7789 ---------------------------------
7790 -- Get_Iterable_Type_Primitive --
7791 ---------------------------------
7792
7793 function Get_Iterable_Type_Primitive
7794 (Typ : Entity_Id;
7795 Nam : Name_Id) return Entity_Id
7796 is
7797 Funcs : constant Node_Id := Find_Value_Of_Aspect (Typ, Aspect_Iterable);
7798 Assoc : Node_Id;
7799
7800 begin
7801 if No (Funcs) then
7802 return Empty;
7803
7804 else
7805 Assoc := First (Component_Associations (Funcs));
7806 while Present (Assoc) loop
7807 if Chars (First (Choices (Assoc))) = Nam then
7808 return Entity (Expression (Assoc));
7809 end if;
7810
7811 Assoc := Next (Assoc);
7812 end loop;
7813
7814 return Empty;
7815 end if;
7816 end Get_Iterable_Type_Primitive;
7817
7818 ----------------------------------
7819 -- Get_Library_Unit_Name_string --
7820 ----------------------------------
7821
7822 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
7823 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
7824
7825 begin
7826 Get_Unit_Name_String (Unit_Name_Id);
7827
7828 -- Remove seven last character (" (spec)" or " (body)")
7829
7830 Name_Len := Name_Len - 7;
7831 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
7832 end Get_Library_Unit_Name_String;
7833
7834 ------------------------
7835 -- Get_Name_Entity_Id --
7836 ------------------------
7837
7838 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
7839 begin
7840 return Entity_Id (Get_Name_Table_Int (Id));
7841 end Get_Name_Entity_Id;
7842
7843 ------------------------------
7844 -- Get_Name_From_CTC_Pragma --
7845 ------------------------------
7846
7847 function Get_Name_From_CTC_Pragma (N : Node_Id) return String_Id is
7848 Arg : constant Node_Id :=
7849 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
7850 begin
7851 return Strval (Expr_Value_S (Arg));
7852 end Get_Name_From_CTC_Pragma;
7853
7854 -----------------------
7855 -- Get_Parent_Entity --
7856 -----------------------
7857
7858 function Get_Parent_Entity (Unit : Node_Id) return Entity_Id is
7859 begin
7860 if Nkind (Unit) = N_Package_Body
7861 and then Nkind (Original_Node (Unit)) = N_Package_Instantiation
7862 then
7863 return Defining_Entity
7864 (Specification (Instance_Spec (Original_Node (Unit))));
7865 elsif Nkind (Unit) = N_Package_Instantiation then
7866 return Defining_Entity (Specification (Instance_Spec (Unit)));
7867 else
7868 return Defining_Entity (Unit);
7869 end if;
7870 end Get_Parent_Entity;
7871
7872 -------------------
7873 -- Get_Pragma_Id --
7874 -------------------
7875
7876 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
7877 begin
7878 return Get_Pragma_Id (Pragma_Name (N));
7879 end Get_Pragma_Id;
7880
7881 -----------------------
7882 -- Get_Reason_String --
7883 -----------------------
7884
7885 procedure Get_Reason_String (N : Node_Id) is
7886 begin
7887 if Nkind (N) = N_String_Literal then
7888 Store_String_Chars (Strval (N));
7889
7890 elsif Nkind (N) = N_Op_Concat then
7891 Get_Reason_String (Left_Opnd (N));
7892 Get_Reason_String (Right_Opnd (N));
7893
7894 -- If not of required form, error
7895
7896 else
7897 Error_Msg_N
7898 ("Reason for pragma Warnings has wrong form", N);
7899 Error_Msg_N
7900 ("\must be string literal or concatenation of string literals", N);
7901 return;
7902 end if;
7903 end Get_Reason_String;
7904
7905 --------------------------------
7906 -- Get_Reference_Discriminant --
7907 --------------------------------
7908
7909 function Get_Reference_Discriminant (Typ : Entity_Id) return Entity_Id is
7910 D : Entity_Id;
7911
7912 begin
7913 D := First_Discriminant (Typ);
7914 while Present (D) loop
7915 if Has_Implicit_Dereference (D) then
7916 return D;
7917 end if;
7918 Next_Discriminant (D);
7919 end loop;
7920
7921 return Empty;
7922 end Get_Reference_Discriminant;
7923
7924 ---------------------------
7925 -- Get_Referenced_Object --
7926 ---------------------------
7927
7928 function Get_Referenced_Object (N : Node_Id) return Node_Id is
7929 R : Node_Id;
7930
7931 begin
7932 R := N;
7933 while Is_Entity_Name (R)
7934 and then Present (Renamed_Object (Entity (R)))
7935 loop
7936 R := Renamed_Object (Entity (R));
7937 end loop;
7938
7939 return R;
7940 end Get_Referenced_Object;
7941
7942 ------------------------
7943 -- Get_Renamed_Entity --
7944 ------------------------
7945
7946 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
7947 R : Entity_Id;
7948
7949 begin
7950 R := E;
7951 while Present (Renamed_Entity (R)) loop
7952 R := Renamed_Entity (R);
7953 end loop;
7954
7955 return R;
7956 end Get_Renamed_Entity;
7957
7958 -----------------------
7959 -- Get_Return_Object --
7960 -----------------------
7961
7962 function Get_Return_Object (N : Node_Id) return Entity_Id is
7963 Decl : Node_Id;
7964
7965 begin
7966 Decl := First (Return_Object_Declarations (N));
7967 while Present (Decl) loop
7968 exit when Nkind (Decl) = N_Object_Declaration
7969 and then Is_Return_Object (Defining_Identifier (Decl));
7970 Next (Decl);
7971 end loop;
7972
7973 pragma Assert (Present (Decl));
7974 return Defining_Identifier (Decl);
7975 end Get_Return_Object;
7976
7977 ---------------------------
7978 -- Get_Subprogram_Entity --
7979 ---------------------------
7980
7981 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
7982 Subp : Node_Id;
7983 Subp_Id : Entity_Id;
7984
7985 begin
7986 if Nkind (Nod) = N_Accept_Statement then
7987 Subp := Entry_Direct_Name (Nod);
7988
7989 elsif Nkind (Nod) = N_Slice then
7990 Subp := Prefix (Nod);
7991
7992 else
7993 Subp := Name (Nod);
7994 end if;
7995
7996 -- Strip the subprogram call
7997
7998 loop
7999 if Nkind_In (Subp, N_Explicit_Dereference,
8000 N_Indexed_Component,
8001 N_Selected_Component)
8002 then
8003 Subp := Prefix (Subp);
8004
8005 elsif Nkind_In (Subp, N_Type_Conversion,
8006 N_Unchecked_Type_Conversion)
8007 then
8008 Subp := Expression (Subp);
8009
8010 else
8011 exit;
8012 end if;
8013 end loop;
8014
8015 -- Extract the entity of the subprogram call
8016
8017 if Is_Entity_Name (Subp) then
8018 Subp_Id := Entity (Subp);
8019
8020 if Ekind (Subp_Id) = E_Access_Subprogram_Type then
8021 Subp_Id := Directly_Designated_Type (Subp_Id);
8022 end if;
8023
8024 if Is_Subprogram (Subp_Id) then
8025 return Subp_Id;
8026 else
8027 return Empty;
8028 end if;
8029
8030 -- The search did not find a construct that denotes a subprogram
8031
8032 else
8033 return Empty;
8034 end if;
8035 end Get_Subprogram_Entity;
8036
8037 -----------------------------
8038 -- Get_Task_Body_Procedure --
8039 -----------------------------
8040
8041 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
8042 begin
8043 -- Note: A task type may be the completion of a private type with
8044 -- discriminants. When performing elaboration checks on a task
8045 -- declaration, the current view of the type may be the private one,
8046 -- and the procedure that holds the body of the task is held in its
8047 -- underlying type.
8048
8049 -- This is an odd function, why not have Task_Body_Procedure do
8050 -- the following digging???
8051
8052 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
8053 end Get_Task_Body_Procedure;
8054
8055 -------------------------
8056 -- Get_User_Defined_Eq --
8057 -------------------------
8058
8059 function Get_User_Defined_Eq (E : Entity_Id) return Entity_Id is
8060 Prim : Elmt_Id;
8061 Op : Entity_Id;
8062
8063 begin
8064 Prim := First_Elmt (Collect_Primitive_Operations (E));
8065 while Present (Prim) loop
8066 Op := Node (Prim);
8067
8068 if Chars (Op) = Name_Op_Eq
8069 and then Etype (Op) = Standard_Boolean
8070 and then Etype (First_Formal (Op)) = E
8071 and then Etype (Next_Formal (First_Formal (Op))) = E
8072 then
8073 return Op;
8074 end if;
8075
8076 Next_Elmt (Prim);
8077 end loop;
8078
8079 return Empty;
8080 end Get_User_Defined_Eq;
8081
8082 -----------------------
8083 -- Has_Access_Values --
8084 -----------------------
8085
8086 function Has_Access_Values (T : Entity_Id) return Boolean is
8087 Typ : constant Entity_Id := Underlying_Type (T);
8088
8089 begin
8090 -- Case of a private type which is not completed yet. This can only
8091 -- happen in the case of a generic format type appearing directly, or
8092 -- as a component of the type to which this function is being applied
8093 -- at the top level. Return False in this case, since we certainly do
8094 -- not know that the type contains access types.
8095
8096 if No (Typ) then
8097 return False;
8098
8099 elsif Is_Access_Type (Typ) then
8100 return True;
8101
8102 elsif Is_Array_Type (Typ) then
8103 return Has_Access_Values (Component_Type (Typ));
8104
8105 elsif Is_Record_Type (Typ) then
8106 declare
8107 Comp : Entity_Id;
8108
8109 begin
8110 -- Loop to Check components
8111
8112 Comp := First_Component_Or_Discriminant (Typ);
8113 while Present (Comp) loop
8114
8115 -- Check for access component, tag field does not count, even
8116 -- though it is implemented internally using an access type.
8117
8118 if Has_Access_Values (Etype (Comp))
8119 and then Chars (Comp) /= Name_uTag
8120 then
8121 return True;
8122 end if;
8123
8124 Next_Component_Or_Discriminant (Comp);
8125 end loop;
8126 end;
8127
8128 return False;
8129
8130 else
8131 return False;
8132 end if;
8133 end Has_Access_Values;
8134
8135 ------------------------------
8136 -- Has_Compatible_Alignment --
8137 ------------------------------
8138
8139 function Has_Compatible_Alignment
8140 (Obj : Entity_Id;
8141 Expr : Node_Id) return Alignment_Result
8142 is
8143 function Has_Compatible_Alignment_Internal
8144 (Obj : Entity_Id;
8145 Expr : Node_Id;
8146 Default : Alignment_Result) return Alignment_Result;
8147 -- This is the internal recursive function that actually does the work.
8148 -- There is one additional parameter, which says what the result should
8149 -- be if no alignment information is found, and there is no definite
8150 -- indication of compatible alignments. At the outer level, this is set
8151 -- to Unknown, but for internal recursive calls in the case where types
8152 -- are known to be correct, it is set to Known_Compatible.
8153
8154 ---------------------------------------
8155 -- Has_Compatible_Alignment_Internal --
8156 ---------------------------------------
8157
8158 function Has_Compatible_Alignment_Internal
8159 (Obj : Entity_Id;
8160 Expr : Node_Id;
8161 Default : Alignment_Result) return Alignment_Result
8162 is
8163 Result : Alignment_Result := Known_Compatible;
8164 -- Holds the current status of the result. Note that once a value of
8165 -- Known_Incompatible is set, it is sticky and does not get changed
8166 -- to Unknown (the value in Result only gets worse as we go along,
8167 -- never better).
8168
8169 Offs : Uint := No_Uint;
8170 -- Set to a factor of the offset from the base object when Expr is a
8171 -- selected or indexed component, based on Component_Bit_Offset and
8172 -- Component_Size respectively. A negative value is used to represent
8173 -- a value which is not known at compile time.
8174
8175 procedure Check_Prefix;
8176 -- Checks the prefix recursively in the case where the expression
8177 -- is an indexed or selected component.
8178
8179 procedure Set_Result (R : Alignment_Result);
8180 -- If R represents a worse outcome (unknown instead of known
8181 -- compatible, or known incompatible), then set Result to R.
8182
8183 ------------------
8184 -- Check_Prefix --
8185 ------------------
8186
8187 procedure Check_Prefix is
8188 begin
8189 -- The subtlety here is that in doing a recursive call to check
8190 -- the prefix, we have to decide what to do in the case where we
8191 -- don't find any specific indication of an alignment problem.
8192
8193 -- At the outer level, we normally set Unknown as the result in
8194 -- this case, since we can only set Known_Compatible if we really
8195 -- know that the alignment value is OK, but for the recursive
8196 -- call, in the case where the types match, and we have not
8197 -- specified a peculiar alignment for the object, we are only
8198 -- concerned about suspicious rep clauses, the default case does
8199 -- not affect us, since the compiler will, in the absence of such
8200 -- rep clauses, ensure that the alignment is correct.
8201
8202 if Default = Known_Compatible
8203 or else
8204 (Etype (Obj) = Etype (Expr)
8205 and then (Unknown_Alignment (Obj)
8206 or else
8207 Alignment (Obj) = Alignment (Etype (Obj))))
8208 then
8209 Set_Result
8210 (Has_Compatible_Alignment_Internal
8211 (Obj, Prefix (Expr), Known_Compatible));
8212
8213 -- In all other cases, we need a full check on the prefix
8214
8215 else
8216 Set_Result
8217 (Has_Compatible_Alignment_Internal
8218 (Obj, Prefix (Expr), Unknown));
8219 end if;
8220 end Check_Prefix;
8221
8222 ----------------
8223 -- Set_Result --
8224 ----------------
8225
8226 procedure Set_Result (R : Alignment_Result) is
8227 begin
8228 if R > Result then
8229 Result := R;
8230 end if;
8231 end Set_Result;
8232
8233 -- Start of processing for Has_Compatible_Alignment_Internal
8234
8235 begin
8236 -- If Expr is a selected component, we must make sure there is no
8237 -- potentially troublesome component clause, and that the record is
8238 -- not packed.
8239
8240 if Nkind (Expr) = N_Selected_Component then
8241
8242 -- Packed record always generate unknown alignment
8243
8244 if Is_Packed (Etype (Prefix (Expr))) then
8245 Set_Result (Unknown);
8246 end if;
8247
8248 -- Check prefix and component offset
8249
8250 Check_Prefix;
8251 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
8252
8253 -- If Expr is an indexed component, we must make sure there is no
8254 -- potentially troublesome Component_Size clause and that the array
8255 -- is not bit-packed.
8256
8257 elsif Nkind (Expr) = N_Indexed_Component then
8258 declare
8259 Typ : constant Entity_Id := Etype (Prefix (Expr));
8260 Ind : constant Node_Id := First_Index (Typ);
8261
8262 begin
8263 -- Bit packed array always generates unknown alignment
8264
8265 if Is_Bit_Packed_Array (Typ) then
8266 Set_Result (Unknown);
8267 end if;
8268
8269 -- Check prefix and component offset
8270
8271 Check_Prefix;
8272 Offs := Component_Size (Typ);
8273
8274 -- Small optimization: compute the full offset when possible
8275
8276 if Offs /= No_Uint
8277 and then Offs > Uint_0
8278 and then Present (Ind)
8279 and then Nkind (Ind) = N_Range
8280 and then Compile_Time_Known_Value (Low_Bound (Ind))
8281 and then Compile_Time_Known_Value (First (Expressions (Expr)))
8282 then
8283 Offs := Offs * (Expr_Value (First (Expressions (Expr)))
8284 - Expr_Value (Low_Bound ((Ind))));
8285 end if;
8286 end;
8287 end if;
8288
8289 -- If we have a null offset, the result is entirely determined by
8290 -- the base object and has already been computed recursively.
8291
8292 if Offs = Uint_0 then
8293 null;
8294
8295 -- Case where we know the alignment of the object
8296
8297 elsif Known_Alignment (Obj) then
8298 declare
8299 ObjA : constant Uint := Alignment (Obj);
8300 ExpA : Uint := No_Uint;
8301 SizA : Uint := No_Uint;
8302
8303 begin
8304 -- If alignment of Obj is 1, then we are always OK
8305
8306 if ObjA = 1 then
8307 Set_Result (Known_Compatible);
8308
8309 -- Alignment of Obj is greater than 1, so we need to check
8310
8311 else
8312 -- If we have an offset, see if it is compatible
8313
8314 if Offs /= No_Uint and Offs > Uint_0 then
8315 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
8316 Set_Result (Known_Incompatible);
8317 end if;
8318
8319 -- See if Expr is an object with known alignment
8320
8321 elsif Is_Entity_Name (Expr)
8322 and then Known_Alignment (Entity (Expr))
8323 then
8324 ExpA := Alignment (Entity (Expr));
8325
8326 -- Otherwise, we can use the alignment of the type of
8327 -- Expr given that we already checked for
8328 -- discombobulating rep clauses for the cases of indexed
8329 -- and selected components above.
8330
8331 elsif Known_Alignment (Etype (Expr)) then
8332 ExpA := Alignment (Etype (Expr));
8333
8334 -- Otherwise the alignment is unknown
8335
8336 else
8337 Set_Result (Default);
8338 end if;
8339
8340 -- If we got an alignment, see if it is acceptable
8341
8342 if ExpA /= No_Uint and then ExpA < ObjA then
8343 Set_Result (Known_Incompatible);
8344 end if;
8345
8346 -- If Expr is not a piece of a larger object, see if size
8347 -- is given. If so, check that it is not too small for the
8348 -- required alignment.
8349
8350 if Offs /= No_Uint then
8351 null;
8352
8353 -- See if Expr is an object with known size
8354
8355 elsif Is_Entity_Name (Expr)
8356 and then Known_Static_Esize (Entity (Expr))
8357 then
8358 SizA := Esize (Entity (Expr));
8359
8360 -- Otherwise, we check the object size of the Expr type
8361
8362 elsif Known_Static_Esize (Etype (Expr)) then
8363 SizA := Esize (Etype (Expr));
8364 end if;
8365
8366 -- If we got a size, see if it is a multiple of the Obj
8367 -- alignment, if not, then the alignment cannot be
8368 -- acceptable, since the size is always a multiple of the
8369 -- alignment.
8370
8371 if SizA /= No_Uint then
8372 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
8373 Set_Result (Known_Incompatible);
8374 end if;
8375 end if;
8376 end if;
8377 end;
8378
8379 -- If we do not know required alignment, any non-zero offset is a
8380 -- potential problem (but certainly may be OK, so result is unknown).
8381
8382 elsif Offs /= No_Uint then
8383 Set_Result (Unknown);
8384
8385 -- If we can't find the result by direct comparison of alignment
8386 -- values, then there is still one case that we can determine known
8387 -- result, and that is when we can determine that the types are the
8388 -- same, and no alignments are specified. Then we known that the
8389 -- alignments are compatible, even if we don't know the alignment
8390 -- value in the front end.
8391
8392 elsif Etype (Obj) = Etype (Expr) then
8393
8394 -- Types are the same, but we have to check for possible size
8395 -- and alignments on the Expr object that may make the alignment
8396 -- different, even though the types are the same.
8397
8398 if Is_Entity_Name (Expr) then
8399
8400 -- First check alignment of the Expr object. Any alignment less
8401 -- than Maximum_Alignment is worrisome since this is the case
8402 -- where we do not know the alignment of Obj.
8403
8404 if Known_Alignment (Entity (Expr))
8405 and then UI_To_Int (Alignment (Entity (Expr))) <
8406 Ttypes.Maximum_Alignment
8407 then
8408 Set_Result (Unknown);
8409
8410 -- Now check size of Expr object. Any size that is not an
8411 -- even multiple of Maximum_Alignment is also worrisome
8412 -- since it may cause the alignment of the object to be less
8413 -- than the alignment of the type.
8414
8415 elsif Known_Static_Esize (Entity (Expr))
8416 and then
8417 (UI_To_Int (Esize (Entity (Expr))) mod
8418 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
8419 /= 0
8420 then
8421 Set_Result (Unknown);
8422
8423 -- Otherwise same type is decisive
8424
8425 else
8426 Set_Result (Known_Compatible);
8427 end if;
8428 end if;
8429
8430 -- Another case to deal with is when there is an explicit size or
8431 -- alignment clause when the types are not the same. If so, then the
8432 -- result is Unknown. We don't need to do this test if the Default is
8433 -- Unknown, since that result will be set in any case.
8434
8435 elsif Default /= Unknown
8436 and then (Has_Size_Clause (Etype (Expr))
8437 or else
8438 Has_Alignment_Clause (Etype (Expr)))
8439 then
8440 Set_Result (Unknown);
8441
8442 -- If no indication found, set default
8443
8444 else
8445 Set_Result (Default);
8446 end if;
8447
8448 -- Return worst result found
8449
8450 return Result;
8451 end Has_Compatible_Alignment_Internal;
8452
8453 -- Start of processing for Has_Compatible_Alignment
8454
8455 begin
8456 -- If Obj has no specified alignment, then set alignment from the type
8457 -- alignment. Perhaps we should always do this, but for sure we should
8458 -- do it when there is an address clause since we can do more if the
8459 -- alignment is known.
8460
8461 if Unknown_Alignment (Obj) then
8462 Set_Alignment (Obj, Alignment (Etype (Obj)));
8463 end if;
8464
8465 -- Now do the internal call that does all the work
8466
8467 return Has_Compatible_Alignment_Internal (Obj, Expr, Unknown);
8468 end Has_Compatible_Alignment;
8469
8470 ----------------------
8471 -- Has_Declarations --
8472 ----------------------
8473
8474 function Has_Declarations (N : Node_Id) return Boolean is
8475 begin
8476 return Nkind_In (Nkind (N), N_Accept_Statement,
8477 N_Block_Statement,
8478 N_Compilation_Unit_Aux,
8479 N_Entry_Body,
8480 N_Package_Body,
8481 N_Protected_Body,
8482 N_Subprogram_Body,
8483 N_Task_Body,
8484 N_Package_Specification);
8485 end Has_Declarations;
8486
8487 ---------------------------------
8488 -- Has_Defaulted_Discriminants --
8489 ---------------------------------
8490
8491 function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean is
8492 begin
8493 return Has_Discriminants (Typ)
8494 and then Present (First_Discriminant (Typ))
8495 and then Present (Discriminant_Default_Value
8496 (First_Discriminant (Typ)));
8497 end Has_Defaulted_Discriminants;
8498
8499 -------------------
8500 -- Has_Denormals --
8501 -------------------
8502
8503 function Has_Denormals (E : Entity_Id) return Boolean is
8504 begin
8505 return Is_Floating_Point_Type (E) and then Denorm_On_Target;
8506 end Has_Denormals;
8507
8508 -------------------------------------------
8509 -- Has_Discriminant_Dependent_Constraint --
8510 -------------------------------------------
8511
8512 function Has_Discriminant_Dependent_Constraint
8513 (Comp : Entity_Id) return Boolean
8514 is
8515 Comp_Decl : constant Node_Id := Parent (Comp);
8516 Subt_Indic : Node_Id;
8517 Constr : Node_Id;
8518 Assn : Node_Id;
8519
8520 begin
8521 -- Discriminants can't depend on discriminants
8522
8523 if Ekind (Comp) = E_Discriminant then
8524 return False;
8525
8526 else
8527 Subt_Indic := Subtype_Indication (Component_Definition (Comp_Decl));
8528
8529 if Nkind (Subt_Indic) = N_Subtype_Indication then
8530 Constr := Constraint (Subt_Indic);
8531
8532 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
8533 Assn := First (Constraints (Constr));
8534 while Present (Assn) loop
8535 case Nkind (Assn) is
8536 when N_Subtype_Indication |
8537 N_Range |
8538 N_Identifier
8539 =>
8540 if Depends_On_Discriminant (Assn) then
8541 return True;
8542 end if;
8543
8544 when N_Discriminant_Association =>
8545 if Depends_On_Discriminant (Expression (Assn)) then
8546 return True;
8547 end if;
8548
8549 when others =>
8550 null;
8551 end case;
8552
8553 Next (Assn);
8554 end loop;
8555 end if;
8556 end if;
8557 end if;
8558
8559 return False;
8560 end Has_Discriminant_Dependent_Constraint;
8561
8562 --------------------------------------
8563 -- Has_Effectively_Volatile_Profile --
8564 --------------------------------------
8565
8566 function Has_Effectively_Volatile_Profile
8567 (Subp_Id : Entity_Id) return Boolean
8568 is
8569 Formal : Entity_Id;
8570
8571 begin
8572 -- Inspect the formal parameters looking for an effectively volatile
8573 -- type.
8574
8575 Formal := First_Formal (Subp_Id);
8576 while Present (Formal) loop
8577 if Is_Effectively_Volatile (Etype (Formal)) then
8578 return True;
8579 end if;
8580
8581 Next_Formal (Formal);
8582 end loop;
8583
8584 -- Inspect the return type of functions
8585
8586 if Ekind_In (Subp_Id, E_Function, E_Generic_Function)
8587 and then Is_Effectively_Volatile (Etype (Subp_Id))
8588 then
8589 return True;
8590 end if;
8591
8592 return False;
8593 end Has_Effectively_Volatile_Profile;
8594
8595 --------------------------
8596 -- Has_Enabled_Property --
8597 --------------------------
8598
8599 function Has_Enabled_Property
8600 (Item_Id : Entity_Id;
8601 Property : Name_Id) return Boolean
8602 is
8603 function State_Has_Enabled_Property return Boolean;
8604 -- Determine whether a state denoted by Item_Id has the property enabled
8605
8606 function Variable_Has_Enabled_Property return Boolean;
8607 -- Determine whether a variable denoted by Item_Id has the property
8608 -- enabled.
8609
8610 --------------------------------
8611 -- State_Has_Enabled_Property --
8612 --------------------------------
8613
8614 function State_Has_Enabled_Property return Boolean is
8615 Decl : constant Node_Id := Parent (Item_Id);
8616 Opt : Node_Id;
8617 Opt_Nam : Node_Id;
8618 Prop : Node_Id;
8619 Prop_Nam : Node_Id;
8620 Props : Node_Id;
8621
8622 begin
8623 -- The declaration of an external abstract state appears as an
8624 -- extension aggregate. If this is not the case, properties can never
8625 -- be set.
8626
8627 if Nkind (Decl) /= N_Extension_Aggregate then
8628 return False;
8629 end if;
8630
8631 -- When External appears as a simple option, it automatically enables
8632 -- all properties.
8633
8634 Opt := First (Expressions (Decl));
8635 while Present (Opt) loop
8636 if Nkind (Opt) = N_Identifier
8637 and then Chars (Opt) = Name_External
8638 then
8639 return True;
8640 end if;
8641
8642 Next (Opt);
8643 end loop;
8644
8645 -- When External specifies particular properties, inspect those and
8646 -- find the desired one (if any).
8647
8648 Opt := First (Component_Associations (Decl));
8649 while Present (Opt) loop
8650 Opt_Nam := First (Choices (Opt));
8651
8652 if Nkind (Opt_Nam) = N_Identifier
8653 and then Chars (Opt_Nam) = Name_External
8654 then
8655 Props := Expression (Opt);
8656
8657 -- Multiple properties appear as an aggregate
8658
8659 if Nkind (Props) = N_Aggregate then
8660
8661 -- Simple property form
8662
8663 Prop := First (Expressions (Props));
8664 while Present (Prop) loop
8665 if Chars (Prop) = Property then
8666 return True;
8667 end if;
8668
8669 Next (Prop);
8670 end loop;
8671
8672 -- Property with expression form
8673
8674 Prop := First (Component_Associations (Props));
8675 while Present (Prop) loop
8676 Prop_Nam := First (Choices (Prop));
8677
8678 -- The property can be represented in two ways:
8679 -- others => <value>
8680 -- <property> => <value>
8681
8682 if Nkind (Prop_Nam) = N_Others_Choice
8683 or else (Nkind (Prop_Nam) = N_Identifier
8684 and then Chars (Prop_Nam) = Property)
8685 then
8686 return Is_True (Expr_Value (Expression (Prop)));
8687 end if;
8688
8689 Next (Prop);
8690 end loop;
8691
8692 -- Single property
8693
8694 else
8695 return Chars (Props) = Property;
8696 end if;
8697 end if;
8698
8699 Next (Opt);
8700 end loop;
8701
8702 return False;
8703 end State_Has_Enabled_Property;
8704
8705 -----------------------------------
8706 -- Variable_Has_Enabled_Property --
8707 -----------------------------------
8708
8709 function Variable_Has_Enabled_Property return Boolean is
8710 function Is_Enabled (Prag : Node_Id) return Boolean;
8711 -- Determine whether property pragma Prag (if present) denotes an
8712 -- enabled property.
8713
8714 ----------------
8715 -- Is_Enabled --
8716 ----------------
8717
8718 function Is_Enabled (Prag : Node_Id) return Boolean is
8719 Arg1 : Node_Id;
8720
8721 begin
8722 if Present (Prag) then
8723 Arg1 := First (Pragma_Argument_Associations (Prag));
8724
8725 -- The pragma has an optional Boolean expression, the related
8726 -- property is enabled only when the expression evaluates to
8727 -- True.
8728
8729 if Present (Arg1) then
8730 return Is_True (Expr_Value (Get_Pragma_Arg (Arg1)));
8731
8732 -- Otherwise the lack of expression enables the property by
8733 -- default.
8734
8735 else
8736 return True;
8737 end if;
8738
8739 -- The property was never set in the first place
8740
8741 else
8742 return False;
8743 end if;
8744 end Is_Enabled;
8745
8746 -- Local variables
8747
8748 AR : constant Node_Id :=
8749 Get_Pragma (Item_Id, Pragma_Async_Readers);
8750 AW : constant Node_Id :=
8751 Get_Pragma (Item_Id, Pragma_Async_Writers);
8752 ER : constant Node_Id :=
8753 Get_Pragma (Item_Id, Pragma_Effective_Reads);
8754 EW : constant Node_Id :=
8755 Get_Pragma (Item_Id, Pragma_Effective_Writes);
8756
8757 -- Start of processing for Variable_Has_Enabled_Property
8758
8759 begin
8760 -- A non-effectively volatile object can never possess external
8761 -- properties.
8762
8763 if not Is_Effectively_Volatile (Item_Id) then
8764 return False;
8765
8766 -- External properties related to variables come in two flavors -
8767 -- explicit and implicit. The explicit case is characterized by the
8768 -- presence of a property pragma with an optional Boolean flag. The
8769 -- property is enabled when the flag evaluates to True or the flag is
8770 -- missing altogether.
8771
8772 elsif Property = Name_Async_Readers and then Is_Enabled (AR) then
8773 return True;
8774
8775 elsif Property = Name_Async_Writers and then Is_Enabled (AW) then
8776 return True;
8777
8778 elsif Property = Name_Effective_Reads and then Is_Enabled (ER) then
8779 return True;
8780
8781 elsif Property = Name_Effective_Writes and then Is_Enabled (EW) then
8782 return True;
8783
8784 -- The implicit case lacks all property pragmas
8785
8786 elsif No (AR) and then No (AW) and then No (ER) and then No (EW) then
8787 return True;
8788
8789 else
8790 return False;
8791 end if;
8792 end Variable_Has_Enabled_Property;
8793
8794 -- Start of processing for Has_Enabled_Property
8795
8796 begin
8797 -- Abstract states and variables have a flexible scheme of specifying
8798 -- external properties.
8799
8800 if Ekind (Item_Id) = E_Abstract_State then
8801 return State_Has_Enabled_Property;
8802
8803 elsif Ekind (Item_Id) = E_Variable then
8804 return Variable_Has_Enabled_Property;
8805
8806 -- Otherwise a property is enabled when the related item is effectively
8807 -- volatile.
8808
8809 else
8810 return Is_Effectively_Volatile (Item_Id);
8811 end if;
8812 end Has_Enabled_Property;
8813
8814 -------------------------------------
8815 -- Has_Full_Default_Initialization --
8816 -------------------------------------
8817
8818 function Has_Full_Default_Initialization (Typ : Entity_Id) return Boolean is
8819 Comp : Entity_Id;
8820
8821 begin
8822 -- A scalar type is fully default initialized if it is subject to aspect
8823 -- Default_Value.
8824
8825 if Is_Scalar_Type (Typ) then
8826 return Has_Default_Aspect (Typ);
8827
8828 -- An array type is fully default initialized if its element type is
8829 -- scalar and the array type carries aspect Default_Component_Value or
8830 -- the element type is fully default initialized.
8831
8832 elsif Is_Array_Type (Typ) then
8833 return
8834 Has_Default_Aspect (Typ)
8835 or else Has_Full_Default_Initialization (Component_Type (Typ));
8836
8837 -- A protected type, record type or type extension is fully default
8838 -- initialized if all its components either carry an initialization
8839 -- expression or have a type that is fully default initialized. The
8840 -- parent type of a type extension must be fully default initialized.
8841
8842 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
8843
8844 -- Inspect all entities defined in the scope of the type, looking for
8845 -- uninitialized components.
8846
8847 Comp := First_Entity (Typ);
8848 while Present (Comp) loop
8849 if Ekind (Comp) = E_Component
8850 and then Comes_From_Source (Comp)
8851 and then No (Expression (Parent (Comp)))
8852 and then not Has_Full_Default_Initialization (Etype (Comp))
8853 then
8854 return False;
8855 end if;
8856
8857 Next_Entity (Comp);
8858 end loop;
8859
8860 -- Ensure that the parent type of a type extension is fully default
8861 -- initialized.
8862
8863 if Etype (Typ) /= Typ
8864 and then not Has_Full_Default_Initialization (Etype (Typ))
8865 then
8866 return False;
8867 end if;
8868
8869 -- If we get here, then all components and parent portion are fully
8870 -- default initialized.
8871
8872 return True;
8873
8874 -- A task type is fully default initialized by default
8875
8876 elsif Is_Task_Type (Typ) then
8877 return True;
8878 end if;
8879
8880 -- A private type and by extension its full view is fully default
8881 -- initialized if it is subject to pragma Default_Initial_Condition
8882 -- with a non-null argument or inherits the pragma from a parent type.
8883 -- Since any type can act as the full view of a private type, this check
8884 -- is separated from the circuitry above.
8885
8886 if Has_Default_Init_Cond (Typ)
8887 or else Has_Inherited_Default_Init_Cond (Typ)
8888 then
8889 return
8890 Nkind (First (Pragma_Argument_Associations (Get_Pragma
8891 (Typ, Pragma_Default_Initial_Condition)))) /= N_Null;
8892
8893 -- Otherwise the type is not fully default initialized
8894
8895 else
8896 return False;
8897 end if;
8898 end Has_Full_Default_Initialization;
8899
8900 --------------------
8901 -- Has_Infinities --
8902 --------------------
8903
8904 function Has_Infinities (E : Entity_Id) return Boolean is
8905 begin
8906 return
8907 Is_Floating_Point_Type (E)
8908 and then Nkind (Scalar_Range (E)) = N_Range
8909 and then Includes_Infinities (Scalar_Range (E));
8910 end Has_Infinities;
8911
8912 --------------------
8913 -- Has_Interfaces --
8914 --------------------
8915
8916 function Has_Interfaces
8917 (T : Entity_Id;
8918 Use_Full_View : Boolean := True) return Boolean
8919 is
8920 Typ : Entity_Id := Base_Type (T);
8921
8922 begin
8923 -- Handle concurrent types
8924
8925 if Is_Concurrent_Type (Typ) then
8926 Typ := Corresponding_Record_Type (Typ);
8927 end if;
8928
8929 if not Present (Typ)
8930 or else not Is_Record_Type (Typ)
8931 or else not Is_Tagged_Type (Typ)
8932 then
8933 return False;
8934 end if;
8935
8936 -- Handle private types
8937
8938 if Use_Full_View and then Present (Full_View (Typ)) then
8939 Typ := Full_View (Typ);
8940 end if;
8941
8942 -- Handle concurrent record types
8943
8944 if Is_Concurrent_Record_Type (Typ)
8945 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
8946 then
8947 return True;
8948 end if;
8949
8950 loop
8951 if Is_Interface (Typ)
8952 or else
8953 (Is_Record_Type (Typ)
8954 and then Present (Interfaces (Typ))
8955 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
8956 then
8957 return True;
8958 end if;
8959
8960 exit when Etype (Typ) = Typ
8961
8962 -- Handle private types
8963
8964 or else (Present (Full_View (Etype (Typ)))
8965 and then Full_View (Etype (Typ)) = Typ)
8966
8967 -- Protect frontend against wrong sources with cyclic derivations
8968
8969 or else Etype (Typ) = T;
8970
8971 -- Climb to the ancestor type handling private types
8972
8973 if Present (Full_View (Etype (Typ))) then
8974 Typ := Full_View (Etype (Typ));
8975 else
8976 Typ := Etype (Typ);
8977 end if;
8978 end loop;
8979
8980 return False;
8981 end Has_Interfaces;
8982
8983 ---------------------------------
8984 -- Has_No_Obvious_Side_Effects --
8985 ---------------------------------
8986
8987 function Has_No_Obvious_Side_Effects (N : Node_Id) return Boolean is
8988 begin
8989 -- For now, just handle literals, constants, and non-volatile
8990 -- variables and expressions combining these with operators or
8991 -- short circuit forms.
8992
8993 if Nkind (N) in N_Numeric_Or_String_Literal then
8994 return True;
8995
8996 elsif Nkind (N) = N_Character_Literal then
8997 return True;
8998
8999 elsif Nkind (N) in N_Unary_Op then
9000 return Has_No_Obvious_Side_Effects (Right_Opnd (N));
9001
9002 elsif Nkind (N) in N_Binary_Op or else Nkind (N) in N_Short_Circuit then
9003 return Has_No_Obvious_Side_Effects (Left_Opnd (N))
9004 and then
9005 Has_No_Obvious_Side_Effects (Right_Opnd (N));
9006
9007 elsif Nkind (N) = N_Expression_With_Actions
9008 and then Is_Empty_List (Actions (N))
9009 then
9010 return Has_No_Obvious_Side_Effects (Expression (N));
9011
9012 elsif Nkind (N) in N_Has_Entity then
9013 return Present (Entity (N))
9014 and then Ekind_In (Entity (N), E_Variable,
9015 E_Constant,
9016 E_Enumeration_Literal,
9017 E_In_Parameter,
9018 E_Out_Parameter,
9019 E_In_Out_Parameter)
9020 and then not Is_Volatile (Entity (N));
9021
9022 else
9023 return False;
9024 end if;
9025 end Has_No_Obvious_Side_Effects;
9026
9027 ------------------------
9028 -- Has_Null_Exclusion --
9029 ------------------------
9030
9031 function Has_Null_Exclusion (N : Node_Id) return Boolean is
9032 begin
9033 case Nkind (N) is
9034 when N_Access_Definition |
9035 N_Access_Function_Definition |
9036 N_Access_Procedure_Definition |
9037 N_Access_To_Object_Definition |
9038 N_Allocator |
9039 N_Derived_Type_Definition |
9040 N_Function_Specification |
9041 N_Subtype_Declaration =>
9042 return Null_Exclusion_Present (N);
9043
9044 when N_Component_Definition |
9045 N_Formal_Object_Declaration |
9046 N_Object_Renaming_Declaration =>
9047 if Present (Subtype_Mark (N)) then
9048 return Null_Exclusion_Present (N);
9049 else pragma Assert (Present (Access_Definition (N)));
9050 return Null_Exclusion_Present (Access_Definition (N));
9051 end if;
9052
9053 when N_Discriminant_Specification =>
9054 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
9055 return Null_Exclusion_Present (Discriminant_Type (N));
9056 else
9057 return Null_Exclusion_Present (N);
9058 end if;
9059
9060 when N_Object_Declaration =>
9061 if Nkind (Object_Definition (N)) = N_Access_Definition then
9062 return Null_Exclusion_Present (Object_Definition (N));
9063 else
9064 return Null_Exclusion_Present (N);
9065 end if;
9066
9067 when N_Parameter_Specification =>
9068 if Nkind (Parameter_Type (N)) = N_Access_Definition then
9069 return Null_Exclusion_Present (Parameter_Type (N));
9070 else
9071 return Null_Exclusion_Present (N);
9072 end if;
9073
9074 when others =>
9075 return False;
9076
9077 end case;
9078 end Has_Null_Exclusion;
9079
9080 ------------------------
9081 -- Has_Null_Extension --
9082 ------------------------
9083
9084 function Has_Null_Extension (T : Entity_Id) return Boolean is
9085 B : constant Entity_Id := Base_Type (T);
9086 Comps : Node_Id;
9087 Ext : Node_Id;
9088
9089 begin
9090 if Nkind (Parent (B)) = N_Full_Type_Declaration
9091 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
9092 then
9093 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
9094
9095 if Present (Ext) then
9096 if Null_Present (Ext) then
9097 return True;
9098 else
9099 Comps := Component_List (Ext);
9100
9101 -- The null component list is rewritten during analysis to
9102 -- include the parent component. Any other component indicates
9103 -- that the extension was not originally null.
9104
9105 return Null_Present (Comps)
9106 or else No (Next (First (Component_Items (Comps))));
9107 end if;
9108 else
9109 return False;
9110 end if;
9111
9112 else
9113 return False;
9114 end if;
9115 end Has_Null_Extension;
9116
9117 -------------------------------
9118 -- Has_Overriding_Initialize --
9119 -------------------------------
9120
9121 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
9122 BT : constant Entity_Id := Base_Type (T);
9123 P : Elmt_Id;
9124
9125 begin
9126 if Is_Controlled (BT) then
9127 if Is_RTU (Scope (BT), Ada_Finalization) then
9128 return False;
9129
9130 elsif Present (Primitive_Operations (BT)) then
9131 P := First_Elmt (Primitive_Operations (BT));
9132 while Present (P) loop
9133 declare
9134 Init : constant Entity_Id := Node (P);
9135 Formal : constant Entity_Id := First_Formal (Init);
9136 begin
9137 if Ekind (Init) = E_Procedure
9138 and then Chars (Init) = Name_Initialize
9139 and then Comes_From_Source (Init)
9140 and then Present (Formal)
9141 and then Etype (Formal) = BT
9142 and then No (Next_Formal (Formal))
9143 and then (Ada_Version < Ada_2012
9144 or else not Null_Present (Parent (Init)))
9145 then
9146 return True;
9147 end if;
9148 end;
9149
9150 Next_Elmt (P);
9151 end loop;
9152 end if;
9153
9154 -- Here if type itself does not have a non-null Initialize operation:
9155 -- check immediate ancestor.
9156
9157 if Is_Derived_Type (BT)
9158 and then Has_Overriding_Initialize (Etype (BT))
9159 then
9160 return True;
9161 end if;
9162 end if;
9163
9164 return False;
9165 end Has_Overriding_Initialize;
9166
9167 --------------------------------------
9168 -- Has_Preelaborable_Initialization --
9169 --------------------------------------
9170
9171 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
9172 Has_PE : Boolean;
9173
9174 procedure Check_Components (E : Entity_Id);
9175 -- Check component/discriminant chain, sets Has_PE False if a component
9176 -- or discriminant does not meet the preelaborable initialization rules.
9177
9178 ----------------------
9179 -- Check_Components --
9180 ----------------------
9181
9182 procedure Check_Components (E : Entity_Id) is
9183 Ent : Entity_Id;
9184 Exp : Node_Id;
9185
9186 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
9187 -- Returns True if and only if the expression denoted by N does not
9188 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
9189
9190 ---------------------------------
9191 -- Is_Preelaborable_Expression --
9192 ---------------------------------
9193
9194 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
9195 Exp : Node_Id;
9196 Assn : Node_Id;
9197 Choice : Node_Id;
9198 Comp_Type : Entity_Id;
9199 Is_Array_Aggr : Boolean;
9200
9201 begin
9202 if Is_OK_Static_Expression (N) then
9203 return True;
9204
9205 elsif Nkind (N) = N_Null then
9206 return True;
9207
9208 -- Attributes are allowed in general, even if their prefix is a
9209 -- formal type. (It seems that certain attributes known not to be
9210 -- static might not be allowed, but there are no rules to prevent
9211 -- them.)
9212
9213 elsif Nkind (N) = N_Attribute_Reference then
9214 return True;
9215
9216 -- The name of a discriminant evaluated within its parent type is
9217 -- defined to be preelaborable (10.2.1(8)). Note that we test for
9218 -- names that denote discriminals as well as discriminants to
9219 -- catch references occurring within init procs.
9220
9221 elsif Is_Entity_Name (N)
9222 and then
9223 (Ekind (Entity (N)) = E_Discriminant
9224 or else (Ekind_In (Entity (N), E_Constant, E_In_Parameter)
9225 and then Present (Discriminal_Link (Entity (N)))))
9226 then
9227 return True;
9228
9229 elsif Nkind (N) = N_Qualified_Expression then
9230 return Is_Preelaborable_Expression (Expression (N));
9231
9232 -- For aggregates we have to check that each of the associations
9233 -- is preelaborable.
9234
9235 elsif Nkind_In (N, N_Aggregate, N_Extension_Aggregate) then
9236 Is_Array_Aggr := Is_Array_Type (Etype (N));
9237
9238 if Is_Array_Aggr then
9239 Comp_Type := Component_Type (Etype (N));
9240 end if;
9241
9242 -- Check the ancestor part of extension aggregates, which must
9243 -- be either the name of a type that has preelaborable init or
9244 -- an expression that is preelaborable.
9245
9246 if Nkind (N) = N_Extension_Aggregate then
9247 declare
9248 Anc_Part : constant Node_Id := Ancestor_Part (N);
9249
9250 begin
9251 if Is_Entity_Name (Anc_Part)
9252 and then Is_Type (Entity (Anc_Part))
9253 then
9254 if not Has_Preelaborable_Initialization
9255 (Entity (Anc_Part))
9256 then
9257 return False;
9258 end if;
9259
9260 elsif not Is_Preelaborable_Expression (Anc_Part) then
9261 return False;
9262 end if;
9263 end;
9264 end if;
9265
9266 -- Check positional associations
9267
9268 Exp := First (Expressions (N));
9269 while Present (Exp) loop
9270 if not Is_Preelaborable_Expression (Exp) then
9271 return False;
9272 end if;
9273
9274 Next (Exp);
9275 end loop;
9276
9277 -- Check named associations
9278
9279 Assn := First (Component_Associations (N));
9280 while Present (Assn) loop
9281 Choice := First (Choices (Assn));
9282 while Present (Choice) loop
9283 if Is_Array_Aggr then
9284 if Nkind (Choice) = N_Others_Choice then
9285 null;
9286
9287 elsif Nkind (Choice) = N_Range then
9288 if not Is_OK_Static_Range (Choice) then
9289 return False;
9290 end if;
9291
9292 elsif not Is_OK_Static_Expression (Choice) then
9293 return False;
9294 end if;
9295
9296 else
9297 Comp_Type := Etype (Choice);
9298 end if;
9299
9300 Next (Choice);
9301 end loop;
9302
9303 -- If the association has a <> at this point, then we have
9304 -- to check whether the component's type has preelaborable
9305 -- initialization. Note that this only occurs when the
9306 -- association's corresponding component does not have a
9307 -- default expression, the latter case having already been
9308 -- expanded as an expression for the association.
9309
9310 if Box_Present (Assn) then
9311 if not Has_Preelaborable_Initialization (Comp_Type) then
9312 return False;
9313 end if;
9314
9315 -- In the expression case we check whether the expression
9316 -- is preelaborable.
9317
9318 elsif
9319 not Is_Preelaborable_Expression (Expression (Assn))
9320 then
9321 return False;
9322 end if;
9323
9324 Next (Assn);
9325 end loop;
9326
9327 -- If we get here then aggregate as a whole is preelaborable
9328
9329 return True;
9330
9331 -- All other cases are not preelaborable
9332
9333 else
9334 return False;
9335 end if;
9336 end Is_Preelaborable_Expression;
9337
9338 -- Start of processing for Check_Components
9339
9340 begin
9341 -- Loop through entities of record or protected type
9342
9343 Ent := E;
9344 while Present (Ent) loop
9345
9346 -- We are interested only in components and discriminants
9347
9348 Exp := Empty;
9349
9350 case Ekind (Ent) is
9351 when E_Component =>
9352
9353 -- Get default expression if any. If there is no declaration
9354 -- node, it means we have an internal entity. The parent and
9355 -- tag fields are examples of such entities. For such cases,
9356 -- we just test the type of the entity.
9357
9358 if Present (Declaration_Node (Ent)) then
9359 Exp := Expression (Declaration_Node (Ent));
9360 end if;
9361
9362 when E_Discriminant =>
9363
9364 -- Note: for a renamed discriminant, the Declaration_Node
9365 -- may point to the one from the ancestor, and have a
9366 -- different expression, so use the proper attribute to
9367 -- retrieve the expression from the derived constraint.
9368
9369 Exp := Discriminant_Default_Value (Ent);
9370
9371 when others =>
9372 goto Check_Next_Entity;
9373 end case;
9374
9375 -- A component has PI if it has no default expression and the
9376 -- component type has PI.
9377
9378 if No (Exp) then
9379 if not Has_Preelaborable_Initialization (Etype (Ent)) then
9380 Has_PE := False;
9381 exit;
9382 end if;
9383
9384 -- Require the default expression to be preelaborable
9385
9386 elsif not Is_Preelaborable_Expression (Exp) then
9387 Has_PE := False;
9388 exit;
9389 end if;
9390
9391 <<Check_Next_Entity>>
9392 Next_Entity (Ent);
9393 end loop;
9394 end Check_Components;
9395
9396 -- Start of processing for Has_Preelaborable_Initialization
9397
9398 begin
9399 -- Immediate return if already marked as known preelaborable init. This
9400 -- covers types for which this function has already been called once
9401 -- and returned True (in which case the result is cached), and also
9402 -- types to which a pragma Preelaborable_Initialization applies.
9403
9404 if Known_To_Have_Preelab_Init (E) then
9405 return True;
9406 end if;
9407
9408 -- If the type is a subtype representing a generic actual type, then
9409 -- test whether its base type has preelaborable initialization since
9410 -- the subtype representing the actual does not inherit this attribute
9411 -- from the actual or formal. (but maybe it should???)
9412
9413 if Is_Generic_Actual_Type (E) then
9414 return Has_Preelaborable_Initialization (Base_Type (E));
9415 end if;
9416
9417 -- All elementary types have preelaborable initialization
9418
9419 if Is_Elementary_Type (E) then
9420 Has_PE := True;
9421
9422 -- Array types have PI if the component type has PI
9423
9424 elsif Is_Array_Type (E) then
9425 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
9426
9427 -- A derived type has preelaborable initialization if its parent type
9428 -- has preelaborable initialization and (in the case of a derived record
9429 -- extension) if the non-inherited components all have preelaborable
9430 -- initialization. However, a user-defined controlled type with an
9431 -- overriding Initialize procedure does not have preelaborable
9432 -- initialization.
9433
9434 elsif Is_Derived_Type (E) then
9435
9436 -- If the derived type is a private extension then it doesn't have
9437 -- preelaborable initialization.
9438
9439 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
9440 return False;
9441 end if;
9442
9443 -- First check whether ancestor type has preelaborable initialization
9444
9445 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
9446
9447 -- If OK, check extension components (if any)
9448
9449 if Has_PE and then Is_Record_Type (E) then
9450 Check_Components (First_Entity (E));
9451 end if;
9452
9453 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
9454 -- with a user defined Initialize procedure does not have PI. If
9455 -- the type is untagged, the control primitives come from a component
9456 -- that has already been checked.
9457
9458 if Has_PE
9459 and then Is_Controlled (E)
9460 and then Is_Tagged_Type (E)
9461 and then Has_Overriding_Initialize (E)
9462 then
9463 Has_PE := False;
9464 end if;
9465
9466 -- Private types not derived from a type having preelaborable init and
9467 -- that are not marked with pragma Preelaborable_Initialization do not
9468 -- have preelaborable initialization.
9469
9470 elsif Is_Private_Type (E) then
9471 return False;
9472
9473 -- Record type has PI if it is non private and all components have PI
9474
9475 elsif Is_Record_Type (E) then
9476 Has_PE := True;
9477 Check_Components (First_Entity (E));
9478
9479 -- Protected types must not have entries, and components must meet
9480 -- same set of rules as for record components.
9481
9482 elsif Is_Protected_Type (E) then
9483 if Has_Entries (E) then
9484 Has_PE := False;
9485 else
9486 Has_PE := True;
9487 Check_Components (First_Entity (E));
9488 Check_Components (First_Private_Entity (E));
9489 end if;
9490
9491 -- Type System.Address always has preelaborable initialization
9492
9493 elsif Is_RTE (E, RE_Address) then
9494 Has_PE := True;
9495
9496 -- In all other cases, type does not have preelaborable initialization
9497
9498 else
9499 return False;
9500 end if;
9501
9502 -- If type has preelaborable initialization, cache result
9503
9504 if Has_PE then
9505 Set_Known_To_Have_Preelab_Init (E);
9506 end if;
9507
9508 return Has_PE;
9509 end Has_Preelaborable_Initialization;
9510
9511 ---------------------------
9512 -- Has_Private_Component --
9513 ---------------------------
9514
9515 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
9516 Btype : Entity_Id := Base_Type (Type_Id);
9517 Component : Entity_Id;
9518
9519 begin
9520 if Error_Posted (Type_Id)
9521 or else Error_Posted (Btype)
9522 then
9523 return False;
9524 end if;
9525
9526 if Is_Class_Wide_Type (Btype) then
9527 Btype := Root_Type (Btype);
9528 end if;
9529
9530 if Is_Private_Type (Btype) then
9531 declare
9532 UT : constant Entity_Id := Underlying_Type (Btype);
9533 begin
9534 if No (UT) then
9535 if No (Full_View (Btype)) then
9536 return not Is_Generic_Type (Btype)
9537 and then
9538 not Is_Generic_Type (Root_Type (Btype));
9539 else
9540 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
9541 end if;
9542 else
9543 return not Is_Frozen (UT) and then Has_Private_Component (UT);
9544 end if;
9545 end;
9546
9547 elsif Is_Array_Type (Btype) then
9548 return Has_Private_Component (Component_Type (Btype));
9549
9550 elsif Is_Record_Type (Btype) then
9551 Component := First_Component (Btype);
9552 while Present (Component) loop
9553 if Has_Private_Component (Etype (Component)) then
9554 return True;
9555 end if;
9556
9557 Next_Component (Component);
9558 end loop;
9559
9560 return False;
9561
9562 elsif Is_Protected_Type (Btype)
9563 and then Present (Corresponding_Record_Type (Btype))
9564 then
9565 return Has_Private_Component (Corresponding_Record_Type (Btype));
9566
9567 else
9568 return False;
9569 end if;
9570 end Has_Private_Component;
9571
9572 ----------------------
9573 -- Has_Signed_Zeros --
9574 ----------------------
9575
9576 function Has_Signed_Zeros (E : Entity_Id) return Boolean is
9577 begin
9578 return Is_Floating_Point_Type (E) and then Signed_Zeros_On_Target;
9579 end Has_Signed_Zeros;
9580
9581 ------------------------------
9582 -- Has_Significant_Contract --
9583 ------------------------------
9584
9585 function Has_Significant_Contract (Subp_Id : Entity_Id) return Boolean is
9586 Subp_Nam : constant Name_Id := Chars (Subp_Id);
9587
9588 begin
9589 -- _Finalizer procedure
9590
9591 if Subp_Nam = Name_uFinalizer then
9592 return False;
9593
9594 -- _Postconditions procedure
9595
9596 elsif Subp_Nam = Name_uPostconditions then
9597 return False;
9598
9599 -- Predicate function
9600
9601 elsif Ekind (Subp_Id) = E_Function
9602 and then Is_Predicate_Function (Subp_Id)
9603 then
9604 return False;
9605
9606 -- TSS subprogram
9607
9608 elsif Get_TSS_Name (Subp_Id) /= TSS_Null then
9609 return False;
9610
9611 else
9612 return True;
9613 end if;
9614 end Has_Significant_Contract;
9615
9616 -----------------------------
9617 -- Has_Static_Array_Bounds --
9618 -----------------------------
9619
9620 function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is
9621 Ndims : constant Nat := Number_Dimensions (Typ);
9622
9623 Index : Node_Id;
9624 Low : Node_Id;
9625 High : Node_Id;
9626
9627 begin
9628 -- Unconstrained types do not have static bounds
9629
9630 if not Is_Constrained (Typ) then
9631 return False;
9632 end if;
9633
9634 -- First treat string literals specially, as the lower bound and length
9635 -- of string literals are not stored like those of arrays.
9636
9637 -- A string literal always has static bounds
9638
9639 if Ekind (Typ) = E_String_Literal_Subtype then
9640 return True;
9641 end if;
9642
9643 -- Treat all dimensions in turn
9644
9645 Index := First_Index (Typ);
9646 for Indx in 1 .. Ndims loop
9647
9648 -- In case of an illegal index which is not a discrete type, return
9649 -- that the type is not static.
9650
9651 if not Is_Discrete_Type (Etype (Index))
9652 or else Etype (Index) = Any_Type
9653 then
9654 return False;
9655 end if;
9656
9657 Get_Index_Bounds (Index, Low, High);
9658
9659 if Error_Posted (Low) or else Error_Posted (High) then
9660 return False;
9661 end if;
9662
9663 if Is_OK_Static_Expression (Low)
9664 and then
9665 Is_OK_Static_Expression (High)
9666 then
9667 null;
9668 else
9669 return False;
9670 end if;
9671
9672 Next (Index);
9673 end loop;
9674
9675 -- If we fall through the loop, all indexes matched
9676
9677 return True;
9678 end Has_Static_Array_Bounds;
9679
9680 ----------------
9681 -- Has_Stream --
9682 ----------------
9683
9684 function Has_Stream (T : Entity_Id) return Boolean is
9685 E : Entity_Id;
9686
9687 begin
9688 if No (T) then
9689 return False;
9690
9691 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
9692 return True;
9693
9694 elsif Is_Array_Type (T) then
9695 return Has_Stream (Component_Type (T));
9696
9697 elsif Is_Record_Type (T) then
9698 E := First_Component (T);
9699 while Present (E) loop
9700 if Has_Stream (Etype (E)) then
9701 return True;
9702 else
9703 Next_Component (E);
9704 end if;
9705 end loop;
9706
9707 return False;
9708
9709 elsif Is_Private_Type (T) then
9710 return Has_Stream (Underlying_Type (T));
9711
9712 else
9713 return False;
9714 end if;
9715 end Has_Stream;
9716
9717 ----------------
9718 -- Has_Suffix --
9719 ----------------
9720
9721 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
9722 begin
9723 Get_Name_String (Chars (E));
9724 return Name_Buffer (Name_Len) = Suffix;
9725 end Has_Suffix;
9726
9727 ----------------
9728 -- Add_Suffix --
9729 ----------------
9730
9731 function Add_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
9732 begin
9733 Get_Name_String (Chars (E));
9734 Add_Char_To_Name_Buffer (Suffix);
9735 return Name_Find;
9736 end Add_Suffix;
9737
9738 -------------------
9739 -- Remove_Suffix --
9740 -------------------
9741
9742 function Remove_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
9743 begin
9744 pragma Assert (Has_Suffix (E, Suffix));
9745 Get_Name_String (Chars (E));
9746 Name_Len := Name_Len - 1;
9747 return Name_Find;
9748 end Remove_Suffix;
9749
9750 --------------------------
9751 -- Has_Tagged_Component --
9752 --------------------------
9753
9754 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
9755 Comp : Entity_Id;
9756
9757 begin
9758 if Is_Private_Type (Typ) and then Present (Underlying_Type (Typ)) then
9759 return Has_Tagged_Component (Underlying_Type (Typ));
9760
9761 elsif Is_Array_Type (Typ) then
9762 return Has_Tagged_Component (Component_Type (Typ));
9763
9764 elsif Is_Tagged_Type (Typ) then
9765 return True;
9766
9767 elsif Is_Record_Type (Typ) then
9768 Comp := First_Component (Typ);
9769 while Present (Comp) loop
9770 if Has_Tagged_Component (Etype (Comp)) then
9771 return True;
9772 end if;
9773
9774 Next_Component (Comp);
9775 end loop;
9776
9777 return False;
9778
9779 else
9780 return False;
9781 end if;
9782 end Has_Tagged_Component;
9783
9784 ----------------------------
9785 -- Has_Volatile_Component --
9786 ----------------------------
9787
9788 function Has_Volatile_Component (Typ : Entity_Id) return Boolean is
9789 Comp : Entity_Id;
9790
9791 begin
9792 if Has_Volatile_Components (Typ) then
9793 return True;
9794
9795 elsif Is_Array_Type (Typ) then
9796 return Is_Volatile (Component_Type (Typ));
9797
9798 elsif Is_Record_Type (Typ) then
9799 Comp := First_Component (Typ);
9800 while Present (Comp) loop
9801 if Is_Volatile_Object (Comp) then
9802 return True;
9803 end if;
9804
9805 Comp := Next_Component (Comp);
9806 end loop;
9807 end if;
9808
9809 return False;
9810 end Has_Volatile_Component;
9811
9812 -------------------------
9813 -- Implementation_Kind --
9814 -------------------------
9815
9816 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
9817 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
9818 Arg : Node_Id;
9819 begin
9820 pragma Assert (Present (Impl_Prag));
9821 Arg := Last (Pragma_Argument_Associations (Impl_Prag));
9822 return Chars (Get_Pragma_Arg (Arg));
9823 end Implementation_Kind;
9824
9825 --------------------------
9826 -- Implements_Interface --
9827 --------------------------
9828
9829 function Implements_Interface
9830 (Typ_Ent : Entity_Id;
9831 Iface_Ent : Entity_Id;
9832 Exclude_Parents : Boolean := False) return Boolean
9833 is
9834 Ifaces_List : Elist_Id;
9835 Elmt : Elmt_Id;
9836 Iface : Entity_Id := Base_Type (Iface_Ent);
9837 Typ : Entity_Id := Base_Type (Typ_Ent);
9838
9839 begin
9840 if Is_Class_Wide_Type (Typ) then
9841 Typ := Root_Type (Typ);
9842 end if;
9843
9844 if not Has_Interfaces (Typ) then
9845 return False;
9846 end if;
9847
9848 if Is_Class_Wide_Type (Iface) then
9849 Iface := Root_Type (Iface);
9850 end if;
9851
9852 Collect_Interfaces (Typ, Ifaces_List);
9853
9854 Elmt := First_Elmt (Ifaces_List);
9855 while Present (Elmt) loop
9856 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
9857 and then Exclude_Parents
9858 then
9859 null;
9860
9861 elsif Node (Elmt) = Iface then
9862 return True;
9863 end if;
9864
9865 Next_Elmt (Elmt);
9866 end loop;
9867
9868 return False;
9869 end Implements_Interface;
9870
9871 ------------------------------------
9872 -- In_Assertion_Expression_Pragma --
9873 ------------------------------------
9874
9875 function In_Assertion_Expression_Pragma (N : Node_Id) return Boolean is
9876 Par : Node_Id;
9877 Prag : Node_Id := Empty;
9878
9879 begin
9880 -- Climb the parent chain looking for an enclosing pragma
9881
9882 Par := N;
9883 while Present (Par) loop
9884 if Nkind (Par) = N_Pragma then
9885 Prag := Par;
9886 exit;
9887
9888 -- Precondition-like pragmas are expanded into if statements, check
9889 -- the original node instead.
9890
9891 elsif Nkind (Original_Node (Par)) = N_Pragma then
9892 Prag := Original_Node (Par);
9893 exit;
9894
9895 -- The expansion of attribute 'Old generates a constant to capture
9896 -- the result of the prefix. If the parent traversal reaches
9897 -- one of these constants, then the node technically came from a
9898 -- postcondition-like pragma. Note that the Ekind is not tested here
9899 -- because N may be the expression of an object declaration which is
9900 -- currently being analyzed. Such objects carry Ekind of E_Void.
9901
9902 elsif Nkind (Par) = N_Object_Declaration
9903 and then Constant_Present (Par)
9904 and then Stores_Attribute_Old_Prefix (Defining_Entity (Par))
9905 then
9906 return True;
9907
9908 -- Prevent the search from going too far
9909
9910 elsif Is_Body_Or_Package_Declaration (Par) then
9911 return False;
9912 end if;
9913
9914 Par := Parent (Par);
9915 end loop;
9916
9917 return
9918 Present (Prag)
9919 and then Assertion_Expression_Pragma (Get_Pragma_Id (Prag));
9920 end In_Assertion_Expression_Pragma;
9921
9922 -----------------
9923 -- In_Instance --
9924 -----------------
9925
9926 function In_Instance return Boolean is
9927 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
9928 S : Entity_Id;
9929
9930 begin
9931 S := Current_Scope;
9932 while Present (S) and then S /= Standard_Standard loop
9933 if Ekind_In (S, E_Function, E_Package, E_Procedure)
9934 and then Is_Generic_Instance (S)
9935 then
9936 -- A child instance is always compiled in the context of a parent
9937 -- instance. Nevertheless, the actuals are not analyzed in an
9938 -- instance context. We detect this case by examining the current
9939 -- compilation unit, which must be a child instance, and checking
9940 -- that it is not currently on the scope stack.
9941
9942 if Is_Child_Unit (Curr_Unit)
9943 and then Nkind (Unit (Cunit (Current_Sem_Unit))) =
9944 N_Package_Instantiation
9945 and then not In_Open_Scopes (Curr_Unit)
9946 then
9947 return False;
9948 else
9949 return True;
9950 end if;
9951 end if;
9952
9953 S := Scope (S);
9954 end loop;
9955
9956 return False;
9957 end In_Instance;
9958
9959 ----------------------
9960 -- In_Instance_Body --
9961 ----------------------
9962
9963 function In_Instance_Body return Boolean is
9964 S : Entity_Id;
9965
9966 begin
9967 S := Current_Scope;
9968 while Present (S) and then S /= Standard_Standard loop
9969 if Ekind_In (S, E_Function, E_Procedure)
9970 and then Is_Generic_Instance (S)
9971 then
9972 return True;
9973
9974 elsif Ekind (S) = E_Package
9975 and then In_Package_Body (S)
9976 and then Is_Generic_Instance (S)
9977 then
9978 return True;
9979 end if;
9980
9981 S := Scope (S);
9982 end loop;
9983
9984 return False;
9985 end In_Instance_Body;
9986
9987 -----------------------------
9988 -- In_Instance_Not_Visible --
9989 -----------------------------
9990
9991 function In_Instance_Not_Visible return Boolean is
9992 S : Entity_Id;
9993
9994 begin
9995 S := Current_Scope;
9996 while Present (S) and then S /= Standard_Standard loop
9997 if Ekind_In (S, E_Function, E_Procedure)
9998 and then Is_Generic_Instance (S)
9999 then
10000 return True;
10001
10002 elsif Ekind (S) = E_Package
10003 and then (In_Package_Body (S) or else In_Private_Part (S))
10004 and then Is_Generic_Instance (S)
10005 then
10006 return True;
10007 end if;
10008
10009 S := Scope (S);
10010 end loop;
10011
10012 return False;
10013 end In_Instance_Not_Visible;
10014
10015 ------------------------------
10016 -- In_Instance_Visible_Part --
10017 ------------------------------
10018
10019 function In_Instance_Visible_Part return Boolean is
10020 S : Entity_Id;
10021
10022 begin
10023 S := Current_Scope;
10024 while Present (S) and then S /= Standard_Standard loop
10025 if Ekind (S) = E_Package
10026 and then Is_Generic_Instance (S)
10027 and then not In_Package_Body (S)
10028 and then not In_Private_Part (S)
10029 then
10030 return True;
10031 end if;
10032
10033 S := Scope (S);
10034 end loop;
10035
10036 return False;
10037 end In_Instance_Visible_Part;
10038
10039 ---------------------
10040 -- In_Package_Body --
10041 ---------------------
10042
10043 function In_Package_Body return Boolean is
10044 S : Entity_Id;
10045
10046 begin
10047 S := Current_Scope;
10048 while Present (S) and then S /= Standard_Standard loop
10049 if Ekind (S) = E_Package and then In_Package_Body (S) then
10050 return True;
10051 else
10052 S := Scope (S);
10053 end if;
10054 end loop;
10055
10056 return False;
10057 end In_Package_Body;
10058
10059 --------------------------------
10060 -- In_Parameter_Specification --
10061 --------------------------------
10062
10063 function In_Parameter_Specification (N : Node_Id) return Boolean is
10064 PN : Node_Id;
10065
10066 begin
10067 PN := Parent (N);
10068 while Present (PN) loop
10069 if Nkind (PN) = N_Parameter_Specification then
10070 return True;
10071 end if;
10072
10073 PN := Parent (PN);
10074 end loop;
10075
10076 return False;
10077 end In_Parameter_Specification;
10078
10079 --------------------------
10080 -- In_Pragma_Expression --
10081 --------------------------
10082
10083 function In_Pragma_Expression (N : Node_Id; Nam : Name_Id) return Boolean is
10084 P : Node_Id;
10085 begin
10086 P := Parent (N);
10087 loop
10088 if No (P) then
10089 return False;
10090 elsif Nkind (P) = N_Pragma and then Pragma_Name (P) = Nam then
10091 return True;
10092 else
10093 P := Parent (P);
10094 end if;
10095 end loop;
10096 end In_Pragma_Expression;
10097
10098 -------------------------------------
10099 -- In_Reverse_Storage_Order_Object --
10100 -------------------------------------
10101
10102 function In_Reverse_Storage_Order_Object (N : Node_Id) return Boolean is
10103 Pref : Node_Id;
10104 Btyp : Entity_Id := Empty;
10105
10106 begin
10107 -- Climb up indexed components
10108
10109 Pref := N;
10110 loop
10111 case Nkind (Pref) is
10112 when N_Selected_Component =>
10113 Pref := Prefix (Pref);
10114 exit;
10115
10116 when N_Indexed_Component =>
10117 Pref := Prefix (Pref);
10118
10119 when others =>
10120 Pref := Empty;
10121 exit;
10122 end case;
10123 end loop;
10124
10125 if Present (Pref) then
10126 Btyp := Base_Type (Etype (Pref));
10127 end if;
10128
10129 return Present (Btyp)
10130 and then (Is_Record_Type (Btyp) or else Is_Array_Type (Btyp))
10131 and then Reverse_Storage_Order (Btyp);
10132 end In_Reverse_Storage_Order_Object;
10133
10134 --------------------------------------
10135 -- In_Subprogram_Or_Concurrent_Unit --
10136 --------------------------------------
10137
10138 function In_Subprogram_Or_Concurrent_Unit return Boolean is
10139 E : Entity_Id;
10140 K : Entity_Kind;
10141
10142 begin
10143 -- Use scope chain to check successively outer scopes
10144
10145 E := Current_Scope;
10146 loop
10147 K := Ekind (E);
10148
10149 if K in Subprogram_Kind
10150 or else K in Concurrent_Kind
10151 or else K in Generic_Subprogram_Kind
10152 then
10153 return True;
10154
10155 elsif E = Standard_Standard then
10156 return False;
10157 end if;
10158
10159 E := Scope (E);
10160 end loop;
10161 end In_Subprogram_Or_Concurrent_Unit;
10162
10163 ---------------------
10164 -- In_Visible_Part --
10165 ---------------------
10166
10167 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
10168 begin
10169 return Is_Package_Or_Generic_Package (Scope_Id)
10170 and then In_Open_Scopes (Scope_Id)
10171 and then not In_Package_Body (Scope_Id)
10172 and then not In_Private_Part (Scope_Id);
10173 end In_Visible_Part;
10174
10175 --------------------------------
10176 -- Incomplete_Or_Partial_View --
10177 --------------------------------
10178
10179 function Incomplete_Or_Partial_View (Id : Entity_Id) return Entity_Id is
10180 function Inspect_Decls
10181 (Decls : List_Id;
10182 Taft : Boolean := False) return Entity_Id;
10183 -- Check whether a declarative region contains the incomplete or partial
10184 -- view of Id.
10185
10186 -------------------
10187 -- Inspect_Decls --
10188 -------------------
10189
10190 function Inspect_Decls
10191 (Decls : List_Id;
10192 Taft : Boolean := False) return Entity_Id
10193 is
10194 Decl : Node_Id;
10195 Match : Node_Id;
10196
10197 begin
10198 Decl := First (Decls);
10199 while Present (Decl) loop
10200 Match := Empty;
10201
10202 if Taft then
10203 if Nkind (Decl) = N_Incomplete_Type_Declaration then
10204 Match := Defining_Identifier (Decl);
10205 end if;
10206
10207 else
10208 if Nkind_In (Decl, N_Private_Extension_Declaration,
10209 N_Private_Type_Declaration)
10210 then
10211 Match := Defining_Identifier (Decl);
10212 end if;
10213 end if;
10214
10215 if Present (Match)
10216 and then Present (Full_View (Match))
10217 and then Full_View (Match) = Id
10218 then
10219 return Match;
10220 end if;
10221
10222 Next (Decl);
10223 end loop;
10224
10225 return Empty;
10226 end Inspect_Decls;
10227
10228 -- Local variables
10229
10230 Prev : Entity_Id;
10231
10232 -- Start of processing for Incomplete_Or_Partial_View
10233
10234 begin
10235 -- Deferred constant or incomplete type case
10236
10237 Prev := Current_Entity_In_Scope (Id);
10238
10239 if Present (Prev)
10240 and then (Is_Incomplete_Type (Prev) or else Ekind (Prev) = E_Constant)
10241 and then Present (Full_View (Prev))
10242 and then Full_View (Prev) = Id
10243 then
10244 return Prev;
10245 end if;
10246
10247 -- Private or Taft amendment type case
10248
10249 declare
10250 Pkg : constant Entity_Id := Scope (Id);
10251 Pkg_Decl : Node_Id := Pkg;
10252
10253 begin
10254 if Present (Pkg) and then Ekind (Pkg) = E_Package then
10255 while Nkind (Pkg_Decl) /= N_Package_Specification loop
10256 Pkg_Decl := Parent (Pkg_Decl);
10257 end loop;
10258
10259 -- It is knows that Typ has a private view, look for it in the
10260 -- visible declarations of the enclosing scope. A special case
10261 -- of this is when the two views have been exchanged - the full
10262 -- appears earlier than the private.
10263
10264 if Has_Private_Declaration (Id) then
10265 Prev := Inspect_Decls (Visible_Declarations (Pkg_Decl));
10266
10267 -- Exchanged view case, look in the private declarations
10268
10269 if No (Prev) then
10270 Prev := Inspect_Decls (Private_Declarations (Pkg_Decl));
10271 end if;
10272
10273 return Prev;
10274
10275 -- Otherwise if this is the package body, then Typ is a potential
10276 -- Taft amendment type. The incomplete view should be located in
10277 -- the private declarations of the enclosing scope.
10278
10279 elsif In_Package_Body (Pkg) then
10280 return Inspect_Decls (Private_Declarations (Pkg_Decl), True);
10281 end if;
10282 end if;
10283 end;
10284
10285 -- The type has no incomplete or private view
10286
10287 return Empty;
10288 end Incomplete_Or_Partial_View;
10289
10290 -----------------------------------------
10291 -- Inherit_Default_Init_Cond_Procedure --
10292 -----------------------------------------
10293
10294 procedure Inherit_Default_Init_Cond_Procedure (Typ : Entity_Id) is
10295 Par_Typ : constant Entity_Id := Etype (Typ);
10296
10297 begin
10298 -- A derived type inherits the default initial condition procedure of
10299 -- its parent type.
10300
10301 if No (Default_Init_Cond_Procedure (Typ)) then
10302 Set_Default_Init_Cond_Procedure
10303 (Typ, Default_Init_Cond_Procedure (Par_Typ));
10304 end if;
10305 end Inherit_Default_Init_Cond_Procedure;
10306
10307 ----------------------------
10308 -- Inherit_Rep_Item_Chain --
10309 ----------------------------
10310
10311 procedure Inherit_Rep_Item_Chain (Typ : Entity_Id; From_Typ : Entity_Id) is
10312 From_Item : constant Node_Id := First_Rep_Item (From_Typ);
10313 Item : Node_Id := Empty;
10314 Last_Item : Node_Id := Empty;
10315
10316 begin
10317 -- Reach the end of the destination type's chain (if any) and capture
10318 -- the last item.
10319
10320 Item := First_Rep_Item (Typ);
10321 while Present (Item) loop
10322
10323 -- Do not inherit a chain that has been inherited already
10324
10325 if Item = From_Item then
10326 return;
10327 end if;
10328
10329 Last_Item := Item;
10330 Item := Next_Rep_Item (Item);
10331 end loop;
10332
10333 Item := First_Rep_Item (From_Typ);
10334
10335 -- Additional check when both parent and current type have rep.
10336 -- items, to prevent circularities when the derivation completes
10337 -- a private declaration and inherits from both views of the parent.
10338 -- There may be a remaining problem with the proper ordering of
10339 -- attribute specifications and aspects on the chains of the four
10340 -- entities involved. ???
10341
10342 if Present (Item) and then Present (From_Item) then
10343 while Present (Item) loop
10344 if Item = First_Rep_Item (Typ) then
10345 return;
10346 end if;
10347
10348 Item := Next_Rep_Item (Item);
10349 end loop;
10350 end if;
10351
10352 -- When the destination type has a rep item chain, the chain of the
10353 -- source type is appended to it.
10354
10355 if Present (Last_Item) then
10356 Set_Next_Rep_Item (Last_Item, From_Item);
10357
10358 -- Otherwise the destination type directly inherits the rep item chain
10359 -- of the source type (if any).
10360
10361 else
10362 Set_First_Rep_Item (Typ, From_Item);
10363 end if;
10364 end Inherit_Rep_Item_Chain;
10365
10366 ---------------------------------
10367 -- Insert_Explicit_Dereference --
10368 ---------------------------------
10369
10370 procedure Insert_Explicit_Dereference (N : Node_Id) is
10371 New_Prefix : constant Node_Id := Relocate_Node (N);
10372 Ent : Entity_Id := Empty;
10373 Pref : Node_Id;
10374 I : Interp_Index;
10375 It : Interp;
10376 T : Entity_Id;
10377
10378 begin
10379 Save_Interps (N, New_Prefix);
10380
10381 Rewrite (N,
10382 Make_Explicit_Dereference (Sloc (Parent (N)),
10383 Prefix => New_Prefix));
10384
10385 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
10386
10387 if Is_Overloaded (New_Prefix) then
10388
10389 -- The dereference is also overloaded, and its interpretations are
10390 -- the designated types of the interpretations of the original node.
10391
10392 Set_Etype (N, Any_Type);
10393
10394 Get_First_Interp (New_Prefix, I, It);
10395 while Present (It.Nam) loop
10396 T := It.Typ;
10397
10398 if Is_Access_Type (T) then
10399 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
10400 end if;
10401
10402 Get_Next_Interp (I, It);
10403 end loop;
10404
10405 End_Interp_List;
10406
10407 else
10408 -- Prefix is unambiguous: mark the original prefix (which might
10409 -- Come_From_Source) as a reference, since the new (relocated) one
10410 -- won't be taken into account.
10411
10412 if Is_Entity_Name (New_Prefix) then
10413 Ent := Entity (New_Prefix);
10414 Pref := New_Prefix;
10415
10416 -- For a retrieval of a subcomponent of some composite object,
10417 -- retrieve the ultimate entity if there is one.
10418
10419 elsif Nkind_In (New_Prefix, N_Selected_Component,
10420 N_Indexed_Component)
10421 then
10422 Pref := Prefix (New_Prefix);
10423 while Present (Pref)
10424 and then Nkind_In (Pref, N_Selected_Component,
10425 N_Indexed_Component)
10426 loop
10427 Pref := Prefix (Pref);
10428 end loop;
10429
10430 if Present (Pref) and then Is_Entity_Name (Pref) then
10431 Ent := Entity (Pref);
10432 end if;
10433 end if;
10434
10435 -- Place the reference on the entity node
10436
10437 if Present (Ent) then
10438 Generate_Reference (Ent, Pref);
10439 end if;
10440 end if;
10441 end Insert_Explicit_Dereference;
10442
10443 ------------------------------------------
10444 -- Inspect_Deferred_Constant_Completion --
10445 ------------------------------------------
10446
10447 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
10448 Decl : Node_Id;
10449
10450 begin
10451 Decl := First (Decls);
10452 while Present (Decl) loop
10453
10454 -- Deferred constant signature
10455
10456 if Nkind (Decl) = N_Object_Declaration
10457 and then Constant_Present (Decl)
10458 and then No (Expression (Decl))
10459
10460 -- No need to check internally generated constants
10461
10462 and then Comes_From_Source (Decl)
10463
10464 -- The constant is not completed. A full object declaration or a
10465 -- pragma Import complete a deferred constant.
10466
10467 and then not Has_Completion (Defining_Identifier (Decl))
10468 then
10469 Error_Msg_N
10470 ("constant declaration requires initialization expression",
10471 Defining_Identifier (Decl));
10472 end if;
10473
10474 Decl := Next (Decl);
10475 end loop;
10476 end Inspect_Deferred_Constant_Completion;
10477
10478 -----------------------------
10479 -- Install_Generic_Formals --
10480 -----------------------------
10481
10482 procedure Install_Generic_Formals (Subp_Id : Entity_Id) is
10483 E : Entity_Id;
10484
10485 begin
10486 pragma Assert (Is_Generic_Subprogram (Subp_Id));
10487
10488 E := First_Entity (Subp_Id);
10489 while Present (E) loop
10490 Install_Entity (E);
10491 Next_Entity (E);
10492 end loop;
10493 end Install_Generic_Formals;
10494
10495 -----------------------------
10496 -- Is_Actual_Out_Parameter --
10497 -----------------------------
10498
10499 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
10500 Formal : Entity_Id;
10501 Call : Node_Id;
10502 begin
10503 Find_Actual (N, Formal, Call);
10504 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
10505 end Is_Actual_Out_Parameter;
10506
10507 -------------------------
10508 -- Is_Actual_Parameter --
10509 -------------------------
10510
10511 function Is_Actual_Parameter (N : Node_Id) return Boolean is
10512 PK : constant Node_Kind := Nkind (Parent (N));
10513
10514 begin
10515 case PK is
10516 when N_Parameter_Association =>
10517 return N = Explicit_Actual_Parameter (Parent (N));
10518
10519 when N_Subprogram_Call =>
10520 return Is_List_Member (N)
10521 and then
10522 List_Containing (N) = Parameter_Associations (Parent (N));
10523
10524 when others =>
10525 return False;
10526 end case;
10527 end Is_Actual_Parameter;
10528
10529 --------------------------------
10530 -- Is_Actual_Tagged_Parameter --
10531 --------------------------------
10532
10533 function Is_Actual_Tagged_Parameter (N : Node_Id) return Boolean is
10534 Formal : Entity_Id;
10535 Call : Node_Id;
10536 begin
10537 Find_Actual (N, Formal, Call);
10538 return Present (Formal) and then Is_Tagged_Type (Etype (Formal));
10539 end Is_Actual_Tagged_Parameter;
10540
10541 ---------------------
10542 -- Is_Aliased_View --
10543 ---------------------
10544
10545 function Is_Aliased_View (Obj : Node_Id) return Boolean is
10546 E : Entity_Id;
10547
10548 begin
10549 if Is_Entity_Name (Obj) then
10550 E := Entity (Obj);
10551
10552 return
10553 (Is_Object (E)
10554 and then
10555 (Is_Aliased (E)
10556 or else (Present (Renamed_Object (E))
10557 and then Is_Aliased_View (Renamed_Object (E)))))
10558
10559 or else ((Is_Formal (E)
10560 or else Ekind_In (E, E_Generic_In_Out_Parameter,
10561 E_Generic_In_Parameter))
10562 and then Is_Tagged_Type (Etype (E)))
10563
10564 or else (Is_Concurrent_Type (E) and then In_Open_Scopes (E))
10565
10566 -- Current instance of type, either directly or as rewritten
10567 -- reference to the current object.
10568
10569 or else (Is_Entity_Name (Original_Node (Obj))
10570 and then Present (Entity (Original_Node (Obj)))
10571 and then Is_Type (Entity (Original_Node (Obj))))
10572
10573 or else (Is_Type (E) and then E = Current_Scope)
10574
10575 or else (Is_Incomplete_Or_Private_Type (E)
10576 and then Full_View (E) = Current_Scope)
10577
10578 -- Ada 2012 AI05-0053: the return object of an extended return
10579 -- statement is aliased if its type is immutably limited.
10580
10581 or else (Is_Return_Object (E)
10582 and then Is_Limited_View (Etype (E)));
10583
10584 elsif Nkind (Obj) = N_Selected_Component then
10585 return Is_Aliased (Entity (Selector_Name (Obj)));
10586
10587 elsif Nkind (Obj) = N_Indexed_Component then
10588 return Has_Aliased_Components (Etype (Prefix (Obj)))
10589 or else
10590 (Is_Access_Type (Etype (Prefix (Obj)))
10591 and then Has_Aliased_Components
10592 (Designated_Type (Etype (Prefix (Obj)))));
10593
10594 elsif Nkind_In (Obj, N_Unchecked_Type_Conversion, N_Type_Conversion) then
10595 return Is_Tagged_Type (Etype (Obj))
10596 and then Is_Aliased_View (Expression (Obj));
10597
10598 elsif Nkind (Obj) = N_Explicit_Dereference then
10599 return Nkind (Original_Node (Obj)) /= N_Function_Call;
10600
10601 else
10602 return False;
10603 end if;
10604 end Is_Aliased_View;
10605
10606 -------------------------
10607 -- Is_Ancestor_Package --
10608 -------------------------
10609
10610 function Is_Ancestor_Package
10611 (E1 : Entity_Id;
10612 E2 : Entity_Id) return Boolean
10613 is
10614 Par : Entity_Id;
10615
10616 begin
10617 Par := E2;
10618 while Present (Par) and then Par /= Standard_Standard loop
10619 if Par = E1 then
10620 return True;
10621 end if;
10622
10623 Par := Scope (Par);
10624 end loop;
10625
10626 return False;
10627 end Is_Ancestor_Package;
10628
10629 ----------------------
10630 -- Is_Atomic_Object --
10631 ----------------------
10632
10633 function Is_Atomic_Object (N : Node_Id) return Boolean is
10634
10635 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
10636 -- Determines if given object has atomic components
10637
10638 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
10639 -- If prefix is an implicit dereference, examine designated type
10640
10641 ----------------------
10642 -- Is_Atomic_Prefix --
10643 ----------------------
10644
10645 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
10646 begin
10647 if Is_Access_Type (Etype (N)) then
10648 return
10649 Has_Atomic_Components (Designated_Type (Etype (N)));
10650 else
10651 return Object_Has_Atomic_Components (N);
10652 end if;
10653 end Is_Atomic_Prefix;
10654
10655 ----------------------------------
10656 -- Object_Has_Atomic_Components --
10657 ----------------------------------
10658
10659 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
10660 begin
10661 if Has_Atomic_Components (Etype (N))
10662 or else Is_Atomic (Etype (N))
10663 then
10664 return True;
10665
10666 elsif Is_Entity_Name (N)
10667 and then (Has_Atomic_Components (Entity (N))
10668 or else Is_Atomic (Entity (N)))
10669 then
10670 return True;
10671
10672 elsif Nkind (N) = N_Selected_Component
10673 and then Is_Atomic (Entity (Selector_Name (N)))
10674 then
10675 return True;
10676
10677 elsif Nkind (N) = N_Indexed_Component
10678 or else Nkind (N) = N_Selected_Component
10679 then
10680 return Is_Atomic_Prefix (Prefix (N));
10681
10682 else
10683 return False;
10684 end if;
10685 end Object_Has_Atomic_Components;
10686
10687 -- Start of processing for Is_Atomic_Object
10688
10689 begin
10690 -- Predicate is not relevant to subprograms
10691
10692 if Is_Entity_Name (N) and then Is_Overloadable (Entity (N)) then
10693 return False;
10694
10695 elsif Is_Atomic (Etype (N))
10696 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
10697 then
10698 return True;
10699
10700 elsif Nkind (N) = N_Selected_Component
10701 and then Is_Atomic (Entity (Selector_Name (N)))
10702 then
10703 return True;
10704
10705 elsif Nkind (N) = N_Indexed_Component
10706 or else Nkind (N) = N_Selected_Component
10707 then
10708 return Is_Atomic_Prefix (Prefix (N));
10709
10710 else
10711 return False;
10712 end if;
10713 end Is_Atomic_Object;
10714
10715 -----------------------------
10716 -- Is_Atomic_Or_VFA_Object --
10717 -----------------------------
10718
10719 function Is_Atomic_Or_VFA_Object (N : Node_Id) return Boolean is
10720 begin
10721 return Is_Atomic_Object (N)
10722 or else (Is_Object_Reference (N)
10723 and then Is_Entity_Name (N)
10724 and then (Is_Volatile_Full_Access (Entity (N))
10725 or else
10726 Is_Volatile_Full_Access (Etype (Entity (N)))));
10727 end Is_Atomic_Or_VFA_Object;
10728
10729 -------------------------
10730 -- Is_Attribute_Result --
10731 -------------------------
10732
10733 function Is_Attribute_Result (N : Node_Id) return Boolean is
10734 begin
10735 return Nkind (N) = N_Attribute_Reference
10736 and then Attribute_Name (N) = Name_Result;
10737 end Is_Attribute_Result;
10738
10739 -------------------------
10740 -- Is_Attribute_Update --
10741 -------------------------
10742
10743 function Is_Attribute_Update (N : Node_Id) return Boolean is
10744 begin
10745 return Nkind (N) = N_Attribute_Reference
10746 and then Attribute_Name (N) = Name_Update;
10747 end Is_Attribute_Update;
10748
10749 ------------------------------------
10750 -- Is_Body_Or_Package_Declaration --
10751 ------------------------------------
10752
10753 function Is_Body_Or_Package_Declaration (N : Node_Id) return Boolean is
10754 begin
10755 return Nkind_In (N, N_Entry_Body,
10756 N_Package_Body,
10757 N_Package_Declaration,
10758 N_Protected_Body,
10759 N_Subprogram_Body,
10760 N_Task_Body);
10761 end Is_Body_Or_Package_Declaration;
10762
10763 -----------------------
10764 -- Is_Bounded_String --
10765 -----------------------
10766
10767 function Is_Bounded_String (T : Entity_Id) return Boolean is
10768 Under : constant Entity_Id := Underlying_Type (Root_Type (T));
10769
10770 begin
10771 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
10772 -- Super_String, or one of the [Wide_]Wide_ versions. This will
10773 -- be True for all the Bounded_String types in instances of the
10774 -- Generic_Bounded_Length generics, and for types derived from those.
10775
10776 return Present (Under)
10777 and then (Is_RTE (Root_Type (Under), RO_SU_Super_String) or else
10778 Is_RTE (Root_Type (Under), RO_WI_Super_String) or else
10779 Is_RTE (Root_Type (Under), RO_WW_Super_String));
10780 end Is_Bounded_String;
10781
10782 -------------------------
10783 -- Is_Child_Or_Sibling --
10784 -------------------------
10785
10786 function Is_Child_Or_Sibling
10787 (Pack_1 : Entity_Id;
10788 Pack_2 : Entity_Id) return Boolean
10789 is
10790 function Distance_From_Standard (Pack : Entity_Id) return Nat;
10791 -- Given an arbitrary package, return the number of "climbs" necessary
10792 -- to reach scope Standard_Standard.
10793
10794 procedure Equalize_Depths
10795 (Pack : in out Entity_Id;
10796 Depth : in out Nat;
10797 Depth_To_Reach : Nat);
10798 -- Given an arbitrary package, its depth and a target depth to reach,
10799 -- climb the scope chain until the said depth is reached. The pointer
10800 -- to the package and its depth a modified during the climb.
10801
10802 ----------------------------
10803 -- Distance_From_Standard --
10804 ----------------------------
10805
10806 function Distance_From_Standard (Pack : Entity_Id) return Nat is
10807 Dist : Nat;
10808 Scop : Entity_Id;
10809
10810 begin
10811 Dist := 0;
10812 Scop := Pack;
10813 while Present (Scop) and then Scop /= Standard_Standard loop
10814 Dist := Dist + 1;
10815 Scop := Scope (Scop);
10816 end loop;
10817
10818 return Dist;
10819 end Distance_From_Standard;
10820
10821 ---------------------
10822 -- Equalize_Depths --
10823 ---------------------
10824
10825 procedure Equalize_Depths
10826 (Pack : in out Entity_Id;
10827 Depth : in out Nat;
10828 Depth_To_Reach : Nat)
10829 is
10830 begin
10831 -- The package must be at a greater or equal depth
10832
10833 if Depth < Depth_To_Reach then
10834 raise Program_Error;
10835 end if;
10836
10837 -- Climb the scope chain until the desired depth is reached
10838
10839 while Present (Pack) and then Depth /= Depth_To_Reach loop
10840 Pack := Scope (Pack);
10841 Depth := Depth - 1;
10842 end loop;
10843 end Equalize_Depths;
10844
10845 -- Local variables
10846
10847 P_1 : Entity_Id := Pack_1;
10848 P_1_Child : Boolean := False;
10849 P_1_Depth : Nat := Distance_From_Standard (P_1);
10850 P_2 : Entity_Id := Pack_2;
10851 P_2_Child : Boolean := False;
10852 P_2_Depth : Nat := Distance_From_Standard (P_2);
10853
10854 -- Start of processing for Is_Child_Or_Sibling
10855
10856 begin
10857 pragma Assert
10858 (Ekind (Pack_1) = E_Package and then Ekind (Pack_2) = E_Package);
10859
10860 -- Both packages denote the same entity, therefore they cannot be
10861 -- children or siblings.
10862
10863 if P_1 = P_2 then
10864 return False;
10865
10866 -- One of the packages is at a deeper level than the other. Note that
10867 -- both may still come from differen hierarchies.
10868
10869 -- (root) P_2
10870 -- / \ :
10871 -- X P_2 or X
10872 -- : :
10873 -- P_1 P_1
10874
10875 elsif P_1_Depth > P_2_Depth then
10876 Equalize_Depths
10877 (Pack => P_1,
10878 Depth => P_1_Depth,
10879 Depth_To_Reach => P_2_Depth);
10880 P_1_Child := True;
10881
10882 -- (root) P_1
10883 -- / \ :
10884 -- P_1 X or X
10885 -- : :
10886 -- P_2 P_2
10887
10888 elsif P_2_Depth > P_1_Depth then
10889 Equalize_Depths
10890 (Pack => P_2,
10891 Depth => P_2_Depth,
10892 Depth_To_Reach => P_1_Depth);
10893 P_2_Child := True;
10894 end if;
10895
10896 -- At this stage the package pointers have been elevated to the same
10897 -- depth. If the related entities are the same, then one package is a
10898 -- potential child of the other:
10899
10900 -- P_1
10901 -- :
10902 -- X became P_1 P_2 or vica versa
10903 -- :
10904 -- P_2
10905
10906 if P_1 = P_2 then
10907 if P_1_Child then
10908 return Is_Child_Unit (Pack_1);
10909
10910 else pragma Assert (P_2_Child);
10911 return Is_Child_Unit (Pack_2);
10912 end if;
10913
10914 -- The packages may come from the same package chain or from entirely
10915 -- different hierarcies. To determine this, climb the scope stack until
10916 -- a common root is found.
10917
10918 -- (root) (root 1) (root 2)
10919 -- / \ | |
10920 -- P_1 P_2 P_1 P_2
10921
10922 else
10923 while Present (P_1) and then Present (P_2) loop
10924
10925 -- The two packages may be siblings
10926
10927 if P_1 = P_2 then
10928 return Is_Child_Unit (Pack_1) and then Is_Child_Unit (Pack_2);
10929 end if;
10930
10931 P_1 := Scope (P_1);
10932 P_2 := Scope (P_2);
10933 end loop;
10934 end if;
10935
10936 return False;
10937 end Is_Child_Or_Sibling;
10938
10939 -----------------------------
10940 -- Is_Concurrent_Interface --
10941 -----------------------------
10942
10943 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
10944 begin
10945 return Is_Interface (T)
10946 and then
10947 (Is_Protected_Interface (T)
10948 or else Is_Synchronized_Interface (T)
10949 or else Is_Task_Interface (T));
10950 end Is_Concurrent_Interface;
10951
10952 -----------------------
10953 -- Is_Constant_Bound --
10954 -----------------------
10955
10956 function Is_Constant_Bound (Exp : Node_Id) return Boolean is
10957 begin
10958 if Compile_Time_Known_Value (Exp) then
10959 return True;
10960
10961 elsif Is_Entity_Name (Exp) and then Present (Entity (Exp)) then
10962 return Is_Constant_Object (Entity (Exp))
10963 or else Ekind (Entity (Exp)) = E_Enumeration_Literal;
10964
10965 elsif Nkind (Exp) in N_Binary_Op then
10966 return Is_Constant_Bound (Left_Opnd (Exp))
10967 and then Is_Constant_Bound (Right_Opnd (Exp))
10968 and then Scope (Entity (Exp)) = Standard_Standard;
10969
10970 else
10971 return False;
10972 end if;
10973 end Is_Constant_Bound;
10974
10975 ---------------------------
10976 -- Is_Container_Element --
10977 ---------------------------
10978
10979 function Is_Container_Element (Exp : Node_Id) return Boolean is
10980 Loc : constant Source_Ptr := Sloc (Exp);
10981 Pref : constant Node_Id := Prefix (Exp);
10982
10983 Call : Node_Id;
10984 -- Call to an indexing aspect
10985
10986 Cont_Typ : Entity_Id;
10987 -- The type of the container being accessed
10988
10989 Elem_Typ : Entity_Id;
10990 -- Its element type
10991
10992 Indexing : Entity_Id;
10993 Is_Const : Boolean;
10994 -- Indicates that constant indexing is used, and the element is thus
10995 -- a constant.
10996
10997 Ref_Typ : Entity_Id;
10998 -- The reference type returned by the indexing operation
10999
11000 begin
11001 -- If C is a container, in a context that imposes the element type of
11002 -- that container, the indexing notation C (X) is rewritten as:
11003
11004 -- Indexing (C, X).Discr.all
11005
11006 -- where Indexing is one of the indexing aspects of the container.
11007 -- If the context does not require a reference, the construct can be
11008 -- rewritten as
11009
11010 -- Element (C, X)
11011
11012 -- First, verify that the construct has the proper form
11013
11014 if not Expander_Active then
11015 return False;
11016
11017 elsif Nkind (Pref) /= N_Selected_Component then
11018 return False;
11019
11020 elsif Nkind (Prefix (Pref)) /= N_Function_Call then
11021 return False;
11022
11023 else
11024 Call := Prefix (Pref);
11025 Ref_Typ := Etype (Call);
11026 end if;
11027
11028 if not Has_Implicit_Dereference (Ref_Typ)
11029 or else No (First (Parameter_Associations (Call)))
11030 or else not Is_Entity_Name (Name (Call))
11031 then
11032 return False;
11033 end if;
11034
11035 -- Retrieve type of container object, and its iterator aspects
11036
11037 Cont_Typ := Etype (First (Parameter_Associations (Call)));
11038 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Constant_Indexing);
11039 Is_Const := False;
11040
11041 if No (Indexing) then
11042
11043 -- Container should have at least one indexing operation
11044
11045 return False;
11046
11047 elsif Entity (Name (Call)) /= Entity (Indexing) then
11048
11049 -- This may be a variable indexing operation
11050
11051 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Variable_Indexing);
11052
11053 if No (Indexing)
11054 or else Entity (Name (Call)) /= Entity (Indexing)
11055 then
11056 return False;
11057 end if;
11058
11059 else
11060 Is_Const := True;
11061 end if;
11062
11063 Elem_Typ := Find_Value_Of_Aspect (Cont_Typ, Aspect_Iterator_Element);
11064
11065 if No (Elem_Typ) or else Entity (Elem_Typ) /= Etype (Exp) then
11066 return False;
11067 end if;
11068
11069 -- Check that the expression is not the target of an assignment, in
11070 -- which case the rewriting is not possible.
11071
11072 if not Is_Const then
11073 declare
11074 Par : Node_Id;
11075
11076 begin
11077 Par := Exp;
11078 while Present (Par)
11079 loop
11080 if Nkind (Parent (Par)) = N_Assignment_Statement
11081 and then Par = Name (Parent (Par))
11082 then
11083 return False;
11084
11085 -- A renaming produces a reference, and the transformation
11086 -- does not apply.
11087
11088 elsif Nkind (Parent (Par)) = N_Object_Renaming_Declaration then
11089 return False;
11090
11091 elsif Nkind_In
11092 (Nkind (Parent (Par)), N_Function_Call,
11093 N_Procedure_Call_Statement,
11094 N_Entry_Call_Statement)
11095 then
11096 -- Check that the element is not part of an actual for an
11097 -- in-out parameter.
11098
11099 declare
11100 F : Entity_Id;
11101 A : Node_Id;
11102
11103 begin
11104 F := First_Formal (Entity (Name (Parent (Par))));
11105 A := First (Parameter_Associations (Parent (Par)));
11106 while Present (F) loop
11107 if A = Par and then Ekind (F) /= E_In_Parameter then
11108 return False;
11109 end if;
11110
11111 Next_Formal (F);
11112 Next (A);
11113 end loop;
11114 end;
11115
11116 -- E_In_Parameter in a call: element is not modified.
11117
11118 exit;
11119 end if;
11120
11121 Par := Parent (Par);
11122 end loop;
11123 end;
11124 end if;
11125
11126 -- The expression has the proper form and the context requires the
11127 -- element type. Retrieve the Element function of the container and
11128 -- rewrite the construct as a call to it.
11129
11130 declare
11131 Op : Elmt_Id;
11132
11133 begin
11134 Op := First_Elmt (Primitive_Operations (Cont_Typ));
11135 while Present (Op) loop
11136 exit when Chars (Node (Op)) = Name_Element;
11137 Next_Elmt (Op);
11138 end loop;
11139
11140 if No (Op) then
11141 return False;
11142
11143 else
11144 Rewrite (Exp,
11145 Make_Function_Call (Loc,
11146 Name => New_Occurrence_Of (Node (Op), Loc),
11147 Parameter_Associations => Parameter_Associations (Call)));
11148 Analyze_And_Resolve (Exp, Entity (Elem_Typ));
11149 return True;
11150 end if;
11151 end;
11152 end Is_Container_Element;
11153
11154 ----------------------------
11155 -- Is_Contract_Annotation --
11156 ----------------------------
11157
11158 function Is_Contract_Annotation (Item : Node_Id) return Boolean is
11159 begin
11160 return Is_Package_Contract_Annotation (Item)
11161 or else
11162 Is_Subprogram_Contract_Annotation (Item);
11163 end Is_Contract_Annotation;
11164
11165 --------------------------------------
11166 -- Is_Controlling_Limited_Procedure --
11167 --------------------------------------
11168
11169 function Is_Controlling_Limited_Procedure
11170 (Proc_Nam : Entity_Id) return Boolean
11171 is
11172 Param_Typ : Entity_Id := Empty;
11173
11174 begin
11175 if Ekind (Proc_Nam) = E_Procedure
11176 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
11177 then
11178 Param_Typ := Etype (Parameter_Type (First (
11179 Parameter_Specifications (Parent (Proc_Nam)))));
11180
11181 -- In this case where an Itype was created, the procedure call has been
11182 -- rewritten.
11183
11184 elsif Present (Associated_Node_For_Itype (Proc_Nam))
11185 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
11186 and then
11187 Present (Parameter_Associations
11188 (Associated_Node_For_Itype (Proc_Nam)))
11189 then
11190 Param_Typ :=
11191 Etype (First (Parameter_Associations
11192 (Associated_Node_For_Itype (Proc_Nam))));
11193 end if;
11194
11195 if Present (Param_Typ) then
11196 return
11197 Is_Interface (Param_Typ)
11198 and then Is_Limited_Record (Param_Typ);
11199 end if;
11200
11201 return False;
11202 end Is_Controlling_Limited_Procedure;
11203
11204 -----------------------------
11205 -- Is_CPP_Constructor_Call --
11206 -----------------------------
11207
11208 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
11209 begin
11210 return Nkind (N) = N_Function_Call
11211 and then Is_CPP_Class (Etype (Etype (N)))
11212 and then Is_Constructor (Entity (Name (N)))
11213 and then Is_Imported (Entity (Name (N)));
11214 end Is_CPP_Constructor_Call;
11215
11216 -------------------------
11217 -- Is_Current_Instance --
11218 -------------------------
11219
11220 function Is_Current_Instance (N : Node_Id) return Boolean is
11221 Typ : constant Entity_Id := Entity (N);
11222 P : Node_Id;
11223
11224 begin
11225 -- Simplest case: entity is a concurrent type and we are currently
11226 -- inside the body. This will eventually be expanded into a
11227 -- call to Self (for tasks) or _object (for protected objects).
11228
11229 if Is_Concurrent_Type (Typ) and then In_Open_Scopes (Typ) then
11230 return True;
11231
11232 else
11233 -- Check whether the context is a (sub)type declaration for the
11234 -- type entity.
11235
11236 P := Parent (N);
11237 while Present (P) loop
11238 if Nkind_In (P, N_Full_Type_Declaration,
11239 N_Private_Type_Declaration,
11240 N_Subtype_Declaration)
11241 and then Comes_From_Source (P)
11242 and then Defining_Entity (P) = Typ
11243 then
11244 return True;
11245 end if;
11246
11247 P := Parent (P);
11248 end loop;
11249 end if;
11250
11251 -- In any other context this is not a current occurrence
11252
11253 return False;
11254 end Is_Current_Instance;
11255
11256 --------------------
11257 -- Is_Declaration --
11258 --------------------
11259
11260 function Is_Declaration (N : Node_Id) return Boolean is
11261 begin
11262 case Nkind (N) is
11263 when N_Abstract_Subprogram_Declaration |
11264 N_Exception_Declaration |
11265 N_Exception_Renaming_Declaration |
11266 N_Full_Type_Declaration |
11267 N_Generic_Function_Renaming_Declaration |
11268 N_Generic_Package_Declaration |
11269 N_Generic_Package_Renaming_Declaration |
11270 N_Generic_Procedure_Renaming_Declaration |
11271 N_Generic_Subprogram_Declaration |
11272 N_Number_Declaration |
11273 N_Object_Declaration |
11274 N_Object_Renaming_Declaration |
11275 N_Package_Declaration |
11276 N_Package_Renaming_Declaration |
11277 N_Private_Extension_Declaration |
11278 N_Private_Type_Declaration |
11279 N_Subprogram_Declaration |
11280 N_Subprogram_Renaming_Declaration |
11281 N_Subtype_Declaration =>
11282 return True;
11283
11284 when others =>
11285 return False;
11286 end case;
11287 end Is_Declaration;
11288
11289 --------------------------------
11290 -- Is_Declared_Within_Variant --
11291 --------------------------------
11292
11293 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
11294 Comp_Decl : constant Node_Id := Parent (Comp);
11295 Comp_List : constant Node_Id := Parent (Comp_Decl);
11296 begin
11297 return Nkind (Parent (Comp_List)) = N_Variant;
11298 end Is_Declared_Within_Variant;
11299
11300 ----------------------------------------------
11301 -- Is_Dependent_Component_Of_Mutable_Object --
11302 ----------------------------------------------
11303
11304 function Is_Dependent_Component_Of_Mutable_Object
11305 (Object : Node_Id) return Boolean
11306 is
11307 P : Node_Id;
11308 Prefix_Type : Entity_Id;
11309 P_Aliased : Boolean := False;
11310 Comp : Entity_Id;
11311
11312 Deref : Node_Id := Object;
11313 -- Dereference node, in something like X.all.Y(2)
11314
11315 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
11316
11317 begin
11318 -- Find the dereference node if any
11319
11320 while Nkind_In (Deref, N_Indexed_Component,
11321 N_Selected_Component,
11322 N_Slice)
11323 loop
11324 Deref := Prefix (Deref);
11325 end loop;
11326
11327 -- Ada 2005: If we have a component or slice of a dereference,
11328 -- something like X.all.Y (2), and the type of X is access-to-constant,
11329 -- Is_Variable will return False, because it is indeed a constant
11330 -- view. But it might be a view of a variable object, so we want the
11331 -- following condition to be True in that case.
11332
11333 if Is_Variable (Object)
11334 or else (Ada_Version >= Ada_2005
11335 and then Nkind (Deref) = N_Explicit_Dereference)
11336 then
11337 if Nkind (Object) = N_Selected_Component then
11338 P := Prefix (Object);
11339 Prefix_Type := Etype (P);
11340
11341 if Is_Entity_Name (P) then
11342 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
11343 Prefix_Type := Base_Type (Prefix_Type);
11344 end if;
11345
11346 if Is_Aliased (Entity (P)) then
11347 P_Aliased := True;
11348 end if;
11349
11350 -- A discriminant check on a selected component may be expanded
11351 -- into a dereference when removing side-effects. Recover the
11352 -- original node and its type, which may be unconstrained.
11353
11354 elsif Nkind (P) = N_Explicit_Dereference
11355 and then not (Comes_From_Source (P))
11356 then
11357 P := Original_Node (P);
11358 Prefix_Type := Etype (P);
11359
11360 else
11361 -- Check for prefix being an aliased component???
11362
11363 null;
11364
11365 end if;
11366
11367 -- A heap object is constrained by its initial value
11368
11369 -- Ada 2005 (AI-363): Always assume the object could be mutable in
11370 -- the dereferenced case, since the access value might denote an
11371 -- unconstrained aliased object, whereas in Ada 95 the designated
11372 -- object is guaranteed to be constrained. A worst-case assumption
11373 -- has to apply in Ada 2005 because we can't tell at compile
11374 -- time whether the object is "constrained by its initial value"
11375 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are semantic
11376 -- rules (these rules are acknowledged to need fixing).
11377
11378 if Ada_Version < Ada_2005 then
11379 if Is_Access_Type (Prefix_Type)
11380 or else Nkind (P) = N_Explicit_Dereference
11381 then
11382 return False;
11383 end if;
11384
11385 else pragma Assert (Ada_Version >= Ada_2005);
11386 if Is_Access_Type (Prefix_Type) then
11387
11388 -- If the access type is pool-specific, and there is no
11389 -- constrained partial view of the designated type, then the
11390 -- designated object is known to be constrained.
11391
11392 if Ekind (Prefix_Type) = E_Access_Type
11393 and then not Object_Type_Has_Constrained_Partial_View
11394 (Typ => Designated_Type (Prefix_Type),
11395 Scop => Current_Scope)
11396 then
11397 return False;
11398
11399 -- Otherwise (general access type, or there is a constrained
11400 -- partial view of the designated type), we need to check
11401 -- based on the designated type.
11402
11403 else
11404 Prefix_Type := Designated_Type (Prefix_Type);
11405 end if;
11406 end if;
11407 end if;
11408
11409 Comp :=
11410 Original_Record_Component (Entity (Selector_Name (Object)));
11411
11412 -- As per AI-0017, the renaming is illegal in a generic body, even
11413 -- if the subtype is indefinite.
11414
11415 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
11416
11417 if not Is_Constrained (Prefix_Type)
11418 and then (Is_Definite_Subtype (Prefix_Type)
11419 or else
11420 (Is_Generic_Type (Prefix_Type)
11421 and then Ekind (Current_Scope) = E_Generic_Package
11422 and then In_Package_Body (Current_Scope)))
11423
11424 and then (Is_Declared_Within_Variant (Comp)
11425 or else Has_Discriminant_Dependent_Constraint (Comp))
11426 and then (not P_Aliased or else Ada_Version >= Ada_2005)
11427 then
11428 return True;
11429
11430 -- If the prefix is of an access type at this point, then we want
11431 -- to return False, rather than calling this function recursively
11432 -- on the access object (which itself might be a discriminant-
11433 -- dependent component of some other object, but that isn't
11434 -- relevant to checking the object passed to us). This avoids
11435 -- issuing wrong errors when compiling with -gnatc, where there
11436 -- can be implicit dereferences that have not been expanded.
11437
11438 elsif Is_Access_Type (Etype (Prefix (Object))) then
11439 return False;
11440
11441 else
11442 return
11443 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
11444 end if;
11445
11446 elsif Nkind (Object) = N_Indexed_Component
11447 or else Nkind (Object) = N_Slice
11448 then
11449 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
11450
11451 -- A type conversion that Is_Variable is a view conversion:
11452 -- go back to the denoted object.
11453
11454 elsif Nkind (Object) = N_Type_Conversion then
11455 return
11456 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
11457 end if;
11458 end if;
11459
11460 return False;
11461 end Is_Dependent_Component_Of_Mutable_Object;
11462
11463 ---------------------
11464 -- Is_Dereferenced --
11465 ---------------------
11466
11467 function Is_Dereferenced (N : Node_Id) return Boolean is
11468 P : constant Node_Id := Parent (N);
11469 begin
11470 return Nkind_In (P, N_Selected_Component,
11471 N_Explicit_Dereference,
11472 N_Indexed_Component,
11473 N_Slice)
11474 and then Prefix (P) = N;
11475 end Is_Dereferenced;
11476
11477 ----------------------
11478 -- Is_Descendent_Of --
11479 ----------------------
11480
11481 function Is_Descendent_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
11482 T : Entity_Id;
11483 Etyp : Entity_Id;
11484
11485 begin
11486 pragma Assert (Nkind (T1) in N_Entity);
11487 pragma Assert (Nkind (T2) in N_Entity);
11488
11489 T := Base_Type (T1);
11490
11491 -- Immediate return if the types match
11492
11493 if T = T2 then
11494 return True;
11495
11496 -- Comment needed here ???
11497
11498 elsif Ekind (T) = E_Class_Wide_Type then
11499 return Etype (T) = T2;
11500
11501 -- All other cases
11502
11503 else
11504 loop
11505 Etyp := Etype (T);
11506
11507 -- Done if we found the type we are looking for
11508
11509 if Etyp = T2 then
11510 return True;
11511
11512 -- Done if no more derivations to check
11513
11514 elsif T = T1
11515 or else T = Etyp
11516 then
11517 return False;
11518
11519 -- Following test catches error cases resulting from prev errors
11520
11521 elsif No (Etyp) then
11522 return False;
11523
11524 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
11525 return False;
11526
11527 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
11528 return False;
11529 end if;
11530
11531 T := Base_Type (Etyp);
11532 end loop;
11533 end if;
11534 end Is_Descendent_Of;
11535
11536 ----------------------------------------
11537 -- Is_Descendant_Of_Suspension_Object --
11538 ----------------------------------------
11539
11540 function Is_Descendant_Of_Suspension_Object
11541 (Typ : Entity_Id) return Boolean
11542 is
11543 Cur_Typ : Entity_Id;
11544 Par_Typ : Entity_Id;
11545
11546 begin
11547 -- Climb the type derivation chain checking each parent type against
11548 -- Suspension_Object.
11549
11550 Cur_Typ := Base_Type (Typ);
11551 while Present (Cur_Typ) loop
11552 Par_Typ := Etype (Cur_Typ);
11553
11554 -- The current type is a match
11555
11556 if Is_Suspension_Object (Cur_Typ) then
11557 return True;
11558
11559 -- Stop the traversal once the root of the derivation chain has been
11560 -- reached. In that case the current type is its own base type.
11561
11562 elsif Cur_Typ = Par_Typ then
11563 exit;
11564 end if;
11565
11566 Cur_Typ := Base_Type (Par_Typ);
11567 end loop;
11568
11569 return False;
11570 end Is_Descendant_Of_Suspension_Object;
11571
11572 ---------------------------------------------
11573 -- Is_Double_Precision_Floating_Point_Type --
11574 ---------------------------------------------
11575
11576 function Is_Double_Precision_Floating_Point_Type
11577 (E : Entity_Id) return Boolean is
11578 begin
11579 return Is_Floating_Point_Type (E)
11580 and then Machine_Radix_Value (E) = Uint_2
11581 and then Machine_Mantissa_Value (E) = UI_From_Int (53)
11582 and then Machine_Emax_Value (E) = Uint_2 ** Uint_10
11583 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_10);
11584 end Is_Double_Precision_Floating_Point_Type;
11585
11586 -----------------------------
11587 -- Is_Effectively_Volatile --
11588 -----------------------------
11589
11590 function Is_Effectively_Volatile (Id : Entity_Id) return Boolean is
11591 begin
11592 if Is_Type (Id) then
11593
11594 -- An arbitrary type is effectively volatile when it is subject to
11595 -- pragma Atomic or Volatile.
11596
11597 if Is_Volatile (Id) then
11598 return True;
11599
11600 -- An array type is effectively volatile when it is subject to pragma
11601 -- Atomic_Components or Volatile_Components or its compolent type is
11602 -- effectively volatile.
11603
11604 elsif Is_Array_Type (Id) then
11605 return
11606 Has_Volatile_Components (Id)
11607 or else
11608 Is_Effectively_Volatile (Component_Type (Base_Type (Id)));
11609
11610 -- A protected type is always volatile
11611
11612 elsif Is_Protected_Type (Id) then
11613 return True;
11614
11615 -- A descendant of Ada.Synchronous_Task_Control.Suspension_Object is
11616 -- automatically volatile.
11617
11618 elsif Is_Descendant_Of_Suspension_Object (Id) then
11619 return True;
11620
11621 -- Otherwise the type is not effectively volatile
11622
11623 else
11624 return False;
11625 end if;
11626
11627 -- Otherwise Id denotes an object
11628
11629 else
11630 return
11631 Is_Volatile (Id)
11632 or else Has_Volatile_Components (Id)
11633 or else Is_Effectively_Volatile (Etype (Id));
11634 end if;
11635 end Is_Effectively_Volatile;
11636
11637 ------------------------------------
11638 -- Is_Effectively_Volatile_Object --
11639 ------------------------------------
11640
11641 function Is_Effectively_Volatile_Object (N : Node_Id) return Boolean is
11642 begin
11643 if Is_Entity_Name (N) then
11644 return Is_Effectively_Volatile (Entity (N));
11645
11646 elsif Nkind (N) = N_Expanded_Name then
11647 return Is_Effectively_Volatile (Entity (N));
11648
11649 elsif Nkind (N) = N_Indexed_Component then
11650 return Is_Effectively_Volatile_Object (Prefix (N));
11651
11652 elsif Nkind (N) = N_Selected_Component then
11653 return
11654 Is_Effectively_Volatile_Object (Prefix (N))
11655 or else
11656 Is_Effectively_Volatile_Object (Selector_Name (N));
11657
11658 else
11659 return False;
11660 end if;
11661 end Is_Effectively_Volatile_Object;
11662
11663 -------------------
11664 -- Is_Entry_Body --
11665 -------------------
11666
11667 function Is_Entry_Body (Id : Entity_Id) return Boolean is
11668 begin
11669 return
11670 Ekind_In (Id, E_Entry, E_Entry_Family)
11671 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Body;
11672 end Is_Entry_Body;
11673
11674 --------------------------
11675 -- Is_Entry_Declaration --
11676 --------------------------
11677
11678 function Is_Entry_Declaration (Id : Entity_Id) return Boolean is
11679 begin
11680 return
11681 Ekind_In (Id, E_Entry, E_Entry_Family)
11682 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Declaration;
11683 end Is_Entry_Declaration;
11684
11685 ----------------------------
11686 -- Is_Expression_Function --
11687 ----------------------------
11688
11689 function Is_Expression_Function (Subp : Entity_Id) return Boolean is
11690 begin
11691 if Ekind_In (Subp, E_Function, E_Subprogram_Body) then
11692 return
11693 Nkind (Original_Node (Unit_Declaration_Node (Subp))) =
11694 N_Expression_Function;
11695 else
11696 return False;
11697 end if;
11698 end Is_Expression_Function;
11699
11700 ------------------------------------------
11701 -- Is_Expression_Function_Or_Completion --
11702 ------------------------------------------
11703
11704 function Is_Expression_Function_Or_Completion
11705 (Subp : Entity_Id) return Boolean
11706 is
11707 Subp_Decl : Node_Id;
11708
11709 begin
11710 if Ekind (Subp) = E_Function then
11711 Subp_Decl := Unit_Declaration_Node (Subp);
11712
11713 -- The function declaration is either an expression function or is
11714 -- completed by an expression function body.
11715
11716 return
11717 Is_Expression_Function (Subp)
11718 or else (Nkind (Subp_Decl) = N_Subprogram_Declaration
11719 and then Present (Corresponding_Body (Subp_Decl))
11720 and then Is_Expression_Function
11721 (Corresponding_Body (Subp_Decl)));
11722
11723 elsif Ekind (Subp) = E_Subprogram_Body then
11724 return Is_Expression_Function (Subp);
11725
11726 else
11727 return False;
11728 end if;
11729 end Is_Expression_Function_Or_Completion;
11730
11731 -----------------------
11732 -- Is_EVF_Expression --
11733 -----------------------
11734
11735 function Is_EVF_Expression (N : Node_Id) return Boolean is
11736 Orig_N : constant Node_Id := Original_Node (N);
11737 Alt : Node_Id;
11738 Expr : Node_Id;
11739 Id : Entity_Id;
11740
11741 begin
11742 -- Detect a reference to a formal parameter of a specific tagged type
11743 -- whose related subprogram is subject to pragma Expresions_Visible with
11744 -- value "False".
11745
11746 if Is_Entity_Name (N) and then Present (Entity (N)) then
11747 Id := Entity (N);
11748
11749 return
11750 Is_Formal (Id)
11751 and then Is_Specific_Tagged_Type (Etype (Id))
11752 and then Extensions_Visible_Status (Id) =
11753 Extensions_Visible_False;
11754
11755 -- A case expression is an EVF expression when it contains at least one
11756 -- EVF dependent_expression. Note that a case expression may have been
11757 -- expanded, hence the use of Original_Node.
11758
11759 elsif Nkind (Orig_N) = N_Case_Expression then
11760 Alt := First (Alternatives (Orig_N));
11761 while Present (Alt) loop
11762 if Is_EVF_Expression (Expression (Alt)) then
11763 return True;
11764 end if;
11765
11766 Next (Alt);
11767 end loop;
11768
11769 -- An if expression is an EVF expression when it contains at least one
11770 -- EVF dependent_expression. Note that an if expression may have been
11771 -- expanded, hence the use of Original_Node.
11772
11773 elsif Nkind (Orig_N) = N_If_Expression then
11774 Expr := Next (First (Expressions (Orig_N)));
11775 while Present (Expr) loop
11776 if Is_EVF_Expression (Expr) then
11777 return True;
11778 end if;
11779
11780 Next (Expr);
11781 end loop;
11782
11783 -- A qualified expression or a type conversion is an EVF expression when
11784 -- its operand is an EVF expression.
11785
11786 elsif Nkind_In (N, N_Qualified_Expression,
11787 N_Unchecked_Type_Conversion,
11788 N_Type_Conversion)
11789 then
11790 return Is_EVF_Expression (Expression (N));
11791
11792 -- Attributes 'Loop_Entry, 'Old, and 'Update are EVF expressions when
11793 -- their prefix denotes an EVF expression.
11794
11795 elsif Nkind (N) = N_Attribute_Reference
11796 and then Nam_In (Attribute_Name (N), Name_Loop_Entry,
11797 Name_Old,
11798 Name_Update)
11799 then
11800 return Is_EVF_Expression (Prefix (N));
11801 end if;
11802
11803 return False;
11804 end Is_EVF_Expression;
11805
11806 --------------
11807 -- Is_False --
11808 --------------
11809
11810 function Is_False (U : Uint) return Boolean is
11811 begin
11812 return (U = 0);
11813 end Is_False;
11814
11815 ---------------------------
11816 -- Is_Fixed_Model_Number --
11817 ---------------------------
11818
11819 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
11820 S : constant Ureal := Small_Value (T);
11821 M : Urealp.Save_Mark;
11822 R : Boolean;
11823 begin
11824 M := Urealp.Mark;
11825 R := (U = UR_Trunc (U / S) * S);
11826 Urealp.Release (M);
11827 return R;
11828 end Is_Fixed_Model_Number;
11829
11830 -------------------------------
11831 -- Is_Fully_Initialized_Type --
11832 -------------------------------
11833
11834 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
11835 begin
11836 -- Scalar types
11837
11838 if Is_Scalar_Type (Typ) then
11839
11840 -- A scalar type with an aspect Default_Value is fully initialized
11841
11842 -- Note: Iniitalize/Normalize_Scalars also ensure full initialization
11843 -- of a scalar type, but we don't take that into account here, since
11844 -- we don't want these to affect warnings.
11845
11846 return Has_Default_Aspect (Typ);
11847
11848 elsif Is_Access_Type (Typ) then
11849 return True;
11850
11851 elsif Is_Array_Type (Typ) then
11852 if Is_Fully_Initialized_Type (Component_Type (Typ))
11853 or else (Ada_Version >= Ada_2012 and then Has_Default_Aspect (Typ))
11854 then
11855 return True;
11856 end if;
11857
11858 -- An interesting case, if we have a constrained type one of whose
11859 -- bounds is known to be null, then there are no elements to be
11860 -- initialized, so all the elements are initialized.
11861
11862 if Is_Constrained (Typ) then
11863 declare
11864 Indx : Node_Id;
11865 Indx_Typ : Entity_Id;
11866 Lbd, Hbd : Node_Id;
11867
11868 begin
11869 Indx := First_Index (Typ);
11870 while Present (Indx) loop
11871 if Etype (Indx) = Any_Type then
11872 return False;
11873
11874 -- If index is a range, use directly
11875
11876 elsif Nkind (Indx) = N_Range then
11877 Lbd := Low_Bound (Indx);
11878 Hbd := High_Bound (Indx);
11879
11880 else
11881 Indx_Typ := Etype (Indx);
11882
11883 if Is_Private_Type (Indx_Typ) then
11884 Indx_Typ := Full_View (Indx_Typ);
11885 end if;
11886
11887 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
11888 return False;
11889 else
11890 Lbd := Type_Low_Bound (Indx_Typ);
11891 Hbd := Type_High_Bound (Indx_Typ);
11892 end if;
11893 end if;
11894
11895 if Compile_Time_Known_Value (Lbd)
11896 and then
11897 Compile_Time_Known_Value (Hbd)
11898 then
11899 if Expr_Value (Hbd) < Expr_Value (Lbd) then
11900 return True;
11901 end if;
11902 end if;
11903
11904 Next_Index (Indx);
11905 end loop;
11906 end;
11907 end if;
11908
11909 -- If no null indexes, then type is not fully initialized
11910
11911 return False;
11912
11913 -- Record types
11914
11915 elsif Is_Record_Type (Typ) then
11916 if Has_Discriminants (Typ)
11917 and then
11918 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
11919 and then Is_Fully_Initialized_Variant (Typ)
11920 then
11921 return True;
11922 end if;
11923
11924 -- We consider bounded string types to be fully initialized, because
11925 -- otherwise we get false alarms when the Data component is not
11926 -- default-initialized.
11927
11928 if Is_Bounded_String (Typ) then
11929 return True;
11930 end if;
11931
11932 -- Controlled records are considered to be fully initialized if
11933 -- there is a user defined Initialize routine. This may not be
11934 -- entirely correct, but as the spec notes, we are guessing here
11935 -- what is best from the point of view of issuing warnings.
11936
11937 if Is_Controlled (Typ) then
11938 declare
11939 Utyp : constant Entity_Id := Underlying_Type (Typ);
11940
11941 begin
11942 if Present (Utyp) then
11943 declare
11944 Init : constant Entity_Id :=
11945 (Find_Optional_Prim_Op
11946 (Underlying_Type (Typ), Name_Initialize));
11947
11948 begin
11949 if Present (Init)
11950 and then Comes_From_Source (Init)
11951 and then not
11952 Is_Predefined_File_Name
11953 (File_Name (Get_Source_File_Index (Sloc (Init))))
11954 then
11955 return True;
11956
11957 elsif Has_Null_Extension (Typ)
11958 and then
11959 Is_Fully_Initialized_Type
11960 (Etype (Base_Type (Typ)))
11961 then
11962 return True;
11963 end if;
11964 end;
11965 end if;
11966 end;
11967 end if;
11968
11969 -- Otherwise see if all record components are initialized
11970
11971 declare
11972 Ent : Entity_Id;
11973
11974 begin
11975 Ent := First_Entity (Typ);
11976 while Present (Ent) loop
11977 if Ekind (Ent) = E_Component
11978 and then (No (Parent (Ent))
11979 or else No (Expression (Parent (Ent))))
11980 and then not Is_Fully_Initialized_Type (Etype (Ent))
11981
11982 -- Special VM case for tag components, which need to be
11983 -- defined in this case, but are never initialized as VMs
11984 -- are using other dispatching mechanisms. Ignore this
11985 -- uninitialized case. Note that this applies both to the
11986 -- uTag entry and the main vtable pointer (CPP_Class case).
11987
11988 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
11989 then
11990 return False;
11991 end if;
11992
11993 Next_Entity (Ent);
11994 end loop;
11995 end;
11996
11997 -- No uninitialized components, so type is fully initialized.
11998 -- Note that this catches the case of no components as well.
11999
12000 return True;
12001
12002 elsif Is_Concurrent_Type (Typ) then
12003 return True;
12004
12005 elsif Is_Private_Type (Typ) then
12006 declare
12007 U : constant Entity_Id := Underlying_Type (Typ);
12008
12009 begin
12010 if No (U) then
12011 return False;
12012 else
12013 return Is_Fully_Initialized_Type (U);
12014 end if;
12015 end;
12016
12017 else
12018 return False;
12019 end if;
12020 end Is_Fully_Initialized_Type;
12021
12022 ----------------------------------
12023 -- Is_Fully_Initialized_Variant --
12024 ----------------------------------
12025
12026 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
12027 Loc : constant Source_Ptr := Sloc (Typ);
12028 Constraints : constant List_Id := New_List;
12029 Components : constant Elist_Id := New_Elmt_List;
12030 Comp_Elmt : Elmt_Id;
12031 Comp_Id : Node_Id;
12032 Comp_List : Node_Id;
12033 Discr : Entity_Id;
12034 Discr_Val : Node_Id;
12035
12036 Report_Errors : Boolean;
12037 pragma Warnings (Off, Report_Errors);
12038
12039 begin
12040 if Serious_Errors_Detected > 0 then
12041 return False;
12042 end if;
12043
12044 if Is_Record_Type (Typ)
12045 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
12046 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
12047 then
12048 Comp_List := Component_List (Type_Definition (Parent (Typ)));
12049
12050 Discr := First_Discriminant (Typ);
12051 while Present (Discr) loop
12052 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
12053 Discr_Val := Expression (Parent (Discr));
12054
12055 if Present (Discr_Val)
12056 and then Is_OK_Static_Expression (Discr_Val)
12057 then
12058 Append_To (Constraints,
12059 Make_Component_Association (Loc,
12060 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
12061 Expression => New_Copy (Discr_Val)));
12062 else
12063 return False;
12064 end if;
12065 else
12066 return False;
12067 end if;
12068
12069 Next_Discriminant (Discr);
12070 end loop;
12071
12072 Gather_Components
12073 (Typ => Typ,
12074 Comp_List => Comp_List,
12075 Governed_By => Constraints,
12076 Into => Components,
12077 Report_Errors => Report_Errors);
12078
12079 -- Check that each component present is fully initialized
12080
12081 Comp_Elmt := First_Elmt (Components);
12082 while Present (Comp_Elmt) loop
12083 Comp_Id := Node (Comp_Elmt);
12084
12085 if Ekind (Comp_Id) = E_Component
12086 and then (No (Parent (Comp_Id))
12087 or else No (Expression (Parent (Comp_Id))))
12088 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
12089 then
12090 return False;
12091 end if;
12092
12093 Next_Elmt (Comp_Elmt);
12094 end loop;
12095
12096 return True;
12097
12098 elsif Is_Private_Type (Typ) then
12099 declare
12100 U : constant Entity_Id := Underlying_Type (Typ);
12101
12102 begin
12103 if No (U) then
12104 return False;
12105 else
12106 return Is_Fully_Initialized_Variant (U);
12107 end if;
12108 end;
12109
12110 else
12111 return False;
12112 end if;
12113 end Is_Fully_Initialized_Variant;
12114
12115 ------------------------------------
12116 -- Is_Generic_Declaration_Or_Body --
12117 ------------------------------------
12118
12119 function Is_Generic_Declaration_Or_Body (Decl : Node_Id) return Boolean is
12120 Spec_Decl : Node_Id;
12121
12122 begin
12123 -- Package/subprogram body
12124
12125 if Nkind_In (Decl, N_Package_Body, N_Subprogram_Body)
12126 and then Present (Corresponding_Spec (Decl))
12127 then
12128 Spec_Decl := Unit_Declaration_Node (Corresponding_Spec (Decl));
12129
12130 -- Package/subprogram body stub
12131
12132 elsif Nkind_In (Decl, N_Package_Body_Stub, N_Subprogram_Body_Stub)
12133 and then Present (Corresponding_Spec_Of_Stub (Decl))
12134 then
12135 Spec_Decl :=
12136 Unit_Declaration_Node (Corresponding_Spec_Of_Stub (Decl));
12137
12138 -- All other cases
12139
12140 else
12141 Spec_Decl := Decl;
12142 end if;
12143
12144 -- Rather than inspecting the defining entity of the spec declaration,
12145 -- look at its Nkind. This takes care of the case where the analysis of
12146 -- a generic body modifies the Ekind of its spec to allow for recursive
12147 -- calls.
12148
12149 return
12150 Nkind_In (Spec_Decl, N_Generic_Package_Declaration,
12151 N_Generic_Subprogram_Declaration);
12152 end Is_Generic_Declaration_Or_Body;
12153
12154 ----------------------------
12155 -- Is_Inherited_Operation --
12156 ----------------------------
12157
12158 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
12159 pragma Assert (Is_Overloadable (E));
12160 Kind : constant Node_Kind := Nkind (Parent (E));
12161 begin
12162 return Kind = N_Full_Type_Declaration
12163 or else Kind = N_Private_Extension_Declaration
12164 or else Kind = N_Subtype_Declaration
12165 or else (Ekind (E) = E_Enumeration_Literal
12166 and then Is_Derived_Type (Etype (E)));
12167 end Is_Inherited_Operation;
12168
12169 -------------------------------------
12170 -- Is_Inherited_Operation_For_Type --
12171 -------------------------------------
12172
12173 function Is_Inherited_Operation_For_Type
12174 (E : Entity_Id;
12175 Typ : Entity_Id) return Boolean
12176 is
12177 begin
12178 -- Check that the operation has been created by the type declaration
12179
12180 return Is_Inherited_Operation (E)
12181 and then Defining_Identifier (Parent (E)) = Typ;
12182 end Is_Inherited_Operation_For_Type;
12183
12184 -----------------
12185 -- Is_Iterator --
12186 -----------------
12187
12188 function Is_Iterator (Typ : Entity_Id) return Boolean is
12189 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean;
12190 -- Determine whether type Iter_Typ is a predefined forward or reversible
12191 -- iterator.
12192
12193 ----------------------
12194 -- Denotes_Iterator --
12195 ----------------------
12196
12197 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean is
12198 begin
12199 return
12200 Nam_In (Chars (Iter_Typ), Name_Forward_Iterator,
12201 Name_Reversible_Iterator)
12202 and then Is_Predefined_File_Name
12203 (Unit_File_Name (Get_Source_Unit (Iter_Typ)));
12204 end Denotes_Iterator;
12205
12206 -- Local variables
12207
12208 Iface_Elmt : Elmt_Id;
12209 Ifaces : Elist_Id;
12210
12211 -- Start of processing for Is_Iterator
12212
12213 begin
12214 -- The type may be a subtype of a descendant of the proper instance of
12215 -- the predefined interface type, so we must use the root type of the
12216 -- given type. The same is done for Is_Reversible_Iterator.
12217
12218 if Is_Class_Wide_Type (Typ)
12219 and then Denotes_Iterator (Root_Type (Typ))
12220 then
12221 return True;
12222
12223 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
12224 return False;
12225
12226 elsif Present (Find_Value_Of_Aspect (Typ, Aspect_Iterable)) then
12227 return True;
12228
12229 else
12230 Collect_Interfaces (Typ, Ifaces);
12231
12232 Iface_Elmt := First_Elmt (Ifaces);
12233 while Present (Iface_Elmt) loop
12234 if Denotes_Iterator (Node (Iface_Elmt)) then
12235 return True;
12236 end if;
12237
12238 Next_Elmt (Iface_Elmt);
12239 end loop;
12240
12241 return False;
12242 end if;
12243 end Is_Iterator;
12244
12245 ----------------------------
12246 -- Is_Iterator_Over_Array --
12247 ----------------------------
12248
12249 function Is_Iterator_Over_Array (N : Node_Id) return Boolean is
12250 Container : constant Node_Id := Name (N);
12251 Container_Typ : constant Entity_Id := Base_Type (Etype (Container));
12252 begin
12253 return Is_Array_Type (Container_Typ);
12254 end Is_Iterator_Over_Array;
12255
12256 ------------
12257 -- Is_LHS --
12258 ------------
12259
12260 -- We seem to have a lot of overlapping functions that do similar things
12261 -- (testing for left hand sides or lvalues???).
12262
12263 function Is_LHS (N : Node_Id) return Is_LHS_Result is
12264 P : constant Node_Id := Parent (N);
12265
12266 begin
12267 -- Return True if we are the left hand side of an assignment statement
12268
12269 if Nkind (P) = N_Assignment_Statement then
12270 if Name (P) = N then
12271 return Yes;
12272 else
12273 return No;
12274 end if;
12275
12276 -- Case of prefix of indexed or selected component or slice
12277
12278 elsif Nkind_In (P, N_Indexed_Component, N_Selected_Component, N_Slice)
12279 and then N = Prefix (P)
12280 then
12281 -- Here we have the case where the parent P is N.Q or N(Q .. R).
12282 -- If P is an LHS, then N is also effectively an LHS, but there
12283 -- is an important exception. If N is of an access type, then
12284 -- what we really have is N.all.Q (or N.all(Q .. R)). In either
12285 -- case this makes N.all a left hand side but not N itself.
12286
12287 -- If we don't know the type yet, this is the case where we return
12288 -- Unknown, since the answer depends on the type which is unknown.
12289
12290 if No (Etype (N)) then
12291 return Unknown;
12292
12293 -- We have an Etype set, so we can check it
12294
12295 elsif Is_Access_Type (Etype (N)) then
12296 return No;
12297
12298 -- OK, not access type case, so just test whole expression
12299
12300 else
12301 return Is_LHS (P);
12302 end if;
12303
12304 -- All other cases are not left hand sides
12305
12306 else
12307 return No;
12308 end if;
12309 end Is_LHS;
12310
12311 -----------------------------
12312 -- Is_Library_Level_Entity --
12313 -----------------------------
12314
12315 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
12316 begin
12317 -- The following is a small optimization, and it also properly handles
12318 -- discriminals, which in task bodies might appear in expressions before
12319 -- the corresponding procedure has been created, and which therefore do
12320 -- not have an assigned scope.
12321
12322 if Is_Formal (E) then
12323 return False;
12324 end if;
12325
12326 -- Normal test is simply that the enclosing dynamic scope is Standard
12327
12328 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
12329 end Is_Library_Level_Entity;
12330
12331 --------------------------------
12332 -- Is_Limited_Class_Wide_Type --
12333 --------------------------------
12334
12335 function Is_Limited_Class_Wide_Type (Typ : Entity_Id) return Boolean is
12336 begin
12337 return
12338 Is_Class_Wide_Type (Typ)
12339 and then (Is_Limited_Type (Typ) or else From_Limited_With (Typ));
12340 end Is_Limited_Class_Wide_Type;
12341
12342 ---------------------------------
12343 -- Is_Local_Variable_Reference --
12344 ---------------------------------
12345
12346 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
12347 begin
12348 if not Is_Entity_Name (Expr) then
12349 return False;
12350
12351 else
12352 declare
12353 Ent : constant Entity_Id := Entity (Expr);
12354 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
12355 begin
12356 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
12357 return False;
12358 else
12359 return Present (Sub) and then Sub = Current_Subprogram;
12360 end if;
12361 end;
12362 end if;
12363 end Is_Local_Variable_Reference;
12364
12365 -------------------------
12366 -- Is_Object_Reference --
12367 -------------------------
12368
12369 function Is_Object_Reference (N : Node_Id) return Boolean is
12370
12371 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean;
12372 -- Determine whether N is the name of an internally-generated renaming
12373
12374 --------------------------------------
12375 -- Is_Internally_Generated_Renaming --
12376 --------------------------------------
12377
12378 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean is
12379 P : Node_Id;
12380
12381 begin
12382 P := N;
12383 while Present (P) loop
12384 if Nkind (P) = N_Object_Renaming_Declaration then
12385 return not Comes_From_Source (P);
12386 elsif Is_List_Member (P) then
12387 return False;
12388 end if;
12389
12390 P := Parent (P);
12391 end loop;
12392
12393 return False;
12394 end Is_Internally_Generated_Renaming;
12395
12396 -- Start of processing for Is_Object_Reference
12397
12398 begin
12399 if Is_Entity_Name (N) then
12400 return Present (Entity (N)) and then Is_Object (Entity (N));
12401
12402 else
12403 case Nkind (N) is
12404 when N_Indexed_Component | N_Slice =>
12405 return
12406 Is_Object_Reference (Prefix (N))
12407 or else Is_Access_Type (Etype (Prefix (N)));
12408
12409 -- In Ada 95, a function call is a constant object; a procedure
12410 -- call is not.
12411
12412 when N_Function_Call =>
12413 return Etype (N) /= Standard_Void_Type;
12414
12415 -- Attributes 'Input, 'Loop_Entry, 'Old and 'Result produce
12416 -- objects.
12417
12418 when N_Attribute_Reference =>
12419 return
12420 Nam_In (Attribute_Name (N), Name_Input,
12421 Name_Loop_Entry,
12422 Name_Old,
12423 Name_Result);
12424
12425 when N_Selected_Component =>
12426 return
12427 Is_Object_Reference (Selector_Name (N))
12428 and then
12429 (Is_Object_Reference (Prefix (N))
12430 or else Is_Access_Type (Etype (Prefix (N))));
12431
12432 when N_Explicit_Dereference =>
12433 return True;
12434
12435 -- A view conversion of a tagged object is an object reference
12436
12437 when N_Type_Conversion =>
12438 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
12439 and then Is_Tagged_Type (Etype (Expression (N)))
12440 and then Is_Object_Reference (Expression (N));
12441
12442 -- An unchecked type conversion is considered to be an object if
12443 -- the operand is an object (this construction arises only as a
12444 -- result of expansion activities).
12445
12446 when N_Unchecked_Type_Conversion =>
12447 return True;
12448
12449 -- Allow string literals to act as objects as long as they appear
12450 -- in internally-generated renamings. The expansion of iterators
12451 -- may generate such renamings when the range involves a string
12452 -- literal.
12453
12454 when N_String_Literal =>
12455 return Is_Internally_Generated_Renaming (Parent (N));
12456
12457 -- AI05-0003: In Ada 2012 a qualified expression is a name.
12458 -- This allows disambiguation of function calls and the use
12459 -- of aggregates in more contexts.
12460
12461 when N_Qualified_Expression =>
12462 if Ada_Version < Ada_2012 then
12463 return False;
12464 else
12465 return Is_Object_Reference (Expression (N))
12466 or else Nkind (Expression (N)) = N_Aggregate;
12467 end if;
12468
12469 when others =>
12470 return False;
12471 end case;
12472 end if;
12473 end Is_Object_Reference;
12474
12475 -----------------------------------
12476 -- Is_OK_Variable_For_Out_Formal --
12477 -----------------------------------
12478
12479 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
12480 begin
12481 Note_Possible_Modification (AV, Sure => True);
12482
12483 -- We must reject parenthesized variable names. Comes_From_Source is
12484 -- checked because there are currently cases where the compiler violates
12485 -- this rule (e.g. passing a task object to its controlled Initialize
12486 -- routine). This should be properly documented in sinfo???
12487
12488 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
12489 return False;
12490
12491 -- A variable is always allowed
12492
12493 elsif Is_Variable (AV) then
12494 return True;
12495
12496 -- Generalized indexing operations are rewritten as explicit
12497 -- dereferences, and it is only during resolution that we can
12498 -- check whether the context requires an access_to_variable type.
12499
12500 elsif Nkind (AV) = N_Explicit_Dereference
12501 and then Ada_Version >= Ada_2012
12502 and then Nkind (Original_Node (AV)) = N_Indexed_Component
12503 and then Present (Etype (Original_Node (AV)))
12504 and then Has_Implicit_Dereference (Etype (Original_Node (AV)))
12505 then
12506 return not Is_Access_Constant (Etype (Prefix (AV)));
12507
12508 -- Unchecked conversions are allowed only if they come from the
12509 -- generated code, which sometimes uses unchecked conversions for out
12510 -- parameters in cases where code generation is unaffected. We tell
12511 -- source unchecked conversions by seeing if they are rewrites of
12512 -- an original Unchecked_Conversion function call, or of an explicit
12513 -- conversion of a function call or an aggregate (as may happen in the
12514 -- expansion of a packed array aggregate).
12515
12516 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
12517 if Nkind_In (Original_Node (AV), N_Function_Call, N_Aggregate) then
12518 return False;
12519
12520 elsif Comes_From_Source (AV)
12521 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
12522 then
12523 return False;
12524
12525 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
12526 return Is_OK_Variable_For_Out_Formal (Expression (AV));
12527
12528 else
12529 return True;
12530 end if;
12531
12532 -- Normal type conversions are allowed if argument is a variable
12533
12534 elsif Nkind (AV) = N_Type_Conversion then
12535 if Is_Variable (Expression (AV))
12536 and then Paren_Count (Expression (AV)) = 0
12537 then
12538 Note_Possible_Modification (Expression (AV), Sure => True);
12539 return True;
12540
12541 -- We also allow a non-parenthesized expression that raises
12542 -- constraint error if it rewrites what used to be a variable
12543
12544 elsif Raises_Constraint_Error (Expression (AV))
12545 and then Paren_Count (Expression (AV)) = 0
12546 and then Is_Variable (Original_Node (Expression (AV)))
12547 then
12548 return True;
12549
12550 -- Type conversion of something other than a variable
12551
12552 else
12553 return False;
12554 end if;
12555
12556 -- If this node is rewritten, then test the original form, if that is
12557 -- OK, then we consider the rewritten node OK (for example, if the
12558 -- original node is a conversion, then Is_Variable will not be true
12559 -- but we still want to allow the conversion if it converts a variable).
12560
12561 elsif Original_Node (AV) /= AV then
12562
12563 -- In Ada 2012, the explicit dereference may be a rewritten call to a
12564 -- Reference function.
12565
12566 if Ada_Version >= Ada_2012
12567 and then Nkind (Original_Node (AV)) = N_Function_Call
12568 and then
12569 Has_Implicit_Dereference (Etype (Name (Original_Node (AV))))
12570 then
12571
12572 -- Check that this is not a constant reference.
12573
12574 return not Is_Access_Constant (Etype (Prefix (AV)));
12575
12576 elsif Has_Implicit_Dereference (Etype (Original_Node (AV))) then
12577 return
12578 not Is_Access_Constant (Etype
12579 (Get_Reference_Discriminant (Etype (Original_Node (AV)))));
12580
12581 else
12582 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
12583 end if;
12584
12585 -- All other non-variables are rejected
12586
12587 else
12588 return False;
12589 end if;
12590 end Is_OK_Variable_For_Out_Formal;
12591
12592 ------------------------------------
12593 -- Is_Package_Contract_Annotation --
12594 ------------------------------------
12595
12596 function Is_Package_Contract_Annotation (Item : Node_Id) return Boolean is
12597 Nam : Name_Id;
12598
12599 begin
12600 if Nkind (Item) = N_Aspect_Specification then
12601 Nam := Chars (Identifier (Item));
12602
12603 else pragma Assert (Nkind (Item) = N_Pragma);
12604 Nam := Pragma_Name (Item);
12605 end if;
12606
12607 return Nam = Name_Abstract_State
12608 or else Nam = Name_Initial_Condition
12609 or else Nam = Name_Initializes
12610 or else Nam = Name_Refined_State;
12611 end Is_Package_Contract_Annotation;
12612
12613 -----------------------------------
12614 -- Is_Partially_Initialized_Type --
12615 -----------------------------------
12616
12617 function Is_Partially_Initialized_Type
12618 (Typ : Entity_Id;
12619 Include_Implicit : Boolean := True) return Boolean
12620 is
12621 begin
12622 if Is_Scalar_Type (Typ) then
12623 return False;
12624
12625 elsif Is_Access_Type (Typ) then
12626 return Include_Implicit;
12627
12628 elsif Is_Array_Type (Typ) then
12629
12630 -- If component type is partially initialized, so is array type
12631
12632 if Is_Partially_Initialized_Type
12633 (Component_Type (Typ), Include_Implicit)
12634 then
12635 return True;
12636
12637 -- Otherwise we are only partially initialized if we are fully
12638 -- initialized (this is the empty array case, no point in us
12639 -- duplicating that code here).
12640
12641 else
12642 return Is_Fully_Initialized_Type (Typ);
12643 end if;
12644
12645 elsif Is_Record_Type (Typ) then
12646
12647 -- A discriminated type is always partially initialized if in
12648 -- all mode
12649
12650 if Has_Discriminants (Typ) and then Include_Implicit then
12651 return True;
12652
12653 -- A tagged type is always partially initialized
12654
12655 elsif Is_Tagged_Type (Typ) then
12656 return True;
12657
12658 -- Case of non-discriminated record
12659
12660 else
12661 declare
12662 Ent : Entity_Id;
12663
12664 Component_Present : Boolean := False;
12665 -- Set True if at least one component is present. If no
12666 -- components are present, then record type is fully
12667 -- initialized (another odd case, like the null array).
12668
12669 begin
12670 -- Loop through components
12671
12672 Ent := First_Entity (Typ);
12673 while Present (Ent) loop
12674 if Ekind (Ent) = E_Component then
12675 Component_Present := True;
12676
12677 -- If a component has an initialization expression then
12678 -- the enclosing record type is partially initialized
12679
12680 if Present (Parent (Ent))
12681 and then Present (Expression (Parent (Ent)))
12682 then
12683 return True;
12684
12685 -- If a component is of a type which is itself partially
12686 -- initialized, then the enclosing record type is also.
12687
12688 elsif Is_Partially_Initialized_Type
12689 (Etype (Ent), Include_Implicit)
12690 then
12691 return True;
12692 end if;
12693 end if;
12694
12695 Next_Entity (Ent);
12696 end loop;
12697
12698 -- No initialized components found. If we found any components
12699 -- they were all uninitialized so the result is false.
12700
12701 if Component_Present then
12702 return False;
12703
12704 -- But if we found no components, then all the components are
12705 -- initialized so we consider the type to be initialized.
12706
12707 else
12708 return True;
12709 end if;
12710 end;
12711 end if;
12712
12713 -- Concurrent types are always fully initialized
12714
12715 elsif Is_Concurrent_Type (Typ) then
12716 return True;
12717
12718 -- For a private type, go to underlying type. If there is no underlying
12719 -- type then just assume this partially initialized. Not clear if this
12720 -- can happen in a non-error case, but no harm in testing for this.
12721
12722 elsif Is_Private_Type (Typ) then
12723 declare
12724 U : constant Entity_Id := Underlying_Type (Typ);
12725 begin
12726 if No (U) then
12727 return True;
12728 else
12729 return Is_Partially_Initialized_Type (U, Include_Implicit);
12730 end if;
12731 end;
12732
12733 -- For any other type (are there any?) assume partially initialized
12734
12735 else
12736 return True;
12737 end if;
12738 end Is_Partially_Initialized_Type;
12739
12740 ------------------------------------
12741 -- Is_Potentially_Persistent_Type --
12742 ------------------------------------
12743
12744 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
12745 Comp : Entity_Id;
12746 Indx : Node_Id;
12747
12748 begin
12749 -- For private type, test corresponding full type
12750
12751 if Is_Private_Type (T) then
12752 return Is_Potentially_Persistent_Type (Full_View (T));
12753
12754 -- Scalar types are potentially persistent
12755
12756 elsif Is_Scalar_Type (T) then
12757 return True;
12758
12759 -- Record type is potentially persistent if not tagged and the types of
12760 -- all it components are potentially persistent, and no component has
12761 -- an initialization expression.
12762
12763 elsif Is_Record_Type (T)
12764 and then not Is_Tagged_Type (T)
12765 and then not Is_Partially_Initialized_Type (T)
12766 then
12767 Comp := First_Component (T);
12768 while Present (Comp) loop
12769 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
12770 return False;
12771 else
12772 Next_Entity (Comp);
12773 end if;
12774 end loop;
12775
12776 return True;
12777
12778 -- Array type is potentially persistent if its component type is
12779 -- potentially persistent and if all its constraints are static.
12780
12781 elsif Is_Array_Type (T) then
12782 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
12783 return False;
12784 end if;
12785
12786 Indx := First_Index (T);
12787 while Present (Indx) loop
12788 if not Is_OK_Static_Subtype (Etype (Indx)) then
12789 return False;
12790 else
12791 Next_Index (Indx);
12792 end if;
12793 end loop;
12794
12795 return True;
12796
12797 -- All other types are not potentially persistent
12798
12799 else
12800 return False;
12801 end if;
12802 end Is_Potentially_Persistent_Type;
12803
12804 --------------------------------
12805 -- Is_Potentially_Unevaluated --
12806 --------------------------------
12807
12808 function Is_Potentially_Unevaluated (N : Node_Id) return Boolean is
12809 Par : Node_Id;
12810 Expr : Node_Id;
12811
12812 begin
12813 Expr := N;
12814 Par := Parent (N);
12815
12816 -- A postcondition whose expression is a short-circuit is broken down
12817 -- into individual aspects for better exception reporting. The original
12818 -- short-circuit expression is rewritten as the second operand, and an
12819 -- occurrence of 'Old in that operand is potentially unevaluated.
12820 -- See Sem_ch13.adb for details of this transformation.
12821
12822 if Nkind (Original_Node (Par)) = N_And_Then then
12823 return True;
12824 end if;
12825
12826 while not Nkind_In (Par, N_If_Expression,
12827 N_Case_Expression,
12828 N_And_Then,
12829 N_Or_Else,
12830 N_In,
12831 N_Not_In)
12832 loop
12833 Expr := Par;
12834 Par := Parent (Par);
12835
12836 -- If the context is not an expression, or if is the result of
12837 -- expansion of an enclosing construct (such as another attribute)
12838 -- the predicate does not apply.
12839
12840 if Nkind (Par) not in N_Subexpr
12841 or else not Comes_From_Source (Par)
12842 then
12843 return False;
12844 end if;
12845 end loop;
12846
12847 if Nkind (Par) = N_If_Expression then
12848 return Is_Elsif (Par) or else Expr /= First (Expressions (Par));
12849
12850 elsif Nkind (Par) = N_Case_Expression then
12851 return Expr /= Expression (Par);
12852
12853 elsif Nkind_In (Par, N_And_Then, N_Or_Else) then
12854 return Expr = Right_Opnd (Par);
12855
12856 elsif Nkind_In (Par, N_In, N_Not_In) then
12857 return Expr /= Left_Opnd (Par);
12858
12859 else
12860 return False;
12861 end if;
12862 end Is_Potentially_Unevaluated;
12863
12864 ---------------------------------
12865 -- Is_Protected_Self_Reference --
12866 ---------------------------------
12867
12868 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
12869
12870 function In_Access_Definition (N : Node_Id) return Boolean;
12871 -- Returns true if N belongs to an access definition
12872
12873 --------------------------
12874 -- In_Access_Definition --
12875 --------------------------
12876
12877 function In_Access_Definition (N : Node_Id) return Boolean is
12878 P : Node_Id;
12879
12880 begin
12881 P := Parent (N);
12882 while Present (P) loop
12883 if Nkind (P) = N_Access_Definition then
12884 return True;
12885 end if;
12886
12887 P := Parent (P);
12888 end loop;
12889
12890 return False;
12891 end In_Access_Definition;
12892
12893 -- Start of processing for Is_Protected_Self_Reference
12894
12895 begin
12896 -- Verify that prefix is analyzed and has the proper form. Note that
12897 -- the attributes Elab_Spec, Elab_Body and Elab_Subp_Body which also
12898 -- produce the address of an entity, do not analyze their prefix
12899 -- because they denote entities that are not necessarily visible.
12900 -- Neither of them can apply to a protected type.
12901
12902 return Ada_Version >= Ada_2005
12903 and then Is_Entity_Name (N)
12904 and then Present (Entity (N))
12905 and then Is_Protected_Type (Entity (N))
12906 and then In_Open_Scopes (Entity (N))
12907 and then not In_Access_Definition (N);
12908 end Is_Protected_Self_Reference;
12909
12910 -----------------------------
12911 -- Is_RCI_Pkg_Spec_Or_Body --
12912 -----------------------------
12913
12914 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
12915
12916 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
12917 -- Return True if the unit of Cunit is an RCI package declaration
12918
12919 ---------------------------
12920 -- Is_RCI_Pkg_Decl_Cunit --
12921 ---------------------------
12922
12923 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
12924 The_Unit : constant Node_Id := Unit (Cunit);
12925
12926 begin
12927 if Nkind (The_Unit) /= N_Package_Declaration then
12928 return False;
12929 end if;
12930
12931 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
12932 end Is_RCI_Pkg_Decl_Cunit;
12933
12934 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
12935
12936 begin
12937 return Is_RCI_Pkg_Decl_Cunit (Cunit)
12938 or else
12939 (Nkind (Unit (Cunit)) = N_Package_Body
12940 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
12941 end Is_RCI_Pkg_Spec_Or_Body;
12942
12943 -----------------------------------------
12944 -- Is_Remote_Access_To_Class_Wide_Type --
12945 -----------------------------------------
12946
12947 function Is_Remote_Access_To_Class_Wide_Type
12948 (E : Entity_Id) return Boolean
12949 is
12950 begin
12951 -- A remote access to class-wide type is a general access to object type
12952 -- declared in the visible part of a Remote_Types or Remote_Call_
12953 -- Interface unit.
12954
12955 return Ekind (E) = E_General_Access_Type
12956 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
12957 end Is_Remote_Access_To_Class_Wide_Type;
12958
12959 -----------------------------------------
12960 -- Is_Remote_Access_To_Subprogram_Type --
12961 -----------------------------------------
12962
12963 function Is_Remote_Access_To_Subprogram_Type
12964 (E : Entity_Id) return Boolean
12965 is
12966 begin
12967 return (Ekind (E) = E_Access_Subprogram_Type
12968 or else (Ekind (E) = E_Record_Type
12969 and then Present (Corresponding_Remote_Type (E))))
12970 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
12971 end Is_Remote_Access_To_Subprogram_Type;
12972
12973 --------------------
12974 -- Is_Remote_Call --
12975 --------------------
12976
12977 function Is_Remote_Call (N : Node_Id) return Boolean is
12978 begin
12979 if Nkind (N) not in N_Subprogram_Call then
12980
12981 -- An entry call cannot be remote
12982
12983 return False;
12984
12985 elsif Nkind (Name (N)) in N_Has_Entity
12986 and then Is_Remote_Call_Interface (Entity (Name (N)))
12987 then
12988 -- A subprogram declared in the spec of a RCI package is remote
12989
12990 return True;
12991
12992 elsif Nkind (Name (N)) = N_Explicit_Dereference
12993 and then Is_Remote_Access_To_Subprogram_Type
12994 (Etype (Prefix (Name (N))))
12995 then
12996 -- The dereference of a RAS is a remote call
12997
12998 return True;
12999
13000 elsif Present (Controlling_Argument (N))
13001 and then Is_Remote_Access_To_Class_Wide_Type
13002 (Etype (Controlling_Argument (N)))
13003 then
13004 -- Any primitive operation call with a controlling argument of
13005 -- a RACW type is a remote call.
13006
13007 return True;
13008 end if;
13009
13010 -- All other calls are local calls
13011
13012 return False;
13013 end Is_Remote_Call;
13014
13015 ----------------------
13016 -- Is_Renamed_Entry --
13017 ----------------------
13018
13019 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
13020 Orig_Node : Node_Id := Empty;
13021 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
13022
13023 function Is_Entry (Nam : Node_Id) return Boolean;
13024 -- Determine whether Nam is an entry. Traverse selectors if there are
13025 -- nested selected components.
13026
13027 --------------
13028 -- Is_Entry --
13029 --------------
13030
13031 function Is_Entry (Nam : Node_Id) return Boolean is
13032 begin
13033 if Nkind (Nam) = N_Selected_Component then
13034 return Is_Entry (Selector_Name (Nam));
13035 end if;
13036
13037 return Ekind (Entity (Nam)) = E_Entry;
13038 end Is_Entry;
13039
13040 -- Start of processing for Is_Renamed_Entry
13041
13042 begin
13043 if Present (Alias (Proc_Nam)) then
13044 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
13045 end if;
13046
13047 -- Look for a rewritten subprogram renaming declaration
13048
13049 if Nkind (Subp_Decl) = N_Subprogram_Declaration
13050 and then Present (Original_Node (Subp_Decl))
13051 then
13052 Orig_Node := Original_Node (Subp_Decl);
13053 end if;
13054
13055 -- The rewritten subprogram is actually an entry
13056
13057 if Present (Orig_Node)
13058 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
13059 and then Is_Entry (Name (Orig_Node))
13060 then
13061 return True;
13062 end if;
13063
13064 return False;
13065 end Is_Renamed_Entry;
13066
13067 -----------------------------
13068 -- Is_Renaming_Declaration --
13069 -----------------------------
13070
13071 function Is_Renaming_Declaration (N : Node_Id) return Boolean is
13072 begin
13073 case Nkind (N) is
13074 when N_Exception_Renaming_Declaration |
13075 N_Generic_Function_Renaming_Declaration |
13076 N_Generic_Package_Renaming_Declaration |
13077 N_Generic_Procedure_Renaming_Declaration |
13078 N_Object_Renaming_Declaration |
13079 N_Package_Renaming_Declaration |
13080 N_Subprogram_Renaming_Declaration =>
13081 return True;
13082
13083 when others =>
13084 return False;
13085 end case;
13086 end Is_Renaming_Declaration;
13087
13088 ----------------------------
13089 -- Is_Reversible_Iterator --
13090 ----------------------------
13091
13092 function Is_Reversible_Iterator (Typ : Entity_Id) return Boolean is
13093 Ifaces_List : Elist_Id;
13094 Iface_Elmt : Elmt_Id;
13095 Iface : Entity_Id;
13096
13097 begin
13098 if Is_Class_Wide_Type (Typ)
13099 and then Chars (Root_Type (Typ)) = Name_Reversible_Iterator
13100 and then Is_Predefined_File_Name
13101 (Unit_File_Name (Get_Source_Unit (Root_Type (Typ))))
13102 then
13103 return True;
13104
13105 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
13106 return False;
13107
13108 else
13109 Collect_Interfaces (Typ, Ifaces_List);
13110
13111 Iface_Elmt := First_Elmt (Ifaces_List);
13112 while Present (Iface_Elmt) loop
13113 Iface := Node (Iface_Elmt);
13114 if Chars (Iface) = Name_Reversible_Iterator
13115 and then
13116 Is_Predefined_File_Name
13117 (Unit_File_Name (Get_Source_Unit (Iface)))
13118 then
13119 return True;
13120 end if;
13121
13122 Next_Elmt (Iface_Elmt);
13123 end loop;
13124 end if;
13125
13126 return False;
13127 end Is_Reversible_Iterator;
13128
13129 ----------------------
13130 -- Is_Selector_Name --
13131 ----------------------
13132
13133 function Is_Selector_Name (N : Node_Id) return Boolean is
13134 begin
13135 if not Is_List_Member (N) then
13136 declare
13137 P : constant Node_Id := Parent (N);
13138 begin
13139 return Nkind_In (P, N_Expanded_Name,
13140 N_Generic_Association,
13141 N_Parameter_Association,
13142 N_Selected_Component)
13143 and then Selector_Name (P) = N;
13144 end;
13145
13146 else
13147 declare
13148 L : constant List_Id := List_Containing (N);
13149 P : constant Node_Id := Parent (L);
13150 begin
13151 return (Nkind (P) = N_Discriminant_Association
13152 and then Selector_Names (P) = L)
13153 or else
13154 (Nkind (P) = N_Component_Association
13155 and then Choices (P) = L);
13156 end;
13157 end if;
13158 end Is_Selector_Name;
13159
13160 ---------------------------------
13161 -- Is_Single_Concurrent_Object --
13162 ---------------------------------
13163
13164 function Is_Single_Concurrent_Object (Id : Entity_Id) return Boolean is
13165 begin
13166 return
13167 Ekind (Id) = E_Variable
13168 and then Is_Single_Concurrent_Type (Etype (Id));
13169 end Is_Single_Concurrent_Object;
13170
13171 -------------------------------
13172 -- Is_Single_Concurrent_Type --
13173 -------------------------------
13174
13175 function Is_Single_Concurrent_Type (Id : Entity_Id) return Boolean is
13176 begin
13177 return
13178 Ekind_In (Id, E_Protected_Type, E_Task_Type)
13179 and then Is_Single_Concurrent_Type_Declaration
13180 (Declaration_Node (Id));
13181 end Is_Single_Concurrent_Type;
13182
13183 -------------------------------------------
13184 -- Is_Single_Concurrent_Type_Declaration --
13185 -------------------------------------------
13186
13187 function Is_Single_Concurrent_Type_Declaration
13188 (N : Node_Id) return Boolean
13189 is
13190 begin
13191 return Nkind_In (Original_Node (N), N_Single_Protected_Declaration,
13192 N_Single_Task_Declaration);
13193 end Is_Single_Concurrent_Type_Declaration;
13194
13195 ---------------------------------------------
13196 -- Is_Single_Precision_Floating_Point_Type --
13197 ---------------------------------------------
13198
13199 function Is_Single_Precision_Floating_Point_Type
13200 (E : Entity_Id) return Boolean is
13201 begin
13202 return Is_Floating_Point_Type (E)
13203 and then Machine_Radix_Value (E) = Uint_2
13204 and then Machine_Mantissa_Value (E) = Uint_24
13205 and then Machine_Emax_Value (E) = Uint_2 ** Uint_7
13206 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_7);
13207 end Is_Single_Precision_Floating_Point_Type;
13208
13209 -------------------------------------
13210 -- Is_SPARK_05_Initialization_Expr --
13211 -------------------------------------
13212
13213 function Is_SPARK_05_Initialization_Expr (N : Node_Id) return Boolean is
13214 Is_Ok : Boolean;
13215 Expr : Node_Id;
13216 Comp_Assn : Node_Id;
13217 Orig_N : constant Node_Id := Original_Node (N);
13218
13219 begin
13220 Is_Ok := True;
13221
13222 if not Comes_From_Source (Orig_N) then
13223 goto Done;
13224 end if;
13225
13226 pragma Assert (Nkind (Orig_N) in N_Subexpr);
13227
13228 case Nkind (Orig_N) is
13229 when N_Character_Literal |
13230 N_Integer_Literal |
13231 N_Real_Literal |
13232 N_String_Literal =>
13233 null;
13234
13235 when N_Identifier |
13236 N_Expanded_Name =>
13237 if Is_Entity_Name (Orig_N)
13238 and then Present (Entity (Orig_N)) -- needed in some cases
13239 then
13240 case Ekind (Entity (Orig_N)) is
13241 when E_Constant |
13242 E_Enumeration_Literal |
13243 E_Named_Integer |
13244 E_Named_Real =>
13245 null;
13246 when others =>
13247 if Is_Type (Entity (Orig_N)) then
13248 null;
13249 else
13250 Is_Ok := False;
13251 end if;
13252 end case;
13253 end if;
13254
13255 when N_Qualified_Expression |
13256 N_Type_Conversion =>
13257 Is_Ok := Is_SPARK_05_Initialization_Expr (Expression (Orig_N));
13258
13259 when N_Unary_Op =>
13260 Is_Ok := Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
13261
13262 when N_Binary_Op |
13263 N_Short_Circuit |
13264 N_Membership_Test =>
13265 Is_Ok := Is_SPARK_05_Initialization_Expr (Left_Opnd (Orig_N))
13266 and then
13267 Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
13268
13269 when N_Aggregate |
13270 N_Extension_Aggregate =>
13271 if Nkind (Orig_N) = N_Extension_Aggregate then
13272 Is_Ok :=
13273 Is_SPARK_05_Initialization_Expr (Ancestor_Part (Orig_N));
13274 end if;
13275
13276 Expr := First (Expressions (Orig_N));
13277 while Present (Expr) loop
13278 if not Is_SPARK_05_Initialization_Expr (Expr) then
13279 Is_Ok := False;
13280 goto Done;
13281 end if;
13282
13283 Next (Expr);
13284 end loop;
13285
13286 Comp_Assn := First (Component_Associations (Orig_N));
13287 while Present (Comp_Assn) loop
13288 Expr := Expression (Comp_Assn);
13289
13290 -- Note: test for Present here needed for box assocation
13291
13292 if Present (Expr)
13293 and then not Is_SPARK_05_Initialization_Expr (Expr)
13294 then
13295 Is_Ok := False;
13296 goto Done;
13297 end if;
13298
13299 Next (Comp_Assn);
13300 end loop;
13301
13302 when N_Attribute_Reference =>
13303 if Nkind (Prefix (Orig_N)) in N_Subexpr then
13304 Is_Ok := Is_SPARK_05_Initialization_Expr (Prefix (Orig_N));
13305 end if;
13306
13307 Expr := First (Expressions (Orig_N));
13308 while Present (Expr) loop
13309 if not Is_SPARK_05_Initialization_Expr (Expr) then
13310 Is_Ok := False;
13311 goto Done;
13312 end if;
13313
13314 Next (Expr);
13315 end loop;
13316
13317 -- Selected components might be expanded named not yet resolved, so
13318 -- default on the safe side. (Eg on sparklex.ads)
13319
13320 when N_Selected_Component =>
13321 null;
13322
13323 when others =>
13324 Is_Ok := False;
13325 end case;
13326
13327 <<Done>>
13328 return Is_Ok;
13329 end Is_SPARK_05_Initialization_Expr;
13330
13331 ----------------------------------
13332 -- Is_SPARK_05_Object_Reference --
13333 ----------------------------------
13334
13335 function Is_SPARK_05_Object_Reference (N : Node_Id) return Boolean is
13336 begin
13337 if Is_Entity_Name (N) then
13338 return Present (Entity (N))
13339 and then
13340 (Ekind_In (Entity (N), E_Constant, E_Variable)
13341 or else Ekind (Entity (N)) in Formal_Kind);
13342
13343 else
13344 case Nkind (N) is
13345 when N_Selected_Component =>
13346 return Is_SPARK_05_Object_Reference (Prefix (N));
13347
13348 when others =>
13349 return False;
13350 end case;
13351 end if;
13352 end Is_SPARK_05_Object_Reference;
13353
13354 -----------------------------
13355 -- Is_Specific_Tagged_Type --
13356 -----------------------------
13357
13358 function Is_Specific_Tagged_Type (Typ : Entity_Id) return Boolean is
13359 Full_Typ : Entity_Id;
13360
13361 begin
13362 -- Handle private types
13363
13364 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
13365 Full_Typ := Full_View (Typ);
13366 else
13367 Full_Typ := Typ;
13368 end if;
13369
13370 -- A specific tagged type is a non-class-wide tagged type
13371
13372 return Is_Tagged_Type (Full_Typ) and not Is_Class_Wide_Type (Full_Typ);
13373 end Is_Specific_Tagged_Type;
13374
13375 ------------------
13376 -- Is_Statement --
13377 ------------------
13378
13379 function Is_Statement (N : Node_Id) return Boolean is
13380 begin
13381 return
13382 Nkind (N) in N_Statement_Other_Than_Procedure_Call
13383 or else Nkind (N) = N_Procedure_Call_Statement;
13384 end Is_Statement;
13385
13386 ---------------------------------------
13387 -- Is_Subprogram_Contract_Annotation --
13388 ---------------------------------------
13389
13390 function Is_Subprogram_Contract_Annotation
13391 (Item : Node_Id) return Boolean
13392 is
13393 Nam : Name_Id;
13394
13395 begin
13396 if Nkind (Item) = N_Aspect_Specification then
13397 Nam := Chars (Identifier (Item));
13398
13399 else pragma Assert (Nkind (Item) = N_Pragma);
13400 Nam := Pragma_Name (Item);
13401 end if;
13402
13403 return Nam = Name_Contract_Cases
13404 or else Nam = Name_Depends
13405 or else Nam = Name_Extensions_Visible
13406 or else Nam = Name_Global
13407 or else Nam = Name_Post
13408 or else Nam = Name_Post_Class
13409 or else Nam = Name_Postcondition
13410 or else Nam = Name_Pre
13411 or else Nam = Name_Pre_Class
13412 or else Nam = Name_Precondition
13413 or else Nam = Name_Refined_Depends
13414 or else Nam = Name_Refined_Global
13415 or else Nam = Name_Refined_Post
13416 or else Nam = Name_Test_Case;
13417 end Is_Subprogram_Contract_Annotation;
13418
13419 --------------------------------------------------
13420 -- Is_Subprogram_Stub_Without_Prior_Declaration --
13421 --------------------------------------------------
13422
13423 function Is_Subprogram_Stub_Without_Prior_Declaration
13424 (N : Node_Id) return Boolean
13425 is
13426 begin
13427 -- A subprogram stub without prior declaration serves as declaration for
13428 -- the actual subprogram body. As such, it has an attached defining
13429 -- entity of E_[Generic_]Function or E_[Generic_]Procedure.
13430
13431 return Nkind (N) = N_Subprogram_Body_Stub
13432 and then Ekind (Defining_Entity (N)) /= E_Subprogram_Body;
13433 end Is_Subprogram_Stub_Without_Prior_Declaration;
13434
13435 --------------------------
13436 -- Is_Suspension_Object --
13437 --------------------------
13438
13439 function Is_Suspension_Object (Id : Entity_Id) return Boolean is
13440 begin
13441 -- This approach does an exact name match rather than to rely on
13442 -- RTSfind. Routine Is_Effectively_Volatile is used by clients of the
13443 -- front end at point where all auxiliary tables are locked and any
13444 -- modifications to them are treated as violations. Do not tamper with
13445 -- the tables, instead examine the Chars fields of all the scopes of Id.
13446
13447 return
13448 Chars (Id) = Name_Suspension_Object
13449 and then Present (Scope (Id))
13450 and then Chars (Scope (Id)) = Name_Synchronous_Task_Control
13451 and then Present (Scope (Scope (Id)))
13452 and then Chars (Scope (Scope (Id))) = Name_Ada
13453 and then Present (Scope (Scope (Scope (Id))))
13454 and then Scope (Scope (Scope (Id))) = Standard_Standard;
13455 end Is_Suspension_Object;
13456
13457 ----------------------------
13458 -- Is_Synchronized_Object --
13459 ----------------------------
13460
13461 function Is_Synchronized_Object (Id : Entity_Id) return Boolean is
13462 Prag : Node_Id;
13463
13464 begin
13465 if Is_Object (Id) then
13466
13467 -- The object is synchronized if it is of a type that yields a
13468 -- synchronized object.
13469
13470 if Yields_Synchronized_Object (Etype (Id)) then
13471 return True;
13472
13473 -- The object is synchronized if it is atomic and Async_Writers is
13474 -- enabled.
13475
13476 elsif Is_Atomic (Id) and then Async_Writers_Enabled (Id) then
13477 return True;
13478
13479 -- A constant is a synchronized object by default
13480
13481 elsif Ekind (Id) = E_Constant then
13482 return True;
13483
13484 -- A variable is a synchronized object if it is subject to pragma
13485 -- Constant_After_Elaboration.
13486
13487 elsif Ekind (Id) = E_Variable then
13488 Prag := Get_Pragma (Id, Pragma_Constant_After_Elaboration);
13489
13490 return Present (Prag) and then Is_Enabled_Pragma (Prag);
13491 end if;
13492 end if;
13493
13494 -- Otherwise the input is not an object or it does not qualify as a
13495 -- synchronized object.
13496
13497 return False;
13498 end Is_Synchronized_Object;
13499
13500 ---------------------------------
13501 -- Is_Synchronized_Tagged_Type --
13502 ---------------------------------
13503
13504 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
13505 Kind : constant Entity_Kind := Ekind (Base_Type (E));
13506
13507 begin
13508 -- A task or protected type derived from an interface is a tagged type.
13509 -- Such a tagged type is called a synchronized tagged type, as are
13510 -- synchronized interfaces and private extensions whose declaration
13511 -- includes the reserved word synchronized.
13512
13513 return (Is_Tagged_Type (E)
13514 and then (Kind = E_Task_Type
13515 or else
13516 Kind = E_Protected_Type))
13517 or else
13518 (Is_Interface (E)
13519 and then Is_Synchronized_Interface (E))
13520 or else
13521 (Ekind (E) = E_Record_Type_With_Private
13522 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
13523 and then (Synchronized_Present (Parent (E))
13524 or else Is_Synchronized_Interface (Etype (E))));
13525 end Is_Synchronized_Tagged_Type;
13526
13527 -----------------
13528 -- Is_Transfer --
13529 -----------------
13530
13531 function Is_Transfer (N : Node_Id) return Boolean is
13532 Kind : constant Node_Kind := Nkind (N);
13533
13534 begin
13535 if Kind = N_Simple_Return_Statement
13536 or else
13537 Kind = N_Extended_Return_Statement
13538 or else
13539 Kind = N_Goto_Statement
13540 or else
13541 Kind = N_Raise_Statement
13542 or else
13543 Kind = N_Requeue_Statement
13544 then
13545 return True;
13546
13547 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
13548 and then No (Condition (N))
13549 then
13550 return True;
13551
13552 elsif Kind = N_Procedure_Call_Statement
13553 and then Is_Entity_Name (Name (N))
13554 and then Present (Entity (Name (N)))
13555 and then No_Return (Entity (Name (N)))
13556 then
13557 return True;
13558
13559 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
13560 return True;
13561
13562 else
13563 return False;
13564 end if;
13565 end Is_Transfer;
13566
13567 -------------
13568 -- Is_True --
13569 -------------
13570
13571 function Is_True (U : Uint) return Boolean is
13572 begin
13573 return (U /= 0);
13574 end Is_True;
13575
13576 --------------------------------------
13577 -- Is_Unchecked_Conversion_Instance --
13578 --------------------------------------
13579
13580 function Is_Unchecked_Conversion_Instance (Id : Entity_Id) return Boolean is
13581 Gen_Par : Entity_Id;
13582
13583 begin
13584 -- Look for a function whose generic parent is the predefined intrinsic
13585 -- function Unchecked_Conversion.
13586
13587 if Ekind (Id) = E_Function then
13588 Gen_Par := Generic_Parent (Parent (Id));
13589
13590 return
13591 Present (Gen_Par)
13592 and then Chars (Gen_Par) = Name_Unchecked_Conversion
13593 and then Is_Intrinsic_Subprogram (Gen_Par)
13594 and then Is_Predefined_File_Name
13595 (Unit_File_Name (Get_Source_Unit (Gen_Par)));
13596 end if;
13597
13598 return False;
13599 end Is_Unchecked_Conversion_Instance;
13600
13601 -------------------------------
13602 -- Is_Universal_Numeric_Type --
13603 -------------------------------
13604
13605 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
13606 begin
13607 return T = Universal_Integer or else T = Universal_Real;
13608 end Is_Universal_Numeric_Type;
13609
13610 ----------------------------
13611 -- Is_Variable_Size_Array --
13612 ----------------------------
13613
13614 function Is_Variable_Size_Array (E : Entity_Id) return Boolean is
13615 Idx : Node_Id;
13616
13617 begin
13618 pragma Assert (Is_Array_Type (E));
13619
13620 -- Check if some index is initialized with a non-constant value
13621
13622 Idx := First_Index (E);
13623 while Present (Idx) loop
13624 if Nkind (Idx) = N_Range then
13625 if not Is_Constant_Bound (Low_Bound (Idx))
13626 or else not Is_Constant_Bound (High_Bound (Idx))
13627 then
13628 return True;
13629 end if;
13630 end if;
13631
13632 Idx := Next_Index (Idx);
13633 end loop;
13634
13635 return False;
13636 end Is_Variable_Size_Array;
13637
13638 -----------------------------
13639 -- Is_Variable_Size_Record --
13640 -----------------------------
13641
13642 function Is_Variable_Size_Record (E : Entity_Id) return Boolean is
13643 Comp : Entity_Id;
13644 Comp_Typ : Entity_Id;
13645
13646 begin
13647 pragma Assert (Is_Record_Type (E));
13648
13649 Comp := First_Entity (E);
13650 while Present (Comp) loop
13651 Comp_Typ := Etype (Comp);
13652
13653 -- Recursive call if the record type has discriminants
13654
13655 if Is_Record_Type (Comp_Typ)
13656 and then Has_Discriminants (Comp_Typ)
13657 and then Is_Variable_Size_Record (Comp_Typ)
13658 then
13659 return True;
13660
13661 elsif Is_Array_Type (Comp_Typ)
13662 and then Is_Variable_Size_Array (Comp_Typ)
13663 then
13664 return True;
13665 end if;
13666
13667 Next_Entity (Comp);
13668 end loop;
13669
13670 return False;
13671 end Is_Variable_Size_Record;
13672
13673 -----------------
13674 -- Is_Variable --
13675 -----------------
13676
13677 function Is_Variable
13678 (N : Node_Id;
13679 Use_Original_Node : Boolean := True) return Boolean
13680 is
13681 Orig_Node : Node_Id;
13682
13683 function In_Protected_Function (E : Entity_Id) return Boolean;
13684 -- Within a protected function, the private components of the enclosing
13685 -- protected type are constants. A function nested within a (protected)
13686 -- procedure is not itself protected. Within the body of a protected
13687 -- function the current instance of the protected type is a constant.
13688
13689 function Is_Variable_Prefix (P : Node_Id) return Boolean;
13690 -- Prefixes can involve implicit dereferences, in which case we must
13691 -- test for the case of a reference of a constant access type, which can
13692 -- can never be a variable.
13693
13694 ---------------------------
13695 -- In_Protected_Function --
13696 ---------------------------
13697
13698 function In_Protected_Function (E : Entity_Id) return Boolean is
13699 Prot : Entity_Id;
13700 S : Entity_Id;
13701
13702 begin
13703 -- E is the current instance of a type
13704
13705 if Is_Type (E) then
13706 Prot := E;
13707
13708 -- E is an object
13709
13710 else
13711 Prot := Scope (E);
13712 end if;
13713
13714 if not Is_Protected_Type (Prot) then
13715 return False;
13716
13717 else
13718 S := Current_Scope;
13719 while Present (S) and then S /= Prot loop
13720 if Ekind (S) = E_Function and then Scope (S) = Prot then
13721 return True;
13722 end if;
13723
13724 S := Scope (S);
13725 end loop;
13726
13727 return False;
13728 end if;
13729 end In_Protected_Function;
13730
13731 ------------------------
13732 -- Is_Variable_Prefix --
13733 ------------------------
13734
13735 function Is_Variable_Prefix (P : Node_Id) return Boolean is
13736 begin
13737 if Is_Access_Type (Etype (P)) then
13738 return not Is_Access_Constant (Root_Type (Etype (P)));
13739
13740 -- For the case of an indexed component whose prefix has a packed
13741 -- array type, the prefix has been rewritten into a type conversion.
13742 -- Determine variable-ness from the converted expression.
13743
13744 elsif Nkind (P) = N_Type_Conversion
13745 and then not Comes_From_Source (P)
13746 and then Is_Array_Type (Etype (P))
13747 and then Is_Packed (Etype (P))
13748 then
13749 return Is_Variable (Expression (P));
13750
13751 else
13752 return Is_Variable (P);
13753 end if;
13754 end Is_Variable_Prefix;
13755
13756 -- Start of processing for Is_Variable
13757
13758 begin
13759 -- Special check, allow x'Deref(expr) as a variable
13760
13761 if Nkind (N) = N_Attribute_Reference
13762 and then Attribute_Name (N) = Name_Deref
13763 then
13764 return True;
13765 end if;
13766
13767 -- Check if we perform the test on the original node since this may be a
13768 -- test of syntactic categories which must not be disturbed by whatever
13769 -- rewriting might have occurred. For example, an aggregate, which is
13770 -- certainly NOT a variable, could be turned into a variable by
13771 -- expansion.
13772
13773 if Use_Original_Node then
13774 Orig_Node := Original_Node (N);
13775 else
13776 Orig_Node := N;
13777 end if;
13778
13779 -- Definitely OK if Assignment_OK is set. Since this is something that
13780 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
13781
13782 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
13783 return True;
13784
13785 -- Normally we go to the original node, but there is one exception where
13786 -- we use the rewritten node, namely when it is an explicit dereference.
13787 -- The generated code may rewrite a prefix which is an access type with
13788 -- an explicit dereference. The dereference is a variable, even though
13789 -- the original node may not be (since it could be a constant of the
13790 -- access type).
13791
13792 -- In Ada 2005 we have a further case to consider: the prefix may be a
13793 -- function call given in prefix notation. The original node appears to
13794 -- be a selected component, but we need to examine the call.
13795
13796 elsif Nkind (N) = N_Explicit_Dereference
13797 and then Nkind (Orig_Node) /= N_Explicit_Dereference
13798 and then Present (Etype (Orig_Node))
13799 and then Is_Access_Type (Etype (Orig_Node))
13800 then
13801 -- Note that if the prefix is an explicit dereference that does not
13802 -- come from source, we must check for a rewritten function call in
13803 -- prefixed notation before other forms of rewriting, to prevent a
13804 -- compiler crash.
13805
13806 return
13807 (Nkind (Orig_Node) = N_Function_Call
13808 and then not Is_Access_Constant (Etype (Prefix (N))))
13809 or else
13810 Is_Variable_Prefix (Original_Node (Prefix (N)));
13811
13812 -- in Ada 2012, the dereference may have been added for a type with
13813 -- a declared implicit dereference aspect. Check that it is not an
13814 -- access to constant.
13815
13816 elsif Nkind (N) = N_Explicit_Dereference
13817 and then Present (Etype (Orig_Node))
13818 and then Ada_Version >= Ada_2012
13819 and then Has_Implicit_Dereference (Etype (Orig_Node))
13820 then
13821 return not Is_Access_Constant (Etype (Prefix (N)));
13822
13823 -- A function call is never a variable
13824
13825 elsif Nkind (N) = N_Function_Call then
13826 return False;
13827
13828 -- All remaining checks use the original node
13829
13830 elsif Is_Entity_Name (Orig_Node)
13831 and then Present (Entity (Orig_Node))
13832 then
13833 declare
13834 E : constant Entity_Id := Entity (Orig_Node);
13835 K : constant Entity_Kind := Ekind (E);
13836
13837 begin
13838 return (K = E_Variable
13839 and then Nkind (Parent (E)) /= N_Exception_Handler)
13840 or else (K = E_Component
13841 and then not In_Protected_Function (E))
13842 or else K = E_Out_Parameter
13843 or else K = E_In_Out_Parameter
13844 or else K = E_Generic_In_Out_Parameter
13845
13846 -- Current instance of type. If this is a protected type, check
13847 -- we are not within the body of one of its protected functions.
13848
13849 or else (Is_Type (E)
13850 and then In_Open_Scopes (E)
13851 and then not In_Protected_Function (E))
13852
13853 or else (Is_Incomplete_Or_Private_Type (E)
13854 and then In_Open_Scopes (Full_View (E)));
13855 end;
13856
13857 else
13858 case Nkind (Orig_Node) is
13859 when N_Indexed_Component | N_Slice =>
13860 return Is_Variable_Prefix (Prefix (Orig_Node));
13861
13862 when N_Selected_Component =>
13863 return (Is_Variable (Selector_Name (Orig_Node))
13864 and then Is_Variable_Prefix (Prefix (Orig_Node)))
13865 or else
13866 (Nkind (N) = N_Expanded_Name
13867 and then Scope (Entity (N)) = Entity (Prefix (N)));
13868
13869 -- For an explicit dereference, the type of the prefix cannot
13870 -- be an access to constant or an access to subprogram.
13871
13872 when N_Explicit_Dereference =>
13873 declare
13874 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
13875 begin
13876 return Is_Access_Type (Typ)
13877 and then not Is_Access_Constant (Root_Type (Typ))
13878 and then Ekind (Typ) /= E_Access_Subprogram_Type;
13879 end;
13880
13881 -- The type conversion is the case where we do not deal with the
13882 -- context dependent special case of an actual parameter. Thus
13883 -- the type conversion is only considered a variable for the
13884 -- purposes of this routine if the target type is tagged. However,
13885 -- a type conversion is considered to be a variable if it does not
13886 -- come from source (this deals for example with the conversions
13887 -- of expressions to their actual subtypes).
13888
13889 when N_Type_Conversion =>
13890 return Is_Variable (Expression (Orig_Node))
13891 and then
13892 (not Comes_From_Source (Orig_Node)
13893 or else
13894 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
13895 and then
13896 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
13897
13898 -- GNAT allows an unchecked type conversion as a variable. This
13899 -- only affects the generation of internal expanded code, since
13900 -- calls to instantiations of Unchecked_Conversion are never
13901 -- considered variables (since they are function calls).
13902
13903 when N_Unchecked_Type_Conversion =>
13904 return Is_Variable (Expression (Orig_Node));
13905
13906 when others =>
13907 return False;
13908 end case;
13909 end if;
13910 end Is_Variable;
13911
13912 ---------------------------
13913 -- Is_Visibly_Controlled --
13914 ---------------------------
13915
13916 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
13917 Root : constant Entity_Id := Root_Type (T);
13918 begin
13919 return Chars (Scope (Root)) = Name_Finalization
13920 and then Chars (Scope (Scope (Root))) = Name_Ada
13921 and then Scope (Scope (Scope (Root))) = Standard_Standard;
13922 end Is_Visibly_Controlled;
13923
13924 --------------------------
13925 -- Is_Volatile_Function --
13926 --------------------------
13927
13928 function Is_Volatile_Function (Func_Id : Entity_Id) return Boolean is
13929 begin
13930 -- The caller must ensure that Func_Id denotes a function
13931
13932 pragma Assert (Ekind_In (Func_Id, E_Function, E_Generic_Function));
13933
13934 -- A protected function is automatically volatile
13935
13936 if Is_Primitive (Func_Id)
13937 and then Present (First_Formal (Func_Id))
13938 and then Is_Protected_Type (Etype (First_Formal (Func_Id)))
13939 then
13940 return True;
13941
13942 -- An instance of Ada.Unchecked_Conversion is a volatile function if
13943 -- either the source or the target are effectively volatile.
13944
13945 elsif Is_Unchecked_Conversion_Instance (Func_Id)
13946 and then Has_Effectively_Volatile_Profile (Func_Id)
13947 then
13948 return True;
13949
13950 -- Otherwise the function is treated as volatile if it is subject to
13951 -- enabled pragma Volatile_Function.
13952
13953 else
13954 return
13955 Is_Enabled_Pragma (Get_Pragma (Func_Id, Pragma_Volatile_Function));
13956 end if;
13957 end Is_Volatile_Function;
13958
13959 ------------------------
13960 -- Is_Volatile_Object --
13961 ------------------------
13962
13963 function Is_Volatile_Object (N : Node_Id) return Boolean is
13964
13965 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
13966 -- If prefix is an implicit dereference, examine designated type
13967
13968 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
13969 -- Determines if given object has volatile components
13970
13971 ------------------------
13972 -- Is_Volatile_Prefix --
13973 ------------------------
13974
13975 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
13976 Typ : constant Entity_Id := Etype (N);
13977
13978 begin
13979 if Is_Access_Type (Typ) then
13980 declare
13981 Dtyp : constant Entity_Id := Designated_Type (Typ);
13982
13983 begin
13984 return Is_Volatile (Dtyp)
13985 or else Has_Volatile_Components (Dtyp);
13986 end;
13987
13988 else
13989 return Object_Has_Volatile_Components (N);
13990 end if;
13991 end Is_Volatile_Prefix;
13992
13993 ------------------------------------
13994 -- Object_Has_Volatile_Components --
13995 ------------------------------------
13996
13997 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
13998 Typ : constant Entity_Id := Etype (N);
13999
14000 begin
14001 if Is_Volatile (Typ)
14002 or else Has_Volatile_Components (Typ)
14003 then
14004 return True;
14005
14006 elsif Is_Entity_Name (N)
14007 and then (Has_Volatile_Components (Entity (N))
14008 or else Is_Volatile (Entity (N)))
14009 then
14010 return True;
14011
14012 elsif Nkind (N) = N_Indexed_Component
14013 or else Nkind (N) = N_Selected_Component
14014 then
14015 return Is_Volatile_Prefix (Prefix (N));
14016
14017 else
14018 return False;
14019 end if;
14020 end Object_Has_Volatile_Components;
14021
14022 -- Start of processing for Is_Volatile_Object
14023
14024 begin
14025 if Nkind (N) = N_Defining_Identifier then
14026 return Is_Volatile (N) or else Is_Volatile (Etype (N));
14027
14028 elsif Nkind (N) = N_Expanded_Name then
14029 return Is_Volatile_Object (Entity (N));
14030
14031 elsif Is_Volatile (Etype (N))
14032 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
14033 then
14034 return True;
14035
14036 elsif Nkind_In (N, N_Indexed_Component, N_Selected_Component)
14037 and then Is_Volatile_Prefix (Prefix (N))
14038 then
14039 return True;
14040
14041 elsif Nkind (N) = N_Selected_Component
14042 and then Is_Volatile (Entity (Selector_Name (N)))
14043 then
14044 return True;
14045
14046 else
14047 return False;
14048 end if;
14049 end Is_Volatile_Object;
14050
14051 ---------------------------
14052 -- Itype_Has_Declaration --
14053 ---------------------------
14054
14055 function Itype_Has_Declaration (Id : Entity_Id) return Boolean is
14056 begin
14057 pragma Assert (Is_Itype (Id));
14058 return Present (Parent (Id))
14059 and then Nkind_In (Parent (Id), N_Full_Type_Declaration,
14060 N_Subtype_Declaration)
14061 and then Defining_Entity (Parent (Id)) = Id;
14062 end Itype_Has_Declaration;
14063
14064 -------------------------
14065 -- Kill_Current_Values --
14066 -------------------------
14067
14068 procedure Kill_Current_Values
14069 (Ent : Entity_Id;
14070 Last_Assignment_Only : Boolean := False)
14071 is
14072 begin
14073 if Is_Assignable (Ent) then
14074 Set_Last_Assignment (Ent, Empty);
14075 end if;
14076
14077 if Is_Object (Ent) then
14078 if not Last_Assignment_Only then
14079 Kill_Checks (Ent);
14080 Set_Current_Value (Ent, Empty);
14081
14082 -- Do not reset the Is_Known_[Non_]Null and Is_Known_Valid flags
14083 -- for a constant. Once the constant is elaborated, its value is
14084 -- not changed, therefore the associated flags that describe the
14085 -- value should not be modified either.
14086
14087 if Ekind (Ent) = E_Constant then
14088 null;
14089
14090 -- Non-constant entities
14091
14092 else
14093 if not Can_Never_Be_Null (Ent) then
14094 Set_Is_Known_Non_Null (Ent, False);
14095 end if;
14096
14097 Set_Is_Known_Null (Ent, False);
14098
14099 -- Reset the Is_Known_Valid flag unless the type is always
14100 -- valid. This does not apply to a loop parameter because its
14101 -- bounds are defined by the loop header and therefore always
14102 -- valid.
14103
14104 if not Is_Known_Valid (Etype (Ent))
14105 and then Ekind (Ent) /= E_Loop_Parameter
14106 then
14107 Set_Is_Known_Valid (Ent, False);
14108 end if;
14109 end if;
14110 end if;
14111 end if;
14112 end Kill_Current_Values;
14113
14114 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
14115 S : Entity_Id;
14116
14117 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
14118 -- Clear current value for entity E and all entities chained to E
14119
14120 ------------------------------------------
14121 -- Kill_Current_Values_For_Entity_Chain --
14122 ------------------------------------------
14123
14124 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
14125 Ent : Entity_Id;
14126 begin
14127 Ent := E;
14128 while Present (Ent) loop
14129 Kill_Current_Values (Ent, Last_Assignment_Only);
14130 Next_Entity (Ent);
14131 end loop;
14132 end Kill_Current_Values_For_Entity_Chain;
14133
14134 -- Start of processing for Kill_Current_Values
14135
14136 begin
14137 -- Kill all saved checks, a special case of killing saved values
14138
14139 if not Last_Assignment_Only then
14140 Kill_All_Checks;
14141 end if;
14142
14143 -- Loop through relevant scopes, which includes the current scope and
14144 -- any parent scopes if the current scope is a block or a package.
14145
14146 S := Current_Scope;
14147 Scope_Loop : loop
14148
14149 -- Clear current values of all entities in current scope
14150
14151 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
14152
14153 -- If scope is a package, also clear current values of all private
14154 -- entities in the scope.
14155
14156 if Is_Package_Or_Generic_Package (S)
14157 or else Is_Concurrent_Type (S)
14158 then
14159 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
14160 end if;
14161
14162 -- If this is a not a subprogram, deal with parents
14163
14164 if not Is_Subprogram (S) then
14165 S := Scope (S);
14166 exit Scope_Loop when S = Standard_Standard;
14167 else
14168 exit Scope_Loop;
14169 end if;
14170 end loop Scope_Loop;
14171 end Kill_Current_Values;
14172
14173 --------------------------
14174 -- Kill_Size_Check_Code --
14175 --------------------------
14176
14177 procedure Kill_Size_Check_Code (E : Entity_Id) is
14178 begin
14179 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
14180 and then Present (Size_Check_Code (E))
14181 then
14182 Remove (Size_Check_Code (E));
14183 Set_Size_Check_Code (E, Empty);
14184 end if;
14185 end Kill_Size_Check_Code;
14186
14187 --------------------------
14188 -- Known_To_Be_Assigned --
14189 --------------------------
14190
14191 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
14192 P : constant Node_Id := Parent (N);
14193
14194 begin
14195 case Nkind (P) is
14196
14197 -- Test left side of assignment
14198
14199 when N_Assignment_Statement =>
14200 return N = Name (P);
14201
14202 -- Function call arguments are never lvalues
14203
14204 when N_Function_Call =>
14205 return False;
14206
14207 -- Positional parameter for procedure or accept call
14208
14209 when N_Procedure_Call_Statement |
14210 N_Accept_Statement
14211 =>
14212 declare
14213 Proc : Entity_Id;
14214 Form : Entity_Id;
14215 Act : Node_Id;
14216
14217 begin
14218 Proc := Get_Subprogram_Entity (P);
14219
14220 if No (Proc) then
14221 return False;
14222 end if;
14223
14224 -- If we are not a list member, something is strange, so
14225 -- be conservative and return False.
14226
14227 if not Is_List_Member (N) then
14228 return False;
14229 end if;
14230
14231 -- We are going to find the right formal by stepping forward
14232 -- through the formals, as we step backwards in the actuals.
14233
14234 Form := First_Formal (Proc);
14235 Act := N;
14236 loop
14237 -- If no formal, something is weird, so be conservative
14238 -- and return False.
14239
14240 if No (Form) then
14241 return False;
14242 end if;
14243
14244 Prev (Act);
14245 exit when No (Act);
14246 Next_Formal (Form);
14247 end loop;
14248
14249 return Ekind (Form) /= E_In_Parameter;
14250 end;
14251
14252 -- Named parameter for procedure or accept call
14253
14254 when N_Parameter_Association =>
14255 declare
14256 Proc : Entity_Id;
14257 Form : Entity_Id;
14258
14259 begin
14260 Proc := Get_Subprogram_Entity (Parent (P));
14261
14262 if No (Proc) then
14263 return False;
14264 end if;
14265
14266 -- Loop through formals to find the one that matches
14267
14268 Form := First_Formal (Proc);
14269 loop
14270 -- If no matching formal, that's peculiar, some kind of
14271 -- previous error, so return False to be conservative.
14272 -- Actually this also happens in legal code in the case
14273 -- where P is a parameter association for an Extra_Formal???
14274
14275 if No (Form) then
14276 return False;
14277 end if;
14278
14279 -- Else test for match
14280
14281 if Chars (Form) = Chars (Selector_Name (P)) then
14282 return Ekind (Form) /= E_In_Parameter;
14283 end if;
14284
14285 Next_Formal (Form);
14286 end loop;
14287 end;
14288
14289 -- Test for appearing in a conversion that itself appears
14290 -- in an lvalue context, since this should be an lvalue.
14291
14292 when N_Type_Conversion =>
14293 return Known_To_Be_Assigned (P);
14294
14295 -- All other references are definitely not known to be modifications
14296
14297 when others =>
14298 return False;
14299
14300 end case;
14301 end Known_To_Be_Assigned;
14302
14303 ---------------------------
14304 -- Last_Source_Statement --
14305 ---------------------------
14306
14307 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
14308 N : Node_Id;
14309
14310 begin
14311 N := Last (Statements (HSS));
14312 while Present (N) loop
14313 exit when Comes_From_Source (N);
14314 Prev (N);
14315 end loop;
14316
14317 return N;
14318 end Last_Source_Statement;
14319
14320 ----------------------------------
14321 -- Matching_Static_Array_Bounds --
14322 ----------------------------------
14323
14324 function Matching_Static_Array_Bounds
14325 (L_Typ : Node_Id;
14326 R_Typ : Node_Id) return Boolean
14327 is
14328 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
14329 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
14330
14331 L_Index : Node_Id;
14332 R_Index : Node_Id;
14333 L_Low : Node_Id;
14334 L_High : Node_Id;
14335 L_Len : Uint;
14336 R_Low : Node_Id;
14337 R_High : Node_Id;
14338 R_Len : Uint;
14339
14340 begin
14341 if L_Ndims /= R_Ndims then
14342 return False;
14343 end if;
14344
14345 -- Unconstrained types do not have static bounds
14346
14347 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
14348 return False;
14349 end if;
14350
14351 -- First treat specially the first dimension, as the lower bound and
14352 -- length of string literals are not stored like those of arrays.
14353
14354 if Ekind (L_Typ) = E_String_Literal_Subtype then
14355 L_Low := String_Literal_Low_Bound (L_Typ);
14356 L_Len := String_Literal_Length (L_Typ);
14357 else
14358 L_Index := First_Index (L_Typ);
14359 Get_Index_Bounds (L_Index, L_Low, L_High);
14360
14361 if Is_OK_Static_Expression (L_Low)
14362 and then
14363 Is_OK_Static_Expression (L_High)
14364 then
14365 if Expr_Value (L_High) < Expr_Value (L_Low) then
14366 L_Len := Uint_0;
14367 else
14368 L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
14369 end if;
14370 else
14371 return False;
14372 end if;
14373 end if;
14374
14375 if Ekind (R_Typ) = E_String_Literal_Subtype then
14376 R_Low := String_Literal_Low_Bound (R_Typ);
14377 R_Len := String_Literal_Length (R_Typ);
14378 else
14379 R_Index := First_Index (R_Typ);
14380 Get_Index_Bounds (R_Index, R_Low, R_High);
14381
14382 if Is_OK_Static_Expression (R_Low)
14383 and then
14384 Is_OK_Static_Expression (R_High)
14385 then
14386 if Expr_Value (R_High) < Expr_Value (R_Low) then
14387 R_Len := Uint_0;
14388 else
14389 R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
14390 end if;
14391 else
14392 return False;
14393 end if;
14394 end if;
14395
14396 if (Is_OK_Static_Expression (L_Low)
14397 and then
14398 Is_OK_Static_Expression (R_Low))
14399 and then Expr_Value (L_Low) = Expr_Value (R_Low)
14400 and then L_Len = R_Len
14401 then
14402 null;
14403 else
14404 return False;
14405 end if;
14406
14407 -- Then treat all other dimensions
14408
14409 for Indx in 2 .. L_Ndims loop
14410 Next (L_Index);
14411 Next (R_Index);
14412
14413 Get_Index_Bounds (L_Index, L_Low, L_High);
14414 Get_Index_Bounds (R_Index, R_Low, R_High);
14415
14416 if (Is_OK_Static_Expression (L_Low) and then
14417 Is_OK_Static_Expression (L_High) and then
14418 Is_OK_Static_Expression (R_Low) and then
14419 Is_OK_Static_Expression (R_High))
14420 and then (Expr_Value (L_Low) = Expr_Value (R_Low)
14421 and then
14422 Expr_Value (L_High) = Expr_Value (R_High))
14423 then
14424 null;
14425 else
14426 return False;
14427 end if;
14428 end loop;
14429
14430 -- If we fall through the loop, all indexes matched
14431
14432 return True;
14433 end Matching_Static_Array_Bounds;
14434
14435 -------------------
14436 -- May_Be_Lvalue --
14437 -------------------
14438
14439 function May_Be_Lvalue (N : Node_Id) return Boolean is
14440 P : constant Node_Id := Parent (N);
14441
14442 begin
14443 case Nkind (P) is
14444
14445 -- Test left side of assignment
14446
14447 when N_Assignment_Statement =>
14448 return N = Name (P);
14449
14450 -- Test prefix of component or attribute. Note that the prefix of an
14451 -- explicit or implicit dereference cannot be an l-value.
14452
14453 when N_Attribute_Reference =>
14454 return N = Prefix (P)
14455 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P));
14456
14457 -- For an expanded name, the name is an lvalue if the expanded name
14458 -- is an lvalue, but the prefix is never an lvalue, since it is just
14459 -- the scope where the name is found.
14460
14461 when N_Expanded_Name =>
14462 if N = Prefix (P) then
14463 return May_Be_Lvalue (P);
14464 else
14465 return False;
14466 end if;
14467
14468 -- For a selected component A.B, A is certainly an lvalue if A.B is.
14469 -- B is a little interesting, if we have A.B := 3, there is some
14470 -- discussion as to whether B is an lvalue or not, we choose to say
14471 -- it is. Note however that A is not an lvalue if it is of an access
14472 -- type since this is an implicit dereference.
14473
14474 when N_Selected_Component =>
14475 if N = Prefix (P)
14476 and then Present (Etype (N))
14477 and then Is_Access_Type (Etype (N))
14478 then
14479 return False;
14480 else
14481 return May_Be_Lvalue (P);
14482 end if;
14483
14484 -- For an indexed component or slice, the index or slice bounds is
14485 -- never an lvalue. The prefix is an lvalue if the indexed component
14486 -- or slice is an lvalue, except if it is an access type, where we
14487 -- have an implicit dereference.
14488
14489 when N_Indexed_Component | N_Slice =>
14490 if N /= Prefix (P)
14491 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
14492 then
14493 return False;
14494 else
14495 return May_Be_Lvalue (P);
14496 end if;
14497
14498 -- Prefix of a reference is an lvalue if the reference is an lvalue
14499
14500 when N_Reference =>
14501 return May_Be_Lvalue (P);
14502
14503 -- Prefix of explicit dereference is never an lvalue
14504
14505 when N_Explicit_Dereference =>
14506 return False;
14507
14508 -- Positional parameter for subprogram, entry, or accept call.
14509 -- In older versions of Ada function call arguments are never
14510 -- lvalues. In Ada 2012 functions can have in-out parameters.
14511
14512 when N_Subprogram_Call |
14513 N_Entry_Call_Statement |
14514 N_Accept_Statement
14515 =>
14516 if Nkind (P) = N_Function_Call and then Ada_Version < Ada_2012 then
14517 return False;
14518 end if;
14519
14520 -- The following mechanism is clumsy and fragile. A single flag
14521 -- set in Resolve_Actuals would be preferable ???
14522
14523 declare
14524 Proc : Entity_Id;
14525 Form : Entity_Id;
14526 Act : Node_Id;
14527
14528 begin
14529 Proc := Get_Subprogram_Entity (P);
14530
14531 if No (Proc) then
14532 return True;
14533 end if;
14534
14535 -- If we are not a list member, something is strange, so be
14536 -- conservative and return True.
14537
14538 if not Is_List_Member (N) then
14539 return True;
14540 end if;
14541
14542 -- We are going to find the right formal by stepping forward
14543 -- through the formals, as we step backwards in the actuals.
14544
14545 Form := First_Formal (Proc);
14546 Act := N;
14547 loop
14548 -- If no formal, something is weird, so be conservative and
14549 -- return True.
14550
14551 if No (Form) then
14552 return True;
14553 end if;
14554
14555 Prev (Act);
14556 exit when No (Act);
14557 Next_Formal (Form);
14558 end loop;
14559
14560 return Ekind (Form) /= E_In_Parameter;
14561 end;
14562
14563 -- Named parameter for procedure or accept call
14564
14565 when N_Parameter_Association =>
14566 declare
14567 Proc : Entity_Id;
14568 Form : Entity_Id;
14569
14570 begin
14571 Proc := Get_Subprogram_Entity (Parent (P));
14572
14573 if No (Proc) then
14574 return True;
14575 end if;
14576
14577 -- Loop through formals to find the one that matches
14578
14579 Form := First_Formal (Proc);
14580 loop
14581 -- If no matching formal, that's peculiar, some kind of
14582 -- previous error, so return True to be conservative.
14583 -- Actually happens with legal code for an unresolved call
14584 -- where we may get the wrong homonym???
14585
14586 if No (Form) then
14587 return True;
14588 end if;
14589
14590 -- Else test for match
14591
14592 if Chars (Form) = Chars (Selector_Name (P)) then
14593 return Ekind (Form) /= E_In_Parameter;
14594 end if;
14595
14596 Next_Formal (Form);
14597 end loop;
14598 end;
14599
14600 -- Test for appearing in a conversion that itself appears in an
14601 -- lvalue context, since this should be an lvalue.
14602
14603 when N_Type_Conversion =>
14604 return May_Be_Lvalue (P);
14605
14606 -- Test for appearance in object renaming declaration
14607
14608 when N_Object_Renaming_Declaration =>
14609 return True;
14610
14611 -- All other references are definitely not lvalues
14612
14613 when others =>
14614 return False;
14615
14616 end case;
14617 end May_Be_Lvalue;
14618
14619 -----------------------
14620 -- Mark_Coextensions --
14621 -----------------------
14622
14623 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
14624 Is_Dynamic : Boolean;
14625 -- Indicates whether the context causes nested coextensions to be
14626 -- dynamic or static
14627
14628 function Mark_Allocator (N : Node_Id) return Traverse_Result;
14629 -- Recognize an allocator node and label it as a dynamic coextension
14630
14631 --------------------
14632 -- Mark_Allocator --
14633 --------------------
14634
14635 function Mark_Allocator (N : Node_Id) return Traverse_Result is
14636 begin
14637 if Nkind (N) = N_Allocator then
14638 if Is_Dynamic then
14639 Set_Is_Dynamic_Coextension (N);
14640
14641 -- If the allocator expression is potentially dynamic, it may
14642 -- be expanded out of order and require dynamic allocation
14643 -- anyway, so we treat the coextension itself as dynamic.
14644 -- Potential optimization ???
14645
14646 elsif Nkind (Expression (N)) = N_Qualified_Expression
14647 and then Nkind (Expression (Expression (N))) = N_Op_Concat
14648 then
14649 Set_Is_Dynamic_Coextension (N);
14650 else
14651 Set_Is_Static_Coextension (N);
14652 end if;
14653 end if;
14654
14655 return OK;
14656 end Mark_Allocator;
14657
14658 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
14659
14660 -- Start of processing for Mark_Coextensions
14661
14662 begin
14663 -- An allocator that appears on the right-hand side of an assignment is
14664 -- treated as a potentially dynamic coextension when the right-hand side
14665 -- is an allocator or a qualified expression.
14666
14667 -- Obj := new ...'(new Coextension ...);
14668
14669 if Nkind (Context_Nod) = N_Assignment_Statement then
14670 Is_Dynamic :=
14671 Nkind_In (Expression (Context_Nod), N_Allocator,
14672 N_Qualified_Expression);
14673
14674 -- An allocator that appears within the expression of a simple return
14675 -- statement is treated as a potentially dynamic coextension when the
14676 -- expression is either aggregate, allocator, or qualified expression.
14677
14678 -- return (new Coextension ...);
14679 -- return new ...'(new Coextension ...);
14680
14681 elsif Nkind (Context_Nod) = N_Simple_Return_Statement then
14682 Is_Dynamic :=
14683 Nkind_In (Expression (Context_Nod), N_Aggregate,
14684 N_Allocator,
14685 N_Qualified_Expression);
14686
14687 -- An alloctor that appears within the initialization expression of an
14688 -- object declaration is considered a potentially dynamic coextension
14689 -- when the initialization expression is an allocator or a qualified
14690 -- expression.
14691
14692 -- Obj : ... := new ...'(new Coextension ...);
14693
14694 -- A similar case arises when the object declaration is part of an
14695 -- extended return statement.
14696
14697 -- return Obj : ... := new ...'(new Coextension ...);
14698 -- return Obj : ... := (new Coextension ...);
14699
14700 elsif Nkind (Context_Nod) = N_Object_Declaration then
14701 Is_Dynamic :=
14702 Nkind_In (Root_Nod, N_Allocator, N_Qualified_Expression)
14703 or else
14704 Nkind (Parent (Context_Nod)) = N_Extended_Return_Statement;
14705
14706 -- This routine should not be called with constructs that cannot contain
14707 -- coextensions.
14708
14709 else
14710 raise Program_Error;
14711 end if;
14712
14713 Mark_Allocators (Root_Nod);
14714 end Mark_Coextensions;
14715
14716 ----------------------
14717 -- Needs_One_Actual --
14718 ----------------------
14719
14720 function Needs_One_Actual (E : Entity_Id) return Boolean is
14721 Formal : Entity_Id;
14722
14723 begin
14724 -- Ada 2005 or later, and formals present
14725
14726 if Ada_Version >= Ada_2005 and then Present (First_Formal (E)) then
14727 Formal := Next_Formal (First_Formal (E));
14728 while Present (Formal) loop
14729 if No (Default_Value (Formal)) then
14730 return False;
14731 end if;
14732
14733 Next_Formal (Formal);
14734 end loop;
14735
14736 return True;
14737
14738 -- Ada 83/95 or no formals
14739
14740 else
14741 return False;
14742 end if;
14743 end Needs_One_Actual;
14744
14745 ------------------------
14746 -- New_Copy_List_Tree --
14747 ------------------------
14748
14749 function New_Copy_List_Tree (List : List_Id) return List_Id is
14750 NL : List_Id;
14751 E : Node_Id;
14752
14753 begin
14754 if List = No_List then
14755 return No_List;
14756
14757 else
14758 NL := New_List;
14759 E := First (List);
14760
14761 while Present (E) loop
14762 Append (New_Copy_Tree (E), NL);
14763 E := Next (E);
14764 end loop;
14765
14766 return NL;
14767 end if;
14768 end New_Copy_List_Tree;
14769
14770 --------------------------------------------------
14771 -- New_Copy_Tree Auxiliary Data and Subprograms --
14772 --------------------------------------------------
14773
14774 use Atree.Unchecked_Access;
14775 use Atree_Private_Part;
14776
14777 -- Our approach here requires a two pass traversal of the tree. The
14778 -- first pass visits all nodes that eventually will be copied looking
14779 -- for defining Itypes. If any defining Itypes are found, then they are
14780 -- copied, and an entry is added to the replacement map. In the second
14781 -- phase, the tree is copied, using the replacement map to replace any
14782 -- Itype references within the copied tree.
14783
14784 -- The following hash tables are used if the Map supplied has more
14785 -- than hash threshold entries to speed up access to the map. If
14786 -- there are fewer entries, then the map is searched sequentially
14787 -- (because setting up a hash table for only a few entries takes
14788 -- more time than it saves.
14789
14790 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num;
14791 -- Hash function used for hash operations
14792
14793 -------------------
14794 -- New_Copy_Hash --
14795 -------------------
14796
14797 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num is
14798 begin
14799 return Nat (E) mod (NCT_Header_Num'Last + 1);
14800 end New_Copy_Hash;
14801
14802 ---------------
14803 -- NCT_Assoc --
14804 ---------------
14805
14806 -- The hash table NCT_Assoc associates old entities in the table
14807 -- with their corresponding new entities (i.e. the pairs of entries
14808 -- presented in the original Map argument are Key-Element pairs).
14809
14810 package NCT_Assoc is new Simple_HTable (
14811 Header_Num => NCT_Header_Num,
14812 Element => Entity_Id,
14813 No_Element => Empty,
14814 Key => Entity_Id,
14815 Hash => New_Copy_Hash,
14816 Equal => Types."=");
14817
14818 ---------------------
14819 -- NCT_Itype_Assoc --
14820 ---------------------
14821
14822 -- The hash table NCT_Itype_Assoc contains entries only for those
14823 -- old nodes which have a non-empty Associated_Node_For_Itype set.
14824 -- The key is the associated node, and the element is the new node
14825 -- itself (NOT the associated node for the new node).
14826
14827 package NCT_Itype_Assoc is new Simple_HTable (
14828 Header_Num => NCT_Header_Num,
14829 Element => Entity_Id,
14830 No_Element => Empty,
14831 Key => Entity_Id,
14832 Hash => New_Copy_Hash,
14833 Equal => Types."=");
14834
14835 -------------------
14836 -- New_Copy_Tree --
14837 -------------------
14838
14839 function New_Copy_Tree
14840 (Source : Node_Id;
14841 Map : Elist_Id := No_Elist;
14842 New_Sloc : Source_Ptr := No_Location;
14843 New_Scope : Entity_Id := Empty) return Node_Id
14844 is
14845 Actual_Map : Elist_Id := Map;
14846 -- This is the actual map for the copy. It is initialized with the
14847 -- given elements, and then enlarged as required for Itypes that are
14848 -- copied during the first phase of the copy operation. The visit
14849 -- procedures add elements to this map as Itypes are encountered.
14850 -- The reason we cannot use Map directly, is that it may well be
14851 -- (and normally is) initialized to No_Elist, and if we have mapped
14852 -- entities, we have to reset it to point to a real Elist.
14853
14854 function Assoc (N : Node_Or_Entity_Id) return Node_Id;
14855 -- Called during second phase to map entities into their corresponding
14856 -- copies using Actual_Map. If the argument is not an entity, or is not
14857 -- in Actual_Map, then it is returned unchanged.
14858
14859 procedure Build_NCT_Hash_Tables;
14860 -- Builds hash tables (number of elements >= threshold value)
14861
14862 function Copy_Elist_With_Replacement
14863 (Old_Elist : Elist_Id) return Elist_Id;
14864 -- Called during second phase to copy element list doing replacements
14865
14866 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id);
14867 -- Called during the second phase to process a copied Itype. The actual
14868 -- copy happened during the first phase (so that we could make the entry
14869 -- in the mapping), but we still have to deal with the descendents of
14870 -- the copied Itype and copy them where necessary.
14871
14872 function Copy_List_With_Replacement (Old_List : List_Id) return List_Id;
14873 -- Called during second phase to copy list doing replacements
14874
14875 function Copy_Node_With_Replacement (Old_Node : Node_Id) return Node_Id;
14876 -- Called during second phase to copy node doing replacements
14877
14878 procedure Visit_Elist (E : Elist_Id);
14879 -- Called during first phase to visit all elements of an Elist
14880
14881 procedure Visit_Field (F : Union_Id; N : Node_Id);
14882 -- Visit a single field, recursing to call Visit_Node or Visit_List
14883 -- if the field is a syntactic descendent of the current node (i.e.
14884 -- its parent is Node N).
14885
14886 procedure Visit_Itype (Old_Itype : Entity_Id);
14887 -- Called during first phase to visit subsidiary fields of a defining
14888 -- Itype, and also create a copy and make an entry in the replacement
14889 -- map for the new copy.
14890
14891 procedure Visit_List (L : List_Id);
14892 -- Called during first phase to visit all elements of a List
14893
14894 procedure Visit_Node (N : Node_Or_Entity_Id);
14895 -- Called during first phase to visit a node and all its subtrees
14896
14897 -----------
14898 -- Assoc --
14899 -----------
14900
14901 function Assoc (N : Node_Or_Entity_Id) return Node_Id is
14902 E : Elmt_Id;
14903 Ent : Entity_Id;
14904
14905 begin
14906 if not Has_Extension (N) or else No (Actual_Map) then
14907 return N;
14908
14909 elsif NCT_Hash_Tables_Used then
14910 Ent := NCT_Assoc.Get (Entity_Id (N));
14911
14912 if Present (Ent) then
14913 return Ent;
14914 else
14915 return N;
14916 end if;
14917
14918 -- No hash table used, do serial search
14919
14920 else
14921 E := First_Elmt (Actual_Map);
14922 while Present (E) loop
14923 if Node (E) = N then
14924 return Node (Next_Elmt (E));
14925 else
14926 E := Next_Elmt (Next_Elmt (E));
14927 end if;
14928 end loop;
14929 end if;
14930
14931 return N;
14932 end Assoc;
14933
14934 ---------------------------
14935 -- Build_NCT_Hash_Tables --
14936 ---------------------------
14937
14938 procedure Build_NCT_Hash_Tables is
14939 Elmt : Elmt_Id;
14940 Ent : Entity_Id;
14941 begin
14942 if NCT_Hash_Table_Setup then
14943 NCT_Assoc.Reset;
14944 NCT_Itype_Assoc.Reset;
14945 end if;
14946
14947 Elmt := First_Elmt (Actual_Map);
14948 while Present (Elmt) loop
14949 Ent := Node (Elmt);
14950
14951 -- Get new entity, and associate old and new
14952
14953 Next_Elmt (Elmt);
14954 NCT_Assoc.Set (Ent, Node (Elmt));
14955
14956 if Is_Type (Ent) then
14957 declare
14958 Anode : constant Entity_Id :=
14959 Associated_Node_For_Itype (Ent);
14960
14961 begin
14962 if Present (Anode) then
14963
14964 -- Enter a link between the associated node of the
14965 -- old Itype and the new Itype, for updating later
14966 -- when node is copied.
14967
14968 NCT_Itype_Assoc.Set (Anode, Node (Elmt));
14969 end if;
14970 end;
14971 end if;
14972
14973 Next_Elmt (Elmt);
14974 end loop;
14975
14976 NCT_Hash_Tables_Used := True;
14977 NCT_Hash_Table_Setup := True;
14978 end Build_NCT_Hash_Tables;
14979
14980 ---------------------------------
14981 -- Copy_Elist_With_Replacement --
14982 ---------------------------------
14983
14984 function Copy_Elist_With_Replacement
14985 (Old_Elist : Elist_Id) return Elist_Id
14986 is
14987 M : Elmt_Id;
14988 New_Elist : Elist_Id;
14989
14990 begin
14991 if No (Old_Elist) then
14992 return No_Elist;
14993
14994 else
14995 New_Elist := New_Elmt_List;
14996
14997 M := First_Elmt (Old_Elist);
14998 while Present (M) loop
14999 Append_Elmt (Copy_Node_With_Replacement (Node (M)), New_Elist);
15000 Next_Elmt (M);
15001 end loop;
15002 end if;
15003
15004 return New_Elist;
15005 end Copy_Elist_With_Replacement;
15006
15007 ---------------------------------
15008 -- Copy_Itype_With_Replacement --
15009 ---------------------------------
15010
15011 -- This routine exactly parallels its phase one analog Visit_Itype,
15012
15013 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id) is
15014 begin
15015 -- Translate Next_Entity, Scope and Etype fields, in case they
15016 -- reference entities that have been mapped into copies.
15017
15018 Set_Next_Entity (New_Itype, Assoc (Next_Entity (New_Itype)));
15019 Set_Etype (New_Itype, Assoc (Etype (New_Itype)));
15020
15021 if Present (New_Scope) then
15022 Set_Scope (New_Itype, New_Scope);
15023 else
15024 Set_Scope (New_Itype, Assoc (Scope (New_Itype)));
15025 end if;
15026
15027 -- Copy referenced fields
15028
15029 if Is_Discrete_Type (New_Itype) then
15030 Set_Scalar_Range (New_Itype,
15031 Copy_Node_With_Replacement (Scalar_Range (New_Itype)));
15032
15033 elsif Has_Discriminants (Base_Type (New_Itype)) then
15034 Set_Discriminant_Constraint (New_Itype,
15035 Copy_Elist_With_Replacement
15036 (Discriminant_Constraint (New_Itype)));
15037
15038 elsif Is_Array_Type (New_Itype) then
15039 if Present (First_Index (New_Itype)) then
15040 Set_First_Index (New_Itype,
15041 First (Copy_List_With_Replacement
15042 (List_Containing (First_Index (New_Itype)))));
15043 end if;
15044
15045 if Is_Packed (New_Itype) then
15046 Set_Packed_Array_Impl_Type (New_Itype,
15047 Copy_Node_With_Replacement
15048 (Packed_Array_Impl_Type (New_Itype)));
15049 end if;
15050 end if;
15051 end Copy_Itype_With_Replacement;
15052
15053 --------------------------------
15054 -- Copy_List_With_Replacement --
15055 --------------------------------
15056
15057 function Copy_List_With_Replacement
15058 (Old_List : List_Id) return List_Id
15059 is
15060 New_List : List_Id;
15061 E : Node_Id;
15062
15063 begin
15064 if Old_List = No_List then
15065 return No_List;
15066
15067 else
15068 New_List := Empty_List;
15069
15070 E := First (Old_List);
15071 while Present (E) loop
15072 Append (Copy_Node_With_Replacement (E), New_List);
15073 Next (E);
15074 end loop;
15075
15076 return New_List;
15077 end if;
15078 end Copy_List_With_Replacement;
15079
15080 --------------------------------
15081 -- Copy_Node_With_Replacement --
15082 --------------------------------
15083
15084 function Copy_Node_With_Replacement
15085 (Old_Node : Node_Id) return Node_Id
15086 is
15087 New_Node : Node_Id;
15088
15089 procedure Adjust_Named_Associations
15090 (Old_Node : Node_Id;
15091 New_Node : Node_Id);
15092 -- If a call node has named associations, these are chained through
15093 -- the First_Named_Actual, Next_Named_Actual links. These must be
15094 -- propagated separately to the new parameter list, because these
15095 -- are not syntactic fields.
15096
15097 function Copy_Field_With_Replacement
15098 (Field : Union_Id) return Union_Id;
15099 -- Given Field, which is a field of Old_Node, return a copy of it
15100 -- if it is a syntactic field (i.e. its parent is Node), setting
15101 -- the parent of the copy to poit to New_Node. Otherwise returns
15102 -- the field (possibly mapped if it is an entity).
15103
15104 -------------------------------
15105 -- Adjust_Named_Associations --
15106 -------------------------------
15107
15108 procedure Adjust_Named_Associations
15109 (Old_Node : Node_Id;
15110 New_Node : Node_Id)
15111 is
15112 Old_E : Node_Id;
15113 New_E : Node_Id;
15114
15115 Old_Next : Node_Id;
15116 New_Next : Node_Id;
15117
15118 begin
15119 Old_E := First (Parameter_Associations (Old_Node));
15120 New_E := First (Parameter_Associations (New_Node));
15121 while Present (Old_E) loop
15122 if Nkind (Old_E) = N_Parameter_Association
15123 and then Present (Next_Named_Actual (Old_E))
15124 then
15125 if First_Named_Actual (Old_Node)
15126 = Explicit_Actual_Parameter (Old_E)
15127 then
15128 Set_First_Named_Actual
15129 (New_Node, Explicit_Actual_Parameter (New_E));
15130 end if;
15131
15132 -- Now scan parameter list from the beginning,to locate
15133 -- next named actual, which can be out of order.
15134
15135 Old_Next := First (Parameter_Associations (Old_Node));
15136 New_Next := First (Parameter_Associations (New_Node));
15137
15138 while Nkind (Old_Next) /= N_Parameter_Association
15139 or else Explicit_Actual_Parameter (Old_Next) /=
15140 Next_Named_Actual (Old_E)
15141 loop
15142 Next (Old_Next);
15143 Next (New_Next);
15144 end loop;
15145
15146 Set_Next_Named_Actual
15147 (New_E, Explicit_Actual_Parameter (New_Next));
15148 end if;
15149
15150 Next (Old_E);
15151 Next (New_E);
15152 end loop;
15153 end Adjust_Named_Associations;
15154
15155 ---------------------------------
15156 -- Copy_Field_With_Replacement --
15157 ---------------------------------
15158
15159 function Copy_Field_With_Replacement
15160 (Field : Union_Id) return Union_Id
15161 is
15162 begin
15163 if Field = Union_Id (Empty) then
15164 return Field;
15165
15166 elsif Field in Node_Range then
15167 declare
15168 Old_N : constant Node_Id := Node_Id (Field);
15169 New_N : Node_Id;
15170
15171 begin
15172 -- If syntactic field, as indicated by the parent pointer
15173 -- being set, then copy the referenced node recursively.
15174
15175 if Parent (Old_N) = Old_Node then
15176 New_N := Copy_Node_With_Replacement (Old_N);
15177
15178 if New_N /= Old_N then
15179 Set_Parent (New_N, New_Node);
15180 end if;
15181
15182 -- For semantic fields, update possible entity reference
15183 -- from the replacement map.
15184
15185 else
15186 New_N := Assoc (Old_N);
15187 end if;
15188
15189 return Union_Id (New_N);
15190 end;
15191
15192 elsif Field in List_Range then
15193 declare
15194 Old_L : constant List_Id := List_Id (Field);
15195 New_L : List_Id;
15196
15197 begin
15198 -- If syntactic field, as indicated by the parent pointer,
15199 -- then recursively copy the entire referenced list.
15200
15201 if Parent (Old_L) = Old_Node then
15202 New_L := Copy_List_With_Replacement (Old_L);
15203 Set_Parent (New_L, New_Node);
15204
15205 -- For semantic list, just returned unchanged
15206
15207 else
15208 New_L := Old_L;
15209 end if;
15210
15211 return Union_Id (New_L);
15212 end;
15213
15214 -- Anything other than a list or a node is returned unchanged
15215
15216 else
15217 return Field;
15218 end if;
15219 end Copy_Field_With_Replacement;
15220
15221 -- Start of processing for Copy_Node_With_Replacement
15222
15223 begin
15224 if Old_Node <= Empty_Or_Error then
15225 return Old_Node;
15226
15227 elsif Has_Extension (Old_Node) then
15228 return Assoc (Old_Node);
15229
15230 else
15231 New_Node := New_Copy (Old_Node);
15232
15233 -- If the node we are copying is the associated node of a
15234 -- previously copied Itype, then adjust the associated node
15235 -- of the copy of that Itype accordingly.
15236
15237 if Present (Actual_Map) then
15238 declare
15239 E : Elmt_Id;
15240 Ent : Entity_Id;
15241
15242 begin
15243 -- Case of hash table used
15244
15245 if NCT_Hash_Tables_Used then
15246 Ent := NCT_Itype_Assoc.Get (Old_Node);
15247
15248 if Present (Ent) then
15249 Set_Associated_Node_For_Itype (Ent, New_Node);
15250 end if;
15251
15252 -- Case of no hash table used
15253
15254 else
15255 E := First_Elmt (Actual_Map);
15256 while Present (E) loop
15257 if Is_Itype (Node (E))
15258 and then
15259 Old_Node = Associated_Node_For_Itype (Node (E))
15260 then
15261 Set_Associated_Node_For_Itype
15262 (Node (Next_Elmt (E)), New_Node);
15263 end if;
15264
15265 E := Next_Elmt (Next_Elmt (E));
15266 end loop;
15267 end if;
15268 end;
15269 end if;
15270
15271 -- Recursively copy descendents
15272
15273 Set_Field1
15274 (New_Node, Copy_Field_With_Replacement (Field1 (New_Node)));
15275 Set_Field2
15276 (New_Node, Copy_Field_With_Replacement (Field2 (New_Node)));
15277 Set_Field3
15278 (New_Node, Copy_Field_With_Replacement (Field3 (New_Node)));
15279 Set_Field4
15280 (New_Node, Copy_Field_With_Replacement (Field4 (New_Node)));
15281 Set_Field5
15282 (New_Node, Copy_Field_With_Replacement (Field5 (New_Node)));
15283
15284 -- Adjust Sloc of new node if necessary
15285
15286 if New_Sloc /= No_Location then
15287 Set_Sloc (New_Node, New_Sloc);
15288
15289 -- If we adjust the Sloc, then we are essentially making
15290 -- a completely new node, so the Comes_From_Source flag
15291 -- should be reset to the proper default value.
15292
15293 Nodes.Table (New_Node).Comes_From_Source :=
15294 Default_Node.Comes_From_Source;
15295 end if;
15296
15297 -- If the node is call and has named associations,
15298 -- set the corresponding links in the copy.
15299
15300 if (Nkind (Old_Node) = N_Function_Call
15301 or else Nkind (Old_Node) = N_Entry_Call_Statement
15302 or else
15303 Nkind (Old_Node) = N_Procedure_Call_Statement)
15304 and then Present (First_Named_Actual (Old_Node))
15305 then
15306 Adjust_Named_Associations (Old_Node, New_Node);
15307 end if;
15308
15309 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
15310 -- The replacement mechanism applies to entities, and is not used
15311 -- here. Eventually we may need a more general graph-copying
15312 -- routine. For now, do a sequential search to find desired node.
15313
15314 if Nkind (Old_Node) = N_Handled_Sequence_Of_Statements
15315 and then Present (First_Real_Statement (Old_Node))
15316 then
15317 declare
15318 Old_F : constant Node_Id := First_Real_Statement (Old_Node);
15319 N1, N2 : Node_Id;
15320
15321 begin
15322 N1 := First (Statements (Old_Node));
15323 N2 := First (Statements (New_Node));
15324
15325 while N1 /= Old_F loop
15326 Next (N1);
15327 Next (N2);
15328 end loop;
15329
15330 Set_First_Real_Statement (New_Node, N2);
15331 end;
15332 end if;
15333 end if;
15334
15335 -- All done, return copied node
15336
15337 return New_Node;
15338 end Copy_Node_With_Replacement;
15339
15340 -----------------
15341 -- Visit_Elist --
15342 -----------------
15343
15344 procedure Visit_Elist (E : Elist_Id) is
15345 Elmt : Elmt_Id;
15346 begin
15347 if Present (E) then
15348 Elmt := First_Elmt (E);
15349
15350 while Elmt /= No_Elmt loop
15351 Visit_Node (Node (Elmt));
15352 Next_Elmt (Elmt);
15353 end loop;
15354 end if;
15355 end Visit_Elist;
15356
15357 -----------------
15358 -- Visit_Field --
15359 -----------------
15360
15361 procedure Visit_Field (F : Union_Id; N : Node_Id) is
15362 begin
15363 if F = Union_Id (Empty) then
15364 return;
15365
15366 elsif F in Node_Range then
15367
15368 -- Copy node if it is syntactic, i.e. its parent pointer is
15369 -- set to point to the field that referenced it (certain
15370 -- Itypes will also meet this criterion, which is fine, since
15371 -- these are clearly Itypes that do need to be copied, since
15372 -- we are copying their parent.)
15373
15374 if Parent (Node_Id (F)) = N then
15375 Visit_Node (Node_Id (F));
15376 return;
15377
15378 -- Another case, if we are pointing to an Itype, then we want
15379 -- to copy it if its associated node is somewhere in the tree
15380 -- being copied.
15381
15382 -- Note: the exclusion of self-referential copies is just an
15383 -- optimization, since the search of the already copied list
15384 -- would catch it, but it is a common case (Etype pointing
15385 -- to itself for an Itype that is a base type).
15386
15387 elsif Has_Extension (Node_Id (F))
15388 and then Is_Itype (Entity_Id (F))
15389 and then Node_Id (F) /= N
15390 then
15391 declare
15392 P : Node_Id;
15393
15394 begin
15395 P := Associated_Node_For_Itype (Node_Id (F));
15396 while Present (P) loop
15397 if P = Source then
15398 Visit_Node (Node_Id (F));
15399 return;
15400 else
15401 P := Parent (P);
15402 end if;
15403 end loop;
15404
15405 -- An Itype whose parent is not being copied definitely
15406 -- should NOT be copied, since it does not belong in any
15407 -- sense to the copied subtree.
15408
15409 return;
15410 end;
15411 end if;
15412
15413 elsif F in List_Range and then Parent (List_Id (F)) = N then
15414 Visit_List (List_Id (F));
15415 return;
15416 end if;
15417 end Visit_Field;
15418
15419 -----------------
15420 -- Visit_Itype --
15421 -----------------
15422
15423 procedure Visit_Itype (Old_Itype : Entity_Id) is
15424 New_Itype : Entity_Id;
15425 E : Elmt_Id;
15426 Ent : Entity_Id;
15427
15428 begin
15429 -- Itypes that describe the designated type of access to subprograms
15430 -- have the structure of subprogram declarations, with signatures,
15431 -- etc. Either we duplicate the signatures completely, or choose to
15432 -- share such itypes, which is fine because their elaboration will
15433 -- have no side effects.
15434
15435 if Ekind (Old_Itype) = E_Subprogram_Type then
15436 return;
15437 end if;
15438
15439 New_Itype := New_Copy (Old_Itype);
15440
15441 -- The new Itype has all the attributes of the old one, and
15442 -- we just copy the contents of the entity. However, the back-end
15443 -- needs different names for debugging purposes, so we create a
15444 -- new internal name for it in all cases.
15445
15446 Set_Chars (New_Itype, New_Internal_Name ('T'));
15447
15448 -- If our associated node is an entity that has already been copied,
15449 -- then set the associated node of the copy to point to the right
15450 -- copy. If we have copied an Itype that is itself the associated
15451 -- node of some previously copied Itype, then we set the right
15452 -- pointer in the other direction.
15453
15454 if Present (Actual_Map) then
15455
15456 -- Case of hash tables used
15457
15458 if NCT_Hash_Tables_Used then
15459
15460 Ent := NCT_Assoc.Get (Associated_Node_For_Itype (Old_Itype));
15461
15462 if Present (Ent) then
15463 Set_Associated_Node_For_Itype (New_Itype, Ent);
15464 end if;
15465
15466 Ent := NCT_Itype_Assoc.Get (Old_Itype);
15467 if Present (Ent) then
15468 Set_Associated_Node_For_Itype (Ent, New_Itype);
15469
15470 -- If the hash table has no association for this Itype and
15471 -- its associated node, enter one now.
15472
15473 else
15474 NCT_Itype_Assoc.Set
15475 (Associated_Node_For_Itype (Old_Itype), New_Itype);
15476 end if;
15477
15478 -- Case of hash tables not used
15479
15480 else
15481 E := First_Elmt (Actual_Map);
15482 while Present (E) loop
15483 if Associated_Node_For_Itype (Old_Itype) = Node (E) then
15484 Set_Associated_Node_For_Itype
15485 (New_Itype, Node (Next_Elmt (E)));
15486 end if;
15487
15488 if Is_Type (Node (E))
15489 and then Old_Itype = Associated_Node_For_Itype (Node (E))
15490 then
15491 Set_Associated_Node_For_Itype
15492 (Node (Next_Elmt (E)), New_Itype);
15493 end if;
15494
15495 E := Next_Elmt (Next_Elmt (E));
15496 end loop;
15497 end if;
15498 end if;
15499
15500 if Present (Freeze_Node (New_Itype)) then
15501 Set_Is_Frozen (New_Itype, False);
15502 Set_Freeze_Node (New_Itype, Empty);
15503 end if;
15504
15505 -- Add new association to map
15506
15507 if No (Actual_Map) then
15508 Actual_Map := New_Elmt_List;
15509 end if;
15510
15511 Append_Elmt (Old_Itype, Actual_Map);
15512 Append_Elmt (New_Itype, Actual_Map);
15513
15514 if NCT_Hash_Tables_Used then
15515 NCT_Assoc.Set (Old_Itype, New_Itype);
15516
15517 else
15518 NCT_Table_Entries := NCT_Table_Entries + 1;
15519
15520 if NCT_Table_Entries > NCT_Hash_Threshold then
15521 Build_NCT_Hash_Tables;
15522 end if;
15523 end if;
15524
15525 -- If a record subtype is simply copied, the entity list will be
15526 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
15527
15528 if Ekind_In (Old_Itype, E_Record_Subtype, E_Class_Wide_Subtype) then
15529 Set_Cloned_Subtype (New_Itype, Old_Itype);
15530 end if;
15531
15532 -- Visit descendents that eventually get copied
15533
15534 Visit_Field (Union_Id (Etype (Old_Itype)), Old_Itype);
15535
15536 if Is_Discrete_Type (Old_Itype) then
15537 Visit_Field (Union_Id (Scalar_Range (Old_Itype)), Old_Itype);
15538
15539 elsif Has_Discriminants (Base_Type (Old_Itype)) then
15540 -- ??? This should involve call to Visit_Field
15541 Visit_Elist (Discriminant_Constraint (Old_Itype));
15542
15543 elsif Is_Array_Type (Old_Itype) then
15544 if Present (First_Index (Old_Itype)) then
15545 Visit_Field (Union_Id (List_Containing
15546 (First_Index (Old_Itype))),
15547 Old_Itype);
15548 end if;
15549
15550 if Is_Packed (Old_Itype) then
15551 Visit_Field (Union_Id (Packed_Array_Impl_Type (Old_Itype)),
15552 Old_Itype);
15553 end if;
15554 end if;
15555 end Visit_Itype;
15556
15557 ----------------
15558 -- Visit_List --
15559 ----------------
15560
15561 procedure Visit_List (L : List_Id) is
15562 N : Node_Id;
15563 begin
15564 if L /= No_List then
15565 N := First (L);
15566
15567 while Present (N) loop
15568 Visit_Node (N);
15569 Next (N);
15570 end loop;
15571 end if;
15572 end Visit_List;
15573
15574 ----------------
15575 -- Visit_Node --
15576 ----------------
15577
15578 procedure Visit_Node (N : Node_Or_Entity_Id) is
15579
15580 -- Start of processing for Visit_Node
15581
15582 begin
15583 -- Handle case of an Itype, which must be copied
15584
15585 if Has_Extension (N) and then Is_Itype (N) then
15586
15587 -- Nothing to do if already in the list. This can happen with an
15588 -- Itype entity that appears more than once in the tree.
15589 -- Note that we do not want to visit descendents in this case.
15590
15591 -- Test for already in list when hash table is used
15592
15593 if NCT_Hash_Tables_Used then
15594 if Present (NCT_Assoc.Get (Entity_Id (N))) then
15595 return;
15596 end if;
15597
15598 -- Test for already in list when hash table not used
15599
15600 else
15601 declare
15602 E : Elmt_Id;
15603 begin
15604 if Present (Actual_Map) then
15605 E := First_Elmt (Actual_Map);
15606 while Present (E) loop
15607 if Node (E) = N then
15608 return;
15609 else
15610 E := Next_Elmt (Next_Elmt (E));
15611 end if;
15612 end loop;
15613 end if;
15614 end;
15615 end if;
15616
15617 Visit_Itype (N);
15618 end if;
15619
15620 -- Visit descendents
15621
15622 Visit_Field (Field1 (N), N);
15623 Visit_Field (Field2 (N), N);
15624 Visit_Field (Field3 (N), N);
15625 Visit_Field (Field4 (N), N);
15626 Visit_Field (Field5 (N), N);
15627 end Visit_Node;
15628
15629 -- Start of processing for New_Copy_Tree
15630
15631 begin
15632 Actual_Map := Map;
15633
15634 -- See if we should use hash table
15635
15636 if No (Actual_Map) then
15637 NCT_Hash_Tables_Used := False;
15638
15639 else
15640 declare
15641 Elmt : Elmt_Id;
15642
15643 begin
15644 NCT_Table_Entries := 0;
15645
15646 Elmt := First_Elmt (Actual_Map);
15647 while Present (Elmt) loop
15648 NCT_Table_Entries := NCT_Table_Entries + 1;
15649 Next_Elmt (Elmt);
15650 Next_Elmt (Elmt);
15651 end loop;
15652
15653 if NCT_Table_Entries > NCT_Hash_Threshold then
15654 Build_NCT_Hash_Tables;
15655 else
15656 NCT_Hash_Tables_Used := False;
15657 end if;
15658 end;
15659 end if;
15660
15661 -- Hash table set up if required, now start phase one by visiting
15662 -- top node (we will recursively visit the descendents).
15663
15664 Visit_Node (Source);
15665
15666 -- Now the second phase of the copy can start. First we process
15667 -- all the mapped entities, copying their descendents.
15668
15669 if Present (Actual_Map) then
15670 declare
15671 Elmt : Elmt_Id;
15672 New_Itype : Entity_Id;
15673 begin
15674 Elmt := First_Elmt (Actual_Map);
15675 while Present (Elmt) loop
15676 Next_Elmt (Elmt);
15677 New_Itype := Node (Elmt);
15678
15679 if Is_Itype (New_Itype) then
15680 Copy_Itype_With_Replacement (New_Itype);
15681 end if;
15682 Next_Elmt (Elmt);
15683 end loop;
15684 end;
15685 end if;
15686
15687 -- Now we can copy the actual tree
15688
15689 return Copy_Node_With_Replacement (Source);
15690 end New_Copy_Tree;
15691
15692 -------------------------
15693 -- New_External_Entity --
15694 -------------------------
15695
15696 function New_External_Entity
15697 (Kind : Entity_Kind;
15698 Scope_Id : Entity_Id;
15699 Sloc_Value : Source_Ptr;
15700 Related_Id : Entity_Id;
15701 Suffix : Character;
15702 Suffix_Index : Nat := 0;
15703 Prefix : Character := ' ') return Entity_Id
15704 is
15705 N : constant Entity_Id :=
15706 Make_Defining_Identifier (Sloc_Value,
15707 New_External_Name
15708 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
15709
15710 begin
15711 Set_Ekind (N, Kind);
15712 Set_Is_Internal (N, True);
15713 Append_Entity (N, Scope_Id);
15714 Set_Public_Status (N);
15715
15716 if Kind in Type_Kind then
15717 Init_Size_Align (N);
15718 end if;
15719
15720 return N;
15721 end New_External_Entity;
15722
15723 -------------------------
15724 -- New_Internal_Entity --
15725 -------------------------
15726
15727 function New_Internal_Entity
15728 (Kind : Entity_Kind;
15729 Scope_Id : Entity_Id;
15730 Sloc_Value : Source_Ptr;
15731 Id_Char : Character) return Entity_Id
15732 is
15733 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
15734
15735 begin
15736 Set_Ekind (N, Kind);
15737 Set_Is_Internal (N, True);
15738 Append_Entity (N, Scope_Id);
15739
15740 if Kind in Type_Kind then
15741 Init_Size_Align (N);
15742 end if;
15743
15744 return N;
15745 end New_Internal_Entity;
15746
15747 -----------------
15748 -- Next_Actual --
15749 -----------------
15750
15751 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
15752 N : Node_Id;
15753
15754 begin
15755 -- If we are pointing at a positional parameter, it is a member of a
15756 -- node list (the list of parameters), and the next parameter is the
15757 -- next node on the list, unless we hit a parameter association, then
15758 -- we shift to using the chain whose head is the First_Named_Actual in
15759 -- the parent, and then is threaded using the Next_Named_Actual of the
15760 -- Parameter_Association. All this fiddling is because the original node
15761 -- list is in the textual call order, and what we need is the
15762 -- declaration order.
15763
15764 if Is_List_Member (Actual_Id) then
15765 N := Next (Actual_Id);
15766
15767 if Nkind (N) = N_Parameter_Association then
15768 return First_Named_Actual (Parent (Actual_Id));
15769 else
15770 return N;
15771 end if;
15772
15773 else
15774 return Next_Named_Actual (Parent (Actual_Id));
15775 end if;
15776 end Next_Actual;
15777
15778 procedure Next_Actual (Actual_Id : in out Node_Id) is
15779 begin
15780 Actual_Id := Next_Actual (Actual_Id);
15781 end Next_Actual;
15782
15783 -----------------------
15784 -- Normalize_Actuals --
15785 -----------------------
15786
15787 -- Chain actuals according to formals of subprogram. If there are no named
15788 -- associations, the chain is simply the list of Parameter Associations,
15789 -- since the order is the same as the declaration order. If there are named
15790 -- associations, then the First_Named_Actual field in the N_Function_Call
15791 -- or N_Procedure_Call_Statement node points to the Parameter_Association
15792 -- node for the parameter that comes first in declaration order. The
15793 -- remaining named parameters are then chained in declaration order using
15794 -- Next_Named_Actual.
15795
15796 -- This routine also verifies that the number of actuals is compatible with
15797 -- the number and default values of formals, but performs no type checking
15798 -- (type checking is done by the caller).
15799
15800 -- If the matching succeeds, Success is set to True and the caller proceeds
15801 -- with type-checking. If the match is unsuccessful, then Success is set to
15802 -- False, and the caller attempts a different interpretation, if there is
15803 -- one.
15804
15805 -- If the flag Report is on, the call is not overloaded, and a failure to
15806 -- match can be reported here, rather than in the caller.
15807
15808 procedure Normalize_Actuals
15809 (N : Node_Id;
15810 S : Entity_Id;
15811 Report : Boolean;
15812 Success : out Boolean)
15813 is
15814 Actuals : constant List_Id := Parameter_Associations (N);
15815 Actual : Node_Id := Empty;
15816 Formal : Entity_Id;
15817 Last : Node_Id := Empty;
15818 First_Named : Node_Id := Empty;
15819 Found : Boolean;
15820
15821 Formals_To_Match : Integer := 0;
15822 Actuals_To_Match : Integer := 0;
15823
15824 procedure Chain (A : Node_Id);
15825 -- Add named actual at the proper place in the list, using the
15826 -- Next_Named_Actual link.
15827
15828 function Reporting return Boolean;
15829 -- Determines if an error is to be reported. To report an error, we
15830 -- need Report to be True, and also we do not report errors caused
15831 -- by calls to init procs that occur within other init procs. Such
15832 -- errors must always be cascaded errors, since if all the types are
15833 -- declared correctly, the compiler will certainly build decent calls.
15834
15835 -----------
15836 -- Chain --
15837 -----------
15838
15839 procedure Chain (A : Node_Id) is
15840 begin
15841 if No (Last) then
15842
15843 -- Call node points to first actual in list
15844
15845 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
15846
15847 else
15848 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
15849 end if;
15850
15851 Last := A;
15852 Set_Next_Named_Actual (Last, Empty);
15853 end Chain;
15854
15855 ---------------
15856 -- Reporting --
15857 ---------------
15858
15859 function Reporting return Boolean is
15860 begin
15861 if not Report then
15862 return False;
15863
15864 elsif not Within_Init_Proc then
15865 return True;
15866
15867 elsif Is_Init_Proc (Entity (Name (N))) then
15868 return False;
15869
15870 else
15871 return True;
15872 end if;
15873 end Reporting;
15874
15875 -- Start of processing for Normalize_Actuals
15876
15877 begin
15878 if Is_Access_Type (S) then
15879
15880 -- The name in the call is a function call that returns an access
15881 -- to subprogram. The designated type has the list of formals.
15882
15883 Formal := First_Formal (Designated_Type (S));
15884 else
15885 Formal := First_Formal (S);
15886 end if;
15887
15888 while Present (Formal) loop
15889 Formals_To_Match := Formals_To_Match + 1;
15890 Next_Formal (Formal);
15891 end loop;
15892
15893 -- Find if there is a named association, and verify that no positional
15894 -- associations appear after named ones.
15895
15896 if Present (Actuals) then
15897 Actual := First (Actuals);
15898 end if;
15899
15900 while Present (Actual)
15901 and then Nkind (Actual) /= N_Parameter_Association
15902 loop
15903 Actuals_To_Match := Actuals_To_Match + 1;
15904 Next (Actual);
15905 end loop;
15906
15907 if No (Actual) and Actuals_To_Match = Formals_To_Match then
15908
15909 -- Most common case: positional notation, no defaults
15910
15911 Success := True;
15912 return;
15913
15914 elsif Actuals_To_Match > Formals_To_Match then
15915
15916 -- Too many actuals: will not work
15917
15918 if Reporting then
15919 if Is_Entity_Name (Name (N)) then
15920 Error_Msg_N ("too many arguments in call to&", Name (N));
15921 else
15922 Error_Msg_N ("too many arguments in call", N);
15923 end if;
15924 end if;
15925
15926 Success := False;
15927 return;
15928 end if;
15929
15930 First_Named := Actual;
15931
15932 while Present (Actual) loop
15933 if Nkind (Actual) /= N_Parameter_Association then
15934 Error_Msg_N
15935 ("positional parameters not allowed after named ones", Actual);
15936 Success := False;
15937 return;
15938
15939 else
15940 Actuals_To_Match := Actuals_To_Match + 1;
15941 end if;
15942
15943 Next (Actual);
15944 end loop;
15945
15946 if Present (Actuals) then
15947 Actual := First (Actuals);
15948 end if;
15949
15950 Formal := First_Formal (S);
15951 while Present (Formal) loop
15952
15953 -- Match the formals in order. If the corresponding actual is
15954 -- positional, nothing to do. Else scan the list of named actuals
15955 -- to find the one with the right name.
15956
15957 if Present (Actual)
15958 and then Nkind (Actual) /= N_Parameter_Association
15959 then
15960 Next (Actual);
15961 Actuals_To_Match := Actuals_To_Match - 1;
15962 Formals_To_Match := Formals_To_Match - 1;
15963
15964 else
15965 -- For named parameters, search the list of actuals to find
15966 -- one that matches the next formal name.
15967
15968 Actual := First_Named;
15969 Found := False;
15970 while Present (Actual) loop
15971 if Chars (Selector_Name (Actual)) = Chars (Formal) then
15972 Found := True;
15973 Chain (Actual);
15974 Actuals_To_Match := Actuals_To_Match - 1;
15975 Formals_To_Match := Formals_To_Match - 1;
15976 exit;
15977 end if;
15978
15979 Next (Actual);
15980 end loop;
15981
15982 if not Found then
15983 if Ekind (Formal) /= E_In_Parameter
15984 or else No (Default_Value (Formal))
15985 then
15986 if Reporting then
15987 if (Comes_From_Source (S)
15988 or else Sloc (S) = Standard_Location)
15989 and then Is_Overloadable (S)
15990 then
15991 if No (Actuals)
15992 and then
15993 Nkind_In (Parent (N), N_Procedure_Call_Statement,
15994 N_Function_Call,
15995 N_Parameter_Association)
15996 and then Ekind (S) /= E_Function
15997 then
15998 Set_Etype (N, Etype (S));
15999
16000 else
16001 Error_Msg_Name_1 := Chars (S);
16002 Error_Msg_Sloc := Sloc (S);
16003 Error_Msg_NE
16004 ("missing argument for parameter & "
16005 & "in call to % declared #", N, Formal);
16006 end if;
16007
16008 elsif Is_Overloadable (S) then
16009 Error_Msg_Name_1 := Chars (S);
16010
16011 -- Point to type derivation that generated the
16012 -- operation.
16013
16014 Error_Msg_Sloc := Sloc (Parent (S));
16015
16016 Error_Msg_NE
16017 ("missing argument for parameter & "
16018 & "in call to % (inherited) #", N, Formal);
16019
16020 else
16021 Error_Msg_NE
16022 ("missing argument for parameter &", N, Formal);
16023 end if;
16024 end if;
16025
16026 Success := False;
16027 return;
16028
16029 else
16030 Formals_To_Match := Formals_To_Match - 1;
16031 end if;
16032 end if;
16033 end if;
16034
16035 Next_Formal (Formal);
16036 end loop;
16037
16038 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
16039 Success := True;
16040 return;
16041
16042 else
16043 if Reporting then
16044
16045 -- Find some superfluous named actual that did not get
16046 -- attached to the list of associations.
16047
16048 Actual := First (Actuals);
16049 while Present (Actual) loop
16050 if Nkind (Actual) = N_Parameter_Association
16051 and then Actual /= Last
16052 and then No (Next_Named_Actual (Actual))
16053 then
16054 Error_Msg_N ("unmatched actual & in call",
16055 Selector_Name (Actual));
16056 exit;
16057 end if;
16058
16059 Next (Actual);
16060 end loop;
16061 end if;
16062
16063 Success := False;
16064 return;
16065 end if;
16066 end Normalize_Actuals;
16067
16068 --------------------------------
16069 -- Note_Possible_Modification --
16070 --------------------------------
16071
16072 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
16073 Modification_Comes_From_Source : constant Boolean :=
16074 Comes_From_Source (Parent (N));
16075
16076 Ent : Entity_Id;
16077 Exp : Node_Id;
16078
16079 begin
16080 -- Loop to find referenced entity, if there is one
16081
16082 Exp := N;
16083 loop
16084 Ent := Empty;
16085
16086 if Is_Entity_Name (Exp) then
16087 Ent := Entity (Exp);
16088
16089 -- If the entity is missing, it is an undeclared identifier,
16090 -- and there is nothing to annotate.
16091
16092 if No (Ent) then
16093 return;
16094 end if;
16095
16096 elsif Nkind (Exp) = N_Explicit_Dereference then
16097 declare
16098 P : constant Node_Id := Prefix (Exp);
16099
16100 begin
16101 -- In formal verification mode, keep track of all reads and
16102 -- writes through explicit dereferences.
16103
16104 if GNATprove_Mode then
16105 SPARK_Specific.Generate_Dereference (N, 'm');
16106 end if;
16107
16108 if Nkind (P) = N_Selected_Component
16109 and then Present (Entry_Formal (Entity (Selector_Name (P))))
16110 then
16111 -- Case of a reference to an entry formal
16112
16113 Ent := Entry_Formal (Entity (Selector_Name (P)));
16114
16115 elsif Nkind (P) = N_Identifier
16116 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
16117 and then Present (Expression (Parent (Entity (P))))
16118 and then Nkind (Expression (Parent (Entity (P)))) =
16119 N_Reference
16120 then
16121 -- Case of a reference to a value on which side effects have
16122 -- been removed.
16123
16124 Exp := Prefix (Expression (Parent (Entity (P))));
16125 goto Continue;
16126
16127 else
16128 return;
16129 end if;
16130 end;
16131
16132 elsif Nkind_In (Exp, N_Type_Conversion,
16133 N_Unchecked_Type_Conversion)
16134 then
16135 Exp := Expression (Exp);
16136 goto Continue;
16137
16138 elsif Nkind_In (Exp, N_Slice,
16139 N_Indexed_Component,
16140 N_Selected_Component)
16141 then
16142 -- Special check, if the prefix is an access type, then return
16143 -- since we are modifying the thing pointed to, not the prefix.
16144 -- When we are expanding, most usually the prefix is replaced
16145 -- by an explicit dereference, and this test is not needed, but
16146 -- in some cases (notably -gnatc mode and generics) when we do
16147 -- not do full expansion, we need this special test.
16148
16149 if Is_Access_Type (Etype (Prefix (Exp))) then
16150 return;
16151
16152 -- Otherwise go to prefix and keep going
16153
16154 else
16155 Exp := Prefix (Exp);
16156 goto Continue;
16157 end if;
16158
16159 -- All other cases, not a modification
16160
16161 else
16162 return;
16163 end if;
16164
16165 -- Now look for entity being referenced
16166
16167 if Present (Ent) then
16168 if Is_Object (Ent) then
16169 if Comes_From_Source (Exp)
16170 or else Modification_Comes_From_Source
16171 then
16172 -- Give warning if pragma unmodified given and we are
16173 -- sure this is a modification.
16174
16175 if Has_Pragma_Unmodified (Ent) and then Sure then
16176 Error_Msg_NE ("??pragma Unmodified given for &!", N, Ent);
16177 end if;
16178
16179 Set_Never_Set_In_Source (Ent, False);
16180 end if;
16181
16182 Set_Is_True_Constant (Ent, False);
16183 Set_Current_Value (Ent, Empty);
16184 Set_Is_Known_Null (Ent, False);
16185
16186 if not Can_Never_Be_Null (Ent) then
16187 Set_Is_Known_Non_Null (Ent, False);
16188 end if;
16189
16190 -- Follow renaming chain
16191
16192 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
16193 and then Present (Renamed_Object (Ent))
16194 then
16195 Exp := Renamed_Object (Ent);
16196
16197 -- If the entity is the loop variable in an iteration over
16198 -- a container, retrieve container expression to indicate
16199 -- possible modification.
16200
16201 if Present (Related_Expression (Ent))
16202 and then Nkind (Parent (Related_Expression (Ent))) =
16203 N_Iterator_Specification
16204 then
16205 Exp := Original_Node (Related_Expression (Ent));
16206 end if;
16207
16208 goto Continue;
16209
16210 -- The expression may be the renaming of a subcomponent of an
16211 -- array or container. The assignment to the subcomponent is
16212 -- a modification of the container.
16213
16214 elsif Comes_From_Source (Original_Node (Exp))
16215 and then Nkind_In (Original_Node (Exp), N_Selected_Component,
16216 N_Indexed_Component)
16217 then
16218 Exp := Prefix (Original_Node (Exp));
16219 goto Continue;
16220 end if;
16221
16222 -- Generate a reference only if the assignment comes from
16223 -- source. This excludes, for example, calls to a dispatching
16224 -- assignment operation when the left-hand side is tagged. In
16225 -- GNATprove mode, we need those references also on generated
16226 -- code, as these are used to compute the local effects of
16227 -- subprograms.
16228
16229 if Modification_Comes_From_Source or GNATprove_Mode then
16230 Generate_Reference (Ent, Exp, 'm');
16231
16232 -- If the target of the assignment is the bound variable
16233 -- in an iterator, indicate that the corresponding array
16234 -- or container is also modified.
16235
16236 if Ada_Version >= Ada_2012
16237 and then Nkind (Parent (Ent)) = N_Iterator_Specification
16238 then
16239 declare
16240 Domain : constant Node_Id := Name (Parent (Ent));
16241
16242 begin
16243 -- TBD : in the full version of the construct, the
16244 -- domain of iteration can be given by an expression.
16245
16246 if Is_Entity_Name (Domain) then
16247 Generate_Reference (Entity (Domain), Exp, 'm');
16248 Set_Is_True_Constant (Entity (Domain), False);
16249 Set_Never_Set_In_Source (Entity (Domain), False);
16250 end if;
16251 end;
16252 end if;
16253 end if;
16254 end if;
16255
16256 Kill_Checks (Ent);
16257
16258 -- If we are sure this is a modification from source, and we know
16259 -- this modifies a constant, then give an appropriate warning.
16260
16261 if Sure
16262 and then Modification_Comes_From_Source
16263 and then Overlays_Constant (Ent)
16264 and then Address_Clause_Overlay_Warnings
16265 then
16266 declare
16267 Addr : constant Node_Id := Address_Clause (Ent);
16268 O_Ent : Entity_Id;
16269 Off : Boolean;
16270
16271 begin
16272 Find_Overlaid_Entity (Addr, O_Ent, Off);
16273
16274 Error_Msg_Sloc := Sloc (Addr);
16275 Error_Msg_NE
16276 ("??constant& may be modified via address clause#",
16277 N, O_Ent);
16278 end;
16279 end if;
16280
16281 return;
16282 end if;
16283
16284 <<Continue>>
16285 null;
16286 end loop;
16287 end Note_Possible_Modification;
16288
16289 -------------------------
16290 -- Object_Access_Level --
16291 -------------------------
16292
16293 -- Returns the static accessibility level of the view denoted by Obj. Note
16294 -- that the value returned is the result of a call to Scope_Depth. Only
16295 -- scope depths associated with dynamic scopes can actually be returned.
16296 -- Since only relative levels matter for accessibility checking, the fact
16297 -- that the distance between successive levels of accessibility is not
16298 -- always one is immaterial (invariant: if level(E2) is deeper than
16299 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
16300
16301 function Object_Access_Level (Obj : Node_Id) return Uint is
16302 function Is_Interface_Conversion (N : Node_Id) return Boolean;
16303 -- Determine whether N is a construct of the form
16304 -- Some_Type (Operand._tag'Address)
16305 -- This construct appears in the context of dispatching calls.
16306
16307 function Reference_To (Obj : Node_Id) return Node_Id;
16308 -- An explicit dereference is created when removing side-effects from
16309 -- expressions for constraint checking purposes. In this case a local
16310 -- access type is created for it. The correct access level is that of
16311 -- the original source node. We detect this case by noting that the
16312 -- prefix of the dereference is created by an object declaration whose
16313 -- initial expression is a reference.
16314
16315 -----------------------------
16316 -- Is_Interface_Conversion --
16317 -----------------------------
16318
16319 function Is_Interface_Conversion (N : Node_Id) return Boolean is
16320 begin
16321 return Nkind (N) = N_Unchecked_Type_Conversion
16322 and then Nkind (Expression (N)) = N_Attribute_Reference
16323 and then Attribute_Name (Expression (N)) = Name_Address;
16324 end Is_Interface_Conversion;
16325
16326 ------------------
16327 -- Reference_To --
16328 ------------------
16329
16330 function Reference_To (Obj : Node_Id) return Node_Id is
16331 Pref : constant Node_Id := Prefix (Obj);
16332 begin
16333 if Is_Entity_Name (Pref)
16334 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
16335 and then Present (Expression (Parent (Entity (Pref))))
16336 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
16337 then
16338 return (Prefix (Expression (Parent (Entity (Pref)))));
16339 else
16340 return Empty;
16341 end if;
16342 end Reference_To;
16343
16344 -- Local variables
16345
16346 E : Entity_Id;
16347
16348 -- Start of processing for Object_Access_Level
16349
16350 begin
16351 if Nkind (Obj) = N_Defining_Identifier
16352 or else Is_Entity_Name (Obj)
16353 then
16354 if Nkind (Obj) = N_Defining_Identifier then
16355 E := Obj;
16356 else
16357 E := Entity (Obj);
16358 end if;
16359
16360 if Is_Prival (E) then
16361 E := Prival_Link (E);
16362 end if;
16363
16364 -- If E is a type then it denotes a current instance. For this case
16365 -- we add one to the normal accessibility level of the type to ensure
16366 -- that current instances are treated as always being deeper than
16367 -- than the level of any visible named access type (see 3.10.2(21)).
16368
16369 if Is_Type (E) then
16370 return Type_Access_Level (E) + 1;
16371
16372 elsif Present (Renamed_Object (E)) then
16373 return Object_Access_Level (Renamed_Object (E));
16374
16375 -- Similarly, if E is a component of the current instance of a
16376 -- protected type, any instance of it is assumed to be at a deeper
16377 -- level than the type. For a protected object (whose type is an
16378 -- anonymous protected type) its components are at the same level
16379 -- as the type itself.
16380
16381 elsif not Is_Overloadable (E)
16382 and then Ekind (Scope (E)) = E_Protected_Type
16383 and then Comes_From_Source (Scope (E))
16384 then
16385 return Type_Access_Level (Scope (E)) + 1;
16386
16387 else
16388 -- Aliased formals of functions take their access level from the
16389 -- point of call, i.e. require a dynamic check. For static check
16390 -- purposes, this is smaller than the level of the subprogram
16391 -- itself. For procedures the aliased makes no difference.
16392
16393 if Is_Formal (E)
16394 and then Is_Aliased (E)
16395 and then Ekind (Scope (E)) = E_Function
16396 then
16397 return Type_Access_Level (Etype (E));
16398
16399 else
16400 return Scope_Depth (Enclosing_Dynamic_Scope (E));
16401 end if;
16402 end if;
16403
16404 elsif Nkind (Obj) = N_Selected_Component then
16405 if Is_Access_Type (Etype (Prefix (Obj))) then
16406 return Type_Access_Level (Etype (Prefix (Obj)));
16407 else
16408 return Object_Access_Level (Prefix (Obj));
16409 end if;
16410
16411 elsif Nkind (Obj) = N_Indexed_Component then
16412 if Is_Access_Type (Etype (Prefix (Obj))) then
16413 return Type_Access_Level (Etype (Prefix (Obj)));
16414 else
16415 return Object_Access_Level (Prefix (Obj));
16416 end if;
16417
16418 elsif Nkind (Obj) = N_Explicit_Dereference then
16419
16420 -- If the prefix is a selected access discriminant then we make a
16421 -- recursive call on the prefix, which will in turn check the level
16422 -- of the prefix object of the selected discriminant.
16423
16424 -- In Ada 2012, if the discriminant has implicit dereference and
16425 -- the context is a selected component, treat this as an object of
16426 -- unknown scope (see below). This is necessary in compile-only mode;
16427 -- otherwise expansion will already have transformed the prefix into
16428 -- a temporary.
16429
16430 if Nkind (Prefix (Obj)) = N_Selected_Component
16431 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
16432 and then
16433 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
16434 and then
16435 (not Has_Implicit_Dereference
16436 (Entity (Selector_Name (Prefix (Obj))))
16437 or else Nkind (Parent (Obj)) /= N_Selected_Component)
16438 then
16439 return Object_Access_Level (Prefix (Obj));
16440
16441 -- Detect an interface conversion in the context of a dispatching
16442 -- call. Use the original form of the conversion to find the access
16443 -- level of the operand.
16444
16445 elsif Is_Interface (Etype (Obj))
16446 and then Is_Interface_Conversion (Prefix (Obj))
16447 and then Nkind (Original_Node (Obj)) = N_Type_Conversion
16448 then
16449 return Object_Access_Level (Original_Node (Obj));
16450
16451 elsif not Comes_From_Source (Obj) then
16452 declare
16453 Ref : constant Node_Id := Reference_To (Obj);
16454 begin
16455 if Present (Ref) then
16456 return Object_Access_Level (Ref);
16457 else
16458 return Type_Access_Level (Etype (Prefix (Obj)));
16459 end if;
16460 end;
16461
16462 else
16463 return Type_Access_Level (Etype (Prefix (Obj)));
16464 end if;
16465
16466 elsif Nkind_In (Obj, N_Type_Conversion, N_Unchecked_Type_Conversion) then
16467 return Object_Access_Level (Expression (Obj));
16468
16469 elsif Nkind (Obj) = N_Function_Call then
16470
16471 -- Function results are objects, so we get either the access level of
16472 -- the function or, in the case of an indirect call, the level of the
16473 -- access-to-subprogram type. (This code is used for Ada 95, but it
16474 -- looks wrong, because it seems that we should be checking the level
16475 -- of the call itself, even for Ada 95. However, using the Ada 2005
16476 -- version of the code causes regressions in several tests that are
16477 -- compiled with -gnat95. ???)
16478
16479 if Ada_Version < Ada_2005 then
16480 if Is_Entity_Name (Name (Obj)) then
16481 return Subprogram_Access_Level (Entity (Name (Obj)));
16482 else
16483 return Type_Access_Level (Etype (Prefix (Name (Obj))));
16484 end if;
16485
16486 -- For Ada 2005, the level of the result object of a function call is
16487 -- defined to be the level of the call's innermost enclosing master.
16488 -- We determine that by querying the depth of the innermost enclosing
16489 -- dynamic scope.
16490
16491 else
16492 Return_Master_Scope_Depth_Of_Call : declare
16493
16494 function Innermost_Master_Scope_Depth
16495 (N : Node_Id) return Uint;
16496 -- Returns the scope depth of the given node's innermost
16497 -- enclosing dynamic scope (effectively the accessibility
16498 -- level of the innermost enclosing master).
16499
16500 ----------------------------------
16501 -- Innermost_Master_Scope_Depth --
16502 ----------------------------------
16503
16504 function Innermost_Master_Scope_Depth
16505 (N : Node_Id) return Uint
16506 is
16507 Node_Par : Node_Id := Parent (N);
16508
16509 begin
16510 -- Locate the nearest enclosing node (by traversing Parents)
16511 -- that Defining_Entity can be applied to, and return the
16512 -- depth of that entity's nearest enclosing dynamic scope.
16513
16514 while Present (Node_Par) loop
16515 case Nkind (Node_Par) is
16516 when N_Component_Declaration |
16517 N_Entry_Declaration |
16518 N_Formal_Object_Declaration |
16519 N_Formal_Type_Declaration |
16520 N_Full_Type_Declaration |
16521 N_Incomplete_Type_Declaration |
16522 N_Loop_Parameter_Specification |
16523 N_Object_Declaration |
16524 N_Protected_Type_Declaration |
16525 N_Private_Extension_Declaration |
16526 N_Private_Type_Declaration |
16527 N_Subtype_Declaration |
16528 N_Function_Specification |
16529 N_Procedure_Specification |
16530 N_Task_Type_Declaration |
16531 N_Body_Stub |
16532 N_Generic_Instantiation |
16533 N_Proper_Body |
16534 N_Implicit_Label_Declaration |
16535 N_Package_Declaration |
16536 N_Single_Task_Declaration |
16537 N_Subprogram_Declaration |
16538 N_Generic_Declaration |
16539 N_Renaming_Declaration |
16540 N_Block_Statement |
16541 N_Formal_Subprogram_Declaration |
16542 N_Abstract_Subprogram_Declaration |
16543 N_Entry_Body |
16544 N_Exception_Declaration |
16545 N_Formal_Package_Declaration |
16546 N_Number_Declaration |
16547 N_Package_Specification |
16548 N_Parameter_Specification |
16549 N_Single_Protected_Declaration |
16550 N_Subunit =>
16551
16552 return Scope_Depth
16553 (Nearest_Dynamic_Scope
16554 (Defining_Entity (Node_Par)));
16555
16556 when others =>
16557 null;
16558 end case;
16559
16560 Node_Par := Parent (Node_Par);
16561 end loop;
16562
16563 pragma Assert (False);
16564
16565 -- Should never reach the following return
16566
16567 return Scope_Depth (Current_Scope) + 1;
16568 end Innermost_Master_Scope_Depth;
16569
16570 -- Start of processing for Return_Master_Scope_Depth_Of_Call
16571
16572 begin
16573 return Innermost_Master_Scope_Depth (Obj);
16574 end Return_Master_Scope_Depth_Of_Call;
16575 end if;
16576
16577 -- For convenience we handle qualified expressions, even though they
16578 -- aren't technically object names.
16579
16580 elsif Nkind (Obj) = N_Qualified_Expression then
16581 return Object_Access_Level (Expression (Obj));
16582
16583 -- Ditto for aggregates. They have the level of the temporary that
16584 -- will hold their value.
16585
16586 elsif Nkind (Obj) = N_Aggregate then
16587 return Object_Access_Level (Current_Scope);
16588
16589 -- Otherwise return the scope level of Standard. (If there are cases
16590 -- that fall through to this point they will be treated as having
16591 -- global accessibility for now. ???)
16592
16593 else
16594 return Scope_Depth (Standard_Standard);
16595 end if;
16596 end Object_Access_Level;
16597
16598 ---------------------------------
16599 -- Original_Aspect_Pragma_Name --
16600 ---------------------------------
16601
16602 function Original_Aspect_Pragma_Name (N : Node_Id) return Name_Id is
16603 Item : Node_Id;
16604 Item_Nam : Name_Id;
16605
16606 begin
16607 pragma Assert (Nkind_In (N, N_Aspect_Specification, N_Pragma));
16608
16609 Item := N;
16610
16611 -- The pragma was generated to emulate an aspect, use the original
16612 -- aspect specification.
16613
16614 if Nkind (Item) = N_Pragma and then From_Aspect_Specification (Item) then
16615 Item := Corresponding_Aspect (Item);
16616 end if;
16617
16618 -- Retrieve the name of the aspect/pragma. Note that Pre, Pre_Class,
16619 -- Post and Post_Class rewrite their pragma identifier to preserve the
16620 -- original name.
16621 -- ??? this is kludgey
16622
16623 if Nkind (Item) = N_Pragma then
16624 Item_Nam := Chars (Original_Node (Pragma_Identifier (Item)));
16625
16626 else
16627 pragma Assert (Nkind (Item) = N_Aspect_Specification);
16628 Item_Nam := Chars (Identifier (Item));
16629 end if;
16630
16631 -- Deal with 'Class by converting the name to its _XXX form
16632
16633 if Class_Present (Item) then
16634 if Item_Nam = Name_Invariant then
16635 Item_Nam := Name_uInvariant;
16636
16637 elsif Item_Nam = Name_Post then
16638 Item_Nam := Name_uPost;
16639
16640 elsif Item_Nam = Name_Pre then
16641 Item_Nam := Name_uPre;
16642
16643 elsif Nam_In (Item_Nam, Name_Type_Invariant,
16644 Name_Type_Invariant_Class)
16645 then
16646 Item_Nam := Name_uType_Invariant;
16647
16648 -- Nothing to do for other cases (e.g. a Check that derived from
16649 -- Pre_Class and has the flag set). Also we do nothing if the name
16650 -- is already in special _xxx form.
16651
16652 end if;
16653 end if;
16654
16655 return Item_Nam;
16656 end Original_Aspect_Pragma_Name;
16657
16658 --------------------------------------
16659 -- Original_Corresponding_Operation --
16660 --------------------------------------
16661
16662 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
16663 is
16664 Typ : constant Entity_Id := Find_Dispatching_Type (S);
16665
16666 begin
16667 -- If S is an inherited primitive S2 the original corresponding
16668 -- operation of S is the original corresponding operation of S2
16669
16670 if Present (Alias (S))
16671 and then Find_Dispatching_Type (Alias (S)) /= Typ
16672 then
16673 return Original_Corresponding_Operation (Alias (S));
16674
16675 -- If S overrides an inherited subprogram S2 the original corresponding
16676 -- operation of S is the original corresponding operation of S2
16677
16678 elsif Present (Overridden_Operation (S)) then
16679 return Original_Corresponding_Operation (Overridden_Operation (S));
16680
16681 -- otherwise it is S itself
16682
16683 else
16684 return S;
16685 end if;
16686 end Original_Corresponding_Operation;
16687
16688 ----------------------
16689 -- Policy_In_Effect --
16690 ----------------------
16691
16692 function Policy_In_Effect (Policy : Name_Id) return Name_Id is
16693 function Policy_In_List (List : Node_Id) return Name_Id;
16694 -- Determine the mode of a policy in a N_Pragma list
16695
16696 --------------------
16697 -- Policy_In_List --
16698 --------------------
16699
16700 function Policy_In_List (List : Node_Id) return Name_Id is
16701 Arg1 : Node_Id;
16702 Arg2 : Node_Id;
16703 Prag : Node_Id;
16704
16705 begin
16706 Prag := List;
16707 while Present (Prag) loop
16708 Arg1 := First (Pragma_Argument_Associations (Prag));
16709 Arg2 := Next (Arg1);
16710
16711 Arg1 := Get_Pragma_Arg (Arg1);
16712 Arg2 := Get_Pragma_Arg (Arg2);
16713
16714 -- The current Check_Policy pragma matches the requested policy or
16715 -- appears in the single argument form (Assertion, policy_id).
16716
16717 if Nam_In (Chars (Arg1), Name_Assertion, Policy) then
16718 return Chars (Arg2);
16719 end if;
16720
16721 Prag := Next_Pragma (Prag);
16722 end loop;
16723
16724 return No_Name;
16725 end Policy_In_List;
16726
16727 -- Local variables
16728
16729 Kind : Name_Id;
16730
16731 -- Start of processing for Policy_In_Effect
16732
16733 begin
16734 if not Is_Valid_Assertion_Kind (Policy) then
16735 raise Program_Error;
16736 end if;
16737
16738 -- Inspect all policy pragmas that appear within scopes (if any)
16739
16740 Kind := Policy_In_List (Check_Policy_List);
16741
16742 -- Inspect all configuration policy pragmas (if any)
16743
16744 if Kind = No_Name then
16745 Kind := Policy_In_List (Check_Policy_List_Config);
16746 end if;
16747
16748 -- The context lacks policy pragmas, determine the mode based on whether
16749 -- assertions are enabled at the configuration level. This ensures that
16750 -- the policy is preserved when analyzing generics.
16751
16752 if Kind = No_Name then
16753 if Assertions_Enabled_Config then
16754 Kind := Name_Check;
16755 else
16756 Kind := Name_Ignore;
16757 end if;
16758 end if;
16759
16760 return Kind;
16761 end Policy_In_Effect;
16762
16763 ----------------------------------
16764 -- Predicate_Tests_On_Arguments --
16765 ----------------------------------
16766
16767 function Predicate_Tests_On_Arguments (Subp : Entity_Id) return Boolean is
16768 begin
16769 -- Always test predicates on indirect call
16770
16771 if Ekind (Subp) = E_Subprogram_Type then
16772 return True;
16773
16774 -- Do not test predicates on call to generated default Finalize, since
16775 -- we are not interested in whether something we are finalizing (and
16776 -- typically destroying) satisfies its predicates.
16777
16778 elsif Chars (Subp) = Name_Finalize
16779 and then not Comes_From_Source (Subp)
16780 then
16781 return False;
16782
16783 -- Do not test predicates on any internally generated routines
16784
16785 elsif Is_Internal_Name (Chars (Subp)) then
16786 return False;
16787
16788 -- Do not test predicates on call to Init_Proc, since if needed the
16789 -- predicate test will occur at some other point.
16790
16791 elsif Is_Init_Proc (Subp) then
16792 return False;
16793
16794 -- Do not test predicates on call to predicate function, since this
16795 -- would cause infinite recursion.
16796
16797 elsif Ekind (Subp) = E_Function
16798 and then (Is_Predicate_Function (Subp)
16799 or else
16800 Is_Predicate_Function_M (Subp))
16801 then
16802 return False;
16803
16804 -- For now, no other exceptions
16805
16806 else
16807 return True;
16808 end if;
16809 end Predicate_Tests_On_Arguments;
16810
16811 -----------------------
16812 -- Private_Component --
16813 -----------------------
16814
16815 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
16816 Ancestor : constant Entity_Id := Base_Type (Type_Id);
16817
16818 function Trace_Components
16819 (T : Entity_Id;
16820 Check : Boolean) return Entity_Id;
16821 -- Recursive function that does the work, and checks against circular
16822 -- definition for each subcomponent type.
16823
16824 ----------------------
16825 -- Trace_Components --
16826 ----------------------
16827
16828 function Trace_Components
16829 (T : Entity_Id;
16830 Check : Boolean) return Entity_Id
16831 is
16832 Btype : constant Entity_Id := Base_Type (T);
16833 Component : Entity_Id;
16834 P : Entity_Id;
16835 Candidate : Entity_Id := Empty;
16836
16837 begin
16838 if Check and then Btype = Ancestor then
16839 Error_Msg_N ("circular type definition", Type_Id);
16840 return Any_Type;
16841 end if;
16842
16843 if Is_Private_Type (Btype) and then not Is_Generic_Type (Btype) then
16844 if Present (Full_View (Btype))
16845 and then Is_Record_Type (Full_View (Btype))
16846 and then not Is_Frozen (Btype)
16847 then
16848 -- To indicate that the ancestor depends on a private type, the
16849 -- current Btype is sufficient. However, to check for circular
16850 -- definition we must recurse on the full view.
16851
16852 Candidate := Trace_Components (Full_View (Btype), True);
16853
16854 if Candidate = Any_Type then
16855 return Any_Type;
16856 else
16857 return Btype;
16858 end if;
16859
16860 else
16861 return Btype;
16862 end if;
16863
16864 elsif Is_Array_Type (Btype) then
16865 return Trace_Components (Component_Type (Btype), True);
16866
16867 elsif Is_Record_Type (Btype) then
16868 Component := First_Entity (Btype);
16869 while Present (Component)
16870 and then Comes_From_Source (Component)
16871 loop
16872 -- Skip anonymous types generated by constrained components
16873
16874 if not Is_Type (Component) then
16875 P := Trace_Components (Etype (Component), True);
16876
16877 if Present (P) then
16878 if P = Any_Type then
16879 return P;
16880 else
16881 Candidate := P;
16882 end if;
16883 end if;
16884 end if;
16885
16886 Next_Entity (Component);
16887 end loop;
16888
16889 return Candidate;
16890
16891 else
16892 return Empty;
16893 end if;
16894 end Trace_Components;
16895
16896 -- Start of processing for Private_Component
16897
16898 begin
16899 return Trace_Components (Type_Id, False);
16900 end Private_Component;
16901
16902 ---------------------------
16903 -- Primitive_Names_Match --
16904 ---------------------------
16905
16906 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
16907
16908 function Non_Internal_Name (E : Entity_Id) return Name_Id;
16909 -- Given an internal name, returns the corresponding non-internal name
16910
16911 ------------------------
16912 -- Non_Internal_Name --
16913 ------------------------
16914
16915 function Non_Internal_Name (E : Entity_Id) return Name_Id is
16916 begin
16917 Get_Name_String (Chars (E));
16918 Name_Len := Name_Len - 1;
16919 return Name_Find;
16920 end Non_Internal_Name;
16921
16922 -- Start of processing for Primitive_Names_Match
16923
16924 begin
16925 pragma Assert (Present (E1) and then Present (E2));
16926
16927 return Chars (E1) = Chars (E2)
16928 or else
16929 (not Is_Internal_Name (Chars (E1))
16930 and then Is_Internal_Name (Chars (E2))
16931 and then Non_Internal_Name (E2) = Chars (E1))
16932 or else
16933 (not Is_Internal_Name (Chars (E2))
16934 and then Is_Internal_Name (Chars (E1))
16935 and then Non_Internal_Name (E1) = Chars (E2))
16936 or else
16937 (Is_Predefined_Dispatching_Operation (E1)
16938 and then Is_Predefined_Dispatching_Operation (E2)
16939 and then Same_TSS (E1, E2))
16940 or else
16941 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
16942 end Primitive_Names_Match;
16943
16944 -----------------------
16945 -- Process_End_Label --
16946 -----------------------
16947
16948 procedure Process_End_Label
16949 (N : Node_Id;
16950 Typ : Character;
16951 Ent : Entity_Id)
16952 is
16953 Loc : Source_Ptr;
16954 Nam : Node_Id;
16955 Scop : Entity_Id;
16956
16957 Label_Ref : Boolean;
16958 -- Set True if reference to end label itself is required
16959
16960 Endl : Node_Id;
16961 -- Gets set to the operator symbol or identifier that references the
16962 -- entity Ent. For the child unit case, this is the identifier from the
16963 -- designator. For other cases, this is simply Endl.
16964
16965 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
16966 -- N is an identifier node that appears as a parent unit reference in
16967 -- the case where Ent is a child unit. This procedure generates an
16968 -- appropriate cross-reference entry. E is the corresponding entity.
16969
16970 -------------------------
16971 -- Generate_Parent_Ref --
16972 -------------------------
16973
16974 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
16975 begin
16976 -- If names do not match, something weird, skip reference
16977
16978 if Chars (E) = Chars (N) then
16979
16980 -- Generate the reference. We do NOT consider this as a reference
16981 -- for unreferenced symbol purposes.
16982
16983 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
16984
16985 if Style_Check then
16986 Style.Check_Identifier (N, E);
16987 end if;
16988 end if;
16989 end Generate_Parent_Ref;
16990
16991 -- Start of processing for Process_End_Label
16992
16993 begin
16994 -- If no node, ignore. This happens in some error situations, and
16995 -- also for some internally generated structures where no end label
16996 -- references are required in any case.
16997
16998 if No (N) then
16999 return;
17000 end if;
17001
17002 -- Nothing to do if no End_Label, happens for internally generated
17003 -- constructs where we don't want an end label reference anyway. Also
17004 -- nothing to do if Endl is a string literal, which means there was
17005 -- some prior error (bad operator symbol)
17006
17007 Endl := End_Label (N);
17008
17009 if No (Endl) or else Nkind (Endl) = N_String_Literal then
17010 return;
17011 end if;
17012
17013 -- Reference node is not in extended main source unit
17014
17015 if not In_Extended_Main_Source_Unit (N) then
17016
17017 -- Generally we do not collect references except for the extended
17018 -- main source unit. The one exception is the 'e' entry for a
17019 -- package spec, where it is useful for a client to have the
17020 -- ending information to define scopes.
17021
17022 if Typ /= 'e' then
17023 return;
17024
17025 else
17026 Label_Ref := False;
17027
17028 -- For this case, we can ignore any parent references, but we
17029 -- need the package name itself for the 'e' entry.
17030
17031 if Nkind (Endl) = N_Designator then
17032 Endl := Identifier (Endl);
17033 end if;
17034 end if;
17035
17036 -- Reference is in extended main source unit
17037
17038 else
17039 Label_Ref := True;
17040
17041 -- For designator, generate references for the parent entries
17042
17043 if Nkind (Endl) = N_Designator then
17044
17045 -- Generate references for the prefix if the END line comes from
17046 -- source (otherwise we do not need these references) We climb the
17047 -- scope stack to find the expected entities.
17048
17049 if Comes_From_Source (Endl) then
17050 Nam := Name (Endl);
17051 Scop := Current_Scope;
17052 while Nkind (Nam) = N_Selected_Component loop
17053 Scop := Scope (Scop);
17054 exit when No (Scop);
17055 Generate_Parent_Ref (Selector_Name (Nam), Scop);
17056 Nam := Prefix (Nam);
17057 end loop;
17058
17059 if Present (Scop) then
17060 Generate_Parent_Ref (Nam, Scope (Scop));
17061 end if;
17062 end if;
17063
17064 Endl := Identifier (Endl);
17065 end if;
17066 end if;
17067
17068 -- If the end label is not for the given entity, then either we have
17069 -- some previous error, or this is a generic instantiation for which
17070 -- we do not need to make a cross-reference in this case anyway. In
17071 -- either case we simply ignore the call.
17072
17073 if Chars (Ent) /= Chars (Endl) then
17074 return;
17075 end if;
17076
17077 -- If label was really there, then generate a normal reference and then
17078 -- adjust the location in the end label to point past the name (which
17079 -- should almost always be the semicolon).
17080
17081 Loc := Sloc (Endl);
17082
17083 if Comes_From_Source (Endl) then
17084
17085 -- If a label reference is required, then do the style check and
17086 -- generate an l-type cross-reference entry for the label
17087
17088 if Label_Ref then
17089 if Style_Check then
17090 Style.Check_Identifier (Endl, Ent);
17091 end if;
17092
17093 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
17094 end if;
17095
17096 -- Set the location to point past the label (normally this will
17097 -- mean the semicolon immediately following the label). This is
17098 -- done for the sake of the 'e' or 't' entry generated below.
17099
17100 Get_Decoded_Name_String (Chars (Endl));
17101 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
17102
17103 else
17104 -- In SPARK mode, no missing label is allowed for packages and
17105 -- subprogram bodies. Detect those cases by testing whether
17106 -- Process_End_Label was called for a body (Typ = 't') or a package.
17107
17108 if Restriction_Check_Required (SPARK_05)
17109 and then (Typ = 't' or else Ekind (Ent) = E_Package)
17110 then
17111 Error_Msg_Node_1 := Endl;
17112 Check_SPARK_05_Restriction
17113 ("`END &` required", Endl, Force => True);
17114 end if;
17115 end if;
17116
17117 -- Now generate the e/t reference
17118
17119 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
17120
17121 -- Restore Sloc, in case modified above, since we have an identifier
17122 -- and the normal Sloc should be left set in the tree.
17123
17124 Set_Sloc (Endl, Loc);
17125 end Process_End_Label;
17126
17127 ----------------
17128 -- Referenced --
17129 ----------------
17130
17131 function Referenced (Id : Entity_Id; Expr : Node_Id) return Boolean is
17132 Seen : Boolean := False;
17133
17134 function Is_Reference (N : Node_Id) return Traverse_Result;
17135 -- Determine whether node N denotes a reference to Id. If this is the
17136 -- case, set global flag Seen to True and stop the traversal.
17137
17138 ------------------
17139 -- Is_Reference --
17140 ------------------
17141
17142 function Is_Reference (N : Node_Id) return Traverse_Result is
17143 begin
17144 if Is_Entity_Name (N)
17145 and then Present (Entity (N))
17146 and then Entity (N) = Id
17147 then
17148 Seen := True;
17149 return Abandon;
17150 else
17151 return OK;
17152 end if;
17153 end Is_Reference;
17154
17155 procedure Inspect_Expression is new Traverse_Proc (Is_Reference);
17156
17157 -- Start of processing for Referenced
17158
17159 begin
17160 Inspect_Expression (Expr);
17161 return Seen;
17162 end Referenced;
17163
17164 ------------------------------------
17165 -- References_Generic_Formal_Type --
17166 ------------------------------------
17167
17168 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
17169
17170 function Process (N : Node_Id) return Traverse_Result;
17171 -- Process one node in search for generic formal type
17172
17173 -------------
17174 -- Process --
17175 -------------
17176
17177 function Process (N : Node_Id) return Traverse_Result is
17178 begin
17179 if Nkind (N) in N_Has_Entity then
17180 declare
17181 E : constant Entity_Id := Entity (N);
17182 begin
17183 if Present (E) then
17184 if Is_Generic_Type (E) then
17185 return Abandon;
17186 elsif Present (Etype (E))
17187 and then Is_Generic_Type (Etype (E))
17188 then
17189 return Abandon;
17190 end if;
17191 end if;
17192 end;
17193 end if;
17194
17195 return Atree.OK;
17196 end Process;
17197
17198 function Traverse is new Traverse_Func (Process);
17199 -- Traverse tree to look for generic type
17200
17201 begin
17202 if Inside_A_Generic then
17203 return Traverse (N) = Abandon;
17204 else
17205 return False;
17206 end if;
17207 end References_Generic_Formal_Type;
17208
17209 --------------------
17210 -- Remove_Homonym --
17211 --------------------
17212
17213 procedure Remove_Homonym (E : Entity_Id) is
17214 Prev : Entity_Id := Empty;
17215 H : Entity_Id;
17216
17217 begin
17218 if E = Current_Entity (E) then
17219 if Present (Homonym (E)) then
17220 Set_Current_Entity (Homonym (E));
17221 else
17222 Set_Name_Entity_Id (Chars (E), Empty);
17223 end if;
17224
17225 else
17226 H := Current_Entity (E);
17227 while Present (H) and then H /= E loop
17228 Prev := H;
17229 H := Homonym (H);
17230 end loop;
17231
17232 -- If E is not on the homonym chain, nothing to do
17233
17234 if Present (H) then
17235 Set_Homonym (Prev, Homonym (E));
17236 end if;
17237 end if;
17238 end Remove_Homonym;
17239
17240 ------------------------------
17241 -- Remove_Overloaded_Entity --
17242 ------------------------------
17243
17244 procedure Remove_Overloaded_Entity (Id : Entity_Id) is
17245 procedure Remove_Primitive_Of (Typ : Entity_Id);
17246 -- Remove primitive subprogram Id from the list of primitives that
17247 -- belong to type Typ.
17248
17249 -------------------------
17250 -- Remove_Primitive_Of --
17251 -------------------------
17252
17253 procedure Remove_Primitive_Of (Typ : Entity_Id) is
17254 Prims : Elist_Id;
17255
17256 begin
17257 if Is_Tagged_Type (Typ) then
17258 Prims := Direct_Primitive_Operations (Typ);
17259
17260 if Present (Prims) then
17261 Remove (Prims, Id);
17262 end if;
17263 end if;
17264 end Remove_Primitive_Of;
17265
17266 -- Local variables
17267
17268 Scop : constant Entity_Id := Scope (Id);
17269 Formal : Entity_Id;
17270 Prev_Id : Entity_Id;
17271
17272 -- Start of processing for Remove_Overloaded_Entity
17273
17274 begin
17275 -- Remove the entity from the homonym chain. When the entity is the
17276 -- head of the chain, associate the entry in the name table with its
17277 -- homonym effectively making it the new head of the chain.
17278
17279 if Current_Entity (Id) = Id then
17280 Set_Name_Entity_Id (Chars (Id), Homonym (Id));
17281
17282 -- Otherwise link the previous and next homonyms
17283
17284 else
17285 Prev_Id := Current_Entity (Id);
17286 while Present (Prev_Id) and then Homonym (Prev_Id) /= Id loop
17287 Prev_Id := Homonym (Prev_Id);
17288 end loop;
17289
17290 Set_Homonym (Prev_Id, Homonym (Id));
17291 end if;
17292
17293 -- Remove the entity from the scope entity chain. When the entity is
17294 -- the head of the chain, set the next entity as the new head of the
17295 -- chain.
17296
17297 if First_Entity (Scop) = Id then
17298 Prev_Id := Empty;
17299 Set_First_Entity (Scop, Next_Entity (Id));
17300
17301 -- Otherwise the entity is either in the middle of the chain or it acts
17302 -- as its tail. Traverse and link the previous and next entities.
17303
17304 else
17305 Prev_Id := First_Entity (Scop);
17306 while Present (Prev_Id) and then Next_Entity (Prev_Id) /= Id loop
17307 Next_Entity (Prev_Id);
17308 end loop;
17309
17310 Set_Next_Entity (Prev_Id, Next_Entity (Id));
17311 end if;
17312
17313 -- Handle the case where the entity acts as the tail of the scope entity
17314 -- chain.
17315
17316 if Last_Entity (Scop) = Id then
17317 Set_Last_Entity (Scop, Prev_Id);
17318 end if;
17319
17320 -- The entity denotes a primitive subprogram. Remove it from the list of
17321 -- primitives of the associated controlling type.
17322
17323 if Ekind_In (Id, E_Function, E_Procedure) and then Is_Primitive (Id) then
17324 Formal := First_Formal (Id);
17325 while Present (Formal) loop
17326 if Is_Controlling_Formal (Formal) then
17327 Remove_Primitive_Of (Etype (Formal));
17328 exit;
17329 end if;
17330
17331 Next_Formal (Formal);
17332 end loop;
17333
17334 if Ekind (Id) = E_Function and then Has_Controlling_Result (Id) then
17335 Remove_Primitive_Of (Etype (Id));
17336 end if;
17337 end if;
17338 end Remove_Overloaded_Entity;
17339
17340 ---------------------
17341 -- Rep_To_Pos_Flag --
17342 ---------------------
17343
17344 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
17345 begin
17346 return New_Occurrence_Of
17347 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
17348 end Rep_To_Pos_Flag;
17349
17350 -------------------------------
17351 -- Report_Unused_Body_States --
17352 -------------------------------
17353
17354 procedure Report_Unused_Body_States
17355 (Body_Id : Entity_Id;
17356 States : Elist_Id)
17357 is
17358 Posted : Boolean := False;
17359 State_Elmt : Elmt_Id;
17360 State_Id : Entity_Id;
17361
17362 begin
17363 if Present (States) then
17364 State_Elmt := First_Elmt (States);
17365 while Present (State_Elmt) loop
17366 State_Id := Node (State_Elmt);
17367
17368 -- Constants are part of the hidden state of a package, but the
17369 -- compiler cannot determine whether they have variable input
17370 -- (SPARK RM 7.1.1(2)) and cannot classify them properly as a
17371 -- hidden state. Do not emit an error when a constant does not
17372 -- participate in a state refinement, even though it acts as a
17373 -- hidden state.
17374
17375 if Ekind (State_Id) = E_Constant then
17376 null;
17377
17378 -- Generate an error message of the form:
17379
17380 -- body of package ... has unused hidden states
17381 -- abstract state ... defined at ...
17382 -- variable ... defined at ...
17383
17384 else
17385 if not Posted then
17386 Posted := True;
17387 SPARK_Msg_N
17388 ("body of package & has unused hidden states", Body_Id);
17389 end if;
17390
17391 Error_Msg_Sloc := Sloc (State_Id);
17392
17393 if Ekind (State_Id) = E_Abstract_State then
17394 SPARK_Msg_NE
17395 ("\abstract state & defined #", Body_Id, State_Id);
17396
17397 else
17398 SPARK_Msg_NE ("\variable & defined #", Body_Id, State_Id);
17399 end if;
17400 end if;
17401
17402 Next_Elmt (State_Elmt);
17403 end loop;
17404 end if;
17405 end Report_Unused_Body_States;
17406
17407 --------------------
17408 -- Require_Entity --
17409 --------------------
17410
17411 procedure Require_Entity (N : Node_Id) is
17412 begin
17413 if Is_Entity_Name (N) and then No (Entity (N)) then
17414 if Total_Errors_Detected /= 0 then
17415 Set_Entity (N, Any_Id);
17416 else
17417 raise Program_Error;
17418 end if;
17419 end if;
17420 end Require_Entity;
17421
17422 -------------------------------
17423 -- Requires_State_Refinement --
17424 -------------------------------
17425
17426 function Requires_State_Refinement
17427 (Spec_Id : Entity_Id;
17428 Body_Id : Entity_Id) return Boolean
17429 is
17430 function Mode_Is_Off (Prag : Node_Id) return Boolean;
17431 -- Given pragma SPARK_Mode, determine whether the mode is Off
17432
17433 -----------------
17434 -- Mode_Is_Off --
17435 -----------------
17436
17437 function Mode_Is_Off (Prag : Node_Id) return Boolean is
17438 Mode : Node_Id;
17439
17440 begin
17441 -- The default SPARK mode is On
17442
17443 if No (Prag) then
17444 return False;
17445 end if;
17446
17447 Mode := Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
17448
17449 -- Then the pragma lacks an argument, the default mode is On
17450
17451 if No (Mode) then
17452 return False;
17453 else
17454 return Chars (Mode) = Name_Off;
17455 end if;
17456 end Mode_Is_Off;
17457
17458 -- Start of processing for Requires_State_Refinement
17459
17460 begin
17461 -- A package that does not define at least one abstract state cannot
17462 -- possibly require refinement.
17463
17464 if No (Abstract_States (Spec_Id)) then
17465 return False;
17466
17467 -- The package instroduces a single null state which does not merit
17468 -- refinement.
17469
17470 elsif Has_Null_Abstract_State (Spec_Id) then
17471 return False;
17472
17473 -- Check whether the package body is subject to pragma SPARK_Mode. If
17474 -- it is and the mode is Off, the package body is considered to be in
17475 -- regular Ada and does not require refinement.
17476
17477 elsif Mode_Is_Off (SPARK_Pragma (Body_Id)) then
17478 return False;
17479
17480 -- The body's SPARK_Mode may be inherited from a similar pragma that
17481 -- appears in the private declarations of the spec. The pragma we are
17482 -- interested appears as the second entry in SPARK_Pragma.
17483
17484 elsif Present (SPARK_Pragma (Spec_Id))
17485 and then Mode_Is_Off (Next_Pragma (SPARK_Pragma (Spec_Id)))
17486 then
17487 return False;
17488
17489 -- The spec defines at least one abstract state and the body has no way
17490 -- of circumventing the refinement.
17491
17492 else
17493 return True;
17494 end if;
17495 end Requires_State_Refinement;
17496
17497 ------------------------------
17498 -- Requires_Transient_Scope --
17499 ------------------------------
17500
17501 -- A transient scope is required when variable-sized temporaries are
17502 -- allocated on the secondary stack, or when finalization actions must be
17503 -- generated before the next instruction.
17504
17505 function Old_Requires_Transient_Scope (Id : Entity_Id) return Boolean;
17506 function New_Requires_Transient_Scope (Id : Entity_Id) return Boolean;
17507 -- ???We retain the old and new algorithms for Requires_Transient_Scope for
17508 -- the time being. New_Requires_Transient_Scope is used by default; the
17509 -- debug switch -gnatdQ can be used to do Old_Requires_Transient_Scope
17510 -- instead. The intent is to use this temporarily to measure before/after
17511 -- efficiency. Note: when this temporary code is removed, the documentation
17512 -- of dQ in debug.adb should be removed.
17513
17514 procedure Results_Differ (Id : Entity_Id);
17515 -- ???Debugging code. Called when the Old_ and New_ results differ. Will be
17516 -- removed when New_Requires_Transient_Scope becomes
17517 -- Requires_Transient_Scope and Old_Requires_Transient_Scope is eliminated.
17518
17519 procedure Results_Differ (Id : Entity_Id) is
17520 begin
17521 if False then -- False to disable; True for debugging
17522 Treepr.Print_Tree_Node (Id);
17523
17524 if Old_Requires_Transient_Scope (Id) =
17525 New_Requires_Transient_Scope (Id)
17526 then
17527 raise Program_Error;
17528 end if;
17529 end if;
17530 end Results_Differ;
17531
17532 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
17533 Old_Result : constant Boolean := Old_Requires_Transient_Scope (Id);
17534
17535 begin
17536 if Debug_Flag_QQ then
17537 return Old_Result;
17538 end if;
17539
17540 declare
17541 New_Result : constant Boolean := New_Requires_Transient_Scope (Id);
17542
17543 begin
17544 -- Assert that we're not putting things on the secondary stack if we
17545 -- didn't before; we are trying to AVOID secondary stack when
17546 -- possible.
17547
17548 if not Old_Result then
17549 pragma Assert (not New_Result);
17550 null;
17551 end if;
17552
17553 if New_Result /= Old_Result then
17554 Results_Differ (Id);
17555 end if;
17556
17557 return New_Result;
17558 end;
17559 end Requires_Transient_Scope;
17560
17561 ----------------------------------
17562 -- Old_Requires_Transient_Scope --
17563 ----------------------------------
17564
17565 function Old_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
17566 Typ : constant Entity_Id := Underlying_Type (Id);
17567
17568 begin
17569 -- This is a private type which is not completed yet. This can only
17570 -- happen in a default expression (of a formal parameter or of a
17571 -- record component). Do not expand transient scope in this case.
17572
17573 if No (Typ) then
17574 return False;
17575
17576 -- Do not expand transient scope for non-existent procedure return
17577
17578 elsif Typ = Standard_Void_Type then
17579 return False;
17580
17581 -- Elementary types do not require a transient scope
17582
17583 elsif Is_Elementary_Type (Typ) then
17584 return False;
17585
17586 -- Generally, indefinite subtypes require a transient scope, since the
17587 -- back end cannot generate temporaries, since this is not a valid type
17588 -- for declaring an object. It might be possible to relax this in the
17589 -- future, e.g. by declaring the maximum possible space for the type.
17590
17591 elsif not Is_Definite_Subtype (Typ) then
17592 return True;
17593
17594 -- Functions returning tagged types may dispatch on result so their
17595 -- returned value is allocated on the secondary stack. Controlled
17596 -- type temporaries need finalization.
17597
17598 elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
17599 return True;
17600
17601 -- Record type
17602
17603 elsif Is_Record_Type (Typ) then
17604 declare
17605 Comp : Entity_Id;
17606
17607 begin
17608 Comp := First_Entity (Typ);
17609 while Present (Comp) loop
17610 if Ekind (Comp) = E_Component then
17611
17612 -- ???It's not clear we need a full recursive call to
17613 -- Old_Requires_Transient_Scope here. Note that the
17614 -- following can't happen.
17615
17616 pragma Assert (Is_Definite_Subtype (Etype (Comp)));
17617 pragma Assert (not Has_Controlled_Component (Etype (Comp)));
17618
17619 if Old_Requires_Transient_Scope (Etype (Comp)) then
17620 return True;
17621 end if;
17622 end if;
17623
17624 Next_Entity (Comp);
17625 end loop;
17626 end;
17627
17628 return False;
17629
17630 -- String literal types never require transient scope
17631
17632 elsif Ekind (Typ) = E_String_Literal_Subtype then
17633 return False;
17634
17635 -- Array type. Note that we already know that this is a constrained
17636 -- array, since unconstrained arrays will fail the indefinite test.
17637
17638 elsif Is_Array_Type (Typ) then
17639
17640 -- If component type requires a transient scope, the array does too
17641
17642 if Old_Requires_Transient_Scope (Component_Type (Typ)) then
17643 return True;
17644
17645 -- Otherwise, we only need a transient scope if the size depends on
17646 -- the value of one or more discriminants.
17647
17648 else
17649 return Size_Depends_On_Discriminant (Typ);
17650 end if;
17651
17652 -- All other cases do not require a transient scope
17653
17654 else
17655 pragma Assert (Is_Protected_Type (Typ) or else Is_Task_Type (Typ));
17656 return False;
17657 end if;
17658 end Old_Requires_Transient_Scope;
17659
17660 ----------------------------------
17661 -- New_Requires_Transient_Scope --
17662 ----------------------------------
17663
17664 function New_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
17665
17666 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean;
17667 -- This is called for untagged records and protected types, with
17668 -- nondefaulted discriminants. Returns True if the size of function
17669 -- results is known at the call site, False otherwise. Returns False
17670 -- if there is a variant part that depends on the discriminants of
17671 -- this type, or if there is an array constrained by the discriminants
17672 -- of this type. ???Currently, this is overly conservative (the array
17673 -- could be nested inside some other record that is constrained by
17674 -- nondiscriminants). That is, the recursive calls are too conservative.
17675
17676 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean;
17677 -- Returns True if Typ is a nonlimited record with defaulted
17678 -- discriminants whose max size makes it unsuitable for allocating on
17679 -- the primary stack.
17680
17681 ------------------------------
17682 -- Caller_Known_Size_Record --
17683 ------------------------------
17684
17685 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean is
17686 pragma Assert (Typ = Underlying_Type (Typ));
17687
17688 begin
17689 if Has_Variant_Part (Typ) and then not Is_Definite_Subtype (Typ) then
17690 return False;
17691 end if;
17692
17693 declare
17694 Comp : Entity_Id;
17695
17696 begin
17697 Comp := First_Entity (Typ);
17698 while Present (Comp) loop
17699
17700 -- Only look at E_Component entities. No need to look at
17701 -- E_Discriminant entities, and we must ignore internal
17702 -- subtypes generated for constrained components.
17703
17704 if Ekind (Comp) = E_Component then
17705 declare
17706 Comp_Type : constant Entity_Id :=
17707 Underlying_Type (Etype (Comp));
17708
17709 begin
17710 if Is_Record_Type (Comp_Type)
17711 or else
17712 Is_Protected_Type (Comp_Type)
17713 then
17714 if not Caller_Known_Size_Record (Comp_Type) then
17715 return False;
17716 end if;
17717
17718 elsif Is_Array_Type (Comp_Type) then
17719 if Size_Depends_On_Discriminant (Comp_Type) then
17720 return False;
17721 end if;
17722 end if;
17723 end;
17724 end if;
17725
17726 Next_Entity (Comp);
17727 end loop;
17728 end;
17729
17730 return True;
17731 end Caller_Known_Size_Record;
17732
17733 ------------------------------
17734 -- Large_Max_Size_Mutable --
17735 ------------------------------
17736
17737 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean is
17738 pragma Assert (Typ = Underlying_Type (Typ));
17739
17740 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean;
17741 -- Returns true if the discrete type T has a large range
17742
17743 ----------------------------
17744 -- Is_Large_Discrete_Type --
17745 ----------------------------
17746
17747 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean is
17748 Threshold : constant Int := 16;
17749 -- Arbitrary threshold above which we consider it "large". We want
17750 -- a fairly large threshold, because these large types really
17751 -- shouldn't have default discriminants in the first place, in
17752 -- most cases.
17753
17754 begin
17755 return UI_To_Int (RM_Size (T)) > Threshold;
17756 end Is_Large_Discrete_Type;
17757
17758 begin
17759 if Is_Record_Type (Typ)
17760 and then not Is_Limited_View (Typ)
17761 and then Has_Defaulted_Discriminants (Typ)
17762 then
17763 -- Loop through the components, looking for an array whose upper
17764 -- bound(s) depends on discriminants, where both the subtype of
17765 -- the discriminant and the index subtype are too large.
17766
17767 declare
17768 Comp : Entity_Id;
17769
17770 begin
17771 Comp := First_Entity (Typ);
17772 while Present (Comp) loop
17773 if Ekind (Comp) = E_Component then
17774 declare
17775 Comp_Type : constant Entity_Id :=
17776 Underlying_Type (Etype (Comp));
17777 Indx : Node_Id;
17778 Ityp : Entity_Id;
17779 Hi : Node_Id;
17780
17781 begin
17782 if Is_Array_Type (Comp_Type) then
17783 Indx := First_Index (Comp_Type);
17784
17785 while Present (Indx) loop
17786 Ityp := Etype (Indx);
17787 Hi := Type_High_Bound (Ityp);
17788
17789 if Nkind (Hi) = N_Identifier
17790 and then Ekind (Entity (Hi)) = E_Discriminant
17791 and then Is_Large_Discrete_Type (Ityp)
17792 and then Is_Large_Discrete_Type
17793 (Etype (Entity (Hi)))
17794 then
17795 return True;
17796 end if;
17797
17798 Next_Index (Indx);
17799 end loop;
17800 end if;
17801 end;
17802 end if;
17803
17804 Next_Entity (Comp);
17805 end loop;
17806 end;
17807 end if;
17808
17809 return False;
17810 end Large_Max_Size_Mutable;
17811
17812 -- Local declarations
17813
17814 Typ : constant Entity_Id := Underlying_Type (Id);
17815
17816 -- Start of processing for New_Requires_Transient_Scope
17817
17818 begin
17819 -- This is a private type which is not completed yet. This can only
17820 -- happen in a default expression (of a formal parameter or of a
17821 -- record component). Do not expand transient scope in this case.
17822
17823 if No (Typ) then
17824 return False;
17825
17826 -- Do not expand transient scope for non-existent procedure return or
17827 -- string literal types.
17828
17829 elsif Typ = Standard_Void_Type
17830 or else Ekind (Typ) = E_String_Literal_Subtype
17831 then
17832 return False;
17833
17834 -- If Typ is a generic formal incomplete type, then we want to look at
17835 -- the actual type.
17836
17837 elsif Ekind (Typ) = E_Record_Subtype
17838 and then Present (Cloned_Subtype (Typ))
17839 then
17840 return New_Requires_Transient_Scope (Cloned_Subtype (Typ));
17841
17842 -- Functions returning specific tagged types may dispatch on result, so
17843 -- their returned value is allocated on the secondary stack, even in the
17844 -- definite case. We must treat nondispatching functions the same way,
17845 -- because access-to-function types can point at both, so the calling
17846 -- conventions must be compatible. Is_Tagged_Type includes controlled
17847 -- types and class-wide types. Controlled type temporaries need
17848 -- finalization.
17849
17850 -- ???It's not clear why we need to return noncontrolled types with
17851 -- controlled components on the secondary stack.
17852
17853 elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
17854 return True;
17855
17856 -- Untagged definite subtypes are known size. This includes all
17857 -- elementary [sub]types. Tasks are known size even if they have
17858 -- discriminants. So we return False here, with one exception:
17859 -- For a type like:
17860 -- type T (Last : Natural := 0) is
17861 -- X : String (1 .. Last);
17862 -- end record;
17863 -- we return True. That's because for "P(F(...));", where F returns T,
17864 -- we don't know the size of the result at the call site, so if we
17865 -- allocated it on the primary stack, we would have to allocate the
17866 -- maximum size, which is way too big.
17867
17868 elsif Is_Definite_Subtype (Typ) or else Is_Task_Type (Typ) then
17869 return Large_Max_Size_Mutable (Typ);
17870
17871 -- Indefinite (discriminated) untagged record or protected type
17872
17873 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
17874 return not Caller_Known_Size_Record (Typ);
17875
17876 -- Unconstrained array
17877
17878 else
17879 pragma Assert (Is_Array_Type (Typ) and not Is_Definite_Subtype (Typ));
17880 return True;
17881 end if;
17882 end New_Requires_Transient_Scope;
17883
17884 --------------------------
17885 -- Reset_Analyzed_Flags --
17886 --------------------------
17887
17888 procedure Reset_Analyzed_Flags (N : Node_Id) is
17889
17890 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
17891 -- Function used to reset Analyzed flags in tree. Note that we do
17892 -- not reset Analyzed flags in entities, since there is no need to
17893 -- reanalyze entities, and indeed, it is wrong to do so, since it
17894 -- can result in generating auxiliary stuff more than once.
17895
17896 --------------------
17897 -- Clear_Analyzed --
17898 --------------------
17899
17900 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
17901 begin
17902 if not Has_Extension (N) then
17903 Set_Analyzed (N, False);
17904 end if;
17905
17906 return OK;
17907 end Clear_Analyzed;
17908
17909 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
17910
17911 -- Start of processing for Reset_Analyzed_Flags
17912
17913 begin
17914 Reset_Analyzed (N);
17915 end Reset_Analyzed_Flags;
17916
17917 ------------------------
17918 -- Restore_SPARK_Mode --
17919 ------------------------
17920
17921 procedure Restore_SPARK_Mode (Mode : SPARK_Mode_Type) is
17922 begin
17923 SPARK_Mode := Mode;
17924 end Restore_SPARK_Mode;
17925
17926 --------------------------------
17927 -- Returns_Unconstrained_Type --
17928 --------------------------------
17929
17930 function Returns_Unconstrained_Type (Subp : Entity_Id) return Boolean is
17931 begin
17932 return Ekind (Subp) = E_Function
17933 and then not Is_Scalar_Type (Etype (Subp))
17934 and then not Is_Access_Type (Etype (Subp))
17935 and then not Is_Constrained (Etype (Subp));
17936 end Returns_Unconstrained_Type;
17937
17938 ----------------------------
17939 -- Root_Type_Of_Full_View --
17940 ----------------------------
17941
17942 function Root_Type_Of_Full_View (T : Entity_Id) return Entity_Id is
17943 Rtyp : constant Entity_Id := Root_Type (T);
17944
17945 begin
17946 -- The root type of the full view may itself be a private type. Keep
17947 -- looking for the ultimate derivation parent.
17948
17949 if Is_Private_Type (Rtyp) and then Present (Full_View (Rtyp)) then
17950 return Root_Type_Of_Full_View (Full_View (Rtyp));
17951 else
17952 return Rtyp;
17953 end if;
17954 end Root_Type_Of_Full_View;
17955
17956 ---------------------------
17957 -- Safe_To_Capture_Value --
17958 ---------------------------
17959
17960 function Safe_To_Capture_Value
17961 (N : Node_Id;
17962 Ent : Entity_Id;
17963 Cond : Boolean := False) return Boolean
17964 is
17965 begin
17966 -- The only entities for which we track constant values are variables
17967 -- which are not renamings, constants, out parameters, and in out
17968 -- parameters, so check if we have this case.
17969
17970 -- Note: it may seem odd to track constant values for constants, but in
17971 -- fact this routine is used for other purposes than simply capturing
17972 -- the value. In particular, the setting of Known[_Non]_Null.
17973
17974 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
17975 or else
17976 Ekind_In (Ent, E_Constant, E_Out_Parameter, E_In_Out_Parameter)
17977 then
17978 null;
17979
17980 -- For conditionals, we also allow loop parameters and all formals,
17981 -- including in parameters.
17982
17983 elsif Cond and then Ekind_In (Ent, E_Loop_Parameter, E_In_Parameter) then
17984 null;
17985
17986 -- For all other cases, not just unsafe, but impossible to capture
17987 -- Current_Value, since the above are the only entities which have
17988 -- Current_Value fields.
17989
17990 else
17991 return False;
17992 end if;
17993
17994 -- Skip if volatile or aliased, since funny things might be going on in
17995 -- these cases which we cannot necessarily track. Also skip any variable
17996 -- for which an address clause is given, or whose address is taken. Also
17997 -- never capture value of library level variables (an attempt to do so
17998 -- can occur in the case of package elaboration code).
17999
18000 if Treat_As_Volatile (Ent)
18001 or else Is_Aliased (Ent)
18002 or else Present (Address_Clause (Ent))
18003 or else Address_Taken (Ent)
18004 or else (Is_Library_Level_Entity (Ent)
18005 and then Ekind (Ent) = E_Variable)
18006 then
18007 return False;
18008 end if;
18009
18010 -- OK, all above conditions are met. We also require that the scope of
18011 -- the reference be the same as the scope of the entity, not counting
18012 -- packages and blocks and loops.
18013
18014 declare
18015 E_Scope : constant Entity_Id := Scope (Ent);
18016 R_Scope : Entity_Id;
18017
18018 begin
18019 R_Scope := Current_Scope;
18020 while R_Scope /= Standard_Standard loop
18021 exit when R_Scope = E_Scope;
18022
18023 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
18024 return False;
18025 else
18026 R_Scope := Scope (R_Scope);
18027 end if;
18028 end loop;
18029 end;
18030
18031 -- We also require that the reference does not appear in a context
18032 -- where it is not sure to be executed (i.e. a conditional context
18033 -- or an exception handler). We skip this if Cond is True, since the
18034 -- capturing of values from conditional tests handles this ok.
18035
18036 if Cond then
18037 return True;
18038 end if;
18039
18040 declare
18041 Desc : Node_Id;
18042 P : Node_Id;
18043
18044 begin
18045 Desc := N;
18046
18047 -- Seems dubious that case expressions are not handled here ???
18048
18049 P := Parent (N);
18050 while Present (P) loop
18051 if Nkind (P) = N_If_Statement
18052 or else Nkind (P) = N_Case_Statement
18053 or else (Nkind (P) in N_Short_Circuit
18054 and then Desc = Right_Opnd (P))
18055 or else (Nkind (P) = N_If_Expression
18056 and then Desc /= First (Expressions (P)))
18057 or else Nkind (P) = N_Exception_Handler
18058 or else Nkind (P) = N_Selective_Accept
18059 or else Nkind (P) = N_Conditional_Entry_Call
18060 or else Nkind (P) = N_Timed_Entry_Call
18061 or else Nkind (P) = N_Asynchronous_Select
18062 then
18063 return False;
18064
18065 else
18066 Desc := P;
18067 P := Parent (P);
18068
18069 -- A special Ada 2012 case: the original node may be part
18070 -- of the else_actions of a conditional expression, in which
18071 -- case it might not have been expanded yet, and appears in
18072 -- a non-syntactic list of actions. In that case it is clearly
18073 -- not safe to save a value.
18074
18075 if No (P)
18076 and then Is_List_Member (Desc)
18077 and then No (Parent (List_Containing (Desc)))
18078 then
18079 return False;
18080 end if;
18081 end if;
18082 end loop;
18083 end;
18084
18085 -- OK, looks safe to set value
18086
18087 return True;
18088 end Safe_To_Capture_Value;
18089
18090 ---------------
18091 -- Same_Name --
18092 ---------------
18093
18094 function Same_Name (N1, N2 : Node_Id) return Boolean is
18095 K1 : constant Node_Kind := Nkind (N1);
18096 K2 : constant Node_Kind := Nkind (N2);
18097
18098 begin
18099 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
18100 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
18101 then
18102 return Chars (N1) = Chars (N2);
18103
18104 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
18105 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
18106 then
18107 return Same_Name (Selector_Name (N1), Selector_Name (N2))
18108 and then Same_Name (Prefix (N1), Prefix (N2));
18109
18110 else
18111 return False;
18112 end if;
18113 end Same_Name;
18114
18115 -----------------
18116 -- Same_Object --
18117 -----------------
18118
18119 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
18120 N1 : constant Node_Id := Original_Node (Node1);
18121 N2 : constant Node_Id := Original_Node (Node2);
18122 -- We do the tests on original nodes, since we are most interested
18123 -- in the original source, not any expansion that got in the way.
18124
18125 K1 : constant Node_Kind := Nkind (N1);
18126 K2 : constant Node_Kind := Nkind (N2);
18127
18128 begin
18129 -- First case, both are entities with same entity
18130
18131 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
18132 declare
18133 EN1 : constant Entity_Id := Entity (N1);
18134 EN2 : constant Entity_Id := Entity (N2);
18135 begin
18136 if Present (EN1) and then Present (EN2)
18137 and then (Ekind_In (EN1, E_Variable, E_Constant)
18138 or else Is_Formal (EN1))
18139 and then EN1 = EN2
18140 then
18141 return True;
18142 end if;
18143 end;
18144 end if;
18145
18146 -- Second case, selected component with same selector, same record
18147
18148 if K1 = N_Selected_Component
18149 and then K2 = N_Selected_Component
18150 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
18151 then
18152 return Same_Object (Prefix (N1), Prefix (N2));
18153
18154 -- Third case, indexed component with same subscripts, same array
18155
18156 elsif K1 = N_Indexed_Component
18157 and then K2 = N_Indexed_Component
18158 and then Same_Object (Prefix (N1), Prefix (N2))
18159 then
18160 declare
18161 E1, E2 : Node_Id;
18162 begin
18163 E1 := First (Expressions (N1));
18164 E2 := First (Expressions (N2));
18165 while Present (E1) loop
18166 if not Same_Value (E1, E2) then
18167 return False;
18168 else
18169 Next (E1);
18170 Next (E2);
18171 end if;
18172 end loop;
18173
18174 return True;
18175 end;
18176
18177 -- Fourth case, slice of same array with same bounds
18178
18179 elsif K1 = N_Slice
18180 and then K2 = N_Slice
18181 and then Nkind (Discrete_Range (N1)) = N_Range
18182 and then Nkind (Discrete_Range (N2)) = N_Range
18183 and then Same_Value (Low_Bound (Discrete_Range (N1)),
18184 Low_Bound (Discrete_Range (N2)))
18185 and then Same_Value (High_Bound (Discrete_Range (N1)),
18186 High_Bound (Discrete_Range (N2)))
18187 then
18188 return Same_Name (Prefix (N1), Prefix (N2));
18189
18190 -- All other cases, not clearly the same object
18191
18192 else
18193 return False;
18194 end if;
18195 end Same_Object;
18196
18197 ---------------
18198 -- Same_Type --
18199 ---------------
18200
18201 function Same_Type (T1, T2 : Entity_Id) return Boolean is
18202 begin
18203 if T1 = T2 then
18204 return True;
18205
18206 elsif not Is_Constrained (T1)
18207 and then not Is_Constrained (T2)
18208 and then Base_Type (T1) = Base_Type (T2)
18209 then
18210 return True;
18211
18212 -- For now don't bother with case of identical constraints, to be
18213 -- fiddled with later on perhaps (this is only used for optimization
18214 -- purposes, so it is not critical to do a best possible job)
18215
18216 else
18217 return False;
18218 end if;
18219 end Same_Type;
18220
18221 ----------------
18222 -- Same_Value --
18223 ----------------
18224
18225 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
18226 begin
18227 if Compile_Time_Known_Value (Node1)
18228 and then Compile_Time_Known_Value (Node2)
18229 and then Expr_Value (Node1) = Expr_Value (Node2)
18230 then
18231 return True;
18232 elsif Same_Object (Node1, Node2) then
18233 return True;
18234 else
18235 return False;
18236 end if;
18237 end Same_Value;
18238
18239 -----------------------------
18240 -- Save_SPARK_Mode_And_Set --
18241 -----------------------------
18242
18243 procedure Save_SPARK_Mode_And_Set
18244 (Context : Entity_Id;
18245 Mode : out SPARK_Mode_Type)
18246 is
18247 begin
18248 -- Save the current mode in effect
18249
18250 Mode := SPARK_Mode;
18251
18252 -- Do not consider illegal or partially decorated constructs
18253
18254 if Ekind (Context) = E_Void or else Error_Posted (Context) then
18255 null;
18256
18257 elsif Present (SPARK_Pragma (Context)) then
18258 SPARK_Mode := Get_SPARK_Mode_From_Pragma (SPARK_Pragma (Context));
18259 end if;
18260 end Save_SPARK_Mode_And_Set;
18261
18262 -------------------------
18263 -- Scalar_Part_Present --
18264 -------------------------
18265
18266 function Scalar_Part_Present (T : Entity_Id) return Boolean is
18267 C : Entity_Id;
18268
18269 begin
18270 if Is_Scalar_Type (T) then
18271 return True;
18272
18273 elsif Is_Array_Type (T) then
18274 return Scalar_Part_Present (Component_Type (T));
18275
18276 elsif Is_Record_Type (T) or else Has_Discriminants (T) then
18277 C := First_Component_Or_Discriminant (T);
18278 while Present (C) loop
18279 if Scalar_Part_Present (Etype (C)) then
18280 return True;
18281 else
18282 Next_Component_Or_Discriminant (C);
18283 end if;
18284 end loop;
18285 end if;
18286
18287 return False;
18288 end Scalar_Part_Present;
18289
18290 ------------------------
18291 -- Scope_Is_Transient --
18292 ------------------------
18293
18294 function Scope_Is_Transient return Boolean is
18295 begin
18296 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
18297 end Scope_Is_Transient;
18298
18299 ------------------
18300 -- Scope_Within --
18301 ------------------
18302
18303 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
18304 Scop : Entity_Id;
18305
18306 begin
18307 Scop := Scope1;
18308 while Scop /= Standard_Standard loop
18309 Scop := Scope (Scop);
18310
18311 if Scop = Scope2 then
18312 return True;
18313 end if;
18314 end loop;
18315
18316 return False;
18317 end Scope_Within;
18318
18319 --------------------------
18320 -- Scope_Within_Or_Same --
18321 --------------------------
18322
18323 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
18324 Scop : Entity_Id;
18325
18326 begin
18327 Scop := Scope1;
18328 while Scop /= Standard_Standard loop
18329 if Scop = Scope2 then
18330 return True;
18331 else
18332 Scop := Scope (Scop);
18333 end if;
18334 end loop;
18335
18336 return False;
18337 end Scope_Within_Or_Same;
18338
18339 --------------------
18340 -- Set_Convention --
18341 --------------------
18342
18343 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
18344 begin
18345 Basic_Set_Convention (E, Val);
18346
18347 if Is_Type (E)
18348 and then Is_Access_Subprogram_Type (Base_Type (E))
18349 and then Has_Foreign_Convention (E)
18350 then
18351
18352 -- A pragma Convention in an instance may apply to the subtype
18353 -- created for a formal, in which case we have already verified
18354 -- that conventions of actual and formal match and there is nothing
18355 -- to flag on the subtype.
18356
18357 if In_Instance then
18358 null;
18359 else
18360 Set_Can_Use_Internal_Rep (E, False);
18361 end if;
18362 end if;
18363
18364 -- If E is an object or component, and the type of E is an anonymous
18365 -- access type with no convention set, then also set the convention of
18366 -- the anonymous access type. We do not do this for anonymous protected
18367 -- types, since protected types always have the default convention.
18368
18369 if Present (Etype (E))
18370 and then (Is_Object (E)
18371 or else Ekind (E) = E_Component
18372
18373 -- Allow E_Void (happens for pragma Convention appearing
18374 -- in the middle of a record applying to a component)
18375
18376 or else Ekind (E) = E_Void)
18377 then
18378 declare
18379 Typ : constant Entity_Id := Etype (E);
18380
18381 begin
18382 if Ekind_In (Typ, E_Anonymous_Access_Type,
18383 E_Anonymous_Access_Subprogram_Type)
18384 and then not Has_Convention_Pragma (Typ)
18385 then
18386 Basic_Set_Convention (Typ, Val);
18387 Set_Has_Convention_Pragma (Typ);
18388
18389 -- And for the access subprogram type, deal similarly with the
18390 -- designated E_Subprogram_Type if it is also internal (which
18391 -- it always is?)
18392
18393 if Ekind (Typ) = E_Anonymous_Access_Subprogram_Type then
18394 declare
18395 Dtype : constant Entity_Id := Designated_Type (Typ);
18396 begin
18397 if Ekind (Dtype) = E_Subprogram_Type
18398 and then Is_Itype (Dtype)
18399 and then not Has_Convention_Pragma (Dtype)
18400 then
18401 Basic_Set_Convention (Dtype, Val);
18402 Set_Has_Convention_Pragma (Dtype);
18403 end if;
18404 end;
18405 end if;
18406 end if;
18407 end;
18408 end if;
18409 end Set_Convention;
18410
18411 ------------------------
18412 -- Set_Current_Entity --
18413 ------------------------
18414
18415 -- The given entity is to be set as the currently visible definition of its
18416 -- associated name (i.e. the Node_Id associated with its name). All we have
18417 -- to do is to get the name from the identifier, and then set the
18418 -- associated Node_Id to point to the given entity.
18419
18420 procedure Set_Current_Entity (E : Entity_Id) is
18421 begin
18422 Set_Name_Entity_Id (Chars (E), E);
18423 end Set_Current_Entity;
18424
18425 ---------------------------
18426 -- Set_Debug_Info_Needed --
18427 ---------------------------
18428
18429 procedure Set_Debug_Info_Needed (T : Entity_Id) is
18430
18431 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
18432 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
18433 -- Used to set debug info in a related node if not set already
18434
18435 --------------------------------------
18436 -- Set_Debug_Info_Needed_If_Not_Set --
18437 --------------------------------------
18438
18439 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
18440 begin
18441 if Present (E) and then not Needs_Debug_Info (E) then
18442 Set_Debug_Info_Needed (E);
18443
18444 -- For a private type, indicate that the full view also needs
18445 -- debug information.
18446
18447 if Is_Type (E)
18448 and then Is_Private_Type (E)
18449 and then Present (Full_View (E))
18450 then
18451 Set_Debug_Info_Needed (Full_View (E));
18452 end if;
18453 end if;
18454 end Set_Debug_Info_Needed_If_Not_Set;
18455
18456 -- Start of processing for Set_Debug_Info_Needed
18457
18458 begin
18459 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
18460 -- indicates that Debug_Info_Needed is never required for the entity.
18461 -- Nothing to do if entity comes from a predefined file. Library files
18462 -- are compiled without debug information, but inlined bodies of these
18463 -- routines may appear in user code, and debug information on them ends
18464 -- up complicating debugging the user code.
18465
18466 if No (T)
18467 or else Debug_Info_Off (T)
18468 then
18469 return;
18470
18471 elsif In_Inlined_Body
18472 and then Is_Predefined_File_Name
18473 (Unit_File_Name (Get_Source_Unit (Sloc (T))))
18474 then
18475 Set_Needs_Debug_Info (T, False);
18476 end if;
18477
18478 -- Set flag in entity itself. Note that we will go through the following
18479 -- circuitry even if the flag is already set on T. That's intentional,
18480 -- it makes sure that the flag will be set in subsidiary entities.
18481
18482 Set_Needs_Debug_Info (T);
18483
18484 -- Set flag on subsidiary entities if not set already
18485
18486 if Is_Object (T) then
18487 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
18488
18489 elsif Is_Type (T) then
18490 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
18491
18492 if Is_Record_Type (T) then
18493 declare
18494 Ent : Entity_Id := First_Entity (T);
18495 begin
18496 while Present (Ent) loop
18497 Set_Debug_Info_Needed_If_Not_Set (Ent);
18498 Next_Entity (Ent);
18499 end loop;
18500 end;
18501
18502 -- For a class wide subtype, we also need debug information
18503 -- for the equivalent type.
18504
18505 if Ekind (T) = E_Class_Wide_Subtype then
18506 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
18507 end if;
18508
18509 elsif Is_Array_Type (T) then
18510 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
18511
18512 declare
18513 Indx : Node_Id := First_Index (T);
18514 begin
18515 while Present (Indx) loop
18516 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
18517 Indx := Next_Index (Indx);
18518 end loop;
18519 end;
18520
18521 -- For a packed array type, we also need debug information for
18522 -- the type used to represent the packed array. Conversely, we
18523 -- also need it for the former if we need it for the latter.
18524
18525 if Is_Packed (T) then
18526 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Impl_Type (T));
18527 end if;
18528
18529 if Is_Packed_Array_Impl_Type (T) then
18530 Set_Debug_Info_Needed_If_Not_Set (Original_Array_Type (T));
18531 end if;
18532
18533 elsif Is_Access_Type (T) then
18534 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
18535
18536 elsif Is_Private_Type (T) then
18537 declare
18538 FV : constant Entity_Id := Full_View (T);
18539
18540 begin
18541 Set_Debug_Info_Needed_If_Not_Set (FV);
18542
18543 -- If the full view is itself a derived private type, we need
18544 -- debug information on its underlying type.
18545
18546 if Present (FV)
18547 and then Is_Private_Type (FV)
18548 and then Present (Underlying_Full_View (FV))
18549 then
18550 Set_Needs_Debug_Info (Underlying_Full_View (FV));
18551 end if;
18552 end;
18553
18554 elsif Is_Protected_Type (T) then
18555 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
18556
18557 elsif Is_Scalar_Type (T) then
18558
18559 -- If the subrange bounds are materialized by dedicated constant
18560 -- objects, also include them in the debug info to make sure the
18561 -- debugger can properly use them.
18562
18563 if Present (Scalar_Range (T))
18564 and then Nkind (Scalar_Range (T)) = N_Range
18565 then
18566 declare
18567 Low_Bnd : constant Node_Id := Type_Low_Bound (T);
18568 High_Bnd : constant Node_Id := Type_High_Bound (T);
18569
18570 begin
18571 if Is_Entity_Name (Low_Bnd) then
18572 Set_Debug_Info_Needed_If_Not_Set (Entity (Low_Bnd));
18573 end if;
18574
18575 if Is_Entity_Name (High_Bnd) then
18576 Set_Debug_Info_Needed_If_Not_Set (Entity (High_Bnd));
18577 end if;
18578 end;
18579 end if;
18580 end if;
18581 end if;
18582 end Set_Debug_Info_Needed;
18583
18584 ----------------------------
18585 -- Set_Entity_With_Checks --
18586 ----------------------------
18587
18588 procedure Set_Entity_With_Checks (N : Node_Id; Val : Entity_Id) is
18589 Val_Actual : Entity_Id;
18590 Nod : Node_Id;
18591 Post_Node : Node_Id;
18592
18593 begin
18594 -- Unconditionally set the entity
18595
18596 Set_Entity (N, Val);
18597
18598 -- The node to post on is the selector in the case of an expanded name,
18599 -- and otherwise the node itself.
18600
18601 if Nkind (N) = N_Expanded_Name then
18602 Post_Node := Selector_Name (N);
18603 else
18604 Post_Node := N;
18605 end if;
18606
18607 -- Check for violation of No_Fixed_IO
18608
18609 if Restriction_Check_Required (No_Fixed_IO)
18610 and then
18611 ((RTU_Loaded (Ada_Text_IO)
18612 and then (Is_RTE (Val, RE_Decimal_IO)
18613 or else
18614 Is_RTE (Val, RE_Fixed_IO)))
18615
18616 or else
18617 (RTU_Loaded (Ada_Wide_Text_IO)
18618 and then (Is_RTE (Val, RO_WT_Decimal_IO)
18619 or else
18620 Is_RTE (Val, RO_WT_Fixed_IO)))
18621
18622 or else
18623 (RTU_Loaded (Ada_Wide_Wide_Text_IO)
18624 and then (Is_RTE (Val, RO_WW_Decimal_IO)
18625 or else
18626 Is_RTE (Val, RO_WW_Fixed_IO))))
18627
18628 -- A special extra check, don't complain about a reference from within
18629 -- the Ada.Interrupts package itself!
18630
18631 and then not In_Same_Extended_Unit (N, Val)
18632 then
18633 Check_Restriction (No_Fixed_IO, Post_Node);
18634 end if;
18635
18636 -- Remaining checks are only done on source nodes. Note that we test
18637 -- for violation of No_Fixed_IO even on non-source nodes, because the
18638 -- cases for checking violations of this restriction are instantiations
18639 -- where the reference in the instance has Comes_From_Source False.
18640
18641 if not Comes_From_Source (N) then
18642 return;
18643 end if;
18644
18645 -- Check for violation of No_Abort_Statements, which is triggered by
18646 -- call to Ada.Task_Identification.Abort_Task.
18647
18648 if Restriction_Check_Required (No_Abort_Statements)
18649 and then (Is_RTE (Val, RE_Abort_Task))
18650
18651 -- A special extra check, don't complain about a reference from within
18652 -- the Ada.Task_Identification package itself!
18653
18654 and then not In_Same_Extended_Unit (N, Val)
18655 then
18656 Check_Restriction (No_Abort_Statements, Post_Node);
18657 end if;
18658
18659 if Val = Standard_Long_Long_Integer then
18660 Check_Restriction (No_Long_Long_Integers, Post_Node);
18661 end if;
18662
18663 -- Check for violation of No_Dynamic_Attachment
18664
18665 if Restriction_Check_Required (No_Dynamic_Attachment)
18666 and then RTU_Loaded (Ada_Interrupts)
18667 and then (Is_RTE (Val, RE_Is_Reserved) or else
18668 Is_RTE (Val, RE_Is_Attached) or else
18669 Is_RTE (Val, RE_Current_Handler) or else
18670 Is_RTE (Val, RE_Attach_Handler) or else
18671 Is_RTE (Val, RE_Exchange_Handler) or else
18672 Is_RTE (Val, RE_Detach_Handler) or else
18673 Is_RTE (Val, RE_Reference))
18674
18675 -- A special extra check, don't complain about a reference from within
18676 -- the Ada.Interrupts package itself!
18677
18678 and then not In_Same_Extended_Unit (N, Val)
18679 then
18680 Check_Restriction (No_Dynamic_Attachment, Post_Node);
18681 end if;
18682
18683 -- Check for No_Implementation_Identifiers
18684
18685 if Restriction_Check_Required (No_Implementation_Identifiers) then
18686
18687 -- We have an implementation defined entity if it is marked as
18688 -- implementation defined, or is defined in a package marked as
18689 -- implementation defined. However, library packages themselves
18690 -- are excluded (we don't want to flag Interfaces itself, just
18691 -- the entities within it).
18692
18693 if (Is_Implementation_Defined (Val)
18694 or else
18695 (Present (Scope (Val))
18696 and then Is_Implementation_Defined (Scope (Val))))
18697 and then not (Ekind_In (Val, E_Package, E_Generic_Package)
18698 and then Is_Library_Level_Entity (Val))
18699 then
18700 Check_Restriction (No_Implementation_Identifiers, Post_Node);
18701 end if;
18702 end if;
18703
18704 -- Do the style check
18705
18706 if Style_Check
18707 and then not Suppress_Style_Checks (Val)
18708 and then not In_Instance
18709 then
18710 if Nkind (N) = N_Identifier then
18711 Nod := N;
18712 elsif Nkind (N) = N_Expanded_Name then
18713 Nod := Selector_Name (N);
18714 else
18715 return;
18716 end if;
18717
18718 -- A special situation arises for derived operations, where we want
18719 -- to do the check against the parent (since the Sloc of the derived
18720 -- operation points to the derived type declaration itself).
18721
18722 Val_Actual := Val;
18723 while not Comes_From_Source (Val_Actual)
18724 and then Nkind (Val_Actual) in N_Entity
18725 and then (Ekind (Val_Actual) = E_Enumeration_Literal
18726 or else Is_Subprogram_Or_Generic_Subprogram (Val_Actual))
18727 and then Present (Alias (Val_Actual))
18728 loop
18729 Val_Actual := Alias (Val_Actual);
18730 end loop;
18731
18732 -- Renaming declarations for generic actuals do not come from source,
18733 -- and have a different name from that of the entity they rename, so
18734 -- there is no style check to perform here.
18735
18736 if Chars (Nod) = Chars (Val_Actual) then
18737 Style.Check_Identifier (Nod, Val_Actual);
18738 end if;
18739 end if;
18740
18741 Set_Entity (N, Val);
18742 end Set_Entity_With_Checks;
18743
18744 ------------------------
18745 -- Set_Name_Entity_Id --
18746 ------------------------
18747
18748 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
18749 begin
18750 Set_Name_Table_Int (Id, Int (Val));
18751 end Set_Name_Entity_Id;
18752
18753 ---------------------
18754 -- Set_Next_Actual --
18755 ---------------------
18756
18757 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
18758 begin
18759 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
18760 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
18761 end if;
18762 end Set_Next_Actual;
18763
18764 ----------------------------------
18765 -- Set_Optimize_Alignment_Flags --
18766 ----------------------------------
18767
18768 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
18769 begin
18770 if Optimize_Alignment = 'S' then
18771 Set_Optimize_Alignment_Space (E);
18772 elsif Optimize_Alignment = 'T' then
18773 Set_Optimize_Alignment_Time (E);
18774 end if;
18775 end Set_Optimize_Alignment_Flags;
18776
18777 -----------------------
18778 -- Set_Public_Status --
18779 -----------------------
18780
18781 procedure Set_Public_Status (Id : Entity_Id) is
18782 S : constant Entity_Id := Current_Scope;
18783
18784 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
18785 -- Determines if E is defined within handled statement sequence or
18786 -- an if statement, returns True if so, False otherwise.
18787
18788 ----------------------
18789 -- Within_HSS_Or_If --
18790 ----------------------
18791
18792 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
18793 N : Node_Id;
18794 begin
18795 N := Declaration_Node (E);
18796 loop
18797 N := Parent (N);
18798
18799 if No (N) then
18800 return False;
18801
18802 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
18803 N_If_Statement)
18804 then
18805 return True;
18806 end if;
18807 end loop;
18808 end Within_HSS_Or_If;
18809
18810 -- Start of processing for Set_Public_Status
18811
18812 begin
18813 -- Everything in the scope of Standard is public
18814
18815 if S = Standard_Standard then
18816 Set_Is_Public (Id);
18817
18818 -- Entity is definitely not public if enclosing scope is not public
18819
18820 elsif not Is_Public (S) then
18821 return;
18822
18823 -- An object or function declaration that occurs in a handled sequence
18824 -- of statements or within an if statement is the declaration for a
18825 -- temporary object or local subprogram generated by the expander. It
18826 -- never needs to be made public and furthermore, making it public can
18827 -- cause back end problems.
18828
18829 elsif Nkind_In (Parent (Id), N_Object_Declaration,
18830 N_Function_Specification)
18831 and then Within_HSS_Or_If (Id)
18832 then
18833 return;
18834
18835 -- Entities in public packages or records are public
18836
18837 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
18838 Set_Is_Public (Id);
18839
18840 -- The bounds of an entry family declaration can generate object
18841 -- declarations that are visible to the back-end, e.g. in the
18842 -- the declaration of a composite type that contains tasks.
18843
18844 elsif Is_Concurrent_Type (S)
18845 and then not Has_Completion (S)
18846 and then Nkind (Parent (Id)) = N_Object_Declaration
18847 then
18848 Set_Is_Public (Id);
18849 end if;
18850 end Set_Public_Status;
18851
18852 -----------------------------
18853 -- Set_Referenced_Modified --
18854 -----------------------------
18855
18856 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
18857 Pref : Node_Id;
18858
18859 begin
18860 -- Deal with indexed or selected component where prefix is modified
18861
18862 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
18863 Pref := Prefix (N);
18864
18865 -- If prefix is access type, then it is the designated object that is
18866 -- being modified, which means we have no entity to set the flag on.
18867
18868 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
18869 return;
18870
18871 -- Otherwise chase the prefix
18872
18873 else
18874 Set_Referenced_Modified (Pref, Out_Param);
18875 end if;
18876
18877 -- Otherwise see if we have an entity name (only other case to process)
18878
18879 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
18880 Set_Referenced_As_LHS (Entity (N), not Out_Param);
18881 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
18882 end if;
18883 end Set_Referenced_Modified;
18884
18885 ----------------------------
18886 -- Set_Scope_Is_Transient --
18887 ----------------------------
18888
18889 procedure Set_Scope_Is_Transient (V : Boolean := True) is
18890 begin
18891 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
18892 end Set_Scope_Is_Transient;
18893
18894 -------------------
18895 -- Set_Size_Info --
18896 -------------------
18897
18898 procedure Set_Size_Info (T1, T2 : Entity_Id) is
18899 begin
18900 -- We copy Esize, but not RM_Size, since in general RM_Size is
18901 -- subtype specific and does not get inherited by all subtypes.
18902
18903 Set_Esize (T1, Esize (T2));
18904 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
18905
18906 if Is_Discrete_Or_Fixed_Point_Type (T1)
18907 and then
18908 Is_Discrete_Or_Fixed_Point_Type (T2)
18909 then
18910 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
18911 end if;
18912
18913 Set_Alignment (T1, Alignment (T2));
18914 end Set_Size_Info;
18915
18916 --------------------
18917 -- Static_Boolean --
18918 --------------------
18919
18920 function Static_Boolean (N : Node_Id) return Uint is
18921 begin
18922 Analyze_And_Resolve (N, Standard_Boolean);
18923
18924 if N = Error
18925 or else Error_Posted (N)
18926 or else Etype (N) = Any_Type
18927 then
18928 return No_Uint;
18929 end if;
18930
18931 if Is_OK_Static_Expression (N) then
18932 if not Raises_Constraint_Error (N) then
18933 return Expr_Value (N);
18934 else
18935 return No_Uint;
18936 end if;
18937
18938 elsif Etype (N) = Any_Type then
18939 return No_Uint;
18940
18941 else
18942 Flag_Non_Static_Expr
18943 ("static boolean expression required here", N);
18944 return No_Uint;
18945 end if;
18946 end Static_Boolean;
18947
18948 --------------------
18949 -- Static_Integer --
18950 --------------------
18951
18952 function Static_Integer (N : Node_Id) return Uint is
18953 begin
18954 Analyze_And_Resolve (N, Any_Integer);
18955
18956 if N = Error
18957 or else Error_Posted (N)
18958 or else Etype (N) = Any_Type
18959 then
18960 return No_Uint;
18961 end if;
18962
18963 if Is_OK_Static_Expression (N) then
18964 if not Raises_Constraint_Error (N) then
18965 return Expr_Value (N);
18966 else
18967 return No_Uint;
18968 end if;
18969
18970 elsif Etype (N) = Any_Type then
18971 return No_Uint;
18972
18973 else
18974 Flag_Non_Static_Expr
18975 ("static integer expression required here", N);
18976 return No_Uint;
18977 end if;
18978 end Static_Integer;
18979
18980 --------------------------
18981 -- Statically_Different --
18982 --------------------------
18983
18984 function Statically_Different (E1, E2 : Node_Id) return Boolean is
18985 R1 : constant Node_Id := Get_Referenced_Object (E1);
18986 R2 : constant Node_Id := Get_Referenced_Object (E2);
18987 begin
18988 return Is_Entity_Name (R1)
18989 and then Is_Entity_Name (R2)
18990 and then Entity (R1) /= Entity (R2)
18991 and then not Is_Formal (Entity (R1))
18992 and then not Is_Formal (Entity (R2));
18993 end Statically_Different;
18994
18995 --------------------------------------
18996 -- Subject_To_Loop_Entry_Attributes --
18997 --------------------------------------
18998
18999 function Subject_To_Loop_Entry_Attributes (N : Node_Id) return Boolean is
19000 Stmt : Node_Id;
19001
19002 begin
19003 Stmt := N;
19004
19005 -- The expansion mechanism transform a loop subject to at least one
19006 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
19007 -- the conditional part.
19008
19009 if Nkind_In (Stmt, N_Block_Statement, N_If_Statement)
19010 and then Nkind (Original_Node (N)) = N_Loop_Statement
19011 then
19012 Stmt := Original_Node (N);
19013 end if;
19014
19015 return
19016 Nkind (Stmt) = N_Loop_Statement
19017 and then Present (Identifier (Stmt))
19018 and then Present (Entity (Identifier (Stmt)))
19019 and then Has_Loop_Entry_Attributes (Entity (Identifier (Stmt)));
19020 end Subject_To_Loop_Entry_Attributes;
19021
19022 -----------------------------
19023 -- Subprogram_Access_Level --
19024 -----------------------------
19025
19026 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
19027 begin
19028 if Present (Alias (Subp)) then
19029 return Subprogram_Access_Level (Alias (Subp));
19030 else
19031 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
19032 end if;
19033 end Subprogram_Access_Level;
19034
19035 -------------------------------
19036 -- Support_Atomic_Primitives --
19037 -------------------------------
19038
19039 function Support_Atomic_Primitives (Typ : Entity_Id) return Boolean is
19040 Size : Int;
19041
19042 begin
19043 -- Verify the alignment of Typ is known
19044
19045 if not Known_Alignment (Typ) then
19046 return False;
19047 end if;
19048
19049 if Known_Static_Esize (Typ) then
19050 Size := UI_To_Int (Esize (Typ));
19051
19052 -- If the Esize (Object_Size) is unknown at compile time, look at the
19053 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
19054
19055 elsif Known_Static_RM_Size (Typ) then
19056 Size := UI_To_Int (RM_Size (Typ));
19057
19058 -- Otherwise, the size is considered to be unknown.
19059
19060 else
19061 return False;
19062 end if;
19063
19064 -- Check that the size of the component is 8, 16, 32 or 64 bits and that
19065 -- Typ is properly aligned.
19066
19067 case Size is
19068 when 8 | 16 | 32 | 64 =>
19069 return Size = UI_To_Int (Alignment (Typ)) * 8;
19070 when others =>
19071 return False;
19072 end case;
19073 end Support_Atomic_Primitives;
19074
19075 -----------------
19076 -- Trace_Scope --
19077 -----------------
19078
19079 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
19080 begin
19081 if Debug_Flag_W then
19082 for J in 0 .. Scope_Stack.Last loop
19083 Write_Str (" ");
19084 end loop;
19085
19086 Write_Str (Msg);
19087 Write_Name (Chars (E));
19088 Write_Str (" from ");
19089 Write_Location (Sloc (N));
19090 Write_Eol;
19091 end if;
19092 end Trace_Scope;
19093
19094 -----------------------
19095 -- Transfer_Entities --
19096 -----------------------
19097
19098 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
19099 procedure Set_Public_Status_Of (Id : Entity_Id);
19100 -- Set the Is_Public attribute of arbitrary entity Id by calling routine
19101 -- Set_Public_Status. If successfull and Id denotes a record type, set
19102 -- the Is_Public attribute of its fields.
19103
19104 --------------------------
19105 -- Set_Public_Status_Of --
19106 --------------------------
19107
19108 procedure Set_Public_Status_Of (Id : Entity_Id) is
19109 Field : Entity_Id;
19110
19111 begin
19112 if not Is_Public (Id) then
19113 Set_Public_Status (Id);
19114
19115 -- When the input entity is a public record type, ensure that all
19116 -- its internal fields are also exposed to the linker. The fields
19117 -- of a class-wide type are never made public.
19118
19119 if Is_Public (Id)
19120 and then Is_Record_Type (Id)
19121 and then not Is_Class_Wide_Type (Id)
19122 then
19123 Field := First_Entity (Id);
19124 while Present (Field) loop
19125 Set_Is_Public (Field);
19126 Next_Entity (Field);
19127 end loop;
19128 end if;
19129 end if;
19130 end Set_Public_Status_Of;
19131
19132 -- Local variables
19133
19134 Full_Id : Entity_Id;
19135 Id : Entity_Id;
19136
19137 -- Start of processing for Transfer_Entities
19138
19139 begin
19140 Id := First_Entity (From);
19141
19142 if Present (Id) then
19143
19144 -- Merge the entity chain of the source scope with that of the
19145 -- destination scope.
19146
19147 if Present (Last_Entity (To)) then
19148 Set_Next_Entity (Last_Entity (To), Id);
19149 else
19150 Set_First_Entity (To, Id);
19151 end if;
19152
19153 Set_Last_Entity (To, Last_Entity (From));
19154
19155 -- Inspect the entities of the source scope and update their Scope
19156 -- attribute.
19157
19158 while Present (Id) loop
19159 Set_Scope (Id, To);
19160 Set_Public_Status_Of (Id);
19161
19162 -- Handle an internally generated full view for a private type
19163
19164 if Is_Private_Type (Id)
19165 and then Present (Full_View (Id))
19166 and then Is_Itype (Full_View (Id))
19167 then
19168 Full_Id := Full_View (Id);
19169
19170 Set_Scope (Full_Id, To);
19171 Set_Public_Status_Of (Full_Id);
19172 end if;
19173
19174 Next_Entity (Id);
19175 end loop;
19176
19177 Set_First_Entity (From, Empty);
19178 Set_Last_Entity (From, Empty);
19179 end if;
19180 end Transfer_Entities;
19181
19182 -----------------------
19183 -- Type_Access_Level --
19184 -----------------------
19185
19186 function Type_Access_Level (Typ : Entity_Id) return Uint is
19187 Btyp : Entity_Id;
19188
19189 begin
19190 Btyp := Base_Type (Typ);
19191
19192 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
19193 -- simply use the level where the type is declared. This is true for
19194 -- stand-alone object declarations, and for anonymous access types
19195 -- associated with components the level is the same as that of the
19196 -- enclosing composite type. However, special treatment is needed for
19197 -- the cases of access parameters, return objects of an anonymous access
19198 -- type, and, in Ada 95, access discriminants of limited types.
19199
19200 if Is_Access_Type (Btyp) then
19201 if Ekind (Btyp) = E_Anonymous_Access_Type then
19202
19203 -- If the type is a nonlocal anonymous access type (such as for
19204 -- an access parameter) we treat it as being declared at the
19205 -- library level to ensure that names such as X.all'access don't
19206 -- fail static accessibility checks.
19207
19208 if not Is_Local_Anonymous_Access (Typ) then
19209 return Scope_Depth (Standard_Standard);
19210
19211 -- If this is a return object, the accessibility level is that of
19212 -- the result subtype of the enclosing function. The test here is
19213 -- little complicated, because we have to account for extended
19214 -- return statements that have been rewritten as blocks, in which
19215 -- case we have to find and the Is_Return_Object attribute of the
19216 -- itype's associated object. It would be nice to find a way to
19217 -- simplify this test, but it doesn't seem worthwhile to add a new
19218 -- flag just for purposes of this test. ???
19219
19220 elsif Ekind (Scope (Btyp)) = E_Return_Statement
19221 or else
19222 (Is_Itype (Btyp)
19223 and then Nkind (Associated_Node_For_Itype (Btyp)) =
19224 N_Object_Declaration
19225 and then Is_Return_Object
19226 (Defining_Identifier
19227 (Associated_Node_For_Itype (Btyp))))
19228 then
19229 declare
19230 Scop : Entity_Id;
19231
19232 begin
19233 Scop := Scope (Scope (Btyp));
19234 while Present (Scop) loop
19235 exit when Ekind (Scop) = E_Function;
19236 Scop := Scope (Scop);
19237 end loop;
19238
19239 -- Treat the return object's type as having the level of the
19240 -- function's result subtype (as per RM05-6.5(5.3/2)).
19241
19242 return Type_Access_Level (Etype (Scop));
19243 end;
19244 end if;
19245 end if;
19246
19247 Btyp := Root_Type (Btyp);
19248
19249 -- The accessibility level of anonymous access types associated with
19250 -- discriminants is that of the current instance of the type, and
19251 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
19252
19253 -- AI-402: access discriminants have accessibility based on the
19254 -- object rather than the type in Ada 2005, so the above paragraph
19255 -- doesn't apply.
19256
19257 -- ??? Needs completion with rules from AI-416
19258
19259 if Ada_Version <= Ada_95
19260 and then Ekind (Typ) = E_Anonymous_Access_Type
19261 and then Present (Associated_Node_For_Itype (Typ))
19262 and then Nkind (Associated_Node_For_Itype (Typ)) =
19263 N_Discriminant_Specification
19264 then
19265 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
19266 end if;
19267 end if;
19268
19269 -- Return library level for a generic formal type. This is done because
19270 -- RM(10.3.2) says that "The statically deeper relationship does not
19271 -- apply to ... a descendant of a generic formal type". Rather than
19272 -- checking at each point where a static accessibility check is
19273 -- performed to see if we are dealing with a formal type, this rule is
19274 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
19275 -- return extreme values for a formal type; Deepest_Type_Access_Level
19276 -- returns Int'Last. By calling the appropriate function from among the
19277 -- two, we ensure that the static accessibility check will pass if we
19278 -- happen to run into a formal type. More specifically, we should call
19279 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
19280 -- call occurs as part of a static accessibility check and the error
19281 -- case is the case where the type's level is too shallow (as opposed
19282 -- to too deep).
19283
19284 if Is_Generic_Type (Root_Type (Btyp)) then
19285 return Scope_Depth (Standard_Standard);
19286 end if;
19287
19288 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
19289 end Type_Access_Level;
19290
19291 ------------------------------------
19292 -- Type_Without_Stream_Operation --
19293 ------------------------------------
19294
19295 function Type_Without_Stream_Operation
19296 (T : Entity_Id;
19297 Op : TSS_Name_Type := TSS_Null) return Entity_Id
19298 is
19299 BT : constant Entity_Id := Base_Type (T);
19300 Op_Missing : Boolean;
19301
19302 begin
19303 if not Restriction_Active (No_Default_Stream_Attributes) then
19304 return Empty;
19305 end if;
19306
19307 if Is_Elementary_Type (T) then
19308 if Op = TSS_Null then
19309 Op_Missing :=
19310 No (TSS (BT, TSS_Stream_Read))
19311 or else No (TSS (BT, TSS_Stream_Write));
19312
19313 else
19314 Op_Missing := No (TSS (BT, Op));
19315 end if;
19316
19317 if Op_Missing then
19318 return T;
19319 else
19320 return Empty;
19321 end if;
19322
19323 elsif Is_Array_Type (T) then
19324 return Type_Without_Stream_Operation (Component_Type (T), Op);
19325
19326 elsif Is_Record_Type (T) then
19327 declare
19328 Comp : Entity_Id;
19329 C_Typ : Entity_Id;
19330
19331 begin
19332 Comp := First_Component (T);
19333 while Present (Comp) loop
19334 C_Typ := Type_Without_Stream_Operation (Etype (Comp), Op);
19335
19336 if Present (C_Typ) then
19337 return C_Typ;
19338 end if;
19339
19340 Next_Component (Comp);
19341 end loop;
19342
19343 return Empty;
19344 end;
19345
19346 elsif Is_Private_Type (T) and then Present (Full_View (T)) then
19347 return Type_Without_Stream_Operation (Full_View (T), Op);
19348 else
19349 return Empty;
19350 end if;
19351 end Type_Without_Stream_Operation;
19352
19353 ----------------------------
19354 -- Unique_Defining_Entity --
19355 ----------------------------
19356
19357 function Unique_Defining_Entity (N : Node_Id) return Entity_Id is
19358 begin
19359 return Unique_Entity (Defining_Entity (N));
19360 end Unique_Defining_Entity;
19361
19362 -------------------
19363 -- Unique_Entity --
19364 -------------------
19365
19366 function Unique_Entity (E : Entity_Id) return Entity_Id is
19367 U : Entity_Id := E;
19368 P : Node_Id;
19369
19370 begin
19371 case Ekind (E) is
19372 when E_Constant =>
19373 if Present (Full_View (E)) then
19374 U := Full_View (E);
19375 end if;
19376
19377 when Entry_Kind =>
19378 if Nkind (Parent (E)) = N_Entry_Body then
19379 declare
19380 Prot_Item : Entity_Id;
19381 begin
19382 -- Traverse the entity list of the protected type and locate
19383 -- an entry declaration which matches the entry body.
19384
19385 Prot_Item := First_Entity (Scope (E));
19386 while Present (Prot_Item) loop
19387 if Ekind (Prot_Item) = E_Entry
19388 and then Corresponding_Body (Parent (Prot_Item)) = E
19389 then
19390 U := Prot_Item;
19391 exit;
19392 end if;
19393
19394 Next_Entity (Prot_Item);
19395 end loop;
19396 end;
19397 end if;
19398
19399 when Formal_Kind =>
19400 if Present (Spec_Entity (E)) then
19401 U := Spec_Entity (E);
19402 end if;
19403
19404 when E_Package_Body =>
19405 P := Parent (E);
19406
19407 if Nkind (P) = N_Defining_Program_Unit_Name then
19408 P := Parent (P);
19409 end if;
19410
19411 if Nkind (P) = N_Package_Body
19412 and then Present (Corresponding_Spec (P))
19413 then
19414 U := Corresponding_Spec (P);
19415
19416 elsif Nkind (P) = N_Package_Body_Stub
19417 and then Present (Corresponding_Spec_Of_Stub (P))
19418 then
19419 U := Corresponding_Spec_Of_Stub (P);
19420 end if;
19421
19422 when E_Protected_Body =>
19423 P := Parent (E);
19424
19425 if Nkind (P) = N_Protected_Body
19426 and then Present (Corresponding_Spec (P))
19427 then
19428 U := Corresponding_Spec (P);
19429
19430 elsif Nkind (P) = N_Protected_Body_Stub
19431 and then Present (Corresponding_Spec_Of_Stub (P))
19432 then
19433 U := Corresponding_Spec_Of_Stub (P);
19434 end if;
19435
19436 when E_Subprogram_Body =>
19437 P := Parent (E);
19438
19439 if Nkind (P) = N_Defining_Program_Unit_Name then
19440 P := Parent (P);
19441 end if;
19442
19443 P := Parent (P);
19444
19445 if Nkind (P) = N_Subprogram_Body
19446 and then Present (Corresponding_Spec (P))
19447 then
19448 U := Corresponding_Spec (P);
19449
19450 elsif Nkind (P) = N_Subprogram_Body_Stub
19451 and then Present (Corresponding_Spec_Of_Stub (P))
19452 then
19453 U := Corresponding_Spec_Of_Stub (P);
19454 end if;
19455
19456 when E_Task_Body =>
19457 P := Parent (E);
19458
19459 if Nkind (P) = N_Task_Body
19460 and then Present (Corresponding_Spec (P))
19461 then
19462 U := Corresponding_Spec (P);
19463
19464 elsif Nkind (P) = N_Task_Body_Stub
19465 and then Present (Corresponding_Spec_Of_Stub (P))
19466 then
19467 U := Corresponding_Spec_Of_Stub (P);
19468 end if;
19469
19470 when Type_Kind =>
19471 if Present (Full_View (E)) then
19472 U := Full_View (E);
19473 end if;
19474
19475 when others =>
19476 null;
19477 end case;
19478
19479 return U;
19480 end Unique_Entity;
19481
19482 -----------------
19483 -- Unique_Name --
19484 -----------------
19485
19486 function Unique_Name (E : Entity_Id) return String is
19487
19488 -- Names of E_Subprogram_Body or E_Package_Body entities are not
19489 -- reliable, as they may not include the overloading suffix. Instead,
19490 -- when looking for the name of E or one of its enclosing scope, we get
19491 -- the name of the corresponding Unique_Entity.
19492
19493 function Get_Scoped_Name (E : Entity_Id) return String;
19494 -- Return the name of E prefixed by all the names of the scopes to which
19495 -- E belongs, except for Standard.
19496
19497 ---------------------
19498 -- Get_Scoped_Name --
19499 ---------------------
19500
19501 function Get_Scoped_Name (E : Entity_Id) return String is
19502 Name : constant String := Get_Name_String (Chars (E));
19503 begin
19504 if Has_Fully_Qualified_Name (E)
19505 or else Scope (E) = Standard_Standard
19506 then
19507 return Name;
19508 else
19509 return Get_Scoped_Name (Unique_Entity (Scope (E))) & "__" & Name;
19510 end if;
19511 end Get_Scoped_Name;
19512
19513 -- Start of processing for Unique_Name
19514
19515 begin
19516 if E = Standard_Standard then
19517 return Get_Name_String (Name_Standard);
19518
19519 elsif Scope (E) = Standard_Standard
19520 and then not (Ekind (E) = E_Package or else Is_Subprogram (E))
19521 then
19522 return Get_Name_String (Name_Standard) & "__" &
19523 Get_Name_String (Chars (E));
19524
19525 elsif Ekind (E) = E_Enumeration_Literal then
19526 return Unique_Name (Etype (E)) & "__" & Get_Name_String (Chars (E));
19527
19528 else
19529 return Get_Scoped_Name (Unique_Entity (E));
19530 end if;
19531 end Unique_Name;
19532
19533 ---------------------
19534 -- Unit_Is_Visible --
19535 ---------------------
19536
19537 function Unit_Is_Visible (U : Entity_Id) return Boolean is
19538 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
19539 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
19540
19541 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
19542 -- For a child unit, check whether unit appears in a with_clause
19543 -- of a parent.
19544
19545 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
19546 -- Scan the context clause of one compilation unit looking for a
19547 -- with_clause for the unit in question.
19548
19549 ----------------------------
19550 -- Unit_In_Parent_Context --
19551 ----------------------------
19552
19553 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
19554 begin
19555 if Unit_In_Context (Par_Unit) then
19556 return True;
19557
19558 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
19559 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
19560
19561 else
19562 return False;
19563 end if;
19564 end Unit_In_Parent_Context;
19565
19566 ---------------------
19567 -- Unit_In_Context --
19568 ---------------------
19569
19570 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
19571 Clause : Node_Id;
19572
19573 begin
19574 Clause := First (Context_Items (Comp_Unit));
19575 while Present (Clause) loop
19576 if Nkind (Clause) = N_With_Clause then
19577 if Library_Unit (Clause) = U then
19578 return True;
19579
19580 -- The with_clause may denote a renaming of the unit we are
19581 -- looking for, eg. Text_IO which renames Ada.Text_IO.
19582
19583 elsif
19584 Renamed_Entity (Entity (Name (Clause))) =
19585 Defining_Entity (Unit (U))
19586 then
19587 return True;
19588 end if;
19589 end if;
19590
19591 Next (Clause);
19592 end loop;
19593
19594 return False;
19595 end Unit_In_Context;
19596
19597 -- Start of processing for Unit_Is_Visible
19598
19599 begin
19600 -- The currrent unit is directly visible
19601
19602 if Curr = U then
19603 return True;
19604
19605 elsif Unit_In_Context (Curr) then
19606 return True;
19607
19608 -- If the current unit is a body, check the context of the spec
19609
19610 elsif Nkind (Unit (Curr)) = N_Package_Body
19611 or else
19612 (Nkind (Unit (Curr)) = N_Subprogram_Body
19613 and then not Acts_As_Spec (Unit (Curr)))
19614 then
19615 if Unit_In_Context (Library_Unit (Curr)) then
19616 return True;
19617 end if;
19618 end if;
19619
19620 -- If the spec is a child unit, examine the parents
19621
19622 if Is_Child_Unit (Curr_Entity) then
19623 if Nkind (Unit (Curr)) in N_Unit_Body then
19624 return
19625 Unit_In_Parent_Context
19626 (Parent_Spec (Unit (Library_Unit (Curr))));
19627 else
19628 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
19629 end if;
19630
19631 else
19632 return False;
19633 end if;
19634 end Unit_Is_Visible;
19635
19636 ------------------------------
19637 -- Universal_Interpretation --
19638 ------------------------------
19639
19640 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
19641 Index : Interp_Index;
19642 It : Interp;
19643
19644 begin
19645 -- The argument may be a formal parameter of an operator or subprogram
19646 -- with multiple interpretations, or else an expression for an actual.
19647
19648 if Nkind (Opnd) = N_Defining_Identifier
19649 or else not Is_Overloaded (Opnd)
19650 then
19651 if Etype (Opnd) = Universal_Integer
19652 or else Etype (Opnd) = Universal_Real
19653 then
19654 return Etype (Opnd);
19655 else
19656 return Empty;
19657 end if;
19658
19659 else
19660 Get_First_Interp (Opnd, Index, It);
19661 while Present (It.Typ) loop
19662 if It.Typ = Universal_Integer
19663 or else It.Typ = Universal_Real
19664 then
19665 return It.Typ;
19666 end if;
19667
19668 Get_Next_Interp (Index, It);
19669 end loop;
19670
19671 return Empty;
19672 end if;
19673 end Universal_Interpretation;
19674
19675 ---------------
19676 -- Unqualify --
19677 ---------------
19678
19679 function Unqualify (Expr : Node_Id) return Node_Id is
19680 begin
19681 -- Recurse to handle unlikely case of multiple levels of qualification
19682
19683 if Nkind (Expr) = N_Qualified_Expression then
19684 return Unqualify (Expression (Expr));
19685
19686 -- Normal case, not a qualified expression
19687
19688 else
19689 return Expr;
19690 end if;
19691 end Unqualify;
19692
19693 -----------------------
19694 -- Visible_Ancestors --
19695 -----------------------
19696
19697 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
19698 List_1 : Elist_Id;
19699 List_2 : Elist_Id;
19700 Elmt : Elmt_Id;
19701
19702 begin
19703 pragma Assert (Is_Record_Type (Typ) and then Is_Tagged_Type (Typ));
19704
19705 -- Collect all the parents and progenitors of Typ. If the full-view of
19706 -- private parents and progenitors is available then it is used to
19707 -- generate the list of visible ancestors; otherwise their partial
19708 -- view is added to the resulting list.
19709
19710 Collect_Parents
19711 (T => Typ,
19712 List => List_1,
19713 Use_Full_View => True);
19714
19715 Collect_Interfaces
19716 (T => Typ,
19717 Ifaces_List => List_2,
19718 Exclude_Parents => True,
19719 Use_Full_View => True);
19720
19721 -- Join the two lists. Avoid duplications because an interface may
19722 -- simultaneously be parent and progenitor of a type.
19723
19724 Elmt := First_Elmt (List_2);
19725 while Present (Elmt) loop
19726 Append_Unique_Elmt (Node (Elmt), List_1);
19727 Next_Elmt (Elmt);
19728 end loop;
19729
19730 return List_1;
19731 end Visible_Ancestors;
19732
19733 ----------------------
19734 -- Within_Init_Proc --
19735 ----------------------
19736
19737 function Within_Init_Proc return Boolean is
19738 S : Entity_Id;
19739
19740 begin
19741 S := Current_Scope;
19742 while not Is_Overloadable (S) loop
19743 if S = Standard_Standard then
19744 return False;
19745 else
19746 S := Scope (S);
19747 end if;
19748 end loop;
19749
19750 return Is_Init_Proc (S);
19751 end Within_Init_Proc;
19752
19753 ------------------
19754 -- Within_Scope --
19755 ------------------
19756
19757 function Within_Scope (E : Entity_Id; S : Entity_Id) return Boolean is
19758 SE : Entity_Id;
19759 begin
19760 SE := Scope (E);
19761 loop
19762 if SE = S then
19763 return True;
19764 elsif SE = Standard_Standard then
19765 return False;
19766 else
19767 SE := Scope (SE);
19768 end if;
19769 end loop;
19770 end Within_Scope;
19771
19772 ----------------
19773 -- Wrong_Type --
19774 ----------------
19775
19776 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
19777 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
19778 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
19779
19780 Matching_Field : Entity_Id;
19781 -- Entity to give a more precise suggestion on how to write a one-
19782 -- element positional aggregate.
19783
19784 function Has_One_Matching_Field return Boolean;
19785 -- Determines if Expec_Type is a record type with a single component or
19786 -- discriminant whose type matches the found type or is one dimensional
19787 -- array whose component type matches the found type. In the case of
19788 -- one discriminant, we ignore the variant parts. That's not accurate,
19789 -- but good enough for the warning.
19790
19791 ----------------------------
19792 -- Has_One_Matching_Field --
19793 ----------------------------
19794
19795 function Has_One_Matching_Field return Boolean is
19796 E : Entity_Id;
19797
19798 begin
19799 Matching_Field := Empty;
19800
19801 if Is_Array_Type (Expec_Type)
19802 and then Number_Dimensions (Expec_Type) = 1
19803 and then Covers (Etype (Component_Type (Expec_Type)), Found_Type)
19804 then
19805 -- Use type name if available. This excludes multidimensional
19806 -- arrays and anonymous arrays.
19807
19808 if Comes_From_Source (Expec_Type) then
19809 Matching_Field := Expec_Type;
19810
19811 -- For an assignment, use name of target
19812
19813 elsif Nkind (Parent (Expr)) = N_Assignment_Statement
19814 and then Is_Entity_Name (Name (Parent (Expr)))
19815 then
19816 Matching_Field := Entity (Name (Parent (Expr)));
19817 end if;
19818
19819 return True;
19820
19821 elsif not Is_Record_Type (Expec_Type) then
19822 return False;
19823
19824 else
19825 E := First_Entity (Expec_Type);
19826 loop
19827 if No (E) then
19828 return False;
19829
19830 elsif not Ekind_In (E, E_Discriminant, E_Component)
19831 or else Nam_In (Chars (E), Name_uTag, Name_uParent)
19832 then
19833 Next_Entity (E);
19834
19835 else
19836 exit;
19837 end if;
19838 end loop;
19839
19840 if not Covers (Etype (E), Found_Type) then
19841 return False;
19842
19843 elsif Present (Next_Entity (E))
19844 and then (Ekind (E) = E_Component
19845 or else Ekind (Next_Entity (E)) = E_Discriminant)
19846 then
19847 return False;
19848
19849 else
19850 Matching_Field := E;
19851 return True;
19852 end if;
19853 end if;
19854 end Has_One_Matching_Field;
19855
19856 -- Start of processing for Wrong_Type
19857
19858 begin
19859 -- Don't output message if either type is Any_Type, or if a message
19860 -- has already been posted for this node. We need to do the latter
19861 -- check explicitly (it is ordinarily done in Errout), because we
19862 -- are using ! to force the output of the error messages.
19863
19864 if Expec_Type = Any_Type
19865 or else Found_Type = Any_Type
19866 or else Error_Posted (Expr)
19867 then
19868 return;
19869
19870 -- If one of the types is a Taft-Amendment type and the other it its
19871 -- completion, it must be an illegal use of a TAT in the spec, for
19872 -- which an error was already emitted. Avoid cascaded errors.
19873
19874 elsif Is_Incomplete_Type (Expec_Type)
19875 and then Has_Completion_In_Body (Expec_Type)
19876 and then Full_View (Expec_Type) = Etype (Expr)
19877 then
19878 return;
19879
19880 elsif Is_Incomplete_Type (Etype (Expr))
19881 and then Has_Completion_In_Body (Etype (Expr))
19882 and then Full_View (Etype (Expr)) = Expec_Type
19883 then
19884 return;
19885
19886 -- In an instance, there is an ongoing problem with completion of
19887 -- type derived from private types. Their structure is what Gigi
19888 -- expects, but the Etype is the parent type rather than the
19889 -- derived private type itself. Do not flag error in this case. The
19890 -- private completion is an entity without a parent, like an Itype.
19891 -- Similarly, full and partial views may be incorrect in the instance.
19892 -- There is no simple way to insure that it is consistent ???
19893
19894 -- A similar view discrepancy can happen in an inlined body, for the
19895 -- same reason: inserted body may be outside of the original package
19896 -- and only partial views are visible at the point of insertion.
19897
19898 elsif In_Instance or else In_Inlined_Body then
19899 if Etype (Etype (Expr)) = Etype (Expected_Type)
19900 and then
19901 (Has_Private_Declaration (Expected_Type)
19902 or else Has_Private_Declaration (Etype (Expr)))
19903 and then No (Parent (Expected_Type))
19904 then
19905 return;
19906
19907 elsif Nkind (Parent (Expr)) = N_Qualified_Expression
19908 and then Entity (Subtype_Mark (Parent (Expr))) = Expected_Type
19909 then
19910 return;
19911
19912 elsif Is_Private_Type (Expected_Type)
19913 and then Present (Full_View (Expected_Type))
19914 and then Covers (Full_View (Expected_Type), Etype (Expr))
19915 then
19916 return;
19917
19918 -- Conversely, type of expression may be the private one
19919
19920 elsif Is_Private_Type (Base_Type (Etype (Expr)))
19921 and then Full_View (Base_Type (Etype (Expr))) = Expected_Type
19922 then
19923 return;
19924 end if;
19925 end if;
19926
19927 -- An interesting special check. If the expression is parenthesized
19928 -- and its type corresponds to the type of the sole component of the
19929 -- expected record type, or to the component type of the expected one
19930 -- dimensional array type, then assume we have a bad aggregate attempt.
19931
19932 if Nkind (Expr) in N_Subexpr
19933 and then Paren_Count (Expr) /= 0
19934 and then Has_One_Matching_Field
19935 then
19936 Error_Msg_N ("positional aggregate cannot have one component", Expr);
19937
19938 if Present (Matching_Field) then
19939 if Is_Array_Type (Expec_Type) then
19940 Error_Msg_NE
19941 ("\write instead `&''First ='> ...`", Expr, Matching_Field);
19942 else
19943 Error_Msg_NE
19944 ("\write instead `& ='> ...`", Expr, Matching_Field);
19945 end if;
19946 end if;
19947
19948 -- Another special check, if we are looking for a pool-specific access
19949 -- type and we found an E_Access_Attribute_Type, then we have the case
19950 -- of an Access attribute being used in a context which needs a pool-
19951 -- specific type, which is never allowed. The one extra check we make
19952 -- is that the expected designated type covers the Found_Type.
19953
19954 elsif Is_Access_Type (Expec_Type)
19955 and then Ekind (Found_Type) = E_Access_Attribute_Type
19956 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
19957 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
19958 and then Covers
19959 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
19960 then
19961 Error_Msg_N -- CODEFIX
19962 ("result must be general access type!", Expr);
19963 Error_Msg_NE -- CODEFIX
19964 ("add ALL to }!", Expr, Expec_Type);
19965
19966 -- Another special check, if the expected type is an integer type,
19967 -- but the expression is of type System.Address, and the parent is
19968 -- an addition or subtraction operation whose left operand is the
19969 -- expression in question and whose right operand is of an integral
19970 -- type, then this is an attempt at address arithmetic, so give
19971 -- appropriate message.
19972
19973 elsif Is_Integer_Type (Expec_Type)
19974 and then Is_RTE (Found_Type, RE_Address)
19975 and then Nkind_In (Parent (Expr), N_Op_Add, N_Op_Subtract)
19976 and then Expr = Left_Opnd (Parent (Expr))
19977 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
19978 then
19979 Error_Msg_N
19980 ("address arithmetic not predefined in package System",
19981 Parent (Expr));
19982 Error_Msg_N
19983 ("\possible missing with/use of System.Storage_Elements",
19984 Parent (Expr));
19985 return;
19986
19987 -- If the expected type is an anonymous access type, as for access
19988 -- parameters and discriminants, the error is on the designated types.
19989
19990 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
19991 if Comes_From_Source (Expec_Type) then
19992 Error_Msg_NE ("expected}!", Expr, Expec_Type);
19993 else
19994 Error_Msg_NE
19995 ("expected an access type with designated}",
19996 Expr, Designated_Type (Expec_Type));
19997 end if;
19998
19999 if Is_Access_Type (Found_Type)
20000 and then not Comes_From_Source (Found_Type)
20001 then
20002 Error_Msg_NE
20003 ("\\found an access type with designated}!",
20004 Expr, Designated_Type (Found_Type));
20005 else
20006 if From_Limited_With (Found_Type) then
20007 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
20008 Error_Msg_Qual_Level := 99;
20009 Error_Msg_NE -- CODEFIX
20010 ("\\missing `WITH &;", Expr, Scope (Found_Type));
20011 Error_Msg_Qual_Level := 0;
20012 else
20013 Error_Msg_NE ("found}!", Expr, Found_Type);
20014 end if;
20015 end if;
20016
20017 -- Normal case of one type found, some other type expected
20018
20019 else
20020 -- If the names of the two types are the same, see if some number
20021 -- of levels of qualification will help. Don't try more than three
20022 -- levels, and if we get to standard, it's no use (and probably
20023 -- represents an error in the compiler) Also do not bother with
20024 -- internal scope names.
20025
20026 declare
20027 Expec_Scope : Entity_Id;
20028 Found_Scope : Entity_Id;
20029
20030 begin
20031 Expec_Scope := Expec_Type;
20032 Found_Scope := Found_Type;
20033
20034 for Levels in Nat range 0 .. 3 loop
20035 if Chars (Expec_Scope) /= Chars (Found_Scope) then
20036 Error_Msg_Qual_Level := Levels;
20037 exit;
20038 end if;
20039
20040 Expec_Scope := Scope (Expec_Scope);
20041 Found_Scope := Scope (Found_Scope);
20042
20043 exit when Expec_Scope = Standard_Standard
20044 or else Found_Scope = Standard_Standard
20045 or else not Comes_From_Source (Expec_Scope)
20046 or else not Comes_From_Source (Found_Scope);
20047 end loop;
20048 end;
20049
20050 if Is_Record_Type (Expec_Type)
20051 and then Present (Corresponding_Remote_Type (Expec_Type))
20052 then
20053 Error_Msg_NE ("expected}!", Expr,
20054 Corresponding_Remote_Type (Expec_Type));
20055 else
20056 Error_Msg_NE ("expected}!", Expr, Expec_Type);
20057 end if;
20058
20059 if Is_Entity_Name (Expr)
20060 and then Is_Package_Or_Generic_Package (Entity (Expr))
20061 then
20062 Error_Msg_N ("\\found package name!", Expr);
20063
20064 elsif Is_Entity_Name (Expr)
20065 and then Ekind_In (Entity (Expr), E_Procedure, E_Generic_Procedure)
20066 then
20067 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
20068 Error_Msg_N
20069 ("found procedure name, possibly missing Access attribute!",
20070 Expr);
20071 else
20072 Error_Msg_N
20073 ("\\found procedure name instead of function!", Expr);
20074 end if;
20075
20076 elsif Nkind (Expr) = N_Function_Call
20077 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
20078 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
20079 and then No (Parameter_Associations (Expr))
20080 then
20081 Error_Msg_N
20082 ("found function name, possibly missing Access attribute!",
20083 Expr);
20084
20085 -- Catch common error: a prefix or infix operator which is not
20086 -- directly visible because the type isn't.
20087
20088 elsif Nkind (Expr) in N_Op
20089 and then Is_Overloaded (Expr)
20090 and then not Is_Immediately_Visible (Expec_Type)
20091 and then not Is_Potentially_Use_Visible (Expec_Type)
20092 and then not In_Use (Expec_Type)
20093 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
20094 then
20095 Error_Msg_N
20096 ("operator of the type is not directly visible!", Expr);
20097
20098 elsif Ekind (Found_Type) = E_Void
20099 and then Present (Parent (Found_Type))
20100 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
20101 then
20102 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
20103
20104 else
20105 Error_Msg_NE ("\\found}!", Expr, Found_Type);
20106 end if;
20107
20108 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
20109 -- of the same modular type, and (M1 and M2) = 0 was intended.
20110
20111 if Expec_Type = Standard_Boolean
20112 and then Is_Modular_Integer_Type (Found_Type)
20113 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
20114 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
20115 then
20116 declare
20117 Op : constant Node_Id := Right_Opnd (Parent (Expr));
20118 L : constant Node_Id := Left_Opnd (Op);
20119 R : constant Node_Id := Right_Opnd (Op);
20120
20121 begin
20122 -- The case for the message is when the left operand of the
20123 -- comparison is the same modular type, or when it is an
20124 -- integer literal (or other universal integer expression),
20125 -- which would have been typed as the modular type if the
20126 -- parens had been there.
20127
20128 if (Etype (L) = Found_Type
20129 or else
20130 Etype (L) = Universal_Integer)
20131 and then Is_Integer_Type (Etype (R))
20132 then
20133 Error_Msg_N
20134 ("\\possible missing parens for modular operation", Expr);
20135 end if;
20136 end;
20137 end if;
20138
20139 -- Reset error message qualification indication
20140
20141 Error_Msg_Qual_Level := 0;
20142 end if;
20143 end Wrong_Type;
20144
20145 --------------------------------
20146 -- Yields_Synchronized_Object --
20147 --------------------------------
20148
20149 function Yields_Synchronized_Object (Typ : Entity_Id) return Boolean is
20150 Has_Sync_Comp : Boolean := False;
20151 Id : Entity_Id;
20152
20153 begin
20154 -- An array type yields a synchronized object if its component type
20155 -- yields a synchronized object.
20156
20157 if Is_Array_Type (Typ) then
20158 return Yields_Synchronized_Object (Component_Type (Typ));
20159
20160 -- A descendant of type Ada.Synchronous_Task_Control.Suspension_Object
20161 -- yields a synchronized object by default.
20162
20163 elsif Is_Descendant_Of_Suspension_Object (Typ) then
20164 return True;
20165
20166 -- A protected type yields a synchronized object by default
20167
20168 elsif Is_Protected_Type (Typ) then
20169 return True;
20170
20171 -- A record type or type extension yields a synchronized object when its
20172 -- discriminants (if any) lack default values and all components are of
20173 -- a type that yelds a synchronized object.
20174
20175 elsif Is_Record_Type (Typ) then
20176
20177 -- Inspect all entities defined in the scope of the type, looking for
20178 -- components of a type that does not yeld a synchronized object or
20179 -- for discriminants with default values.
20180
20181 Id := First_Entity (Typ);
20182 while Present (Id) loop
20183 if Comes_From_Source (Id) then
20184 if Ekind (Id) = E_Component then
20185 if Yields_Synchronized_Object (Etype (Id)) then
20186 Has_Sync_Comp := True;
20187
20188 -- The component does not yield a synchronized object
20189
20190 else
20191 return False;
20192 end if;
20193
20194 elsif Ekind (Id) = E_Discriminant
20195 and then Present (Expression (Parent (Id)))
20196 then
20197 return False;
20198 end if;
20199 end if;
20200
20201 Next_Entity (Id);
20202 end loop;
20203
20204 -- Ensure that the parent type of a type extension yields a
20205 -- synchronized object.
20206
20207 if Etype (Typ) /= Typ
20208 and then not Yields_Synchronized_Object (Etype (Typ))
20209 then
20210 return False;
20211 end if;
20212
20213 -- If we get here, then all discriminants lack default values and all
20214 -- components are of a type that yields a synchronized object.
20215
20216 return Has_Sync_Comp;
20217
20218 -- A synchronized interface type yields a synchronized object by default
20219
20220 elsif Is_Synchronized_Interface (Typ) then
20221 return True;
20222
20223 -- A task type yelds a synchronized object by default
20224
20225 elsif Is_Task_Type (Typ) then
20226 return True;
20227
20228 -- Otherwise the type does not yield a synchronized object
20229
20230 else
20231 return False;
20232 end if;
20233 end Yields_Synchronized_Object;
20234
20235 end Sem_Util;
This page took 0.924983 seconds and 6 git commands to generate.