Fix date
[official-gcc.git] / gcc / ada / sem_util.adb
blobfcb9453c8189b098f929813d15832629f80cab06
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S E M _ U T I L --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2017, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 with Treepr; -- ???For debugging code below
28 with Aspects; use Aspects;
29 with Atree; use Atree;
30 with Casing; use Casing;
31 with Checks; use Checks;
32 with Debug; use Debug;
33 with Elists; use Elists;
34 with Errout; use Errout;
35 with Erroutc; use Erroutc;
36 with Exp_Ch11; use Exp_Ch11;
37 with Exp_Disp; use Exp_Disp;
38 with Exp_Util; use Exp_Util;
39 with Fname; use Fname;
40 with Freeze; use Freeze;
41 with Lib; use Lib;
42 with Lib.Xref; use Lib.Xref;
43 with Namet.Sp; use Namet.Sp;
44 with Nlists; use Nlists;
45 with Nmake; use Nmake;
46 with Output; use Output;
47 with Restrict; use Restrict;
48 with Rident; use Rident;
49 with Rtsfind; use Rtsfind;
50 with Sem; use Sem;
51 with Sem_Aux; use Sem_Aux;
52 with Sem_Attr; use Sem_Attr;
53 with Sem_Ch6; use Sem_Ch6;
54 with Sem_Ch8; use Sem_Ch8;
55 with Sem_Disp; use Sem_Disp;
56 with Sem_Eval; use Sem_Eval;
57 with Sem_Prag; use Sem_Prag;
58 with Sem_Res; use Sem_Res;
59 with Sem_Warn; use Sem_Warn;
60 with Sem_Type; use Sem_Type;
61 with Sinfo; use Sinfo;
62 with Sinput; use Sinput;
63 with Stand; use Stand;
64 with Style;
65 with Stringt; use Stringt;
66 with Targparm; use Targparm;
67 with Tbuild; use Tbuild;
68 with Ttypes; use Ttypes;
69 with Uname; use Uname;
71 with GNAT.HTable; use GNAT.HTable;
73 package body Sem_Util is
75 -----------------------
76 -- Local Subprograms --
77 -----------------------
79 function Build_Component_Subtype
80 (C : List_Id;
81 Loc : Source_Ptr;
82 T : Entity_Id) return Node_Id;
83 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
84 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
85 -- Loc is the source location, T is the original subtype.
87 function Has_Enabled_Property
88 (Item_Id : Entity_Id;
89 Property : Name_Id) return Boolean;
90 -- Subsidiary to routines Async_xxx_Enabled and Effective_xxx_Enabled.
91 -- Determine whether an abstract state or a variable denoted by entity
92 -- Item_Id has enabled property Property.
94 function Has_Null_Extension (T : Entity_Id) return Boolean;
95 -- T is a derived tagged type. Check whether the type extension is null.
96 -- If the parent type is fully initialized, T can be treated as such.
98 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
99 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
100 -- with discriminants whose default values are static, examine only the
101 -- components in the selected variant to determine whether all of them
102 -- have a default.
104 type Null_Status_Kind is
105 (Is_Null,
106 -- This value indicates that a subexpression is known to have a null
107 -- value at compile time.
109 Is_Non_Null,
110 -- This value indicates that a subexpression is known to have a non-null
111 -- value at compile time.
113 Unknown);
114 -- This value indicates that it cannot be determined at compile time
115 -- whether a subexpression yields a null or non-null value.
117 function Null_Status (N : Node_Id) return Null_Status_Kind;
118 -- Determine whether subexpression N of an access type yields a null value,
119 -- a non-null value, or the value cannot be determined at compile time. The
120 -- routine does not take simple flow diagnostics into account, it relies on
121 -- static facts such as the presence of null exclusions.
123 function Old_Requires_Transient_Scope (Id : Entity_Id) return Boolean;
124 function New_Requires_Transient_Scope (Id : Entity_Id) return Boolean;
125 -- ???We retain the old and new algorithms for Requires_Transient_Scope for
126 -- the time being. New_Requires_Transient_Scope is used by default; the
127 -- debug switch -gnatdQ can be used to do Old_Requires_Transient_Scope
128 -- instead. The intent is to use this temporarily to measure before/after
129 -- efficiency. Note: when this temporary code is removed, the documentation
130 -- of dQ in debug.adb should be removed.
132 procedure Results_Differ
133 (Id : Entity_Id;
134 Old_Val : Boolean;
135 New_Val : Boolean);
136 -- ???Debugging code. Called when the Old_Val and New_Val differ. This
137 -- routine will be removed eventially when New_Requires_Transient_Scope
138 -- becomes Requires_Transient_Scope and Old_Requires_Transient_Scope is
139 -- eliminated.
141 function Subprogram_Name (N : Node_Id) return String;
142 -- Return the fully qualified name of the enclosing subprogram for the
143 -- given node N.
145 ------------------------------
146 -- Abstract_Interface_List --
147 ------------------------------
149 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
150 Nod : Node_Id;
152 begin
153 if Is_Concurrent_Type (Typ) then
155 -- If we are dealing with a synchronized subtype, go to the base
156 -- type, whose declaration has the interface list.
158 -- Shouldn't this be Declaration_Node???
160 Nod := Parent (Base_Type (Typ));
162 if Nkind (Nod) = N_Full_Type_Declaration then
163 return Empty_List;
164 end if;
166 elsif Ekind (Typ) = E_Record_Type_With_Private then
167 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
168 Nod := Type_Definition (Parent (Typ));
170 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
171 if Present (Full_View (Typ))
172 and then
173 Nkind (Parent (Full_View (Typ))) = N_Full_Type_Declaration
174 then
175 Nod := Type_Definition (Parent (Full_View (Typ)));
177 -- If the full-view is not available we cannot do anything else
178 -- here (the source has errors).
180 else
181 return Empty_List;
182 end if;
184 -- Support for generic formals with interfaces is still missing ???
186 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
187 return Empty_List;
189 else
190 pragma Assert
191 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
192 Nod := Parent (Typ);
193 end if;
195 elsif Ekind (Typ) = E_Record_Subtype then
196 Nod := Type_Definition (Parent (Etype (Typ)));
198 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
200 -- Recurse, because parent may still be a private extension. Also
201 -- note that the full view of the subtype or the full view of its
202 -- base type may (both) be unavailable.
204 return Abstract_Interface_List (Etype (Typ));
206 elsif Ekind (Typ) = E_Record_Type then
207 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
208 Nod := Formal_Type_Definition (Parent (Typ));
209 else
210 Nod := Type_Definition (Parent (Typ));
211 end if;
213 -- Otherwise the type is of a kind which does not implement interfaces
215 else
216 return Empty_List;
217 end if;
219 return Interface_List (Nod);
220 end Abstract_Interface_List;
222 --------------------------------
223 -- Add_Access_Type_To_Process --
224 --------------------------------
226 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
227 L : Elist_Id;
229 begin
230 Ensure_Freeze_Node (E);
231 L := Access_Types_To_Process (Freeze_Node (E));
233 if No (L) then
234 L := New_Elmt_List;
235 Set_Access_Types_To_Process (Freeze_Node (E), L);
236 end if;
238 Append_Elmt (A, L);
239 end Add_Access_Type_To_Process;
241 --------------------------
242 -- Add_Block_Identifier --
243 --------------------------
245 procedure Add_Block_Identifier (N : Node_Id; Id : out Entity_Id) is
246 Loc : constant Source_Ptr := Sloc (N);
248 begin
249 pragma Assert (Nkind (N) = N_Block_Statement);
251 -- The block already has a label, return its entity
253 if Present (Identifier (N)) then
254 Id := Entity (Identifier (N));
256 -- Create a new block label and set its attributes
258 else
259 Id := New_Internal_Entity (E_Block, Current_Scope, Loc, 'B');
260 Set_Etype (Id, Standard_Void_Type);
261 Set_Parent (Id, N);
263 Set_Identifier (N, New_Occurrence_Of (Id, Loc));
264 Set_Block_Node (Id, Identifier (N));
265 end if;
266 end Add_Block_Identifier;
268 ----------------------------
269 -- Add_Global_Declaration --
270 ----------------------------
272 procedure Add_Global_Declaration (N : Node_Id) is
273 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
275 begin
276 if No (Declarations (Aux_Node)) then
277 Set_Declarations (Aux_Node, New_List);
278 end if;
280 Append_To (Declarations (Aux_Node), N);
281 Analyze (N);
282 end Add_Global_Declaration;
284 --------------------------------
285 -- Address_Integer_Convert_OK --
286 --------------------------------
288 function Address_Integer_Convert_OK (T1, T2 : Entity_Id) return Boolean is
289 begin
290 if Allow_Integer_Address
291 and then ((Is_Descendant_Of_Address (T1)
292 and then Is_Private_Type (T1)
293 and then Is_Integer_Type (T2))
294 or else
295 (Is_Descendant_Of_Address (T2)
296 and then Is_Private_Type (T2)
297 and then Is_Integer_Type (T1)))
298 then
299 return True;
300 else
301 return False;
302 end if;
303 end Address_Integer_Convert_OK;
305 -------------------
306 -- Address_Value --
307 -------------------
309 function Address_Value (N : Node_Id) return Node_Id is
310 Expr : Node_Id := N;
312 begin
313 loop
314 -- For constant, get constant expression
316 if Is_Entity_Name (Expr)
317 and then Ekind (Entity (Expr)) = E_Constant
318 then
319 Expr := Constant_Value (Entity (Expr));
321 -- For unchecked conversion, get result to convert
323 elsif Nkind (Expr) = N_Unchecked_Type_Conversion then
324 Expr := Expression (Expr);
326 -- For (common case) of To_Address call, get argument
328 elsif Nkind (Expr) = N_Function_Call
329 and then Is_Entity_Name (Name (Expr))
330 and then Is_RTE (Entity (Name (Expr)), RE_To_Address)
331 then
332 Expr := First (Parameter_Associations (Expr));
334 if Nkind (Expr) = N_Parameter_Association then
335 Expr := Explicit_Actual_Parameter (Expr);
336 end if;
338 -- We finally have the real expression
340 else
341 exit;
342 end if;
343 end loop;
345 return Expr;
346 end Address_Value;
348 -----------------
349 -- Addressable --
350 -----------------
352 -- For now, just 8/16/32/64
354 function Addressable (V : Uint) return Boolean is
355 begin
356 return V = Uint_8 or else
357 V = Uint_16 or else
358 V = Uint_32 or else
359 V = Uint_64;
360 end Addressable;
362 function Addressable (V : Int) return Boolean is
363 begin
364 return V = 8 or else
365 V = 16 or else
366 V = 32 or else
367 V = 64;
368 end Addressable;
370 ---------------------------------
371 -- Aggregate_Constraint_Checks --
372 ---------------------------------
374 procedure Aggregate_Constraint_Checks
375 (Exp : Node_Id;
376 Check_Typ : Entity_Id)
378 Exp_Typ : constant Entity_Id := Etype (Exp);
380 begin
381 if Raises_Constraint_Error (Exp) then
382 return;
383 end if;
385 -- Ada 2005 (AI-230): Generate a conversion to an anonymous access
386 -- component's type to force the appropriate accessibility checks.
388 -- Ada 2005 (AI-231): Generate conversion to the null-excluding type to
389 -- force the corresponding run-time check
391 if Is_Access_Type (Check_Typ)
392 and then Is_Local_Anonymous_Access (Check_Typ)
393 then
394 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
395 Analyze_And_Resolve (Exp, Check_Typ);
396 Check_Unset_Reference (Exp);
397 end if;
399 -- What follows is really expansion activity, so check that expansion
400 -- is on and is allowed. In GNATprove mode, we also want check flags to
401 -- be added in the tree, so that the formal verification can rely on
402 -- those to be present. In GNATprove mode for formal verification, some
403 -- treatment typically only done during expansion needs to be performed
404 -- on the tree, but it should not be applied inside generics. Otherwise,
405 -- this breaks the name resolution mechanism for generic instances.
407 if not Expander_Active
408 and (Inside_A_Generic or not Full_Analysis or not GNATprove_Mode)
409 then
410 return;
411 end if;
413 if Is_Access_Type (Check_Typ)
414 and then Can_Never_Be_Null (Check_Typ)
415 and then not Can_Never_Be_Null (Exp_Typ)
416 then
417 Install_Null_Excluding_Check (Exp);
418 end if;
420 -- First check if we have to insert discriminant checks
422 if Has_Discriminants (Exp_Typ) then
423 Apply_Discriminant_Check (Exp, Check_Typ);
425 -- Next emit length checks for array aggregates
427 elsif Is_Array_Type (Exp_Typ) then
428 Apply_Length_Check (Exp, Check_Typ);
430 -- Finally emit scalar and string checks. If we are dealing with a
431 -- scalar literal we need to check by hand because the Etype of
432 -- literals is not necessarily correct.
434 elsif Is_Scalar_Type (Exp_Typ)
435 and then Compile_Time_Known_Value (Exp)
436 then
437 if Is_Out_Of_Range (Exp, Base_Type (Check_Typ)) then
438 Apply_Compile_Time_Constraint_Error
439 (Exp, "value not in range of}??", CE_Range_Check_Failed,
440 Ent => Base_Type (Check_Typ),
441 Typ => Base_Type (Check_Typ));
443 elsif Is_Out_Of_Range (Exp, Check_Typ) then
444 Apply_Compile_Time_Constraint_Error
445 (Exp, "value not in range of}??", CE_Range_Check_Failed,
446 Ent => Check_Typ,
447 Typ => Check_Typ);
449 elsif not Range_Checks_Suppressed (Check_Typ) then
450 Apply_Scalar_Range_Check (Exp, Check_Typ);
451 end if;
453 -- Verify that target type is also scalar, to prevent view anomalies
454 -- in instantiations.
456 elsif (Is_Scalar_Type (Exp_Typ)
457 or else Nkind (Exp) = N_String_Literal)
458 and then Is_Scalar_Type (Check_Typ)
459 and then Exp_Typ /= Check_Typ
460 then
461 if Is_Entity_Name (Exp)
462 and then Ekind (Entity (Exp)) = E_Constant
463 then
464 -- If expression is a constant, it is worthwhile checking whether
465 -- it is a bound of the type.
467 if (Is_Entity_Name (Type_Low_Bound (Check_Typ))
468 and then Entity (Exp) = Entity (Type_Low_Bound (Check_Typ)))
469 or else
470 (Is_Entity_Name (Type_High_Bound (Check_Typ))
471 and then Entity (Exp) = Entity (Type_High_Bound (Check_Typ)))
472 then
473 return;
475 else
476 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
477 Analyze_And_Resolve (Exp, Check_Typ);
478 Check_Unset_Reference (Exp);
479 end if;
481 -- Could use a comment on this case ???
483 else
484 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
485 Analyze_And_Resolve (Exp, Check_Typ);
486 Check_Unset_Reference (Exp);
487 end if;
489 end if;
490 end Aggregate_Constraint_Checks;
492 -----------------------
493 -- Alignment_In_Bits --
494 -----------------------
496 function Alignment_In_Bits (E : Entity_Id) return Uint is
497 begin
498 return Alignment (E) * System_Storage_Unit;
499 end Alignment_In_Bits;
501 --------------------------------------
502 -- All_Composite_Constraints_Static --
503 --------------------------------------
505 function All_Composite_Constraints_Static
506 (Constr : Node_Id) return Boolean
508 begin
509 if No (Constr) or else Error_Posted (Constr) then
510 return True;
511 end if;
513 case Nkind (Constr) is
514 when N_Subexpr =>
515 if Nkind (Constr) in N_Has_Entity
516 and then Present (Entity (Constr))
517 then
518 if Is_Type (Entity (Constr)) then
519 return
520 not Is_Discrete_Type (Entity (Constr))
521 or else Is_OK_Static_Subtype (Entity (Constr));
522 end if;
524 elsif Nkind (Constr) = N_Range then
525 return
526 Is_OK_Static_Expression (Low_Bound (Constr))
527 and then
528 Is_OK_Static_Expression (High_Bound (Constr));
530 elsif Nkind (Constr) = N_Attribute_Reference
531 and then Attribute_Name (Constr) = Name_Range
532 then
533 return
534 Is_OK_Static_Expression
535 (Type_Low_Bound (Etype (Prefix (Constr))))
536 and then
537 Is_OK_Static_Expression
538 (Type_High_Bound (Etype (Prefix (Constr))));
539 end if;
541 return
542 not Present (Etype (Constr)) -- previous error
543 or else not Is_Discrete_Type (Etype (Constr))
544 or else Is_OK_Static_Expression (Constr);
546 when N_Discriminant_Association =>
547 return All_Composite_Constraints_Static (Expression (Constr));
549 when N_Range_Constraint =>
550 return
551 All_Composite_Constraints_Static (Range_Expression (Constr));
553 when N_Index_Or_Discriminant_Constraint =>
554 declare
555 One_Cstr : Entity_Id;
556 begin
557 One_Cstr := First (Constraints (Constr));
558 while Present (One_Cstr) loop
559 if not All_Composite_Constraints_Static (One_Cstr) then
560 return False;
561 end if;
563 Next (One_Cstr);
564 end loop;
565 end;
567 return True;
569 when N_Subtype_Indication =>
570 return
571 All_Composite_Constraints_Static (Subtype_Mark (Constr))
572 and then
573 All_Composite_Constraints_Static (Constraint (Constr));
575 when others =>
576 raise Program_Error;
577 end case;
578 end All_Composite_Constraints_Static;
580 ------------------------
581 -- Append_Entity_Name --
582 ------------------------
584 procedure Append_Entity_Name (Buf : in out Bounded_String; E : Entity_Id) is
585 Temp : Bounded_String;
587 procedure Inner (E : Entity_Id);
588 -- Inner recursive routine, keep outer routine nonrecursive to ease
589 -- debugging when we get strange results from this routine.
591 -----------
592 -- Inner --
593 -----------
595 procedure Inner (E : Entity_Id) is
596 begin
597 -- If entity has an internal name, skip by it, and print its scope.
598 -- Note that we strip a final R from the name before the test; this
599 -- is needed for some cases of instantiations.
601 declare
602 E_Name : Bounded_String;
604 begin
605 Append (E_Name, Chars (E));
607 if E_Name.Chars (E_Name.Length) = 'R' then
608 E_Name.Length := E_Name.Length - 1;
609 end if;
611 if Is_Internal_Name (E_Name) then
612 Inner (Scope (E));
613 return;
614 end if;
615 end;
617 -- Just print entity name if its scope is at the outer level
619 if Scope (E) = Standard_Standard then
620 null;
622 -- If scope comes from source, write scope and entity
624 elsif Comes_From_Source (Scope (E)) then
625 Append_Entity_Name (Temp, Scope (E));
626 Append (Temp, '.');
628 -- If in wrapper package skip past it
630 elsif Is_Wrapper_Package (Scope (E)) then
631 Append_Entity_Name (Temp, Scope (Scope (E)));
632 Append (Temp, '.');
634 -- Otherwise nothing to output (happens in unnamed block statements)
636 else
637 null;
638 end if;
640 -- Output the name
642 declare
643 E_Name : Bounded_String;
645 begin
646 Append_Unqualified_Decoded (E_Name, Chars (E));
648 -- Remove trailing upper-case letters from the name (useful for
649 -- dealing with some cases of internal names generated in the case
650 -- of references from within a generic).
652 while E_Name.Length > 1
653 and then E_Name.Chars (E_Name.Length) in 'A' .. 'Z'
654 loop
655 E_Name.Length := E_Name.Length - 1;
656 end loop;
658 -- Adjust casing appropriately (gets name from source if possible)
660 Adjust_Name_Case (E_Name, Sloc (E));
661 Append (Temp, E_Name);
662 end;
663 end Inner;
665 -- Start of processing for Append_Entity_Name
667 begin
668 Inner (E);
669 Append (Buf, Temp);
670 end Append_Entity_Name;
672 ---------------------------------
673 -- Append_Inherited_Subprogram --
674 ---------------------------------
676 procedure Append_Inherited_Subprogram (S : Entity_Id) is
677 Par : constant Entity_Id := Alias (S);
678 -- The parent subprogram
680 Scop : constant Entity_Id := Scope (Par);
681 -- The scope of definition of the parent subprogram
683 Typ : constant Entity_Id := Defining_Entity (Parent (S));
684 -- The derived type of which S is a primitive operation
686 Decl : Node_Id;
687 Next_E : Entity_Id;
689 begin
690 if Ekind (Current_Scope) = E_Package
691 and then In_Private_Part (Current_Scope)
692 and then Has_Private_Declaration (Typ)
693 and then Is_Tagged_Type (Typ)
694 and then Scop = Current_Scope
695 then
696 -- The inherited operation is available at the earliest place after
697 -- the derived type declaration ( RM 7.3.1 (6/1)). This is only
698 -- relevant for type extensions. If the parent operation appears
699 -- after the type extension, the operation is not visible.
701 Decl := First
702 (Visible_Declarations
703 (Package_Specification (Current_Scope)));
704 while Present (Decl) loop
705 if Nkind (Decl) = N_Private_Extension_Declaration
706 and then Defining_Entity (Decl) = Typ
707 then
708 if Sloc (Decl) > Sloc (Par) then
709 Next_E := Next_Entity (Par);
710 Set_Next_Entity (Par, S);
711 Set_Next_Entity (S, Next_E);
712 return;
714 else
715 exit;
716 end if;
717 end if;
719 Next (Decl);
720 end loop;
721 end if;
723 -- If partial view is not a type extension, or it appears before the
724 -- subprogram declaration, insert normally at end of entity list.
726 Append_Entity (S, Current_Scope);
727 end Append_Inherited_Subprogram;
729 -----------------------------------------
730 -- Apply_Compile_Time_Constraint_Error --
731 -----------------------------------------
733 procedure Apply_Compile_Time_Constraint_Error
734 (N : Node_Id;
735 Msg : String;
736 Reason : RT_Exception_Code;
737 Ent : Entity_Id := Empty;
738 Typ : Entity_Id := Empty;
739 Loc : Source_Ptr := No_Location;
740 Rep : Boolean := True;
741 Warn : Boolean := False)
743 Stat : constant Boolean := Is_Static_Expression (N);
744 R_Stat : constant Node_Id :=
745 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
746 Rtyp : Entity_Id;
748 begin
749 if No (Typ) then
750 Rtyp := Etype (N);
751 else
752 Rtyp := Typ;
753 end if;
755 Discard_Node
756 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
758 -- In GNATprove mode, do not replace the node with an exception raised.
759 -- In such a case, either the call to Compile_Time_Constraint_Error
760 -- issues an error which stops analysis, or it issues a warning in
761 -- a few cases where a suitable check flag is set for GNATprove to
762 -- generate a check message.
764 if not Rep or GNATprove_Mode then
765 return;
766 end if;
768 -- Now we replace the node by an N_Raise_Constraint_Error node
769 -- This does not need reanalyzing, so set it as analyzed now.
771 Rewrite (N, R_Stat);
772 Set_Analyzed (N, True);
774 Set_Etype (N, Rtyp);
775 Set_Raises_Constraint_Error (N);
777 -- Now deal with possible local raise handling
779 Possible_Local_Raise (N, Standard_Constraint_Error);
781 -- If the original expression was marked as static, the result is
782 -- still marked as static, but the Raises_Constraint_Error flag is
783 -- always set so that further static evaluation is not attempted.
785 if Stat then
786 Set_Is_Static_Expression (N);
787 end if;
788 end Apply_Compile_Time_Constraint_Error;
790 ---------------------------
791 -- Async_Readers_Enabled --
792 ---------------------------
794 function Async_Readers_Enabled (Id : Entity_Id) return Boolean is
795 begin
796 return Has_Enabled_Property (Id, Name_Async_Readers);
797 end Async_Readers_Enabled;
799 ---------------------------
800 -- Async_Writers_Enabled --
801 ---------------------------
803 function Async_Writers_Enabled (Id : Entity_Id) return Boolean is
804 begin
805 return Has_Enabled_Property (Id, Name_Async_Writers);
806 end Async_Writers_Enabled;
808 --------------------------------------
809 -- Available_Full_View_Of_Component --
810 --------------------------------------
812 function Available_Full_View_Of_Component (T : Entity_Id) return Boolean is
813 ST : constant Entity_Id := Scope (T);
814 SCT : constant Entity_Id := Scope (Component_Type (T));
815 begin
816 return In_Open_Scopes (ST)
817 and then In_Open_Scopes (SCT)
818 and then Scope_Depth (ST) >= Scope_Depth (SCT);
819 end Available_Full_View_Of_Component;
821 -------------------
822 -- Bad_Attribute --
823 -------------------
825 procedure Bad_Attribute
826 (N : Node_Id;
827 Nam : Name_Id;
828 Warn : Boolean := False)
830 begin
831 Error_Msg_Warn := Warn;
832 Error_Msg_N ("unrecognized attribute&<<", N);
834 -- Check for possible misspelling
836 Error_Msg_Name_1 := First_Attribute_Name;
837 while Error_Msg_Name_1 <= Last_Attribute_Name loop
838 if Is_Bad_Spelling_Of (Nam, Error_Msg_Name_1) then
839 Error_Msg_N -- CODEFIX
840 ("\possible misspelling of %<<", N);
841 exit;
842 end if;
844 Error_Msg_Name_1 := Error_Msg_Name_1 + 1;
845 end loop;
846 end Bad_Attribute;
848 --------------------------------
849 -- Bad_Predicated_Subtype_Use --
850 --------------------------------
852 procedure Bad_Predicated_Subtype_Use
853 (Msg : String;
854 N : Node_Id;
855 Typ : Entity_Id;
856 Suggest_Static : Boolean := False)
858 Gen : Entity_Id;
860 begin
861 -- Avoid cascaded errors
863 if Error_Posted (N) then
864 return;
865 end if;
867 if Inside_A_Generic then
868 Gen := Current_Scope;
869 while Present (Gen) and then Ekind (Gen) /= E_Generic_Package loop
870 Gen := Scope (Gen);
871 end loop;
873 if No (Gen) then
874 return;
875 end if;
877 if Is_Generic_Formal (Typ) and then Is_Discrete_Type (Typ) then
878 Set_No_Predicate_On_Actual (Typ);
879 end if;
881 elsif Has_Predicates (Typ) then
882 if Is_Generic_Actual_Type (Typ) then
884 -- The restriction on loop parameters is only that the type
885 -- should have no dynamic predicates.
887 if Nkind (Parent (N)) = N_Loop_Parameter_Specification
888 and then not Has_Dynamic_Predicate_Aspect (Typ)
889 and then Is_OK_Static_Subtype (Typ)
890 then
891 return;
892 end if;
894 Gen := Current_Scope;
895 while not Is_Generic_Instance (Gen) loop
896 Gen := Scope (Gen);
897 end loop;
899 pragma Assert (Present (Gen));
901 if Ekind (Gen) = E_Package and then In_Package_Body (Gen) then
902 Error_Msg_Warn := SPARK_Mode /= On;
903 Error_Msg_FE (Msg & "<<", N, Typ);
904 Error_Msg_F ("\Program_Error [<<", N);
906 Insert_Action (N,
907 Make_Raise_Program_Error (Sloc (N),
908 Reason => PE_Bad_Predicated_Generic_Type));
910 else
911 Error_Msg_FE (Msg & "<<", N, Typ);
912 end if;
914 else
915 Error_Msg_FE (Msg, N, Typ);
916 end if;
918 -- Emit an optional suggestion on how to remedy the error if the
919 -- context warrants it.
921 if Suggest_Static and then Has_Static_Predicate (Typ) then
922 Error_Msg_FE ("\predicate of & should be marked static", N, Typ);
923 end if;
924 end if;
925 end Bad_Predicated_Subtype_Use;
927 -----------------------------------------
928 -- Bad_Unordered_Enumeration_Reference --
929 -----------------------------------------
931 function Bad_Unordered_Enumeration_Reference
932 (N : Node_Id;
933 T : Entity_Id) return Boolean
935 begin
936 return Is_Enumeration_Type (T)
937 and then Warn_On_Unordered_Enumeration_Type
938 and then not Is_Generic_Type (T)
939 and then Comes_From_Source (N)
940 and then not Has_Pragma_Ordered (T)
941 and then not In_Same_Extended_Unit (N, T);
942 end Bad_Unordered_Enumeration_Reference;
944 --------------------------
945 -- Build_Actual_Subtype --
946 --------------------------
948 function Build_Actual_Subtype
949 (T : Entity_Id;
950 N : Node_Or_Entity_Id) return Node_Id
952 Loc : Source_Ptr;
953 -- Normally Sloc (N), but may point to corresponding body in some cases
955 Constraints : List_Id;
956 Decl : Node_Id;
957 Discr : Entity_Id;
958 Hi : Node_Id;
959 Lo : Node_Id;
960 Subt : Entity_Id;
961 Disc_Type : Entity_Id;
962 Obj : Node_Id;
964 begin
965 Loc := Sloc (N);
967 if Nkind (N) = N_Defining_Identifier then
968 Obj := New_Occurrence_Of (N, Loc);
970 -- If this is a formal parameter of a subprogram declaration, and
971 -- we are compiling the body, we want the declaration for the
972 -- actual subtype to carry the source position of the body, to
973 -- prevent anomalies in gdb when stepping through the code.
975 if Is_Formal (N) then
976 declare
977 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
978 begin
979 if Nkind (Decl) = N_Subprogram_Declaration
980 and then Present (Corresponding_Body (Decl))
981 then
982 Loc := Sloc (Corresponding_Body (Decl));
983 end if;
984 end;
985 end if;
987 else
988 Obj := N;
989 end if;
991 if Is_Array_Type (T) then
992 Constraints := New_List;
993 for J in 1 .. Number_Dimensions (T) loop
995 -- Build an array subtype declaration with the nominal subtype and
996 -- the bounds of the actual. Add the declaration in front of the
997 -- local declarations for the subprogram, for analysis before any
998 -- reference to the formal in the body.
1000 Lo :=
1001 Make_Attribute_Reference (Loc,
1002 Prefix =>
1003 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
1004 Attribute_Name => Name_First,
1005 Expressions => New_List (
1006 Make_Integer_Literal (Loc, J)));
1008 Hi :=
1009 Make_Attribute_Reference (Loc,
1010 Prefix =>
1011 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
1012 Attribute_Name => Name_Last,
1013 Expressions => New_List (
1014 Make_Integer_Literal (Loc, J)));
1016 Append (Make_Range (Loc, Lo, Hi), Constraints);
1017 end loop;
1019 -- If the type has unknown discriminants there is no constrained
1020 -- subtype to build. This is never called for a formal or for a
1021 -- lhs, so returning the type is ok ???
1023 elsif Has_Unknown_Discriminants (T) then
1024 return T;
1026 else
1027 Constraints := New_List;
1029 -- Type T is a generic derived type, inherit the discriminants from
1030 -- the parent type.
1032 if Is_Private_Type (T)
1033 and then No (Full_View (T))
1035 -- T was flagged as an error if it was declared as a formal
1036 -- derived type with known discriminants. In this case there
1037 -- is no need to look at the parent type since T already carries
1038 -- its own discriminants.
1040 and then not Error_Posted (T)
1041 then
1042 Disc_Type := Etype (Base_Type (T));
1043 else
1044 Disc_Type := T;
1045 end if;
1047 Discr := First_Discriminant (Disc_Type);
1048 while Present (Discr) loop
1049 Append_To (Constraints,
1050 Make_Selected_Component (Loc,
1051 Prefix =>
1052 Duplicate_Subexpr_No_Checks (Obj),
1053 Selector_Name => New_Occurrence_Of (Discr, Loc)));
1054 Next_Discriminant (Discr);
1055 end loop;
1056 end if;
1058 Subt := Make_Temporary (Loc, 'S', Related_Node => N);
1059 Set_Is_Internal (Subt);
1061 Decl :=
1062 Make_Subtype_Declaration (Loc,
1063 Defining_Identifier => Subt,
1064 Subtype_Indication =>
1065 Make_Subtype_Indication (Loc,
1066 Subtype_Mark => New_Occurrence_Of (T, Loc),
1067 Constraint =>
1068 Make_Index_Or_Discriminant_Constraint (Loc,
1069 Constraints => Constraints)));
1071 Mark_Rewrite_Insertion (Decl);
1072 return Decl;
1073 end Build_Actual_Subtype;
1075 ---------------------------------------
1076 -- Build_Actual_Subtype_Of_Component --
1077 ---------------------------------------
1079 function Build_Actual_Subtype_Of_Component
1080 (T : Entity_Id;
1081 N : Node_Id) return Node_Id
1083 Loc : constant Source_Ptr := Sloc (N);
1084 P : constant Node_Id := Prefix (N);
1085 D : Elmt_Id;
1086 Id : Node_Id;
1087 Index_Typ : Entity_Id;
1089 Desig_Typ : Entity_Id;
1090 -- This is either a copy of T, or if T is an access type, then it is
1091 -- the directly designated type of this access type.
1093 function Build_Actual_Array_Constraint return List_Id;
1094 -- If one or more of the bounds of the component depends on
1095 -- discriminants, build actual constraint using the discriminants
1096 -- of the prefix.
1098 function Build_Actual_Record_Constraint return List_Id;
1099 -- Similar to previous one, for discriminated components constrained
1100 -- by the discriminant of the enclosing object.
1102 -----------------------------------
1103 -- Build_Actual_Array_Constraint --
1104 -----------------------------------
1106 function Build_Actual_Array_Constraint return List_Id is
1107 Constraints : constant List_Id := New_List;
1108 Indx : Node_Id;
1109 Hi : Node_Id;
1110 Lo : Node_Id;
1111 Old_Hi : Node_Id;
1112 Old_Lo : Node_Id;
1114 begin
1115 Indx := First_Index (Desig_Typ);
1116 while Present (Indx) loop
1117 Old_Lo := Type_Low_Bound (Etype (Indx));
1118 Old_Hi := Type_High_Bound (Etype (Indx));
1120 if Denotes_Discriminant (Old_Lo) then
1121 Lo :=
1122 Make_Selected_Component (Loc,
1123 Prefix => New_Copy_Tree (P),
1124 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
1126 else
1127 Lo := New_Copy_Tree (Old_Lo);
1129 -- The new bound will be reanalyzed in the enclosing
1130 -- declaration. For literal bounds that come from a type
1131 -- declaration, the type of the context must be imposed, so
1132 -- insure that analysis will take place. For non-universal
1133 -- types this is not strictly necessary.
1135 Set_Analyzed (Lo, False);
1136 end if;
1138 if Denotes_Discriminant (Old_Hi) then
1139 Hi :=
1140 Make_Selected_Component (Loc,
1141 Prefix => New_Copy_Tree (P),
1142 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
1144 else
1145 Hi := New_Copy_Tree (Old_Hi);
1146 Set_Analyzed (Hi, False);
1147 end if;
1149 Append (Make_Range (Loc, Lo, Hi), Constraints);
1150 Next_Index (Indx);
1151 end loop;
1153 return Constraints;
1154 end Build_Actual_Array_Constraint;
1156 ------------------------------------
1157 -- Build_Actual_Record_Constraint --
1158 ------------------------------------
1160 function Build_Actual_Record_Constraint return List_Id is
1161 Constraints : constant List_Id := New_List;
1162 D : Elmt_Id;
1163 D_Val : Node_Id;
1165 begin
1166 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1167 while Present (D) loop
1168 if Denotes_Discriminant (Node (D)) then
1169 D_Val := Make_Selected_Component (Loc,
1170 Prefix => New_Copy_Tree (P),
1171 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
1173 else
1174 D_Val := New_Copy_Tree (Node (D));
1175 end if;
1177 Append (D_Val, Constraints);
1178 Next_Elmt (D);
1179 end loop;
1181 return Constraints;
1182 end Build_Actual_Record_Constraint;
1184 -- Start of processing for Build_Actual_Subtype_Of_Component
1186 begin
1187 -- Why the test for Spec_Expression mode here???
1189 if In_Spec_Expression then
1190 return Empty;
1192 -- More comments for the rest of this body would be good ???
1194 elsif Nkind (N) = N_Explicit_Dereference then
1195 if Is_Composite_Type (T)
1196 and then not Is_Constrained (T)
1197 and then not (Is_Class_Wide_Type (T)
1198 and then Is_Constrained (Root_Type (T)))
1199 and then not Has_Unknown_Discriminants (T)
1200 then
1201 -- If the type of the dereference is already constrained, it is an
1202 -- actual subtype.
1204 if Is_Array_Type (Etype (N))
1205 and then Is_Constrained (Etype (N))
1206 then
1207 return Empty;
1208 else
1209 Remove_Side_Effects (P);
1210 return Build_Actual_Subtype (T, N);
1211 end if;
1212 else
1213 return Empty;
1214 end if;
1215 end if;
1217 if Ekind (T) = E_Access_Subtype then
1218 Desig_Typ := Designated_Type (T);
1219 else
1220 Desig_Typ := T;
1221 end if;
1223 if Ekind (Desig_Typ) = E_Array_Subtype then
1224 Id := First_Index (Desig_Typ);
1225 while Present (Id) loop
1226 Index_Typ := Underlying_Type (Etype (Id));
1228 if Denotes_Discriminant (Type_Low_Bound (Index_Typ))
1229 or else
1230 Denotes_Discriminant (Type_High_Bound (Index_Typ))
1231 then
1232 Remove_Side_Effects (P);
1233 return
1234 Build_Component_Subtype
1235 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
1236 end if;
1238 Next_Index (Id);
1239 end loop;
1241 elsif Is_Composite_Type (Desig_Typ)
1242 and then Has_Discriminants (Desig_Typ)
1243 and then not Has_Unknown_Discriminants (Desig_Typ)
1244 then
1245 if Is_Private_Type (Desig_Typ)
1246 and then No (Discriminant_Constraint (Desig_Typ))
1247 then
1248 Desig_Typ := Full_View (Desig_Typ);
1249 end if;
1251 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1252 while Present (D) loop
1253 if Denotes_Discriminant (Node (D)) then
1254 Remove_Side_Effects (P);
1255 return
1256 Build_Component_Subtype (
1257 Build_Actual_Record_Constraint, Loc, Base_Type (T));
1258 end if;
1260 Next_Elmt (D);
1261 end loop;
1262 end if;
1264 -- If none of the above, the actual and nominal subtypes are the same
1266 return Empty;
1267 end Build_Actual_Subtype_Of_Component;
1269 ---------------------------------
1270 -- Build_Class_Wide_Clone_Body --
1271 ---------------------------------
1273 procedure Build_Class_Wide_Clone_Body
1274 (Spec_Id : Entity_Id;
1275 Bod : Node_Id)
1277 Loc : constant Source_Ptr := Sloc (Bod);
1278 Clone_Id : constant Entity_Id := Class_Wide_Clone (Spec_Id);
1279 Clone_Body : Node_Id;
1281 begin
1282 -- The declaration of the class-wide clone was created when the
1283 -- corresponding class-wide condition was analyzed.
1285 Clone_Body :=
1286 Make_Subprogram_Body (Loc,
1287 Specification =>
1288 Copy_Subprogram_Spec (Parent (Clone_Id)),
1289 Declarations => Declarations (Bod),
1290 Handled_Statement_Sequence => Handled_Statement_Sequence (Bod));
1292 -- The new operation is internal and overriding indicators do not apply
1293 -- (the original primitive may have carried one).
1295 Set_Must_Override (Specification (Clone_Body), False);
1296 Insert_Before (Bod, Clone_Body);
1297 Analyze (Clone_Body);
1298 end Build_Class_Wide_Clone_Body;
1300 ---------------------------------
1301 -- Build_Class_Wide_Clone_Call --
1302 ---------------------------------
1304 function Build_Class_Wide_Clone_Call
1305 (Loc : Source_Ptr;
1306 Decls : List_Id;
1307 Spec_Id : Entity_Id;
1308 Spec : Node_Id) return Node_Id
1310 Clone_Id : constant Entity_Id := Class_Wide_Clone (Spec_Id);
1311 Par_Type : constant Entity_Id := Find_Dispatching_Type (Spec_Id);
1313 Actuals : List_Id;
1314 Call : Node_Id;
1315 Formal : Entity_Id;
1316 New_Body : Node_Id;
1317 New_F_Spec : Entity_Id;
1318 New_Formal : Entity_Id;
1320 begin
1321 Actuals := Empty_List;
1322 Formal := First_Formal (Spec_Id);
1323 New_F_Spec := First (Parameter_Specifications (Spec));
1325 -- Build parameter association for call to class-wide clone.
1327 while Present (Formal) loop
1328 New_Formal := Defining_Identifier (New_F_Spec);
1330 -- If controlling argument and operation is inherited, add conversion
1331 -- to parent type for the call.
1333 if Etype (Formal) = Par_Type
1334 and then not Is_Empty_List (Decls)
1335 then
1336 Append_To (Actuals,
1337 Make_Type_Conversion (Loc,
1338 New_Occurrence_Of (Par_Type, Loc),
1339 New_Occurrence_Of (New_Formal, Loc)));
1341 else
1342 Append_To (Actuals, New_Occurrence_Of (New_Formal, Loc));
1343 end if;
1345 Next_Formal (Formal);
1346 Next (New_F_Spec);
1347 end loop;
1349 if Ekind (Spec_Id) = E_Procedure then
1350 Call :=
1351 Make_Procedure_Call_Statement (Loc,
1352 Name => New_Occurrence_Of (Clone_Id, Loc),
1353 Parameter_Associations => Actuals);
1354 else
1355 Call :=
1356 Make_Simple_Return_Statement (Loc,
1357 Expression =>
1358 Make_Function_Call (Loc,
1359 Name => New_Occurrence_Of (Clone_Id, Loc),
1360 Parameter_Associations => Actuals));
1361 end if;
1363 New_Body :=
1364 Make_Subprogram_Body (Loc,
1365 Specification =>
1366 Copy_Subprogram_Spec (Spec),
1367 Declarations => Decls,
1368 Handled_Statement_Sequence =>
1369 Make_Handled_Sequence_Of_Statements (Loc,
1370 Statements => New_List (Call),
1371 End_Label => Make_Identifier (Loc, Chars (Spec_Id))));
1373 return New_Body;
1374 end Build_Class_Wide_Clone_Call;
1376 ---------------------------------
1377 -- Build_Class_Wide_Clone_Decl --
1378 ---------------------------------
1380 procedure Build_Class_Wide_Clone_Decl (Spec_Id : Entity_Id) is
1381 Loc : constant Source_Ptr := Sloc (Spec_Id);
1382 Clone_Id : constant Entity_Id :=
1383 Make_Defining_Identifier (Loc,
1384 New_External_Name (Chars (Spec_Id), Suffix => "CL"));
1386 Decl : Node_Id;
1387 Spec : Node_Id;
1389 begin
1390 Spec := Copy_Subprogram_Spec (Parent (Spec_Id));
1391 Set_Must_Override (Spec, False);
1392 Set_Must_Not_Override (Spec, False);
1393 Set_Defining_Unit_Name (Spec, Clone_Id);
1395 Decl := Make_Subprogram_Declaration (Loc, Spec);
1396 Append (Decl, List_Containing (Unit_Declaration_Node (Spec_Id)));
1398 -- Link clone to original subprogram, for use when building body and
1399 -- wrapper call to inherited operation.
1401 Set_Class_Wide_Clone (Spec_Id, Clone_Id);
1402 end Build_Class_Wide_Clone_Decl;
1404 -----------------------------
1405 -- Build_Component_Subtype --
1406 -----------------------------
1408 function Build_Component_Subtype
1409 (C : List_Id;
1410 Loc : Source_Ptr;
1411 T : Entity_Id) return Node_Id
1413 Subt : Entity_Id;
1414 Decl : Node_Id;
1416 begin
1417 -- Unchecked_Union components do not require component subtypes
1419 if Is_Unchecked_Union (T) then
1420 return Empty;
1421 end if;
1423 Subt := Make_Temporary (Loc, 'S');
1424 Set_Is_Internal (Subt);
1426 Decl :=
1427 Make_Subtype_Declaration (Loc,
1428 Defining_Identifier => Subt,
1429 Subtype_Indication =>
1430 Make_Subtype_Indication (Loc,
1431 Subtype_Mark => New_Occurrence_Of (Base_Type (T), Loc),
1432 Constraint =>
1433 Make_Index_Or_Discriminant_Constraint (Loc,
1434 Constraints => C)));
1436 Mark_Rewrite_Insertion (Decl);
1437 return Decl;
1438 end Build_Component_Subtype;
1440 ---------------------------
1441 -- Build_Default_Subtype --
1442 ---------------------------
1444 function Build_Default_Subtype
1445 (T : Entity_Id;
1446 N : Node_Id) return Entity_Id
1448 Loc : constant Source_Ptr := Sloc (N);
1449 Disc : Entity_Id;
1451 Bas : Entity_Id;
1452 -- The base type that is to be constrained by the defaults
1454 begin
1455 if not Has_Discriminants (T) or else Is_Constrained (T) then
1456 return T;
1457 end if;
1459 Bas := Base_Type (T);
1461 -- If T is non-private but its base type is private, this is the
1462 -- completion of a subtype declaration whose parent type is private
1463 -- (see Complete_Private_Subtype in Sem_Ch3). The proper discriminants
1464 -- are to be found in the full view of the base. Check that the private
1465 -- status of T and its base differ.
1467 if Is_Private_Type (Bas)
1468 and then not Is_Private_Type (T)
1469 and then Present (Full_View (Bas))
1470 then
1471 Bas := Full_View (Bas);
1472 end if;
1474 Disc := First_Discriminant (T);
1476 if No (Discriminant_Default_Value (Disc)) then
1477 return T;
1478 end if;
1480 declare
1481 Act : constant Entity_Id := Make_Temporary (Loc, 'S');
1482 Constraints : constant List_Id := New_List;
1483 Decl : Node_Id;
1485 begin
1486 while Present (Disc) loop
1487 Append_To (Constraints,
1488 New_Copy_Tree (Discriminant_Default_Value (Disc)));
1489 Next_Discriminant (Disc);
1490 end loop;
1492 Decl :=
1493 Make_Subtype_Declaration (Loc,
1494 Defining_Identifier => Act,
1495 Subtype_Indication =>
1496 Make_Subtype_Indication (Loc,
1497 Subtype_Mark => New_Occurrence_Of (Bas, Loc),
1498 Constraint =>
1499 Make_Index_Or_Discriminant_Constraint (Loc,
1500 Constraints => Constraints)));
1502 Insert_Action (N, Decl);
1504 -- If the context is a component declaration the subtype declaration
1505 -- will be analyzed when the enclosing type is frozen, otherwise do
1506 -- it now.
1508 if Ekind (Current_Scope) /= E_Record_Type then
1509 Analyze (Decl);
1510 end if;
1512 return Act;
1513 end;
1514 end Build_Default_Subtype;
1516 --------------------------------------------
1517 -- Build_Discriminal_Subtype_Of_Component --
1518 --------------------------------------------
1520 function Build_Discriminal_Subtype_Of_Component
1521 (T : Entity_Id) return Node_Id
1523 Loc : constant Source_Ptr := Sloc (T);
1524 D : Elmt_Id;
1525 Id : Node_Id;
1527 function Build_Discriminal_Array_Constraint return List_Id;
1528 -- If one or more of the bounds of the component depends on
1529 -- discriminants, build actual constraint using the discriminants
1530 -- of the prefix.
1532 function Build_Discriminal_Record_Constraint return List_Id;
1533 -- Similar to previous one, for discriminated components constrained by
1534 -- the discriminant of the enclosing object.
1536 ----------------------------------------
1537 -- Build_Discriminal_Array_Constraint --
1538 ----------------------------------------
1540 function Build_Discriminal_Array_Constraint return List_Id is
1541 Constraints : constant List_Id := New_List;
1542 Indx : Node_Id;
1543 Hi : Node_Id;
1544 Lo : Node_Id;
1545 Old_Hi : Node_Id;
1546 Old_Lo : Node_Id;
1548 begin
1549 Indx := First_Index (T);
1550 while Present (Indx) loop
1551 Old_Lo := Type_Low_Bound (Etype (Indx));
1552 Old_Hi := Type_High_Bound (Etype (Indx));
1554 if Denotes_Discriminant (Old_Lo) then
1555 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
1557 else
1558 Lo := New_Copy_Tree (Old_Lo);
1559 end if;
1561 if Denotes_Discriminant (Old_Hi) then
1562 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
1564 else
1565 Hi := New_Copy_Tree (Old_Hi);
1566 end if;
1568 Append (Make_Range (Loc, Lo, Hi), Constraints);
1569 Next_Index (Indx);
1570 end loop;
1572 return Constraints;
1573 end Build_Discriminal_Array_Constraint;
1575 -----------------------------------------
1576 -- Build_Discriminal_Record_Constraint --
1577 -----------------------------------------
1579 function Build_Discriminal_Record_Constraint return List_Id is
1580 Constraints : constant List_Id := New_List;
1581 D : Elmt_Id;
1582 D_Val : Node_Id;
1584 begin
1585 D := First_Elmt (Discriminant_Constraint (T));
1586 while Present (D) loop
1587 if Denotes_Discriminant (Node (D)) then
1588 D_Val :=
1589 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
1590 else
1591 D_Val := New_Copy_Tree (Node (D));
1592 end if;
1594 Append (D_Val, Constraints);
1595 Next_Elmt (D);
1596 end loop;
1598 return Constraints;
1599 end Build_Discriminal_Record_Constraint;
1601 -- Start of processing for Build_Discriminal_Subtype_Of_Component
1603 begin
1604 if Ekind (T) = E_Array_Subtype then
1605 Id := First_Index (T);
1606 while Present (Id) loop
1607 if Denotes_Discriminant (Type_Low_Bound (Etype (Id)))
1608 or else
1609 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
1610 then
1611 return Build_Component_Subtype
1612 (Build_Discriminal_Array_Constraint, Loc, T);
1613 end if;
1615 Next_Index (Id);
1616 end loop;
1618 elsif Ekind (T) = E_Record_Subtype
1619 and then Has_Discriminants (T)
1620 and then not Has_Unknown_Discriminants (T)
1621 then
1622 D := First_Elmt (Discriminant_Constraint (T));
1623 while Present (D) loop
1624 if Denotes_Discriminant (Node (D)) then
1625 return Build_Component_Subtype
1626 (Build_Discriminal_Record_Constraint, Loc, T);
1627 end if;
1629 Next_Elmt (D);
1630 end loop;
1631 end if;
1633 -- If none of the above, the actual and nominal subtypes are the same
1635 return Empty;
1636 end Build_Discriminal_Subtype_Of_Component;
1638 ------------------------------
1639 -- Build_Elaboration_Entity --
1640 ------------------------------
1642 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
1643 Loc : constant Source_Ptr := Sloc (N);
1644 Decl : Node_Id;
1645 Elab_Ent : Entity_Id;
1647 procedure Set_Package_Name (Ent : Entity_Id);
1648 -- Given an entity, sets the fully qualified name of the entity in
1649 -- Name_Buffer, with components separated by double underscores. This
1650 -- is a recursive routine that climbs the scope chain to Standard.
1652 ----------------------
1653 -- Set_Package_Name --
1654 ----------------------
1656 procedure Set_Package_Name (Ent : Entity_Id) is
1657 begin
1658 if Scope (Ent) /= Standard_Standard then
1659 Set_Package_Name (Scope (Ent));
1661 declare
1662 Nam : constant String := Get_Name_String (Chars (Ent));
1663 begin
1664 Name_Buffer (Name_Len + 1) := '_';
1665 Name_Buffer (Name_Len + 2) := '_';
1666 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
1667 Name_Len := Name_Len + Nam'Length + 2;
1668 end;
1670 else
1671 Get_Name_String (Chars (Ent));
1672 end if;
1673 end Set_Package_Name;
1675 -- Start of processing for Build_Elaboration_Entity
1677 begin
1678 -- Ignore call if already constructed
1680 if Present (Elaboration_Entity (Spec_Id)) then
1681 return;
1683 -- Ignore in ASIS mode, elaboration entity is not in source and plays
1684 -- no role in analysis.
1686 elsif ASIS_Mode then
1687 return;
1689 -- Do not generate an elaboration entity in GNATprove move because the
1690 -- elaboration counter is a form of expansion.
1692 elsif GNATprove_Mode then
1693 return;
1695 -- See if we need elaboration entity
1697 -- We always need an elaboration entity when preserving control flow, as
1698 -- we want to remain explicit about the unit's elaboration order.
1700 elsif Opt.Suppress_Control_Flow_Optimizations then
1701 null;
1703 -- We always need an elaboration entity for the dynamic elaboration
1704 -- model, since it is needed to properly generate the PE exception for
1705 -- access before elaboration.
1707 elsif Dynamic_Elaboration_Checks then
1708 null;
1710 -- For the static model, we don't need the elaboration counter if this
1711 -- unit is sure to have no elaboration code, since that means there
1712 -- is no elaboration unit to be called. Note that we can't just decide
1713 -- after the fact by looking to see whether there was elaboration code,
1714 -- because that's too late to make this decision.
1716 elsif Restriction_Active (No_Elaboration_Code) then
1717 return;
1719 -- Similarly, for the static model, we can skip the elaboration counter
1720 -- if we have the No_Multiple_Elaboration restriction, since for the
1721 -- static model, that's the only purpose of the counter (to avoid
1722 -- multiple elaboration).
1724 elsif Restriction_Active (No_Multiple_Elaboration) then
1725 return;
1726 end if;
1728 -- Here we need the elaboration entity
1730 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
1731 -- name with dots replaced by double underscore. We have to manually
1732 -- construct this name, since it will be elaborated in the outer scope,
1733 -- and thus will not have the unit name automatically prepended.
1735 Set_Package_Name (Spec_Id);
1736 Add_Str_To_Name_Buffer ("_E");
1738 -- Create elaboration counter
1740 Elab_Ent := Make_Defining_Identifier (Loc, Chars => Name_Find);
1741 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
1743 Decl :=
1744 Make_Object_Declaration (Loc,
1745 Defining_Identifier => Elab_Ent,
1746 Object_Definition =>
1747 New_Occurrence_Of (Standard_Short_Integer, Loc),
1748 Expression => Make_Integer_Literal (Loc, Uint_0));
1750 Push_Scope (Standard_Standard);
1751 Add_Global_Declaration (Decl);
1752 Pop_Scope;
1754 -- Reset True_Constant indication, since we will indeed assign a value
1755 -- to the variable in the binder main. We also kill the Current_Value
1756 -- and Last_Assignment fields for the same reason.
1758 Set_Is_True_Constant (Elab_Ent, False);
1759 Set_Current_Value (Elab_Ent, Empty);
1760 Set_Last_Assignment (Elab_Ent, Empty);
1762 -- We do not want any further qualification of the name (if we did not
1763 -- do this, we would pick up the name of the generic package in the case
1764 -- of a library level generic instantiation).
1766 Set_Has_Qualified_Name (Elab_Ent);
1767 Set_Has_Fully_Qualified_Name (Elab_Ent);
1768 end Build_Elaboration_Entity;
1770 --------------------------------
1771 -- Build_Explicit_Dereference --
1772 --------------------------------
1774 procedure Build_Explicit_Dereference
1775 (Expr : Node_Id;
1776 Disc : Entity_Id)
1778 Loc : constant Source_Ptr := Sloc (Expr);
1779 I : Interp_Index;
1780 It : Interp;
1782 begin
1783 -- An entity of a type with a reference aspect is overloaded with
1784 -- both interpretations: with and without the dereference. Now that
1785 -- the dereference is made explicit, set the type of the node properly,
1786 -- to prevent anomalies in the backend. Same if the expression is an
1787 -- overloaded function call whose return type has a reference aspect.
1789 if Is_Entity_Name (Expr) then
1790 Set_Etype (Expr, Etype (Entity (Expr)));
1792 -- The designated entity will not be examined again when resolving
1793 -- the dereference, so generate a reference to it now.
1795 Generate_Reference (Entity (Expr), Expr);
1797 elsif Nkind (Expr) = N_Function_Call then
1799 -- If the name of the indexing function is overloaded, locate the one
1800 -- whose return type has an implicit dereference on the desired
1801 -- discriminant, and set entity and type of function call.
1803 if Is_Overloaded (Name (Expr)) then
1804 Get_First_Interp (Name (Expr), I, It);
1806 while Present (It.Nam) loop
1807 if Ekind ((It.Typ)) = E_Record_Type
1808 and then First_Entity ((It.Typ)) = Disc
1809 then
1810 Set_Entity (Name (Expr), It.Nam);
1811 Set_Etype (Name (Expr), Etype (It.Nam));
1812 exit;
1813 end if;
1815 Get_Next_Interp (I, It);
1816 end loop;
1817 end if;
1819 -- Set type of call from resolved function name.
1821 Set_Etype (Expr, Etype (Name (Expr)));
1822 end if;
1824 Set_Is_Overloaded (Expr, False);
1826 -- The expression will often be a generalized indexing that yields a
1827 -- container element that is then dereferenced, in which case the
1828 -- generalized indexing call is also non-overloaded.
1830 if Nkind (Expr) = N_Indexed_Component
1831 and then Present (Generalized_Indexing (Expr))
1832 then
1833 Set_Is_Overloaded (Generalized_Indexing (Expr), False);
1834 end if;
1836 Rewrite (Expr,
1837 Make_Explicit_Dereference (Loc,
1838 Prefix =>
1839 Make_Selected_Component (Loc,
1840 Prefix => Relocate_Node (Expr),
1841 Selector_Name => New_Occurrence_Of (Disc, Loc))));
1842 Set_Etype (Prefix (Expr), Etype (Disc));
1843 Set_Etype (Expr, Designated_Type (Etype (Disc)));
1844 end Build_Explicit_Dereference;
1846 ---------------------------
1847 -- Build_Overriding_Spec --
1848 ---------------------------
1850 function Build_Overriding_Spec
1851 (Op : Entity_Id;
1852 Typ : Entity_Id) return Node_Id
1854 Loc : constant Source_Ptr := Sloc (Typ);
1855 Par_Typ : constant Entity_Id := Find_Dispatching_Type (Op);
1856 Spec : constant Node_Id := Specification (Unit_Declaration_Node (Op));
1858 Formal_Spec : Node_Id;
1859 Formal_Type : Node_Id;
1860 New_Spec : Node_Id;
1862 begin
1863 New_Spec := Copy_Subprogram_Spec (Spec);
1865 Formal_Spec := First (Parameter_Specifications (New_Spec));
1866 while Present (Formal_Spec) loop
1867 Formal_Type := Parameter_Type (Formal_Spec);
1869 if Is_Entity_Name (Formal_Type)
1870 and then Entity (Formal_Type) = Par_Typ
1871 then
1872 Rewrite (Formal_Type, New_Occurrence_Of (Typ, Loc));
1873 end if;
1875 -- Nothing needs to be done for access parameters
1877 Next (Formal_Spec);
1878 end loop;
1880 return New_Spec;
1881 end Build_Overriding_Spec;
1883 -----------------------------------
1884 -- Cannot_Raise_Constraint_Error --
1885 -----------------------------------
1887 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
1888 begin
1889 if Compile_Time_Known_Value (Expr) then
1890 return True;
1892 elsif Do_Range_Check (Expr) then
1893 return False;
1895 elsif Raises_Constraint_Error (Expr) then
1896 return False;
1898 else
1899 case Nkind (Expr) is
1900 when N_Identifier =>
1901 return True;
1903 when N_Expanded_Name =>
1904 return True;
1906 when N_Selected_Component =>
1907 return not Do_Discriminant_Check (Expr);
1909 when N_Attribute_Reference =>
1910 if Do_Overflow_Check (Expr) then
1911 return False;
1913 elsif No (Expressions (Expr)) then
1914 return True;
1916 else
1917 declare
1918 N : Node_Id;
1920 begin
1921 N := First (Expressions (Expr));
1922 while Present (N) loop
1923 if Cannot_Raise_Constraint_Error (N) then
1924 Next (N);
1925 else
1926 return False;
1927 end if;
1928 end loop;
1930 return True;
1931 end;
1932 end if;
1934 when N_Type_Conversion =>
1935 if Do_Overflow_Check (Expr)
1936 or else Do_Length_Check (Expr)
1937 or else Do_Tag_Check (Expr)
1938 then
1939 return False;
1940 else
1941 return Cannot_Raise_Constraint_Error (Expression (Expr));
1942 end if;
1944 when N_Unchecked_Type_Conversion =>
1945 return Cannot_Raise_Constraint_Error (Expression (Expr));
1947 when N_Unary_Op =>
1948 if Do_Overflow_Check (Expr) then
1949 return False;
1950 else
1951 return Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1952 end if;
1954 when N_Op_Divide
1955 | N_Op_Mod
1956 | N_Op_Rem
1958 if Do_Division_Check (Expr)
1959 or else
1960 Do_Overflow_Check (Expr)
1961 then
1962 return False;
1963 else
1964 return
1965 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1966 and then
1967 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1968 end if;
1970 when N_Op_Add
1971 | N_Op_And
1972 | N_Op_Concat
1973 | N_Op_Eq
1974 | N_Op_Expon
1975 | N_Op_Ge
1976 | N_Op_Gt
1977 | N_Op_Le
1978 | N_Op_Lt
1979 | N_Op_Multiply
1980 | N_Op_Ne
1981 | N_Op_Or
1982 | N_Op_Rotate_Left
1983 | N_Op_Rotate_Right
1984 | N_Op_Shift_Left
1985 | N_Op_Shift_Right
1986 | N_Op_Shift_Right_Arithmetic
1987 | N_Op_Subtract
1988 | N_Op_Xor
1990 if Do_Overflow_Check (Expr) then
1991 return False;
1992 else
1993 return
1994 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1995 and then
1996 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1997 end if;
1999 when others =>
2000 return False;
2001 end case;
2002 end if;
2003 end Cannot_Raise_Constraint_Error;
2005 -----------------------------------------
2006 -- Check_Dynamically_Tagged_Expression --
2007 -----------------------------------------
2009 procedure Check_Dynamically_Tagged_Expression
2010 (Expr : Node_Id;
2011 Typ : Entity_Id;
2012 Related_Nod : Node_Id)
2014 begin
2015 pragma Assert (Is_Tagged_Type (Typ));
2017 -- In order to avoid spurious errors when analyzing the expanded code,
2018 -- this check is done only for nodes that come from source and for
2019 -- actuals of generic instantiations.
2021 if (Comes_From_Source (Related_Nod)
2022 or else In_Generic_Actual (Expr))
2023 and then (Is_Class_Wide_Type (Etype (Expr))
2024 or else Is_Dynamically_Tagged (Expr))
2025 and then Is_Tagged_Type (Typ)
2026 and then not Is_Class_Wide_Type (Typ)
2027 then
2028 Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
2029 end if;
2030 end Check_Dynamically_Tagged_Expression;
2032 --------------------------
2033 -- Check_Fully_Declared --
2034 --------------------------
2036 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
2037 begin
2038 if Ekind (T) = E_Incomplete_Type then
2040 -- Ada 2005 (AI-50217): If the type is available through a limited
2041 -- with_clause, verify that its full view has been analyzed.
2043 if From_Limited_With (T)
2044 and then Present (Non_Limited_View (T))
2045 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
2046 then
2047 -- The non-limited view is fully declared
2049 null;
2051 else
2052 Error_Msg_NE
2053 ("premature usage of incomplete}", N, First_Subtype (T));
2054 end if;
2056 -- Need comments for these tests ???
2058 elsif Has_Private_Component (T)
2059 and then not Is_Generic_Type (Root_Type (T))
2060 and then not In_Spec_Expression
2061 then
2062 -- Special case: if T is the anonymous type created for a single
2063 -- task or protected object, use the name of the source object.
2065 if Is_Concurrent_Type (T)
2066 and then not Comes_From_Source (T)
2067 and then Nkind (N) = N_Object_Declaration
2068 then
2069 Error_Msg_NE
2070 ("type of& has incomplete component",
2071 N, Defining_Identifier (N));
2072 else
2073 Error_Msg_NE
2074 ("premature usage of incomplete}",
2075 N, First_Subtype (T));
2076 end if;
2077 end if;
2078 end Check_Fully_Declared;
2080 -------------------------------------------
2081 -- Check_Function_With_Address_Parameter --
2082 -------------------------------------------
2084 procedure Check_Function_With_Address_Parameter (Subp_Id : Entity_Id) is
2085 F : Entity_Id;
2086 T : Entity_Id;
2088 begin
2089 F := First_Formal (Subp_Id);
2090 while Present (F) loop
2091 T := Etype (F);
2093 if Is_Private_Type (T) and then Present (Full_View (T)) then
2094 T := Full_View (T);
2095 end if;
2097 if Is_Descendant_Of_Address (T) or else Is_Limited_Type (T) then
2098 Set_Is_Pure (Subp_Id, False);
2099 exit;
2100 end if;
2102 Next_Formal (F);
2103 end loop;
2104 end Check_Function_With_Address_Parameter;
2106 -------------------------------------
2107 -- Check_Function_Writable_Actuals --
2108 -------------------------------------
2110 procedure Check_Function_Writable_Actuals (N : Node_Id) is
2111 Writable_Actuals_List : Elist_Id := No_Elist;
2112 Identifiers_List : Elist_Id := No_Elist;
2113 Aggr_Error_Node : Node_Id := Empty;
2114 Error_Node : Node_Id := Empty;
2116 procedure Collect_Identifiers (N : Node_Id);
2117 -- In a single traversal of subtree N collect in Writable_Actuals_List
2118 -- all the actuals of functions with writable actuals, and in the list
2119 -- Identifiers_List collect all the identifiers that are not actuals of
2120 -- functions with writable actuals. If a writable actual is referenced
2121 -- twice as writable actual then Error_Node is set to reference its
2122 -- second occurrence, the error is reported, and the tree traversal
2123 -- is abandoned.
2125 procedure Preanalyze_Without_Errors (N : Node_Id);
2126 -- Preanalyze N without reporting errors. Very dubious, you can't just
2127 -- go analyzing things more than once???
2129 -------------------------
2130 -- Collect_Identifiers --
2131 -------------------------
2133 procedure Collect_Identifiers (N : Node_Id) is
2135 function Check_Node (N : Node_Id) return Traverse_Result;
2136 -- Process a single node during the tree traversal to collect the
2137 -- writable actuals of functions and all the identifiers which are
2138 -- not writable actuals of functions.
2140 function Contains (List : Elist_Id; N : Node_Id) return Boolean;
2141 -- Returns True if List has a node whose Entity is Entity (N)
2143 ----------------
2144 -- Check_Node --
2145 ----------------
2147 function Check_Node (N : Node_Id) return Traverse_Result is
2148 Is_Writable_Actual : Boolean := False;
2149 Id : Entity_Id;
2151 begin
2152 if Nkind (N) = N_Identifier then
2154 -- No analysis possible if the entity is not decorated
2156 if No (Entity (N)) then
2157 return Skip;
2159 -- Don't collect identifiers of packages, called functions, etc
2161 elsif Ekind_In (Entity (N), E_Package,
2162 E_Function,
2163 E_Procedure,
2164 E_Entry)
2165 then
2166 return Skip;
2168 -- For rewritten nodes, continue the traversal in the original
2169 -- subtree. Needed to handle aggregates in original expressions
2170 -- extracted from the tree by Remove_Side_Effects.
2172 elsif Is_Rewrite_Substitution (N) then
2173 Collect_Identifiers (Original_Node (N));
2174 return Skip;
2176 -- For now we skip aggregate discriminants, since they require
2177 -- performing the analysis in two phases to identify conflicts:
2178 -- first one analyzing discriminants and second one analyzing
2179 -- the rest of components (since at run time, discriminants are
2180 -- evaluated prior to components): too much computation cost
2181 -- to identify a corner case???
2183 elsif Nkind (Parent (N)) = N_Component_Association
2184 and then Nkind_In (Parent (Parent (N)),
2185 N_Aggregate,
2186 N_Extension_Aggregate)
2187 then
2188 declare
2189 Choice : constant Node_Id := First (Choices (Parent (N)));
2191 begin
2192 if Ekind (Entity (N)) = E_Discriminant then
2193 return Skip;
2195 elsif Expression (Parent (N)) = N
2196 and then Nkind (Choice) = N_Identifier
2197 and then Ekind (Entity (Choice)) = E_Discriminant
2198 then
2199 return Skip;
2200 end if;
2201 end;
2203 -- Analyze if N is a writable actual of a function
2205 elsif Nkind (Parent (N)) = N_Function_Call then
2206 declare
2207 Call : constant Node_Id := Parent (N);
2208 Actual : Node_Id;
2209 Formal : Node_Id;
2211 begin
2212 Id := Get_Called_Entity (Call);
2214 -- In case of previous error, no check is possible
2216 if No (Id) then
2217 return Abandon;
2218 end if;
2220 if Ekind_In (Id, E_Function, E_Generic_Function)
2221 and then Has_Out_Or_In_Out_Parameter (Id)
2222 then
2223 Formal := First_Formal (Id);
2224 Actual := First_Actual (Call);
2225 while Present (Actual) and then Present (Formal) loop
2226 if Actual = N then
2227 if Ekind_In (Formal, E_Out_Parameter,
2228 E_In_Out_Parameter)
2229 then
2230 Is_Writable_Actual := True;
2231 end if;
2233 exit;
2234 end if;
2236 Next_Formal (Formal);
2237 Next_Actual (Actual);
2238 end loop;
2239 end if;
2240 end;
2241 end if;
2243 if Is_Writable_Actual then
2245 -- Skip checking the error in non-elementary types since
2246 -- RM 6.4.1(6.15/3) is restricted to elementary types, but
2247 -- store this actual in Writable_Actuals_List since it is
2248 -- needed to perform checks on other constructs that have
2249 -- arbitrary order of evaluation (for example, aggregates).
2251 if not Is_Elementary_Type (Etype (N)) then
2252 if not Contains (Writable_Actuals_List, N) then
2253 Append_New_Elmt (N, To => Writable_Actuals_List);
2254 end if;
2256 -- Second occurrence of an elementary type writable actual
2258 elsif Contains (Writable_Actuals_List, N) then
2260 -- Report the error on the second occurrence of the
2261 -- identifier. We cannot assume that N is the second
2262 -- occurrence (according to their location in the
2263 -- sources), since Traverse_Func walks through Field2
2264 -- last (see comment in the body of Traverse_Func).
2266 declare
2267 Elmt : Elmt_Id;
2269 begin
2270 Elmt := First_Elmt (Writable_Actuals_List);
2271 while Present (Elmt)
2272 and then Entity (Node (Elmt)) /= Entity (N)
2273 loop
2274 Next_Elmt (Elmt);
2275 end loop;
2277 if Sloc (N) > Sloc (Node (Elmt)) then
2278 Error_Node := N;
2279 else
2280 Error_Node := Node (Elmt);
2281 end if;
2283 Error_Msg_NE
2284 ("value may be affected by call to & "
2285 & "because order of evaluation is arbitrary",
2286 Error_Node, Id);
2287 return Abandon;
2288 end;
2290 -- First occurrence of a elementary type writable actual
2292 else
2293 Append_New_Elmt (N, To => Writable_Actuals_List);
2294 end if;
2296 else
2297 if Identifiers_List = No_Elist then
2298 Identifiers_List := New_Elmt_List;
2299 end if;
2301 Append_Unique_Elmt (N, Identifiers_List);
2302 end if;
2303 end if;
2305 return OK;
2306 end Check_Node;
2308 --------------
2309 -- Contains --
2310 --------------
2312 function Contains
2313 (List : Elist_Id;
2314 N : Node_Id) return Boolean
2316 pragma Assert (Nkind (N) in N_Has_Entity);
2318 Elmt : Elmt_Id;
2320 begin
2321 if List = No_Elist then
2322 return False;
2323 end if;
2325 Elmt := First_Elmt (List);
2326 while Present (Elmt) loop
2327 if Entity (Node (Elmt)) = Entity (N) then
2328 return True;
2329 else
2330 Next_Elmt (Elmt);
2331 end if;
2332 end loop;
2334 return False;
2335 end Contains;
2337 ------------------
2338 -- Do_Traversal --
2339 ------------------
2341 procedure Do_Traversal is new Traverse_Proc (Check_Node);
2342 -- The traversal procedure
2344 -- Start of processing for Collect_Identifiers
2346 begin
2347 if Present (Error_Node) then
2348 return;
2349 end if;
2351 if Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then
2352 return;
2353 end if;
2355 Do_Traversal (N);
2356 end Collect_Identifiers;
2358 -------------------------------
2359 -- Preanalyze_Without_Errors --
2360 -------------------------------
2362 procedure Preanalyze_Without_Errors (N : Node_Id) is
2363 Status : constant Boolean := Get_Ignore_Errors;
2364 begin
2365 Set_Ignore_Errors (True);
2366 Preanalyze (N);
2367 Set_Ignore_Errors (Status);
2368 end Preanalyze_Without_Errors;
2370 -- Start of processing for Check_Function_Writable_Actuals
2372 begin
2373 -- The check only applies to Ada 2012 code on which Check_Actuals has
2374 -- been set, and only to constructs that have multiple constituents
2375 -- whose order of evaluation is not specified by the language.
2377 if Ada_Version < Ada_2012
2378 or else not Check_Actuals (N)
2379 or else (not (Nkind (N) in N_Op)
2380 and then not (Nkind (N) in N_Membership_Test)
2381 and then not Nkind_In (N, N_Range,
2382 N_Aggregate,
2383 N_Extension_Aggregate,
2384 N_Full_Type_Declaration,
2385 N_Function_Call,
2386 N_Procedure_Call_Statement,
2387 N_Entry_Call_Statement))
2388 or else (Nkind (N) = N_Full_Type_Declaration
2389 and then not Is_Record_Type (Defining_Identifier (N)))
2391 -- In addition, this check only applies to source code, not to code
2392 -- generated by constraint checks.
2394 or else not Comes_From_Source (N)
2395 then
2396 return;
2397 end if;
2399 -- If a construct C has two or more direct constituents that are names
2400 -- or expressions whose evaluation may occur in an arbitrary order, at
2401 -- least one of which contains a function call with an in out or out
2402 -- parameter, then the construct is legal only if: for each name N that
2403 -- is passed as a parameter of mode in out or out to some inner function
2404 -- call C2 (not including the construct C itself), there is no other
2405 -- name anywhere within a direct constituent of the construct C other
2406 -- than the one containing C2, that is known to refer to the same
2407 -- object (RM 6.4.1(6.17/3)).
2409 case Nkind (N) is
2410 when N_Range =>
2411 Collect_Identifiers (Low_Bound (N));
2412 Collect_Identifiers (High_Bound (N));
2414 when N_Membership_Test
2415 | N_Op
2417 declare
2418 Expr : Node_Id;
2420 begin
2421 Collect_Identifiers (Left_Opnd (N));
2423 if Present (Right_Opnd (N)) then
2424 Collect_Identifiers (Right_Opnd (N));
2425 end if;
2427 if Nkind_In (N, N_In, N_Not_In)
2428 and then Present (Alternatives (N))
2429 then
2430 Expr := First (Alternatives (N));
2431 while Present (Expr) loop
2432 Collect_Identifiers (Expr);
2434 Next (Expr);
2435 end loop;
2436 end if;
2437 end;
2439 when N_Full_Type_Declaration =>
2440 declare
2441 function Get_Record_Part (N : Node_Id) return Node_Id;
2442 -- Return the record part of this record type definition
2444 function Get_Record_Part (N : Node_Id) return Node_Id is
2445 Type_Def : constant Node_Id := Type_Definition (N);
2446 begin
2447 if Nkind (Type_Def) = N_Derived_Type_Definition then
2448 return Record_Extension_Part (Type_Def);
2449 else
2450 return Type_Def;
2451 end if;
2452 end Get_Record_Part;
2454 Comp : Node_Id;
2455 Def_Id : Entity_Id := Defining_Identifier (N);
2456 Rec : Node_Id := Get_Record_Part (N);
2458 begin
2459 -- No need to perform any analysis if the record has no
2460 -- components
2462 if No (Rec) or else No (Component_List (Rec)) then
2463 return;
2464 end if;
2466 -- Collect the identifiers starting from the deepest
2467 -- derivation. Done to report the error in the deepest
2468 -- derivation.
2470 loop
2471 if Present (Component_List (Rec)) then
2472 Comp := First (Component_Items (Component_List (Rec)));
2473 while Present (Comp) loop
2474 if Nkind (Comp) = N_Component_Declaration
2475 and then Present (Expression (Comp))
2476 then
2477 Collect_Identifiers (Expression (Comp));
2478 end if;
2480 Next (Comp);
2481 end loop;
2482 end if;
2484 exit when No (Underlying_Type (Etype (Def_Id)))
2485 or else Base_Type (Underlying_Type (Etype (Def_Id)))
2486 = Def_Id;
2488 Def_Id := Base_Type (Underlying_Type (Etype (Def_Id)));
2489 Rec := Get_Record_Part (Parent (Def_Id));
2490 end loop;
2491 end;
2493 when N_Entry_Call_Statement
2494 | N_Subprogram_Call
2496 declare
2497 Id : constant Entity_Id := Get_Called_Entity (N);
2498 Formal : Node_Id;
2499 Actual : Node_Id;
2501 begin
2502 Formal := First_Formal (Id);
2503 Actual := First_Actual (N);
2504 while Present (Actual) and then Present (Formal) loop
2505 if Ekind_In (Formal, E_Out_Parameter,
2506 E_In_Out_Parameter)
2507 then
2508 Collect_Identifiers (Actual);
2509 end if;
2511 Next_Formal (Formal);
2512 Next_Actual (Actual);
2513 end loop;
2514 end;
2516 when N_Aggregate
2517 | N_Extension_Aggregate
2519 declare
2520 Assoc : Node_Id;
2521 Choice : Node_Id;
2522 Comp_Expr : Node_Id;
2524 begin
2525 -- Handle the N_Others_Choice of array aggregates with static
2526 -- bounds. There is no need to perform this analysis in
2527 -- aggregates without static bounds since we cannot evaluate
2528 -- if the N_Others_Choice covers several elements. There is
2529 -- no need to handle the N_Others choice of record aggregates
2530 -- since at this stage it has been already expanded by
2531 -- Resolve_Record_Aggregate.
2533 if Is_Array_Type (Etype (N))
2534 and then Nkind (N) = N_Aggregate
2535 and then Present (Aggregate_Bounds (N))
2536 and then Compile_Time_Known_Bounds (Etype (N))
2537 and then Expr_Value (High_Bound (Aggregate_Bounds (N)))
2539 Expr_Value (Low_Bound (Aggregate_Bounds (N)))
2540 then
2541 declare
2542 Count_Components : Uint := Uint_0;
2543 Num_Components : Uint;
2544 Others_Assoc : Node_Id;
2545 Others_Choice : Node_Id := Empty;
2546 Others_Box_Present : Boolean := False;
2548 begin
2549 -- Count positional associations
2551 if Present (Expressions (N)) then
2552 Comp_Expr := First (Expressions (N));
2553 while Present (Comp_Expr) loop
2554 Count_Components := Count_Components + 1;
2555 Next (Comp_Expr);
2556 end loop;
2557 end if;
2559 -- Count the rest of elements and locate the N_Others
2560 -- choice (if any)
2562 Assoc := First (Component_Associations (N));
2563 while Present (Assoc) loop
2564 Choice := First (Choices (Assoc));
2565 while Present (Choice) loop
2566 if Nkind (Choice) = N_Others_Choice then
2567 Others_Assoc := Assoc;
2568 Others_Choice := Choice;
2569 Others_Box_Present := Box_Present (Assoc);
2571 -- Count several components
2573 elsif Nkind_In (Choice, N_Range,
2574 N_Subtype_Indication)
2575 or else (Is_Entity_Name (Choice)
2576 and then Is_Type (Entity (Choice)))
2577 then
2578 declare
2579 L, H : Node_Id;
2580 begin
2581 Get_Index_Bounds (Choice, L, H);
2582 pragma Assert
2583 (Compile_Time_Known_Value (L)
2584 and then Compile_Time_Known_Value (H));
2585 Count_Components :=
2586 Count_Components
2587 + Expr_Value (H) - Expr_Value (L) + 1;
2588 end;
2590 -- Count single component. No other case available
2591 -- since we are handling an aggregate with static
2592 -- bounds.
2594 else
2595 pragma Assert (Is_OK_Static_Expression (Choice)
2596 or else Nkind (Choice) = N_Identifier
2597 or else Nkind (Choice) = N_Integer_Literal);
2599 Count_Components := Count_Components + 1;
2600 end if;
2602 Next (Choice);
2603 end loop;
2605 Next (Assoc);
2606 end loop;
2608 Num_Components :=
2609 Expr_Value (High_Bound (Aggregate_Bounds (N))) -
2610 Expr_Value (Low_Bound (Aggregate_Bounds (N))) + 1;
2612 pragma Assert (Count_Components <= Num_Components);
2614 -- Handle the N_Others choice if it covers several
2615 -- components
2617 if Present (Others_Choice)
2618 and then (Num_Components - Count_Components) > 1
2619 then
2620 if not Others_Box_Present then
2622 -- At this stage, if expansion is active, the
2623 -- expression of the others choice has not been
2624 -- analyzed. Hence we generate a duplicate and
2625 -- we analyze it silently to have available the
2626 -- minimum decoration required to collect the
2627 -- identifiers.
2629 if not Expander_Active then
2630 Comp_Expr := Expression (Others_Assoc);
2631 else
2632 Comp_Expr :=
2633 New_Copy_Tree (Expression (Others_Assoc));
2634 Preanalyze_Without_Errors (Comp_Expr);
2635 end if;
2637 Collect_Identifiers (Comp_Expr);
2639 if Writable_Actuals_List /= No_Elist then
2641 -- As suggested by Robert, at current stage we
2642 -- report occurrences of this case as warnings.
2644 Error_Msg_N
2645 ("writable function parameter may affect "
2646 & "value in other component because order "
2647 & "of evaluation is unspecified??",
2648 Node (First_Elmt (Writable_Actuals_List)));
2649 end if;
2650 end if;
2651 end if;
2652 end;
2654 -- For an array aggregate, a discrete_choice_list that has
2655 -- a nonstatic range is considered as two or more separate
2656 -- occurrences of the expression (RM 6.4.1(20/3)).
2658 elsif Is_Array_Type (Etype (N))
2659 and then Nkind (N) = N_Aggregate
2660 and then Present (Aggregate_Bounds (N))
2661 and then not Compile_Time_Known_Bounds (Etype (N))
2662 then
2663 -- Collect identifiers found in the dynamic bounds
2665 declare
2666 Count_Components : Natural := 0;
2667 Low, High : Node_Id;
2669 begin
2670 Assoc := First (Component_Associations (N));
2671 while Present (Assoc) loop
2672 Choice := First (Choices (Assoc));
2673 while Present (Choice) loop
2674 if Nkind_In (Choice, N_Range,
2675 N_Subtype_Indication)
2676 or else (Is_Entity_Name (Choice)
2677 and then Is_Type (Entity (Choice)))
2678 then
2679 Get_Index_Bounds (Choice, Low, High);
2681 if not Compile_Time_Known_Value (Low) then
2682 Collect_Identifiers (Low);
2684 if No (Aggr_Error_Node) then
2685 Aggr_Error_Node := Low;
2686 end if;
2687 end if;
2689 if not Compile_Time_Known_Value (High) then
2690 Collect_Identifiers (High);
2692 if No (Aggr_Error_Node) then
2693 Aggr_Error_Node := High;
2694 end if;
2695 end if;
2697 -- The RM rule is violated if there is more than
2698 -- a single choice in a component association.
2700 else
2701 Count_Components := Count_Components + 1;
2703 if No (Aggr_Error_Node)
2704 and then Count_Components > 1
2705 then
2706 Aggr_Error_Node := Choice;
2707 end if;
2709 if not Compile_Time_Known_Value (Choice) then
2710 Collect_Identifiers (Choice);
2711 end if;
2712 end if;
2714 Next (Choice);
2715 end loop;
2717 Next (Assoc);
2718 end loop;
2719 end;
2720 end if;
2722 -- Handle ancestor part of extension aggregates
2724 if Nkind (N) = N_Extension_Aggregate then
2725 Collect_Identifiers (Ancestor_Part (N));
2726 end if;
2728 -- Handle positional associations
2730 if Present (Expressions (N)) then
2731 Comp_Expr := First (Expressions (N));
2732 while Present (Comp_Expr) loop
2733 if not Is_OK_Static_Expression (Comp_Expr) then
2734 Collect_Identifiers (Comp_Expr);
2735 end if;
2737 Next (Comp_Expr);
2738 end loop;
2739 end if;
2741 -- Handle discrete associations
2743 if Present (Component_Associations (N)) then
2744 Assoc := First (Component_Associations (N));
2745 while Present (Assoc) loop
2747 if not Box_Present (Assoc) then
2748 Choice := First (Choices (Assoc));
2749 while Present (Choice) loop
2751 -- For now we skip discriminants since it requires
2752 -- performing the analysis in two phases: first one
2753 -- analyzing discriminants and second one analyzing
2754 -- the rest of components since discriminants are
2755 -- evaluated prior to components: too much extra
2756 -- work to detect a corner case???
2758 if Nkind (Choice) in N_Has_Entity
2759 and then Present (Entity (Choice))
2760 and then Ekind (Entity (Choice)) = E_Discriminant
2761 then
2762 null;
2764 elsif Box_Present (Assoc) then
2765 null;
2767 else
2768 if not Analyzed (Expression (Assoc)) then
2769 Comp_Expr :=
2770 New_Copy_Tree (Expression (Assoc));
2771 Set_Parent (Comp_Expr, Parent (N));
2772 Preanalyze_Without_Errors (Comp_Expr);
2773 else
2774 Comp_Expr := Expression (Assoc);
2775 end if;
2777 Collect_Identifiers (Comp_Expr);
2778 end if;
2780 Next (Choice);
2781 end loop;
2782 end if;
2784 Next (Assoc);
2785 end loop;
2786 end if;
2787 end;
2789 when others =>
2790 return;
2791 end case;
2793 -- No further action needed if we already reported an error
2795 if Present (Error_Node) then
2796 return;
2797 end if;
2799 -- Check violation of RM 6.20/3 in aggregates
2801 if Present (Aggr_Error_Node)
2802 and then Writable_Actuals_List /= No_Elist
2803 then
2804 Error_Msg_N
2805 ("value may be affected by call in other component because they "
2806 & "are evaluated in unspecified order",
2807 Node (First_Elmt (Writable_Actuals_List)));
2808 return;
2809 end if;
2811 -- Check if some writable argument of a function is referenced
2813 if Writable_Actuals_List /= No_Elist
2814 and then Identifiers_List /= No_Elist
2815 then
2816 declare
2817 Elmt_1 : Elmt_Id;
2818 Elmt_2 : Elmt_Id;
2820 begin
2821 Elmt_1 := First_Elmt (Writable_Actuals_List);
2822 while Present (Elmt_1) loop
2823 Elmt_2 := First_Elmt (Identifiers_List);
2824 while Present (Elmt_2) loop
2825 if Entity (Node (Elmt_1)) = Entity (Node (Elmt_2)) then
2826 case Nkind (Parent (Node (Elmt_2))) is
2827 when N_Aggregate
2828 | N_Component_Association
2829 | N_Component_Declaration
2831 Error_Msg_N
2832 ("value may be affected by call in other "
2833 & "component because they are evaluated "
2834 & "in unspecified order",
2835 Node (Elmt_2));
2837 when N_In
2838 | N_Not_In
2840 Error_Msg_N
2841 ("value may be affected by call in other "
2842 & "alternative because they are evaluated "
2843 & "in unspecified order",
2844 Node (Elmt_2));
2846 when others =>
2847 Error_Msg_N
2848 ("value of actual may be affected by call in "
2849 & "other actual because they are evaluated "
2850 & "in unspecified order",
2851 Node (Elmt_2));
2852 end case;
2853 end if;
2855 Next_Elmt (Elmt_2);
2856 end loop;
2858 Next_Elmt (Elmt_1);
2859 end loop;
2860 end;
2861 end if;
2862 end Check_Function_Writable_Actuals;
2864 --------------------------------
2865 -- Check_Implicit_Dereference --
2866 --------------------------------
2868 procedure Check_Implicit_Dereference (N : Node_Id; Typ : Entity_Id) is
2869 Disc : Entity_Id;
2870 Desig : Entity_Id;
2871 Nam : Node_Id;
2873 begin
2874 if Nkind (N) = N_Indexed_Component
2875 and then Present (Generalized_Indexing (N))
2876 then
2877 Nam := Generalized_Indexing (N);
2878 else
2879 Nam := N;
2880 end if;
2882 if Ada_Version < Ada_2012
2883 or else not Has_Implicit_Dereference (Base_Type (Typ))
2884 then
2885 return;
2887 elsif not Comes_From_Source (N)
2888 and then Nkind (N) /= N_Indexed_Component
2889 then
2890 return;
2892 elsif Is_Entity_Name (Nam) and then Is_Type (Entity (Nam)) then
2893 null;
2895 else
2896 Disc := First_Discriminant (Typ);
2897 while Present (Disc) loop
2898 if Has_Implicit_Dereference (Disc) then
2899 Desig := Designated_Type (Etype (Disc));
2900 Add_One_Interp (Nam, Disc, Desig);
2902 -- If the node is a generalized indexing, add interpretation
2903 -- to that node as well, for subsequent resolution.
2905 if Nkind (N) = N_Indexed_Component then
2906 Add_One_Interp (N, Disc, Desig);
2907 end if;
2909 -- If the operation comes from a generic unit and the context
2910 -- is a selected component, the selector name may be global
2911 -- and set in the instance already. Remove the entity to
2912 -- force resolution of the selected component, and the
2913 -- generation of an explicit dereference if needed.
2915 if In_Instance
2916 and then Nkind (Parent (Nam)) = N_Selected_Component
2917 then
2918 Set_Entity (Selector_Name (Parent (Nam)), Empty);
2919 end if;
2921 exit;
2922 end if;
2924 Next_Discriminant (Disc);
2925 end loop;
2926 end if;
2927 end Check_Implicit_Dereference;
2929 ----------------------------------
2930 -- Check_Internal_Protected_Use --
2931 ----------------------------------
2933 procedure Check_Internal_Protected_Use (N : Node_Id; Nam : Entity_Id) is
2934 S : Entity_Id;
2935 Prot : Entity_Id;
2937 begin
2938 Prot := Empty;
2940 S := Current_Scope;
2941 while Present (S) loop
2942 if S = Standard_Standard then
2943 exit;
2945 elsif Ekind (S) = E_Function
2946 and then Ekind (Scope (S)) = E_Protected_Type
2947 then
2948 Prot := Scope (S);
2949 exit;
2950 end if;
2952 S := Scope (S);
2953 end loop;
2955 if Present (Prot)
2956 and then Scope (Nam) = Prot
2957 and then Ekind (Nam) /= E_Function
2958 then
2959 -- An indirect function call (e.g. a callback within a protected
2960 -- function body) is not statically illegal. If the access type is
2961 -- anonymous and is the type of an access parameter, the scope of Nam
2962 -- will be the protected type, but it is not a protected operation.
2964 if Ekind (Nam) = E_Subprogram_Type
2965 and then Nkind (Associated_Node_For_Itype (Nam)) =
2966 N_Function_Specification
2967 then
2968 null;
2970 elsif Nkind (N) = N_Subprogram_Renaming_Declaration then
2971 Error_Msg_N
2972 ("within protected function cannot use protected procedure in "
2973 & "renaming or as generic actual", N);
2975 elsif Nkind (N) = N_Attribute_Reference then
2976 Error_Msg_N
2977 ("within protected function cannot take access of protected "
2978 & "procedure", N);
2980 else
2981 Error_Msg_N
2982 ("within protected function, protected object is constant", N);
2983 Error_Msg_N
2984 ("\cannot call operation that may modify it", N);
2985 end if;
2986 end if;
2988 -- Verify that an internal call does not appear within a precondition
2989 -- of a protected operation. This implements AI12-0166.
2990 -- The precondition aspect has been rewritten as a pragma Precondition
2991 -- and we check whether the scope of the called subprogram is the same
2992 -- as that of the entity to which the aspect applies.
2994 if Convention (Nam) = Convention_Protected then
2995 declare
2996 P : Node_Id;
2998 begin
2999 P := Parent (N);
3000 while Present (P) loop
3001 if Nkind (P) = N_Pragma
3002 and then Chars (Pragma_Identifier (P)) = Name_Precondition
3003 and then From_Aspect_Specification (P)
3004 and then
3005 Scope (Entity (Corresponding_Aspect (P))) = Scope (Nam)
3006 then
3007 Error_Msg_N
3008 ("internal call cannot appear in precondition of "
3009 & "protected operation", N);
3010 return;
3012 elsif Nkind (P) = N_Pragma
3013 and then Chars (Pragma_Identifier (P)) = Name_Contract_Cases
3014 then
3015 -- Check whether call is in a case guard. It is legal in a
3016 -- consequence.
3018 P := N;
3019 while Present (P) loop
3020 if Nkind (Parent (P)) = N_Component_Association
3021 and then P /= Expression (Parent (P))
3022 then
3023 Error_Msg_N
3024 ("internal call cannot appear in case guard in a "
3025 & "contract case", N);
3026 end if;
3028 P := Parent (P);
3029 end loop;
3031 return;
3033 elsif Nkind (P) = N_Parameter_Specification
3034 and then Scope (Current_Scope) = Scope (Nam)
3035 and then Nkind_In (Parent (P), N_Entry_Declaration,
3036 N_Subprogram_Declaration)
3037 then
3038 Error_Msg_N
3039 ("internal call cannot appear in default for formal of "
3040 & "protected operation", N);
3041 return;
3042 end if;
3044 P := Parent (P);
3045 end loop;
3046 end;
3047 end if;
3048 end Check_Internal_Protected_Use;
3050 ---------------------------------------
3051 -- Check_Later_Vs_Basic_Declarations --
3052 ---------------------------------------
3054 procedure Check_Later_Vs_Basic_Declarations
3055 (Decls : List_Id;
3056 During_Parsing : Boolean)
3058 Body_Sloc : Source_Ptr;
3059 Decl : Node_Id;
3061 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean;
3062 -- Return whether Decl is considered as a declarative item.
3063 -- When During_Parsing is True, the semantics of Ada 83 is followed.
3064 -- When During_Parsing is False, the semantics of SPARK is followed.
3066 -------------------------------
3067 -- Is_Later_Declarative_Item --
3068 -------------------------------
3070 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean is
3071 begin
3072 if Nkind (Decl) in N_Later_Decl_Item then
3073 return True;
3075 elsif Nkind (Decl) = N_Pragma then
3076 return True;
3078 elsif During_Parsing then
3079 return False;
3081 -- In SPARK, a package declaration is not considered as a later
3082 -- declarative item.
3084 elsif Nkind (Decl) = N_Package_Declaration then
3085 return False;
3087 -- In SPARK, a renaming is considered as a later declarative item
3089 elsif Nkind (Decl) in N_Renaming_Declaration then
3090 return True;
3092 else
3093 return False;
3094 end if;
3095 end Is_Later_Declarative_Item;
3097 -- Start of processing for Check_Later_Vs_Basic_Declarations
3099 begin
3100 Decl := First (Decls);
3102 -- Loop through sequence of basic declarative items
3104 Outer : while Present (Decl) loop
3105 if not Nkind_In (Decl, N_Subprogram_Body, N_Package_Body, N_Task_Body)
3106 and then Nkind (Decl) not in N_Body_Stub
3107 then
3108 Next (Decl);
3110 -- Once a body is encountered, we only allow later declarative
3111 -- items. The inner loop checks the rest of the list.
3113 else
3114 Body_Sloc := Sloc (Decl);
3116 Inner : while Present (Decl) loop
3117 if not Is_Later_Declarative_Item (Decl) then
3118 if During_Parsing then
3119 if Ada_Version = Ada_83 then
3120 Error_Msg_Sloc := Body_Sloc;
3121 Error_Msg_N
3122 ("(Ada 83) decl cannot appear after body#", Decl);
3123 end if;
3124 else
3125 Error_Msg_Sloc := Body_Sloc;
3126 Check_SPARK_05_Restriction
3127 ("decl cannot appear after body#", Decl);
3128 end if;
3129 end if;
3131 Next (Decl);
3132 end loop Inner;
3133 end if;
3134 end loop Outer;
3135 end Check_Later_Vs_Basic_Declarations;
3137 ---------------------------
3138 -- Check_No_Hidden_State --
3139 ---------------------------
3141 procedure Check_No_Hidden_State (Id : Entity_Id) is
3142 function Has_Null_Abstract_State (Pkg : Entity_Id) return Boolean;
3143 -- Determine whether the entity of a package denoted by Pkg has a null
3144 -- abstract state.
3146 -----------------------------
3147 -- Has_Null_Abstract_State --
3148 -----------------------------
3150 function Has_Null_Abstract_State (Pkg : Entity_Id) return Boolean is
3151 States : constant Elist_Id := Abstract_States (Pkg);
3153 begin
3154 -- Check first available state of related package. A null abstract
3155 -- state always appears as the sole element of the state list.
3157 return
3158 Present (States)
3159 and then Is_Null_State (Node (First_Elmt (States)));
3160 end Has_Null_Abstract_State;
3162 -- Local variables
3164 Context : Entity_Id := Empty;
3165 Not_Visible : Boolean := False;
3166 Scop : Entity_Id;
3168 -- Start of processing for Check_No_Hidden_State
3170 begin
3171 pragma Assert (Ekind_In (Id, E_Abstract_State, E_Variable));
3173 -- Find the proper context where the object or state appears
3175 Scop := Scope (Id);
3176 while Present (Scop) loop
3177 Context := Scop;
3179 -- Keep track of the context's visibility
3181 Not_Visible := Not_Visible or else In_Private_Part (Context);
3183 -- Prevent the search from going too far
3185 if Context = Standard_Standard then
3186 return;
3188 -- Objects and states that appear immediately within a subprogram or
3189 -- inside a construct nested within a subprogram do not introduce a
3190 -- hidden state. They behave as local variable declarations.
3192 elsif Is_Subprogram (Context) then
3193 return;
3195 -- When examining a package body, use the entity of the spec as it
3196 -- carries the abstract state declarations.
3198 elsif Ekind (Context) = E_Package_Body then
3199 Context := Spec_Entity (Context);
3200 end if;
3202 -- Stop the traversal when a package subject to a null abstract state
3203 -- has been found.
3205 if Ekind_In (Context, E_Generic_Package, E_Package)
3206 and then Has_Null_Abstract_State (Context)
3207 then
3208 exit;
3209 end if;
3211 Scop := Scope (Scop);
3212 end loop;
3214 -- At this point we know that there is at least one package with a null
3215 -- abstract state in visibility. Emit an error message unconditionally
3216 -- if the entity being processed is a state because the placement of the
3217 -- related package is irrelevant. This is not the case for objects as
3218 -- the intermediate context matters.
3220 if Present (Context)
3221 and then (Ekind (Id) = E_Abstract_State or else Not_Visible)
3222 then
3223 Error_Msg_N ("cannot introduce hidden state &", Id);
3224 Error_Msg_NE ("\package & has null abstract state", Id, Context);
3225 end if;
3226 end Check_No_Hidden_State;
3228 ----------------------------------------
3229 -- Check_Nonvolatile_Function_Profile --
3230 ----------------------------------------
3232 procedure Check_Nonvolatile_Function_Profile (Func_Id : Entity_Id) is
3233 Formal : Entity_Id;
3235 begin
3236 -- Inspect all formal parameters
3238 Formal := First_Formal (Func_Id);
3239 while Present (Formal) loop
3240 if Is_Effectively_Volatile (Etype (Formal)) then
3241 Error_Msg_NE
3242 ("nonvolatile function & cannot have a volatile parameter",
3243 Formal, Func_Id);
3244 end if;
3246 Next_Formal (Formal);
3247 end loop;
3249 -- Inspect the return type
3251 if Is_Effectively_Volatile (Etype (Func_Id)) then
3252 Error_Msg_NE
3253 ("nonvolatile function & cannot have a volatile return type",
3254 Result_Definition (Parent (Func_Id)), Func_Id);
3255 end if;
3256 end Check_Nonvolatile_Function_Profile;
3258 -----------------------------
3259 -- Check_Part_Of_Reference --
3260 -----------------------------
3262 procedure Check_Part_Of_Reference (Var_Id : Entity_Id; Ref : Node_Id) is
3263 Conc_Obj : constant Entity_Id := Encapsulating_State (Var_Id);
3264 Decl : Node_Id;
3265 OK_Use : Boolean := False;
3266 Par : Node_Id;
3267 Prag_Nam : Name_Id;
3268 Spec_Id : Entity_Id;
3270 begin
3271 -- Traverse the parent chain looking for a suitable context for the
3272 -- reference to the concurrent constituent.
3274 Par := Parent (Ref);
3275 while Present (Par) loop
3276 if Nkind (Par) = N_Pragma then
3277 Prag_Nam := Pragma_Name (Par);
3279 -- A concurrent constituent is allowed to appear in pragmas
3280 -- Initial_Condition and Initializes as this is part of the
3281 -- elaboration checks for the constituent (SPARK RM 9.3).
3283 if Nam_In (Prag_Nam, Name_Initial_Condition, Name_Initializes) then
3284 OK_Use := True;
3285 exit;
3287 -- When the reference appears within pragma Depends or Global,
3288 -- check whether the pragma applies to a single task type. Note
3289 -- that the pragma is not encapsulated by the type definition,
3290 -- but this is still a valid context.
3292 elsif Nam_In (Prag_Nam, Name_Depends, Name_Global) then
3293 Decl := Find_Related_Declaration_Or_Body (Par);
3295 if Nkind (Decl) = N_Object_Declaration
3296 and then Defining_Entity (Decl) = Conc_Obj
3297 then
3298 OK_Use := True;
3299 exit;
3300 end if;
3301 end if;
3303 -- The reference appears somewhere in the definition of the single
3304 -- protected/task type (SPARK RM 9.3).
3306 elsif Nkind_In (Par, N_Single_Protected_Declaration,
3307 N_Single_Task_Declaration)
3308 and then Defining_Entity (Par) = Conc_Obj
3309 then
3310 OK_Use := True;
3311 exit;
3313 -- The reference appears within the expanded declaration or the body
3314 -- of the single protected/task type (SPARK RM 9.3).
3316 elsif Nkind_In (Par, N_Protected_Body,
3317 N_Protected_Type_Declaration,
3318 N_Task_Body,
3319 N_Task_Type_Declaration)
3320 then
3321 Spec_Id := Unique_Defining_Entity (Par);
3323 if Present (Anonymous_Object (Spec_Id))
3324 and then Anonymous_Object (Spec_Id) = Conc_Obj
3325 then
3326 OK_Use := True;
3327 exit;
3328 end if;
3330 -- The reference has been relocated within an internally generated
3331 -- package or subprogram. Assume that the reference is legal as the
3332 -- real check was already performed in the original context of the
3333 -- reference.
3335 elsif Nkind_In (Par, N_Package_Body,
3336 N_Package_Declaration,
3337 N_Subprogram_Body,
3338 N_Subprogram_Declaration)
3339 and then not Comes_From_Source (Par)
3340 then
3341 -- Continue to examine the context if the reference appears in a
3342 -- subprogram body which was previously an expression function.
3344 if Nkind (Par) = N_Subprogram_Body
3345 and then Was_Expression_Function (Par)
3346 then
3347 null;
3349 -- Otherwise the reference is legal
3351 else
3352 OK_Use := True;
3353 exit;
3354 end if;
3356 -- The reference has been relocated to an inlined body for GNATprove.
3357 -- Assume that the reference is legal as the real check was already
3358 -- performed in the original context of the reference.
3360 elsif GNATprove_Mode
3361 and then Nkind (Par) = N_Subprogram_Body
3362 and then Chars (Defining_Entity (Par)) = Name_uParent
3363 then
3364 OK_Use := True;
3365 exit;
3366 end if;
3368 Par := Parent (Par);
3369 end loop;
3371 -- The reference is illegal as it appears outside the definition or
3372 -- body of the single protected/task type.
3374 if not OK_Use then
3375 Error_Msg_NE
3376 ("reference to variable & cannot appear in this context",
3377 Ref, Var_Id);
3378 Error_Msg_Name_1 := Chars (Var_Id);
3380 if Is_Single_Protected_Object (Conc_Obj) then
3381 Error_Msg_NE
3382 ("\% is constituent of single protected type &", Ref, Conc_Obj);
3384 else
3385 Error_Msg_NE
3386 ("\% is constituent of single task type &", Ref, Conc_Obj);
3387 end if;
3388 end if;
3389 end Check_Part_Of_Reference;
3391 ------------------------------------------
3392 -- Check_Potentially_Blocking_Operation --
3393 ------------------------------------------
3395 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
3396 S : Entity_Id;
3398 begin
3399 -- N is one of the potentially blocking operations listed in 9.5.1(8).
3400 -- When pragma Detect_Blocking is active, the run time will raise
3401 -- Program_Error. Here we only issue a warning, since we generally
3402 -- support the use of potentially blocking operations in the absence
3403 -- of the pragma.
3405 -- Indirect blocking through a subprogram call cannot be diagnosed
3406 -- statically without interprocedural analysis, so we do not attempt
3407 -- to do it here.
3409 S := Scope (Current_Scope);
3410 while Present (S) and then S /= Standard_Standard loop
3411 if Is_Protected_Type (S) then
3412 Error_Msg_N
3413 ("potentially blocking operation in protected operation??", N);
3414 return;
3415 end if;
3417 S := Scope (S);
3418 end loop;
3419 end Check_Potentially_Blocking_Operation;
3421 ------------------------------------
3422 -- Check_Previous_Null_Procedure --
3423 ------------------------------------
3425 procedure Check_Previous_Null_Procedure
3426 (Decl : Node_Id;
3427 Prev : Entity_Id)
3429 begin
3430 if Ekind (Prev) = E_Procedure
3431 and then Nkind (Parent (Prev)) = N_Procedure_Specification
3432 and then Null_Present (Parent (Prev))
3433 then
3434 Error_Msg_Sloc := Sloc (Prev);
3435 Error_Msg_N
3436 ("declaration cannot complete previous null procedure#", Decl);
3437 end if;
3438 end Check_Previous_Null_Procedure;
3440 ---------------------------------
3441 -- Check_Result_And_Post_State --
3442 ---------------------------------
3444 procedure Check_Result_And_Post_State (Subp_Id : Entity_Id) is
3445 procedure Check_Result_And_Post_State_In_Pragma
3446 (Prag : Node_Id;
3447 Result_Seen : in out Boolean);
3448 -- Determine whether pragma Prag mentions attribute 'Result and whether
3449 -- the pragma contains an expression that evaluates differently in pre-
3450 -- and post-state. Prag is a [refined] postcondition or a contract-cases
3451 -- pragma. Result_Seen is set when the pragma mentions attribute 'Result
3453 function Has_In_Out_Parameter (Subp_Id : Entity_Id) return Boolean;
3454 -- Determine whether subprogram Subp_Id contains at least one IN OUT
3455 -- formal parameter.
3457 -------------------------------------------
3458 -- Check_Result_And_Post_State_In_Pragma --
3459 -------------------------------------------
3461 procedure Check_Result_And_Post_State_In_Pragma
3462 (Prag : Node_Id;
3463 Result_Seen : in out Boolean)
3465 procedure Check_Conjunct (Expr : Node_Id);
3466 -- Check an individual conjunct in a conjunction of Boolean
3467 -- expressions, connected by "and" or "and then" operators.
3469 procedure Check_Conjuncts (Expr : Node_Id);
3470 -- Apply the post-state check to every conjunct in an expression, in
3471 -- case this is a conjunction of Boolean expressions. Otherwise apply
3472 -- it to the expression as a whole.
3474 procedure Check_Expression (Expr : Node_Id);
3475 -- Perform the 'Result and post-state checks on a given expression
3477 function Is_Function_Result (N : Node_Id) return Traverse_Result;
3478 -- Attempt to find attribute 'Result in a subtree denoted by N
3480 function Is_Trivial_Boolean (N : Node_Id) return Boolean;
3481 -- Determine whether source node N denotes "True" or "False"
3483 function Mentions_Post_State (N : Node_Id) return Boolean;
3484 -- Determine whether a subtree denoted by N mentions any construct
3485 -- that denotes a post-state.
3487 procedure Check_Function_Result is
3488 new Traverse_Proc (Is_Function_Result);
3490 --------------------
3491 -- Check_Conjunct --
3492 --------------------
3494 procedure Check_Conjunct (Expr : Node_Id) is
3495 function Adjust_Message (Msg : String) return String;
3496 -- Prepend a prefix to the input message Msg denoting that the
3497 -- message applies to a conjunct in the expression, when this
3498 -- is the case.
3500 function Applied_On_Conjunct return Boolean;
3501 -- Returns True if the message applies to a conjunct in the
3502 -- expression, instead of the whole expression.
3504 --------------------
3505 -- Adjust_Message --
3506 --------------------
3508 function Adjust_Message (Msg : String) return String is
3509 begin
3510 if Applied_On_Conjunct then
3511 return "conjunct in " & Msg;
3512 else
3513 return Msg;
3514 end if;
3515 end Adjust_Message;
3517 -------------------------
3518 -- Applied_On_Conjunct --
3519 -------------------------
3521 function Applied_On_Conjunct return Boolean is
3522 begin
3523 -- Expr is the conjunct of an enclosing "and" expression
3525 return Nkind (Parent (Expr)) in N_Subexpr
3527 -- or Expr is a conjunct of an enclosing "and then"
3528 -- expression in a postcondition aspect that was split into
3529 -- multiple pragmas. The first conjunct has the "and then"
3530 -- expression as Original_Node, and other conjuncts have
3531 -- Split_PCC set to True.
3533 or else Nkind (Original_Node (Expr)) = N_And_Then
3534 or else Split_PPC (Prag);
3535 end Applied_On_Conjunct;
3537 -- Local variables
3539 Err_Node : Node_Id;
3540 -- Error node when reporting a warning on a (refined)
3541 -- postcondition.
3543 -- Start of processing for Check_Conjunct
3545 begin
3546 if Applied_On_Conjunct then
3547 Err_Node := Expr;
3548 else
3549 Err_Node := Prag;
3550 end if;
3552 if not Is_Trivial_Boolean (Expr)
3553 and then not Mentions_Post_State (Expr)
3554 then
3555 if Pragma_Name (Prag) = Name_Contract_Cases then
3556 Error_Msg_NE (Adjust_Message
3557 ("contract case does not check the outcome of calling "
3558 & "&?T?"), Expr, Subp_Id);
3560 elsif Pragma_Name (Prag) = Name_Refined_Post then
3561 Error_Msg_NE (Adjust_Message
3562 ("refined postcondition does not check the outcome of "
3563 & "calling &?T?"), Err_Node, Subp_Id);
3565 else
3566 Error_Msg_NE (Adjust_Message
3567 ("postcondition does not check the outcome of calling "
3568 & "&?T?"), Err_Node, Subp_Id);
3569 end if;
3570 end if;
3571 end Check_Conjunct;
3573 ---------------------
3574 -- Check_Conjuncts --
3575 ---------------------
3577 procedure Check_Conjuncts (Expr : Node_Id) is
3578 begin
3579 if Nkind_In (Expr, N_Op_And, N_And_Then) then
3580 Check_Conjuncts (Left_Opnd (Expr));
3581 Check_Conjuncts (Right_Opnd (Expr));
3582 else
3583 Check_Conjunct (Expr);
3584 end if;
3585 end Check_Conjuncts;
3587 ----------------------
3588 -- Check_Expression --
3589 ----------------------
3591 procedure Check_Expression (Expr : Node_Id) is
3592 begin
3593 if not Is_Trivial_Boolean (Expr) then
3594 Check_Function_Result (Expr);
3595 Check_Conjuncts (Expr);
3596 end if;
3597 end Check_Expression;
3599 ------------------------
3600 -- Is_Function_Result --
3601 ------------------------
3603 function Is_Function_Result (N : Node_Id) return Traverse_Result is
3604 begin
3605 if Is_Attribute_Result (N) then
3606 Result_Seen := True;
3607 return Abandon;
3609 -- Continue the traversal
3611 else
3612 return OK;
3613 end if;
3614 end Is_Function_Result;
3616 ------------------------
3617 -- Is_Trivial_Boolean --
3618 ------------------------
3620 function Is_Trivial_Boolean (N : Node_Id) return Boolean is
3621 begin
3622 return
3623 Comes_From_Source (N)
3624 and then Is_Entity_Name (N)
3625 and then (Entity (N) = Standard_True
3626 or else
3627 Entity (N) = Standard_False);
3628 end Is_Trivial_Boolean;
3630 -------------------------
3631 -- Mentions_Post_State --
3632 -------------------------
3634 function Mentions_Post_State (N : Node_Id) return Boolean is
3635 Post_State_Seen : Boolean := False;
3637 function Is_Post_State (N : Node_Id) return Traverse_Result;
3638 -- Attempt to find a construct that denotes a post-state. If this
3639 -- is the case, set flag Post_State_Seen.
3641 -------------------
3642 -- Is_Post_State --
3643 -------------------
3645 function Is_Post_State (N : Node_Id) return Traverse_Result is
3646 Ent : Entity_Id;
3648 begin
3649 if Nkind_In (N, N_Explicit_Dereference, N_Function_Call) then
3650 Post_State_Seen := True;
3651 return Abandon;
3653 elsif Nkind_In (N, N_Expanded_Name, N_Identifier) then
3654 Ent := Entity (N);
3656 -- Treat an undecorated reference as OK
3658 if No (Ent)
3660 -- A reference to an assignable entity is considered a
3661 -- change in the post-state of a subprogram.
3663 or else Ekind_In (Ent, E_Generic_In_Out_Parameter,
3664 E_In_Out_Parameter,
3665 E_Out_Parameter,
3666 E_Variable)
3668 -- The reference may be modified through a dereference
3670 or else (Is_Access_Type (Etype (Ent))
3671 and then Nkind (Parent (N)) =
3672 N_Selected_Component)
3673 then
3674 Post_State_Seen := True;
3675 return Abandon;
3676 end if;
3678 elsif Nkind (N) = N_Attribute_Reference then
3679 if Attribute_Name (N) = Name_Old then
3680 return Skip;
3682 elsif Attribute_Name (N) = Name_Result then
3683 Post_State_Seen := True;
3684 return Abandon;
3685 end if;
3686 end if;
3688 return OK;
3689 end Is_Post_State;
3691 procedure Find_Post_State is new Traverse_Proc (Is_Post_State);
3693 -- Start of processing for Mentions_Post_State
3695 begin
3696 Find_Post_State (N);
3698 return Post_State_Seen;
3699 end Mentions_Post_State;
3701 -- Local variables
3703 Expr : constant Node_Id :=
3704 Get_Pragma_Arg
3705 (First (Pragma_Argument_Associations (Prag)));
3706 Nam : constant Name_Id := Pragma_Name (Prag);
3707 CCase : Node_Id;
3709 -- Start of processing for Check_Result_And_Post_State_In_Pragma
3711 begin
3712 -- Examine all consequences
3714 if Nam = Name_Contract_Cases then
3715 CCase := First (Component_Associations (Expr));
3716 while Present (CCase) loop
3717 Check_Expression (Expression (CCase));
3719 Next (CCase);
3720 end loop;
3722 -- Examine the expression of a postcondition
3724 else pragma Assert (Nam_In (Nam, Name_Postcondition,
3725 Name_Refined_Post));
3726 Check_Expression (Expr);
3727 end if;
3728 end Check_Result_And_Post_State_In_Pragma;
3730 --------------------------
3731 -- Has_In_Out_Parameter --
3732 --------------------------
3734 function Has_In_Out_Parameter (Subp_Id : Entity_Id) return Boolean is
3735 Formal : Entity_Id;
3737 begin
3738 -- Traverse the formals looking for an IN OUT parameter
3740 Formal := First_Formal (Subp_Id);
3741 while Present (Formal) loop
3742 if Ekind (Formal) = E_In_Out_Parameter then
3743 return True;
3744 end if;
3746 Next_Formal (Formal);
3747 end loop;
3749 return False;
3750 end Has_In_Out_Parameter;
3752 -- Local variables
3754 Items : constant Node_Id := Contract (Subp_Id);
3755 Subp_Decl : constant Node_Id := Unit_Declaration_Node (Subp_Id);
3756 Case_Prag : Node_Id := Empty;
3757 Post_Prag : Node_Id := Empty;
3758 Prag : Node_Id;
3759 Seen_In_Case : Boolean := False;
3760 Seen_In_Post : Boolean := False;
3761 Spec_Id : Entity_Id;
3763 -- Start of processing for Check_Result_And_Post_State
3765 begin
3766 -- The lack of attribute 'Result or a post-state is classified as a
3767 -- suspicious contract. Do not perform the check if the corresponding
3768 -- swich is not set.
3770 if not Warn_On_Suspicious_Contract then
3771 return;
3773 -- Nothing to do if there is no contract
3775 elsif No (Items) then
3776 return;
3777 end if;
3779 -- Retrieve the entity of the subprogram spec (if any)
3781 if Nkind (Subp_Decl) = N_Subprogram_Body
3782 and then Present (Corresponding_Spec (Subp_Decl))
3783 then
3784 Spec_Id := Corresponding_Spec (Subp_Decl);
3786 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
3787 and then Present (Corresponding_Spec_Of_Stub (Subp_Decl))
3788 then
3789 Spec_Id := Corresponding_Spec_Of_Stub (Subp_Decl);
3791 else
3792 Spec_Id := Subp_Id;
3793 end if;
3795 -- Examine all postconditions for attribute 'Result and a post-state
3797 Prag := Pre_Post_Conditions (Items);
3798 while Present (Prag) loop
3799 if Nam_In (Pragma_Name_Unmapped (Prag),
3800 Name_Postcondition, Name_Refined_Post)
3801 and then not Error_Posted (Prag)
3802 then
3803 Post_Prag := Prag;
3804 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Post);
3805 end if;
3807 Prag := Next_Pragma (Prag);
3808 end loop;
3810 -- Examine the contract cases of the subprogram for attribute 'Result
3811 -- and a post-state.
3813 Prag := Contract_Test_Cases (Items);
3814 while Present (Prag) loop
3815 if Pragma_Name (Prag) = Name_Contract_Cases
3816 and then not Error_Posted (Prag)
3817 then
3818 Case_Prag := Prag;
3819 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Case);
3820 end if;
3822 Prag := Next_Pragma (Prag);
3823 end loop;
3825 -- Do not emit any errors if the subprogram is not a function
3827 if not Ekind_In (Spec_Id, E_Function, E_Generic_Function) then
3828 null;
3830 -- Regardless of whether the function has postconditions or contract
3831 -- cases, or whether they mention attribute 'Result, an IN OUT formal
3832 -- parameter is always treated as a result.
3834 elsif Has_In_Out_Parameter (Spec_Id) then
3835 null;
3837 -- The function has both a postcondition and contract cases and they do
3838 -- not mention attribute 'Result.
3840 elsif Present (Case_Prag)
3841 and then not Seen_In_Case
3842 and then Present (Post_Prag)
3843 and then not Seen_In_Post
3844 then
3845 Error_Msg_N
3846 ("neither postcondition nor contract cases mention function "
3847 & "result?T?", Post_Prag);
3849 -- The function has contract cases only and they do not mention
3850 -- attribute 'Result.
3852 elsif Present (Case_Prag) and then not Seen_In_Case then
3853 Error_Msg_N ("contract cases do not mention result?T?", Case_Prag);
3855 -- The function has postconditions only and they do not mention
3856 -- attribute 'Result.
3858 elsif Present (Post_Prag) and then not Seen_In_Post then
3859 Error_Msg_N
3860 ("postcondition does not mention function result?T?", Post_Prag);
3861 end if;
3862 end Check_Result_And_Post_State;
3864 -----------------------------
3865 -- Check_State_Refinements --
3866 -----------------------------
3868 procedure Check_State_Refinements
3869 (Context : Node_Id;
3870 Is_Main_Unit : Boolean := False)
3872 procedure Check_Package (Pack : Node_Id);
3873 -- Verify that all abstract states of a [generic] package denoted by its
3874 -- declarative node Pack have proper refinement. Recursively verify the
3875 -- visible and private declarations of the [generic] package for other
3876 -- nested packages.
3878 procedure Check_Packages_In (Decls : List_Id);
3879 -- Seek out [generic] package declarations within declarative list Decls
3880 -- and verify the status of their abstract state refinement.
3882 function SPARK_Mode_Is_Off (N : Node_Id) return Boolean;
3883 -- Determine whether construct N is subject to pragma SPARK_Mode Off
3885 -------------------
3886 -- Check_Package --
3887 -------------------
3889 procedure Check_Package (Pack : Node_Id) is
3890 Body_Id : constant Entity_Id := Corresponding_Body (Pack);
3891 Spec : constant Node_Id := Specification (Pack);
3892 States : constant Elist_Id :=
3893 Abstract_States (Defining_Entity (Pack));
3895 State_Elmt : Elmt_Id;
3896 State_Id : Entity_Id;
3898 begin
3899 -- Do not verify proper state refinement when the package is subject
3900 -- to pragma SPARK_Mode Off because this disables the requirement for
3901 -- state refinement.
3903 if SPARK_Mode_Is_Off (Pack) then
3904 null;
3906 -- State refinement can only occur in a completing packge body. Do
3907 -- not verify proper state refinement when the body is subject to
3908 -- pragma SPARK_Mode Off because this disables the requirement for
3909 -- state refinement.
3911 elsif Present (Body_Id)
3912 and then SPARK_Mode_Is_Off (Unit_Declaration_Node (Body_Id))
3913 then
3914 null;
3916 -- Do not verify proper state refinement when the package is an
3917 -- instance as this check was already performed in the generic.
3919 elsif Present (Generic_Parent (Spec)) then
3920 null;
3922 -- Otherwise examine the contents of the package
3924 else
3925 if Present (States) then
3926 State_Elmt := First_Elmt (States);
3927 while Present (State_Elmt) loop
3928 State_Id := Node (State_Elmt);
3930 -- Emit an error when a non-null state lacks any form of
3931 -- refinement.
3933 if not Is_Null_State (State_Id)
3934 and then not Has_Null_Refinement (State_Id)
3935 and then not Has_Non_Null_Refinement (State_Id)
3936 then
3937 Error_Msg_N ("state & requires refinement", State_Id);
3938 end if;
3940 Next_Elmt (State_Elmt);
3941 end loop;
3942 end if;
3944 Check_Packages_In (Visible_Declarations (Spec));
3945 Check_Packages_In (Private_Declarations (Spec));
3946 end if;
3947 end Check_Package;
3949 -----------------------
3950 -- Check_Packages_In --
3951 -----------------------
3953 procedure Check_Packages_In (Decls : List_Id) is
3954 Decl : Node_Id;
3956 begin
3957 if Present (Decls) then
3958 Decl := First (Decls);
3959 while Present (Decl) loop
3960 if Nkind_In (Decl, N_Generic_Package_Declaration,
3961 N_Package_Declaration)
3962 then
3963 Check_Package (Decl);
3964 end if;
3966 Next (Decl);
3967 end loop;
3968 end if;
3969 end Check_Packages_In;
3971 -----------------------
3972 -- SPARK_Mode_Is_Off --
3973 -----------------------
3975 function SPARK_Mode_Is_Off (N : Node_Id) return Boolean is
3976 Id : constant Entity_Id := Defining_Entity (N);
3977 Prag : constant Node_Id := SPARK_Pragma (Id);
3979 begin
3980 -- Default the mode to "off" when the context is an instance and all
3981 -- SPARK_Mode pragmas found within are to be ignored.
3983 if Ignore_SPARK_Mode_Pragmas (Id) then
3984 return True;
3986 else
3987 return
3988 Present (Prag)
3989 and then Get_SPARK_Mode_From_Annotation (Prag) = Off;
3990 end if;
3991 end SPARK_Mode_Is_Off;
3993 -- Start of processing for Check_State_Refinements
3995 begin
3996 -- A block may declare a nested package
3998 if Nkind (Context) = N_Block_Statement then
3999 Check_Packages_In (Declarations (Context));
4001 -- An entry, protected, subprogram, or task body may declare a nested
4002 -- package.
4004 elsif Nkind_In (Context, N_Entry_Body,
4005 N_Protected_Body,
4006 N_Subprogram_Body,
4007 N_Task_Body)
4008 then
4009 -- Do not verify proper state refinement when the body is subject to
4010 -- pragma SPARK_Mode Off because this disables the requirement for
4011 -- state refinement.
4013 if not SPARK_Mode_Is_Off (Context) then
4014 Check_Packages_In (Declarations (Context));
4015 end if;
4017 -- A package body may declare a nested package
4019 elsif Nkind (Context) = N_Package_Body then
4020 Check_Package (Unit_Declaration_Node (Corresponding_Spec (Context)));
4022 -- Do not verify proper state refinement when the body is subject to
4023 -- pragma SPARK_Mode Off because this disables the requirement for
4024 -- state refinement.
4026 if not SPARK_Mode_Is_Off (Context) then
4027 Check_Packages_In (Declarations (Context));
4028 end if;
4030 -- A library level [generic] package may declare a nested package
4032 elsif Nkind_In (Context, N_Generic_Package_Declaration,
4033 N_Package_Declaration)
4034 and then Is_Main_Unit
4035 then
4036 Check_Package (Context);
4037 end if;
4038 end Check_State_Refinements;
4040 ------------------------------
4041 -- Check_Unprotected_Access --
4042 ------------------------------
4044 procedure Check_Unprotected_Access
4045 (Context : Node_Id;
4046 Expr : Node_Id)
4048 Cont_Encl_Typ : Entity_Id;
4049 Pref_Encl_Typ : Entity_Id;
4051 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
4052 -- Check whether Obj is a private component of a protected object.
4053 -- Return the protected type where the component resides, Empty
4054 -- otherwise.
4056 function Is_Public_Operation return Boolean;
4057 -- Verify that the enclosing operation is callable from outside the
4058 -- protected object, to minimize false positives.
4060 ------------------------------
4061 -- Enclosing_Protected_Type --
4062 ------------------------------
4064 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
4065 begin
4066 if Is_Entity_Name (Obj) then
4067 declare
4068 Ent : Entity_Id := Entity (Obj);
4070 begin
4071 -- The object can be a renaming of a private component, use
4072 -- the original record component.
4074 if Is_Prival (Ent) then
4075 Ent := Prival_Link (Ent);
4076 end if;
4078 if Is_Protected_Type (Scope (Ent)) then
4079 return Scope (Ent);
4080 end if;
4081 end;
4082 end if;
4084 -- For indexed and selected components, recursively check the prefix
4086 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
4087 return Enclosing_Protected_Type (Prefix (Obj));
4089 -- The object does not denote a protected component
4091 else
4092 return Empty;
4093 end if;
4094 end Enclosing_Protected_Type;
4096 -------------------------
4097 -- Is_Public_Operation --
4098 -------------------------
4100 function Is_Public_Operation return Boolean is
4101 S : Entity_Id;
4102 E : Entity_Id;
4104 begin
4105 S := Current_Scope;
4106 while Present (S) and then S /= Pref_Encl_Typ loop
4107 if Scope (S) = Pref_Encl_Typ then
4108 E := First_Entity (Pref_Encl_Typ);
4109 while Present (E)
4110 and then E /= First_Private_Entity (Pref_Encl_Typ)
4111 loop
4112 if E = S then
4113 return True;
4114 end if;
4116 Next_Entity (E);
4117 end loop;
4118 end if;
4120 S := Scope (S);
4121 end loop;
4123 return False;
4124 end Is_Public_Operation;
4126 -- Start of processing for Check_Unprotected_Access
4128 begin
4129 if Nkind (Expr) = N_Attribute_Reference
4130 and then Attribute_Name (Expr) = Name_Unchecked_Access
4131 then
4132 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
4133 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
4135 -- Check whether we are trying to export a protected component to a
4136 -- context with an equal or lower access level.
4138 if Present (Pref_Encl_Typ)
4139 and then No (Cont_Encl_Typ)
4140 and then Is_Public_Operation
4141 and then Scope_Depth (Pref_Encl_Typ) >=
4142 Object_Access_Level (Context)
4143 then
4144 Error_Msg_N
4145 ("??possible unprotected access to protected data", Expr);
4146 end if;
4147 end if;
4148 end Check_Unprotected_Access;
4150 ------------------------------
4151 -- Check_Unused_Body_States --
4152 ------------------------------
4154 procedure Check_Unused_Body_States (Body_Id : Entity_Id) is
4155 procedure Process_Refinement_Clause
4156 (Clause : Node_Id;
4157 States : Elist_Id);
4158 -- Inspect all constituents of refinement clause Clause and remove any
4159 -- matches from body state list States.
4161 procedure Report_Unused_Body_States (States : Elist_Id);
4162 -- Emit errors for each abstract state or object found in list States
4164 -------------------------------
4165 -- Process_Refinement_Clause --
4166 -------------------------------
4168 procedure Process_Refinement_Clause
4169 (Clause : Node_Id;
4170 States : Elist_Id)
4172 procedure Process_Constituent (Constit : Node_Id);
4173 -- Remove constituent Constit from body state list States
4175 -------------------------
4176 -- Process_Constituent --
4177 -------------------------
4179 procedure Process_Constituent (Constit : Node_Id) is
4180 Constit_Id : Entity_Id;
4182 begin
4183 -- Guard against illegal constituents. Only abstract states and
4184 -- objects can appear on the right hand side of a refinement.
4186 if Is_Entity_Name (Constit) then
4187 Constit_Id := Entity_Of (Constit);
4189 if Present (Constit_Id)
4190 and then Ekind_In (Constit_Id, E_Abstract_State,
4191 E_Constant,
4192 E_Variable)
4193 then
4194 Remove (States, Constit_Id);
4195 end if;
4196 end if;
4197 end Process_Constituent;
4199 -- Local variables
4201 Constit : Node_Id;
4203 -- Start of processing for Process_Refinement_Clause
4205 begin
4206 if Nkind (Clause) = N_Component_Association then
4207 Constit := Expression (Clause);
4209 -- Multiple constituents appear as an aggregate
4211 if Nkind (Constit) = N_Aggregate then
4212 Constit := First (Expressions (Constit));
4213 while Present (Constit) loop
4214 Process_Constituent (Constit);
4215 Next (Constit);
4216 end loop;
4218 -- Various forms of a single constituent
4220 else
4221 Process_Constituent (Constit);
4222 end if;
4223 end if;
4224 end Process_Refinement_Clause;
4226 -------------------------------
4227 -- Report_Unused_Body_States --
4228 -------------------------------
4230 procedure Report_Unused_Body_States (States : Elist_Id) is
4231 Posted : Boolean := False;
4232 State_Elmt : Elmt_Id;
4233 State_Id : Entity_Id;
4235 begin
4236 if Present (States) then
4237 State_Elmt := First_Elmt (States);
4238 while Present (State_Elmt) loop
4239 State_Id := Node (State_Elmt);
4241 -- Constants are part of the hidden state of a package, but the
4242 -- compiler cannot determine whether they have variable input
4243 -- (SPARK RM 7.1.1(2)) and cannot classify them properly as a
4244 -- hidden state. Do not emit an error when a constant does not
4245 -- participate in a state refinement, even though it acts as a
4246 -- hidden state.
4248 if Ekind (State_Id) = E_Constant then
4249 null;
4251 -- Generate an error message of the form:
4253 -- body of package ... has unused hidden states
4254 -- abstract state ... defined at ...
4255 -- variable ... defined at ...
4257 else
4258 if not Posted then
4259 Posted := True;
4260 SPARK_Msg_N
4261 ("body of package & has unused hidden states", Body_Id);
4262 end if;
4264 Error_Msg_Sloc := Sloc (State_Id);
4266 if Ekind (State_Id) = E_Abstract_State then
4267 SPARK_Msg_NE
4268 ("\abstract state & defined #", Body_Id, State_Id);
4270 else
4271 SPARK_Msg_NE ("\variable & defined #", Body_Id, State_Id);
4272 end if;
4273 end if;
4275 Next_Elmt (State_Elmt);
4276 end loop;
4277 end if;
4278 end Report_Unused_Body_States;
4280 -- Local variables
4282 Prag : constant Node_Id := Get_Pragma (Body_Id, Pragma_Refined_State);
4283 Spec_Id : constant Entity_Id := Spec_Entity (Body_Id);
4284 Clause : Node_Id;
4285 States : Elist_Id;
4287 -- Start of processing for Check_Unused_Body_States
4289 begin
4290 -- Inspect the clauses of pragma Refined_State and determine whether all
4291 -- visible states declared within the package body participate in the
4292 -- refinement.
4294 if Present (Prag) then
4295 Clause := Expression (Get_Argument (Prag, Spec_Id));
4296 States := Collect_Body_States (Body_Id);
4298 -- Multiple non-null state refinements appear as an aggregate
4300 if Nkind (Clause) = N_Aggregate then
4301 Clause := First (Component_Associations (Clause));
4302 while Present (Clause) loop
4303 Process_Refinement_Clause (Clause, States);
4304 Next (Clause);
4305 end loop;
4307 -- Various forms of a single state refinement
4309 else
4310 Process_Refinement_Clause (Clause, States);
4311 end if;
4313 -- Ensure that all abstract states and objects declared in the
4314 -- package body state space are utilized as constituents.
4316 Report_Unused_Body_States (States);
4317 end if;
4318 end Check_Unused_Body_States;
4320 -----------------
4321 -- Choice_List --
4322 -----------------
4324 function Choice_List (N : Node_Id) return List_Id is
4325 begin
4326 if Nkind (N) = N_Iterated_Component_Association then
4327 return Discrete_Choices (N);
4328 else
4329 return Choices (N);
4330 end if;
4331 end Choice_List;
4333 -------------------------
4334 -- Collect_Body_States --
4335 -------------------------
4337 function Collect_Body_States (Body_Id : Entity_Id) return Elist_Id is
4338 function Is_Visible_Object (Obj_Id : Entity_Id) return Boolean;
4339 -- Determine whether object Obj_Id is a suitable visible state of a
4340 -- package body.
4342 procedure Collect_Visible_States
4343 (Pack_Id : Entity_Id;
4344 States : in out Elist_Id);
4345 -- Gather the entities of all abstract states and objects declared in
4346 -- the visible state space of package Pack_Id.
4348 ----------------------------
4349 -- Collect_Visible_States --
4350 ----------------------------
4352 procedure Collect_Visible_States
4353 (Pack_Id : Entity_Id;
4354 States : in out Elist_Id)
4356 Item_Id : Entity_Id;
4358 begin
4359 -- Traverse the entity chain of the package and inspect all visible
4360 -- items.
4362 Item_Id := First_Entity (Pack_Id);
4363 while Present (Item_Id) and then not In_Private_Part (Item_Id) loop
4365 -- Do not consider internally generated items as those cannot be
4366 -- named and participate in refinement.
4368 if not Comes_From_Source (Item_Id) then
4369 null;
4371 elsif Ekind (Item_Id) = E_Abstract_State then
4372 Append_New_Elmt (Item_Id, States);
4374 elsif Ekind_In (Item_Id, E_Constant, E_Variable)
4375 and then Is_Visible_Object (Item_Id)
4376 then
4377 Append_New_Elmt (Item_Id, States);
4379 -- Recursively gather the visible states of a nested package
4381 elsif Ekind (Item_Id) = E_Package then
4382 Collect_Visible_States (Item_Id, States);
4383 end if;
4385 Next_Entity (Item_Id);
4386 end loop;
4387 end Collect_Visible_States;
4389 -----------------------
4390 -- Is_Visible_Object --
4391 -----------------------
4393 function Is_Visible_Object (Obj_Id : Entity_Id) return Boolean is
4394 begin
4395 -- Objects that map generic formals to their actuals are not visible
4396 -- from outside the generic instantiation.
4398 if Present (Corresponding_Generic_Association
4399 (Declaration_Node (Obj_Id)))
4400 then
4401 return False;
4403 -- Constituents of a single protected/task type act as components of
4404 -- the type and are not visible from outside the type.
4406 elsif Ekind (Obj_Id) = E_Variable
4407 and then Present (Encapsulating_State (Obj_Id))
4408 and then Is_Single_Concurrent_Object (Encapsulating_State (Obj_Id))
4409 then
4410 return False;
4412 else
4413 return True;
4414 end if;
4415 end Is_Visible_Object;
4417 -- Local variables
4419 Body_Decl : constant Node_Id := Unit_Declaration_Node (Body_Id);
4420 Decl : Node_Id;
4421 Item_Id : Entity_Id;
4422 States : Elist_Id := No_Elist;
4424 -- Start of processing for Collect_Body_States
4426 begin
4427 -- Inspect the declarations of the body looking for source objects,
4428 -- packages and package instantiations. Note that even though this
4429 -- processing is very similar to Collect_Visible_States, a package
4430 -- body does not have a First/Next_Entity list.
4432 Decl := First (Declarations (Body_Decl));
4433 while Present (Decl) loop
4435 -- Capture source objects as internally generated temporaries cannot
4436 -- be named and participate in refinement.
4438 if Nkind (Decl) = N_Object_Declaration then
4439 Item_Id := Defining_Entity (Decl);
4441 if Comes_From_Source (Item_Id)
4442 and then Is_Visible_Object (Item_Id)
4443 then
4444 Append_New_Elmt (Item_Id, States);
4445 end if;
4447 -- Capture the visible abstract states and objects of a source
4448 -- package [instantiation].
4450 elsif Nkind (Decl) = N_Package_Declaration then
4451 Item_Id := Defining_Entity (Decl);
4453 if Comes_From_Source (Item_Id) then
4454 Collect_Visible_States (Item_Id, States);
4455 end if;
4456 end if;
4458 Next (Decl);
4459 end loop;
4461 return States;
4462 end Collect_Body_States;
4464 ------------------------
4465 -- Collect_Interfaces --
4466 ------------------------
4468 procedure Collect_Interfaces
4469 (T : Entity_Id;
4470 Ifaces_List : out Elist_Id;
4471 Exclude_Parents : Boolean := False;
4472 Use_Full_View : Boolean := True)
4474 procedure Collect (Typ : Entity_Id);
4475 -- Subsidiary subprogram used to traverse the whole list
4476 -- of directly and indirectly implemented interfaces
4478 -------------
4479 -- Collect --
4480 -------------
4482 procedure Collect (Typ : Entity_Id) is
4483 Ancestor : Entity_Id;
4484 Full_T : Entity_Id;
4485 Id : Node_Id;
4486 Iface : Entity_Id;
4488 begin
4489 Full_T := Typ;
4491 -- Handle private types and subtypes
4493 if Use_Full_View
4494 and then Is_Private_Type (Typ)
4495 and then Present (Full_View (Typ))
4496 then
4497 Full_T := Full_View (Typ);
4499 if Ekind (Full_T) = E_Record_Subtype then
4500 Full_T := Etype (Typ);
4502 if Present (Full_View (Full_T)) then
4503 Full_T := Full_View (Full_T);
4504 end if;
4505 end if;
4506 end if;
4508 -- Include the ancestor if we are generating the whole list of
4509 -- abstract interfaces.
4511 if Etype (Full_T) /= Typ
4513 -- Protect the frontend against wrong sources. For example:
4515 -- package P is
4516 -- type A is tagged null record;
4517 -- type B is new A with private;
4518 -- type C is new A with private;
4519 -- private
4520 -- type B is new C with null record;
4521 -- type C is new B with null record;
4522 -- end P;
4524 and then Etype (Full_T) /= T
4525 then
4526 Ancestor := Etype (Full_T);
4527 Collect (Ancestor);
4529 if Is_Interface (Ancestor) and then not Exclude_Parents then
4530 Append_Unique_Elmt (Ancestor, Ifaces_List);
4531 end if;
4532 end if;
4534 -- Traverse the graph of ancestor interfaces
4536 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
4537 Id := First (Abstract_Interface_List (Full_T));
4538 while Present (Id) loop
4539 Iface := Etype (Id);
4541 -- Protect against wrong uses. For example:
4542 -- type I is interface;
4543 -- type O is tagged null record;
4544 -- type Wrong is new I and O with null record; -- ERROR
4546 if Is_Interface (Iface) then
4547 if Exclude_Parents
4548 and then Etype (T) /= T
4549 and then Interface_Present_In_Ancestor (Etype (T), Iface)
4550 then
4551 null;
4552 else
4553 Collect (Iface);
4554 Append_Unique_Elmt (Iface, Ifaces_List);
4555 end if;
4556 end if;
4558 Next (Id);
4559 end loop;
4560 end if;
4561 end Collect;
4563 -- Start of processing for Collect_Interfaces
4565 begin
4566 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
4567 Ifaces_List := New_Elmt_List;
4568 Collect (T);
4569 end Collect_Interfaces;
4571 ----------------------------------
4572 -- Collect_Interface_Components --
4573 ----------------------------------
4575 procedure Collect_Interface_Components
4576 (Tagged_Type : Entity_Id;
4577 Components_List : out Elist_Id)
4579 procedure Collect (Typ : Entity_Id);
4580 -- Subsidiary subprogram used to climb to the parents
4582 -------------
4583 -- Collect --
4584 -------------
4586 procedure Collect (Typ : Entity_Id) is
4587 Tag_Comp : Entity_Id;
4588 Parent_Typ : Entity_Id;
4590 begin
4591 -- Handle private types
4593 if Present (Full_View (Etype (Typ))) then
4594 Parent_Typ := Full_View (Etype (Typ));
4595 else
4596 Parent_Typ := Etype (Typ);
4597 end if;
4599 if Parent_Typ /= Typ
4601 -- Protect the frontend against wrong sources. For example:
4603 -- package P is
4604 -- type A is tagged null record;
4605 -- type B is new A with private;
4606 -- type C is new A with private;
4607 -- private
4608 -- type B is new C with null record;
4609 -- type C is new B with null record;
4610 -- end P;
4612 and then Parent_Typ /= Tagged_Type
4613 then
4614 Collect (Parent_Typ);
4615 end if;
4617 -- Collect the components containing tags of secondary dispatch
4618 -- tables.
4620 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
4621 while Present (Tag_Comp) loop
4622 pragma Assert (Present (Related_Type (Tag_Comp)));
4623 Append_Elmt (Tag_Comp, Components_List);
4625 Tag_Comp := Next_Tag_Component (Tag_Comp);
4626 end loop;
4627 end Collect;
4629 -- Start of processing for Collect_Interface_Components
4631 begin
4632 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
4633 and then Is_Tagged_Type (Tagged_Type));
4635 Components_List := New_Elmt_List;
4636 Collect (Tagged_Type);
4637 end Collect_Interface_Components;
4639 -----------------------------
4640 -- Collect_Interfaces_Info --
4641 -----------------------------
4643 procedure Collect_Interfaces_Info
4644 (T : Entity_Id;
4645 Ifaces_List : out Elist_Id;
4646 Components_List : out Elist_Id;
4647 Tags_List : out Elist_Id)
4649 Comps_List : Elist_Id;
4650 Comp_Elmt : Elmt_Id;
4651 Comp_Iface : Entity_Id;
4652 Iface_Elmt : Elmt_Id;
4653 Iface : Entity_Id;
4655 function Search_Tag (Iface : Entity_Id) return Entity_Id;
4656 -- Search for the secondary tag associated with the interface type
4657 -- Iface that is implemented by T.
4659 ----------------
4660 -- Search_Tag --
4661 ----------------
4663 function Search_Tag (Iface : Entity_Id) return Entity_Id is
4664 ADT : Elmt_Id;
4665 begin
4666 if not Is_CPP_Class (T) then
4667 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
4668 else
4669 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
4670 end if;
4672 while Present (ADT)
4673 and then Is_Tag (Node (ADT))
4674 and then Related_Type (Node (ADT)) /= Iface
4675 loop
4676 -- Skip secondary dispatch table referencing thunks to user
4677 -- defined primitives covered by this interface.
4679 pragma Assert (Has_Suffix (Node (ADT), 'P'));
4680 Next_Elmt (ADT);
4682 -- Skip secondary dispatch tables of Ada types
4684 if not Is_CPP_Class (T) then
4686 -- Skip secondary dispatch table referencing thunks to
4687 -- predefined primitives.
4689 pragma Assert (Has_Suffix (Node (ADT), 'Y'));
4690 Next_Elmt (ADT);
4692 -- Skip secondary dispatch table referencing user-defined
4693 -- primitives covered by this interface.
4695 pragma Assert (Has_Suffix (Node (ADT), 'D'));
4696 Next_Elmt (ADT);
4698 -- Skip secondary dispatch table referencing predefined
4699 -- primitives.
4701 pragma Assert (Has_Suffix (Node (ADT), 'Z'));
4702 Next_Elmt (ADT);
4703 end if;
4704 end loop;
4706 pragma Assert (Is_Tag (Node (ADT)));
4707 return Node (ADT);
4708 end Search_Tag;
4710 -- Start of processing for Collect_Interfaces_Info
4712 begin
4713 Collect_Interfaces (T, Ifaces_List);
4714 Collect_Interface_Components (T, Comps_List);
4716 -- Search for the record component and tag associated with each
4717 -- interface type of T.
4719 Components_List := New_Elmt_List;
4720 Tags_List := New_Elmt_List;
4722 Iface_Elmt := First_Elmt (Ifaces_List);
4723 while Present (Iface_Elmt) loop
4724 Iface := Node (Iface_Elmt);
4726 -- Associate the primary tag component and the primary dispatch table
4727 -- with all the interfaces that are parents of T
4729 if Is_Ancestor (Iface, T, Use_Full_View => True) then
4730 Append_Elmt (First_Tag_Component (T), Components_List);
4731 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
4733 -- Otherwise search for the tag component and secondary dispatch
4734 -- table of Iface
4736 else
4737 Comp_Elmt := First_Elmt (Comps_List);
4738 while Present (Comp_Elmt) loop
4739 Comp_Iface := Related_Type (Node (Comp_Elmt));
4741 if Comp_Iface = Iface
4742 or else Is_Ancestor (Iface, Comp_Iface, Use_Full_View => True)
4743 then
4744 Append_Elmt (Node (Comp_Elmt), Components_List);
4745 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
4746 exit;
4747 end if;
4749 Next_Elmt (Comp_Elmt);
4750 end loop;
4751 pragma Assert (Present (Comp_Elmt));
4752 end if;
4754 Next_Elmt (Iface_Elmt);
4755 end loop;
4756 end Collect_Interfaces_Info;
4758 ---------------------
4759 -- Collect_Parents --
4760 ---------------------
4762 procedure Collect_Parents
4763 (T : Entity_Id;
4764 List : out Elist_Id;
4765 Use_Full_View : Boolean := True)
4767 Current_Typ : Entity_Id := T;
4768 Parent_Typ : Entity_Id;
4770 begin
4771 List := New_Elmt_List;
4773 -- No action if the if the type has no parents
4775 if T = Etype (T) then
4776 return;
4777 end if;
4779 loop
4780 Parent_Typ := Etype (Current_Typ);
4782 if Is_Private_Type (Parent_Typ)
4783 and then Present (Full_View (Parent_Typ))
4784 and then Use_Full_View
4785 then
4786 Parent_Typ := Full_View (Base_Type (Parent_Typ));
4787 end if;
4789 Append_Elmt (Parent_Typ, List);
4791 exit when Parent_Typ = Current_Typ;
4792 Current_Typ := Parent_Typ;
4793 end loop;
4794 end Collect_Parents;
4796 ----------------------------------
4797 -- Collect_Primitive_Operations --
4798 ----------------------------------
4800 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
4801 B_Type : constant Entity_Id := Base_Type (T);
4802 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
4803 B_Scope : Entity_Id := Scope (B_Type);
4804 Op_List : Elist_Id;
4805 Formal : Entity_Id;
4806 Is_Prim : Boolean;
4807 Is_Type_In_Pkg : Boolean;
4808 Formal_Derived : Boolean := False;
4809 Id : Entity_Id;
4811 function Match (E : Entity_Id) return Boolean;
4812 -- True if E's base type is B_Type, or E is of an anonymous access type
4813 -- and the base type of its designated type is B_Type.
4815 -----------
4816 -- Match --
4817 -----------
4819 function Match (E : Entity_Id) return Boolean is
4820 Etyp : Entity_Id := Etype (E);
4822 begin
4823 if Ekind (Etyp) = E_Anonymous_Access_Type then
4824 Etyp := Designated_Type (Etyp);
4825 end if;
4827 -- In Ada 2012 a primitive operation may have a formal of an
4828 -- incomplete view of the parent type.
4830 return Base_Type (Etyp) = B_Type
4831 or else
4832 (Ada_Version >= Ada_2012
4833 and then Ekind (Etyp) = E_Incomplete_Type
4834 and then Full_View (Etyp) = B_Type);
4835 end Match;
4837 -- Start of processing for Collect_Primitive_Operations
4839 begin
4840 -- For tagged types, the primitive operations are collected as they
4841 -- are declared, and held in an explicit list which is simply returned.
4843 if Is_Tagged_Type (B_Type) then
4844 return Primitive_Operations (B_Type);
4846 -- An untagged generic type that is a derived type inherits the
4847 -- primitive operations of its parent type. Other formal types only
4848 -- have predefined operators, which are not explicitly represented.
4850 elsif Is_Generic_Type (B_Type) then
4851 if Nkind (B_Decl) = N_Formal_Type_Declaration
4852 and then Nkind (Formal_Type_Definition (B_Decl)) =
4853 N_Formal_Derived_Type_Definition
4854 then
4855 Formal_Derived := True;
4856 else
4857 return New_Elmt_List;
4858 end if;
4859 end if;
4861 Op_List := New_Elmt_List;
4863 if B_Scope = Standard_Standard then
4864 if B_Type = Standard_String then
4865 Append_Elmt (Standard_Op_Concat, Op_List);
4867 elsif B_Type = Standard_Wide_String then
4868 Append_Elmt (Standard_Op_Concatw, Op_List);
4870 else
4871 null;
4872 end if;
4874 -- Locate the primitive subprograms of the type
4876 else
4877 -- The primitive operations appear after the base type, except
4878 -- if the derivation happens within the private part of B_Scope
4879 -- and the type is a private type, in which case both the type
4880 -- and some primitive operations may appear before the base
4881 -- type, and the list of candidates starts after the type.
4883 if In_Open_Scopes (B_Scope)
4884 and then Scope (T) = B_Scope
4885 and then In_Private_Part (B_Scope)
4886 then
4887 Id := Next_Entity (T);
4889 -- In Ada 2012, If the type has an incomplete partial view, there
4890 -- may be primitive operations declared before the full view, so
4891 -- we need to start scanning from the incomplete view, which is
4892 -- earlier on the entity chain.
4894 elsif Nkind (Parent (B_Type)) = N_Full_Type_Declaration
4895 and then Present (Incomplete_View (Parent (B_Type)))
4896 then
4897 Id := Defining_Entity (Incomplete_View (Parent (B_Type)));
4899 -- If T is a derived from a type with an incomplete view declared
4900 -- elsewhere, that incomplete view is irrelevant, we want the
4901 -- operations in the scope of T.
4903 if Scope (Id) /= Scope (B_Type) then
4904 Id := Next_Entity (B_Type);
4905 end if;
4907 else
4908 Id := Next_Entity (B_Type);
4909 end if;
4911 -- Set flag if this is a type in a package spec
4913 Is_Type_In_Pkg :=
4914 Is_Package_Or_Generic_Package (B_Scope)
4915 and then
4916 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
4917 N_Package_Body;
4919 while Present (Id) loop
4921 -- Test whether the result type or any of the parameter types of
4922 -- each subprogram following the type match that type when the
4923 -- type is declared in a package spec, is a derived type, or the
4924 -- subprogram is marked as primitive. (The Is_Primitive test is
4925 -- needed to find primitives of nonderived types in declarative
4926 -- parts that happen to override the predefined "=" operator.)
4928 -- Note that generic formal subprograms are not considered to be
4929 -- primitive operations and thus are never inherited.
4931 if Is_Overloadable (Id)
4932 and then (Is_Type_In_Pkg
4933 or else Is_Derived_Type (B_Type)
4934 or else Is_Primitive (Id))
4935 and then Nkind (Parent (Parent (Id)))
4936 not in N_Formal_Subprogram_Declaration
4937 then
4938 Is_Prim := False;
4940 if Match (Id) then
4941 Is_Prim := True;
4943 else
4944 Formal := First_Formal (Id);
4945 while Present (Formal) loop
4946 if Match (Formal) then
4947 Is_Prim := True;
4948 exit;
4949 end if;
4951 Next_Formal (Formal);
4952 end loop;
4953 end if;
4955 -- For a formal derived type, the only primitives are the ones
4956 -- inherited from the parent type. Operations appearing in the
4957 -- package declaration are not primitive for it.
4959 if Is_Prim
4960 and then (not Formal_Derived or else Present (Alias (Id)))
4961 then
4962 -- In the special case of an equality operator aliased to
4963 -- an overriding dispatching equality belonging to the same
4964 -- type, we don't include it in the list of primitives.
4965 -- This avoids inheriting multiple equality operators when
4966 -- deriving from untagged private types whose full type is
4967 -- tagged, which can otherwise cause ambiguities. Note that
4968 -- this should only happen for this kind of untagged parent
4969 -- type, since normally dispatching operations are inherited
4970 -- using the type's Primitive_Operations list.
4972 if Chars (Id) = Name_Op_Eq
4973 and then Is_Dispatching_Operation (Id)
4974 and then Present (Alias (Id))
4975 and then Present (Overridden_Operation (Alias (Id)))
4976 and then Base_Type (Etype (First_Entity (Id))) =
4977 Base_Type (Etype (First_Entity (Alias (Id))))
4978 then
4979 null;
4981 -- Include the subprogram in the list of primitives
4983 else
4984 Append_Elmt (Id, Op_List);
4985 end if;
4986 end if;
4987 end if;
4989 Next_Entity (Id);
4991 -- For a type declared in System, some of its operations may
4992 -- appear in the target-specific extension to System.
4994 if No (Id)
4995 and then B_Scope = RTU_Entity (System)
4996 and then Present_System_Aux
4997 then
4998 B_Scope := System_Aux_Id;
4999 Id := First_Entity (System_Aux_Id);
5000 end if;
5001 end loop;
5002 end if;
5004 return Op_List;
5005 end Collect_Primitive_Operations;
5007 -----------------------------------
5008 -- Compile_Time_Constraint_Error --
5009 -----------------------------------
5011 function Compile_Time_Constraint_Error
5012 (N : Node_Id;
5013 Msg : String;
5014 Ent : Entity_Id := Empty;
5015 Loc : Source_Ptr := No_Location;
5016 Warn : Boolean := False) return Node_Id
5018 Msgc : String (1 .. Msg'Length + 3);
5019 -- Copy of message, with room for possible ?? or << and ! at end
5021 Msgl : Natural;
5022 Wmsg : Boolean;
5023 Eloc : Source_Ptr;
5025 -- Start of processing for Compile_Time_Constraint_Error
5027 begin
5028 -- If this is a warning, convert it into an error if we are in code
5029 -- subject to SPARK_Mode being set On, unless Warn is True to force a
5030 -- warning. The rationale is that a compile-time constraint error should
5031 -- lead to an error instead of a warning when SPARK_Mode is On, but in
5032 -- a few cases we prefer to issue a warning and generate both a suitable
5033 -- run-time error in GNAT and a suitable check message in GNATprove.
5034 -- Those cases are those that likely correspond to deactivated SPARK
5035 -- code, so that this kind of code can be compiled and analyzed instead
5036 -- of being rejected.
5038 Error_Msg_Warn := Warn or SPARK_Mode /= On;
5040 -- A static constraint error in an instance body is not a fatal error.
5041 -- we choose to inhibit the message altogether, because there is no
5042 -- obvious node (for now) on which to post it. On the other hand the
5043 -- offending node must be replaced with a constraint_error in any case.
5045 -- No messages are generated if we already posted an error on this node
5047 if not Error_Posted (N) then
5048 if Loc /= No_Location then
5049 Eloc := Loc;
5050 else
5051 Eloc := Sloc (N);
5052 end if;
5054 -- Copy message to Msgc, converting any ? in the message into <
5055 -- instead, so that we have an error in GNATprove mode.
5057 Msgl := Msg'Length;
5059 for J in 1 .. Msgl loop
5060 if Msg (J) = '?' and then (J = 1 or else Msg (J - 1) /= ''') then
5061 Msgc (J) := '<';
5062 else
5063 Msgc (J) := Msg (J);
5064 end if;
5065 end loop;
5067 -- Message is a warning, even in Ada 95 case
5069 if Msg (Msg'Last) = '?' or else Msg (Msg'Last) = '<' then
5070 Wmsg := True;
5072 -- In Ada 83, all messages are warnings. In the private part and the
5073 -- body of an instance, constraint_checks are only warnings. We also
5074 -- make this a warning if the Warn parameter is set.
5076 elsif Warn
5077 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
5078 or else In_Instance_Not_Visible
5079 then
5080 Msgl := Msgl + 1;
5081 Msgc (Msgl) := '<';
5082 Msgl := Msgl + 1;
5083 Msgc (Msgl) := '<';
5084 Wmsg := True;
5086 -- Otherwise we have a real error message (Ada 95 static case) and we
5087 -- make this an unconditional message. Note that in the warning case
5088 -- we do not make the message unconditional, it seems reasonable to
5089 -- delete messages like this (about exceptions that will be raised)
5090 -- in dead code.
5092 else
5093 Wmsg := False;
5094 Msgl := Msgl + 1;
5095 Msgc (Msgl) := '!';
5096 end if;
5098 -- One more test, skip the warning if the related expression is
5099 -- statically unevaluated, since we don't want to warn about what
5100 -- will happen when something is evaluated if it never will be
5101 -- evaluated.
5103 if not Is_Statically_Unevaluated (N) then
5104 if Present (Ent) then
5105 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
5106 else
5107 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
5108 end if;
5110 if Wmsg then
5112 -- Check whether the context is an Init_Proc
5114 if Inside_Init_Proc then
5115 declare
5116 Conc_Typ : constant Entity_Id :=
5117 Corresponding_Concurrent_Type
5118 (Entity (Parameter_Type (First
5119 (Parameter_Specifications
5120 (Parent (Current_Scope))))));
5122 begin
5123 -- Don't complain if the corresponding concurrent type
5124 -- doesn't come from source (i.e. a single task/protected
5125 -- object).
5127 if Present (Conc_Typ)
5128 and then not Comes_From_Source (Conc_Typ)
5129 then
5130 Error_Msg_NEL
5131 ("\& [<<", N, Standard_Constraint_Error, Eloc);
5133 else
5134 if GNATprove_Mode then
5135 Error_Msg_NEL
5136 ("\& would have been raised for objects of this "
5137 & "type", N, Standard_Constraint_Error, Eloc);
5138 else
5139 Error_Msg_NEL
5140 ("\& will be raised for objects of this type??",
5141 N, Standard_Constraint_Error, Eloc);
5142 end if;
5143 end if;
5144 end;
5146 else
5147 Error_Msg_NEL ("\& [<<", N, Standard_Constraint_Error, Eloc);
5148 end if;
5150 else
5151 Error_Msg ("\static expression fails Constraint_Check", Eloc);
5152 Set_Error_Posted (N);
5153 end if;
5154 end if;
5155 end if;
5157 return N;
5158 end Compile_Time_Constraint_Error;
5160 -----------------------
5161 -- Conditional_Delay --
5162 -----------------------
5164 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
5165 begin
5166 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
5167 Set_Has_Delayed_Freeze (New_Ent);
5168 end if;
5169 end Conditional_Delay;
5171 ----------------------------
5172 -- Contains_Refined_State --
5173 ----------------------------
5175 function Contains_Refined_State (Prag : Node_Id) return Boolean is
5176 function Has_State_In_Dependency (List : Node_Id) return Boolean;
5177 -- Determine whether a dependency list mentions a state with a visible
5178 -- refinement.
5180 function Has_State_In_Global (List : Node_Id) return Boolean;
5181 -- Determine whether a global list mentions a state with a visible
5182 -- refinement.
5184 function Is_Refined_State (Item : Node_Id) return Boolean;
5185 -- Determine whether Item is a reference to an abstract state with a
5186 -- visible refinement.
5188 -----------------------------
5189 -- Has_State_In_Dependency --
5190 -----------------------------
5192 function Has_State_In_Dependency (List : Node_Id) return Boolean is
5193 Clause : Node_Id;
5194 Output : Node_Id;
5196 begin
5197 -- A null dependency list does not mention any states
5199 if Nkind (List) = N_Null then
5200 return False;
5202 -- Dependency clauses appear as component associations of an
5203 -- aggregate.
5205 elsif Nkind (List) = N_Aggregate
5206 and then Present (Component_Associations (List))
5207 then
5208 Clause := First (Component_Associations (List));
5209 while Present (Clause) loop
5211 -- Inspect the outputs of a dependency clause
5213 Output := First (Choices (Clause));
5214 while Present (Output) loop
5215 if Is_Refined_State (Output) then
5216 return True;
5217 end if;
5219 Next (Output);
5220 end loop;
5222 -- Inspect the outputs of a dependency clause
5224 if Is_Refined_State (Expression (Clause)) then
5225 return True;
5226 end if;
5228 Next (Clause);
5229 end loop;
5231 -- If we get here, then none of the dependency clauses mention a
5232 -- state with visible refinement.
5234 return False;
5236 -- An illegal pragma managed to sneak in
5238 else
5239 raise Program_Error;
5240 end if;
5241 end Has_State_In_Dependency;
5243 -------------------------
5244 -- Has_State_In_Global --
5245 -------------------------
5247 function Has_State_In_Global (List : Node_Id) return Boolean is
5248 Item : Node_Id;
5250 begin
5251 -- A null global list does not mention any states
5253 if Nkind (List) = N_Null then
5254 return False;
5256 -- Simple global list or moded global list declaration
5258 elsif Nkind (List) = N_Aggregate then
5260 -- The declaration of a simple global list appear as a collection
5261 -- of expressions.
5263 if Present (Expressions (List)) then
5264 Item := First (Expressions (List));
5265 while Present (Item) loop
5266 if Is_Refined_State (Item) then
5267 return True;
5268 end if;
5270 Next (Item);
5271 end loop;
5273 -- The declaration of a moded global list appears as a collection
5274 -- of component associations where individual choices denote
5275 -- modes.
5277 else
5278 Item := First (Component_Associations (List));
5279 while Present (Item) loop
5280 if Has_State_In_Global (Expression (Item)) then
5281 return True;
5282 end if;
5284 Next (Item);
5285 end loop;
5286 end if;
5288 -- If we get here, then the simple/moded global list did not
5289 -- mention any states with a visible refinement.
5291 return False;
5293 -- Single global item declaration
5295 elsif Is_Entity_Name (List) then
5296 return Is_Refined_State (List);
5298 -- An illegal pragma managed to sneak in
5300 else
5301 raise Program_Error;
5302 end if;
5303 end Has_State_In_Global;
5305 ----------------------
5306 -- Is_Refined_State --
5307 ----------------------
5309 function Is_Refined_State (Item : Node_Id) return Boolean is
5310 Elmt : Node_Id;
5311 Item_Id : Entity_Id;
5313 begin
5314 if Nkind (Item) = N_Null then
5315 return False;
5317 -- States cannot be subject to attribute 'Result. This case arises
5318 -- in dependency relations.
5320 elsif Nkind (Item) = N_Attribute_Reference
5321 and then Attribute_Name (Item) = Name_Result
5322 then
5323 return False;
5325 -- Multiple items appear as an aggregate. This case arises in
5326 -- dependency relations.
5328 elsif Nkind (Item) = N_Aggregate
5329 and then Present (Expressions (Item))
5330 then
5331 Elmt := First (Expressions (Item));
5332 while Present (Elmt) loop
5333 if Is_Refined_State (Elmt) then
5334 return True;
5335 end if;
5337 Next (Elmt);
5338 end loop;
5340 -- If we get here, then none of the inputs or outputs reference a
5341 -- state with visible refinement.
5343 return False;
5345 -- Single item
5347 else
5348 Item_Id := Entity_Of (Item);
5350 return
5351 Present (Item_Id)
5352 and then Ekind (Item_Id) = E_Abstract_State
5353 and then Has_Visible_Refinement (Item_Id);
5354 end if;
5355 end Is_Refined_State;
5357 -- Local variables
5359 Arg : constant Node_Id :=
5360 Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
5361 Nam : constant Name_Id := Pragma_Name (Prag);
5363 -- Start of processing for Contains_Refined_State
5365 begin
5366 if Nam = Name_Depends then
5367 return Has_State_In_Dependency (Arg);
5369 else pragma Assert (Nam = Name_Global);
5370 return Has_State_In_Global (Arg);
5371 end if;
5372 end Contains_Refined_State;
5374 -------------------------
5375 -- Copy_Component_List --
5376 -------------------------
5378 function Copy_Component_List
5379 (R_Typ : Entity_Id;
5380 Loc : Source_Ptr) return List_Id
5382 Comp : Node_Id;
5383 Comps : constant List_Id := New_List;
5385 begin
5386 Comp := First_Component (Underlying_Type (R_Typ));
5387 while Present (Comp) loop
5388 if Comes_From_Source (Comp) then
5389 declare
5390 Comp_Decl : constant Node_Id := Declaration_Node (Comp);
5391 begin
5392 Append_To (Comps,
5393 Make_Component_Declaration (Loc,
5394 Defining_Identifier =>
5395 Make_Defining_Identifier (Loc, Chars (Comp)),
5396 Component_Definition =>
5397 New_Copy_Tree
5398 (Component_Definition (Comp_Decl), New_Sloc => Loc)));
5399 end;
5400 end if;
5402 Next_Component (Comp);
5403 end loop;
5405 return Comps;
5406 end Copy_Component_List;
5408 -------------------------
5409 -- Copy_Parameter_List --
5410 -------------------------
5412 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
5413 Loc : constant Source_Ptr := Sloc (Subp_Id);
5414 Plist : List_Id;
5415 Formal : Entity_Id;
5417 begin
5418 if No (First_Formal (Subp_Id)) then
5419 return No_List;
5420 else
5421 Plist := New_List;
5422 Formal := First_Formal (Subp_Id);
5423 while Present (Formal) loop
5424 Append_To (Plist,
5425 Make_Parameter_Specification (Loc,
5426 Defining_Identifier =>
5427 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)),
5428 In_Present => In_Present (Parent (Formal)),
5429 Out_Present => Out_Present (Parent (Formal)),
5430 Parameter_Type =>
5431 New_Occurrence_Of (Etype (Formal), Loc),
5432 Expression =>
5433 New_Copy_Tree (Expression (Parent (Formal)))));
5435 Next_Formal (Formal);
5436 end loop;
5437 end if;
5439 return Plist;
5440 end Copy_Parameter_List;
5442 ----------------------------
5443 -- Copy_SPARK_Mode_Aspect --
5444 ----------------------------
5446 procedure Copy_SPARK_Mode_Aspect (From : Node_Id; To : Node_Id) is
5447 pragma Assert (not Has_Aspects (To));
5448 Asp : Node_Id;
5450 begin
5451 if Has_Aspects (From) then
5452 Asp := Find_Aspect (Defining_Entity (From), Aspect_SPARK_Mode);
5454 if Present (Asp) then
5455 Set_Aspect_Specifications (To, New_List (New_Copy_Tree (Asp)));
5456 Set_Has_Aspects (To, True);
5457 end if;
5458 end if;
5459 end Copy_SPARK_Mode_Aspect;
5461 --------------------------
5462 -- Copy_Subprogram_Spec --
5463 --------------------------
5465 function Copy_Subprogram_Spec (Spec : Node_Id) return Node_Id is
5466 Def_Id : Node_Id;
5467 Formal_Spec : Node_Id;
5468 Result : Node_Id;
5470 begin
5471 -- The structure of the original tree must be replicated without any
5472 -- alterations. Use New_Copy_Tree for this purpose.
5474 Result := New_Copy_Tree (Spec);
5476 -- However, the spec of a null procedure carries the corresponding null
5477 -- statement of the body (created by the parser), and this cannot be
5478 -- shared with the new subprogram spec.
5480 if Nkind (Result) = N_Procedure_Specification then
5481 Set_Null_Statement (Result, Empty);
5482 end if;
5484 -- Create a new entity for the defining unit name
5486 Def_Id := Defining_Unit_Name (Result);
5487 Set_Defining_Unit_Name (Result,
5488 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
5490 -- Create new entities for the formal parameters
5492 if Present (Parameter_Specifications (Result)) then
5493 Formal_Spec := First (Parameter_Specifications (Result));
5494 while Present (Formal_Spec) loop
5495 Def_Id := Defining_Identifier (Formal_Spec);
5496 Set_Defining_Identifier (Formal_Spec,
5497 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
5499 Next (Formal_Spec);
5500 end loop;
5501 end if;
5503 return Result;
5504 end Copy_Subprogram_Spec;
5506 --------------------------------
5507 -- Corresponding_Generic_Type --
5508 --------------------------------
5510 function Corresponding_Generic_Type (T : Entity_Id) return Entity_Id is
5511 Inst : Entity_Id;
5512 Gen : Entity_Id;
5513 Typ : Entity_Id;
5515 begin
5516 if not Is_Generic_Actual_Type (T) then
5517 return Any_Type;
5519 -- If the actual is the actual of an enclosing instance, resolution
5520 -- was correct in the generic.
5522 elsif Nkind (Parent (T)) = N_Subtype_Declaration
5523 and then Is_Entity_Name (Subtype_Indication (Parent (T)))
5524 and then
5525 Is_Generic_Actual_Type (Entity (Subtype_Indication (Parent (T))))
5526 then
5527 return Any_Type;
5529 else
5530 Inst := Scope (T);
5532 if Is_Wrapper_Package (Inst) then
5533 Inst := Related_Instance (Inst);
5534 end if;
5536 Gen :=
5537 Generic_Parent
5538 (Specification (Unit_Declaration_Node (Inst)));
5540 -- Generic actual has the same name as the corresponding formal
5542 Typ := First_Entity (Gen);
5543 while Present (Typ) loop
5544 if Chars (Typ) = Chars (T) then
5545 return Typ;
5546 end if;
5548 Next_Entity (Typ);
5549 end loop;
5551 return Any_Type;
5552 end if;
5553 end Corresponding_Generic_Type;
5555 --------------------
5556 -- Current_Entity --
5557 --------------------
5559 -- The currently visible definition for a given identifier is the
5560 -- one most chained at the start of the visibility chain, i.e. the
5561 -- one that is referenced by the Node_Id value of the name of the
5562 -- given identifier.
5564 function Current_Entity (N : Node_Id) return Entity_Id is
5565 begin
5566 return Get_Name_Entity_Id (Chars (N));
5567 end Current_Entity;
5569 -----------------------------
5570 -- Current_Entity_In_Scope --
5571 -----------------------------
5573 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
5574 E : Entity_Id;
5575 CS : constant Entity_Id := Current_Scope;
5577 Transient_Case : constant Boolean := Scope_Is_Transient;
5579 begin
5580 E := Get_Name_Entity_Id (Chars (N));
5581 while Present (E)
5582 and then Scope (E) /= CS
5583 and then (not Transient_Case or else Scope (E) /= Scope (CS))
5584 loop
5585 E := Homonym (E);
5586 end loop;
5588 return E;
5589 end Current_Entity_In_Scope;
5591 -------------------
5592 -- Current_Scope --
5593 -------------------
5595 function Current_Scope return Entity_Id is
5596 begin
5597 if Scope_Stack.Last = -1 then
5598 return Standard_Standard;
5599 else
5600 declare
5601 C : constant Entity_Id :=
5602 Scope_Stack.Table (Scope_Stack.Last).Entity;
5603 begin
5604 if Present (C) then
5605 return C;
5606 else
5607 return Standard_Standard;
5608 end if;
5609 end;
5610 end if;
5611 end Current_Scope;
5613 ----------------------------
5614 -- Current_Scope_No_Loops --
5615 ----------------------------
5617 function Current_Scope_No_Loops return Entity_Id is
5618 S : Entity_Id;
5620 begin
5621 -- Examine the scope stack starting from the current scope and skip any
5622 -- internally generated loops.
5624 S := Current_Scope;
5625 while Present (S) and then S /= Standard_Standard loop
5626 if Ekind (S) = E_Loop and then not Comes_From_Source (S) then
5627 S := Scope (S);
5628 else
5629 exit;
5630 end if;
5631 end loop;
5633 return S;
5634 end Current_Scope_No_Loops;
5636 ------------------------
5637 -- Current_Subprogram --
5638 ------------------------
5640 function Current_Subprogram return Entity_Id is
5641 Scop : constant Entity_Id := Current_Scope;
5642 begin
5643 if Is_Subprogram_Or_Generic_Subprogram (Scop) then
5644 return Scop;
5645 else
5646 return Enclosing_Subprogram (Scop);
5647 end if;
5648 end Current_Subprogram;
5650 ----------------------------------
5651 -- Deepest_Type_Access_Level --
5652 ----------------------------------
5654 function Deepest_Type_Access_Level (Typ : Entity_Id) return Uint is
5655 begin
5656 if Ekind (Typ) = E_Anonymous_Access_Type
5657 and then not Is_Local_Anonymous_Access (Typ)
5658 and then Nkind (Associated_Node_For_Itype (Typ)) = N_Object_Declaration
5659 then
5660 -- Typ is the type of an Ada 2012 stand-alone object of an anonymous
5661 -- access type.
5663 return
5664 Scope_Depth (Enclosing_Dynamic_Scope
5665 (Defining_Identifier
5666 (Associated_Node_For_Itype (Typ))));
5668 -- For generic formal type, return Int'Last (infinite).
5669 -- See comment preceding Is_Generic_Type call in Type_Access_Level.
5671 elsif Is_Generic_Type (Root_Type (Typ)) then
5672 return UI_From_Int (Int'Last);
5674 else
5675 return Type_Access_Level (Typ);
5676 end if;
5677 end Deepest_Type_Access_Level;
5679 ---------------------
5680 -- Defining_Entity --
5681 ---------------------
5683 function Defining_Entity
5684 (N : Node_Id;
5685 Empty_On_Errors : Boolean := False) return Entity_Id
5687 Err : Entity_Id := Empty;
5689 begin
5690 case Nkind (N) is
5691 when N_Abstract_Subprogram_Declaration
5692 | N_Expression_Function
5693 | N_Formal_Subprogram_Declaration
5694 | N_Generic_Package_Declaration
5695 | N_Generic_Subprogram_Declaration
5696 | N_Package_Declaration
5697 | N_Subprogram_Body
5698 | N_Subprogram_Body_Stub
5699 | N_Subprogram_Declaration
5700 | N_Subprogram_Renaming_Declaration
5702 return Defining_Entity (Specification (N));
5704 when N_Component_Declaration
5705 | N_Defining_Program_Unit_Name
5706 | N_Discriminant_Specification
5707 | N_Entry_Body
5708 | N_Entry_Declaration
5709 | N_Entry_Index_Specification
5710 | N_Exception_Declaration
5711 | N_Exception_Renaming_Declaration
5712 | N_Formal_Object_Declaration
5713 | N_Formal_Package_Declaration
5714 | N_Formal_Type_Declaration
5715 | N_Full_Type_Declaration
5716 | N_Implicit_Label_Declaration
5717 | N_Incomplete_Type_Declaration
5718 | N_Iterator_Specification
5719 | N_Loop_Parameter_Specification
5720 | N_Number_Declaration
5721 | N_Object_Declaration
5722 | N_Object_Renaming_Declaration
5723 | N_Package_Body_Stub
5724 | N_Parameter_Specification
5725 | N_Private_Extension_Declaration
5726 | N_Private_Type_Declaration
5727 | N_Protected_Body
5728 | N_Protected_Body_Stub
5729 | N_Protected_Type_Declaration
5730 | N_Single_Protected_Declaration
5731 | N_Single_Task_Declaration
5732 | N_Subtype_Declaration
5733 | N_Task_Body
5734 | N_Task_Body_Stub
5735 | N_Task_Type_Declaration
5737 return Defining_Identifier (N);
5739 when N_Subunit =>
5740 return Defining_Entity (Proper_Body (N));
5742 when N_Function_Instantiation
5743 | N_Function_Specification
5744 | N_Generic_Function_Renaming_Declaration
5745 | N_Generic_Package_Renaming_Declaration
5746 | N_Generic_Procedure_Renaming_Declaration
5747 | N_Package_Body
5748 | N_Package_Instantiation
5749 | N_Package_Renaming_Declaration
5750 | N_Package_Specification
5751 | N_Procedure_Instantiation
5752 | N_Procedure_Specification
5754 declare
5755 Nam : constant Node_Id := Defining_Unit_Name (N);
5757 begin
5758 if Nkind (Nam) in N_Entity then
5759 return Nam;
5761 -- For Error, make up a name and attach to declaration so we
5762 -- can continue semantic analysis.
5764 elsif Nam = Error then
5765 if Empty_On_Errors then
5766 return Empty;
5767 else
5768 Err := Make_Temporary (Sloc (N), 'T');
5769 Set_Defining_Unit_Name (N, Err);
5771 return Err;
5772 end if;
5774 -- If not an entity, get defining identifier
5776 else
5777 return Defining_Identifier (Nam);
5778 end if;
5779 end;
5781 when N_Block_Statement
5782 | N_Loop_Statement
5784 return Entity (Identifier (N));
5786 when others =>
5787 if Empty_On_Errors then
5788 return Empty;
5789 else
5790 raise Program_Error;
5791 end if;
5792 end case;
5793 end Defining_Entity;
5795 --------------------------
5796 -- Denotes_Discriminant --
5797 --------------------------
5799 function Denotes_Discriminant
5800 (N : Node_Id;
5801 Check_Concurrent : Boolean := False) return Boolean
5803 E : Entity_Id;
5805 begin
5806 if not Is_Entity_Name (N) or else No (Entity (N)) then
5807 return False;
5808 else
5809 E := Entity (N);
5810 end if;
5812 -- If we are checking for a protected type, the discriminant may have
5813 -- been rewritten as the corresponding discriminal of the original type
5814 -- or of the corresponding concurrent record, depending on whether we
5815 -- are in the spec or body of the protected type.
5817 return Ekind (E) = E_Discriminant
5818 or else
5819 (Check_Concurrent
5820 and then Ekind (E) = E_In_Parameter
5821 and then Present (Discriminal_Link (E))
5822 and then
5823 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
5824 or else
5825 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
5826 end Denotes_Discriminant;
5828 -------------------------
5829 -- Denotes_Same_Object --
5830 -------------------------
5832 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
5833 Obj1 : Node_Id := A1;
5834 Obj2 : Node_Id := A2;
5836 function Has_Prefix (N : Node_Id) return Boolean;
5837 -- Return True if N has attribute Prefix
5839 function Is_Renaming (N : Node_Id) return Boolean;
5840 -- Return true if N names a renaming entity
5842 function Is_Valid_Renaming (N : Node_Id) return Boolean;
5843 -- For renamings, return False if the prefix of any dereference within
5844 -- the renamed object_name is a variable, or any expression within the
5845 -- renamed object_name contains references to variables or calls on
5846 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
5848 ----------------
5849 -- Has_Prefix --
5850 ----------------
5852 function Has_Prefix (N : Node_Id) return Boolean is
5853 begin
5854 return
5855 Nkind_In (N,
5856 N_Attribute_Reference,
5857 N_Expanded_Name,
5858 N_Explicit_Dereference,
5859 N_Indexed_Component,
5860 N_Reference,
5861 N_Selected_Component,
5862 N_Slice);
5863 end Has_Prefix;
5865 -----------------
5866 -- Is_Renaming --
5867 -----------------
5869 function Is_Renaming (N : Node_Id) return Boolean is
5870 begin
5871 return Is_Entity_Name (N)
5872 and then Present (Renamed_Entity (Entity (N)));
5873 end Is_Renaming;
5875 -----------------------
5876 -- Is_Valid_Renaming --
5877 -----------------------
5879 function Is_Valid_Renaming (N : Node_Id) return Boolean is
5881 function Check_Renaming (N : Node_Id) return Boolean;
5882 -- Recursive function used to traverse all the prefixes of N
5884 function Check_Renaming (N : Node_Id) return Boolean is
5885 begin
5886 if Is_Renaming (N)
5887 and then not Check_Renaming (Renamed_Entity (Entity (N)))
5888 then
5889 return False;
5890 end if;
5892 if Nkind (N) = N_Indexed_Component then
5893 declare
5894 Indx : Node_Id;
5896 begin
5897 Indx := First (Expressions (N));
5898 while Present (Indx) loop
5899 if not Is_OK_Static_Expression (Indx) then
5900 return False;
5901 end if;
5903 Next_Index (Indx);
5904 end loop;
5905 end;
5906 end if;
5908 if Has_Prefix (N) then
5909 declare
5910 P : constant Node_Id := Prefix (N);
5912 begin
5913 if Nkind (N) = N_Explicit_Dereference
5914 and then Is_Variable (P)
5915 then
5916 return False;
5918 elsif Is_Entity_Name (P)
5919 and then Ekind (Entity (P)) = E_Function
5920 then
5921 return False;
5923 elsif Nkind (P) = N_Function_Call then
5924 return False;
5925 end if;
5927 -- Recursion to continue traversing the prefix of the
5928 -- renaming expression
5930 return Check_Renaming (P);
5931 end;
5932 end if;
5934 return True;
5935 end Check_Renaming;
5937 -- Start of processing for Is_Valid_Renaming
5939 begin
5940 return Check_Renaming (N);
5941 end Is_Valid_Renaming;
5943 -- Start of processing for Denotes_Same_Object
5945 begin
5946 -- Both names statically denote the same stand-alone object or parameter
5947 -- (RM 6.4.1(6.5/3))
5949 if Is_Entity_Name (Obj1)
5950 and then Is_Entity_Name (Obj2)
5951 and then Entity (Obj1) = Entity (Obj2)
5952 then
5953 return True;
5954 end if;
5956 -- For renamings, the prefix of any dereference within the renamed
5957 -- object_name is not a variable, and any expression within the
5958 -- renamed object_name contains no references to variables nor
5959 -- calls on nonstatic functions (RM 6.4.1(6.10/3)).
5961 if Is_Renaming (Obj1) then
5962 if Is_Valid_Renaming (Obj1) then
5963 Obj1 := Renamed_Entity (Entity (Obj1));
5964 else
5965 return False;
5966 end if;
5967 end if;
5969 if Is_Renaming (Obj2) then
5970 if Is_Valid_Renaming (Obj2) then
5971 Obj2 := Renamed_Entity (Entity (Obj2));
5972 else
5973 return False;
5974 end if;
5975 end if;
5977 -- No match if not same node kind (such cases are handled by
5978 -- Denotes_Same_Prefix)
5980 if Nkind (Obj1) /= Nkind (Obj2) then
5981 return False;
5983 -- After handling valid renamings, one of the two names statically
5984 -- denoted a renaming declaration whose renamed object_name is known
5985 -- to denote the same object as the other (RM 6.4.1(6.10/3))
5987 elsif Is_Entity_Name (Obj1) then
5988 if Is_Entity_Name (Obj2) then
5989 return Entity (Obj1) = Entity (Obj2);
5990 else
5991 return False;
5992 end if;
5994 -- Both names are selected_components, their prefixes are known to
5995 -- denote the same object, and their selector_names denote the same
5996 -- component (RM 6.4.1(6.6/3)).
5998 elsif Nkind (Obj1) = N_Selected_Component then
5999 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
6000 and then
6001 Entity (Selector_Name (Obj1)) = Entity (Selector_Name (Obj2));
6003 -- Both names are dereferences and the dereferenced names are known to
6004 -- denote the same object (RM 6.4.1(6.7/3))
6006 elsif Nkind (Obj1) = N_Explicit_Dereference then
6007 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2));
6009 -- Both names are indexed_components, their prefixes are known to denote
6010 -- the same object, and each of the pairs of corresponding index values
6011 -- are either both static expressions with the same static value or both
6012 -- names that are known to denote the same object (RM 6.4.1(6.8/3))
6014 elsif Nkind (Obj1) = N_Indexed_Component then
6015 if not Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2)) then
6016 return False;
6017 else
6018 declare
6019 Indx1 : Node_Id;
6020 Indx2 : Node_Id;
6022 begin
6023 Indx1 := First (Expressions (Obj1));
6024 Indx2 := First (Expressions (Obj2));
6025 while Present (Indx1) loop
6027 -- Indexes must denote the same static value or same object
6029 if Is_OK_Static_Expression (Indx1) then
6030 if not Is_OK_Static_Expression (Indx2) then
6031 return False;
6033 elsif Expr_Value (Indx1) /= Expr_Value (Indx2) then
6034 return False;
6035 end if;
6037 elsif not Denotes_Same_Object (Indx1, Indx2) then
6038 return False;
6039 end if;
6041 Next (Indx1);
6042 Next (Indx2);
6043 end loop;
6045 return True;
6046 end;
6047 end if;
6049 -- Both names are slices, their prefixes are known to denote the same
6050 -- object, and the two slices have statically matching index constraints
6051 -- (RM 6.4.1(6.9/3))
6053 elsif Nkind (Obj1) = N_Slice
6054 and then Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
6055 then
6056 declare
6057 Lo1, Lo2, Hi1, Hi2 : Node_Id;
6059 begin
6060 Get_Index_Bounds (Etype (Obj1), Lo1, Hi1);
6061 Get_Index_Bounds (Etype (Obj2), Lo2, Hi2);
6063 -- Check whether bounds are statically identical. There is no
6064 -- attempt to detect partial overlap of slices.
6066 return Denotes_Same_Object (Lo1, Lo2)
6067 and then
6068 Denotes_Same_Object (Hi1, Hi2);
6069 end;
6071 -- In the recursion, literals appear as indexes
6073 elsif Nkind (Obj1) = N_Integer_Literal
6074 and then
6075 Nkind (Obj2) = N_Integer_Literal
6076 then
6077 return Intval (Obj1) = Intval (Obj2);
6079 else
6080 return False;
6081 end if;
6082 end Denotes_Same_Object;
6084 -------------------------
6085 -- Denotes_Same_Prefix --
6086 -------------------------
6088 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
6089 begin
6090 if Is_Entity_Name (A1) then
6091 if Nkind_In (A2, N_Selected_Component, N_Indexed_Component)
6092 and then not Is_Access_Type (Etype (A1))
6093 then
6094 return Denotes_Same_Object (A1, Prefix (A2))
6095 or else Denotes_Same_Prefix (A1, Prefix (A2));
6096 else
6097 return False;
6098 end if;
6100 elsif Is_Entity_Name (A2) then
6101 return Denotes_Same_Prefix (A1 => A2, A2 => A1);
6103 elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
6104 and then
6105 Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
6106 then
6107 declare
6108 Root1, Root2 : Node_Id;
6109 Depth1, Depth2 : Nat := 0;
6111 begin
6112 Root1 := Prefix (A1);
6113 while not Is_Entity_Name (Root1) loop
6114 if not Nkind_In
6115 (Root1, N_Selected_Component, N_Indexed_Component)
6116 then
6117 return False;
6118 else
6119 Root1 := Prefix (Root1);
6120 end if;
6122 Depth1 := Depth1 + 1;
6123 end loop;
6125 Root2 := Prefix (A2);
6126 while not Is_Entity_Name (Root2) loop
6127 if not Nkind_In (Root2, N_Selected_Component,
6128 N_Indexed_Component)
6129 then
6130 return False;
6131 else
6132 Root2 := Prefix (Root2);
6133 end if;
6135 Depth2 := Depth2 + 1;
6136 end loop;
6138 -- If both have the same depth and they do not denote the same
6139 -- object, they are disjoint and no warning is needed.
6141 if Depth1 = Depth2 then
6142 return False;
6144 elsif Depth1 > Depth2 then
6145 Root1 := Prefix (A1);
6146 for J in 1 .. Depth1 - Depth2 - 1 loop
6147 Root1 := Prefix (Root1);
6148 end loop;
6150 return Denotes_Same_Object (Root1, A2);
6152 else
6153 Root2 := Prefix (A2);
6154 for J in 1 .. Depth2 - Depth1 - 1 loop
6155 Root2 := Prefix (Root2);
6156 end loop;
6158 return Denotes_Same_Object (A1, Root2);
6159 end if;
6160 end;
6162 else
6163 return False;
6164 end if;
6165 end Denotes_Same_Prefix;
6167 ----------------------
6168 -- Denotes_Variable --
6169 ----------------------
6171 function Denotes_Variable (N : Node_Id) return Boolean is
6172 begin
6173 return Is_Variable (N) and then Paren_Count (N) = 0;
6174 end Denotes_Variable;
6176 -----------------------------
6177 -- Depends_On_Discriminant --
6178 -----------------------------
6180 function Depends_On_Discriminant (N : Node_Id) return Boolean is
6181 L : Node_Id;
6182 H : Node_Id;
6184 begin
6185 Get_Index_Bounds (N, L, H);
6186 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
6187 end Depends_On_Discriminant;
6189 -------------------------
6190 -- Designate_Same_Unit --
6191 -------------------------
6193 function Designate_Same_Unit
6194 (Name1 : Node_Id;
6195 Name2 : Node_Id) return Boolean
6197 K1 : constant Node_Kind := Nkind (Name1);
6198 K2 : constant Node_Kind := Nkind (Name2);
6200 function Prefix_Node (N : Node_Id) return Node_Id;
6201 -- Returns the parent unit name node of a defining program unit name
6202 -- or the prefix if N is a selected component or an expanded name.
6204 function Select_Node (N : Node_Id) return Node_Id;
6205 -- Returns the defining identifier node of a defining program unit
6206 -- name or the selector node if N is a selected component or an
6207 -- expanded name.
6209 -----------------
6210 -- Prefix_Node --
6211 -----------------
6213 function Prefix_Node (N : Node_Id) return Node_Id is
6214 begin
6215 if Nkind (N) = N_Defining_Program_Unit_Name then
6216 return Name (N);
6217 else
6218 return Prefix (N);
6219 end if;
6220 end Prefix_Node;
6222 -----------------
6223 -- Select_Node --
6224 -----------------
6226 function Select_Node (N : Node_Id) return Node_Id is
6227 begin
6228 if Nkind (N) = N_Defining_Program_Unit_Name then
6229 return Defining_Identifier (N);
6230 else
6231 return Selector_Name (N);
6232 end if;
6233 end Select_Node;
6235 -- Start of processing for Designate_Same_Unit
6237 begin
6238 if Nkind_In (K1, N_Identifier, N_Defining_Identifier)
6239 and then
6240 Nkind_In (K2, N_Identifier, N_Defining_Identifier)
6241 then
6242 return Chars (Name1) = Chars (Name2);
6244 elsif Nkind_In (K1, N_Expanded_Name,
6245 N_Selected_Component,
6246 N_Defining_Program_Unit_Name)
6247 and then
6248 Nkind_In (K2, N_Expanded_Name,
6249 N_Selected_Component,
6250 N_Defining_Program_Unit_Name)
6251 then
6252 return
6253 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
6254 and then
6255 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
6257 else
6258 return False;
6259 end if;
6260 end Designate_Same_Unit;
6262 ---------------------------------------------
6263 -- Diagnose_Iterated_Component_Association --
6264 ---------------------------------------------
6266 procedure Diagnose_Iterated_Component_Association (N : Node_Id) is
6267 Def_Id : constant Entity_Id := Defining_Identifier (N);
6268 Aggr : Node_Id;
6270 begin
6271 -- Determine whether the iterated component association appears within
6272 -- an aggregate. If this is the case, raise Program_Error because the
6273 -- iterated component association cannot be left in the tree as is and
6274 -- must always be processed by the related aggregate.
6276 Aggr := N;
6277 while Present (Aggr) loop
6278 if Nkind (Aggr) = N_Aggregate then
6279 raise Program_Error;
6281 -- Prevent the search from going too far
6283 elsif Is_Body_Or_Package_Declaration (Aggr) then
6284 exit;
6285 end if;
6287 Aggr := Parent (Aggr);
6288 end loop;
6290 -- At this point it is known that the iterated component association is
6291 -- not within an aggregate. This is really a quantified expression with
6292 -- a missing "all" or "some" quantifier.
6294 Error_Msg_N ("missing quantifier", Def_Id);
6296 -- Rewrite the iterated component association as True to prevent any
6297 -- cascaded errors.
6299 Rewrite (N, New_Occurrence_Of (Standard_True, Sloc (N)));
6300 Analyze (N);
6301 end Diagnose_Iterated_Component_Association;
6303 ---------------------------------
6304 -- Dynamic_Accessibility_Level --
6305 ---------------------------------
6307 function Dynamic_Accessibility_Level (Expr : Node_Id) return Node_Id is
6308 Loc : constant Source_Ptr := Sloc (Expr);
6310 function Make_Level_Literal (Level : Uint) return Node_Id;
6311 -- Construct an integer literal representing an accessibility level
6312 -- with its type set to Natural.
6314 ------------------------
6315 -- Make_Level_Literal --
6316 ------------------------
6318 function Make_Level_Literal (Level : Uint) return Node_Id is
6319 Result : constant Node_Id := Make_Integer_Literal (Loc, Level);
6321 begin
6322 Set_Etype (Result, Standard_Natural);
6323 return Result;
6324 end Make_Level_Literal;
6326 -- Local variables
6328 E : Entity_Id;
6330 -- Start of processing for Dynamic_Accessibility_Level
6332 begin
6333 if Is_Entity_Name (Expr) then
6334 E := Entity (Expr);
6336 if Present (Renamed_Object (E)) then
6337 return Dynamic_Accessibility_Level (Renamed_Object (E));
6338 end if;
6340 if Is_Formal (E) or else Ekind_In (E, E_Variable, E_Constant) then
6341 if Present (Extra_Accessibility (E)) then
6342 return New_Occurrence_Of (Extra_Accessibility (E), Loc);
6343 end if;
6344 end if;
6345 end if;
6347 -- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
6349 case Nkind (Expr) is
6351 -- For access discriminant, the level of the enclosing object
6353 when N_Selected_Component =>
6354 if Ekind (Entity (Selector_Name (Expr))) = E_Discriminant
6355 and then Ekind (Etype (Entity (Selector_Name (Expr)))) =
6356 E_Anonymous_Access_Type
6357 then
6358 return Make_Level_Literal (Object_Access_Level (Expr));
6359 end if;
6361 when N_Attribute_Reference =>
6362 case Get_Attribute_Id (Attribute_Name (Expr)) is
6364 -- For X'Access, the level of the prefix X
6366 when Attribute_Access =>
6367 return Make_Level_Literal
6368 (Object_Access_Level (Prefix (Expr)));
6370 -- Treat the unchecked attributes as library-level
6372 when Attribute_Unchecked_Access
6373 | Attribute_Unrestricted_Access
6375 return Make_Level_Literal (Scope_Depth (Standard_Standard));
6377 -- No other access-valued attributes
6379 when others =>
6380 raise Program_Error;
6381 end case;
6383 when N_Allocator =>
6385 -- Unimplemented: depends on context. As an actual parameter where
6386 -- formal type is anonymous, use
6387 -- Scope_Depth (Current_Scope) + 1.
6388 -- For other cases, see 3.10.2(14/3) and following. ???
6390 null;
6392 when N_Type_Conversion =>
6393 if not Is_Local_Anonymous_Access (Etype (Expr)) then
6395 -- Handle type conversions introduced for a rename of an
6396 -- Ada 2012 stand-alone object of an anonymous access type.
6398 return Dynamic_Accessibility_Level (Expression (Expr));
6399 end if;
6401 when others =>
6402 null;
6403 end case;
6405 return Make_Level_Literal (Type_Access_Level (Etype (Expr)));
6406 end Dynamic_Accessibility_Level;
6408 ------------------------
6409 -- Discriminated_Size --
6410 ------------------------
6412 function Discriminated_Size (Comp : Entity_Id) return Boolean is
6413 function Non_Static_Bound (Bound : Node_Id) return Boolean;
6414 -- Check whether the bound of an index is non-static and does denote
6415 -- a discriminant, in which case any object of the type (protected or
6416 -- otherwise) will have a non-static size.
6418 ----------------------
6419 -- Non_Static_Bound --
6420 ----------------------
6422 function Non_Static_Bound (Bound : Node_Id) return Boolean is
6423 begin
6424 if Is_OK_Static_Expression (Bound) then
6425 return False;
6427 -- If the bound is given by a discriminant it is non-static
6428 -- (A static constraint replaces the reference with the value).
6429 -- In an protected object the discriminant has been replaced by
6430 -- the corresponding discriminal within the protected operation.
6432 elsif Is_Entity_Name (Bound)
6433 and then
6434 (Ekind (Entity (Bound)) = E_Discriminant
6435 or else Present (Discriminal_Link (Entity (Bound))))
6436 then
6437 return False;
6439 else
6440 return True;
6441 end if;
6442 end Non_Static_Bound;
6444 -- Local variables
6446 Typ : constant Entity_Id := Etype (Comp);
6447 Index : Node_Id;
6449 -- Start of processing for Discriminated_Size
6451 begin
6452 if not Is_Array_Type (Typ) then
6453 return False;
6454 end if;
6456 if Ekind (Typ) = E_Array_Subtype then
6457 Index := First_Index (Typ);
6458 while Present (Index) loop
6459 if Non_Static_Bound (Low_Bound (Index))
6460 or else Non_Static_Bound (High_Bound (Index))
6461 then
6462 return False;
6463 end if;
6465 Next_Index (Index);
6466 end loop;
6468 return True;
6469 end if;
6471 return False;
6472 end Discriminated_Size;
6474 -----------------------------------
6475 -- Effective_Extra_Accessibility --
6476 -----------------------------------
6478 function Effective_Extra_Accessibility (Id : Entity_Id) return Entity_Id is
6479 begin
6480 if Present (Renamed_Object (Id))
6481 and then Is_Entity_Name (Renamed_Object (Id))
6482 then
6483 return Effective_Extra_Accessibility (Entity (Renamed_Object (Id)));
6484 else
6485 return Extra_Accessibility (Id);
6486 end if;
6487 end Effective_Extra_Accessibility;
6489 -----------------------------
6490 -- Effective_Reads_Enabled --
6491 -----------------------------
6493 function Effective_Reads_Enabled (Id : Entity_Id) return Boolean is
6494 begin
6495 return Has_Enabled_Property (Id, Name_Effective_Reads);
6496 end Effective_Reads_Enabled;
6498 ------------------------------
6499 -- Effective_Writes_Enabled --
6500 ------------------------------
6502 function Effective_Writes_Enabled (Id : Entity_Id) return Boolean is
6503 begin
6504 return Has_Enabled_Property (Id, Name_Effective_Writes);
6505 end Effective_Writes_Enabled;
6507 ------------------------------
6508 -- Enclosing_Comp_Unit_Node --
6509 ------------------------------
6511 function Enclosing_Comp_Unit_Node (N : Node_Id) return Node_Id is
6512 Current_Node : Node_Id;
6514 begin
6515 Current_Node := N;
6516 while Present (Current_Node)
6517 and then Nkind (Current_Node) /= N_Compilation_Unit
6518 loop
6519 Current_Node := Parent (Current_Node);
6520 end loop;
6522 if Nkind (Current_Node) /= N_Compilation_Unit then
6523 return Empty;
6524 else
6525 return Current_Node;
6526 end if;
6527 end Enclosing_Comp_Unit_Node;
6529 --------------------------
6530 -- Enclosing_CPP_Parent --
6531 --------------------------
6533 function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is
6534 Parent_Typ : Entity_Id := Typ;
6536 begin
6537 while not Is_CPP_Class (Parent_Typ)
6538 and then Etype (Parent_Typ) /= Parent_Typ
6539 loop
6540 Parent_Typ := Etype (Parent_Typ);
6542 if Is_Private_Type (Parent_Typ) then
6543 Parent_Typ := Full_View (Base_Type (Parent_Typ));
6544 end if;
6545 end loop;
6547 pragma Assert (Is_CPP_Class (Parent_Typ));
6548 return Parent_Typ;
6549 end Enclosing_CPP_Parent;
6551 ---------------------------
6552 -- Enclosing_Declaration --
6553 ---------------------------
6555 function Enclosing_Declaration (N : Node_Id) return Node_Id is
6556 Decl : Node_Id := N;
6558 begin
6559 while Present (Decl)
6560 and then not (Nkind (Decl) in N_Declaration
6561 or else
6562 Nkind (Decl) in N_Later_Decl_Item)
6563 loop
6564 Decl := Parent (Decl);
6565 end loop;
6567 return Decl;
6568 end Enclosing_Declaration;
6570 ----------------------------
6571 -- Enclosing_Generic_Body --
6572 ----------------------------
6574 function Enclosing_Generic_Body
6575 (N : Node_Id) return Node_Id
6577 P : Node_Id;
6578 Decl : Node_Id;
6579 Spec : Node_Id;
6581 begin
6582 P := Parent (N);
6583 while Present (P) loop
6584 if Nkind (P) = N_Package_Body
6585 or else Nkind (P) = N_Subprogram_Body
6586 then
6587 Spec := Corresponding_Spec (P);
6589 if Present (Spec) then
6590 Decl := Unit_Declaration_Node (Spec);
6592 if Nkind (Decl) = N_Generic_Package_Declaration
6593 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
6594 then
6595 return P;
6596 end if;
6597 end if;
6598 end if;
6600 P := Parent (P);
6601 end loop;
6603 return Empty;
6604 end Enclosing_Generic_Body;
6606 ----------------------------
6607 -- Enclosing_Generic_Unit --
6608 ----------------------------
6610 function Enclosing_Generic_Unit
6611 (N : Node_Id) return Node_Id
6613 P : Node_Id;
6614 Decl : Node_Id;
6615 Spec : Node_Id;
6617 begin
6618 P := Parent (N);
6619 while Present (P) loop
6620 if Nkind (P) = N_Generic_Package_Declaration
6621 or else Nkind (P) = N_Generic_Subprogram_Declaration
6622 then
6623 return P;
6625 elsif Nkind (P) = N_Package_Body
6626 or else Nkind (P) = N_Subprogram_Body
6627 then
6628 Spec := Corresponding_Spec (P);
6630 if Present (Spec) then
6631 Decl := Unit_Declaration_Node (Spec);
6633 if Nkind (Decl) = N_Generic_Package_Declaration
6634 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
6635 then
6636 return Decl;
6637 end if;
6638 end if;
6639 end if;
6641 P := Parent (P);
6642 end loop;
6644 return Empty;
6645 end Enclosing_Generic_Unit;
6647 -------------------------------
6648 -- Enclosing_Lib_Unit_Entity --
6649 -------------------------------
6651 function Enclosing_Lib_Unit_Entity
6652 (E : Entity_Id := Current_Scope) return Entity_Id
6654 Unit_Entity : Entity_Id;
6656 begin
6657 -- Look for enclosing library unit entity by following scope links.
6658 -- Equivalent to, but faster than indexing through the scope stack.
6660 Unit_Entity := E;
6661 while (Present (Scope (Unit_Entity))
6662 and then Scope (Unit_Entity) /= Standard_Standard)
6663 and not Is_Child_Unit (Unit_Entity)
6664 loop
6665 Unit_Entity := Scope (Unit_Entity);
6666 end loop;
6668 return Unit_Entity;
6669 end Enclosing_Lib_Unit_Entity;
6671 -----------------------------
6672 -- Enclosing_Lib_Unit_Node --
6673 -----------------------------
6675 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
6676 Encl_Unit : Node_Id;
6678 begin
6679 Encl_Unit := Enclosing_Comp_Unit_Node (N);
6680 while Present (Encl_Unit)
6681 and then Nkind (Unit (Encl_Unit)) = N_Subunit
6682 loop
6683 Encl_Unit := Library_Unit (Encl_Unit);
6684 end loop;
6686 pragma Assert (Nkind (Encl_Unit) = N_Compilation_Unit);
6687 return Encl_Unit;
6688 end Enclosing_Lib_Unit_Node;
6690 -----------------------
6691 -- Enclosing_Package --
6692 -----------------------
6694 function Enclosing_Package (E : Entity_Id) return Entity_Id is
6695 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
6697 begin
6698 if Dynamic_Scope = Standard_Standard then
6699 return Standard_Standard;
6701 elsif Dynamic_Scope = Empty then
6702 return Empty;
6704 elsif Ekind_In (Dynamic_Scope, E_Package, E_Package_Body,
6705 E_Generic_Package)
6706 then
6707 return Dynamic_Scope;
6709 else
6710 return Enclosing_Package (Dynamic_Scope);
6711 end if;
6712 end Enclosing_Package;
6714 -------------------------------------
6715 -- Enclosing_Package_Or_Subprogram --
6716 -------------------------------------
6718 function Enclosing_Package_Or_Subprogram (E : Entity_Id) return Entity_Id is
6719 S : Entity_Id;
6721 begin
6722 S := Scope (E);
6723 while Present (S) loop
6724 if Is_Package_Or_Generic_Package (S)
6725 or else Ekind (S) = E_Package_Body
6726 then
6727 return S;
6729 elsif Is_Subprogram_Or_Generic_Subprogram (S)
6730 or else Ekind (S) = E_Subprogram_Body
6731 then
6732 return S;
6734 else
6735 S := Scope (S);
6736 end if;
6737 end loop;
6739 return Empty;
6740 end Enclosing_Package_Or_Subprogram;
6742 --------------------------
6743 -- Enclosing_Subprogram --
6744 --------------------------
6746 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
6747 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
6749 begin
6750 if Dynamic_Scope = Standard_Standard then
6751 return Empty;
6753 elsif Dynamic_Scope = Empty then
6754 return Empty;
6756 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
6757 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
6759 elsif Ekind (Dynamic_Scope) = E_Block
6760 or else Ekind (Dynamic_Scope) = E_Return_Statement
6761 then
6762 return Enclosing_Subprogram (Dynamic_Scope);
6764 elsif Ekind (Dynamic_Scope) = E_Task_Type then
6765 return Get_Task_Body_Procedure (Dynamic_Scope);
6767 elsif Ekind (Dynamic_Scope) = E_Limited_Private_Type
6768 and then Present (Full_View (Dynamic_Scope))
6769 and then Ekind (Full_View (Dynamic_Scope)) = E_Task_Type
6770 then
6771 return Get_Task_Body_Procedure (Full_View (Dynamic_Scope));
6773 -- No body is generated if the protected operation is eliminated
6775 elsif Convention (Dynamic_Scope) = Convention_Protected
6776 and then not Is_Eliminated (Dynamic_Scope)
6777 and then Present (Protected_Body_Subprogram (Dynamic_Scope))
6778 then
6779 return Protected_Body_Subprogram (Dynamic_Scope);
6781 else
6782 return Dynamic_Scope;
6783 end if;
6784 end Enclosing_Subprogram;
6786 ------------------------
6787 -- Ensure_Freeze_Node --
6788 ------------------------
6790 procedure Ensure_Freeze_Node (E : Entity_Id) is
6791 FN : Node_Id;
6792 begin
6793 if No (Freeze_Node (E)) then
6794 FN := Make_Freeze_Entity (Sloc (E));
6795 Set_Has_Delayed_Freeze (E);
6796 Set_Freeze_Node (E, FN);
6797 Set_Access_Types_To_Process (FN, No_Elist);
6798 Set_TSS_Elist (FN, No_Elist);
6799 Set_Entity (FN, E);
6800 end if;
6801 end Ensure_Freeze_Node;
6803 ----------------
6804 -- Enter_Name --
6805 ----------------
6807 procedure Enter_Name (Def_Id : Entity_Id) is
6808 C : constant Entity_Id := Current_Entity (Def_Id);
6809 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
6810 S : constant Entity_Id := Current_Scope;
6812 begin
6813 Generate_Definition (Def_Id);
6815 -- Add new name to current scope declarations. Check for duplicate
6816 -- declaration, which may or may not be a genuine error.
6818 if Present (E) then
6820 -- Case of previous entity entered because of a missing declaration
6821 -- or else a bad subtype indication. Best is to use the new entity,
6822 -- and make the previous one invisible.
6824 if Etype (E) = Any_Type then
6825 Set_Is_Immediately_Visible (E, False);
6827 -- Case of renaming declaration constructed for package instances.
6828 -- if there is an explicit declaration with the same identifier,
6829 -- the renaming is not immediately visible any longer, but remains
6830 -- visible through selected component notation.
6832 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
6833 and then not Comes_From_Source (E)
6834 then
6835 Set_Is_Immediately_Visible (E, False);
6837 -- The new entity may be the package renaming, which has the same
6838 -- same name as a generic formal which has been seen already.
6840 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
6841 and then not Comes_From_Source (Def_Id)
6842 then
6843 Set_Is_Immediately_Visible (E, False);
6845 -- For a fat pointer corresponding to a remote access to subprogram,
6846 -- we use the same identifier as the RAS type, so that the proper
6847 -- name appears in the stub. This type is only retrieved through
6848 -- the RAS type and never by visibility, and is not added to the
6849 -- visibility list (see below).
6851 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
6852 and then Ekind (Def_Id) = E_Record_Type
6853 and then Present (Corresponding_Remote_Type (Def_Id))
6854 then
6855 null;
6857 -- Case of an implicit operation or derived literal. The new entity
6858 -- hides the implicit one, which is removed from all visibility,
6859 -- i.e. the entity list of its scope, and homonym chain of its name.
6861 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
6862 or else Is_Internal (E)
6863 then
6864 declare
6865 Decl : constant Node_Id := Parent (E);
6866 Prev : Entity_Id;
6867 Prev_Vis : Entity_Id;
6869 begin
6870 -- If E is an implicit declaration, it cannot be the first
6871 -- entity in the scope.
6873 Prev := First_Entity (Current_Scope);
6874 while Present (Prev) and then Next_Entity (Prev) /= E loop
6875 Next_Entity (Prev);
6876 end loop;
6878 if No (Prev) then
6880 -- If E is not on the entity chain of the current scope,
6881 -- it is an implicit declaration in the generic formal
6882 -- part of a generic subprogram. When analyzing the body,
6883 -- the generic formals are visible but not on the entity
6884 -- chain of the subprogram. The new entity will become
6885 -- the visible one in the body.
6887 pragma Assert
6888 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
6889 null;
6891 else
6892 Set_Next_Entity (Prev, Next_Entity (E));
6894 if No (Next_Entity (Prev)) then
6895 Set_Last_Entity (Current_Scope, Prev);
6896 end if;
6898 if E = Current_Entity (E) then
6899 Prev_Vis := Empty;
6901 else
6902 Prev_Vis := Current_Entity (E);
6903 while Homonym (Prev_Vis) /= E loop
6904 Prev_Vis := Homonym (Prev_Vis);
6905 end loop;
6906 end if;
6908 if Present (Prev_Vis) then
6910 -- Skip E in the visibility chain
6912 Set_Homonym (Prev_Vis, Homonym (E));
6914 else
6915 Set_Name_Entity_Id (Chars (E), Homonym (E));
6916 end if;
6917 end if;
6918 end;
6920 -- This section of code could use a comment ???
6922 elsif Present (Etype (E))
6923 and then Is_Concurrent_Type (Etype (E))
6924 and then E = Def_Id
6925 then
6926 return;
6928 -- If the homograph is a protected component renaming, it should not
6929 -- be hiding the current entity. Such renamings are treated as weak
6930 -- declarations.
6932 elsif Is_Prival (E) then
6933 Set_Is_Immediately_Visible (E, False);
6935 -- In this case the current entity is a protected component renaming.
6936 -- Perform minimal decoration by setting the scope and return since
6937 -- the prival should not be hiding other visible entities.
6939 elsif Is_Prival (Def_Id) then
6940 Set_Scope (Def_Id, Current_Scope);
6941 return;
6943 -- Analogous to privals, the discriminal generated for an entry index
6944 -- parameter acts as a weak declaration. Perform minimal decoration
6945 -- to avoid bogus errors.
6947 elsif Is_Discriminal (Def_Id)
6948 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
6949 then
6950 Set_Scope (Def_Id, Current_Scope);
6951 return;
6953 -- In the body or private part of an instance, a type extension may
6954 -- introduce a component with the same name as that of an actual. The
6955 -- legality rule is not enforced, but the semantics of the full type
6956 -- with two components of same name are not clear at this point???
6958 elsif In_Instance_Not_Visible then
6959 null;
6961 -- When compiling a package body, some child units may have become
6962 -- visible. They cannot conflict with local entities that hide them.
6964 elsif Is_Child_Unit (E)
6965 and then In_Open_Scopes (Scope (E))
6966 and then not Is_Immediately_Visible (E)
6967 then
6968 null;
6970 -- Conversely, with front-end inlining we may compile the parent body
6971 -- first, and a child unit subsequently. The context is now the
6972 -- parent spec, and body entities are not visible.
6974 elsif Is_Child_Unit (Def_Id)
6975 and then Is_Package_Body_Entity (E)
6976 and then not In_Package_Body (Current_Scope)
6977 then
6978 null;
6980 -- Case of genuine duplicate declaration
6982 else
6983 Error_Msg_Sloc := Sloc (E);
6985 -- If the previous declaration is an incomplete type declaration
6986 -- this may be an attempt to complete it with a private type. The
6987 -- following avoids confusing cascaded errors.
6989 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
6990 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
6991 then
6992 Error_Msg_N
6993 ("incomplete type cannot be completed with a private " &
6994 "declaration", Parent (Def_Id));
6995 Set_Is_Immediately_Visible (E, False);
6996 Set_Full_View (E, Def_Id);
6998 -- An inherited component of a record conflicts with a new
6999 -- discriminant. The discriminant is inserted first in the scope,
7000 -- but the error should be posted on it, not on the component.
7002 elsif Ekind (E) = E_Discriminant
7003 and then Present (Scope (Def_Id))
7004 and then Scope (Def_Id) /= Current_Scope
7005 then
7006 Error_Msg_Sloc := Sloc (Def_Id);
7007 Error_Msg_N ("& conflicts with declaration#", E);
7008 return;
7010 -- If the name of the unit appears in its own context clause, a
7011 -- dummy package with the name has already been created, and the
7012 -- error emitted. Try to continue quietly.
7014 elsif Error_Posted (E)
7015 and then Sloc (E) = No_Location
7016 and then Nkind (Parent (E)) = N_Package_Specification
7017 and then Current_Scope = Standard_Standard
7018 then
7019 Set_Scope (Def_Id, Current_Scope);
7020 return;
7022 else
7023 Error_Msg_N ("& conflicts with declaration#", Def_Id);
7025 -- Avoid cascaded messages with duplicate components in
7026 -- derived types.
7028 if Ekind_In (E, E_Component, E_Discriminant) then
7029 return;
7030 end if;
7031 end if;
7033 if Nkind (Parent (Parent (Def_Id))) =
7034 N_Generic_Subprogram_Declaration
7035 and then Def_Id =
7036 Defining_Entity (Specification (Parent (Parent (Def_Id))))
7037 then
7038 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
7039 end if;
7041 -- If entity is in standard, then we are in trouble, because it
7042 -- means that we have a library package with a duplicated name.
7043 -- That's hard to recover from, so abort.
7045 if S = Standard_Standard then
7046 raise Unrecoverable_Error;
7048 -- Otherwise we continue with the declaration. Having two
7049 -- identical declarations should not cause us too much trouble.
7051 else
7052 null;
7053 end if;
7054 end if;
7055 end if;
7057 -- If we fall through, declaration is OK, at least OK enough to continue
7059 -- If Def_Id is a discriminant or a record component we are in the midst
7060 -- of inheriting components in a derived record definition. Preserve
7061 -- their Ekind and Etype.
7063 if Ekind_In (Def_Id, E_Discriminant, E_Component) then
7064 null;
7066 -- If a type is already set, leave it alone (happens when a type
7067 -- declaration is reanalyzed following a call to the optimizer).
7069 elsif Present (Etype (Def_Id)) then
7070 null;
7072 -- Otherwise, the kind E_Void insures that premature uses of the entity
7073 -- will be detected. Any_Type insures that no cascaded errors will occur
7075 else
7076 Set_Ekind (Def_Id, E_Void);
7077 Set_Etype (Def_Id, Any_Type);
7078 end if;
7080 -- Inherited discriminants and components in derived record types are
7081 -- immediately visible. Itypes are not.
7083 -- Unless the Itype is for a record type with a corresponding remote
7084 -- type (what is that about, it was not commented ???)
7086 if Ekind_In (Def_Id, E_Discriminant, E_Component)
7087 or else
7088 ((not Is_Record_Type (Def_Id)
7089 or else No (Corresponding_Remote_Type (Def_Id)))
7090 and then not Is_Itype (Def_Id))
7091 then
7092 Set_Is_Immediately_Visible (Def_Id);
7093 Set_Current_Entity (Def_Id);
7094 end if;
7096 Set_Homonym (Def_Id, C);
7097 Append_Entity (Def_Id, S);
7098 Set_Public_Status (Def_Id);
7100 -- Declaring a homonym is not allowed in SPARK ...
7102 if Present (C) and then Restriction_Check_Required (SPARK_05) then
7103 declare
7104 Enclosing_Subp : constant Node_Id := Enclosing_Subprogram (Def_Id);
7105 Enclosing_Pack : constant Node_Id := Enclosing_Package (Def_Id);
7106 Other_Scope : constant Node_Id := Enclosing_Dynamic_Scope (C);
7108 begin
7109 -- ... unless the new declaration is in a subprogram, and the
7110 -- visible declaration is a variable declaration or a parameter
7111 -- specification outside that subprogram.
7113 if Present (Enclosing_Subp)
7114 and then Nkind_In (Parent (C), N_Object_Declaration,
7115 N_Parameter_Specification)
7116 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Subp)
7117 then
7118 null;
7120 -- ... or the new declaration is in a package, and the visible
7121 -- declaration occurs outside that package.
7123 elsif Present (Enclosing_Pack)
7124 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Pack)
7125 then
7126 null;
7128 -- ... or the new declaration is a component declaration in a
7129 -- record type definition.
7131 elsif Nkind (Parent (Def_Id)) = N_Component_Declaration then
7132 null;
7134 -- Don't issue error for non-source entities
7136 elsif Comes_From_Source (Def_Id)
7137 and then Comes_From_Source (C)
7138 then
7139 Error_Msg_Sloc := Sloc (C);
7140 Check_SPARK_05_Restriction
7141 ("redeclaration of identifier &#", Def_Id);
7142 end if;
7143 end;
7144 end if;
7146 -- Warn if new entity hides an old one
7148 if Warn_On_Hiding and then Present (C)
7150 -- Don't warn for record components since they always have a well
7151 -- defined scope which does not confuse other uses. Note that in
7152 -- some cases, Ekind has not been set yet.
7154 and then Ekind (C) /= E_Component
7155 and then Ekind (C) /= E_Discriminant
7156 and then Nkind (Parent (C)) /= N_Component_Declaration
7157 and then Ekind (Def_Id) /= E_Component
7158 and then Ekind (Def_Id) /= E_Discriminant
7159 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
7161 -- Don't warn for one character variables. It is too common to use
7162 -- such variables as locals and will just cause too many false hits.
7164 and then Length_Of_Name (Chars (C)) /= 1
7166 -- Don't warn for non-source entities
7168 and then Comes_From_Source (C)
7169 and then Comes_From_Source (Def_Id)
7171 -- Don't warn unless entity in question is in extended main source
7173 and then In_Extended_Main_Source_Unit (Def_Id)
7175 -- Finally, the hidden entity must be either immediately visible or
7176 -- use visible (i.e. from a used package).
7178 and then
7179 (Is_Immediately_Visible (C)
7180 or else
7181 Is_Potentially_Use_Visible (C))
7182 then
7183 Error_Msg_Sloc := Sloc (C);
7184 Error_Msg_N ("declaration hides &#?h?", Def_Id);
7185 end if;
7186 end Enter_Name;
7188 ---------------
7189 -- Entity_Of --
7190 ---------------
7192 function Entity_Of (N : Node_Id) return Entity_Id is
7193 Id : Entity_Id;
7194 Ren : Node_Id;
7196 begin
7197 -- Assume that the arbitrary node does not have an entity
7199 Id := Empty;
7201 if Is_Entity_Name (N) then
7202 Id := Entity (N);
7204 -- Follow a possible chain of renamings to reach the earliest renamed
7205 -- source object.
7207 while Present (Id)
7208 and then Is_Object (Id)
7209 and then Present (Renamed_Object (Id))
7210 loop
7211 Ren := Renamed_Object (Id);
7213 -- The reference renames an abstract state or a whole object
7215 -- Obj : ...;
7216 -- Ren : ... renames Obj;
7218 if Is_Entity_Name (Ren) then
7219 Id := Entity (Ren);
7221 -- The reference renames a function result. Check the original
7222 -- node in case expansion relocates the function call.
7224 -- Ren : ... renames Func_Call;
7226 elsif Nkind (Original_Node (Ren)) = N_Function_Call then
7227 exit;
7229 -- Otherwise the reference renames something which does not yield
7230 -- an abstract state or a whole object. Treat the reference as not
7231 -- having a proper entity for SPARK legality purposes.
7233 else
7234 Id := Empty;
7235 exit;
7236 end if;
7237 end loop;
7238 end if;
7240 return Id;
7241 end Entity_Of;
7243 --------------------------
7244 -- Explain_Limited_Type --
7245 --------------------------
7247 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
7248 C : Entity_Id;
7250 begin
7251 -- For array, component type must be limited
7253 if Is_Array_Type (T) then
7254 Error_Msg_Node_2 := T;
7255 Error_Msg_NE
7256 ("\component type& of type& is limited", N, Component_Type (T));
7257 Explain_Limited_Type (Component_Type (T), N);
7259 elsif Is_Record_Type (T) then
7261 -- No need for extra messages if explicit limited record
7263 if Is_Limited_Record (Base_Type (T)) then
7264 return;
7265 end if;
7267 -- Otherwise find a limited component. Check only components that
7268 -- come from source, or inherited components that appear in the
7269 -- source of the ancestor.
7271 C := First_Component (T);
7272 while Present (C) loop
7273 if Is_Limited_Type (Etype (C))
7274 and then
7275 (Comes_From_Source (C)
7276 or else
7277 (Present (Original_Record_Component (C))
7278 and then
7279 Comes_From_Source (Original_Record_Component (C))))
7280 then
7281 Error_Msg_Node_2 := T;
7282 Error_Msg_NE ("\component& of type& has limited type", N, C);
7283 Explain_Limited_Type (Etype (C), N);
7284 return;
7285 end if;
7287 Next_Component (C);
7288 end loop;
7290 -- The type may be declared explicitly limited, even if no component
7291 -- of it is limited, in which case we fall out of the loop.
7292 return;
7293 end if;
7294 end Explain_Limited_Type;
7296 ---------------------------------------
7297 -- Expression_Of_Expression_Function --
7298 ---------------------------------------
7300 function Expression_Of_Expression_Function
7301 (Subp : Entity_Id) return Node_Id
7303 Expr_Func : Node_Id;
7305 begin
7306 pragma Assert (Is_Expression_Function_Or_Completion (Subp));
7308 if Nkind (Original_Node (Subprogram_Spec (Subp))) =
7309 N_Expression_Function
7310 then
7311 Expr_Func := Original_Node (Subprogram_Spec (Subp));
7313 elsif Nkind (Original_Node (Subprogram_Body (Subp))) =
7314 N_Expression_Function
7315 then
7316 Expr_Func := Original_Node (Subprogram_Body (Subp));
7318 else
7319 pragma Assert (False);
7320 null;
7321 end if;
7323 return Original_Node (Expression (Expr_Func));
7324 end Expression_Of_Expression_Function;
7326 -------------------------------
7327 -- Extensions_Visible_Status --
7328 -------------------------------
7330 function Extensions_Visible_Status
7331 (Id : Entity_Id) return Extensions_Visible_Mode
7333 Arg : Node_Id;
7334 Decl : Node_Id;
7335 Expr : Node_Id;
7336 Prag : Node_Id;
7337 Subp : Entity_Id;
7339 begin
7340 -- When a formal parameter is subject to Extensions_Visible, the pragma
7341 -- is stored in the contract of related subprogram.
7343 if Is_Formal (Id) then
7344 Subp := Scope (Id);
7346 elsif Is_Subprogram_Or_Generic_Subprogram (Id) then
7347 Subp := Id;
7349 -- No other construct carries this pragma
7351 else
7352 return Extensions_Visible_None;
7353 end if;
7355 Prag := Get_Pragma (Subp, Pragma_Extensions_Visible);
7357 -- In certain cases analysis may request the Extensions_Visible status
7358 -- of an expression function before the pragma has been analyzed yet.
7359 -- Inspect the declarative items after the expression function looking
7360 -- for the pragma (if any).
7362 if No (Prag) and then Is_Expression_Function (Subp) then
7363 Decl := Next (Unit_Declaration_Node (Subp));
7364 while Present (Decl) loop
7365 if Nkind (Decl) = N_Pragma
7366 and then Pragma_Name (Decl) = Name_Extensions_Visible
7367 then
7368 Prag := Decl;
7369 exit;
7371 -- A source construct ends the region where Extensions_Visible may
7372 -- appear, stop the traversal. An expanded expression function is
7373 -- no longer a source construct, but it must still be recognized.
7375 elsif Comes_From_Source (Decl)
7376 or else
7377 (Nkind_In (Decl, N_Subprogram_Body,
7378 N_Subprogram_Declaration)
7379 and then Is_Expression_Function (Defining_Entity (Decl)))
7380 then
7381 exit;
7382 end if;
7384 Next (Decl);
7385 end loop;
7386 end if;
7388 -- Extract the value from the Boolean expression (if any)
7390 if Present (Prag) then
7391 Arg := First (Pragma_Argument_Associations (Prag));
7393 if Present (Arg) then
7394 Expr := Get_Pragma_Arg (Arg);
7396 -- When the associated subprogram is an expression function, the
7397 -- argument of the pragma may not have been analyzed.
7399 if not Analyzed (Expr) then
7400 Preanalyze_And_Resolve (Expr, Standard_Boolean);
7401 end if;
7403 -- Guard against cascading errors when the argument of pragma
7404 -- Extensions_Visible is not a valid static Boolean expression.
7406 if Error_Posted (Expr) then
7407 return Extensions_Visible_None;
7409 elsif Is_True (Expr_Value (Expr)) then
7410 return Extensions_Visible_True;
7412 else
7413 return Extensions_Visible_False;
7414 end if;
7416 -- Otherwise the aspect or pragma defaults to True
7418 else
7419 return Extensions_Visible_True;
7420 end if;
7422 -- Otherwise aspect or pragma Extensions_Visible is not inherited or
7423 -- directly specified. In SPARK code, its value defaults to "False".
7425 elsif SPARK_Mode = On then
7426 return Extensions_Visible_False;
7428 -- In non-SPARK code, aspect or pragma Extensions_Visible defaults to
7429 -- "True".
7431 else
7432 return Extensions_Visible_True;
7433 end if;
7434 end Extensions_Visible_Status;
7436 -----------------
7437 -- Find_Actual --
7438 -----------------
7440 procedure Find_Actual
7441 (N : Node_Id;
7442 Formal : out Entity_Id;
7443 Call : out Node_Id)
7445 Context : constant Node_Id := Parent (N);
7446 Actual : Node_Id;
7447 Call_Nam : Node_Id;
7449 begin
7450 if Nkind_In (Context, N_Indexed_Component, N_Selected_Component)
7451 and then N = Prefix (Context)
7452 then
7453 Find_Actual (Context, Formal, Call);
7454 return;
7456 elsif Nkind (Context) = N_Parameter_Association
7457 and then N = Explicit_Actual_Parameter (Context)
7458 then
7459 Call := Parent (Context);
7461 elsif Nkind_In (Context, N_Entry_Call_Statement,
7462 N_Function_Call,
7463 N_Procedure_Call_Statement)
7464 then
7465 Call := Context;
7467 else
7468 Formal := Empty;
7469 Call := Empty;
7470 return;
7471 end if;
7473 -- If we have a call to a subprogram look for the parameter. Note that
7474 -- we exclude overloaded calls, since we don't know enough to be sure
7475 -- of giving the right answer in this case.
7477 if Nkind_In (Call, N_Entry_Call_Statement,
7478 N_Function_Call,
7479 N_Procedure_Call_Statement)
7480 then
7481 Call_Nam := Name (Call);
7483 -- A call to a protected or task entry appears as a selected
7484 -- component rather than an expanded name.
7486 if Nkind (Call_Nam) = N_Selected_Component then
7487 Call_Nam := Selector_Name (Call_Nam);
7488 end if;
7490 if Is_Entity_Name (Call_Nam)
7491 and then Present (Entity (Call_Nam))
7492 and then Is_Overloadable (Entity (Call_Nam))
7493 and then not Is_Overloaded (Call_Nam)
7494 then
7495 -- If node is name in call it is not an actual
7497 if N = Call_Nam then
7498 Formal := Empty;
7499 Call := Empty;
7500 return;
7501 end if;
7503 -- Fall here if we are definitely a parameter
7505 Actual := First_Actual (Call);
7506 Formal := First_Formal (Entity (Call_Nam));
7507 while Present (Formal) and then Present (Actual) loop
7508 if Actual = N then
7509 return;
7511 -- An actual that is the prefix in a prefixed call may have
7512 -- been rewritten in the call, after the deferred reference
7513 -- was collected. Check if sloc and kinds and names match.
7515 elsif Sloc (Actual) = Sloc (N)
7516 and then Nkind (Actual) = N_Identifier
7517 and then Nkind (Actual) = Nkind (N)
7518 and then Chars (Actual) = Chars (N)
7519 then
7520 return;
7522 else
7523 Actual := Next_Actual (Actual);
7524 Formal := Next_Formal (Formal);
7525 end if;
7526 end loop;
7527 end if;
7528 end if;
7530 -- Fall through here if we did not find matching actual
7532 Formal := Empty;
7533 Call := Empty;
7534 end Find_Actual;
7536 ---------------------------
7537 -- Find_Body_Discriminal --
7538 ---------------------------
7540 function Find_Body_Discriminal
7541 (Spec_Discriminant : Entity_Id) return Entity_Id
7543 Tsk : Entity_Id;
7544 Disc : Entity_Id;
7546 begin
7547 -- If expansion is suppressed, then the scope can be the concurrent type
7548 -- itself rather than a corresponding concurrent record type.
7550 if Is_Concurrent_Type (Scope (Spec_Discriminant)) then
7551 Tsk := Scope (Spec_Discriminant);
7553 else
7554 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
7556 Tsk := Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
7557 end if;
7559 -- Find discriminant of original concurrent type, and use its current
7560 -- discriminal, which is the renaming within the task/protected body.
7562 Disc := First_Discriminant (Tsk);
7563 while Present (Disc) loop
7564 if Chars (Disc) = Chars (Spec_Discriminant) then
7565 return Discriminal (Disc);
7566 end if;
7568 Next_Discriminant (Disc);
7569 end loop;
7571 -- That loop should always succeed in finding a matching entry and
7572 -- returning. Fatal error if not.
7574 raise Program_Error;
7575 end Find_Body_Discriminal;
7577 -------------------------------------
7578 -- Find_Corresponding_Discriminant --
7579 -------------------------------------
7581 function Find_Corresponding_Discriminant
7582 (Id : Node_Id;
7583 Typ : Entity_Id) return Entity_Id
7585 Par_Disc : Entity_Id;
7586 Old_Disc : Entity_Id;
7587 New_Disc : Entity_Id;
7589 begin
7590 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
7592 -- The original type may currently be private, and the discriminant
7593 -- only appear on its full view.
7595 if Is_Private_Type (Scope (Par_Disc))
7596 and then not Has_Discriminants (Scope (Par_Disc))
7597 and then Present (Full_View (Scope (Par_Disc)))
7598 then
7599 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
7600 else
7601 Old_Disc := First_Discriminant (Scope (Par_Disc));
7602 end if;
7604 if Is_Class_Wide_Type (Typ) then
7605 New_Disc := First_Discriminant (Root_Type (Typ));
7606 else
7607 New_Disc := First_Discriminant (Typ);
7608 end if;
7610 while Present (Old_Disc) and then Present (New_Disc) loop
7611 if Old_Disc = Par_Disc then
7612 return New_Disc;
7613 end if;
7615 Next_Discriminant (Old_Disc);
7616 Next_Discriminant (New_Disc);
7617 end loop;
7619 -- Should always find it
7621 raise Program_Error;
7622 end Find_Corresponding_Discriminant;
7624 ----------------------------------
7625 -- Find_Enclosing_Iterator_Loop --
7626 ----------------------------------
7628 function Find_Enclosing_Iterator_Loop (Id : Entity_Id) return Entity_Id is
7629 Constr : Node_Id;
7630 S : Entity_Id;
7632 begin
7633 -- Traverse the scope chain looking for an iterator loop. Such loops are
7634 -- usually transformed into blocks, hence the use of Original_Node.
7636 S := Id;
7637 while Present (S) and then S /= Standard_Standard loop
7638 if Ekind (S) = E_Loop
7639 and then Nkind (Parent (S)) = N_Implicit_Label_Declaration
7640 then
7641 Constr := Original_Node (Label_Construct (Parent (S)));
7643 if Nkind (Constr) = N_Loop_Statement
7644 and then Present (Iteration_Scheme (Constr))
7645 and then Nkind (Iterator_Specification
7646 (Iteration_Scheme (Constr))) =
7647 N_Iterator_Specification
7648 then
7649 return S;
7650 end if;
7651 end if;
7653 S := Scope (S);
7654 end loop;
7656 return Empty;
7657 end Find_Enclosing_Iterator_Loop;
7659 ------------------------------------
7660 -- Find_Loop_In_Conditional_Block --
7661 ------------------------------------
7663 function Find_Loop_In_Conditional_Block (N : Node_Id) return Node_Id is
7664 Stmt : Node_Id;
7666 begin
7667 Stmt := N;
7669 if Nkind (Stmt) = N_If_Statement then
7670 Stmt := First (Then_Statements (Stmt));
7671 end if;
7673 pragma Assert (Nkind (Stmt) = N_Block_Statement);
7675 -- Inspect the statements of the conditional block. In general the loop
7676 -- should be the first statement in the statement sequence of the block,
7677 -- but the finalization machinery may have introduced extra object
7678 -- declarations.
7680 Stmt := First (Statements (Handled_Statement_Sequence (Stmt)));
7681 while Present (Stmt) loop
7682 if Nkind (Stmt) = N_Loop_Statement then
7683 return Stmt;
7684 end if;
7686 Next (Stmt);
7687 end loop;
7689 -- The expansion of attribute 'Loop_Entry produced a malformed block
7691 raise Program_Error;
7692 end Find_Loop_In_Conditional_Block;
7694 --------------------------
7695 -- Find_Overlaid_Entity --
7696 --------------------------
7698 procedure Find_Overlaid_Entity
7699 (N : Node_Id;
7700 Ent : out Entity_Id;
7701 Off : out Boolean)
7703 Expr : Node_Id;
7705 begin
7706 -- We are looking for one of the two following forms:
7708 -- for X'Address use Y'Address
7710 -- or
7712 -- Const : constant Address := expr;
7713 -- ...
7714 -- for X'Address use Const;
7716 -- In the second case, the expr is either Y'Address, or recursively a
7717 -- constant that eventually references Y'Address.
7719 Ent := Empty;
7720 Off := False;
7722 if Nkind (N) = N_Attribute_Definition_Clause
7723 and then Chars (N) = Name_Address
7724 then
7725 Expr := Expression (N);
7727 -- This loop checks the form of the expression for Y'Address,
7728 -- using recursion to deal with intermediate constants.
7730 loop
7731 -- Check for Y'Address
7733 if Nkind (Expr) = N_Attribute_Reference
7734 and then Attribute_Name (Expr) = Name_Address
7735 then
7736 Expr := Prefix (Expr);
7737 exit;
7739 -- Check for Const where Const is a constant entity
7741 elsif Is_Entity_Name (Expr)
7742 and then Ekind (Entity (Expr)) = E_Constant
7743 then
7744 Expr := Constant_Value (Entity (Expr));
7746 -- Anything else does not need checking
7748 else
7749 return;
7750 end if;
7751 end loop;
7753 -- This loop checks the form of the prefix for an entity, using
7754 -- recursion to deal with intermediate components.
7756 loop
7757 -- Check for Y where Y is an entity
7759 if Is_Entity_Name (Expr) then
7760 Ent := Entity (Expr);
7761 return;
7763 -- Check for components
7765 elsif
7766 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component)
7767 then
7768 Expr := Prefix (Expr);
7769 Off := True;
7771 -- Anything else does not need checking
7773 else
7774 return;
7775 end if;
7776 end loop;
7777 end if;
7778 end Find_Overlaid_Entity;
7780 -------------------------
7781 -- Find_Parameter_Type --
7782 -------------------------
7784 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
7785 begin
7786 if Nkind (Param) /= N_Parameter_Specification then
7787 return Empty;
7789 -- For an access parameter, obtain the type from the formal entity
7790 -- itself, because access to subprogram nodes do not carry a type.
7791 -- Shouldn't we always use the formal entity ???
7793 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
7794 return Etype (Defining_Identifier (Param));
7796 else
7797 return Etype (Parameter_Type (Param));
7798 end if;
7799 end Find_Parameter_Type;
7801 -----------------------------------
7802 -- Find_Placement_In_State_Space --
7803 -----------------------------------
7805 procedure Find_Placement_In_State_Space
7806 (Item_Id : Entity_Id;
7807 Placement : out State_Space_Kind;
7808 Pack_Id : out Entity_Id)
7810 Context : Entity_Id;
7812 begin
7813 -- Assume that the item does not appear in the state space of a package
7815 Placement := Not_In_Package;
7816 Pack_Id := Empty;
7818 -- Climb the scope stack and examine the enclosing context
7820 Context := Scope (Item_Id);
7821 while Present (Context) and then Context /= Standard_Standard loop
7822 if Ekind (Context) = E_Package then
7823 Pack_Id := Context;
7825 -- A package body is a cut off point for the traversal as the item
7826 -- cannot be visible to the outside from this point on. Note that
7827 -- this test must be done first as a body is also classified as a
7828 -- private part.
7830 if In_Package_Body (Context) then
7831 Placement := Body_State_Space;
7832 return;
7834 -- The private part of a package is a cut off point for the
7835 -- traversal as the item cannot be visible to the outside from
7836 -- this point on.
7838 elsif In_Private_Part (Context) then
7839 Placement := Private_State_Space;
7840 return;
7842 -- When the item appears in the visible state space of a package,
7843 -- continue to climb the scope stack as this may not be the final
7844 -- state space.
7846 else
7847 Placement := Visible_State_Space;
7849 -- The visible state space of a child unit acts as the proper
7850 -- placement of an item.
7852 if Is_Child_Unit (Context) then
7853 return;
7854 end if;
7855 end if;
7857 -- The item or its enclosing package appear in a construct that has
7858 -- no state space.
7860 else
7861 Placement := Not_In_Package;
7862 return;
7863 end if;
7865 Context := Scope (Context);
7866 end loop;
7867 end Find_Placement_In_State_Space;
7869 ------------------------
7870 -- Find_Specific_Type --
7871 ------------------------
7873 function Find_Specific_Type (CW : Entity_Id) return Entity_Id is
7874 Typ : Entity_Id := Root_Type (CW);
7876 begin
7877 if Ekind (Typ) = E_Incomplete_Type then
7878 if From_Limited_With (Typ) then
7879 Typ := Non_Limited_View (Typ);
7880 else
7881 Typ := Full_View (Typ);
7882 end if;
7883 end if;
7885 if Is_Private_Type (Typ)
7886 and then not Is_Tagged_Type (Typ)
7887 and then Present (Full_View (Typ))
7888 then
7889 return Full_View (Typ);
7890 else
7891 return Typ;
7892 end if;
7893 end Find_Specific_Type;
7895 -----------------------------
7896 -- Find_Static_Alternative --
7897 -----------------------------
7899 function Find_Static_Alternative (N : Node_Id) return Node_Id is
7900 Expr : constant Node_Id := Expression (N);
7901 Val : constant Uint := Expr_Value (Expr);
7902 Alt : Node_Id;
7903 Choice : Node_Id;
7905 begin
7906 Alt := First (Alternatives (N));
7908 Search : loop
7909 if Nkind (Alt) /= N_Pragma then
7910 Choice := First (Discrete_Choices (Alt));
7911 while Present (Choice) loop
7913 -- Others choice, always matches
7915 if Nkind (Choice) = N_Others_Choice then
7916 exit Search;
7918 -- Range, check if value is in the range
7920 elsif Nkind (Choice) = N_Range then
7921 exit Search when
7922 Val >= Expr_Value (Low_Bound (Choice))
7923 and then
7924 Val <= Expr_Value (High_Bound (Choice));
7926 -- Choice is a subtype name. Note that we know it must
7927 -- be a static subtype, since otherwise it would have
7928 -- been diagnosed as illegal.
7930 elsif Is_Entity_Name (Choice)
7931 and then Is_Type (Entity (Choice))
7932 then
7933 exit Search when Is_In_Range (Expr, Etype (Choice),
7934 Assume_Valid => False);
7936 -- Choice is a subtype indication
7938 elsif Nkind (Choice) = N_Subtype_Indication then
7939 declare
7940 C : constant Node_Id := Constraint (Choice);
7941 R : constant Node_Id := Range_Expression (C);
7943 begin
7944 exit Search when
7945 Val >= Expr_Value (Low_Bound (R))
7946 and then
7947 Val <= Expr_Value (High_Bound (R));
7948 end;
7950 -- Choice is a simple expression
7952 else
7953 exit Search when Val = Expr_Value (Choice);
7954 end if;
7956 Next (Choice);
7957 end loop;
7958 end if;
7960 Next (Alt);
7961 pragma Assert (Present (Alt));
7962 end loop Search;
7964 -- The above loop *must* terminate by finding a match, since we know the
7965 -- case statement is valid, and the value of the expression is known at
7966 -- compile time. When we fall out of the loop, Alt points to the
7967 -- alternative that we know will be selected at run time.
7969 return Alt;
7970 end Find_Static_Alternative;
7972 ------------------
7973 -- First_Actual --
7974 ------------------
7976 function First_Actual (Node : Node_Id) return Node_Id is
7977 N : Node_Id;
7979 begin
7980 if No (Parameter_Associations (Node)) then
7981 return Empty;
7982 end if;
7984 N := First (Parameter_Associations (Node));
7986 if Nkind (N) = N_Parameter_Association then
7987 return First_Named_Actual (Node);
7988 else
7989 return N;
7990 end if;
7991 end First_Actual;
7993 -------------
7994 -- Fix_Msg --
7995 -------------
7997 function Fix_Msg (Id : Entity_Id; Msg : String) return String is
7998 Is_Task : constant Boolean :=
7999 Ekind_In (Id, E_Task_Body, E_Task_Type)
8000 or else Is_Single_Task_Object (Id);
8001 Msg_Last : constant Natural := Msg'Last;
8002 Msg_Index : Natural;
8003 Res : String (Msg'Range) := (others => ' ');
8004 Res_Index : Natural;
8006 begin
8007 -- Copy all characters from the input message Msg to result Res with
8008 -- suitable replacements.
8010 Msg_Index := Msg'First;
8011 Res_Index := Res'First;
8012 while Msg_Index <= Msg_Last loop
8014 -- Replace "subprogram" with a different word
8016 if Msg_Index <= Msg_Last - 10
8017 and then Msg (Msg_Index .. Msg_Index + 9) = "subprogram"
8018 then
8019 if Ekind_In (Id, E_Entry, E_Entry_Family) then
8020 Res (Res_Index .. Res_Index + 4) := "entry";
8021 Res_Index := Res_Index + 5;
8023 elsif Is_Task then
8024 Res (Res_Index .. Res_Index + 8) := "task type";
8025 Res_Index := Res_Index + 9;
8027 else
8028 Res (Res_Index .. Res_Index + 9) := "subprogram";
8029 Res_Index := Res_Index + 10;
8030 end if;
8032 Msg_Index := Msg_Index + 10;
8034 -- Replace "protected" with a different word
8036 elsif Msg_Index <= Msg_Last - 9
8037 and then Msg (Msg_Index .. Msg_Index + 8) = "protected"
8038 and then Is_Task
8039 then
8040 Res (Res_Index .. Res_Index + 3) := "task";
8041 Res_Index := Res_Index + 4;
8042 Msg_Index := Msg_Index + 9;
8044 -- Otherwise copy the character
8046 else
8047 Res (Res_Index) := Msg (Msg_Index);
8048 Msg_Index := Msg_Index + 1;
8049 Res_Index := Res_Index + 1;
8050 end if;
8051 end loop;
8053 return Res (Res'First .. Res_Index - 1);
8054 end Fix_Msg;
8056 -------------------------
8057 -- From_Nested_Package --
8058 -------------------------
8060 function From_Nested_Package (T : Entity_Id) return Boolean is
8061 Pack : constant Entity_Id := Scope (T);
8063 begin
8064 return
8065 Ekind (Pack) = E_Package
8066 and then not Is_Frozen (Pack)
8067 and then not Scope_Within_Or_Same (Current_Scope, Pack)
8068 and then In_Open_Scopes (Scope (Pack));
8069 end From_Nested_Package;
8071 -----------------------
8072 -- Gather_Components --
8073 -----------------------
8075 procedure Gather_Components
8076 (Typ : Entity_Id;
8077 Comp_List : Node_Id;
8078 Governed_By : List_Id;
8079 Into : Elist_Id;
8080 Report_Errors : out Boolean)
8082 Assoc : Node_Id;
8083 Variant : Node_Id;
8084 Discrete_Choice : Node_Id;
8085 Comp_Item : Node_Id;
8087 Discrim : Entity_Id;
8088 Discrim_Name : Node_Id;
8089 Discrim_Value : Node_Id;
8091 begin
8092 Report_Errors := False;
8094 if No (Comp_List) or else Null_Present (Comp_List) then
8095 return;
8097 elsif Present (Component_Items (Comp_List)) then
8098 Comp_Item := First (Component_Items (Comp_List));
8100 else
8101 Comp_Item := Empty;
8102 end if;
8104 while Present (Comp_Item) loop
8106 -- Skip the tag of a tagged record, the interface tags, as well
8107 -- as all items that are not user components (anonymous types,
8108 -- rep clauses, Parent field, controller field).
8110 if Nkind (Comp_Item) = N_Component_Declaration then
8111 declare
8112 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
8113 begin
8114 if not Is_Tag (Comp) and then Chars (Comp) /= Name_uParent then
8115 Append_Elmt (Comp, Into);
8116 end if;
8117 end;
8118 end if;
8120 Next (Comp_Item);
8121 end loop;
8123 if No (Variant_Part (Comp_List)) then
8124 return;
8125 else
8126 Discrim_Name := Name (Variant_Part (Comp_List));
8127 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
8128 end if;
8130 -- Look for the discriminant that governs this variant part.
8131 -- The discriminant *must* be in the Governed_By List
8133 Assoc := First (Governed_By);
8134 Find_Constraint : loop
8135 Discrim := First (Choices (Assoc));
8136 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
8137 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
8138 and then
8139 Chars (Corresponding_Discriminant (Entity (Discrim))) =
8140 Chars (Discrim_Name))
8141 or else Chars (Original_Record_Component (Entity (Discrim)))
8142 = Chars (Discrim_Name);
8144 if No (Next (Assoc)) then
8145 if not Is_Constrained (Typ)
8146 and then Is_Derived_Type (Typ)
8147 and then Present (Stored_Constraint (Typ))
8148 then
8149 -- If the type is a tagged type with inherited discriminants,
8150 -- use the stored constraint on the parent in order to find
8151 -- the values of discriminants that are otherwise hidden by an
8152 -- explicit constraint. Renamed discriminants are handled in
8153 -- the code above.
8155 -- If several parent discriminants are renamed by a single
8156 -- discriminant of the derived type, the call to obtain the
8157 -- Corresponding_Discriminant field only retrieves the last
8158 -- of them. We recover the constraint on the others from the
8159 -- Stored_Constraint as well.
8161 declare
8162 D : Entity_Id;
8163 C : Elmt_Id;
8165 begin
8166 D := First_Discriminant (Etype (Typ));
8167 C := First_Elmt (Stored_Constraint (Typ));
8168 while Present (D) and then Present (C) loop
8169 if Chars (Discrim_Name) = Chars (D) then
8170 if Is_Entity_Name (Node (C))
8171 and then Entity (Node (C)) = Entity (Discrim)
8172 then
8173 -- D is renamed by Discrim, whose value is given in
8174 -- Assoc.
8176 null;
8178 else
8179 Assoc :=
8180 Make_Component_Association (Sloc (Typ),
8181 New_List
8182 (New_Occurrence_Of (D, Sloc (Typ))),
8183 Duplicate_Subexpr_No_Checks (Node (C)));
8184 end if;
8185 exit Find_Constraint;
8186 end if;
8188 Next_Discriminant (D);
8189 Next_Elmt (C);
8190 end loop;
8191 end;
8192 end if;
8193 end if;
8195 if No (Next (Assoc)) then
8196 Error_Msg_NE (" missing value for discriminant&",
8197 First (Governed_By), Discrim_Name);
8198 Report_Errors := True;
8199 return;
8200 end if;
8202 Next (Assoc);
8203 end loop Find_Constraint;
8205 Discrim_Value := Expression (Assoc);
8207 if not Is_OK_Static_Expression (Discrim_Value) then
8209 -- If the variant part is governed by a discriminant of the type
8210 -- this is an error. If the variant part and the discriminant are
8211 -- inherited from an ancestor this is legal (AI05-120) unless the
8212 -- components are being gathered for an aggregate, in which case
8213 -- the caller must check Report_Errors.
8215 if Scope (Original_Record_Component
8216 ((Entity (First (Choices (Assoc)))))) = Typ
8217 then
8218 Error_Msg_FE
8219 ("value for discriminant & must be static!",
8220 Discrim_Value, Discrim);
8221 Why_Not_Static (Discrim_Value);
8222 end if;
8224 Report_Errors := True;
8225 return;
8226 end if;
8228 Search_For_Discriminant_Value : declare
8229 Low : Node_Id;
8230 High : Node_Id;
8232 UI_High : Uint;
8233 UI_Low : Uint;
8234 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
8236 begin
8237 Find_Discrete_Value : while Present (Variant) loop
8238 Discrete_Choice := First (Discrete_Choices (Variant));
8239 while Present (Discrete_Choice) loop
8240 exit Find_Discrete_Value when
8241 Nkind (Discrete_Choice) = N_Others_Choice;
8243 Get_Index_Bounds (Discrete_Choice, Low, High);
8245 UI_Low := Expr_Value (Low);
8246 UI_High := Expr_Value (High);
8248 exit Find_Discrete_Value when
8249 UI_Low <= UI_Discrim_Value
8250 and then
8251 UI_High >= UI_Discrim_Value;
8253 Next (Discrete_Choice);
8254 end loop;
8256 Next_Non_Pragma (Variant);
8257 end loop Find_Discrete_Value;
8258 end Search_For_Discriminant_Value;
8260 -- The case statement must include a variant that corresponds to the
8261 -- value of the discriminant, unless the discriminant type has a
8262 -- static predicate. In that case the absence of an others_choice that
8263 -- would cover this value becomes a run-time error (3.8,1 (21.1/2)).
8265 if No (Variant)
8266 and then not Has_Static_Predicate (Etype (Discrim_Name))
8267 then
8268 Error_Msg_NE
8269 ("value of discriminant & is out of range", Discrim_Value, Discrim);
8270 Report_Errors := True;
8271 return;
8272 end if;
8274 -- If we have found the corresponding choice, recursively add its
8275 -- components to the Into list. The nested components are part of
8276 -- the same record type.
8278 if Present (Variant) then
8279 Gather_Components
8280 (Typ, Component_List (Variant), Governed_By, Into, Report_Errors);
8281 end if;
8282 end Gather_Components;
8284 ------------------------
8285 -- Get_Actual_Subtype --
8286 ------------------------
8288 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
8289 Typ : constant Entity_Id := Etype (N);
8290 Utyp : Entity_Id := Underlying_Type (Typ);
8291 Decl : Node_Id;
8292 Atyp : Entity_Id;
8294 begin
8295 if No (Utyp) then
8296 Utyp := Typ;
8297 end if;
8299 -- If what we have is an identifier that references a subprogram
8300 -- formal, or a variable or constant object, then we get the actual
8301 -- subtype from the referenced entity if one has been built.
8303 if Nkind (N) = N_Identifier
8304 and then
8305 (Is_Formal (Entity (N))
8306 or else Ekind (Entity (N)) = E_Constant
8307 or else Ekind (Entity (N)) = E_Variable)
8308 and then Present (Actual_Subtype (Entity (N)))
8309 then
8310 return Actual_Subtype (Entity (N));
8312 -- Actual subtype of unchecked union is always itself. We never need
8313 -- the "real" actual subtype. If we did, we couldn't get it anyway
8314 -- because the discriminant is not available. The restrictions on
8315 -- Unchecked_Union are designed to make sure that this is OK.
8317 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
8318 return Typ;
8320 -- Here for the unconstrained case, we must find actual subtype
8321 -- No actual subtype is available, so we must build it on the fly.
8323 -- Checking the type, not the underlying type, for constrainedness
8324 -- seems to be necessary. Maybe all the tests should be on the type???
8326 elsif (not Is_Constrained (Typ))
8327 and then (Is_Array_Type (Utyp)
8328 or else (Is_Record_Type (Utyp)
8329 and then Has_Discriminants (Utyp)))
8330 and then not Has_Unknown_Discriminants (Utyp)
8331 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
8332 then
8333 -- Nothing to do if in spec expression (why not???)
8335 if In_Spec_Expression then
8336 return Typ;
8338 elsif Is_Private_Type (Typ) and then not Has_Discriminants (Typ) then
8340 -- If the type has no discriminants, there is no subtype to
8341 -- build, even if the underlying type is discriminated.
8343 return Typ;
8345 -- Else build the actual subtype
8347 else
8348 Decl := Build_Actual_Subtype (Typ, N);
8349 Atyp := Defining_Identifier (Decl);
8351 -- If Build_Actual_Subtype generated a new declaration then use it
8353 if Atyp /= Typ then
8355 -- The actual subtype is an Itype, so analyze the declaration,
8356 -- but do not attach it to the tree, to get the type defined.
8358 Set_Parent (Decl, N);
8359 Set_Is_Itype (Atyp);
8360 Analyze (Decl, Suppress => All_Checks);
8361 Set_Associated_Node_For_Itype (Atyp, N);
8362 Set_Has_Delayed_Freeze (Atyp, False);
8364 -- We need to freeze the actual subtype immediately. This is
8365 -- needed, because otherwise this Itype will not get frozen
8366 -- at all, and it is always safe to freeze on creation because
8367 -- any associated types must be frozen at this point.
8369 Freeze_Itype (Atyp, N);
8370 return Atyp;
8372 -- Otherwise we did not build a declaration, so return original
8374 else
8375 return Typ;
8376 end if;
8377 end if;
8379 -- For all remaining cases, the actual subtype is the same as
8380 -- the nominal type.
8382 else
8383 return Typ;
8384 end if;
8385 end Get_Actual_Subtype;
8387 -------------------------------------
8388 -- Get_Actual_Subtype_If_Available --
8389 -------------------------------------
8391 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
8392 Typ : constant Entity_Id := Etype (N);
8394 begin
8395 -- If what we have is an identifier that references a subprogram
8396 -- formal, or a variable or constant object, then we get the actual
8397 -- subtype from the referenced entity if one has been built.
8399 if Nkind (N) = N_Identifier
8400 and then
8401 (Is_Formal (Entity (N))
8402 or else Ekind (Entity (N)) = E_Constant
8403 or else Ekind (Entity (N)) = E_Variable)
8404 and then Present (Actual_Subtype (Entity (N)))
8405 then
8406 return Actual_Subtype (Entity (N));
8408 -- Otherwise the Etype of N is returned unchanged
8410 else
8411 return Typ;
8412 end if;
8413 end Get_Actual_Subtype_If_Available;
8415 ------------------------
8416 -- Get_Body_From_Stub --
8417 ------------------------
8419 function Get_Body_From_Stub (N : Node_Id) return Node_Id is
8420 begin
8421 return Proper_Body (Unit (Library_Unit (N)));
8422 end Get_Body_From_Stub;
8424 ---------------------
8425 -- Get_Cursor_Type --
8426 ---------------------
8428 function Get_Cursor_Type
8429 (Aspect : Node_Id;
8430 Typ : Entity_Id) return Entity_Id
8432 Assoc : Node_Id;
8433 Func : Entity_Id;
8434 First_Op : Entity_Id;
8435 Cursor : Entity_Id;
8437 begin
8438 -- If error already detected, return
8440 if Error_Posted (Aspect) then
8441 return Any_Type;
8442 end if;
8444 -- The cursor type for an Iterable aspect is the return type of a
8445 -- non-overloaded First primitive operation. Locate association for
8446 -- First.
8448 Assoc := First (Component_Associations (Expression (Aspect)));
8449 First_Op := Any_Id;
8450 while Present (Assoc) loop
8451 if Chars (First (Choices (Assoc))) = Name_First then
8452 First_Op := Expression (Assoc);
8453 exit;
8454 end if;
8456 Next (Assoc);
8457 end loop;
8459 if First_Op = Any_Id then
8460 Error_Msg_N ("aspect Iterable must specify First operation", Aspect);
8461 return Any_Type;
8462 end if;
8464 Cursor := Any_Type;
8466 -- Locate function with desired name and profile in scope of type
8467 -- In the rare case where the type is an integer type, a base type
8468 -- is created for it, check that the base type of the first formal
8469 -- of First matches the base type of the domain.
8471 Func := First_Entity (Scope (Typ));
8472 while Present (Func) loop
8473 if Chars (Func) = Chars (First_Op)
8474 and then Ekind (Func) = E_Function
8475 and then Present (First_Formal (Func))
8476 and then Base_Type (Etype (First_Formal (Func))) = Base_Type (Typ)
8477 and then No (Next_Formal (First_Formal (Func)))
8478 then
8479 if Cursor /= Any_Type then
8480 Error_Msg_N
8481 ("Operation First for iterable type must be unique", Aspect);
8482 return Any_Type;
8483 else
8484 Cursor := Etype (Func);
8485 end if;
8486 end if;
8488 Next_Entity (Func);
8489 end loop;
8491 -- If not found, no way to resolve remaining primitives.
8493 if Cursor = Any_Type then
8494 Error_Msg_N
8495 ("No legal primitive operation First for Iterable type", Aspect);
8496 end if;
8498 return Cursor;
8499 end Get_Cursor_Type;
8501 function Get_Cursor_Type (Typ : Entity_Id) return Entity_Id is
8502 begin
8503 return Etype (Get_Iterable_Type_Primitive (Typ, Name_First));
8504 end Get_Cursor_Type;
8506 -------------------------------
8507 -- Get_Default_External_Name --
8508 -------------------------------
8510 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
8511 begin
8512 Get_Decoded_Name_String (Chars (E));
8514 if Opt.External_Name_Imp_Casing = Uppercase then
8515 Set_Casing (All_Upper_Case);
8516 else
8517 Set_Casing (All_Lower_Case);
8518 end if;
8520 return
8521 Make_String_Literal (Sloc (E),
8522 Strval => String_From_Name_Buffer);
8523 end Get_Default_External_Name;
8525 --------------------------
8526 -- Get_Enclosing_Object --
8527 --------------------------
8529 function Get_Enclosing_Object (N : Node_Id) return Entity_Id is
8530 begin
8531 if Is_Entity_Name (N) then
8532 return Entity (N);
8533 else
8534 case Nkind (N) is
8535 when N_Indexed_Component
8536 | N_Selected_Component
8537 | N_Slice
8539 -- If not generating code, a dereference may be left implicit.
8540 -- In thoses cases, return Empty.
8542 if Is_Access_Type (Etype (Prefix (N))) then
8543 return Empty;
8544 else
8545 return Get_Enclosing_Object (Prefix (N));
8546 end if;
8548 when N_Type_Conversion =>
8549 return Get_Enclosing_Object (Expression (N));
8551 when others =>
8552 return Empty;
8553 end case;
8554 end if;
8555 end Get_Enclosing_Object;
8557 ---------------------------
8558 -- Get_Enum_Lit_From_Pos --
8559 ---------------------------
8561 function Get_Enum_Lit_From_Pos
8562 (T : Entity_Id;
8563 Pos : Uint;
8564 Loc : Source_Ptr) return Node_Id
8566 Btyp : Entity_Id := Base_Type (T);
8567 Lit : Node_Id;
8568 LLoc : Source_Ptr;
8570 begin
8571 -- In the case where the literal is of type Character, Wide_Character
8572 -- or Wide_Wide_Character or of a type derived from them, there needs
8573 -- to be some special handling since there is no explicit chain of
8574 -- literals to search. Instead, an N_Character_Literal node is created
8575 -- with the appropriate Char_Code and Chars fields.
8577 if Is_Standard_Character_Type (T) then
8578 Set_Character_Literal_Name (UI_To_CC (Pos));
8580 return
8581 Make_Character_Literal (Loc,
8582 Chars => Name_Find,
8583 Char_Literal_Value => Pos);
8585 -- For all other cases, we have a complete table of literals, and
8586 -- we simply iterate through the chain of literal until the one
8587 -- with the desired position value is found.
8589 else
8590 if Is_Private_Type (Btyp) and then Present (Full_View (Btyp)) then
8591 Btyp := Full_View (Btyp);
8592 end if;
8594 Lit := First_Literal (Btyp);
8595 for J in 1 .. UI_To_Int (Pos) loop
8596 Next_Literal (Lit);
8598 -- If Lit is Empty, Pos is not in range, so raise Constraint_Error
8599 -- inside the loop to avoid calling Next_Literal on Empty.
8601 if No (Lit) then
8602 raise Constraint_Error;
8603 end if;
8604 end loop;
8606 -- Create a new node from Lit, with source location provided by Loc
8607 -- if not equal to No_Location, or by copying the source location of
8608 -- Lit otherwise.
8610 LLoc := Loc;
8612 if LLoc = No_Location then
8613 LLoc := Sloc (Lit);
8614 end if;
8616 return New_Occurrence_Of (Lit, LLoc);
8617 end if;
8618 end Get_Enum_Lit_From_Pos;
8620 ------------------------
8621 -- Get_Generic_Entity --
8622 ------------------------
8624 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
8625 Ent : constant Entity_Id := Entity (Name (N));
8626 begin
8627 if Present (Renamed_Object (Ent)) then
8628 return Renamed_Object (Ent);
8629 else
8630 return Ent;
8631 end if;
8632 end Get_Generic_Entity;
8634 -------------------------------------
8635 -- Get_Incomplete_View_Of_Ancestor --
8636 -------------------------------------
8638 function Get_Incomplete_View_Of_Ancestor (E : Entity_Id) return Entity_Id is
8639 Cur_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
8640 Par_Scope : Entity_Id;
8641 Par_Type : Entity_Id;
8643 begin
8644 -- The incomplete view of an ancestor is only relevant for private
8645 -- derived types in child units.
8647 if not Is_Derived_Type (E)
8648 or else not Is_Child_Unit (Cur_Unit)
8649 then
8650 return Empty;
8652 else
8653 Par_Scope := Scope (Cur_Unit);
8654 if No (Par_Scope) then
8655 return Empty;
8656 end if;
8658 Par_Type := Etype (Base_Type (E));
8660 -- Traverse list of ancestor types until we find one declared in
8661 -- a parent or grandparent unit (two levels seem sufficient).
8663 while Present (Par_Type) loop
8664 if Scope (Par_Type) = Par_Scope
8665 or else Scope (Par_Type) = Scope (Par_Scope)
8666 then
8667 return Par_Type;
8669 elsif not Is_Derived_Type (Par_Type) then
8670 return Empty;
8672 else
8673 Par_Type := Etype (Base_Type (Par_Type));
8674 end if;
8675 end loop;
8677 -- If none found, there is no relevant ancestor type.
8679 return Empty;
8680 end if;
8681 end Get_Incomplete_View_Of_Ancestor;
8683 ----------------------
8684 -- Get_Index_Bounds --
8685 ----------------------
8687 procedure Get_Index_Bounds
8688 (N : Node_Id;
8689 L : out Node_Id;
8690 H : out Node_Id;
8691 Use_Full_View : Boolean := False)
8693 function Scalar_Range_Of_Type (Typ : Entity_Id) return Node_Id;
8694 -- Obtain the scalar range of type Typ. If flag Use_Full_View is set and
8695 -- Typ qualifies, the scalar range is obtained from the full view of the
8696 -- type.
8698 --------------------------
8699 -- Scalar_Range_Of_Type --
8700 --------------------------
8702 function Scalar_Range_Of_Type (Typ : Entity_Id) return Node_Id is
8703 T : Entity_Id := Typ;
8705 begin
8706 if Use_Full_View and then Present (Full_View (T)) then
8707 T := Full_View (T);
8708 end if;
8710 return Scalar_Range (T);
8711 end Scalar_Range_Of_Type;
8713 -- Local variables
8715 Kind : constant Node_Kind := Nkind (N);
8716 Rng : Node_Id;
8718 -- Start of processing for Get_Index_Bounds
8720 begin
8721 if Kind = N_Range then
8722 L := Low_Bound (N);
8723 H := High_Bound (N);
8725 elsif Kind = N_Subtype_Indication then
8726 Rng := Range_Expression (Constraint (N));
8728 if Rng = Error then
8729 L := Error;
8730 H := Error;
8731 return;
8733 else
8734 L := Low_Bound (Range_Expression (Constraint (N)));
8735 H := High_Bound (Range_Expression (Constraint (N)));
8736 end if;
8738 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
8739 Rng := Scalar_Range_Of_Type (Entity (N));
8741 if Error_Posted (Rng) then
8742 L := Error;
8743 H := Error;
8745 elsif Nkind (Rng) = N_Subtype_Indication then
8746 Get_Index_Bounds (Rng, L, H);
8748 else
8749 L := Low_Bound (Rng);
8750 H := High_Bound (Rng);
8751 end if;
8753 else
8754 -- N is an expression, indicating a range with one value
8756 L := N;
8757 H := N;
8758 end if;
8759 end Get_Index_Bounds;
8761 -----------------------------
8762 -- Get_Interfacing_Aspects --
8763 -----------------------------
8765 procedure Get_Interfacing_Aspects
8766 (Iface_Asp : Node_Id;
8767 Conv_Asp : out Node_Id;
8768 EN_Asp : out Node_Id;
8769 Expo_Asp : out Node_Id;
8770 Imp_Asp : out Node_Id;
8771 LN_Asp : out Node_Id;
8772 Do_Checks : Boolean := False)
8774 procedure Save_Or_Duplication_Error
8775 (Asp : Node_Id;
8776 To : in out Node_Id);
8777 -- Save the value of aspect Asp in node To. If To already has a value,
8778 -- then this is considered a duplicate use of aspect. Emit an error if
8779 -- flag Do_Checks is set.
8781 -------------------------------
8782 -- Save_Or_Duplication_Error --
8783 -------------------------------
8785 procedure Save_Or_Duplication_Error
8786 (Asp : Node_Id;
8787 To : in out Node_Id)
8789 begin
8790 -- Detect an extra aspect and issue an error
8792 if Present (To) then
8793 if Do_Checks then
8794 Error_Msg_Name_1 := Chars (Identifier (Asp));
8795 Error_Msg_Sloc := Sloc (To);
8796 Error_Msg_N ("aspect % previously given #", Asp);
8797 end if;
8799 -- Otherwise capture the aspect
8801 else
8802 To := Asp;
8803 end if;
8804 end Save_Or_Duplication_Error;
8806 -- Local variables
8808 Asp : Node_Id;
8809 Asp_Id : Aspect_Id;
8811 -- The following variables capture each individual aspect
8813 Conv : Node_Id := Empty;
8814 EN : Node_Id := Empty;
8815 Expo : Node_Id := Empty;
8816 Imp : Node_Id := Empty;
8817 LN : Node_Id := Empty;
8819 -- Start of processing for Get_Interfacing_Aspects
8821 begin
8822 -- The input interfacing aspect should reside in an aspect specification
8823 -- list.
8825 pragma Assert (Is_List_Member (Iface_Asp));
8827 -- Examine the aspect specifications of the related entity. Find and
8828 -- capture all interfacing aspects. Detect duplicates and emit errors
8829 -- if applicable.
8831 Asp := First (List_Containing (Iface_Asp));
8832 while Present (Asp) loop
8833 Asp_Id := Get_Aspect_Id (Asp);
8835 if Asp_Id = Aspect_Convention then
8836 Save_Or_Duplication_Error (Asp, Conv);
8838 elsif Asp_Id = Aspect_External_Name then
8839 Save_Or_Duplication_Error (Asp, EN);
8841 elsif Asp_Id = Aspect_Export then
8842 Save_Or_Duplication_Error (Asp, Expo);
8844 elsif Asp_Id = Aspect_Import then
8845 Save_Or_Duplication_Error (Asp, Imp);
8847 elsif Asp_Id = Aspect_Link_Name then
8848 Save_Or_Duplication_Error (Asp, LN);
8849 end if;
8851 Next (Asp);
8852 end loop;
8854 Conv_Asp := Conv;
8855 EN_Asp := EN;
8856 Expo_Asp := Expo;
8857 Imp_Asp := Imp;
8858 LN_Asp := LN;
8859 end Get_Interfacing_Aspects;
8861 ---------------------------------
8862 -- Get_Iterable_Type_Primitive --
8863 ---------------------------------
8865 function Get_Iterable_Type_Primitive
8866 (Typ : Entity_Id;
8867 Nam : Name_Id) return Entity_Id
8869 Funcs : constant Node_Id := Find_Value_Of_Aspect (Typ, Aspect_Iterable);
8870 Assoc : Node_Id;
8872 begin
8873 if No (Funcs) then
8874 return Empty;
8876 else
8877 Assoc := First (Component_Associations (Funcs));
8878 while Present (Assoc) loop
8879 if Chars (First (Choices (Assoc))) = Nam then
8880 return Entity (Expression (Assoc));
8881 end if;
8883 Assoc := Next (Assoc);
8884 end loop;
8886 return Empty;
8887 end if;
8888 end Get_Iterable_Type_Primitive;
8890 ----------------------------------
8891 -- Get_Library_Unit_Name_string --
8892 ----------------------------------
8894 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
8895 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
8897 begin
8898 Get_Unit_Name_String (Unit_Name_Id);
8900 -- Remove seven last character (" (spec)" or " (body)")
8902 Name_Len := Name_Len - 7;
8903 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
8904 end Get_Library_Unit_Name_String;
8906 --------------------------
8907 -- Get_Max_Queue_Length --
8908 --------------------------
8910 function Get_Max_Queue_Length (Id : Entity_Id) return Uint is
8911 pragma Assert (Is_Entry (Id));
8912 Prag : constant Entity_Id := Get_Pragma (Id, Pragma_Max_Queue_Length);
8914 begin
8915 -- A value of 0 represents no maximum specified, and entries and entry
8916 -- families with no Max_Queue_Length aspect or pragma default to it.
8918 if not Present (Prag) then
8919 return Uint_0;
8920 end if;
8922 return Intval (Expression (First (Pragma_Argument_Associations (Prag))));
8923 end Get_Max_Queue_Length;
8925 ------------------------
8926 -- Get_Name_Entity_Id --
8927 ------------------------
8929 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
8930 begin
8931 return Entity_Id (Get_Name_Table_Int (Id));
8932 end Get_Name_Entity_Id;
8934 ------------------------------
8935 -- Get_Name_From_CTC_Pragma --
8936 ------------------------------
8938 function Get_Name_From_CTC_Pragma (N : Node_Id) return String_Id is
8939 Arg : constant Node_Id :=
8940 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
8941 begin
8942 return Strval (Expr_Value_S (Arg));
8943 end Get_Name_From_CTC_Pragma;
8945 -----------------------
8946 -- Get_Parent_Entity --
8947 -----------------------
8949 function Get_Parent_Entity (Unit : Node_Id) return Entity_Id is
8950 begin
8951 if Nkind (Unit) = N_Package_Body
8952 and then Nkind (Original_Node (Unit)) = N_Package_Instantiation
8953 then
8954 return Defining_Entity
8955 (Specification (Instance_Spec (Original_Node (Unit))));
8956 elsif Nkind (Unit) = N_Package_Instantiation then
8957 return Defining_Entity (Specification (Instance_Spec (Unit)));
8958 else
8959 return Defining_Entity (Unit);
8960 end if;
8961 end Get_Parent_Entity;
8963 -------------------
8964 -- Get_Pragma_Id --
8965 -------------------
8967 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
8968 begin
8969 return Get_Pragma_Id (Pragma_Name_Unmapped (N));
8970 end Get_Pragma_Id;
8972 ------------------------
8973 -- Get_Qualified_Name --
8974 ------------------------
8976 function Get_Qualified_Name
8977 (Id : Entity_Id;
8978 Suffix : Entity_Id := Empty) return Name_Id
8980 Suffix_Nam : Name_Id := No_Name;
8982 begin
8983 if Present (Suffix) then
8984 Suffix_Nam := Chars (Suffix);
8985 end if;
8987 return Get_Qualified_Name (Chars (Id), Suffix_Nam, Scope (Id));
8988 end Get_Qualified_Name;
8990 function Get_Qualified_Name
8991 (Nam : Name_Id;
8992 Suffix : Name_Id := No_Name;
8993 Scop : Entity_Id := Current_Scope) return Name_Id
8995 procedure Add_Scope (S : Entity_Id);
8996 -- Add the fully qualified form of scope S to the name buffer. The
8997 -- format is:
8998 -- s-1__s__
9000 ---------------
9001 -- Add_Scope --
9002 ---------------
9004 procedure Add_Scope (S : Entity_Id) is
9005 begin
9006 if S = Empty then
9007 null;
9009 elsif S = Standard_Standard then
9010 null;
9012 else
9013 Add_Scope (Scope (S));
9014 Get_Name_String_And_Append (Chars (S));
9015 Add_Str_To_Name_Buffer ("__");
9016 end if;
9017 end Add_Scope;
9019 -- Start of processing for Get_Qualified_Name
9021 begin
9022 Name_Len := 0;
9023 Add_Scope (Scop);
9025 -- Append the base name after all scopes have been chained
9027 Get_Name_String_And_Append (Nam);
9029 -- Append the suffix (if present)
9031 if Suffix /= No_Name then
9032 Add_Str_To_Name_Buffer ("__");
9033 Get_Name_String_And_Append (Suffix);
9034 end if;
9036 return Name_Find;
9037 end Get_Qualified_Name;
9039 -----------------------
9040 -- Get_Reason_String --
9041 -----------------------
9043 procedure Get_Reason_String (N : Node_Id) is
9044 begin
9045 if Nkind (N) = N_String_Literal then
9046 Store_String_Chars (Strval (N));
9048 elsif Nkind (N) = N_Op_Concat then
9049 Get_Reason_String (Left_Opnd (N));
9050 Get_Reason_String (Right_Opnd (N));
9052 -- If not of required form, error
9054 else
9055 Error_Msg_N
9056 ("Reason for pragma Warnings has wrong form", N);
9057 Error_Msg_N
9058 ("\must be string literal or concatenation of string literals", N);
9059 return;
9060 end if;
9061 end Get_Reason_String;
9063 --------------------------------
9064 -- Get_Reference_Discriminant --
9065 --------------------------------
9067 function Get_Reference_Discriminant (Typ : Entity_Id) return Entity_Id is
9068 D : Entity_Id;
9070 begin
9071 D := First_Discriminant (Typ);
9072 while Present (D) loop
9073 if Has_Implicit_Dereference (D) then
9074 return D;
9075 end if;
9076 Next_Discriminant (D);
9077 end loop;
9079 return Empty;
9080 end Get_Reference_Discriminant;
9082 ---------------------------
9083 -- Get_Referenced_Object --
9084 ---------------------------
9086 function Get_Referenced_Object (N : Node_Id) return Node_Id is
9087 R : Node_Id;
9089 begin
9090 R := N;
9091 while Is_Entity_Name (R)
9092 and then Present (Renamed_Object (Entity (R)))
9093 loop
9094 R := Renamed_Object (Entity (R));
9095 end loop;
9097 return R;
9098 end Get_Referenced_Object;
9100 ------------------------
9101 -- Get_Renamed_Entity --
9102 ------------------------
9104 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
9105 R : Entity_Id;
9107 begin
9108 R := E;
9109 while Present (Renamed_Entity (R)) loop
9110 R := Renamed_Entity (R);
9111 end loop;
9113 return R;
9114 end Get_Renamed_Entity;
9116 -----------------------
9117 -- Get_Return_Object --
9118 -----------------------
9120 function Get_Return_Object (N : Node_Id) return Entity_Id is
9121 Decl : Node_Id;
9123 begin
9124 Decl := First (Return_Object_Declarations (N));
9125 while Present (Decl) loop
9126 exit when Nkind (Decl) = N_Object_Declaration
9127 and then Is_Return_Object (Defining_Identifier (Decl));
9128 Next (Decl);
9129 end loop;
9131 pragma Assert (Present (Decl));
9132 return Defining_Identifier (Decl);
9133 end Get_Return_Object;
9135 ---------------------------
9136 -- Get_Subprogram_Entity --
9137 ---------------------------
9139 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
9140 Subp : Node_Id;
9141 Subp_Id : Entity_Id;
9143 begin
9144 if Nkind (Nod) = N_Accept_Statement then
9145 Subp := Entry_Direct_Name (Nod);
9147 elsif Nkind (Nod) = N_Slice then
9148 Subp := Prefix (Nod);
9150 else
9151 Subp := Name (Nod);
9152 end if;
9154 -- Strip the subprogram call
9156 loop
9157 if Nkind_In (Subp, N_Explicit_Dereference,
9158 N_Indexed_Component,
9159 N_Selected_Component)
9160 then
9161 Subp := Prefix (Subp);
9163 elsif Nkind_In (Subp, N_Type_Conversion,
9164 N_Unchecked_Type_Conversion)
9165 then
9166 Subp := Expression (Subp);
9168 else
9169 exit;
9170 end if;
9171 end loop;
9173 -- Extract the entity of the subprogram call
9175 if Is_Entity_Name (Subp) then
9176 Subp_Id := Entity (Subp);
9178 if Ekind (Subp_Id) = E_Access_Subprogram_Type then
9179 Subp_Id := Directly_Designated_Type (Subp_Id);
9180 end if;
9182 if Is_Subprogram (Subp_Id) then
9183 return Subp_Id;
9184 else
9185 return Empty;
9186 end if;
9188 -- The search did not find a construct that denotes a subprogram
9190 else
9191 return Empty;
9192 end if;
9193 end Get_Subprogram_Entity;
9195 -----------------------------
9196 -- Get_Task_Body_Procedure --
9197 -----------------------------
9199 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
9200 begin
9201 -- Note: A task type may be the completion of a private type with
9202 -- discriminants. When performing elaboration checks on a task
9203 -- declaration, the current view of the type may be the private one,
9204 -- and the procedure that holds the body of the task is held in its
9205 -- underlying type.
9207 -- This is an odd function, why not have Task_Body_Procedure do
9208 -- the following digging???
9210 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
9211 end Get_Task_Body_Procedure;
9213 -------------------------
9214 -- Get_User_Defined_Eq --
9215 -------------------------
9217 function Get_User_Defined_Eq (E : Entity_Id) return Entity_Id is
9218 Prim : Elmt_Id;
9219 Op : Entity_Id;
9221 begin
9222 Prim := First_Elmt (Collect_Primitive_Operations (E));
9223 while Present (Prim) loop
9224 Op := Node (Prim);
9226 if Chars (Op) = Name_Op_Eq
9227 and then Etype (Op) = Standard_Boolean
9228 and then Etype (First_Formal (Op)) = E
9229 and then Etype (Next_Formal (First_Formal (Op))) = E
9230 then
9231 return Op;
9232 end if;
9234 Next_Elmt (Prim);
9235 end loop;
9237 return Empty;
9238 end Get_User_Defined_Eq;
9240 ---------------
9241 -- Get_Views --
9242 ---------------
9244 procedure Get_Views
9245 (Typ : Entity_Id;
9246 Priv_Typ : out Entity_Id;
9247 Full_Typ : out Entity_Id;
9248 Full_Base : out Entity_Id;
9249 CRec_Typ : out Entity_Id)
9251 IP_View : Entity_Id;
9253 begin
9254 -- Assume that none of the views can be recovered
9256 Priv_Typ := Empty;
9257 Full_Typ := Empty;
9258 Full_Base := Empty;
9259 CRec_Typ := Empty;
9261 -- The input type is the corresponding record type of a protected or a
9262 -- task type.
9264 if Ekind (Typ) = E_Record_Type
9265 and then Is_Concurrent_Record_Type (Typ)
9266 then
9267 CRec_Typ := Typ;
9268 Full_Typ := Corresponding_Concurrent_Type (CRec_Typ);
9269 Full_Base := Base_Type (Full_Typ);
9270 Priv_Typ := Incomplete_Or_Partial_View (Full_Typ);
9272 -- Otherwise the input type denotes an arbitrary type
9274 else
9275 IP_View := Incomplete_Or_Partial_View (Typ);
9277 -- The input type denotes the full view of a private type
9279 if Present (IP_View) then
9280 Priv_Typ := IP_View;
9281 Full_Typ := Typ;
9283 -- The input type is a private type
9285 elsif Is_Private_Type (Typ) then
9286 Priv_Typ := Typ;
9287 Full_Typ := Full_View (Priv_Typ);
9289 -- Otherwise the input type does not have any views
9291 else
9292 Full_Typ := Typ;
9293 end if;
9295 if Present (Full_Typ) then
9296 Full_Base := Base_Type (Full_Typ);
9298 if Ekind_In (Full_Typ, E_Protected_Type, E_Task_Type) then
9299 CRec_Typ := Corresponding_Record_Type (Full_Typ);
9300 end if;
9301 end if;
9302 end if;
9303 end Get_Views;
9305 -----------------------
9306 -- Has_Access_Values --
9307 -----------------------
9309 function Has_Access_Values (T : Entity_Id) return Boolean is
9310 Typ : constant Entity_Id := Underlying_Type (T);
9312 begin
9313 -- Case of a private type which is not completed yet. This can only
9314 -- happen in the case of a generic format type appearing directly, or
9315 -- as a component of the type to which this function is being applied
9316 -- at the top level. Return False in this case, since we certainly do
9317 -- not know that the type contains access types.
9319 if No (Typ) then
9320 return False;
9322 elsif Is_Access_Type (Typ) then
9323 return True;
9325 elsif Is_Array_Type (Typ) then
9326 return Has_Access_Values (Component_Type (Typ));
9328 elsif Is_Record_Type (Typ) then
9329 declare
9330 Comp : Entity_Id;
9332 begin
9333 -- Loop to Check components
9335 Comp := First_Component_Or_Discriminant (Typ);
9336 while Present (Comp) loop
9338 -- Check for access component, tag field does not count, even
9339 -- though it is implemented internally using an access type.
9341 if Has_Access_Values (Etype (Comp))
9342 and then Chars (Comp) /= Name_uTag
9343 then
9344 return True;
9345 end if;
9347 Next_Component_Or_Discriminant (Comp);
9348 end loop;
9349 end;
9351 return False;
9353 else
9354 return False;
9355 end if;
9356 end Has_Access_Values;
9358 ------------------------------
9359 -- Has_Compatible_Alignment --
9360 ------------------------------
9362 function Has_Compatible_Alignment
9363 (Obj : Entity_Id;
9364 Expr : Node_Id;
9365 Layout_Done : Boolean) return Alignment_Result
9367 function Has_Compatible_Alignment_Internal
9368 (Obj : Entity_Id;
9369 Expr : Node_Id;
9370 Layout_Done : Boolean;
9371 Default : Alignment_Result) return Alignment_Result;
9372 -- This is the internal recursive function that actually does the work.
9373 -- There is one additional parameter, which says what the result should
9374 -- be if no alignment information is found, and there is no definite
9375 -- indication of compatible alignments. At the outer level, this is set
9376 -- to Unknown, but for internal recursive calls in the case where types
9377 -- are known to be correct, it is set to Known_Compatible.
9379 ---------------------------------------
9380 -- Has_Compatible_Alignment_Internal --
9381 ---------------------------------------
9383 function Has_Compatible_Alignment_Internal
9384 (Obj : Entity_Id;
9385 Expr : Node_Id;
9386 Layout_Done : Boolean;
9387 Default : Alignment_Result) return Alignment_Result
9389 Result : Alignment_Result := Known_Compatible;
9390 -- Holds the current status of the result. Note that once a value of
9391 -- Known_Incompatible is set, it is sticky and does not get changed
9392 -- to Unknown (the value in Result only gets worse as we go along,
9393 -- never better).
9395 Offs : Uint := No_Uint;
9396 -- Set to a factor of the offset from the base object when Expr is a
9397 -- selected or indexed component, based on Component_Bit_Offset and
9398 -- Component_Size respectively. A negative value is used to represent
9399 -- a value which is not known at compile time.
9401 procedure Check_Prefix;
9402 -- Checks the prefix recursively in the case where the expression
9403 -- is an indexed or selected component.
9405 procedure Set_Result (R : Alignment_Result);
9406 -- If R represents a worse outcome (unknown instead of known
9407 -- compatible, or known incompatible), then set Result to R.
9409 ------------------
9410 -- Check_Prefix --
9411 ------------------
9413 procedure Check_Prefix is
9414 begin
9415 -- The subtlety here is that in doing a recursive call to check
9416 -- the prefix, we have to decide what to do in the case where we
9417 -- don't find any specific indication of an alignment problem.
9419 -- At the outer level, we normally set Unknown as the result in
9420 -- this case, since we can only set Known_Compatible if we really
9421 -- know that the alignment value is OK, but for the recursive
9422 -- call, in the case where the types match, and we have not
9423 -- specified a peculiar alignment for the object, we are only
9424 -- concerned about suspicious rep clauses, the default case does
9425 -- not affect us, since the compiler will, in the absence of such
9426 -- rep clauses, ensure that the alignment is correct.
9428 if Default = Known_Compatible
9429 or else
9430 (Etype (Obj) = Etype (Expr)
9431 and then (Unknown_Alignment (Obj)
9432 or else
9433 Alignment (Obj) = Alignment (Etype (Obj))))
9434 then
9435 Set_Result
9436 (Has_Compatible_Alignment_Internal
9437 (Obj, Prefix (Expr), Layout_Done, Known_Compatible));
9439 -- In all other cases, we need a full check on the prefix
9441 else
9442 Set_Result
9443 (Has_Compatible_Alignment_Internal
9444 (Obj, Prefix (Expr), Layout_Done, Unknown));
9445 end if;
9446 end Check_Prefix;
9448 ----------------
9449 -- Set_Result --
9450 ----------------
9452 procedure Set_Result (R : Alignment_Result) is
9453 begin
9454 if R > Result then
9455 Result := R;
9456 end if;
9457 end Set_Result;
9459 -- Start of processing for Has_Compatible_Alignment_Internal
9461 begin
9462 -- If Expr is a selected component, we must make sure there is no
9463 -- potentially troublesome component clause and that the record is
9464 -- not packed if the layout is not done.
9466 if Nkind (Expr) = N_Selected_Component then
9468 -- Packing generates unknown alignment if layout is not done
9470 if Is_Packed (Etype (Prefix (Expr))) and then not Layout_Done then
9471 Set_Result (Unknown);
9472 end if;
9474 -- Check prefix and component offset
9476 Check_Prefix;
9477 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
9479 -- If Expr is an indexed component, we must make sure there is no
9480 -- potentially troublesome Component_Size clause and that the array
9481 -- is not bit-packed if the layout is not done.
9483 elsif Nkind (Expr) = N_Indexed_Component then
9484 declare
9485 Typ : constant Entity_Id := Etype (Prefix (Expr));
9487 begin
9488 -- Packing generates unknown alignment if layout is not done
9490 if Is_Bit_Packed_Array (Typ) and then not Layout_Done then
9491 Set_Result (Unknown);
9492 end if;
9494 -- Check prefix and component offset (or at least size)
9496 Check_Prefix;
9497 Offs := Indexed_Component_Bit_Offset (Expr);
9498 if Offs = No_Uint then
9499 Offs := Component_Size (Typ);
9500 end if;
9501 end;
9502 end if;
9504 -- If we have a null offset, the result is entirely determined by
9505 -- the base object and has already been computed recursively.
9507 if Offs = Uint_0 then
9508 null;
9510 -- Case where we know the alignment of the object
9512 elsif Known_Alignment (Obj) then
9513 declare
9514 ObjA : constant Uint := Alignment (Obj);
9515 ExpA : Uint := No_Uint;
9516 SizA : Uint := No_Uint;
9518 begin
9519 -- If alignment of Obj is 1, then we are always OK
9521 if ObjA = 1 then
9522 Set_Result (Known_Compatible);
9524 -- Alignment of Obj is greater than 1, so we need to check
9526 else
9527 -- If we have an offset, see if it is compatible
9529 if Offs /= No_Uint and Offs > Uint_0 then
9530 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
9531 Set_Result (Known_Incompatible);
9532 end if;
9534 -- See if Expr is an object with known alignment
9536 elsif Is_Entity_Name (Expr)
9537 and then Known_Alignment (Entity (Expr))
9538 then
9539 ExpA := Alignment (Entity (Expr));
9541 -- Otherwise, we can use the alignment of the type of
9542 -- Expr given that we already checked for
9543 -- discombobulating rep clauses for the cases of indexed
9544 -- and selected components above.
9546 elsif Known_Alignment (Etype (Expr)) then
9547 ExpA := Alignment (Etype (Expr));
9549 -- Otherwise the alignment is unknown
9551 else
9552 Set_Result (Default);
9553 end if;
9555 -- If we got an alignment, see if it is acceptable
9557 if ExpA /= No_Uint and then ExpA < ObjA then
9558 Set_Result (Known_Incompatible);
9559 end if;
9561 -- If Expr is not a piece of a larger object, see if size
9562 -- is given. If so, check that it is not too small for the
9563 -- required alignment.
9565 if Offs /= No_Uint then
9566 null;
9568 -- See if Expr is an object with known size
9570 elsif Is_Entity_Name (Expr)
9571 and then Known_Static_Esize (Entity (Expr))
9572 then
9573 SizA := Esize (Entity (Expr));
9575 -- Otherwise, we check the object size of the Expr type
9577 elsif Known_Static_Esize (Etype (Expr)) then
9578 SizA := Esize (Etype (Expr));
9579 end if;
9581 -- If we got a size, see if it is a multiple of the Obj
9582 -- alignment, if not, then the alignment cannot be
9583 -- acceptable, since the size is always a multiple of the
9584 -- alignment.
9586 if SizA /= No_Uint then
9587 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
9588 Set_Result (Known_Incompatible);
9589 end if;
9590 end if;
9591 end if;
9592 end;
9594 -- If we do not know required alignment, any non-zero offset is a
9595 -- potential problem (but certainly may be OK, so result is unknown).
9597 elsif Offs /= No_Uint then
9598 Set_Result (Unknown);
9600 -- If we can't find the result by direct comparison of alignment
9601 -- values, then there is still one case that we can determine known
9602 -- result, and that is when we can determine that the types are the
9603 -- same, and no alignments are specified. Then we known that the
9604 -- alignments are compatible, even if we don't know the alignment
9605 -- value in the front end.
9607 elsif Etype (Obj) = Etype (Expr) then
9609 -- Types are the same, but we have to check for possible size
9610 -- and alignments on the Expr object that may make the alignment
9611 -- different, even though the types are the same.
9613 if Is_Entity_Name (Expr) then
9615 -- First check alignment of the Expr object. Any alignment less
9616 -- than Maximum_Alignment is worrisome since this is the case
9617 -- where we do not know the alignment of Obj.
9619 if Known_Alignment (Entity (Expr))
9620 and then UI_To_Int (Alignment (Entity (Expr))) <
9621 Ttypes.Maximum_Alignment
9622 then
9623 Set_Result (Unknown);
9625 -- Now check size of Expr object. Any size that is not an
9626 -- even multiple of Maximum_Alignment is also worrisome
9627 -- since it may cause the alignment of the object to be less
9628 -- than the alignment of the type.
9630 elsif Known_Static_Esize (Entity (Expr))
9631 and then
9632 (UI_To_Int (Esize (Entity (Expr))) mod
9633 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
9634 /= 0
9635 then
9636 Set_Result (Unknown);
9638 -- Otherwise same type is decisive
9640 else
9641 Set_Result (Known_Compatible);
9642 end if;
9643 end if;
9645 -- Another case to deal with is when there is an explicit size or
9646 -- alignment clause when the types are not the same. If so, then the
9647 -- result is Unknown. We don't need to do this test if the Default is
9648 -- Unknown, since that result will be set in any case.
9650 elsif Default /= Unknown
9651 and then (Has_Size_Clause (Etype (Expr))
9652 or else
9653 Has_Alignment_Clause (Etype (Expr)))
9654 then
9655 Set_Result (Unknown);
9657 -- If no indication found, set default
9659 else
9660 Set_Result (Default);
9661 end if;
9663 -- Return worst result found
9665 return Result;
9666 end Has_Compatible_Alignment_Internal;
9668 -- Start of processing for Has_Compatible_Alignment
9670 begin
9671 -- If Obj has no specified alignment, then set alignment from the type
9672 -- alignment. Perhaps we should always do this, but for sure we should
9673 -- do it when there is an address clause since we can do more if the
9674 -- alignment is known.
9676 if Unknown_Alignment (Obj) then
9677 Set_Alignment (Obj, Alignment (Etype (Obj)));
9678 end if;
9680 -- Now do the internal call that does all the work
9682 return
9683 Has_Compatible_Alignment_Internal (Obj, Expr, Layout_Done, Unknown);
9684 end Has_Compatible_Alignment;
9686 ----------------------
9687 -- Has_Declarations --
9688 ----------------------
9690 function Has_Declarations (N : Node_Id) return Boolean is
9691 begin
9692 return Nkind_In (Nkind (N), N_Accept_Statement,
9693 N_Block_Statement,
9694 N_Compilation_Unit_Aux,
9695 N_Entry_Body,
9696 N_Package_Body,
9697 N_Protected_Body,
9698 N_Subprogram_Body,
9699 N_Task_Body,
9700 N_Package_Specification);
9701 end Has_Declarations;
9703 ---------------------------------
9704 -- Has_Defaulted_Discriminants --
9705 ---------------------------------
9707 function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean is
9708 begin
9709 return Has_Discriminants (Typ)
9710 and then Present (First_Discriminant (Typ))
9711 and then Present (Discriminant_Default_Value
9712 (First_Discriminant (Typ)));
9713 end Has_Defaulted_Discriminants;
9715 -------------------
9716 -- Has_Denormals --
9717 -------------------
9719 function Has_Denormals (E : Entity_Id) return Boolean is
9720 begin
9721 return Is_Floating_Point_Type (E) and then Denorm_On_Target;
9722 end Has_Denormals;
9724 -------------------------------------------
9725 -- Has_Discriminant_Dependent_Constraint --
9726 -------------------------------------------
9728 function Has_Discriminant_Dependent_Constraint
9729 (Comp : Entity_Id) return Boolean
9731 Comp_Decl : constant Node_Id := Parent (Comp);
9732 Subt_Indic : Node_Id;
9733 Constr : Node_Id;
9734 Assn : Node_Id;
9736 begin
9737 -- Discriminants can't depend on discriminants
9739 if Ekind (Comp) = E_Discriminant then
9740 return False;
9742 else
9743 Subt_Indic := Subtype_Indication (Component_Definition (Comp_Decl));
9745 if Nkind (Subt_Indic) = N_Subtype_Indication then
9746 Constr := Constraint (Subt_Indic);
9748 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
9749 Assn := First (Constraints (Constr));
9750 while Present (Assn) loop
9751 case Nkind (Assn) is
9752 when N_Identifier
9753 | N_Range
9754 | N_Subtype_Indication
9756 if Depends_On_Discriminant (Assn) then
9757 return True;
9758 end if;
9760 when N_Discriminant_Association =>
9761 if Depends_On_Discriminant (Expression (Assn)) then
9762 return True;
9763 end if;
9765 when others =>
9766 null;
9767 end case;
9769 Next (Assn);
9770 end loop;
9771 end if;
9772 end if;
9773 end if;
9775 return False;
9776 end Has_Discriminant_Dependent_Constraint;
9778 --------------------------------------
9779 -- Has_Effectively_Volatile_Profile --
9780 --------------------------------------
9782 function Has_Effectively_Volatile_Profile
9783 (Subp_Id : Entity_Id) return Boolean
9785 Formal : Entity_Id;
9787 begin
9788 -- Inspect the formal parameters looking for an effectively volatile
9789 -- type.
9791 Formal := First_Formal (Subp_Id);
9792 while Present (Formal) loop
9793 if Is_Effectively_Volatile (Etype (Formal)) then
9794 return True;
9795 end if;
9797 Next_Formal (Formal);
9798 end loop;
9800 -- Inspect the return type of functions
9802 if Ekind_In (Subp_Id, E_Function, E_Generic_Function)
9803 and then Is_Effectively_Volatile (Etype (Subp_Id))
9804 then
9805 return True;
9806 end if;
9808 return False;
9809 end Has_Effectively_Volatile_Profile;
9811 --------------------------
9812 -- Has_Enabled_Property --
9813 --------------------------
9815 function Has_Enabled_Property
9816 (Item_Id : Entity_Id;
9817 Property : Name_Id) return Boolean
9819 function Protected_Object_Has_Enabled_Property return Boolean;
9820 -- Determine whether a protected object denoted by Item_Id has the
9821 -- property enabled.
9823 function State_Has_Enabled_Property return Boolean;
9824 -- Determine whether a state denoted by Item_Id has the property enabled
9826 function Variable_Has_Enabled_Property return Boolean;
9827 -- Determine whether a variable denoted by Item_Id has the property
9828 -- enabled.
9830 -------------------------------------------
9831 -- Protected_Object_Has_Enabled_Property --
9832 -------------------------------------------
9834 function Protected_Object_Has_Enabled_Property return Boolean is
9835 Constits : constant Elist_Id := Part_Of_Constituents (Item_Id);
9836 Constit_Elmt : Elmt_Id;
9837 Constit_Id : Entity_Id;
9839 begin
9840 -- Protected objects always have the properties Async_Readers and
9841 -- Async_Writers (SPARK RM 7.1.2(16)).
9843 if Property = Name_Async_Readers
9844 or else Property = Name_Async_Writers
9845 then
9846 return True;
9848 -- Protected objects that have Part_Of components also inherit their
9849 -- properties Effective_Reads and Effective_Writes
9850 -- (SPARK RM 7.1.2(16)).
9852 elsif Present (Constits) then
9853 Constit_Elmt := First_Elmt (Constits);
9854 while Present (Constit_Elmt) loop
9855 Constit_Id := Node (Constit_Elmt);
9857 if Has_Enabled_Property (Constit_Id, Property) then
9858 return True;
9859 end if;
9861 Next_Elmt (Constit_Elmt);
9862 end loop;
9863 end if;
9865 return False;
9866 end Protected_Object_Has_Enabled_Property;
9868 --------------------------------
9869 -- State_Has_Enabled_Property --
9870 --------------------------------
9872 function State_Has_Enabled_Property return Boolean is
9873 Decl : constant Node_Id := Parent (Item_Id);
9874 Opt : Node_Id;
9875 Opt_Nam : Node_Id;
9876 Prop : Node_Id;
9877 Prop_Nam : Node_Id;
9878 Props : Node_Id;
9880 begin
9881 -- The declaration of an external abstract state appears as an
9882 -- extension aggregate. If this is not the case, properties can never
9883 -- be set.
9885 if Nkind (Decl) /= N_Extension_Aggregate then
9886 return False;
9887 end if;
9889 -- When External appears as a simple option, it automatically enables
9890 -- all properties.
9892 Opt := First (Expressions (Decl));
9893 while Present (Opt) loop
9894 if Nkind (Opt) = N_Identifier
9895 and then Chars (Opt) = Name_External
9896 then
9897 return True;
9898 end if;
9900 Next (Opt);
9901 end loop;
9903 -- When External specifies particular properties, inspect those and
9904 -- find the desired one (if any).
9906 Opt := First (Component_Associations (Decl));
9907 while Present (Opt) loop
9908 Opt_Nam := First (Choices (Opt));
9910 if Nkind (Opt_Nam) = N_Identifier
9911 and then Chars (Opt_Nam) = Name_External
9912 then
9913 Props := Expression (Opt);
9915 -- Multiple properties appear as an aggregate
9917 if Nkind (Props) = N_Aggregate then
9919 -- Simple property form
9921 Prop := First (Expressions (Props));
9922 while Present (Prop) loop
9923 if Chars (Prop) = Property then
9924 return True;
9925 end if;
9927 Next (Prop);
9928 end loop;
9930 -- Property with expression form
9932 Prop := First (Component_Associations (Props));
9933 while Present (Prop) loop
9934 Prop_Nam := First (Choices (Prop));
9936 -- The property can be represented in two ways:
9937 -- others => <value>
9938 -- <property> => <value>
9940 if Nkind (Prop_Nam) = N_Others_Choice
9941 or else (Nkind (Prop_Nam) = N_Identifier
9942 and then Chars (Prop_Nam) = Property)
9943 then
9944 return Is_True (Expr_Value (Expression (Prop)));
9945 end if;
9947 Next (Prop);
9948 end loop;
9950 -- Single property
9952 else
9953 return Chars (Props) = Property;
9954 end if;
9955 end if;
9957 Next (Opt);
9958 end loop;
9960 return False;
9961 end State_Has_Enabled_Property;
9963 -----------------------------------
9964 -- Variable_Has_Enabled_Property --
9965 -----------------------------------
9967 function Variable_Has_Enabled_Property return Boolean is
9968 function Is_Enabled (Prag : Node_Id) return Boolean;
9969 -- Determine whether property pragma Prag (if present) denotes an
9970 -- enabled property.
9972 ----------------
9973 -- Is_Enabled --
9974 ----------------
9976 function Is_Enabled (Prag : Node_Id) return Boolean is
9977 Arg1 : Node_Id;
9979 begin
9980 if Present (Prag) then
9981 Arg1 := First (Pragma_Argument_Associations (Prag));
9983 -- The pragma has an optional Boolean expression, the related
9984 -- property is enabled only when the expression evaluates to
9985 -- True.
9987 if Present (Arg1) then
9988 return Is_True (Expr_Value (Get_Pragma_Arg (Arg1)));
9990 -- Otherwise the lack of expression enables the property by
9991 -- default.
9993 else
9994 return True;
9995 end if;
9997 -- The property was never set in the first place
9999 else
10000 return False;
10001 end if;
10002 end Is_Enabled;
10004 -- Local variables
10006 AR : constant Node_Id :=
10007 Get_Pragma (Item_Id, Pragma_Async_Readers);
10008 AW : constant Node_Id :=
10009 Get_Pragma (Item_Id, Pragma_Async_Writers);
10010 ER : constant Node_Id :=
10011 Get_Pragma (Item_Id, Pragma_Effective_Reads);
10012 EW : constant Node_Id :=
10013 Get_Pragma (Item_Id, Pragma_Effective_Writes);
10015 -- Start of processing for Variable_Has_Enabled_Property
10017 begin
10018 -- A non-effectively volatile object can never possess external
10019 -- properties.
10021 if not Is_Effectively_Volatile (Item_Id) then
10022 return False;
10024 -- External properties related to variables come in two flavors -
10025 -- explicit and implicit. The explicit case is characterized by the
10026 -- presence of a property pragma with an optional Boolean flag. The
10027 -- property is enabled when the flag evaluates to True or the flag is
10028 -- missing altogether.
10030 elsif Property = Name_Async_Readers and then Is_Enabled (AR) then
10031 return True;
10033 elsif Property = Name_Async_Writers and then Is_Enabled (AW) then
10034 return True;
10036 elsif Property = Name_Effective_Reads and then Is_Enabled (ER) then
10037 return True;
10039 elsif Property = Name_Effective_Writes and then Is_Enabled (EW) then
10040 return True;
10042 -- The implicit case lacks all property pragmas
10044 elsif No (AR) and then No (AW) and then No (ER) and then No (EW) then
10045 if Is_Protected_Type (Etype (Item_Id)) then
10046 return Protected_Object_Has_Enabled_Property;
10047 else
10048 return True;
10049 end if;
10051 else
10052 return False;
10053 end if;
10054 end Variable_Has_Enabled_Property;
10056 -- Start of processing for Has_Enabled_Property
10058 begin
10059 -- Abstract states and variables have a flexible scheme of specifying
10060 -- external properties.
10062 if Ekind (Item_Id) = E_Abstract_State then
10063 return State_Has_Enabled_Property;
10065 elsif Ekind (Item_Id) = E_Variable then
10066 return Variable_Has_Enabled_Property;
10068 -- By default, protected objects only have the properties Async_Readers
10069 -- and Async_Writers. If they have Part_Of components, they also inherit
10070 -- their properties Effective_Reads and Effective_Writes
10071 -- (SPARK RM 7.1.2(16)).
10073 elsif Ekind (Item_Id) = E_Protected_Object then
10074 return Protected_Object_Has_Enabled_Property;
10076 -- Otherwise a property is enabled when the related item is effectively
10077 -- volatile.
10079 else
10080 return Is_Effectively_Volatile (Item_Id);
10081 end if;
10082 end Has_Enabled_Property;
10084 -------------------------------------
10085 -- Has_Full_Default_Initialization --
10086 -------------------------------------
10088 function Has_Full_Default_Initialization (Typ : Entity_Id) return Boolean is
10089 Comp : Entity_Id;
10090 Prag : Node_Id;
10092 begin
10093 -- A type subject to pragma Default_Initial_Condition is fully default
10094 -- initialized when the pragma appears with a non-null argument. Since
10095 -- any type may act as the full view of a private type, this check must
10096 -- be performed prior to the specialized tests below.
10098 if Has_DIC (Typ) then
10099 Prag := Get_Pragma (Typ, Pragma_Default_Initial_Condition);
10100 pragma Assert (Present (Prag));
10102 return Is_Verifiable_DIC_Pragma (Prag);
10103 end if;
10105 -- A scalar type is fully default initialized if it is subject to aspect
10106 -- Default_Value.
10108 if Is_Scalar_Type (Typ) then
10109 return Has_Default_Aspect (Typ);
10111 -- An array type is fully default initialized if its element type is
10112 -- scalar and the array type carries aspect Default_Component_Value or
10113 -- the element type is fully default initialized.
10115 elsif Is_Array_Type (Typ) then
10116 return
10117 Has_Default_Aspect (Typ)
10118 or else Has_Full_Default_Initialization (Component_Type (Typ));
10120 -- A protected type, record type, or type extension is fully default
10121 -- initialized if all its components either carry an initialization
10122 -- expression or have a type that is fully default initialized. The
10123 -- parent type of a type extension must be fully default initialized.
10125 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
10127 -- Inspect all entities defined in the scope of the type, looking for
10128 -- uninitialized components.
10130 Comp := First_Entity (Typ);
10131 while Present (Comp) loop
10132 if Ekind (Comp) = E_Component
10133 and then Comes_From_Source (Comp)
10134 and then No (Expression (Parent (Comp)))
10135 and then not Has_Full_Default_Initialization (Etype (Comp))
10136 then
10137 return False;
10138 end if;
10140 Next_Entity (Comp);
10141 end loop;
10143 -- Ensure that the parent type of a type extension is fully default
10144 -- initialized.
10146 if Etype (Typ) /= Typ
10147 and then not Has_Full_Default_Initialization (Etype (Typ))
10148 then
10149 return False;
10150 end if;
10152 -- If we get here, then all components and parent portion are fully
10153 -- default initialized.
10155 return True;
10157 -- A task type is fully default initialized by default
10159 elsif Is_Task_Type (Typ) then
10160 return True;
10162 -- Otherwise the type is not fully default initialized
10164 else
10165 return False;
10166 end if;
10167 end Has_Full_Default_Initialization;
10169 --------------------
10170 -- Has_Infinities --
10171 --------------------
10173 function Has_Infinities (E : Entity_Id) return Boolean is
10174 begin
10175 return
10176 Is_Floating_Point_Type (E)
10177 and then Nkind (Scalar_Range (E)) = N_Range
10178 and then Includes_Infinities (Scalar_Range (E));
10179 end Has_Infinities;
10181 --------------------
10182 -- Has_Interfaces --
10183 --------------------
10185 function Has_Interfaces
10186 (T : Entity_Id;
10187 Use_Full_View : Boolean := True) return Boolean
10189 Typ : Entity_Id := Base_Type (T);
10191 begin
10192 -- Handle concurrent types
10194 if Is_Concurrent_Type (Typ) then
10195 Typ := Corresponding_Record_Type (Typ);
10196 end if;
10198 if not Present (Typ)
10199 or else not Is_Record_Type (Typ)
10200 or else not Is_Tagged_Type (Typ)
10201 then
10202 return False;
10203 end if;
10205 -- Handle private types
10207 if Use_Full_View and then Present (Full_View (Typ)) then
10208 Typ := Full_View (Typ);
10209 end if;
10211 -- Handle concurrent record types
10213 if Is_Concurrent_Record_Type (Typ)
10214 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
10215 then
10216 return True;
10217 end if;
10219 loop
10220 if Is_Interface (Typ)
10221 or else
10222 (Is_Record_Type (Typ)
10223 and then Present (Interfaces (Typ))
10224 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
10225 then
10226 return True;
10227 end if;
10229 exit when Etype (Typ) = Typ
10231 -- Handle private types
10233 or else (Present (Full_View (Etype (Typ)))
10234 and then Full_View (Etype (Typ)) = Typ)
10236 -- Protect frontend against wrong sources with cyclic derivations
10238 or else Etype (Typ) = T;
10240 -- Climb to the ancestor type handling private types
10242 if Present (Full_View (Etype (Typ))) then
10243 Typ := Full_View (Etype (Typ));
10244 else
10245 Typ := Etype (Typ);
10246 end if;
10247 end loop;
10249 return False;
10250 end Has_Interfaces;
10252 --------------------------
10253 -- Has_Max_Queue_Length --
10254 --------------------------
10256 function Has_Max_Queue_Length (Id : Entity_Id) return Boolean is
10257 begin
10258 return
10259 Ekind (Id) = E_Entry
10260 and then Present (Get_Pragma (Id, Pragma_Max_Queue_Length));
10261 end Has_Max_Queue_Length;
10263 ---------------------------------
10264 -- Has_No_Obvious_Side_Effects --
10265 ---------------------------------
10267 function Has_No_Obvious_Side_Effects (N : Node_Id) return Boolean is
10268 begin
10269 -- For now handle literals, constants, and non-volatile variables and
10270 -- expressions combining these with operators or short circuit forms.
10272 if Nkind (N) in N_Numeric_Or_String_Literal then
10273 return True;
10275 elsif Nkind (N) = N_Character_Literal then
10276 return True;
10278 elsif Nkind (N) in N_Unary_Op then
10279 return Has_No_Obvious_Side_Effects (Right_Opnd (N));
10281 elsif Nkind (N) in N_Binary_Op or else Nkind (N) in N_Short_Circuit then
10282 return Has_No_Obvious_Side_Effects (Left_Opnd (N))
10283 and then
10284 Has_No_Obvious_Side_Effects (Right_Opnd (N));
10286 elsif Nkind (N) = N_Expression_With_Actions
10287 and then Is_Empty_List (Actions (N))
10288 then
10289 return Has_No_Obvious_Side_Effects (Expression (N));
10291 elsif Nkind (N) in N_Has_Entity then
10292 return Present (Entity (N))
10293 and then Ekind_In (Entity (N), E_Variable,
10294 E_Constant,
10295 E_Enumeration_Literal,
10296 E_In_Parameter,
10297 E_Out_Parameter,
10298 E_In_Out_Parameter)
10299 and then not Is_Volatile (Entity (N));
10301 else
10302 return False;
10303 end if;
10304 end Has_No_Obvious_Side_Effects;
10306 -----------------------------
10307 -- Has_Non_Null_Refinement --
10308 -----------------------------
10310 function Has_Non_Null_Refinement (Id : Entity_Id) return Boolean is
10311 Constits : Elist_Id;
10313 begin
10314 pragma Assert (Ekind (Id) = E_Abstract_State);
10315 Constits := Refinement_Constituents (Id);
10317 -- For a refinement to be non-null, the first constituent must be
10318 -- anything other than null.
10320 return
10321 Present (Constits)
10322 and then Nkind (Node (First_Elmt (Constits))) /= N_Null;
10323 end Has_Non_Null_Refinement;
10325 ----------------------------------
10326 -- Has_Non_Trivial_Precondition --
10327 ----------------------------------
10329 function Has_Non_Trivial_Precondition (P : Entity_Id) return Boolean is
10330 Cont : constant Node_Id := Find_Aspect (P, Aspect_Pre);
10331 begin
10332 return Present (Cont)
10333 and then Class_Present (Cont)
10334 and then not Is_Entity_Name (Expression (Cont));
10335 end Has_Non_Trivial_Precondition;
10337 -------------------
10338 -- Has_Null_Body --
10339 -------------------
10341 function Has_Null_Body (Proc_Id : Entity_Id) return Boolean is
10342 Body_Id : Entity_Id;
10343 Decl : Node_Id;
10344 Spec : Node_Id;
10345 Stmt1 : Node_Id;
10346 Stmt2 : Node_Id;
10348 begin
10349 Spec := Parent (Proc_Id);
10350 Decl := Parent (Spec);
10352 -- Retrieve the entity of the procedure body (e.g. invariant proc).
10354 if Nkind (Spec) = N_Procedure_Specification
10355 and then Nkind (Decl) = N_Subprogram_Declaration
10356 then
10357 Body_Id := Corresponding_Body (Decl);
10359 -- The body acts as a spec
10361 else
10362 Body_Id := Proc_Id;
10363 end if;
10365 -- The body will be generated later
10367 if No (Body_Id) then
10368 return False;
10369 end if;
10371 Spec := Parent (Body_Id);
10372 Decl := Parent (Spec);
10374 pragma Assert
10375 (Nkind (Spec) = N_Procedure_Specification
10376 and then Nkind (Decl) = N_Subprogram_Body);
10378 Stmt1 := First (Statements (Handled_Statement_Sequence (Decl)));
10380 -- Look for a null statement followed by an optional return
10381 -- statement.
10383 if Nkind (Stmt1) = N_Null_Statement then
10384 Stmt2 := Next (Stmt1);
10386 if Present (Stmt2) then
10387 return Nkind (Stmt2) = N_Simple_Return_Statement;
10388 else
10389 return True;
10390 end if;
10391 end if;
10393 return False;
10394 end Has_Null_Body;
10396 ------------------------
10397 -- Has_Null_Exclusion --
10398 ------------------------
10400 function Has_Null_Exclusion (N : Node_Id) return Boolean is
10401 begin
10402 case Nkind (N) is
10403 when N_Access_Definition
10404 | N_Access_Function_Definition
10405 | N_Access_Procedure_Definition
10406 | N_Access_To_Object_Definition
10407 | N_Allocator
10408 | N_Derived_Type_Definition
10409 | N_Function_Specification
10410 | N_Subtype_Declaration
10412 return Null_Exclusion_Present (N);
10414 when N_Component_Definition
10415 | N_Formal_Object_Declaration
10416 | N_Object_Renaming_Declaration
10418 if Present (Subtype_Mark (N)) then
10419 return Null_Exclusion_Present (N);
10420 else pragma Assert (Present (Access_Definition (N)));
10421 return Null_Exclusion_Present (Access_Definition (N));
10422 end if;
10424 when N_Discriminant_Specification =>
10425 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
10426 return Null_Exclusion_Present (Discriminant_Type (N));
10427 else
10428 return Null_Exclusion_Present (N);
10429 end if;
10431 when N_Object_Declaration =>
10432 if Nkind (Object_Definition (N)) = N_Access_Definition then
10433 return Null_Exclusion_Present (Object_Definition (N));
10434 else
10435 return Null_Exclusion_Present (N);
10436 end if;
10438 when N_Parameter_Specification =>
10439 if Nkind (Parameter_Type (N)) = N_Access_Definition then
10440 return Null_Exclusion_Present (Parameter_Type (N));
10441 else
10442 return Null_Exclusion_Present (N);
10443 end if;
10445 when others =>
10446 return False;
10447 end case;
10448 end Has_Null_Exclusion;
10450 ------------------------
10451 -- Has_Null_Extension --
10452 ------------------------
10454 function Has_Null_Extension (T : Entity_Id) return Boolean is
10455 B : constant Entity_Id := Base_Type (T);
10456 Comps : Node_Id;
10457 Ext : Node_Id;
10459 begin
10460 if Nkind (Parent (B)) = N_Full_Type_Declaration
10461 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
10462 then
10463 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
10465 if Present (Ext) then
10466 if Null_Present (Ext) then
10467 return True;
10468 else
10469 Comps := Component_List (Ext);
10471 -- The null component list is rewritten during analysis to
10472 -- include the parent component. Any other component indicates
10473 -- that the extension was not originally null.
10475 return Null_Present (Comps)
10476 or else No (Next (First (Component_Items (Comps))));
10477 end if;
10478 else
10479 return False;
10480 end if;
10482 else
10483 return False;
10484 end if;
10485 end Has_Null_Extension;
10487 -------------------------
10488 -- Has_Null_Refinement --
10489 -------------------------
10491 function Has_Null_Refinement (Id : Entity_Id) return Boolean is
10492 Constits : Elist_Id;
10494 begin
10495 pragma Assert (Ekind (Id) = E_Abstract_State);
10496 Constits := Refinement_Constituents (Id);
10498 -- For a refinement to be null, the state's sole constituent must be a
10499 -- null.
10501 return
10502 Present (Constits)
10503 and then Nkind (Node (First_Elmt (Constits))) = N_Null;
10504 end Has_Null_Refinement;
10506 -------------------------------
10507 -- Has_Overriding_Initialize --
10508 -------------------------------
10510 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
10511 BT : constant Entity_Id := Base_Type (T);
10512 P : Elmt_Id;
10514 begin
10515 if Is_Controlled (BT) then
10516 if Is_RTU (Scope (BT), Ada_Finalization) then
10517 return False;
10519 elsif Present (Primitive_Operations (BT)) then
10520 P := First_Elmt (Primitive_Operations (BT));
10521 while Present (P) loop
10522 declare
10523 Init : constant Entity_Id := Node (P);
10524 Formal : constant Entity_Id := First_Formal (Init);
10525 begin
10526 if Ekind (Init) = E_Procedure
10527 and then Chars (Init) = Name_Initialize
10528 and then Comes_From_Source (Init)
10529 and then Present (Formal)
10530 and then Etype (Formal) = BT
10531 and then No (Next_Formal (Formal))
10532 and then (Ada_Version < Ada_2012
10533 or else not Null_Present (Parent (Init)))
10534 then
10535 return True;
10536 end if;
10537 end;
10539 Next_Elmt (P);
10540 end loop;
10541 end if;
10543 -- Here if type itself does not have a non-null Initialize operation:
10544 -- check immediate ancestor.
10546 if Is_Derived_Type (BT)
10547 and then Has_Overriding_Initialize (Etype (BT))
10548 then
10549 return True;
10550 end if;
10551 end if;
10553 return False;
10554 end Has_Overriding_Initialize;
10556 --------------------------------------
10557 -- Has_Preelaborable_Initialization --
10558 --------------------------------------
10560 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
10561 Has_PE : Boolean;
10563 procedure Check_Components (E : Entity_Id);
10564 -- Check component/discriminant chain, sets Has_PE False if a component
10565 -- or discriminant does not meet the preelaborable initialization rules.
10567 ----------------------
10568 -- Check_Components --
10569 ----------------------
10571 procedure Check_Components (E : Entity_Id) is
10572 Ent : Entity_Id;
10573 Exp : Node_Id;
10575 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
10576 -- Returns True if and only if the expression denoted by N does not
10577 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
10579 ---------------------------------
10580 -- Is_Preelaborable_Expression --
10581 ---------------------------------
10583 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
10584 Exp : Node_Id;
10585 Assn : Node_Id;
10586 Choice : Node_Id;
10587 Comp_Type : Entity_Id;
10588 Is_Array_Aggr : Boolean;
10590 begin
10591 if Is_OK_Static_Expression (N) then
10592 return True;
10594 elsif Nkind (N) = N_Null then
10595 return True;
10597 -- Attributes are allowed in general, even if their prefix is a
10598 -- formal type. (It seems that certain attributes known not to be
10599 -- static might not be allowed, but there are no rules to prevent
10600 -- them.)
10602 elsif Nkind (N) = N_Attribute_Reference then
10603 return True;
10605 -- The name of a discriminant evaluated within its parent type is
10606 -- defined to be preelaborable (10.2.1(8)). Note that we test for
10607 -- names that denote discriminals as well as discriminants to
10608 -- catch references occurring within init procs.
10610 elsif Is_Entity_Name (N)
10611 and then
10612 (Ekind (Entity (N)) = E_Discriminant
10613 or else (Ekind_In (Entity (N), E_Constant, E_In_Parameter)
10614 and then Present (Discriminal_Link (Entity (N)))))
10615 then
10616 return True;
10618 elsif Nkind (N) = N_Qualified_Expression then
10619 return Is_Preelaborable_Expression (Expression (N));
10621 -- For aggregates we have to check that each of the associations
10622 -- is preelaborable.
10624 elsif Nkind_In (N, N_Aggregate, N_Extension_Aggregate) then
10625 Is_Array_Aggr := Is_Array_Type (Etype (N));
10627 if Is_Array_Aggr then
10628 Comp_Type := Component_Type (Etype (N));
10629 end if;
10631 -- Check the ancestor part of extension aggregates, which must
10632 -- be either the name of a type that has preelaborable init or
10633 -- an expression that is preelaborable.
10635 if Nkind (N) = N_Extension_Aggregate then
10636 declare
10637 Anc_Part : constant Node_Id := Ancestor_Part (N);
10639 begin
10640 if Is_Entity_Name (Anc_Part)
10641 and then Is_Type (Entity (Anc_Part))
10642 then
10643 if not Has_Preelaborable_Initialization
10644 (Entity (Anc_Part))
10645 then
10646 return False;
10647 end if;
10649 elsif not Is_Preelaborable_Expression (Anc_Part) then
10650 return False;
10651 end if;
10652 end;
10653 end if;
10655 -- Check positional associations
10657 Exp := First (Expressions (N));
10658 while Present (Exp) loop
10659 if not Is_Preelaborable_Expression (Exp) then
10660 return False;
10661 end if;
10663 Next (Exp);
10664 end loop;
10666 -- Check named associations
10668 Assn := First (Component_Associations (N));
10669 while Present (Assn) loop
10670 Choice := First (Choices (Assn));
10671 while Present (Choice) loop
10672 if Is_Array_Aggr then
10673 if Nkind (Choice) = N_Others_Choice then
10674 null;
10676 elsif Nkind (Choice) = N_Range then
10677 if not Is_OK_Static_Range (Choice) then
10678 return False;
10679 end if;
10681 elsif not Is_OK_Static_Expression (Choice) then
10682 return False;
10683 end if;
10685 else
10686 Comp_Type := Etype (Choice);
10687 end if;
10689 Next (Choice);
10690 end loop;
10692 -- If the association has a <> at this point, then we have
10693 -- to check whether the component's type has preelaborable
10694 -- initialization. Note that this only occurs when the
10695 -- association's corresponding component does not have a
10696 -- default expression, the latter case having already been
10697 -- expanded as an expression for the association.
10699 if Box_Present (Assn) then
10700 if not Has_Preelaborable_Initialization (Comp_Type) then
10701 return False;
10702 end if;
10704 -- In the expression case we check whether the expression
10705 -- is preelaborable.
10707 elsif
10708 not Is_Preelaborable_Expression (Expression (Assn))
10709 then
10710 return False;
10711 end if;
10713 Next (Assn);
10714 end loop;
10716 -- If we get here then aggregate as a whole is preelaborable
10718 return True;
10720 -- All other cases are not preelaborable
10722 else
10723 return False;
10724 end if;
10725 end Is_Preelaborable_Expression;
10727 -- Start of processing for Check_Components
10729 begin
10730 -- Loop through entities of record or protected type
10732 Ent := E;
10733 while Present (Ent) loop
10735 -- We are interested only in components and discriminants
10737 Exp := Empty;
10739 case Ekind (Ent) is
10740 when E_Component =>
10742 -- Get default expression if any. If there is no declaration
10743 -- node, it means we have an internal entity. The parent and
10744 -- tag fields are examples of such entities. For such cases,
10745 -- we just test the type of the entity.
10747 if Present (Declaration_Node (Ent)) then
10748 Exp := Expression (Declaration_Node (Ent));
10749 end if;
10751 when E_Discriminant =>
10753 -- Note: for a renamed discriminant, the Declaration_Node
10754 -- may point to the one from the ancestor, and have a
10755 -- different expression, so use the proper attribute to
10756 -- retrieve the expression from the derived constraint.
10758 Exp := Discriminant_Default_Value (Ent);
10760 when others =>
10761 goto Check_Next_Entity;
10762 end case;
10764 -- A component has PI if it has no default expression and the
10765 -- component type has PI.
10767 if No (Exp) then
10768 if not Has_Preelaborable_Initialization (Etype (Ent)) then
10769 Has_PE := False;
10770 exit;
10771 end if;
10773 -- Require the default expression to be preelaborable
10775 elsif not Is_Preelaborable_Expression (Exp) then
10776 Has_PE := False;
10777 exit;
10778 end if;
10780 <<Check_Next_Entity>>
10781 Next_Entity (Ent);
10782 end loop;
10783 end Check_Components;
10785 -- Start of processing for Has_Preelaborable_Initialization
10787 begin
10788 -- Immediate return if already marked as known preelaborable init. This
10789 -- covers types for which this function has already been called once
10790 -- and returned True (in which case the result is cached), and also
10791 -- types to which a pragma Preelaborable_Initialization applies.
10793 if Known_To_Have_Preelab_Init (E) then
10794 return True;
10795 end if;
10797 -- If the type is a subtype representing a generic actual type, then
10798 -- test whether its base type has preelaborable initialization since
10799 -- the subtype representing the actual does not inherit this attribute
10800 -- from the actual or formal. (but maybe it should???)
10802 if Is_Generic_Actual_Type (E) then
10803 return Has_Preelaborable_Initialization (Base_Type (E));
10804 end if;
10806 -- All elementary types have preelaborable initialization
10808 if Is_Elementary_Type (E) then
10809 Has_PE := True;
10811 -- Array types have PI if the component type has PI
10813 elsif Is_Array_Type (E) then
10814 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
10816 -- A derived type has preelaborable initialization if its parent type
10817 -- has preelaborable initialization and (in the case of a derived record
10818 -- extension) if the non-inherited components all have preelaborable
10819 -- initialization. However, a user-defined controlled type with an
10820 -- overriding Initialize procedure does not have preelaborable
10821 -- initialization.
10823 elsif Is_Derived_Type (E) then
10825 -- If the derived type is a private extension then it doesn't have
10826 -- preelaborable initialization.
10828 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
10829 return False;
10830 end if;
10832 -- First check whether ancestor type has preelaborable initialization
10834 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
10836 -- If OK, check extension components (if any)
10838 if Has_PE and then Is_Record_Type (E) then
10839 Check_Components (First_Entity (E));
10840 end if;
10842 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
10843 -- with a user defined Initialize procedure does not have PI. If
10844 -- the type is untagged, the control primitives come from a component
10845 -- that has already been checked.
10847 if Has_PE
10848 and then Is_Controlled (E)
10849 and then Is_Tagged_Type (E)
10850 and then Has_Overriding_Initialize (E)
10851 then
10852 Has_PE := False;
10853 end if;
10855 -- Private types not derived from a type having preelaborable init and
10856 -- that are not marked with pragma Preelaborable_Initialization do not
10857 -- have preelaborable initialization.
10859 elsif Is_Private_Type (E) then
10860 return False;
10862 -- Record type has PI if it is non private and all components have PI
10864 elsif Is_Record_Type (E) then
10865 Has_PE := True;
10866 Check_Components (First_Entity (E));
10868 -- Protected types must not have entries, and components must meet
10869 -- same set of rules as for record components.
10871 elsif Is_Protected_Type (E) then
10872 if Has_Entries (E) then
10873 Has_PE := False;
10874 else
10875 Has_PE := True;
10876 Check_Components (First_Entity (E));
10877 Check_Components (First_Private_Entity (E));
10878 end if;
10880 -- Type System.Address always has preelaborable initialization
10882 elsif Is_RTE (E, RE_Address) then
10883 Has_PE := True;
10885 -- In all other cases, type does not have preelaborable initialization
10887 else
10888 return False;
10889 end if;
10891 -- If type has preelaborable initialization, cache result
10893 if Has_PE then
10894 Set_Known_To_Have_Preelab_Init (E);
10895 end if;
10897 return Has_PE;
10898 end Has_Preelaborable_Initialization;
10900 ---------------------------
10901 -- Has_Private_Component --
10902 ---------------------------
10904 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
10905 Btype : Entity_Id := Base_Type (Type_Id);
10906 Component : Entity_Id;
10908 begin
10909 if Error_Posted (Type_Id)
10910 or else Error_Posted (Btype)
10911 then
10912 return False;
10913 end if;
10915 if Is_Class_Wide_Type (Btype) then
10916 Btype := Root_Type (Btype);
10917 end if;
10919 if Is_Private_Type (Btype) then
10920 declare
10921 UT : constant Entity_Id := Underlying_Type (Btype);
10922 begin
10923 if No (UT) then
10924 if No (Full_View (Btype)) then
10925 return not Is_Generic_Type (Btype)
10926 and then
10927 not Is_Generic_Type (Root_Type (Btype));
10928 else
10929 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
10930 end if;
10931 else
10932 return not Is_Frozen (UT) and then Has_Private_Component (UT);
10933 end if;
10934 end;
10936 elsif Is_Array_Type (Btype) then
10937 return Has_Private_Component (Component_Type (Btype));
10939 elsif Is_Record_Type (Btype) then
10940 Component := First_Component (Btype);
10941 while Present (Component) loop
10942 if Has_Private_Component (Etype (Component)) then
10943 return True;
10944 end if;
10946 Next_Component (Component);
10947 end loop;
10949 return False;
10951 elsif Is_Protected_Type (Btype)
10952 and then Present (Corresponding_Record_Type (Btype))
10953 then
10954 return Has_Private_Component (Corresponding_Record_Type (Btype));
10956 else
10957 return False;
10958 end if;
10959 end Has_Private_Component;
10961 ----------------------
10962 -- Has_Signed_Zeros --
10963 ----------------------
10965 function Has_Signed_Zeros (E : Entity_Id) return Boolean is
10966 begin
10967 return Is_Floating_Point_Type (E) and then Signed_Zeros_On_Target;
10968 end Has_Signed_Zeros;
10970 ------------------------------
10971 -- Has_Significant_Contract --
10972 ------------------------------
10974 function Has_Significant_Contract (Subp_Id : Entity_Id) return Boolean is
10975 Subp_Nam : constant Name_Id := Chars (Subp_Id);
10977 begin
10978 -- _Finalizer procedure
10980 if Subp_Nam = Name_uFinalizer then
10981 return False;
10983 -- _Postconditions procedure
10985 elsif Subp_Nam = Name_uPostconditions then
10986 return False;
10988 -- Predicate function
10990 elsif Ekind (Subp_Id) = E_Function
10991 and then Is_Predicate_Function (Subp_Id)
10992 then
10993 return False;
10995 -- TSS subprogram
10997 elsif Get_TSS_Name (Subp_Id) /= TSS_Null then
10998 return False;
11000 else
11001 return True;
11002 end if;
11003 end Has_Significant_Contract;
11005 -----------------------------
11006 -- Has_Static_Array_Bounds --
11007 -----------------------------
11009 function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is
11010 Ndims : constant Nat := Number_Dimensions (Typ);
11012 Index : Node_Id;
11013 Low : Node_Id;
11014 High : Node_Id;
11016 begin
11017 -- Unconstrained types do not have static bounds
11019 if not Is_Constrained (Typ) then
11020 return False;
11021 end if;
11023 -- First treat string literals specially, as the lower bound and length
11024 -- of string literals are not stored like those of arrays.
11026 -- A string literal always has static bounds
11028 if Ekind (Typ) = E_String_Literal_Subtype then
11029 return True;
11030 end if;
11032 -- Treat all dimensions in turn
11034 Index := First_Index (Typ);
11035 for Indx in 1 .. Ndims loop
11037 -- In case of an illegal index which is not a discrete type, return
11038 -- that the type is not static.
11040 if not Is_Discrete_Type (Etype (Index))
11041 or else Etype (Index) = Any_Type
11042 then
11043 return False;
11044 end if;
11046 Get_Index_Bounds (Index, Low, High);
11048 if Error_Posted (Low) or else Error_Posted (High) then
11049 return False;
11050 end if;
11052 if Is_OK_Static_Expression (Low)
11053 and then
11054 Is_OK_Static_Expression (High)
11055 then
11056 null;
11057 else
11058 return False;
11059 end if;
11061 Next (Index);
11062 end loop;
11064 -- If we fall through the loop, all indexes matched
11066 return True;
11067 end Has_Static_Array_Bounds;
11069 ----------------
11070 -- Has_Stream --
11071 ----------------
11073 function Has_Stream (T : Entity_Id) return Boolean is
11074 E : Entity_Id;
11076 begin
11077 if No (T) then
11078 return False;
11080 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
11081 return True;
11083 elsif Is_Array_Type (T) then
11084 return Has_Stream (Component_Type (T));
11086 elsif Is_Record_Type (T) then
11087 E := First_Component (T);
11088 while Present (E) loop
11089 if Has_Stream (Etype (E)) then
11090 return True;
11091 else
11092 Next_Component (E);
11093 end if;
11094 end loop;
11096 return False;
11098 elsif Is_Private_Type (T) then
11099 return Has_Stream (Underlying_Type (T));
11101 else
11102 return False;
11103 end if;
11104 end Has_Stream;
11106 ----------------
11107 -- Has_Suffix --
11108 ----------------
11110 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
11111 begin
11112 Get_Name_String (Chars (E));
11113 return Name_Buffer (Name_Len) = Suffix;
11114 end Has_Suffix;
11116 ----------------
11117 -- Add_Suffix --
11118 ----------------
11120 function Add_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
11121 begin
11122 Get_Name_String (Chars (E));
11123 Add_Char_To_Name_Buffer (Suffix);
11124 return Name_Find;
11125 end Add_Suffix;
11127 -------------------
11128 -- Remove_Suffix --
11129 -------------------
11131 function Remove_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
11132 begin
11133 pragma Assert (Has_Suffix (E, Suffix));
11134 Get_Name_String (Chars (E));
11135 Name_Len := Name_Len - 1;
11136 return Name_Find;
11137 end Remove_Suffix;
11139 ----------------------------------
11140 -- Replace_Null_By_Null_Address --
11141 ----------------------------------
11143 procedure Replace_Null_By_Null_Address (N : Node_Id) is
11144 procedure Replace_Null_Operand (Op : Node_Id; Other_Op : Node_Id);
11145 -- Replace operand Op with a reference to Null_Address when the operand
11146 -- denotes a null Address. Other_Op denotes the other operand.
11148 --------------------------
11149 -- Replace_Null_Operand --
11150 --------------------------
11152 procedure Replace_Null_Operand (Op : Node_Id; Other_Op : Node_Id) is
11153 begin
11154 -- Check the type of the complementary operand since the N_Null node
11155 -- has not been decorated yet.
11157 if Nkind (Op) = N_Null
11158 and then Is_Descendant_Of_Address (Etype (Other_Op))
11159 then
11160 Rewrite (Op, New_Occurrence_Of (RTE (RE_Null_Address), Sloc (Op)));
11161 end if;
11162 end Replace_Null_Operand;
11164 -- Start of processing for Replace_Null_By_Null_Address
11166 begin
11167 pragma Assert (Relaxed_RM_Semantics);
11168 pragma Assert (Nkind_In (N, N_Null,
11169 N_Op_Eq,
11170 N_Op_Ge,
11171 N_Op_Gt,
11172 N_Op_Le,
11173 N_Op_Lt,
11174 N_Op_Ne));
11176 if Nkind (N) = N_Null then
11177 Rewrite (N, New_Occurrence_Of (RTE (RE_Null_Address), Sloc (N)));
11179 else
11180 declare
11181 L : constant Node_Id := Left_Opnd (N);
11182 R : constant Node_Id := Right_Opnd (N);
11184 begin
11185 Replace_Null_Operand (L, Other_Op => R);
11186 Replace_Null_Operand (R, Other_Op => L);
11187 end;
11188 end if;
11189 end Replace_Null_By_Null_Address;
11191 --------------------------
11192 -- Has_Tagged_Component --
11193 --------------------------
11195 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
11196 Comp : Entity_Id;
11198 begin
11199 if Is_Private_Type (Typ) and then Present (Underlying_Type (Typ)) then
11200 return Has_Tagged_Component (Underlying_Type (Typ));
11202 elsif Is_Array_Type (Typ) then
11203 return Has_Tagged_Component (Component_Type (Typ));
11205 elsif Is_Tagged_Type (Typ) then
11206 return True;
11208 elsif Is_Record_Type (Typ) then
11209 Comp := First_Component (Typ);
11210 while Present (Comp) loop
11211 if Has_Tagged_Component (Etype (Comp)) then
11212 return True;
11213 end if;
11215 Next_Component (Comp);
11216 end loop;
11218 return False;
11220 else
11221 return False;
11222 end if;
11223 end Has_Tagged_Component;
11225 -----------------------------
11226 -- Has_Undefined_Reference --
11227 -----------------------------
11229 function Has_Undefined_Reference (Expr : Node_Id) return Boolean is
11230 Has_Undef_Ref : Boolean := False;
11231 -- Flag set when expression Expr contains at least one undefined
11232 -- reference.
11234 function Is_Undefined_Reference (N : Node_Id) return Traverse_Result;
11235 -- Determine whether N denotes a reference and if it does, whether it is
11236 -- undefined.
11238 ----------------------------
11239 -- Is_Undefined_Reference --
11240 ----------------------------
11242 function Is_Undefined_Reference (N : Node_Id) return Traverse_Result is
11243 begin
11244 if Is_Entity_Name (N)
11245 and then Present (Entity (N))
11246 and then Entity (N) = Any_Id
11247 then
11248 Has_Undef_Ref := True;
11249 return Abandon;
11250 end if;
11252 return OK;
11253 end Is_Undefined_Reference;
11255 procedure Find_Undefined_References is
11256 new Traverse_Proc (Is_Undefined_Reference);
11258 -- Start of processing for Has_Undefined_Reference
11260 begin
11261 Find_Undefined_References (Expr);
11263 return Has_Undef_Ref;
11264 end Has_Undefined_Reference;
11266 ----------------------------
11267 -- Has_Volatile_Component --
11268 ----------------------------
11270 function Has_Volatile_Component (Typ : Entity_Id) return Boolean is
11271 Comp : Entity_Id;
11273 begin
11274 if Has_Volatile_Components (Typ) then
11275 return True;
11277 elsif Is_Array_Type (Typ) then
11278 return Is_Volatile (Component_Type (Typ));
11280 elsif Is_Record_Type (Typ) then
11281 Comp := First_Component (Typ);
11282 while Present (Comp) loop
11283 if Is_Volatile_Object (Comp) then
11284 return True;
11285 end if;
11287 Comp := Next_Component (Comp);
11288 end loop;
11289 end if;
11291 return False;
11292 end Has_Volatile_Component;
11294 -------------------------
11295 -- Implementation_Kind --
11296 -------------------------
11298 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
11299 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
11300 Arg : Node_Id;
11301 begin
11302 pragma Assert (Present (Impl_Prag));
11303 Arg := Last (Pragma_Argument_Associations (Impl_Prag));
11304 return Chars (Get_Pragma_Arg (Arg));
11305 end Implementation_Kind;
11307 --------------------------
11308 -- Implements_Interface --
11309 --------------------------
11311 function Implements_Interface
11312 (Typ_Ent : Entity_Id;
11313 Iface_Ent : Entity_Id;
11314 Exclude_Parents : Boolean := False) return Boolean
11316 Ifaces_List : Elist_Id;
11317 Elmt : Elmt_Id;
11318 Iface : Entity_Id := Base_Type (Iface_Ent);
11319 Typ : Entity_Id := Base_Type (Typ_Ent);
11321 begin
11322 if Is_Class_Wide_Type (Typ) then
11323 Typ := Root_Type (Typ);
11324 end if;
11326 if not Has_Interfaces (Typ) then
11327 return False;
11328 end if;
11330 if Is_Class_Wide_Type (Iface) then
11331 Iface := Root_Type (Iface);
11332 end if;
11334 Collect_Interfaces (Typ, Ifaces_List);
11336 Elmt := First_Elmt (Ifaces_List);
11337 while Present (Elmt) loop
11338 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
11339 and then Exclude_Parents
11340 then
11341 null;
11343 elsif Node (Elmt) = Iface then
11344 return True;
11345 end if;
11347 Next_Elmt (Elmt);
11348 end loop;
11350 return False;
11351 end Implements_Interface;
11353 ------------------------------------
11354 -- In_Assertion_Expression_Pragma --
11355 ------------------------------------
11357 function In_Assertion_Expression_Pragma (N : Node_Id) return Boolean is
11358 Par : Node_Id;
11359 Prag : Node_Id := Empty;
11361 begin
11362 -- Climb the parent chain looking for an enclosing pragma
11364 Par := N;
11365 while Present (Par) loop
11366 if Nkind (Par) = N_Pragma then
11367 Prag := Par;
11368 exit;
11370 -- Precondition-like pragmas are expanded into if statements, check
11371 -- the original node instead.
11373 elsif Nkind (Original_Node (Par)) = N_Pragma then
11374 Prag := Original_Node (Par);
11375 exit;
11377 -- The expansion of attribute 'Old generates a constant to capture
11378 -- the result of the prefix. If the parent traversal reaches
11379 -- one of these constants, then the node technically came from a
11380 -- postcondition-like pragma. Note that the Ekind is not tested here
11381 -- because N may be the expression of an object declaration which is
11382 -- currently being analyzed. Such objects carry Ekind of E_Void.
11384 elsif Nkind (Par) = N_Object_Declaration
11385 and then Constant_Present (Par)
11386 and then Stores_Attribute_Old_Prefix (Defining_Entity (Par))
11387 then
11388 return True;
11390 -- Prevent the search from going too far
11392 elsif Is_Body_Or_Package_Declaration (Par) then
11393 return False;
11394 end if;
11396 Par := Parent (Par);
11397 end loop;
11399 return
11400 Present (Prag)
11401 and then Assertion_Expression_Pragma (Get_Pragma_Id (Prag));
11402 end In_Assertion_Expression_Pragma;
11404 ----------------------
11405 -- In_Generic_Scope --
11406 ----------------------
11408 function In_Generic_Scope (E : Entity_Id) return Boolean is
11409 S : Entity_Id;
11411 begin
11412 S := Scope (E);
11413 while Present (S) and then S /= Standard_Standard loop
11414 if Is_Generic_Unit (S) then
11415 return True;
11416 end if;
11418 S := Scope (S);
11419 end loop;
11421 return False;
11422 end In_Generic_Scope;
11424 -----------------
11425 -- In_Instance --
11426 -----------------
11428 function In_Instance return Boolean is
11429 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
11430 S : Entity_Id;
11432 begin
11433 S := Current_Scope;
11434 while Present (S) and then S /= Standard_Standard loop
11435 if Is_Generic_Instance (S) then
11437 -- A child instance is always compiled in the context of a parent
11438 -- instance. Nevertheless, the actuals are not analyzed in an
11439 -- instance context. We detect this case by examining the current
11440 -- compilation unit, which must be a child instance, and checking
11441 -- that it is not currently on the scope stack.
11443 if Is_Child_Unit (Curr_Unit)
11444 and then Nkind (Unit (Cunit (Current_Sem_Unit))) =
11445 N_Package_Instantiation
11446 and then not In_Open_Scopes (Curr_Unit)
11447 then
11448 return False;
11449 else
11450 return True;
11451 end if;
11452 end if;
11454 S := Scope (S);
11455 end loop;
11457 return False;
11458 end In_Instance;
11460 ----------------------
11461 -- In_Instance_Body --
11462 ----------------------
11464 function In_Instance_Body return Boolean is
11465 S : Entity_Id;
11467 begin
11468 S := Current_Scope;
11469 while Present (S) and then S /= Standard_Standard loop
11470 if Ekind_In (S, E_Function, E_Procedure)
11471 and then Is_Generic_Instance (S)
11472 then
11473 return True;
11475 elsif Ekind (S) = E_Package
11476 and then In_Package_Body (S)
11477 and then Is_Generic_Instance (S)
11478 then
11479 return True;
11480 end if;
11482 S := Scope (S);
11483 end loop;
11485 return False;
11486 end In_Instance_Body;
11488 -----------------------------
11489 -- In_Instance_Not_Visible --
11490 -----------------------------
11492 function In_Instance_Not_Visible return Boolean is
11493 S : Entity_Id;
11495 begin
11496 S := Current_Scope;
11497 while Present (S) and then S /= Standard_Standard loop
11498 if Ekind_In (S, E_Function, E_Procedure)
11499 and then Is_Generic_Instance (S)
11500 then
11501 return True;
11503 elsif Ekind (S) = E_Package
11504 and then (In_Package_Body (S) or else In_Private_Part (S))
11505 and then Is_Generic_Instance (S)
11506 then
11507 return True;
11508 end if;
11510 S := Scope (S);
11511 end loop;
11513 return False;
11514 end In_Instance_Not_Visible;
11516 ------------------------------
11517 -- In_Instance_Visible_Part --
11518 ------------------------------
11520 function In_Instance_Visible_Part return Boolean is
11521 S : Entity_Id;
11523 begin
11524 S := Current_Scope;
11525 while Present (S) and then S /= Standard_Standard loop
11526 if Ekind (S) = E_Package
11527 and then Is_Generic_Instance (S)
11528 and then not In_Package_Body (S)
11529 and then not In_Private_Part (S)
11530 then
11531 return True;
11532 end if;
11534 S := Scope (S);
11535 end loop;
11537 return False;
11538 end In_Instance_Visible_Part;
11540 ---------------------
11541 -- In_Package_Body --
11542 ---------------------
11544 function In_Package_Body return Boolean is
11545 S : Entity_Id;
11547 begin
11548 S := Current_Scope;
11549 while Present (S) and then S /= Standard_Standard loop
11550 if Ekind (S) = E_Package and then In_Package_Body (S) then
11551 return True;
11552 else
11553 S := Scope (S);
11554 end if;
11555 end loop;
11557 return False;
11558 end In_Package_Body;
11560 --------------------------
11561 -- In_Pragma_Expression --
11562 --------------------------
11564 function In_Pragma_Expression (N : Node_Id; Nam : Name_Id) return Boolean is
11565 P : Node_Id;
11566 begin
11567 P := Parent (N);
11568 loop
11569 if No (P) then
11570 return False;
11571 elsif Nkind (P) = N_Pragma and then Pragma_Name (P) = Nam then
11572 return True;
11573 else
11574 P := Parent (P);
11575 end if;
11576 end loop;
11577 end In_Pragma_Expression;
11579 ---------------------------
11580 -- In_Pre_Post_Condition --
11581 ---------------------------
11583 function In_Pre_Post_Condition (N : Node_Id) return Boolean is
11584 Par : Node_Id;
11585 Prag : Node_Id := Empty;
11586 Prag_Id : Pragma_Id;
11588 begin
11589 -- Climb the parent chain looking for an enclosing pragma
11591 Par := N;
11592 while Present (Par) loop
11593 if Nkind (Par) = N_Pragma then
11594 Prag := Par;
11595 exit;
11597 -- Prevent the search from going too far
11599 elsif Is_Body_Or_Package_Declaration (Par) then
11600 exit;
11601 end if;
11603 Par := Parent (Par);
11604 end loop;
11606 if Present (Prag) then
11607 Prag_Id := Get_Pragma_Id (Prag);
11609 return
11610 Prag_Id = Pragma_Post
11611 or else Prag_Id = Pragma_Post_Class
11612 or else Prag_Id = Pragma_Postcondition
11613 or else Prag_Id = Pragma_Pre
11614 or else Prag_Id = Pragma_Pre_Class
11615 or else Prag_Id = Pragma_Precondition;
11617 -- Otherwise the node is not enclosed by a pre/postcondition pragma
11619 else
11620 return False;
11621 end if;
11622 end In_Pre_Post_Condition;
11624 -------------------------------------
11625 -- In_Reverse_Storage_Order_Object --
11626 -------------------------------------
11628 function In_Reverse_Storage_Order_Object (N : Node_Id) return Boolean is
11629 Pref : Node_Id;
11630 Btyp : Entity_Id := Empty;
11632 begin
11633 -- Climb up indexed components
11635 Pref := N;
11636 loop
11637 case Nkind (Pref) is
11638 when N_Selected_Component =>
11639 Pref := Prefix (Pref);
11640 exit;
11642 when N_Indexed_Component =>
11643 Pref := Prefix (Pref);
11645 when others =>
11646 Pref := Empty;
11647 exit;
11648 end case;
11649 end loop;
11651 if Present (Pref) then
11652 Btyp := Base_Type (Etype (Pref));
11653 end if;
11655 return Present (Btyp)
11656 and then (Is_Record_Type (Btyp) or else Is_Array_Type (Btyp))
11657 and then Reverse_Storage_Order (Btyp);
11658 end In_Reverse_Storage_Order_Object;
11660 --------------------------------------
11661 -- In_Subprogram_Or_Concurrent_Unit --
11662 --------------------------------------
11664 function In_Subprogram_Or_Concurrent_Unit return Boolean is
11665 E : Entity_Id;
11666 K : Entity_Kind;
11668 begin
11669 -- Use scope chain to check successively outer scopes
11671 E := Current_Scope;
11672 loop
11673 K := Ekind (E);
11675 if K in Subprogram_Kind
11676 or else K in Concurrent_Kind
11677 or else K in Generic_Subprogram_Kind
11678 then
11679 return True;
11681 elsif E = Standard_Standard then
11682 return False;
11683 end if;
11685 E := Scope (E);
11686 end loop;
11687 end In_Subprogram_Or_Concurrent_Unit;
11689 ----------------
11690 -- In_Subtree --
11691 ----------------
11693 function In_Subtree (Root : Node_Id; N : Node_Id) return Boolean is
11694 Curr : Node_Id;
11696 begin
11697 Curr := N;
11698 while Present (Curr) loop
11699 if Curr = Root then
11700 return True;
11701 end if;
11703 Curr := Parent (Curr);
11704 end loop;
11706 return False;
11707 end In_Subtree;
11709 ---------------------
11710 -- In_Visible_Part --
11711 ---------------------
11713 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
11714 begin
11715 return Is_Package_Or_Generic_Package (Scope_Id)
11716 and then In_Open_Scopes (Scope_Id)
11717 and then not In_Package_Body (Scope_Id)
11718 and then not In_Private_Part (Scope_Id);
11719 end In_Visible_Part;
11721 --------------------------------
11722 -- Incomplete_Or_Partial_View --
11723 --------------------------------
11725 function Incomplete_Or_Partial_View (Id : Entity_Id) return Entity_Id is
11726 function Inspect_Decls
11727 (Decls : List_Id;
11728 Taft : Boolean := False) return Entity_Id;
11729 -- Check whether a declarative region contains the incomplete or partial
11730 -- view of Id.
11732 -------------------
11733 -- Inspect_Decls --
11734 -------------------
11736 function Inspect_Decls
11737 (Decls : List_Id;
11738 Taft : Boolean := False) return Entity_Id
11740 Decl : Node_Id;
11741 Match : Node_Id;
11743 begin
11744 Decl := First (Decls);
11745 while Present (Decl) loop
11746 Match := Empty;
11748 -- The partial view of a Taft-amendment type is an incomplete
11749 -- type.
11751 if Taft then
11752 if Nkind (Decl) = N_Incomplete_Type_Declaration then
11753 Match := Defining_Identifier (Decl);
11754 end if;
11756 -- Otherwise look for a private type whose full view matches the
11757 -- input type. Note that this checks full_type_declaration nodes
11758 -- to account for derivations from a private type where the type
11759 -- declaration hold the partial view and the full view is an
11760 -- itype.
11762 elsif Nkind_In (Decl, N_Full_Type_Declaration,
11763 N_Private_Extension_Declaration,
11764 N_Private_Type_Declaration)
11765 then
11766 Match := Defining_Identifier (Decl);
11767 end if;
11769 -- Guard against unanalyzed entities
11771 if Present (Match)
11772 and then Is_Type (Match)
11773 and then Present (Full_View (Match))
11774 and then Full_View (Match) = Id
11775 then
11776 return Match;
11777 end if;
11779 Next (Decl);
11780 end loop;
11782 return Empty;
11783 end Inspect_Decls;
11785 -- Local variables
11787 Prev : Entity_Id;
11789 -- Start of processing for Incomplete_Or_Partial_View
11791 begin
11792 -- Deferred constant or incomplete type case
11794 Prev := Current_Entity_In_Scope (Id);
11796 if Present (Prev)
11797 and then (Is_Incomplete_Type (Prev) or else Ekind (Prev) = E_Constant)
11798 and then Present (Full_View (Prev))
11799 and then Full_View (Prev) = Id
11800 then
11801 return Prev;
11802 end if;
11804 -- Private or Taft amendment type case
11806 declare
11807 Pkg : constant Entity_Id := Scope (Id);
11808 Pkg_Decl : Node_Id := Pkg;
11810 begin
11811 if Present (Pkg)
11812 and then Ekind_In (Pkg, E_Generic_Package, E_Package)
11813 then
11814 while Nkind (Pkg_Decl) /= N_Package_Specification loop
11815 Pkg_Decl := Parent (Pkg_Decl);
11816 end loop;
11818 -- It is knows that Typ has a private view, look for it in the
11819 -- visible declarations of the enclosing scope. A special case
11820 -- of this is when the two views have been exchanged - the full
11821 -- appears earlier than the private.
11823 if Has_Private_Declaration (Id) then
11824 Prev := Inspect_Decls (Visible_Declarations (Pkg_Decl));
11826 -- Exchanged view case, look in the private declarations
11828 if No (Prev) then
11829 Prev := Inspect_Decls (Private_Declarations (Pkg_Decl));
11830 end if;
11832 return Prev;
11834 -- Otherwise if this is the package body, then Typ is a potential
11835 -- Taft amendment type. The incomplete view should be located in
11836 -- the private declarations of the enclosing scope.
11838 elsif In_Package_Body (Pkg) then
11839 return Inspect_Decls (Private_Declarations (Pkg_Decl), True);
11840 end if;
11841 end if;
11842 end;
11844 -- The type has no incomplete or private view
11846 return Empty;
11847 end Incomplete_Or_Partial_View;
11849 ----------------------------------
11850 -- Indexed_Component_Bit_Offset --
11851 ----------------------------------
11853 function Indexed_Component_Bit_Offset (N : Node_Id) return Uint is
11854 Exp : constant Node_Id := First (Expressions (N));
11855 Typ : constant Entity_Id := Etype (Prefix (N));
11856 Off : constant Uint := Component_Size (Typ);
11857 Ind : Node_Id;
11859 begin
11860 -- Return early if the component size is not known or variable
11862 if Off = No_Uint or else Off < Uint_0 then
11863 return No_Uint;
11864 end if;
11866 -- Deal with the degenerate case of an empty component
11868 if Off = Uint_0 then
11869 return Off;
11870 end if;
11872 -- Check that both the index value and the low bound are known
11874 if not Compile_Time_Known_Value (Exp) then
11875 return No_Uint;
11876 end if;
11878 Ind := First_Index (Typ);
11879 if No (Ind) then
11880 return No_Uint;
11881 end if;
11883 if Nkind (Ind) = N_Subtype_Indication then
11884 Ind := Constraint (Ind);
11886 if Nkind (Ind) = N_Range_Constraint then
11887 Ind := Range_Expression (Ind);
11888 end if;
11889 end if;
11891 if Nkind (Ind) /= N_Range
11892 or else not Compile_Time_Known_Value (Low_Bound (Ind))
11893 then
11894 return No_Uint;
11895 end if;
11897 -- Return the scaled offset
11899 return Off * (Expr_Value (Exp) - Expr_Value (Low_Bound ((Ind))));
11900 end Indexed_Component_Bit_Offset;
11902 ----------------------------
11903 -- Inherit_Rep_Item_Chain --
11904 ----------------------------
11906 procedure Inherit_Rep_Item_Chain (Typ : Entity_Id; From_Typ : Entity_Id) is
11907 Item : Node_Id;
11908 Next_Item : Node_Id;
11910 begin
11911 -- There are several inheritance scenarios to consider depending on
11912 -- whether both types have rep item chains and whether the destination
11913 -- type already inherits part of the source type's rep item chain.
11915 -- 1) The source type lacks a rep item chain
11916 -- From_Typ ---> Empty
11918 -- Typ --------> Item (or Empty)
11920 -- In this case inheritance cannot take place because there are no items
11921 -- to inherit.
11923 -- 2) The destination type lacks a rep item chain
11924 -- From_Typ ---> Item ---> ...
11926 -- Typ --------> Empty
11928 -- Inheritance takes place by setting the First_Rep_Item of the
11929 -- destination type to the First_Rep_Item of the source type.
11930 -- From_Typ ---> Item ---> ...
11931 -- ^
11932 -- Typ -----------+
11934 -- 3.1) Both source and destination types have at least one rep item.
11935 -- The destination type does NOT inherit a rep item from the source
11936 -- type.
11937 -- From_Typ ---> Item ---> Item
11939 -- Typ --------> Item ---> Item
11941 -- Inheritance takes place by setting the Next_Rep_Item of the last item
11942 -- of the destination type to the First_Rep_Item of the source type.
11943 -- From_Typ -------------------> Item ---> Item
11944 -- ^
11945 -- Typ --------> Item ---> Item --+
11947 -- 3.2) Both source and destination types have at least one rep item.
11948 -- The destination type DOES inherit part of the rep item chain of the
11949 -- source type.
11950 -- From_Typ ---> Item ---> Item ---> Item
11951 -- ^
11952 -- Typ --------> Item ------+
11954 -- This rare case arises when the full view of a private extension must
11955 -- inherit the rep item chain from the full view of its parent type and
11956 -- the full view of the parent type contains extra rep items. Currently
11957 -- only invariants may lead to such form of inheritance.
11959 -- type From_Typ is tagged private
11960 -- with Type_Invariant'Class => Item_2;
11962 -- type Typ is new From_Typ with private
11963 -- with Type_Invariant => Item_4;
11965 -- At this point the rep item chains contain the following items
11967 -- From_Typ -----------> Item_2 ---> Item_3
11968 -- ^
11969 -- Typ --------> Item_4 --+
11971 -- The full views of both types may introduce extra invariants
11973 -- type From_Typ is tagged null record
11974 -- with Type_Invariant => Item_1;
11976 -- type Typ is new From_Typ with null record;
11978 -- The full view of Typ would have to inherit any new rep items added to
11979 -- the full view of From_Typ.
11981 -- From_Typ -----------> Item_1 ---> Item_2 ---> Item_3
11982 -- ^
11983 -- Typ --------> Item_4 --+
11985 -- To achieve this form of inheritance, the destination type must first
11986 -- sever the link between its own rep chain and that of the source type,
11987 -- then inheritance 3.1 takes place.
11989 -- Case 1: The source type lacks a rep item chain
11991 if No (First_Rep_Item (From_Typ)) then
11992 return;
11994 -- Case 2: The destination type lacks a rep item chain
11996 elsif No (First_Rep_Item (Typ)) then
11997 Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ));
11999 -- Case 3: Both the source and destination types have at least one rep
12000 -- item. Traverse the rep item chain of the destination type to find the
12001 -- last rep item.
12003 else
12004 Item := Empty;
12005 Next_Item := First_Rep_Item (Typ);
12006 while Present (Next_Item) loop
12008 -- Detect a link between the destination type's rep chain and that
12009 -- of the source type. There are two possibilities:
12011 -- Variant 1
12012 -- Next_Item
12013 -- V
12014 -- From_Typ ---> Item_1 --->
12015 -- ^
12016 -- Typ -----------+
12018 -- Item is Empty
12020 -- Variant 2
12021 -- Next_Item
12022 -- V
12023 -- From_Typ ---> Item_1 ---> Item_2 --->
12024 -- ^
12025 -- Typ --------> Item_3 ------+
12026 -- ^
12027 -- Item
12029 if Has_Rep_Item (From_Typ, Next_Item) then
12030 exit;
12031 end if;
12033 Item := Next_Item;
12034 Next_Item := Next_Rep_Item (Next_Item);
12035 end loop;
12037 -- Inherit the source type's rep item chain
12039 if Present (Item) then
12040 Set_Next_Rep_Item (Item, First_Rep_Item (From_Typ));
12041 else
12042 Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ));
12043 end if;
12044 end if;
12045 end Inherit_Rep_Item_Chain;
12047 ---------------------------------
12048 -- Insert_Explicit_Dereference --
12049 ---------------------------------
12051 procedure Insert_Explicit_Dereference (N : Node_Id) is
12052 New_Prefix : constant Node_Id := Relocate_Node (N);
12053 Ent : Entity_Id := Empty;
12054 Pref : Node_Id;
12055 I : Interp_Index;
12056 It : Interp;
12057 T : Entity_Id;
12059 begin
12060 Save_Interps (N, New_Prefix);
12062 Rewrite (N,
12063 Make_Explicit_Dereference (Sloc (Parent (N)),
12064 Prefix => New_Prefix));
12066 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
12068 if Is_Overloaded (New_Prefix) then
12070 -- The dereference is also overloaded, and its interpretations are
12071 -- the designated types of the interpretations of the original node.
12073 Set_Etype (N, Any_Type);
12075 Get_First_Interp (New_Prefix, I, It);
12076 while Present (It.Nam) loop
12077 T := It.Typ;
12079 if Is_Access_Type (T) then
12080 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
12081 end if;
12083 Get_Next_Interp (I, It);
12084 end loop;
12086 End_Interp_List;
12088 else
12089 -- Prefix is unambiguous: mark the original prefix (which might
12090 -- Come_From_Source) as a reference, since the new (relocated) one
12091 -- won't be taken into account.
12093 if Is_Entity_Name (New_Prefix) then
12094 Ent := Entity (New_Prefix);
12095 Pref := New_Prefix;
12097 -- For a retrieval of a subcomponent of some composite object,
12098 -- retrieve the ultimate entity if there is one.
12100 elsif Nkind_In (New_Prefix, N_Selected_Component,
12101 N_Indexed_Component)
12102 then
12103 Pref := Prefix (New_Prefix);
12104 while Present (Pref)
12105 and then Nkind_In (Pref, N_Selected_Component,
12106 N_Indexed_Component)
12107 loop
12108 Pref := Prefix (Pref);
12109 end loop;
12111 if Present (Pref) and then Is_Entity_Name (Pref) then
12112 Ent := Entity (Pref);
12113 end if;
12114 end if;
12116 -- Place the reference on the entity node
12118 if Present (Ent) then
12119 Generate_Reference (Ent, Pref);
12120 end if;
12121 end if;
12122 end Insert_Explicit_Dereference;
12124 ------------------------------------------
12125 -- Inspect_Deferred_Constant_Completion --
12126 ------------------------------------------
12128 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
12129 Decl : Node_Id;
12131 begin
12132 Decl := First (Decls);
12133 while Present (Decl) loop
12135 -- Deferred constant signature
12137 if Nkind (Decl) = N_Object_Declaration
12138 and then Constant_Present (Decl)
12139 and then No (Expression (Decl))
12141 -- No need to check internally generated constants
12143 and then Comes_From_Source (Decl)
12145 -- The constant is not completed. A full object declaration or a
12146 -- pragma Import complete a deferred constant.
12148 and then not Has_Completion (Defining_Identifier (Decl))
12149 then
12150 Error_Msg_N
12151 ("constant declaration requires initialization expression",
12152 Defining_Identifier (Decl));
12153 end if;
12155 Decl := Next (Decl);
12156 end loop;
12157 end Inspect_Deferred_Constant_Completion;
12159 -----------------------------
12160 -- Install_Generic_Formals --
12161 -----------------------------
12163 procedure Install_Generic_Formals (Subp_Id : Entity_Id) is
12164 E : Entity_Id;
12166 begin
12167 pragma Assert (Is_Generic_Subprogram (Subp_Id));
12169 E := First_Entity (Subp_Id);
12170 while Present (E) loop
12171 Install_Entity (E);
12172 Next_Entity (E);
12173 end loop;
12174 end Install_Generic_Formals;
12176 ------------------------
12177 -- Install_SPARK_Mode --
12178 ------------------------
12180 procedure Install_SPARK_Mode (Mode : SPARK_Mode_Type; Prag : Node_Id) is
12181 begin
12182 SPARK_Mode := Mode;
12183 SPARK_Mode_Pragma := Prag;
12184 end Install_SPARK_Mode;
12186 -----------------------------
12187 -- Is_Actual_Out_Parameter --
12188 -----------------------------
12190 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
12191 Formal : Entity_Id;
12192 Call : Node_Id;
12193 begin
12194 Find_Actual (N, Formal, Call);
12195 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
12196 end Is_Actual_Out_Parameter;
12198 -------------------------
12199 -- Is_Actual_Parameter --
12200 -------------------------
12202 function Is_Actual_Parameter (N : Node_Id) return Boolean is
12203 PK : constant Node_Kind := Nkind (Parent (N));
12205 begin
12206 case PK is
12207 when N_Parameter_Association =>
12208 return N = Explicit_Actual_Parameter (Parent (N));
12210 when N_Subprogram_Call =>
12211 return Is_List_Member (N)
12212 and then
12213 List_Containing (N) = Parameter_Associations (Parent (N));
12215 when others =>
12216 return False;
12217 end case;
12218 end Is_Actual_Parameter;
12220 --------------------------------
12221 -- Is_Actual_Tagged_Parameter --
12222 --------------------------------
12224 function Is_Actual_Tagged_Parameter (N : Node_Id) return Boolean is
12225 Formal : Entity_Id;
12226 Call : Node_Id;
12227 begin
12228 Find_Actual (N, Formal, Call);
12229 return Present (Formal) and then Is_Tagged_Type (Etype (Formal));
12230 end Is_Actual_Tagged_Parameter;
12232 ---------------------
12233 -- Is_Aliased_View --
12234 ---------------------
12236 function Is_Aliased_View (Obj : Node_Id) return Boolean is
12237 E : Entity_Id;
12239 begin
12240 if Is_Entity_Name (Obj) then
12241 E := Entity (Obj);
12243 return
12244 (Is_Object (E)
12245 and then
12246 (Is_Aliased (E)
12247 or else (Present (Renamed_Object (E))
12248 and then Is_Aliased_View (Renamed_Object (E)))))
12250 or else ((Is_Formal (E)
12251 or else Ekind_In (E, E_Generic_In_Out_Parameter,
12252 E_Generic_In_Parameter))
12253 and then Is_Tagged_Type (Etype (E)))
12255 or else (Is_Concurrent_Type (E) and then In_Open_Scopes (E))
12257 -- Current instance of type, either directly or as rewritten
12258 -- reference to the current object.
12260 or else (Is_Entity_Name (Original_Node (Obj))
12261 and then Present (Entity (Original_Node (Obj)))
12262 and then Is_Type (Entity (Original_Node (Obj))))
12264 or else (Is_Type (E) and then E = Current_Scope)
12266 or else (Is_Incomplete_Or_Private_Type (E)
12267 and then Full_View (E) = Current_Scope)
12269 -- Ada 2012 AI05-0053: the return object of an extended return
12270 -- statement is aliased if its type is immutably limited.
12272 or else (Is_Return_Object (E)
12273 and then Is_Limited_View (Etype (E)));
12275 elsif Nkind (Obj) = N_Selected_Component then
12276 return Is_Aliased (Entity (Selector_Name (Obj)));
12278 elsif Nkind (Obj) = N_Indexed_Component then
12279 return Has_Aliased_Components (Etype (Prefix (Obj)))
12280 or else
12281 (Is_Access_Type (Etype (Prefix (Obj)))
12282 and then Has_Aliased_Components
12283 (Designated_Type (Etype (Prefix (Obj)))));
12285 elsif Nkind_In (Obj, N_Unchecked_Type_Conversion, N_Type_Conversion) then
12286 return Is_Tagged_Type (Etype (Obj))
12287 and then Is_Aliased_View (Expression (Obj));
12289 elsif Nkind (Obj) = N_Explicit_Dereference then
12290 return Nkind (Original_Node (Obj)) /= N_Function_Call;
12292 else
12293 return False;
12294 end if;
12295 end Is_Aliased_View;
12297 -------------------------
12298 -- Is_Ancestor_Package --
12299 -------------------------
12301 function Is_Ancestor_Package
12302 (E1 : Entity_Id;
12303 E2 : Entity_Id) return Boolean
12305 Par : Entity_Id;
12307 begin
12308 Par := E2;
12309 while Present (Par) and then Par /= Standard_Standard loop
12310 if Par = E1 then
12311 return True;
12312 end if;
12314 Par := Scope (Par);
12315 end loop;
12317 return False;
12318 end Is_Ancestor_Package;
12320 ----------------------
12321 -- Is_Atomic_Object --
12322 ----------------------
12324 function Is_Atomic_Object (N : Node_Id) return Boolean is
12326 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
12327 -- Determines if given object has atomic components
12329 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
12330 -- If prefix is an implicit dereference, examine designated type
12332 ----------------------
12333 -- Is_Atomic_Prefix --
12334 ----------------------
12336 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
12337 begin
12338 if Is_Access_Type (Etype (N)) then
12339 return
12340 Has_Atomic_Components (Designated_Type (Etype (N)));
12341 else
12342 return Object_Has_Atomic_Components (N);
12343 end if;
12344 end Is_Atomic_Prefix;
12346 ----------------------------------
12347 -- Object_Has_Atomic_Components --
12348 ----------------------------------
12350 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
12351 begin
12352 if Has_Atomic_Components (Etype (N))
12353 or else Is_Atomic (Etype (N))
12354 then
12355 return True;
12357 elsif Is_Entity_Name (N)
12358 and then (Has_Atomic_Components (Entity (N))
12359 or else Is_Atomic (Entity (N)))
12360 then
12361 return True;
12363 elsif Nkind (N) = N_Selected_Component
12364 and then Is_Atomic (Entity (Selector_Name (N)))
12365 then
12366 return True;
12368 elsif Nkind (N) = N_Indexed_Component
12369 or else Nkind (N) = N_Selected_Component
12370 then
12371 return Is_Atomic_Prefix (Prefix (N));
12373 else
12374 return False;
12375 end if;
12376 end Object_Has_Atomic_Components;
12378 -- Start of processing for Is_Atomic_Object
12380 begin
12381 -- Predicate is not relevant to subprograms
12383 if Is_Entity_Name (N) and then Is_Overloadable (Entity (N)) then
12384 return False;
12386 elsif Is_Atomic (Etype (N))
12387 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
12388 then
12389 return True;
12391 elsif Nkind (N) = N_Selected_Component
12392 and then Is_Atomic (Entity (Selector_Name (N)))
12393 then
12394 return True;
12396 elsif Nkind (N) = N_Indexed_Component
12397 or else Nkind (N) = N_Selected_Component
12398 then
12399 return Is_Atomic_Prefix (Prefix (N));
12401 else
12402 return False;
12403 end if;
12404 end Is_Atomic_Object;
12406 -----------------------------
12407 -- Is_Atomic_Or_VFA_Object --
12408 -----------------------------
12410 function Is_Atomic_Or_VFA_Object (N : Node_Id) return Boolean is
12411 begin
12412 return Is_Atomic_Object (N)
12413 or else (Is_Object_Reference (N)
12414 and then Is_Entity_Name (N)
12415 and then (Is_Volatile_Full_Access (Entity (N))
12416 or else
12417 Is_Volatile_Full_Access (Etype (Entity (N)))));
12418 end Is_Atomic_Or_VFA_Object;
12420 -------------------------
12421 -- Is_Attribute_Result --
12422 -------------------------
12424 function Is_Attribute_Result (N : Node_Id) return Boolean is
12425 begin
12426 return Nkind (N) = N_Attribute_Reference
12427 and then Attribute_Name (N) = Name_Result;
12428 end Is_Attribute_Result;
12430 -------------------------
12431 -- Is_Attribute_Update --
12432 -------------------------
12434 function Is_Attribute_Update (N : Node_Id) return Boolean is
12435 begin
12436 return Nkind (N) = N_Attribute_Reference
12437 and then Attribute_Name (N) = Name_Update;
12438 end Is_Attribute_Update;
12440 ------------------------------------
12441 -- Is_Body_Or_Package_Declaration --
12442 ------------------------------------
12444 function Is_Body_Or_Package_Declaration (N : Node_Id) return Boolean is
12445 begin
12446 return Nkind_In (N, N_Entry_Body,
12447 N_Package_Body,
12448 N_Package_Declaration,
12449 N_Protected_Body,
12450 N_Subprogram_Body,
12451 N_Task_Body);
12452 end Is_Body_Or_Package_Declaration;
12454 -----------------------
12455 -- Is_Bounded_String --
12456 -----------------------
12458 function Is_Bounded_String (T : Entity_Id) return Boolean is
12459 Under : constant Entity_Id := Underlying_Type (Root_Type (T));
12461 begin
12462 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
12463 -- Super_String, or one of the [Wide_]Wide_ versions. This will
12464 -- be True for all the Bounded_String types in instances of the
12465 -- Generic_Bounded_Length generics, and for types derived from those.
12467 return Present (Under)
12468 and then (Is_RTE (Root_Type (Under), RO_SU_Super_String) or else
12469 Is_RTE (Root_Type (Under), RO_WI_Super_String) or else
12470 Is_RTE (Root_Type (Under), RO_WW_Super_String));
12471 end Is_Bounded_String;
12473 ---------------------
12474 -- Is_CCT_Instance --
12475 ---------------------
12477 function Is_CCT_Instance
12478 (Ref_Id : Entity_Id;
12479 Context_Id : Entity_Id) return Boolean
12481 begin
12482 pragma Assert (Ekind_In (Ref_Id, E_Protected_Type, E_Task_Type));
12484 if Is_Single_Task_Object (Context_Id) then
12485 return Scope_Within_Or_Same (Etype (Context_Id), Ref_Id);
12487 else
12488 pragma Assert (Ekind_In (Context_Id, E_Entry,
12489 E_Entry_Family,
12490 E_Function,
12491 E_Package,
12492 E_Procedure,
12493 E_Protected_Type,
12494 E_Task_Type));
12496 return Scope_Within_Or_Same (Context_Id, Ref_Id);
12497 end if;
12498 end Is_CCT_Instance;
12500 -------------------------
12501 -- Is_Child_Or_Sibling --
12502 -------------------------
12504 function Is_Child_Or_Sibling
12505 (Pack_1 : Entity_Id;
12506 Pack_2 : Entity_Id) return Boolean
12508 function Distance_From_Standard (Pack : Entity_Id) return Nat;
12509 -- Given an arbitrary package, return the number of "climbs" necessary
12510 -- to reach scope Standard_Standard.
12512 procedure Equalize_Depths
12513 (Pack : in out Entity_Id;
12514 Depth : in out Nat;
12515 Depth_To_Reach : Nat);
12516 -- Given an arbitrary package, its depth and a target depth to reach,
12517 -- climb the scope chain until the said depth is reached. The pointer
12518 -- to the package and its depth a modified during the climb.
12520 ----------------------------
12521 -- Distance_From_Standard --
12522 ----------------------------
12524 function Distance_From_Standard (Pack : Entity_Id) return Nat is
12525 Dist : Nat;
12526 Scop : Entity_Id;
12528 begin
12529 Dist := 0;
12530 Scop := Pack;
12531 while Present (Scop) and then Scop /= Standard_Standard loop
12532 Dist := Dist + 1;
12533 Scop := Scope (Scop);
12534 end loop;
12536 return Dist;
12537 end Distance_From_Standard;
12539 ---------------------
12540 -- Equalize_Depths --
12541 ---------------------
12543 procedure Equalize_Depths
12544 (Pack : in out Entity_Id;
12545 Depth : in out Nat;
12546 Depth_To_Reach : Nat)
12548 begin
12549 -- The package must be at a greater or equal depth
12551 if Depth < Depth_To_Reach then
12552 raise Program_Error;
12553 end if;
12555 -- Climb the scope chain until the desired depth is reached
12557 while Present (Pack) and then Depth /= Depth_To_Reach loop
12558 Pack := Scope (Pack);
12559 Depth := Depth - 1;
12560 end loop;
12561 end Equalize_Depths;
12563 -- Local variables
12565 P_1 : Entity_Id := Pack_1;
12566 P_1_Child : Boolean := False;
12567 P_1_Depth : Nat := Distance_From_Standard (P_1);
12568 P_2 : Entity_Id := Pack_2;
12569 P_2_Child : Boolean := False;
12570 P_2_Depth : Nat := Distance_From_Standard (P_2);
12572 -- Start of processing for Is_Child_Or_Sibling
12574 begin
12575 pragma Assert
12576 (Ekind (Pack_1) = E_Package and then Ekind (Pack_2) = E_Package);
12578 -- Both packages denote the same entity, therefore they cannot be
12579 -- children or siblings.
12581 if P_1 = P_2 then
12582 return False;
12584 -- One of the packages is at a deeper level than the other. Note that
12585 -- both may still come from different hierarchies.
12587 -- (root) P_2
12588 -- / \ :
12589 -- X P_2 or X
12590 -- : :
12591 -- P_1 P_1
12593 elsif P_1_Depth > P_2_Depth then
12594 Equalize_Depths
12595 (Pack => P_1,
12596 Depth => P_1_Depth,
12597 Depth_To_Reach => P_2_Depth);
12598 P_1_Child := True;
12600 -- (root) P_1
12601 -- / \ :
12602 -- P_1 X or X
12603 -- : :
12604 -- P_2 P_2
12606 elsif P_2_Depth > P_1_Depth then
12607 Equalize_Depths
12608 (Pack => P_2,
12609 Depth => P_2_Depth,
12610 Depth_To_Reach => P_1_Depth);
12611 P_2_Child := True;
12612 end if;
12614 -- At this stage the package pointers have been elevated to the same
12615 -- depth. If the related entities are the same, then one package is a
12616 -- potential child of the other:
12618 -- P_1
12619 -- :
12620 -- X became P_1 P_2 or vice versa
12621 -- :
12622 -- P_2
12624 if P_1 = P_2 then
12625 if P_1_Child then
12626 return Is_Child_Unit (Pack_1);
12628 else pragma Assert (P_2_Child);
12629 return Is_Child_Unit (Pack_2);
12630 end if;
12632 -- The packages may come from the same package chain or from entirely
12633 -- different hierarcies. To determine this, climb the scope stack until
12634 -- a common root is found.
12636 -- (root) (root 1) (root 2)
12637 -- / \ | |
12638 -- P_1 P_2 P_1 P_2
12640 else
12641 while Present (P_1) and then Present (P_2) loop
12643 -- The two packages may be siblings
12645 if P_1 = P_2 then
12646 return Is_Child_Unit (Pack_1) and then Is_Child_Unit (Pack_2);
12647 end if;
12649 P_1 := Scope (P_1);
12650 P_2 := Scope (P_2);
12651 end loop;
12652 end if;
12654 return False;
12655 end Is_Child_Or_Sibling;
12657 -----------------------------
12658 -- Is_Concurrent_Interface --
12659 -----------------------------
12661 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
12662 begin
12663 return Is_Interface (T)
12664 and then
12665 (Is_Protected_Interface (T)
12666 or else Is_Synchronized_Interface (T)
12667 or else Is_Task_Interface (T));
12668 end Is_Concurrent_Interface;
12670 -----------------------
12671 -- Is_Constant_Bound --
12672 -----------------------
12674 function Is_Constant_Bound (Exp : Node_Id) return Boolean is
12675 begin
12676 if Compile_Time_Known_Value (Exp) then
12677 return True;
12679 elsif Is_Entity_Name (Exp) and then Present (Entity (Exp)) then
12680 return Is_Constant_Object (Entity (Exp))
12681 or else Ekind (Entity (Exp)) = E_Enumeration_Literal;
12683 elsif Nkind (Exp) in N_Binary_Op then
12684 return Is_Constant_Bound (Left_Opnd (Exp))
12685 and then Is_Constant_Bound (Right_Opnd (Exp))
12686 and then Scope (Entity (Exp)) = Standard_Standard;
12688 else
12689 return False;
12690 end if;
12691 end Is_Constant_Bound;
12693 ---------------------------
12694 -- Is_Container_Element --
12695 ---------------------------
12697 function Is_Container_Element (Exp : Node_Id) return Boolean is
12698 Loc : constant Source_Ptr := Sloc (Exp);
12699 Pref : constant Node_Id := Prefix (Exp);
12701 Call : Node_Id;
12702 -- Call to an indexing aspect
12704 Cont_Typ : Entity_Id;
12705 -- The type of the container being accessed
12707 Elem_Typ : Entity_Id;
12708 -- Its element type
12710 Indexing : Entity_Id;
12711 Is_Const : Boolean;
12712 -- Indicates that constant indexing is used, and the element is thus
12713 -- a constant.
12715 Ref_Typ : Entity_Id;
12716 -- The reference type returned by the indexing operation
12718 begin
12719 -- If C is a container, in a context that imposes the element type of
12720 -- that container, the indexing notation C (X) is rewritten as:
12722 -- Indexing (C, X).Discr.all
12724 -- where Indexing is one of the indexing aspects of the container.
12725 -- If the context does not require a reference, the construct can be
12726 -- rewritten as
12728 -- Element (C, X)
12730 -- First, verify that the construct has the proper form
12732 if not Expander_Active then
12733 return False;
12735 elsif Nkind (Pref) /= N_Selected_Component then
12736 return False;
12738 elsif Nkind (Prefix (Pref)) /= N_Function_Call then
12739 return False;
12741 else
12742 Call := Prefix (Pref);
12743 Ref_Typ := Etype (Call);
12744 end if;
12746 if not Has_Implicit_Dereference (Ref_Typ)
12747 or else No (First (Parameter_Associations (Call)))
12748 or else not Is_Entity_Name (Name (Call))
12749 then
12750 return False;
12751 end if;
12753 -- Retrieve type of container object, and its iterator aspects
12755 Cont_Typ := Etype (First (Parameter_Associations (Call)));
12756 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Constant_Indexing);
12757 Is_Const := False;
12759 if No (Indexing) then
12761 -- Container should have at least one indexing operation
12763 return False;
12765 elsif Entity (Name (Call)) /= Entity (Indexing) then
12767 -- This may be a variable indexing operation
12769 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Variable_Indexing);
12771 if No (Indexing)
12772 or else Entity (Name (Call)) /= Entity (Indexing)
12773 then
12774 return False;
12775 end if;
12777 else
12778 Is_Const := True;
12779 end if;
12781 Elem_Typ := Find_Value_Of_Aspect (Cont_Typ, Aspect_Iterator_Element);
12783 if No (Elem_Typ) or else Entity (Elem_Typ) /= Etype (Exp) then
12784 return False;
12785 end if;
12787 -- Check that the expression is not the target of an assignment, in
12788 -- which case the rewriting is not possible.
12790 if not Is_Const then
12791 declare
12792 Par : Node_Id;
12794 begin
12795 Par := Exp;
12796 while Present (Par)
12797 loop
12798 if Nkind (Parent (Par)) = N_Assignment_Statement
12799 and then Par = Name (Parent (Par))
12800 then
12801 return False;
12803 -- A renaming produces a reference, and the transformation
12804 -- does not apply.
12806 elsif Nkind (Parent (Par)) = N_Object_Renaming_Declaration then
12807 return False;
12809 elsif Nkind_In
12810 (Nkind (Parent (Par)), N_Function_Call,
12811 N_Procedure_Call_Statement,
12812 N_Entry_Call_Statement)
12813 then
12814 -- Check that the element is not part of an actual for an
12815 -- in-out parameter.
12817 declare
12818 F : Entity_Id;
12819 A : Node_Id;
12821 begin
12822 F := First_Formal (Entity (Name (Parent (Par))));
12823 A := First (Parameter_Associations (Parent (Par)));
12824 while Present (F) loop
12825 if A = Par and then Ekind (F) /= E_In_Parameter then
12826 return False;
12827 end if;
12829 Next_Formal (F);
12830 Next (A);
12831 end loop;
12832 end;
12834 -- E_In_Parameter in a call: element is not modified.
12836 exit;
12837 end if;
12839 Par := Parent (Par);
12840 end loop;
12841 end;
12842 end if;
12844 -- The expression has the proper form and the context requires the
12845 -- element type. Retrieve the Element function of the container and
12846 -- rewrite the construct as a call to it.
12848 declare
12849 Op : Elmt_Id;
12851 begin
12852 Op := First_Elmt (Primitive_Operations (Cont_Typ));
12853 while Present (Op) loop
12854 exit when Chars (Node (Op)) = Name_Element;
12855 Next_Elmt (Op);
12856 end loop;
12858 if No (Op) then
12859 return False;
12861 else
12862 Rewrite (Exp,
12863 Make_Function_Call (Loc,
12864 Name => New_Occurrence_Of (Node (Op), Loc),
12865 Parameter_Associations => Parameter_Associations (Call)));
12866 Analyze_And_Resolve (Exp, Entity (Elem_Typ));
12867 return True;
12868 end if;
12869 end;
12870 end Is_Container_Element;
12872 ----------------------------
12873 -- Is_Contract_Annotation --
12874 ----------------------------
12876 function Is_Contract_Annotation (Item : Node_Id) return Boolean is
12877 begin
12878 return Is_Package_Contract_Annotation (Item)
12879 or else
12880 Is_Subprogram_Contract_Annotation (Item);
12881 end Is_Contract_Annotation;
12883 --------------------------------------
12884 -- Is_Controlling_Limited_Procedure --
12885 --------------------------------------
12887 function Is_Controlling_Limited_Procedure
12888 (Proc_Nam : Entity_Id) return Boolean
12890 Param_Typ : Entity_Id := Empty;
12892 begin
12893 if Ekind (Proc_Nam) = E_Procedure
12894 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
12895 then
12896 Param_Typ := Etype (Parameter_Type (First (
12897 Parameter_Specifications (Parent (Proc_Nam)))));
12899 -- In this case where an Itype was created, the procedure call has been
12900 -- rewritten.
12902 elsif Present (Associated_Node_For_Itype (Proc_Nam))
12903 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
12904 and then
12905 Present (Parameter_Associations
12906 (Associated_Node_For_Itype (Proc_Nam)))
12907 then
12908 Param_Typ :=
12909 Etype (First (Parameter_Associations
12910 (Associated_Node_For_Itype (Proc_Nam))));
12911 end if;
12913 if Present (Param_Typ) then
12914 return
12915 Is_Interface (Param_Typ)
12916 and then Is_Limited_Record (Param_Typ);
12917 end if;
12919 return False;
12920 end Is_Controlling_Limited_Procedure;
12922 -----------------------------
12923 -- Is_CPP_Constructor_Call --
12924 -----------------------------
12926 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
12927 begin
12928 return Nkind (N) = N_Function_Call
12929 and then Is_CPP_Class (Etype (Etype (N)))
12930 and then Is_Constructor (Entity (Name (N)))
12931 and then Is_Imported (Entity (Name (N)));
12932 end Is_CPP_Constructor_Call;
12934 -------------------------
12935 -- Is_Current_Instance --
12936 -------------------------
12938 function Is_Current_Instance (N : Node_Id) return Boolean is
12939 Typ : constant Entity_Id := Entity (N);
12940 P : Node_Id;
12942 begin
12943 -- Simplest case: entity is a concurrent type and we are currently
12944 -- inside the body. This will eventually be expanded into a
12945 -- call to Self (for tasks) or _object (for protected objects).
12947 if Is_Concurrent_Type (Typ) and then In_Open_Scopes (Typ) then
12948 return True;
12950 else
12951 -- Check whether the context is a (sub)type declaration for the
12952 -- type entity.
12954 P := Parent (N);
12955 while Present (P) loop
12956 if Nkind_In (P, N_Full_Type_Declaration,
12957 N_Private_Type_Declaration,
12958 N_Subtype_Declaration)
12959 and then Comes_From_Source (P)
12960 and then Defining_Entity (P) = Typ
12961 then
12962 return True;
12964 -- A subtype name may appear in an aspect specification for a
12965 -- Predicate_Failure aspect, for which we do not construct a
12966 -- wrapper procedure. The subtype will be replaced by the
12967 -- expression being tested when the corresponding predicate
12968 -- check is expanded.
12970 elsif Nkind (P) = N_Aspect_Specification
12971 and then Nkind (Parent (P)) = N_Subtype_Declaration
12972 then
12973 return True;
12975 elsif Nkind (P) = N_Pragma
12976 and then
12977 Get_Pragma_Id (P) = Pragma_Predicate_Failure
12978 then
12979 return True;
12980 end if;
12982 P := Parent (P);
12983 end loop;
12984 end if;
12986 -- In any other context this is not a current occurrence
12988 return False;
12989 end Is_Current_Instance;
12991 --------------------
12992 -- Is_Declaration --
12993 --------------------
12995 function Is_Declaration (N : Node_Id) return Boolean is
12996 begin
12997 return
12998 Is_Declaration_Other_Than_Renaming (N)
12999 or else Is_Renaming_Declaration (N);
13000 end Is_Declaration;
13002 ----------------------------------------
13003 -- Is_Declaration_Other_Than_Renaming --
13004 ----------------------------------------
13006 function Is_Declaration_Other_Than_Renaming (N : Node_Id) return Boolean is
13007 begin
13008 case Nkind (N) is
13009 when N_Abstract_Subprogram_Declaration
13010 | N_Exception_Declaration
13011 | N_Expression_Function
13012 | N_Full_Type_Declaration
13013 | N_Generic_Package_Declaration
13014 | N_Generic_Subprogram_Declaration
13015 | N_Number_Declaration
13016 | N_Object_Declaration
13017 | N_Package_Declaration
13018 | N_Private_Extension_Declaration
13019 | N_Private_Type_Declaration
13020 | N_Subprogram_Declaration
13021 | N_Subtype_Declaration
13023 return True;
13025 when others =>
13026 return False;
13027 end case;
13028 end Is_Declaration_Other_Than_Renaming;
13030 --------------------------------
13031 -- Is_Declared_Within_Variant --
13032 --------------------------------
13034 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
13035 Comp_Decl : constant Node_Id := Parent (Comp);
13036 Comp_List : constant Node_Id := Parent (Comp_Decl);
13037 begin
13038 return Nkind (Parent (Comp_List)) = N_Variant;
13039 end Is_Declared_Within_Variant;
13041 ----------------------------------------------
13042 -- Is_Dependent_Component_Of_Mutable_Object --
13043 ----------------------------------------------
13045 function Is_Dependent_Component_Of_Mutable_Object
13046 (Object : Node_Id) return Boolean
13048 P : Node_Id;
13049 Prefix_Type : Entity_Id;
13050 P_Aliased : Boolean := False;
13051 Comp : Entity_Id;
13053 Deref : Node_Id := Object;
13054 -- Dereference node, in something like X.all.Y(2)
13056 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
13058 begin
13059 -- Find the dereference node if any
13061 while Nkind_In (Deref, N_Indexed_Component,
13062 N_Selected_Component,
13063 N_Slice)
13064 loop
13065 Deref := Prefix (Deref);
13066 end loop;
13068 -- Ada 2005: If we have a component or slice of a dereference,
13069 -- something like X.all.Y (2), and the type of X is access-to-constant,
13070 -- Is_Variable will return False, because it is indeed a constant
13071 -- view. But it might be a view of a variable object, so we want the
13072 -- following condition to be True in that case.
13074 if Is_Variable (Object)
13075 or else (Ada_Version >= Ada_2005
13076 and then Nkind (Deref) = N_Explicit_Dereference)
13077 then
13078 if Nkind (Object) = N_Selected_Component then
13079 P := Prefix (Object);
13080 Prefix_Type := Etype (P);
13082 if Is_Entity_Name (P) then
13083 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
13084 Prefix_Type := Base_Type (Prefix_Type);
13085 end if;
13087 if Is_Aliased (Entity (P)) then
13088 P_Aliased := True;
13089 end if;
13091 -- A discriminant check on a selected component may be expanded
13092 -- into a dereference when removing side-effects. Recover the
13093 -- original node and its type, which may be unconstrained.
13095 elsif Nkind (P) = N_Explicit_Dereference
13096 and then not (Comes_From_Source (P))
13097 then
13098 P := Original_Node (P);
13099 Prefix_Type := Etype (P);
13101 else
13102 -- Check for prefix being an aliased component???
13104 null;
13106 end if;
13108 -- A heap object is constrained by its initial value
13110 -- Ada 2005 (AI-363): Always assume the object could be mutable in
13111 -- the dereferenced case, since the access value might denote an
13112 -- unconstrained aliased object, whereas in Ada 95 the designated
13113 -- object is guaranteed to be constrained. A worst-case assumption
13114 -- has to apply in Ada 2005 because we can't tell at compile
13115 -- time whether the object is "constrained by its initial value",
13116 -- despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are semantic
13117 -- rules (these rules are acknowledged to need fixing). We don't
13118 -- impose this more stringent checking for earlier Ada versions or
13119 -- when Relaxed_RM_Semantics applies (the latter for CodePeer's
13120 -- benefit, though it's unclear on why using -gnat95 would not be
13121 -- sufficient???).
13123 if Ada_Version < Ada_2005 or else Relaxed_RM_Semantics then
13124 if Is_Access_Type (Prefix_Type)
13125 or else Nkind (P) = N_Explicit_Dereference
13126 then
13127 return False;
13128 end if;
13130 else pragma Assert (Ada_Version >= Ada_2005);
13131 if Is_Access_Type (Prefix_Type) then
13133 -- If the access type is pool-specific, and there is no
13134 -- constrained partial view of the designated type, then the
13135 -- designated object is known to be constrained.
13137 if Ekind (Prefix_Type) = E_Access_Type
13138 and then not Object_Type_Has_Constrained_Partial_View
13139 (Typ => Designated_Type (Prefix_Type),
13140 Scop => Current_Scope)
13141 then
13142 return False;
13144 -- Otherwise (general access type, or there is a constrained
13145 -- partial view of the designated type), we need to check
13146 -- based on the designated type.
13148 else
13149 Prefix_Type := Designated_Type (Prefix_Type);
13150 end if;
13151 end if;
13152 end if;
13154 Comp :=
13155 Original_Record_Component (Entity (Selector_Name (Object)));
13157 -- As per AI-0017, the renaming is illegal in a generic body, even
13158 -- if the subtype is indefinite.
13160 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
13162 if not Is_Constrained (Prefix_Type)
13163 and then (Is_Definite_Subtype (Prefix_Type)
13164 or else
13165 (Is_Generic_Type (Prefix_Type)
13166 and then Ekind (Current_Scope) = E_Generic_Package
13167 and then In_Package_Body (Current_Scope)))
13169 and then (Is_Declared_Within_Variant (Comp)
13170 or else Has_Discriminant_Dependent_Constraint (Comp))
13171 and then (not P_Aliased or else Ada_Version >= Ada_2005)
13172 then
13173 return True;
13175 -- If the prefix is of an access type at this point, then we want
13176 -- to return False, rather than calling this function recursively
13177 -- on the access object (which itself might be a discriminant-
13178 -- dependent component of some other object, but that isn't
13179 -- relevant to checking the object passed to us). This avoids
13180 -- issuing wrong errors when compiling with -gnatc, where there
13181 -- can be implicit dereferences that have not been expanded.
13183 elsif Is_Access_Type (Etype (Prefix (Object))) then
13184 return False;
13186 else
13187 return
13188 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
13189 end if;
13191 elsif Nkind (Object) = N_Indexed_Component
13192 or else Nkind (Object) = N_Slice
13193 then
13194 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
13196 -- A type conversion that Is_Variable is a view conversion:
13197 -- go back to the denoted object.
13199 elsif Nkind (Object) = N_Type_Conversion then
13200 return
13201 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
13202 end if;
13203 end if;
13205 return False;
13206 end Is_Dependent_Component_Of_Mutable_Object;
13208 ---------------------
13209 -- Is_Dereferenced --
13210 ---------------------
13212 function Is_Dereferenced (N : Node_Id) return Boolean is
13213 P : constant Node_Id := Parent (N);
13214 begin
13215 return Nkind_In (P, N_Selected_Component,
13216 N_Explicit_Dereference,
13217 N_Indexed_Component,
13218 N_Slice)
13219 and then Prefix (P) = N;
13220 end Is_Dereferenced;
13222 ----------------------
13223 -- Is_Descendant_Of --
13224 ----------------------
13226 function Is_Descendant_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
13227 T : Entity_Id;
13228 Etyp : Entity_Id;
13230 begin
13231 pragma Assert (Nkind (T1) in N_Entity);
13232 pragma Assert (Nkind (T2) in N_Entity);
13234 T := Base_Type (T1);
13236 -- Immediate return if the types match
13238 if T = T2 then
13239 return True;
13241 -- Comment needed here ???
13243 elsif Ekind (T) = E_Class_Wide_Type then
13244 return Etype (T) = T2;
13246 -- All other cases
13248 else
13249 loop
13250 Etyp := Etype (T);
13252 -- Done if we found the type we are looking for
13254 if Etyp = T2 then
13255 return True;
13257 -- Done if no more derivations to check
13259 elsif T = T1
13260 or else T = Etyp
13261 then
13262 return False;
13264 -- Following test catches error cases resulting from prev errors
13266 elsif No (Etyp) then
13267 return False;
13269 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
13270 return False;
13272 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
13273 return False;
13274 end if;
13276 T := Base_Type (Etyp);
13277 end loop;
13278 end if;
13279 end Is_Descendant_Of;
13281 ----------------------------------------
13282 -- Is_Descendant_Of_Suspension_Object --
13283 ----------------------------------------
13285 function Is_Descendant_Of_Suspension_Object
13286 (Typ : Entity_Id) return Boolean
13288 Cur_Typ : Entity_Id;
13289 Par_Typ : Entity_Id;
13291 begin
13292 -- Climb the type derivation chain checking each parent type against
13293 -- Suspension_Object.
13295 Cur_Typ := Base_Type (Typ);
13296 while Present (Cur_Typ) loop
13297 Par_Typ := Etype (Cur_Typ);
13299 -- The current type is a match
13301 if Is_Suspension_Object (Cur_Typ) then
13302 return True;
13304 -- Stop the traversal once the root of the derivation chain has been
13305 -- reached. In that case the current type is its own base type.
13307 elsif Cur_Typ = Par_Typ then
13308 exit;
13309 end if;
13311 Cur_Typ := Base_Type (Par_Typ);
13312 end loop;
13314 return False;
13315 end Is_Descendant_Of_Suspension_Object;
13317 ---------------------------------------------
13318 -- Is_Double_Precision_Floating_Point_Type --
13319 ---------------------------------------------
13321 function Is_Double_Precision_Floating_Point_Type
13322 (E : Entity_Id) return Boolean is
13323 begin
13324 return Is_Floating_Point_Type (E)
13325 and then Machine_Radix_Value (E) = Uint_2
13326 and then Machine_Mantissa_Value (E) = UI_From_Int (53)
13327 and then Machine_Emax_Value (E) = Uint_2 ** Uint_10
13328 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_10);
13329 end Is_Double_Precision_Floating_Point_Type;
13331 -----------------------------
13332 -- Is_Effectively_Volatile --
13333 -----------------------------
13335 function Is_Effectively_Volatile (Id : Entity_Id) return Boolean is
13336 begin
13337 if Is_Type (Id) then
13339 -- An arbitrary type is effectively volatile when it is subject to
13340 -- pragma Atomic or Volatile.
13342 if Is_Volatile (Id) then
13343 return True;
13345 -- An array type is effectively volatile when it is subject to pragma
13346 -- Atomic_Components or Volatile_Components or its component type is
13347 -- effectively volatile.
13349 elsif Is_Array_Type (Id) then
13350 declare
13351 Anc : Entity_Id := Base_Type (Id);
13352 begin
13353 if Is_Private_Type (Anc) then
13354 Anc := Full_View (Anc);
13355 end if;
13357 -- Test for presence of ancestor, as the full view of a private
13358 -- type may be missing in case of error.
13360 return
13361 Has_Volatile_Components (Id)
13362 or else
13363 (Present (Anc)
13364 and then Is_Effectively_Volatile (Component_Type (Anc)));
13365 end;
13367 -- A protected type is always volatile
13369 elsif Is_Protected_Type (Id) then
13370 return True;
13372 -- A descendant of Ada.Synchronous_Task_Control.Suspension_Object is
13373 -- automatically volatile.
13375 elsif Is_Descendant_Of_Suspension_Object (Id) then
13376 return True;
13378 -- Otherwise the type is not effectively volatile
13380 else
13381 return False;
13382 end if;
13384 -- Otherwise Id denotes an object
13386 else
13387 return
13388 Is_Volatile (Id)
13389 or else Has_Volatile_Components (Id)
13390 or else Is_Effectively_Volatile (Etype (Id));
13391 end if;
13392 end Is_Effectively_Volatile;
13394 ------------------------------------
13395 -- Is_Effectively_Volatile_Object --
13396 ------------------------------------
13398 function Is_Effectively_Volatile_Object (N : Node_Id) return Boolean is
13399 begin
13400 if Is_Entity_Name (N) then
13401 return Is_Effectively_Volatile (Entity (N));
13403 elsif Nkind (N) = N_Indexed_Component then
13404 return Is_Effectively_Volatile_Object (Prefix (N));
13406 elsif Nkind (N) = N_Selected_Component then
13407 return
13408 Is_Effectively_Volatile_Object (Prefix (N))
13409 or else
13410 Is_Effectively_Volatile_Object (Selector_Name (N));
13412 else
13413 return False;
13414 end if;
13415 end Is_Effectively_Volatile_Object;
13417 -------------------
13418 -- Is_Entry_Body --
13419 -------------------
13421 function Is_Entry_Body (Id : Entity_Id) return Boolean is
13422 begin
13423 return
13424 Ekind_In (Id, E_Entry, E_Entry_Family)
13425 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Body;
13426 end Is_Entry_Body;
13428 --------------------------
13429 -- Is_Entry_Declaration --
13430 --------------------------
13432 function Is_Entry_Declaration (Id : Entity_Id) return Boolean is
13433 begin
13434 return
13435 Ekind_In (Id, E_Entry, E_Entry_Family)
13436 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Declaration;
13437 end Is_Entry_Declaration;
13439 ------------------------------------
13440 -- Is_Expanded_Priority_Attribute --
13441 ------------------------------------
13443 function Is_Expanded_Priority_Attribute (E : Entity_Id) return Boolean is
13444 begin
13445 return
13446 Nkind (E) = N_Function_Call
13447 and then not Configurable_Run_Time_Mode
13448 and then (Entity (Name (E)) = RTE (RE_Get_Ceiling)
13449 or else Entity (Name (E)) = RTE (RO_PE_Get_Ceiling));
13450 end Is_Expanded_Priority_Attribute;
13452 ----------------------------
13453 -- Is_Expression_Function --
13454 ----------------------------
13456 function Is_Expression_Function (Subp : Entity_Id) return Boolean is
13457 begin
13458 if Ekind_In (Subp, E_Function, E_Subprogram_Body) then
13459 return
13460 Nkind (Original_Node (Unit_Declaration_Node (Subp))) =
13461 N_Expression_Function;
13462 else
13463 return False;
13464 end if;
13465 end Is_Expression_Function;
13467 ------------------------------------------
13468 -- Is_Expression_Function_Or_Completion --
13469 ------------------------------------------
13471 function Is_Expression_Function_Or_Completion
13472 (Subp : Entity_Id) return Boolean
13474 Subp_Decl : Node_Id;
13476 begin
13477 if Ekind (Subp) = E_Function then
13478 Subp_Decl := Unit_Declaration_Node (Subp);
13480 -- The function declaration is either an expression function or is
13481 -- completed by an expression function body.
13483 return
13484 Is_Expression_Function (Subp)
13485 or else (Nkind (Subp_Decl) = N_Subprogram_Declaration
13486 and then Present (Corresponding_Body (Subp_Decl))
13487 and then Is_Expression_Function
13488 (Corresponding_Body (Subp_Decl)));
13490 elsif Ekind (Subp) = E_Subprogram_Body then
13491 return Is_Expression_Function (Subp);
13493 else
13494 return False;
13495 end if;
13496 end Is_Expression_Function_Or_Completion;
13498 -----------------------
13499 -- Is_EVF_Expression --
13500 -----------------------
13502 function Is_EVF_Expression (N : Node_Id) return Boolean is
13503 Orig_N : constant Node_Id := Original_Node (N);
13504 Alt : Node_Id;
13505 Expr : Node_Id;
13506 Id : Entity_Id;
13508 begin
13509 -- Detect a reference to a formal parameter of a specific tagged type
13510 -- whose related subprogram is subject to pragma Expresions_Visible with
13511 -- value "False".
13513 if Is_Entity_Name (N) and then Present (Entity (N)) then
13514 Id := Entity (N);
13516 return
13517 Is_Formal (Id)
13518 and then Is_Specific_Tagged_Type (Etype (Id))
13519 and then Extensions_Visible_Status (Id) =
13520 Extensions_Visible_False;
13522 -- A case expression is an EVF expression when it contains at least one
13523 -- EVF dependent_expression. Note that a case expression may have been
13524 -- expanded, hence the use of Original_Node.
13526 elsif Nkind (Orig_N) = N_Case_Expression then
13527 Alt := First (Alternatives (Orig_N));
13528 while Present (Alt) loop
13529 if Is_EVF_Expression (Expression (Alt)) then
13530 return True;
13531 end if;
13533 Next (Alt);
13534 end loop;
13536 -- An if expression is an EVF expression when it contains at least one
13537 -- EVF dependent_expression. Note that an if expression may have been
13538 -- expanded, hence the use of Original_Node.
13540 elsif Nkind (Orig_N) = N_If_Expression then
13541 Expr := Next (First (Expressions (Orig_N)));
13542 while Present (Expr) loop
13543 if Is_EVF_Expression (Expr) then
13544 return True;
13545 end if;
13547 Next (Expr);
13548 end loop;
13550 -- A qualified expression or a type conversion is an EVF expression when
13551 -- its operand is an EVF expression.
13553 elsif Nkind_In (N, N_Qualified_Expression,
13554 N_Unchecked_Type_Conversion,
13555 N_Type_Conversion)
13556 then
13557 return Is_EVF_Expression (Expression (N));
13559 -- Attributes 'Loop_Entry, 'Old, and 'Update are EVF expressions when
13560 -- their prefix denotes an EVF expression.
13562 elsif Nkind (N) = N_Attribute_Reference
13563 and then Nam_In (Attribute_Name (N), Name_Loop_Entry,
13564 Name_Old,
13565 Name_Update)
13566 then
13567 return Is_EVF_Expression (Prefix (N));
13568 end if;
13570 return False;
13571 end Is_EVF_Expression;
13573 --------------
13574 -- Is_False --
13575 --------------
13577 function Is_False (U : Uint) return Boolean is
13578 begin
13579 return (U = 0);
13580 end Is_False;
13582 ---------------------------
13583 -- Is_Fixed_Model_Number --
13584 ---------------------------
13586 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
13587 S : constant Ureal := Small_Value (T);
13588 M : Urealp.Save_Mark;
13589 R : Boolean;
13591 begin
13592 M := Urealp.Mark;
13593 R := (U = UR_Trunc (U / S) * S);
13594 Urealp.Release (M);
13595 return R;
13596 end Is_Fixed_Model_Number;
13598 -------------------------------
13599 -- Is_Fully_Initialized_Type --
13600 -------------------------------
13602 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
13603 begin
13604 -- Scalar types
13606 if Is_Scalar_Type (Typ) then
13608 -- A scalar type with an aspect Default_Value is fully initialized
13610 -- Note: Iniitalize/Normalize_Scalars also ensure full initialization
13611 -- of a scalar type, but we don't take that into account here, since
13612 -- we don't want these to affect warnings.
13614 return Has_Default_Aspect (Typ);
13616 elsif Is_Access_Type (Typ) then
13617 return True;
13619 elsif Is_Array_Type (Typ) then
13620 if Is_Fully_Initialized_Type (Component_Type (Typ))
13621 or else (Ada_Version >= Ada_2012 and then Has_Default_Aspect (Typ))
13622 then
13623 return True;
13624 end if;
13626 -- An interesting case, if we have a constrained type one of whose
13627 -- bounds is known to be null, then there are no elements to be
13628 -- initialized, so all the elements are initialized.
13630 if Is_Constrained (Typ) then
13631 declare
13632 Indx : Node_Id;
13633 Indx_Typ : Entity_Id;
13634 Lbd, Hbd : Node_Id;
13636 begin
13637 Indx := First_Index (Typ);
13638 while Present (Indx) loop
13639 if Etype (Indx) = Any_Type then
13640 return False;
13642 -- If index is a range, use directly
13644 elsif Nkind (Indx) = N_Range then
13645 Lbd := Low_Bound (Indx);
13646 Hbd := High_Bound (Indx);
13648 else
13649 Indx_Typ := Etype (Indx);
13651 if Is_Private_Type (Indx_Typ) then
13652 Indx_Typ := Full_View (Indx_Typ);
13653 end if;
13655 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
13656 return False;
13657 else
13658 Lbd := Type_Low_Bound (Indx_Typ);
13659 Hbd := Type_High_Bound (Indx_Typ);
13660 end if;
13661 end if;
13663 if Compile_Time_Known_Value (Lbd)
13664 and then
13665 Compile_Time_Known_Value (Hbd)
13666 then
13667 if Expr_Value (Hbd) < Expr_Value (Lbd) then
13668 return True;
13669 end if;
13670 end if;
13672 Next_Index (Indx);
13673 end loop;
13674 end;
13675 end if;
13677 -- If no null indexes, then type is not fully initialized
13679 return False;
13681 -- Record types
13683 elsif Is_Record_Type (Typ) then
13684 if Has_Discriminants (Typ)
13685 and then
13686 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
13687 and then Is_Fully_Initialized_Variant (Typ)
13688 then
13689 return True;
13690 end if;
13692 -- We consider bounded string types to be fully initialized, because
13693 -- otherwise we get false alarms when the Data component is not
13694 -- default-initialized.
13696 if Is_Bounded_String (Typ) then
13697 return True;
13698 end if;
13700 -- Controlled records are considered to be fully initialized if
13701 -- there is a user defined Initialize routine. This may not be
13702 -- entirely correct, but as the spec notes, we are guessing here
13703 -- what is best from the point of view of issuing warnings.
13705 if Is_Controlled (Typ) then
13706 declare
13707 Utyp : constant Entity_Id := Underlying_Type (Typ);
13709 begin
13710 if Present (Utyp) then
13711 declare
13712 Init : constant Entity_Id :=
13713 (Find_Optional_Prim_Op
13714 (Underlying_Type (Typ), Name_Initialize));
13716 begin
13717 if Present (Init)
13718 and then Comes_From_Source (Init)
13719 and then not In_Predefined_Unit (Init)
13720 then
13721 return True;
13723 elsif Has_Null_Extension (Typ)
13724 and then
13725 Is_Fully_Initialized_Type
13726 (Etype (Base_Type (Typ)))
13727 then
13728 return True;
13729 end if;
13730 end;
13731 end if;
13732 end;
13733 end if;
13735 -- Otherwise see if all record components are initialized
13737 declare
13738 Ent : Entity_Id;
13740 begin
13741 Ent := First_Entity (Typ);
13742 while Present (Ent) loop
13743 if Ekind (Ent) = E_Component
13744 and then (No (Parent (Ent))
13745 or else No (Expression (Parent (Ent))))
13746 and then not Is_Fully_Initialized_Type (Etype (Ent))
13748 -- Special VM case for tag components, which need to be
13749 -- defined in this case, but are never initialized as VMs
13750 -- are using other dispatching mechanisms. Ignore this
13751 -- uninitialized case. Note that this applies both to the
13752 -- uTag entry and the main vtable pointer (CPP_Class case).
13754 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
13755 then
13756 return False;
13757 end if;
13759 Next_Entity (Ent);
13760 end loop;
13761 end;
13763 -- No uninitialized components, so type is fully initialized.
13764 -- Note that this catches the case of no components as well.
13766 return True;
13768 elsif Is_Concurrent_Type (Typ) then
13769 return True;
13771 elsif Is_Private_Type (Typ) then
13772 declare
13773 U : constant Entity_Id := Underlying_Type (Typ);
13775 begin
13776 if No (U) then
13777 return False;
13778 else
13779 return Is_Fully_Initialized_Type (U);
13780 end if;
13781 end;
13783 else
13784 return False;
13785 end if;
13786 end Is_Fully_Initialized_Type;
13788 ----------------------------------
13789 -- Is_Fully_Initialized_Variant --
13790 ----------------------------------
13792 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
13793 Loc : constant Source_Ptr := Sloc (Typ);
13794 Constraints : constant List_Id := New_List;
13795 Components : constant Elist_Id := New_Elmt_List;
13796 Comp_Elmt : Elmt_Id;
13797 Comp_Id : Node_Id;
13798 Comp_List : Node_Id;
13799 Discr : Entity_Id;
13800 Discr_Val : Node_Id;
13802 Report_Errors : Boolean;
13803 pragma Warnings (Off, Report_Errors);
13805 begin
13806 if Serious_Errors_Detected > 0 then
13807 return False;
13808 end if;
13810 if Is_Record_Type (Typ)
13811 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
13812 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
13813 then
13814 Comp_List := Component_List (Type_Definition (Parent (Typ)));
13816 Discr := First_Discriminant (Typ);
13817 while Present (Discr) loop
13818 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
13819 Discr_Val := Expression (Parent (Discr));
13821 if Present (Discr_Val)
13822 and then Is_OK_Static_Expression (Discr_Val)
13823 then
13824 Append_To (Constraints,
13825 Make_Component_Association (Loc,
13826 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
13827 Expression => New_Copy (Discr_Val)));
13828 else
13829 return False;
13830 end if;
13831 else
13832 return False;
13833 end if;
13835 Next_Discriminant (Discr);
13836 end loop;
13838 Gather_Components
13839 (Typ => Typ,
13840 Comp_List => Comp_List,
13841 Governed_By => Constraints,
13842 Into => Components,
13843 Report_Errors => Report_Errors);
13845 -- Check that each component present is fully initialized
13847 Comp_Elmt := First_Elmt (Components);
13848 while Present (Comp_Elmt) loop
13849 Comp_Id := Node (Comp_Elmt);
13851 if Ekind (Comp_Id) = E_Component
13852 and then (No (Parent (Comp_Id))
13853 or else No (Expression (Parent (Comp_Id))))
13854 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
13855 then
13856 return False;
13857 end if;
13859 Next_Elmt (Comp_Elmt);
13860 end loop;
13862 return True;
13864 elsif Is_Private_Type (Typ) then
13865 declare
13866 U : constant Entity_Id := Underlying_Type (Typ);
13868 begin
13869 if No (U) then
13870 return False;
13871 else
13872 return Is_Fully_Initialized_Variant (U);
13873 end if;
13874 end;
13876 else
13877 return False;
13878 end if;
13879 end Is_Fully_Initialized_Variant;
13881 ------------------------------------
13882 -- Is_Generic_Declaration_Or_Body --
13883 ------------------------------------
13885 function Is_Generic_Declaration_Or_Body (Decl : Node_Id) return Boolean is
13886 Spec_Decl : Node_Id;
13888 begin
13889 -- Package/subprogram body
13891 if Nkind_In (Decl, N_Package_Body, N_Subprogram_Body)
13892 and then Present (Corresponding_Spec (Decl))
13893 then
13894 Spec_Decl := Unit_Declaration_Node (Corresponding_Spec (Decl));
13896 -- Package/subprogram body stub
13898 elsif Nkind_In (Decl, N_Package_Body_Stub, N_Subprogram_Body_Stub)
13899 and then Present (Corresponding_Spec_Of_Stub (Decl))
13900 then
13901 Spec_Decl :=
13902 Unit_Declaration_Node (Corresponding_Spec_Of_Stub (Decl));
13904 -- All other cases
13906 else
13907 Spec_Decl := Decl;
13908 end if;
13910 -- Rather than inspecting the defining entity of the spec declaration,
13911 -- look at its Nkind. This takes care of the case where the analysis of
13912 -- a generic body modifies the Ekind of its spec to allow for recursive
13913 -- calls.
13915 return
13916 Nkind_In (Spec_Decl, N_Generic_Package_Declaration,
13917 N_Generic_Subprogram_Declaration);
13918 end Is_Generic_Declaration_Or_Body;
13920 ----------------------------
13921 -- Is_Inherited_Operation --
13922 ----------------------------
13924 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
13925 pragma Assert (Is_Overloadable (E));
13926 Kind : constant Node_Kind := Nkind (Parent (E));
13927 begin
13928 return Kind = N_Full_Type_Declaration
13929 or else Kind = N_Private_Extension_Declaration
13930 or else Kind = N_Subtype_Declaration
13931 or else (Ekind (E) = E_Enumeration_Literal
13932 and then Is_Derived_Type (Etype (E)));
13933 end Is_Inherited_Operation;
13935 -------------------------------------
13936 -- Is_Inherited_Operation_For_Type --
13937 -------------------------------------
13939 function Is_Inherited_Operation_For_Type
13940 (E : Entity_Id;
13941 Typ : Entity_Id) return Boolean
13943 begin
13944 -- Check that the operation has been created by the type declaration
13946 return Is_Inherited_Operation (E)
13947 and then Defining_Identifier (Parent (E)) = Typ;
13948 end Is_Inherited_Operation_For_Type;
13950 --------------------------------------
13951 -- Is_Inlinable_Expression_Function --
13952 --------------------------------------
13954 function Is_Inlinable_Expression_Function
13955 (Subp : Entity_Id) return Boolean
13957 Return_Expr : Node_Id;
13959 begin
13960 if Is_Expression_Function_Or_Completion (Subp)
13961 and then Has_Pragma_Inline_Always (Subp)
13962 and then Needs_No_Actuals (Subp)
13963 and then No (Contract (Subp))
13964 and then not Is_Dispatching_Operation (Subp)
13965 and then Needs_Finalization (Etype (Subp))
13966 and then not Is_Class_Wide_Type (Etype (Subp))
13967 and then not (Has_Invariants (Etype (Subp)))
13968 and then Present (Subprogram_Body (Subp))
13969 and then Was_Expression_Function (Subprogram_Body (Subp))
13970 then
13971 Return_Expr := Expression_Of_Expression_Function (Subp);
13973 -- The returned object must not have a qualified expression and its
13974 -- nominal subtype must be statically compatible with the result
13975 -- subtype of the expression function.
13977 return
13978 Nkind (Return_Expr) = N_Identifier
13979 and then Etype (Return_Expr) = Etype (Subp);
13980 end if;
13982 return False;
13983 end Is_Inlinable_Expression_Function;
13985 -----------------
13986 -- Is_Iterator --
13987 -----------------
13989 function Is_Iterator (Typ : Entity_Id) return Boolean is
13990 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean;
13991 -- Determine whether type Iter_Typ is a predefined forward or reversible
13992 -- iterator.
13994 ----------------------
13995 -- Denotes_Iterator --
13996 ----------------------
13998 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean is
13999 begin
14000 -- Check that the name matches, and that the ultimate ancestor is in
14001 -- a predefined unit, i.e the one that declares iterator interfaces.
14003 return
14004 Nam_In (Chars (Iter_Typ), Name_Forward_Iterator,
14005 Name_Reversible_Iterator)
14006 and then In_Predefined_Unit (Root_Type (Iter_Typ));
14007 end Denotes_Iterator;
14009 -- Local variables
14011 Iface_Elmt : Elmt_Id;
14012 Ifaces : Elist_Id;
14014 -- Start of processing for Is_Iterator
14016 begin
14017 -- The type may be a subtype of a descendant of the proper instance of
14018 -- the predefined interface type, so we must use the root type of the
14019 -- given type. The same is done for Is_Reversible_Iterator.
14021 if Is_Class_Wide_Type (Typ)
14022 and then Denotes_Iterator (Root_Type (Typ))
14023 then
14024 return True;
14026 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
14027 return False;
14029 elsif Present (Find_Value_Of_Aspect (Typ, Aspect_Iterable)) then
14030 return True;
14032 else
14033 Collect_Interfaces (Typ, Ifaces);
14035 Iface_Elmt := First_Elmt (Ifaces);
14036 while Present (Iface_Elmt) loop
14037 if Denotes_Iterator (Node (Iface_Elmt)) then
14038 return True;
14039 end if;
14041 Next_Elmt (Iface_Elmt);
14042 end loop;
14044 return False;
14045 end if;
14046 end Is_Iterator;
14048 ----------------------------
14049 -- Is_Iterator_Over_Array --
14050 ----------------------------
14052 function Is_Iterator_Over_Array (N : Node_Id) return Boolean is
14053 Container : constant Node_Id := Name (N);
14054 Container_Typ : constant Entity_Id := Base_Type (Etype (Container));
14055 begin
14056 return Is_Array_Type (Container_Typ);
14057 end Is_Iterator_Over_Array;
14059 ------------
14060 -- Is_LHS --
14061 ------------
14063 -- We seem to have a lot of overlapping functions that do similar things
14064 -- (testing for left hand sides or lvalues???).
14066 function Is_LHS (N : Node_Id) return Is_LHS_Result is
14067 P : constant Node_Id := Parent (N);
14069 begin
14070 -- Return True if we are the left hand side of an assignment statement
14072 if Nkind (P) = N_Assignment_Statement then
14073 if Name (P) = N then
14074 return Yes;
14075 else
14076 return No;
14077 end if;
14079 -- Case of prefix of indexed or selected component or slice
14081 elsif Nkind_In (P, N_Indexed_Component, N_Selected_Component, N_Slice)
14082 and then N = Prefix (P)
14083 then
14084 -- Here we have the case where the parent P is N.Q or N(Q .. R).
14085 -- If P is an LHS, then N is also effectively an LHS, but there
14086 -- is an important exception. If N is of an access type, then
14087 -- what we really have is N.all.Q (or N.all(Q .. R)). In either
14088 -- case this makes N.all a left hand side but not N itself.
14090 -- If we don't know the type yet, this is the case where we return
14091 -- Unknown, since the answer depends on the type which is unknown.
14093 if No (Etype (N)) then
14094 return Unknown;
14096 -- We have an Etype set, so we can check it
14098 elsif Is_Access_Type (Etype (N)) then
14099 return No;
14101 -- OK, not access type case, so just test whole expression
14103 else
14104 return Is_LHS (P);
14105 end if;
14107 -- All other cases are not left hand sides
14109 else
14110 return No;
14111 end if;
14112 end Is_LHS;
14114 -----------------------------
14115 -- Is_Library_Level_Entity --
14116 -----------------------------
14118 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
14119 begin
14120 -- The following is a small optimization, and it also properly handles
14121 -- discriminals, which in task bodies might appear in expressions before
14122 -- the corresponding procedure has been created, and which therefore do
14123 -- not have an assigned scope.
14125 if Is_Formal (E) then
14126 return False;
14127 end if;
14129 -- Normal test is simply that the enclosing dynamic scope is Standard
14131 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
14132 end Is_Library_Level_Entity;
14134 --------------------------------
14135 -- Is_Limited_Class_Wide_Type --
14136 --------------------------------
14138 function Is_Limited_Class_Wide_Type (Typ : Entity_Id) return Boolean is
14139 begin
14140 return
14141 Is_Class_Wide_Type (Typ)
14142 and then (Is_Limited_Type (Typ) or else From_Limited_With (Typ));
14143 end Is_Limited_Class_Wide_Type;
14145 ---------------------------------
14146 -- Is_Local_Variable_Reference --
14147 ---------------------------------
14149 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
14150 begin
14151 if not Is_Entity_Name (Expr) then
14152 return False;
14154 else
14155 declare
14156 Ent : constant Entity_Id := Entity (Expr);
14157 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
14158 begin
14159 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
14160 return False;
14161 else
14162 return Present (Sub) and then Sub = Current_Subprogram;
14163 end if;
14164 end;
14165 end if;
14166 end Is_Local_Variable_Reference;
14168 -----------------------
14169 -- Is_Name_Reference --
14170 -----------------------
14172 function Is_Name_Reference (N : Node_Id) return Boolean is
14173 begin
14174 if Is_Entity_Name (N) then
14175 return Present (Entity (N)) and then Is_Object (Entity (N));
14176 end if;
14178 case Nkind (N) is
14179 when N_Indexed_Component
14180 | N_Slice
14182 return
14183 Is_Name_Reference (Prefix (N))
14184 or else Is_Access_Type (Etype (Prefix (N)));
14186 -- Attributes 'Input, 'Old and 'Result produce objects
14188 when N_Attribute_Reference =>
14189 return
14190 Nam_In (Attribute_Name (N), Name_Input, Name_Old, Name_Result);
14192 when N_Selected_Component =>
14193 return
14194 Is_Name_Reference (Selector_Name (N))
14195 and then
14196 (Is_Name_Reference (Prefix (N))
14197 or else Is_Access_Type (Etype (Prefix (N))));
14199 when N_Explicit_Dereference =>
14200 return True;
14202 -- A view conversion of a tagged name is a name reference
14204 when N_Type_Conversion =>
14205 return
14206 Is_Tagged_Type (Etype (Subtype_Mark (N)))
14207 and then Is_Tagged_Type (Etype (Expression (N)))
14208 and then Is_Name_Reference (Expression (N));
14210 -- An unchecked type conversion is considered to be a name if the
14211 -- operand is a name (this construction arises only as a result of
14212 -- expansion activities).
14214 when N_Unchecked_Type_Conversion =>
14215 return Is_Name_Reference (Expression (N));
14217 when others =>
14218 return False;
14219 end case;
14220 end Is_Name_Reference;
14222 ---------------------------------
14223 -- Is_Nontrivial_DIC_Procedure --
14224 ---------------------------------
14226 function Is_Nontrivial_DIC_Procedure (Id : Entity_Id) return Boolean is
14227 Body_Decl : Node_Id;
14228 Stmt : Node_Id;
14230 begin
14231 if Ekind (Id) = E_Procedure and then Is_DIC_Procedure (Id) then
14232 Body_Decl :=
14233 Unit_Declaration_Node
14234 (Corresponding_Body (Unit_Declaration_Node (Id)));
14236 -- The body of the Default_Initial_Condition procedure must contain
14237 -- at least one statement, otherwise the generation of the subprogram
14238 -- body failed.
14240 pragma Assert (Present (Handled_Statement_Sequence (Body_Decl)));
14242 -- To qualify as nontrivial, the first statement of the procedure
14243 -- must be a check in the form of an if statement. If the original
14244 -- Default_Initial_Condition expression was folded, then the first
14245 -- statement is not a check.
14247 Stmt := First (Statements (Handled_Statement_Sequence (Body_Decl)));
14249 return
14250 Nkind (Stmt) = N_If_Statement
14251 and then Nkind (Original_Node (Stmt)) = N_Pragma;
14252 end if;
14254 return False;
14255 end Is_Nontrivial_DIC_Procedure;
14257 -------------------------
14258 -- Is_Null_Record_Type --
14259 -------------------------
14261 function Is_Null_Record_Type (T : Entity_Id) return Boolean is
14262 Decl : constant Node_Id := Parent (T);
14263 begin
14264 return Nkind (Decl) = N_Full_Type_Declaration
14265 and then Nkind (Type_Definition (Decl)) = N_Record_Definition
14266 and then
14267 (No (Component_List (Type_Definition (Decl)))
14268 or else Null_Present (Component_List (Type_Definition (Decl))));
14269 end Is_Null_Record_Type;
14271 ---------------------
14272 -- Is_Object_Image --
14273 ---------------------
14275 function Is_Object_Image (Prefix : Node_Id) return Boolean is
14276 begin
14277 -- When the type of the prefix is not scalar, then the prefix is not
14278 -- valid in any scenario.
14280 if not Is_Scalar_Type (Etype (Prefix)) then
14281 return False;
14282 end if;
14284 -- Here we test for the case that the prefix is not a type and assume
14285 -- if it is not then it must be a named value or an object reference.
14286 -- This is because the parser always checks that prefixes of attributes
14287 -- are named.
14289 return not (Is_Entity_Name (Prefix) and then Is_Type (Entity (Prefix)));
14290 end Is_Object_Image;
14292 -------------------------
14293 -- Is_Object_Reference --
14294 -------------------------
14296 function Is_Object_Reference (N : Node_Id) return Boolean is
14297 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean;
14298 -- Determine whether N is the name of an internally-generated renaming
14300 --------------------------------------
14301 -- Is_Internally_Generated_Renaming --
14302 --------------------------------------
14304 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean is
14305 P : Node_Id;
14307 begin
14308 P := N;
14309 while Present (P) loop
14310 if Nkind (P) = N_Object_Renaming_Declaration then
14311 return not Comes_From_Source (P);
14312 elsif Is_List_Member (P) then
14313 return False;
14314 end if;
14316 P := Parent (P);
14317 end loop;
14319 return False;
14320 end Is_Internally_Generated_Renaming;
14322 -- Start of processing for Is_Object_Reference
14324 begin
14325 if Is_Entity_Name (N) then
14326 return Present (Entity (N)) and then Is_Object (Entity (N));
14328 else
14329 case Nkind (N) is
14330 when N_Indexed_Component
14331 | N_Slice
14333 return
14334 Is_Object_Reference (Prefix (N))
14335 or else Is_Access_Type (Etype (Prefix (N)));
14337 -- In Ada 95, a function call is a constant object; a procedure
14338 -- call is not.
14340 -- Note that predefined operators are functions as well, and so
14341 -- are attributes that are (can be renamed as) functions.
14343 when N_Binary_Op
14344 | N_Function_Call
14345 | N_Unary_Op
14347 return Etype (N) /= Standard_Void_Type;
14349 -- Attributes references 'Loop_Entry, 'Old, and 'Result yield
14350 -- objects, even though they are not functions.
14352 when N_Attribute_Reference =>
14353 return
14354 Nam_In (Attribute_Name (N), Name_Loop_Entry,
14355 Name_Old,
14356 Name_Result)
14357 or else Is_Function_Attribute_Name (Attribute_Name (N));
14359 when N_Selected_Component =>
14360 return
14361 Is_Object_Reference (Selector_Name (N))
14362 and then
14363 (Is_Object_Reference (Prefix (N))
14364 or else Is_Access_Type (Etype (Prefix (N))));
14366 -- An explicit dereference denotes an object, except that a
14367 -- conditional expression gets turned into an explicit dereference
14368 -- in some cases, and conditional expressions are not object
14369 -- names.
14371 when N_Explicit_Dereference =>
14372 return not Nkind_In (Original_Node (N), N_Case_Expression,
14373 N_If_Expression);
14375 -- A view conversion of a tagged object is an object reference
14377 when N_Type_Conversion =>
14378 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
14379 and then Is_Tagged_Type (Etype (Expression (N)))
14380 and then Is_Object_Reference (Expression (N));
14382 -- An unchecked type conversion is considered to be an object if
14383 -- the operand is an object (this construction arises only as a
14384 -- result of expansion activities).
14386 when N_Unchecked_Type_Conversion =>
14387 return True;
14389 -- Allow string literals to act as objects as long as they appear
14390 -- in internally-generated renamings. The expansion of iterators
14391 -- may generate such renamings when the range involves a string
14392 -- literal.
14394 when N_String_Literal =>
14395 return Is_Internally_Generated_Renaming (Parent (N));
14397 -- AI05-0003: In Ada 2012 a qualified expression is a name.
14398 -- This allows disambiguation of function calls and the use
14399 -- of aggregates in more contexts.
14401 when N_Qualified_Expression =>
14402 if Ada_Version < Ada_2012 then
14403 return False;
14404 else
14405 return Is_Object_Reference (Expression (N))
14406 or else Nkind (Expression (N)) = N_Aggregate;
14407 end if;
14409 when others =>
14410 return False;
14411 end case;
14412 end if;
14413 end Is_Object_Reference;
14415 -----------------------------------
14416 -- Is_OK_Variable_For_Out_Formal --
14417 -----------------------------------
14419 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
14420 begin
14421 Note_Possible_Modification (AV, Sure => True);
14423 -- We must reject parenthesized variable names. Comes_From_Source is
14424 -- checked because there are currently cases where the compiler violates
14425 -- this rule (e.g. passing a task object to its controlled Initialize
14426 -- routine). This should be properly documented in sinfo???
14428 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
14429 return False;
14431 -- A variable is always allowed
14433 elsif Is_Variable (AV) then
14434 return True;
14436 -- Generalized indexing operations are rewritten as explicit
14437 -- dereferences, and it is only during resolution that we can
14438 -- check whether the context requires an access_to_variable type.
14440 elsif Nkind (AV) = N_Explicit_Dereference
14441 and then Ada_Version >= Ada_2012
14442 and then Nkind (Original_Node (AV)) = N_Indexed_Component
14443 and then Present (Etype (Original_Node (AV)))
14444 and then Has_Implicit_Dereference (Etype (Original_Node (AV)))
14445 then
14446 return not Is_Access_Constant (Etype (Prefix (AV)));
14448 -- Unchecked conversions are allowed only if they come from the
14449 -- generated code, which sometimes uses unchecked conversions for out
14450 -- parameters in cases where code generation is unaffected. We tell
14451 -- source unchecked conversions by seeing if they are rewrites of
14452 -- an original Unchecked_Conversion function call, or of an explicit
14453 -- conversion of a function call or an aggregate (as may happen in the
14454 -- expansion of a packed array aggregate).
14456 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
14457 if Nkind_In (Original_Node (AV), N_Function_Call, N_Aggregate) then
14458 return False;
14460 elsif Comes_From_Source (AV)
14461 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
14462 then
14463 return False;
14465 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
14466 return Is_OK_Variable_For_Out_Formal (Expression (AV));
14468 else
14469 return True;
14470 end if;
14472 -- Normal type conversions are allowed if argument is a variable
14474 elsif Nkind (AV) = N_Type_Conversion then
14475 if Is_Variable (Expression (AV))
14476 and then Paren_Count (Expression (AV)) = 0
14477 then
14478 Note_Possible_Modification (Expression (AV), Sure => True);
14479 return True;
14481 -- We also allow a non-parenthesized expression that raises
14482 -- constraint error if it rewrites what used to be a variable
14484 elsif Raises_Constraint_Error (Expression (AV))
14485 and then Paren_Count (Expression (AV)) = 0
14486 and then Is_Variable (Original_Node (Expression (AV)))
14487 then
14488 return True;
14490 -- Type conversion of something other than a variable
14492 else
14493 return False;
14494 end if;
14496 -- If this node is rewritten, then test the original form, if that is
14497 -- OK, then we consider the rewritten node OK (for example, if the
14498 -- original node is a conversion, then Is_Variable will not be true
14499 -- but we still want to allow the conversion if it converts a variable).
14501 elsif Original_Node (AV) /= AV then
14503 -- In Ada 2012, the explicit dereference may be a rewritten call to a
14504 -- Reference function.
14506 if Ada_Version >= Ada_2012
14507 and then Nkind (Original_Node (AV)) = N_Function_Call
14508 and then
14509 Has_Implicit_Dereference (Etype (Name (Original_Node (AV))))
14510 then
14512 -- Check that this is not a constant reference.
14514 return not Is_Access_Constant (Etype (Prefix (AV)));
14516 elsif Has_Implicit_Dereference (Etype (Original_Node (AV))) then
14517 return
14518 not Is_Access_Constant (Etype
14519 (Get_Reference_Discriminant (Etype (Original_Node (AV)))));
14521 else
14522 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
14523 end if;
14525 -- All other non-variables are rejected
14527 else
14528 return False;
14529 end if;
14530 end Is_OK_Variable_For_Out_Formal;
14532 ----------------------------
14533 -- Is_OK_Volatile_Context --
14534 ----------------------------
14536 function Is_OK_Volatile_Context
14537 (Context : Node_Id;
14538 Obj_Ref : Node_Id) return Boolean
14540 function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean;
14541 -- Determine whether an arbitrary node denotes a call to a protected
14542 -- entry, function, or procedure in prefixed form where the prefix is
14543 -- Obj_Ref.
14545 function Within_Check (Nod : Node_Id) return Boolean;
14546 -- Determine whether an arbitrary node appears in a check node
14548 function Within_Subprogram_Call (Nod : Node_Id) return Boolean;
14549 -- Determine whether an arbitrary node appears in an entry, function, or
14550 -- procedure call.
14552 function Within_Volatile_Function (Id : Entity_Id) return Boolean;
14553 -- Determine whether an arbitrary entity appears in a volatile function
14555 ---------------------------------
14556 -- Is_Protected_Operation_Call --
14557 ---------------------------------
14559 function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean is
14560 Pref : Node_Id;
14561 Subp : Node_Id;
14563 begin
14564 -- A call to a protected operations retains its selected component
14565 -- form as opposed to other prefixed calls that are transformed in
14566 -- expanded names.
14568 if Nkind (Nod) = N_Selected_Component then
14569 Pref := Prefix (Nod);
14570 Subp := Selector_Name (Nod);
14572 return
14573 Pref = Obj_Ref
14574 and then Present (Etype (Pref))
14575 and then Is_Protected_Type (Etype (Pref))
14576 and then Is_Entity_Name (Subp)
14577 and then Present (Entity (Subp))
14578 and then Ekind_In (Entity (Subp), E_Entry,
14579 E_Entry_Family,
14580 E_Function,
14581 E_Procedure);
14582 else
14583 return False;
14584 end if;
14585 end Is_Protected_Operation_Call;
14587 ------------------
14588 -- Within_Check --
14589 ------------------
14591 function Within_Check (Nod : Node_Id) return Boolean is
14592 Par : Node_Id;
14594 begin
14595 -- Climb the parent chain looking for a check node
14597 Par := Nod;
14598 while Present (Par) loop
14599 if Nkind (Par) in N_Raise_xxx_Error then
14600 return True;
14602 -- Prevent the search from going too far
14604 elsif Is_Body_Or_Package_Declaration (Par) then
14605 exit;
14606 end if;
14608 Par := Parent (Par);
14609 end loop;
14611 return False;
14612 end Within_Check;
14614 ----------------------------
14615 -- Within_Subprogram_Call --
14616 ----------------------------
14618 function Within_Subprogram_Call (Nod : Node_Id) return Boolean is
14619 Par : Node_Id;
14621 begin
14622 -- Climb the parent chain looking for a function or procedure call
14624 Par := Nod;
14625 while Present (Par) loop
14626 if Nkind_In (Par, N_Entry_Call_Statement,
14627 N_Function_Call,
14628 N_Procedure_Call_Statement)
14629 then
14630 return True;
14632 -- Prevent the search from going too far
14634 elsif Is_Body_Or_Package_Declaration (Par) then
14635 exit;
14636 end if;
14638 Par := Parent (Par);
14639 end loop;
14641 return False;
14642 end Within_Subprogram_Call;
14644 ------------------------------
14645 -- Within_Volatile_Function --
14646 ------------------------------
14648 function Within_Volatile_Function (Id : Entity_Id) return Boolean is
14649 Func_Id : Entity_Id;
14651 begin
14652 -- Traverse the scope stack looking for a [generic] function
14654 Func_Id := Id;
14655 while Present (Func_Id) and then Func_Id /= Standard_Standard loop
14656 if Ekind_In (Func_Id, E_Function, E_Generic_Function) then
14657 return Is_Volatile_Function (Func_Id);
14658 end if;
14660 Func_Id := Scope (Func_Id);
14661 end loop;
14663 return False;
14664 end Within_Volatile_Function;
14666 -- Local variables
14668 Obj_Id : Entity_Id;
14670 -- Start of processing for Is_OK_Volatile_Context
14672 begin
14673 -- The volatile object appears on either side of an assignment
14675 if Nkind (Context) = N_Assignment_Statement then
14676 return True;
14678 -- The volatile object is part of the initialization expression of
14679 -- another object.
14681 elsif Nkind (Context) = N_Object_Declaration
14682 and then Present (Expression (Context))
14683 and then Expression (Context) = Obj_Ref
14684 then
14685 Obj_Id := Defining_Entity (Context);
14687 -- The volatile object acts as the initialization expression of an
14688 -- extended return statement. This is valid context as long as the
14689 -- function is volatile.
14691 if Is_Return_Object (Obj_Id) then
14692 return Within_Volatile_Function (Obj_Id);
14694 -- Otherwise this is a normal object initialization
14696 else
14697 return True;
14698 end if;
14700 -- The volatile object acts as the name of a renaming declaration
14702 elsif Nkind (Context) = N_Object_Renaming_Declaration
14703 and then Name (Context) = Obj_Ref
14704 then
14705 return True;
14707 -- The volatile object appears as an actual parameter in a call to an
14708 -- instance of Unchecked_Conversion whose result is renamed.
14710 elsif Nkind (Context) = N_Function_Call
14711 and then Is_Entity_Name (Name (Context))
14712 and then Is_Unchecked_Conversion_Instance (Entity (Name (Context)))
14713 and then Nkind (Parent (Context)) = N_Object_Renaming_Declaration
14714 then
14715 return True;
14717 -- The volatile object is actually the prefix in a protected entry,
14718 -- function, or procedure call.
14720 elsif Is_Protected_Operation_Call (Context) then
14721 return True;
14723 -- The volatile object appears as the expression of a simple return
14724 -- statement that applies to a volatile function.
14726 elsif Nkind (Context) = N_Simple_Return_Statement
14727 and then Expression (Context) = Obj_Ref
14728 then
14729 return
14730 Within_Volatile_Function (Return_Statement_Entity (Context));
14732 -- The volatile object appears as the prefix of a name occurring in a
14733 -- non-interfering context.
14735 elsif Nkind_In (Context, N_Attribute_Reference,
14736 N_Explicit_Dereference,
14737 N_Indexed_Component,
14738 N_Selected_Component,
14739 N_Slice)
14740 and then Prefix (Context) = Obj_Ref
14741 and then Is_OK_Volatile_Context
14742 (Context => Parent (Context),
14743 Obj_Ref => Context)
14744 then
14745 return True;
14747 -- The volatile object appears as the prefix of attributes Address,
14748 -- Alignment, Component_Size, First_Bit, Last_Bit, Position, Size,
14749 -- Storage_Size.
14751 elsif Nkind (Context) = N_Attribute_Reference
14752 and then Prefix (Context) = Obj_Ref
14753 and then Nam_In (Attribute_Name (Context), Name_Address,
14754 Name_Alignment,
14755 Name_Component_Size,
14756 Name_First_Bit,
14757 Name_Last_Bit,
14758 Name_Position,
14759 Name_Size,
14760 Name_Storage_Size)
14761 then
14762 return True;
14764 -- The volatile object appears as the expression of a type conversion
14765 -- occurring in a non-interfering context.
14767 elsif Nkind_In (Context, N_Type_Conversion,
14768 N_Unchecked_Type_Conversion)
14769 and then Expression (Context) = Obj_Ref
14770 and then Is_OK_Volatile_Context
14771 (Context => Parent (Context),
14772 Obj_Ref => Context)
14773 then
14774 return True;
14776 -- The volatile object appears as the expression in a delay statement
14778 elsif Nkind (Context) in N_Delay_Statement then
14779 return True;
14781 -- Allow references to volatile objects in various checks. This is not a
14782 -- direct SPARK 2014 requirement.
14784 elsif Within_Check (Context) then
14785 return True;
14787 -- Assume that references to effectively volatile objects that appear
14788 -- as actual parameters in a subprogram call are always legal. A full
14789 -- legality check is done when the actuals are resolved (see routine
14790 -- Resolve_Actuals).
14792 elsif Within_Subprogram_Call (Context) then
14793 return True;
14795 -- Otherwise the context is not suitable for an effectively volatile
14796 -- object.
14798 else
14799 return False;
14800 end if;
14801 end Is_OK_Volatile_Context;
14803 ------------------------------------
14804 -- Is_Package_Contract_Annotation --
14805 ------------------------------------
14807 function Is_Package_Contract_Annotation (Item : Node_Id) return Boolean is
14808 Nam : Name_Id;
14810 begin
14811 if Nkind (Item) = N_Aspect_Specification then
14812 Nam := Chars (Identifier (Item));
14814 else pragma Assert (Nkind (Item) = N_Pragma);
14815 Nam := Pragma_Name (Item);
14816 end if;
14818 return Nam = Name_Abstract_State
14819 or else Nam = Name_Initial_Condition
14820 or else Nam = Name_Initializes
14821 or else Nam = Name_Refined_State;
14822 end Is_Package_Contract_Annotation;
14824 -----------------------------------
14825 -- Is_Partially_Initialized_Type --
14826 -----------------------------------
14828 function Is_Partially_Initialized_Type
14829 (Typ : Entity_Id;
14830 Include_Implicit : Boolean := True) return Boolean
14832 begin
14833 if Is_Scalar_Type (Typ) then
14834 return False;
14836 elsif Is_Access_Type (Typ) then
14837 return Include_Implicit;
14839 elsif Is_Array_Type (Typ) then
14841 -- If component type is partially initialized, so is array type
14843 if Is_Partially_Initialized_Type
14844 (Component_Type (Typ), Include_Implicit)
14845 then
14846 return True;
14848 -- Otherwise we are only partially initialized if we are fully
14849 -- initialized (this is the empty array case, no point in us
14850 -- duplicating that code here).
14852 else
14853 return Is_Fully_Initialized_Type (Typ);
14854 end if;
14856 elsif Is_Record_Type (Typ) then
14858 -- A discriminated type is always partially initialized if in
14859 -- all mode
14861 if Has_Discriminants (Typ) and then Include_Implicit then
14862 return True;
14864 -- A tagged type is always partially initialized
14866 elsif Is_Tagged_Type (Typ) then
14867 return True;
14869 -- Case of non-discriminated record
14871 else
14872 declare
14873 Ent : Entity_Id;
14875 Component_Present : Boolean := False;
14876 -- Set True if at least one component is present. If no
14877 -- components are present, then record type is fully
14878 -- initialized (another odd case, like the null array).
14880 begin
14881 -- Loop through components
14883 Ent := First_Entity (Typ);
14884 while Present (Ent) loop
14885 if Ekind (Ent) = E_Component then
14886 Component_Present := True;
14888 -- If a component has an initialization expression then
14889 -- the enclosing record type is partially initialized
14891 if Present (Parent (Ent))
14892 and then Present (Expression (Parent (Ent)))
14893 then
14894 return True;
14896 -- If a component is of a type which is itself partially
14897 -- initialized, then the enclosing record type is also.
14899 elsif Is_Partially_Initialized_Type
14900 (Etype (Ent), Include_Implicit)
14901 then
14902 return True;
14903 end if;
14904 end if;
14906 Next_Entity (Ent);
14907 end loop;
14909 -- No initialized components found. If we found any components
14910 -- they were all uninitialized so the result is false.
14912 if Component_Present then
14913 return False;
14915 -- But if we found no components, then all the components are
14916 -- initialized so we consider the type to be initialized.
14918 else
14919 return True;
14920 end if;
14921 end;
14922 end if;
14924 -- Concurrent types are always fully initialized
14926 elsif Is_Concurrent_Type (Typ) then
14927 return True;
14929 -- For a private type, go to underlying type. If there is no underlying
14930 -- type then just assume this partially initialized. Not clear if this
14931 -- can happen in a non-error case, but no harm in testing for this.
14933 elsif Is_Private_Type (Typ) then
14934 declare
14935 U : constant Entity_Id := Underlying_Type (Typ);
14936 begin
14937 if No (U) then
14938 return True;
14939 else
14940 return Is_Partially_Initialized_Type (U, Include_Implicit);
14941 end if;
14942 end;
14944 -- For any other type (are there any?) assume partially initialized
14946 else
14947 return True;
14948 end if;
14949 end Is_Partially_Initialized_Type;
14951 ------------------------------------
14952 -- Is_Potentially_Persistent_Type --
14953 ------------------------------------
14955 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
14956 Comp : Entity_Id;
14957 Indx : Node_Id;
14959 begin
14960 -- For private type, test corresponding full type
14962 if Is_Private_Type (T) then
14963 return Is_Potentially_Persistent_Type (Full_View (T));
14965 -- Scalar types are potentially persistent
14967 elsif Is_Scalar_Type (T) then
14968 return True;
14970 -- Record type is potentially persistent if not tagged and the types of
14971 -- all it components are potentially persistent, and no component has
14972 -- an initialization expression.
14974 elsif Is_Record_Type (T)
14975 and then not Is_Tagged_Type (T)
14976 and then not Is_Partially_Initialized_Type (T)
14977 then
14978 Comp := First_Component (T);
14979 while Present (Comp) loop
14980 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
14981 return False;
14982 else
14983 Next_Entity (Comp);
14984 end if;
14985 end loop;
14987 return True;
14989 -- Array type is potentially persistent if its component type is
14990 -- potentially persistent and if all its constraints are static.
14992 elsif Is_Array_Type (T) then
14993 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
14994 return False;
14995 end if;
14997 Indx := First_Index (T);
14998 while Present (Indx) loop
14999 if not Is_OK_Static_Subtype (Etype (Indx)) then
15000 return False;
15001 else
15002 Next_Index (Indx);
15003 end if;
15004 end loop;
15006 return True;
15008 -- All other types are not potentially persistent
15010 else
15011 return False;
15012 end if;
15013 end Is_Potentially_Persistent_Type;
15015 --------------------------------
15016 -- Is_Potentially_Unevaluated --
15017 --------------------------------
15019 function Is_Potentially_Unevaluated (N : Node_Id) return Boolean is
15020 Par : Node_Id;
15021 Expr : Node_Id;
15023 begin
15024 Expr := N;
15025 Par := Parent (N);
15027 -- A postcondition whose expression is a short-circuit is broken down
15028 -- into individual aspects for better exception reporting. The original
15029 -- short-circuit expression is rewritten as the second operand, and an
15030 -- occurrence of 'Old in that operand is potentially unevaluated.
15031 -- See Sem_ch13.adb for details of this transformation.
15033 if Nkind (Original_Node (Par)) = N_And_Then then
15034 return True;
15035 end if;
15037 while not Nkind_In (Par, N_If_Expression,
15038 N_Case_Expression,
15039 N_And_Then,
15040 N_Or_Else,
15041 N_In,
15042 N_Not_In,
15043 N_Quantified_Expression)
15044 loop
15045 Expr := Par;
15046 Par := Parent (Par);
15048 -- If the context is not an expression, or if is the result of
15049 -- expansion of an enclosing construct (such as another attribute)
15050 -- the predicate does not apply.
15052 if Nkind (Par) = N_Case_Expression_Alternative then
15053 null;
15055 elsif Nkind (Par) not in N_Subexpr
15056 or else not Comes_From_Source (Par)
15057 then
15058 return False;
15059 end if;
15060 end loop;
15062 if Nkind (Par) = N_If_Expression then
15063 return Is_Elsif (Par) or else Expr /= First (Expressions (Par));
15065 elsif Nkind (Par) = N_Case_Expression then
15066 return Expr /= Expression (Par);
15068 elsif Nkind_In (Par, N_And_Then, N_Or_Else) then
15069 return Expr = Right_Opnd (Par);
15071 elsif Nkind_In (Par, N_In, N_Not_In) then
15073 -- If the membership includes several alternatives, only the first is
15074 -- definitely evaluated.
15076 if Present (Alternatives (Par)) then
15077 return Expr /= First (Alternatives (Par));
15079 -- If this is a range membership both bounds are evaluated
15081 else
15082 return False;
15083 end if;
15085 elsif Nkind (Par) = N_Quantified_Expression then
15086 return Expr = Condition (Par);
15088 else
15089 return False;
15090 end if;
15091 end Is_Potentially_Unevaluated;
15093 ---------------------------------
15094 -- Is_Protected_Self_Reference --
15095 ---------------------------------
15097 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
15099 function In_Access_Definition (N : Node_Id) return Boolean;
15100 -- Returns true if N belongs to an access definition
15102 --------------------------
15103 -- In_Access_Definition --
15104 --------------------------
15106 function In_Access_Definition (N : Node_Id) return Boolean is
15107 P : Node_Id;
15109 begin
15110 P := Parent (N);
15111 while Present (P) loop
15112 if Nkind (P) = N_Access_Definition then
15113 return True;
15114 end if;
15116 P := Parent (P);
15117 end loop;
15119 return False;
15120 end In_Access_Definition;
15122 -- Start of processing for Is_Protected_Self_Reference
15124 begin
15125 -- Verify that prefix is analyzed and has the proper form. Note that
15126 -- the attributes Elab_Spec, Elab_Body, and Elab_Subp_Body, which also
15127 -- produce the address of an entity, do not analyze their prefix
15128 -- because they denote entities that are not necessarily visible.
15129 -- Neither of them can apply to a protected type.
15131 return Ada_Version >= Ada_2005
15132 and then Is_Entity_Name (N)
15133 and then Present (Entity (N))
15134 and then Is_Protected_Type (Entity (N))
15135 and then In_Open_Scopes (Entity (N))
15136 and then not In_Access_Definition (N);
15137 end Is_Protected_Self_Reference;
15139 -----------------------------
15140 -- Is_RCI_Pkg_Spec_Or_Body --
15141 -----------------------------
15143 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
15145 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
15146 -- Return True if the unit of Cunit is an RCI package declaration
15148 ---------------------------
15149 -- Is_RCI_Pkg_Decl_Cunit --
15150 ---------------------------
15152 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
15153 The_Unit : constant Node_Id := Unit (Cunit);
15155 begin
15156 if Nkind (The_Unit) /= N_Package_Declaration then
15157 return False;
15158 end if;
15160 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
15161 end Is_RCI_Pkg_Decl_Cunit;
15163 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
15165 begin
15166 return Is_RCI_Pkg_Decl_Cunit (Cunit)
15167 or else
15168 (Nkind (Unit (Cunit)) = N_Package_Body
15169 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
15170 end Is_RCI_Pkg_Spec_Or_Body;
15172 -----------------------------------------
15173 -- Is_Remote_Access_To_Class_Wide_Type --
15174 -----------------------------------------
15176 function Is_Remote_Access_To_Class_Wide_Type
15177 (E : Entity_Id) return Boolean
15179 begin
15180 -- A remote access to class-wide type is a general access to object type
15181 -- declared in the visible part of a Remote_Types or Remote_Call_
15182 -- Interface unit.
15184 return Ekind (E) = E_General_Access_Type
15185 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
15186 end Is_Remote_Access_To_Class_Wide_Type;
15188 -----------------------------------------
15189 -- Is_Remote_Access_To_Subprogram_Type --
15190 -----------------------------------------
15192 function Is_Remote_Access_To_Subprogram_Type
15193 (E : Entity_Id) return Boolean
15195 begin
15196 return (Ekind (E) = E_Access_Subprogram_Type
15197 or else (Ekind (E) = E_Record_Type
15198 and then Present (Corresponding_Remote_Type (E))))
15199 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
15200 end Is_Remote_Access_To_Subprogram_Type;
15202 --------------------
15203 -- Is_Remote_Call --
15204 --------------------
15206 function Is_Remote_Call (N : Node_Id) return Boolean is
15207 begin
15208 if Nkind (N) not in N_Subprogram_Call then
15210 -- An entry call cannot be remote
15212 return False;
15214 elsif Nkind (Name (N)) in N_Has_Entity
15215 and then Is_Remote_Call_Interface (Entity (Name (N)))
15216 then
15217 -- A subprogram declared in the spec of a RCI package is remote
15219 return True;
15221 elsif Nkind (Name (N)) = N_Explicit_Dereference
15222 and then Is_Remote_Access_To_Subprogram_Type
15223 (Etype (Prefix (Name (N))))
15224 then
15225 -- The dereference of a RAS is a remote call
15227 return True;
15229 elsif Present (Controlling_Argument (N))
15230 and then Is_Remote_Access_To_Class_Wide_Type
15231 (Etype (Controlling_Argument (N)))
15232 then
15233 -- Any primitive operation call with a controlling argument of
15234 -- a RACW type is a remote call.
15236 return True;
15237 end if;
15239 -- All other calls are local calls
15241 return False;
15242 end Is_Remote_Call;
15244 ----------------------
15245 -- Is_Renamed_Entry --
15246 ----------------------
15248 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
15249 Orig_Node : Node_Id := Empty;
15250 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
15252 function Is_Entry (Nam : Node_Id) return Boolean;
15253 -- Determine whether Nam is an entry. Traverse selectors if there are
15254 -- nested selected components.
15256 --------------
15257 -- Is_Entry --
15258 --------------
15260 function Is_Entry (Nam : Node_Id) return Boolean is
15261 begin
15262 if Nkind (Nam) = N_Selected_Component then
15263 return Is_Entry (Selector_Name (Nam));
15264 end if;
15266 return Ekind (Entity (Nam)) = E_Entry;
15267 end Is_Entry;
15269 -- Start of processing for Is_Renamed_Entry
15271 begin
15272 if Present (Alias (Proc_Nam)) then
15273 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
15274 end if;
15276 -- Look for a rewritten subprogram renaming declaration
15278 if Nkind (Subp_Decl) = N_Subprogram_Declaration
15279 and then Present (Original_Node (Subp_Decl))
15280 then
15281 Orig_Node := Original_Node (Subp_Decl);
15282 end if;
15284 -- The rewritten subprogram is actually an entry
15286 if Present (Orig_Node)
15287 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
15288 and then Is_Entry (Name (Orig_Node))
15289 then
15290 return True;
15291 end if;
15293 return False;
15294 end Is_Renamed_Entry;
15296 -----------------------------
15297 -- Is_Renaming_Declaration --
15298 -----------------------------
15300 function Is_Renaming_Declaration (N : Node_Id) return Boolean is
15301 begin
15302 case Nkind (N) is
15303 when N_Exception_Renaming_Declaration
15304 | N_Generic_Function_Renaming_Declaration
15305 | N_Generic_Package_Renaming_Declaration
15306 | N_Generic_Procedure_Renaming_Declaration
15307 | N_Object_Renaming_Declaration
15308 | N_Package_Renaming_Declaration
15309 | N_Subprogram_Renaming_Declaration
15311 return True;
15313 when others =>
15314 return False;
15315 end case;
15316 end Is_Renaming_Declaration;
15318 ----------------------------
15319 -- Is_Reversible_Iterator --
15320 ----------------------------
15322 function Is_Reversible_Iterator (Typ : Entity_Id) return Boolean is
15323 Ifaces_List : Elist_Id;
15324 Iface_Elmt : Elmt_Id;
15325 Iface : Entity_Id;
15327 begin
15328 if Is_Class_Wide_Type (Typ)
15329 and then Chars (Root_Type (Typ)) = Name_Reversible_Iterator
15330 and then In_Predefined_Unit (Root_Type (Typ))
15331 then
15332 return True;
15334 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
15335 return False;
15337 else
15338 Collect_Interfaces (Typ, Ifaces_List);
15340 Iface_Elmt := First_Elmt (Ifaces_List);
15341 while Present (Iface_Elmt) loop
15342 Iface := Node (Iface_Elmt);
15343 if Chars (Iface) = Name_Reversible_Iterator
15344 and then In_Predefined_Unit (Iface)
15345 then
15346 return True;
15347 end if;
15349 Next_Elmt (Iface_Elmt);
15350 end loop;
15351 end if;
15353 return False;
15354 end Is_Reversible_Iterator;
15356 ----------------------
15357 -- Is_Selector_Name --
15358 ----------------------
15360 function Is_Selector_Name (N : Node_Id) return Boolean is
15361 begin
15362 if not Is_List_Member (N) then
15363 declare
15364 P : constant Node_Id := Parent (N);
15365 begin
15366 return Nkind_In (P, N_Expanded_Name,
15367 N_Generic_Association,
15368 N_Parameter_Association,
15369 N_Selected_Component)
15370 and then Selector_Name (P) = N;
15371 end;
15373 else
15374 declare
15375 L : constant List_Id := List_Containing (N);
15376 P : constant Node_Id := Parent (L);
15377 begin
15378 return (Nkind (P) = N_Discriminant_Association
15379 and then Selector_Names (P) = L)
15380 or else
15381 (Nkind (P) = N_Component_Association
15382 and then Choices (P) = L);
15383 end;
15384 end if;
15385 end Is_Selector_Name;
15387 ---------------------------------
15388 -- Is_Single_Concurrent_Object --
15389 ---------------------------------
15391 function Is_Single_Concurrent_Object (Id : Entity_Id) return Boolean is
15392 begin
15393 return
15394 Is_Single_Protected_Object (Id) or else Is_Single_Task_Object (Id);
15395 end Is_Single_Concurrent_Object;
15397 -------------------------------
15398 -- Is_Single_Concurrent_Type --
15399 -------------------------------
15401 function Is_Single_Concurrent_Type (Id : Entity_Id) return Boolean is
15402 begin
15403 return
15404 Ekind_In (Id, E_Protected_Type, E_Task_Type)
15405 and then Is_Single_Concurrent_Type_Declaration
15406 (Declaration_Node (Id));
15407 end Is_Single_Concurrent_Type;
15409 -------------------------------------------
15410 -- Is_Single_Concurrent_Type_Declaration --
15411 -------------------------------------------
15413 function Is_Single_Concurrent_Type_Declaration
15414 (N : Node_Id) return Boolean
15416 begin
15417 return Nkind_In (Original_Node (N), N_Single_Protected_Declaration,
15418 N_Single_Task_Declaration);
15419 end Is_Single_Concurrent_Type_Declaration;
15421 ---------------------------------------------
15422 -- Is_Single_Precision_Floating_Point_Type --
15423 ---------------------------------------------
15425 function Is_Single_Precision_Floating_Point_Type
15426 (E : Entity_Id) return Boolean is
15427 begin
15428 return Is_Floating_Point_Type (E)
15429 and then Machine_Radix_Value (E) = Uint_2
15430 and then Machine_Mantissa_Value (E) = Uint_24
15431 and then Machine_Emax_Value (E) = Uint_2 ** Uint_7
15432 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_7);
15433 end Is_Single_Precision_Floating_Point_Type;
15435 --------------------------------
15436 -- Is_Single_Protected_Object --
15437 --------------------------------
15439 function Is_Single_Protected_Object (Id : Entity_Id) return Boolean is
15440 begin
15441 return
15442 Ekind (Id) = E_Variable
15443 and then Ekind (Etype (Id)) = E_Protected_Type
15444 and then Is_Single_Concurrent_Type (Etype (Id));
15445 end Is_Single_Protected_Object;
15447 ---------------------------
15448 -- Is_Single_Task_Object --
15449 ---------------------------
15451 function Is_Single_Task_Object (Id : Entity_Id) return Boolean is
15452 begin
15453 return
15454 Ekind (Id) = E_Variable
15455 and then Ekind (Etype (Id)) = E_Task_Type
15456 and then Is_Single_Concurrent_Type (Etype (Id));
15457 end Is_Single_Task_Object;
15459 -------------------------------------
15460 -- Is_SPARK_05_Initialization_Expr --
15461 -------------------------------------
15463 function Is_SPARK_05_Initialization_Expr (N : Node_Id) return Boolean is
15464 Is_Ok : Boolean;
15465 Expr : Node_Id;
15466 Comp_Assn : Node_Id;
15467 Orig_N : constant Node_Id := Original_Node (N);
15469 begin
15470 Is_Ok := True;
15472 if not Comes_From_Source (Orig_N) then
15473 goto Done;
15474 end if;
15476 pragma Assert (Nkind (Orig_N) in N_Subexpr);
15478 case Nkind (Orig_N) is
15479 when N_Character_Literal
15480 | N_Integer_Literal
15481 | N_Real_Literal
15482 | N_String_Literal
15484 null;
15486 when N_Expanded_Name
15487 | N_Identifier
15489 if Is_Entity_Name (Orig_N)
15490 and then Present (Entity (Orig_N)) -- needed in some cases
15491 then
15492 case Ekind (Entity (Orig_N)) is
15493 when E_Constant
15494 | E_Enumeration_Literal
15495 | E_Named_Integer
15496 | E_Named_Real
15498 null;
15500 when others =>
15501 if Is_Type (Entity (Orig_N)) then
15502 null;
15503 else
15504 Is_Ok := False;
15505 end if;
15506 end case;
15507 end if;
15509 when N_Qualified_Expression
15510 | N_Type_Conversion
15512 Is_Ok := Is_SPARK_05_Initialization_Expr (Expression (Orig_N));
15514 when N_Unary_Op =>
15515 Is_Ok := Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
15517 when N_Binary_Op
15518 | N_Membership_Test
15519 | N_Short_Circuit
15521 Is_Ok := Is_SPARK_05_Initialization_Expr (Left_Opnd (Orig_N))
15522 and then
15523 Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
15525 when N_Aggregate
15526 | N_Extension_Aggregate
15528 if Nkind (Orig_N) = N_Extension_Aggregate then
15529 Is_Ok :=
15530 Is_SPARK_05_Initialization_Expr (Ancestor_Part (Orig_N));
15531 end if;
15533 Expr := First (Expressions (Orig_N));
15534 while Present (Expr) loop
15535 if not Is_SPARK_05_Initialization_Expr (Expr) then
15536 Is_Ok := False;
15537 goto Done;
15538 end if;
15540 Next (Expr);
15541 end loop;
15543 Comp_Assn := First (Component_Associations (Orig_N));
15544 while Present (Comp_Assn) loop
15545 Expr := Expression (Comp_Assn);
15547 -- Note: test for Present here needed for box assocation
15549 if Present (Expr)
15550 and then not Is_SPARK_05_Initialization_Expr (Expr)
15551 then
15552 Is_Ok := False;
15553 goto Done;
15554 end if;
15556 Next (Comp_Assn);
15557 end loop;
15559 when N_Attribute_Reference =>
15560 if Nkind (Prefix (Orig_N)) in N_Subexpr then
15561 Is_Ok := Is_SPARK_05_Initialization_Expr (Prefix (Orig_N));
15562 end if;
15564 Expr := First (Expressions (Orig_N));
15565 while Present (Expr) loop
15566 if not Is_SPARK_05_Initialization_Expr (Expr) then
15567 Is_Ok := False;
15568 goto Done;
15569 end if;
15571 Next (Expr);
15572 end loop;
15574 -- Selected components might be expanded named not yet resolved, so
15575 -- default on the safe side. (Eg on sparklex.ads)
15577 when N_Selected_Component =>
15578 null;
15580 when others =>
15581 Is_Ok := False;
15582 end case;
15584 <<Done>>
15585 return Is_Ok;
15586 end Is_SPARK_05_Initialization_Expr;
15588 ----------------------------------
15589 -- Is_SPARK_05_Object_Reference --
15590 ----------------------------------
15592 function Is_SPARK_05_Object_Reference (N : Node_Id) return Boolean is
15593 begin
15594 if Is_Entity_Name (N) then
15595 return Present (Entity (N))
15596 and then
15597 (Ekind_In (Entity (N), E_Constant, E_Variable)
15598 or else Ekind (Entity (N)) in Formal_Kind);
15600 else
15601 case Nkind (N) is
15602 when N_Selected_Component =>
15603 return Is_SPARK_05_Object_Reference (Prefix (N));
15605 when others =>
15606 return False;
15607 end case;
15608 end if;
15609 end Is_SPARK_05_Object_Reference;
15611 -----------------------------
15612 -- Is_Specific_Tagged_Type --
15613 -----------------------------
15615 function Is_Specific_Tagged_Type (Typ : Entity_Id) return Boolean is
15616 Full_Typ : Entity_Id;
15618 begin
15619 -- Handle private types
15621 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
15622 Full_Typ := Full_View (Typ);
15623 else
15624 Full_Typ := Typ;
15625 end if;
15627 -- A specific tagged type is a non-class-wide tagged type
15629 return Is_Tagged_Type (Full_Typ) and not Is_Class_Wide_Type (Full_Typ);
15630 end Is_Specific_Tagged_Type;
15632 ------------------
15633 -- Is_Statement --
15634 ------------------
15636 function Is_Statement (N : Node_Id) return Boolean is
15637 begin
15638 return
15639 Nkind (N) in N_Statement_Other_Than_Procedure_Call
15640 or else Nkind (N) = N_Procedure_Call_Statement;
15641 end Is_Statement;
15643 ---------------------------------------
15644 -- Is_Subprogram_Contract_Annotation --
15645 ---------------------------------------
15647 function Is_Subprogram_Contract_Annotation
15648 (Item : Node_Id) return Boolean
15650 Nam : Name_Id;
15652 begin
15653 if Nkind (Item) = N_Aspect_Specification then
15654 Nam := Chars (Identifier (Item));
15656 else pragma Assert (Nkind (Item) = N_Pragma);
15657 Nam := Pragma_Name (Item);
15658 end if;
15660 return Nam = Name_Contract_Cases
15661 or else Nam = Name_Depends
15662 or else Nam = Name_Extensions_Visible
15663 or else Nam = Name_Global
15664 or else Nam = Name_Post
15665 or else Nam = Name_Post_Class
15666 or else Nam = Name_Postcondition
15667 or else Nam = Name_Pre
15668 or else Nam = Name_Pre_Class
15669 or else Nam = Name_Precondition
15670 or else Nam = Name_Refined_Depends
15671 or else Nam = Name_Refined_Global
15672 or else Nam = Name_Refined_Post
15673 or else Nam = Name_Test_Case;
15674 end Is_Subprogram_Contract_Annotation;
15676 --------------------------------------------------
15677 -- Is_Subprogram_Stub_Without_Prior_Declaration --
15678 --------------------------------------------------
15680 function Is_Subprogram_Stub_Without_Prior_Declaration
15681 (N : Node_Id) return Boolean
15683 begin
15684 -- A subprogram stub without prior declaration serves as declaration for
15685 -- the actual subprogram body. As such, it has an attached defining
15686 -- entity of E_[Generic_]Function or E_[Generic_]Procedure.
15688 return Nkind (N) = N_Subprogram_Body_Stub
15689 and then Ekind (Defining_Entity (N)) /= E_Subprogram_Body;
15690 end Is_Subprogram_Stub_Without_Prior_Declaration;
15692 --------------------------
15693 -- Is_Suspension_Object --
15694 --------------------------
15696 function Is_Suspension_Object (Id : Entity_Id) return Boolean is
15697 begin
15698 -- This approach does an exact name match rather than to rely on
15699 -- RTSfind. Routine Is_Effectively_Volatile is used by clients of the
15700 -- front end at point where all auxiliary tables are locked and any
15701 -- modifications to them are treated as violations. Do not tamper with
15702 -- the tables, instead examine the Chars fields of all the scopes of Id.
15704 return
15705 Chars (Id) = Name_Suspension_Object
15706 and then Present (Scope (Id))
15707 and then Chars (Scope (Id)) = Name_Synchronous_Task_Control
15708 and then Present (Scope (Scope (Id)))
15709 and then Chars (Scope (Scope (Id))) = Name_Ada
15710 and then Present (Scope (Scope (Scope (Id))))
15711 and then Scope (Scope (Scope (Id))) = Standard_Standard;
15712 end Is_Suspension_Object;
15714 ----------------------------
15715 -- Is_Synchronized_Object --
15716 ----------------------------
15718 function Is_Synchronized_Object (Id : Entity_Id) return Boolean is
15719 Prag : Node_Id;
15721 begin
15722 if Is_Object (Id) then
15724 -- The object is synchronized if it is of a type that yields a
15725 -- synchronized object.
15727 if Yields_Synchronized_Object (Etype (Id)) then
15728 return True;
15730 -- The object is synchronized if it is atomic and Async_Writers is
15731 -- enabled.
15733 elsif Is_Atomic (Id) and then Async_Writers_Enabled (Id) then
15734 return True;
15736 -- A constant is a synchronized object by default
15738 elsif Ekind (Id) = E_Constant then
15739 return True;
15741 -- A variable is a synchronized object if it is subject to pragma
15742 -- Constant_After_Elaboration.
15744 elsif Ekind (Id) = E_Variable then
15745 Prag := Get_Pragma (Id, Pragma_Constant_After_Elaboration);
15747 return Present (Prag) and then Is_Enabled_Pragma (Prag);
15748 end if;
15749 end if;
15751 -- Otherwise the input is not an object or it does not qualify as a
15752 -- synchronized object.
15754 return False;
15755 end Is_Synchronized_Object;
15757 ---------------------------------
15758 -- Is_Synchronized_Tagged_Type --
15759 ---------------------------------
15761 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
15762 Kind : constant Entity_Kind := Ekind (Base_Type (E));
15764 begin
15765 -- A task or protected type derived from an interface is a tagged type.
15766 -- Such a tagged type is called a synchronized tagged type, as are
15767 -- synchronized interfaces and private extensions whose declaration
15768 -- includes the reserved word synchronized.
15770 return (Is_Tagged_Type (E)
15771 and then (Kind = E_Task_Type
15772 or else
15773 Kind = E_Protected_Type))
15774 or else
15775 (Is_Interface (E)
15776 and then Is_Synchronized_Interface (E))
15777 or else
15778 (Ekind (E) = E_Record_Type_With_Private
15779 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
15780 and then (Synchronized_Present (Parent (E))
15781 or else Is_Synchronized_Interface (Etype (E))));
15782 end Is_Synchronized_Tagged_Type;
15784 -----------------
15785 -- Is_Transfer --
15786 -----------------
15788 function Is_Transfer (N : Node_Id) return Boolean is
15789 Kind : constant Node_Kind := Nkind (N);
15791 begin
15792 if Kind = N_Simple_Return_Statement
15793 or else
15794 Kind = N_Extended_Return_Statement
15795 or else
15796 Kind = N_Goto_Statement
15797 or else
15798 Kind = N_Raise_Statement
15799 or else
15800 Kind = N_Requeue_Statement
15801 then
15802 return True;
15804 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
15805 and then No (Condition (N))
15806 then
15807 return True;
15809 elsif Kind = N_Procedure_Call_Statement
15810 and then Is_Entity_Name (Name (N))
15811 and then Present (Entity (Name (N)))
15812 and then No_Return (Entity (Name (N)))
15813 then
15814 return True;
15816 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
15817 return True;
15819 else
15820 return False;
15821 end if;
15822 end Is_Transfer;
15824 -------------
15825 -- Is_True --
15826 -------------
15828 function Is_True (U : Uint) return Boolean is
15829 begin
15830 return (U /= 0);
15831 end Is_True;
15833 --------------------------------------
15834 -- Is_Unchecked_Conversion_Instance --
15835 --------------------------------------
15837 function Is_Unchecked_Conversion_Instance (Id : Entity_Id) return Boolean is
15838 Par : Node_Id;
15840 begin
15841 -- Look for a function whose generic parent is the predefined intrinsic
15842 -- function Unchecked_Conversion, or for one that renames such an
15843 -- instance.
15845 if Ekind (Id) = E_Function then
15846 Par := Parent (Id);
15848 if Nkind (Par) = N_Function_Specification then
15849 Par := Generic_Parent (Par);
15851 if Present (Par) then
15852 return
15853 Chars (Par) = Name_Unchecked_Conversion
15854 and then Is_Intrinsic_Subprogram (Par)
15855 and then In_Predefined_Unit (Par);
15856 else
15857 return
15858 Present (Alias (Id))
15859 and then Is_Unchecked_Conversion_Instance (Alias (Id));
15860 end if;
15861 end if;
15862 end if;
15864 return False;
15865 end Is_Unchecked_Conversion_Instance;
15867 -------------------------------
15868 -- Is_Universal_Numeric_Type --
15869 -------------------------------
15871 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
15872 begin
15873 return T = Universal_Integer or else T = Universal_Real;
15874 end Is_Universal_Numeric_Type;
15876 ------------------------------
15877 -- Is_User_Defined_Equality --
15878 ------------------------------
15880 function Is_User_Defined_Equality (Id : Entity_Id) return Boolean is
15881 begin
15882 return Ekind (Id) = E_Function
15883 and then Chars (Id) = Name_Op_Eq
15884 and then Comes_From_Source (Id)
15886 -- Internally generated equalities have a full type declaration
15887 -- as their parent.
15889 and then Nkind (Parent (Id)) = N_Function_Specification;
15890 end Is_User_Defined_Equality;
15892 --------------------------------------
15893 -- Is_Validation_Variable_Reference --
15894 --------------------------------------
15896 function Is_Validation_Variable_Reference (N : Node_Id) return Boolean is
15897 Var : constant Node_Id := Unqual_Conv (N);
15898 Var_Id : Entity_Id;
15900 begin
15901 Var_Id := Empty;
15903 if Is_Entity_Name (Var) then
15904 Var_Id := Entity (Var);
15905 end if;
15907 return
15908 Present (Var_Id)
15909 and then Ekind (Var_Id) = E_Variable
15910 and then Present (Validated_Object (Var_Id));
15911 end Is_Validation_Variable_Reference;
15913 ----------------------------
15914 -- Is_Variable_Size_Array --
15915 ----------------------------
15917 function Is_Variable_Size_Array (E : Entity_Id) return Boolean is
15918 Idx : Node_Id;
15920 begin
15921 pragma Assert (Is_Array_Type (E));
15923 -- Check if some index is initialized with a non-constant value
15925 Idx := First_Index (E);
15926 while Present (Idx) loop
15927 if Nkind (Idx) = N_Range then
15928 if not Is_Constant_Bound (Low_Bound (Idx))
15929 or else not Is_Constant_Bound (High_Bound (Idx))
15930 then
15931 return True;
15932 end if;
15933 end if;
15935 Idx := Next_Index (Idx);
15936 end loop;
15938 return False;
15939 end Is_Variable_Size_Array;
15941 -----------------------------
15942 -- Is_Variable_Size_Record --
15943 -----------------------------
15945 function Is_Variable_Size_Record (E : Entity_Id) return Boolean is
15946 Comp : Entity_Id;
15947 Comp_Typ : Entity_Id;
15949 begin
15950 pragma Assert (Is_Record_Type (E));
15952 Comp := First_Entity (E);
15953 while Present (Comp) loop
15954 Comp_Typ := Etype (Comp);
15956 -- Recursive call if the record type has discriminants
15958 if Is_Record_Type (Comp_Typ)
15959 and then Has_Discriminants (Comp_Typ)
15960 and then Is_Variable_Size_Record (Comp_Typ)
15961 then
15962 return True;
15964 elsif Is_Array_Type (Comp_Typ)
15965 and then Is_Variable_Size_Array (Comp_Typ)
15966 then
15967 return True;
15968 end if;
15970 Next_Entity (Comp);
15971 end loop;
15973 return False;
15974 end Is_Variable_Size_Record;
15976 -----------------
15977 -- Is_Variable --
15978 -----------------
15980 function Is_Variable
15981 (N : Node_Id;
15982 Use_Original_Node : Boolean := True) return Boolean
15984 Orig_Node : Node_Id;
15986 function In_Protected_Function (E : Entity_Id) return Boolean;
15987 -- Within a protected function, the private components of the enclosing
15988 -- protected type are constants. A function nested within a (protected)
15989 -- procedure is not itself protected. Within the body of a protected
15990 -- function the current instance of the protected type is a constant.
15992 function Is_Variable_Prefix (P : Node_Id) return Boolean;
15993 -- Prefixes can involve implicit dereferences, in which case we must
15994 -- test for the case of a reference of a constant access type, which can
15995 -- can never be a variable.
15997 ---------------------------
15998 -- In_Protected_Function --
15999 ---------------------------
16001 function In_Protected_Function (E : Entity_Id) return Boolean is
16002 Prot : Entity_Id;
16003 S : Entity_Id;
16005 begin
16006 -- E is the current instance of a type
16008 if Is_Type (E) then
16009 Prot := E;
16011 -- E is an object
16013 else
16014 Prot := Scope (E);
16015 end if;
16017 if not Is_Protected_Type (Prot) then
16018 return False;
16020 else
16021 S := Current_Scope;
16022 while Present (S) and then S /= Prot loop
16023 if Ekind (S) = E_Function and then Scope (S) = Prot then
16024 return True;
16025 end if;
16027 S := Scope (S);
16028 end loop;
16030 return False;
16031 end if;
16032 end In_Protected_Function;
16034 ------------------------
16035 -- Is_Variable_Prefix --
16036 ------------------------
16038 function Is_Variable_Prefix (P : Node_Id) return Boolean is
16039 begin
16040 if Is_Access_Type (Etype (P)) then
16041 return not Is_Access_Constant (Root_Type (Etype (P)));
16043 -- For the case of an indexed component whose prefix has a packed
16044 -- array type, the prefix has been rewritten into a type conversion.
16045 -- Determine variable-ness from the converted expression.
16047 elsif Nkind (P) = N_Type_Conversion
16048 and then not Comes_From_Source (P)
16049 and then Is_Array_Type (Etype (P))
16050 and then Is_Packed (Etype (P))
16051 then
16052 return Is_Variable (Expression (P));
16054 else
16055 return Is_Variable (P);
16056 end if;
16057 end Is_Variable_Prefix;
16059 -- Start of processing for Is_Variable
16061 begin
16062 -- Special check, allow x'Deref(expr) as a variable
16064 if Nkind (N) = N_Attribute_Reference
16065 and then Attribute_Name (N) = Name_Deref
16066 then
16067 return True;
16068 end if;
16070 -- Check if we perform the test on the original node since this may be a
16071 -- test of syntactic categories which must not be disturbed by whatever
16072 -- rewriting might have occurred. For example, an aggregate, which is
16073 -- certainly NOT a variable, could be turned into a variable by
16074 -- expansion.
16076 if Use_Original_Node then
16077 Orig_Node := Original_Node (N);
16078 else
16079 Orig_Node := N;
16080 end if;
16082 -- Definitely OK if Assignment_OK is set. Since this is something that
16083 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
16085 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
16086 return True;
16088 -- Normally we go to the original node, but there is one exception where
16089 -- we use the rewritten node, namely when it is an explicit dereference.
16090 -- The generated code may rewrite a prefix which is an access type with
16091 -- an explicit dereference. The dereference is a variable, even though
16092 -- the original node may not be (since it could be a constant of the
16093 -- access type).
16095 -- In Ada 2005 we have a further case to consider: the prefix may be a
16096 -- function call given in prefix notation. The original node appears to
16097 -- be a selected component, but we need to examine the call.
16099 elsif Nkind (N) = N_Explicit_Dereference
16100 and then Nkind (Orig_Node) /= N_Explicit_Dereference
16101 and then Present (Etype (Orig_Node))
16102 and then Is_Access_Type (Etype (Orig_Node))
16103 then
16104 -- Note that if the prefix is an explicit dereference that does not
16105 -- come from source, we must check for a rewritten function call in
16106 -- prefixed notation before other forms of rewriting, to prevent a
16107 -- compiler crash.
16109 return
16110 (Nkind (Orig_Node) = N_Function_Call
16111 and then not Is_Access_Constant (Etype (Prefix (N))))
16112 or else
16113 Is_Variable_Prefix (Original_Node (Prefix (N)));
16115 -- in Ada 2012, the dereference may have been added for a type with
16116 -- a declared implicit dereference aspect. Check that it is not an
16117 -- access to constant.
16119 elsif Nkind (N) = N_Explicit_Dereference
16120 and then Present (Etype (Orig_Node))
16121 and then Ada_Version >= Ada_2012
16122 and then Has_Implicit_Dereference (Etype (Orig_Node))
16123 then
16124 return not Is_Access_Constant (Etype (Prefix (N)));
16126 -- A function call is never a variable
16128 elsif Nkind (N) = N_Function_Call then
16129 return False;
16131 -- All remaining checks use the original node
16133 elsif Is_Entity_Name (Orig_Node)
16134 and then Present (Entity (Orig_Node))
16135 then
16136 declare
16137 E : constant Entity_Id := Entity (Orig_Node);
16138 K : constant Entity_Kind := Ekind (E);
16140 begin
16141 return (K = E_Variable
16142 and then Nkind (Parent (E)) /= N_Exception_Handler)
16143 or else (K = E_Component
16144 and then not In_Protected_Function (E))
16145 or else K = E_Out_Parameter
16146 or else K = E_In_Out_Parameter
16147 or else K = E_Generic_In_Out_Parameter
16149 -- Current instance of type. If this is a protected type, check
16150 -- we are not within the body of one of its protected functions.
16152 or else (Is_Type (E)
16153 and then In_Open_Scopes (E)
16154 and then not In_Protected_Function (E))
16156 or else (Is_Incomplete_Or_Private_Type (E)
16157 and then In_Open_Scopes (Full_View (E)));
16158 end;
16160 else
16161 case Nkind (Orig_Node) is
16162 when N_Indexed_Component
16163 | N_Slice
16165 return Is_Variable_Prefix (Prefix (Orig_Node));
16167 when N_Selected_Component =>
16168 return (Is_Variable (Selector_Name (Orig_Node))
16169 and then Is_Variable_Prefix (Prefix (Orig_Node)))
16170 or else
16171 (Nkind (N) = N_Expanded_Name
16172 and then Scope (Entity (N)) = Entity (Prefix (N)));
16174 -- For an explicit dereference, the type of the prefix cannot
16175 -- be an access to constant or an access to subprogram.
16177 when N_Explicit_Dereference =>
16178 declare
16179 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
16180 begin
16181 return Is_Access_Type (Typ)
16182 and then not Is_Access_Constant (Root_Type (Typ))
16183 and then Ekind (Typ) /= E_Access_Subprogram_Type;
16184 end;
16186 -- The type conversion is the case where we do not deal with the
16187 -- context dependent special case of an actual parameter. Thus
16188 -- the type conversion is only considered a variable for the
16189 -- purposes of this routine if the target type is tagged. However,
16190 -- a type conversion is considered to be a variable if it does not
16191 -- come from source (this deals for example with the conversions
16192 -- of expressions to their actual subtypes).
16194 when N_Type_Conversion =>
16195 return Is_Variable (Expression (Orig_Node))
16196 and then
16197 (not Comes_From_Source (Orig_Node)
16198 or else
16199 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
16200 and then
16201 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
16203 -- GNAT allows an unchecked type conversion as a variable. This
16204 -- only affects the generation of internal expanded code, since
16205 -- calls to instantiations of Unchecked_Conversion are never
16206 -- considered variables (since they are function calls).
16208 when N_Unchecked_Type_Conversion =>
16209 return Is_Variable (Expression (Orig_Node));
16211 when others =>
16212 return False;
16213 end case;
16214 end if;
16215 end Is_Variable;
16217 ------------------------------
16218 -- Is_Verifiable_DIC_Pragma --
16219 ------------------------------
16221 function Is_Verifiable_DIC_Pragma (Prag : Node_Id) return Boolean is
16222 Args : constant List_Id := Pragma_Argument_Associations (Prag);
16224 begin
16225 -- To qualify as verifiable, a DIC pragma must have a non-null argument
16227 return
16228 Present (Args)
16229 and then Nkind (Get_Pragma_Arg (First (Args))) /= N_Null;
16230 end Is_Verifiable_DIC_Pragma;
16232 ---------------------------
16233 -- Is_Visibly_Controlled --
16234 ---------------------------
16236 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
16237 Root : constant Entity_Id := Root_Type (T);
16238 begin
16239 return Chars (Scope (Root)) = Name_Finalization
16240 and then Chars (Scope (Scope (Root))) = Name_Ada
16241 and then Scope (Scope (Scope (Root))) = Standard_Standard;
16242 end Is_Visibly_Controlled;
16244 --------------------------
16245 -- Is_Volatile_Function --
16246 --------------------------
16248 function Is_Volatile_Function (Func_Id : Entity_Id) return Boolean is
16249 begin
16250 pragma Assert (Ekind_In (Func_Id, E_Function, E_Generic_Function));
16252 -- A function declared within a protected type is volatile
16254 if Is_Protected_Type (Scope (Func_Id)) then
16255 return True;
16257 -- An instance of Ada.Unchecked_Conversion is a volatile function if
16258 -- either the source or the target are effectively volatile.
16260 elsif Is_Unchecked_Conversion_Instance (Func_Id)
16261 and then Has_Effectively_Volatile_Profile (Func_Id)
16262 then
16263 return True;
16265 -- Otherwise the function is treated as volatile if it is subject to
16266 -- enabled pragma Volatile_Function.
16268 else
16269 return
16270 Is_Enabled_Pragma (Get_Pragma (Func_Id, Pragma_Volatile_Function));
16271 end if;
16272 end Is_Volatile_Function;
16274 ------------------------
16275 -- Is_Volatile_Object --
16276 ------------------------
16278 function Is_Volatile_Object (N : Node_Id) return Boolean is
16279 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
16280 -- If prefix is an implicit dereference, examine designated type
16282 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
16283 -- Determines if given object has volatile components
16285 ------------------------
16286 -- Is_Volatile_Prefix --
16287 ------------------------
16289 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
16290 Typ : constant Entity_Id := Etype (N);
16292 begin
16293 if Is_Access_Type (Typ) then
16294 declare
16295 Dtyp : constant Entity_Id := Designated_Type (Typ);
16297 begin
16298 return Is_Volatile (Dtyp)
16299 or else Has_Volatile_Components (Dtyp);
16300 end;
16302 else
16303 return Object_Has_Volatile_Components (N);
16304 end if;
16305 end Is_Volatile_Prefix;
16307 ------------------------------------
16308 -- Object_Has_Volatile_Components --
16309 ------------------------------------
16311 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
16312 Typ : constant Entity_Id := Etype (N);
16314 begin
16315 if Is_Volatile (Typ)
16316 or else Has_Volatile_Components (Typ)
16317 then
16318 return True;
16320 elsif Is_Entity_Name (N)
16321 and then (Has_Volatile_Components (Entity (N))
16322 or else Is_Volatile (Entity (N)))
16323 then
16324 return True;
16326 elsif Nkind (N) = N_Indexed_Component
16327 or else Nkind (N) = N_Selected_Component
16328 then
16329 return Is_Volatile_Prefix (Prefix (N));
16331 else
16332 return False;
16333 end if;
16334 end Object_Has_Volatile_Components;
16336 -- Start of processing for Is_Volatile_Object
16338 begin
16339 if Nkind (N) = N_Defining_Identifier then
16340 return Is_Volatile (N) or else Is_Volatile (Etype (N));
16342 elsif Nkind (N) = N_Expanded_Name then
16343 return Is_Volatile_Object (Entity (N));
16345 elsif Is_Volatile (Etype (N))
16346 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
16347 then
16348 return True;
16350 elsif Nkind_In (N, N_Indexed_Component, N_Selected_Component)
16351 and then Is_Volatile_Prefix (Prefix (N))
16352 then
16353 return True;
16355 elsif Nkind (N) = N_Selected_Component
16356 and then Is_Volatile (Entity (Selector_Name (N)))
16357 then
16358 return True;
16360 else
16361 return False;
16362 end if;
16363 end Is_Volatile_Object;
16365 -----------------------------
16366 -- Iterate_Call_Parameters --
16367 -----------------------------
16369 procedure Iterate_Call_Parameters (Call : Node_Id) is
16370 Formal : Entity_Id := First_Formal (Get_Called_Entity (Call));
16371 Actual : Node_Id := First_Actual (Call);
16373 begin
16374 while Present (Formal) and then Present (Actual) loop
16375 Handle_Parameter (Formal, Actual);
16376 Formal := Next_Formal (Formal);
16377 Actual := Next_Actual (Actual);
16378 end loop;
16379 end Iterate_Call_Parameters;
16381 ---------------------------
16382 -- Itype_Has_Declaration --
16383 ---------------------------
16385 function Itype_Has_Declaration (Id : Entity_Id) return Boolean is
16386 begin
16387 pragma Assert (Is_Itype (Id));
16388 return Present (Parent (Id))
16389 and then Nkind_In (Parent (Id), N_Full_Type_Declaration,
16390 N_Subtype_Declaration)
16391 and then Defining_Entity (Parent (Id)) = Id;
16392 end Itype_Has_Declaration;
16394 -------------------------
16395 -- Kill_Current_Values --
16396 -------------------------
16398 procedure Kill_Current_Values
16399 (Ent : Entity_Id;
16400 Last_Assignment_Only : Boolean := False)
16402 begin
16403 if Is_Assignable (Ent) then
16404 Set_Last_Assignment (Ent, Empty);
16405 end if;
16407 if Is_Object (Ent) then
16408 if not Last_Assignment_Only then
16409 Kill_Checks (Ent);
16410 Set_Current_Value (Ent, Empty);
16412 -- Do not reset the Is_Known_[Non_]Null and Is_Known_Valid flags
16413 -- for a constant. Once the constant is elaborated, its value is
16414 -- not changed, therefore the associated flags that describe the
16415 -- value should not be modified either.
16417 if Ekind (Ent) = E_Constant then
16418 null;
16420 -- Non-constant entities
16422 else
16423 if not Can_Never_Be_Null (Ent) then
16424 Set_Is_Known_Non_Null (Ent, False);
16425 end if;
16427 Set_Is_Known_Null (Ent, False);
16429 -- Reset the Is_Known_Valid flag unless the type is always
16430 -- valid. This does not apply to a loop parameter because its
16431 -- bounds are defined by the loop header and therefore always
16432 -- valid.
16434 if not Is_Known_Valid (Etype (Ent))
16435 and then Ekind (Ent) /= E_Loop_Parameter
16436 then
16437 Set_Is_Known_Valid (Ent, False);
16438 end if;
16439 end if;
16440 end if;
16441 end if;
16442 end Kill_Current_Values;
16444 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
16445 S : Entity_Id;
16447 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
16448 -- Clear current value for entity E and all entities chained to E
16450 ------------------------------------------
16451 -- Kill_Current_Values_For_Entity_Chain --
16452 ------------------------------------------
16454 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
16455 Ent : Entity_Id;
16456 begin
16457 Ent := E;
16458 while Present (Ent) loop
16459 Kill_Current_Values (Ent, Last_Assignment_Only);
16460 Next_Entity (Ent);
16461 end loop;
16462 end Kill_Current_Values_For_Entity_Chain;
16464 -- Start of processing for Kill_Current_Values
16466 begin
16467 -- Kill all saved checks, a special case of killing saved values
16469 if not Last_Assignment_Only then
16470 Kill_All_Checks;
16471 end if;
16473 -- Loop through relevant scopes, which includes the current scope and
16474 -- any parent scopes if the current scope is a block or a package.
16476 S := Current_Scope;
16477 Scope_Loop : loop
16479 -- Clear current values of all entities in current scope
16481 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
16483 -- If scope is a package, also clear current values of all private
16484 -- entities in the scope.
16486 if Is_Package_Or_Generic_Package (S)
16487 or else Is_Concurrent_Type (S)
16488 then
16489 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
16490 end if;
16492 -- If this is a not a subprogram, deal with parents
16494 if not Is_Subprogram (S) then
16495 S := Scope (S);
16496 exit Scope_Loop when S = Standard_Standard;
16497 else
16498 exit Scope_Loop;
16499 end if;
16500 end loop Scope_Loop;
16501 end Kill_Current_Values;
16503 --------------------------
16504 -- Kill_Size_Check_Code --
16505 --------------------------
16507 procedure Kill_Size_Check_Code (E : Entity_Id) is
16508 begin
16509 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
16510 and then Present (Size_Check_Code (E))
16511 then
16512 Remove (Size_Check_Code (E));
16513 Set_Size_Check_Code (E, Empty);
16514 end if;
16515 end Kill_Size_Check_Code;
16517 --------------------
16518 -- Known_Non_Null --
16519 --------------------
16521 function Known_Non_Null (N : Node_Id) return Boolean is
16522 Status : constant Null_Status_Kind := Null_Status (N);
16524 Id : Entity_Id;
16525 Op : Node_Kind;
16526 Val : Node_Id;
16528 begin
16529 -- The expression yields a non-null value ignoring simple flow analysis
16531 if Status = Is_Non_Null then
16532 return True;
16534 -- Otherwise check whether N is a reference to an entity that appears
16535 -- within a conditional construct.
16537 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
16539 -- First check if we are in decisive conditional
16541 Get_Current_Value_Condition (N, Op, Val);
16543 if Known_Null (Val) then
16544 if Op = N_Op_Eq then
16545 return False;
16546 elsif Op = N_Op_Ne then
16547 return True;
16548 end if;
16549 end if;
16551 -- If OK to do replacement, test Is_Known_Non_Null flag
16553 Id := Entity (N);
16555 if OK_To_Do_Constant_Replacement (Id) then
16556 return Is_Known_Non_Null (Id);
16557 end if;
16558 end if;
16560 -- Otherwise it is not possible to determine whether N yields a non-null
16561 -- value.
16563 return False;
16564 end Known_Non_Null;
16566 ----------------
16567 -- Known_Null --
16568 ----------------
16570 function Known_Null (N : Node_Id) return Boolean is
16571 Status : constant Null_Status_Kind := Null_Status (N);
16573 Id : Entity_Id;
16574 Op : Node_Kind;
16575 Val : Node_Id;
16577 begin
16578 -- The expression yields a null value ignoring simple flow analysis
16580 if Status = Is_Null then
16581 return True;
16583 -- Otherwise check whether N is a reference to an entity that appears
16584 -- within a conditional construct.
16586 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
16588 -- First check if we are in decisive conditional
16590 Get_Current_Value_Condition (N, Op, Val);
16592 if Known_Null (Val) then
16593 if Op = N_Op_Eq then
16594 return True;
16595 elsif Op = N_Op_Ne then
16596 return False;
16597 end if;
16598 end if;
16600 -- If OK to do replacement, test Is_Known_Null flag
16602 Id := Entity (N);
16604 if OK_To_Do_Constant_Replacement (Id) then
16605 return Is_Known_Null (Id);
16606 end if;
16607 end if;
16609 -- Otherwise it is not possible to determine whether N yields a null
16610 -- value.
16612 return False;
16613 end Known_Null;
16615 --------------------------
16616 -- Known_To_Be_Assigned --
16617 --------------------------
16619 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
16620 P : constant Node_Id := Parent (N);
16622 begin
16623 case Nkind (P) is
16625 -- Test left side of assignment
16627 when N_Assignment_Statement =>
16628 return N = Name (P);
16630 -- Function call arguments are never lvalues
16632 when N_Function_Call =>
16633 return False;
16635 -- Positional parameter for procedure or accept call
16637 when N_Accept_Statement
16638 | N_Procedure_Call_Statement
16640 declare
16641 Proc : Entity_Id;
16642 Form : Entity_Id;
16643 Act : Node_Id;
16645 begin
16646 Proc := Get_Subprogram_Entity (P);
16648 if No (Proc) then
16649 return False;
16650 end if;
16652 -- If we are not a list member, something is strange, so
16653 -- be conservative and return False.
16655 if not Is_List_Member (N) then
16656 return False;
16657 end if;
16659 -- We are going to find the right formal by stepping forward
16660 -- through the formals, as we step backwards in the actuals.
16662 Form := First_Formal (Proc);
16663 Act := N;
16664 loop
16665 -- If no formal, something is weird, so be conservative
16666 -- and return False.
16668 if No (Form) then
16669 return False;
16670 end if;
16672 Prev (Act);
16673 exit when No (Act);
16674 Next_Formal (Form);
16675 end loop;
16677 return Ekind (Form) /= E_In_Parameter;
16678 end;
16680 -- Named parameter for procedure or accept call
16682 when N_Parameter_Association =>
16683 declare
16684 Proc : Entity_Id;
16685 Form : Entity_Id;
16687 begin
16688 Proc := Get_Subprogram_Entity (Parent (P));
16690 if No (Proc) then
16691 return False;
16692 end if;
16694 -- Loop through formals to find the one that matches
16696 Form := First_Formal (Proc);
16697 loop
16698 -- If no matching formal, that's peculiar, some kind of
16699 -- previous error, so return False to be conservative.
16700 -- Actually this also happens in legal code in the case
16701 -- where P is a parameter association for an Extra_Formal???
16703 if No (Form) then
16704 return False;
16705 end if;
16707 -- Else test for match
16709 if Chars (Form) = Chars (Selector_Name (P)) then
16710 return Ekind (Form) /= E_In_Parameter;
16711 end if;
16713 Next_Formal (Form);
16714 end loop;
16715 end;
16717 -- Test for appearing in a conversion that itself appears
16718 -- in an lvalue context, since this should be an lvalue.
16720 when N_Type_Conversion =>
16721 return Known_To_Be_Assigned (P);
16723 -- All other references are definitely not known to be modifications
16725 when others =>
16726 return False;
16727 end case;
16728 end Known_To_Be_Assigned;
16730 ---------------------------
16731 -- Last_Source_Statement --
16732 ---------------------------
16734 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
16735 N : Node_Id;
16737 begin
16738 N := Last (Statements (HSS));
16739 while Present (N) loop
16740 exit when Comes_From_Source (N);
16741 Prev (N);
16742 end loop;
16744 return N;
16745 end Last_Source_Statement;
16747 ----------------------------------
16748 -- Matching_Static_Array_Bounds --
16749 ----------------------------------
16751 function Matching_Static_Array_Bounds
16752 (L_Typ : Node_Id;
16753 R_Typ : Node_Id) return Boolean
16755 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
16756 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
16758 L_Index : Node_Id;
16759 R_Index : Node_Id;
16760 L_Low : Node_Id;
16761 L_High : Node_Id;
16762 L_Len : Uint;
16763 R_Low : Node_Id;
16764 R_High : Node_Id;
16765 R_Len : Uint;
16767 begin
16768 if L_Ndims /= R_Ndims then
16769 return False;
16770 end if;
16772 -- Unconstrained types do not have static bounds
16774 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
16775 return False;
16776 end if;
16778 -- First treat specially the first dimension, as the lower bound and
16779 -- length of string literals are not stored like those of arrays.
16781 if Ekind (L_Typ) = E_String_Literal_Subtype then
16782 L_Low := String_Literal_Low_Bound (L_Typ);
16783 L_Len := String_Literal_Length (L_Typ);
16784 else
16785 L_Index := First_Index (L_Typ);
16786 Get_Index_Bounds (L_Index, L_Low, L_High);
16788 if Is_OK_Static_Expression (L_Low)
16789 and then
16790 Is_OK_Static_Expression (L_High)
16791 then
16792 if Expr_Value (L_High) < Expr_Value (L_Low) then
16793 L_Len := Uint_0;
16794 else
16795 L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
16796 end if;
16797 else
16798 return False;
16799 end if;
16800 end if;
16802 if Ekind (R_Typ) = E_String_Literal_Subtype then
16803 R_Low := String_Literal_Low_Bound (R_Typ);
16804 R_Len := String_Literal_Length (R_Typ);
16805 else
16806 R_Index := First_Index (R_Typ);
16807 Get_Index_Bounds (R_Index, R_Low, R_High);
16809 if Is_OK_Static_Expression (R_Low)
16810 and then
16811 Is_OK_Static_Expression (R_High)
16812 then
16813 if Expr_Value (R_High) < Expr_Value (R_Low) then
16814 R_Len := Uint_0;
16815 else
16816 R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
16817 end if;
16818 else
16819 return False;
16820 end if;
16821 end if;
16823 if (Is_OK_Static_Expression (L_Low)
16824 and then
16825 Is_OK_Static_Expression (R_Low))
16826 and then Expr_Value (L_Low) = Expr_Value (R_Low)
16827 and then L_Len = R_Len
16828 then
16829 null;
16830 else
16831 return False;
16832 end if;
16834 -- Then treat all other dimensions
16836 for Indx in 2 .. L_Ndims loop
16837 Next (L_Index);
16838 Next (R_Index);
16840 Get_Index_Bounds (L_Index, L_Low, L_High);
16841 Get_Index_Bounds (R_Index, R_Low, R_High);
16843 if (Is_OK_Static_Expression (L_Low) and then
16844 Is_OK_Static_Expression (L_High) and then
16845 Is_OK_Static_Expression (R_Low) and then
16846 Is_OK_Static_Expression (R_High))
16847 and then (Expr_Value (L_Low) = Expr_Value (R_Low)
16848 and then
16849 Expr_Value (L_High) = Expr_Value (R_High))
16850 then
16851 null;
16852 else
16853 return False;
16854 end if;
16855 end loop;
16857 -- If we fall through the loop, all indexes matched
16859 return True;
16860 end Matching_Static_Array_Bounds;
16862 -------------------
16863 -- May_Be_Lvalue --
16864 -------------------
16866 function May_Be_Lvalue (N : Node_Id) return Boolean is
16867 P : constant Node_Id := Parent (N);
16869 begin
16870 case Nkind (P) is
16872 -- Test left side of assignment
16874 when N_Assignment_Statement =>
16875 return N = Name (P);
16877 -- Test prefix of component or attribute. Note that the prefix of an
16878 -- explicit or implicit dereference cannot be an l-value. In the case
16879 -- of a 'Read attribute, the reference can be an actual in the
16880 -- argument list of the attribute.
16882 when N_Attribute_Reference =>
16883 return (N = Prefix (P)
16884 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P)))
16885 or else
16886 Attribute_Name (P) = Name_Read;
16888 -- For an expanded name, the name is an lvalue if the expanded name
16889 -- is an lvalue, but the prefix is never an lvalue, since it is just
16890 -- the scope where the name is found.
16892 when N_Expanded_Name =>
16893 if N = Prefix (P) then
16894 return May_Be_Lvalue (P);
16895 else
16896 return False;
16897 end if;
16899 -- For a selected component A.B, A is certainly an lvalue if A.B is.
16900 -- B is a little interesting, if we have A.B := 3, there is some
16901 -- discussion as to whether B is an lvalue or not, we choose to say
16902 -- it is. Note however that A is not an lvalue if it is of an access
16903 -- type since this is an implicit dereference.
16905 when N_Selected_Component =>
16906 if N = Prefix (P)
16907 and then Present (Etype (N))
16908 and then Is_Access_Type (Etype (N))
16909 then
16910 return False;
16911 else
16912 return May_Be_Lvalue (P);
16913 end if;
16915 -- For an indexed component or slice, the index or slice bounds is
16916 -- never an lvalue. The prefix is an lvalue if the indexed component
16917 -- or slice is an lvalue, except if it is an access type, where we
16918 -- have an implicit dereference.
16920 when N_Indexed_Component
16921 | N_Slice
16923 if N /= Prefix (P)
16924 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
16925 then
16926 return False;
16927 else
16928 return May_Be_Lvalue (P);
16929 end if;
16931 -- Prefix of a reference is an lvalue if the reference is an lvalue
16933 when N_Reference =>
16934 return May_Be_Lvalue (P);
16936 -- Prefix of explicit dereference is never an lvalue
16938 when N_Explicit_Dereference =>
16939 return False;
16941 -- Positional parameter for subprogram, entry, or accept call.
16942 -- In older versions of Ada function call arguments are never
16943 -- lvalues. In Ada 2012 functions can have in-out parameters.
16945 when N_Accept_Statement
16946 | N_Entry_Call_Statement
16947 | N_Subprogram_Call
16949 if Nkind (P) = N_Function_Call and then Ada_Version < Ada_2012 then
16950 return False;
16951 end if;
16953 -- The following mechanism is clumsy and fragile. A single flag
16954 -- set in Resolve_Actuals would be preferable ???
16956 declare
16957 Proc : Entity_Id;
16958 Form : Entity_Id;
16959 Act : Node_Id;
16961 begin
16962 Proc := Get_Subprogram_Entity (P);
16964 if No (Proc) then
16965 return True;
16966 end if;
16968 -- If we are not a list member, something is strange, so be
16969 -- conservative and return True.
16971 if not Is_List_Member (N) then
16972 return True;
16973 end if;
16975 -- We are going to find the right formal by stepping forward
16976 -- through the formals, as we step backwards in the actuals.
16978 Form := First_Formal (Proc);
16979 Act := N;
16980 loop
16981 -- If no formal, something is weird, so be conservative and
16982 -- return True.
16984 if No (Form) then
16985 return True;
16986 end if;
16988 Prev (Act);
16989 exit when No (Act);
16990 Next_Formal (Form);
16991 end loop;
16993 return Ekind (Form) /= E_In_Parameter;
16994 end;
16996 -- Named parameter for procedure or accept call
16998 when N_Parameter_Association =>
16999 declare
17000 Proc : Entity_Id;
17001 Form : Entity_Id;
17003 begin
17004 Proc := Get_Subprogram_Entity (Parent (P));
17006 if No (Proc) then
17007 return True;
17008 end if;
17010 -- Loop through formals to find the one that matches
17012 Form := First_Formal (Proc);
17013 loop
17014 -- If no matching formal, that's peculiar, some kind of
17015 -- previous error, so return True to be conservative.
17016 -- Actually happens with legal code for an unresolved call
17017 -- where we may get the wrong homonym???
17019 if No (Form) then
17020 return True;
17021 end if;
17023 -- Else test for match
17025 if Chars (Form) = Chars (Selector_Name (P)) then
17026 return Ekind (Form) /= E_In_Parameter;
17027 end if;
17029 Next_Formal (Form);
17030 end loop;
17031 end;
17033 -- Test for appearing in a conversion that itself appears in an
17034 -- lvalue context, since this should be an lvalue.
17036 when N_Type_Conversion =>
17037 return May_Be_Lvalue (P);
17039 -- Test for appearance in object renaming declaration
17041 when N_Object_Renaming_Declaration =>
17042 return True;
17044 -- All other references are definitely not lvalues
17046 when others =>
17047 return False;
17048 end case;
17049 end May_Be_Lvalue;
17051 -----------------------
17052 -- Mark_Coextensions --
17053 -----------------------
17055 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
17056 Is_Dynamic : Boolean;
17057 -- Indicates whether the context causes nested coextensions to be
17058 -- dynamic or static
17060 function Mark_Allocator (N : Node_Id) return Traverse_Result;
17061 -- Recognize an allocator node and label it as a dynamic coextension
17063 --------------------
17064 -- Mark_Allocator --
17065 --------------------
17067 function Mark_Allocator (N : Node_Id) return Traverse_Result is
17068 begin
17069 if Nkind (N) = N_Allocator then
17070 if Is_Dynamic then
17071 Set_Is_Dynamic_Coextension (N);
17073 -- If the allocator expression is potentially dynamic, it may
17074 -- be expanded out of order and require dynamic allocation
17075 -- anyway, so we treat the coextension itself as dynamic.
17076 -- Potential optimization ???
17078 elsif Nkind (Expression (N)) = N_Qualified_Expression
17079 and then Nkind (Expression (Expression (N))) = N_Op_Concat
17080 then
17081 Set_Is_Dynamic_Coextension (N);
17082 else
17083 Set_Is_Static_Coextension (N);
17084 end if;
17085 end if;
17087 return OK;
17088 end Mark_Allocator;
17090 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
17092 -- Start of processing for Mark_Coextensions
17094 begin
17095 -- An allocator that appears on the right-hand side of an assignment is
17096 -- treated as a potentially dynamic coextension when the right-hand side
17097 -- is an allocator or a qualified expression.
17099 -- Obj := new ...'(new Coextension ...);
17101 if Nkind (Context_Nod) = N_Assignment_Statement then
17102 Is_Dynamic :=
17103 Nkind_In (Expression (Context_Nod), N_Allocator,
17104 N_Qualified_Expression);
17106 -- An allocator that appears within the expression of a simple return
17107 -- statement is treated as a potentially dynamic coextension when the
17108 -- expression is either aggregate, allocator, or qualified expression.
17110 -- return (new Coextension ...);
17111 -- return new ...'(new Coextension ...);
17113 elsif Nkind (Context_Nod) = N_Simple_Return_Statement then
17114 Is_Dynamic :=
17115 Nkind_In (Expression (Context_Nod), N_Aggregate,
17116 N_Allocator,
17117 N_Qualified_Expression);
17119 -- An allocator that appears within the initialization expression of an
17120 -- object declaration is considered a potentially dynamic coextension
17121 -- when the initialization expression is an allocator or a qualified
17122 -- expression.
17124 -- Obj : ... := new ...'(new Coextension ...);
17126 -- A similar case arises when the object declaration is part of an
17127 -- extended return statement.
17129 -- return Obj : ... := new ...'(new Coextension ...);
17130 -- return Obj : ... := (new Coextension ...);
17132 elsif Nkind (Context_Nod) = N_Object_Declaration then
17133 Is_Dynamic :=
17134 Nkind_In (Root_Nod, N_Allocator, N_Qualified_Expression)
17135 or else
17136 Nkind (Parent (Context_Nod)) = N_Extended_Return_Statement;
17138 -- This routine should not be called with constructs that cannot contain
17139 -- coextensions.
17141 else
17142 raise Program_Error;
17143 end if;
17145 Mark_Allocators (Root_Nod);
17146 end Mark_Coextensions;
17148 -----------------
17149 -- Might_Raise --
17150 -----------------
17152 function Might_Raise (N : Node_Id) return Boolean is
17153 Result : Boolean := False;
17155 function Process (N : Node_Id) return Traverse_Result;
17156 -- Set Result to True if we find something that could raise an exception
17158 -------------
17159 -- Process --
17160 -------------
17162 function Process (N : Node_Id) return Traverse_Result is
17163 begin
17164 if Nkind_In (N, N_Procedure_Call_Statement,
17165 N_Function_Call,
17166 N_Raise_Statement,
17167 N_Raise_Constraint_Error,
17168 N_Raise_Program_Error,
17169 N_Raise_Storage_Error)
17170 then
17171 Result := True;
17172 return Abandon;
17173 else
17174 return OK;
17175 end if;
17176 end Process;
17178 procedure Set_Result is new Traverse_Proc (Process);
17180 -- Start of processing for Might_Raise
17182 begin
17183 -- False if exceptions can't be propagated
17185 if No_Exception_Handlers_Set then
17186 return False;
17187 end if;
17189 -- If the checks handled by the back end are not disabled, we cannot
17190 -- ensure that no exception will be raised.
17192 if not Access_Checks_Suppressed (Empty)
17193 or else not Discriminant_Checks_Suppressed (Empty)
17194 or else not Range_Checks_Suppressed (Empty)
17195 or else not Index_Checks_Suppressed (Empty)
17196 or else Opt.Stack_Checking_Enabled
17197 then
17198 return True;
17199 end if;
17201 Set_Result (N);
17202 return Result;
17203 end Might_Raise;
17205 --------------------------------
17206 -- Nearest_Enclosing_Instance --
17207 --------------------------------
17209 function Nearest_Enclosing_Instance (E : Entity_Id) return Entity_Id is
17210 Inst : Entity_Id;
17212 begin
17213 Inst := Scope (E);
17214 while Present (Inst) and then Inst /= Standard_Standard loop
17215 if Is_Generic_Instance (Inst) then
17216 return Inst;
17217 end if;
17219 Inst := Scope (Inst);
17220 end loop;
17222 return Empty;
17223 end Nearest_Enclosing_Instance;
17225 ----------------------
17226 -- Needs_One_Actual --
17227 ----------------------
17229 function Needs_One_Actual (E : Entity_Id) return Boolean is
17230 Formal : Entity_Id;
17232 begin
17233 -- Ada 2005 or later, and formals present. The first formal must be
17234 -- of a type that supports prefix notation: a controlling argument,
17235 -- a class-wide type, or an access to such.
17237 if Ada_Version >= Ada_2005
17238 and then Present (First_Formal (E))
17239 and then No (Default_Value (First_Formal (E)))
17240 and then
17241 (Is_Controlling_Formal (First_Formal (E))
17242 or else Is_Class_Wide_Type (Etype (First_Formal (E)))
17243 or else Is_Anonymous_Access_Type (Etype (First_Formal (E))))
17244 then
17245 Formal := Next_Formal (First_Formal (E));
17246 while Present (Formal) loop
17247 if No (Default_Value (Formal)) then
17248 return False;
17249 end if;
17251 Next_Formal (Formal);
17252 end loop;
17254 return True;
17256 -- Ada 83/95 or no formals
17258 else
17259 return False;
17260 end if;
17261 end Needs_One_Actual;
17263 ------------------------
17264 -- New_Copy_List_Tree --
17265 ------------------------
17267 function New_Copy_List_Tree (List : List_Id) return List_Id is
17268 NL : List_Id;
17269 E : Node_Id;
17271 begin
17272 if List = No_List then
17273 return No_List;
17275 else
17276 NL := New_List;
17277 E := First (List);
17279 while Present (E) loop
17280 Append (New_Copy_Tree (E), NL);
17281 E := Next (E);
17282 end loop;
17284 return NL;
17285 end if;
17286 end New_Copy_List_Tree;
17288 -------------------
17289 -- New_Copy_Tree --
17290 -------------------
17292 -- The following tables play a key role in replicating entities and Itypes.
17293 -- They are intentionally declared at the library level rather than within
17294 -- New_Copy_Tree to avoid elaborating them on each call. This performance
17295 -- optimization saves up to 2% of the entire compilation time spent in the
17296 -- front end. Care should be taken to reset the tables on each new call to
17297 -- New_Copy_Tree.
17299 NCT_Table_Max : constant := 511;
17301 subtype NCT_Table_Index is Nat range 0 .. NCT_Table_Max - 1;
17303 function NCT_Table_Hash (Key : Node_Or_Entity_Id) return NCT_Table_Index;
17304 -- Obtain the hash value of node or entity Key
17306 NCT_Tables_In_Use : Boolean := False;
17307 -- This flag keeps track of whether the two tables NCT_New_Entities and
17308 -- NCT_Pending_Itypes are in use. The flag is part of an optimization
17309 -- where certain operations are not performed if the tables are not in
17310 -- use. This saves up to 8% of the entire compilation time spent in the
17311 -- front end.
17313 --------------------
17314 -- NCT_Table_Hash --
17315 --------------------
17317 function NCT_Table_Hash (Key : Node_Or_Entity_Id) return NCT_Table_Index is
17318 begin
17319 return NCT_Table_Index (Key mod NCT_Table_Max);
17320 end NCT_Table_Hash;
17322 ----------------------
17323 -- NCT_New_Entities --
17324 ----------------------
17326 -- The following table maps old entities and Itypes to their corresponding
17327 -- new entities and Itypes.
17329 -- Aaa -> Xxx
17331 package NCT_New_Entities is new Simple_HTable (
17332 Header_Num => NCT_Table_Index,
17333 Element => Entity_Id,
17334 No_Element => Empty,
17335 Key => Entity_Id,
17336 Hash => NCT_Table_Hash,
17337 Equal => "=");
17339 ------------------------
17340 -- NCT_Pending_Itypes --
17341 ------------------------
17343 -- The following table maps old Associated_Node_For_Itype nodes to a set of
17344 -- new itypes. Given a set of old Itypes Aaa, Bbb, and Ccc, where all three
17345 -- have the same Associated_Node_For_Itype Ppp, and their corresponding new
17346 -- Itypes Xxx, Yyy, Zzz, the table contains the following mapping:
17348 -- Ppp -> (Xxx, Yyy, Zzz)
17350 -- The set is expressed as an Elist
17352 package NCT_Pending_Itypes is new Simple_HTable (
17353 Header_Num => NCT_Table_Index,
17354 Element => Elist_Id,
17355 No_Element => No_Elist,
17356 Key => Node_Id,
17357 Hash => NCT_Table_Hash,
17358 Equal => "=");
17360 -------------------
17361 -- New_Copy_Tree --
17362 -------------------
17364 function New_Copy_Tree
17365 (Source : Node_Id;
17366 Map : Elist_Id := No_Elist;
17367 New_Sloc : Source_Ptr := No_Location;
17368 New_Scope : Entity_Id := Empty) return Node_Id
17370 -- This routine performs low-level tree manipulations and needs access
17371 -- to the internals of the tree.
17373 use Atree.Unchecked_Access;
17374 use Atree_Private_Part;
17376 EWA_Level : Nat := 0;
17377 -- This counter keeps track of how many N_Expression_With_Actions nodes
17378 -- are encountered during a depth-first traversal of the subtree. These
17379 -- nodes may define new entities in their Actions lists and thus require
17380 -- special processing.
17382 EWA_Inner_Scope_Level : Nat := 0;
17383 -- This counter keeps track of how many scoping constructs appear within
17384 -- an N_Expression_With_Actions node.
17386 procedure Add_New_Entity (Old_Id : Entity_Id; New_Id : Entity_Id);
17387 pragma Inline (Add_New_Entity);
17388 -- Add an entry in the NCT_New_Entities table which maps key Old_Id to
17389 -- value New_Id. Old_Id is an entity which appears within the Actions
17390 -- list of an N_Expression_With_Actions node, or within an entity map.
17391 -- New_Id is the corresponding new entity generated during Phase 1.
17393 procedure Add_Pending_Itype (Assoc_Nod : Node_Id; Itype : Entity_Id);
17394 pragma Inline (Add_New_Entity);
17395 -- Add an entry in the NCT_Pending_Itypes which maps key Assoc_Nod to
17396 -- value Itype. Assoc_Nod is the associated node of an itype. Itype is
17397 -- an itype.
17399 procedure Build_NCT_Tables (Entity_Map : Elist_Id);
17400 pragma Inline (Build_NCT_Tables);
17401 -- Populate tables NCT_New_Entities and NCT_Pending_Itypes with the
17402 -- information supplied in entity map Entity_Map. The format of the
17403 -- entity map must be as follows:
17405 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
17407 function Copy_Any_Node_With_Replacement
17408 (N : Node_Or_Entity_Id) return Node_Or_Entity_Id;
17409 pragma Inline (Copy_Any_Node_With_Replacement);
17410 -- Replicate entity or node N by invoking one of the following routines:
17412 -- Copy_Node_With_Replacement
17413 -- Corresponding_Entity
17415 function Copy_Elist_With_Replacement (List : Elist_Id) return Elist_Id;
17416 -- Replicate the elements of entity list List
17418 function Copy_Field_With_Replacement
17419 (Field : Union_Id;
17420 Old_Par : Node_Id := Empty;
17421 New_Par : Node_Id := Empty;
17422 Semantic : Boolean := False) return Union_Id;
17423 -- Replicate field Field by invoking one of the following routines:
17425 -- Copy_Elist_With_Replacement
17426 -- Copy_List_With_Replacement
17427 -- Copy_Node_With_Replacement
17428 -- Corresponding_Entity
17430 -- If the field is not an entity list, entity, itype, syntactic list,
17431 -- or node, then the field is returned unchanged. The routine always
17432 -- replicates entities, itypes, and valid syntactic fields. Old_Par is
17433 -- the expected parent of a syntactic field. New_Par is the new parent
17434 -- associated with a replicated syntactic field. Flag Semantic should
17435 -- be set when the input is a semantic field.
17437 function Copy_List_With_Replacement (List : List_Id) return List_Id;
17438 -- Replicate the elements of syntactic list List
17440 function Copy_Node_With_Replacement (N : Node_Id) return Node_Id;
17441 -- Replicate node N
17443 function Corresponding_Entity (Id : Entity_Id) return Entity_Id;
17444 pragma Inline (Corresponding_Entity);
17445 -- Return the corresponding new entity of Id generated during Phase 1.
17446 -- If there is no such entity, return Id.
17448 function In_Entity_Map
17449 (Id : Entity_Id;
17450 Entity_Map : Elist_Id) return Boolean;
17451 pragma Inline (In_Entity_Map);
17452 -- Determine whether entity Id is one of the old ids specified in entity
17453 -- map Entity_Map. The format of the entity map must be as follows:
17455 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
17457 procedure Update_CFS_Sloc (N : Node_Or_Entity_Id);
17458 pragma Inline (Update_CFS_Sloc);
17459 -- Update the Comes_From_Source and Sloc attributes of node or entity N
17461 procedure Update_First_Real_Statement
17462 (Old_HSS : Node_Id;
17463 New_HSS : Node_Id);
17464 pragma Inline (Update_First_Real_Statement);
17465 -- Update semantic attribute First_Real_Statement of handled sequence of
17466 -- statements New_HSS based on handled sequence of statements Old_HSS.
17468 procedure Update_Named_Associations
17469 (Old_Call : Node_Id;
17470 New_Call : Node_Id);
17471 pragma Inline (Update_Named_Associations);
17472 -- Update semantic chain First/Next_Named_Association of call New_call
17473 -- based on call Old_Call.
17475 procedure Update_New_Entities (Entity_Map : Elist_Id);
17476 pragma Inline (Update_New_Entities);
17477 -- Update the semantic attributes of all new entities generated during
17478 -- Phase 1 that do not appear in entity map Entity_Map. The format of
17479 -- the entity map must be as follows:
17481 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
17483 procedure Update_Pending_Itypes
17484 (Old_Assoc : Node_Id;
17485 New_Assoc : Node_Id);
17486 pragma Inline (Update_Pending_Itypes);
17487 -- Update semantic attribute Associated_Node_For_Itype to refer to node
17488 -- New_Assoc for all itypes whose associated node is Old_Assoc.
17490 procedure Update_Semantic_Fields (Id : Entity_Id);
17491 pragma Inline (Update_Semantic_Fields);
17492 -- Subsidiary to Update_New_Entities. Update semantic fields of entity
17493 -- or itype Id.
17495 procedure Visit_Any_Node (N : Node_Or_Entity_Id);
17496 pragma Inline (Visit_Any_Node);
17497 -- Visit entity of node N by invoking one of the following routines:
17499 -- Visit_Entity
17500 -- Visit_Itype
17501 -- Visit_Node
17503 procedure Visit_Elist (List : Elist_Id);
17504 -- Visit the elements of entity list List
17506 procedure Visit_Entity (Id : Entity_Id);
17507 -- Visit entity Id. This action may create a new entity of Id and save
17508 -- it in table NCT_New_Entities.
17510 procedure Visit_Field
17511 (Field : Union_Id;
17512 Par_Nod : Node_Id := Empty;
17513 Semantic : Boolean := False);
17514 -- Visit field Field by invoking one of the following routines:
17516 -- Visit_Elist
17517 -- Visit_Entity
17518 -- Visit_Itype
17519 -- Visit_List
17520 -- Visit_Node
17522 -- If the field is not an entity list, entity, itype, syntactic list,
17523 -- or node, then the field is not visited. The routine always visits
17524 -- valid syntactic fields. Par_Nod is the expected parent of the
17525 -- syntactic field. Flag Semantic should be set when the input is a
17526 -- semantic field.
17528 procedure Visit_Itype (Itype : Entity_Id);
17529 -- Visit itype Itype. This action may create a new entity for Itype and
17530 -- save it in table NCT_New_Entities. In addition, the routine may map
17531 -- the associated node of Itype to the new itype in NCT_Pending_Itypes.
17533 procedure Visit_List (List : List_Id);
17534 -- Visit the elements of syntactic list List
17536 procedure Visit_Node (N : Node_Id);
17537 -- Visit node N
17539 procedure Visit_Semantic_Fields (Id : Entity_Id);
17540 pragma Inline (Visit_Semantic_Fields);
17541 -- Subsidiary to Visit_Entity and Visit_Itype. Visit common semantic
17542 -- fields of entity or itype Id.
17544 --------------------
17545 -- Add_New_Entity --
17546 --------------------
17548 procedure Add_New_Entity (Old_Id : Entity_Id; New_Id : Entity_Id) is
17549 begin
17550 pragma Assert (Present (Old_Id));
17551 pragma Assert (Present (New_Id));
17552 pragma Assert (Nkind (Old_Id) in N_Entity);
17553 pragma Assert (Nkind (New_Id) in N_Entity);
17555 NCT_Tables_In_Use := True;
17557 -- Sanity check the NCT_New_Entities table. No previous mapping with
17558 -- key Old_Id should exist.
17560 pragma Assert (No (NCT_New_Entities.Get (Old_Id)));
17562 -- Establish the mapping
17564 -- Old_Id -> New_Id
17566 NCT_New_Entities.Set (Old_Id, New_Id);
17567 end Add_New_Entity;
17569 -----------------------
17570 -- Add_Pending_Itype --
17571 -----------------------
17573 procedure Add_Pending_Itype (Assoc_Nod : Node_Id; Itype : Entity_Id) is
17574 Itypes : Elist_Id;
17576 begin
17577 pragma Assert (Present (Assoc_Nod));
17578 pragma Assert (Present (Itype));
17579 pragma Assert (Nkind (Itype) in N_Entity);
17580 pragma Assert (Is_Itype (Itype));
17582 NCT_Tables_In_Use := True;
17584 -- It is not possible to sanity check the NCT_Pendint_Itypes table
17585 -- directly because a single node may act as the associated node for
17586 -- multiple itypes.
17588 Itypes := NCT_Pending_Itypes.Get (Assoc_Nod);
17590 if No (Itypes) then
17591 Itypes := New_Elmt_List;
17592 NCT_Pending_Itypes.Set (Assoc_Nod, Itypes);
17593 end if;
17595 -- Establish the mapping
17597 -- Assoc_Nod -> (Itype, ...)
17599 -- Avoid inserting the same itype multiple times. This involves a
17600 -- linear search, however the set of itypes with the same associated
17601 -- node is very small.
17603 Append_Unique_Elmt (Itype, Itypes);
17604 end Add_Pending_Itype;
17606 ----------------------
17607 -- Build_NCT_Tables --
17608 ----------------------
17610 procedure Build_NCT_Tables (Entity_Map : Elist_Id) is
17611 Elmt : Elmt_Id;
17612 Old_Id : Entity_Id;
17613 New_Id : Entity_Id;
17615 begin
17616 -- Nothing to do when there is no entity map
17618 if No (Entity_Map) then
17619 return;
17620 end if;
17622 Elmt := First_Elmt (Entity_Map);
17623 while Present (Elmt) loop
17625 -- Extract the (Old_Id, New_Id) pair from the entity map
17627 Old_Id := Node (Elmt);
17628 Next_Elmt (Elmt);
17630 New_Id := Node (Elmt);
17631 Next_Elmt (Elmt);
17633 -- Establish the following mapping within table NCT_New_Entities
17635 -- Old_Id -> New_Id
17637 Add_New_Entity (Old_Id, New_Id);
17639 -- Establish the following mapping within table NCT_Pending_Itypes
17640 -- when the new entity is an itype.
17642 -- Assoc_Nod -> (New_Id, ...)
17644 -- IMPORTANT: the associated node is that of the old itype because
17645 -- the node will be replicated in Phase 2.
17647 if Is_Itype (Old_Id) then
17648 Add_Pending_Itype
17649 (Assoc_Nod => Associated_Node_For_Itype (Old_Id),
17650 Itype => New_Id);
17651 end if;
17652 end loop;
17653 end Build_NCT_Tables;
17655 ------------------------------------
17656 -- Copy_Any_Node_With_Replacement --
17657 ------------------------------------
17659 function Copy_Any_Node_With_Replacement
17660 (N : Node_Or_Entity_Id) return Node_Or_Entity_Id
17662 begin
17663 if Nkind (N) in N_Entity then
17664 return Corresponding_Entity (N);
17665 else
17666 return Copy_Node_With_Replacement (N);
17667 end if;
17668 end Copy_Any_Node_With_Replacement;
17670 ---------------------------------
17671 -- Copy_Elist_With_Replacement --
17672 ---------------------------------
17674 function Copy_Elist_With_Replacement (List : Elist_Id) return Elist_Id is
17675 Elmt : Elmt_Id;
17676 Result : Elist_Id;
17678 begin
17679 -- Copy the contents of the old list. Note that the list itself may
17680 -- be empty, in which case the routine returns a new empty list. This
17681 -- avoids sharing lists between subtrees. The element of an entity
17682 -- list could be an entity or a node, hence the invocation of routine
17683 -- Copy_Any_Node_With_Replacement.
17685 if Present (List) then
17686 Result := New_Elmt_List;
17688 Elmt := First_Elmt (List);
17689 while Present (Elmt) loop
17690 Append_Elmt
17691 (Copy_Any_Node_With_Replacement (Node (Elmt)), Result);
17693 Next_Elmt (Elmt);
17694 end loop;
17696 -- Otherwise the list does not exist
17698 else
17699 Result := No_Elist;
17700 end if;
17702 return Result;
17703 end Copy_Elist_With_Replacement;
17705 ---------------------------------
17706 -- Copy_Field_With_Replacement --
17707 ---------------------------------
17709 function Copy_Field_With_Replacement
17710 (Field : Union_Id;
17711 Old_Par : Node_Id := Empty;
17712 New_Par : Node_Id := Empty;
17713 Semantic : Boolean := False) return Union_Id
17715 begin
17716 -- The field is empty
17718 if Field = Union_Id (Empty) then
17719 return Field;
17721 -- The field is an entity/itype/node
17723 elsif Field in Node_Range then
17724 declare
17725 Old_N : constant Node_Id := Node_Id (Field);
17726 Syntactic : constant Boolean := Parent (Old_N) = Old_Par;
17728 New_N : Node_Id;
17730 begin
17731 -- The field is an entity/itype
17733 if Nkind (Old_N) in N_Entity then
17735 -- An entity/itype is always replicated
17737 New_N := Corresponding_Entity (Old_N);
17739 -- Update the parent pointer when the entity is a syntactic
17740 -- field. Note that itypes do not have parent pointers.
17742 if Syntactic and then New_N /= Old_N then
17743 Set_Parent (New_N, New_Par);
17744 end if;
17746 -- The field is a node
17748 else
17749 -- A node is replicated when it is either a syntactic field
17750 -- or when the caller treats it as a semantic attribute.
17752 if Syntactic or else Semantic then
17753 New_N := Copy_Node_With_Replacement (Old_N);
17755 -- Update the parent pointer when the node is a syntactic
17756 -- field.
17758 if Syntactic and then New_N /= Old_N then
17759 Set_Parent (New_N, New_Par);
17760 end if;
17762 -- Otherwise the node is returned unchanged
17764 else
17765 New_N := Old_N;
17766 end if;
17767 end if;
17769 return Union_Id (New_N);
17770 end;
17772 -- The field is an entity list
17774 elsif Field in Elist_Range then
17775 return Union_Id (Copy_Elist_With_Replacement (Elist_Id (Field)));
17777 -- The field is a syntactic list
17779 elsif Field in List_Range then
17780 declare
17781 Old_List : constant List_Id := List_Id (Field);
17782 Syntactic : constant Boolean := Parent (Old_List) = Old_Par;
17784 New_List : List_Id;
17786 begin
17787 -- A list is replicated when it is either a syntactic field or
17788 -- when the caller treats it as a semantic attribute.
17790 if Syntactic or else Semantic then
17791 New_List := Copy_List_With_Replacement (Old_List);
17793 -- Update the parent pointer when the list is a syntactic
17794 -- field.
17796 if Syntactic and then New_List /= Old_List then
17797 Set_Parent (New_List, New_Par);
17798 end if;
17800 -- Otherwise the list is returned unchanged
17802 else
17803 New_List := Old_List;
17804 end if;
17806 return Union_Id (New_List);
17807 end;
17809 -- Otherwise the field denotes an attribute that does not need to be
17810 -- replicated (Chars, literals, etc).
17812 else
17813 return Field;
17814 end if;
17815 end Copy_Field_With_Replacement;
17817 --------------------------------
17818 -- Copy_List_With_Replacement --
17819 --------------------------------
17821 function Copy_List_With_Replacement (List : List_Id) return List_Id is
17822 Elmt : Node_Id;
17823 Result : List_Id;
17825 begin
17826 -- Copy the contents of the old list. Note that the list itself may
17827 -- be empty, in which case the routine returns a new empty list. This
17828 -- avoids sharing lists between subtrees. The element of a syntactic
17829 -- list is always a node, never an entity or itype, hence the call to
17830 -- routine Copy_Node_With_Replacement.
17832 if Present (List) then
17833 Result := New_List;
17835 Elmt := First (List);
17836 while Present (Elmt) loop
17837 Append (Copy_Node_With_Replacement (Elmt), Result);
17839 Next (Elmt);
17840 end loop;
17842 -- Otherwise the list does not exist
17844 else
17845 Result := No_List;
17846 end if;
17848 return Result;
17849 end Copy_List_With_Replacement;
17851 --------------------------------
17852 -- Copy_Node_With_Replacement --
17853 --------------------------------
17855 function Copy_Node_With_Replacement (N : Node_Id) return Node_Id is
17856 Result : Node_Id;
17858 begin
17859 -- Assume that the node must be returned unchanged
17861 Result := N;
17863 if N > Empty_Or_Error then
17864 pragma Assert (Nkind (N) not in N_Entity);
17866 Result := New_Copy (N);
17868 Set_Field1 (Result,
17869 Copy_Field_With_Replacement
17870 (Field => Field1 (Result),
17871 Old_Par => N,
17872 New_Par => Result));
17874 Set_Field2 (Result,
17875 Copy_Field_With_Replacement
17876 (Field => Field2 (Result),
17877 Old_Par => N,
17878 New_Par => Result));
17880 Set_Field3 (Result,
17881 Copy_Field_With_Replacement
17882 (Field => Field3 (Result),
17883 Old_Par => N,
17884 New_Par => Result));
17886 Set_Field4 (Result,
17887 Copy_Field_With_Replacement
17888 (Field => Field4 (Result),
17889 Old_Par => N,
17890 New_Par => Result));
17892 Set_Field5 (Result,
17893 Copy_Field_With_Replacement
17894 (Field => Field5 (Result),
17895 Old_Par => N,
17896 New_Par => Result));
17898 -- Update the Comes_From_Source and Sloc attributes of the node
17899 -- in case the caller has supplied new values.
17901 Update_CFS_Sloc (Result);
17903 -- Update the Associated_Node_For_Itype attribute of all itypes
17904 -- created during Phase 1 whose associated node is N. As a result
17905 -- the Associated_Node_For_Itype refers to the replicated node.
17906 -- No action needs to be taken when the Associated_Node_For_Itype
17907 -- refers to an entity because this was already handled during
17908 -- Phase 1, in Visit_Itype.
17910 Update_Pending_Itypes
17911 (Old_Assoc => N,
17912 New_Assoc => Result);
17914 -- Update the First/Next_Named_Association chain for a replicated
17915 -- call.
17917 if Nkind_In (N, N_Entry_Call_Statement,
17918 N_Function_Call,
17919 N_Procedure_Call_Statement)
17920 then
17921 Update_Named_Associations
17922 (Old_Call => N,
17923 New_Call => Result);
17925 -- Update the Renamed_Object attribute of a replicated object
17926 -- declaration.
17928 elsif Nkind (N) = N_Object_Renaming_Declaration then
17929 Set_Renamed_Object (Defining_Entity (Result), Name (Result));
17931 -- Update the First_Real_Statement attribute of a replicated
17932 -- handled sequence of statements.
17934 elsif Nkind (N) = N_Handled_Sequence_Of_Statements then
17935 Update_First_Real_Statement
17936 (Old_HSS => N,
17937 New_HSS => Result);
17938 end if;
17939 end if;
17941 return Result;
17942 end Copy_Node_With_Replacement;
17944 --------------------------
17945 -- Corresponding_Entity --
17946 --------------------------
17948 function Corresponding_Entity (Id : Entity_Id) return Entity_Id is
17949 New_Id : Entity_Id;
17950 Result : Entity_Id;
17952 begin
17953 -- Assume that the entity must be returned unchanged
17955 Result := Id;
17957 if Id > Empty_Or_Error then
17958 pragma Assert (Nkind (Id) in N_Entity);
17960 -- Determine whether the entity has a corresponding new entity
17961 -- generated during Phase 1 and if it does, use it.
17963 if NCT_Tables_In_Use then
17964 New_Id := NCT_New_Entities.Get (Id);
17966 if Present (New_Id) then
17967 Result := New_Id;
17968 end if;
17969 end if;
17970 end if;
17972 return Result;
17973 end Corresponding_Entity;
17975 -------------------
17976 -- In_Entity_Map --
17977 -------------------
17979 function In_Entity_Map
17980 (Id : Entity_Id;
17981 Entity_Map : Elist_Id) return Boolean
17983 Elmt : Elmt_Id;
17984 Old_Id : Entity_Id;
17986 begin
17987 -- The entity map contains pairs (Old_Id, New_Id). The advancement
17988 -- step always skips the New_Id portion of the pair.
17990 if Present (Entity_Map) then
17991 Elmt := First_Elmt (Entity_Map);
17992 while Present (Elmt) loop
17993 Old_Id := Node (Elmt);
17995 if Old_Id = Id then
17996 return True;
17997 end if;
17999 Next_Elmt (Elmt);
18000 Next_Elmt (Elmt);
18001 end loop;
18002 end if;
18004 return False;
18005 end In_Entity_Map;
18007 ---------------------
18008 -- Update_CFS_Sloc --
18009 ---------------------
18011 procedure Update_CFS_Sloc (N : Node_Or_Entity_Id) is
18012 begin
18013 -- A new source location defaults the Comes_From_Source attribute
18015 if New_Sloc /= No_Location then
18016 Set_Comes_From_Source (N, Default_Node.Comes_From_Source);
18017 Set_Sloc (N, New_Sloc);
18018 end if;
18019 end Update_CFS_Sloc;
18021 ---------------------------------
18022 -- Update_First_Real_Statement --
18023 ---------------------------------
18025 procedure Update_First_Real_Statement
18026 (Old_HSS : Node_Id;
18027 New_HSS : Node_Id)
18029 Old_First_Stmt : constant Node_Id := First_Real_Statement (Old_HSS);
18031 New_Stmt : Node_Id;
18032 Old_Stmt : Node_Id;
18034 begin
18035 -- Recreate the First_Real_Statement attribute of a handled sequence
18036 -- of statements by traversing the statement lists of both sequences
18037 -- in parallel.
18039 if Present (Old_First_Stmt) then
18040 New_Stmt := First (Statements (New_HSS));
18041 Old_Stmt := First (Statements (Old_HSS));
18042 while Present (Old_Stmt) and then Old_Stmt /= Old_First_Stmt loop
18043 Next (New_Stmt);
18044 Next (Old_Stmt);
18045 end loop;
18047 pragma Assert (Present (New_Stmt));
18048 pragma Assert (Present (Old_Stmt));
18050 Set_First_Real_Statement (New_HSS, New_Stmt);
18051 end if;
18052 end Update_First_Real_Statement;
18054 -------------------------------
18055 -- Update_Named_Associations --
18056 -------------------------------
18058 procedure Update_Named_Associations
18059 (Old_Call : Node_Id;
18060 New_Call : Node_Id)
18062 New_Act : Node_Id;
18063 New_Next : Node_Id;
18064 Old_Act : Node_Id;
18065 Old_Next : Node_Id;
18067 begin
18068 -- Recreate the First/Next_Named_Actual chain of a call by traversing
18069 -- the chains of both the old and new calls in parallel.
18071 New_Act := First (Parameter_Associations (New_Call));
18072 Old_Act := First (Parameter_Associations (Old_Call));
18073 while Present (Old_Act) loop
18074 if Nkind (Old_Act) = N_Parameter_Association
18075 and then Present (Next_Named_Actual (Old_Act))
18076 then
18077 if First_Named_Actual (Old_Call) =
18078 Explicit_Actual_Parameter (Old_Act)
18079 then
18080 Set_First_Named_Actual (New_Call,
18081 Explicit_Actual_Parameter (New_Act));
18082 end if;
18084 -- Scan the actual parameter list to find the next suitable
18085 -- named actual. Note that the list may be out of order.
18087 New_Next := First (Parameter_Associations (New_Call));
18088 Old_Next := First (Parameter_Associations (Old_Call));
18089 while Nkind (Old_Next) /= N_Parameter_Association
18090 or else Explicit_Actual_Parameter (Old_Next) /=
18091 Next_Named_Actual (Old_Act)
18092 loop
18093 Next (New_Next);
18094 Next (Old_Next);
18095 end loop;
18097 Set_Next_Named_Actual (New_Act,
18098 Explicit_Actual_Parameter (New_Next));
18099 end if;
18101 Next (New_Act);
18102 Next (Old_Act);
18103 end loop;
18104 end Update_Named_Associations;
18106 -------------------------
18107 -- Update_New_Entities --
18108 -------------------------
18110 procedure Update_New_Entities (Entity_Map : Elist_Id) is
18111 New_Id : Entity_Id := Empty;
18112 Old_Id : Entity_Id := Empty;
18114 begin
18115 if NCT_Tables_In_Use then
18116 NCT_New_Entities.Get_First (Old_Id, New_Id);
18118 -- Update the semantic fields of all new entities created during
18119 -- Phase 1 which were not supplied via an entity map.
18120 -- ??? Is there a better way of distinguishing those?
18122 while Present (Old_Id) and then Present (New_Id) loop
18123 if not (Present (Entity_Map)
18124 and then In_Entity_Map (Old_Id, Entity_Map))
18125 then
18126 Update_Semantic_Fields (New_Id);
18127 end if;
18129 NCT_New_Entities.Get_Next (Old_Id, New_Id);
18130 end loop;
18131 end if;
18132 end Update_New_Entities;
18134 ---------------------------
18135 -- Update_Pending_Itypes --
18136 ---------------------------
18138 procedure Update_Pending_Itypes
18139 (Old_Assoc : Node_Id;
18140 New_Assoc : Node_Id)
18142 Item : Elmt_Id;
18143 Itypes : Elist_Id;
18145 begin
18146 if NCT_Tables_In_Use then
18147 Itypes := NCT_Pending_Itypes.Get (Old_Assoc);
18149 -- Update the Associated_Node_For_Itype attribute for all itypes
18150 -- which originally refer to Old_Assoc to designate New_Assoc.
18152 if Present (Itypes) then
18153 Item := First_Elmt (Itypes);
18154 while Present (Item) loop
18155 Set_Associated_Node_For_Itype (Node (Item), New_Assoc);
18157 Next_Elmt (Item);
18158 end loop;
18159 end if;
18160 end if;
18161 end Update_Pending_Itypes;
18163 ----------------------------
18164 -- Update_Semantic_Fields --
18165 ----------------------------
18167 procedure Update_Semantic_Fields (Id : Entity_Id) is
18168 begin
18169 -- Discriminant_Constraint
18171 if Has_Discriminants (Base_Type (Id)) then
18172 Set_Discriminant_Constraint (Id, Elist_Id (
18173 Copy_Field_With_Replacement
18174 (Field => Union_Id (Discriminant_Constraint (Id)),
18175 Semantic => True)));
18176 end if;
18178 -- Etype
18180 Set_Etype (Id, Node_Id (
18181 Copy_Field_With_Replacement
18182 (Field => Union_Id (Etype (Id)),
18183 Semantic => True)));
18185 -- First_Index
18186 -- Packed_Array_Impl_Type
18188 if Is_Array_Type (Id) then
18189 if Present (First_Index (Id)) then
18190 Set_First_Index (Id, First (List_Id (
18191 Copy_Field_With_Replacement
18192 (Field => Union_Id (List_Containing (First_Index (Id))),
18193 Semantic => True))));
18194 end if;
18196 if Is_Packed (Id) then
18197 Set_Packed_Array_Impl_Type (Id, Node_Id (
18198 Copy_Field_With_Replacement
18199 (Field => Union_Id (Packed_Array_Impl_Type (Id)),
18200 Semantic => True)));
18201 end if;
18202 end if;
18204 -- Next_Entity
18206 Set_Next_Entity (Id, Node_Id (
18207 Copy_Field_With_Replacement
18208 (Field => Union_Id (Next_Entity (Id)),
18209 Semantic => True)));
18211 -- Scalar_Range
18213 if Is_Discrete_Type (Id) then
18214 Set_Scalar_Range (Id, Node_Id (
18215 Copy_Field_With_Replacement
18216 (Field => Union_Id (Scalar_Range (Id)),
18217 Semantic => True)));
18218 end if;
18220 -- Scope
18222 -- Update the scope when the caller specified an explicit one
18224 if Present (New_Scope) then
18225 Set_Scope (Id, New_Scope);
18226 else
18227 Set_Scope (Id, Node_Id (
18228 Copy_Field_With_Replacement
18229 (Field => Union_Id (Scope (Id)),
18230 Semantic => True)));
18231 end if;
18232 end Update_Semantic_Fields;
18234 --------------------
18235 -- Visit_Any_Node --
18236 --------------------
18238 procedure Visit_Any_Node (N : Node_Or_Entity_Id) is
18239 begin
18240 if Nkind (N) in N_Entity then
18241 if Is_Itype (N) then
18242 Visit_Itype (N);
18243 else
18244 Visit_Entity (N);
18245 end if;
18246 else
18247 Visit_Node (N);
18248 end if;
18249 end Visit_Any_Node;
18251 -----------------
18252 -- Visit_Elist --
18253 -----------------
18255 procedure Visit_Elist (List : Elist_Id) is
18256 Elmt : Elmt_Id;
18258 begin
18259 -- The element of an entity list could be an entity, itype, or a
18260 -- node, hence the call to Visit_Any_Node.
18262 if Present (List) then
18263 Elmt := First_Elmt (List);
18264 while Present (Elmt) loop
18265 Visit_Any_Node (Node (Elmt));
18267 Next_Elmt (Elmt);
18268 end loop;
18269 end if;
18270 end Visit_Elist;
18272 ------------------
18273 -- Visit_Entity --
18274 ------------------
18276 procedure Visit_Entity (Id : Entity_Id) is
18277 New_Id : Entity_Id;
18279 begin
18280 pragma Assert (Nkind (Id) in N_Entity);
18281 pragma Assert (not Is_Itype (Id));
18283 -- Nothing to do if the entity is not defined in the Actions list of
18284 -- an N_Expression_With_Actions node.
18286 if EWA_Level = 0 then
18287 return;
18289 -- Nothing to do if the entity is defined within a scoping construct
18290 -- of an N_Expression_With_Actions node.
18292 elsif EWA_Inner_Scope_Level > 0 then
18293 return;
18295 -- Nothing to do if the entity is not an object or a type. Relaxing
18296 -- this restriction leads to a performance penalty.
18298 elsif not Ekind_In (Id, E_Constant, E_Variable)
18299 and then not Is_Type (Id)
18300 then
18301 return;
18303 -- Nothing to do if the entity was already visited
18305 elsif NCT_Tables_In_Use
18306 and then Present (NCT_New_Entities.Get (Id))
18307 then
18308 return;
18310 -- Nothing to do if the declaration node of the entity is not within
18311 -- the subtree being replicated.
18313 elsif not In_Subtree
18314 (Root => Source,
18315 N => Declaration_Node (Id))
18316 then
18317 return;
18318 end if;
18320 -- Create a new entity by directly copying the old entity. This
18321 -- action causes all attributes of the old entity to be inherited.
18323 New_Id := New_Copy (Id);
18325 -- Create a new name for the new entity because the back end needs
18326 -- distinct names for debugging purposes.
18328 Set_Chars (New_Id, New_Internal_Name ('T'));
18330 -- Update the Comes_From_Source and Sloc attributes of the entity in
18331 -- case the caller has supplied new values.
18333 Update_CFS_Sloc (New_Id);
18335 -- Establish the following mapping within table NCT_New_Entities:
18337 -- Id -> New_Id
18339 Add_New_Entity (Id, New_Id);
18341 -- Deal with the semantic fields of entities. The fields are visited
18342 -- because they may mention entities which reside within the subtree
18343 -- being copied.
18345 Visit_Semantic_Fields (Id);
18346 end Visit_Entity;
18348 -----------------
18349 -- Visit_Field --
18350 -----------------
18352 procedure Visit_Field
18353 (Field : Union_Id;
18354 Par_Nod : Node_Id := Empty;
18355 Semantic : Boolean := False)
18357 begin
18358 -- The field is empty
18360 if Field = Union_Id (Empty) then
18361 return;
18363 -- The field is an entity/itype/node
18365 elsif Field in Node_Range then
18366 declare
18367 N : constant Node_Id := Node_Id (Field);
18369 begin
18370 -- The field is an entity/itype
18372 if Nkind (N) in N_Entity then
18374 -- Itypes are always visited
18376 if Is_Itype (N) then
18377 Visit_Itype (N);
18379 -- An entity is visited when it is either a syntactic field
18380 -- or when the caller treats it as a semantic attribute.
18382 elsif Parent (N) = Par_Nod or else Semantic then
18383 Visit_Entity (N);
18384 end if;
18386 -- The field is a node
18388 else
18389 -- A node is visited when it is either a syntactic field or
18390 -- when the caller treats it as a semantic attribute.
18392 if Parent (N) = Par_Nod or else Semantic then
18393 Visit_Node (N);
18394 end if;
18395 end if;
18396 end;
18398 -- The field is an entity list
18400 elsif Field in Elist_Range then
18401 Visit_Elist (Elist_Id (Field));
18403 -- The field is a syntax list
18405 elsif Field in List_Range then
18406 declare
18407 List : constant List_Id := List_Id (Field);
18409 begin
18410 -- A syntax list is visited when it is either a syntactic field
18411 -- or when the caller treats it as a semantic attribute.
18413 if Parent (List) = Par_Nod or else Semantic then
18414 Visit_List (List);
18415 end if;
18416 end;
18418 -- Otherwise the field denotes information which does not need to be
18419 -- visited (chars, literals, etc.).
18421 else
18422 null;
18423 end if;
18424 end Visit_Field;
18426 -----------------
18427 -- Visit_Itype --
18428 -----------------
18430 procedure Visit_Itype (Itype : Entity_Id) is
18431 New_Assoc : Node_Id;
18432 New_Itype : Entity_Id;
18433 Old_Assoc : Node_Id;
18435 begin
18436 pragma Assert (Nkind (Itype) in N_Entity);
18437 pragma Assert (Is_Itype (Itype));
18439 -- Itypes that describe the designated type of access to subprograms
18440 -- have the structure of subprogram declarations, with signatures,
18441 -- etc. Either we duplicate the signatures completely, or choose to
18442 -- share such itypes, which is fine because their elaboration will
18443 -- have no side effects.
18445 if Ekind (Itype) = E_Subprogram_Type then
18446 return;
18448 -- Nothing to do if the itype was already visited
18450 elsif NCT_Tables_In_Use
18451 and then Present (NCT_New_Entities.Get (Itype))
18452 then
18453 return;
18455 -- Nothing to do if the associated node of the itype is not within
18456 -- the subtree being replicated.
18458 elsif not In_Subtree
18459 (Root => Source,
18460 N => Associated_Node_For_Itype (Itype))
18461 then
18462 return;
18463 end if;
18465 -- Create a new itype by directly copying the old itype. This action
18466 -- causes all attributes of the old itype to be inherited.
18468 New_Itype := New_Copy (Itype);
18470 -- Create a new name for the new itype because the back end requires
18471 -- distinct names for debugging purposes.
18473 Set_Chars (New_Itype, New_Internal_Name ('T'));
18475 -- Update the Comes_From_Source and Sloc attributes of the itype in
18476 -- case the caller has supplied new values.
18478 Update_CFS_Sloc (New_Itype);
18480 -- Establish the following mapping within table NCT_New_Entities:
18482 -- Itype -> New_Itype
18484 Add_New_Entity (Itype, New_Itype);
18486 -- The new itype must be unfrozen because the resulting subtree may
18487 -- be inserted anywhere and cause an earlier or later freezing.
18489 if Present (Freeze_Node (New_Itype)) then
18490 Set_Freeze_Node (New_Itype, Empty);
18491 Set_Is_Frozen (New_Itype, False);
18492 end if;
18494 -- If a record subtype is simply copied, the entity list will be
18495 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
18496 -- ??? What does this do?
18498 if Ekind_In (Itype, E_Class_Wide_Subtype, E_Record_Subtype) then
18499 Set_Cloned_Subtype (New_Itype, Itype);
18500 end if;
18502 -- The associated node may denote an entity, in which case it may
18503 -- already have a new corresponding entity created during a prior
18504 -- call to Visit_Entity or Visit_Itype for the same subtree.
18506 -- Given
18507 -- Old_Assoc ---------> New_Assoc
18509 -- Created by Visit_Itype
18510 -- Itype -------------> New_Itype
18511 -- ANFI = Old_Assoc ANFI = Old_Assoc < must be updated
18513 -- In the example above, Old_Assoc is an arbitrary entity that was
18514 -- already visited for the same subtree and has a corresponding new
18515 -- entity New_Assoc. Old_Assoc was inherited by New_Itype by virtue
18516 -- of copying entities, however it must be updated to New_Assoc.
18518 Old_Assoc := Associated_Node_For_Itype (Itype);
18520 if Nkind (Old_Assoc) in N_Entity then
18521 if NCT_Tables_In_Use then
18522 New_Assoc := NCT_New_Entities.Get (Old_Assoc);
18524 if Present (New_Assoc) then
18525 Set_Associated_Node_For_Itype (New_Itype, New_Assoc);
18526 end if;
18527 end if;
18529 -- Otherwise the associated node denotes a node. Postpone the update
18530 -- until Phase 2 when the node is replicated. Establish the following
18531 -- mapping within table NCT_Pending_Itypes:
18533 -- Old_Assoc -> (New_Type, ...)
18535 else
18536 Add_Pending_Itype (Old_Assoc, New_Itype);
18537 end if;
18539 -- Deal with the semantic fields of itypes. The fields are visited
18540 -- because they may mention entities that reside within the subtree
18541 -- being copied.
18543 Visit_Semantic_Fields (Itype);
18544 end Visit_Itype;
18546 ----------------
18547 -- Visit_List --
18548 ----------------
18550 procedure Visit_List (List : List_Id) is
18551 Elmt : Node_Id;
18553 begin
18554 -- Note that the element of a syntactic list is always a node, never
18555 -- an entity or itype, hence the call to Visit_Node.
18557 if Present (List) then
18558 Elmt := First (List);
18559 while Present (Elmt) loop
18560 Visit_Node (Elmt);
18562 Next (Elmt);
18563 end loop;
18564 end if;
18565 end Visit_List;
18567 ----------------
18568 -- Visit_Node --
18569 ----------------
18571 procedure Visit_Node (N : Node_Or_Entity_Id) is
18572 begin
18573 pragma Assert (Nkind (N) not in N_Entity);
18575 if Nkind (N) = N_Expression_With_Actions then
18576 EWA_Level := EWA_Level + 1;
18578 elsif EWA_Level > 0
18579 and then Nkind_In (N, N_Block_Statement,
18580 N_Subprogram_Body,
18581 N_Subprogram_Declaration)
18582 then
18583 EWA_Inner_Scope_Level := EWA_Inner_Scope_Level + 1;
18584 end if;
18586 Visit_Field
18587 (Field => Field1 (N),
18588 Par_Nod => N);
18590 Visit_Field
18591 (Field => Field2 (N),
18592 Par_Nod => N);
18594 Visit_Field
18595 (Field => Field3 (N),
18596 Par_Nod => N);
18598 Visit_Field
18599 (Field => Field4 (N),
18600 Par_Nod => N);
18602 Visit_Field
18603 (Field => Field5 (N),
18604 Par_Nod => N);
18606 if EWA_Level > 0
18607 and then Nkind_In (N, N_Block_Statement,
18608 N_Subprogram_Body,
18609 N_Subprogram_Declaration)
18610 then
18611 EWA_Inner_Scope_Level := EWA_Inner_Scope_Level - 1;
18613 elsif Nkind (N) = N_Expression_With_Actions then
18614 EWA_Level := EWA_Level - 1;
18615 end if;
18616 end Visit_Node;
18618 ---------------------------
18619 -- Visit_Semantic_Fields --
18620 ---------------------------
18622 procedure Visit_Semantic_Fields (Id : Entity_Id) is
18623 begin
18624 pragma Assert (Nkind (Id) in N_Entity);
18626 -- Discriminant_Constraint
18628 if Has_Discriminants (Base_Type (Id)) then
18629 Visit_Field
18630 (Field => Union_Id (Discriminant_Constraint (Id)),
18631 Semantic => True);
18632 end if;
18634 -- Etype
18636 Visit_Field
18637 (Field => Union_Id (Etype (Id)),
18638 Semantic => True);
18640 -- First_Index
18641 -- Packed_Array_Impl_Type
18643 if Is_Array_Type (Id) then
18644 if Present (First_Index (Id)) then
18645 Visit_Field
18646 (Field => Union_Id (List_Containing (First_Index (Id))),
18647 Semantic => True);
18648 end if;
18650 if Is_Packed (Id) then
18651 Visit_Field
18652 (Field => Union_Id (Packed_Array_Impl_Type (Id)),
18653 Semantic => True);
18654 end if;
18655 end if;
18657 -- Scalar_Range
18659 if Is_Discrete_Type (Id) then
18660 Visit_Field
18661 (Field => Union_Id (Scalar_Range (Id)),
18662 Semantic => True);
18663 end if;
18664 end Visit_Semantic_Fields;
18666 -- Start of processing for New_Copy_Tree
18668 begin
18669 -- Routine New_Copy_Tree performs a deep copy of a subtree by creating
18670 -- shallow copies for each node within, and then updating the child and
18671 -- parent pointers accordingly. This process is straightforward, however
18672 -- the routine must deal with the following complications:
18674 -- * Entities defined within N_Expression_With_Actions nodes must be
18675 -- replicated rather than shared to avoid introducing two identical
18676 -- symbols within the same scope. Note that no other expression can
18677 -- currently define entities.
18679 -- do
18680 -- Source_Low : ...;
18681 -- Source_High : ...;
18683 -- <reference to Source_Low>
18684 -- <reference to Source_High>
18685 -- in ... end;
18687 -- New_Copy_Tree handles this case by first creating new entities
18688 -- and then updating all existing references to point to these new
18689 -- entities.
18691 -- do
18692 -- New_Low : ...;
18693 -- New_High : ...;
18695 -- <reference to New_Low>
18696 -- <reference to New_High>
18697 -- in ... end;
18699 -- * Itypes defined within the subtree must be replicated to avoid any
18700 -- dependencies on invalid or inaccessible data.
18702 -- subtype Source_Itype is ... range Source_Low .. Source_High;
18704 -- New_Copy_Tree handles this case by first creating a new itype in
18705 -- the same fashion as entities, and then updating various relevant
18706 -- constraints.
18708 -- subtype New_Itype is ... range New_Low .. New_High;
18710 -- * The Associated_Node_For_Itype field of itypes must be updated to
18711 -- reference the proper replicated entity or node.
18713 -- * Semantic fields of entities such as Etype and Scope must be
18714 -- updated to reference the proper replicated entities.
18716 -- * Semantic fields of nodes such as First_Real_Statement must be
18717 -- updated to reference the proper replicated nodes.
18719 -- To meet all these demands, routine New_Copy_Tree is split into two
18720 -- phases.
18722 -- Phase 1 traverses the tree in order to locate entities and itypes
18723 -- defined within the subtree. New entities are generated and saved in
18724 -- table NCT_New_Entities. The semantic fields of all new entities and
18725 -- itypes are then updated accordingly.
18727 -- Phase 2 traverses the tree in order to replicate each node. Various
18728 -- semantic fields of nodes and entities are updated accordingly.
18730 -- Preparatory phase. Clear the contents of tables NCT_New_Entities and
18731 -- NCT_Pending_Itypes in case a previous call to New_Copy_Tree left some
18732 -- data inside.
18734 if NCT_Tables_In_Use then
18735 NCT_Tables_In_Use := False;
18737 NCT_New_Entities.Reset;
18738 NCT_Pending_Itypes.Reset;
18739 end if;
18741 -- Populate tables NCT_New_Entities and NCT_Pending_Itypes with data
18742 -- supplied by a linear entity map. The tables offer faster access to
18743 -- the same data.
18745 Build_NCT_Tables (Map);
18747 -- Execute Phase 1. Traverse the subtree and generate new entities for
18748 -- the following cases:
18750 -- * An entity defined within an N_Expression_With_Actions node
18752 -- * An itype referenced within the subtree where the associated node
18753 -- is also in the subtree.
18755 -- All new entities are accessible via table NCT_New_Entities, which
18756 -- contains mappings of the form:
18758 -- Old_Entity -> New_Entity
18759 -- Old_Itype -> New_Itype
18761 -- In addition, the associated nodes of all new itypes are mapped in
18762 -- table NCT_Pending_Itypes:
18764 -- Assoc_Nod -> (New_Itype1, New_Itype2, .., New_ItypeN)
18766 Visit_Any_Node (Source);
18768 -- Update the semantic attributes of all new entities generated during
18769 -- Phase 1 before starting Phase 2. The updates could be performed in
18770 -- routine Corresponding_Entity, however this may cause the same entity
18771 -- to be updated multiple times, effectively generating useless nodes.
18772 -- Keeping the updates separates from Phase 2 ensures that only one set
18773 -- of attributes is generated for an entity at any one time.
18775 Update_New_Entities (Map);
18777 -- Execute Phase 2. Replicate the source subtree one node at a time.
18778 -- The following transformations take place:
18780 -- * References to entities and itypes are updated to refer to the
18781 -- new entities and itypes generated during Phase 1.
18783 -- * All Associated_Node_For_Itype attributes of itypes are updated
18784 -- to refer to the new replicated Associated_Node_For_Itype.
18786 return Copy_Node_With_Replacement (Source);
18787 end New_Copy_Tree;
18789 -------------------------
18790 -- New_External_Entity --
18791 -------------------------
18793 function New_External_Entity
18794 (Kind : Entity_Kind;
18795 Scope_Id : Entity_Id;
18796 Sloc_Value : Source_Ptr;
18797 Related_Id : Entity_Id;
18798 Suffix : Character;
18799 Suffix_Index : Nat := 0;
18800 Prefix : Character := ' ') return Entity_Id
18802 N : constant Entity_Id :=
18803 Make_Defining_Identifier (Sloc_Value,
18804 New_External_Name
18805 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
18807 begin
18808 Set_Ekind (N, Kind);
18809 Set_Is_Internal (N, True);
18810 Append_Entity (N, Scope_Id);
18811 Set_Public_Status (N);
18813 if Kind in Type_Kind then
18814 Init_Size_Align (N);
18815 end if;
18817 return N;
18818 end New_External_Entity;
18820 -------------------------
18821 -- New_Internal_Entity --
18822 -------------------------
18824 function New_Internal_Entity
18825 (Kind : Entity_Kind;
18826 Scope_Id : Entity_Id;
18827 Sloc_Value : Source_Ptr;
18828 Id_Char : Character) return Entity_Id
18830 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
18832 begin
18833 Set_Ekind (N, Kind);
18834 Set_Is_Internal (N, True);
18835 Append_Entity (N, Scope_Id);
18837 if Kind in Type_Kind then
18838 Init_Size_Align (N);
18839 end if;
18841 return N;
18842 end New_Internal_Entity;
18844 -----------------
18845 -- Next_Actual --
18846 -----------------
18848 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
18849 N : Node_Id;
18851 begin
18852 -- If we are pointing at a positional parameter, it is a member of a
18853 -- node list (the list of parameters), and the next parameter is the
18854 -- next node on the list, unless we hit a parameter association, then
18855 -- we shift to using the chain whose head is the First_Named_Actual in
18856 -- the parent, and then is threaded using the Next_Named_Actual of the
18857 -- Parameter_Association. All this fiddling is because the original node
18858 -- list is in the textual call order, and what we need is the
18859 -- declaration order.
18861 if Is_List_Member (Actual_Id) then
18862 N := Next (Actual_Id);
18864 if Nkind (N) = N_Parameter_Association then
18865 return First_Named_Actual (Parent (Actual_Id));
18866 else
18867 return N;
18868 end if;
18870 else
18871 return Next_Named_Actual (Parent (Actual_Id));
18872 end if;
18873 end Next_Actual;
18875 procedure Next_Actual (Actual_Id : in out Node_Id) is
18876 begin
18877 Actual_Id := Next_Actual (Actual_Id);
18878 end Next_Actual;
18880 ----------------------------------
18881 -- New_Requires_Transient_Scope --
18882 ----------------------------------
18884 function New_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
18885 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean;
18886 -- This is called for untagged records and protected types, with
18887 -- nondefaulted discriminants. Returns True if the size of function
18888 -- results is known at the call site, False otherwise. Returns False
18889 -- if there is a variant part that depends on the discriminants of
18890 -- this type, or if there is an array constrained by the discriminants
18891 -- of this type. ???Currently, this is overly conservative (the array
18892 -- could be nested inside some other record that is constrained by
18893 -- nondiscriminants). That is, the recursive calls are too conservative.
18895 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean;
18896 -- Returns True if Typ is a nonlimited record with defaulted
18897 -- discriminants whose max size makes it unsuitable for allocating on
18898 -- the primary stack.
18900 ------------------------------
18901 -- Caller_Known_Size_Record --
18902 ------------------------------
18904 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean is
18905 pragma Assert (Typ = Underlying_Type (Typ));
18907 begin
18908 if Has_Variant_Part (Typ) and then not Is_Definite_Subtype (Typ) then
18909 return False;
18910 end if;
18912 declare
18913 Comp : Entity_Id;
18915 begin
18916 Comp := First_Entity (Typ);
18917 while Present (Comp) loop
18919 -- Only look at E_Component entities. No need to look at
18920 -- E_Discriminant entities, and we must ignore internal
18921 -- subtypes generated for constrained components.
18923 if Ekind (Comp) = E_Component then
18924 declare
18925 Comp_Type : constant Entity_Id :=
18926 Underlying_Type (Etype (Comp));
18928 begin
18929 if Is_Record_Type (Comp_Type)
18930 or else
18931 Is_Protected_Type (Comp_Type)
18932 then
18933 if not Caller_Known_Size_Record (Comp_Type) then
18934 return False;
18935 end if;
18937 elsif Is_Array_Type (Comp_Type) then
18938 if Size_Depends_On_Discriminant (Comp_Type) then
18939 return False;
18940 end if;
18941 end if;
18942 end;
18943 end if;
18945 Next_Entity (Comp);
18946 end loop;
18947 end;
18949 return True;
18950 end Caller_Known_Size_Record;
18952 ------------------------------
18953 -- Large_Max_Size_Mutable --
18954 ------------------------------
18956 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean is
18957 pragma Assert (Typ = Underlying_Type (Typ));
18959 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean;
18960 -- Returns true if the discrete type T has a large range
18962 ----------------------------
18963 -- Is_Large_Discrete_Type --
18964 ----------------------------
18966 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean is
18967 Threshold : constant Int := 16;
18968 -- Arbitrary threshold above which we consider it "large". We want
18969 -- a fairly large threshold, because these large types really
18970 -- shouldn't have default discriminants in the first place, in
18971 -- most cases.
18973 begin
18974 return UI_To_Int (RM_Size (T)) > Threshold;
18975 end Is_Large_Discrete_Type;
18977 -- Start of processing for Large_Max_Size_Mutable
18979 begin
18980 if Is_Record_Type (Typ)
18981 and then not Is_Limited_View (Typ)
18982 and then Has_Defaulted_Discriminants (Typ)
18983 then
18984 -- Loop through the components, looking for an array whose upper
18985 -- bound(s) depends on discriminants, where both the subtype of
18986 -- the discriminant and the index subtype are too large.
18988 declare
18989 Comp : Entity_Id;
18991 begin
18992 Comp := First_Entity (Typ);
18993 while Present (Comp) loop
18994 if Ekind (Comp) = E_Component then
18995 declare
18996 Comp_Type : constant Entity_Id :=
18997 Underlying_Type (Etype (Comp));
18999 Hi : Node_Id;
19000 Indx : Node_Id;
19001 Ityp : Entity_Id;
19003 begin
19004 if Is_Array_Type (Comp_Type) then
19005 Indx := First_Index (Comp_Type);
19007 while Present (Indx) loop
19008 Ityp := Etype (Indx);
19009 Hi := Type_High_Bound (Ityp);
19011 if Nkind (Hi) = N_Identifier
19012 and then Ekind (Entity (Hi)) = E_Discriminant
19013 and then Is_Large_Discrete_Type (Ityp)
19014 and then Is_Large_Discrete_Type
19015 (Etype (Entity (Hi)))
19016 then
19017 return True;
19018 end if;
19020 Next_Index (Indx);
19021 end loop;
19022 end if;
19023 end;
19024 end if;
19026 Next_Entity (Comp);
19027 end loop;
19028 end;
19029 end if;
19031 return False;
19032 end Large_Max_Size_Mutable;
19034 -- Local declarations
19036 Typ : constant Entity_Id := Underlying_Type (Id);
19038 -- Start of processing for New_Requires_Transient_Scope
19040 begin
19041 -- This is a private type which is not completed yet. This can only
19042 -- happen in a default expression (of a formal parameter or of a
19043 -- record component). Do not expand transient scope in this case.
19045 if No (Typ) then
19046 return False;
19048 -- Do not expand transient scope for non-existent procedure return or
19049 -- string literal types.
19051 elsif Typ = Standard_Void_Type
19052 or else Ekind (Typ) = E_String_Literal_Subtype
19053 then
19054 return False;
19056 -- If Typ is a generic formal incomplete type, then we want to look at
19057 -- the actual type.
19059 elsif Ekind (Typ) = E_Record_Subtype
19060 and then Present (Cloned_Subtype (Typ))
19061 then
19062 return New_Requires_Transient_Scope (Cloned_Subtype (Typ));
19064 -- Functions returning specific tagged types may dispatch on result, so
19065 -- their returned value is allocated on the secondary stack, even in the
19066 -- definite case. We must treat nondispatching functions the same way,
19067 -- because access-to-function types can point at both, so the calling
19068 -- conventions must be compatible. Is_Tagged_Type includes controlled
19069 -- types and class-wide types. Controlled type temporaries need
19070 -- finalization.
19072 -- ???It's not clear why we need to return noncontrolled types with
19073 -- controlled components on the secondary stack.
19075 elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
19076 return True;
19078 -- Untagged definite subtypes are known size. This includes all
19079 -- elementary [sub]types. Tasks are known size even if they have
19080 -- discriminants. So we return False here, with one exception:
19081 -- For a type like:
19082 -- type T (Last : Natural := 0) is
19083 -- X : String (1 .. Last);
19084 -- end record;
19085 -- we return True. That's because for "P(F(...));", where F returns T,
19086 -- we don't know the size of the result at the call site, so if we
19087 -- allocated it on the primary stack, we would have to allocate the
19088 -- maximum size, which is way too big.
19090 elsif Is_Definite_Subtype (Typ) or else Is_Task_Type (Typ) then
19091 return Large_Max_Size_Mutable (Typ);
19093 -- Indefinite (discriminated) untagged record or protected type
19095 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
19096 return not Caller_Known_Size_Record (Typ);
19098 -- Unconstrained array
19100 else
19101 pragma Assert (Is_Array_Type (Typ) and not Is_Definite_Subtype (Typ));
19102 return True;
19103 end if;
19104 end New_Requires_Transient_Scope;
19106 --------------------------
19107 -- No_Heap_Finalization --
19108 --------------------------
19110 function No_Heap_Finalization (Typ : Entity_Id) return Boolean is
19111 begin
19112 if Ekind_In (Typ, E_Access_Type, E_General_Access_Type)
19113 and then Is_Library_Level_Entity (Typ)
19114 then
19115 -- A global No_Heap_Finalization pragma applies to all library-level
19116 -- named access-to-object types.
19118 if Present (No_Heap_Finalization_Pragma) then
19119 return True;
19121 -- The library-level named access-to-object type itself is subject to
19122 -- pragma No_Heap_Finalization.
19124 elsif Present (Get_Pragma (Typ, Pragma_No_Heap_Finalization)) then
19125 return True;
19126 end if;
19127 end if;
19129 return False;
19130 end No_Heap_Finalization;
19132 -----------------------
19133 -- Normalize_Actuals --
19134 -----------------------
19136 -- Chain actuals according to formals of subprogram. If there are no named
19137 -- associations, the chain is simply the list of Parameter Associations,
19138 -- since the order is the same as the declaration order. If there are named
19139 -- associations, then the First_Named_Actual field in the N_Function_Call
19140 -- or N_Procedure_Call_Statement node points to the Parameter_Association
19141 -- node for the parameter that comes first in declaration order. The
19142 -- remaining named parameters are then chained in declaration order using
19143 -- Next_Named_Actual.
19145 -- This routine also verifies that the number of actuals is compatible with
19146 -- the number and default values of formals, but performs no type checking
19147 -- (type checking is done by the caller).
19149 -- If the matching succeeds, Success is set to True and the caller proceeds
19150 -- with type-checking. If the match is unsuccessful, then Success is set to
19151 -- False, and the caller attempts a different interpretation, if there is
19152 -- one.
19154 -- If the flag Report is on, the call is not overloaded, and a failure to
19155 -- match can be reported here, rather than in the caller.
19157 procedure Normalize_Actuals
19158 (N : Node_Id;
19159 S : Entity_Id;
19160 Report : Boolean;
19161 Success : out Boolean)
19163 Actuals : constant List_Id := Parameter_Associations (N);
19164 Actual : Node_Id := Empty;
19165 Formal : Entity_Id;
19166 Last : Node_Id := Empty;
19167 First_Named : Node_Id := Empty;
19168 Found : Boolean;
19170 Formals_To_Match : Integer := 0;
19171 Actuals_To_Match : Integer := 0;
19173 procedure Chain (A : Node_Id);
19174 -- Add named actual at the proper place in the list, using the
19175 -- Next_Named_Actual link.
19177 function Reporting return Boolean;
19178 -- Determines if an error is to be reported. To report an error, we
19179 -- need Report to be True, and also we do not report errors caused
19180 -- by calls to init procs that occur within other init procs. Such
19181 -- errors must always be cascaded errors, since if all the types are
19182 -- declared correctly, the compiler will certainly build decent calls.
19184 -----------
19185 -- Chain --
19186 -----------
19188 procedure Chain (A : Node_Id) is
19189 begin
19190 if No (Last) then
19192 -- Call node points to first actual in list
19194 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
19196 else
19197 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
19198 end if;
19200 Last := A;
19201 Set_Next_Named_Actual (Last, Empty);
19202 end Chain;
19204 ---------------
19205 -- Reporting --
19206 ---------------
19208 function Reporting return Boolean is
19209 begin
19210 if not Report then
19211 return False;
19213 elsif not Within_Init_Proc then
19214 return True;
19216 elsif Is_Init_Proc (Entity (Name (N))) then
19217 return False;
19219 else
19220 return True;
19221 end if;
19222 end Reporting;
19224 -- Start of processing for Normalize_Actuals
19226 begin
19227 if Is_Access_Type (S) then
19229 -- The name in the call is a function call that returns an access
19230 -- to subprogram. The designated type has the list of formals.
19232 Formal := First_Formal (Designated_Type (S));
19233 else
19234 Formal := First_Formal (S);
19235 end if;
19237 while Present (Formal) loop
19238 Formals_To_Match := Formals_To_Match + 1;
19239 Next_Formal (Formal);
19240 end loop;
19242 -- Find if there is a named association, and verify that no positional
19243 -- associations appear after named ones.
19245 if Present (Actuals) then
19246 Actual := First (Actuals);
19247 end if;
19249 while Present (Actual)
19250 and then Nkind (Actual) /= N_Parameter_Association
19251 loop
19252 Actuals_To_Match := Actuals_To_Match + 1;
19253 Next (Actual);
19254 end loop;
19256 if No (Actual) and Actuals_To_Match = Formals_To_Match then
19258 -- Most common case: positional notation, no defaults
19260 Success := True;
19261 return;
19263 elsif Actuals_To_Match > Formals_To_Match then
19265 -- Too many actuals: will not work
19267 if Reporting then
19268 if Is_Entity_Name (Name (N)) then
19269 Error_Msg_N ("too many arguments in call to&", Name (N));
19270 else
19271 Error_Msg_N ("too many arguments in call", N);
19272 end if;
19273 end if;
19275 Success := False;
19276 return;
19277 end if;
19279 First_Named := Actual;
19281 while Present (Actual) loop
19282 if Nkind (Actual) /= N_Parameter_Association then
19283 Error_Msg_N
19284 ("positional parameters not allowed after named ones", Actual);
19285 Success := False;
19286 return;
19288 else
19289 Actuals_To_Match := Actuals_To_Match + 1;
19290 end if;
19292 Next (Actual);
19293 end loop;
19295 if Present (Actuals) then
19296 Actual := First (Actuals);
19297 end if;
19299 Formal := First_Formal (S);
19300 while Present (Formal) loop
19302 -- Match the formals in order. If the corresponding actual is
19303 -- positional, nothing to do. Else scan the list of named actuals
19304 -- to find the one with the right name.
19306 if Present (Actual)
19307 and then Nkind (Actual) /= N_Parameter_Association
19308 then
19309 Next (Actual);
19310 Actuals_To_Match := Actuals_To_Match - 1;
19311 Formals_To_Match := Formals_To_Match - 1;
19313 else
19314 -- For named parameters, search the list of actuals to find
19315 -- one that matches the next formal name.
19317 Actual := First_Named;
19318 Found := False;
19319 while Present (Actual) loop
19320 if Chars (Selector_Name (Actual)) = Chars (Formal) then
19321 Found := True;
19322 Chain (Actual);
19323 Actuals_To_Match := Actuals_To_Match - 1;
19324 Formals_To_Match := Formals_To_Match - 1;
19325 exit;
19326 end if;
19328 Next (Actual);
19329 end loop;
19331 if not Found then
19332 if Ekind (Formal) /= E_In_Parameter
19333 or else No (Default_Value (Formal))
19334 then
19335 if Reporting then
19336 if (Comes_From_Source (S)
19337 or else Sloc (S) = Standard_Location)
19338 and then Is_Overloadable (S)
19339 then
19340 if No (Actuals)
19341 and then
19342 Nkind_In (Parent (N), N_Procedure_Call_Statement,
19343 N_Function_Call,
19344 N_Parameter_Association)
19345 and then Ekind (S) /= E_Function
19346 then
19347 Set_Etype (N, Etype (S));
19349 else
19350 Error_Msg_Name_1 := Chars (S);
19351 Error_Msg_Sloc := Sloc (S);
19352 Error_Msg_NE
19353 ("missing argument for parameter & "
19354 & "in call to % declared #", N, Formal);
19355 end if;
19357 elsif Is_Overloadable (S) then
19358 Error_Msg_Name_1 := Chars (S);
19360 -- Point to type derivation that generated the
19361 -- operation.
19363 Error_Msg_Sloc := Sloc (Parent (S));
19365 Error_Msg_NE
19366 ("missing argument for parameter & "
19367 & "in call to % (inherited) #", N, Formal);
19369 else
19370 Error_Msg_NE
19371 ("missing argument for parameter &", N, Formal);
19372 end if;
19373 end if;
19375 Success := False;
19376 return;
19378 else
19379 Formals_To_Match := Formals_To_Match - 1;
19380 end if;
19381 end if;
19382 end if;
19384 Next_Formal (Formal);
19385 end loop;
19387 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
19388 Success := True;
19389 return;
19391 else
19392 if Reporting then
19394 -- Find some superfluous named actual that did not get
19395 -- attached to the list of associations.
19397 Actual := First (Actuals);
19398 while Present (Actual) loop
19399 if Nkind (Actual) = N_Parameter_Association
19400 and then Actual /= Last
19401 and then No (Next_Named_Actual (Actual))
19402 then
19403 -- A validity check may introduce a copy of a call that
19404 -- includes an extra actual (for example for an unrelated
19405 -- accessibility check). Check that the extra actual matches
19406 -- some extra formal, which must exist already because
19407 -- subprogram must be frozen at this point.
19409 if Present (Extra_Formals (S))
19410 and then not Comes_From_Source (Actual)
19411 and then Nkind (Actual) = N_Parameter_Association
19412 and then Chars (Extra_Formals (S)) =
19413 Chars (Selector_Name (Actual))
19414 then
19415 null;
19416 else
19417 Error_Msg_N
19418 ("unmatched actual & in call", Selector_Name (Actual));
19419 exit;
19420 end if;
19421 end if;
19423 Next (Actual);
19424 end loop;
19425 end if;
19427 Success := False;
19428 return;
19429 end if;
19430 end Normalize_Actuals;
19432 --------------------------------
19433 -- Note_Possible_Modification --
19434 --------------------------------
19436 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
19437 Modification_Comes_From_Source : constant Boolean :=
19438 Comes_From_Source (Parent (N));
19440 Ent : Entity_Id;
19441 Exp : Node_Id;
19443 begin
19444 -- Loop to find referenced entity, if there is one
19446 Exp := N;
19447 loop
19448 Ent := Empty;
19450 if Is_Entity_Name (Exp) then
19451 Ent := Entity (Exp);
19453 -- If the entity is missing, it is an undeclared identifier,
19454 -- and there is nothing to annotate.
19456 if No (Ent) then
19457 return;
19458 end if;
19460 elsif Nkind (Exp) = N_Explicit_Dereference then
19461 declare
19462 P : constant Node_Id := Prefix (Exp);
19464 begin
19465 -- In formal verification mode, keep track of all reads and
19466 -- writes through explicit dereferences.
19468 if GNATprove_Mode then
19469 SPARK_Specific.Generate_Dereference (N, 'm');
19470 end if;
19472 if Nkind (P) = N_Selected_Component
19473 and then Present (Entry_Formal (Entity (Selector_Name (P))))
19474 then
19475 -- Case of a reference to an entry formal
19477 Ent := Entry_Formal (Entity (Selector_Name (P)));
19479 elsif Nkind (P) = N_Identifier
19480 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
19481 and then Present (Expression (Parent (Entity (P))))
19482 and then Nkind (Expression (Parent (Entity (P)))) =
19483 N_Reference
19484 then
19485 -- Case of a reference to a value on which side effects have
19486 -- been removed.
19488 Exp := Prefix (Expression (Parent (Entity (P))));
19489 goto Continue;
19491 else
19492 return;
19493 end if;
19494 end;
19496 elsif Nkind_In (Exp, N_Type_Conversion,
19497 N_Unchecked_Type_Conversion)
19498 then
19499 Exp := Expression (Exp);
19500 goto Continue;
19502 elsif Nkind_In (Exp, N_Slice,
19503 N_Indexed_Component,
19504 N_Selected_Component)
19505 then
19506 -- Special check, if the prefix is an access type, then return
19507 -- since we are modifying the thing pointed to, not the prefix.
19508 -- When we are expanding, most usually the prefix is replaced
19509 -- by an explicit dereference, and this test is not needed, but
19510 -- in some cases (notably -gnatc mode and generics) when we do
19511 -- not do full expansion, we need this special test.
19513 if Is_Access_Type (Etype (Prefix (Exp))) then
19514 return;
19516 -- Otherwise go to prefix and keep going
19518 else
19519 Exp := Prefix (Exp);
19520 goto Continue;
19521 end if;
19523 -- All other cases, not a modification
19525 else
19526 return;
19527 end if;
19529 -- Now look for entity being referenced
19531 if Present (Ent) then
19532 if Is_Object (Ent) then
19533 if Comes_From_Source (Exp)
19534 or else Modification_Comes_From_Source
19535 then
19536 -- Give warning if pragma unmodified is given and we are
19537 -- sure this is a modification.
19539 if Has_Pragma_Unmodified (Ent) and then Sure then
19541 -- Note that the entity may be present only as a result
19542 -- of pragma Unused.
19544 if Has_Pragma_Unused (Ent) then
19545 Error_Msg_NE ("??pragma Unused given for &!", N, Ent);
19546 else
19547 Error_Msg_NE
19548 ("??pragma Unmodified given for &!", N, Ent);
19549 end if;
19550 end if;
19552 Set_Never_Set_In_Source (Ent, False);
19553 end if;
19555 Set_Is_True_Constant (Ent, False);
19556 Set_Current_Value (Ent, Empty);
19557 Set_Is_Known_Null (Ent, False);
19559 if not Can_Never_Be_Null (Ent) then
19560 Set_Is_Known_Non_Null (Ent, False);
19561 end if;
19563 -- Follow renaming chain
19565 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
19566 and then Present (Renamed_Object (Ent))
19567 then
19568 Exp := Renamed_Object (Ent);
19570 -- If the entity is the loop variable in an iteration over
19571 -- a container, retrieve container expression to indicate
19572 -- possible modification.
19574 if Present (Related_Expression (Ent))
19575 and then Nkind (Parent (Related_Expression (Ent))) =
19576 N_Iterator_Specification
19577 then
19578 Exp := Original_Node (Related_Expression (Ent));
19579 end if;
19581 goto Continue;
19583 -- The expression may be the renaming of a subcomponent of an
19584 -- array or container. The assignment to the subcomponent is
19585 -- a modification of the container.
19587 elsif Comes_From_Source (Original_Node (Exp))
19588 and then Nkind_In (Original_Node (Exp), N_Selected_Component,
19589 N_Indexed_Component)
19590 then
19591 Exp := Prefix (Original_Node (Exp));
19592 goto Continue;
19593 end if;
19595 -- Generate a reference only if the assignment comes from
19596 -- source. This excludes, for example, calls to a dispatching
19597 -- assignment operation when the left-hand side is tagged. In
19598 -- GNATprove mode, we need those references also on generated
19599 -- code, as these are used to compute the local effects of
19600 -- subprograms.
19602 if Modification_Comes_From_Source or GNATprove_Mode then
19603 Generate_Reference (Ent, Exp, 'm');
19605 -- If the target of the assignment is the bound variable
19606 -- in an iterator, indicate that the corresponding array
19607 -- or container is also modified.
19609 if Ada_Version >= Ada_2012
19610 and then Nkind (Parent (Ent)) = N_Iterator_Specification
19611 then
19612 declare
19613 Domain : constant Node_Id := Name (Parent (Ent));
19615 begin
19616 -- TBD : in the full version of the construct, the
19617 -- domain of iteration can be given by an expression.
19619 if Is_Entity_Name (Domain) then
19620 Generate_Reference (Entity (Domain), Exp, 'm');
19621 Set_Is_True_Constant (Entity (Domain), False);
19622 Set_Never_Set_In_Source (Entity (Domain), False);
19623 end if;
19624 end;
19625 end if;
19626 end if;
19627 end if;
19629 Kill_Checks (Ent);
19631 -- If we are sure this is a modification from source, and we know
19632 -- this modifies a constant, then give an appropriate warning.
19634 if Sure
19635 and then Modification_Comes_From_Source
19636 and then Overlays_Constant (Ent)
19637 and then Address_Clause_Overlay_Warnings
19638 then
19639 declare
19640 Addr : constant Node_Id := Address_Clause (Ent);
19641 O_Ent : Entity_Id;
19642 Off : Boolean;
19644 begin
19645 Find_Overlaid_Entity (Addr, O_Ent, Off);
19647 Error_Msg_Sloc := Sloc (Addr);
19648 Error_Msg_NE
19649 ("??constant& may be modified via address clause#",
19650 N, O_Ent);
19651 end;
19652 end if;
19654 return;
19655 end if;
19657 <<Continue>>
19658 null;
19659 end loop;
19660 end Note_Possible_Modification;
19662 -----------------
19663 -- Null_Status --
19664 -----------------
19666 function Null_Status (N : Node_Id) return Null_Status_Kind is
19667 function Is_Null_Excluding_Def (Def : Node_Id) return Boolean;
19668 -- Determine whether definition Def carries a null exclusion
19670 function Null_Status_Of_Entity (Id : Entity_Id) return Null_Status_Kind;
19671 -- Determine the null status of arbitrary entity Id
19673 function Null_Status_Of_Type (Typ : Entity_Id) return Null_Status_Kind;
19674 -- Determine the null status of type Typ
19676 ---------------------------
19677 -- Is_Null_Excluding_Def --
19678 ---------------------------
19680 function Is_Null_Excluding_Def (Def : Node_Id) return Boolean is
19681 begin
19682 return
19683 Nkind_In (Def, N_Access_Definition,
19684 N_Access_Function_Definition,
19685 N_Access_Procedure_Definition,
19686 N_Access_To_Object_Definition,
19687 N_Component_Definition,
19688 N_Derived_Type_Definition)
19689 and then Null_Exclusion_Present (Def);
19690 end Is_Null_Excluding_Def;
19692 ---------------------------
19693 -- Null_Status_Of_Entity --
19694 ---------------------------
19696 function Null_Status_Of_Entity
19697 (Id : Entity_Id) return Null_Status_Kind
19699 Decl : constant Node_Id := Declaration_Node (Id);
19700 Def : Node_Id;
19702 begin
19703 -- The value of an imported or exported entity may be set externally
19704 -- regardless of a null exclusion. As a result, the value cannot be
19705 -- determined statically.
19707 if Is_Imported (Id) or else Is_Exported (Id) then
19708 return Unknown;
19710 elsif Nkind_In (Decl, N_Component_Declaration,
19711 N_Discriminant_Specification,
19712 N_Formal_Object_Declaration,
19713 N_Object_Declaration,
19714 N_Object_Renaming_Declaration,
19715 N_Parameter_Specification)
19716 then
19717 -- A component declaration yields a non-null value when either
19718 -- its component definition or access definition carries a null
19719 -- exclusion.
19721 if Nkind (Decl) = N_Component_Declaration then
19722 Def := Component_Definition (Decl);
19724 if Is_Null_Excluding_Def (Def) then
19725 return Is_Non_Null;
19726 end if;
19728 Def := Access_Definition (Def);
19730 if Present (Def) and then Is_Null_Excluding_Def (Def) then
19731 return Is_Non_Null;
19732 end if;
19734 -- A formal object declaration yields a non-null value if its
19735 -- access definition carries a null exclusion. If the object is
19736 -- default initialized, then the value depends on the expression.
19738 elsif Nkind (Decl) = N_Formal_Object_Declaration then
19739 Def := Access_Definition (Decl);
19741 if Present (Def) and then Is_Null_Excluding_Def (Def) then
19742 return Is_Non_Null;
19743 end if;
19745 -- A constant may yield a null or non-null value depending on its
19746 -- initialization expression.
19748 elsif Ekind (Id) = E_Constant then
19749 return Null_Status (Constant_Value (Id));
19751 -- The construct yields a non-null value when it has a null
19752 -- exclusion.
19754 elsif Null_Exclusion_Present (Decl) then
19755 return Is_Non_Null;
19757 -- An object renaming declaration yields a non-null value if its
19758 -- access definition carries a null exclusion. Otherwise the value
19759 -- depends on the renamed name.
19761 elsif Nkind (Decl) = N_Object_Renaming_Declaration then
19762 Def := Access_Definition (Decl);
19764 if Present (Def) and then Is_Null_Excluding_Def (Def) then
19765 return Is_Non_Null;
19767 else
19768 return Null_Status (Name (Decl));
19769 end if;
19770 end if;
19771 end if;
19773 -- At this point the declaration of the entity does not carry a null
19774 -- exclusion and lacks an initialization expression. Check the status
19775 -- of its type.
19777 return Null_Status_Of_Type (Etype (Id));
19778 end Null_Status_Of_Entity;
19780 -------------------------
19781 -- Null_Status_Of_Type --
19782 -------------------------
19784 function Null_Status_Of_Type (Typ : Entity_Id) return Null_Status_Kind is
19785 Curr : Entity_Id;
19786 Decl : Node_Id;
19788 begin
19789 -- Traverse the type chain looking for types with null exclusion
19791 Curr := Typ;
19792 while Present (Curr) and then Etype (Curr) /= Curr loop
19793 Decl := Parent (Curr);
19795 -- Guard against itypes which do not always have declarations. A
19796 -- type yields a non-null value if it carries a null exclusion.
19798 if Present (Decl) then
19799 if Nkind (Decl) = N_Full_Type_Declaration
19800 and then Is_Null_Excluding_Def (Type_Definition (Decl))
19801 then
19802 return Is_Non_Null;
19804 elsif Nkind (Decl) = N_Subtype_Declaration
19805 and then Null_Exclusion_Present (Decl)
19806 then
19807 return Is_Non_Null;
19808 end if;
19809 end if;
19811 Curr := Etype (Curr);
19812 end loop;
19814 -- The type chain does not contain any null excluding types
19816 return Unknown;
19817 end Null_Status_Of_Type;
19819 -- Start of processing for Null_Status
19821 begin
19822 -- An allocator always creates a non-null value
19824 if Nkind (N) = N_Allocator then
19825 return Is_Non_Null;
19827 -- Taking the 'Access of something yields a non-null value
19829 elsif Nkind (N) = N_Attribute_Reference
19830 and then Nam_In (Attribute_Name (N), Name_Access,
19831 Name_Unchecked_Access,
19832 Name_Unrestricted_Access)
19833 then
19834 return Is_Non_Null;
19836 -- "null" yields null
19838 elsif Nkind (N) = N_Null then
19839 return Is_Null;
19841 -- Check the status of the operand of a type conversion
19843 elsif Nkind (N) = N_Type_Conversion then
19844 return Null_Status (Expression (N));
19846 -- The input denotes a reference to an entity. Determine whether the
19847 -- entity or its type yields a null or non-null value.
19849 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
19850 return Null_Status_Of_Entity (Entity (N));
19851 end if;
19853 -- Otherwise it is not possible to determine the null status of the
19854 -- subexpression at compile time without resorting to simple flow
19855 -- analysis.
19857 return Unknown;
19858 end Null_Status;
19860 --------------------------------------
19861 -- Null_To_Null_Address_Convert_OK --
19862 --------------------------------------
19864 function Null_To_Null_Address_Convert_OK
19865 (N : Node_Id;
19866 Typ : Entity_Id := Empty) return Boolean
19868 begin
19869 if not Relaxed_RM_Semantics then
19870 return False;
19871 end if;
19873 if Nkind (N) = N_Null then
19874 return Present (Typ) and then Is_Descendant_Of_Address (Typ);
19876 elsif Nkind_In (N, N_Op_Eq, N_Op_Ge, N_Op_Gt, N_Op_Le, N_Op_Lt, N_Op_Ne)
19877 then
19878 declare
19879 L : constant Node_Id := Left_Opnd (N);
19880 R : constant Node_Id := Right_Opnd (N);
19882 begin
19883 -- We check the Etype of the complementary operand since the
19884 -- N_Null node is not decorated at this stage.
19886 return
19887 ((Nkind (L) = N_Null
19888 and then Is_Descendant_Of_Address (Etype (R)))
19889 or else
19890 (Nkind (R) = N_Null
19891 and then Is_Descendant_Of_Address (Etype (L))));
19892 end;
19893 end if;
19895 return False;
19896 end Null_To_Null_Address_Convert_OK;
19898 -------------------------
19899 -- Object_Access_Level --
19900 -------------------------
19902 -- Returns the static accessibility level of the view denoted by Obj. Note
19903 -- that the value returned is the result of a call to Scope_Depth. Only
19904 -- scope depths associated with dynamic scopes can actually be returned.
19905 -- Since only relative levels matter for accessibility checking, the fact
19906 -- that the distance between successive levels of accessibility is not
19907 -- always one is immaterial (invariant: if level(E2) is deeper than
19908 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
19910 function Object_Access_Level (Obj : Node_Id) return Uint is
19911 function Is_Interface_Conversion (N : Node_Id) return Boolean;
19912 -- Determine whether N is a construct of the form
19913 -- Some_Type (Operand._tag'Address)
19914 -- This construct appears in the context of dispatching calls.
19916 function Reference_To (Obj : Node_Id) return Node_Id;
19917 -- An explicit dereference is created when removing side-effects from
19918 -- expressions for constraint checking purposes. In this case a local
19919 -- access type is created for it. The correct access level is that of
19920 -- the original source node. We detect this case by noting that the
19921 -- prefix of the dereference is created by an object declaration whose
19922 -- initial expression is a reference.
19924 -----------------------------
19925 -- Is_Interface_Conversion --
19926 -----------------------------
19928 function Is_Interface_Conversion (N : Node_Id) return Boolean is
19929 begin
19930 return Nkind (N) = N_Unchecked_Type_Conversion
19931 and then Nkind (Expression (N)) = N_Attribute_Reference
19932 and then Attribute_Name (Expression (N)) = Name_Address;
19933 end Is_Interface_Conversion;
19935 ------------------
19936 -- Reference_To --
19937 ------------------
19939 function Reference_To (Obj : Node_Id) return Node_Id is
19940 Pref : constant Node_Id := Prefix (Obj);
19941 begin
19942 if Is_Entity_Name (Pref)
19943 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
19944 and then Present (Expression (Parent (Entity (Pref))))
19945 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
19946 then
19947 return (Prefix (Expression (Parent (Entity (Pref)))));
19948 else
19949 return Empty;
19950 end if;
19951 end Reference_To;
19953 -- Local variables
19955 E : Entity_Id;
19957 -- Start of processing for Object_Access_Level
19959 begin
19960 if Nkind (Obj) = N_Defining_Identifier
19961 or else Is_Entity_Name (Obj)
19962 then
19963 if Nkind (Obj) = N_Defining_Identifier then
19964 E := Obj;
19965 else
19966 E := Entity (Obj);
19967 end if;
19969 if Is_Prival (E) then
19970 E := Prival_Link (E);
19971 end if;
19973 -- If E is a type then it denotes a current instance. For this case
19974 -- we add one to the normal accessibility level of the type to ensure
19975 -- that current instances are treated as always being deeper than
19976 -- than the level of any visible named access type (see 3.10.2(21)).
19978 if Is_Type (E) then
19979 return Type_Access_Level (E) + 1;
19981 elsif Present (Renamed_Object (E)) then
19982 return Object_Access_Level (Renamed_Object (E));
19984 -- Similarly, if E is a component of the current instance of a
19985 -- protected type, any instance of it is assumed to be at a deeper
19986 -- level than the type. For a protected object (whose type is an
19987 -- anonymous protected type) its components are at the same level
19988 -- as the type itself.
19990 elsif not Is_Overloadable (E)
19991 and then Ekind (Scope (E)) = E_Protected_Type
19992 and then Comes_From_Source (Scope (E))
19993 then
19994 return Type_Access_Level (Scope (E)) + 1;
19996 else
19997 -- Aliased formals of functions take their access level from the
19998 -- point of call, i.e. require a dynamic check. For static check
19999 -- purposes, this is smaller than the level of the subprogram
20000 -- itself. For procedures the aliased makes no difference.
20002 if Is_Formal (E)
20003 and then Is_Aliased (E)
20004 and then Ekind (Scope (E)) = E_Function
20005 then
20006 return Type_Access_Level (Etype (E));
20008 else
20009 return Scope_Depth (Enclosing_Dynamic_Scope (E));
20010 end if;
20011 end if;
20013 elsif Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
20014 if Is_Access_Type (Etype (Prefix (Obj))) then
20015 return Type_Access_Level (Etype (Prefix (Obj)));
20016 else
20017 return Object_Access_Level (Prefix (Obj));
20018 end if;
20020 elsif Nkind (Obj) = N_Explicit_Dereference then
20022 -- If the prefix is a selected access discriminant then we make a
20023 -- recursive call on the prefix, which will in turn check the level
20024 -- of the prefix object of the selected discriminant.
20026 -- In Ada 2012, if the discriminant has implicit dereference and
20027 -- the context is a selected component, treat this as an object of
20028 -- unknown scope (see below). This is necessary in compile-only mode;
20029 -- otherwise expansion will already have transformed the prefix into
20030 -- a temporary.
20032 if Nkind (Prefix (Obj)) = N_Selected_Component
20033 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
20034 and then
20035 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
20036 and then
20037 (not Has_Implicit_Dereference
20038 (Entity (Selector_Name (Prefix (Obj))))
20039 or else Nkind (Parent (Obj)) /= N_Selected_Component)
20040 then
20041 return Object_Access_Level (Prefix (Obj));
20043 -- Detect an interface conversion in the context of a dispatching
20044 -- call. Use the original form of the conversion to find the access
20045 -- level of the operand.
20047 elsif Is_Interface (Etype (Obj))
20048 and then Is_Interface_Conversion (Prefix (Obj))
20049 and then Nkind (Original_Node (Obj)) = N_Type_Conversion
20050 then
20051 return Object_Access_Level (Original_Node (Obj));
20053 elsif not Comes_From_Source (Obj) then
20054 declare
20055 Ref : constant Node_Id := Reference_To (Obj);
20056 begin
20057 if Present (Ref) then
20058 return Object_Access_Level (Ref);
20059 else
20060 return Type_Access_Level (Etype (Prefix (Obj)));
20061 end if;
20062 end;
20064 else
20065 return Type_Access_Level (Etype (Prefix (Obj)));
20066 end if;
20068 elsif Nkind_In (Obj, N_Type_Conversion, N_Unchecked_Type_Conversion) then
20069 return Object_Access_Level (Expression (Obj));
20071 elsif Nkind (Obj) = N_Function_Call then
20073 -- Function results are objects, so we get either the access level of
20074 -- the function or, in the case of an indirect call, the level of the
20075 -- access-to-subprogram type. (This code is used for Ada 95, but it
20076 -- looks wrong, because it seems that we should be checking the level
20077 -- of the call itself, even for Ada 95. However, using the Ada 2005
20078 -- version of the code causes regressions in several tests that are
20079 -- compiled with -gnat95. ???)
20081 if Ada_Version < Ada_2005 then
20082 if Is_Entity_Name (Name (Obj)) then
20083 return Subprogram_Access_Level (Entity (Name (Obj)));
20084 else
20085 return Type_Access_Level (Etype (Prefix (Name (Obj))));
20086 end if;
20088 -- For Ada 2005, the level of the result object of a function call is
20089 -- defined to be the level of the call's innermost enclosing master.
20090 -- We determine that by querying the depth of the innermost enclosing
20091 -- dynamic scope.
20093 else
20094 Return_Master_Scope_Depth_Of_Call : declare
20095 function Innermost_Master_Scope_Depth
20096 (N : Node_Id) return Uint;
20097 -- Returns the scope depth of the given node's innermost
20098 -- enclosing dynamic scope (effectively the accessibility
20099 -- level of the innermost enclosing master).
20101 ----------------------------------
20102 -- Innermost_Master_Scope_Depth --
20103 ----------------------------------
20105 function Innermost_Master_Scope_Depth
20106 (N : Node_Id) return Uint
20108 Node_Par : Node_Id := Parent (N);
20110 begin
20111 -- Locate the nearest enclosing node (by traversing Parents)
20112 -- that Defining_Entity can be applied to, and return the
20113 -- depth of that entity's nearest enclosing dynamic scope.
20115 while Present (Node_Par) loop
20116 case Nkind (Node_Par) is
20117 when N_Abstract_Subprogram_Declaration
20118 | N_Block_Statement
20119 | N_Body_Stub
20120 | N_Component_Declaration
20121 | N_Entry_Body
20122 | N_Entry_Declaration
20123 | N_Exception_Declaration
20124 | N_Formal_Object_Declaration
20125 | N_Formal_Package_Declaration
20126 | N_Formal_Subprogram_Declaration
20127 | N_Formal_Type_Declaration
20128 | N_Full_Type_Declaration
20129 | N_Function_Specification
20130 | N_Generic_Declaration
20131 | N_Generic_Instantiation
20132 | N_Implicit_Label_Declaration
20133 | N_Incomplete_Type_Declaration
20134 | N_Loop_Parameter_Specification
20135 | N_Number_Declaration
20136 | N_Object_Declaration
20137 | N_Package_Declaration
20138 | N_Package_Specification
20139 | N_Parameter_Specification
20140 | N_Private_Extension_Declaration
20141 | N_Private_Type_Declaration
20142 | N_Procedure_Specification
20143 | N_Proper_Body
20144 | N_Protected_Type_Declaration
20145 | N_Renaming_Declaration
20146 | N_Single_Protected_Declaration
20147 | N_Single_Task_Declaration
20148 | N_Subprogram_Declaration
20149 | N_Subtype_Declaration
20150 | N_Subunit
20151 | N_Task_Type_Declaration
20153 return Scope_Depth
20154 (Nearest_Dynamic_Scope
20155 (Defining_Entity (Node_Par)));
20157 when others =>
20158 null;
20159 end case;
20161 Node_Par := Parent (Node_Par);
20162 end loop;
20164 pragma Assert (False);
20166 -- Should never reach the following return
20168 return Scope_Depth (Current_Scope) + 1;
20169 end Innermost_Master_Scope_Depth;
20171 -- Start of processing for Return_Master_Scope_Depth_Of_Call
20173 begin
20174 return Innermost_Master_Scope_Depth (Obj);
20175 end Return_Master_Scope_Depth_Of_Call;
20176 end if;
20178 -- For convenience we handle qualified expressions, even though they
20179 -- aren't technically object names.
20181 elsif Nkind (Obj) = N_Qualified_Expression then
20182 return Object_Access_Level (Expression (Obj));
20184 -- Ditto for aggregates. They have the level of the temporary that
20185 -- will hold their value.
20187 elsif Nkind (Obj) = N_Aggregate then
20188 return Object_Access_Level (Current_Scope);
20190 -- Otherwise return the scope level of Standard. (If there are cases
20191 -- that fall through to this point they will be treated as having
20192 -- global accessibility for now. ???)
20194 else
20195 return Scope_Depth (Standard_Standard);
20196 end if;
20197 end Object_Access_Level;
20199 ----------------------------------
20200 -- Old_Requires_Transient_Scope --
20201 ----------------------------------
20203 function Old_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
20204 Typ : constant Entity_Id := Underlying_Type (Id);
20206 begin
20207 -- This is a private type which is not completed yet. This can only
20208 -- happen in a default expression (of a formal parameter or of a
20209 -- record component). Do not expand transient scope in this case.
20211 if No (Typ) then
20212 return False;
20214 -- Do not expand transient scope for non-existent procedure return
20216 elsif Typ = Standard_Void_Type then
20217 return False;
20219 -- Elementary types do not require a transient scope
20221 elsif Is_Elementary_Type (Typ) then
20222 return False;
20224 -- Generally, indefinite subtypes require a transient scope, since the
20225 -- back end cannot generate temporaries, since this is not a valid type
20226 -- for declaring an object. It might be possible to relax this in the
20227 -- future, e.g. by declaring the maximum possible space for the type.
20229 elsif not Is_Definite_Subtype (Typ) then
20230 return True;
20232 -- Functions returning tagged types may dispatch on result so their
20233 -- returned value is allocated on the secondary stack. Controlled
20234 -- type temporaries need finalization.
20236 elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
20237 return True;
20239 -- Record type
20241 elsif Is_Record_Type (Typ) then
20242 declare
20243 Comp : Entity_Id;
20245 begin
20246 Comp := First_Entity (Typ);
20247 while Present (Comp) loop
20248 if Ekind (Comp) = E_Component then
20250 -- ???It's not clear we need a full recursive call to
20251 -- Old_Requires_Transient_Scope here. Note that the
20252 -- following can't happen.
20254 pragma Assert (Is_Definite_Subtype (Etype (Comp)));
20255 pragma Assert (not Has_Controlled_Component (Etype (Comp)));
20257 if Old_Requires_Transient_Scope (Etype (Comp)) then
20258 return True;
20259 end if;
20260 end if;
20262 Next_Entity (Comp);
20263 end loop;
20264 end;
20266 return False;
20268 -- String literal types never require transient scope
20270 elsif Ekind (Typ) = E_String_Literal_Subtype then
20271 return False;
20273 -- Array type. Note that we already know that this is a constrained
20274 -- array, since unconstrained arrays will fail the indefinite test.
20276 elsif Is_Array_Type (Typ) then
20278 -- If component type requires a transient scope, the array does too
20280 if Old_Requires_Transient_Scope (Component_Type (Typ)) then
20281 return True;
20283 -- Otherwise, we only need a transient scope if the size depends on
20284 -- the value of one or more discriminants.
20286 else
20287 return Size_Depends_On_Discriminant (Typ);
20288 end if;
20290 -- All other cases do not require a transient scope
20292 else
20293 pragma Assert (Is_Protected_Type (Typ) or else Is_Task_Type (Typ));
20294 return False;
20295 end if;
20296 end Old_Requires_Transient_Scope;
20298 ---------------------------------
20299 -- Original_Aspect_Pragma_Name --
20300 ---------------------------------
20302 function Original_Aspect_Pragma_Name (N : Node_Id) return Name_Id is
20303 Item : Node_Id;
20304 Item_Nam : Name_Id;
20306 begin
20307 pragma Assert (Nkind_In (N, N_Aspect_Specification, N_Pragma));
20309 Item := N;
20311 -- The pragma was generated to emulate an aspect, use the original
20312 -- aspect specification.
20314 if Nkind (Item) = N_Pragma and then From_Aspect_Specification (Item) then
20315 Item := Corresponding_Aspect (Item);
20316 end if;
20318 -- Retrieve the name of the aspect/pragma. Note that Pre, Pre_Class,
20319 -- Post and Post_Class rewrite their pragma identifier to preserve the
20320 -- original name.
20321 -- ??? this is kludgey
20323 if Nkind (Item) = N_Pragma then
20324 Item_Nam := Chars (Original_Node (Pragma_Identifier (Item)));
20326 else
20327 pragma Assert (Nkind (Item) = N_Aspect_Specification);
20328 Item_Nam := Chars (Identifier (Item));
20329 end if;
20331 -- Deal with 'Class by converting the name to its _XXX form
20333 if Class_Present (Item) then
20334 if Item_Nam = Name_Invariant then
20335 Item_Nam := Name_uInvariant;
20337 elsif Item_Nam = Name_Post then
20338 Item_Nam := Name_uPost;
20340 elsif Item_Nam = Name_Pre then
20341 Item_Nam := Name_uPre;
20343 elsif Nam_In (Item_Nam, Name_Type_Invariant,
20344 Name_Type_Invariant_Class)
20345 then
20346 Item_Nam := Name_uType_Invariant;
20348 -- Nothing to do for other cases (e.g. a Check that derived from
20349 -- Pre_Class and has the flag set). Also we do nothing if the name
20350 -- is already in special _xxx form.
20352 end if;
20353 end if;
20355 return Item_Nam;
20356 end Original_Aspect_Pragma_Name;
20358 --------------------------------------
20359 -- Original_Corresponding_Operation --
20360 --------------------------------------
20362 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
20364 Typ : constant Entity_Id := Find_Dispatching_Type (S);
20366 begin
20367 -- If S is an inherited primitive S2 the original corresponding
20368 -- operation of S is the original corresponding operation of S2
20370 if Present (Alias (S))
20371 and then Find_Dispatching_Type (Alias (S)) /= Typ
20372 then
20373 return Original_Corresponding_Operation (Alias (S));
20375 -- If S overrides an inherited subprogram S2 the original corresponding
20376 -- operation of S is the original corresponding operation of S2
20378 elsif Present (Overridden_Operation (S)) then
20379 return Original_Corresponding_Operation (Overridden_Operation (S));
20381 -- otherwise it is S itself
20383 else
20384 return S;
20385 end if;
20386 end Original_Corresponding_Operation;
20388 -------------------
20389 -- Output_Entity --
20390 -------------------
20392 procedure Output_Entity (Id : Entity_Id) is
20393 Scop : Entity_Id;
20395 begin
20396 Scop := Scope (Id);
20398 -- The entity may lack a scope when it is in the process of being
20399 -- analyzed. Use the current scope as an approximation.
20401 if No (Scop) then
20402 Scop := Current_Scope;
20403 end if;
20405 Output_Name (Chars (Id), Scop);
20406 end Output_Entity;
20408 -----------------
20409 -- Output_Name --
20410 -----------------
20412 procedure Output_Name (Nam : Name_Id; Scop : Entity_Id := Current_Scope) is
20413 begin
20414 Write_Str
20415 (Get_Name_String
20416 (Get_Qualified_Name
20417 (Nam => Nam,
20418 Suffix => No_Name,
20419 Scop => Scop)));
20420 Write_Eol;
20421 end Output_Name;
20423 ----------------------
20424 -- Policy_In_Effect --
20425 ----------------------
20427 function Policy_In_Effect (Policy : Name_Id) return Name_Id is
20428 function Policy_In_List (List : Node_Id) return Name_Id;
20429 -- Determine the mode of a policy in a N_Pragma list
20431 --------------------
20432 -- Policy_In_List --
20433 --------------------
20435 function Policy_In_List (List : Node_Id) return Name_Id is
20436 Arg1 : Node_Id;
20437 Arg2 : Node_Id;
20438 Prag : Node_Id;
20440 begin
20441 Prag := List;
20442 while Present (Prag) loop
20443 Arg1 := First (Pragma_Argument_Associations (Prag));
20444 Arg2 := Next (Arg1);
20446 Arg1 := Get_Pragma_Arg (Arg1);
20447 Arg2 := Get_Pragma_Arg (Arg2);
20449 -- The current Check_Policy pragma matches the requested policy or
20450 -- appears in the single argument form (Assertion, policy_id).
20452 if Nam_In (Chars (Arg1), Name_Assertion, Policy) then
20453 return Chars (Arg2);
20454 end if;
20456 Prag := Next_Pragma (Prag);
20457 end loop;
20459 return No_Name;
20460 end Policy_In_List;
20462 -- Local variables
20464 Kind : Name_Id;
20466 -- Start of processing for Policy_In_Effect
20468 begin
20469 if not Is_Valid_Assertion_Kind (Policy) then
20470 raise Program_Error;
20471 end if;
20473 -- Inspect all policy pragmas that appear within scopes (if any)
20475 Kind := Policy_In_List (Check_Policy_List);
20477 -- Inspect all configuration policy pragmas (if any)
20479 if Kind = No_Name then
20480 Kind := Policy_In_List (Check_Policy_List_Config);
20481 end if;
20483 -- The context lacks policy pragmas, determine the mode based on whether
20484 -- assertions are enabled at the configuration level. This ensures that
20485 -- the policy is preserved when analyzing generics.
20487 if Kind = No_Name then
20488 if Assertions_Enabled_Config then
20489 Kind := Name_Check;
20490 else
20491 Kind := Name_Ignore;
20492 end if;
20493 end if;
20495 return Kind;
20496 end Policy_In_Effect;
20498 ----------------------------------
20499 -- Predicate_Tests_On_Arguments --
20500 ----------------------------------
20502 function Predicate_Tests_On_Arguments (Subp : Entity_Id) return Boolean is
20503 begin
20504 -- Always test predicates on indirect call
20506 if Ekind (Subp) = E_Subprogram_Type then
20507 return True;
20509 -- Do not test predicates on call to generated default Finalize, since
20510 -- we are not interested in whether something we are finalizing (and
20511 -- typically destroying) satisfies its predicates.
20513 elsif Chars (Subp) = Name_Finalize
20514 and then not Comes_From_Source (Subp)
20515 then
20516 return False;
20518 -- Do not test predicates on any internally generated routines
20520 elsif Is_Internal_Name (Chars (Subp)) then
20521 return False;
20523 -- Do not test predicates on call to Init_Proc, since if needed the
20524 -- predicate test will occur at some other point.
20526 elsif Is_Init_Proc (Subp) then
20527 return False;
20529 -- Do not test predicates on call to predicate function, since this
20530 -- would cause infinite recursion.
20532 elsif Ekind (Subp) = E_Function
20533 and then (Is_Predicate_Function (Subp)
20534 or else
20535 Is_Predicate_Function_M (Subp))
20536 then
20537 return False;
20539 -- For now, no other exceptions
20541 else
20542 return True;
20543 end if;
20544 end Predicate_Tests_On_Arguments;
20546 -----------------------
20547 -- Private_Component --
20548 -----------------------
20550 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
20551 Ancestor : constant Entity_Id := Base_Type (Type_Id);
20553 function Trace_Components
20554 (T : Entity_Id;
20555 Check : Boolean) return Entity_Id;
20556 -- Recursive function that does the work, and checks against circular
20557 -- definition for each subcomponent type.
20559 ----------------------
20560 -- Trace_Components --
20561 ----------------------
20563 function Trace_Components
20564 (T : Entity_Id;
20565 Check : Boolean) return Entity_Id
20567 Btype : constant Entity_Id := Base_Type (T);
20568 Component : Entity_Id;
20569 P : Entity_Id;
20570 Candidate : Entity_Id := Empty;
20572 begin
20573 if Check and then Btype = Ancestor then
20574 Error_Msg_N ("circular type definition", Type_Id);
20575 return Any_Type;
20576 end if;
20578 if Is_Private_Type (Btype) and then not Is_Generic_Type (Btype) then
20579 if Present (Full_View (Btype))
20580 and then Is_Record_Type (Full_View (Btype))
20581 and then not Is_Frozen (Btype)
20582 then
20583 -- To indicate that the ancestor depends on a private type, the
20584 -- current Btype is sufficient. However, to check for circular
20585 -- definition we must recurse on the full view.
20587 Candidate := Trace_Components (Full_View (Btype), True);
20589 if Candidate = Any_Type then
20590 return Any_Type;
20591 else
20592 return Btype;
20593 end if;
20595 else
20596 return Btype;
20597 end if;
20599 elsif Is_Array_Type (Btype) then
20600 return Trace_Components (Component_Type (Btype), True);
20602 elsif Is_Record_Type (Btype) then
20603 Component := First_Entity (Btype);
20604 while Present (Component)
20605 and then Comes_From_Source (Component)
20606 loop
20607 -- Skip anonymous types generated by constrained components
20609 if not Is_Type (Component) then
20610 P := Trace_Components (Etype (Component), True);
20612 if Present (P) then
20613 if P = Any_Type then
20614 return P;
20615 else
20616 Candidate := P;
20617 end if;
20618 end if;
20619 end if;
20621 Next_Entity (Component);
20622 end loop;
20624 return Candidate;
20626 else
20627 return Empty;
20628 end if;
20629 end Trace_Components;
20631 -- Start of processing for Private_Component
20633 begin
20634 return Trace_Components (Type_Id, False);
20635 end Private_Component;
20637 ---------------------------
20638 -- Primitive_Names_Match --
20639 ---------------------------
20641 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
20642 function Non_Internal_Name (E : Entity_Id) return Name_Id;
20643 -- Given an internal name, returns the corresponding non-internal name
20645 ------------------------
20646 -- Non_Internal_Name --
20647 ------------------------
20649 function Non_Internal_Name (E : Entity_Id) return Name_Id is
20650 begin
20651 Get_Name_String (Chars (E));
20652 Name_Len := Name_Len - 1;
20653 return Name_Find;
20654 end Non_Internal_Name;
20656 -- Start of processing for Primitive_Names_Match
20658 begin
20659 pragma Assert (Present (E1) and then Present (E2));
20661 return Chars (E1) = Chars (E2)
20662 or else
20663 (not Is_Internal_Name (Chars (E1))
20664 and then Is_Internal_Name (Chars (E2))
20665 and then Non_Internal_Name (E2) = Chars (E1))
20666 or else
20667 (not Is_Internal_Name (Chars (E2))
20668 and then Is_Internal_Name (Chars (E1))
20669 and then Non_Internal_Name (E1) = Chars (E2))
20670 or else
20671 (Is_Predefined_Dispatching_Operation (E1)
20672 and then Is_Predefined_Dispatching_Operation (E2)
20673 and then Same_TSS (E1, E2))
20674 or else
20675 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
20676 end Primitive_Names_Match;
20678 -----------------------
20679 -- Process_End_Label --
20680 -----------------------
20682 procedure Process_End_Label
20683 (N : Node_Id;
20684 Typ : Character;
20685 Ent : Entity_Id)
20687 Loc : Source_Ptr;
20688 Nam : Node_Id;
20689 Scop : Entity_Id;
20691 Label_Ref : Boolean;
20692 -- Set True if reference to end label itself is required
20694 Endl : Node_Id;
20695 -- Gets set to the operator symbol or identifier that references the
20696 -- entity Ent. For the child unit case, this is the identifier from the
20697 -- designator. For other cases, this is simply Endl.
20699 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
20700 -- N is an identifier node that appears as a parent unit reference in
20701 -- the case where Ent is a child unit. This procedure generates an
20702 -- appropriate cross-reference entry. E is the corresponding entity.
20704 -------------------------
20705 -- Generate_Parent_Ref --
20706 -------------------------
20708 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
20709 begin
20710 -- If names do not match, something weird, skip reference
20712 if Chars (E) = Chars (N) then
20714 -- Generate the reference. We do NOT consider this as a reference
20715 -- for unreferenced symbol purposes.
20717 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
20719 if Style_Check then
20720 Style.Check_Identifier (N, E);
20721 end if;
20722 end if;
20723 end Generate_Parent_Ref;
20725 -- Start of processing for Process_End_Label
20727 begin
20728 -- If no node, ignore. This happens in some error situations, and
20729 -- also for some internally generated structures where no end label
20730 -- references are required in any case.
20732 if No (N) then
20733 return;
20734 end if;
20736 -- Nothing to do if no End_Label, happens for internally generated
20737 -- constructs where we don't want an end label reference anyway. Also
20738 -- nothing to do if Endl is a string literal, which means there was
20739 -- some prior error (bad operator symbol)
20741 Endl := End_Label (N);
20743 if No (Endl) or else Nkind (Endl) = N_String_Literal then
20744 return;
20745 end if;
20747 -- Reference node is not in extended main source unit
20749 if not In_Extended_Main_Source_Unit (N) then
20751 -- Generally we do not collect references except for the extended
20752 -- main source unit. The one exception is the 'e' entry for a
20753 -- package spec, where it is useful for a client to have the
20754 -- ending information to define scopes.
20756 if Typ /= 'e' then
20757 return;
20759 else
20760 Label_Ref := False;
20762 -- For this case, we can ignore any parent references, but we
20763 -- need the package name itself for the 'e' entry.
20765 if Nkind (Endl) = N_Designator then
20766 Endl := Identifier (Endl);
20767 end if;
20768 end if;
20770 -- Reference is in extended main source unit
20772 else
20773 Label_Ref := True;
20775 -- For designator, generate references for the parent entries
20777 if Nkind (Endl) = N_Designator then
20779 -- Generate references for the prefix if the END line comes from
20780 -- source (otherwise we do not need these references) We climb the
20781 -- scope stack to find the expected entities.
20783 if Comes_From_Source (Endl) then
20784 Nam := Name (Endl);
20785 Scop := Current_Scope;
20786 while Nkind (Nam) = N_Selected_Component loop
20787 Scop := Scope (Scop);
20788 exit when No (Scop);
20789 Generate_Parent_Ref (Selector_Name (Nam), Scop);
20790 Nam := Prefix (Nam);
20791 end loop;
20793 if Present (Scop) then
20794 Generate_Parent_Ref (Nam, Scope (Scop));
20795 end if;
20796 end if;
20798 Endl := Identifier (Endl);
20799 end if;
20800 end if;
20802 -- If the end label is not for the given entity, then either we have
20803 -- some previous error, or this is a generic instantiation for which
20804 -- we do not need to make a cross-reference in this case anyway. In
20805 -- either case we simply ignore the call.
20807 if Chars (Ent) /= Chars (Endl) then
20808 return;
20809 end if;
20811 -- If label was really there, then generate a normal reference and then
20812 -- adjust the location in the end label to point past the name (which
20813 -- should almost always be the semicolon).
20815 Loc := Sloc (Endl);
20817 if Comes_From_Source (Endl) then
20819 -- If a label reference is required, then do the style check and
20820 -- generate an l-type cross-reference entry for the label
20822 if Label_Ref then
20823 if Style_Check then
20824 Style.Check_Identifier (Endl, Ent);
20825 end if;
20827 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
20828 end if;
20830 -- Set the location to point past the label (normally this will
20831 -- mean the semicolon immediately following the label). This is
20832 -- done for the sake of the 'e' or 't' entry generated below.
20834 Get_Decoded_Name_String (Chars (Endl));
20835 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
20837 else
20838 -- In SPARK mode, no missing label is allowed for packages and
20839 -- subprogram bodies. Detect those cases by testing whether
20840 -- Process_End_Label was called for a body (Typ = 't') or a package.
20842 if Restriction_Check_Required (SPARK_05)
20843 and then (Typ = 't' or else Ekind (Ent) = E_Package)
20844 then
20845 Error_Msg_Node_1 := Endl;
20846 Check_SPARK_05_Restriction
20847 ("`END &` required", Endl, Force => True);
20848 end if;
20849 end if;
20851 -- Now generate the e/t reference
20853 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
20855 -- Restore Sloc, in case modified above, since we have an identifier
20856 -- and the normal Sloc should be left set in the tree.
20858 Set_Sloc (Endl, Loc);
20859 end Process_End_Label;
20861 --------------------------------
20862 -- Propagate_Concurrent_Flags --
20863 --------------------------------
20865 procedure Propagate_Concurrent_Flags
20866 (Typ : Entity_Id;
20867 Comp_Typ : Entity_Id)
20869 begin
20870 if Has_Task (Comp_Typ) then
20871 Set_Has_Task (Typ);
20872 end if;
20874 if Has_Protected (Comp_Typ) then
20875 Set_Has_Protected (Typ);
20876 end if;
20878 if Has_Timing_Event (Comp_Typ) then
20879 Set_Has_Timing_Event (Typ);
20880 end if;
20881 end Propagate_Concurrent_Flags;
20883 ------------------------------
20884 -- Propagate_DIC_Attributes --
20885 ------------------------------
20887 procedure Propagate_DIC_Attributes
20888 (Typ : Entity_Id;
20889 From_Typ : Entity_Id)
20891 DIC_Proc : Entity_Id;
20893 begin
20894 if Present (Typ) and then Present (From_Typ) then
20895 pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
20897 -- Nothing to do if both the source and the destination denote the
20898 -- same type.
20900 if From_Typ = Typ then
20901 return;
20902 end if;
20904 DIC_Proc := DIC_Procedure (From_Typ);
20906 -- The setting of the attributes is intentionally conservative. This
20907 -- prevents accidental clobbering of enabled attributes.
20909 if Has_Inherited_DIC (From_Typ)
20910 and then not Has_Inherited_DIC (Typ)
20911 then
20912 Set_Has_Inherited_DIC (Typ);
20913 end if;
20915 if Has_Own_DIC (From_Typ) and then not Has_Own_DIC (Typ) then
20916 Set_Has_Own_DIC (Typ);
20917 end if;
20919 if Present (DIC_Proc) and then No (DIC_Procedure (Typ)) then
20920 Set_DIC_Procedure (Typ, DIC_Proc);
20921 end if;
20922 end if;
20923 end Propagate_DIC_Attributes;
20925 ------------------------------------
20926 -- Propagate_Invariant_Attributes --
20927 ------------------------------------
20929 procedure Propagate_Invariant_Attributes
20930 (Typ : Entity_Id;
20931 From_Typ : Entity_Id)
20933 Full_IP : Entity_Id;
20934 Part_IP : Entity_Id;
20936 begin
20937 if Present (Typ) and then Present (From_Typ) then
20938 pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
20940 -- Nothing to do if both the source and the destination denote the
20941 -- same type.
20943 if From_Typ = Typ then
20944 return;
20945 end if;
20947 Full_IP := Invariant_Procedure (From_Typ);
20948 Part_IP := Partial_Invariant_Procedure (From_Typ);
20950 -- The setting of the attributes is intentionally conservative. This
20951 -- prevents accidental clobbering of enabled attributes.
20953 if Has_Inheritable_Invariants (From_Typ)
20954 and then not Has_Inheritable_Invariants (Typ)
20955 then
20956 Set_Has_Inheritable_Invariants (Typ, True);
20957 end if;
20959 if Has_Inherited_Invariants (From_Typ)
20960 and then not Has_Inherited_Invariants (Typ)
20961 then
20962 Set_Has_Inherited_Invariants (Typ, True);
20963 end if;
20965 if Has_Own_Invariants (From_Typ)
20966 and then not Has_Own_Invariants (Typ)
20967 then
20968 Set_Has_Own_Invariants (Typ, True);
20969 end if;
20971 if Present (Full_IP) and then No (Invariant_Procedure (Typ)) then
20972 Set_Invariant_Procedure (Typ, Full_IP);
20973 end if;
20975 if Present (Part_IP) and then No (Partial_Invariant_Procedure (Typ))
20976 then
20977 Set_Partial_Invariant_Procedure (Typ, Part_IP);
20978 end if;
20979 end if;
20980 end Propagate_Invariant_Attributes;
20982 ---------------------------------------
20983 -- Record_Possible_Part_Of_Reference --
20984 ---------------------------------------
20986 procedure Record_Possible_Part_Of_Reference
20987 (Var_Id : Entity_Id;
20988 Ref : Node_Id)
20990 Encap : constant Entity_Id := Encapsulating_State (Var_Id);
20991 Refs : Elist_Id;
20993 begin
20994 -- The variable is a constituent of a single protected/task type. Such
20995 -- a variable acts as a component of the type and must appear within a
20996 -- specific region (SPARK RM 9.3). Instead of recording the reference,
20997 -- verify its legality now.
20999 if Present (Encap) and then Is_Single_Concurrent_Object (Encap) then
21000 Check_Part_Of_Reference (Var_Id, Ref);
21002 -- The variable is subject to pragma Part_Of and may eventually become a
21003 -- constituent of a single protected/task type. Record the reference to
21004 -- verify its placement when the contract of the variable is analyzed.
21006 elsif Present (Get_Pragma (Var_Id, Pragma_Part_Of)) then
21007 Refs := Part_Of_References (Var_Id);
21009 if No (Refs) then
21010 Refs := New_Elmt_List;
21011 Set_Part_Of_References (Var_Id, Refs);
21012 end if;
21014 Append_Elmt (Ref, Refs);
21015 end if;
21016 end Record_Possible_Part_Of_Reference;
21018 ----------------
21019 -- Referenced --
21020 ----------------
21022 function Referenced (Id : Entity_Id; Expr : Node_Id) return Boolean is
21023 Seen : Boolean := False;
21025 function Is_Reference (N : Node_Id) return Traverse_Result;
21026 -- Determine whether node N denotes a reference to Id. If this is the
21027 -- case, set global flag Seen to True and stop the traversal.
21029 ------------------
21030 -- Is_Reference --
21031 ------------------
21033 function Is_Reference (N : Node_Id) return Traverse_Result is
21034 begin
21035 if Is_Entity_Name (N)
21036 and then Present (Entity (N))
21037 and then Entity (N) = Id
21038 then
21039 Seen := True;
21040 return Abandon;
21041 else
21042 return OK;
21043 end if;
21044 end Is_Reference;
21046 procedure Inspect_Expression is new Traverse_Proc (Is_Reference);
21048 -- Start of processing for Referenced
21050 begin
21051 Inspect_Expression (Expr);
21052 return Seen;
21053 end Referenced;
21055 ------------------------------------
21056 -- References_Generic_Formal_Type --
21057 ------------------------------------
21059 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
21061 function Process (N : Node_Id) return Traverse_Result;
21062 -- Process one node in search for generic formal type
21064 -------------
21065 -- Process --
21066 -------------
21068 function Process (N : Node_Id) return Traverse_Result is
21069 begin
21070 if Nkind (N) in N_Has_Entity then
21071 declare
21072 E : constant Entity_Id := Entity (N);
21073 begin
21074 if Present (E) then
21075 if Is_Generic_Type (E) then
21076 return Abandon;
21077 elsif Present (Etype (E))
21078 and then Is_Generic_Type (Etype (E))
21079 then
21080 return Abandon;
21081 end if;
21082 end if;
21083 end;
21084 end if;
21086 return Atree.OK;
21087 end Process;
21089 function Traverse is new Traverse_Func (Process);
21090 -- Traverse tree to look for generic type
21092 begin
21093 if Inside_A_Generic then
21094 return Traverse (N) = Abandon;
21095 else
21096 return False;
21097 end if;
21098 end References_Generic_Formal_Type;
21100 -------------------
21101 -- Remove_Entity --
21102 -------------------
21104 procedure Remove_Entity (Id : Entity_Id) is
21105 Scop : constant Entity_Id := Scope (Id);
21106 Prev_Id : Entity_Id;
21108 begin
21109 -- Remove the entity from the homonym chain. When the entity is the
21110 -- head of the chain, associate the entry in the name table with its
21111 -- homonym effectively making it the new head of the chain.
21113 if Current_Entity (Id) = Id then
21114 Set_Name_Entity_Id (Chars (Id), Homonym (Id));
21116 -- Otherwise link the previous and next homonyms
21118 else
21119 Prev_Id := Current_Entity (Id);
21120 while Present (Prev_Id) and then Homonym (Prev_Id) /= Id loop
21121 Prev_Id := Homonym (Prev_Id);
21122 end loop;
21124 Set_Homonym (Prev_Id, Homonym (Id));
21125 end if;
21127 -- Remove the entity from the scope entity chain. When the entity is
21128 -- the head of the chain, set the next entity as the new head of the
21129 -- chain.
21131 if First_Entity (Scop) = Id then
21132 Prev_Id := Empty;
21133 Set_First_Entity (Scop, Next_Entity (Id));
21135 -- Otherwise the entity is either in the middle of the chain or it acts
21136 -- as its tail. Traverse and link the previous and next entities.
21138 else
21139 Prev_Id := First_Entity (Scop);
21140 while Present (Prev_Id) and then Next_Entity (Prev_Id) /= Id loop
21141 Next_Entity (Prev_Id);
21142 end loop;
21144 Set_Next_Entity (Prev_Id, Next_Entity (Id));
21145 end if;
21147 -- Handle the case where the entity acts as the tail of the scope entity
21148 -- chain.
21150 if Last_Entity (Scop) = Id then
21151 Set_Last_Entity (Scop, Prev_Id);
21152 end if;
21153 end Remove_Entity;
21155 --------------------
21156 -- Remove_Homonym --
21157 --------------------
21159 procedure Remove_Homonym (E : Entity_Id) is
21160 Prev : Entity_Id := Empty;
21161 H : Entity_Id;
21163 begin
21164 if E = Current_Entity (E) then
21165 if Present (Homonym (E)) then
21166 Set_Current_Entity (Homonym (E));
21167 else
21168 Set_Name_Entity_Id (Chars (E), Empty);
21169 end if;
21171 else
21172 H := Current_Entity (E);
21173 while Present (H) and then H /= E loop
21174 Prev := H;
21175 H := Homonym (H);
21176 end loop;
21178 -- If E is not on the homonym chain, nothing to do
21180 if Present (H) then
21181 Set_Homonym (Prev, Homonym (E));
21182 end if;
21183 end if;
21184 end Remove_Homonym;
21186 ------------------------------
21187 -- Remove_Overloaded_Entity --
21188 ------------------------------
21190 procedure Remove_Overloaded_Entity (Id : Entity_Id) is
21191 procedure Remove_Primitive_Of (Typ : Entity_Id);
21192 -- Remove primitive subprogram Id from the list of primitives that
21193 -- belong to type Typ.
21195 -------------------------
21196 -- Remove_Primitive_Of --
21197 -------------------------
21199 procedure Remove_Primitive_Of (Typ : Entity_Id) is
21200 Prims : Elist_Id;
21202 begin
21203 if Is_Tagged_Type (Typ) then
21204 Prims := Direct_Primitive_Operations (Typ);
21206 if Present (Prims) then
21207 Remove (Prims, Id);
21208 end if;
21209 end if;
21210 end Remove_Primitive_Of;
21212 -- Local variables
21214 Formal : Entity_Id;
21216 -- Start of processing for Remove_Overloaded_Entity
21218 begin
21219 -- Remove the entity from both the homonym and scope chains
21221 Remove_Entity (Id);
21223 -- The entity denotes a primitive subprogram. Remove it from the list of
21224 -- primitives of the associated controlling type.
21226 if Ekind_In (Id, E_Function, E_Procedure) and then Is_Primitive (Id) then
21227 Formal := First_Formal (Id);
21228 while Present (Formal) loop
21229 if Is_Controlling_Formal (Formal) then
21230 Remove_Primitive_Of (Etype (Formal));
21231 exit;
21232 end if;
21234 Next_Formal (Formal);
21235 end loop;
21237 if Ekind (Id) = E_Function and then Has_Controlling_Result (Id) then
21238 Remove_Primitive_Of (Etype (Id));
21239 end if;
21240 end if;
21241 end Remove_Overloaded_Entity;
21243 ---------------------
21244 -- Rep_To_Pos_Flag --
21245 ---------------------
21247 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
21248 begin
21249 return New_Occurrence_Of
21250 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
21251 end Rep_To_Pos_Flag;
21253 --------------------
21254 -- Require_Entity --
21255 --------------------
21257 procedure Require_Entity (N : Node_Id) is
21258 begin
21259 if Is_Entity_Name (N) and then No (Entity (N)) then
21260 if Total_Errors_Detected /= 0 then
21261 Set_Entity (N, Any_Id);
21262 else
21263 raise Program_Error;
21264 end if;
21265 end if;
21266 end Require_Entity;
21268 ------------------------------
21269 -- Requires_Transient_Scope --
21270 ------------------------------
21272 -- A transient scope is required when variable-sized temporaries are
21273 -- allocated on the secondary stack, or when finalization actions must be
21274 -- generated before the next instruction.
21276 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
21277 Old_Result : constant Boolean := Old_Requires_Transient_Scope (Id);
21279 begin
21280 if Debug_Flag_QQ then
21281 return Old_Result;
21282 end if;
21284 declare
21285 New_Result : constant Boolean := New_Requires_Transient_Scope (Id);
21287 begin
21288 -- Assert that we're not putting things on the secondary stack if we
21289 -- didn't before; we are trying to AVOID secondary stack when
21290 -- possible.
21292 if not Old_Result then
21293 pragma Assert (not New_Result);
21294 null;
21295 end if;
21297 if New_Result /= Old_Result then
21298 Results_Differ (Id, Old_Result, New_Result);
21299 end if;
21301 return New_Result;
21302 end;
21303 end Requires_Transient_Scope;
21305 --------------------
21306 -- Results_Differ --
21307 --------------------
21309 procedure Results_Differ
21310 (Id : Entity_Id;
21311 Old_Val : Boolean;
21312 New_Val : Boolean)
21314 begin
21315 if False then -- False to disable; True for debugging
21316 Treepr.Print_Tree_Node (Id);
21318 if Old_Val = New_Val then
21319 raise Program_Error;
21320 end if;
21321 end if;
21322 end Results_Differ;
21324 --------------------------
21325 -- Reset_Analyzed_Flags --
21326 --------------------------
21328 procedure Reset_Analyzed_Flags (N : Node_Id) is
21329 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
21330 -- Function used to reset Analyzed flags in tree. Note that we do
21331 -- not reset Analyzed flags in entities, since there is no need to
21332 -- reanalyze entities, and indeed, it is wrong to do so, since it
21333 -- can result in generating auxiliary stuff more than once.
21335 --------------------
21336 -- Clear_Analyzed --
21337 --------------------
21339 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
21340 begin
21341 if Nkind (N) not in N_Entity then
21342 Set_Analyzed (N, False);
21343 end if;
21345 return OK;
21346 end Clear_Analyzed;
21348 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
21350 -- Start of processing for Reset_Analyzed_Flags
21352 begin
21353 Reset_Analyzed (N);
21354 end Reset_Analyzed_Flags;
21356 ------------------------
21357 -- Restore_SPARK_Mode --
21358 ------------------------
21360 procedure Restore_SPARK_Mode
21361 (Mode : SPARK_Mode_Type;
21362 Prag : Node_Id)
21364 begin
21365 SPARK_Mode := Mode;
21366 SPARK_Mode_Pragma := Prag;
21367 end Restore_SPARK_Mode;
21369 --------------------------------
21370 -- Returns_Unconstrained_Type --
21371 --------------------------------
21373 function Returns_Unconstrained_Type (Subp : Entity_Id) return Boolean is
21374 begin
21375 return Ekind (Subp) = E_Function
21376 and then not Is_Scalar_Type (Etype (Subp))
21377 and then not Is_Access_Type (Etype (Subp))
21378 and then not Is_Constrained (Etype (Subp));
21379 end Returns_Unconstrained_Type;
21381 ----------------------------
21382 -- Root_Type_Of_Full_View --
21383 ----------------------------
21385 function Root_Type_Of_Full_View (T : Entity_Id) return Entity_Id is
21386 Rtyp : constant Entity_Id := Root_Type (T);
21388 begin
21389 -- The root type of the full view may itself be a private type. Keep
21390 -- looking for the ultimate derivation parent.
21392 if Is_Private_Type (Rtyp) and then Present (Full_View (Rtyp)) then
21393 return Root_Type_Of_Full_View (Full_View (Rtyp));
21394 else
21395 return Rtyp;
21396 end if;
21397 end Root_Type_Of_Full_View;
21399 ---------------------------
21400 -- Safe_To_Capture_Value --
21401 ---------------------------
21403 function Safe_To_Capture_Value
21404 (N : Node_Id;
21405 Ent : Entity_Id;
21406 Cond : Boolean := False) return Boolean
21408 begin
21409 -- The only entities for which we track constant values are variables
21410 -- which are not renamings, constants, out parameters, and in out
21411 -- parameters, so check if we have this case.
21413 -- Note: it may seem odd to track constant values for constants, but in
21414 -- fact this routine is used for other purposes than simply capturing
21415 -- the value. In particular, the setting of Known[_Non]_Null.
21417 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
21418 or else
21419 Ekind_In (Ent, E_Constant, E_Out_Parameter, E_In_Out_Parameter)
21420 then
21421 null;
21423 -- For conditionals, we also allow loop parameters and all formals,
21424 -- including in parameters.
21426 elsif Cond and then Ekind_In (Ent, E_Loop_Parameter, E_In_Parameter) then
21427 null;
21429 -- For all other cases, not just unsafe, but impossible to capture
21430 -- Current_Value, since the above are the only entities which have
21431 -- Current_Value fields.
21433 else
21434 return False;
21435 end if;
21437 -- Skip if volatile or aliased, since funny things might be going on in
21438 -- these cases which we cannot necessarily track. Also skip any variable
21439 -- for which an address clause is given, or whose address is taken. Also
21440 -- never capture value of library level variables (an attempt to do so
21441 -- can occur in the case of package elaboration code).
21443 if Treat_As_Volatile (Ent)
21444 or else Is_Aliased (Ent)
21445 or else Present (Address_Clause (Ent))
21446 or else Address_Taken (Ent)
21447 or else (Is_Library_Level_Entity (Ent)
21448 and then Ekind (Ent) = E_Variable)
21449 then
21450 return False;
21451 end if;
21453 -- OK, all above conditions are met. We also require that the scope of
21454 -- the reference be the same as the scope of the entity, not counting
21455 -- packages and blocks and loops.
21457 declare
21458 E_Scope : constant Entity_Id := Scope (Ent);
21459 R_Scope : Entity_Id;
21461 begin
21462 R_Scope := Current_Scope;
21463 while R_Scope /= Standard_Standard loop
21464 exit when R_Scope = E_Scope;
21466 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
21467 return False;
21468 else
21469 R_Scope := Scope (R_Scope);
21470 end if;
21471 end loop;
21472 end;
21474 -- We also require that the reference does not appear in a context
21475 -- where it is not sure to be executed (i.e. a conditional context
21476 -- or an exception handler). We skip this if Cond is True, since the
21477 -- capturing of values from conditional tests handles this ok.
21479 if Cond then
21480 return True;
21481 end if;
21483 declare
21484 Desc : Node_Id;
21485 P : Node_Id;
21487 begin
21488 Desc := N;
21490 -- Seems dubious that case expressions are not handled here ???
21492 P := Parent (N);
21493 while Present (P) loop
21494 if Nkind (P) = N_If_Statement
21495 or else Nkind (P) = N_Case_Statement
21496 or else (Nkind (P) in N_Short_Circuit
21497 and then Desc = Right_Opnd (P))
21498 or else (Nkind (P) = N_If_Expression
21499 and then Desc /= First (Expressions (P)))
21500 or else Nkind (P) = N_Exception_Handler
21501 or else Nkind (P) = N_Selective_Accept
21502 or else Nkind (P) = N_Conditional_Entry_Call
21503 or else Nkind (P) = N_Timed_Entry_Call
21504 or else Nkind (P) = N_Asynchronous_Select
21505 then
21506 return False;
21508 else
21509 Desc := P;
21510 P := Parent (P);
21512 -- A special Ada 2012 case: the original node may be part
21513 -- of the else_actions of a conditional expression, in which
21514 -- case it might not have been expanded yet, and appears in
21515 -- a non-syntactic list of actions. In that case it is clearly
21516 -- not safe to save a value.
21518 if No (P)
21519 and then Is_List_Member (Desc)
21520 and then No (Parent (List_Containing (Desc)))
21521 then
21522 return False;
21523 end if;
21524 end if;
21525 end loop;
21526 end;
21528 -- OK, looks safe to set value
21530 return True;
21531 end Safe_To_Capture_Value;
21533 ---------------
21534 -- Same_Name --
21535 ---------------
21537 function Same_Name (N1, N2 : Node_Id) return Boolean is
21538 K1 : constant Node_Kind := Nkind (N1);
21539 K2 : constant Node_Kind := Nkind (N2);
21541 begin
21542 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
21543 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
21544 then
21545 return Chars (N1) = Chars (N2);
21547 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
21548 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
21549 then
21550 return Same_Name (Selector_Name (N1), Selector_Name (N2))
21551 and then Same_Name (Prefix (N1), Prefix (N2));
21553 else
21554 return False;
21555 end if;
21556 end Same_Name;
21558 -----------------
21559 -- Same_Object --
21560 -----------------
21562 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
21563 N1 : constant Node_Id := Original_Node (Node1);
21564 N2 : constant Node_Id := Original_Node (Node2);
21565 -- We do the tests on original nodes, since we are most interested
21566 -- in the original source, not any expansion that got in the way.
21568 K1 : constant Node_Kind := Nkind (N1);
21569 K2 : constant Node_Kind := Nkind (N2);
21571 begin
21572 -- First case, both are entities with same entity
21574 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
21575 declare
21576 EN1 : constant Entity_Id := Entity (N1);
21577 EN2 : constant Entity_Id := Entity (N2);
21578 begin
21579 if Present (EN1) and then Present (EN2)
21580 and then (Ekind_In (EN1, E_Variable, E_Constant)
21581 or else Is_Formal (EN1))
21582 and then EN1 = EN2
21583 then
21584 return True;
21585 end if;
21586 end;
21587 end if;
21589 -- Second case, selected component with same selector, same record
21591 if K1 = N_Selected_Component
21592 and then K2 = N_Selected_Component
21593 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
21594 then
21595 return Same_Object (Prefix (N1), Prefix (N2));
21597 -- Third case, indexed component with same subscripts, same array
21599 elsif K1 = N_Indexed_Component
21600 and then K2 = N_Indexed_Component
21601 and then Same_Object (Prefix (N1), Prefix (N2))
21602 then
21603 declare
21604 E1, E2 : Node_Id;
21605 begin
21606 E1 := First (Expressions (N1));
21607 E2 := First (Expressions (N2));
21608 while Present (E1) loop
21609 if not Same_Value (E1, E2) then
21610 return False;
21611 else
21612 Next (E1);
21613 Next (E2);
21614 end if;
21615 end loop;
21617 return True;
21618 end;
21620 -- Fourth case, slice of same array with same bounds
21622 elsif K1 = N_Slice
21623 and then K2 = N_Slice
21624 and then Nkind (Discrete_Range (N1)) = N_Range
21625 and then Nkind (Discrete_Range (N2)) = N_Range
21626 and then Same_Value (Low_Bound (Discrete_Range (N1)),
21627 Low_Bound (Discrete_Range (N2)))
21628 and then Same_Value (High_Bound (Discrete_Range (N1)),
21629 High_Bound (Discrete_Range (N2)))
21630 then
21631 return Same_Name (Prefix (N1), Prefix (N2));
21633 -- All other cases, not clearly the same object
21635 else
21636 return False;
21637 end if;
21638 end Same_Object;
21640 ---------------
21641 -- Same_Type --
21642 ---------------
21644 function Same_Type (T1, T2 : Entity_Id) return Boolean is
21645 begin
21646 if T1 = T2 then
21647 return True;
21649 elsif not Is_Constrained (T1)
21650 and then not Is_Constrained (T2)
21651 and then Base_Type (T1) = Base_Type (T2)
21652 then
21653 return True;
21655 -- For now don't bother with case of identical constraints, to be
21656 -- fiddled with later on perhaps (this is only used for optimization
21657 -- purposes, so it is not critical to do a best possible job)
21659 else
21660 return False;
21661 end if;
21662 end Same_Type;
21664 ----------------
21665 -- Same_Value --
21666 ----------------
21668 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
21669 begin
21670 if Compile_Time_Known_Value (Node1)
21671 and then Compile_Time_Known_Value (Node2)
21672 then
21673 -- Handle properly compile-time expressions that are not
21674 -- scalar.
21676 if Is_String_Type (Etype (Node1)) then
21677 return Expr_Value_S (Node1) = Expr_Value_S (Node2);
21679 else
21680 return Expr_Value (Node1) = Expr_Value (Node2);
21681 end if;
21683 elsif Same_Object (Node1, Node2) then
21684 return True;
21685 else
21686 return False;
21687 end if;
21688 end Same_Value;
21690 --------------------
21691 -- Set_SPARK_Mode --
21692 --------------------
21694 procedure Set_SPARK_Mode (Context : Entity_Id) is
21695 begin
21696 -- Do not consider illegal or partially decorated constructs
21698 if Ekind (Context) = E_Void or else Error_Posted (Context) then
21699 null;
21701 elsif Present (SPARK_Pragma (Context)) then
21702 Install_SPARK_Mode
21703 (Mode => Get_SPARK_Mode_From_Annotation (SPARK_Pragma (Context)),
21704 Prag => SPARK_Pragma (Context));
21705 end if;
21706 end Set_SPARK_Mode;
21708 -------------------------
21709 -- Scalar_Part_Present --
21710 -------------------------
21712 function Scalar_Part_Present (T : Entity_Id) return Boolean is
21713 C : Entity_Id;
21715 begin
21716 if Is_Scalar_Type (T) then
21717 return True;
21719 elsif Is_Array_Type (T) then
21720 return Scalar_Part_Present (Component_Type (T));
21722 elsif Is_Record_Type (T) or else Has_Discriminants (T) then
21723 C := First_Component_Or_Discriminant (T);
21724 while Present (C) loop
21725 if Scalar_Part_Present (Etype (C)) then
21726 return True;
21727 else
21728 Next_Component_Or_Discriminant (C);
21729 end if;
21730 end loop;
21731 end if;
21733 return False;
21734 end Scalar_Part_Present;
21736 ------------------------
21737 -- Scope_Is_Transient --
21738 ------------------------
21740 function Scope_Is_Transient return Boolean is
21741 begin
21742 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
21743 end Scope_Is_Transient;
21745 ------------------
21746 -- Scope_Within --
21747 ------------------
21749 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
21750 Scop : Entity_Id;
21752 begin
21753 Scop := Scope1;
21754 while Scop /= Standard_Standard loop
21755 Scop := Scope (Scop);
21757 if Scop = Scope2 then
21758 return True;
21759 end if;
21760 end loop;
21762 return False;
21763 end Scope_Within;
21765 --------------------------
21766 -- Scope_Within_Or_Same --
21767 --------------------------
21769 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
21770 Scop : Entity_Id;
21772 begin
21773 Scop := Scope1;
21774 while Scop /= Standard_Standard loop
21775 if Scop = Scope2 then
21776 return True;
21777 else
21778 Scop := Scope (Scop);
21779 end if;
21780 end loop;
21782 return False;
21783 end Scope_Within_Or_Same;
21785 --------------------
21786 -- Set_Convention --
21787 --------------------
21789 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
21790 begin
21791 Basic_Set_Convention (E, Val);
21793 if Is_Type (E)
21794 and then Is_Access_Subprogram_Type (Base_Type (E))
21795 and then Has_Foreign_Convention (E)
21796 then
21798 -- A pragma Convention in an instance may apply to the subtype
21799 -- created for a formal, in which case we have already verified
21800 -- that conventions of actual and formal match and there is nothing
21801 -- to flag on the subtype.
21803 if In_Instance then
21804 null;
21805 else
21806 Set_Can_Use_Internal_Rep (E, False);
21807 end if;
21808 end if;
21810 -- If E is an object or component, and the type of E is an anonymous
21811 -- access type with no convention set, then also set the convention of
21812 -- the anonymous access type. We do not do this for anonymous protected
21813 -- types, since protected types always have the default convention.
21815 if Present (Etype (E))
21816 and then (Is_Object (E)
21817 or else Ekind (E) = E_Component
21819 -- Allow E_Void (happens for pragma Convention appearing
21820 -- in the middle of a record applying to a component)
21822 or else Ekind (E) = E_Void)
21823 then
21824 declare
21825 Typ : constant Entity_Id := Etype (E);
21827 begin
21828 if Ekind_In (Typ, E_Anonymous_Access_Type,
21829 E_Anonymous_Access_Subprogram_Type)
21830 and then not Has_Convention_Pragma (Typ)
21831 then
21832 Basic_Set_Convention (Typ, Val);
21833 Set_Has_Convention_Pragma (Typ);
21835 -- And for the access subprogram type, deal similarly with the
21836 -- designated E_Subprogram_Type if it is also internal (which
21837 -- it always is?)
21839 if Ekind (Typ) = E_Anonymous_Access_Subprogram_Type then
21840 declare
21841 Dtype : constant Entity_Id := Designated_Type (Typ);
21842 begin
21843 if Ekind (Dtype) = E_Subprogram_Type
21844 and then Is_Itype (Dtype)
21845 and then not Has_Convention_Pragma (Dtype)
21846 then
21847 Basic_Set_Convention (Dtype, Val);
21848 Set_Has_Convention_Pragma (Dtype);
21849 end if;
21850 end;
21851 end if;
21852 end if;
21853 end;
21854 end if;
21855 end Set_Convention;
21857 ------------------------
21858 -- Set_Current_Entity --
21859 ------------------------
21861 -- The given entity is to be set as the currently visible definition of its
21862 -- associated name (i.e. the Node_Id associated with its name). All we have
21863 -- to do is to get the name from the identifier, and then set the
21864 -- associated Node_Id to point to the given entity.
21866 procedure Set_Current_Entity (E : Entity_Id) is
21867 begin
21868 Set_Name_Entity_Id (Chars (E), E);
21869 end Set_Current_Entity;
21871 ---------------------------
21872 -- Set_Debug_Info_Needed --
21873 ---------------------------
21875 procedure Set_Debug_Info_Needed (T : Entity_Id) is
21877 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
21878 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
21879 -- Used to set debug info in a related node if not set already
21881 --------------------------------------
21882 -- Set_Debug_Info_Needed_If_Not_Set --
21883 --------------------------------------
21885 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
21886 begin
21887 if Present (E) and then not Needs_Debug_Info (E) then
21888 Set_Debug_Info_Needed (E);
21890 -- For a private type, indicate that the full view also needs
21891 -- debug information.
21893 if Is_Type (E)
21894 and then Is_Private_Type (E)
21895 and then Present (Full_View (E))
21896 then
21897 Set_Debug_Info_Needed (Full_View (E));
21898 end if;
21899 end if;
21900 end Set_Debug_Info_Needed_If_Not_Set;
21902 -- Start of processing for Set_Debug_Info_Needed
21904 begin
21905 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
21906 -- indicates that Debug_Info_Needed is never required for the entity.
21907 -- Nothing to do if entity comes from a predefined file. Library files
21908 -- are compiled without debug information, but inlined bodies of these
21909 -- routines may appear in user code, and debug information on them ends
21910 -- up complicating debugging the user code.
21912 if No (T)
21913 or else Debug_Info_Off (T)
21914 then
21915 return;
21917 elsif In_Inlined_Body and then In_Predefined_Unit (T) then
21918 Set_Needs_Debug_Info (T, False);
21919 end if;
21921 -- Set flag in entity itself. Note that we will go through the following
21922 -- circuitry even if the flag is already set on T. That's intentional,
21923 -- it makes sure that the flag will be set in subsidiary entities.
21925 Set_Needs_Debug_Info (T);
21927 -- Set flag on subsidiary entities if not set already
21929 if Is_Object (T) then
21930 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
21932 elsif Is_Type (T) then
21933 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
21935 if Is_Record_Type (T) then
21936 declare
21937 Ent : Entity_Id := First_Entity (T);
21938 begin
21939 while Present (Ent) loop
21940 Set_Debug_Info_Needed_If_Not_Set (Ent);
21941 Next_Entity (Ent);
21942 end loop;
21943 end;
21945 -- For a class wide subtype, we also need debug information
21946 -- for the equivalent type.
21948 if Ekind (T) = E_Class_Wide_Subtype then
21949 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
21950 end if;
21952 elsif Is_Array_Type (T) then
21953 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
21955 declare
21956 Indx : Node_Id := First_Index (T);
21957 begin
21958 while Present (Indx) loop
21959 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
21960 Indx := Next_Index (Indx);
21961 end loop;
21962 end;
21964 -- For a packed array type, we also need debug information for
21965 -- the type used to represent the packed array. Conversely, we
21966 -- also need it for the former if we need it for the latter.
21968 if Is_Packed (T) then
21969 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Impl_Type (T));
21970 end if;
21972 if Is_Packed_Array_Impl_Type (T) then
21973 Set_Debug_Info_Needed_If_Not_Set (Original_Array_Type (T));
21974 end if;
21976 elsif Is_Access_Type (T) then
21977 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
21979 elsif Is_Private_Type (T) then
21980 declare
21981 FV : constant Entity_Id := Full_View (T);
21983 begin
21984 Set_Debug_Info_Needed_If_Not_Set (FV);
21986 -- If the full view is itself a derived private type, we need
21987 -- debug information on its underlying type.
21989 if Present (FV)
21990 and then Is_Private_Type (FV)
21991 and then Present (Underlying_Full_View (FV))
21992 then
21993 Set_Needs_Debug_Info (Underlying_Full_View (FV));
21994 end if;
21995 end;
21997 elsif Is_Protected_Type (T) then
21998 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
22000 elsif Is_Scalar_Type (T) then
22002 -- If the subrange bounds are materialized by dedicated constant
22003 -- objects, also include them in the debug info to make sure the
22004 -- debugger can properly use them.
22006 if Present (Scalar_Range (T))
22007 and then Nkind (Scalar_Range (T)) = N_Range
22008 then
22009 declare
22010 Low_Bnd : constant Node_Id := Type_Low_Bound (T);
22011 High_Bnd : constant Node_Id := Type_High_Bound (T);
22013 begin
22014 if Is_Entity_Name (Low_Bnd) then
22015 Set_Debug_Info_Needed_If_Not_Set (Entity (Low_Bnd));
22016 end if;
22018 if Is_Entity_Name (High_Bnd) then
22019 Set_Debug_Info_Needed_If_Not_Set (Entity (High_Bnd));
22020 end if;
22021 end;
22022 end if;
22023 end if;
22024 end if;
22025 end Set_Debug_Info_Needed;
22027 ----------------------------
22028 -- Set_Entity_With_Checks --
22029 ----------------------------
22031 procedure Set_Entity_With_Checks (N : Node_Id; Val : Entity_Id) is
22032 Val_Actual : Entity_Id;
22033 Nod : Node_Id;
22034 Post_Node : Node_Id;
22036 begin
22037 -- Unconditionally set the entity
22039 Set_Entity (N, Val);
22041 -- The node to post on is the selector in the case of an expanded name,
22042 -- and otherwise the node itself.
22044 if Nkind (N) = N_Expanded_Name then
22045 Post_Node := Selector_Name (N);
22046 else
22047 Post_Node := N;
22048 end if;
22050 -- Check for violation of No_Fixed_IO
22052 if Restriction_Check_Required (No_Fixed_IO)
22053 and then
22054 ((RTU_Loaded (Ada_Text_IO)
22055 and then (Is_RTE (Val, RE_Decimal_IO)
22056 or else
22057 Is_RTE (Val, RE_Fixed_IO)))
22059 or else
22060 (RTU_Loaded (Ada_Wide_Text_IO)
22061 and then (Is_RTE (Val, RO_WT_Decimal_IO)
22062 or else
22063 Is_RTE (Val, RO_WT_Fixed_IO)))
22065 or else
22066 (RTU_Loaded (Ada_Wide_Wide_Text_IO)
22067 and then (Is_RTE (Val, RO_WW_Decimal_IO)
22068 or else
22069 Is_RTE (Val, RO_WW_Fixed_IO))))
22071 -- A special extra check, don't complain about a reference from within
22072 -- the Ada.Interrupts package itself!
22074 and then not In_Same_Extended_Unit (N, Val)
22075 then
22076 Check_Restriction (No_Fixed_IO, Post_Node);
22077 end if;
22079 -- Remaining checks are only done on source nodes. Note that we test
22080 -- for violation of No_Fixed_IO even on non-source nodes, because the
22081 -- cases for checking violations of this restriction are instantiations
22082 -- where the reference in the instance has Comes_From_Source False.
22084 if not Comes_From_Source (N) then
22085 return;
22086 end if;
22088 -- Check for violation of No_Abort_Statements, which is triggered by
22089 -- call to Ada.Task_Identification.Abort_Task.
22091 if Restriction_Check_Required (No_Abort_Statements)
22092 and then (Is_RTE (Val, RE_Abort_Task))
22094 -- A special extra check, don't complain about a reference from within
22095 -- the Ada.Task_Identification package itself!
22097 and then not In_Same_Extended_Unit (N, Val)
22098 then
22099 Check_Restriction (No_Abort_Statements, Post_Node);
22100 end if;
22102 if Val = Standard_Long_Long_Integer then
22103 Check_Restriction (No_Long_Long_Integers, Post_Node);
22104 end if;
22106 -- Check for violation of No_Dynamic_Attachment
22108 if Restriction_Check_Required (No_Dynamic_Attachment)
22109 and then RTU_Loaded (Ada_Interrupts)
22110 and then (Is_RTE (Val, RE_Is_Reserved) or else
22111 Is_RTE (Val, RE_Is_Attached) or else
22112 Is_RTE (Val, RE_Current_Handler) or else
22113 Is_RTE (Val, RE_Attach_Handler) or else
22114 Is_RTE (Val, RE_Exchange_Handler) or else
22115 Is_RTE (Val, RE_Detach_Handler) or else
22116 Is_RTE (Val, RE_Reference))
22118 -- A special extra check, don't complain about a reference from within
22119 -- the Ada.Interrupts package itself!
22121 and then not In_Same_Extended_Unit (N, Val)
22122 then
22123 Check_Restriction (No_Dynamic_Attachment, Post_Node);
22124 end if;
22126 -- Check for No_Implementation_Identifiers
22128 if Restriction_Check_Required (No_Implementation_Identifiers) then
22130 -- We have an implementation defined entity if it is marked as
22131 -- implementation defined, or is defined in a package marked as
22132 -- implementation defined. However, library packages themselves
22133 -- are excluded (we don't want to flag Interfaces itself, just
22134 -- the entities within it).
22136 if (Is_Implementation_Defined (Val)
22137 or else
22138 (Present (Scope (Val))
22139 and then Is_Implementation_Defined (Scope (Val))))
22140 and then not (Ekind_In (Val, E_Package, E_Generic_Package)
22141 and then Is_Library_Level_Entity (Val))
22142 then
22143 Check_Restriction (No_Implementation_Identifiers, Post_Node);
22144 end if;
22145 end if;
22147 -- Do the style check
22149 if Style_Check
22150 and then not Suppress_Style_Checks (Val)
22151 and then not In_Instance
22152 then
22153 if Nkind (N) = N_Identifier then
22154 Nod := N;
22155 elsif Nkind (N) = N_Expanded_Name then
22156 Nod := Selector_Name (N);
22157 else
22158 return;
22159 end if;
22161 -- A special situation arises for derived operations, where we want
22162 -- to do the check against the parent (since the Sloc of the derived
22163 -- operation points to the derived type declaration itself).
22165 Val_Actual := Val;
22166 while not Comes_From_Source (Val_Actual)
22167 and then Nkind (Val_Actual) in N_Entity
22168 and then (Ekind (Val_Actual) = E_Enumeration_Literal
22169 or else Is_Subprogram_Or_Generic_Subprogram (Val_Actual))
22170 and then Present (Alias (Val_Actual))
22171 loop
22172 Val_Actual := Alias (Val_Actual);
22173 end loop;
22175 -- Renaming declarations for generic actuals do not come from source,
22176 -- and have a different name from that of the entity they rename, so
22177 -- there is no style check to perform here.
22179 if Chars (Nod) = Chars (Val_Actual) then
22180 Style.Check_Identifier (Nod, Val_Actual);
22181 end if;
22182 end if;
22184 Set_Entity (N, Val);
22185 end Set_Entity_With_Checks;
22187 ------------------------
22188 -- Set_Name_Entity_Id --
22189 ------------------------
22191 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
22192 begin
22193 Set_Name_Table_Int (Id, Int (Val));
22194 end Set_Name_Entity_Id;
22196 ---------------------
22197 -- Set_Next_Actual --
22198 ---------------------
22200 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
22201 begin
22202 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
22203 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
22204 end if;
22205 end Set_Next_Actual;
22207 ----------------------------------
22208 -- Set_Optimize_Alignment_Flags --
22209 ----------------------------------
22211 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
22212 begin
22213 if Optimize_Alignment = 'S' then
22214 Set_Optimize_Alignment_Space (E);
22215 elsif Optimize_Alignment = 'T' then
22216 Set_Optimize_Alignment_Time (E);
22217 end if;
22218 end Set_Optimize_Alignment_Flags;
22220 -----------------------
22221 -- Set_Public_Status --
22222 -----------------------
22224 procedure Set_Public_Status (Id : Entity_Id) is
22225 S : constant Entity_Id := Current_Scope;
22227 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
22228 -- Determines if E is defined within handled statement sequence or
22229 -- an if statement, returns True if so, False otherwise.
22231 ----------------------
22232 -- Within_HSS_Or_If --
22233 ----------------------
22235 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
22236 N : Node_Id;
22237 begin
22238 N := Declaration_Node (E);
22239 loop
22240 N := Parent (N);
22242 if No (N) then
22243 return False;
22245 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
22246 N_If_Statement)
22247 then
22248 return True;
22249 end if;
22250 end loop;
22251 end Within_HSS_Or_If;
22253 -- Start of processing for Set_Public_Status
22255 begin
22256 -- Everything in the scope of Standard is public
22258 if S = Standard_Standard then
22259 Set_Is_Public (Id);
22261 -- Entity is definitely not public if enclosing scope is not public
22263 elsif not Is_Public (S) then
22264 return;
22266 -- An object or function declaration that occurs in a handled sequence
22267 -- of statements or within an if statement is the declaration for a
22268 -- temporary object or local subprogram generated by the expander. It
22269 -- never needs to be made public and furthermore, making it public can
22270 -- cause back end problems.
22272 elsif Nkind_In (Parent (Id), N_Object_Declaration,
22273 N_Function_Specification)
22274 and then Within_HSS_Or_If (Id)
22275 then
22276 return;
22278 -- Entities in public packages or records are public
22280 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
22281 Set_Is_Public (Id);
22283 -- The bounds of an entry family declaration can generate object
22284 -- declarations that are visible to the back-end, e.g. in the
22285 -- the declaration of a composite type that contains tasks.
22287 elsif Is_Concurrent_Type (S)
22288 and then not Has_Completion (S)
22289 and then Nkind (Parent (Id)) = N_Object_Declaration
22290 then
22291 Set_Is_Public (Id);
22292 end if;
22293 end Set_Public_Status;
22295 -----------------------------
22296 -- Set_Referenced_Modified --
22297 -----------------------------
22299 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
22300 Pref : Node_Id;
22302 begin
22303 -- Deal with indexed or selected component where prefix is modified
22305 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
22306 Pref := Prefix (N);
22308 -- If prefix is access type, then it is the designated object that is
22309 -- being modified, which means we have no entity to set the flag on.
22311 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
22312 return;
22314 -- Otherwise chase the prefix
22316 else
22317 Set_Referenced_Modified (Pref, Out_Param);
22318 end if;
22320 -- Otherwise see if we have an entity name (only other case to process)
22322 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
22323 Set_Referenced_As_LHS (Entity (N), not Out_Param);
22324 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
22325 end if;
22326 end Set_Referenced_Modified;
22328 ------------------
22329 -- Set_Rep_Info --
22330 ------------------
22332 procedure Set_Rep_Info (T1 : Entity_Id; T2 : Entity_Id) is
22333 begin
22334 Set_Is_Atomic (T1, Is_Atomic (T2));
22335 Set_Is_Independent (T1, Is_Independent (T2));
22336 Set_Is_Volatile_Full_Access (T1, Is_Volatile_Full_Access (T2));
22338 if Is_Base_Type (T1) then
22339 Set_Is_Volatile (T1, Is_Volatile (T2));
22340 end if;
22341 end Set_Rep_Info;
22343 ----------------------------
22344 -- Set_Scope_Is_Transient --
22345 ----------------------------
22347 procedure Set_Scope_Is_Transient (V : Boolean := True) is
22348 begin
22349 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
22350 end Set_Scope_Is_Transient;
22352 -------------------
22353 -- Set_Size_Info --
22354 -------------------
22356 procedure Set_Size_Info (T1, T2 : Entity_Id) is
22357 begin
22358 -- We copy Esize, but not RM_Size, since in general RM_Size is
22359 -- subtype specific and does not get inherited by all subtypes.
22361 Set_Esize (T1, Esize (T2));
22362 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
22364 if Is_Discrete_Or_Fixed_Point_Type (T1)
22365 and then
22366 Is_Discrete_Or_Fixed_Point_Type (T2)
22367 then
22368 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
22369 end if;
22371 Set_Alignment (T1, Alignment (T2));
22372 end Set_Size_Info;
22374 ------------------------------
22375 -- Should_Ignore_Pragma_Par --
22376 ------------------------------
22378 function Should_Ignore_Pragma_Par (Prag_Name : Name_Id) return Boolean is
22379 pragma Assert (Compiler_State = Parsing);
22380 -- This one can't work during semantic analysis, because we don't have a
22381 -- correct Current_Source_File.
22383 Result : constant Boolean :=
22384 Get_Name_Table_Boolean3 (Prag_Name)
22385 and then not Is_Internal_File_Name
22386 (File_Name (Current_Source_File));
22387 begin
22388 return Result;
22389 end Should_Ignore_Pragma_Par;
22391 ------------------------------
22392 -- Should_Ignore_Pragma_Sem --
22393 ------------------------------
22395 function Should_Ignore_Pragma_Sem (N : Node_Id) return Boolean is
22396 pragma Assert (Compiler_State = Analyzing);
22397 Prag_Name : constant Name_Id := Pragma_Name (N);
22398 Result : constant Boolean :=
22399 Get_Name_Table_Boolean3 (Prag_Name)
22400 and then not In_Internal_Unit (N);
22402 begin
22403 return Result;
22404 end Should_Ignore_Pragma_Sem;
22406 --------------------
22407 -- Static_Boolean --
22408 --------------------
22410 function Static_Boolean (N : Node_Id) return Uint is
22411 begin
22412 Analyze_And_Resolve (N, Standard_Boolean);
22414 if N = Error
22415 or else Error_Posted (N)
22416 or else Etype (N) = Any_Type
22417 then
22418 return No_Uint;
22419 end if;
22421 if Is_OK_Static_Expression (N) then
22422 if not Raises_Constraint_Error (N) then
22423 return Expr_Value (N);
22424 else
22425 return No_Uint;
22426 end if;
22428 elsif Etype (N) = Any_Type then
22429 return No_Uint;
22431 else
22432 Flag_Non_Static_Expr
22433 ("static boolean expression required here", N);
22434 return No_Uint;
22435 end if;
22436 end Static_Boolean;
22438 --------------------
22439 -- Static_Integer --
22440 --------------------
22442 function Static_Integer (N : Node_Id) return Uint is
22443 begin
22444 Analyze_And_Resolve (N, Any_Integer);
22446 if N = Error
22447 or else Error_Posted (N)
22448 or else Etype (N) = Any_Type
22449 then
22450 return No_Uint;
22451 end if;
22453 if Is_OK_Static_Expression (N) then
22454 if not Raises_Constraint_Error (N) then
22455 return Expr_Value (N);
22456 else
22457 return No_Uint;
22458 end if;
22460 elsif Etype (N) = Any_Type then
22461 return No_Uint;
22463 else
22464 Flag_Non_Static_Expr
22465 ("static integer expression required here", N);
22466 return No_Uint;
22467 end if;
22468 end Static_Integer;
22470 --------------------------
22471 -- Statically_Different --
22472 --------------------------
22474 function Statically_Different (E1, E2 : Node_Id) return Boolean is
22475 R1 : constant Node_Id := Get_Referenced_Object (E1);
22476 R2 : constant Node_Id := Get_Referenced_Object (E2);
22477 begin
22478 return Is_Entity_Name (R1)
22479 and then Is_Entity_Name (R2)
22480 and then Entity (R1) /= Entity (R2)
22481 and then not Is_Formal (Entity (R1))
22482 and then not Is_Formal (Entity (R2));
22483 end Statically_Different;
22485 --------------------------------------
22486 -- Subject_To_Loop_Entry_Attributes --
22487 --------------------------------------
22489 function Subject_To_Loop_Entry_Attributes (N : Node_Id) return Boolean is
22490 Stmt : Node_Id;
22492 begin
22493 Stmt := N;
22495 -- The expansion mechanism transform a loop subject to at least one
22496 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
22497 -- the conditional part.
22499 if Nkind_In (Stmt, N_Block_Statement, N_If_Statement)
22500 and then Nkind (Original_Node (N)) = N_Loop_Statement
22501 then
22502 Stmt := Original_Node (N);
22503 end if;
22505 return
22506 Nkind (Stmt) = N_Loop_Statement
22507 and then Present (Identifier (Stmt))
22508 and then Present (Entity (Identifier (Stmt)))
22509 and then Has_Loop_Entry_Attributes (Entity (Identifier (Stmt)));
22510 end Subject_To_Loop_Entry_Attributes;
22512 -----------------------------
22513 -- Subprogram_Access_Level --
22514 -----------------------------
22516 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
22517 begin
22518 if Present (Alias (Subp)) then
22519 return Subprogram_Access_Level (Alias (Subp));
22520 else
22521 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
22522 end if;
22523 end Subprogram_Access_Level;
22525 ---------------------
22526 -- Subprogram_Name --
22527 ---------------------
22529 function Subprogram_Name (N : Node_Id) return String is
22530 Buf : Bounded_String;
22531 Ent : Node_Id := N;
22533 begin
22534 while Present (Ent) loop
22535 case Nkind (Ent) is
22536 when N_Subprogram_Body =>
22537 Ent := Defining_Unit_Name (Specification (Ent));
22538 exit;
22540 when N_Package_Body
22541 | N_Package_Specification
22542 | N_Subprogram_Specification
22544 Ent := Defining_Unit_Name (Ent);
22545 exit;
22547 when N_Protected_Body
22548 | N_Protected_Type_Declaration
22549 | N_Task_Body
22551 exit;
22553 when others =>
22554 null;
22555 end case;
22557 Ent := Parent (Ent);
22558 end loop;
22560 if No (Ent) then
22561 return "unknown subprogram";
22562 end if;
22564 Append_Entity_Name (Buf, Ent);
22565 return +Buf;
22566 end Subprogram_Name;
22568 -------------------------------
22569 -- Support_Atomic_Primitives --
22570 -------------------------------
22572 function Support_Atomic_Primitives (Typ : Entity_Id) return Boolean is
22573 Size : Int;
22575 begin
22576 -- Verify the alignment of Typ is known
22578 if not Known_Alignment (Typ) then
22579 return False;
22580 end if;
22582 if Known_Static_Esize (Typ) then
22583 Size := UI_To_Int (Esize (Typ));
22585 -- If the Esize (Object_Size) is unknown at compile time, look at the
22586 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
22588 elsif Known_Static_RM_Size (Typ) then
22589 Size := UI_To_Int (RM_Size (Typ));
22591 -- Otherwise, the size is considered to be unknown.
22593 else
22594 return False;
22595 end if;
22597 -- Check that the size of the component is 8, 16, 32, or 64 bits and
22598 -- that Typ is properly aligned.
22600 case Size is
22601 when 8 | 16 | 32 | 64 =>
22602 return Size = UI_To_Int (Alignment (Typ)) * 8;
22604 when others =>
22605 return False;
22606 end case;
22607 end Support_Atomic_Primitives;
22609 -----------------
22610 -- Trace_Scope --
22611 -----------------
22613 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
22614 begin
22615 if Debug_Flag_W then
22616 for J in 0 .. Scope_Stack.Last loop
22617 Write_Str (" ");
22618 end loop;
22620 Write_Str (Msg);
22621 Write_Name (Chars (E));
22622 Write_Str (" from ");
22623 Write_Location (Sloc (N));
22624 Write_Eol;
22625 end if;
22626 end Trace_Scope;
22628 -----------------------
22629 -- Transfer_Entities --
22630 -----------------------
22632 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
22633 procedure Set_Public_Status_Of (Id : Entity_Id);
22634 -- Set the Is_Public attribute of arbitrary entity Id by calling routine
22635 -- Set_Public_Status. If successful and Id denotes a record type, set
22636 -- the Is_Public attribute of its fields.
22638 --------------------------
22639 -- Set_Public_Status_Of --
22640 --------------------------
22642 procedure Set_Public_Status_Of (Id : Entity_Id) is
22643 Field : Entity_Id;
22645 begin
22646 if not Is_Public (Id) then
22647 Set_Public_Status (Id);
22649 -- When the input entity is a public record type, ensure that all
22650 -- its internal fields are also exposed to the linker. The fields
22651 -- of a class-wide type are never made public.
22653 if Is_Public (Id)
22654 and then Is_Record_Type (Id)
22655 and then not Is_Class_Wide_Type (Id)
22656 then
22657 Field := First_Entity (Id);
22658 while Present (Field) loop
22659 Set_Is_Public (Field);
22660 Next_Entity (Field);
22661 end loop;
22662 end if;
22663 end if;
22664 end Set_Public_Status_Of;
22666 -- Local variables
22668 Full_Id : Entity_Id;
22669 Id : Entity_Id;
22671 -- Start of processing for Transfer_Entities
22673 begin
22674 Id := First_Entity (From);
22676 if Present (Id) then
22678 -- Merge the entity chain of the source scope with that of the
22679 -- destination scope.
22681 if Present (Last_Entity (To)) then
22682 Set_Next_Entity (Last_Entity (To), Id);
22683 else
22684 Set_First_Entity (To, Id);
22685 end if;
22687 Set_Last_Entity (To, Last_Entity (From));
22689 -- Inspect the entities of the source scope and update their Scope
22690 -- attribute.
22692 while Present (Id) loop
22693 Set_Scope (Id, To);
22694 Set_Public_Status_Of (Id);
22696 -- Handle an internally generated full view for a private type
22698 if Is_Private_Type (Id)
22699 and then Present (Full_View (Id))
22700 and then Is_Itype (Full_View (Id))
22701 then
22702 Full_Id := Full_View (Id);
22704 Set_Scope (Full_Id, To);
22705 Set_Public_Status_Of (Full_Id);
22706 end if;
22708 Next_Entity (Id);
22709 end loop;
22711 Set_First_Entity (From, Empty);
22712 Set_Last_Entity (From, Empty);
22713 end if;
22714 end Transfer_Entities;
22716 -----------------------
22717 -- Type_Access_Level --
22718 -----------------------
22720 function Type_Access_Level (Typ : Entity_Id) return Uint is
22721 Btyp : Entity_Id;
22723 begin
22724 Btyp := Base_Type (Typ);
22726 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
22727 -- simply use the level where the type is declared. This is true for
22728 -- stand-alone object declarations, and for anonymous access types
22729 -- associated with components the level is the same as that of the
22730 -- enclosing composite type. However, special treatment is needed for
22731 -- the cases of access parameters, return objects of an anonymous access
22732 -- type, and, in Ada 95, access discriminants of limited types.
22734 if Is_Access_Type (Btyp) then
22735 if Ekind (Btyp) = E_Anonymous_Access_Type then
22737 -- If the type is a nonlocal anonymous access type (such as for
22738 -- an access parameter) we treat it as being declared at the
22739 -- library level to ensure that names such as X.all'access don't
22740 -- fail static accessibility checks.
22742 if not Is_Local_Anonymous_Access (Typ) then
22743 return Scope_Depth (Standard_Standard);
22745 -- If this is a return object, the accessibility level is that of
22746 -- the result subtype of the enclosing function. The test here is
22747 -- little complicated, because we have to account for extended
22748 -- return statements that have been rewritten as blocks, in which
22749 -- case we have to find and the Is_Return_Object attribute of the
22750 -- itype's associated object. It would be nice to find a way to
22751 -- simplify this test, but it doesn't seem worthwhile to add a new
22752 -- flag just for purposes of this test. ???
22754 elsif Ekind (Scope (Btyp)) = E_Return_Statement
22755 or else
22756 (Is_Itype (Btyp)
22757 and then Nkind (Associated_Node_For_Itype (Btyp)) =
22758 N_Object_Declaration
22759 and then Is_Return_Object
22760 (Defining_Identifier
22761 (Associated_Node_For_Itype (Btyp))))
22762 then
22763 declare
22764 Scop : Entity_Id;
22766 begin
22767 Scop := Scope (Scope (Btyp));
22768 while Present (Scop) loop
22769 exit when Ekind (Scop) = E_Function;
22770 Scop := Scope (Scop);
22771 end loop;
22773 -- Treat the return object's type as having the level of the
22774 -- function's result subtype (as per RM05-6.5(5.3/2)).
22776 return Type_Access_Level (Etype (Scop));
22777 end;
22778 end if;
22779 end if;
22781 Btyp := Root_Type (Btyp);
22783 -- The accessibility level of anonymous access types associated with
22784 -- discriminants is that of the current instance of the type, and
22785 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
22787 -- AI-402: access discriminants have accessibility based on the
22788 -- object rather than the type in Ada 2005, so the above paragraph
22789 -- doesn't apply.
22791 -- ??? Needs completion with rules from AI-416
22793 if Ada_Version <= Ada_95
22794 and then Ekind (Typ) = E_Anonymous_Access_Type
22795 and then Present (Associated_Node_For_Itype (Typ))
22796 and then Nkind (Associated_Node_For_Itype (Typ)) =
22797 N_Discriminant_Specification
22798 then
22799 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
22800 end if;
22801 end if;
22803 -- Return library level for a generic formal type. This is done because
22804 -- RM(10.3.2) says that "The statically deeper relationship does not
22805 -- apply to ... a descendant of a generic formal type". Rather than
22806 -- checking at each point where a static accessibility check is
22807 -- performed to see if we are dealing with a formal type, this rule is
22808 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
22809 -- return extreme values for a formal type; Deepest_Type_Access_Level
22810 -- returns Int'Last. By calling the appropriate function from among the
22811 -- two, we ensure that the static accessibility check will pass if we
22812 -- happen to run into a formal type. More specifically, we should call
22813 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
22814 -- call occurs as part of a static accessibility check and the error
22815 -- case is the case where the type's level is too shallow (as opposed
22816 -- to too deep).
22818 if Is_Generic_Type (Root_Type (Btyp)) then
22819 return Scope_Depth (Standard_Standard);
22820 end if;
22822 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
22823 end Type_Access_Level;
22825 ------------------------------------
22826 -- Type_Without_Stream_Operation --
22827 ------------------------------------
22829 function Type_Without_Stream_Operation
22830 (T : Entity_Id;
22831 Op : TSS_Name_Type := TSS_Null) return Entity_Id
22833 BT : constant Entity_Id := Base_Type (T);
22834 Op_Missing : Boolean;
22836 begin
22837 if not Restriction_Active (No_Default_Stream_Attributes) then
22838 return Empty;
22839 end if;
22841 if Is_Elementary_Type (T) then
22842 if Op = TSS_Null then
22843 Op_Missing :=
22844 No (TSS (BT, TSS_Stream_Read))
22845 or else No (TSS (BT, TSS_Stream_Write));
22847 else
22848 Op_Missing := No (TSS (BT, Op));
22849 end if;
22851 if Op_Missing then
22852 return T;
22853 else
22854 return Empty;
22855 end if;
22857 elsif Is_Array_Type (T) then
22858 return Type_Without_Stream_Operation (Component_Type (T), Op);
22860 elsif Is_Record_Type (T) then
22861 declare
22862 Comp : Entity_Id;
22863 C_Typ : Entity_Id;
22865 begin
22866 Comp := First_Component (T);
22867 while Present (Comp) loop
22868 C_Typ := Type_Without_Stream_Operation (Etype (Comp), Op);
22870 if Present (C_Typ) then
22871 return C_Typ;
22872 end if;
22874 Next_Component (Comp);
22875 end loop;
22877 return Empty;
22878 end;
22880 elsif Is_Private_Type (T) and then Present (Full_View (T)) then
22881 return Type_Without_Stream_Operation (Full_View (T), Op);
22882 else
22883 return Empty;
22884 end if;
22885 end Type_Without_Stream_Operation;
22887 ----------------------------
22888 -- Unique_Defining_Entity --
22889 ----------------------------
22891 function Unique_Defining_Entity (N : Node_Id) return Entity_Id is
22892 begin
22893 return Unique_Entity (Defining_Entity (N));
22894 end Unique_Defining_Entity;
22896 -------------------
22897 -- Unique_Entity --
22898 -------------------
22900 function Unique_Entity (E : Entity_Id) return Entity_Id is
22901 U : Entity_Id := E;
22902 P : Node_Id;
22904 begin
22905 case Ekind (E) is
22906 when E_Constant =>
22907 if Present (Full_View (E)) then
22908 U := Full_View (E);
22909 end if;
22911 when Entry_Kind =>
22912 if Nkind (Parent (E)) = N_Entry_Body then
22913 declare
22914 Prot_Item : Entity_Id;
22915 Prot_Type : Entity_Id;
22917 begin
22918 if Ekind (E) = E_Entry then
22919 Prot_Type := Scope (E);
22921 -- Bodies of entry families are nested within an extra scope
22922 -- that contains an entry index declaration.
22924 else
22925 Prot_Type := Scope (Scope (E));
22926 end if;
22928 -- A protected type may be declared as a private type, in
22929 -- which case we need to get its full view.
22931 if Is_Private_Type (Prot_Type) then
22932 Prot_Type := Full_View (Prot_Type);
22933 end if;
22935 -- Full view may not be present on error, in which case
22936 -- return E by default.
22938 if Present (Prot_Type) then
22939 pragma Assert (Ekind (Prot_Type) = E_Protected_Type);
22941 -- Traverse the entity list of the protected type and
22942 -- locate an entry declaration which matches the entry
22943 -- body.
22945 Prot_Item := First_Entity (Prot_Type);
22946 while Present (Prot_Item) loop
22947 if Ekind (Prot_Item) in Entry_Kind
22948 and then Corresponding_Body (Parent (Prot_Item)) = E
22949 then
22950 U := Prot_Item;
22951 exit;
22952 end if;
22954 Next_Entity (Prot_Item);
22955 end loop;
22956 end if;
22957 end;
22958 end if;
22960 when Formal_Kind =>
22961 if Present (Spec_Entity (E)) then
22962 U := Spec_Entity (E);
22963 end if;
22965 when E_Package_Body =>
22966 P := Parent (E);
22968 if Nkind (P) = N_Defining_Program_Unit_Name then
22969 P := Parent (P);
22970 end if;
22972 if Nkind (P) = N_Package_Body
22973 and then Present (Corresponding_Spec (P))
22974 then
22975 U := Corresponding_Spec (P);
22977 elsif Nkind (P) = N_Package_Body_Stub
22978 and then Present (Corresponding_Spec_Of_Stub (P))
22979 then
22980 U := Corresponding_Spec_Of_Stub (P);
22981 end if;
22983 when E_Protected_Body =>
22984 P := Parent (E);
22986 if Nkind (P) = N_Protected_Body
22987 and then Present (Corresponding_Spec (P))
22988 then
22989 U := Corresponding_Spec (P);
22991 elsif Nkind (P) = N_Protected_Body_Stub
22992 and then Present (Corresponding_Spec_Of_Stub (P))
22993 then
22994 U := Corresponding_Spec_Of_Stub (P);
22996 if Is_Single_Protected_Object (U) then
22997 U := Etype (U);
22998 end if;
22999 end if;
23001 if Is_Private_Type (U) then
23002 U := Full_View (U);
23003 end if;
23005 when E_Subprogram_Body =>
23006 P := Parent (E);
23008 if Nkind (P) = N_Defining_Program_Unit_Name then
23009 P := Parent (P);
23010 end if;
23012 P := Parent (P);
23014 if Nkind (P) = N_Subprogram_Body
23015 and then Present (Corresponding_Spec (P))
23016 then
23017 U := Corresponding_Spec (P);
23019 elsif Nkind (P) = N_Subprogram_Body_Stub
23020 and then Present (Corresponding_Spec_Of_Stub (P))
23021 then
23022 U := Corresponding_Spec_Of_Stub (P);
23024 elsif Nkind (P) = N_Subprogram_Renaming_Declaration then
23025 U := Corresponding_Spec (P);
23026 end if;
23028 when E_Task_Body =>
23029 P := Parent (E);
23031 if Nkind (P) = N_Task_Body
23032 and then Present (Corresponding_Spec (P))
23033 then
23034 U := Corresponding_Spec (P);
23036 elsif Nkind (P) = N_Task_Body_Stub
23037 and then Present (Corresponding_Spec_Of_Stub (P))
23038 then
23039 U := Corresponding_Spec_Of_Stub (P);
23041 if Is_Single_Task_Object (U) then
23042 U := Etype (U);
23043 end if;
23044 end if;
23046 if Is_Private_Type (U) then
23047 U := Full_View (U);
23048 end if;
23050 when Type_Kind =>
23051 if Present (Full_View (E)) then
23052 U := Full_View (E);
23053 end if;
23055 when others =>
23056 null;
23057 end case;
23059 return U;
23060 end Unique_Entity;
23062 -----------------
23063 -- Unique_Name --
23064 -----------------
23066 function Unique_Name (E : Entity_Id) return String is
23068 -- Names in E_Subprogram_Body or E_Package_Body entities are not
23069 -- reliable, as they may not include the overloading suffix. Instead,
23070 -- when looking for the name of E or one of its enclosing scope, we get
23071 -- the name of the corresponding Unique_Entity.
23073 U : constant Entity_Id := Unique_Entity (E);
23075 function This_Name return String;
23077 ---------------
23078 -- This_Name --
23079 ---------------
23081 function This_Name return String is
23082 begin
23083 return Get_Name_String (Chars (U));
23084 end This_Name;
23086 -- Start of processing for Unique_Name
23088 begin
23089 if E = Standard_Standard
23090 or else Has_Fully_Qualified_Name (E)
23091 then
23092 return This_Name;
23094 elsif Ekind (E) = E_Enumeration_Literal then
23095 return Unique_Name (Etype (E)) & "__" & This_Name;
23097 else
23098 declare
23099 S : constant Entity_Id := Scope (U);
23100 pragma Assert (Present (S));
23102 begin
23103 -- Prefix names of predefined types with standard__, but leave
23104 -- names of user-defined packages and subprograms without prefix
23105 -- (even if technically they are nested in the Standard package).
23107 if S = Standard_Standard then
23108 if Ekind (U) = E_Package or else Is_Subprogram (U) then
23109 return This_Name;
23110 else
23111 return Unique_Name (S) & "__" & This_Name;
23112 end if;
23114 -- For intances of generic subprograms use the name of the related
23115 -- instace and skip the scope of its wrapper package.
23117 elsif Is_Wrapper_Package (S) then
23118 pragma Assert (Scope (S) = Scope (Related_Instance (S)));
23119 -- Wrapper package and the instantiation are in the same scope
23121 declare
23122 Enclosing_Name : constant String :=
23123 Unique_Name (Scope (S)) & "__" &
23124 Get_Name_String (Chars (Related_Instance (S)));
23126 begin
23127 if Is_Subprogram (U)
23128 and then not Is_Generic_Actual_Subprogram (U)
23129 then
23130 return Enclosing_Name;
23131 else
23132 return Enclosing_Name & "__" & This_Name;
23133 end if;
23134 end;
23136 else
23137 return Unique_Name (S) & "__" & This_Name;
23138 end if;
23139 end;
23140 end if;
23141 end Unique_Name;
23143 ---------------------
23144 -- Unit_Is_Visible --
23145 ---------------------
23147 function Unit_Is_Visible (U : Entity_Id) return Boolean is
23148 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
23149 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
23151 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
23152 -- For a child unit, check whether unit appears in a with_clause
23153 -- of a parent.
23155 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
23156 -- Scan the context clause of one compilation unit looking for a
23157 -- with_clause for the unit in question.
23159 ----------------------------
23160 -- Unit_In_Parent_Context --
23161 ----------------------------
23163 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
23164 begin
23165 if Unit_In_Context (Par_Unit) then
23166 return True;
23168 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
23169 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
23171 else
23172 return False;
23173 end if;
23174 end Unit_In_Parent_Context;
23176 ---------------------
23177 -- Unit_In_Context --
23178 ---------------------
23180 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
23181 Clause : Node_Id;
23183 begin
23184 Clause := First (Context_Items (Comp_Unit));
23185 while Present (Clause) loop
23186 if Nkind (Clause) = N_With_Clause then
23187 if Library_Unit (Clause) = U then
23188 return True;
23190 -- The with_clause may denote a renaming of the unit we are
23191 -- looking for, eg. Text_IO which renames Ada.Text_IO.
23193 elsif
23194 Renamed_Entity (Entity (Name (Clause))) =
23195 Defining_Entity (Unit (U))
23196 then
23197 return True;
23198 end if;
23199 end if;
23201 Next (Clause);
23202 end loop;
23204 return False;
23205 end Unit_In_Context;
23207 -- Start of processing for Unit_Is_Visible
23209 begin
23210 -- The currrent unit is directly visible
23212 if Curr = U then
23213 return True;
23215 elsif Unit_In_Context (Curr) then
23216 return True;
23218 -- If the current unit is a body, check the context of the spec
23220 elsif Nkind (Unit (Curr)) = N_Package_Body
23221 or else
23222 (Nkind (Unit (Curr)) = N_Subprogram_Body
23223 and then not Acts_As_Spec (Unit (Curr)))
23224 then
23225 if Unit_In_Context (Library_Unit (Curr)) then
23226 return True;
23227 end if;
23228 end if;
23230 -- If the spec is a child unit, examine the parents
23232 if Is_Child_Unit (Curr_Entity) then
23233 if Nkind (Unit (Curr)) in N_Unit_Body then
23234 return
23235 Unit_In_Parent_Context
23236 (Parent_Spec (Unit (Library_Unit (Curr))));
23237 else
23238 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
23239 end if;
23241 else
23242 return False;
23243 end if;
23244 end Unit_Is_Visible;
23246 ------------------------------
23247 -- Universal_Interpretation --
23248 ------------------------------
23250 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
23251 Index : Interp_Index;
23252 It : Interp;
23254 begin
23255 -- The argument may be a formal parameter of an operator or subprogram
23256 -- with multiple interpretations, or else an expression for an actual.
23258 if Nkind (Opnd) = N_Defining_Identifier
23259 or else not Is_Overloaded (Opnd)
23260 then
23261 if Etype (Opnd) = Universal_Integer
23262 or else Etype (Opnd) = Universal_Real
23263 then
23264 return Etype (Opnd);
23265 else
23266 return Empty;
23267 end if;
23269 else
23270 Get_First_Interp (Opnd, Index, It);
23271 while Present (It.Typ) loop
23272 if It.Typ = Universal_Integer
23273 or else It.Typ = Universal_Real
23274 then
23275 return It.Typ;
23276 end if;
23278 Get_Next_Interp (Index, It);
23279 end loop;
23281 return Empty;
23282 end if;
23283 end Universal_Interpretation;
23285 ---------------
23286 -- Unqualify --
23287 ---------------
23289 function Unqualify (Expr : Node_Id) return Node_Id is
23290 begin
23291 -- Recurse to handle unlikely case of multiple levels of qualification
23293 if Nkind (Expr) = N_Qualified_Expression then
23294 return Unqualify (Expression (Expr));
23296 -- Normal case, not a qualified expression
23298 else
23299 return Expr;
23300 end if;
23301 end Unqualify;
23303 -----------------
23304 -- Unqual_Conv --
23305 -----------------
23307 function Unqual_Conv (Expr : Node_Id) return Node_Id is
23308 begin
23309 -- Recurse to handle unlikely case of multiple levels of qualification
23310 -- and/or conversion.
23312 if Nkind_In (Expr, N_Qualified_Expression,
23313 N_Type_Conversion,
23314 N_Unchecked_Type_Conversion)
23315 then
23316 return Unqual_Conv (Expression (Expr));
23318 -- Normal case, not a qualified expression
23320 else
23321 return Expr;
23322 end if;
23323 end Unqual_Conv;
23325 -----------------------
23326 -- Visible_Ancestors --
23327 -----------------------
23329 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
23330 List_1 : Elist_Id;
23331 List_2 : Elist_Id;
23332 Elmt : Elmt_Id;
23334 begin
23335 pragma Assert (Is_Record_Type (Typ) and then Is_Tagged_Type (Typ));
23337 -- Collect all the parents and progenitors of Typ. If the full-view of
23338 -- private parents and progenitors is available then it is used to
23339 -- generate the list of visible ancestors; otherwise their partial
23340 -- view is added to the resulting list.
23342 Collect_Parents
23343 (T => Typ,
23344 List => List_1,
23345 Use_Full_View => True);
23347 Collect_Interfaces
23348 (T => Typ,
23349 Ifaces_List => List_2,
23350 Exclude_Parents => True,
23351 Use_Full_View => True);
23353 -- Join the two lists. Avoid duplications because an interface may
23354 -- simultaneously be parent and progenitor of a type.
23356 Elmt := First_Elmt (List_2);
23357 while Present (Elmt) loop
23358 Append_Unique_Elmt (Node (Elmt), List_1);
23359 Next_Elmt (Elmt);
23360 end loop;
23362 return List_1;
23363 end Visible_Ancestors;
23365 ----------------------
23366 -- Within_Init_Proc --
23367 ----------------------
23369 function Within_Init_Proc return Boolean is
23370 S : Entity_Id;
23372 begin
23373 S := Current_Scope;
23374 while not Is_Overloadable (S) loop
23375 if S = Standard_Standard then
23376 return False;
23377 else
23378 S := Scope (S);
23379 end if;
23380 end loop;
23382 return Is_Init_Proc (S);
23383 end Within_Init_Proc;
23385 ---------------------------
23386 -- Within_Protected_Type --
23387 ---------------------------
23389 function Within_Protected_Type (E : Entity_Id) return Boolean is
23390 Scop : Entity_Id := Scope (E);
23392 begin
23393 while Present (Scop) loop
23394 if Ekind (Scop) = E_Protected_Type then
23395 return True;
23396 end if;
23398 Scop := Scope (Scop);
23399 end loop;
23401 return False;
23402 end Within_Protected_Type;
23404 ------------------
23405 -- Within_Scope --
23406 ------------------
23408 function Within_Scope (E : Entity_Id; S : Entity_Id) return Boolean is
23409 begin
23410 return Scope_Within_Or_Same (Scope (E), S);
23411 end Within_Scope;
23413 ----------------
23414 -- Wrong_Type --
23415 ----------------
23417 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
23418 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
23419 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
23421 Matching_Field : Entity_Id;
23422 -- Entity to give a more precise suggestion on how to write a one-
23423 -- element positional aggregate.
23425 function Has_One_Matching_Field return Boolean;
23426 -- Determines if Expec_Type is a record type with a single component or
23427 -- discriminant whose type matches the found type or is one dimensional
23428 -- array whose component type matches the found type. In the case of
23429 -- one discriminant, we ignore the variant parts. That's not accurate,
23430 -- but good enough for the warning.
23432 ----------------------------
23433 -- Has_One_Matching_Field --
23434 ----------------------------
23436 function Has_One_Matching_Field return Boolean is
23437 E : Entity_Id;
23439 begin
23440 Matching_Field := Empty;
23442 if Is_Array_Type (Expec_Type)
23443 and then Number_Dimensions (Expec_Type) = 1
23444 and then Covers (Etype (Component_Type (Expec_Type)), Found_Type)
23445 then
23446 -- Use type name if available. This excludes multidimensional
23447 -- arrays and anonymous arrays.
23449 if Comes_From_Source (Expec_Type) then
23450 Matching_Field := Expec_Type;
23452 -- For an assignment, use name of target
23454 elsif Nkind (Parent (Expr)) = N_Assignment_Statement
23455 and then Is_Entity_Name (Name (Parent (Expr)))
23456 then
23457 Matching_Field := Entity (Name (Parent (Expr)));
23458 end if;
23460 return True;
23462 elsif not Is_Record_Type (Expec_Type) then
23463 return False;
23465 else
23466 E := First_Entity (Expec_Type);
23467 loop
23468 if No (E) then
23469 return False;
23471 elsif not Ekind_In (E, E_Discriminant, E_Component)
23472 or else Nam_In (Chars (E), Name_uTag, Name_uParent)
23473 then
23474 Next_Entity (E);
23476 else
23477 exit;
23478 end if;
23479 end loop;
23481 if not Covers (Etype (E), Found_Type) then
23482 return False;
23484 elsif Present (Next_Entity (E))
23485 and then (Ekind (E) = E_Component
23486 or else Ekind (Next_Entity (E)) = E_Discriminant)
23487 then
23488 return False;
23490 else
23491 Matching_Field := E;
23492 return True;
23493 end if;
23494 end if;
23495 end Has_One_Matching_Field;
23497 -- Start of processing for Wrong_Type
23499 begin
23500 -- Don't output message if either type is Any_Type, or if a message
23501 -- has already been posted for this node. We need to do the latter
23502 -- check explicitly (it is ordinarily done in Errout), because we
23503 -- are using ! to force the output of the error messages.
23505 if Expec_Type = Any_Type
23506 or else Found_Type = Any_Type
23507 or else Error_Posted (Expr)
23508 then
23509 return;
23511 -- If one of the types is a Taft-Amendment type and the other it its
23512 -- completion, it must be an illegal use of a TAT in the spec, for
23513 -- which an error was already emitted. Avoid cascaded errors.
23515 elsif Is_Incomplete_Type (Expec_Type)
23516 and then Has_Completion_In_Body (Expec_Type)
23517 and then Full_View (Expec_Type) = Etype (Expr)
23518 then
23519 return;
23521 elsif Is_Incomplete_Type (Etype (Expr))
23522 and then Has_Completion_In_Body (Etype (Expr))
23523 and then Full_View (Etype (Expr)) = Expec_Type
23524 then
23525 return;
23527 -- In an instance, there is an ongoing problem with completion of
23528 -- type derived from private types. Their structure is what Gigi
23529 -- expects, but the Etype is the parent type rather than the
23530 -- derived private type itself. Do not flag error in this case. The
23531 -- private completion is an entity without a parent, like an Itype.
23532 -- Similarly, full and partial views may be incorrect in the instance.
23533 -- There is no simple way to insure that it is consistent ???
23535 -- A similar view discrepancy can happen in an inlined body, for the
23536 -- same reason: inserted body may be outside of the original package
23537 -- and only partial views are visible at the point of insertion.
23539 elsif In_Instance or else In_Inlined_Body then
23540 if Etype (Etype (Expr)) = Etype (Expected_Type)
23541 and then
23542 (Has_Private_Declaration (Expected_Type)
23543 or else Has_Private_Declaration (Etype (Expr)))
23544 and then No (Parent (Expected_Type))
23545 then
23546 return;
23548 elsif Nkind (Parent (Expr)) = N_Qualified_Expression
23549 and then Entity (Subtype_Mark (Parent (Expr))) = Expected_Type
23550 then
23551 return;
23553 elsif Is_Private_Type (Expected_Type)
23554 and then Present (Full_View (Expected_Type))
23555 and then Covers (Full_View (Expected_Type), Etype (Expr))
23556 then
23557 return;
23559 -- Conversely, type of expression may be the private one
23561 elsif Is_Private_Type (Base_Type (Etype (Expr)))
23562 and then Full_View (Base_Type (Etype (Expr))) = Expected_Type
23563 then
23564 return;
23565 end if;
23566 end if;
23568 -- An interesting special check. If the expression is parenthesized
23569 -- and its type corresponds to the type of the sole component of the
23570 -- expected record type, or to the component type of the expected one
23571 -- dimensional array type, then assume we have a bad aggregate attempt.
23573 if Nkind (Expr) in N_Subexpr
23574 and then Paren_Count (Expr) /= 0
23575 and then Has_One_Matching_Field
23576 then
23577 Error_Msg_N ("positional aggregate cannot have one component", Expr);
23579 if Present (Matching_Field) then
23580 if Is_Array_Type (Expec_Type) then
23581 Error_Msg_NE
23582 ("\write instead `&''First ='> ...`", Expr, Matching_Field);
23583 else
23584 Error_Msg_NE
23585 ("\write instead `& ='> ...`", Expr, Matching_Field);
23586 end if;
23587 end if;
23589 -- Another special check, if we are looking for a pool-specific access
23590 -- type and we found an E_Access_Attribute_Type, then we have the case
23591 -- of an Access attribute being used in a context which needs a pool-
23592 -- specific type, which is never allowed. The one extra check we make
23593 -- is that the expected designated type covers the Found_Type.
23595 elsif Is_Access_Type (Expec_Type)
23596 and then Ekind (Found_Type) = E_Access_Attribute_Type
23597 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
23598 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
23599 and then Covers
23600 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
23601 then
23602 Error_Msg_N -- CODEFIX
23603 ("result must be general access type!", Expr);
23604 Error_Msg_NE -- CODEFIX
23605 ("add ALL to }!", Expr, Expec_Type);
23607 -- Another special check, if the expected type is an integer type,
23608 -- but the expression is of type System.Address, and the parent is
23609 -- an addition or subtraction operation whose left operand is the
23610 -- expression in question and whose right operand is of an integral
23611 -- type, then this is an attempt at address arithmetic, so give
23612 -- appropriate message.
23614 elsif Is_Integer_Type (Expec_Type)
23615 and then Is_RTE (Found_Type, RE_Address)
23616 and then Nkind_In (Parent (Expr), N_Op_Add, N_Op_Subtract)
23617 and then Expr = Left_Opnd (Parent (Expr))
23618 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
23619 then
23620 Error_Msg_N
23621 ("address arithmetic not predefined in package System",
23622 Parent (Expr));
23623 Error_Msg_N
23624 ("\possible missing with/use of System.Storage_Elements",
23625 Parent (Expr));
23626 return;
23628 -- If the expected type is an anonymous access type, as for access
23629 -- parameters and discriminants, the error is on the designated types.
23631 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
23632 if Comes_From_Source (Expec_Type) then
23633 Error_Msg_NE ("expected}!", Expr, Expec_Type);
23634 else
23635 Error_Msg_NE
23636 ("expected an access type with designated}",
23637 Expr, Designated_Type (Expec_Type));
23638 end if;
23640 if Is_Access_Type (Found_Type)
23641 and then not Comes_From_Source (Found_Type)
23642 then
23643 Error_Msg_NE
23644 ("\\found an access type with designated}!",
23645 Expr, Designated_Type (Found_Type));
23646 else
23647 if From_Limited_With (Found_Type) then
23648 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
23649 Error_Msg_Qual_Level := 99;
23650 Error_Msg_NE -- CODEFIX
23651 ("\\missing `WITH &;", Expr, Scope (Found_Type));
23652 Error_Msg_Qual_Level := 0;
23653 else
23654 Error_Msg_NE ("found}!", Expr, Found_Type);
23655 end if;
23656 end if;
23658 -- Normal case of one type found, some other type expected
23660 else
23661 -- If the names of the two types are the same, see if some number
23662 -- of levels of qualification will help. Don't try more than three
23663 -- levels, and if we get to standard, it's no use (and probably
23664 -- represents an error in the compiler) Also do not bother with
23665 -- internal scope names.
23667 declare
23668 Expec_Scope : Entity_Id;
23669 Found_Scope : Entity_Id;
23671 begin
23672 Expec_Scope := Expec_Type;
23673 Found_Scope := Found_Type;
23675 for Levels in Nat range 0 .. 3 loop
23676 if Chars (Expec_Scope) /= Chars (Found_Scope) then
23677 Error_Msg_Qual_Level := Levels;
23678 exit;
23679 end if;
23681 Expec_Scope := Scope (Expec_Scope);
23682 Found_Scope := Scope (Found_Scope);
23684 exit when Expec_Scope = Standard_Standard
23685 or else Found_Scope = Standard_Standard
23686 or else not Comes_From_Source (Expec_Scope)
23687 or else not Comes_From_Source (Found_Scope);
23688 end loop;
23689 end;
23691 if Is_Record_Type (Expec_Type)
23692 and then Present (Corresponding_Remote_Type (Expec_Type))
23693 then
23694 Error_Msg_NE ("expected}!", Expr,
23695 Corresponding_Remote_Type (Expec_Type));
23696 else
23697 Error_Msg_NE ("expected}!", Expr, Expec_Type);
23698 end if;
23700 if Is_Entity_Name (Expr)
23701 and then Is_Package_Or_Generic_Package (Entity (Expr))
23702 then
23703 Error_Msg_N ("\\found package name!", Expr);
23705 elsif Is_Entity_Name (Expr)
23706 and then Ekind_In (Entity (Expr), E_Procedure, E_Generic_Procedure)
23707 then
23708 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
23709 Error_Msg_N
23710 ("found procedure name, possibly missing Access attribute!",
23711 Expr);
23712 else
23713 Error_Msg_N
23714 ("\\found procedure name instead of function!", Expr);
23715 end if;
23717 elsif Nkind (Expr) = N_Function_Call
23718 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
23719 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
23720 and then No (Parameter_Associations (Expr))
23721 then
23722 Error_Msg_N
23723 ("found function name, possibly missing Access attribute!",
23724 Expr);
23726 -- Catch common error: a prefix or infix operator which is not
23727 -- directly visible because the type isn't.
23729 elsif Nkind (Expr) in N_Op
23730 and then Is_Overloaded (Expr)
23731 and then not Is_Immediately_Visible (Expec_Type)
23732 and then not Is_Potentially_Use_Visible (Expec_Type)
23733 and then not In_Use (Expec_Type)
23734 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
23735 then
23736 Error_Msg_N
23737 ("operator of the type is not directly visible!", Expr);
23739 elsif Ekind (Found_Type) = E_Void
23740 and then Present (Parent (Found_Type))
23741 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
23742 then
23743 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
23745 else
23746 Error_Msg_NE ("\\found}!", Expr, Found_Type);
23747 end if;
23749 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
23750 -- of the same modular type, and (M1 and M2) = 0 was intended.
23752 if Expec_Type = Standard_Boolean
23753 and then Is_Modular_Integer_Type (Found_Type)
23754 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
23755 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
23756 then
23757 declare
23758 Op : constant Node_Id := Right_Opnd (Parent (Expr));
23759 L : constant Node_Id := Left_Opnd (Op);
23760 R : constant Node_Id := Right_Opnd (Op);
23762 begin
23763 -- The case for the message is when the left operand of the
23764 -- comparison is the same modular type, or when it is an
23765 -- integer literal (or other universal integer expression),
23766 -- which would have been typed as the modular type if the
23767 -- parens had been there.
23769 if (Etype (L) = Found_Type
23770 or else
23771 Etype (L) = Universal_Integer)
23772 and then Is_Integer_Type (Etype (R))
23773 then
23774 Error_Msg_N
23775 ("\\possible missing parens for modular operation", Expr);
23776 end if;
23777 end;
23778 end if;
23780 -- Reset error message qualification indication
23782 Error_Msg_Qual_Level := 0;
23783 end if;
23784 end Wrong_Type;
23786 --------------------------------
23787 -- Yields_Synchronized_Object --
23788 --------------------------------
23790 function Yields_Synchronized_Object (Typ : Entity_Id) return Boolean is
23791 Has_Sync_Comp : Boolean := False;
23792 Id : Entity_Id;
23794 begin
23795 -- An array type yields a synchronized object if its component type
23796 -- yields a synchronized object.
23798 if Is_Array_Type (Typ) then
23799 return Yields_Synchronized_Object (Component_Type (Typ));
23801 -- A descendant of type Ada.Synchronous_Task_Control.Suspension_Object
23802 -- yields a synchronized object by default.
23804 elsif Is_Descendant_Of_Suspension_Object (Typ) then
23805 return True;
23807 -- A protected type yields a synchronized object by default
23809 elsif Is_Protected_Type (Typ) then
23810 return True;
23812 -- A record type or type extension yields a synchronized object when its
23813 -- discriminants (if any) lack default values and all components are of
23814 -- a type that yelds a synchronized object.
23816 elsif Is_Record_Type (Typ) then
23818 -- Inspect all entities defined in the scope of the type, looking for
23819 -- components of a type that does not yeld a synchronized object or
23820 -- for discriminants with default values.
23822 Id := First_Entity (Typ);
23823 while Present (Id) loop
23824 if Comes_From_Source (Id) then
23825 if Ekind (Id) = E_Component then
23826 if Yields_Synchronized_Object (Etype (Id)) then
23827 Has_Sync_Comp := True;
23829 -- The component does not yield a synchronized object
23831 else
23832 return False;
23833 end if;
23835 elsif Ekind (Id) = E_Discriminant
23836 and then Present (Expression (Parent (Id)))
23837 then
23838 return False;
23839 end if;
23840 end if;
23842 Next_Entity (Id);
23843 end loop;
23845 -- Ensure that the parent type of a type extension yields a
23846 -- synchronized object.
23848 if Etype (Typ) /= Typ
23849 and then not Yields_Synchronized_Object (Etype (Typ))
23850 then
23851 return False;
23852 end if;
23854 -- If we get here, then all discriminants lack default values and all
23855 -- components are of a type that yields a synchronized object.
23857 return Has_Sync_Comp;
23859 -- A synchronized interface type yields a synchronized object by default
23861 elsif Is_Synchronized_Interface (Typ) then
23862 return True;
23864 -- A task type yelds a synchronized object by default
23866 elsif Is_Task_Type (Typ) then
23867 return True;
23869 -- Otherwise the type does not yield a synchronized object
23871 else
23872 return False;
23873 end if;
23874 end Yields_Synchronized_Object;
23876 ---------------------------
23877 -- Yields_Universal_Type --
23878 ---------------------------
23880 function Yields_Universal_Type (N : Node_Id) return Boolean is
23881 begin
23882 -- Integer and real literals are of a universal type
23884 if Nkind_In (N, N_Integer_Literal, N_Real_Literal) then
23885 return True;
23887 -- The values of certain attributes are of a universal type
23889 elsif Nkind (N) = N_Attribute_Reference then
23890 return
23891 Universal_Type_Attribute (Get_Attribute_Id (Attribute_Name (N)));
23893 -- ??? There are possibly other cases to consider
23895 else
23896 return False;
23897 end if;
23898 end Yields_Universal_Type;
23900 begin
23901 Erroutc.Subprogram_Name_Ptr := Subprogram_Name'Access;
23902 end Sem_Util;