builtins.def: (_Float<N> and _Float<N>X BUILT_IN_CEIL): Add _Float<N> and _Float...
[official-gcc.git] / gcc / ada / sem_util.adb
blob972bda5e34640e0eb80e4f91efa3a1e21300e5d7
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_Elab; use Sem_Elab;
57 with Sem_Eval; use Sem_Eval;
58 with Sem_Prag; use Sem_Prag;
59 with Sem_Res; use Sem_Res;
60 with Sem_Warn; use Sem_Warn;
61 with Sem_Type; use Sem_Type;
62 with Sinfo; use Sinfo;
63 with Sinput; use Sinput;
64 with Stand; use Stand;
65 with Style;
66 with Stringt; use Stringt;
67 with Targparm; use Targparm;
68 with Tbuild; use Tbuild;
69 with Ttypes; use Ttypes;
70 with Uname; use Uname;
72 with GNAT.HTable; use GNAT.HTable;
74 package body Sem_Util is
76 -----------------------
77 -- Local Subprograms --
78 -----------------------
80 function Build_Component_Subtype
81 (C : List_Id;
82 Loc : Source_Ptr;
83 T : Entity_Id) return Node_Id;
84 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
85 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
86 -- Loc is the source location, T is the original subtype.
88 function Has_Enabled_Property
89 (Item_Id : Entity_Id;
90 Property : Name_Id) return Boolean;
91 -- Subsidiary to routines Async_xxx_Enabled and Effective_xxx_Enabled.
92 -- Determine whether an abstract state or a variable denoted by entity
93 -- Item_Id has enabled property Property.
95 function Has_Null_Extension (T : Entity_Id) return Boolean;
96 -- T is a derived tagged type. Check whether the type extension is null.
97 -- If the parent type is fully initialized, T can be treated as such.
99 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
100 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
101 -- with discriminants whose default values are static, examine only the
102 -- components in the selected variant to determine whether all of them
103 -- have a default.
105 type Null_Status_Kind is
106 (Is_Null,
107 -- This value indicates that a subexpression is known to have a null
108 -- value at compile time.
110 Is_Non_Null,
111 -- This value indicates that a subexpression is known to have a non-null
112 -- value at compile time.
114 Unknown);
115 -- This value indicates that it cannot be determined at compile time
116 -- whether a subexpression yields a null or non-null value.
118 function Null_Status (N : Node_Id) return Null_Status_Kind;
119 -- Determine whether subexpression N of an access type yields a null value,
120 -- a non-null value, or the value cannot be determined at compile time. The
121 -- routine does not take simple flow diagnostics into account, it relies on
122 -- static facts such as the presence of null exclusions.
124 function Old_Requires_Transient_Scope (Id : Entity_Id) return Boolean;
125 function New_Requires_Transient_Scope (Id : Entity_Id) return Boolean;
126 -- ???We retain the old and new algorithms for Requires_Transient_Scope for
127 -- the time being. New_Requires_Transient_Scope is used by default; the
128 -- debug switch -gnatdQ can be used to do Old_Requires_Transient_Scope
129 -- instead. The intent is to use this temporarily to measure before/after
130 -- efficiency. Note: when this temporary code is removed, the documentation
131 -- of dQ in debug.adb should be removed.
133 procedure Results_Differ
134 (Id : Entity_Id;
135 Old_Val : Boolean;
136 New_Val : Boolean);
137 -- ???Debugging code. Called when the Old_Val and New_Val differ. This
138 -- routine will be removed eventially when New_Requires_Transient_Scope
139 -- becomes Requires_Transient_Scope and Old_Requires_Transient_Scope is
140 -- eliminated.
142 function Subprogram_Name (N : Node_Id) return String;
143 -- Return the fully qualified name of the enclosing subprogram for the
144 -- given node N, with file:line:col information appended, e.g.
145 -- "subp:file:line:col", corresponding to the source location of the
146 -- body of the subprogram.
148 ------------------------------
149 -- Abstract_Interface_List --
150 ------------------------------
152 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
153 Nod : Node_Id;
155 begin
156 if Is_Concurrent_Type (Typ) then
158 -- If we are dealing with a synchronized subtype, go to the base
159 -- type, whose declaration has the interface list.
161 -- Shouldn't this be Declaration_Node???
163 Nod := Parent (Base_Type (Typ));
165 if Nkind (Nod) = N_Full_Type_Declaration then
166 return Empty_List;
167 end if;
169 elsif Ekind (Typ) = E_Record_Type_With_Private then
170 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
171 Nod := Type_Definition (Parent (Typ));
173 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
174 if Present (Full_View (Typ))
175 and then
176 Nkind (Parent (Full_View (Typ))) = N_Full_Type_Declaration
177 then
178 Nod := Type_Definition (Parent (Full_View (Typ)));
180 -- If the full-view is not available we cannot do anything else
181 -- here (the source has errors).
183 else
184 return Empty_List;
185 end if;
187 -- Support for generic formals with interfaces is still missing ???
189 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
190 return Empty_List;
192 else
193 pragma Assert
194 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
195 Nod := Parent (Typ);
196 end if;
198 elsif Ekind (Typ) = E_Record_Subtype then
199 Nod := Type_Definition (Parent (Etype (Typ)));
201 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
203 -- Recurse, because parent may still be a private extension. Also
204 -- note that the full view of the subtype or the full view of its
205 -- base type may (both) be unavailable.
207 return Abstract_Interface_List (Etype (Typ));
209 elsif Ekind (Typ) = E_Record_Type then
210 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
211 Nod := Formal_Type_Definition (Parent (Typ));
212 else
213 Nod := Type_Definition (Parent (Typ));
214 end if;
216 -- Otherwise the type is of a kind which does not implement interfaces
218 else
219 return Empty_List;
220 end if;
222 return Interface_List (Nod);
223 end Abstract_Interface_List;
225 --------------------------------
226 -- Add_Access_Type_To_Process --
227 --------------------------------
229 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
230 L : Elist_Id;
232 begin
233 Ensure_Freeze_Node (E);
234 L := Access_Types_To_Process (Freeze_Node (E));
236 if No (L) then
237 L := New_Elmt_List;
238 Set_Access_Types_To_Process (Freeze_Node (E), L);
239 end if;
241 Append_Elmt (A, L);
242 end Add_Access_Type_To_Process;
244 --------------------------
245 -- Add_Block_Identifier --
246 --------------------------
248 procedure Add_Block_Identifier (N : Node_Id; Id : out Entity_Id) is
249 Loc : constant Source_Ptr := Sloc (N);
251 begin
252 pragma Assert (Nkind (N) = N_Block_Statement);
254 -- The block already has a label, return its entity
256 if Present (Identifier (N)) then
257 Id := Entity (Identifier (N));
259 -- Create a new block label and set its attributes
261 else
262 Id := New_Internal_Entity (E_Block, Current_Scope, Loc, 'B');
263 Set_Etype (Id, Standard_Void_Type);
264 Set_Parent (Id, N);
266 Set_Identifier (N, New_Occurrence_Of (Id, Loc));
267 Set_Block_Node (Id, Identifier (N));
268 end if;
269 end Add_Block_Identifier;
271 ----------------------------
272 -- Add_Global_Declaration --
273 ----------------------------
275 procedure Add_Global_Declaration (N : Node_Id) is
276 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
278 begin
279 if No (Declarations (Aux_Node)) then
280 Set_Declarations (Aux_Node, New_List);
281 end if;
283 Append_To (Declarations (Aux_Node), N);
284 Analyze (N);
285 end Add_Global_Declaration;
287 --------------------------------
288 -- Address_Integer_Convert_OK --
289 --------------------------------
291 function Address_Integer_Convert_OK (T1, T2 : Entity_Id) return Boolean is
292 begin
293 if Allow_Integer_Address
294 and then ((Is_Descendant_Of_Address (T1)
295 and then Is_Private_Type (T1)
296 and then Is_Integer_Type (T2))
297 or else
298 (Is_Descendant_Of_Address (T2)
299 and then Is_Private_Type (T2)
300 and then Is_Integer_Type (T1)))
301 then
302 return True;
303 else
304 return False;
305 end if;
306 end Address_Integer_Convert_OK;
308 -------------------
309 -- Address_Value --
310 -------------------
312 function Address_Value (N : Node_Id) return Node_Id is
313 Expr : Node_Id := N;
315 begin
316 loop
317 -- For constant, get constant expression
319 if Is_Entity_Name (Expr)
320 and then Ekind (Entity (Expr)) = E_Constant
321 then
322 Expr := Constant_Value (Entity (Expr));
324 -- For unchecked conversion, get result to convert
326 elsif Nkind (Expr) = N_Unchecked_Type_Conversion then
327 Expr := Expression (Expr);
329 -- For (common case) of To_Address call, get argument
331 elsif Nkind (Expr) = N_Function_Call
332 and then Is_Entity_Name (Name (Expr))
333 and then Is_RTE (Entity (Name (Expr)), RE_To_Address)
334 then
335 Expr := First (Parameter_Associations (Expr));
337 if Nkind (Expr) = N_Parameter_Association then
338 Expr := Explicit_Actual_Parameter (Expr);
339 end if;
341 -- We finally have the real expression
343 else
344 exit;
345 end if;
346 end loop;
348 return Expr;
349 end Address_Value;
351 -----------------
352 -- Addressable --
353 -----------------
355 -- For now, just 8/16/32/64
357 function Addressable (V : Uint) return Boolean is
358 begin
359 return V = Uint_8 or else
360 V = Uint_16 or else
361 V = Uint_32 or else
362 V = Uint_64;
363 end Addressable;
365 function Addressable (V : Int) return Boolean is
366 begin
367 return V = 8 or else
368 V = 16 or else
369 V = 32 or else
370 V = 64;
371 end Addressable;
373 ---------------------------------
374 -- Aggregate_Constraint_Checks --
375 ---------------------------------
377 procedure Aggregate_Constraint_Checks
378 (Exp : Node_Id;
379 Check_Typ : Entity_Id)
381 Exp_Typ : constant Entity_Id := Etype (Exp);
383 begin
384 if Raises_Constraint_Error (Exp) then
385 return;
386 end if;
388 -- Ada 2005 (AI-230): Generate a conversion to an anonymous access
389 -- component's type to force the appropriate accessibility checks.
391 -- Ada 2005 (AI-231): Generate conversion to the null-excluding type to
392 -- force the corresponding run-time check
394 if Is_Access_Type (Check_Typ)
395 and then Is_Local_Anonymous_Access (Check_Typ)
396 then
397 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
398 Analyze_And_Resolve (Exp, Check_Typ);
399 Check_Unset_Reference (Exp);
400 end if;
402 -- What follows is really expansion activity, so check that expansion
403 -- is on and is allowed. In GNATprove mode, we also want check flags to
404 -- be added in the tree, so that the formal verification can rely on
405 -- those to be present. In GNATprove mode for formal verification, some
406 -- treatment typically only done during expansion needs to be performed
407 -- on the tree, but it should not be applied inside generics. Otherwise,
408 -- this breaks the name resolution mechanism for generic instances.
410 if not Expander_Active
411 and (Inside_A_Generic or not Full_Analysis or not GNATprove_Mode)
412 then
413 return;
414 end if;
416 if Is_Access_Type (Check_Typ)
417 and then Can_Never_Be_Null (Check_Typ)
418 and then not Can_Never_Be_Null (Exp_Typ)
419 then
420 Install_Null_Excluding_Check (Exp);
421 end if;
423 -- First check if we have to insert discriminant checks
425 if Has_Discriminants (Exp_Typ) then
426 Apply_Discriminant_Check (Exp, Check_Typ);
428 -- Next emit length checks for array aggregates
430 elsif Is_Array_Type (Exp_Typ) then
431 Apply_Length_Check (Exp, Check_Typ);
433 -- Finally emit scalar and string checks. If we are dealing with a
434 -- scalar literal we need to check by hand because the Etype of
435 -- literals is not necessarily correct.
437 elsif Is_Scalar_Type (Exp_Typ)
438 and then Compile_Time_Known_Value (Exp)
439 then
440 if Is_Out_Of_Range (Exp, Base_Type (Check_Typ)) then
441 Apply_Compile_Time_Constraint_Error
442 (Exp, "value not in range of}??", CE_Range_Check_Failed,
443 Ent => Base_Type (Check_Typ),
444 Typ => Base_Type (Check_Typ));
446 elsif Is_Out_Of_Range (Exp, Check_Typ) then
447 Apply_Compile_Time_Constraint_Error
448 (Exp, "value not in range of}??", CE_Range_Check_Failed,
449 Ent => Check_Typ,
450 Typ => Check_Typ);
452 elsif not Range_Checks_Suppressed (Check_Typ) then
453 Apply_Scalar_Range_Check (Exp, Check_Typ);
454 end if;
456 -- Verify that target type is also scalar, to prevent view anomalies
457 -- in instantiations.
459 elsif (Is_Scalar_Type (Exp_Typ)
460 or else Nkind (Exp) = N_String_Literal)
461 and then Is_Scalar_Type (Check_Typ)
462 and then Exp_Typ /= Check_Typ
463 then
464 if Is_Entity_Name (Exp)
465 and then Ekind (Entity (Exp)) = E_Constant
466 then
467 -- If expression is a constant, it is worthwhile checking whether
468 -- it is a bound of the type.
470 if (Is_Entity_Name (Type_Low_Bound (Check_Typ))
471 and then Entity (Exp) = Entity (Type_Low_Bound (Check_Typ)))
472 or else
473 (Is_Entity_Name (Type_High_Bound (Check_Typ))
474 and then Entity (Exp) = Entity (Type_High_Bound (Check_Typ)))
475 then
476 return;
478 else
479 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
480 Analyze_And_Resolve (Exp, Check_Typ);
481 Check_Unset_Reference (Exp);
482 end if;
484 -- Could use a comment on this case ???
486 else
487 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
488 Analyze_And_Resolve (Exp, Check_Typ);
489 Check_Unset_Reference (Exp);
490 end if;
492 end if;
493 end Aggregate_Constraint_Checks;
495 -----------------------
496 -- Alignment_In_Bits --
497 -----------------------
499 function Alignment_In_Bits (E : Entity_Id) return Uint is
500 begin
501 return Alignment (E) * System_Storage_Unit;
502 end Alignment_In_Bits;
504 --------------------------------------
505 -- All_Composite_Constraints_Static --
506 --------------------------------------
508 function All_Composite_Constraints_Static
509 (Constr : Node_Id) return Boolean
511 begin
512 if No (Constr) or else Error_Posted (Constr) then
513 return True;
514 end if;
516 case Nkind (Constr) is
517 when N_Subexpr =>
518 if Nkind (Constr) in N_Has_Entity
519 and then Present (Entity (Constr))
520 then
521 if Is_Type (Entity (Constr)) then
522 return
523 not Is_Discrete_Type (Entity (Constr))
524 or else Is_OK_Static_Subtype (Entity (Constr));
525 end if;
527 elsif Nkind (Constr) = N_Range then
528 return
529 Is_OK_Static_Expression (Low_Bound (Constr))
530 and then
531 Is_OK_Static_Expression (High_Bound (Constr));
533 elsif Nkind (Constr) = N_Attribute_Reference
534 and then Attribute_Name (Constr) = Name_Range
535 then
536 return
537 Is_OK_Static_Expression
538 (Type_Low_Bound (Etype (Prefix (Constr))))
539 and then
540 Is_OK_Static_Expression
541 (Type_High_Bound (Etype (Prefix (Constr))));
542 end if;
544 return
545 not Present (Etype (Constr)) -- previous error
546 or else not Is_Discrete_Type (Etype (Constr))
547 or else Is_OK_Static_Expression (Constr);
549 when N_Discriminant_Association =>
550 return All_Composite_Constraints_Static (Expression (Constr));
552 when N_Range_Constraint =>
553 return
554 All_Composite_Constraints_Static (Range_Expression (Constr));
556 when N_Index_Or_Discriminant_Constraint =>
557 declare
558 One_Cstr : Entity_Id;
559 begin
560 One_Cstr := First (Constraints (Constr));
561 while Present (One_Cstr) loop
562 if not All_Composite_Constraints_Static (One_Cstr) then
563 return False;
564 end if;
566 Next (One_Cstr);
567 end loop;
568 end;
570 return True;
572 when N_Subtype_Indication =>
573 return
574 All_Composite_Constraints_Static (Subtype_Mark (Constr))
575 and then
576 All_Composite_Constraints_Static (Constraint (Constr));
578 when others =>
579 raise Program_Error;
580 end case;
581 end All_Composite_Constraints_Static;
583 ------------------------
584 -- Append_Entity_Name --
585 ------------------------
587 procedure Append_Entity_Name (Buf : in out Bounded_String; E : Entity_Id) is
588 Temp : Bounded_String;
590 procedure Inner (E : Entity_Id);
591 -- Inner recursive routine, keep outer routine nonrecursive to ease
592 -- debugging when we get strange results from this routine.
594 -----------
595 -- Inner --
596 -----------
598 procedure Inner (E : Entity_Id) is
599 Scop : Node_Id;
601 begin
602 -- If entity has an internal name, skip by it, and print its scope.
603 -- Note that we strip a final R from the name before the test; this
604 -- is needed for some cases of instantiations.
606 declare
607 E_Name : Bounded_String;
609 begin
610 Append (E_Name, Chars (E));
612 if E_Name.Chars (E_Name.Length) = 'R' then
613 E_Name.Length := E_Name.Length - 1;
614 end if;
616 if Is_Internal_Name (E_Name) then
617 Inner (Scope (E));
618 return;
619 end if;
620 end;
622 Scop := Scope (E);
624 -- Just print entity name if its scope is at the outer level
626 if Scop = Standard_Standard then
627 null;
629 -- If scope comes from source, write scope and entity
631 elsif Comes_From_Source (Scop) then
632 Append_Entity_Name (Temp, Scop);
633 Append (Temp, '.');
635 -- If in wrapper package skip past it
637 elsif Present (Scop) and then Is_Wrapper_Package (Scop) then
638 Append_Entity_Name (Temp, Scope (Scop));
639 Append (Temp, '.');
641 -- Otherwise nothing to output (happens in unnamed block statements)
643 else
644 null;
645 end if;
647 -- Output the name
649 declare
650 E_Name : Bounded_String;
652 begin
653 Append_Unqualified_Decoded (E_Name, Chars (E));
655 -- Remove trailing upper-case letters from the name (useful for
656 -- dealing with some cases of internal names generated in the case
657 -- of references from within a generic).
659 while E_Name.Length > 1
660 and then E_Name.Chars (E_Name.Length) in 'A' .. 'Z'
661 loop
662 E_Name.Length := E_Name.Length - 1;
663 end loop;
665 -- Adjust casing appropriately (gets name from source if possible)
667 Adjust_Name_Case (E_Name, Sloc (E));
668 Append (Temp, E_Name);
669 end;
670 end Inner;
672 -- Start of processing for Append_Entity_Name
674 begin
675 Inner (E);
676 Append (Buf, Temp);
677 end Append_Entity_Name;
679 ---------------------------------
680 -- Append_Inherited_Subprogram --
681 ---------------------------------
683 procedure Append_Inherited_Subprogram (S : Entity_Id) is
684 Par : constant Entity_Id := Alias (S);
685 -- The parent subprogram
687 Scop : constant Entity_Id := Scope (Par);
688 -- The scope of definition of the parent subprogram
690 Typ : constant Entity_Id := Defining_Entity (Parent (S));
691 -- The derived type of which S is a primitive operation
693 Decl : Node_Id;
694 Next_E : Entity_Id;
696 begin
697 if Ekind (Current_Scope) = E_Package
698 and then In_Private_Part (Current_Scope)
699 and then Has_Private_Declaration (Typ)
700 and then Is_Tagged_Type (Typ)
701 and then Scop = Current_Scope
702 then
703 -- The inherited operation is available at the earliest place after
704 -- the derived type declaration ( RM 7.3.1 (6/1)). This is only
705 -- relevant for type extensions. If the parent operation appears
706 -- after the type extension, the operation is not visible.
708 Decl := First
709 (Visible_Declarations
710 (Package_Specification (Current_Scope)));
711 while Present (Decl) loop
712 if Nkind (Decl) = N_Private_Extension_Declaration
713 and then Defining_Entity (Decl) = Typ
714 then
715 if Sloc (Decl) > Sloc (Par) then
716 Next_E := Next_Entity (Par);
717 Set_Next_Entity (Par, S);
718 Set_Next_Entity (S, Next_E);
719 return;
721 else
722 exit;
723 end if;
724 end if;
726 Next (Decl);
727 end loop;
728 end if;
730 -- If partial view is not a type extension, or it appears before the
731 -- subprogram declaration, insert normally at end of entity list.
733 Append_Entity (S, Current_Scope);
734 end Append_Inherited_Subprogram;
736 -----------------------------------------
737 -- Apply_Compile_Time_Constraint_Error --
738 -----------------------------------------
740 procedure Apply_Compile_Time_Constraint_Error
741 (N : Node_Id;
742 Msg : String;
743 Reason : RT_Exception_Code;
744 Ent : Entity_Id := Empty;
745 Typ : Entity_Id := Empty;
746 Loc : Source_Ptr := No_Location;
747 Rep : Boolean := True;
748 Warn : Boolean := False)
750 Stat : constant Boolean := Is_Static_Expression (N);
751 R_Stat : constant Node_Id :=
752 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
753 Rtyp : Entity_Id;
755 begin
756 if No (Typ) then
757 Rtyp := Etype (N);
758 else
759 Rtyp := Typ;
760 end if;
762 Discard_Node
763 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
765 -- In GNATprove mode, do not replace the node with an exception raised.
766 -- In such a case, either the call to Compile_Time_Constraint_Error
767 -- issues an error which stops analysis, or it issues a warning in
768 -- a few cases where a suitable check flag is set for GNATprove to
769 -- generate a check message.
771 if not Rep or GNATprove_Mode then
772 return;
773 end if;
775 -- Now we replace the node by an N_Raise_Constraint_Error node
776 -- This does not need reanalyzing, so set it as analyzed now.
778 Rewrite (N, R_Stat);
779 Set_Analyzed (N, True);
781 Set_Etype (N, Rtyp);
782 Set_Raises_Constraint_Error (N);
784 -- Now deal with possible local raise handling
786 Possible_Local_Raise (N, Standard_Constraint_Error);
788 -- If the original expression was marked as static, the result is
789 -- still marked as static, but the Raises_Constraint_Error flag is
790 -- always set so that further static evaluation is not attempted.
792 if Stat then
793 Set_Is_Static_Expression (N);
794 end if;
795 end Apply_Compile_Time_Constraint_Error;
797 ---------------------------
798 -- Async_Readers_Enabled --
799 ---------------------------
801 function Async_Readers_Enabled (Id : Entity_Id) return Boolean is
802 begin
803 return Has_Enabled_Property (Id, Name_Async_Readers);
804 end Async_Readers_Enabled;
806 ---------------------------
807 -- Async_Writers_Enabled --
808 ---------------------------
810 function Async_Writers_Enabled (Id : Entity_Id) return Boolean is
811 begin
812 return Has_Enabled_Property (Id, Name_Async_Writers);
813 end Async_Writers_Enabled;
815 --------------------------------------
816 -- Available_Full_View_Of_Component --
817 --------------------------------------
819 function Available_Full_View_Of_Component (T : Entity_Id) return Boolean is
820 ST : constant Entity_Id := Scope (T);
821 SCT : constant Entity_Id := Scope (Component_Type (T));
822 begin
823 return In_Open_Scopes (ST)
824 and then In_Open_Scopes (SCT)
825 and then Scope_Depth (ST) >= Scope_Depth (SCT);
826 end Available_Full_View_Of_Component;
828 -------------------
829 -- Bad_Attribute --
830 -------------------
832 procedure Bad_Attribute
833 (N : Node_Id;
834 Nam : Name_Id;
835 Warn : Boolean := False)
837 begin
838 Error_Msg_Warn := Warn;
839 Error_Msg_N ("unrecognized attribute&<<", N);
841 -- Check for possible misspelling
843 Error_Msg_Name_1 := First_Attribute_Name;
844 while Error_Msg_Name_1 <= Last_Attribute_Name loop
845 if Is_Bad_Spelling_Of (Nam, Error_Msg_Name_1) then
846 Error_Msg_N -- CODEFIX
847 ("\possible misspelling of %<<", N);
848 exit;
849 end if;
851 Error_Msg_Name_1 := Error_Msg_Name_1 + 1;
852 end loop;
853 end Bad_Attribute;
855 --------------------------------
856 -- Bad_Predicated_Subtype_Use --
857 --------------------------------
859 procedure Bad_Predicated_Subtype_Use
860 (Msg : String;
861 N : Node_Id;
862 Typ : Entity_Id;
863 Suggest_Static : Boolean := False)
865 Gen : Entity_Id;
867 begin
868 -- Avoid cascaded errors
870 if Error_Posted (N) then
871 return;
872 end if;
874 if Inside_A_Generic then
875 Gen := Current_Scope;
876 while Present (Gen) and then Ekind (Gen) /= E_Generic_Package loop
877 Gen := Scope (Gen);
878 end loop;
880 if No (Gen) then
881 return;
882 end if;
884 if Is_Generic_Formal (Typ) and then Is_Discrete_Type (Typ) then
885 Set_No_Predicate_On_Actual (Typ);
886 end if;
888 elsif Has_Predicates (Typ) then
889 if Is_Generic_Actual_Type (Typ) then
891 -- The restriction on loop parameters is only that the type
892 -- should have no dynamic predicates.
894 if Nkind (Parent (N)) = N_Loop_Parameter_Specification
895 and then not Has_Dynamic_Predicate_Aspect (Typ)
896 and then Is_OK_Static_Subtype (Typ)
897 then
898 return;
899 end if;
901 Gen := Current_Scope;
902 while not Is_Generic_Instance (Gen) loop
903 Gen := Scope (Gen);
904 end loop;
906 pragma Assert (Present (Gen));
908 if Ekind (Gen) = E_Package and then In_Package_Body (Gen) then
909 Error_Msg_Warn := SPARK_Mode /= On;
910 Error_Msg_FE (Msg & "<<", N, Typ);
911 Error_Msg_F ("\Program_Error [<<", N);
913 Insert_Action (N,
914 Make_Raise_Program_Error (Sloc (N),
915 Reason => PE_Bad_Predicated_Generic_Type));
917 else
918 Error_Msg_FE (Msg & "<<", N, Typ);
919 end if;
921 else
922 Error_Msg_FE (Msg, N, Typ);
923 end if;
925 -- Emit an optional suggestion on how to remedy the error if the
926 -- context warrants it.
928 if Suggest_Static and then Has_Static_Predicate (Typ) then
929 Error_Msg_FE ("\predicate of & should be marked static", N, Typ);
930 end if;
931 end if;
932 end Bad_Predicated_Subtype_Use;
934 -----------------------------------------
935 -- Bad_Unordered_Enumeration_Reference --
936 -----------------------------------------
938 function Bad_Unordered_Enumeration_Reference
939 (N : Node_Id;
940 T : Entity_Id) return Boolean
942 begin
943 return Is_Enumeration_Type (T)
944 and then Warn_On_Unordered_Enumeration_Type
945 and then not Is_Generic_Type (T)
946 and then Comes_From_Source (N)
947 and then not Has_Pragma_Ordered (T)
948 and then not In_Same_Extended_Unit (N, T);
949 end Bad_Unordered_Enumeration_Reference;
951 ----------------------------
952 -- Begin_Keyword_Location --
953 ----------------------------
955 function Begin_Keyword_Location (N : Node_Id) return Source_Ptr is
956 HSS : Node_Id;
958 begin
959 pragma Assert (Nkind_In (N, N_Block_Statement,
960 N_Entry_Body,
961 N_Package_Body,
962 N_Subprogram_Body,
963 N_Task_Body));
965 HSS := Handled_Statement_Sequence (N);
967 -- When the handled sequence of statements comes from source, the
968 -- location of the "begin" keyword is that of the sequence itself.
969 -- Note that an internal construct may inherit a source sequence.
971 if Comes_From_Source (HSS) then
972 return Sloc (HSS);
974 -- The parser generates an internal handled sequence of statements to
975 -- capture the location of the "begin" keyword if present in the source.
976 -- Since there are no source statements, the location of the "begin"
977 -- keyword is effectively that of the "end" keyword.
979 elsif Comes_From_Source (N) then
980 return Sloc (HSS);
982 -- Otherwise the construct is internal and should carry the location of
983 -- the original construct which prompted its creation.
985 else
986 return Sloc (N);
987 end if;
988 end Begin_Keyword_Location;
990 --------------------------
991 -- Build_Actual_Subtype --
992 --------------------------
994 function Build_Actual_Subtype
995 (T : Entity_Id;
996 N : Node_Or_Entity_Id) return Node_Id
998 Loc : Source_Ptr;
999 -- Normally Sloc (N), but may point to corresponding body in some cases
1001 Constraints : List_Id;
1002 Decl : Node_Id;
1003 Discr : Entity_Id;
1004 Hi : Node_Id;
1005 Lo : Node_Id;
1006 Subt : Entity_Id;
1007 Disc_Type : Entity_Id;
1008 Obj : Node_Id;
1010 begin
1011 Loc := Sloc (N);
1013 if Nkind (N) = N_Defining_Identifier then
1014 Obj := New_Occurrence_Of (N, Loc);
1016 -- If this is a formal parameter of a subprogram declaration, and
1017 -- we are compiling the body, we want the declaration for the
1018 -- actual subtype to carry the source position of the body, to
1019 -- prevent anomalies in gdb when stepping through the code.
1021 if Is_Formal (N) then
1022 declare
1023 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
1024 begin
1025 if Nkind (Decl) = N_Subprogram_Declaration
1026 and then Present (Corresponding_Body (Decl))
1027 then
1028 Loc := Sloc (Corresponding_Body (Decl));
1029 end if;
1030 end;
1031 end if;
1033 else
1034 Obj := N;
1035 end if;
1037 if Is_Array_Type (T) then
1038 Constraints := New_List;
1039 for J in 1 .. Number_Dimensions (T) loop
1041 -- Build an array subtype declaration with the nominal subtype and
1042 -- the bounds of the actual. Add the declaration in front of the
1043 -- local declarations for the subprogram, for analysis before any
1044 -- reference to the formal in the body.
1046 Lo :=
1047 Make_Attribute_Reference (Loc,
1048 Prefix =>
1049 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
1050 Attribute_Name => Name_First,
1051 Expressions => New_List (
1052 Make_Integer_Literal (Loc, J)));
1054 Hi :=
1055 Make_Attribute_Reference (Loc,
1056 Prefix =>
1057 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
1058 Attribute_Name => Name_Last,
1059 Expressions => New_List (
1060 Make_Integer_Literal (Loc, J)));
1062 Append (Make_Range (Loc, Lo, Hi), Constraints);
1063 end loop;
1065 -- If the type has unknown discriminants there is no constrained
1066 -- subtype to build. This is never called for a formal or for a
1067 -- lhs, so returning the type is ok ???
1069 elsif Has_Unknown_Discriminants (T) then
1070 return T;
1072 else
1073 Constraints := New_List;
1075 -- Type T is a generic derived type, inherit the discriminants from
1076 -- the parent type.
1078 if Is_Private_Type (T)
1079 and then No (Full_View (T))
1081 -- T was flagged as an error if it was declared as a formal
1082 -- derived type with known discriminants. In this case there
1083 -- is no need to look at the parent type since T already carries
1084 -- its own discriminants.
1086 and then not Error_Posted (T)
1087 then
1088 Disc_Type := Etype (Base_Type (T));
1089 else
1090 Disc_Type := T;
1091 end if;
1093 Discr := First_Discriminant (Disc_Type);
1094 while Present (Discr) loop
1095 Append_To (Constraints,
1096 Make_Selected_Component (Loc,
1097 Prefix =>
1098 Duplicate_Subexpr_No_Checks (Obj),
1099 Selector_Name => New_Occurrence_Of (Discr, Loc)));
1100 Next_Discriminant (Discr);
1101 end loop;
1102 end if;
1104 Subt := Make_Temporary (Loc, 'S', Related_Node => N);
1105 Set_Is_Internal (Subt);
1107 Decl :=
1108 Make_Subtype_Declaration (Loc,
1109 Defining_Identifier => Subt,
1110 Subtype_Indication =>
1111 Make_Subtype_Indication (Loc,
1112 Subtype_Mark => New_Occurrence_Of (T, Loc),
1113 Constraint =>
1114 Make_Index_Or_Discriminant_Constraint (Loc,
1115 Constraints => Constraints)));
1117 Mark_Rewrite_Insertion (Decl);
1118 return Decl;
1119 end Build_Actual_Subtype;
1121 ---------------------------------------
1122 -- Build_Actual_Subtype_Of_Component --
1123 ---------------------------------------
1125 function Build_Actual_Subtype_Of_Component
1126 (T : Entity_Id;
1127 N : Node_Id) return Node_Id
1129 Loc : constant Source_Ptr := Sloc (N);
1130 P : constant Node_Id := Prefix (N);
1131 D : Elmt_Id;
1132 Id : Node_Id;
1133 Index_Typ : Entity_Id;
1135 Desig_Typ : Entity_Id;
1136 -- This is either a copy of T, or if T is an access type, then it is
1137 -- the directly designated type of this access type.
1139 function Build_Actual_Array_Constraint return List_Id;
1140 -- If one or more of the bounds of the component depends on
1141 -- discriminants, build actual constraint using the discriminants
1142 -- of the prefix.
1144 function Build_Actual_Record_Constraint return List_Id;
1145 -- Similar to previous one, for discriminated components constrained
1146 -- by the discriminant of the enclosing object.
1148 -----------------------------------
1149 -- Build_Actual_Array_Constraint --
1150 -----------------------------------
1152 function Build_Actual_Array_Constraint return List_Id is
1153 Constraints : constant List_Id := New_List;
1154 Indx : Node_Id;
1155 Hi : Node_Id;
1156 Lo : Node_Id;
1157 Old_Hi : Node_Id;
1158 Old_Lo : Node_Id;
1160 begin
1161 Indx := First_Index (Desig_Typ);
1162 while Present (Indx) loop
1163 Old_Lo := Type_Low_Bound (Etype (Indx));
1164 Old_Hi := Type_High_Bound (Etype (Indx));
1166 if Denotes_Discriminant (Old_Lo) then
1167 Lo :=
1168 Make_Selected_Component (Loc,
1169 Prefix => New_Copy_Tree (P),
1170 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
1172 else
1173 Lo := New_Copy_Tree (Old_Lo);
1175 -- The new bound will be reanalyzed in the enclosing
1176 -- declaration. For literal bounds that come from a type
1177 -- declaration, the type of the context must be imposed, so
1178 -- insure that analysis will take place. For non-universal
1179 -- types this is not strictly necessary.
1181 Set_Analyzed (Lo, False);
1182 end if;
1184 if Denotes_Discriminant (Old_Hi) then
1185 Hi :=
1186 Make_Selected_Component (Loc,
1187 Prefix => New_Copy_Tree (P),
1188 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
1190 else
1191 Hi := New_Copy_Tree (Old_Hi);
1192 Set_Analyzed (Hi, False);
1193 end if;
1195 Append (Make_Range (Loc, Lo, Hi), Constraints);
1196 Next_Index (Indx);
1197 end loop;
1199 return Constraints;
1200 end Build_Actual_Array_Constraint;
1202 ------------------------------------
1203 -- Build_Actual_Record_Constraint --
1204 ------------------------------------
1206 function Build_Actual_Record_Constraint return List_Id is
1207 Constraints : constant List_Id := New_List;
1208 D : Elmt_Id;
1209 D_Val : Node_Id;
1211 begin
1212 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1213 while Present (D) loop
1214 if Denotes_Discriminant (Node (D)) then
1215 D_Val := Make_Selected_Component (Loc,
1216 Prefix => New_Copy_Tree (P),
1217 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
1219 else
1220 D_Val := New_Copy_Tree (Node (D));
1221 end if;
1223 Append (D_Val, Constraints);
1224 Next_Elmt (D);
1225 end loop;
1227 return Constraints;
1228 end Build_Actual_Record_Constraint;
1230 -- Start of processing for Build_Actual_Subtype_Of_Component
1232 begin
1233 -- Why the test for Spec_Expression mode here???
1235 if In_Spec_Expression then
1236 return Empty;
1238 -- More comments for the rest of this body would be good ???
1240 elsif Nkind (N) = N_Explicit_Dereference then
1241 if Is_Composite_Type (T)
1242 and then not Is_Constrained (T)
1243 and then not (Is_Class_Wide_Type (T)
1244 and then Is_Constrained (Root_Type (T)))
1245 and then not Has_Unknown_Discriminants (T)
1246 then
1247 -- If the type of the dereference is already constrained, it is an
1248 -- actual subtype.
1250 if Is_Array_Type (Etype (N))
1251 and then Is_Constrained (Etype (N))
1252 then
1253 return Empty;
1254 else
1255 Remove_Side_Effects (P);
1256 return Build_Actual_Subtype (T, N);
1257 end if;
1258 else
1259 return Empty;
1260 end if;
1261 end if;
1263 if Ekind (T) = E_Access_Subtype then
1264 Desig_Typ := Designated_Type (T);
1265 else
1266 Desig_Typ := T;
1267 end if;
1269 if Ekind (Desig_Typ) = E_Array_Subtype then
1270 Id := First_Index (Desig_Typ);
1271 while Present (Id) loop
1272 Index_Typ := Underlying_Type (Etype (Id));
1274 if Denotes_Discriminant (Type_Low_Bound (Index_Typ))
1275 or else
1276 Denotes_Discriminant (Type_High_Bound (Index_Typ))
1277 then
1278 Remove_Side_Effects (P);
1279 return
1280 Build_Component_Subtype
1281 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
1282 end if;
1284 Next_Index (Id);
1285 end loop;
1287 elsif Is_Composite_Type (Desig_Typ)
1288 and then Has_Discriminants (Desig_Typ)
1289 and then not Has_Unknown_Discriminants (Desig_Typ)
1290 then
1291 if Is_Private_Type (Desig_Typ)
1292 and then No (Discriminant_Constraint (Desig_Typ))
1293 then
1294 Desig_Typ := Full_View (Desig_Typ);
1295 end if;
1297 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1298 while Present (D) loop
1299 if Denotes_Discriminant (Node (D)) then
1300 Remove_Side_Effects (P);
1301 return
1302 Build_Component_Subtype (
1303 Build_Actual_Record_Constraint, Loc, Base_Type (T));
1304 end if;
1306 Next_Elmt (D);
1307 end loop;
1308 end if;
1310 -- If none of the above, the actual and nominal subtypes are the same
1312 return Empty;
1313 end Build_Actual_Subtype_Of_Component;
1315 ---------------------------------
1316 -- Build_Class_Wide_Clone_Body --
1317 ---------------------------------
1319 procedure Build_Class_Wide_Clone_Body
1320 (Spec_Id : Entity_Id;
1321 Bod : Node_Id)
1323 Loc : constant Source_Ptr := Sloc (Bod);
1324 Clone_Id : constant Entity_Id := Class_Wide_Clone (Spec_Id);
1325 Clone_Body : Node_Id;
1327 begin
1328 -- The declaration of the class-wide clone was created when the
1329 -- corresponding class-wide condition was analyzed.
1331 Clone_Body :=
1332 Make_Subprogram_Body (Loc,
1333 Specification =>
1334 Copy_Subprogram_Spec (Parent (Clone_Id)),
1335 Declarations => Declarations (Bod),
1336 Handled_Statement_Sequence => Handled_Statement_Sequence (Bod));
1338 -- The new operation is internal and overriding indicators do not apply
1339 -- (the original primitive may have carried one).
1341 Set_Must_Override (Specification (Clone_Body), False);
1342 Insert_Before (Bod, Clone_Body);
1343 Analyze (Clone_Body);
1344 end Build_Class_Wide_Clone_Body;
1346 ---------------------------------
1347 -- Build_Class_Wide_Clone_Call --
1348 ---------------------------------
1350 function Build_Class_Wide_Clone_Call
1351 (Loc : Source_Ptr;
1352 Decls : List_Id;
1353 Spec_Id : Entity_Id;
1354 Spec : Node_Id) return Node_Id
1356 Clone_Id : constant Entity_Id := Class_Wide_Clone (Spec_Id);
1357 Par_Type : constant Entity_Id := Find_Dispatching_Type (Spec_Id);
1359 Actuals : List_Id;
1360 Call : Node_Id;
1361 Formal : Entity_Id;
1362 New_Body : Node_Id;
1363 New_F_Spec : Entity_Id;
1364 New_Formal : Entity_Id;
1366 begin
1367 Actuals := Empty_List;
1368 Formal := First_Formal (Spec_Id);
1369 New_F_Spec := First (Parameter_Specifications (Spec));
1371 -- Build parameter association for call to class-wide clone.
1373 while Present (Formal) loop
1374 New_Formal := Defining_Identifier (New_F_Spec);
1376 -- If controlling argument and operation is inherited, add conversion
1377 -- to parent type for the call.
1379 if Etype (Formal) = Par_Type
1380 and then not Is_Empty_List (Decls)
1381 then
1382 Append_To (Actuals,
1383 Make_Type_Conversion (Loc,
1384 New_Occurrence_Of (Par_Type, Loc),
1385 New_Occurrence_Of (New_Formal, Loc)));
1387 else
1388 Append_To (Actuals, New_Occurrence_Of (New_Formal, Loc));
1389 end if;
1391 Next_Formal (Formal);
1392 Next (New_F_Spec);
1393 end loop;
1395 if Ekind (Spec_Id) = E_Procedure then
1396 Call :=
1397 Make_Procedure_Call_Statement (Loc,
1398 Name => New_Occurrence_Of (Clone_Id, Loc),
1399 Parameter_Associations => Actuals);
1400 else
1401 Call :=
1402 Make_Simple_Return_Statement (Loc,
1403 Expression =>
1404 Make_Function_Call (Loc,
1405 Name => New_Occurrence_Of (Clone_Id, Loc),
1406 Parameter_Associations => Actuals));
1407 end if;
1409 New_Body :=
1410 Make_Subprogram_Body (Loc,
1411 Specification =>
1412 Copy_Subprogram_Spec (Spec),
1413 Declarations => Decls,
1414 Handled_Statement_Sequence =>
1415 Make_Handled_Sequence_Of_Statements (Loc,
1416 Statements => New_List (Call),
1417 End_Label => Make_Identifier (Loc, Chars (Spec_Id))));
1419 return New_Body;
1420 end Build_Class_Wide_Clone_Call;
1422 ---------------------------------
1423 -- Build_Class_Wide_Clone_Decl --
1424 ---------------------------------
1426 procedure Build_Class_Wide_Clone_Decl (Spec_Id : Entity_Id) is
1427 Loc : constant Source_Ptr := Sloc (Spec_Id);
1428 Clone_Id : constant Entity_Id :=
1429 Make_Defining_Identifier (Loc,
1430 New_External_Name (Chars (Spec_Id), Suffix => "CL"));
1432 Decl : Node_Id;
1433 Spec : Node_Id;
1435 begin
1436 Spec := Copy_Subprogram_Spec (Parent (Spec_Id));
1437 Set_Must_Override (Spec, False);
1438 Set_Must_Not_Override (Spec, False);
1439 Set_Defining_Unit_Name (Spec, Clone_Id);
1441 Decl := Make_Subprogram_Declaration (Loc, Spec);
1442 Append (Decl, List_Containing (Unit_Declaration_Node (Spec_Id)));
1444 -- Link clone to original subprogram, for use when building body and
1445 -- wrapper call to inherited operation.
1447 Set_Class_Wide_Clone (Spec_Id, Clone_Id);
1448 end Build_Class_Wide_Clone_Decl;
1450 -----------------------------
1451 -- Build_Component_Subtype --
1452 -----------------------------
1454 function Build_Component_Subtype
1455 (C : List_Id;
1456 Loc : Source_Ptr;
1457 T : Entity_Id) return Node_Id
1459 Subt : Entity_Id;
1460 Decl : Node_Id;
1462 begin
1463 -- Unchecked_Union components do not require component subtypes
1465 if Is_Unchecked_Union (T) then
1466 return Empty;
1467 end if;
1469 Subt := Make_Temporary (Loc, 'S');
1470 Set_Is_Internal (Subt);
1472 Decl :=
1473 Make_Subtype_Declaration (Loc,
1474 Defining_Identifier => Subt,
1475 Subtype_Indication =>
1476 Make_Subtype_Indication (Loc,
1477 Subtype_Mark => New_Occurrence_Of (Base_Type (T), Loc),
1478 Constraint =>
1479 Make_Index_Or_Discriminant_Constraint (Loc,
1480 Constraints => C)));
1482 Mark_Rewrite_Insertion (Decl);
1483 return Decl;
1484 end Build_Component_Subtype;
1486 ---------------------------
1487 -- Build_Default_Subtype --
1488 ---------------------------
1490 function Build_Default_Subtype
1491 (T : Entity_Id;
1492 N : Node_Id) return Entity_Id
1494 Loc : constant Source_Ptr := Sloc (N);
1495 Disc : Entity_Id;
1497 Bas : Entity_Id;
1498 -- The base type that is to be constrained by the defaults
1500 begin
1501 if not Has_Discriminants (T) or else Is_Constrained (T) then
1502 return T;
1503 end if;
1505 Bas := Base_Type (T);
1507 -- If T is non-private but its base type is private, this is the
1508 -- completion of a subtype declaration whose parent type is private
1509 -- (see Complete_Private_Subtype in Sem_Ch3). The proper discriminants
1510 -- are to be found in the full view of the base. Check that the private
1511 -- status of T and its base differ.
1513 if Is_Private_Type (Bas)
1514 and then not Is_Private_Type (T)
1515 and then Present (Full_View (Bas))
1516 then
1517 Bas := Full_View (Bas);
1518 end if;
1520 Disc := First_Discriminant (T);
1522 if No (Discriminant_Default_Value (Disc)) then
1523 return T;
1524 end if;
1526 declare
1527 Act : constant Entity_Id := Make_Temporary (Loc, 'S');
1528 Constraints : constant List_Id := New_List;
1529 Decl : Node_Id;
1531 begin
1532 while Present (Disc) loop
1533 Append_To (Constraints,
1534 New_Copy_Tree (Discriminant_Default_Value (Disc)));
1535 Next_Discriminant (Disc);
1536 end loop;
1538 Decl :=
1539 Make_Subtype_Declaration (Loc,
1540 Defining_Identifier => Act,
1541 Subtype_Indication =>
1542 Make_Subtype_Indication (Loc,
1543 Subtype_Mark => New_Occurrence_Of (Bas, Loc),
1544 Constraint =>
1545 Make_Index_Or_Discriminant_Constraint (Loc,
1546 Constraints => Constraints)));
1548 Insert_Action (N, Decl);
1550 -- If the context is a component declaration the subtype declaration
1551 -- will be analyzed when the enclosing type is frozen, otherwise do
1552 -- it now.
1554 if Ekind (Current_Scope) /= E_Record_Type then
1555 Analyze (Decl);
1556 end if;
1558 return Act;
1559 end;
1560 end Build_Default_Subtype;
1562 --------------------------------------------
1563 -- Build_Discriminal_Subtype_Of_Component --
1564 --------------------------------------------
1566 function Build_Discriminal_Subtype_Of_Component
1567 (T : Entity_Id) return Node_Id
1569 Loc : constant Source_Ptr := Sloc (T);
1570 D : Elmt_Id;
1571 Id : Node_Id;
1573 function Build_Discriminal_Array_Constraint return List_Id;
1574 -- If one or more of the bounds of the component depends on
1575 -- discriminants, build actual constraint using the discriminants
1576 -- of the prefix.
1578 function Build_Discriminal_Record_Constraint return List_Id;
1579 -- Similar to previous one, for discriminated components constrained by
1580 -- the discriminant of the enclosing object.
1582 ----------------------------------------
1583 -- Build_Discriminal_Array_Constraint --
1584 ----------------------------------------
1586 function Build_Discriminal_Array_Constraint return List_Id is
1587 Constraints : constant List_Id := New_List;
1588 Indx : Node_Id;
1589 Hi : Node_Id;
1590 Lo : Node_Id;
1591 Old_Hi : Node_Id;
1592 Old_Lo : Node_Id;
1594 begin
1595 Indx := First_Index (T);
1596 while Present (Indx) loop
1597 Old_Lo := Type_Low_Bound (Etype (Indx));
1598 Old_Hi := Type_High_Bound (Etype (Indx));
1600 if Denotes_Discriminant (Old_Lo) then
1601 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
1603 else
1604 Lo := New_Copy_Tree (Old_Lo);
1605 end if;
1607 if Denotes_Discriminant (Old_Hi) then
1608 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
1610 else
1611 Hi := New_Copy_Tree (Old_Hi);
1612 end if;
1614 Append (Make_Range (Loc, Lo, Hi), Constraints);
1615 Next_Index (Indx);
1616 end loop;
1618 return Constraints;
1619 end Build_Discriminal_Array_Constraint;
1621 -----------------------------------------
1622 -- Build_Discriminal_Record_Constraint --
1623 -----------------------------------------
1625 function Build_Discriminal_Record_Constraint return List_Id is
1626 Constraints : constant List_Id := New_List;
1627 D : Elmt_Id;
1628 D_Val : Node_Id;
1630 begin
1631 D := First_Elmt (Discriminant_Constraint (T));
1632 while Present (D) loop
1633 if Denotes_Discriminant (Node (D)) then
1634 D_Val :=
1635 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
1636 else
1637 D_Val := New_Copy_Tree (Node (D));
1638 end if;
1640 Append (D_Val, Constraints);
1641 Next_Elmt (D);
1642 end loop;
1644 return Constraints;
1645 end Build_Discriminal_Record_Constraint;
1647 -- Start of processing for Build_Discriminal_Subtype_Of_Component
1649 begin
1650 if Ekind (T) = E_Array_Subtype then
1651 Id := First_Index (T);
1652 while Present (Id) loop
1653 if Denotes_Discriminant (Type_Low_Bound (Etype (Id)))
1654 or else
1655 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
1656 then
1657 return Build_Component_Subtype
1658 (Build_Discriminal_Array_Constraint, Loc, T);
1659 end if;
1661 Next_Index (Id);
1662 end loop;
1664 elsif Ekind (T) = E_Record_Subtype
1665 and then Has_Discriminants (T)
1666 and then not Has_Unknown_Discriminants (T)
1667 then
1668 D := First_Elmt (Discriminant_Constraint (T));
1669 while Present (D) loop
1670 if Denotes_Discriminant (Node (D)) then
1671 return Build_Component_Subtype
1672 (Build_Discriminal_Record_Constraint, Loc, T);
1673 end if;
1675 Next_Elmt (D);
1676 end loop;
1677 end if;
1679 -- If none of the above, the actual and nominal subtypes are the same
1681 return Empty;
1682 end Build_Discriminal_Subtype_Of_Component;
1684 ------------------------------
1685 -- Build_Elaboration_Entity --
1686 ------------------------------
1688 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
1689 Loc : constant Source_Ptr := Sloc (N);
1690 Decl : Node_Id;
1691 Elab_Ent : Entity_Id;
1693 procedure Set_Package_Name (Ent : Entity_Id);
1694 -- Given an entity, sets the fully qualified name of the entity in
1695 -- Name_Buffer, with components separated by double underscores. This
1696 -- is a recursive routine that climbs the scope chain to Standard.
1698 ----------------------
1699 -- Set_Package_Name --
1700 ----------------------
1702 procedure Set_Package_Name (Ent : Entity_Id) is
1703 begin
1704 if Scope (Ent) /= Standard_Standard then
1705 Set_Package_Name (Scope (Ent));
1707 declare
1708 Nam : constant String := Get_Name_String (Chars (Ent));
1709 begin
1710 Name_Buffer (Name_Len + 1) := '_';
1711 Name_Buffer (Name_Len + 2) := '_';
1712 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
1713 Name_Len := Name_Len + Nam'Length + 2;
1714 end;
1716 else
1717 Get_Name_String (Chars (Ent));
1718 end if;
1719 end Set_Package_Name;
1721 -- Start of processing for Build_Elaboration_Entity
1723 begin
1724 -- Ignore call if already constructed
1726 if Present (Elaboration_Entity (Spec_Id)) then
1727 return;
1729 -- Ignore in ASIS mode, elaboration entity is not in source and plays
1730 -- no role in analysis.
1732 elsif ASIS_Mode then
1733 return;
1735 -- Do not generate an elaboration entity in GNATprove move because the
1736 -- elaboration counter is a form of expansion.
1738 elsif GNATprove_Mode then
1739 return;
1741 -- See if we need elaboration entity
1743 -- We always need an elaboration entity when preserving control flow, as
1744 -- we want to remain explicit about the unit's elaboration order.
1746 elsif Opt.Suppress_Control_Flow_Optimizations then
1747 null;
1749 -- We always need an elaboration entity for the dynamic elaboration
1750 -- model, since it is needed to properly generate the PE exception for
1751 -- access before elaboration.
1753 elsif Dynamic_Elaboration_Checks then
1754 null;
1756 -- For the static model, we don't need the elaboration counter if this
1757 -- unit is sure to have no elaboration code, since that means there
1758 -- is no elaboration unit to be called. Note that we can't just decide
1759 -- after the fact by looking to see whether there was elaboration code,
1760 -- because that's too late to make this decision.
1762 elsif Restriction_Active (No_Elaboration_Code) then
1763 return;
1765 -- Similarly, for the static model, we can skip the elaboration counter
1766 -- if we have the No_Multiple_Elaboration restriction, since for the
1767 -- static model, that's the only purpose of the counter (to avoid
1768 -- multiple elaboration).
1770 elsif Restriction_Active (No_Multiple_Elaboration) then
1771 return;
1772 end if;
1774 -- Here we need the elaboration entity
1776 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
1777 -- name with dots replaced by double underscore. We have to manually
1778 -- construct this name, since it will be elaborated in the outer scope,
1779 -- and thus will not have the unit name automatically prepended.
1781 Set_Package_Name (Spec_Id);
1782 Add_Str_To_Name_Buffer ("_E");
1784 -- Create elaboration counter
1786 Elab_Ent := Make_Defining_Identifier (Loc, Chars => Name_Find);
1787 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
1789 Decl :=
1790 Make_Object_Declaration (Loc,
1791 Defining_Identifier => Elab_Ent,
1792 Object_Definition =>
1793 New_Occurrence_Of (Standard_Short_Integer, Loc),
1794 Expression => Make_Integer_Literal (Loc, Uint_0));
1796 Push_Scope (Standard_Standard);
1797 Add_Global_Declaration (Decl);
1798 Pop_Scope;
1800 -- Reset True_Constant indication, since we will indeed assign a value
1801 -- to the variable in the binder main. We also kill the Current_Value
1802 -- and Last_Assignment fields for the same reason.
1804 Set_Is_True_Constant (Elab_Ent, False);
1805 Set_Current_Value (Elab_Ent, Empty);
1806 Set_Last_Assignment (Elab_Ent, Empty);
1808 -- We do not want any further qualification of the name (if we did not
1809 -- do this, we would pick up the name of the generic package in the case
1810 -- of a library level generic instantiation).
1812 Set_Has_Qualified_Name (Elab_Ent);
1813 Set_Has_Fully_Qualified_Name (Elab_Ent);
1814 end Build_Elaboration_Entity;
1816 --------------------------------
1817 -- Build_Explicit_Dereference --
1818 --------------------------------
1820 procedure Build_Explicit_Dereference
1821 (Expr : Node_Id;
1822 Disc : Entity_Id)
1824 Loc : constant Source_Ptr := Sloc (Expr);
1825 I : Interp_Index;
1826 It : Interp;
1828 begin
1829 -- An entity of a type with a reference aspect is overloaded with
1830 -- both interpretations: with and without the dereference. Now that
1831 -- the dereference is made explicit, set the type of the node properly,
1832 -- to prevent anomalies in the backend. Same if the expression is an
1833 -- overloaded function call whose return type has a reference aspect.
1835 if Is_Entity_Name (Expr) then
1836 Set_Etype (Expr, Etype (Entity (Expr)));
1838 -- The designated entity will not be examined again when resolving
1839 -- the dereference, so generate a reference to it now.
1841 Generate_Reference (Entity (Expr), Expr);
1843 elsif Nkind (Expr) = N_Function_Call then
1845 -- If the name of the indexing function is overloaded, locate the one
1846 -- whose return type has an implicit dereference on the desired
1847 -- discriminant, and set entity and type of function call.
1849 if Is_Overloaded (Name (Expr)) then
1850 Get_First_Interp (Name (Expr), I, It);
1852 while Present (It.Nam) loop
1853 if Ekind ((It.Typ)) = E_Record_Type
1854 and then First_Entity ((It.Typ)) = Disc
1855 then
1856 Set_Entity (Name (Expr), It.Nam);
1857 Set_Etype (Name (Expr), Etype (It.Nam));
1858 exit;
1859 end if;
1861 Get_Next_Interp (I, It);
1862 end loop;
1863 end if;
1865 -- Set type of call from resolved function name.
1867 Set_Etype (Expr, Etype (Name (Expr)));
1868 end if;
1870 Set_Is_Overloaded (Expr, False);
1872 -- The expression will often be a generalized indexing that yields a
1873 -- container element that is then dereferenced, in which case the
1874 -- generalized indexing call is also non-overloaded.
1876 if Nkind (Expr) = N_Indexed_Component
1877 and then Present (Generalized_Indexing (Expr))
1878 then
1879 Set_Is_Overloaded (Generalized_Indexing (Expr), False);
1880 end if;
1882 Rewrite (Expr,
1883 Make_Explicit_Dereference (Loc,
1884 Prefix =>
1885 Make_Selected_Component (Loc,
1886 Prefix => Relocate_Node (Expr),
1887 Selector_Name => New_Occurrence_Of (Disc, Loc))));
1888 Set_Etype (Prefix (Expr), Etype (Disc));
1889 Set_Etype (Expr, Designated_Type (Etype (Disc)));
1890 end Build_Explicit_Dereference;
1892 ---------------------------
1893 -- Build_Overriding_Spec --
1894 ---------------------------
1896 function Build_Overriding_Spec
1897 (Op : Entity_Id;
1898 Typ : Entity_Id) return Node_Id
1900 Loc : constant Source_Ptr := Sloc (Typ);
1901 Par_Typ : constant Entity_Id := Find_Dispatching_Type (Op);
1902 Spec : constant Node_Id := Specification (Unit_Declaration_Node (Op));
1904 Formal_Spec : Node_Id;
1905 Formal_Type : Node_Id;
1906 New_Spec : Node_Id;
1908 begin
1909 New_Spec := Copy_Subprogram_Spec (Spec);
1911 Formal_Spec := First (Parameter_Specifications (New_Spec));
1912 while Present (Formal_Spec) loop
1913 Formal_Type := Parameter_Type (Formal_Spec);
1915 if Is_Entity_Name (Formal_Type)
1916 and then Entity (Formal_Type) = Par_Typ
1917 then
1918 Rewrite (Formal_Type, New_Occurrence_Of (Typ, Loc));
1919 end if;
1921 -- Nothing needs to be done for access parameters
1923 Next (Formal_Spec);
1924 end loop;
1926 return New_Spec;
1927 end Build_Overriding_Spec;
1929 -----------------------------------
1930 -- Cannot_Raise_Constraint_Error --
1931 -----------------------------------
1933 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
1934 begin
1935 if Compile_Time_Known_Value (Expr) then
1936 return True;
1938 elsif Do_Range_Check (Expr) then
1939 return False;
1941 elsif Raises_Constraint_Error (Expr) then
1942 return False;
1944 else
1945 case Nkind (Expr) is
1946 when N_Identifier =>
1947 return True;
1949 when N_Expanded_Name =>
1950 return True;
1952 when N_Selected_Component =>
1953 return not Do_Discriminant_Check (Expr);
1955 when N_Attribute_Reference =>
1956 if Do_Overflow_Check (Expr) then
1957 return False;
1959 elsif No (Expressions (Expr)) then
1960 return True;
1962 else
1963 declare
1964 N : Node_Id;
1966 begin
1967 N := First (Expressions (Expr));
1968 while Present (N) loop
1969 if Cannot_Raise_Constraint_Error (N) then
1970 Next (N);
1971 else
1972 return False;
1973 end if;
1974 end loop;
1976 return True;
1977 end;
1978 end if;
1980 when N_Type_Conversion =>
1981 if Do_Overflow_Check (Expr)
1982 or else Do_Length_Check (Expr)
1983 or else Do_Tag_Check (Expr)
1984 then
1985 return False;
1986 else
1987 return Cannot_Raise_Constraint_Error (Expression (Expr));
1988 end if;
1990 when N_Unchecked_Type_Conversion =>
1991 return Cannot_Raise_Constraint_Error (Expression (Expr));
1993 when N_Unary_Op =>
1994 if Do_Overflow_Check (Expr) then
1995 return False;
1996 else
1997 return Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1998 end if;
2000 when N_Op_Divide
2001 | N_Op_Mod
2002 | N_Op_Rem
2004 if Do_Division_Check (Expr)
2005 or else
2006 Do_Overflow_Check (Expr)
2007 then
2008 return False;
2009 else
2010 return
2011 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
2012 and then
2013 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
2014 end if;
2016 when N_Op_Add
2017 | N_Op_And
2018 | N_Op_Concat
2019 | N_Op_Eq
2020 | N_Op_Expon
2021 | N_Op_Ge
2022 | N_Op_Gt
2023 | N_Op_Le
2024 | N_Op_Lt
2025 | N_Op_Multiply
2026 | N_Op_Ne
2027 | N_Op_Or
2028 | N_Op_Rotate_Left
2029 | N_Op_Rotate_Right
2030 | N_Op_Shift_Left
2031 | N_Op_Shift_Right
2032 | N_Op_Shift_Right_Arithmetic
2033 | N_Op_Subtract
2034 | N_Op_Xor
2036 if Do_Overflow_Check (Expr) then
2037 return False;
2038 else
2039 return
2040 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
2041 and then
2042 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
2043 end if;
2045 when others =>
2046 return False;
2047 end case;
2048 end if;
2049 end Cannot_Raise_Constraint_Error;
2051 -----------------------------------------
2052 -- Check_Dynamically_Tagged_Expression --
2053 -----------------------------------------
2055 procedure Check_Dynamically_Tagged_Expression
2056 (Expr : Node_Id;
2057 Typ : Entity_Id;
2058 Related_Nod : Node_Id)
2060 begin
2061 pragma Assert (Is_Tagged_Type (Typ));
2063 -- In order to avoid spurious errors when analyzing the expanded code,
2064 -- this check is done only for nodes that come from source and for
2065 -- actuals of generic instantiations.
2067 if (Comes_From_Source (Related_Nod)
2068 or else In_Generic_Actual (Expr))
2069 and then (Is_Class_Wide_Type (Etype (Expr))
2070 or else Is_Dynamically_Tagged (Expr))
2071 and then not Is_Class_Wide_Type (Typ)
2072 then
2073 Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
2074 end if;
2075 end Check_Dynamically_Tagged_Expression;
2077 --------------------------
2078 -- Check_Fully_Declared --
2079 --------------------------
2081 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
2082 begin
2083 if Ekind (T) = E_Incomplete_Type then
2085 -- Ada 2005 (AI-50217): If the type is available through a limited
2086 -- with_clause, verify that its full view has been analyzed.
2088 if From_Limited_With (T)
2089 and then Present (Non_Limited_View (T))
2090 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
2091 then
2092 -- The non-limited view is fully declared
2094 null;
2096 else
2097 Error_Msg_NE
2098 ("premature usage of incomplete}", N, First_Subtype (T));
2099 end if;
2101 -- Need comments for these tests ???
2103 elsif Has_Private_Component (T)
2104 and then not Is_Generic_Type (Root_Type (T))
2105 and then not In_Spec_Expression
2106 then
2107 -- Special case: if T is the anonymous type created for a single
2108 -- task or protected object, use the name of the source object.
2110 if Is_Concurrent_Type (T)
2111 and then not Comes_From_Source (T)
2112 and then Nkind (N) = N_Object_Declaration
2113 then
2114 Error_Msg_NE
2115 ("type of& has incomplete component",
2116 N, Defining_Identifier (N));
2117 else
2118 Error_Msg_NE
2119 ("premature usage of incomplete}",
2120 N, First_Subtype (T));
2121 end if;
2122 end if;
2123 end Check_Fully_Declared;
2125 -------------------------------------------
2126 -- Check_Function_With_Address_Parameter --
2127 -------------------------------------------
2129 procedure Check_Function_With_Address_Parameter (Subp_Id : Entity_Id) is
2130 F : Entity_Id;
2131 T : Entity_Id;
2133 begin
2134 F := First_Formal (Subp_Id);
2135 while Present (F) loop
2136 T := Etype (F);
2138 if Is_Private_Type (T) and then Present (Full_View (T)) then
2139 T := Full_View (T);
2140 end if;
2142 if Is_Descendant_Of_Address (T) or else Is_Limited_Type (T) then
2143 Set_Is_Pure (Subp_Id, False);
2144 exit;
2145 end if;
2147 Next_Formal (F);
2148 end loop;
2149 end Check_Function_With_Address_Parameter;
2151 -------------------------------------
2152 -- Check_Function_Writable_Actuals --
2153 -------------------------------------
2155 procedure Check_Function_Writable_Actuals (N : Node_Id) is
2156 Writable_Actuals_List : Elist_Id := No_Elist;
2157 Identifiers_List : Elist_Id := No_Elist;
2158 Aggr_Error_Node : Node_Id := Empty;
2159 Error_Node : Node_Id := Empty;
2161 procedure Collect_Identifiers (N : Node_Id);
2162 -- In a single traversal of subtree N collect in Writable_Actuals_List
2163 -- all the actuals of functions with writable actuals, and in the list
2164 -- Identifiers_List collect all the identifiers that are not actuals of
2165 -- functions with writable actuals. If a writable actual is referenced
2166 -- twice as writable actual then Error_Node is set to reference its
2167 -- second occurrence, the error is reported, and the tree traversal
2168 -- is abandoned.
2170 procedure Preanalyze_Without_Errors (N : Node_Id);
2171 -- Preanalyze N without reporting errors. Very dubious, you can't just
2172 -- go analyzing things more than once???
2174 -------------------------
2175 -- Collect_Identifiers --
2176 -------------------------
2178 procedure Collect_Identifiers (N : Node_Id) is
2180 function Check_Node (N : Node_Id) return Traverse_Result;
2181 -- Process a single node during the tree traversal to collect the
2182 -- writable actuals of functions and all the identifiers which are
2183 -- not writable actuals of functions.
2185 function Contains (List : Elist_Id; N : Node_Id) return Boolean;
2186 -- Returns True if List has a node whose Entity is Entity (N)
2188 ----------------
2189 -- Check_Node --
2190 ----------------
2192 function Check_Node (N : Node_Id) return Traverse_Result is
2193 Is_Writable_Actual : Boolean := False;
2194 Id : Entity_Id;
2196 begin
2197 if Nkind (N) = N_Identifier then
2199 -- No analysis possible if the entity is not decorated
2201 if No (Entity (N)) then
2202 return Skip;
2204 -- Don't collect identifiers of packages, called functions, etc
2206 elsif Ekind_In (Entity (N), E_Package,
2207 E_Function,
2208 E_Procedure,
2209 E_Entry)
2210 then
2211 return Skip;
2213 -- For rewritten nodes, continue the traversal in the original
2214 -- subtree. Needed to handle aggregates in original expressions
2215 -- extracted from the tree by Remove_Side_Effects.
2217 elsif Is_Rewrite_Substitution (N) then
2218 Collect_Identifiers (Original_Node (N));
2219 return Skip;
2221 -- For now we skip aggregate discriminants, since they require
2222 -- performing the analysis in two phases to identify conflicts:
2223 -- first one analyzing discriminants and second one analyzing
2224 -- the rest of components (since at run time, discriminants are
2225 -- evaluated prior to components): too much computation cost
2226 -- to identify a corner case???
2228 elsif Nkind (Parent (N)) = N_Component_Association
2229 and then Nkind_In (Parent (Parent (N)),
2230 N_Aggregate,
2231 N_Extension_Aggregate)
2232 then
2233 declare
2234 Choice : constant Node_Id := First (Choices (Parent (N)));
2236 begin
2237 if Ekind (Entity (N)) = E_Discriminant then
2238 return Skip;
2240 elsif Expression (Parent (N)) = N
2241 and then Nkind (Choice) = N_Identifier
2242 and then Ekind (Entity (Choice)) = E_Discriminant
2243 then
2244 return Skip;
2245 end if;
2246 end;
2248 -- Analyze if N is a writable actual of a function
2250 elsif Nkind (Parent (N)) = N_Function_Call then
2251 declare
2252 Call : constant Node_Id := Parent (N);
2253 Actual : Node_Id;
2254 Formal : Node_Id;
2256 begin
2257 Id := Get_Called_Entity (Call);
2259 -- In case of previous error, no check is possible
2261 if No (Id) then
2262 return Abandon;
2263 end if;
2265 if Ekind_In (Id, E_Function, E_Generic_Function)
2266 and then Has_Out_Or_In_Out_Parameter (Id)
2267 then
2268 Formal := First_Formal (Id);
2269 Actual := First_Actual (Call);
2270 while Present (Actual) and then Present (Formal) loop
2271 if Actual = N then
2272 if Ekind_In (Formal, E_Out_Parameter,
2273 E_In_Out_Parameter)
2274 then
2275 Is_Writable_Actual := True;
2276 end if;
2278 exit;
2279 end if;
2281 Next_Formal (Formal);
2282 Next_Actual (Actual);
2283 end loop;
2284 end if;
2285 end;
2286 end if;
2288 if Is_Writable_Actual then
2290 -- Skip checking the error in non-elementary types since
2291 -- RM 6.4.1(6.15/3) is restricted to elementary types, but
2292 -- store this actual in Writable_Actuals_List since it is
2293 -- needed to perform checks on other constructs that have
2294 -- arbitrary order of evaluation (for example, aggregates).
2296 if not Is_Elementary_Type (Etype (N)) then
2297 if not Contains (Writable_Actuals_List, N) then
2298 Append_New_Elmt (N, To => Writable_Actuals_List);
2299 end if;
2301 -- Second occurrence of an elementary type writable actual
2303 elsif Contains (Writable_Actuals_List, N) then
2305 -- Report the error on the second occurrence of the
2306 -- identifier. We cannot assume that N is the second
2307 -- occurrence (according to their location in the
2308 -- sources), since Traverse_Func walks through Field2
2309 -- last (see comment in the body of Traverse_Func).
2311 declare
2312 Elmt : Elmt_Id;
2314 begin
2315 Elmt := First_Elmt (Writable_Actuals_List);
2316 while Present (Elmt)
2317 and then Entity (Node (Elmt)) /= Entity (N)
2318 loop
2319 Next_Elmt (Elmt);
2320 end loop;
2322 if Sloc (N) > Sloc (Node (Elmt)) then
2323 Error_Node := N;
2324 else
2325 Error_Node := Node (Elmt);
2326 end if;
2328 Error_Msg_NE
2329 ("value may be affected by call to & "
2330 & "because order of evaluation is arbitrary",
2331 Error_Node, Id);
2332 return Abandon;
2333 end;
2335 -- First occurrence of a elementary type writable actual
2337 else
2338 Append_New_Elmt (N, To => Writable_Actuals_List);
2339 end if;
2341 else
2342 if Identifiers_List = No_Elist then
2343 Identifiers_List := New_Elmt_List;
2344 end if;
2346 Append_Unique_Elmt (N, Identifiers_List);
2347 end if;
2348 end if;
2350 return OK;
2351 end Check_Node;
2353 --------------
2354 -- Contains --
2355 --------------
2357 function Contains
2358 (List : Elist_Id;
2359 N : Node_Id) return Boolean
2361 pragma Assert (Nkind (N) in N_Has_Entity);
2363 Elmt : Elmt_Id;
2365 begin
2366 if List = No_Elist then
2367 return False;
2368 end if;
2370 Elmt := First_Elmt (List);
2371 while Present (Elmt) loop
2372 if Entity (Node (Elmt)) = Entity (N) then
2373 return True;
2374 else
2375 Next_Elmt (Elmt);
2376 end if;
2377 end loop;
2379 return False;
2380 end Contains;
2382 ------------------
2383 -- Do_Traversal --
2384 ------------------
2386 procedure Do_Traversal is new Traverse_Proc (Check_Node);
2387 -- The traversal procedure
2389 -- Start of processing for Collect_Identifiers
2391 begin
2392 if Present (Error_Node) then
2393 return;
2394 end if;
2396 if Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then
2397 return;
2398 end if;
2400 Do_Traversal (N);
2401 end Collect_Identifiers;
2403 -------------------------------
2404 -- Preanalyze_Without_Errors --
2405 -------------------------------
2407 procedure Preanalyze_Without_Errors (N : Node_Id) is
2408 Status : constant Boolean := Get_Ignore_Errors;
2409 begin
2410 Set_Ignore_Errors (True);
2411 Preanalyze (N);
2412 Set_Ignore_Errors (Status);
2413 end Preanalyze_Without_Errors;
2415 -- Start of processing for Check_Function_Writable_Actuals
2417 begin
2418 -- The check only applies to Ada 2012 code on which Check_Actuals has
2419 -- been set, and only to constructs that have multiple constituents
2420 -- whose order of evaluation is not specified by the language.
2422 if Ada_Version < Ada_2012
2423 or else not Check_Actuals (N)
2424 or else (not (Nkind (N) in N_Op)
2425 and then not (Nkind (N) in N_Membership_Test)
2426 and then not Nkind_In (N, N_Range,
2427 N_Aggregate,
2428 N_Extension_Aggregate,
2429 N_Full_Type_Declaration,
2430 N_Function_Call,
2431 N_Procedure_Call_Statement,
2432 N_Entry_Call_Statement))
2433 or else (Nkind (N) = N_Full_Type_Declaration
2434 and then not Is_Record_Type (Defining_Identifier (N)))
2436 -- In addition, this check only applies to source code, not to code
2437 -- generated by constraint checks.
2439 or else not Comes_From_Source (N)
2440 then
2441 return;
2442 end if;
2444 -- If a construct C has two or more direct constituents that are names
2445 -- or expressions whose evaluation may occur in an arbitrary order, at
2446 -- least one of which contains a function call with an in out or out
2447 -- parameter, then the construct is legal only if: for each name N that
2448 -- is passed as a parameter of mode in out or out to some inner function
2449 -- call C2 (not including the construct C itself), there is no other
2450 -- name anywhere within a direct constituent of the construct C other
2451 -- than the one containing C2, that is known to refer to the same
2452 -- object (RM 6.4.1(6.17/3)).
2454 case Nkind (N) is
2455 when N_Range =>
2456 Collect_Identifiers (Low_Bound (N));
2457 Collect_Identifiers (High_Bound (N));
2459 when N_Membership_Test
2460 | N_Op
2462 declare
2463 Expr : Node_Id;
2465 begin
2466 Collect_Identifiers (Left_Opnd (N));
2468 if Present (Right_Opnd (N)) then
2469 Collect_Identifiers (Right_Opnd (N));
2470 end if;
2472 if Nkind_In (N, N_In, N_Not_In)
2473 and then Present (Alternatives (N))
2474 then
2475 Expr := First (Alternatives (N));
2476 while Present (Expr) loop
2477 Collect_Identifiers (Expr);
2479 Next (Expr);
2480 end loop;
2481 end if;
2482 end;
2484 when N_Full_Type_Declaration =>
2485 declare
2486 function Get_Record_Part (N : Node_Id) return Node_Id;
2487 -- Return the record part of this record type definition
2489 function Get_Record_Part (N : Node_Id) return Node_Id is
2490 Type_Def : constant Node_Id := Type_Definition (N);
2491 begin
2492 if Nkind (Type_Def) = N_Derived_Type_Definition then
2493 return Record_Extension_Part (Type_Def);
2494 else
2495 return Type_Def;
2496 end if;
2497 end Get_Record_Part;
2499 Comp : Node_Id;
2500 Def_Id : Entity_Id := Defining_Identifier (N);
2501 Rec : Node_Id := Get_Record_Part (N);
2503 begin
2504 -- No need to perform any analysis if the record has no
2505 -- components
2507 if No (Rec) or else No (Component_List (Rec)) then
2508 return;
2509 end if;
2511 -- Collect the identifiers starting from the deepest
2512 -- derivation. Done to report the error in the deepest
2513 -- derivation.
2515 loop
2516 if Present (Component_List (Rec)) then
2517 Comp := First (Component_Items (Component_List (Rec)));
2518 while Present (Comp) loop
2519 if Nkind (Comp) = N_Component_Declaration
2520 and then Present (Expression (Comp))
2521 then
2522 Collect_Identifiers (Expression (Comp));
2523 end if;
2525 Next (Comp);
2526 end loop;
2527 end if;
2529 exit when No (Underlying_Type (Etype (Def_Id)))
2530 or else Base_Type (Underlying_Type (Etype (Def_Id)))
2531 = Def_Id;
2533 Def_Id := Base_Type (Underlying_Type (Etype (Def_Id)));
2534 Rec := Get_Record_Part (Parent (Def_Id));
2535 end loop;
2536 end;
2538 when N_Entry_Call_Statement
2539 | N_Subprogram_Call
2541 declare
2542 Id : constant Entity_Id := Get_Called_Entity (N);
2543 Formal : Node_Id;
2544 Actual : Node_Id;
2546 begin
2547 Formal := First_Formal (Id);
2548 Actual := First_Actual (N);
2549 while Present (Actual) and then Present (Formal) loop
2550 if Ekind_In (Formal, E_Out_Parameter,
2551 E_In_Out_Parameter)
2552 then
2553 Collect_Identifiers (Actual);
2554 end if;
2556 Next_Formal (Formal);
2557 Next_Actual (Actual);
2558 end loop;
2559 end;
2561 when N_Aggregate
2562 | N_Extension_Aggregate
2564 declare
2565 Assoc : Node_Id;
2566 Choice : Node_Id;
2567 Comp_Expr : Node_Id;
2569 begin
2570 -- Handle the N_Others_Choice of array aggregates with static
2571 -- bounds. There is no need to perform this analysis in
2572 -- aggregates without static bounds since we cannot evaluate
2573 -- if the N_Others_Choice covers several elements. There is
2574 -- no need to handle the N_Others choice of record aggregates
2575 -- since at this stage it has been already expanded by
2576 -- Resolve_Record_Aggregate.
2578 if Is_Array_Type (Etype (N))
2579 and then Nkind (N) = N_Aggregate
2580 and then Present (Aggregate_Bounds (N))
2581 and then Compile_Time_Known_Bounds (Etype (N))
2582 and then Expr_Value (High_Bound (Aggregate_Bounds (N)))
2584 Expr_Value (Low_Bound (Aggregate_Bounds (N)))
2585 then
2586 declare
2587 Count_Components : Uint := Uint_0;
2588 Num_Components : Uint;
2589 Others_Assoc : Node_Id;
2590 Others_Choice : Node_Id := Empty;
2591 Others_Box_Present : Boolean := False;
2593 begin
2594 -- Count positional associations
2596 if Present (Expressions (N)) then
2597 Comp_Expr := First (Expressions (N));
2598 while Present (Comp_Expr) loop
2599 Count_Components := Count_Components + 1;
2600 Next (Comp_Expr);
2601 end loop;
2602 end if;
2604 -- Count the rest of elements and locate the N_Others
2605 -- choice (if any)
2607 Assoc := First (Component_Associations (N));
2608 while Present (Assoc) loop
2609 Choice := First (Choices (Assoc));
2610 while Present (Choice) loop
2611 if Nkind (Choice) = N_Others_Choice then
2612 Others_Assoc := Assoc;
2613 Others_Choice := Choice;
2614 Others_Box_Present := Box_Present (Assoc);
2616 -- Count several components
2618 elsif Nkind_In (Choice, N_Range,
2619 N_Subtype_Indication)
2620 or else (Is_Entity_Name (Choice)
2621 and then Is_Type (Entity (Choice)))
2622 then
2623 declare
2624 L, H : Node_Id;
2625 begin
2626 Get_Index_Bounds (Choice, L, H);
2627 pragma Assert
2628 (Compile_Time_Known_Value (L)
2629 and then Compile_Time_Known_Value (H));
2630 Count_Components :=
2631 Count_Components
2632 + Expr_Value (H) - Expr_Value (L) + 1;
2633 end;
2635 -- Count single component. No other case available
2636 -- since we are handling an aggregate with static
2637 -- bounds.
2639 else
2640 pragma Assert (Is_OK_Static_Expression (Choice)
2641 or else Nkind (Choice) = N_Identifier
2642 or else Nkind (Choice) = N_Integer_Literal);
2644 Count_Components := Count_Components + 1;
2645 end if;
2647 Next (Choice);
2648 end loop;
2650 Next (Assoc);
2651 end loop;
2653 Num_Components :=
2654 Expr_Value (High_Bound (Aggregate_Bounds (N))) -
2655 Expr_Value (Low_Bound (Aggregate_Bounds (N))) + 1;
2657 pragma Assert (Count_Components <= Num_Components);
2659 -- Handle the N_Others choice if it covers several
2660 -- components
2662 if Present (Others_Choice)
2663 and then (Num_Components - Count_Components) > 1
2664 then
2665 if not Others_Box_Present then
2667 -- At this stage, if expansion is active, the
2668 -- expression of the others choice has not been
2669 -- analyzed. Hence we generate a duplicate and
2670 -- we analyze it silently to have available the
2671 -- minimum decoration required to collect the
2672 -- identifiers.
2674 if not Expander_Active then
2675 Comp_Expr := Expression (Others_Assoc);
2676 else
2677 Comp_Expr :=
2678 New_Copy_Tree (Expression (Others_Assoc));
2679 Preanalyze_Without_Errors (Comp_Expr);
2680 end if;
2682 Collect_Identifiers (Comp_Expr);
2684 if Writable_Actuals_List /= No_Elist then
2686 -- As suggested by Robert, at current stage we
2687 -- report occurrences of this case as warnings.
2689 Error_Msg_N
2690 ("writable function parameter may affect "
2691 & "value in other component because order "
2692 & "of evaluation is unspecified??",
2693 Node (First_Elmt (Writable_Actuals_List)));
2694 end if;
2695 end if;
2696 end if;
2697 end;
2699 -- For an array aggregate, a discrete_choice_list that has
2700 -- a nonstatic range is considered as two or more separate
2701 -- occurrences of the expression (RM 6.4.1(20/3)).
2703 elsif Is_Array_Type (Etype (N))
2704 and then Nkind (N) = N_Aggregate
2705 and then Present (Aggregate_Bounds (N))
2706 and then not Compile_Time_Known_Bounds (Etype (N))
2707 then
2708 -- Collect identifiers found in the dynamic bounds
2710 declare
2711 Count_Components : Natural := 0;
2712 Low, High : Node_Id;
2714 begin
2715 Assoc := First (Component_Associations (N));
2716 while Present (Assoc) loop
2717 Choice := First (Choices (Assoc));
2718 while Present (Choice) loop
2719 if Nkind_In (Choice, N_Range,
2720 N_Subtype_Indication)
2721 or else (Is_Entity_Name (Choice)
2722 and then Is_Type (Entity (Choice)))
2723 then
2724 Get_Index_Bounds (Choice, Low, High);
2726 if not Compile_Time_Known_Value (Low) then
2727 Collect_Identifiers (Low);
2729 if No (Aggr_Error_Node) then
2730 Aggr_Error_Node := Low;
2731 end if;
2732 end if;
2734 if not Compile_Time_Known_Value (High) then
2735 Collect_Identifiers (High);
2737 if No (Aggr_Error_Node) then
2738 Aggr_Error_Node := High;
2739 end if;
2740 end if;
2742 -- The RM rule is violated if there is more than
2743 -- a single choice in a component association.
2745 else
2746 Count_Components := Count_Components + 1;
2748 if No (Aggr_Error_Node)
2749 and then Count_Components > 1
2750 then
2751 Aggr_Error_Node := Choice;
2752 end if;
2754 if not Compile_Time_Known_Value (Choice) then
2755 Collect_Identifiers (Choice);
2756 end if;
2757 end if;
2759 Next (Choice);
2760 end loop;
2762 Next (Assoc);
2763 end loop;
2764 end;
2765 end if;
2767 -- Handle ancestor part of extension aggregates
2769 if Nkind (N) = N_Extension_Aggregate then
2770 Collect_Identifiers (Ancestor_Part (N));
2771 end if;
2773 -- Handle positional associations
2775 if Present (Expressions (N)) then
2776 Comp_Expr := First (Expressions (N));
2777 while Present (Comp_Expr) loop
2778 if not Is_OK_Static_Expression (Comp_Expr) then
2779 Collect_Identifiers (Comp_Expr);
2780 end if;
2782 Next (Comp_Expr);
2783 end loop;
2784 end if;
2786 -- Handle discrete associations
2788 if Present (Component_Associations (N)) then
2789 Assoc := First (Component_Associations (N));
2790 while Present (Assoc) loop
2792 if not Box_Present (Assoc) then
2793 Choice := First (Choices (Assoc));
2794 while Present (Choice) loop
2796 -- For now we skip discriminants since it requires
2797 -- performing the analysis in two phases: first one
2798 -- analyzing discriminants and second one analyzing
2799 -- the rest of components since discriminants are
2800 -- evaluated prior to components: too much extra
2801 -- work to detect a corner case???
2803 if Nkind (Choice) in N_Has_Entity
2804 and then Present (Entity (Choice))
2805 and then Ekind (Entity (Choice)) = E_Discriminant
2806 then
2807 null;
2809 elsif Box_Present (Assoc) then
2810 null;
2812 else
2813 if not Analyzed (Expression (Assoc)) then
2814 Comp_Expr :=
2815 New_Copy_Tree (Expression (Assoc));
2816 Set_Parent (Comp_Expr, Parent (N));
2817 Preanalyze_Without_Errors (Comp_Expr);
2818 else
2819 Comp_Expr := Expression (Assoc);
2820 end if;
2822 Collect_Identifiers (Comp_Expr);
2823 end if;
2825 Next (Choice);
2826 end loop;
2827 end if;
2829 Next (Assoc);
2830 end loop;
2831 end if;
2832 end;
2834 when others =>
2835 return;
2836 end case;
2838 -- No further action needed if we already reported an error
2840 if Present (Error_Node) then
2841 return;
2842 end if;
2844 -- Check violation of RM 6.20/3 in aggregates
2846 if Present (Aggr_Error_Node)
2847 and then Writable_Actuals_List /= No_Elist
2848 then
2849 Error_Msg_N
2850 ("value may be affected by call in other component because they "
2851 & "are evaluated in unspecified order",
2852 Node (First_Elmt (Writable_Actuals_List)));
2853 return;
2854 end if;
2856 -- Check if some writable argument of a function is referenced
2858 if Writable_Actuals_List /= No_Elist
2859 and then Identifiers_List /= No_Elist
2860 then
2861 declare
2862 Elmt_1 : Elmt_Id;
2863 Elmt_2 : Elmt_Id;
2865 begin
2866 Elmt_1 := First_Elmt (Writable_Actuals_List);
2867 while Present (Elmt_1) loop
2868 Elmt_2 := First_Elmt (Identifiers_List);
2869 while Present (Elmt_2) loop
2870 if Entity (Node (Elmt_1)) = Entity (Node (Elmt_2)) then
2871 case Nkind (Parent (Node (Elmt_2))) is
2872 when N_Aggregate
2873 | N_Component_Association
2874 | N_Component_Declaration
2876 Error_Msg_N
2877 ("value may be affected by call in other "
2878 & "component because they are evaluated "
2879 & "in unspecified order",
2880 Node (Elmt_2));
2882 when N_In
2883 | N_Not_In
2885 Error_Msg_N
2886 ("value may be affected by call in other "
2887 & "alternative because they are evaluated "
2888 & "in unspecified order",
2889 Node (Elmt_2));
2891 when others =>
2892 Error_Msg_N
2893 ("value of actual may be affected by call in "
2894 & "other actual because they are evaluated "
2895 & "in unspecified order",
2896 Node (Elmt_2));
2897 end case;
2898 end if;
2900 Next_Elmt (Elmt_2);
2901 end loop;
2903 Next_Elmt (Elmt_1);
2904 end loop;
2905 end;
2906 end if;
2907 end Check_Function_Writable_Actuals;
2909 --------------------------------
2910 -- Check_Implicit_Dereference --
2911 --------------------------------
2913 procedure Check_Implicit_Dereference (N : Node_Id; Typ : Entity_Id) is
2914 Disc : Entity_Id;
2915 Desig : Entity_Id;
2916 Nam : Node_Id;
2918 begin
2919 if Nkind (N) = N_Indexed_Component
2920 and then Present (Generalized_Indexing (N))
2921 then
2922 Nam := Generalized_Indexing (N);
2923 else
2924 Nam := N;
2925 end if;
2927 if Ada_Version < Ada_2012
2928 or else not Has_Implicit_Dereference (Base_Type (Typ))
2929 then
2930 return;
2932 elsif not Comes_From_Source (N)
2933 and then Nkind (N) /= N_Indexed_Component
2934 then
2935 return;
2937 elsif Is_Entity_Name (Nam) and then Is_Type (Entity (Nam)) then
2938 null;
2940 else
2941 Disc := First_Discriminant (Typ);
2942 while Present (Disc) loop
2943 if Has_Implicit_Dereference (Disc) then
2944 Desig := Designated_Type (Etype (Disc));
2945 Add_One_Interp (Nam, Disc, Desig);
2947 -- If the node is a generalized indexing, add interpretation
2948 -- to that node as well, for subsequent resolution.
2950 if Nkind (N) = N_Indexed_Component then
2951 Add_One_Interp (N, Disc, Desig);
2952 end if;
2954 -- If the operation comes from a generic unit and the context
2955 -- is a selected component, the selector name may be global
2956 -- and set in the instance already. Remove the entity to
2957 -- force resolution of the selected component, and the
2958 -- generation of an explicit dereference if needed.
2960 if In_Instance
2961 and then Nkind (Parent (Nam)) = N_Selected_Component
2962 then
2963 Set_Entity (Selector_Name (Parent (Nam)), Empty);
2964 end if;
2966 exit;
2967 end if;
2969 Next_Discriminant (Disc);
2970 end loop;
2971 end if;
2972 end Check_Implicit_Dereference;
2974 ----------------------------------
2975 -- Check_Internal_Protected_Use --
2976 ----------------------------------
2978 procedure Check_Internal_Protected_Use (N : Node_Id; Nam : Entity_Id) is
2979 S : Entity_Id;
2980 Prot : Entity_Id;
2982 begin
2983 Prot := Empty;
2985 S := Current_Scope;
2986 while Present (S) loop
2987 if S = Standard_Standard then
2988 exit;
2990 elsif Ekind (S) = E_Function
2991 and then Ekind (Scope (S)) = E_Protected_Type
2992 then
2993 Prot := Scope (S);
2994 exit;
2995 end if;
2997 S := Scope (S);
2998 end loop;
3000 if Present (Prot)
3001 and then Scope (Nam) = Prot
3002 and then Ekind (Nam) /= E_Function
3003 then
3004 -- An indirect function call (e.g. a callback within a protected
3005 -- function body) is not statically illegal. If the access type is
3006 -- anonymous and is the type of an access parameter, the scope of Nam
3007 -- will be the protected type, but it is not a protected operation.
3009 if Ekind (Nam) = E_Subprogram_Type
3010 and then Nkind (Associated_Node_For_Itype (Nam)) =
3011 N_Function_Specification
3012 then
3013 null;
3015 elsif Nkind (N) = N_Subprogram_Renaming_Declaration then
3016 Error_Msg_N
3017 ("within protected function cannot use protected procedure in "
3018 & "renaming or as generic actual", N);
3020 elsif Nkind (N) = N_Attribute_Reference then
3021 Error_Msg_N
3022 ("within protected function cannot take access of protected "
3023 & "procedure", N);
3025 else
3026 Error_Msg_N
3027 ("within protected function, protected object is constant", N);
3028 Error_Msg_N
3029 ("\cannot call operation that may modify it", N);
3030 end if;
3031 end if;
3033 -- Verify that an internal call does not appear within a precondition
3034 -- of a protected operation. This implements AI12-0166.
3035 -- The precondition aspect has been rewritten as a pragma Precondition
3036 -- and we check whether the scope of the called subprogram is the same
3037 -- as that of the entity to which the aspect applies.
3039 if Convention (Nam) = Convention_Protected then
3040 declare
3041 P : Node_Id;
3043 begin
3044 P := Parent (N);
3045 while Present (P) loop
3046 if Nkind (P) = N_Pragma
3047 and then Chars (Pragma_Identifier (P)) = Name_Precondition
3048 and then From_Aspect_Specification (P)
3049 and then
3050 Scope (Entity (Corresponding_Aspect (P))) = Scope (Nam)
3051 then
3052 Error_Msg_N
3053 ("internal call cannot appear in precondition of "
3054 & "protected operation", N);
3055 return;
3057 elsif Nkind (P) = N_Pragma
3058 and then Chars (Pragma_Identifier (P)) = Name_Contract_Cases
3059 then
3060 -- Check whether call is in a case guard. It is legal in a
3061 -- consequence.
3063 P := N;
3064 while Present (P) loop
3065 if Nkind (Parent (P)) = N_Component_Association
3066 and then P /= Expression (Parent (P))
3067 then
3068 Error_Msg_N
3069 ("internal call cannot appear in case guard in a "
3070 & "contract case", N);
3071 end if;
3073 P := Parent (P);
3074 end loop;
3076 return;
3078 elsif Nkind (P) = N_Parameter_Specification
3079 and then Scope (Current_Scope) = Scope (Nam)
3080 and then Nkind_In (Parent (P), N_Entry_Declaration,
3081 N_Subprogram_Declaration)
3082 then
3083 Error_Msg_N
3084 ("internal call cannot appear in default for formal of "
3085 & "protected operation", N);
3086 return;
3087 end if;
3089 P := Parent (P);
3090 end loop;
3091 end;
3092 end if;
3093 end Check_Internal_Protected_Use;
3095 ---------------------------------------
3096 -- Check_Later_Vs_Basic_Declarations --
3097 ---------------------------------------
3099 procedure Check_Later_Vs_Basic_Declarations
3100 (Decls : List_Id;
3101 During_Parsing : Boolean)
3103 Body_Sloc : Source_Ptr;
3104 Decl : Node_Id;
3106 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean;
3107 -- Return whether Decl is considered as a declarative item.
3108 -- When During_Parsing is True, the semantics of Ada 83 is followed.
3109 -- When During_Parsing is False, the semantics of SPARK is followed.
3111 -------------------------------
3112 -- Is_Later_Declarative_Item --
3113 -------------------------------
3115 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean is
3116 begin
3117 if Nkind (Decl) in N_Later_Decl_Item then
3118 return True;
3120 elsif Nkind (Decl) = N_Pragma then
3121 return True;
3123 elsif During_Parsing then
3124 return False;
3126 -- In SPARK, a package declaration is not considered as a later
3127 -- declarative item.
3129 elsif Nkind (Decl) = N_Package_Declaration then
3130 return False;
3132 -- In SPARK, a renaming is considered as a later declarative item
3134 elsif Nkind (Decl) in N_Renaming_Declaration then
3135 return True;
3137 else
3138 return False;
3139 end if;
3140 end Is_Later_Declarative_Item;
3142 -- Start of processing for Check_Later_Vs_Basic_Declarations
3144 begin
3145 Decl := First (Decls);
3147 -- Loop through sequence of basic declarative items
3149 Outer : while Present (Decl) loop
3150 if not Nkind_In (Decl, N_Subprogram_Body, N_Package_Body, N_Task_Body)
3151 and then Nkind (Decl) not in N_Body_Stub
3152 then
3153 Next (Decl);
3155 -- Once a body is encountered, we only allow later declarative
3156 -- items. The inner loop checks the rest of the list.
3158 else
3159 Body_Sloc := Sloc (Decl);
3161 Inner : while Present (Decl) loop
3162 if not Is_Later_Declarative_Item (Decl) then
3163 if During_Parsing then
3164 if Ada_Version = Ada_83 then
3165 Error_Msg_Sloc := Body_Sloc;
3166 Error_Msg_N
3167 ("(Ada 83) decl cannot appear after body#", Decl);
3168 end if;
3169 else
3170 Error_Msg_Sloc := Body_Sloc;
3171 Check_SPARK_05_Restriction
3172 ("decl cannot appear after body#", Decl);
3173 end if;
3174 end if;
3176 Next (Decl);
3177 end loop Inner;
3178 end if;
3179 end loop Outer;
3180 end Check_Later_Vs_Basic_Declarations;
3182 ---------------------------
3183 -- Check_No_Hidden_State --
3184 ---------------------------
3186 procedure Check_No_Hidden_State (Id : Entity_Id) is
3187 Context : Entity_Id := Empty;
3188 Not_Visible : Boolean := False;
3189 Scop : Entity_Id;
3191 begin
3192 pragma Assert (Ekind_In (Id, E_Abstract_State, E_Variable));
3194 -- Find the proper context where the object or state appears
3196 Scop := Scope (Id);
3197 while Present (Scop) loop
3198 Context := Scop;
3200 -- Keep track of the context's visibility
3202 Not_Visible := Not_Visible or else In_Private_Part (Context);
3204 -- Prevent the search from going too far
3206 if Context = Standard_Standard then
3207 return;
3209 -- Objects and states that appear immediately within a subprogram or
3210 -- inside a construct nested within a subprogram do not introduce a
3211 -- hidden state. They behave as local variable declarations.
3213 elsif Is_Subprogram (Context) then
3214 return;
3216 -- When examining a package body, use the entity of the spec as it
3217 -- carries the abstract state declarations.
3219 elsif Ekind (Context) = E_Package_Body then
3220 Context := Spec_Entity (Context);
3221 end if;
3223 -- Stop the traversal when a package subject to a null abstract state
3224 -- has been found.
3226 if Ekind_In (Context, E_Generic_Package, E_Package)
3227 and then Has_Null_Abstract_State (Context)
3228 then
3229 exit;
3230 end if;
3232 Scop := Scope (Scop);
3233 end loop;
3235 -- At this point we know that there is at least one package with a null
3236 -- abstract state in visibility. Emit an error message unconditionally
3237 -- if the entity being processed is a state because the placement of the
3238 -- related package is irrelevant. This is not the case for objects as
3239 -- the intermediate context matters.
3241 if Present (Context)
3242 and then (Ekind (Id) = E_Abstract_State or else Not_Visible)
3243 then
3244 Error_Msg_N ("cannot introduce hidden state &", Id);
3245 Error_Msg_NE ("\package & has null abstract state", Id, Context);
3246 end if;
3247 end Check_No_Hidden_State;
3249 ----------------------------------------
3250 -- Check_Nonvolatile_Function_Profile --
3251 ----------------------------------------
3253 procedure Check_Nonvolatile_Function_Profile (Func_Id : Entity_Id) is
3254 Formal : Entity_Id;
3256 begin
3257 -- Inspect all formal parameters
3259 Formal := First_Formal (Func_Id);
3260 while Present (Formal) loop
3261 if Is_Effectively_Volatile (Etype (Formal)) then
3262 Error_Msg_NE
3263 ("nonvolatile function & cannot have a volatile parameter",
3264 Formal, Func_Id);
3265 end if;
3267 Next_Formal (Formal);
3268 end loop;
3270 -- Inspect the return type
3272 if Is_Effectively_Volatile (Etype (Func_Id)) then
3273 Error_Msg_NE
3274 ("nonvolatile function & cannot have a volatile return type",
3275 Result_Definition (Parent (Func_Id)), Func_Id);
3276 end if;
3277 end Check_Nonvolatile_Function_Profile;
3279 -----------------------------
3280 -- Check_Part_Of_Reference --
3281 -----------------------------
3283 procedure Check_Part_Of_Reference (Var_Id : Entity_Id; Ref : Node_Id) is
3284 function Is_Enclosing_Package_Body
3285 (Body_Decl : Node_Id;
3286 Obj_Id : Entity_Id) return Boolean;
3287 pragma Inline (Is_Enclosing_Package_Body);
3288 -- Determine whether package body Body_Decl or its corresponding spec
3289 -- immediately encloses the declaration of object Obj_Id.
3291 function Is_Internal_Declaration_Or_Body
3292 (Decl : Node_Id) return Boolean;
3293 pragma Inline (Is_Internal_Declaration_Or_Body);
3294 -- Determine whether declaration or body denoted by Decl is internal
3296 function Is_Single_Declaration_Or_Body
3297 (Decl : Node_Id;
3298 Conc_Typ : Entity_Id) return Boolean;
3299 pragma Inline (Is_Single_Declaration_Or_Body);
3300 -- Determine whether protected/task declaration or body denoted by Decl
3301 -- belongs to single concurrent type Conc_Typ.
3303 function Is_Single_Task_Pragma
3304 (Prag : Node_Id;
3305 Task_Typ : Entity_Id) return Boolean;
3306 pragma Inline (Is_Single_Task_Pragma);
3307 -- Determine whether pragma Prag belongs to single task type Task_Typ
3309 -------------------------------
3310 -- Is_Enclosing_Package_Body --
3311 -------------------------------
3313 function Is_Enclosing_Package_Body
3314 (Body_Decl : Node_Id;
3315 Obj_Id : Entity_Id) return Boolean
3317 Obj_Context : Node_Id;
3319 begin
3320 -- Find the context of the object declaration
3322 Obj_Context := Parent (Declaration_Node (Obj_Id));
3324 if Nkind (Obj_Context) = N_Package_Specification then
3325 Obj_Context := Parent (Obj_Context);
3326 end if;
3328 -- The object appears immediately within the package body
3330 if Obj_Context = Body_Decl then
3331 return True;
3333 -- The object appears immediately within the corresponding spec
3335 elsif Nkind (Obj_Context) = N_Package_Declaration
3336 and then Unit_Declaration_Node (Corresponding_Spec (Body_Decl)) =
3337 Obj_Context
3338 then
3339 return True;
3340 end if;
3342 return False;
3343 end Is_Enclosing_Package_Body;
3345 -------------------------------------
3346 -- Is_Internal_Declaration_Or_Body --
3347 -------------------------------------
3349 function Is_Internal_Declaration_Or_Body
3350 (Decl : Node_Id) return Boolean
3352 begin
3353 if Comes_From_Source (Decl) then
3354 return False;
3356 -- A body generated for an expression function which has not been
3357 -- inserted into the tree yet (In_Spec_Expression is True) is not
3358 -- considered internal.
3360 elsif Nkind (Decl) = N_Subprogram_Body
3361 and then Was_Expression_Function (Decl)
3362 and then not In_Spec_Expression
3363 then
3364 return False;
3365 end if;
3367 return True;
3368 end Is_Internal_Declaration_Or_Body;
3370 -----------------------------------
3371 -- Is_Single_Declaration_Or_Body --
3372 -----------------------------------
3374 function Is_Single_Declaration_Or_Body
3375 (Decl : Node_Id;
3376 Conc_Typ : Entity_Id) return Boolean
3378 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Decl);
3380 begin
3381 return
3382 Present (Anonymous_Object (Spec_Id))
3383 and then Anonymous_Object (Spec_Id) = Conc_Typ;
3384 end Is_Single_Declaration_Or_Body;
3386 ---------------------------
3387 -- Is_Single_Task_Pragma --
3388 ---------------------------
3390 function Is_Single_Task_Pragma
3391 (Prag : Node_Id;
3392 Task_Typ : Entity_Id) return Boolean
3394 Decl : constant Node_Id := Find_Related_Declaration_Or_Body (Prag);
3396 begin
3397 -- To qualify, the pragma must be associated with single task type
3398 -- Task_Typ.
3400 return
3401 Is_Single_Task_Object (Task_Typ)
3402 and then Nkind (Decl) = N_Object_Declaration
3403 and then Defining_Entity (Decl) = Task_Typ;
3404 end Is_Single_Task_Pragma;
3406 -- Local variables
3408 Conc_Obj : constant Entity_Id := Encapsulating_State (Var_Id);
3409 Par : Node_Id;
3410 Prag_Nam : Name_Id;
3411 Prev : Node_Id;
3413 -- Start of processing for Check_Part_Of_Reference
3415 begin
3416 -- Nothing to do when the variable was recorded, but did not become a
3417 -- constituent of a single concurrent type.
3419 if No (Conc_Obj) then
3420 return;
3421 end if;
3423 -- Traverse the parent chain looking for a suitable context for the
3424 -- reference to the concurrent constituent.
3426 Prev := Ref;
3427 Par := Parent (Prev);
3428 while Present (Par) loop
3429 if Nkind (Par) = N_Pragma then
3430 Prag_Nam := Pragma_Name (Par);
3432 -- A concurrent constituent is allowed to appear in pragmas
3433 -- Initial_Condition and Initializes as this is part of the
3434 -- elaboration checks for the constituent (SPARK RM 9(3)).
3436 if Nam_In (Prag_Nam, Name_Initial_Condition, Name_Initializes) then
3437 return;
3439 -- When the reference appears within pragma Depends or Global,
3440 -- check whether the pragma applies to a single task type. Note
3441 -- that the pragma may not encapsulated by the type definition,
3442 -- but this is still a valid context.
3444 elsif Nam_In (Prag_Nam, Name_Depends, Name_Global)
3445 and then Is_Single_Task_Pragma (Par, Conc_Obj)
3446 then
3447 return;
3448 end if;
3450 -- The reference appears somewhere in the definition of a single
3451 -- concurrent type (SPARK RM 9(3)).
3453 elsif Nkind_In (Par, N_Single_Protected_Declaration,
3454 N_Single_Task_Declaration)
3455 and then Defining_Entity (Par) = Conc_Obj
3456 then
3457 return;
3459 -- The reference appears within the declaration or body of a single
3460 -- concurrent type (SPARK RM 9(3)).
3462 elsif Nkind_In (Par, N_Protected_Body,
3463 N_Protected_Type_Declaration,
3464 N_Task_Body,
3465 N_Task_Type_Declaration)
3466 and then Is_Single_Declaration_Or_Body (Par, Conc_Obj)
3467 then
3468 return;
3470 -- The reference appears within the statement list of the object's
3471 -- immediately enclosing package (SPARK RM 9(3)).
3473 elsif Nkind (Par) = N_Package_Body
3474 and then Nkind (Prev) = N_Handled_Sequence_Of_Statements
3475 and then Is_Enclosing_Package_Body (Par, Var_Id)
3476 then
3477 return;
3479 -- The reference has been relocated within an internally generated
3480 -- package or subprogram. Assume that the reference is legal as the
3481 -- real check was already performed in the original context of the
3482 -- reference.
3484 elsif Nkind_In (Par, N_Package_Body,
3485 N_Package_Declaration,
3486 N_Subprogram_Body,
3487 N_Subprogram_Declaration)
3488 and then Is_Internal_Declaration_Or_Body (Par)
3489 then
3490 return;
3492 -- The reference has been relocated to an inlined body for GNATprove.
3493 -- Assume that the reference is legal as the real check was already
3494 -- performed in the original context of the reference.
3496 elsif GNATprove_Mode
3497 and then Nkind (Par) = N_Subprogram_Body
3498 and then Chars (Defining_Entity (Par)) = Name_uParent
3499 then
3500 return;
3501 end if;
3503 Prev := Par;
3504 Par := Parent (Prev);
3505 end loop;
3507 -- At this point it is known that the reference does not appear within a
3508 -- legal context.
3510 Error_Msg_NE
3511 ("reference to variable & cannot appear in this context", Ref, Var_Id);
3512 Error_Msg_Name_1 := Chars (Var_Id);
3514 if Is_Single_Protected_Object (Conc_Obj) then
3515 Error_Msg_NE
3516 ("\% is constituent of single protected type &", Ref, Conc_Obj);
3518 else
3519 Error_Msg_NE
3520 ("\% is constituent of single task type &", Ref, Conc_Obj);
3521 end if;
3522 end Check_Part_Of_Reference;
3524 ------------------------------------------
3525 -- Check_Potentially_Blocking_Operation --
3526 ------------------------------------------
3528 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
3529 S : Entity_Id;
3531 begin
3532 -- N is one of the potentially blocking operations listed in 9.5.1(8).
3533 -- When pragma Detect_Blocking is active, the run time will raise
3534 -- Program_Error. Here we only issue a warning, since we generally
3535 -- support the use of potentially blocking operations in the absence
3536 -- of the pragma.
3538 -- Indirect blocking through a subprogram call cannot be diagnosed
3539 -- statically without interprocedural analysis, so we do not attempt
3540 -- to do it here.
3542 S := Scope (Current_Scope);
3543 while Present (S) and then S /= Standard_Standard loop
3544 if Is_Protected_Type (S) then
3545 Error_Msg_N
3546 ("potentially blocking operation in protected operation??", N);
3547 return;
3548 end if;
3550 S := Scope (S);
3551 end loop;
3552 end Check_Potentially_Blocking_Operation;
3554 ------------------------------------
3555 -- Check_Previous_Null_Procedure --
3556 ------------------------------------
3558 procedure Check_Previous_Null_Procedure
3559 (Decl : Node_Id;
3560 Prev : Entity_Id)
3562 begin
3563 if Ekind (Prev) = E_Procedure
3564 and then Nkind (Parent (Prev)) = N_Procedure_Specification
3565 and then Null_Present (Parent (Prev))
3566 then
3567 Error_Msg_Sloc := Sloc (Prev);
3568 Error_Msg_N
3569 ("declaration cannot complete previous null procedure#", Decl);
3570 end if;
3571 end Check_Previous_Null_Procedure;
3573 ---------------------------------
3574 -- Check_Result_And_Post_State --
3575 ---------------------------------
3577 procedure Check_Result_And_Post_State (Subp_Id : Entity_Id) is
3578 procedure Check_Result_And_Post_State_In_Pragma
3579 (Prag : Node_Id;
3580 Result_Seen : in out Boolean);
3581 -- Determine whether pragma Prag mentions attribute 'Result and whether
3582 -- the pragma contains an expression that evaluates differently in pre-
3583 -- and post-state. Prag is a [refined] postcondition or a contract-cases
3584 -- pragma. Result_Seen is set when the pragma mentions attribute 'Result
3586 function Has_In_Out_Parameter (Subp_Id : Entity_Id) return Boolean;
3587 -- Determine whether subprogram Subp_Id contains at least one IN OUT
3588 -- formal parameter.
3590 -------------------------------------------
3591 -- Check_Result_And_Post_State_In_Pragma --
3592 -------------------------------------------
3594 procedure Check_Result_And_Post_State_In_Pragma
3595 (Prag : Node_Id;
3596 Result_Seen : in out Boolean)
3598 procedure Check_Conjunct (Expr : Node_Id);
3599 -- Check an individual conjunct in a conjunction of Boolean
3600 -- expressions, connected by "and" or "and then" operators.
3602 procedure Check_Conjuncts (Expr : Node_Id);
3603 -- Apply the post-state check to every conjunct in an expression, in
3604 -- case this is a conjunction of Boolean expressions. Otherwise apply
3605 -- it to the expression as a whole.
3607 procedure Check_Expression (Expr : Node_Id);
3608 -- Perform the 'Result and post-state checks on a given expression
3610 function Is_Function_Result (N : Node_Id) return Traverse_Result;
3611 -- Attempt to find attribute 'Result in a subtree denoted by N
3613 function Is_Trivial_Boolean (N : Node_Id) return Boolean;
3614 -- Determine whether source node N denotes "True" or "False"
3616 function Mentions_Post_State (N : Node_Id) return Boolean;
3617 -- Determine whether a subtree denoted by N mentions any construct
3618 -- that denotes a post-state.
3620 procedure Check_Function_Result is
3621 new Traverse_Proc (Is_Function_Result);
3623 --------------------
3624 -- Check_Conjunct --
3625 --------------------
3627 procedure Check_Conjunct (Expr : Node_Id) is
3628 function Adjust_Message (Msg : String) return String;
3629 -- Prepend a prefix to the input message Msg denoting that the
3630 -- message applies to a conjunct in the expression, when this
3631 -- is the case.
3633 function Applied_On_Conjunct return Boolean;
3634 -- Returns True if the message applies to a conjunct in the
3635 -- expression, instead of the whole expression.
3637 function Has_Global_Output (Subp : Entity_Id) return Boolean;
3638 -- Returns True if Subp has an output in its Global contract
3640 function Has_No_Output (Subp : Entity_Id) return Boolean;
3641 -- Returns True if Subp has no declared output: no function
3642 -- result, no output parameter, and no output in its Global
3643 -- contract.
3645 --------------------
3646 -- Adjust_Message --
3647 --------------------
3649 function Adjust_Message (Msg : String) return String is
3650 begin
3651 if Applied_On_Conjunct then
3652 return "conjunct in " & Msg;
3653 else
3654 return Msg;
3655 end if;
3656 end Adjust_Message;
3658 -------------------------
3659 -- Applied_On_Conjunct --
3660 -------------------------
3662 function Applied_On_Conjunct return Boolean is
3663 begin
3664 -- Expr is the conjunct of an enclosing "and" expression
3666 return Nkind (Parent (Expr)) in N_Subexpr
3668 -- or Expr is a conjunct of an enclosing "and then"
3669 -- expression in a postcondition aspect that was split into
3670 -- multiple pragmas. The first conjunct has the "and then"
3671 -- expression as Original_Node, and other conjuncts have
3672 -- Split_PCC set to True.
3674 or else Nkind (Original_Node (Expr)) = N_And_Then
3675 or else Split_PPC (Prag);
3676 end Applied_On_Conjunct;
3678 -----------------------
3679 -- Has_Global_Output --
3680 -----------------------
3682 function Has_Global_Output (Subp : Entity_Id) return Boolean is
3683 Global : constant Node_Id := Get_Pragma (Subp, Pragma_Global);
3684 List : Node_Id;
3685 Assoc : Node_Id;
3687 begin
3688 if No (Global) then
3689 return False;
3690 end if;
3692 List := Expression (Get_Argument (Global, Subp));
3694 -- Empty list (no global items) or single global item
3695 -- declaration (only input items).
3697 if Nkind_In (List, N_Null,
3698 N_Expanded_Name,
3699 N_Identifier,
3700 N_Selected_Component)
3701 then
3702 return False;
3704 -- Simple global list (only input items) or moded global list
3705 -- declaration.
3707 elsif Nkind (List) = N_Aggregate then
3708 if Present (Expressions (List)) then
3709 return False;
3711 else
3712 Assoc := First (Component_Associations (List));
3713 while Present (Assoc) loop
3714 if Chars (First (Choices (Assoc))) /= Name_Input then
3715 return True;
3716 end if;
3718 Next (Assoc);
3719 end loop;
3721 return False;
3722 end if;
3724 -- To accommodate partial decoration of disabled SPARK
3725 -- features, this routine may be called with illegal input.
3726 -- If this is the case, do not raise Program_Error.
3728 else
3729 return False;
3730 end if;
3731 end Has_Global_Output;
3733 -------------------
3734 -- Has_No_Output --
3735 -------------------
3737 function Has_No_Output (Subp : Entity_Id) return Boolean is
3738 Param : Node_Id;
3740 begin
3741 -- A function has its result as output
3743 if Ekind (Subp) = E_Function then
3744 return False;
3745 end if;
3747 -- An OUT or IN OUT parameter is an output
3749 Param := First_Formal (Subp);
3750 while Present (Param) loop
3751 if Ekind_In (Param, E_Out_Parameter, E_In_Out_Parameter) then
3752 return False;
3753 end if;
3755 Next_Formal (Param);
3756 end loop;
3758 -- An item of mode Output or In_Out in the Global contract is
3759 -- an output.
3761 if Has_Global_Output (Subp) then
3762 return False;
3763 end if;
3765 return True;
3766 end Has_No_Output;
3768 -- Local variables
3770 Err_Node : Node_Id;
3771 -- Error node when reporting a warning on a (refined)
3772 -- postcondition.
3774 -- Start of processing for Check_Conjunct
3776 begin
3777 if Applied_On_Conjunct then
3778 Err_Node := Expr;
3779 else
3780 Err_Node := Prag;
3781 end if;
3783 -- Do not report missing reference to outcome in postcondition if
3784 -- either the postcondition is trivially True or False, or if the
3785 -- subprogram is ghost and has no declared output.
3787 if not Is_Trivial_Boolean (Expr)
3788 and then not Mentions_Post_State (Expr)
3789 and then not (Is_Ghost_Entity (Subp_Id)
3790 and then Has_No_Output (Subp_Id))
3791 then
3792 if Pragma_Name (Prag) = Name_Contract_Cases then
3793 Error_Msg_NE (Adjust_Message
3794 ("contract case does not check the outcome of calling "
3795 & "&?T?"), Expr, Subp_Id);
3797 elsif Pragma_Name (Prag) = Name_Refined_Post then
3798 Error_Msg_NE (Adjust_Message
3799 ("refined postcondition does not check the outcome of "
3800 & "calling &?T?"), Err_Node, Subp_Id);
3802 else
3803 Error_Msg_NE (Adjust_Message
3804 ("postcondition does not check the outcome of calling "
3805 & "&?T?"), Err_Node, Subp_Id);
3806 end if;
3807 end if;
3808 end Check_Conjunct;
3810 ---------------------
3811 -- Check_Conjuncts --
3812 ---------------------
3814 procedure Check_Conjuncts (Expr : Node_Id) is
3815 begin
3816 if Nkind_In (Expr, N_Op_And, N_And_Then) then
3817 Check_Conjuncts (Left_Opnd (Expr));
3818 Check_Conjuncts (Right_Opnd (Expr));
3819 else
3820 Check_Conjunct (Expr);
3821 end if;
3822 end Check_Conjuncts;
3824 ----------------------
3825 -- Check_Expression --
3826 ----------------------
3828 procedure Check_Expression (Expr : Node_Id) is
3829 begin
3830 if not Is_Trivial_Boolean (Expr) then
3831 Check_Function_Result (Expr);
3832 Check_Conjuncts (Expr);
3833 end if;
3834 end Check_Expression;
3836 ------------------------
3837 -- Is_Function_Result --
3838 ------------------------
3840 function Is_Function_Result (N : Node_Id) return Traverse_Result is
3841 begin
3842 if Is_Attribute_Result (N) then
3843 Result_Seen := True;
3844 return Abandon;
3846 -- Continue the traversal
3848 else
3849 return OK;
3850 end if;
3851 end Is_Function_Result;
3853 ------------------------
3854 -- Is_Trivial_Boolean --
3855 ------------------------
3857 function Is_Trivial_Boolean (N : Node_Id) return Boolean is
3858 begin
3859 return
3860 Comes_From_Source (N)
3861 and then Is_Entity_Name (N)
3862 and then (Entity (N) = Standard_True
3863 or else
3864 Entity (N) = Standard_False);
3865 end Is_Trivial_Boolean;
3867 -------------------------
3868 -- Mentions_Post_State --
3869 -------------------------
3871 function Mentions_Post_State (N : Node_Id) return Boolean is
3872 Post_State_Seen : Boolean := False;
3874 function Is_Post_State (N : Node_Id) return Traverse_Result;
3875 -- Attempt to find a construct that denotes a post-state. If this
3876 -- is the case, set flag Post_State_Seen.
3878 -------------------
3879 -- Is_Post_State --
3880 -------------------
3882 function Is_Post_State (N : Node_Id) return Traverse_Result is
3883 Ent : Entity_Id;
3885 begin
3886 if Nkind_In (N, N_Explicit_Dereference, N_Function_Call) then
3887 Post_State_Seen := True;
3888 return Abandon;
3890 elsif Nkind_In (N, N_Expanded_Name, N_Identifier) then
3891 Ent := Entity (N);
3893 -- Treat an undecorated reference as OK
3895 if No (Ent)
3897 -- A reference to an assignable entity is considered a
3898 -- change in the post-state of a subprogram.
3900 or else Ekind_In (Ent, E_Generic_In_Out_Parameter,
3901 E_In_Out_Parameter,
3902 E_Out_Parameter,
3903 E_Variable)
3905 -- The reference may be modified through a dereference
3907 or else (Is_Access_Type (Etype (Ent))
3908 and then Nkind (Parent (N)) =
3909 N_Selected_Component)
3910 then
3911 Post_State_Seen := True;
3912 return Abandon;
3913 end if;
3915 elsif Nkind (N) = N_Attribute_Reference then
3916 if Attribute_Name (N) = Name_Old then
3917 return Skip;
3919 elsif Attribute_Name (N) = Name_Result then
3920 Post_State_Seen := True;
3921 return Abandon;
3922 end if;
3923 end if;
3925 return OK;
3926 end Is_Post_State;
3928 procedure Find_Post_State is new Traverse_Proc (Is_Post_State);
3930 -- Start of processing for Mentions_Post_State
3932 begin
3933 Find_Post_State (N);
3935 return Post_State_Seen;
3936 end Mentions_Post_State;
3938 -- Local variables
3940 Expr : constant Node_Id :=
3941 Get_Pragma_Arg
3942 (First (Pragma_Argument_Associations (Prag)));
3943 Nam : constant Name_Id := Pragma_Name (Prag);
3944 CCase : Node_Id;
3946 -- Start of processing for Check_Result_And_Post_State_In_Pragma
3948 begin
3949 -- Examine all consequences
3951 if Nam = Name_Contract_Cases then
3952 CCase := First (Component_Associations (Expr));
3953 while Present (CCase) loop
3954 Check_Expression (Expression (CCase));
3956 Next (CCase);
3957 end loop;
3959 -- Examine the expression of a postcondition
3961 else pragma Assert (Nam_In (Nam, Name_Postcondition,
3962 Name_Refined_Post));
3963 Check_Expression (Expr);
3964 end if;
3965 end Check_Result_And_Post_State_In_Pragma;
3967 --------------------------
3968 -- Has_In_Out_Parameter --
3969 --------------------------
3971 function Has_In_Out_Parameter (Subp_Id : Entity_Id) return Boolean is
3972 Formal : Entity_Id;
3974 begin
3975 -- Traverse the formals looking for an IN OUT parameter
3977 Formal := First_Formal (Subp_Id);
3978 while Present (Formal) loop
3979 if Ekind (Formal) = E_In_Out_Parameter then
3980 return True;
3981 end if;
3983 Next_Formal (Formal);
3984 end loop;
3986 return False;
3987 end Has_In_Out_Parameter;
3989 -- Local variables
3991 Items : constant Node_Id := Contract (Subp_Id);
3992 Subp_Decl : constant Node_Id := Unit_Declaration_Node (Subp_Id);
3993 Case_Prag : Node_Id := Empty;
3994 Post_Prag : Node_Id := Empty;
3995 Prag : Node_Id;
3996 Seen_In_Case : Boolean := False;
3997 Seen_In_Post : Boolean := False;
3998 Spec_Id : Entity_Id;
4000 -- Start of processing for Check_Result_And_Post_State
4002 begin
4003 -- The lack of attribute 'Result or a post-state is classified as a
4004 -- suspicious contract. Do not perform the check if the corresponding
4005 -- swich is not set.
4007 if not Warn_On_Suspicious_Contract then
4008 return;
4010 -- Nothing to do if there is no contract
4012 elsif No (Items) then
4013 return;
4014 end if;
4016 -- Retrieve the entity of the subprogram spec (if any)
4018 if Nkind (Subp_Decl) = N_Subprogram_Body
4019 and then Present (Corresponding_Spec (Subp_Decl))
4020 then
4021 Spec_Id := Corresponding_Spec (Subp_Decl);
4023 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
4024 and then Present (Corresponding_Spec_Of_Stub (Subp_Decl))
4025 then
4026 Spec_Id := Corresponding_Spec_Of_Stub (Subp_Decl);
4028 else
4029 Spec_Id := Subp_Id;
4030 end if;
4032 -- Examine all postconditions for attribute 'Result and a post-state
4034 Prag := Pre_Post_Conditions (Items);
4035 while Present (Prag) loop
4036 if Nam_In (Pragma_Name_Unmapped (Prag),
4037 Name_Postcondition, Name_Refined_Post)
4038 and then not Error_Posted (Prag)
4039 then
4040 Post_Prag := Prag;
4041 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Post);
4042 end if;
4044 Prag := Next_Pragma (Prag);
4045 end loop;
4047 -- Examine the contract cases of the subprogram for attribute 'Result
4048 -- and a post-state.
4050 Prag := Contract_Test_Cases (Items);
4051 while Present (Prag) loop
4052 if Pragma_Name (Prag) = Name_Contract_Cases
4053 and then not Error_Posted (Prag)
4054 then
4055 Case_Prag := Prag;
4056 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Case);
4057 end if;
4059 Prag := Next_Pragma (Prag);
4060 end loop;
4062 -- Do not emit any errors if the subprogram is not a function
4064 if not Ekind_In (Spec_Id, E_Function, E_Generic_Function) then
4065 null;
4067 -- Regardless of whether the function has postconditions or contract
4068 -- cases, or whether they mention attribute 'Result, an IN OUT formal
4069 -- parameter is always treated as a result.
4071 elsif Has_In_Out_Parameter (Spec_Id) then
4072 null;
4074 -- The function has both a postcondition and contract cases and they do
4075 -- not mention attribute 'Result.
4077 elsif Present (Case_Prag)
4078 and then not Seen_In_Case
4079 and then Present (Post_Prag)
4080 and then not Seen_In_Post
4081 then
4082 Error_Msg_N
4083 ("neither postcondition nor contract cases mention function "
4084 & "result?T?", Post_Prag);
4086 -- The function has contract cases only and they do not mention
4087 -- attribute 'Result.
4089 elsif Present (Case_Prag) and then not Seen_In_Case then
4090 Error_Msg_N ("contract cases do not mention result?T?", Case_Prag);
4092 -- The function has postconditions only and they do not mention
4093 -- attribute 'Result.
4095 elsif Present (Post_Prag) and then not Seen_In_Post then
4096 Error_Msg_N
4097 ("postcondition does not mention function result?T?", Post_Prag);
4098 end if;
4099 end Check_Result_And_Post_State;
4101 -----------------------------
4102 -- Check_State_Refinements --
4103 -----------------------------
4105 procedure Check_State_Refinements
4106 (Context : Node_Id;
4107 Is_Main_Unit : Boolean := False)
4109 procedure Check_Package (Pack : Node_Id);
4110 -- Verify that all abstract states of a [generic] package denoted by its
4111 -- declarative node Pack have proper refinement. Recursively verify the
4112 -- visible and private declarations of the [generic] package for other
4113 -- nested packages.
4115 procedure Check_Packages_In (Decls : List_Id);
4116 -- Seek out [generic] package declarations within declarative list Decls
4117 -- and verify the status of their abstract state refinement.
4119 function SPARK_Mode_Is_Off (N : Node_Id) return Boolean;
4120 -- Determine whether construct N is subject to pragma SPARK_Mode Off
4122 -------------------
4123 -- Check_Package --
4124 -------------------
4126 procedure Check_Package (Pack : Node_Id) is
4127 Body_Id : constant Entity_Id := Corresponding_Body (Pack);
4128 Spec : constant Node_Id := Specification (Pack);
4129 States : constant Elist_Id :=
4130 Abstract_States (Defining_Entity (Pack));
4132 State_Elmt : Elmt_Id;
4133 State_Id : Entity_Id;
4135 begin
4136 -- Do not verify proper state refinement when the package is subject
4137 -- to pragma SPARK_Mode Off because this disables the requirement for
4138 -- state refinement.
4140 if SPARK_Mode_Is_Off (Pack) then
4141 null;
4143 -- State refinement can only occur in a completing package body. Do
4144 -- not verify proper state refinement when the body is subject to
4145 -- pragma SPARK_Mode Off because this disables the requirement for
4146 -- state refinement.
4148 elsif Present (Body_Id)
4149 and then SPARK_Mode_Is_Off (Unit_Declaration_Node (Body_Id))
4150 then
4151 null;
4153 -- Do not verify proper state refinement when the package is an
4154 -- instance as this check was already performed in the generic.
4156 elsif Present (Generic_Parent (Spec)) then
4157 null;
4159 -- Otherwise examine the contents of the package
4161 else
4162 if Present (States) then
4163 State_Elmt := First_Elmt (States);
4164 while Present (State_Elmt) loop
4165 State_Id := Node (State_Elmt);
4167 -- Emit an error when a non-null state lacks any form of
4168 -- refinement.
4170 if not Is_Null_State (State_Id)
4171 and then not Has_Null_Refinement (State_Id)
4172 and then not Has_Non_Null_Refinement (State_Id)
4173 then
4174 Error_Msg_N ("state & requires refinement", State_Id);
4175 end if;
4177 Next_Elmt (State_Elmt);
4178 end loop;
4179 end if;
4181 Check_Packages_In (Visible_Declarations (Spec));
4182 Check_Packages_In (Private_Declarations (Spec));
4183 end if;
4184 end Check_Package;
4186 -----------------------
4187 -- Check_Packages_In --
4188 -----------------------
4190 procedure Check_Packages_In (Decls : List_Id) is
4191 Decl : Node_Id;
4193 begin
4194 if Present (Decls) then
4195 Decl := First (Decls);
4196 while Present (Decl) loop
4197 if Nkind_In (Decl, N_Generic_Package_Declaration,
4198 N_Package_Declaration)
4199 then
4200 Check_Package (Decl);
4201 end if;
4203 Next (Decl);
4204 end loop;
4205 end if;
4206 end Check_Packages_In;
4208 -----------------------
4209 -- SPARK_Mode_Is_Off --
4210 -----------------------
4212 function SPARK_Mode_Is_Off (N : Node_Id) return Boolean is
4213 Id : constant Entity_Id := Defining_Entity (N);
4214 Prag : constant Node_Id := SPARK_Pragma (Id);
4216 begin
4217 -- Default the mode to "off" when the context is an instance and all
4218 -- SPARK_Mode pragmas found within are to be ignored.
4220 if Ignore_SPARK_Mode_Pragmas (Id) then
4221 return True;
4223 else
4224 return
4225 Present (Prag)
4226 and then Get_SPARK_Mode_From_Annotation (Prag) = Off;
4227 end if;
4228 end SPARK_Mode_Is_Off;
4230 -- Start of processing for Check_State_Refinements
4232 begin
4233 -- A block may declare a nested package
4235 if Nkind (Context) = N_Block_Statement then
4236 Check_Packages_In (Declarations (Context));
4238 -- An entry, protected, subprogram, or task body may declare a nested
4239 -- package.
4241 elsif Nkind_In (Context, N_Entry_Body,
4242 N_Protected_Body,
4243 N_Subprogram_Body,
4244 N_Task_Body)
4245 then
4246 -- Do not verify proper state refinement when the body is subject to
4247 -- pragma SPARK_Mode Off because this disables the requirement for
4248 -- state refinement.
4250 if not SPARK_Mode_Is_Off (Context) then
4251 Check_Packages_In (Declarations (Context));
4252 end if;
4254 -- A package body may declare a nested package
4256 elsif Nkind (Context) = N_Package_Body then
4257 Check_Package (Unit_Declaration_Node (Corresponding_Spec (Context)));
4259 -- Do not verify proper state refinement when the body is subject to
4260 -- pragma SPARK_Mode Off because this disables the requirement for
4261 -- state refinement.
4263 if not SPARK_Mode_Is_Off (Context) then
4264 Check_Packages_In (Declarations (Context));
4265 end if;
4267 -- A library level [generic] package may declare a nested package
4269 elsif Nkind_In (Context, N_Generic_Package_Declaration,
4270 N_Package_Declaration)
4271 and then Is_Main_Unit
4272 then
4273 Check_Package (Context);
4274 end if;
4275 end Check_State_Refinements;
4277 ------------------------------
4278 -- Check_Unprotected_Access --
4279 ------------------------------
4281 procedure Check_Unprotected_Access
4282 (Context : Node_Id;
4283 Expr : Node_Id)
4285 Cont_Encl_Typ : Entity_Id;
4286 Pref_Encl_Typ : Entity_Id;
4288 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
4289 -- Check whether Obj is a private component of a protected object.
4290 -- Return the protected type where the component resides, Empty
4291 -- otherwise.
4293 function Is_Public_Operation return Boolean;
4294 -- Verify that the enclosing operation is callable from outside the
4295 -- protected object, to minimize false positives.
4297 ------------------------------
4298 -- Enclosing_Protected_Type --
4299 ------------------------------
4301 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
4302 begin
4303 if Is_Entity_Name (Obj) then
4304 declare
4305 Ent : Entity_Id := Entity (Obj);
4307 begin
4308 -- The object can be a renaming of a private component, use
4309 -- the original record component.
4311 if Is_Prival (Ent) then
4312 Ent := Prival_Link (Ent);
4313 end if;
4315 if Is_Protected_Type (Scope (Ent)) then
4316 return Scope (Ent);
4317 end if;
4318 end;
4319 end if;
4321 -- For indexed and selected components, recursively check the prefix
4323 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
4324 return Enclosing_Protected_Type (Prefix (Obj));
4326 -- The object does not denote a protected component
4328 else
4329 return Empty;
4330 end if;
4331 end Enclosing_Protected_Type;
4333 -------------------------
4334 -- Is_Public_Operation --
4335 -------------------------
4337 function Is_Public_Operation return Boolean is
4338 S : Entity_Id;
4339 E : Entity_Id;
4341 begin
4342 S := Current_Scope;
4343 while Present (S) and then S /= Pref_Encl_Typ loop
4344 if Scope (S) = Pref_Encl_Typ then
4345 E := First_Entity (Pref_Encl_Typ);
4346 while Present (E)
4347 and then E /= First_Private_Entity (Pref_Encl_Typ)
4348 loop
4349 if E = S then
4350 return True;
4351 end if;
4353 Next_Entity (E);
4354 end loop;
4355 end if;
4357 S := Scope (S);
4358 end loop;
4360 return False;
4361 end Is_Public_Operation;
4363 -- Start of processing for Check_Unprotected_Access
4365 begin
4366 if Nkind (Expr) = N_Attribute_Reference
4367 and then Attribute_Name (Expr) = Name_Unchecked_Access
4368 then
4369 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
4370 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
4372 -- Check whether we are trying to export a protected component to a
4373 -- context with an equal or lower access level.
4375 if Present (Pref_Encl_Typ)
4376 and then No (Cont_Encl_Typ)
4377 and then Is_Public_Operation
4378 and then Scope_Depth (Pref_Encl_Typ) >=
4379 Object_Access_Level (Context)
4380 then
4381 Error_Msg_N
4382 ("??possible unprotected access to protected data", Expr);
4383 end if;
4384 end if;
4385 end Check_Unprotected_Access;
4387 ------------------------------
4388 -- Check_Unused_Body_States --
4389 ------------------------------
4391 procedure Check_Unused_Body_States (Body_Id : Entity_Id) is
4392 procedure Process_Refinement_Clause
4393 (Clause : Node_Id;
4394 States : Elist_Id);
4395 -- Inspect all constituents of refinement clause Clause and remove any
4396 -- matches from body state list States.
4398 procedure Report_Unused_Body_States (States : Elist_Id);
4399 -- Emit errors for each abstract state or object found in list States
4401 -------------------------------
4402 -- Process_Refinement_Clause --
4403 -------------------------------
4405 procedure Process_Refinement_Clause
4406 (Clause : Node_Id;
4407 States : Elist_Id)
4409 procedure Process_Constituent (Constit : Node_Id);
4410 -- Remove constituent Constit from body state list States
4412 -------------------------
4413 -- Process_Constituent --
4414 -------------------------
4416 procedure Process_Constituent (Constit : Node_Id) is
4417 Constit_Id : Entity_Id;
4419 begin
4420 -- Guard against illegal constituents. Only abstract states and
4421 -- objects can appear on the right hand side of a refinement.
4423 if Is_Entity_Name (Constit) then
4424 Constit_Id := Entity_Of (Constit);
4426 if Present (Constit_Id)
4427 and then Ekind_In (Constit_Id, E_Abstract_State,
4428 E_Constant,
4429 E_Variable)
4430 then
4431 Remove (States, Constit_Id);
4432 end if;
4433 end if;
4434 end Process_Constituent;
4436 -- Local variables
4438 Constit : Node_Id;
4440 -- Start of processing for Process_Refinement_Clause
4442 begin
4443 if Nkind (Clause) = N_Component_Association then
4444 Constit := Expression (Clause);
4446 -- Multiple constituents appear as an aggregate
4448 if Nkind (Constit) = N_Aggregate then
4449 Constit := First (Expressions (Constit));
4450 while Present (Constit) loop
4451 Process_Constituent (Constit);
4452 Next (Constit);
4453 end loop;
4455 -- Various forms of a single constituent
4457 else
4458 Process_Constituent (Constit);
4459 end if;
4460 end if;
4461 end Process_Refinement_Clause;
4463 -------------------------------
4464 -- Report_Unused_Body_States --
4465 -------------------------------
4467 procedure Report_Unused_Body_States (States : Elist_Id) is
4468 Posted : Boolean := False;
4469 State_Elmt : Elmt_Id;
4470 State_Id : Entity_Id;
4472 begin
4473 if Present (States) then
4474 State_Elmt := First_Elmt (States);
4475 while Present (State_Elmt) loop
4476 State_Id := Node (State_Elmt);
4478 -- Constants are part of the hidden state of a package, but the
4479 -- compiler cannot determine whether they have variable input
4480 -- (SPARK RM 7.1.1(2)) and cannot classify them properly as a
4481 -- hidden state. Do not emit an error when a constant does not
4482 -- participate in a state refinement, even though it acts as a
4483 -- hidden state.
4485 if Ekind (State_Id) = E_Constant then
4486 null;
4488 -- Generate an error message of the form:
4490 -- body of package ... has unused hidden states
4491 -- abstract state ... defined at ...
4492 -- variable ... defined at ...
4494 else
4495 if not Posted then
4496 Posted := True;
4497 SPARK_Msg_N
4498 ("body of package & has unused hidden states", Body_Id);
4499 end if;
4501 Error_Msg_Sloc := Sloc (State_Id);
4503 if Ekind (State_Id) = E_Abstract_State then
4504 SPARK_Msg_NE
4505 ("\abstract state & defined #", Body_Id, State_Id);
4507 else
4508 SPARK_Msg_NE ("\variable & defined #", Body_Id, State_Id);
4509 end if;
4510 end if;
4512 Next_Elmt (State_Elmt);
4513 end loop;
4514 end if;
4515 end Report_Unused_Body_States;
4517 -- Local variables
4519 Prag : constant Node_Id := Get_Pragma (Body_Id, Pragma_Refined_State);
4520 Spec_Id : constant Entity_Id := Spec_Entity (Body_Id);
4521 Clause : Node_Id;
4522 States : Elist_Id;
4524 -- Start of processing for Check_Unused_Body_States
4526 begin
4527 -- Inspect the clauses of pragma Refined_State and determine whether all
4528 -- visible states declared within the package body participate in the
4529 -- refinement.
4531 if Present (Prag) then
4532 Clause := Expression (Get_Argument (Prag, Spec_Id));
4533 States := Collect_Body_States (Body_Id);
4535 -- Multiple non-null state refinements appear as an aggregate
4537 if Nkind (Clause) = N_Aggregate then
4538 Clause := First (Component_Associations (Clause));
4539 while Present (Clause) loop
4540 Process_Refinement_Clause (Clause, States);
4541 Next (Clause);
4542 end loop;
4544 -- Various forms of a single state refinement
4546 else
4547 Process_Refinement_Clause (Clause, States);
4548 end if;
4550 -- Ensure that all abstract states and objects declared in the
4551 -- package body state space are utilized as constituents.
4553 Report_Unused_Body_States (States);
4554 end if;
4555 end Check_Unused_Body_States;
4557 -----------------
4558 -- Choice_List --
4559 -----------------
4561 function Choice_List (N : Node_Id) return List_Id is
4562 begin
4563 if Nkind (N) = N_Iterated_Component_Association then
4564 return Discrete_Choices (N);
4565 else
4566 return Choices (N);
4567 end if;
4568 end Choice_List;
4570 -------------------------
4571 -- Collect_Body_States --
4572 -------------------------
4574 function Collect_Body_States (Body_Id : Entity_Id) return Elist_Id is
4575 function Is_Visible_Object (Obj_Id : Entity_Id) return Boolean;
4576 -- Determine whether object Obj_Id is a suitable visible state of a
4577 -- package body.
4579 procedure Collect_Visible_States
4580 (Pack_Id : Entity_Id;
4581 States : in out Elist_Id);
4582 -- Gather the entities of all abstract states and objects declared in
4583 -- the visible state space of package Pack_Id.
4585 ----------------------------
4586 -- Collect_Visible_States --
4587 ----------------------------
4589 procedure Collect_Visible_States
4590 (Pack_Id : Entity_Id;
4591 States : in out Elist_Id)
4593 Item_Id : Entity_Id;
4595 begin
4596 -- Traverse the entity chain of the package and inspect all visible
4597 -- items.
4599 Item_Id := First_Entity (Pack_Id);
4600 while Present (Item_Id) and then not In_Private_Part (Item_Id) loop
4602 -- Do not consider internally generated items as those cannot be
4603 -- named and participate in refinement.
4605 if not Comes_From_Source (Item_Id) then
4606 null;
4608 elsif Ekind (Item_Id) = E_Abstract_State then
4609 Append_New_Elmt (Item_Id, States);
4611 elsif Ekind_In (Item_Id, E_Constant, E_Variable)
4612 and then Is_Visible_Object (Item_Id)
4613 then
4614 Append_New_Elmt (Item_Id, States);
4616 -- Recursively gather the visible states of a nested package
4618 elsif Ekind (Item_Id) = E_Package then
4619 Collect_Visible_States (Item_Id, States);
4620 end if;
4622 Next_Entity (Item_Id);
4623 end loop;
4624 end Collect_Visible_States;
4626 -----------------------
4627 -- Is_Visible_Object --
4628 -----------------------
4630 function Is_Visible_Object (Obj_Id : Entity_Id) return Boolean is
4631 begin
4632 -- Objects that map generic formals to their actuals are not visible
4633 -- from outside the generic instantiation.
4635 if Present (Corresponding_Generic_Association
4636 (Declaration_Node (Obj_Id)))
4637 then
4638 return False;
4640 -- Constituents of a single protected/task type act as components of
4641 -- the type and are not visible from outside the type.
4643 elsif Ekind (Obj_Id) = E_Variable
4644 and then Present (Encapsulating_State (Obj_Id))
4645 and then Is_Single_Concurrent_Object (Encapsulating_State (Obj_Id))
4646 then
4647 return False;
4649 else
4650 return True;
4651 end if;
4652 end Is_Visible_Object;
4654 -- Local variables
4656 Body_Decl : constant Node_Id := Unit_Declaration_Node (Body_Id);
4657 Decl : Node_Id;
4658 Item_Id : Entity_Id;
4659 States : Elist_Id := No_Elist;
4661 -- Start of processing for Collect_Body_States
4663 begin
4664 -- Inspect the declarations of the body looking for source objects,
4665 -- packages and package instantiations. Note that even though this
4666 -- processing is very similar to Collect_Visible_States, a package
4667 -- body does not have a First/Next_Entity list.
4669 Decl := First (Declarations (Body_Decl));
4670 while Present (Decl) loop
4672 -- Capture source objects as internally generated temporaries cannot
4673 -- be named and participate in refinement.
4675 if Nkind (Decl) = N_Object_Declaration then
4676 Item_Id := Defining_Entity (Decl);
4678 if Comes_From_Source (Item_Id)
4679 and then Is_Visible_Object (Item_Id)
4680 then
4681 Append_New_Elmt (Item_Id, States);
4682 end if;
4684 -- Capture the visible abstract states and objects of a source
4685 -- package [instantiation].
4687 elsif Nkind (Decl) = N_Package_Declaration then
4688 Item_Id := Defining_Entity (Decl);
4690 if Comes_From_Source (Item_Id) then
4691 Collect_Visible_States (Item_Id, States);
4692 end if;
4693 end if;
4695 Next (Decl);
4696 end loop;
4698 return States;
4699 end Collect_Body_States;
4701 ------------------------
4702 -- Collect_Interfaces --
4703 ------------------------
4705 procedure Collect_Interfaces
4706 (T : Entity_Id;
4707 Ifaces_List : out Elist_Id;
4708 Exclude_Parents : Boolean := False;
4709 Use_Full_View : Boolean := True)
4711 procedure Collect (Typ : Entity_Id);
4712 -- Subsidiary subprogram used to traverse the whole list
4713 -- of directly and indirectly implemented interfaces
4715 -------------
4716 -- Collect --
4717 -------------
4719 procedure Collect (Typ : Entity_Id) is
4720 Ancestor : Entity_Id;
4721 Full_T : Entity_Id;
4722 Id : Node_Id;
4723 Iface : Entity_Id;
4725 begin
4726 Full_T := Typ;
4728 -- Handle private types and subtypes
4730 if Use_Full_View
4731 and then Is_Private_Type (Typ)
4732 and then Present (Full_View (Typ))
4733 then
4734 Full_T := Full_View (Typ);
4736 if Ekind (Full_T) = E_Record_Subtype then
4737 Full_T := Etype (Typ);
4739 if Present (Full_View (Full_T)) then
4740 Full_T := Full_View (Full_T);
4741 end if;
4742 end if;
4743 end if;
4745 -- Include the ancestor if we are generating the whole list of
4746 -- abstract interfaces.
4748 if Etype (Full_T) /= Typ
4750 -- Protect the frontend against wrong sources. For example:
4752 -- package P is
4753 -- type A is tagged null record;
4754 -- type B is new A with private;
4755 -- type C is new A with private;
4756 -- private
4757 -- type B is new C with null record;
4758 -- type C is new B with null record;
4759 -- end P;
4761 and then Etype (Full_T) /= T
4762 then
4763 Ancestor := Etype (Full_T);
4764 Collect (Ancestor);
4766 if Is_Interface (Ancestor) and then not Exclude_Parents then
4767 Append_Unique_Elmt (Ancestor, Ifaces_List);
4768 end if;
4769 end if;
4771 -- Traverse the graph of ancestor interfaces
4773 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
4774 Id := First (Abstract_Interface_List (Full_T));
4775 while Present (Id) loop
4776 Iface := Etype (Id);
4778 -- Protect against wrong uses. For example:
4779 -- type I is interface;
4780 -- type O is tagged null record;
4781 -- type Wrong is new I and O with null record; -- ERROR
4783 if Is_Interface (Iface) then
4784 if Exclude_Parents
4785 and then Etype (T) /= T
4786 and then Interface_Present_In_Ancestor (Etype (T), Iface)
4787 then
4788 null;
4789 else
4790 Collect (Iface);
4791 Append_Unique_Elmt (Iface, Ifaces_List);
4792 end if;
4793 end if;
4795 Next (Id);
4796 end loop;
4797 end if;
4798 end Collect;
4800 -- Start of processing for Collect_Interfaces
4802 begin
4803 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
4804 Ifaces_List := New_Elmt_List;
4805 Collect (T);
4806 end Collect_Interfaces;
4808 ----------------------------------
4809 -- Collect_Interface_Components --
4810 ----------------------------------
4812 procedure Collect_Interface_Components
4813 (Tagged_Type : Entity_Id;
4814 Components_List : out Elist_Id)
4816 procedure Collect (Typ : Entity_Id);
4817 -- Subsidiary subprogram used to climb to the parents
4819 -------------
4820 -- Collect --
4821 -------------
4823 procedure Collect (Typ : Entity_Id) is
4824 Tag_Comp : Entity_Id;
4825 Parent_Typ : Entity_Id;
4827 begin
4828 -- Handle private types
4830 if Present (Full_View (Etype (Typ))) then
4831 Parent_Typ := Full_View (Etype (Typ));
4832 else
4833 Parent_Typ := Etype (Typ);
4834 end if;
4836 if Parent_Typ /= Typ
4838 -- Protect the frontend against wrong sources. For example:
4840 -- package P is
4841 -- type A is tagged null record;
4842 -- type B is new A with private;
4843 -- type C is new A with private;
4844 -- private
4845 -- type B is new C with null record;
4846 -- type C is new B with null record;
4847 -- end P;
4849 and then Parent_Typ /= Tagged_Type
4850 then
4851 Collect (Parent_Typ);
4852 end if;
4854 -- Collect the components containing tags of secondary dispatch
4855 -- tables.
4857 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
4858 while Present (Tag_Comp) loop
4859 pragma Assert (Present (Related_Type (Tag_Comp)));
4860 Append_Elmt (Tag_Comp, Components_List);
4862 Tag_Comp := Next_Tag_Component (Tag_Comp);
4863 end loop;
4864 end Collect;
4866 -- Start of processing for Collect_Interface_Components
4868 begin
4869 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
4870 and then Is_Tagged_Type (Tagged_Type));
4872 Components_List := New_Elmt_List;
4873 Collect (Tagged_Type);
4874 end Collect_Interface_Components;
4876 -----------------------------
4877 -- Collect_Interfaces_Info --
4878 -----------------------------
4880 procedure Collect_Interfaces_Info
4881 (T : Entity_Id;
4882 Ifaces_List : out Elist_Id;
4883 Components_List : out Elist_Id;
4884 Tags_List : out Elist_Id)
4886 Comps_List : Elist_Id;
4887 Comp_Elmt : Elmt_Id;
4888 Comp_Iface : Entity_Id;
4889 Iface_Elmt : Elmt_Id;
4890 Iface : Entity_Id;
4892 function Search_Tag (Iface : Entity_Id) return Entity_Id;
4893 -- Search for the secondary tag associated with the interface type
4894 -- Iface that is implemented by T.
4896 ----------------
4897 -- Search_Tag --
4898 ----------------
4900 function Search_Tag (Iface : Entity_Id) return Entity_Id is
4901 ADT : Elmt_Id;
4902 begin
4903 if not Is_CPP_Class (T) then
4904 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
4905 else
4906 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
4907 end if;
4909 while Present (ADT)
4910 and then Is_Tag (Node (ADT))
4911 and then Related_Type (Node (ADT)) /= Iface
4912 loop
4913 -- Skip secondary dispatch table referencing thunks to user
4914 -- defined primitives covered by this interface.
4916 pragma Assert (Has_Suffix (Node (ADT), 'P'));
4917 Next_Elmt (ADT);
4919 -- Skip secondary dispatch tables of Ada types
4921 if not Is_CPP_Class (T) then
4923 -- Skip secondary dispatch table referencing thunks to
4924 -- predefined primitives.
4926 pragma Assert (Has_Suffix (Node (ADT), 'Y'));
4927 Next_Elmt (ADT);
4929 -- Skip secondary dispatch table referencing user-defined
4930 -- primitives covered by this interface.
4932 pragma Assert (Has_Suffix (Node (ADT), 'D'));
4933 Next_Elmt (ADT);
4935 -- Skip secondary dispatch table referencing predefined
4936 -- primitives.
4938 pragma Assert (Has_Suffix (Node (ADT), 'Z'));
4939 Next_Elmt (ADT);
4940 end if;
4941 end loop;
4943 pragma Assert (Is_Tag (Node (ADT)));
4944 return Node (ADT);
4945 end Search_Tag;
4947 -- Start of processing for Collect_Interfaces_Info
4949 begin
4950 Collect_Interfaces (T, Ifaces_List);
4951 Collect_Interface_Components (T, Comps_List);
4953 -- Search for the record component and tag associated with each
4954 -- interface type of T.
4956 Components_List := New_Elmt_List;
4957 Tags_List := New_Elmt_List;
4959 Iface_Elmt := First_Elmt (Ifaces_List);
4960 while Present (Iface_Elmt) loop
4961 Iface := Node (Iface_Elmt);
4963 -- Associate the primary tag component and the primary dispatch table
4964 -- with all the interfaces that are parents of T
4966 if Is_Ancestor (Iface, T, Use_Full_View => True) then
4967 Append_Elmt (First_Tag_Component (T), Components_List);
4968 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
4970 -- Otherwise search for the tag component and secondary dispatch
4971 -- table of Iface
4973 else
4974 Comp_Elmt := First_Elmt (Comps_List);
4975 while Present (Comp_Elmt) loop
4976 Comp_Iface := Related_Type (Node (Comp_Elmt));
4978 if Comp_Iface = Iface
4979 or else Is_Ancestor (Iface, Comp_Iface, Use_Full_View => True)
4980 then
4981 Append_Elmt (Node (Comp_Elmt), Components_List);
4982 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
4983 exit;
4984 end if;
4986 Next_Elmt (Comp_Elmt);
4987 end loop;
4988 pragma Assert (Present (Comp_Elmt));
4989 end if;
4991 Next_Elmt (Iface_Elmt);
4992 end loop;
4993 end Collect_Interfaces_Info;
4995 ---------------------
4996 -- Collect_Parents --
4997 ---------------------
4999 procedure Collect_Parents
5000 (T : Entity_Id;
5001 List : out Elist_Id;
5002 Use_Full_View : Boolean := True)
5004 Current_Typ : Entity_Id := T;
5005 Parent_Typ : Entity_Id;
5007 begin
5008 List := New_Elmt_List;
5010 -- No action if the if the type has no parents
5012 if T = Etype (T) then
5013 return;
5014 end if;
5016 loop
5017 Parent_Typ := Etype (Current_Typ);
5019 if Is_Private_Type (Parent_Typ)
5020 and then Present (Full_View (Parent_Typ))
5021 and then Use_Full_View
5022 then
5023 Parent_Typ := Full_View (Base_Type (Parent_Typ));
5024 end if;
5026 Append_Elmt (Parent_Typ, List);
5028 exit when Parent_Typ = Current_Typ;
5029 Current_Typ := Parent_Typ;
5030 end loop;
5031 end Collect_Parents;
5033 ----------------------------------
5034 -- Collect_Primitive_Operations --
5035 ----------------------------------
5037 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
5038 B_Type : constant Entity_Id := Base_Type (T);
5039 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
5040 B_Scope : Entity_Id := Scope (B_Type);
5041 Op_List : Elist_Id;
5042 Formal : Entity_Id;
5043 Is_Prim : Boolean;
5044 Is_Type_In_Pkg : Boolean;
5045 Formal_Derived : Boolean := False;
5046 Id : Entity_Id;
5048 function Match (E : Entity_Id) return Boolean;
5049 -- True if E's base type is B_Type, or E is of an anonymous access type
5050 -- and the base type of its designated type is B_Type.
5052 -----------
5053 -- Match --
5054 -----------
5056 function Match (E : Entity_Id) return Boolean is
5057 Etyp : Entity_Id := Etype (E);
5059 begin
5060 if Ekind (Etyp) = E_Anonymous_Access_Type then
5061 Etyp := Designated_Type (Etyp);
5062 end if;
5064 -- In Ada 2012 a primitive operation may have a formal of an
5065 -- incomplete view of the parent type.
5067 return Base_Type (Etyp) = B_Type
5068 or else
5069 (Ada_Version >= Ada_2012
5070 and then Ekind (Etyp) = E_Incomplete_Type
5071 and then Full_View (Etyp) = B_Type);
5072 end Match;
5074 -- Start of processing for Collect_Primitive_Operations
5076 begin
5077 -- For tagged types, the primitive operations are collected as they
5078 -- are declared, and held in an explicit list which is simply returned.
5080 if Is_Tagged_Type (B_Type) then
5081 return Primitive_Operations (B_Type);
5083 -- An untagged generic type that is a derived type inherits the
5084 -- primitive operations of its parent type. Other formal types only
5085 -- have predefined operators, which are not explicitly represented.
5087 elsif Is_Generic_Type (B_Type) then
5088 if Nkind (B_Decl) = N_Formal_Type_Declaration
5089 and then Nkind (Formal_Type_Definition (B_Decl)) =
5090 N_Formal_Derived_Type_Definition
5091 then
5092 Formal_Derived := True;
5093 else
5094 return New_Elmt_List;
5095 end if;
5096 end if;
5098 Op_List := New_Elmt_List;
5100 if B_Scope = Standard_Standard then
5101 if B_Type = Standard_String then
5102 Append_Elmt (Standard_Op_Concat, Op_List);
5104 elsif B_Type = Standard_Wide_String then
5105 Append_Elmt (Standard_Op_Concatw, Op_List);
5107 else
5108 null;
5109 end if;
5111 -- Locate the primitive subprograms of the type
5113 else
5114 -- The primitive operations appear after the base type, except
5115 -- if the derivation happens within the private part of B_Scope
5116 -- and the type is a private type, in which case both the type
5117 -- and some primitive operations may appear before the base
5118 -- type, and the list of candidates starts after the type.
5120 if In_Open_Scopes (B_Scope)
5121 and then Scope (T) = B_Scope
5122 and then In_Private_Part (B_Scope)
5123 then
5124 Id := Next_Entity (T);
5126 -- In Ada 2012, If the type has an incomplete partial view, there
5127 -- may be primitive operations declared before the full view, so
5128 -- we need to start scanning from the incomplete view, which is
5129 -- earlier on the entity chain.
5131 elsif Nkind (Parent (B_Type)) = N_Full_Type_Declaration
5132 and then Present (Incomplete_View (Parent (B_Type)))
5133 then
5134 Id := Defining_Entity (Incomplete_View (Parent (B_Type)));
5136 -- If T is a derived from a type with an incomplete view declared
5137 -- elsewhere, that incomplete view is irrelevant, we want the
5138 -- operations in the scope of T.
5140 if Scope (Id) /= Scope (B_Type) then
5141 Id := Next_Entity (B_Type);
5142 end if;
5144 else
5145 Id := Next_Entity (B_Type);
5146 end if;
5148 -- Set flag if this is a type in a package spec
5150 Is_Type_In_Pkg :=
5151 Is_Package_Or_Generic_Package (B_Scope)
5152 and then
5153 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
5154 N_Package_Body;
5156 while Present (Id) loop
5158 -- Test whether the result type or any of the parameter types of
5159 -- each subprogram following the type match that type when the
5160 -- type is declared in a package spec, is a derived type, or the
5161 -- subprogram is marked as primitive. (The Is_Primitive test is
5162 -- needed to find primitives of nonderived types in declarative
5163 -- parts that happen to override the predefined "=" operator.)
5165 -- Note that generic formal subprograms are not considered to be
5166 -- primitive operations and thus are never inherited.
5168 if Is_Overloadable (Id)
5169 and then (Is_Type_In_Pkg
5170 or else Is_Derived_Type (B_Type)
5171 or else Is_Primitive (Id))
5172 and then Nkind (Parent (Parent (Id)))
5173 not in N_Formal_Subprogram_Declaration
5174 then
5175 Is_Prim := False;
5177 if Match (Id) then
5178 Is_Prim := True;
5180 else
5181 Formal := First_Formal (Id);
5182 while Present (Formal) loop
5183 if Match (Formal) then
5184 Is_Prim := True;
5185 exit;
5186 end if;
5188 Next_Formal (Formal);
5189 end loop;
5190 end if;
5192 -- For a formal derived type, the only primitives are the ones
5193 -- inherited from the parent type. Operations appearing in the
5194 -- package declaration are not primitive for it.
5196 if Is_Prim
5197 and then (not Formal_Derived or else Present (Alias (Id)))
5198 then
5199 -- In the special case of an equality operator aliased to
5200 -- an overriding dispatching equality belonging to the same
5201 -- type, we don't include it in the list of primitives.
5202 -- This avoids inheriting multiple equality operators when
5203 -- deriving from untagged private types whose full type is
5204 -- tagged, which can otherwise cause ambiguities. Note that
5205 -- this should only happen for this kind of untagged parent
5206 -- type, since normally dispatching operations are inherited
5207 -- using the type's Primitive_Operations list.
5209 if Chars (Id) = Name_Op_Eq
5210 and then Is_Dispatching_Operation (Id)
5211 and then Present (Alias (Id))
5212 and then Present (Overridden_Operation (Alias (Id)))
5213 and then Base_Type (Etype (First_Entity (Id))) =
5214 Base_Type (Etype (First_Entity (Alias (Id))))
5215 then
5216 null;
5218 -- Include the subprogram in the list of primitives
5220 else
5221 Append_Elmt (Id, Op_List);
5222 end if;
5223 end if;
5224 end if;
5226 Next_Entity (Id);
5228 -- For a type declared in System, some of its operations may
5229 -- appear in the target-specific extension to System.
5231 if No (Id)
5232 and then B_Scope = RTU_Entity (System)
5233 and then Present_System_Aux
5234 then
5235 B_Scope := System_Aux_Id;
5236 Id := First_Entity (System_Aux_Id);
5237 end if;
5238 end loop;
5239 end if;
5241 return Op_List;
5242 end Collect_Primitive_Operations;
5244 -----------------------------------
5245 -- Compile_Time_Constraint_Error --
5246 -----------------------------------
5248 function Compile_Time_Constraint_Error
5249 (N : Node_Id;
5250 Msg : String;
5251 Ent : Entity_Id := Empty;
5252 Loc : Source_Ptr := No_Location;
5253 Warn : Boolean := False) return Node_Id
5255 Msgc : String (1 .. Msg'Length + 3);
5256 -- Copy of message, with room for possible ?? or << and ! at end
5258 Msgl : Natural;
5259 Wmsg : Boolean;
5260 Eloc : Source_Ptr;
5262 -- Start of processing for Compile_Time_Constraint_Error
5264 begin
5265 -- If this is a warning, convert it into an error if we are in code
5266 -- subject to SPARK_Mode being set On, unless Warn is True to force a
5267 -- warning. The rationale is that a compile-time constraint error should
5268 -- lead to an error instead of a warning when SPARK_Mode is On, but in
5269 -- a few cases we prefer to issue a warning and generate both a suitable
5270 -- run-time error in GNAT and a suitable check message in GNATprove.
5271 -- Those cases are those that likely correspond to deactivated SPARK
5272 -- code, so that this kind of code can be compiled and analyzed instead
5273 -- of being rejected.
5275 Error_Msg_Warn := Warn or SPARK_Mode /= On;
5277 -- A static constraint error in an instance body is not a fatal error.
5278 -- we choose to inhibit the message altogether, because there is no
5279 -- obvious node (for now) on which to post it. On the other hand the
5280 -- offending node must be replaced with a constraint_error in any case.
5282 -- No messages are generated if we already posted an error on this node
5284 if not Error_Posted (N) then
5285 if Loc /= No_Location then
5286 Eloc := Loc;
5287 else
5288 Eloc := Sloc (N);
5289 end if;
5291 -- Copy message to Msgc, converting any ? in the message into <
5292 -- instead, so that we have an error in GNATprove mode.
5294 Msgl := Msg'Length;
5296 for J in 1 .. Msgl loop
5297 if Msg (J) = '?' and then (J = 1 or else Msg (J - 1) /= ''') then
5298 Msgc (J) := '<';
5299 else
5300 Msgc (J) := Msg (J);
5301 end if;
5302 end loop;
5304 -- Message is a warning, even in Ada 95 case
5306 if Msg (Msg'Last) = '?' or else Msg (Msg'Last) = '<' then
5307 Wmsg := True;
5309 -- In Ada 83, all messages are warnings. In the private part and the
5310 -- body of an instance, constraint_checks are only warnings. We also
5311 -- make this a warning if the Warn parameter is set.
5313 elsif Warn
5314 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
5315 or else In_Instance_Not_Visible
5316 then
5317 Msgl := Msgl + 1;
5318 Msgc (Msgl) := '<';
5319 Msgl := Msgl + 1;
5320 Msgc (Msgl) := '<';
5321 Wmsg := True;
5323 -- Otherwise we have a real error message (Ada 95 static case) and we
5324 -- make this an unconditional message. Note that in the warning case
5325 -- we do not make the message unconditional, it seems reasonable to
5326 -- delete messages like this (about exceptions that will be raised)
5327 -- in dead code.
5329 else
5330 Wmsg := False;
5331 Msgl := Msgl + 1;
5332 Msgc (Msgl) := '!';
5333 end if;
5335 -- One more test, skip the warning if the related expression is
5336 -- statically unevaluated, since we don't want to warn about what
5337 -- will happen when something is evaluated if it never will be
5338 -- evaluated.
5340 if not Is_Statically_Unevaluated (N) then
5341 if Present (Ent) then
5342 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
5343 else
5344 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
5345 end if;
5347 if Wmsg then
5349 -- Check whether the context is an Init_Proc
5351 if Inside_Init_Proc then
5352 declare
5353 Conc_Typ : constant Entity_Id :=
5354 Corresponding_Concurrent_Type
5355 (Entity (Parameter_Type (First
5356 (Parameter_Specifications
5357 (Parent (Current_Scope))))));
5359 begin
5360 -- Don't complain if the corresponding concurrent type
5361 -- doesn't come from source (i.e. a single task/protected
5362 -- object).
5364 if Present (Conc_Typ)
5365 and then not Comes_From_Source (Conc_Typ)
5366 then
5367 Error_Msg_NEL
5368 ("\& [<<", N, Standard_Constraint_Error, Eloc);
5370 else
5371 if GNATprove_Mode then
5372 Error_Msg_NEL
5373 ("\& would have been raised for objects of this "
5374 & "type", N, Standard_Constraint_Error, Eloc);
5375 else
5376 Error_Msg_NEL
5377 ("\& will be raised for objects of this type??",
5378 N, Standard_Constraint_Error, Eloc);
5379 end if;
5380 end if;
5381 end;
5383 else
5384 Error_Msg_NEL ("\& [<<", N, Standard_Constraint_Error, Eloc);
5385 end if;
5387 else
5388 Error_Msg ("\static expression fails Constraint_Check", Eloc);
5389 Set_Error_Posted (N);
5390 end if;
5391 end if;
5392 end if;
5394 return N;
5395 end Compile_Time_Constraint_Error;
5397 -----------------------
5398 -- Conditional_Delay --
5399 -----------------------
5401 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
5402 begin
5403 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
5404 Set_Has_Delayed_Freeze (New_Ent);
5405 end if;
5406 end Conditional_Delay;
5408 -------------------------
5409 -- Copy_Component_List --
5410 -------------------------
5412 function Copy_Component_List
5413 (R_Typ : Entity_Id;
5414 Loc : Source_Ptr) return List_Id
5416 Comp : Node_Id;
5417 Comps : constant List_Id := New_List;
5419 begin
5420 Comp := First_Component (Underlying_Type (R_Typ));
5421 while Present (Comp) loop
5422 if Comes_From_Source (Comp) then
5423 declare
5424 Comp_Decl : constant Node_Id := Declaration_Node (Comp);
5425 begin
5426 Append_To (Comps,
5427 Make_Component_Declaration (Loc,
5428 Defining_Identifier =>
5429 Make_Defining_Identifier (Loc, Chars (Comp)),
5430 Component_Definition =>
5431 New_Copy_Tree
5432 (Component_Definition (Comp_Decl), New_Sloc => Loc)));
5433 end;
5434 end if;
5436 Next_Component (Comp);
5437 end loop;
5439 return Comps;
5440 end Copy_Component_List;
5442 -------------------------
5443 -- Copy_Parameter_List --
5444 -------------------------
5446 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
5447 Loc : constant Source_Ptr := Sloc (Subp_Id);
5448 Plist : List_Id;
5449 Formal : Entity_Id;
5451 begin
5452 if No (First_Formal (Subp_Id)) then
5453 return No_List;
5454 else
5455 Plist := New_List;
5456 Formal := First_Formal (Subp_Id);
5457 while Present (Formal) loop
5458 Append_To (Plist,
5459 Make_Parameter_Specification (Loc,
5460 Defining_Identifier =>
5461 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)),
5462 In_Present => In_Present (Parent (Formal)),
5463 Out_Present => Out_Present (Parent (Formal)),
5464 Parameter_Type =>
5465 New_Occurrence_Of (Etype (Formal), Loc),
5466 Expression =>
5467 New_Copy_Tree (Expression (Parent (Formal)))));
5469 Next_Formal (Formal);
5470 end loop;
5471 end if;
5473 return Plist;
5474 end Copy_Parameter_List;
5476 ----------------------------
5477 -- Copy_SPARK_Mode_Aspect --
5478 ----------------------------
5480 procedure Copy_SPARK_Mode_Aspect (From : Node_Id; To : Node_Id) is
5481 pragma Assert (not Has_Aspects (To));
5482 Asp : Node_Id;
5484 begin
5485 if Has_Aspects (From) then
5486 Asp := Find_Aspect (Defining_Entity (From), Aspect_SPARK_Mode);
5488 if Present (Asp) then
5489 Set_Aspect_Specifications (To, New_List (New_Copy_Tree (Asp)));
5490 Set_Has_Aspects (To, True);
5491 end if;
5492 end if;
5493 end Copy_SPARK_Mode_Aspect;
5495 --------------------------
5496 -- Copy_Subprogram_Spec --
5497 --------------------------
5499 function Copy_Subprogram_Spec (Spec : Node_Id) return Node_Id is
5500 Def_Id : Node_Id;
5501 Formal_Spec : Node_Id;
5502 Result : Node_Id;
5504 begin
5505 -- The structure of the original tree must be replicated without any
5506 -- alterations. Use New_Copy_Tree for this purpose.
5508 Result := New_Copy_Tree (Spec);
5510 -- However, the spec of a null procedure carries the corresponding null
5511 -- statement of the body (created by the parser), and this cannot be
5512 -- shared with the new subprogram spec.
5514 if Nkind (Result) = N_Procedure_Specification then
5515 Set_Null_Statement (Result, Empty);
5516 end if;
5518 -- Create a new entity for the defining unit name
5520 Def_Id := Defining_Unit_Name (Result);
5521 Set_Defining_Unit_Name (Result,
5522 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
5524 -- Create new entities for the formal parameters
5526 if Present (Parameter_Specifications (Result)) then
5527 Formal_Spec := First (Parameter_Specifications (Result));
5528 while Present (Formal_Spec) loop
5529 Def_Id := Defining_Identifier (Formal_Spec);
5530 Set_Defining_Identifier (Formal_Spec,
5531 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
5533 Next (Formal_Spec);
5534 end loop;
5535 end if;
5537 return Result;
5538 end Copy_Subprogram_Spec;
5540 --------------------------------
5541 -- Corresponding_Generic_Type --
5542 --------------------------------
5544 function Corresponding_Generic_Type (T : Entity_Id) return Entity_Id is
5545 Inst : Entity_Id;
5546 Gen : Entity_Id;
5547 Typ : Entity_Id;
5549 begin
5550 if not Is_Generic_Actual_Type (T) then
5551 return Any_Type;
5553 -- If the actual is the actual of an enclosing instance, resolution
5554 -- was correct in the generic.
5556 elsif Nkind (Parent (T)) = N_Subtype_Declaration
5557 and then Is_Entity_Name (Subtype_Indication (Parent (T)))
5558 and then
5559 Is_Generic_Actual_Type (Entity (Subtype_Indication (Parent (T))))
5560 then
5561 return Any_Type;
5563 else
5564 Inst := Scope (T);
5566 if Is_Wrapper_Package (Inst) then
5567 Inst := Related_Instance (Inst);
5568 end if;
5570 Gen :=
5571 Generic_Parent
5572 (Specification (Unit_Declaration_Node (Inst)));
5574 -- Generic actual has the same name as the corresponding formal
5576 Typ := First_Entity (Gen);
5577 while Present (Typ) loop
5578 if Chars (Typ) = Chars (T) then
5579 return Typ;
5580 end if;
5582 Next_Entity (Typ);
5583 end loop;
5585 return Any_Type;
5586 end if;
5587 end Corresponding_Generic_Type;
5589 --------------------
5590 -- Current_Entity --
5591 --------------------
5593 -- The currently visible definition for a given identifier is the
5594 -- one most chained at the start of the visibility chain, i.e. the
5595 -- one that is referenced by the Node_Id value of the name of the
5596 -- given identifier.
5598 function Current_Entity (N : Node_Id) return Entity_Id is
5599 begin
5600 return Get_Name_Entity_Id (Chars (N));
5601 end Current_Entity;
5603 -----------------------------
5604 -- Current_Entity_In_Scope --
5605 -----------------------------
5607 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
5608 E : Entity_Id;
5609 CS : constant Entity_Id := Current_Scope;
5611 Transient_Case : constant Boolean := Scope_Is_Transient;
5613 begin
5614 E := Get_Name_Entity_Id (Chars (N));
5615 while Present (E)
5616 and then Scope (E) /= CS
5617 and then (not Transient_Case or else Scope (E) /= Scope (CS))
5618 loop
5619 E := Homonym (E);
5620 end loop;
5622 return E;
5623 end Current_Entity_In_Scope;
5625 -------------------
5626 -- Current_Scope --
5627 -------------------
5629 function Current_Scope return Entity_Id is
5630 begin
5631 if Scope_Stack.Last = -1 then
5632 return Standard_Standard;
5633 else
5634 declare
5635 C : constant Entity_Id :=
5636 Scope_Stack.Table (Scope_Stack.Last).Entity;
5637 begin
5638 if Present (C) then
5639 return C;
5640 else
5641 return Standard_Standard;
5642 end if;
5643 end;
5644 end if;
5645 end Current_Scope;
5647 ----------------------------
5648 -- Current_Scope_No_Loops --
5649 ----------------------------
5651 function Current_Scope_No_Loops return Entity_Id is
5652 S : Entity_Id;
5654 begin
5655 -- Examine the scope stack starting from the current scope and skip any
5656 -- internally generated loops.
5658 S := Current_Scope;
5659 while Present (S) and then S /= Standard_Standard loop
5660 if Ekind (S) = E_Loop and then not Comes_From_Source (S) then
5661 S := Scope (S);
5662 else
5663 exit;
5664 end if;
5665 end loop;
5667 return S;
5668 end Current_Scope_No_Loops;
5670 ------------------------
5671 -- Current_Subprogram --
5672 ------------------------
5674 function Current_Subprogram return Entity_Id is
5675 Scop : constant Entity_Id := Current_Scope;
5676 begin
5677 if Is_Subprogram_Or_Generic_Subprogram (Scop) then
5678 return Scop;
5679 else
5680 return Enclosing_Subprogram (Scop);
5681 end if;
5682 end Current_Subprogram;
5684 ----------------------------------
5685 -- Deepest_Type_Access_Level --
5686 ----------------------------------
5688 function Deepest_Type_Access_Level (Typ : Entity_Id) return Uint is
5689 begin
5690 if Ekind (Typ) = E_Anonymous_Access_Type
5691 and then not Is_Local_Anonymous_Access (Typ)
5692 and then Nkind (Associated_Node_For_Itype (Typ)) = N_Object_Declaration
5693 then
5694 -- Typ is the type of an Ada 2012 stand-alone object of an anonymous
5695 -- access type.
5697 return
5698 Scope_Depth (Enclosing_Dynamic_Scope
5699 (Defining_Identifier
5700 (Associated_Node_For_Itype (Typ))));
5702 -- For generic formal type, return Int'Last (infinite).
5703 -- See comment preceding Is_Generic_Type call in Type_Access_Level.
5705 elsif Is_Generic_Type (Root_Type (Typ)) then
5706 return UI_From_Int (Int'Last);
5708 else
5709 return Type_Access_Level (Typ);
5710 end if;
5711 end Deepest_Type_Access_Level;
5713 ---------------------
5714 -- Defining_Entity --
5715 ---------------------
5717 function Defining_Entity
5718 (N : Node_Id;
5719 Empty_On_Errors : Boolean := False;
5720 Concurrent_Subunit : Boolean := False) return Entity_Id
5722 begin
5723 case Nkind (N) is
5724 when N_Abstract_Subprogram_Declaration
5725 | N_Expression_Function
5726 | N_Formal_Subprogram_Declaration
5727 | N_Generic_Package_Declaration
5728 | N_Generic_Subprogram_Declaration
5729 | N_Package_Declaration
5730 | N_Subprogram_Body
5731 | N_Subprogram_Body_Stub
5732 | N_Subprogram_Declaration
5733 | N_Subprogram_Renaming_Declaration
5735 return Defining_Entity (Specification (N));
5737 when N_Component_Declaration
5738 | N_Defining_Program_Unit_Name
5739 | N_Discriminant_Specification
5740 | N_Entry_Body
5741 | N_Entry_Declaration
5742 | N_Entry_Index_Specification
5743 | N_Exception_Declaration
5744 | N_Exception_Renaming_Declaration
5745 | N_Formal_Object_Declaration
5746 | N_Formal_Package_Declaration
5747 | N_Formal_Type_Declaration
5748 | N_Full_Type_Declaration
5749 | N_Implicit_Label_Declaration
5750 | N_Incomplete_Type_Declaration
5751 | N_Iterator_Specification
5752 | N_Loop_Parameter_Specification
5753 | N_Number_Declaration
5754 | N_Object_Declaration
5755 | N_Object_Renaming_Declaration
5756 | N_Package_Body_Stub
5757 | N_Parameter_Specification
5758 | N_Private_Extension_Declaration
5759 | N_Private_Type_Declaration
5760 | N_Protected_Body
5761 | N_Protected_Body_Stub
5762 | N_Protected_Type_Declaration
5763 | N_Single_Protected_Declaration
5764 | N_Single_Task_Declaration
5765 | N_Subtype_Declaration
5766 | N_Task_Body
5767 | N_Task_Body_Stub
5768 | N_Task_Type_Declaration
5770 return Defining_Identifier (N);
5772 when N_Subunit =>
5773 declare
5774 Bod : constant Node_Id := Proper_Body (N);
5775 Orig_Bod : constant Node_Id := Original_Node (Bod);
5777 begin
5778 -- Retrieve the entity of the original protected or task body
5779 -- if requested by the caller.
5781 if Concurrent_Subunit
5782 and then Nkind (Bod) = N_Null_Statement
5783 and then Nkind_In (Orig_Bod, N_Protected_Body, N_Task_Body)
5784 then
5785 return Defining_Entity (Orig_Bod);
5786 else
5787 return Defining_Entity (Bod);
5788 end if;
5789 end;
5791 when N_Function_Instantiation
5792 | N_Function_Specification
5793 | N_Generic_Function_Renaming_Declaration
5794 | N_Generic_Package_Renaming_Declaration
5795 | N_Generic_Procedure_Renaming_Declaration
5796 | N_Package_Body
5797 | N_Package_Instantiation
5798 | N_Package_Renaming_Declaration
5799 | N_Package_Specification
5800 | N_Procedure_Instantiation
5801 | N_Procedure_Specification
5803 declare
5804 Nam : constant Node_Id := Defining_Unit_Name (N);
5805 Err : Entity_Id := Empty;
5807 begin
5808 if Nkind (Nam) in N_Entity then
5809 return Nam;
5811 -- For Error, make up a name and attach to declaration so we
5812 -- can continue semantic analysis.
5814 elsif Nam = Error then
5815 if Empty_On_Errors then
5816 return Empty;
5817 else
5818 Err := Make_Temporary (Sloc (N), 'T');
5819 Set_Defining_Unit_Name (N, Err);
5821 return Err;
5822 end if;
5824 -- If not an entity, get defining identifier
5826 else
5827 return Defining_Identifier (Nam);
5828 end if;
5829 end;
5831 when N_Block_Statement
5832 | N_Loop_Statement
5834 return Entity (Identifier (N));
5836 when others =>
5837 if Empty_On_Errors then
5838 return Empty;
5839 else
5840 raise Program_Error;
5841 end if;
5842 end case;
5843 end Defining_Entity;
5845 --------------------------
5846 -- Denotes_Discriminant --
5847 --------------------------
5849 function Denotes_Discriminant
5850 (N : Node_Id;
5851 Check_Concurrent : Boolean := False) return Boolean
5853 E : Entity_Id;
5855 begin
5856 if not Is_Entity_Name (N) or else No (Entity (N)) then
5857 return False;
5858 else
5859 E := Entity (N);
5860 end if;
5862 -- If we are checking for a protected type, the discriminant may have
5863 -- been rewritten as the corresponding discriminal of the original type
5864 -- or of the corresponding concurrent record, depending on whether we
5865 -- are in the spec or body of the protected type.
5867 return Ekind (E) = E_Discriminant
5868 or else
5869 (Check_Concurrent
5870 and then Ekind (E) = E_In_Parameter
5871 and then Present (Discriminal_Link (E))
5872 and then
5873 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
5874 or else
5875 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
5876 end Denotes_Discriminant;
5878 -------------------------
5879 -- Denotes_Same_Object --
5880 -------------------------
5882 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
5883 Obj1 : Node_Id := A1;
5884 Obj2 : Node_Id := A2;
5886 function Has_Prefix (N : Node_Id) return Boolean;
5887 -- Return True if N has attribute Prefix
5889 function Is_Renaming (N : Node_Id) return Boolean;
5890 -- Return true if N names a renaming entity
5892 function Is_Valid_Renaming (N : Node_Id) return Boolean;
5893 -- For renamings, return False if the prefix of any dereference within
5894 -- the renamed object_name is a variable, or any expression within the
5895 -- renamed object_name contains references to variables or calls on
5896 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
5898 ----------------
5899 -- Has_Prefix --
5900 ----------------
5902 function Has_Prefix (N : Node_Id) return Boolean is
5903 begin
5904 return
5905 Nkind_In (N,
5906 N_Attribute_Reference,
5907 N_Expanded_Name,
5908 N_Explicit_Dereference,
5909 N_Indexed_Component,
5910 N_Reference,
5911 N_Selected_Component,
5912 N_Slice);
5913 end Has_Prefix;
5915 -----------------
5916 -- Is_Renaming --
5917 -----------------
5919 function Is_Renaming (N : Node_Id) return Boolean is
5920 begin
5921 return Is_Entity_Name (N)
5922 and then Present (Renamed_Entity (Entity (N)));
5923 end Is_Renaming;
5925 -----------------------
5926 -- Is_Valid_Renaming --
5927 -----------------------
5929 function Is_Valid_Renaming (N : Node_Id) return Boolean is
5931 function Check_Renaming (N : Node_Id) return Boolean;
5932 -- Recursive function used to traverse all the prefixes of N
5934 function Check_Renaming (N : Node_Id) return Boolean is
5935 begin
5936 if Is_Renaming (N)
5937 and then not Check_Renaming (Renamed_Entity (Entity (N)))
5938 then
5939 return False;
5940 end if;
5942 if Nkind (N) = N_Indexed_Component then
5943 declare
5944 Indx : Node_Id;
5946 begin
5947 Indx := First (Expressions (N));
5948 while Present (Indx) loop
5949 if not Is_OK_Static_Expression (Indx) then
5950 return False;
5951 end if;
5953 Next_Index (Indx);
5954 end loop;
5955 end;
5956 end if;
5958 if Has_Prefix (N) then
5959 declare
5960 P : constant Node_Id := Prefix (N);
5962 begin
5963 if Nkind (N) = N_Explicit_Dereference
5964 and then Is_Variable (P)
5965 then
5966 return False;
5968 elsif Is_Entity_Name (P)
5969 and then Ekind (Entity (P)) = E_Function
5970 then
5971 return False;
5973 elsif Nkind (P) = N_Function_Call then
5974 return False;
5975 end if;
5977 -- Recursion to continue traversing the prefix of the
5978 -- renaming expression
5980 return Check_Renaming (P);
5981 end;
5982 end if;
5984 return True;
5985 end Check_Renaming;
5987 -- Start of processing for Is_Valid_Renaming
5989 begin
5990 return Check_Renaming (N);
5991 end Is_Valid_Renaming;
5993 -- Start of processing for Denotes_Same_Object
5995 begin
5996 -- Both names statically denote the same stand-alone object or parameter
5997 -- (RM 6.4.1(6.5/3))
5999 if Is_Entity_Name (Obj1)
6000 and then Is_Entity_Name (Obj2)
6001 and then Entity (Obj1) = Entity (Obj2)
6002 then
6003 return True;
6004 end if;
6006 -- For renamings, the prefix of any dereference within the renamed
6007 -- object_name is not a variable, and any expression within the
6008 -- renamed object_name contains no references to variables nor
6009 -- calls on nonstatic functions (RM 6.4.1(6.10/3)).
6011 if Is_Renaming (Obj1) then
6012 if Is_Valid_Renaming (Obj1) then
6013 Obj1 := Renamed_Entity (Entity (Obj1));
6014 else
6015 return False;
6016 end if;
6017 end if;
6019 if Is_Renaming (Obj2) then
6020 if Is_Valid_Renaming (Obj2) then
6021 Obj2 := Renamed_Entity (Entity (Obj2));
6022 else
6023 return False;
6024 end if;
6025 end if;
6027 -- No match if not same node kind (such cases are handled by
6028 -- Denotes_Same_Prefix)
6030 if Nkind (Obj1) /= Nkind (Obj2) then
6031 return False;
6033 -- After handling valid renamings, one of the two names statically
6034 -- denoted a renaming declaration whose renamed object_name is known
6035 -- to denote the same object as the other (RM 6.4.1(6.10/3))
6037 elsif Is_Entity_Name (Obj1) then
6038 if Is_Entity_Name (Obj2) then
6039 return Entity (Obj1) = Entity (Obj2);
6040 else
6041 return False;
6042 end if;
6044 -- Both names are selected_components, their prefixes are known to
6045 -- denote the same object, and their selector_names denote the same
6046 -- component (RM 6.4.1(6.6/3)).
6048 elsif Nkind (Obj1) = N_Selected_Component then
6049 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
6050 and then
6051 Entity (Selector_Name (Obj1)) = Entity (Selector_Name (Obj2));
6053 -- Both names are dereferences and the dereferenced names are known to
6054 -- denote the same object (RM 6.4.1(6.7/3))
6056 elsif Nkind (Obj1) = N_Explicit_Dereference then
6057 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2));
6059 -- Both names are indexed_components, their prefixes are known to denote
6060 -- the same object, and each of the pairs of corresponding index values
6061 -- are either both static expressions with the same static value or both
6062 -- names that are known to denote the same object (RM 6.4.1(6.8/3))
6064 elsif Nkind (Obj1) = N_Indexed_Component then
6065 if not Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2)) then
6066 return False;
6067 else
6068 declare
6069 Indx1 : Node_Id;
6070 Indx2 : Node_Id;
6072 begin
6073 Indx1 := First (Expressions (Obj1));
6074 Indx2 := First (Expressions (Obj2));
6075 while Present (Indx1) loop
6077 -- Indexes must denote the same static value or same object
6079 if Is_OK_Static_Expression (Indx1) then
6080 if not Is_OK_Static_Expression (Indx2) then
6081 return False;
6083 elsif Expr_Value (Indx1) /= Expr_Value (Indx2) then
6084 return False;
6085 end if;
6087 elsif not Denotes_Same_Object (Indx1, Indx2) then
6088 return False;
6089 end if;
6091 Next (Indx1);
6092 Next (Indx2);
6093 end loop;
6095 return True;
6096 end;
6097 end if;
6099 -- Both names are slices, their prefixes are known to denote the same
6100 -- object, and the two slices have statically matching index constraints
6101 -- (RM 6.4.1(6.9/3))
6103 elsif Nkind (Obj1) = N_Slice
6104 and then Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
6105 then
6106 declare
6107 Lo1, Lo2, Hi1, Hi2 : Node_Id;
6109 begin
6110 Get_Index_Bounds (Etype (Obj1), Lo1, Hi1);
6111 Get_Index_Bounds (Etype (Obj2), Lo2, Hi2);
6113 -- Check whether bounds are statically identical. There is no
6114 -- attempt to detect partial overlap of slices.
6116 return Denotes_Same_Object (Lo1, Lo2)
6117 and then
6118 Denotes_Same_Object (Hi1, Hi2);
6119 end;
6121 -- In the recursion, literals appear as indexes
6123 elsif Nkind (Obj1) = N_Integer_Literal
6124 and then
6125 Nkind (Obj2) = N_Integer_Literal
6126 then
6127 return Intval (Obj1) = Intval (Obj2);
6129 else
6130 return False;
6131 end if;
6132 end Denotes_Same_Object;
6134 -------------------------
6135 -- Denotes_Same_Prefix --
6136 -------------------------
6138 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
6139 begin
6140 if Is_Entity_Name (A1) then
6141 if Nkind_In (A2, N_Selected_Component, N_Indexed_Component)
6142 and then not Is_Access_Type (Etype (A1))
6143 then
6144 return Denotes_Same_Object (A1, Prefix (A2))
6145 or else Denotes_Same_Prefix (A1, Prefix (A2));
6146 else
6147 return False;
6148 end if;
6150 elsif Is_Entity_Name (A2) then
6151 return Denotes_Same_Prefix (A1 => A2, A2 => A1);
6153 elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
6154 and then
6155 Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
6156 then
6157 declare
6158 Root1, Root2 : Node_Id;
6159 Depth1, Depth2 : Nat := 0;
6161 begin
6162 Root1 := Prefix (A1);
6163 while not Is_Entity_Name (Root1) loop
6164 if not Nkind_In
6165 (Root1, N_Selected_Component, N_Indexed_Component)
6166 then
6167 return False;
6168 else
6169 Root1 := Prefix (Root1);
6170 end if;
6172 Depth1 := Depth1 + 1;
6173 end loop;
6175 Root2 := Prefix (A2);
6176 while not Is_Entity_Name (Root2) loop
6177 if not Nkind_In (Root2, N_Selected_Component,
6178 N_Indexed_Component)
6179 then
6180 return False;
6181 else
6182 Root2 := Prefix (Root2);
6183 end if;
6185 Depth2 := Depth2 + 1;
6186 end loop;
6188 -- If both have the same depth and they do not denote the same
6189 -- object, they are disjoint and no warning is needed.
6191 if Depth1 = Depth2 then
6192 return False;
6194 elsif Depth1 > Depth2 then
6195 Root1 := Prefix (A1);
6196 for J in 1 .. Depth1 - Depth2 - 1 loop
6197 Root1 := Prefix (Root1);
6198 end loop;
6200 return Denotes_Same_Object (Root1, A2);
6202 else
6203 Root2 := Prefix (A2);
6204 for J in 1 .. Depth2 - Depth1 - 1 loop
6205 Root2 := Prefix (Root2);
6206 end loop;
6208 return Denotes_Same_Object (A1, Root2);
6209 end if;
6210 end;
6212 else
6213 return False;
6214 end if;
6215 end Denotes_Same_Prefix;
6217 ----------------------
6218 -- Denotes_Variable --
6219 ----------------------
6221 function Denotes_Variable (N : Node_Id) return Boolean is
6222 begin
6223 return Is_Variable (N) and then Paren_Count (N) = 0;
6224 end Denotes_Variable;
6226 -----------------------------
6227 -- Depends_On_Discriminant --
6228 -----------------------------
6230 function Depends_On_Discriminant (N : Node_Id) return Boolean is
6231 L : Node_Id;
6232 H : Node_Id;
6234 begin
6235 Get_Index_Bounds (N, L, H);
6236 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
6237 end Depends_On_Discriminant;
6239 -------------------------
6240 -- Designate_Same_Unit --
6241 -------------------------
6243 function Designate_Same_Unit
6244 (Name1 : Node_Id;
6245 Name2 : Node_Id) return Boolean
6247 K1 : constant Node_Kind := Nkind (Name1);
6248 K2 : constant Node_Kind := Nkind (Name2);
6250 function Prefix_Node (N : Node_Id) return Node_Id;
6251 -- Returns the parent unit name node of a defining program unit name
6252 -- or the prefix if N is a selected component or an expanded name.
6254 function Select_Node (N : Node_Id) return Node_Id;
6255 -- Returns the defining identifier node of a defining program unit
6256 -- name or the selector node if N is a selected component or an
6257 -- expanded name.
6259 -----------------
6260 -- Prefix_Node --
6261 -----------------
6263 function Prefix_Node (N : Node_Id) return Node_Id is
6264 begin
6265 if Nkind (N) = N_Defining_Program_Unit_Name then
6266 return Name (N);
6267 else
6268 return Prefix (N);
6269 end if;
6270 end Prefix_Node;
6272 -----------------
6273 -- Select_Node --
6274 -----------------
6276 function Select_Node (N : Node_Id) return Node_Id is
6277 begin
6278 if Nkind (N) = N_Defining_Program_Unit_Name then
6279 return Defining_Identifier (N);
6280 else
6281 return Selector_Name (N);
6282 end if;
6283 end Select_Node;
6285 -- Start of processing for Designate_Same_Unit
6287 begin
6288 if Nkind_In (K1, N_Identifier, N_Defining_Identifier)
6289 and then
6290 Nkind_In (K2, N_Identifier, N_Defining_Identifier)
6291 then
6292 return Chars (Name1) = Chars (Name2);
6294 elsif Nkind_In (K1, N_Expanded_Name,
6295 N_Selected_Component,
6296 N_Defining_Program_Unit_Name)
6297 and then
6298 Nkind_In (K2, N_Expanded_Name,
6299 N_Selected_Component,
6300 N_Defining_Program_Unit_Name)
6301 then
6302 return
6303 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
6304 and then
6305 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
6307 else
6308 return False;
6309 end if;
6310 end Designate_Same_Unit;
6312 ---------------------------------------------
6313 -- Diagnose_Iterated_Component_Association --
6314 ---------------------------------------------
6316 procedure Diagnose_Iterated_Component_Association (N : Node_Id) is
6317 Def_Id : constant Entity_Id := Defining_Identifier (N);
6318 Aggr : Node_Id;
6320 begin
6321 -- Determine whether the iterated component association appears within
6322 -- an aggregate. If this is the case, raise Program_Error because the
6323 -- iterated component association cannot be left in the tree as is and
6324 -- must always be processed by the related aggregate.
6326 Aggr := N;
6327 while Present (Aggr) loop
6328 if Nkind (Aggr) = N_Aggregate then
6329 raise Program_Error;
6331 -- Prevent the search from going too far
6333 elsif Is_Body_Or_Package_Declaration (Aggr) then
6334 exit;
6335 end if;
6337 Aggr := Parent (Aggr);
6338 end loop;
6340 -- At this point it is known that the iterated component association is
6341 -- not within an aggregate. This is really a quantified expression with
6342 -- a missing "all" or "some" quantifier.
6344 Error_Msg_N ("missing quantifier", Def_Id);
6346 -- Rewrite the iterated component association as True to prevent any
6347 -- cascaded errors.
6349 Rewrite (N, New_Occurrence_Of (Standard_True, Sloc (N)));
6350 Analyze (N);
6351 end Diagnose_Iterated_Component_Association;
6353 ---------------------------------
6354 -- Dynamic_Accessibility_Level --
6355 ---------------------------------
6357 function Dynamic_Accessibility_Level (Expr : Node_Id) return Node_Id is
6358 Loc : constant Source_Ptr := Sloc (Expr);
6360 function Make_Level_Literal (Level : Uint) return Node_Id;
6361 -- Construct an integer literal representing an accessibility level
6362 -- with its type set to Natural.
6364 ------------------------
6365 -- Make_Level_Literal --
6366 ------------------------
6368 function Make_Level_Literal (Level : Uint) return Node_Id is
6369 Result : constant Node_Id := Make_Integer_Literal (Loc, Level);
6371 begin
6372 Set_Etype (Result, Standard_Natural);
6373 return Result;
6374 end Make_Level_Literal;
6376 -- Local variables
6378 E : Entity_Id;
6380 -- Start of processing for Dynamic_Accessibility_Level
6382 begin
6383 if Is_Entity_Name (Expr) then
6384 E := Entity (Expr);
6386 if Present (Renamed_Object (E)) then
6387 return Dynamic_Accessibility_Level (Renamed_Object (E));
6388 end if;
6390 if Is_Formal (E) or else Ekind_In (E, E_Variable, E_Constant) then
6391 if Present (Extra_Accessibility (E)) then
6392 return New_Occurrence_Of (Extra_Accessibility (E), Loc);
6393 end if;
6394 end if;
6395 end if;
6397 -- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
6399 case Nkind (Expr) is
6401 -- For access discriminant, the level of the enclosing object
6403 when N_Selected_Component =>
6404 if Ekind (Entity (Selector_Name (Expr))) = E_Discriminant
6405 and then Ekind (Etype (Entity (Selector_Name (Expr)))) =
6406 E_Anonymous_Access_Type
6407 then
6408 return Make_Level_Literal (Object_Access_Level (Expr));
6409 end if;
6411 when N_Attribute_Reference =>
6412 case Get_Attribute_Id (Attribute_Name (Expr)) is
6414 -- For X'Access, the level of the prefix X
6416 when Attribute_Access =>
6417 return Make_Level_Literal
6418 (Object_Access_Level (Prefix (Expr)));
6420 -- Treat the unchecked attributes as library-level
6422 when Attribute_Unchecked_Access
6423 | Attribute_Unrestricted_Access
6425 return Make_Level_Literal (Scope_Depth (Standard_Standard));
6427 -- No other access-valued attributes
6429 when others =>
6430 raise Program_Error;
6431 end case;
6433 when N_Allocator =>
6435 -- Unimplemented: depends on context. As an actual parameter where
6436 -- formal type is anonymous, use
6437 -- Scope_Depth (Current_Scope) + 1.
6438 -- For other cases, see 3.10.2(14/3) and following. ???
6440 null;
6442 when N_Type_Conversion =>
6443 if not Is_Local_Anonymous_Access (Etype (Expr)) then
6445 -- Handle type conversions introduced for a rename of an
6446 -- Ada 2012 stand-alone object of an anonymous access type.
6448 return Dynamic_Accessibility_Level (Expression (Expr));
6449 end if;
6451 when others =>
6452 null;
6453 end case;
6455 return Make_Level_Literal (Type_Access_Level (Etype (Expr)));
6456 end Dynamic_Accessibility_Level;
6458 ------------------------
6459 -- Discriminated_Size --
6460 ------------------------
6462 function Discriminated_Size (Comp : Entity_Id) return Boolean is
6463 function Non_Static_Bound (Bound : Node_Id) return Boolean;
6464 -- Check whether the bound of an index is non-static and does denote
6465 -- a discriminant, in which case any object of the type (protected or
6466 -- otherwise) will have a non-static size.
6468 ----------------------
6469 -- Non_Static_Bound --
6470 ----------------------
6472 function Non_Static_Bound (Bound : Node_Id) return Boolean is
6473 begin
6474 if Is_OK_Static_Expression (Bound) then
6475 return False;
6477 -- If the bound is given by a discriminant it is non-static
6478 -- (A static constraint replaces the reference with the value).
6479 -- In an protected object the discriminant has been replaced by
6480 -- the corresponding discriminal within the protected operation.
6482 elsif Is_Entity_Name (Bound)
6483 and then
6484 (Ekind (Entity (Bound)) = E_Discriminant
6485 or else Present (Discriminal_Link (Entity (Bound))))
6486 then
6487 return False;
6489 else
6490 return True;
6491 end if;
6492 end Non_Static_Bound;
6494 -- Local variables
6496 Typ : constant Entity_Id := Etype (Comp);
6497 Index : Node_Id;
6499 -- Start of processing for Discriminated_Size
6501 begin
6502 if not Is_Array_Type (Typ) then
6503 return False;
6504 end if;
6506 if Ekind (Typ) = E_Array_Subtype then
6507 Index := First_Index (Typ);
6508 while Present (Index) loop
6509 if Non_Static_Bound (Low_Bound (Index))
6510 or else Non_Static_Bound (High_Bound (Index))
6511 then
6512 return False;
6513 end if;
6515 Next_Index (Index);
6516 end loop;
6518 return True;
6519 end if;
6521 return False;
6522 end Discriminated_Size;
6524 -----------------------------------
6525 -- Effective_Extra_Accessibility --
6526 -----------------------------------
6528 function Effective_Extra_Accessibility (Id : Entity_Id) return Entity_Id is
6529 begin
6530 if Present (Renamed_Object (Id))
6531 and then Is_Entity_Name (Renamed_Object (Id))
6532 then
6533 return Effective_Extra_Accessibility (Entity (Renamed_Object (Id)));
6534 else
6535 return Extra_Accessibility (Id);
6536 end if;
6537 end Effective_Extra_Accessibility;
6539 -----------------------------
6540 -- Effective_Reads_Enabled --
6541 -----------------------------
6543 function Effective_Reads_Enabled (Id : Entity_Id) return Boolean is
6544 begin
6545 return Has_Enabled_Property (Id, Name_Effective_Reads);
6546 end Effective_Reads_Enabled;
6548 ------------------------------
6549 -- Effective_Writes_Enabled --
6550 ------------------------------
6552 function Effective_Writes_Enabled (Id : Entity_Id) return Boolean is
6553 begin
6554 return Has_Enabled_Property (Id, Name_Effective_Writes);
6555 end Effective_Writes_Enabled;
6557 ------------------------------
6558 -- Enclosing_Comp_Unit_Node --
6559 ------------------------------
6561 function Enclosing_Comp_Unit_Node (N : Node_Id) return Node_Id is
6562 Current_Node : Node_Id;
6564 begin
6565 Current_Node := N;
6566 while Present (Current_Node)
6567 and then Nkind (Current_Node) /= N_Compilation_Unit
6568 loop
6569 Current_Node := Parent (Current_Node);
6570 end loop;
6572 if Nkind (Current_Node) /= N_Compilation_Unit then
6573 return Empty;
6574 else
6575 return Current_Node;
6576 end if;
6577 end Enclosing_Comp_Unit_Node;
6579 --------------------------
6580 -- Enclosing_CPP_Parent --
6581 --------------------------
6583 function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is
6584 Parent_Typ : Entity_Id := Typ;
6586 begin
6587 while not Is_CPP_Class (Parent_Typ)
6588 and then Etype (Parent_Typ) /= Parent_Typ
6589 loop
6590 Parent_Typ := Etype (Parent_Typ);
6592 if Is_Private_Type (Parent_Typ) then
6593 Parent_Typ := Full_View (Base_Type (Parent_Typ));
6594 end if;
6595 end loop;
6597 pragma Assert (Is_CPP_Class (Parent_Typ));
6598 return Parent_Typ;
6599 end Enclosing_CPP_Parent;
6601 ---------------------------
6602 -- Enclosing_Declaration --
6603 ---------------------------
6605 function Enclosing_Declaration (N : Node_Id) return Node_Id is
6606 Decl : Node_Id := N;
6608 begin
6609 while Present (Decl)
6610 and then not (Nkind (Decl) in N_Declaration
6611 or else
6612 Nkind (Decl) in N_Later_Decl_Item)
6613 loop
6614 Decl := Parent (Decl);
6615 end loop;
6617 return Decl;
6618 end Enclosing_Declaration;
6620 ----------------------------
6621 -- Enclosing_Generic_Body --
6622 ----------------------------
6624 function Enclosing_Generic_Body
6625 (N : Node_Id) return Node_Id
6627 P : Node_Id;
6628 Decl : Node_Id;
6629 Spec : Node_Id;
6631 begin
6632 P := Parent (N);
6633 while Present (P) loop
6634 if Nkind (P) = N_Package_Body
6635 or else Nkind (P) = N_Subprogram_Body
6636 then
6637 Spec := Corresponding_Spec (P);
6639 if Present (Spec) then
6640 Decl := Unit_Declaration_Node (Spec);
6642 if Nkind (Decl) = N_Generic_Package_Declaration
6643 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
6644 then
6645 return P;
6646 end if;
6647 end if;
6648 end if;
6650 P := Parent (P);
6651 end loop;
6653 return Empty;
6654 end Enclosing_Generic_Body;
6656 ----------------------------
6657 -- Enclosing_Generic_Unit --
6658 ----------------------------
6660 function Enclosing_Generic_Unit
6661 (N : Node_Id) return Node_Id
6663 P : Node_Id;
6664 Decl : Node_Id;
6665 Spec : Node_Id;
6667 begin
6668 P := Parent (N);
6669 while Present (P) loop
6670 if Nkind (P) = N_Generic_Package_Declaration
6671 or else Nkind (P) = N_Generic_Subprogram_Declaration
6672 then
6673 return P;
6675 elsif Nkind (P) = N_Package_Body
6676 or else Nkind (P) = N_Subprogram_Body
6677 then
6678 Spec := Corresponding_Spec (P);
6680 if Present (Spec) then
6681 Decl := Unit_Declaration_Node (Spec);
6683 if Nkind (Decl) = N_Generic_Package_Declaration
6684 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
6685 then
6686 return Decl;
6687 end if;
6688 end if;
6689 end if;
6691 P := Parent (P);
6692 end loop;
6694 return Empty;
6695 end Enclosing_Generic_Unit;
6697 -------------------------------
6698 -- Enclosing_Lib_Unit_Entity --
6699 -------------------------------
6701 function Enclosing_Lib_Unit_Entity
6702 (E : Entity_Id := Current_Scope) return Entity_Id
6704 Unit_Entity : Entity_Id;
6706 begin
6707 -- Look for enclosing library unit entity by following scope links.
6708 -- Equivalent to, but faster than indexing through the scope stack.
6710 Unit_Entity := E;
6711 while (Present (Scope (Unit_Entity))
6712 and then Scope (Unit_Entity) /= Standard_Standard)
6713 and not Is_Child_Unit (Unit_Entity)
6714 loop
6715 Unit_Entity := Scope (Unit_Entity);
6716 end loop;
6718 return Unit_Entity;
6719 end Enclosing_Lib_Unit_Entity;
6721 -----------------------------
6722 -- Enclosing_Lib_Unit_Node --
6723 -----------------------------
6725 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
6726 Encl_Unit : Node_Id;
6728 begin
6729 Encl_Unit := Enclosing_Comp_Unit_Node (N);
6730 while Present (Encl_Unit)
6731 and then Nkind (Unit (Encl_Unit)) = N_Subunit
6732 loop
6733 Encl_Unit := Library_Unit (Encl_Unit);
6734 end loop;
6736 pragma Assert (Nkind (Encl_Unit) = N_Compilation_Unit);
6737 return Encl_Unit;
6738 end Enclosing_Lib_Unit_Node;
6740 -----------------------
6741 -- Enclosing_Package --
6742 -----------------------
6744 function Enclosing_Package (E : Entity_Id) return Entity_Id is
6745 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
6747 begin
6748 if Dynamic_Scope = Standard_Standard then
6749 return Standard_Standard;
6751 elsif Dynamic_Scope = Empty then
6752 return Empty;
6754 elsif Ekind_In (Dynamic_Scope, E_Package, E_Package_Body,
6755 E_Generic_Package)
6756 then
6757 return Dynamic_Scope;
6759 else
6760 return Enclosing_Package (Dynamic_Scope);
6761 end if;
6762 end Enclosing_Package;
6764 -------------------------------------
6765 -- Enclosing_Package_Or_Subprogram --
6766 -------------------------------------
6768 function Enclosing_Package_Or_Subprogram (E : Entity_Id) return Entity_Id is
6769 S : Entity_Id;
6771 begin
6772 S := Scope (E);
6773 while Present (S) loop
6774 if Is_Package_Or_Generic_Package (S)
6775 or else Ekind (S) = E_Package_Body
6776 then
6777 return S;
6779 elsif Is_Subprogram_Or_Generic_Subprogram (S)
6780 or else Ekind (S) = E_Subprogram_Body
6781 then
6782 return S;
6784 else
6785 S := Scope (S);
6786 end if;
6787 end loop;
6789 return Empty;
6790 end Enclosing_Package_Or_Subprogram;
6792 --------------------------
6793 -- Enclosing_Subprogram --
6794 --------------------------
6796 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
6797 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
6799 begin
6800 if Dynamic_Scope = Standard_Standard then
6801 return Empty;
6803 elsif Dynamic_Scope = Empty then
6804 return Empty;
6806 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
6807 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
6809 elsif Ekind (Dynamic_Scope) = E_Block
6810 or else Ekind (Dynamic_Scope) = E_Return_Statement
6811 then
6812 return Enclosing_Subprogram (Dynamic_Scope);
6814 elsif Ekind (Dynamic_Scope) = E_Task_Type then
6815 return Get_Task_Body_Procedure (Dynamic_Scope);
6817 elsif Ekind (Dynamic_Scope) = E_Limited_Private_Type
6818 and then Present (Full_View (Dynamic_Scope))
6819 and then Ekind (Full_View (Dynamic_Scope)) = E_Task_Type
6820 then
6821 return Get_Task_Body_Procedure (Full_View (Dynamic_Scope));
6823 -- No body is generated if the protected operation is eliminated
6825 elsif Convention (Dynamic_Scope) = Convention_Protected
6826 and then not Is_Eliminated (Dynamic_Scope)
6827 and then Present (Protected_Body_Subprogram (Dynamic_Scope))
6828 then
6829 return Protected_Body_Subprogram (Dynamic_Scope);
6831 else
6832 return Dynamic_Scope;
6833 end if;
6834 end Enclosing_Subprogram;
6836 --------------------------
6837 -- End_Keyword_Location --
6838 --------------------------
6840 function End_Keyword_Location (N : Node_Id) return Source_Ptr is
6841 function End_Label_Loc (Nod : Node_Id) return Source_Ptr;
6842 -- Return the source location of Nod's end label according to the
6843 -- following precedence rules:
6845 -- 1) If the end label exists, return its location
6846 -- 2) If Nod exists, return its location
6847 -- 3) Return the location of N
6849 -------------------
6850 -- End_Label_Loc --
6851 -------------------
6853 function End_Label_Loc (Nod : Node_Id) return Source_Ptr is
6854 Label : Node_Id;
6856 begin
6857 if Present (Nod) then
6858 Label := End_Label (Nod);
6860 if Present (Label) then
6861 return Sloc (Label);
6862 else
6863 return Sloc (Nod);
6864 end if;
6866 else
6867 return Sloc (N);
6868 end if;
6869 end End_Label_Loc;
6871 -- Local variables
6873 Owner : Node_Id;
6875 -- Start of processing for End_Keyword_Location
6877 begin
6878 if Nkind_In (N, N_Block_Statement,
6879 N_Entry_Body,
6880 N_Package_Body,
6881 N_Subprogram_Body,
6882 N_Task_Body)
6883 then
6884 Owner := Handled_Statement_Sequence (N);
6886 elsif Nkind (N) = N_Package_Declaration then
6887 Owner := Specification (N);
6889 elsif Nkind (N) = N_Protected_Body then
6890 Owner := N;
6892 elsif Nkind_In (N, N_Protected_Type_Declaration,
6893 N_Single_Protected_Declaration)
6894 then
6895 Owner := Protected_Definition (N);
6897 elsif Nkind_In (N, N_Single_Task_Declaration,
6898 N_Task_Type_Declaration)
6899 then
6900 Owner := Task_Definition (N);
6902 -- This routine should not be called with other contexts
6904 else
6905 pragma Assert (False);
6906 null;
6907 end if;
6909 return End_Label_Loc (Owner);
6910 end End_Keyword_Location;
6912 ------------------------
6913 -- Ensure_Freeze_Node --
6914 ------------------------
6916 procedure Ensure_Freeze_Node (E : Entity_Id) is
6917 FN : Node_Id;
6918 begin
6919 if No (Freeze_Node (E)) then
6920 FN := Make_Freeze_Entity (Sloc (E));
6921 Set_Has_Delayed_Freeze (E);
6922 Set_Freeze_Node (E, FN);
6923 Set_Access_Types_To_Process (FN, No_Elist);
6924 Set_TSS_Elist (FN, No_Elist);
6925 Set_Entity (FN, E);
6926 end if;
6927 end Ensure_Freeze_Node;
6929 ----------------
6930 -- Enter_Name --
6931 ----------------
6933 procedure Enter_Name (Def_Id : Entity_Id) is
6934 C : constant Entity_Id := Current_Entity (Def_Id);
6935 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
6936 S : constant Entity_Id := Current_Scope;
6938 begin
6939 Generate_Definition (Def_Id);
6941 -- Add new name to current scope declarations. Check for duplicate
6942 -- declaration, which may or may not be a genuine error.
6944 if Present (E) then
6946 -- Case of previous entity entered because of a missing declaration
6947 -- or else a bad subtype indication. Best is to use the new entity,
6948 -- and make the previous one invisible.
6950 if Etype (E) = Any_Type then
6951 Set_Is_Immediately_Visible (E, False);
6953 -- Case of renaming declaration constructed for package instances.
6954 -- if there is an explicit declaration with the same identifier,
6955 -- the renaming is not immediately visible any longer, but remains
6956 -- visible through selected component notation.
6958 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
6959 and then not Comes_From_Source (E)
6960 then
6961 Set_Is_Immediately_Visible (E, False);
6963 -- The new entity may be the package renaming, which has the same
6964 -- same name as a generic formal which has been seen already.
6966 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
6967 and then not Comes_From_Source (Def_Id)
6968 then
6969 Set_Is_Immediately_Visible (E, False);
6971 -- For a fat pointer corresponding to a remote access to subprogram,
6972 -- we use the same identifier as the RAS type, so that the proper
6973 -- name appears in the stub. This type is only retrieved through
6974 -- the RAS type and never by visibility, and is not added to the
6975 -- visibility list (see below).
6977 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
6978 and then Ekind (Def_Id) = E_Record_Type
6979 and then Present (Corresponding_Remote_Type (Def_Id))
6980 then
6981 null;
6983 -- Case of an implicit operation or derived literal. The new entity
6984 -- hides the implicit one, which is removed from all visibility,
6985 -- i.e. the entity list of its scope, and homonym chain of its name.
6987 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
6988 or else Is_Internal (E)
6989 then
6990 declare
6991 Decl : constant Node_Id := Parent (E);
6992 Prev : Entity_Id;
6993 Prev_Vis : Entity_Id;
6995 begin
6996 -- If E is an implicit declaration, it cannot be the first
6997 -- entity in the scope.
6999 Prev := First_Entity (Current_Scope);
7000 while Present (Prev) and then Next_Entity (Prev) /= E loop
7001 Next_Entity (Prev);
7002 end loop;
7004 if No (Prev) then
7006 -- If E is not on the entity chain of the current scope,
7007 -- it is an implicit declaration in the generic formal
7008 -- part of a generic subprogram. When analyzing the body,
7009 -- the generic formals are visible but not on the entity
7010 -- chain of the subprogram. The new entity will become
7011 -- the visible one in the body.
7013 pragma Assert
7014 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
7015 null;
7017 else
7018 Set_Next_Entity (Prev, Next_Entity (E));
7020 if No (Next_Entity (Prev)) then
7021 Set_Last_Entity (Current_Scope, Prev);
7022 end if;
7024 if E = Current_Entity (E) then
7025 Prev_Vis := Empty;
7027 else
7028 Prev_Vis := Current_Entity (E);
7029 while Homonym (Prev_Vis) /= E loop
7030 Prev_Vis := Homonym (Prev_Vis);
7031 end loop;
7032 end if;
7034 if Present (Prev_Vis) then
7036 -- Skip E in the visibility chain
7038 Set_Homonym (Prev_Vis, Homonym (E));
7040 else
7041 Set_Name_Entity_Id (Chars (E), Homonym (E));
7042 end if;
7043 end if;
7044 end;
7046 -- This section of code could use a comment ???
7048 elsif Present (Etype (E))
7049 and then Is_Concurrent_Type (Etype (E))
7050 and then E = Def_Id
7051 then
7052 return;
7054 -- If the homograph is a protected component renaming, it should not
7055 -- be hiding the current entity. Such renamings are treated as weak
7056 -- declarations.
7058 elsif Is_Prival (E) then
7059 Set_Is_Immediately_Visible (E, False);
7061 -- In this case the current entity is a protected component renaming.
7062 -- Perform minimal decoration by setting the scope and return since
7063 -- the prival should not be hiding other visible entities.
7065 elsif Is_Prival (Def_Id) then
7066 Set_Scope (Def_Id, Current_Scope);
7067 return;
7069 -- Analogous to privals, the discriminal generated for an entry index
7070 -- parameter acts as a weak declaration. Perform minimal decoration
7071 -- to avoid bogus errors.
7073 elsif Is_Discriminal (Def_Id)
7074 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
7075 then
7076 Set_Scope (Def_Id, Current_Scope);
7077 return;
7079 -- In the body or private part of an instance, a type extension may
7080 -- introduce a component with the same name as that of an actual. The
7081 -- legality rule is not enforced, but the semantics of the full type
7082 -- with two components of same name are not clear at this point???
7084 elsif In_Instance_Not_Visible then
7085 null;
7087 -- When compiling a package body, some child units may have become
7088 -- visible. They cannot conflict with local entities that hide them.
7090 elsif Is_Child_Unit (E)
7091 and then In_Open_Scopes (Scope (E))
7092 and then not Is_Immediately_Visible (E)
7093 then
7094 null;
7096 -- Conversely, with front-end inlining we may compile the parent body
7097 -- first, and a child unit subsequently. The context is now the
7098 -- parent spec, and body entities are not visible.
7100 elsif Is_Child_Unit (Def_Id)
7101 and then Is_Package_Body_Entity (E)
7102 and then not In_Package_Body (Current_Scope)
7103 then
7104 null;
7106 -- Case of genuine duplicate declaration
7108 else
7109 Error_Msg_Sloc := Sloc (E);
7111 -- If the previous declaration is an incomplete type declaration
7112 -- this may be an attempt to complete it with a private type. The
7113 -- following avoids confusing cascaded errors.
7115 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
7116 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
7117 then
7118 Error_Msg_N
7119 ("incomplete type cannot be completed with a private " &
7120 "declaration", Parent (Def_Id));
7121 Set_Is_Immediately_Visible (E, False);
7122 Set_Full_View (E, Def_Id);
7124 -- An inherited component of a record conflicts with a new
7125 -- discriminant. The discriminant is inserted first in the scope,
7126 -- but the error should be posted on it, not on the component.
7128 elsif Ekind (E) = E_Discriminant
7129 and then Present (Scope (Def_Id))
7130 and then Scope (Def_Id) /= Current_Scope
7131 then
7132 Error_Msg_Sloc := Sloc (Def_Id);
7133 Error_Msg_N ("& conflicts with declaration#", E);
7134 return;
7136 -- If the name of the unit appears in its own context clause, a
7137 -- dummy package with the name has already been created, and the
7138 -- error emitted. Try to continue quietly.
7140 elsif Error_Posted (E)
7141 and then Sloc (E) = No_Location
7142 and then Nkind (Parent (E)) = N_Package_Specification
7143 and then Current_Scope = Standard_Standard
7144 then
7145 Set_Scope (Def_Id, Current_Scope);
7146 return;
7148 else
7149 Error_Msg_N ("& conflicts with declaration#", Def_Id);
7151 -- Avoid cascaded messages with duplicate components in
7152 -- derived types.
7154 if Ekind_In (E, E_Component, E_Discriminant) then
7155 return;
7156 end if;
7157 end if;
7159 if Nkind (Parent (Parent (Def_Id))) =
7160 N_Generic_Subprogram_Declaration
7161 and then Def_Id =
7162 Defining_Entity (Specification (Parent (Parent (Def_Id))))
7163 then
7164 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
7165 end if;
7167 -- If entity is in standard, then we are in trouble, because it
7168 -- means that we have a library package with a duplicated name.
7169 -- That's hard to recover from, so abort.
7171 if S = Standard_Standard then
7172 raise Unrecoverable_Error;
7174 -- Otherwise we continue with the declaration. Having two
7175 -- identical declarations should not cause us too much trouble.
7177 else
7178 null;
7179 end if;
7180 end if;
7181 end if;
7183 -- If we fall through, declaration is OK, at least OK enough to continue
7185 -- If Def_Id is a discriminant or a record component we are in the midst
7186 -- of inheriting components in a derived record definition. Preserve
7187 -- their Ekind and Etype.
7189 if Ekind_In (Def_Id, E_Discriminant, E_Component) then
7190 null;
7192 -- If a type is already set, leave it alone (happens when a type
7193 -- declaration is reanalyzed following a call to the optimizer).
7195 elsif Present (Etype (Def_Id)) then
7196 null;
7198 -- Otherwise, the kind E_Void insures that premature uses of the entity
7199 -- will be detected. Any_Type insures that no cascaded errors will occur
7201 else
7202 Set_Ekind (Def_Id, E_Void);
7203 Set_Etype (Def_Id, Any_Type);
7204 end if;
7206 -- Inherited discriminants and components in derived record types are
7207 -- immediately visible. Itypes are not.
7209 -- Unless the Itype is for a record type with a corresponding remote
7210 -- type (what is that about, it was not commented ???)
7212 if Ekind_In (Def_Id, E_Discriminant, E_Component)
7213 or else
7214 ((not Is_Record_Type (Def_Id)
7215 or else No (Corresponding_Remote_Type (Def_Id)))
7216 and then not Is_Itype (Def_Id))
7217 then
7218 Set_Is_Immediately_Visible (Def_Id);
7219 Set_Current_Entity (Def_Id);
7220 end if;
7222 Set_Homonym (Def_Id, C);
7223 Append_Entity (Def_Id, S);
7224 Set_Public_Status (Def_Id);
7226 -- Declaring a homonym is not allowed in SPARK ...
7228 if Present (C) and then Restriction_Check_Required (SPARK_05) then
7229 declare
7230 Enclosing_Subp : constant Node_Id := Enclosing_Subprogram (Def_Id);
7231 Enclosing_Pack : constant Node_Id := Enclosing_Package (Def_Id);
7232 Other_Scope : constant Node_Id := Enclosing_Dynamic_Scope (C);
7234 begin
7235 -- ... unless the new declaration is in a subprogram, and the
7236 -- visible declaration is a variable declaration or a parameter
7237 -- specification outside that subprogram.
7239 if Present (Enclosing_Subp)
7240 and then Nkind_In (Parent (C), N_Object_Declaration,
7241 N_Parameter_Specification)
7242 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Subp)
7243 then
7244 null;
7246 -- ... or the new declaration is in a package, and the visible
7247 -- declaration occurs outside that package.
7249 elsif Present (Enclosing_Pack)
7250 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Pack)
7251 then
7252 null;
7254 -- ... or the new declaration is a component declaration in a
7255 -- record type definition.
7257 elsif Nkind (Parent (Def_Id)) = N_Component_Declaration then
7258 null;
7260 -- Don't issue error for non-source entities
7262 elsif Comes_From_Source (Def_Id)
7263 and then Comes_From_Source (C)
7264 then
7265 Error_Msg_Sloc := Sloc (C);
7266 Check_SPARK_05_Restriction
7267 ("redeclaration of identifier &#", Def_Id);
7268 end if;
7269 end;
7270 end if;
7272 -- Warn if new entity hides an old one
7274 if Warn_On_Hiding and then Present (C)
7276 -- Don't warn for record components since they always have a well
7277 -- defined scope which does not confuse other uses. Note that in
7278 -- some cases, Ekind has not been set yet.
7280 and then Ekind (C) /= E_Component
7281 and then Ekind (C) /= E_Discriminant
7282 and then Nkind (Parent (C)) /= N_Component_Declaration
7283 and then Ekind (Def_Id) /= E_Component
7284 and then Ekind (Def_Id) /= E_Discriminant
7285 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
7287 -- Don't warn for one character variables. It is too common to use
7288 -- such variables as locals and will just cause too many false hits.
7290 and then Length_Of_Name (Chars (C)) /= 1
7292 -- Don't warn for non-source entities
7294 and then Comes_From_Source (C)
7295 and then Comes_From_Source (Def_Id)
7297 -- Don't warn unless entity in question is in extended main source
7299 and then In_Extended_Main_Source_Unit (Def_Id)
7301 -- Finally, the hidden entity must be either immediately visible or
7302 -- use visible (i.e. from a used package).
7304 and then
7305 (Is_Immediately_Visible (C)
7306 or else
7307 Is_Potentially_Use_Visible (C))
7308 then
7309 Error_Msg_Sloc := Sloc (C);
7310 Error_Msg_N ("declaration hides &#?h?", Def_Id);
7311 end if;
7312 end Enter_Name;
7314 ---------------
7315 -- Entity_Of --
7316 ---------------
7318 function Entity_Of (N : Node_Id) return Entity_Id is
7319 Id : Entity_Id;
7320 Ren : Node_Id;
7322 begin
7323 -- Assume that the arbitrary node does not have an entity
7325 Id := Empty;
7327 if Is_Entity_Name (N) then
7328 Id := Entity (N);
7330 -- Follow a possible chain of renamings to reach the earliest renamed
7331 -- source object.
7333 while Present (Id)
7334 and then Is_Object (Id)
7335 and then Present (Renamed_Object (Id))
7336 loop
7337 Ren := Renamed_Object (Id);
7339 -- The reference renames an abstract state or a whole object
7341 -- Obj : ...;
7342 -- Ren : ... renames Obj;
7344 if Is_Entity_Name (Ren) then
7345 Id := Entity (Ren);
7347 -- The reference renames a function result. Check the original
7348 -- node in case expansion relocates the function call.
7350 -- Ren : ... renames Func_Call;
7352 elsif Nkind (Original_Node (Ren)) = N_Function_Call then
7353 exit;
7355 -- Otherwise the reference renames something which does not yield
7356 -- an abstract state or a whole object. Treat the reference as not
7357 -- having a proper entity for SPARK legality purposes.
7359 else
7360 Id := Empty;
7361 exit;
7362 end if;
7363 end loop;
7364 end if;
7366 return Id;
7367 end Entity_Of;
7369 --------------------------
7370 -- Explain_Limited_Type --
7371 --------------------------
7373 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
7374 C : Entity_Id;
7376 begin
7377 -- For array, component type must be limited
7379 if Is_Array_Type (T) then
7380 Error_Msg_Node_2 := T;
7381 Error_Msg_NE
7382 ("\component type& of type& is limited", N, Component_Type (T));
7383 Explain_Limited_Type (Component_Type (T), N);
7385 elsif Is_Record_Type (T) then
7387 -- No need for extra messages if explicit limited record
7389 if Is_Limited_Record (Base_Type (T)) then
7390 return;
7391 end if;
7393 -- Otherwise find a limited component. Check only components that
7394 -- come from source, or inherited components that appear in the
7395 -- source of the ancestor.
7397 C := First_Component (T);
7398 while Present (C) loop
7399 if Is_Limited_Type (Etype (C))
7400 and then
7401 (Comes_From_Source (C)
7402 or else
7403 (Present (Original_Record_Component (C))
7404 and then
7405 Comes_From_Source (Original_Record_Component (C))))
7406 then
7407 Error_Msg_Node_2 := T;
7408 Error_Msg_NE ("\component& of type& has limited type", N, C);
7409 Explain_Limited_Type (Etype (C), N);
7410 return;
7411 end if;
7413 Next_Component (C);
7414 end loop;
7416 -- The type may be declared explicitly limited, even if no component
7417 -- of it is limited, in which case we fall out of the loop.
7418 return;
7419 end if;
7420 end Explain_Limited_Type;
7422 ---------------------------------------
7423 -- Expression_Of_Expression_Function --
7424 ---------------------------------------
7426 function Expression_Of_Expression_Function
7427 (Subp : Entity_Id) return Node_Id
7429 Expr_Func : Node_Id;
7431 begin
7432 pragma Assert (Is_Expression_Function_Or_Completion (Subp));
7434 if Nkind (Original_Node (Subprogram_Spec (Subp))) =
7435 N_Expression_Function
7436 then
7437 Expr_Func := Original_Node (Subprogram_Spec (Subp));
7439 elsif Nkind (Original_Node (Subprogram_Body (Subp))) =
7440 N_Expression_Function
7441 then
7442 Expr_Func := Original_Node (Subprogram_Body (Subp));
7444 else
7445 pragma Assert (False);
7446 null;
7447 end if;
7449 return Original_Node (Expression (Expr_Func));
7450 end Expression_Of_Expression_Function;
7452 -------------------------------
7453 -- Extensions_Visible_Status --
7454 -------------------------------
7456 function Extensions_Visible_Status
7457 (Id : Entity_Id) return Extensions_Visible_Mode
7459 Arg : Node_Id;
7460 Decl : Node_Id;
7461 Expr : Node_Id;
7462 Prag : Node_Id;
7463 Subp : Entity_Id;
7465 begin
7466 -- When a formal parameter is subject to Extensions_Visible, the pragma
7467 -- is stored in the contract of related subprogram.
7469 if Is_Formal (Id) then
7470 Subp := Scope (Id);
7472 elsif Is_Subprogram_Or_Generic_Subprogram (Id) then
7473 Subp := Id;
7475 -- No other construct carries this pragma
7477 else
7478 return Extensions_Visible_None;
7479 end if;
7481 Prag := Get_Pragma (Subp, Pragma_Extensions_Visible);
7483 -- In certain cases analysis may request the Extensions_Visible status
7484 -- of an expression function before the pragma has been analyzed yet.
7485 -- Inspect the declarative items after the expression function looking
7486 -- for the pragma (if any).
7488 if No (Prag) and then Is_Expression_Function (Subp) then
7489 Decl := Next (Unit_Declaration_Node (Subp));
7490 while Present (Decl) loop
7491 if Nkind (Decl) = N_Pragma
7492 and then Pragma_Name (Decl) = Name_Extensions_Visible
7493 then
7494 Prag := Decl;
7495 exit;
7497 -- A source construct ends the region where Extensions_Visible may
7498 -- appear, stop the traversal. An expanded expression function is
7499 -- no longer a source construct, but it must still be recognized.
7501 elsif Comes_From_Source (Decl)
7502 or else
7503 (Nkind_In (Decl, N_Subprogram_Body,
7504 N_Subprogram_Declaration)
7505 and then Is_Expression_Function (Defining_Entity (Decl)))
7506 then
7507 exit;
7508 end if;
7510 Next (Decl);
7511 end loop;
7512 end if;
7514 -- Extract the value from the Boolean expression (if any)
7516 if Present (Prag) then
7517 Arg := First (Pragma_Argument_Associations (Prag));
7519 if Present (Arg) then
7520 Expr := Get_Pragma_Arg (Arg);
7522 -- When the associated subprogram is an expression function, the
7523 -- argument of the pragma may not have been analyzed.
7525 if not Analyzed (Expr) then
7526 Preanalyze_And_Resolve (Expr, Standard_Boolean);
7527 end if;
7529 -- Guard against cascading errors when the argument of pragma
7530 -- Extensions_Visible is not a valid static Boolean expression.
7532 if Error_Posted (Expr) then
7533 return Extensions_Visible_None;
7535 elsif Is_True (Expr_Value (Expr)) then
7536 return Extensions_Visible_True;
7538 else
7539 return Extensions_Visible_False;
7540 end if;
7542 -- Otherwise the aspect or pragma defaults to True
7544 else
7545 return Extensions_Visible_True;
7546 end if;
7548 -- Otherwise aspect or pragma Extensions_Visible is not inherited or
7549 -- directly specified. In SPARK code, its value defaults to "False".
7551 elsif SPARK_Mode = On then
7552 return Extensions_Visible_False;
7554 -- In non-SPARK code, aspect or pragma Extensions_Visible defaults to
7555 -- "True".
7557 else
7558 return Extensions_Visible_True;
7559 end if;
7560 end Extensions_Visible_Status;
7562 -----------------
7563 -- Find_Actual --
7564 -----------------
7566 procedure Find_Actual
7567 (N : Node_Id;
7568 Formal : out Entity_Id;
7569 Call : out Node_Id)
7571 Context : constant Node_Id := Parent (N);
7572 Actual : Node_Id;
7573 Call_Nam : Node_Id;
7575 begin
7576 if Nkind_In (Context, N_Indexed_Component, N_Selected_Component)
7577 and then N = Prefix (Context)
7578 then
7579 Find_Actual (Context, Formal, Call);
7580 return;
7582 elsif Nkind (Context) = N_Parameter_Association
7583 and then N = Explicit_Actual_Parameter (Context)
7584 then
7585 Call := Parent (Context);
7587 elsif Nkind_In (Context, N_Entry_Call_Statement,
7588 N_Function_Call,
7589 N_Procedure_Call_Statement)
7590 then
7591 Call := Context;
7593 else
7594 Formal := Empty;
7595 Call := Empty;
7596 return;
7597 end if;
7599 -- If we have a call to a subprogram look for the parameter. Note that
7600 -- we exclude overloaded calls, since we don't know enough to be sure
7601 -- of giving the right answer in this case.
7603 if Nkind_In (Call, N_Entry_Call_Statement,
7604 N_Function_Call,
7605 N_Procedure_Call_Statement)
7606 then
7607 Call_Nam := Name (Call);
7609 -- A call to a protected or task entry appears as a selected
7610 -- component rather than an expanded name.
7612 if Nkind (Call_Nam) = N_Selected_Component then
7613 Call_Nam := Selector_Name (Call_Nam);
7614 end if;
7616 if Is_Entity_Name (Call_Nam)
7617 and then Present (Entity (Call_Nam))
7618 and then Is_Overloadable (Entity (Call_Nam))
7619 and then not Is_Overloaded (Call_Nam)
7620 then
7621 -- If node is name in call it is not an actual
7623 if N = Call_Nam then
7624 Formal := Empty;
7625 Call := Empty;
7626 return;
7627 end if;
7629 -- Fall here if we are definitely a parameter
7631 Actual := First_Actual (Call);
7632 Formal := First_Formal (Entity (Call_Nam));
7633 while Present (Formal) and then Present (Actual) loop
7634 if Actual = N then
7635 return;
7637 -- An actual that is the prefix in a prefixed call may have
7638 -- been rewritten in the call, after the deferred reference
7639 -- was collected. Check if sloc and kinds and names match.
7641 elsif Sloc (Actual) = Sloc (N)
7642 and then Nkind (Actual) = N_Identifier
7643 and then Nkind (Actual) = Nkind (N)
7644 and then Chars (Actual) = Chars (N)
7645 then
7646 return;
7648 else
7649 Actual := Next_Actual (Actual);
7650 Formal := Next_Formal (Formal);
7651 end if;
7652 end loop;
7653 end if;
7654 end if;
7656 -- Fall through here if we did not find matching actual
7658 Formal := Empty;
7659 Call := Empty;
7660 end Find_Actual;
7662 ---------------------------
7663 -- Find_Body_Discriminal --
7664 ---------------------------
7666 function Find_Body_Discriminal
7667 (Spec_Discriminant : Entity_Id) return Entity_Id
7669 Tsk : Entity_Id;
7670 Disc : Entity_Id;
7672 begin
7673 -- If expansion is suppressed, then the scope can be the concurrent type
7674 -- itself rather than a corresponding concurrent record type.
7676 if Is_Concurrent_Type (Scope (Spec_Discriminant)) then
7677 Tsk := Scope (Spec_Discriminant);
7679 else
7680 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
7682 Tsk := Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
7683 end if;
7685 -- Find discriminant of original concurrent type, and use its current
7686 -- discriminal, which is the renaming within the task/protected body.
7688 Disc := First_Discriminant (Tsk);
7689 while Present (Disc) loop
7690 if Chars (Disc) = Chars (Spec_Discriminant) then
7691 return Discriminal (Disc);
7692 end if;
7694 Next_Discriminant (Disc);
7695 end loop;
7697 -- That loop should always succeed in finding a matching entry and
7698 -- returning. Fatal error if not.
7700 raise Program_Error;
7701 end Find_Body_Discriminal;
7703 -------------------------------------
7704 -- Find_Corresponding_Discriminant --
7705 -------------------------------------
7707 function Find_Corresponding_Discriminant
7708 (Id : Node_Id;
7709 Typ : Entity_Id) return Entity_Id
7711 Par_Disc : Entity_Id;
7712 Old_Disc : Entity_Id;
7713 New_Disc : Entity_Id;
7715 begin
7716 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
7718 -- The original type may currently be private, and the discriminant
7719 -- only appear on its full view.
7721 if Is_Private_Type (Scope (Par_Disc))
7722 and then not Has_Discriminants (Scope (Par_Disc))
7723 and then Present (Full_View (Scope (Par_Disc)))
7724 then
7725 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
7726 else
7727 Old_Disc := First_Discriminant (Scope (Par_Disc));
7728 end if;
7730 if Is_Class_Wide_Type (Typ) then
7731 New_Disc := First_Discriminant (Root_Type (Typ));
7732 else
7733 New_Disc := First_Discriminant (Typ);
7734 end if;
7736 while Present (Old_Disc) and then Present (New_Disc) loop
7737 if Old_Disc = Par_Disc then
7738 return New_Disc;
7739 end if;
7741 Next_Discriminant (Old_Disc);
7742 Next_Discriminant (New_Disc);
7743 end loop;
7745 -- Should always find it
7747 raise Program_Error;
7748 end Find_Corresponding_Discriminant;
7750 -------------------
7751 -- Find_DIC_Type --
7752 -------------------
7754 function Find_DIC_Type (Typ : Entity_Id) return Entity_Id is
7755 Curr_Typ : Entity_Id;
7756 -- The current type being examined in the parent hierarchy traversal
7758 DIC_Typ : Entity_Id;
7759 -- The type which carries the DIC pragma. This variable denotes the
7760 -- partial view when private types are involved.
7762 Par_Typ : Entity_Id;
7763 -- The parent type of the current type. This variable denotes the full
7764 -- view when private types are involved.
7766 begin
7767 -- The input type defines its own DIC pragma, therefore it is the owner
7769 if Has_Own_DIC (Typ) then
7770 DIC_Typ := Typ;
7772 -- Otherwise the DIC pragma is inherited from a parent type
7774 else
7775 pragma Assert (Has_Inherited_DIC (Typ));
7777 -- Climb the parent chain
7779 Curr_Typ := Typ;
7780 loop
7781 -- Inspect the parent type. Do not consider subtypes as they
7782 -- inherit the DIC attributes from their base types.
7784 DIC_Typ := Base_Type (Etype (Curr_Typ));
7786 -- Look at the full view of a private type because the type may
7787 -- have a hidden parent introduced in the full view.
7789 Par_Typ := DIC_Typ;
7791 if Is_Private_Type (Par_Typ)
7792 and then Present (Full_View (Par_Typ))
7793 then
7794 Par_Typ := Full_View (Par_Typ);
7795 end if;
7797 -- Stop the climb once the nearest parent type which defines a DIC
7798 -- pragma of its own is encountered or when the root of the parent
7799 -- chain is reached.
7801 exit when Has_Own_DIC (DIC_Typ) or else Curr_Typ = Par_Typ;
7803 Curr_Typ := Par_Typ;
7804 end loop;
7805 end if;
7807 return DIC_Typ;
7808 end Find_DIC_Type;
7810 ----------------------------------
7811 -- Find_Enclosing_Iterator_Loop --
7812 ----------------------------------
7814 function Find_Enclosing_Iterator_Loop (Id : Entity_Id) return Entity_Id is
7815 Constr : Node_Id;
7816 S : Entity_Id;
7818 begin
7819 -- Traverse the scope chain looking for an iterator loop. Such loops are
7820 -- usually transformed into blocks, hence the use of Original_Node.
7822 S := Id;
7823 while Present (S) and then S /= Standard_Standard loop
7824 if Ekind (S) = E_Loop
7825 and then Nkind (Parent (S)) = N_Implicit_Label_Declaration
7826 then
7827 Constr := Original_Node (Label_Construct (Parent (S)));
7829 if Nkind (Constr) = N_Loop_Statement
7830 and then Present (Iteration_Scheme (Constr))
7831 and then Nkind (Iterator_Specification
7832 (Iteration_Scheme (Constr))) =
7833 N_Iterator_Specification
7834 then
7835 return S;
7836 end if;
7837 end if;
7839 S := Scope (S);
7840 end loop;
7842 return Empty;
7843 end Find_Enclosing_Iterator_Loop;
7845 --------------------------
7846 -- Find_Enclosing_Scope --
7847 --------------------------
7849 function Find_Enclosing_Scope (N : Node_Id) return Entity_Id is
7850 Par : Node_Id;
7851 Spec_Id : Entity_Id;
7853 begin
7854 -- Examine the parent chain looking for a construct which defines a
7855 -- scope.
7857 Par := Parent (N);
7858 while Present (Par) loop
7859 case Nkind (Par) is
7861 -- The construct denotes a declaration, the proper scope is its
7862 -- entity.
7864 when N_Entry_Declaration
7865 | N_Expression_Function
7866 | N_Full_Type_Declaration
7867 | N_Generic_Package_Declaration
7868 | N_Generic_Subprogram_Declaration
7869 | N_Package_Declaration
7870 | N_Private_Extension_Declaration
7871 | N_Protected_Type_Declaration
7872 | N_Single_Protected_Declaration
7873 | N_Single_Task_Declaration
7874 | N_Subprogram_Declaration
7875 | N_Task_Type_Declaration
7877 return Defining_Entity (Par);
7879 -- The construct denotes a body, the proper scope is the entity of
7880 -- the corresponding spec.
7882 when N_Entry_Body
7883 | N_Package_Body
7884 | N_Protected_Body
7885 | N_Subprogram_Body
7886 | N_Task_Body
7888 Spec_Id := Corresponding_Spec (Par);
7890 -- The defining entity of a stand-alone subprogram body defines
7891 -- a scope.
7893 if Nkind (Par) = N_Subprogram_Body and then No (Spec_Id) then
7894 return Defining_Entity (Par);
7896 -- Otherwise there should be corresponding spec which defines a
7897 -- scope.
7899 else
7900 pragma Assert (Present (Spec_Id));
7902 return Spec_Id;
7903 end if;
7905 -- Special cases
7907 -- Blocks carry either a source or an internally-generated scope,
7908 -- unless the block is a byproduct of exception handling.
7910 when N_Block_Statement =>
7911 if not Exception_Junk (Par) then
7912 return Entity (Identifier (Par));
7913 end if;
7915 -- Loops carry an internally-generated scope
7917 when N_Loop_Statement =>
7918 return Entity (Identifier (Par));
7920 -- Extended return statements carry an internally-generated scope
7922 when N_Extended_Return_Statement =>
7923 return Return_Statement_Entity (Par);
7925 -- A traversal from a subunit continues via the corresponding stub
7927 when N_Subunit =>
7928 Par := Corresponding_Stub (Par);
7930 when others =>
7931 null;
7932 end case;
7934 Par := Parent (Par);
7935 end loop;
7937 return Standard_Standard;
7938 end Find_Enclosing_Scope;
7940 ------------------------------------
7941 -- Find_Loop_In_Conditional_Block --
7942 ------------------------------------
7944 function Find_Loop_In_Conditional_Block (N : Node_Id) return Node_Id is
7945 Stmt : Node_Id;
7947 begin
7948 Stmt := N;
7950 if Nkind (Stmt) = N_If_Statement then
7951 Stmt := First (Then_Statements (Stmt));
7952 end if;
7954 pragma Assert (Nkind (Stmt) = N_Block_Statement);
7956 -- Inspect the statements of the conditional block. In general the loop
7957 -- should be the first statement in the statement sequence of the block,
7958 -- but the finalization machinery may have introduced extra object
7959 -- declarations.
7961 Stmt := First (Statements (Handled_Statement_Sequence (Stmt)));
7962 while Present (Stmt) loop
7963 if Nkind (Stmt) = N_Loop_Statement then
7964 return Stmt;
7965 end if;
7967 Next (Stmt);
7968 end loop;
7970 -- The expansion of attribute 'Loop_Entry produced a malformed block
7972 raise Program_Error;
7973 end Find_Loop_In_Conditional_Block;
7975 --------------------------
7976 -- Find_Overlaid_Entity --
7977 --------------------------
7979 procedure Find_Overlaid_Entity
7980 (N : Node_Id;
7981 Ent : out Entity_Id;
7982 Off : out Boolean)
7984 Expr : Node_Id;
7986 begin
7987 -- We are looking for one of the two following forms:
7989 -- for X'Address use Y'Address
7991 -- or
7993 -- Const : constant Address := expr;
7994 -- ...
7995 -- for X'Address use Const;
7997 -- In the second case, the expr is either Y'Address, or recursively a
7998 -- constant that eventually references Y'Address.
8000 Ent := Empty;
8001 Off := False;
8003 if Nkind (N) = N_Attribute_Definition_Clause
8004 and then Chars (N) = Name_Address
8005 then
8006 Expr := Expression (N);
8008 -- This loop checks the form of the expression for Y'Address,
8009 -- using recursion to deal with intermediate constants.
8011 loop
8012 -- Check for Y'Address
8014 if Nkind (Expr) = N_Attribute_Reference
8015 and then Attribute_Name (Expr) = Name_Address
8016 then
8017 Expr := Prefix (Expr);
8018 exit;
8020 -- Check for Const where Const is a constant entity
8022 elsif Is_Entity_Name (Expr)
8023 and then Ekind (Entity (Expr)) = E_Constant
8024 then
8025 Expr := Constant_Value (Entity (Expr));
8027 -- Anything else does not need checking
8029 else
8030 return;
8031 end if;
8032 end loop;
8034 -- This loop checks the form of the prefix for an entity, using
8035 -- recursion to deal with intermediate components.
8037 loop
8038 -- Check for Y where Y is an entity
8040 if Is_Entity_Name (Expr) then
8041 Ent := Entity (Expr);
8042 return;
8044 -- Check for components
8046 elsif
8047 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component)
8048 then
8049 Expr := Prefix (Expr);
8050 Off := True;
8052 -- Anything else does not need checking
8054 else
8055 return;
8056 end if;
8057 end loop;
8058 end if;
8059 end Find_Overlaid_Entity;
8061 -------------------------
8062 -- Find_Parameter_Type --
8063 -------------------------
8065 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
8066 begin
8067 if Nkind (Param) /= N_Parameter_Specification then
8068 return Empty;
8070 -- For an access parameter, obtain the type from the formal entity
8071 -- itself, because access to subprogram nodes do not carry a type.
8072 -- Shouldn't we always use the formal entity ???
8074 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
8075 return Etype (Defining_Identifier (Param));
8077 else
8078 return Etype (Parameter_Type (Param));
8079 end if;
8080 end Find_Parameter_Type;
8082 -----------------------------------
8083 -- Find_Placement_In_State_Space --
8084 -----------------------------------
8086 procedure Find_Placement_In_State_Space
8087 (Item_Id : Entity_Id;
8088 Placement : out State_Space_Kind;
8089 Pack_Id : out Entity_Id)
8091 Context : Entity_Id;
8093 begin
8094 -- Assume that the item does not appear in the state space of a package
8096 Placement := Not_In_Package;
8097 Pack_Id := Empty;
8099 -- Climb the scope stack and examine the enclosing context
8101 Context := Scope (Item_Id);
8102 while Present (Context) and then Context /= Standard_Standard loop
8103 if Is_Package_Or_Generic_Package (Context) then
8104 Pack_Id := Context;
8106 -- A package body is a cut off point for the traversal as the item
8107 -- cannot be visible to the outside from this point on. Note that
8108 -- this test must be done first as a body is also classified as a
8109 -- private part.
8111 if In_Package_Body (Context) then
8112 Placement := Body_State_Space;
8113 return;
8115 -- The private part of a package is a cut off point for the
8116 -- traversal as the item cannot be visible to the outside from
8117 -- this point on.
8119 elsif In_Private_Part (Context) then
8120 Placement := Private_State_Space;
8121 return;
8123 -- When the item appears in the visible state space of a package,
8124 -- continue to climb the scope stack as this may not be the final
8125 -- state space.
8127 else
8128 Placement := Visible_State_Space;
8130 -- The visible state space of a child unit acts as the proper
8131 -- placement of an item.
8133 if Is_Child_Unit (Context) then
8134 return;
8135 end if;
8136 end if;
8138 -- The item or its enclosing package appear in a construct that has
8139 -- no state space.
8141 else
8142 Placement := Not_In_Package;
8143 return;
8144 end if;
8146 Context := Scope (Context);
8147 end loop;
8148 end Find_Placement_In_State_Space;
8150 ------------------------
8151 -- Find_Specific_Type --
8152 ------------------------
8154 function Find_Specific_Type (CW : Entity_Id) return Entity_Id is
8155 Typ : Entity_Id := Root_Type (CW);
8157 begin
8158 if Ekind (Typ) = E_Incomplete_Type then
8159 if From_Limited_With (Typ) then
8160 Typ := Non_Limited_View (Typ);
8161 else
8162 Typ := Full_View (Typ);
8163 end if;
8164 end if;
8166 if Is_Private_Type (Typ)
8167 and then not Is_Tagged_Type (Typ)
8168 and then Present (Full_View (Typ))
8169 then
8170 return Full_View (Typ);
8171 else
8172 return Typ;
8173 end if;
8174 end Find_Specific_Type;
8176 -----------------------------
8177 -- Find_Static_Alternative --
8178 -----------------------------
8180 function Find_Static_Alternative (N : Node_Id) return Node_Id is
8181 Expr : constant Node_Id := Expression (N);
8182 Val : constant Uint := Expr_Value (Expr);
8183 Alt : Node_Id;
8184 Choice : Node_Id;
8186 begin
8187 Alt := First (Alternatives (N));
8189 Search : loop
8190 if Nkind (Alt) /= N_Pragma then
8191 Choice := First (Discrete_Choices (Alt));
8192 while Present (Choice) loop
8194 -- Others choice, always matches
8196 if Nkind (Choice) = N_Others_Choice then
8197 exit Search;
8199 -- Range, check if value is in the range
8201 elsif Nkind (Choice) = N_Range then
8202 exit Search when
8203 Val >= Expr_Value (Low_Bound (Choice))
8204 and then
8205 Val <= Expr_Value (High_Bound (Choice));
8207 -- Choice is a subtype name. Note that we know it must
8208 -- be a static subtype, since otherwise it would have
8209 -- been diagnosed as illegal.
8211 elsif Is_Entity_Name (Choice)
8212 and then Is_Type (Entity (Choice))
8213 then
8214 exit Search when Is_In_Range (Expr, Etype (Choice),
8215 Assume_Valid => False);
8217 -- Choice is a subtype indication
8219 elsif Nkind (Choice) = N_Subtype_Indication then
8220 declare
8221 C : constant Node_Id := Constraint (Choice);
8222 R : constant Node_Id := Range_Expression (C);
8224 begin
8225 exit Search when
8226 Val >= Expr_Value (Low_Bound (R))
8227 and then
8228 Val <= Expr_Value (High_Bound (R));
8229 end;
8231 -- Choice is a simple expression
8233 else
8234 exit Search when Val = Expr_Value (Choice);
8235 end if;
8237 Next (Choice);
8238 end loop;
8239 end if;
8241 Next (Alt);
8242 pragma Assert (Present (Alt));
8243 end loop Search;
8245 -- The above loop *must* terminate by finding a match, since we know the
8246 -- case statement is valid, and the value of the expression is known at
8247 -- compile time. When we fall out of the loop, Alt points to the
8248 -- alternative that we know will be selected at run time.
8250 return Alt;
8251 end Find_Static_Alternative;
8253 ------------------
8254 -- First_Actual --
8255 ------------------
8257 function First_Actual (Node : Node_Id) return Node_Id is
8258 N : Node_Id;
8260 begin
8261 if No (Parameter_Associations (Node)) then
8262 return Empty;
8263 end if;
8265 N := First (Parameter_Associations (Node));
8267 if Nkind (N) = N_Parameter_Association then
8268 return First_Named_Actual (Node);
8269 else
8270 return N;
8271 end if;
8272 end First_Actual;
8274 ------------------
8275 -- First_Global --
8276 ------------------
8278 function First_Global
8279 (Subp : Entity_Id;
8280 Global_Mode : Name_Id;
8281 Refined : Boolean := False) return Node_Id
8283 function First_From_Global_List
8284 (List : Node_Id;
8285 Global_Mode : Name_Id := Name_Input) return Entity_Id;
8286 -- Get the first item with suitable mode from List
8288 ----------------------------
8289 -- First_From_Global_List --
8290 ----------------------------
8292 function First_From_Global_List
8293 (List : Node_Id;
8294 Global_Mode : Name_Id := Name_Input) return Entity_Id
8296 Assoc : Node_Id;
8298 begin
8299 -- Empty list (no global items)
8301 if Nkind (List) = N_Null then
8302 return Empty;
8304 -- Single global item declaration (only input items)
8306 elsif Nkind_In (List, N_Expanded_Name,
8307 N_Identifier,
8308 N_Selected_Component)
8309 then
8310 if Global_Mode = Name_Input then
8311 return List;
8312 else
8313 return Empty;
8314 end if;
8316 -- Simple global list (only input items) or moded global list
8317 -- declaration.
8319 elsif Nkind (List) = N_Aggregate then
8320 if Present (Expressions (List)) then
8321 if Global_Mode = Name_Input then
8322 return First (Expressions (List));
8323 else
8324 return Empty;
8325 end if;
8327 else
8328 Assoc := First (Component_Associations (List));
8329 while Present (Assoc) loop
8331 -- When we find the desired mode in an association, call
8332 -- recursively First_From_Global_List as if the mode was
8333 -- Name_Input, in order to reuse the existing machinery
8334 -- for the other cases.
8336 if Chars (First (Choices (Assoc))) = Global_Mode then
8337 return First_From_Global_List (Expression (Assoc));
8338 end if;
8340 Next (Assoc);
8341 end loop;
8343 return Empty;
8344 end if;
8346 -- To accommodate partial decoration of disabled SPARK features,
8347 -- this routine may be called with illegal input. If this is the
8348 -- case, do not raise Program_Error.
8350 else
8351 return Empty;
8352 end if;
8353 end First_From_Global_List;
8355 -- Local variables
8357 Global : Node_Id := Empty;
8358 Body_Id : Entity_Id;
8360 begin
8361 pragma Assert (Global_Mode = Name_Input
8362 or else Global_Mode = Name_Output
8363 or else Global_Mode = Name_In_Out
8364 or else Global_Mode = Name_Proof_In);
8366 -- Retrieve the suitable pragma Global or Refined_Global. In the second
8367 -- case, it can only be located on the body entity.
8369 if Refined then
8370 Body_Id := Subprogram_Body_Entity (Subp);
8371 if Present (Body_Id) then
8372 Global := Get_Pragma (Body_Id, Pragma_Refined_Global);
8373 end if;
8374 else
8375 Global := Get_Pragma (Subp, Pragma_Global);
8376 end if;
8378 -- No corresponding global if pragma is not present
8380 if No (Global) then
8381 return Empty;
8383 -- Otherwise retrieve the corresponding list of items depending on the
8384 -- Global_Mode.
8386 else
8387 return First_From_Global_List
8388 (Expression (Get_Argument (Global, Subp)), Global_Mode);
8389 end if;
8390 end First_Global;
8392 -------------
8393 -- Fix_Msg --
8394 -------------
8396 function Fix_Msg (Id : Entity_Id; Msg : String) return String is
8397 Is_Task : constant Boolean :=
8398 Ekind_In (Id, E_Task_Body, E_Task_Type)
8399 or else Is_Single_Task_Object (Id);
8400 Msg_Last : constant Natural := Msg'Last;
8401 Msg_Index : Natural;
8402 Res : String (Msg'Range) := (others => ' ');
8403 Res_Index : Natural;
8405 begin
8406 -- Copy all characters from the input message Msg to result Res with
8407 -- suitable replacements.
8409 Msg_Index := Msg'First;
8410 Res_Index := Res'First;
8411 while Msg_Index <= Msg_Last loop
8413 -- Replace "subprogram" with a different word
8415 if Msg_Index <= Msg_Last - 10
8416 and then Msg (Msg_Index .. Msg_Index + 9) = "subprogram"
8417 then
8418 if Ekind_In (Id, E_Entry, E_Entry_Family) then
8419 Res (Res_Index .. Res_Index + 4) := "entry";
8420 Res_Index := Res_Index + 5;
8422 elsif Is_Task then
8423 Res (Res_Index .. Res_Index + 8) := "task type";
8424 Res_Index := Res_Index + 9;
8426 else
8427 Res (Res_Index .. Res_Index + 9) := "subprogram";
8428 Res_Index := Res_Index + 10;
8429 end if;
8431 Msg_Index := Msg_Index + 10;
8433 -- Replace "protected" with a different word
8435 elsif Msg_Index <= Msg_Last - 9
8436 and then Msg (Msg_Index .. Msg_Index + 8) = "protected"
8437 and then Is_Task
8438 then
8439 Res (Res_Index .. Res_Index + 3) := "task";
8440 Res_Index := Res_Index + 4;
8441 Msg_Index := Msg_Index + 9;
8443 -- Otherwise copy the character
8445 else
8446 Res (Res_Index) := Msg (Msg_Index);
8447 Msg_Index := Msg_Index + 1;
8448 Res_Index := Res_Index + 1;
8449 end if;
8450 end loop;
8452 return Res (Res'First .. Res_Index - 1);
8453 end Fix_Msg;
8455 -------------------------
8456 -- From_Nested_Package --
8457 -------------------------
8459 function From_Nested_Package (T : Entity_Id) return Boolean is
8460 Pack : constant Entity_Id := Scope (T);
8462 begin
8463 return
8464 Ekind (Pack) = E_Package
8465 and then not Is_Frozen (Pack)
8466 and then not Scope_Within_Or_Same (Current_Scope, Pack)
8467 and then In_Open_Scopes (Scope (Pack));
8468 end From_Nested_Package;
8470 -----------------------
8471 -- Gather_Components --
8472 -----------------------
8474 procedure Gather_Components
8475 (Typ : Entity_Id;
8476 Comp_List : Node_Id;
8477 Governed_By : List_Id;
8478 Into : Elist_Id;
8479 Report_Errors : out Boolean)
8481 Assoc : Node_Id;
8482 Variant : Node_Id;
8483 Discrete_Choice : Node_Id;
8484 Comp_Item : Node_Id;
8486 Discrim : Entity_Id;
8487 Discrim_Name : Node_Id;
8488 Discrim_Value : Node_Id;
8490 begin
8491 Report_Errors := False;
8493 if No (Comp_List) or else Null_Present (Comp_List) then
8494 return;
8496 elsif Present (Component_Items (Comp_List)) then
8497 Comp_Item := First (Component_Items (Comp_List));
8499 else
8500 Comp_Item := Empty;
8501 end if;
8503 while Present (Comp_Item) loop
8505 -- Skip the tag of a tagged record, the interface tags, as well
8506 -- as all items that are not user components (anonymous types,
8507 -- rep clauses, Parent field, controller field).
8509 if Nkind (Comp_Item) = N_Component_Declaration then
8510 declare
8511 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
8512 begin
8513 if not Is_Tag (Comp) and then Chars (Comp) /= Name_uParent then
8514 Append_Elmt (Comp, Into);
8515 end if;
8516 end;
8517 end if;
8519 Next (Comp_Item);
8520 end loop;
8522 if No (Variant_Part (Comp_List)) then
8523 return;
8524 else
8525 Discrim_Name := Name (Variant_Part (Comp_List));
8526 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
8527 end if;
8529 -- Look for the discriminant that governs this variant part.
8530 -- The discriminant *must* be in the Governed_By List
8532 Assoc := First (Governed_By);
8533 Find_Constraint : loop
8534 Discrim := First (Choices (Assoc));
8535 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
8536 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
8537 and then
8538 Chars (Corresponding_Discriminant (Entity (Discrim))) =
8539 Chars (Discrim_Name))
8540 or else Chars (Original_Record_Component (Entity (Discrim)))
8541 = Chars (Discrim_Name);
8543 if No (Next (Assoc)) then
8544 if not Is_Constrained (Typ)
8545 and then Is_Derived_Type (Typ)
8546 and then Present (Stored_Constraint (Typ))
8547 then
8548 -- If the type is a tagged type with inherited discriminants,
8549 -- use the stored constraint on the parent in order to find
8550 -- the values of discriminants that are otherwise hidden by an
8551 -- explicit constraint. Renamed discriminants are handled in
8552 -- the code above.
8554 -- If several parent discriminants are renamed by a single
8555 -- discriminant of the derived type, the call to obtain the
8556 -- Corresponding_Discriminant field only retrieves the last
8557 -- of them. We recover the constraint on the others from the
8558 -- Stored_Constraint as well.
8560 declare
8561 D : Entity_Id;
8562 C : Elmt_Id;
8564 begin
8565 D := First_Discriminant (Etype (Typ));
8566 C := First_Elmt (Stored_Constraint (Typ));
8567 while Present (D) and then Present (C) loop
8568 if Chars (Discrim_Name) = Chars (D) then
8569 if Is_Entity_Name (Node (C))
8570 and then Entity (Node (C)) = Entity (Discrim)
8571 then
8572 -- D is renamed by Discrim, whose value is given in
8573 -- Assoc.
8575 null;
8577 else
8578 Assoc :=
8579 Make_Component_Association (Sloc (Typ),
8580 New_List
8581 (New_Occurrence_Of (D, Sloc (Typ))),
8582 Duplicate_Subexpr_No_Checks (Node (C)));
8583 end if;
8584 exit Find_Constraint;
8585 end if;
8587 Next_Discriminant (D);
8588 Next_Elmt (C);
8589 end loop;
8590 end;
8591 end if;
8592 end if;
8594 if No (Next (Assoc)) then
8595 Error_Msg_NE (" missing value for discriminant&",
8596 First (Governed_By), Discrim_Name);
8597 Report_Errors := True;
8598 return;
8599 end if;
8601 Next (Assoc);
8602 end loop Find_Constraint;
8604 Discrim_Value := Expression (Assoc);
8606 if not Is_OK_Static_Expression (Discrim_Value) then
8608 -- If the variant part is governed by a discriminant of the type
8609 -- this is an error. If the variant part and the discriminant are
8610 -- inherited from an ancestor this is legal (AI05-120) unless the
8611 -- components are being gathered for an aggregate, in which case
8612 -- the caller must check Report_Errors.
8614 if Scope (Original_Record_Component
8615 ((Entity (First (Choices (Assoc)))))) = Typ
8616 then
8617 Error_Msg_FE
8618 ("value for discriminant & must be static!",
8619 Discrim_Value, Discrim);
8620 Why_Not_Static (Discrim_Value);
8621 end if;
8623 Report_Errors := True;
8624 return;
8625 end if;
8627 Search_For_Discriminant_Value : declare
8628 Low : Node_Id;
8629 High : Node_Id;
8631 UI_High : Uint;
8632 UI_Low : Uint;
8633 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
8635 begin
8636 Find_Discrete_Value : while Present (Variant) loop
8637 Discrete_Choice := First (Discrete_Choices (Variant));
8638 while Present (Discrete_Choice) loop
8639 exit Find_Discrete_Value when
8640 Nkind (Discrete_Choice) = N_Others_Choice;
8642 Get_Index_Bounds (Discrete_Choice, Low, High);
8644 UI_Low := Expr_Value (Low);
8645 UI_High := Expr_Value (High);
8647 exit Find_Discrete_Value when
8648 UI_Low <= UI_Discrim_Value
8649 and then
8650 UI_High >= UI_Discrim_Value;
8652 Next (Discrete_Choice);
8653 end loop;
8655 Next_Non_Pragma (Variant);
8656 end loop Find_Discrete_Value;
8657 end Search_For_Discriminant_Value;
8659 -- The case statement must include a variant that corresponds to the
8660 -- value of the discriminant, unless the discriminant type has a
8661 -- static predicate. In that case the absence of an others_choice that
8662 -- would cover this value becomes a run-time error (3.8,1 (21.1/2)).
8664 if No (Variant)
8665 and then not Has_Static_Predicate (Etype (Discrim_Name))
8666 then
8667 Error_Msg_NE
8668 ("value of discriminant & is out of range", Discrim_Value, Discrim);
8669 Report_Errors := True;
8670 return;
8671 end if;
8673 -- If we have found the corresponding choice, recursively add its
8674 -- components to the Into list. The nested components are part of
8675 -- the same record type.
8677 if Present (Variant) then
8678 Gather_Components
8679 (Typ, Component_List (Variant), Governed_By, Into, Report_Errors);
8680 end if;
8681 end Gather_Components;
8683 ------------------------
8684 -- Get_Actual_Subtype --
8685 ------------------------
8687 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
8688 Typ : constant Entity_Id := Etype (N);
8689 Utyp : Entity_Id := Underlying_Type (Typ);
8690 Decl : Node_Id;
8691 Atyp : Entity_Id;
8693 begin
8694 if No (Utyp) then
8695 Utyp := Typ;
8696 end if;
8698 -- If what we have is an identifier that references a subprogram
8699 -- formal, or a variable or constant object, then we get the actual
8700 -- subtype from the referenced entity if one has been built.
8702 if Nkind (N) = N_Identifier
8703 and then
8704 (Is_Formal (Entity (N))
8705 or else Ekind (Entity (N)) = E_Constant
8706 or else Ekind (Entity (N)) = E_Variable)
8707 and then Present (Actual_Subtype (Entity (N)))
8708 then
8709 return Actual_Subtype (Entity (N));
8711 -- Actual subtype of unchecked union is always itself. We never need
8712 -- the "real" actual subtype. If we did, we couldn't get it anyway
8713 -- because the discriminant is not available. The restrictions on
8714 -- Unchecked_Union are designed to make sure that this is OK.
8716 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
8717 return Typ;
8719 -- Here for the unconstrained case, we must find actual subtype
8720 -- No actual subtype is available, so we must build it on the fly.
8722 -- Checking the type, not the underlying type, for constrainedness
8723 -- seems to be necessary. Maybe all the tests should be on the type???
8725 elsif (not Is_Constrained (Typ))
8726 and then (Is_Array_Type (Utyp)
8727 or else (Is_Record_Type (Utyp)
8728 and then Has_Discriminants (Utyp)))
8729 and then not Has_Unknown_Discriminants (Utyp)
8730 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
8731 then
8732 -- Nothing to do if in spec expression (why not???)
8734 if In_Spec_Expression then
8735 return Typ;
8737 elsif Is_Private_Type (Typ) and then not Has_Discriminants (Typ) then
8739 -- If the type has no discriminants, there is no subtype to
8740 -- build, even if the underlying type is discriminated.
8742 return Typ;
8744 -- Else build the actual subtype
8746 else
8747 Decl := Build_Actual_Subtype (Typ, N);
8748 Atyp := Defining_Identifier (Decl);
8750 -- If Build_Actual_Subtype generated a new declaration then use it
8752 if Atyp /= Typ then
8754 -- The actual subtype is an Itype, so analyze the declaration,
8755 -- but do not attach it to the tree, to get the type defined.
8757 Set_Parent (Decl, N);
8758 Set_Is_Itype (Atyp);
8759 Analyze (Decl, Suppress => All_Checks);
8760 Set_Associated_Node_For_Itype (Atyp, N);
8761 Set_Has_Delayed_Freeze (Atyp, False);
8763 -- We need to freeze the actual subtype immediately. This is
8764 -- needed, because otherwise this Itype will not get frozen
8765 -- at all, and it is always safe to freeze on creation because
8766 -- any associated types must be frozen at this point.
8768 Freeze_Itype (Atyp, N);
8769 return Atyp;
8771 -- Otherwise we did not build a declaration, so return original
8773 else
8774 return Typ;
8775 end if;
8776 end if;
8778 -- For all remaining cases, the actual subtype is the same as
8779 -- the nominal type.
8781 else
8782 return Typ;
8783 end if;
8784 end Get_Actual_Subtype;
8786 -------------------------------------
8787 -- Get_Actual_Subtype_If_Available --
8788 -------------------------------------
8790 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
8791 Typ : constant Entity_Id := Etype (N);
8793 begin
8794 -- If what we have is an identifier that references a subprogram
8795 -- formal, or a variable or constant object, then we get the actual
8796 -- subtype from the referenced entity if one has been built.
8798 if Nkind (N) = N_Identifier
8799 and then
8800 (Is_Formal (Entity (N))
8801 or else Ekind (Entity (N)) = E_Constant
8802 or else Ekind (Entity (N)) = E_Variable)
8803 and then Present (Actual_Subtype (Entity (N)))
8804 then
8805 return Actual_Subtype (Entity (N));
8807 -- Otherwise the Etype of N is returned unchanged
8809 else
8810 return Typ;
8811 end if;
8812 end Get_Actual_Subtype_If_Available;
8814 ------------------------
8815 -- Get_Body_From_Stub --
8816 ------------------------
8818 function Get_Body_From_Stub (N : Node_Id) return Node_Id is
8819 begin
8820 return Proper_Body (Unit (Library_Unit (N)));
8821 end Get_Body_From_Stub;
8823 ---------------------
8824 -- Get_Cursor_Type --
8825 ---------------------
8827 function Get_Cursor_Type
8828 (Aspect : Node_Id;
8829 Typ : Entity_Id) return Entity_Id
8831 Assoc : Node_Id;
8832 Func : Entity_Id;
8833 First_Op : Entity_Id;
8834 Cursor : Entity_Id;
8836 begin
8837 -- If error already detected, return
8839 if Error_Posted (Aspect) then
8840 return Any_Type;
8841 end if;
8843 -- The cursor type for an Iterable aspect is the return type of a
8844 -- non-overloaded First primitive operation. Locate association for
8845 -- First.
8847 Assoc := First (Component_Associations (Expression (Aspect)));
8848 First_Op := Any_Id;
8849 while Present (Assoc) loop
8850 if Chars (First (Choices (Assoc))) = Name_First then
8851 First_Op := Expression (Assoc);
8852 exit;
8853 end if;
8855 Next (Assoc);
8856 end loop;
8858 if First_Op = Any_Id then
8859 Error_Msg_N ("aspect Iterable must specify First operation", Aspect);
8860 return Any_Type;
8861 end if;
8863 Cursor := Any_Type;
8865 -- Locate function with desired name and profile in scope of type
8866 -- In the rare case where the type is an integer type, a base type
8867 -- is created for it, check that the base type of the first formal
8868 -- of First matches the base type of the domain.
8870 Func := First_Entity (Scope (Typ));
8871 while Present (Func) loop
8872 if Chars (Func) = Chars (First_Op)
8873 and then Ekind (Func) = E_Function
8874 and then Present (First_Formal (Func))
8875 and then Base_Type (Etype (First_Formal (Func))) = Base_Type (Typ)
8876 and then No (Next_Formal (First_Formal (Func)))
8877 then
8878 if Cursor /= Any_Type then
8879 Error_Msg_N
8880 ("Operation First for iterable type must be unique", Aspect);
8881 return Any_Type;
8882 else
8883 Cursor := Etype (Func);
8884 end if;
8885 end if;
8887 Next_Entity (Func);
8888 end loop;
8890 -- If not found, no way to resolve remaining primitives.
8892 if Cursor = Any_Type then
8893 Error_Msg_N
8894 ("No legal primitive operation First for Iterable type", Aspect);
8895 end if;
8897 return Cursor;
8898 end Get_Cursor_Type;
8900 function Get_Cursor_Type (Typ : Entity_Id) return Entity_Id is
8901 begin
8902 return Etype (Get_Iterable_Type_Primitive (Typ, Name_First));
8903 end Get_Cursor_Type;
8905 -------------------------------
8906 -- Get_Default_External_Name --
8907 -------------------------------
8909 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
8910 begin
8911 Get_Decoded_Name_String (Chars (E));
8913 if Opt.External_Name_Imp_Casing = Uppercase then
8914 Set_Casing (All_Upper_Case);
8915 else
8916 Set_Casing (All_Lower_Case);
8917 end if;
8919 return
8920 Make_String_Literal (Sloc (E),
8921 Strval => String_From_Name_Buffer);
8922 end Get_Default_External_Name;
8924 --------------------------
8925 -- Get_Enclosing_Object --
8926 --------------------------
8928 function Get_Enclosing_Object (N : Node_Id) return Entity_Id is
8929 begin
8930 if Is_Entity_Name (N) then
8931 return Entity (N);
8932 else
8933 case Nkind (N) is
8934 when N_Indexed_Component
8935 | N_Selected_Component
8936 | N_Slice
8938 -- If not generating code, a dereference may be left implicit.
8939 -- In thoses cases, return Empty.
8941 if Is_Access_Type (Etype (Prefix (N))) then
8942 return Empty;
8943 else
8944 return Get_Enclosing_Object (Prefix (N));
8945 end if;
8947 when N_Type_Conversion =>
8948 return Get_Enclosing_Object (Expression (N));
8950 when others =>
8951 return Empty;
8952 end case;
8953 end if;
8954 end Get_Enclosing_Object;
8956 ---------------------------
8957 -- Get_Enum_Lit_From_Pos --
8958 ---------------------------
8960 function Get_Enum_Lit_From_Pos
8961 (T : Entity_Id;
8962 Pos : Uint;
8963 Loc : Source_Ptr) return Node_Id
8965 Btyp : Entity_Id := Base_Type (T);
8966 Lit : Node_Id;
8967 LLoc : Source_Ptr;
8969 begin
8970 -- In the case where the literal is of type Character, Wide_Character
8971 -- or Wide_Wide_Character or of a type derived from them, there needs
8972 -- to be some special handling since there is no explicit chain of
8973 -- literals to search. Instead, an N_Character_Literal node is created
8974 -- with the appropriate Char_Code and Chars fields.
8976 if Is_Standard_Character_Type (T) then
8977 Set_Character_Literal_Name (UI_To_CC (Pos));
8979 return
8980 Make_Character_Literal (Loc,
8981 Chars => Name_Find,
8982 Char_Literal_Value => Pos);
8984 -- For all other cases, we have a complete table of literals, and
8985 -- we simply iterate through the chain of literal until the one
8986 -- with the desired position value is found.
8988 else
8989 if Is_Private_Type (Btyp) and then Present (Full_View (Btyp)) then
8990 Btyp := Full_View (Btyp);
8991 end if;
8993 Lit := First_Literal (Btyp);
8995 -- Position in the enumeration type starts at 0
8997 if UI_To_Int (Pos) < 0 then
8998 raise Constraint_Error;
8999 end if;
9001 for J in 1 .. UI_To_Int (Pos) loop
9002 Next_Literal (Lit);
9004 -- If Lit is Empty, Pos is not in range, so raise Constraint_Error
9005 -- inside the loop to avoid calling Next_Literal on Empty.
9007 if No (Lit) then
9008 raise Constraint_Error;
9009 end if;
9010 end loop;
9012 -- Create a new node from Lit, with source location provided by Loc
9013 -- if not equal to No_Location, or by copying the source location of
9014 -- Lit otherwise.
9016 LLoc := Loc;
9018 if LLoc = No_Location then
9019 LLoc := Sloc (Lit);
9020 end if;
9022 return New_Occurrence_Of (Lit, LLoc);
9023 end if;
9024 end Get_Enum_Lit_From_Pos;
9026 ------------------------
9027 -- Get_Generic_Entity --
9028 ------------------------
9030 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
9031 Ent : constant Entity_Id := Entity (Name (N));
9032 begin
9033 if Present (Renamed_Object (Ent)) then
9034 return Renamed_Object (Ent);
9035 else
9036 return Ent;
9037 end if;
9038 end Get_Generic_Entity;
9040 -------------------------------------
9041 -- Get_Incomplete_View_Of_Ancestor --
9042 -------------------------------------
9044 function Get_Incomplete_View_Of_Ancestor (E : Entity_Id) return Entity_Id is
9045 Cur_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
9046 Par_Scope : Entity_Id;
9047 Par_Type : Entity_Id;
9049 begin
9050 -- The incomplete view of an ancestor is only relevant for private
9051 -- derived types in child units.
9053 if not Is_Derived_Type (E)
9054 or else not Is_Child_Unit (Cur_Unit)
9055 then
9056 return Empty;
9058 else
9059 Par_Scope := Scope (Cur_Unit);
9060 if No (Par_Scope) then
9061 return Empty;
9062 end if;
9064 Par_Type := Etype (Base_Type (E));
9066 -- Traverse list of ancestor types until we find one declared in
9067 -- a parent or grandparent unit (two levels seem sufficient).
9069 while Present (Par_Type) loop
9070 if Scope (Par_Type) = Par_Scope
9071 or else Scope (Par_Type) = Scope (Par_Scope)
9072 then
9073 return Par_Type;
9075 elsif not Is_Derived_Type (Par_Type) then
9076 return Empty;
9078 else
9079 Par_Type := Etype (Base_Type (Par_Type));
9080 end if;
9081 end loop;
9083 -- If none found, there is no relevant ancestor type.
9085 return Empty;
9086 end if;
9087 end Get_Incomplete_View_Of_Ancestor;
9089 ----------------------
9090 -- Get_Index_Bounds --
9091 ----------------------
9093 procedure Get_Index_Bounds
9094 (N : Node_Id;
9095 L : out Node_Id;
9096 H : out Node_Id;
9097 Use_Full_View : Boolean := False)
9099 function Scalar_Range_Of_Type (Typ : Entity_Id) return Node_Id;
9100 -- Obtain the scalar range of type Typ. If flag Use_Full_View is set and
9101 -- Typ qualifies, the scalar range is obtained from the full view of the
9102 -- type.
9104 --------------------------
9105 -- Scalar_Range_Of_Type --
9106 --------------------------
9108 function Scalar_Range_Of_Type (Typ : Entity_Id) return Node_Id is
9109 T : Entity_Id := Typ;
9111 begin
9112 if Use_Full_View and then Present (Full_View (T)) then
9113 T := Full_View (T);
9114 end if;
9116 return Scalar_Range (T);
9117 end Scalar_Range_Of_Type;
9119 -- Local variables
9121 Kind : constant Node_Kind := Nkind (N);
9122 Rng : Node_Id;
9124 -- Start of processing for Get_Index_Bounds
9126 begin
9127 if Kind = N_Range then
9128 L := Low_Bound (N);
9129 H := High_Bound (N);
9131 elsif Kind = N_Subtype_Indication then
9132 Rng := Range_Expression (Constraint (N));
9134 if Rng = Error then
9135 L := Error;
9136 H := Error;
9137 return;
9139 else
9140 L := Low_Bound (Range_Expression (Constraint (N)));
9141 H := High_Bound (Range_Expression (Constraint (N)));
9142 end if;
9144 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
9145 Rng := Scalar_Range_Of_Type (Entity (N));
9147 if Error_Posted (Rng) then
9148 L := Error;
9149 H := Error;
9151 elsif Nkind (Rng) = N_Subtype_Indication then
9152 Get_Index_Bounds (Rng, L, H);
9154 else
9155 L := Low_Bound (Rng);
9156 H := High_Bound (Rng);
9157 end if;
9159 else
9160 -- N is an expression, indicating a range with one value
9162 L := N;
9163 H := N;
9164 end if;
9165 end Get_Index_Bounds;
9167 -----------------------------
9168 -- Get_Interfacing_Aspects --
9169 -----------------------------
9171 procedure Get_Interfacing_Aspects
9172 (Iface_Asp : Node_Id;
9173 Conv_Asp : out Node_Id;
9174 EN_Asp : out Node_Id;
9175 Expo_Asp : out Node_Id;
9176 Imp_Asp : out Node_Id;
9177 LN_Asp : out Node_Id;
9178 Do_Checks : Boolean := False)
9180 procedure Save_Or_Duplication_Error
9181 (Asp : Node_Id;
9182 To : in out Node_Id);
9183 -- Save the value of aspect Asp in node To. If To already has a value,
9184 -- then this is considered a duplicate use of aspect. Emit an error if
9185 -- flag Do_Checks is set.
9187 -------------------------------
9188 -- Save_Or_Duplication_Error --
9189 -------------------------------
9191 procedure Save_Or_Duplication_Error
9192 (Asp : Node_Id;
9193 To : in out Node_Id)
9195 begin
9196 -- Detect an extra aspect and issue an error
9198 if Present (To) then
9199 if Do_Checks then
9200 Error_Msg_Name_1 := Chars (Identifier (Asp));
9201 Error_Msg_Sloc := Sloc (To);
9202 Error_Msg_N ("aspect % previously given #", Asp);
9203 end if;
9205 -- Otherwise capture the aspect
9207 else
9208 To := Asp;
9209 end if;
9210 end Save_Or_Duplication_Error;
9212 -- Local variables
9214 Asp : Node_Id;
9215 Asp_Id : Aspect_Id;
9217 -- The following variables capture each individual aspect
9219 Conv : Node_Id := Empty;
9220 EN : Node_Id := Empty;
9221 Expo : Node_Id := Empty;
9222 Imp : Node_Id := Empty;
9223 LN : Node_Id := Empty;
9225 -- Start of processing for Get_Interfacing_Aspects
9227 begin
9228 -- The input interfacing aspect should reside in an aspect specification
9229 -- list.
9231 pragma Assert (Is_List_Member (Iface_Asp));
9233 -- Examine the aspect specifications of the related entity. Find and
9234 -- capture all interfacing aspects. Detect duplicates and emit errors
9235 -- if applicable.
9237 Asp := First (List_Containing (Iface_Asp));
9238 while Present (Asp) loop
9239 Asp_Id := Get_Aspect_Id (Asp);
9241 if Asp_Id = Aspect_Convention then
9242 Save_Or_Duplication_Error (Asp, Conv);
9244 elsif Asp_Id = Aspect_External_Name then
9245 Save_Or_Duplication_Error (Asp, EN);
9247 elsif Asp_Id = Aspect_Export then
9248 Save_Or_Duplication_Error (Asp, Expo);
9250 elsif Asp_Id = Aspect_Import then
9251 Save_Or_Duplication_Error (Asp, Imp);
9253 elsif Asp_Id = Aspect_Link_Name then
9254 Save_Or_Duplication_Error (Asp, LN);
9255 end if;
9257 Next (Asp);
9258 end loop;
9260 Conv_Asp := Conv;
9261 EN_Asp := EN;
9262 Expo_Asp := Expo;
9263 Imp_Asp := Imp;
9264 LN_Asp := LN;
9265 end Get_Interfacing_Aspects;
9267 ---------------------------------
9268 -- Get_Iterable_Type_Primitive --
9269 ---------------------------------
9271 function Get_Iterable_Type_Primitive
9272 (Typ : Entity_Id;
9273 Nam : Name_Id) return Entity_Id
9275 Funcs : constant Node_Id := Find_Value_Of_Aspect (Typ, Aspect_Iterable);
9276 Assoc : Node_Id;
9278 begin
9279 if No (Funcs) then
9280 return Empty;
9282 else
9283 Assoc := First (Component_Associations (Funcs));
9284 while Present (Assoc) loop
9285 if Chars (First (Choices (Assoc))) = Nam then
9286 return Entity (Expression (Assoc));
9287 end if;
9289 Assoc := Next (Assoc);
9290 end loop;
9292 return Empty;
9293 end if;
9294 end Get_Iterable_Type_Primitive;
9296 ----------------------------------
9297 -- Get_Library_Unit_Name_string --
9298 ----------------------------------
9300 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
9301 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
9303 begin
9304 Get_Unit_Name_String (Unit_Name_Id);
9306 -- Remove seven last character (" (spec)" or " (body)")
9308 Name_Len := Name_Len - 7;
9309 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
9310 end Get_Library_Unit_Name_String;
9312 --------------------------
9313 -- Get_Max_Queue_Length --
9314 --------------------------
9316 function Get_Max_Queue_Length (Id : Entity_Id) return Uint is
9317 pragma Assert (Is_Entry (Id));
9318 Prag : constant Entity_Id := Get_Pragma (Id, Pragma_Max_Queue_Length);
9320 begin
9321 -- A value of 0 represents no maximum specified, and entries and entry
9322 -- families with no Max_Queue_Length aspect or pragma default to it.
9324 if not Present (Prag) then
9325 return Uint_0;
9326 end if;
9328 return Intval (Expression (First (Pragma_Argument_Associations (Prag))));
9329 end Get_Max_Queue_Length;
9331 ------------------------
9332 -- Get_Name_Entity_Id --
9333 ------------------------
9335 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
9336 begin
9337 return Entity_Id (Get_Name_Table_Int (Id));
9338 end Get_Name_Entity_Id;
9340 ------------------------------
9341 -- Get_Name_From_CTC_Pragma --
9342 ------------------------------
9344 function Get_Name_From_CTC_Pragma (N : Node_Id) return String_Id is
9345 Arg : constant Node_Id :=
9346 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
9347 begin
9348 return Strval (Expr_Value_S (Arg));
9349 end Get_Name_From_CTC_Pragma;
9351 -----------------------
9352 -- Get_Parent_Entity --
9353 -----------------------
9355 function Get_Parent_Entity (Unit : Node_Id) return Entity_Id is
9356 begin
9357 if Nkind (Unit) = N_Package_Body
9358 and then Nkind (Original_Node (Unit)) = N_Package_Instantiation
9359 then
9360 return Defining_Entity
9361 (Specification (Instance_Spec (Original_Node (Unit))));
9362 elsif Nkind (Unit) = N_Package_Instantiation then
9363 return Defining_Entity (Specification (Instance_Spec (Unit)));
9364 else
9365 return Defining_Entity (Unit);
9366 end if;
9367 end Get_Parent_Entity;
9369 -------------------
9370 -- Get_Pragma_Id --
9371 -------------------
9373 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
9374 begin
9375 return Get_Pragma_Id (Pragma_Name_Unmapped (N));
9376 end Get_Pragma_Id;
9378 ------------------------
9379 -- Get_Qualified_Name --
9380 ------------------------
9382 function Get_Qualified_Name
9383 (Id : Entity_Id;
9384 Suffix : Entity_Id := Empty) return Name_Id
9386 Suffix_Nam : Name_Id := No_Name;
9388 begin
9389 if Present (Suffix) then
9390 Suffix_Nam := Chars (Suffix);
9391 end if;
9393 return Get_Qualified_Name (Chars (Id), Suffix_Nam, Scope (Id));
9394 end Get_Qualified_Name;
9396 function Get_Qualified_Name
9397 (Nam : Name_Id;
9398 Suffix : Name_Id := No_Name;
9399 Scop : Entity_Id := Current_Scope) return Name_Id
9401 procedure Add_Scope (S : Entity_Id);
9402 -- Add the fully qualified form of scope S to the name buffer. The
9403 -- format is:
9404 -- s-1__s__
9406 ---------------
9407 -- Add_Scope --
9408 ---------------
9410 procedure Add_Scope (S : Entity_Id) is
9411 begin
9412 if S = Empty then
9413 null;
9415 elsif S = Standard_Standard then
9416 null;
9418 else
9419 Add_Scope (Scope (S));
9420 Get_Name_String_And_Append (Chars (S));
9421 Add_Str_To_Name_Buffer ("__");
9422 end if;
9423 end Add_Scope;
9425 -- Start of processing for Get_Qualified_Name
9427 begin
9428 Name_Len := 0;
9429 Add_Scope (Scop);
9431 -- Append the base name after all scopes have been chained
9433 Get_Name_String_And_Append (Nam);
9435 -- Append the suffix (if present)
9437 if Suffix /= No_Name then
9438 Add_Str_To_Name_Buffer ("__");
9439 Get_Name_String_And_Append (Suffix);
9440 end if;
9442 return Name_Find;
9443 end Get_Qualified_Name;
9445 -----------------------
9446 -- Get_Reason_String --
9447 -----------------------
9449 procedure Get_Reason_String (N : Node_Id) is
9450 begin
9451 if Nkind (N) = N_String_Literal then
9452 Store_String_Chars (Strval (N));
9454 elsif Nkind (N) = N_Op_Concat then
9455 Get_Reason_String (Left_Opnd (N));
9456 Get_Reason_String (Right_Opnd (N));
9458 -- If not of required form, error
9460 else
9461 Error_Msg_N
9462 ("Reason for pragma Warnings has wrong form", N);
9463 Error_Msg_N
9464 ("\must be string literal or concatenation of string literals", N);
9465 return;
9466 end if;
9467 end Get_Reason_String;
9469 --------------------------------
9470 -- Get_Reference_Discriminant --
9471 --------------------------------
9473 function Get_Reference_Discriminant (Typ : Entity_Id) return Entity_Id is
9474 D : Entity_Id;
9476 begin
9477 D := First_Discriminant (Typ);
9478 while Present (D) loop
9479 if Has_Implicit_Dereference (D) then
9480 return D;
9481 end if;
9482 Next_Discriminant (D);
9483 end loop;
9485 return Empty;
9486 end Get_Reference_Discriminant;
9488 ---------------------------
9489 -- Get_Referenced_Object --
9490 ---------------------------
9492 function Get_Referenced_Object (N : Node_Id) return Node_Id is
9493 R : Node_Id;
9495 begin
9496 R := N;
9497 while Is_Entity_Name (R)
9498 and then Present (Renamed_Object (Entity (R)))
9499 loop
9500 R := Renamed_Object (Entity (R));
9501 end loop;
9503 return R;
9504 end Get_Referenced_Object;
9506 ------------------------
9507 -- Get_Renamed_Entity --
9508 ------------------------
9510 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
9511 R : Entity_Id;
9513 begin
9514 R := E;
9515 while Present (Renamed_Entity (R)) loop
9516 R := Renamed_Entity (R);
9517 end loop;
9519 return R;
9520 end Get_Renamed_Entity;
9522 -----------------------
9523 -- Get_Return_Object --
9524 -----------------------
9526 function Get_Return_Object (N : Node_Id) return Entity_Id is
9527 Decl : Node_Id;
9529 begin
9530 Decl := First (Return_Object_Declarations (N));
9531 while Present (Decl) loop
9532 exit when Nkind (Decl) = N_Object_Declaration
9533 and then Is_Return_Object (Defining_Identifier (Decl));
9534 Next (Decl);
9535 end loop;
9537 pragma Assert (Present (Decl));
9538 return Defining_Identifier (Decl);
9539 end Get_Return_Object;
9541 ---------------------------
9542 -- Get_Subprogram_Entity --
9543 ---------------------------
9545 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
9546 Subp : Node_Id;
9547 Subp_Id : Entity_Id;
9549 begin
9550 if Nkind (Nod) = N_Accept_Statement then
9551 Subp := Entry_Direct_Name (Nod);
9553 elsif Nkind (Nod) = N_Slice then
9554 Subp := Prefix (Nod);
9556 else
9557 Subp := Name (Nod);
9558 end if;
9560 -- Strip the subprogram call
9562 loop
9563 if Nkind_In (Subp, N_Explicit_Dereference,
9564 N_Indexed_Component,
9565 N_Selected_Component)
9566 then
9567 Subp := Prefix (Subp);
9569 elsif Nkind_In (Subp, N_Type_Conversion,
9570 N_Unchecked_Type_Conversion)
9571 then
9572 Subp := Expression (Subp);
9574 else
9575 exit;
9576 end if;
9577 end loop;
9579 -- Extract the entity of the subprogram call
9581 if Is_Entity_Name (Subp) then
9582 Subp_Id := Entity (Subp);
9584 if Ekind (Subp_Id) = E_Access_Subprogram_Type then
9585 Subp_Id := Directly_Designated_Type (Subp_Id);
9586 end if;
9588 if Is_Subprogram (Subp_Id) then
9589 return Subp_Id;
9590 else
9591 return Empty;
9592 end if;
9594 -- The search did not find a construct that denotes a subprogram
9596 else
9597 return Empty;
9598 end if;
9599 end Get_Subprogram_Entity;
9601 -----------------------------
9602 -- Get_Task_Body_Procedure --
9603 -----------------------------
9605 function Get_Task_Body_Procedure (E : Entity_Id) return Entity_Id is
9606 begin
9607 -- Note: A task type may be the completion of a private type with
9608 -- discriminants. When performing elaboration checks on a task
9609 -- declaration, the current view of the type may be the private one,
9610 -- and the procedure that holds the body of the task is held in its
9611 -- underlying type.
9613 -- This is an odd function, why not have Task_Body_Procedure do
9614 -- the following digging???
9616 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
9617 end Get_Task_Body_Procedure;
9619 -------------------------
9620 -- Get_User_Defined_Eq --
9621 -------------------------
9623 function Get_User_Defined_Eq (E : Entity_Id) return Entity_Id is
9624 Prim : Elmt_Id;
9625 Op : Entity_Id;
9627 begin
9628 Prim := First_Elmt (Collect_Primitive_Operations (E));
9629 while Present (Prim) loop
9630 Op := Node (Prim);
9632 if Chars (Op) = Name_Op_Eq
9633 and then Etype (Op) = Standard_Boolean
9634 and then Etype (First_Formal (Op)) = E
9635 and then Etype (Next_Formal (First_Formal (Op))) = E
9636 then
9637 return Op;
9638 end if;
9640 Next_Elmt (Prim);
9641 end loop;
9643 return Empty;
9644 end Get_User_Defined_Eq;
9646 ---------------
9647 -- Get_Views --
9648 ---------------
9650 procedure Get_Views
9651 (Typ : Entity_Id;
9652 Priv_Typ : out Entity_Id;
9653 Full_Typ : out Entity_Id;
9654 Full_Base : out Entity_Id;
9655 CRec_Typ : out Entity_Id)
9657 IP_View : Entity_Id;
9659 begin
9660 -- Assume that none of the views can be recovered
9662 Priv_Typ := Empty;
9663 Full_Typ := Empty;
9664 Full_Base := Empty;
9665 CRec_Typ := Empty;
9667 -- The input type is the corresponding record type of a protected or a
9668 -- task type.
9670 if Ekind (Typ) = E_Record_Type
9671 and then Is_Concurrent_Record_Type (Typ)
9672 then
9673 CRec_Typ := Typ;
9674 Full_Typ := Corresponding_Concurrent_Type (CRec_Typ);
9675 Full_Base := Base_Type (Full_Typ);
9676 Priv_Typ := Incomplete_Or_Partial_View (Full_Typ);
9678 -- Otherwise the input type denotes an arbitrary type
9680 else
9681 IP_View := Incomplete_Or_Partial_View (Typ);
9683 -- The input type denotes the full view of a private type
9685 if Present (IP_View) then
9686 Priv_Typ := IP_View;
9687 Full_Typ := Typ;
9689 -- The input type is a private type
9691 elsif Is_Private_Type (Typ) then
9692 Priv_Typ := Typ;
9693 Full_Typ := Full_View (Priv_Typ);
9695 -- Otherwise the input type does not have any views
9697 else
9698 Full_Typ := Typ;
9699 end if;
9701 if Present (Full_Typ) then
9702 Full_Base := Base_Type (Full_Typ);
9704 if Ekind_In (Full_Typ, E_Protected_Type, E_Task_Type) then
9705 CRec_Typ := Corresponding_Record_Type (Full_Typ);
9706 end if;
9707 end if;
9708 end if;
9709 end Get_Views;
9711 -----------------------
9712 -- Has_Access_Values --
9713 -----------------------
9715 function Has_Access_Values (T : Entity_Id) return Boolean is
9716 Typ : constant Entity_Id := Underlying_Type (T);
9718 begin
9719 -- Case of a private type which is not completed yet. This can only
9720 -- happen in the case of a generic format type appearing directly, or
9721 -- as a component of the type to which this function is being applied
9722 -- at the top level. Return False in this case, since we certainly do
9723 -- not know that the type contains access types.
9725 if No (Typ) then
9726 return False;
9728 elsif Is_Access_Type (Typ) then
9729 return True;
9731 elsif Is_Array_Type (Typ) then
9732 return Has_Access_Values (Component_Type (Typ));
9734 elsif Is_Record_Type (Typ) then
9735 declare
9736 Comp : Entity_Id;
9738 begin
9739 -- Loop to Check components
9741 Comp := First_Component_Or_Discriminant (Typ);
9742 while Present (Comp) loop
9744 -- Check for access component, tag field does not count, even
9745 -- though it is implemented internally using an access type.
9747 if Has_Access_Values (Etype (Comp))
9748 and then Chars (Comp) /= Name_uTag
9749 then
9750 return True;
9751 end if;
9753 Next_Component_Or_Discriminant (Comp);
9754 end loop;
9755 end;
9757 return False;
9759 else
9760 return False;
9761 end if;
9762 end Has_Access_Values;
9764 ------------------------------
9765 -- Has_Compatible_Alignment --
9766 ------------------------------
9768 function Has_Compatible_Alignment
9769 (Obj : Entity_Id;
9770 Expr : Node_Id;
9771 Layout_Done : Boolean) return Alignment_Result
9773 function Has_Compatible_Alignment_Internal
9774 (Obj : Entity_Id;
9775 Expr : Node_Id;
9776 Layout_Done : Boolean;
9777 Default : Alignment_Result) return Alignment_Result;
9778 -- This is the internal recursive function that actually does the work.
9779 -- There is one additional parameter, which says what the result should
9780 -- be if no alignment information is found, and there is no definite
9781 -- indication of compatible alignments. At the outer level, this is set
9782 -- to Unknown, but for internal recursive calls in the case where types
9783 -- are known to be correct, it is set to Known_Compatible.
9785 ---------------------------------------
9786 -- Has_Compatible_Alignment_Internal --
9787 ---------------------------------------
9789 function Has_Compatible_Alignment_Internal
9790 (Obj : Entity_Id;
9791 Expr : Node_Id;
9792 Layout_Done : Boolean;
9793 Default : Alignment_Result) return Alignment_Result
9795 Result : Alignment_Result := Known_Compatible;
9796 -- Holds the current status of the result. Note that once a value of
9797 -- Known_Incompatible is set, it is sticky and does not get changed
9798 -- to Unknown (the value in Result only gets worse as we go along,
9799 -- never better).
9801 Offs : Uint := No_Uint;
9802 -- Set to a factor of the offset from the base object when Expr is a
9803 -- selected or indexed component, based on Component_Bit_Offset and
9804 -- Component_Size respectively. A negative value is used to represent
9805 -- a value which is not known at compile time.
9807 procedure Check_Prefix;
9808 -- Checks the prefix recursively in the case where the expression
9809 -- is an indexed or selected component.
9811 procedure Set_Result (R : Alignment_Result);
9812 -- If R represents a worse outcome (unknown instead of known
9813 -- compatible, or known incompatible), then set Result to R.
9815 ------------------
9816 -- Check_Prefix --
9817 ------------------
9819 procedure Check_Prefix is
9820 begin
9821 -- The subtlety here is that in doing a recursive call to check
9822 -- the prefix, we have to decide what to do in the case where we
9823 -- don't find any specific indication of an alignment problem.
9825 -- At the outer level, we normally set Unknown as the result in
9826 -- this case, since we can only set Known_Compatible if we really
9827 -- know that the alignment value is OK, but for the recursive
9828 -- call, in the case where the types match, and we have not
9829 -- specified a peculiar alignment for the object, we are only
9830 -- concerned about suspicious rep clauses, the default case does
9831 -- not affect us, since the compiler will, in the absence of such
9832 -- rep clauses, ensure that the alignment is correct.
9834 if Default = Known_Compatible
9835 or else
9836 (Etype (Obj) = Etype (Expr)
9837 and then (Unknown_Alignment (Obj)
9838 or else
9839 Alignment (Obj) = Alignment (Etype (Obj))))
9840 then
9841 Set_Result
9842 (Has_Compatible_Alignment_Internal
9843 (Obj, Prefix (Expr), Layout_Done, Known_Compatible));
9845 -- In all other cases, we need a full check on the prefix
9847 else
9848 Set_Result
9849 (Has_Compatible_Alignment_Internal
9850 (Obj, Prefix (Expr), Layout_Done, Unknown));
9851 end if;
9852 end Check_Prefix;
9854 ----------------
9855 -- Set_Result --
9856 ----------------
9858 procedure Set_Result (R : Alignment_Result) is
9859 begin
9860 if R > Result then
9861 Result := R;
9862 end if;
9863 end Set_Result;
9865 -- Start of processing for Has_Compatible_Alignment_Internal
9867 begin
9868 -- If Expr is a selected component, we must make sure there is no
9869 -- potentially troublesome component clause and that the record is
9870 -- not packed if the layout is not done.
9872 if Nkind (Expr) = N_Selected_Component then
9874 -- Packing generates unknown alignment if layout is not done
9876 if Is_Packed (Etype (Prefix (Expr))) and then not Layout_Done then
9877 Set_Result (Unknown);
9878 end if;
9880 -- Check prefix and component offset
9882 Check_Prefix;
9883 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
9885 -- If Expr is an indexed component, we must make sure there is no
9886 -- potentially troublesome Component_Size clause and that the array
9887 -- is not bit-packed if the layout is not done.
9889 elsif Nkind (Expr) = N_Indexed_Component then
9890 declare
9891 Typ : constant Entity_Id := Etype (Prefix (Expr));
9893 begin
9894 -- Packing generates unknown alignment if layout is not done
9896 if Is_Bit_Packed_Array (Typ) and then not Layout_Done then
9897 Set_Result (Unknown);
9898 end if;
9900 -- Check prefix and component offset (or at least size)
9902 Check_Prefix;
9903 Offs := Indexed_Component_Bit_Offset (Expr);
9904 if Offs = No_Uint then
9905 Offs := Component_Size (Typ);
9906 end if;
9907 end;
9908 end if;
9910 -- If we have a null offset, the result is entirely determined by
9911 -- the base object and has already been computed recursively.
9913 if Offs = Uint_0 then
9914 null;
9916 -- Case where we know the alignment of the object
9918 elsif Known_Alignment (Obj) then
9919 declare
9920 ObjA : constant Uint := Alignment (Obj);
9921 ExpA : Uint := No_Uint;
9922 SizA : Uint := No_Uint;
9924 begin
9925 -- If alignment of Obj is 1, then we are always OK
9927 if ObjA = 1 then
9928 Set_Result (Known_Compatible);
9930 -- Alignment of Obj is greater than 1, so we need to check
9932 else
9933 -- If we have an offset, see if it is compatible
9935 if Offs /= No_Uint and Offs > Uint_0 then
9936 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
9937 Set_Result (Known_Incompatible);
9938 end if;
9940 -- See if Expr is an object with known alignment
9942 elsif Is_Entity_Name (Expr)
9943 and then Known_Alignment (Entity (Expr))
9944 then
9945 ExpA := Alignment (Entity (Expr));
9947 -- Otherwise, we can use the alignment of the type of
9948 -- Expr given that we already checked for
9949 -- discombobulating rep clauses for the cases of indexed
9950 -- and selected components above.
9952 elsif Known_Alignment (Etype (Expr)) then
9953 ExpA := Alignment (Etype (Expr));
9955 -- Otherwise the alignment is unknown
9957 else
9958 Set_Result (Default);
9959 end if;
9961 -- If we got an alignment, see if it is acceptable
9963 if ExpA /= No_Uint and then ExpA < ObjA then
9964 Set_Result (Known_Incompatible);
9965 end if;
9967 -- If Expr is not a piece of a larger object, see if size
9968 -- is given. If so, check that it is not too small for the
9969 -- required alignment.
9971 if Offs /= No_Uint then
9972 null;
9974 -- See if Expr is an object with known size
9976 elsif Is_Entity_Name (Expr)
9977 and then Known_Static_Esize (Entity (Expr))
9978 then
9979 SizA := Esize (Entity (Expr));
9981 -- Otherwise, we check the object size of the Expr type
9983 elsif Known_Static_Esize (Etype (Expr)) then
9984 SizA := Esize (Etype (Expr));
9985 end if;
9987 -- If we got a size, see if it is a multiple of the Obj
9988 -- alignment, if not, then the alignment cannot be
9989 -- acceptable, since the size is always a multiple of the
9990 -- alignment.
9992 if SizA /= No_Uint then
9993 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
9994 Set_Result (Known_Incompatible);
9995 end if;
9996 end if;
9997 end if;
9998 end;
10000 -- If we do not know required alignment, any non-zero offset is a
10001 -- potential problem (but certainly may be OK, so result is unknown).
10003 elsif Offs /= No_Uint then
10004 Set_Result (Unknown);
10006 -- If we can't find the result by direct comparison of alignment
10007 -- values, then there is still one case that we can determine known
10008 -- result, and that is when we can determine that the types are the
10009 -- same, and no alignments are specified. Then we known that the
10010 -- alignments are compatible, even if we don't know the alignment
10011 -- value in the front end.
10013 elsif Etype (Obj) = Etype (Expr) then
10015 -- Types are the same, but we have to check for possible size
10016 -- and alignments on the Expr object that may make the alignment
10017 -- different, even though the types are the same.
10019 if Is_Entity_Name (Expr) then
10021 -- First check alignment of the Expr object. Any alignment less
10022 -- than Maximum_Alignment is worrisome since this is the case
10023 -- where we do not know the alignment of Obj.
10025 if Known_Alignment (Entity (Expr))
10026 and then UI_To_Int (Alignment (Entity (Expr))) <
10027 Ttypes.Maximum_Alignment
10028 then
10029 Set_Result (Unknown);
10031 -- Now check size of Expr object. Any size that is not an
10032 -- even multiple of Maximum_Alignment is also worrisome
10033 -- since it may cause the alignment of the object to be less
10034 -- than the alignment of the type.
10036 elsif Known_Static_Esize (Entity (Expr))
10037 and then
10038 (UI_To_Int (Esize (Entity (Expr))) mod
10039 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
10040 /= 0
10041 then
10042 Set_Result (Unknown);
10044 -- Otherwise same type is decisive
10046 else
10047 Set_Result (Known_Compatible);
10048 end if;
10049 end if;
10051 -- Another case to deal with is when there is an explicit size or
10052 -- alignment clause when the types are not the same. If so, then the
10053 -- result is Unknown. We don't need to do this test if the Default is
10054 -- Unknown, since that result will be set in any case.
10056 elsif Default /= Unknown
10057 and then (Has_Size_Clause (Etype (Expr))
10058 or else
10059 Has_Alignment_Clause (Etype (Expr)))
10060 then
10061 Set_Result (Unknown);
10063 -- If no indication found, set default
10065 else
10066 Set_Result (Default);
10067 end if;
10069 -- Return worst result found
10071 return Result;
10072 end Has_Compatible_Alignment_Internal;
10074 -- Start of processing for Has_Compatible_Alignment
10076 begin
10077 -- If Obj has no specified alignment, then set alignment from the type
10078 -- alignment. Perhaps we should always do this, but for sure we should
10079 -- do it when there is an address clause since we can do more if the
10080 -- alignment is known.
10082 if Unknown_Alignment (Obj) then
10083 Set_Alignment (Obj, Alignment (Etype (Obj)));
10084 end if;
10086 -- Now do the internal call that does all the work
10088 return
10089 Has_Compatible_Alignment_Internal (Obj, Expr, Layout_Done, Unknown);
10090 end Has_Compatible_Alignment;
10092 ----------------------
10093 -- Has_Declarations --
10094 ----------------------
10096 function Has_Declarations (N : Node_Id) return Boolean is
10097 begin
10098 return Nkind_In (Nkind (N), N_Accept_Statement,
10099 N_Block_Statement,
10100 N_Compilation_Unit_Aux,
10101 N_Entry_Body,
10102 N_Package_Body,
10103 N_Protected_Body,
10104 N_Subprogram_Body,
10105 N_Task_Body,
10106 N_Package_Specification);
10107 end Has_Declarations;
10109 ---------------------------------
10110 -- Has_Defaulted_Discriminants --
10111 ---------------------------------
10113 function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean is
10114 begin
10115 return Has_Discriminants (Typ)
10116 and then Present (First_Discriminant (Typ))
10117 and then Present (Discriminant_Default_Value
10118 (First_Discriminant (Typ)));
10119 end Has_Defaulted_Discriminants;
10121 -------------------
10122 -- Has_Denormals --
10123 -------------------
10125 function Has_Denormals (E : Entity_Id) return Boolean is
10126 begin
10127 return Is_Floating_Point_Type (E) and then Denorm_On_Target;
10128 end Has_Denormals;
10130 -------------------------------------------
10131 -- Has_Discriminant_Dependent_Constraint --
10132 -------------------------------------------
10134 function Has_Discriminant_Dependent_Constraint
10135 (Comp : Entity_Id) return Boolean
10137 Comp_Decl : constant Node_Id := Parent (Comp);
10138 Subt_Indic : Node_Id;
10139 Constr : Node_Id;
10140 Assn : Node_Id;
10142 begin
10143 -- Discriminants can't depend on discriminants
10145 if Ekind (Comp) = E_Discriminant then
10146 return False;
10148 else
10149 Subt_Indic := Subtype_Indication (Component_Definition (Comp_Decl));
10151 if Nkind (Subt_Indic) = N_Subtype_Indication then
10152 Constr := Constraint (Subt_Indic);
10154 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
10155 Assn := First (Constraints (Constr));
10156 while Present (Assn) loop
10157 case Nkind (Assn) is
10158 when N_Identifier
10159 | N_Range
10160 | N_Subtype_Indication
10162 if Depends_On_Discriminant (Assn) then
10163 return True;
10164 end if;
10166 when N_Discriminant_Association =>
10167 if Depends_On_Discriminant (Expression (Assn)) then
10168 return True;
10169 end if;
10171 when others =>
10172 null;
10173 end case;
10175 Next (Assn);
10176 end loop;
10177 end if;
10178 end if;
10179 end if;
10181 return False;
10182 end Has_Discriminant_Dependent_Constraint;
10184 --------------------------------------
10185 -- Has_Effectively_Volatile_Profile --
10186 --------------------------------------
10188 function Has_Effectively_Volatile_Profile
10189 (Subp_Id : Entity_Id) return Boolean
10191 Formal : Entity_Id;
10193 begin
10194 -- Inspect the formal parameters looking for an effectively volatile
10195 -- type.
10197 Formal := First_Formal (Subp_Id);
10198 while Present (Formal) loop
10199 if Is_Effectively_Volatile (Etype (Formal)) then
10200 return True;
10201 end if;
10203 Next_Formal (Formal);
10204 end loop;
10206 -- Inspect the return type of functions
10208 if Ekind_In (Subp_Id, E_Function, E_Generic_Function)
10209 and then Is_Effectively_Volatile (Etype (Subp_Id))
10210 then
10211 return True;
10212 end if;
10214 return False;
10215 end Has_Effectively_Volatile_Profile;
10217 --------------------------
10218 -- Has_Enabled_Property --
10219 --------------------------
10221 function Has_Enabled_Property
10222 (Item_Id : Entity_Id;
10223 Property : Name_Id) return Boolean
10225 function Protected_Object_Has_Enabled_Property return Boolean;
10226 -- Determine whether a protected object denoted by Item_Id has the
10227 -- property enabled.
10229 function State_Has_Enabled_Property return Boolean;
10230 -- Determine whether a state denoted by Item_Id has the property enabled
10232 function Variable_Has_Enabled_Property return Boolean;
10233 -- Determine whether a variable denoted by Item_Id has the property
10234 -- enabled.
10236 -------------------------------------------
10237 -- Protected_Object_Has_Enabled_Property --
10238 -------------------------------------------
10240 function Protected_Object_Has_Enabled_Property return Boolean is
10241 Constits : constant Elist_Id := Part_Of_Constituents (Item_Id);
10242 Constit_Elmt : Elmt_Id;
10243 Constit_Id : Entity_Id;
10245 begin
10246 -- Protected objects always have the properties Async_Readers and
10247 -- Async_Writers (SPARK RM 7.1.2(16)).
10249 if Property = Name_Async_Readers
10250 or else Property = Name_Async_Writers
10251 then
10252 return True;
10254 -- Protected objects that have Part_Of components also inherit their
10255 -- properties Effective_Reads and Effective_Writes
10256 -- (SPARK RM 7.1.2(16)).
10258 elsif Present (Constits) then
10259 Constit_Elmt := First_Elmt (Constits);
10260 while Present (Constit_Elmt) loop
10261 Constit_Id := Node (Constit_Elmt);
10263 if Has_Enabled_Property (Constit_Id, Property) then
10264 return True;
10265 end if;
10267 Next_Elmt (Constit_Elmt);
10268 end loop;
10269 end if;
10271 return False;
10272 end Protected_Object_Has_Enabled_Property;
10274 --------------------------------
10275 -- State_Has_Enabled_Property --
10276 --------------------------------
10278 function State_Has_Enabled_Property return Boolean is
10279 Decl : constant Node_Id := Parent (Item_Id);
10280 Opt : Node_Id;
10281 Opt_Nam : Node_Id;
10282 Prop : Node_Id;
10283 Prop_Nam : Node_Id;
10284 Props : Node_Id;
10286 begin
10287 -- The declaration of an external abstract state appears as an
10288 -- extension aggregate. If this is not the case, properties can never
10289 -- be set.
10291 if Nkind (Decl) /= N_Extension_Aggregate then
10292 return False;
10293 end if;
10295 -- When External appears as a simple option, it automatically enables
10296 -- all properties.
10298 Opt := First (Expressions (Decl));
10299 while Present (Opt) loop
10300 if Nkind (Opt) = N_Identifier
10301 and then Chars (Opt) = Name_External
10302 then
10303 return True;
10304 end if;
10306 Next (Opt);
10307 end loop;
10309 -- When External specifies particular properties, inspect those and
10310 -- find the desired one (if any).
10312 Opt := First (Component_Associations (Decl));
10313 while Present (Opt) loop
10314 Opt_Nam := First (Choices (Opt));
10316 if Nkind (Opt_Nam) = N_Identifier
10317 and then Chars (Opt_Nam) = Name_External
10318 then
10319 Props := Expression (Opt);
10321 -- Multiple properties appear as an aggregate
10323 if Nkind (Props) = N_Aggregate then
10325 -- Simple property form
10327 Prop := First (Expressions (Props));
10328 while Present (Prop) loop
10329 if Chars (Prop) = Property then
10330 return True;
10331 end if;
10333 Next (Prop);
10334 end loop;
10336 -- Property with expression form
10338 Prop := First (Component_Associations (Props));
10339 while Present (Prop) loop
10340 Prop_Nam := First (Choices (Prop));
10342 -- The property can be represented in two ways:
10343 -- others => <value>
10344 -- <property> => <value>
10346 if Nkind (Prop_Nam) = N_Others_Choice
10347 or else (Nkind (Prop_Nam) = N_Identifier
10348 and then Chars (Prop_Nam) = Property)
10349 then
10350 return Is_True (Expr_Value (Expression (Prop)));
10351 end if;
10353 Next (Prop);
10354 end loop;
10356 -- Single property
10358 else
10359 return Chars (Props) = Property;
10360 end if;
10361 end if;
10363 Next (Opt);
10364 end loop;
10366 return False;
10367 end State_Has_Enabled_Property;
10369 -----------------------------------
10370 -- Variable_Has_Enabled_Property --
10371 -----------------------------------
10373 function Variable_Has_Enabled_Property return Boolean is
10374 function Is_Enabled (Prag : Node_Id) return Boolean;
10375 -- Determine whether property pragma Prag (if present) denotes an
10376 -- enabled property.
10378 ----------------
10379 -- Is_Enabled --
10380 ----------------
10382 function Is_Enabled (Prag : Node_Id) return Boolean is
10383 Arg1 : Node_Id;
10385 begin
10386 if Present (Prag) then
10387 Arg1 := First (Pragma_Argument_Associations (Prag));
10389 -- The pragma has an optional Boolean expression, the related
10390 -- property is enabled only when the expression evaluates to
10391 -- True.
10393 if Present (Arg1) then
10394 return Is_True (Expr_Value (Get_Pragma_Arg (Arg1)));
10396 -- Otherwise the lack of expression enables the property by
10397 -- default.
10399 else
10400 return True;
10401 end if;
10403 -- The property was never set in the first place
10405 else
10406 return False;
10407 end if;
10408 end Is_Enabled;
10410 -- Local variables
10412 AR : constant Node_Id :=
10413 Get_Pragma (Item_Id, Pragma_Async_Readers);
10414 AW : constant Node_Id :=
10415 Get_Pragma (Item_Id, Pragma_Async_Writers);
10416 ER : constant Node_Id :=
10417 Get_Pragma (Item_Id, Pragma_Effective_Reads);
10418 EW : constant Node_Id :=
10419 Get_Pragma (Item_Id, Pragma_Effective_Writes);
10421 -- Start of processing for Variable_Has_Enabled_Property
10423 begin
10424 -- A non-effectively volatile object can never possess external
10425 -- properties.
10427 if not Is_Effectively_Volatile (Item_Id) then
10428 return False;
10430 -- External properties related to variables come in two flavors -
10431 -- explicit and implicit. The explicit case is characterized by the
10432 -- presence of a property pragma with an optional Boolean flag. The
10433 -- property is enabled when the flag evaluates to True or the flag is
10434 -- missing altogether.
10436 elsif Property = Name_Async_Readers and then Is_Enabled (AR) then
10437 return True;
10439 elsif Property = Name_Async_Writers and then Is_Enabled (AW) then
10440 return True;
10442 elsif Property = Name_Effective_Reads and then Is_Enabled (ER) then
10443 return True;
10445 elsif Property = Name_Effective_Writes and then Is_Enabled (EW) then
10446 return True;
10448 -- The implicit case lacks all property pragmas
10450 elsif No (AR) and then No (AW) and then No (ER) and then No (EW) then
10451 if Is_Protected_Type (Etype (Item_Id)) then
10452 return Protected_Object_Has_Enabled_Property;
10453 else
10454 return True;
10455 end if;
10457 else
10458 return False;
10459 end if;
10460 end Variable_Has_Enabled_Property;
10462 -- Start of processing for Has_Enabled_Property
10464 begin
10465 -- Abstract states and variables have a flexible scheme of specifying
10466 -- external properties.
10468 if Ekind (Item_Id) = E_Abstract_State then
10469 return State_Has_Enabled_Property;
10471 elsif Ekind (Item_Id) = E_Variable then
10472 return Variable_Has_Enabled_Property;
10474 -- By default, protected objects only have the properties Async_Readers
10475 -- and Async_Writers. If they have Part_Of components, they also inherit
10476 -- their properties Effective_Reads and Effective_Writes
10477 -- (SPARK RM 7.1.2(16)).
10479 elsif Ekind (Item_Id) = E_Protected_Object then
10480 return Protected_Object_Has_Enabled_Property;
10482 -- Otherwise a property is enabled when the related item is effectively
10483 -- volatile.
10485 else
10486 return Is_Effectively_Volatile (Item_Id);
10487 end if;
10488 end Has_Enabled_Property;
10490 -------------------------------------
10491 -- Has_Full_Default_Initialization --
10492 -------------------------------------
10494 function Has_Full_Default_Initialization (Typ : Entity_Id) return Boolean is
10495 Comp : Entity_Id;
10497 begin
10498 -- A type subject to pragma Default_Initial_Condition may be fully
10499 -- default initialized depending on inheritance and the argument of
10500 -- the pragma. Since any type may act as the full view of a private
10501 -- type, this check must be performed prior to the specialized tests
10502 -- below.
10504 if Has_Fully_Default_Initializing_DIC_Pragma (Typ) then
10505 return True;
10506 end if;
10508 -- A scalar type is fully default initialized if it is subject to aspect
10509 -- Default_Value.
10511 if Is_Scalar_Type (Typ) then
10512 return Has_Default_Aspect (Typ);
10514 -- An array type is fully default initialized if its element type is
10515 -- scalar and the array type carries aspect Default_Component_Value or
10516 -- the element type is fully default initialized.
10518 elsif Is_Array_Type (Typ) then
10519 return
10520 Has_Default_Aspect (Typ)
10521 or else Has_Full_Default_Initialization (Component_Type (Typ));
10523 -- A protected type, record type, or type extension is fully default
10524 -- initialized if all its components either carry an initialization
10525 -- expression or have a type that is fully default initialized. The
10526 -- parent type of a type extension must be fully default initialized.
10528 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
10530 -- Inspect all entities defined in the scope of the type, looking for
10531 -- uninitialized components.
10533 Comp := First_Entity (Typ);
10534 while Present (Comp) loop
10535 if Ekind (Comp) = E_Component
10536 and then Comes_From_Source (Comp)
10537 and then No (Expression (Parent (Comp)))
10538 and then not Has_Full_Default_Initialization (Etype (Comp))
10539 then
10540 return False;
10541 end if;
10543 Next_Entity (Comp);
10544 end loop;
10546 -- Ensure that the parent type of a type extension is fully default
10547 -- initialized.
10549 if Etype (Typ) /= Typ
10550 and then not Has_Full_Default_Initialization (Etype (Typ))
10551 then
10552 return False;
10553 end if;
10555 -- If we get here, then all components and parent portion are fully
10556 -- default initialized.
10558 return True;
10560 -- A task type is fully default initialized by default
10562 elsif Is_Task_Type (Typ) then
10563 return True;
10565 -- Otherwise the type is not fully default initialized
10567 else
10568 return False;
10569 end if;
10570 end Has_Full_Default_Initialization;
10572 -----------------------------------------------
10573 -- Has_Fully_Default_Initializing_DIC_Pragma --
10574 -----------------------------------------------
10576 function Has_Fully_Default_Initializing_DIC_Pragma
10577 (Typ : Entity_Id) return Boolean
10579 Args : List_Id;
10580 Prag : Node_Id;
10582 begin
10583 -- A type that inherits pragma Default_Initial_Condition from a parent
10584 -- type is automatically fully default initialized.
10586 if Has_Inherited_DIC (Typ) then
10587 return True;
10589 -- Otherwise the type is fully default initialized only when the pragma
10590 -- appears without an argument, or the argument is non-null.
10592 elsif Has_Own_DIC (Typ) then
10593 Prag := Get_Pragma (Typ, Pragma_Default_Initial_Condition);
10594 pragma Assert (Present (Prag));
10595 Args := Pragma_Argument_Associations (Prag);
10597 -- The pragma appears without an argument in which case it defaults
10598 -- to True.
10600 if No (Args) then
10601 return True;
10603 -- The pragma appears with a non-null expression
10605 elsif Nkind (Get_Pragma_Arg (First (Args))) /= N_Null then
10606 return True;
10607 end if;
10608 end if;
10610 return False;
10611 end Has_Fully_Default_Initializing_DIC_Pragma;
10613 --------------------
10614 -- Has_Infinities --
10615 --------------------
10617 function Has_Infinities (E : Entity_Id) return Boolean is
10618 begin
10619 return
10620 Is_Floating_Point_Type (E)
10621 and then Nkind (Scalar_Range (E)) = N_Range
10622 and then Includes_Infinities (Scalar_Range (E));
10623 end Has_Infinities;
10625 --------------------
10626 -- Has_Interfaces --
10627 --------------------
10629 function Has_Interfaces
10630 (T : Entity_Id;
10631 Use_Full_View : Boolean := True) return Boolean
10633 Typ : Entity_Id := Base_Type (T);
10635 begin
10636 -- Handle concurrent types
10638 if Is_Concurrent_Type (Typ) then
10639 Typ := Corresponding_Record_Type (Typ);
10640 end if;
10642 if not Present (Typ)
10643 or else not Is_Record_Type (Typ)
10644 or else not Is_Tagged_Type (Typ)
10645 then
10646 return False;
10647 end if;
10649 -- Handle private types
10651 if Use_Full_View and then Present (Full_View (Typ)) then
10652 Typ := Full_View (Typ);
10653 end if;
10655 -- Handle concurrent record types
10657 if Is_Concurrent_Record_Type (Typ)
10658 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
10659 then
10660 return True;
10661 end if;
10663 loop
10664 if Is_Interface (Typ)
10665 or else
10666 (Is_Record_Type (Typ)
10667 and then Present (Interfaces (Typ))
10668 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
10669 then
10670 return True;
10671 end if;
10673 exit when Etype (Typ) = Typ
10675 -- Handle private types
10677 or else (Present (Full_View (Etype (Typ)))
10678 and then Full_View (Etype (Typ)) = Typ)
10680 -- Protect frontend against wrong sources with cyclic derivations
10682 or else Etype (Typ) = T;
10684 -- Climb to the ancestor type handling private types
10686 if Present (Full_View (Etype (Typ))) then
10687 Typ := Full_View (Etype (Typ));
10688 else
10689 Typ := Etype (Typ);
10690 end if;
10691 end loop;
10693 return False;
10694 end Has_Interfaces;
10696 --------------------------
10697 -- Has_Max_Queue_Length --
10698 --------------------------
10700 function Has_Max_Queue_Length (Id : Entity_Id) return Boolean is
10701 begin
10702 return
10703 Ekind (Id) = E_Entry
10704 and then Present (Get_Pragma (Id, Pragma_Max_Queue_Length));
10705 end Has_Max_Queue_Length;
10707 ---------------------------------
10708 -- Has_No_Obvious_Side_Effects --
10709 ---------------------------------
10711 function Has_No_Obvious_Side_Effects (N : Node_Id) return Boolean is
10712 begin
10713 -- For now handle literals, constants, and non-volatile variables and
10714 -- expressions combining these with operators or short circuit forms.
10716 if Nkind (N) in N_Numeric_Or_String_Literal then
10717 return True;
10719 elsif Nkind (N) = N_Character_Literal then
10720 return True;
10722 elsif Nkind (N) in N_Unary_Op then
10723 return Has_No_Obvious_Side_Effects (Right_Opnd (N));
10725 elsif Nkind (N) in N_Binary_Op or else Nkind (N) in N_Short_Circuit then
10726 return Has_No_Obvious_Side_Effects (Left_Opnd (N))
10727 and then
10728 Has_No_Obvious_Side_Effects (Right_Opnd (N));
10730 elsif Nkind (N) = N_Expression_With_Actions
10731 and then Is_Empty_List (Actions (N))
10732 then
10733 return Has_No_Obvious_Side_Effects (Expression (N));
10735 elsif Nkind (N) in N_Has_Entity then
10736 return Present (Entity (N))
10737 and then Ekind_In (Entity (N), E_Variable,
10738 E_Constant,
10739 E_Enumeration_Literal,
10740 E_In_Parameter,
10741 E_Out_Parameter,
10742 E_In_Out_Parameter)
10743 and then not Is_Volatile (Entity (N));
10745 else
10746 return False;
10747 end if;
10748 end Has_No_Obvious_Side_Effects;
10750 -----------------------------
10751 -- Has_Non_Null_Refinement --
10752 -----------------------------
10754 function Has_Non_Null_Refinement (Id : Entity_Id) return Boolean is
10755 Constits : Elist_Id;
10757 begin
10758 pragma Assert (Ekind (Id) = E_Abstract_State);
10759 Constits := Refinement_Constituents (Id);
10761 -- For a refinement to be non-null, the first constituent must be
10762 -- anything other than null.
10764 return
10765 Present (Constits)
10766 and then Nkind (Node (First_Elmt (Constits))) /= N_Null;
10767 end Has_Non_Null_Refinement;
10769 -----------------------------
10770 -- Has_Non_Null_Statements --
10771 -----------------------------
10773 function Has_Non_Null_Statements (L : List_Id) return Boolean is
10774 Node : Node_Id;
10776 begin
10777 if Is_Non_Empty_List (L) then
10778 Node := First (L);
10780 loop
10781 if Nkind (Node) /= N_Null_Statement then
10782 return True;
10783 end if;
10785 Next (Node);
10786 exit when Node = Empty;
10787 end loop;
10788 end if;
10790 return False;
10791 end Has_Non_Null_Statements;
10793 ----------------------------------
10794 -- Has_Non_Trivial_Precondition --
10795 ----------------------------------
10797 function Has_Non_Trivial_Precondition (Subp : Entity_Id) return Boolean is
10798 Pre : constant Node_Id := Find_Aspect (Subp, Aspect_Pre);
10800 begin
10801 return
10802 Present (Pre)
10803 and then Class_Present (Pre)
10804 and then not Is_Entity_Name (Expression (Pre));
10805 end Has_Non_Trivial_Precondition;
10807 -------------------
10808 -- Has_Null_Body --
10809 -------------------
10811 function Has_Null_Body (Proc_Id : Entity_Id) return Boolean is
10812 Body_Id : Entity_Id;
10813 Decl : Node_Id;
10814 Spec : Node_Id;
10815 Stmt1 : Node_Id;
10816 Stmt2 : Node_Id;
10818 begin
10819 Spec := Parent (Proc_Id);
10820 Decl := Parent (Spec);
10822 -- Retrieve the entity of the procedure body (e.g. invariant proc).
10824 if Nkind (Spec) = N_Procedure_Specification
10825 and then Nkind (Decl) = N_Subprogram_Declaration
10826 then
10827 Body_Id := Corresponding_Body (Decl);
10829 -- The body acts as a spec
10831 else
10832 Body_Id := Proc_Id;
10833 end if;
10835 -- The body will be generated later
10837 if No (Body_Id) then
10838 return False;
10839 end if;
10841 Spec := Parent (Body_Id);
10842 Decl := Parent (Spec);
10844 pragma Assert
10845 (Nkind (Spec) = N_Procedure_Specification
10846 and then Nkind (Decl) = N_Subprogram_Body);
10848 Stmt1 := First (Statements (Handled_Statement_Sequence (Decl)));
10850 -- Look for a null statement followed by an optional return
10851 -- statement.
10853 if Nkind (Stmt1) = N_Null_Statement then
10854 Stmt2 := Next (Stmt1);
10856 if Present (Stmt2) then
10857 return Nkind (Stmt2) = N_Simple_Return_Statement;
10858 else
10859 return True;
10860 end if;
10861 end if;
10863 return False;
10864 end Has_Null_Body;
10866 ------------------------
10867 -- Has_Null_Exclusion --
10868 ------------------------
10870 function Has_Null_Exclusion (N : Node_Id) return Boolean is
10871 begin
10872 case Nkind (N) is
10873 when N_Access_Definition
10874 | N_Access_Function_Definition
10875 | N_Access_Procedure_Definition
10876 | N_Access_To_Object_Definition
10877 | N_Allocator
10878 | N_Derived_Type_Definition
10879 | N_Function_Specification
10880 | N_Subtype_Declaration
10882 return Null_Exclusion_Present (N);
10884 when N_Component_Definition
10885 | N_Formal_Object_Declaration
10886 | N_Object_Renaming_Declaration
10888 if Present (Subtype_Mark (N)) then
10889 return Null_Exclusion_Present (N);
10890 else pragma Assert (Present (Access_Definition (N)));
10891 return Null_Exclusion_Present (Access_Definition (N));
10892 end if;
10894 when N_Discriminant_Specification =>
10895 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
10896 return Null_Exclusion_Present (Discriminant_Type (N));
10897 else
10898 return Null_Exclusion_Present (N);
10899 end if;
10901 when N_Object_Declaration =>
10902 if Nkind (Object_Definition (N)) = N_Access_Definition then
10903 return Null_Exclusion_Present (Object_Definition (N));
10904 else
10905 return Null_Exclusion_Present (N);
10906 end if;
10908 when N_Parameter_Specification =>
10909 if Nkind (Parameter_Type (N)) = N_Access_Definition then
10910 return Null_Exclusion_Present (Parameter_Type (N));
10911 else
10912 return Null_Exclusion_Present (N);
10913 end if;
10915 when others =>
10916 return False;
10917 end case;
10918 end Has_Null_Exclusion;
10920 ------------------------
10921 -- Has_Null_Extension --
10922 ------------------------
10924 function Has_Null_Extension (T : Entity_Id) return Boolean is
10925 B : constant Entity_Id := Base_Type (T);
10926 Comps : Node_Id;
10927 Ext : Node_Id;
10929 begin
10930 if Nkind (Parent (B)) = N_Full_Type_Declaration
10931 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
10932 then
10933 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
10935 if Present (Ext) then
10936 if Null_Present (Ext) then
10937 return True;
10938 else
10939 Comps := Component_List (Ext);
10941 -- The null component list is rewritten during analysis to
10942 -- include the parent component. Any other component indicates
10943 -- that the extension was not originally null.
10945 return Null_Present (Comps)
10946 or else No (Next (First (Component_Items (Comps))));
10947 end if;
10948 else
10949 return False;
10950 end if;
10952 else
10953 return False;
10954 end if;
10955 end Has_Null_Extension;
10957 -------------------------
10958 -- Has_Null_Refinement --
10959 -------------------------
10961 function Has_Null_Refinement (Id : Entity_Id) return Boolean is
10962 Constits : Elist_Id;
10964 begin
10965 pragma Assert (Ekind (Id) = E_Abstract_State);
10966 Constits := Refinement_Constituents (Id);
10968 -- For a refinement to be null, the state's sole constituent must be a
10969 -- null.
10971 return
10972 Present (Constits)
10973 and then Nkind (Node (First_Elmt (Constits))) = N_Null;
10974 end Has_Null_Refinement;
10976 -------------------------------
10977 -- Has_Overriding_Initialize --
10978 -------------------------------
10980 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
10981 BT : constant Entity_Id := Base_Type (T);
10982 P : Elmt_Id;
10984 begin
10985 if Is_Controlled (BT) then
10986 if Is_RTU (Scope (BT), Ada_Finalization) then
10987 return False;
10989 elsif Present (Primitive_Operations (BT)) then
10990 P := First_Elmt (Primitive_Operations (BT));
10991 while Present (P) loop
10992 declare
10993 Init : constant Entity_Id := Node (P);
10994 Formal : constant Entity_Id := First_Formal (Init);
10995 begin
10996 if Ekind (Init) = E_Procedure
10997 and then Chars (Init) = Name_Initialize
10998 and then Comes_From_Source (Init)
10999 and then Present (Formal)
11000 and then Etype (Formal) = BT
11001 and then No (Next_Formal (Formal))
11002 and then (Ada_Version < Ada_2012
11003 or else not Null_Present (Parent (Init)))
11004 then
11005 return True;
11006 end if;
11007 end;
11009 Next_Elmt (P);
11010 end loop;
11011 end if;
11013 -- Here if type itself does not have a non-null Initialize operation:
11014 -- check immediate ancestor.
11016 if Is_Derived_Type (BT)
11017 and then Has_Overriding_Initialize (Etype (BT))
11018 then
11019 return True;
11020 end if;
11021 end if;
11023 return False;
11024 end Has_Overriding_Initialize;
11026 --------------------------------------
11027 -- Has_Preelaborable_Initialization --
11028 --------------------------------------
11030 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
11031 Has_PE : Boolean;
11033 procedure Check_Components (E : Entity_Id);
11034 -- Check component/discriminant chain, sets Has_PE False if a component
11035 -- or discriminant does not meet the preelaborable initialization rules.
11037 ----------------------
11038 -- Check_Components --
11039 ----------------------
11041 procedure Check_Components (E : Entity_Id) is
11042 Ent : Entity_Id;
11043 Exp : Node_Id;
11045 begin
11046 -- Loop through entities of record or protected type
11048 Ent := E;
11049 while Present (Ent) loop
11051 -- We are interested only in components and discriminants
11053 Exp := Empty;
11055 case Ekind (Ent) is
11056 when E_Component =>
11058 -- Get default expression if any. If there is no declaration
11059 -- node, it means we have an internal entity. The parent and
11060 -- tag fields are examples of such entities. For such cases,
11061 -- we just test the type of the entity.
11063 if Present (Declaration_Node (Ent)) then
11064 Exp := Expression (Declaration_Node (Ent));
11065 end if;
11067 when E_Discriminant =>
11069 -- Note: for a renamed discriminant, the Declaration_Node
11070 -- may point to the one from the ancestor, and have a
11071 -- different expression, so use the proper attribute to
11072 -- retrieve the expression from the derived constraint.
11074 Exp := Discriminant_Default_Value (Ent);
11076 when others =>
11077 goto Check_Next_Entity;
11078 end case;
11080 -- A component has PI if it has no default expression and the
11081 -- component type has PI.
11083 if No (Exp) then
11084 if not Has_Preelaborable_Initialization (Etype (Ent)) then
11085 Has_PE := False;
11086 exit;
11087 end if;
11089 -- Require the default expression to be preelaborable
11091 elsif not Is_Preelaborable_Construct (Exp) then
11092 Has_PE := False;
11093 exit;
11094 end if;
11096 <<Check_Next_Entity>>
11097 Next_Entity (Ent);
11098 end loop;
11099 end Check_Components;
11101 -- Start of processing for Has_Preelaborable_Initialization
11103 begin
11104 -- Immediate return if already marked as known preelaborable init. This
11105 -- covers types for which this function has already been called once
11106 -- and returned True (in which case the result is cached), and also
11107 -- types to which a pragma Preelaborable_Initialization applies.
11109 if Known_To_Have_Preelab_Init (E) then
11110 return True;
11111 end if;
11113 -- If the type is a subtype representing a generic actual type, then
11114 -- test whether its base type has preelaborable initialization since
11115 -- the subtype representing the actual does not inherit this attribute
11116 -- from the actual or formal. (but maybe it should???)
11118 if Is_Generic_Actual_Type (E) then
11119 return Has_Preelaborable_Initialization (Base_Type (E));
11120 end if;
11122 -- All elementary types have preelaborable initialization
11124 if Is_Elementary_Type (E) then
11125 Has_PE := True;
11127 -- Array types have PI if the component type has PI
11129 elsif Is_Array_Type (E) then
11130 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
11132 -- A derived type has preelaborable initialization if its parent type
11133 -- has preelaborable initialization and (in the case of a derived record
11134 -- extension) if the non-inherited components all have preelaborable
11135 -- initialization. However, a user-defined controlled type with an
11136 -- overriding Initialize procedure does not have preelaborable
11137 -- initialization.
11139 elsif Is_Derived_Type (E) then
11141 -- If the derived type is a private extension then it doesn't have
11142 -- preelaborable initialization.
11144 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
11145 return False;
11146 end if;
11148 -- First check whether ancestor type has preelaborable initialization
11150 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
11152 -- If OK, check extension components (if any)
11154 if Has_PE and then Is_Record_Type (E) then
11155 Check_Components (First_Entity (E));
11156 end if;
11158 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
11159 -- with a user defined Initialize procedure does not have PI. If
11160 -- the type is untagged, the control primitives come from a component
11161 -- that has already been checked.
11163 if Has_PE
11164 and then Is_Controlled (E)
11165 and then Is_Tagged_Type (E)
11166 and then Has_Overriding_Initialize (E)
11167 then
11168 Has_PE := False;
11169 end if;
11171 -- Private types not derived from a type having preelaborable init and
11172 -- that are not marked with pragma Preelaborable_Initialization do not
11173 -- have preelaborable initialization.
11175 elsif Is_Private_Type (E) then
11176 return False;
11178 -- Record type has PI if it is non private and all components have PI
11180 elsif Is_Record_Type (E) then
11181 Has_PE := True;
11182 Check_Components (First_Entity (E));
11184 -- Protected types must not have entries, and components must meet
11185 -- same set of rules as for record components.
11187 elsif Is_Protected_Type (E) then
11188 if Has_Entries (E) then
11189 Has_PE := False;
11190 else
11191 Has_PE := True;
11192 Check_Components (First_Entity (E));
11193 Check_Components (First_Private_Entity (E));
11194 end if;
11196 -- Type System.Address always has preelaborable initialization
11198 elsif Is_RTE (E, RE_Address) then
11199 Has_PE := True;
11201 -- In all other cases, type does not have preelaborable initialization
11203 else
11204 return False;
11205 end if;
11207 -- If type has preelaborable initialization, cache result
11209 if Has_PE then
11210 Set_Known_To_Have_Preelab_Init (E);
11211 end if;
11213 return Has_PE;
11214 end Has_Preelaborable_Initialization;
11216 ---------------------------
11217 -- Has_Private_Component --
11218 ---------------------------
11220 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
11221 Btype : Entity_Id := Base_Type (Type_Id);
11222 Component : Entity_Id;
11224 begin
11225 if Error_Posted (Type_Id)
11226 or else Error_Posted (Btype)
11227 then
11228 return False;
11229 end if;
11231 if Is_Class_Wide_Type (Btype) then
11232 Btype := Root_Type (Btype);
11233 end if;
11235 if Is_Private_Type (Btype) then
11236 declare
11237 UT : constant Entity_Id := Underlying_Type (Btype);
11238 begin
11239 if No (UT) then
11240 if No (Full_View (Btype)) then
11241 return not Is_Generic_Type (Btype)
11242 and then
11243 not Is_Generic_Type (Root_Type (Btype));
11244 else
11245 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
11246 end if;
11247 else
11248 return not Is_Frozen (UT) and then Has_Private_Component (UT);
11249 end if;
11250 end;
11252 elsif Is_Array_Type (Btype) then
11253 return Has_Private_Component (Component_Type (Btype));
11255 elsif Is_Record_Type (Btype) then
11256 Component := First_Component (Btype);
11257 while Present (Component) loop
11258 if Has_Private_Component (Etype (Component)) then
11259 return True;
11260 end if;
11262 Next_Component (Component);
11263 end loop;
11265 return False;
11267 elsif Is_Protected_Type (Btype)
11268 and then Present (Corresponding_Record_Type (Btype))
11269 then
11270 return Has_Private_Component (Corresponding_Record_Type (Btype));
11272 else
11273 return False;
11274 end if;
11275 end Has_Private_Component;
11277 ----------------------
11278 -- Has_Signed_Zeros --
11279 ----------------------
11281 function Has_Signed_Zeros (E : Entity_Id) return Boolean is
11282 begin
11283 return Is_Floating_Point_Type (E) and then Signed_Zeros_On_Target;
11284 end Has_Signed_Zeros;
11286 ------------------------------
11287 -- Has_Significant_Contract --
11288 ------------------------------
11290 function Has_Significant_Contract (Subp_Id : Entity_Id) return Boolean is
11291 Subp_Nam : constant Name_Id := Chars (Subp_Id);
11293 begin
11294 -- _Finalizer procedure
11296 if Subp_Nam = Name_uFinalizer then
11297 return False;
11299 -- _Postconditions procedure
11301 elsif Subp_Nam = Name_uPostconditions then
11302 return False;
11304 -- Predicate function
11306 elsif Ekind (Subp_Id) = E_Function
11307 and then Is_Predicate_Function (Subp_Id)
11308 then
11309 return False;
11311 -- TSS subprogram
11313 elsif Get_TSS_Name (Subp_Id) /= TSS_Null then
11314 return False;
11316 else
11317 return True;
11318 end if;
11319 end Has_Significant_Contract;
11321 -----------------------------
11322 -- Has_Static_Array_Bounds --
11323 -----------------------------
11325 function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is
11326 Ndims : constant Nat := Number_Dimensions (Typ);
11328 Index : Node_Id;
11329 Low : Node_Id;
11330 High : Node_Id;
11332 begin
11333 -- Unconstrained types do not have static bounds
11335 if not Is_Constrained (Typ) then
11336 return False;
11337 end if;
11339 -- First treat string literals specially, as the lower bound and length
11340 -- of string literals are not stored like those of arrays.
11342 -- A string literal always has static bounds
11344 if Ekind (Typ) = E_String_Literal_Subtype then
11345 return True;
11346 end if;
11348 -- Treat all dimensions in turn
11350 Index := First_Index (Typ);
11351 for Indx in 1 .. Ndims loop
11353 -- In case of an illegal index which is not a discrete type, return
11354 -- that the type is not static.
11356 if not Is_Discrete_Type (Etype (Index))
11357 or else Etype (Index) = Any_Type
11358 then
11359 return False;
11360 end if;
11362 Get_Index_Bounds (Index, Low, High);
11364 if Error_Posted (Low) or else Error_Posted (High) then
11365 return False;
11366 end if;
11368 if Is_OK_Static_Expression (Low)
11369 and then
11370 Is_OK_Static_Expression (High)
11371 then
11372 null;
11373 else
11374 return False;
11375 end if;
11377 Next (Index);
11378 end loop;
11380 -- If we fall through the loop, all indexes matched
11382 return True;
11383 end Has_Static_Array_Bounds;
11385 ----------------
11386 -- Has_Stream --
11387 ----------------
11389 function Has_Stream (T : Entity_Id) return Boolean is
11390 E : Entity_Id;
11392 begin
11393 if No (T) then
11394 return False;
11396 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
11397 return True;
11399 elsif Is_Array_Type (T) then
11400 return Has_Stream (Component_Type (T));
11402 elsif Is_Record_Type (T) then
11403 E := First_Component (T);
11404 while Present (E) loop
11405 if Has_Stream (Etype (E)) then
11406 return True;
11407 else
11408 Next_Component (E);
11409 end if;
11410 end loop;
11412 return False;
11414 elsif Is_Private_Type (T) then
11415 return Has_Stream (Underlying_Type (T));
11417 else
11418 return False;
11419 end if;
11420 end Has_Stream;
11422 ----------------
11423 -- Has_Suffix --
11424 ----------------
11426 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
11427 begin
11428 Get_Name_String (Chars (E));
11429 return Name_Buffer (Name_Len) = Suffix;
11430 end Has_Suffix;
11432 ----------------
11433 -- Add_Suffix --
11434 ----------------
11436 function Add_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
11437 begin
11438 Get_Name_String (Chars (E));
11439 Add_Char_To_Name_Buffer (Suffix);
11440 return Name_Find;
11441 end Add_Suffix;
11443 -------------------
11444 -- Remove_Suffix --
11445 -------------------
11447 function Remove_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
11448 begin
11449 pragma Assert (Has_Suffix (E, Suffix));
11450 Get_Name_String (Chars (E));
11451 Name_Len := Name_Len - 1;
11452 return Name_Find;
11453 end Remove_Suffix;
11455 ----------------------------------
11456 -- Replace_Null_By_Null_Address --
11457 ----------------------------------
11459 procedure Replace_Null_By_Null_Address (N : Node_Id) is
11460 procedure Replace_Null_Operand (Op : Node_Id; Other_Op : Node_Id);
11461 -- Replace operand Op with a reference to Null_Address when the operand
11462 -- denotes a null Address. Other_Op denotes the other operand.
11464 --------------------------
11465 -- Replace_Null_Operand --
11466 --------------------------
11468 procedure Replace_Null_Operand (Op : Node_Id; Other_Op : Node_Id) is
11469 begin
11470 -- Check the type of the complementary operand since the N_Null node
11471 -- has not been decorated yet.
11473 if Nkind (Op) = N_Null
11474 and then Is_Descendant_Of_Address (Etype (Other_Op))
11475 then
11476 Rewrite (Op, New_Occurrence_Of (RTE (RE_Null_Address), Sloc (Op)));
11477 end if;
11478 end Replace_Null_Operand;
11480 -- Start of processing for Replace_Null_By_Null_Address
11482 begin
11483 pragma Assert (Relaxed_RM_Semantics);
11484 pragma Assert (Nkind_In (N, N_Null,
11485 N_Op_Eq,
11486 N_Op_Ge,
11487 N_Op_Gt,
11488 N_Op_Le,
11489 N_Op_Lt,
11490 N_Op_Ne));
11492 if Nkind (N) = N_Null then
11493 Rewrite (N, New_Occurrence_Of (RTE (RE_Null_Address), Sloc (N)));
11495 else
11496 declare
11497 L : constant Node_Id := Left_Opnd (N);
11498 R : constant Node_Id := Right_Opnd (N);
11500 begin
11501 Replace_Null_Operand (L, Other_Op => R);
11502 Replace_Null_Operand (R, Other_Op => L);
11503 end;
11504 end if;
11505 end Replace_Null_By_Null_Address;
11507 --------------------------
11508 -- Has_Tagged_Component --
11509 --------------------------
11511 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
11512 Comp : Entity_Id;
11514 begin
11515 if Is_Private_Type (Typ) and then Present (Underlying_Type (Typ)) then
11516 return Has_Tagged_Component (Underlying_Type (Typ));
11518 elsif Is_Array_Type (Typ) then
11519 return Has_Tagged_Component (Component_Type (Typ));
11521 elsif Is_Tagged_Type (Typ) then
11522 return True;
11524 elsif Is_Record_Type (Typ) then
11525 Comp := First_Component (Typ);
11526 while Present (Comp) loop
11527 if Has_Tagged_Component (Etype (Comp)) then
11528 return True;
11529 end if;
11531 Next_Component (Comp);
11532 end loop;
11534 return False;
11536 else
11537 return False;
11538 end if;
11539 end Has_Tagged_Component;
11541 -----------------------------
11542 -- Has_Undefined_Reference --
11543 -----------------------------
11545 function Has_Undefined_Reference (Expr : Node_Id) return Boolean is
11546 Has_Undef_Ref : Boolean := False;
11547 -- Flag set when expression Expr contains at least one undefined
11548 -- reference.
11550 function Is_Undefined_Reference (N : Node_Id) return Traverse_Result;
11551 -- Determine whether N denotes a reference and if it does, whether it is
11552 -- undefined.
11554 ----------------------------
11555 -- Is_Undefined_Reference --
11556 ----------------------------
11558 function Is_Undefined_Reference (N : Node_Id) return Traverse_Result is
11559 begin
11560 if Is_Entity_Name (N)
11561 and then Present (Entity (N))
11562 and then Entity (N) = Any_Id
11563 then
11564 Has_Undef_Ref := True;
11565 return Abandon;
11566 end if;
11568 return OK;
11569 end Is_Undefined_Reference;
11571 procedure Find_Undefined_References is
11572 new Traverse_Proc (Is_Undefined_Reference);
11574 -- Start of processing for Has_Undefined_Reference
11576 begin
11577 Find_Undefined_References (Expr);
11579 return Has_Undef_Ref;
11580 end Has_Undefined_Reference;
11582 ----------------------------
11583 -- Has_Volatile_Component --
11584 ----------------------------
11586 function Has_Volatile_Component (Typ : Entity_Id) return Boolean is
11587 Comp : Entity_Id;
11589 begin
11590 if Has_Volatile_Components (Typ) then
11591 return True;
11593 elsif Is_Array_Type (Typ) then
11594 return Is_Volatile (Component_Type (Typ));
11596 elsif Is_Record_Type (Typ) then
11597 Comp := First_Component (Typ);
11598 while Present (Comp) loop
11599 if Is_Volatile_Object (Comp) then
11600 return True;
11601 end if;
11603 Comp := Next_Component (Comp);
11604 end loop;
11605 end if;
11607 return False;
11608 end Has_Volatile_Component;
11610 -------------------------
11611 -- Implementation_Kind --
11612 -------------------------
11614 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
11615 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
11616 Arg : Node_Id;
11617 begin
11618 pragma Assert (Present (Impl_Prag));
11619 Arg := Last (Pragma_Argument_Associations (Impl_Prag));
11620 return Chars (Get_Pragma_Arg (Arg));
11621 end Implementation_Kind;
11623 --------------------------
11624 -- Implements_Interface --
11625 --------------------------
11627 function Implements_Interface
11628 (Typ_Ent : Entity_Id;
11629 Iface_Ent : Entity_Id;
11630 Exclude_Parents : Boolean := False) return Boolean
11632 Ifaces_List : Elist_Id;
11633 Elmt : Elmt_Id;
11634 Iface : Entity_Id := Base_Type (Iface_Ent);
11635 Typ : Entity_Id := Base_Type (Typ_Ent);
11637 begin
11638 if Is_Class_Wide_Type (Typ) then
11639 Typ := Root_Type (Typ);
11640 end if;
11642 if not Has_Interfaces (Typ) then
11643 return False;
11644 end if;
11646 if Is_Class_Wide_Type (Iface) then
11647 Iface := Root_Type (Iface);
11648 end if;
11650 Collect_Interfaces (Typ, Ifaces_List);
11652 Elmt := First_Elmt (Ifaces_List);
11653 while Present (Elmt) loop
11654 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
11655 and then Exclude_Parents
11656 then
11657 null;
11659 elsif Node (Elmt) = Iface then
11660 return True;
11661 end if;
11663 Next_Elmt (Elmt);
11664 end loop;
11666 return False;
11667 end Implements_Interface;
11669 ------------------------------------
11670 -- In_Assertion_Expression_Pragma --
11671 ------------------------------------
11673 function In_Assertion_Expression_Pragma (N : Node_Id) return Boolean is
11674 Par : Node_Id;
11675 Prag : Node_Id := Empty;
11677 begin
11678 -- Climb the parent chain looking for an enclosing pragma
11680 Par := N;
11681 while Present (Par) loop
11682 if Nkind (Par) = N_Pragma then
11683 Prag := Par;
11684 exit;
11686 -- Precondition-like pragmas are expanded into if statements, check
11687 -- the original node instead.
11689 elsif Nkind (Original_Node (Par)) = N_Pragma then
11690 Prag := Original_Node (Par);
11691 exit;
11693 -- The expansion of attribute 'Old generates a constant to capture
11694 -- the result of the prefix. If the parent traversal reaches
11695 -- one of these constants, then the node technically came from a
11696 -- postcondition-like pragma. Note that the Ekind is not tested here
11697 -- because N may be the expression of an object declaration which is
11698 -- currently being analyzed. Such objects carry Ekind of E_Void.
11700 elsif Nkind (Par) = N_Object_Declaration
11701 and then Constant_Present (Par)
11702 and then Stores_Attribute_Old_Prefix (Defining_Entity (Par))
11703 then
11704 return True;
11706 -- Prevent the search from going too far
11708 elsif Is_Body_Or_Package_Declaration (Par) then
11709 return False;
11710 end if;
11712 Par := Parent (Par);
11713 end loop;
11715 return
11716 Present (Prag)
11717 and then Assertion_Expression_Pragma (Get_Pragma_Id (Prag));
11718 end In_Assertion_Expression_Pragma;
11720 ----------------------
11721 -- In_Generic_Scope --
11722 ----------------------
11724 function In_Generic_Scope (E : Entity_Id) return Boolean is
11725 S : Entity_Id;
11727 begin
11728 S := Scope (E);
11729 while Present (S) and then S /= Standard_Standard loop
11730 if Is_Generic_Unit (S) then
11731 return True;
11732 end if;
11734 S := Scope (S);
11735 end loop;
11737 return False;
11738 end In_Generic_Scope;
11740 -----------------
11741 -- In_Instance --
11742 -----------------
11744 function In_Instance return Boolean is
11745 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
11746 S : Entity_Id;
11748 begin
11749 S := Current_Scope;
11750 while Present (S) and then S /= Standard_Standard loop
11751 if Is_Generic_Instance (S) then
11753 -- A child instance is always compiled in the context of a parent
11754 -- instance. Nevertheless, the actuals are not analyzed in an
11755 -- instance context. We detect this case by examining the current
11756 -- compilation unit, which must be a child instance, and checking
11757 -- that it is not currently on the scope stack.
11759 if Is_Child_Unit (Curr_Unit)
11760 and then Nkind (Unit (Cunit (Current_Sem_Unit))) =
11761 N_Package_Instantiation
11762 and then not In_Open_Scopes (Curr_Unit)
11763 then
11764 return False;
11765 else
11766 return True;
11767 end if;
11768 end if;
11770 S := Scope (S);
11771 end loop;
11773 return False;
11774 end In_Instance;
11776 ----------------------
11777 -- In_Instance_Body --
11778 ----------------------
11780 function In_Instance_Body return Boolean is
11781 S : Entity_Id;
11783 begin
11784 S := Current_Scope;
11785 while Present (S) and then S /= Standard_Standard loop
11786 if Ekind_In (S, E_Function, E_Procedure)
11787 and then Is_Generic_Instance (S)
11788 then
11789 return True;
11791 elsif Ekind (S) = E_Package
11792 and then In_Package_Body (S)
11793 and then Is_Generic_Instance (S)
11794 then
11795 return True;
11796 end if;
11798 S := Scope (S);
11799 end loop;
11801 return False;
11802 end In_Instance_Body;
11804 -----------------------------
11805 -- In_Instance_Not_Visible --
11806 -----------------------------
11808 function In_Instance_Not_Visible return Boolean is
11809 S : Entity_Id;
11811 begin
11812 S := Current_Scope;
11813 while Present (S) and then S /= Standard_Standard loop
11814 if Ekind_In (S, E_Function, E_Procedure)
11815 and then Is_Generic_Instance (S)
11816 then
11817 return True;
11819 elsif Ekind (S) = E_Package
11820 and then (In_Package_Body (S) or else In_Private_Part (S))
11821 and then Is_Generic_Instance (S)
11822 then
11823 return True;
11824 end if;
11826 S := Scope (S);
11827 end loop;
11829 return False;
11830 end In_Instance_Not_Visible;
11832 ------------------------------
11833 -- In_Instance_Visible_Part --
11834 ------------------------------
11836 function In_Instance_Visible_Part
11837 (Id : Entity_Id := Current_Scope) return Boolean
11839 Inst : Entity_Id;
11841 begin
11842 Inst := Id;
11843 while Present (Inst) and then Inst /= Standard_Standard loop
11844 if Ekind (Inst) = E_Package
11845 and then Is_Generic_Instance (Inst)
11846 and then not In_Package_Body (Inst)
11847 and then not In_Private_Part (Inst)
11848 then
11849 return True;
11850 end if;
11852 Inst := Scope (Inst);
11853 end loop;
11855 return False;
11856 end In_Instance_Visible_Part;
11858 ---------------------
11859 -- In_Package_Body --
11860 ---------------------
11862 function In_Package_Body return Boolean is
11863 S : Entity_Id;
11865 begin
11866 S := Current_Scope;
11867 while Present (S) and then S /= Standard_Standard loop
11868 if Ekind (S) = E_Package and then In_Package_Body (S) then
11869 return True;
11870 else
11871 S := Scope (S);
11872 end if;
11873 end loop;
11875 return False;
11876 end In_Package_Body;
11878 --------------------------
11879 -- In_Pragma_Expression --
11880 --------------------------
11882 function In_Pragma_Expression (N : Node_Id; Nam : Name_Id) return Boolean is
11883 P : Node_Id;
11884 begin
11885 P := Parent (N);
11886 loop
11887 if No (P) then
11888 return False;
11889 elsif Nkind (P) = N_Pragma and then Pragma_Name (P) = Nam then
11890 return True;
11891 else
11892 P := Parent (P);
11893 end if;
11894 end loop;
11895 end In_Pragma_Expression;
11897 ---------------------------
11898 -- In_Pre_Post_Condition --
11899 ---------------------------
11901 function In_Pre_Post_Condition (N : Node_Id) return Boolean is
11902 Par : Node_Id;
11903 Prag : Node_Id := Empty;
11904 Prag_Id : Pragma_Id;
11906 begin
11907 -- Climb the parent chain looking for an enclosing pragma
11909 Par := N;
11910 while Present (Par) loop
11911 if Nkind (Par) = N_Pragma then
11912 Prag := Par;
11913 exit;
11915 -- Prevent the search from going too far
11917 elsif Is_Body_Or_Package_Declaration (Par) then
11918 exit;
11919 end if;
11921 Par := Parent (Par);
11922 end loop;
11924 if Present (Prag) then
11925 Prag_Id := Get_Pragma_Id (Prag);
11927 return
11928 Prag_Id = Pragma_Post
11929 or else Prag_Id = Pragma_Post_Class
11930 or else Prag_Id = Pragma_Postcondition
11931 or else Prag_Id = Pragma_Pre
11932 or else Prag_Id = Pragma_Pre_Class
11933 or else Prag_Id = Pragma_Precondition;
11935 -- Otherwise the node is not enclosed by a pre/postcondition pragma
11937 else
11938 return False;
11939 end if;
11940 end In_Pre_Post_Condition;
11942 -------------------------------------
11943 -- In_Reverse_Storage_Order_Object --
11944 -------------------------------------
11946 function In_Reverse_Storage_Order_Object (N : Node_Id) return Boolean is
11947 Pref : Node_Id;
11948 Btyp : Entity_Id := Empty;
11950 begin
11951 -- Climb up indexed components
11953 Pref := N;
11954 loop
11955 case Nkind (Pref) is
11956 when N_Selected_Component =>
11957 Pref := Prefix (Pref);
11958 exit;
11960 when N_Indexed_Component =>
11961 Pref := Prefix (Pref);
11963 when others =>
11964 Pref := Empty;
11965 exit;
11966 end case;
11967 end loop;
11969 if Present (Pref) then
11970 Btyp := Base_Type (Etype (Pref));
11971 end if;
11973 return Present (Btyp)
11974 and then (Is_Record_Type (Btyp) or else Is_Array_Type (Btyp))
11975 and then Reverse_Storage_Order (Btyp);
11976 end In_Reverse_Storage_Order_Object;
11978 --------------------------------------
11979 -- In_Subprogram_Or_Concurrent_Unit --
11980 --------------------------------------
11982 function In_Subprogram_Or_Concurrent_Unit return Boolean is
11983 E : Entity_Id;
11984 K : Entity_Kind;
11986 begin
11987 -- Use scope chain to check successively outer scopes
11989 E := Current_Scope;
11990 loop
11991 K := Ekind (E);
11993 if K in Subprogram_Kind
11994 or else K in Concurrent_Kind
11995 or else K in Generic_Subprogram_Kind
11996 then
11997 return True;
11999 elsif E = Standard_Standard then
12000 return False;
12001 end if;
12003 E := Scope (E);
12004 end loop;
12005 end In_Subprogram_Or_Concurrent_Unit;
12007 ----------------
12008 -- In_Subtree --
12009 ----------------
12011 function In_Subtree (N : Node_Id; Root : Node_Id) return Boolean is
12012 Curr : Node_Id;
12014 begin
12015 Curr := N;
12016 while Present (Curr) loop
12017 if Curr = Root then
12018 return True;
12019 end if;
12021 Curr := Parent (Curr);
12022 end loop;
12024 return False;
12025 end In_Subtree;
12027 ----------------
12028 -- In_Subtree --
12029 ----------------
12031 function In_Subtree
12032 (N : Node_Id;
12033 Root1 : Node_Id;
12034 Root2 : Node_Id) return Boolean
12036 Curr : Node_Id;
12038 begin
12039 Curr := N;
12040 while Present (Curr) loop
12041 if Curr = Root1 or else Curr = Root2 then
12042 return True;
12043 end if;
12045 Curr := Parent (Curr);
12046 end loop;
12048 return False;
12049 end In_Subtree;
12051 ---------------------
12052 -- In_Visible_Part --
12053 ---------------------
12055 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
12056 begin
12057 return Is_Package_Or_Generic_Package (Scope_Id)
12058 and then In_Open_Scopes (Scope_Id)
12059 and then not In_Package_Body (Scope_Id)
12060 and then not In_Private_Part (Scope_Id);
12061 end In_Visible_Part;
12063 --------------------------------
12064 -- Incomplete_Or_Partial_View --
12065 --------------------------------
12067 function Incomplete_Or_Partial_View (Id : Entity_Id) return Entity_Id is
12068 function Inspect_Decls
12069 (Decls : List_Id;
12070 Taft : Boolean := False) return Entity_Id;
12071 -- Check whether a declarative region contains the incomplete or partial
12072 -- view of Id.
12074 -------------------
12075 -- Inspect_Decls --
12076 -------------------
12078 function Inspect_Decls
12079 (Decls : List_Id;
12080 Taft : Boolean := False) return Entity_Id
12082 Decl : Node_Id;
12083 Match : Node_Id;
12085 begin
12086 Decl := First (Decls);
12087 while Present (Decl) loop
12088 Match := Empty;
12090 -- The partial view of a Taft-amendment type is an incomplete
12091 -- type.
12093 if Taft then
12094 if Nkind (Decl) = N_Incomplete_Type_Declaration then
12095 Match := Defining_Identifier (Decl);
12096 end if;
12098 -- Otherwise look for a private type whose full view matches the
12099 -- input type. Note that this checks full_type_declaration nodes
12100 -- to account for derivations from a private type where the type
12101 -- declaration hold the partial view and the full view is an
12102 -- itype.
12104 elsif Nkind_In (Decl, N_Full_Type_Declaration,
12105 N_Private_Extension_Declaration,
12106 N_Private_Type_Declaration)
12107 then
12108 Match := Defining_Identifier (Decl);
12109 end if;
12111 -- Guard against unanalyzed entities
12113 if Present (Match)
12114 and then Is_Type (Match)
12115 and then Present (Full_View (Match))
12116 and then Full_View (Match) = Id
12117 then
12118 return Match;
12119 end if;
12121 Next (Decl);
12122 end loop;
12124 return Empty;
12125 end Inspect_Decls;
12127 -- Local variables
12129 Prev : Entity_Id;
12131 -- Start of processing for Incomplete_Or_Partial_View
12133 begin
12134 -- Deferred constant or incomplete type case
12136 Prev := Current_Entity_In_Scope (Id);
12138 if Present (Prev)
12139 and then (Is_Incomplete_Type (Prev) or else Ekind (Prev) = E_Constant)
12140 and then Present (Full_View (Prev))
12141 and then Full_View (Prev) = Id
12142 then
12143 return Prev;
12144 end if;
12146 -- Private or Taft amendment type case
12148 declare
12149 Pkg : constant Entity_Id := Scope (Id);
12150 Pkg_Decl : Node_Id := Pkg;
12152 begin
12153 if Present (Pkg)
12154 and then Ekind_In (Pkg, E_Generic_Package, E_Package)
12155 then
12156 while Nkind (Pkg_Decl) /= N_Package_Specification loop
12157 Pkg_Decl := Parent (Pkg_Decl);
12158 end loop;
12160 -- It is knows that Typ has a private view, look for it in the
12161 -- visible declarations of the enclosing scope. A special case
12162 -- of this is when the two views have been exchanged - the full
12163 -- appears earlier than the private.
12165 if Has_Private_Declaration (Id) then
12166 Prev := Inspect_Decls (Visible_Declarations (Pkg_Decl));
12168 -- Exchanged view case, look in the private declarations
12170 if No (Prev) then
12171 Prev := Inspect_Decls (Private_Declarations (Pkg_Decl));
12172 end if;
12174 return Prev;
12176 -- Otherwise if this is the package body, then Typ is a potential
12177 -- Taft amendment type. The incomplete view should be located in
12178 -- the private declarations of the enclosing scope.
12180 elsif In_Package_Body (Pkg) then
12181 return Inspect_Decls (Private_Declarations (Pkg_Decl), True);
12182 end if;
12183 end if;
12184 end;
12186 -- The type has no incomplete or private view
12188 return Empty;
12189 end Incomplete_Or_Partial_View;
12191 ---------------------------------------
12192 -- Incomplete_View_From_Limited_With --
12193 ---------------------------------------
12195 function Incomplete_View_From_Limited_With
12196 (Typ : Entity_Id) return Entity_Id
12198 begin
12199 -- It might make sense to make this an attribute in Einfo, and set it
12200 -- in Sem_Ch10 in Build_Shadow_Entity. However, we're running short on
12201 -- slots for new attributes, and it seems a bit simpler to just search
12202 -- the Limited_View (if it exists) for an incomplete type whose
12203 -- Non_Limited_View is Typ.
12205 if Ekind (Scope (Typ)) = E_Package
12206 and then Present (Limited_View (Scope (Typ)))
12207 then
12208 declare
12209 Ent : Entity_Id := First_Entity (Limited_View (Scope (Typ)));
12210 begin
12211 while Present (Ent) loop
12212 if Ekind (Ent) in Incomplete_Kind
12213 and then Non_Limited_View (Ent) = Typ
12214 then
12215 return Ent;
12216 end if;
12218 Ent := Next_Entity (Ent);
12219 end loop;
12220 end;
12221 end if;
12223 return Typ;
12224 end Incomplete_View_From_Limited_With;
12226 ----------------------------------
12227 -- Indexed_Component_Bit_Offset --
12228 ----------------------------------
12230 function Indexed_Component_Bit_Offset (N : Node_Id) return Uint is
12231 Exp : constant Node_Id := First (Expressions (N));
12232 Typ : constant Entity_Id := Etype (Prefix (N));
12233 Off : constant Uint := Component_Size (Typ);
12234 Ind : Node_Id;
12236 begin
12237 -- Return early if the component size is not known or variable
12239 if Off = No_Uint or else Off < Uint_0 then
12240 return No_Uint;
12241 end if;
12243 -- Deal with the degenerate case of an empty component
12245 if Off = Uint_0 then
12246 return Off;
12247 end if;
12249 -- Check that both the index value and the low bound are known
12251 if not Compile_Time_Known_Value (Exp) then
12252 return No_Uint;
12253 end if;
12255 Ind := First_Index (Typ);
12256 if No (Ind) then
12257 return No_Uint;
12258 end if;
12260 if Nkind (Ind) = N_Subtype_Indication then
12261 Ind := Constraint (Ind);
12263 if Nkind (Ind) = N_Range_Constraint then
12264 Ind := Range_Expression (Ind);
12265 end if;
12266 end if;
12268 if Nkind (Ind) /= N_Range
12269 or else not Compile_Time_Known_Value (Low_Bound (Ind))
12270 then
12271 return No_Uint;
12272 end if;
12274 -- Return the scaled offset
12276 return Off * (Expr_Value (Exp) - Expr_Value (Low_Bound ((Ind))));
12277 end Indexed_Component_Bit_Offset;
12279 ----------------------------
12280 -- Inherit_Rep_Item_Chain --
12281 ----------------------------
12283 procedure Inherit_Rep_Item_Chain (Typ : Entity_Id; From_Typ : Entity_Id) is
12284 Item : Node_Id;
12285 Next_Item : Node_Id;
12287 begin
12288 -- There are several inheritance scenarios to consider depending on
12289 -- whether both types have rep item chains and whether the destination
12290 -- type already inherits part of the source type's rep item chain.
12292 -- 1) The source type lacks a rep item chain
12293 -- From_Typ ---> Empty
12295 -- Typ --------> Item (or Empty)
12297 -- In this case inheritance cannot take place because there are no items
12298 -- to inherit.
12300 -- 2) The destination type lacks a rep item chain
12301 -- From_Typ ---> Item ---> ...
12303 -- Typ --------> Empty
12305 -- Inheritance takes place by setting the First_Rep_Item of the
12306 -- destination type to the First_Rep_Item of the source type.
12307 -- From_Typ ---> Item ---> ...
12308 -- ^
12309 -- Typ -----------+
12311 -- 3.1) Both source and destination types have at least one rep item.
12312 -- The destination type does NOT inherit a rep item from the source
12313 -- type.
12314 -- From_Typ ---> Item ---> Item
12316 -- Typ --------> Item ---> Item
12318 -- Inheritance takes place by setting the Next_Rep_Item of the last item
12319 -- of the destination type to the First_Rep_Item of the source type.
12320 -- From_Typ -------------------> Item ---> Item
12321 -- ^
12322 -- Typ --------> Item ---> Item --+
12324 -- 3.2) Both source and destination types have at least one rep item.
12325 -- The destination type DOES inherit part of the rep item chain of the
12326 -- source type.
12327 -- From_Typ ---> Item ---> Item ---> Item
12328 -- ^
12329 -- Typ --------> Item ------+
12331 -- This rare case arises when the full view of a private extension must
12332 -- inherit the rep item chain from the full view of its parent type and
12333 -- the full view of the parent type contains extra rep items. Currently
12334 -- only invariants may lead to such form of inheritance.
12336 -- type From_Typ is tagged private
12337 -- with Type_Invariant'Class => Item_2;
12339 -- type Typ is new From_Typ with private
12340 -- with Type_Invariant => Item_4;
12342 -- At this point the rep item chains contain the following items
12344 -- From_Typ -----------> Item_2 ---> Item_3
12345 -- ^
12346 -- Typ --------> Item_4 --+
12348 -- The full views of both types may introduce extra invariants
12350 -- type From_Typ is tagged null record
12351 -- with Type_Invariant => Item_1;
12353 -- type Typ is new From_Typ with null record;
12355 -- The full view of Typ would have to inherit any new rep items added to
12356 -- the full view of From_Typ.
12358 -- From_Typ -----------> Item_1 ---> Item_2 ---> Item_3
12359 -- ^
12360 -- Typ --------> Item_4 --+
12362 -- To achieve this form of inheritance, the destination type must first
12363 -- sever the link between its own rep chain and that of the source type,
12364 -- then inheritance 3.1 takes place.
12366 -- Case 1: The source type lacks a rep item chain
12368 if No (First_Rep_Item (From_Typ)) then
12369 return;
12371 -- Case 2: The destination type lacks a rep item chain
12373 elsif No (First_Rep_Item (Typ)) then
12374 Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ));
12376 -- Case 3: Both the source and destination types have at least one rep
12377 -- item. Traverse the rep item chain of the destination type to find the
12378 -- last rep item.
12380 else
12381 Item := Empty;
12382 Next_Item := First_Rep_Item (Typ);
12383 while Present (Next_Item) loop
12385 -- Detect a link between the destination type's rep chain and that
12386 -- of the source type. There are two possibilities:
12388 -- Variant 1
12389 -- Next_Item
12390 -- V
12391 -- From_Typ ---> Item_1 --->
12392 -- ^
12393 -- Typ -----------+
12395 -- Item is Empty
12397 -- Variant 2
12398 -- Next_Item
12399 -- V
12400 -- From_Typ ---> Item_1 ---> Item_2 --->
12401 -- ^
12402 -- Typ --------> Item_3 ------+
12403 -- ^
12404 -- Item
12406 if Has_Rep_Item (From_Typ, Next_Item) then
12407 exit;
12408 end if;
12410 Item := Next_Item;
12411 Next_Item := Next_Rep_Item (Next_Item);
12412 end loop;
12414 -- Inherit the source type's rep item chain
12416 if Present (Item) then
12417 Set_Next_Rep_Item (Item, First_Rep_Item (From_Typ));
12418 else
12419 Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ));
12420 end if;
12421 end if;
12422 end Inherit_Rep_Item_Chain;
12424 ---------------------------------
12425 -- Insert_Explicit_Dereference --
12426 ---------------------------------
12428 procedure Insert_Explicit_Dereference (N : Node_Id) is
12429 New_Prefix : constant Node_Id := Relocate_Node (N);
12430 Ent : Entity_Id := Empty;
12431 Pref : Node_Id;
12432 I : Interp_Index;
12433 It : Interp;
12434 T : Entity_Id;
12436 begin
12437 Save_Interps (N, New_Prefix);
12439 Rewrite (N,
12440 Make_Explicit_Dereference (Sloc (Parent (N)),
12441 Prefix => New_Prefix));
12443 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
12445 if Is_Overloaded (New_Prefix) then
12447 -- The dereference is also overloaded, and its interpretations are
12448 -- the designated types of the interpretations of the original node.
12450 Set_Etype (N, Any_Type);
12452 Get_First_Interp (New_Prefix, I, It);
12453 while Present (It.Nam) loop
12454 T := It.Typ;
12456 if Is_Access_Type (T) then
12457 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
12458 end if;
12460 Get_Next_Interp (I, It);
12461 end loop;
12463 End_Interp_List;
12465 else
12466 -- Prefix is unambiguous: mark the original prefix (which might
12467 -- Come_From_Source) as a reference, since the new (relocated) one
12468 -- won't be taken into account.
12470 if Is_Entity_Name (New_Prefix) then
12471 Ent := Entity (New_Prefix);
12472 Pref := New_Prefix;
12474 -- For a retrieval of a subcomponent of some composite object,
12475 -- retrieve the ultimate entity if there is one.
12477 elsif Nkind_In (New_Prefix, N_Selected_Component,
12478 N_Indexed_Component)
12479 then
12480 Pref := Prefix (New_Prefix);
12481 while Present (Pref)
12482 and then Nkind_In (Pref, N_Selected_Component,
12483 N_Indexed_Component)
12484 loop
12485 Pref := Prefix (Pref);
12486 end loop;
12488 if Present (Pref) and then Is_Entity_Name (Pref) then
12489 Ent := Entity (Pref);
12490 end if;
12491 end if;
12493 -- Place the reference on the entity node
12495 if Present (Ent) then
12496 Generate_Reference (Ent, Pref);
12497 end if;
12498 end if;
12499 end Insert_Explicit_Dereference;
12501 ------------------------------------------
12502 -- Inspect_Deferred_Constant_Completion --
12503 ------------------------------------------
12505 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
12506 Decl : Node_Id;
12508 begin
12509 Decl := First (Decls);
12510 while Present (Decl) loop
12512 -- Deferred constant signature
12514 if Nkind (Decl) = N_Object_Declaration
12515 and then Constant_Present (Decl)
12516 and then No (Expression (Decl))
12518 -- No need to check internally generated constants
12520 and then Comes_From_Source (Decl)
12522 -- The constant is not completed. A full object declaration or a
12523 -- pragma Import complete a deferred constant.
12525 and then not Has_Completion (Defining_Identifier (Decl))
12526 then
12527 Error_Msg_N
12528 ("constant declaration requires initialization expression",
12529 Defining_Identifier (Decl));
12530 end if;
12532 Decl := Next (Decl);
12533 end loop;
12534 end Inspect_Deferred_Constant_Completion;
12536 -----------------------------
12537 -- Install_Generic_Formals --
12538 -----------------------------
12540 procedure Install_Generic_Formals (Subp_Id : Entity_Id) is
12541 E : Entity_Id;
12543 begin
12544 pragma Assert (Is_Generic_Subprogram (Subp_Id));
12546 E := First_Entity (Subp_Id);
12547 while Present (E) loop
12548 Install_Entity (E);
12549 Next_Entity (E);
12550 end loop;
12551 end Install_Generic_Formals;
12553 ------------------------
12554 -- Install_SPARK_Mode --
12555 ------------------------
12557 procedure Install_SPARK_Mode (Mode : SPARK_Mode_Type; Prag : Node_Id) is
12558 begin
12559 SPARK_Mode := Mode;
12560 SPARK_Mode_Pragma := Prag;
12561 end Install_SPARK_Mode;
12563 -----------------------------
12564 -- Is_Actual_Out_Parameter --
12565 -----------------------------
12567 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
12568 Formal : Entity_Id;
12569 Call : Node_Id;
12570 begin
12571 Find_Actual (N, Formal, Call);
12572 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
12573 end Is_Actual_Out_Parameter;
12575 -------------------------
12576 -- Is_Actual_Parameter --
12577 -------------------------
12579 function Is_Actual_Parameter (N : Node_Id) return Boolean is
12580 PK : constant Node_Kind := Nkind (Parent (N));
12582 begin
12583 case PK is
12584 when N_Parameter_Association =>
12585 return N = Explicit_Actual_Parameter (Parent (N));
12587 when N_Subprogram_Call =>
12588 return Is_List_Member (N)
12589 and then
12590 List_Containing (N) = Parameter_Associations (Parent (N));
12592 when others =>
12593 return False;
12594 end case;
12595 end Is_Actual_Parameter;
12597 --------------------------------
12598 -- Is_Actual_Tagged_Parameter --
12599 --------------------------------
12601 function Is_Actual_Tagged_Parameter (N : Node_Id) return Boolean is
12602 Formal : Entity_Id;
12603 Call : Node_Id;
12604 begin
12605 Find_Actual (N, Formal, Call);
12606 return Present (Formal) and then Is_Tagged_Type (Etype (Formal));
12607 end Is_Actual_Tagged_Parameter;
12609 ---------------------
12610 -- Is_Aliased_View --
12611 ---------------------
12613 function Is_Aliased_View (Obj : Node_Id) return Boolean is
12614 E : Entity_Id;
12616 begin
12617 if Is_Entity_Name (Obj) then
12618 E := Entity (Obj);
12620 return
12621 (Is_Object (E)
12622 and then
12623 (Is_Aliased (E)
12624 or else (Present (Renamed_Object (E))
12625 and then Is_Aliased_View (Renamed_Object (E)))))
12627 or else ((Is_Formal (E) or else Is_Formal_Object (E))
12628 and then Is_Tagged_Type (Etype (E)))
12630 or else (Is_Concurrent_Type (E) and then In_Open_Scopes (E))
12632 -- Current instance of type, either directly or as rewritten
12633 -- reference to the current object.
12635 or else (Is_Entity_Name (Original_Node (Obj))
12636 and then Present (Entity (Original_Node (Obj)))
12637 and then Is_Type (Entity (Original_Node (Obj))))
12639 or else (Is_Type (E) and then E = Current_Scope)
12641 or else (Is_Incomplete_Or_Private_Type (E)
12642 and then Full_View (E) = Current_Scope)
12644 -- Ada 2012 AI05-0053: the return object of an extended return
12645 -- statement is aliased if its type is immutably limited.
12647 or else (Is_Return_Object (E)
12648 and then Is_Limited_View (Etype (E)));
12650 elsif Nkind (Obj) = N_Selected_Component then
12651 return Is_Aliased (Entity (Selector_Name (Obj)));
12653 elsif Nkind (Obj) = N_Indexed_Component then
12654 return Has_Aliased_Components (Etype (Prefix (Obj)))
12655 or else
12656 (Is_Access_Type (Etype (Prefix (Obj)))
12657 and then Has_Aliased_Components
12658 (Designated_Type (Etype (Prefix (Obj)))));
12660 elsif Nkind_In (Obj, N_Unchecked_Type_Conversion, N_Type_Conversion) then
12661 return Is_Tagged_Type (Etype (Obj))
12662 and then Is_Aliased_View (Expression (Obj));
12664 elsif Nkind (Obj) = N_Explicit_Dereference then
12665 return Nkind (Original_Node (Obj)) /= N_Function_Call;
12667 else
12668 return False;
12669 end if;
12670 end Is_Aliased_View;
12672 -------------------------
12673 -- Is_Ancestor_Package --
12674 -------------------------
12676 function Is_Ancestor_Package
12677 (E1 : Entity_Id;
12678 E2 : Entity_Id) return Boolean
12680 Par : Entity_Id;
12682 begin
12683 Par := E2;
12684 while Present (Par) and then Par /= Standard_Standard loop
12685 if Par = E1 then
12686 return True;
12687 end if;
12689 Par := Scope (Par);
12690 end loop;
12692 return False;
12693 end Is_Ancestor_Package;
12695 ----------------------
12696 -- Is_Atomic_Object --
12697 ----------------------
12699 function Is_Atomic_Object (N : Node_Id) return Boolean is
12701 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
12702 -- Determines if given object has atomic components
12704 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
12705 -- If prefix is an implicit dereference, examine designated type
12707 ----------------------
12708 -- Is_Atomic_Prefix --
12709 ----------------------
12711 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
12712 begin
12713 if Is_Access_Type (Etype (N)) then
12714 return
12715 Has_Atomic_Components (Designated_Type (Etype (N)));
12716 else
12717 return Object_Has_Atomic_Components (N);
12718 end if;
12719 end Is_Atomic_Prefix;
12721 ----------------------------------
12722 -- Object_Has_Atomic_Components --
12723 ----------------------------------
12725 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
12726 begin
12727 if Has_Atomic_Components (Etype (N))
12728 or else Is_Atomic (Etype (N))
12729 then
12730 return True;
12732 elsif Is_Entity_Name (N)
12733 and then (Has_Atomic_Components (Entity (N))
12734 or else Is_Atomic (Entity (N)))
12735 then
12736 return True;
12738 elsif Nkind (N) = N_Selected_Component
12739 and then Is_Atomic (Entity (Selector_Name (N)))
12740 then
12741 return True;
12743 elsif Nkind (N) = N_Indexed_Component
12744 or else Nkind (N) = N_Selected_Component
12745 then
12746 return Is_Atomic_Prefix (Prefix (N));
12748 else
12749 return False;
12750 end if;
12751 end Object_Has_Atomic_Components;
12753 -- Start of processing for Is_Atomic_Object
12755 begin
12756 -- Predicate is not relevant to subprograms
12758 if Is_Entity_Name (N) and then Is_Overloadable (Entity (N)) then
12759 return False;
12761 elsif Is_Atomic (Etype (N))
12762 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
12763 then
12764 return True;
12766 elsif Nkind (N) = N_Selected_Component
12767 and then Is_Atomic (Entity (Selector_Name (N)))
12768 then
12769 return True;
12771 elsif Nkind (N) = N_Indexed_Component
12772 or else Nkind (N) = N_Selected_Component
12773 then
12774 return Is_Atomic_Prefix (Prefix (N));
12776 else
12777 return False;
12778 end if;
12779 end Is_Atomic_Object;
12781 -----------------------------
12782 -- Is_Atomic_Or_VFA_Object --
12783 -----------------------------
12785 function Is_Atomic_Or_VFA_Object (N : Node_Id) return Boolean is
12786 begin
12787 return Is_Atomic_Object (N)
12788 or else (Is_Object_Reference (N)
12789 and then Is_Entity_Name (N)
12790 and then (Is_Volatile_Full_Access (Entity (N))
12791 or else
12792 Is_Volatile_Full_Access (Etype (Entity (N)))));
12793 end Is_Atomic_Or_VFA_Object;
12795 -------------------------
12796 -- Is_Attribute_Result --
12797 -------------------------
12799 function Is_Attribute_Result (N : Node_Id) return Boolean is
12800 begin
12801 return Nkind (N) = N_Attribute_Reference
12802 and then Attribute_Name (N) = Name_Result;
12803 end Is_Attribute_Result;
12805 -------------------------
12806 -- Is_Attribute_Update --
12807 -------------------------
12809 function Is_Attribute_Update (N : Node_Id) return Boolean is
12810 begin
12811 return Nkind (N) = N_Attribute_Reference
12812 and then Attribute_Name (N) = Name_Update;
12813 end Is_Attribute_Update;
12815 ------------------------------------
12816 -- Is_Body_Or_Package_Declaration --
12817 ------------------------------------
12819 function Is_Body_Or_Package_Declaration (N : Node_Id) return Boolean is
12820 begin
12821 return Nkind_In (N, N_Entry_Body,
12822 N_Package_Body,
12823 N_Package_Declaration,
12824 N_Protected_Body,
12825 N_Subprogram_Body,
12826 N_Task_Body);
12827 end Is_Body_Or_Package_Declaration;
12829 -----------------------
12830 -- Is_Bounded_String --
12831 -----------------------
12833 function Is_Bounded_String (T : Entity_Id) return Boolean is
12834 Under : constant Entity_Id := Underlying_Type (Root_Type (T));
12836 begin
12837 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
12838 -- Super_String, or one of the [Wide_]Wide_ versions. This will
12839 -- be True for all the Bounded_String types in instances of the
12840 -- Generic_Bounded_Length generics, and for types derived from those.
12842 return Present (Under)
12843 and then (Is_RTE (Root_Type (Under), RO_SU_Super_String) or else
12844 Is_RTE (Root_Type (Under), RO_WI_Super_String) or else
12845 Is_RTE (Root_Type (Under), RO_WW_Super_String));
12846 end Is_Bounded_String;
12848 ---------------------
12849 -- Is_CCT_Instance --
12850 ---------------------
12852 function Is_CCT_Instance
12853 (Ref_Id : Entity_Id;
12854 Context_Id : Entity_Id) return Boolean
12856 begin
12857 pragma Assert (Ekind_In (Ref_Id, E_Protected_Type, E_Task_Type));
12859 if Is_Single_Task_Object (Context_Id) then
12860 return Scope_Within_Or_Same (Etype (Context_Id), Ref_Id);
12862 else
12863 pragma Assert (Ekind_In (Context_Id, E_Entry,
12864 E_Entry_Family,
12865 E_Function,
12866 E_Package,
12867 E_Procedure,
12868 E_Protected_Type,
12869 E_Task_Type)
12870 or else
12871 Is_Record_Type (Context_Id));
12872 return Scope_Within_Or_Same (Context_Id, Ref_Id);
12873 end if;
12874 end Is_CCT_Instance;
12876 -------------------------
12877 -- Is_Child_Or_Sibling --
12878 -------------------------
12880 function Is_Child_Or_Sibling
12881 (Pack_1 : Entity_Id;
12882 Pack_2 : Entity_Id) return Boolean
12884 function Distance_From_Standard (Pack : Entity_Id) return Nat;
12885 -- Given an arbitrary package, return the number of "climbs" necessary
12886 -- to reach scope Standard_Standard.
12888 procedure Equalize_Depths
12889 (Pack : in out Entity_Id;
12890 Depth : in out Nat;
12891 Depth_To_Reach : Nat);
12892 -- Given an arbitrary package, its depth and a target depth to reach,
12893 -- climb the scope chain until the said depth is reached. The pointer
12894 -- to the package and its depth a modified during the climb.
12896 ----------------------------
12897 -- Distance_From_Standard --
12898 ----------------------------
12900 function Distance_From_Standard (Pack : Entity_Id) return Nat is
12901 Dist : Nat;
12902 Scop : Entity_Id;
12904 begin
12905 Dist := 0;
12906 Scop := Pack;
12907 while Present (Scop) and then Scop /= Standard_Standard loop
12908 Dist := Dist + 1;
12909 Scop := Scope (Scop);
12910 end loop;
12912 return Dist;
12913 end Distance_From_Standard;
12915 ---------------------
12916 -- Equalize_Depths --
12917 ---------------------
12919 procedure Equalize_Depths
12920 (Pack : in out Entity_Id;
12921 Depth : in out Nat;
12922 Depth_To_Reach : Nat)
12924 begin
12925 -- The package must be at a greater or equal depth
12927 if Depth < Depth_To_Reach then
12928 raise Program_Error;
12929 end if;
12931 -- Climb the scope chain until the desired depth is reached
12933 while Present (Pack) and then Depth /= Depth_To_Reach loop
12934 Pack := Scope (Pack);
12935 Depth := Depth - 1;
12936 end loop;
12937 end Equalize_Depths;
12939 -- Local variables
12941 P_1 : Entity_Id := Pack_1;
12942 P_1_Child : Boolean := False;
12943 P_1_Depth : Nat := Distance_From_Standard (P_1);
12944 P_2 : Entity_Id := Pack_2;
12945 P_2_Child : Boolean := False;
12946 P_2_Depth : Nat := Distance_From_Standard (P_2);
12948 -- Start of processing for Is_Child_Or_Sibling
12950 begin
12951 pragma Assert
12952 (Ekind (Pack_1) = E_Package and then Ekind (Pack_2) = E_Package);
12954 -- Both packages denote the same entity, therefore they cannot be
12955 -- children or siblings.
12957 if P_1 = P_2 then
12958 return False;
12960 -- One of the packages is at a deeper level than the other. Note that
12961 -- both may still come from different hierarchies.
12963 -- (root) P_2
12964 -- / \ :
12965 -- X P_2 or X
12966 -- : :
12967 -- P_1 P_1
12969 elsif P_1_Depth > P_2_Depth then
12970 Equalize_Depths
12971 (Pack => P_1,
12972 Depth => P_1_Depth,
12973 Depth_To_Reach => P_2_Depth);
12974 P_1_Child := True;
12976 -- (root) P_1
12977 -- / \ :
12978 -- P_1 X or X
12979 -- : :
12980 -- P_2 P_2
12982 elsif P_2_Depth > P_1_Depth then
12983 Equalize_Depths
12984 (Pack => P_2,
12985 Depth => P_2_Depth,
12986 Depth_To_Reach => P_1_Depth);
12987 P_2_Child := True;
12988 end if;
12990 -- At this stage the package pointers have been elevated to the same
12991 -- depth. If the related entities are the same, then one package is a
12992 -- potential child of the other:
12994 -- P_1
12995 -- :
12996 -- X became P_1 P_2 or vice versa
12997 -- :
12998 -- P_2
13000 if P_1 = P_2 then
13001 if P_1_Child then
13002 return Is_Child_Unit (Pack_1);
13004 else pragma Assert (P_2_Child);
13005 return Is_Child_Unit (Pack_2);
13006 end if;
13008 -- The packages may come from the same package chain or from entirely
13009 -- different hierarcies. To determine this, climb the scope stack until
13010 -- a common root is found.
13012 -- (root) (root 1) (root 2)
13013 -- / \ | |
13014 -- P_1 P_2 P_1 P_2
13016 else
13017 while Present (P_1) and then Present (P_2) loop
13019 -- The two packages may be siblings
13021 if P_1 = P_2 then
13022 return Is_Child_Unit (Pack_1) and then Is_Child_Unit (Pack_2);
13023 end if;
13025 P_1 := Scope (P_1);
13026 P_2 := Scope (P_2);
13027 end loop;
13028 end if;
13030 return False;
13031 end Is_Child_Or_Sibling;
13033 -----------------------------
13034 -- Is_Concurrent_Interface --
13035 -----------------------------
13037 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
13038 begin
13039 return Is_Interface (T)
13040 and then
13041 (Is_Protected_Interface (T)
13042 or else Is_Synchronized_Interface (T)
13043 or else Is_Task_Interface (T));
13044 end Is_Concurrent_Interface;
13046 -----------------------
13047 -- Is_Constant_Bound --
13048 -----------------------
13050 function Is_Constant_Bound (Exp : Node_Id) return Boolean is
13051 begin
13052 if Compile_Time_Known_Value (Exp) then
13053 return True;
13055 elsif Is_Entity_Name (Exp) and then Present (Entity (Exp)) then
13056 return Is_Constant_Object (Entity (Exp))
13057 or else Ekind (Entity (Exp)) = E_Enumeration_Literal;
13059 elsif Nkind (Exp) in N_Binary_Op then
13060 return Is_Constant_Bound (Left_Opnd (Exp))
13061 and then Is_Constant_Bound (Right_Opnd (Exp))
13062 and then Scope (Entity (Exp)) = Standard_Standard;
13064 else
13065 return False;
13066 end if;
13067 end Is_Constant_Bound;
13069 ---------------------------
13070 -- Is_Container_Element --
13071 ---------------------------
13073 function Is_Container_Element (Exp : Node_Id) return Boolean is
13074 Loc : constant Source_Ptr := Sloc (Exp);
13075 Pref : constant Node_Id := Prefix (Exp);
13077 Call : Node_Id;
13078 -- Call to an indexing aspect
13080 Cont_Typ : Entity_Id;
13081 -- The type of the container being accessed
13083 Elem_Typ : Entity_Id;
13084 -- Its element type
13086 Indexing : Entity_Id;
13087 Is_Const : Boolean;
13088 -- Indicates that constant indexing is used, and the element is thus
13089 -- a constant.
13091 Ref_Typ : Entity_Id;
13092 -- The reference type returned by the indexing operation
13094 begin
13095 -- If C is a container, in a context that imposes the element type of
13096 -- that container, the indexing notation C (X) is rewritten as:
13098 -- Indexing (C, X).Discr.all
13100 -- where Indexing is one of the indexing aspects of the container.
13101 -- If the context does not require a reference, the construct can be
13102 -- rewritten as
13104 -- Element (C, X)
13106 -- First, verify that the construct has the proper form
13108 if not Expander_Active then
13109 return False;
13111 elsif Nkind (Pref) /= N_Selected_Component then
13112 return False;
13114 elsif Nkind (Prefix (Pref)) /= N_Function_Call then
13115 return False;
13117 else
13118 Call := Prefix (Pref);
13119 Ref_Typ := Etype (Call);
13120 end if;
13122 if not Has_Implicit_Dereference (Ref_Typ)
13123 or else No (First (Parameter_Associations (Call)))
13124 or else not Is_Entity_Name (Name (Call))
13125 then
13126 return False;
13127 end if;
13129 -- Retrieve type of container object, and its iterator aspects
13131 Cont_Typ := Etype (First (Parameter_Associations (Call)));
13132 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Constant_Indexing);
13133 Is_Const := False;
13135 if No (Indexing) then
13137 -- Container should have at least one indexing operation
13139 return False;
13141 elsif Entity (Name (Call)) /= Entity (Indexing) then
13143 -- This may be a variable indexing operation
13145 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Variable_Indexing);
13147 if No (Indexing)
13148 or else Entity (Name (Call)) /= Entity (Indexing)
13149 then
13150 return False;
13151 end if;
13153 else
13154 Is_Const := True;
13155 end if;
13157 Elem_Typ := Find_Value_Of_Aspect (Cont_Typ, Aspect_Iterator_Element);
13159 if No (Elem_Typ) or else Entity (Elem_Typ) /= Etype (Exp) then
13160 return False;
13161 end if;
13163 -- Check that the expression is not the target of an assignment, in
13164 -- which case the rewriting is not possible.
13166 if not Is_Const then
13167 declare
13168 Par : Node_Id;
13170 begin
13171 Par := Exp;
13172 while Present (Par)
13173 loop
13174 if Nkind (Parent (Par)) = N_Assignment_Statement
13175 and then Par = Name (Parent (Par))
13176 then
13177 return False;
13179 -- A renaming produces a reference, and the transformation
13180 -- does not apply.
13182 elsif Nkind (Parent (Par)) = N_Object_Renaming_Declaration then
13183 return False;
13185 elsif Nkind_In
13186 (Nkind (Parent (Par)), N_Function_Call,
13187 N_Procedure_Call_Statement,
13188 N_Entry_Call_Statement)
13189 then
13190 -- Check that the element is not part of an actual for an
13191 -- in-out parameter.
13193 declare
13194 F : Entity_Id;
13195 A : Node_Id;
13197 begin
13198 F := First_Formal (Entity (Name (Parent (Par))));
13199 A := First (Parameter_Associations (Parent (Par)));
13200 while Present (F) loop
13201 if A = Par and then Ekind (F) /= E_In_Parameter then
13202 return False;
13203 end if;
13205 Next_Formal (F);
13206 Next (A);
13207 end loop;
13208 end;
13210 -- E_In_Parameter in a call: element is not modified.
13212 exit;
13213 end if;
13215 Par := Parent (Par);
13216 end loop;
13217 end;
13218 end if;
13220 -- The expression has the proper form and the context requires the
13221 -- element type. Retrieve the Element function of the container and
13222 -- rewrite the construct as a call to it.
13224 declare
13225 Op : Elmt_Id;
13227 begin
13228 Op := First_Elmt (Primitive_Operations (Cont_Typ));
13229 while Present (Op) loop
13230 exit when Chars (Node (Op)) = Name_Element;
13231 Next_Elmt (Op);
13232 end loop;
13234 if No (Op) then
13235 return False;
13237 else
13238 Rewrite (Exp,
13239 Make_Function_Call (Loc,
13240 Name => New_Occurrence_Of (Node (Op), Loc),
13241 Parameter_Associations => Parameter_Associations (Call)));
13242 Analyze_And_Resolve (Exp, Entity (Elem_Typ));
13243 return True;
13244 end if;
13245 end;
13246 end Is_Container_Element;
13248 ----------------------------
13249 -- Is_Contract_Annotation --
13250 ----------------------------
13252 function Is_Contract_Annotation (Item : Node_Id) return Boolean is
13253 begin
13254 return Is_Package_Contract_Annotation (Item)
13255 or else
13256 Is_Subprogram_Contract_Annotation (Item);
13257 end Is_Contract_Annotation;
13259 --------------------------------------
13260 -- Is_Controlling_Limited_Procedure --
13261 --------------------------------------
13263 function Is_Controlling_Limited_Procedure
13264 (Proc_Nam : Entity_Id) return Boolean
13266 Param : Node_Id;
13267 Param_Typ : Entity_Id := Empty;
13269 begin
13270 if Ekind (Proc_Nam) = E_Procedure
13271 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
13272 then
13273 Param :=
13274 Parameter_Type
13275 (First (Parameter_Specifications (Parent (Proc_Nam))));
13277 -- The formal may be an anonymous access type
13279 if Nkind (Param) = N_Access_Definition then
13280 Param_Typ := Entity (Subtype_Mark (Param));
13281 else
13282 Param_Typ := Etype (Param);
13283 end if;
13285 -- In the case where an Itype was created for a dispatchin call, the
13286 -- procedure call has been rewritten. The actual may be an access to
13287 -- interface type in which case it is the designated type that is the
13288 -- controlling type.
13290 elsif Present (Associated_Node_For_Itype (Proc_Nam))
13291 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
13292 and then
13293 Present (Parameter_Associations
13294 (Associated_Node_For_Itype (Proc_Nam)))
13295 then
13296 Param_Typ :=
13297 Etype (First (Parameter_Associations
13298 (Associated_Node_For_Itype (Proc_Nam))));
13300 if Ekind (Param_Typ) = E_Anonymous_Access_Type then
13301 Param_Typ := Directly_Designated_Type (Param_Typ);
13302 end if;
13303 end if;
13305 if Present (Param_Typ) then
13306 return
13307 Is_Interface (Param_Typ)
13308 and then Is_Limited_Record (Param_Typ);
13309 end if;
13311 return False;
13312 end Is_Controlling_Limited_Procedure;
13314 -----------------------------
13315 -- Is_CPP_Constructor_Call --
13316 -----------------------------
13318 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
13319 begin
13320 return Nkind (N) = N_Function_Call
13321 and then Is_CPP_Class (Etype (Etype (N)))
13322 and then Is_Constructor (Entity (Name (N)))
13323 and then Is_Imported (Entity (Name (N)));
13324 end Is_CPP_Constructor_Call;
13326 -------------------------
13327 -- Is_Current_Instance --
13328 -------------------------
13330 function Is_Current_Instance (N : Node_Id) return Boolean is
13331 Typ : constant Entity_Id := Entity (N);
13332 P : Node_Id;
13334 begin
13335 -- Simplest case: entity is a concurrent type and we are currently
13336 -- inside the body. This will eventually be expanded into a
13337 -- call to Self (for tasks) or _object (for protected objects).
13339 if Is_Concurrent_Type (Typ) and then In_Open_Scopes (Typ) then
13340 return True;
13342 else
13343 -- Check whether the context is a (sub)type declaration for the
13344 -- type entity.
13346 P := Parent (N);
13347 while Present (P) loop
13348 if Nkind_In (P, N_Full_Type_Declaration,
13349 N_Private_Type_Declaration,
13350 N_Subtype_Declaration)
13351 and then Comes_From_Source (P)
13352 and then Defining_Entity (P) = Typ
13353 then
13354 return True;
13356 -- A subtype name may appear in an aspect specification for a
13357 -- Predicate_Failure aspect, for which we do not construct a
13358 -- wrapper procedure. The subtype will be replaced by the
13359 -- expression being tested when the corresponding predicate
13360 -- check is expanded.
13362 elsif Nkind (P) = N_Aspect_Specification
13363 and then Nkind (Parent (P)) = N_Subtype_Declaration
13364 then
13365 return True;
13367 elsif Nkind (P) = N_Pragma
13368 and then
13369 Get_Pragma_Id (P) = Pragma_Predicate_Failure
13370 then
13371 return True;
13372 end if;
13374 P := Parent (P);
13375 end loop;
13376 end if;
13378 -- In any other context this is not a current occurrence
13380 return False;
13381 end Is_Current_Instance;
13383 --------------------
13384 -- Is_Declaration --
13385 --------------------
13387 function Is_Declaration (N : Node_Id) return Boolean is
13388 begin
13389 return
13390 Is_Declaration_Other_Than_Renaming (N)
13391 or else Is_Renaming_Declaration (N);
13392 end Is_Declaration;
13394 ----------------------------------------
13395 -- Is_Declaration_Other_Than_Renaming --
13396 ----------------------------------------
13398 function Is_Declaration_Other_Than_Renaming (N : Node_Id) return Boolean is
13399 begin
13400 case Nkind (N) is
13401 when N_Abstract_Subprogram_Declaration
13402 | N_Exception_Declaration
13403 | N_Expression_Function
13404 | N_Full_Type_Declaration
13405 | N_Generic_Package_Declaration
13406 | N_Generic_Subprogram_Declaration
13407 | N_Number_Declaration
13408 | N_Object_Declaration
13409 | N_Package_Declaration
13410 | N_Private_Extension_Declaration
13411 | N_Private_Type_Declaration
13412 | N_Subprogram_Declaration
13413 | N_Subtype_Declaration
13415 return True;
13417 when others =>
13418 return False;
13419 end case;
13420 end Is_Declaration_Other_Than_Renaming;
13422 --------------------------------
13423 -- Is_Declared_Within_Variant --
13424 --------------------------------
13426 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
13427 Comp_Decl : constant Node_Id := Parent (Comp);
13428 Comp_List : constant Node_Id := Parent (Comp_Decl);
13429 begin
13430 return Nkind (Parent (Comp_List)) = N_Variant;
13431 end Is_Declared_Within_Variant;
13433 ----------------------------------------------
13434 -- Is_Dependent_Component_Of_Mutable_Object --
13435 ----------------------------------------------
13437 function Is_Dependent_Component_Of_Mutable_Object
13438 (Object : Node_Id) return Boolean
13440 P : Node_Id;
13441 Prefix_Type : Entity_Id;
13442 P_Aliased : Boolean := False;
13443 Comp : Entity_Id;
13445 Deref : Node_Id := Object;
13446 -- Dereference node, in something like X.all.Y(2)
13448 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
13450 begin
13451 -- Find the dereference node if any
13453 while Nkind_In (Deref, N_Indexed_Component,
13454 N_Selected_Component,
13455 N_Slice)
13456 loop
13457 Deref := Prefix (Deref);
13458 end loop;
13460 -- Ada 2005: If we have a component or slice of a dereference,
13461 -- something like X.all.Y (2), and the type of X is access-to-constant,
13462 -- Is_Variable will return False, because it is indeed a constant
13463 -- view. But it might be a view of a variable object, so we want the
13464 -- following condition to be True in that case.
13466 if Is_Variable (Object)
13467 or else (Ada_Version >= Ada_2005
13468 and then Nkind (Deref) = N_Explicit_Dereference)
13469 then
13470 if Nkind (Object) = N_Selected_Component then
13471 P := Prefix (Object);
13472 Prefix_Type := Etype (P);
13474 if Is_Entity_Name (P) then
13475 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
13476 Prefix_Type := Base_Type (Prefix_Type);
13477 end if;
13479 if Is_Aliased (Entity (P)) then
13480 P_Aliased := True;
13481 end if;
13483 -- A discriminant check on a selected component may be expanded
13484 -- into a dereference when removing side effects. Recover the
13485 -- original node and its type, which may be unconstrained.
13487 elsif Nkind (P) = N_Explicit_Dereference
13488 and then not (Comes_From_Source (P))
13489 then
13490 P := Original_Node (P);
13491 Prefix_Type := Etype (P);
13493 else
13494 -- Check for prefix being an aliased component???
13496 null;
13498 end if;
13500 -- A heap object is constrained by its initial value
13502 -- Ada 2005 (AI-363): Always assume the object could be mutable in
13503 -- the dereferenced case, since the access value might denote an
13504 -- unconstrained aliased object, whereas in Ada 95 the designated
13505 -- object is guaranteed to be constrained. A worst-case assumption
13506 -- has to apply in Ada 2005 because we can't tell at compile
13507 -- time whether the object is "constrained by its initial value",
13508 -- despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are semantic
13509 -- rules (these rules are acknowledged to need fixing). We don't
13510 -- impose this more stringent checking for earlier Ada versions or
13511 -- when Relaxed_RM_Semantics applies (the latter for CodePeer's
13512 -- benefit, though it's unclear on why using -gnat95 would not be
13513 -- sufficient???).
13515 if Ada_Version < Ada_2005 or else Relaxed_RM_Semantics then
13516 if Is_Access_Type (Prefix_Type)
13517 or else Nkind (P) = N_Explicit_Dereference
13518 then
13519 return False;
13520 end if;
13522 else pragma Assert (Ada_Version >= Ada_2005);
13523 if Is_Access_Type (Prefix_Type) then
13525 -- If the access type is pool-specific, and there is no
13526 -- constrained partial view of the designated type, then the
13527 -- designated object is known to be constrained.
13529 if Ekind (Prefix_Type) = E_Access_Type
13530 and then not Object_Type_Has_Constrained_Partial_View
13531 (Typ => Designated_Type (Prefix_Type),
13532 Scop => Current_Scope)
13533 then
13534 return False;
13536 -- Otherwise (general access type, or there is a constrained
13537 -- partial view of the designated type), we need to check
13538 -- based on the designated type.
13540 else
13541 Prefix_Type := Designated_Type (Prefix_Type);
13542 end if;
13543 end if;
13544 end if;
13546 Comp :=
13547 Original_Record_Component (Entity (Selector_Name (Object)));
13549 -- As per AI-0017, the renaming is illegal in a generic body, even
13550 -- if the subtype is indefinite.
13552 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
13554 if not Is_Constrained (Prefix_Type)
13555 and then (Is_Definite_Subtype (Prefix_Type)
13556 or else
13557 (Is_Generic_Type (Prefix_Type)
13558 and then Ekind (Current_Scope) = E_Generic_Package
13559 and then In_Package_Body (Current_Scope)))
13561 and then (Is_Declared_Within_Variant (Comp)
13562 or else Has_Discriminant_Dependent_Constraint (Comp))
13563 and then (not P_Aliased or else Ada_Version >= Ada_2005)
13564 then
13565 return True;
13567 -- If the prefix is of an access type at this point, then we want
13568 -- to return False, rather than calling this function recursively
13569 -- on the access object (which itself might be a discriminant-
13570 -- dependent component of some other object, but that isn't
13571 -- relevant to checking the object passed to us). This avoids
13572 -- issuing wrong errors when compiling with -gnatc, where there
13573 -- can be implicit dereferences that have not been expanded.
13575 elsif Is_Access_Type (Etype (Prefix (Object))) then
13576 return False;
13578 else
13579 return
13580 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
13581 end if;
13583 elsif Nkind (Object) = N_Indexed_Component
13584 or else Nkind (Object) = N_Slice
13585 then
13586 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
13588 -- A type conversion that Is_Variable is a view conversion:
13589 -- go back to the denoted object.
13591 elsif Nkind (Object) = N_Type_Conversion then
13592 return
13593 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
13594 end if;
13595 end if;
13597 return False;
13598 end Is_Dependent_Component_Of_Mutable_Object;
13600 ---------------------
13601 -- Is_Dereferenced --
13602 ---------------------
13604 function Is_Dereferenced (N : Node_Id) return Boolean is
13605 P : constant Node_Id := Parent (N);
13606 begin
13607 return Nkind_In (P, N_Selected_Component,
13608 N_Explicit_Dereference,
13609 N_Indexed_Component,
13610 N_Slice)
13611 and then Prefix (P) = N;
13612 end Is_Dereferenced;
13614 ----------------------
13615 -- Is_Descendant_Of --
13616 ----------------------
13618 function Is_Descendant_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
13619 T : Entity_Id;
13620 Etyp : Entity_Id;
13622 begin
13623 pragma Assert (Nkind (T1) in N_Entity);
13624 pragma Assert (Nkind (T2) in N_Entity);
13626 T := Base_Type (T1);
13628 -- Immediate return if the types match
13630 if T = T2 then
13631 return True;
13633 -- Comment needed here ???
13635 elsif Ekind (T) = E_Class_Wide_Type then
13636 return Etype (T) = T2;
13638 -- All other cases
13640 else
13641 loop
13642 Etyp := Etype (T);
13644 -- Done if we found the type we are looking for
13646 if Etyp = T2 then
13647 return True;
13649 -- Done if no more derivations to check
13651 elsif T = T1
13652 or else T = Etyp
13653 then
13654 return False;
13656 -- Following test catches error cases resulting from prev errors
13658 elsif No (Etyp) then
13659 return False;
13661 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
13662 return False;
13664 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
13665 return False;
13666 end if;
13668 T := Base_Type (Etyp);
13669 end loop;
13670 end if;
13671 end Is_Descendant_Of;
13673 ----------------------------------------
13674 -- Is_Descendant_Of_Suspension_Object --
13675 ----------------------------------------
13677 function Is_Descendant_Of_Suspension_Object
13678 (Typ : Entity_Id) return Boolean
13680 Cur_Typ : Entity_Id;
13681 Par_Typ : Entity_Id;
13683 begin
13684 -- Climb the type derivation chain checking each parent type against
13685 -- Suspension_Object.
13687 Cur_Typ := Base_Type (Typ);
13688 while Present (Cur_Typ) loop
13689 Par_Typ := Etype (Cur_Typ);
13691 -- The current type is a match
13693 if Is_Suspension_Object (Cur_Typ) then
13694 return True;
13696 -- Stop the traversal once the root of the derivation chain has been
13697 -- reached. In that case the current type is its own base type.
13699 elsif Cur_Typ = Par_Typ then
13700 exit;
13701 end if;
13703 Cur_Typ := Base_Type (Par_Typ);
13704 end loop;
13706 return False;
13707 end Is_Descendant_Of_Suspension_Object;
13709 ---------------------------------------------
13710 -- Is_Double_Precision_Floating_Point_Type --
13711 ---------------------------------------------
13713 function Is_Double_Precision_Floating_Point_Type
13714 (E : Entity_Id) return Boolean is
13715 begin
13716 return Is_Floating_Point_Type (E)
13717 and then Machine_Radix_Value (E) = Uint_2
13718 and then Machine_Mantissa_Value (E) = UI_From_Int (53)
13719 and then Machine_Emax_Value (E) = Uint_2 ** Uint_10
13720 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_10);
13721 end Is_Double_Precision_Floating_Point_Type;
13723 -----------------------------
13724 -- Is_Effectively_Volatile --
13725 -----------------------------
13727 function Is_Effectively_Volatile (Id : Entity_Id) return Boolean is
13728 begin
13729 if Is_Type (Id) then
13731 -- An arbitrary type is effectively volatile when it is subject to
13732 -- pragma Atomic or Volatile.
13734 if Is_Volatile (Id) then
13735 return True;
13737 -- An array type is effectively volatile when it is subject to pragma
13738 -- Atomic_Components or Volatile_Components or its component type is
13739 -- effectively volatile.
13741 elsif Is_Array_Type (Id) then
13742 declare
13743 Anc : Entity_Id := Base_Type (Id);
13744 begin
13745 if Is_Private_Type (Anc) then
13746 Anc := Full_View (Anc);
13747 end if;
13749 -- Test for presence of ancestor, as the full view of a private
13750 -- type may be missing in case of error.
13752 return
13753 Has_Volatile_Components (Id)
13754 or else
13755 (Present (Anc)
13756 and then Is_Effectively_Volatile (Component_Type (Anc)));
13757 end;
13759 -- A protected type is always volatile
13761 elsif Is_Protected_Type (Id) then
13762 return True;
13764 -- A descendant of Ada.Synchronous_Task_Control.Suspension_Object is
13765 -- automatically volatile.
13767 elsif Is_Descendant_Of_Suspension_Object (Id) then
13768 return True;
13770 -- Otherwise the type is not effectively volatile
13772 else
13773 return False;
13774 end if;
13776 -- Otherwise Id denotes an object
13778 else
13779 return
13780 Is_Volatile (Id)
13781 or else Has_Volatile_Components (Id)
13782 or else Is_Effectively_Volatile (Etype (Id));
13783 end if;
13784 end Is_Effectively_Volatile;
13786 ------------------------------------
13787 -- Is_Effectively_Volatile_Object --
13788 ------------------------------------
13790 function Is_Effectively_Volatile_Object (N : Node_Id) return Boolean is
13791 begin
13792 if Is_Entity_Name (N) then
13793 return Is_Effectively_Volatile (Entity (N));
13795 elsif Nkind (N) = N_Indexed_Component then
13796 return Is_Effectively_Volatile_Object (Prefix (N));
13798 elsif Nkind (N) = N_Selected_Component then
13799 return
13800 Is_Effectively_Volatile_Object (Prefix (N))
13801 or else
13802 Is_Effectively_Volatile_Object (Selector_Name (N));
13804 else
13805 return False;
13806 end if;
13807 end Is_Effectively_Volatile_Object;
13809 -------------------
13810 -- Is_Entry_Body --
13811 -------------------
13813 function Is_Entry_Body (Id : Entity_Id) return Boolean is
13814 begin
13815 return
13816 Ekind_In (Id, E_Entry, E_Entry_Family)
13817 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Body;
13818 end Is_Entry_Body;
13820 --------------------------
13821 -- Is_Entry_Declaration --
13822 --------------------------
13824 function Is_Entry_Declaration (Id : Entity_Id) return Boolean is
13825 begin
13826 return
13827 Ekind_In (Id, E_Entry, E_Entry_Family)
13828 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Declaration;
13829 end Is_Entry_Declaration;
13831 ------------------------------------
13832 -- Is_Expanded_Priority_Attribute --
13833 ------------------------------------
13835 function Is_Expanded_Priority_Attribute (E : Entity_Id) return Boolean is
13836 begin
13837 return
13838 Nkind (E) = N_Function_Call
13839 and then not Configurable_Run_Time_Mode
13840 and then (Entity (Name (E)) = RTE (RE_Get_Ceiling)
13841 or else Entity (Name (E)) = RTE (RO_PE_Get_Ceiling));
13842 end Is_Expanded_Priority_Attribute;
13844 ----------------------------
13845 -- Is_Expression_Function --
13846 ----------------------------
13848 function Is_Expression_Function (Subp : Entity_Id) return Boolean is
13849 begin
13850 if Ekind_In (Subp, E_Function, E_Subprogram_Body) then
13851 return
13852 Nkind (Original_Node (Unit_Declaration_Node (Subp))) =
13853 N_Expression_Function;
13854 else
13855 return False;
13856 end if;
13857 end Is_Expression_Function;
13859 ------------------------------------------
13860 -- Is_Expression_Function_Or_Completion --
13861 ------------------------------------------
13863 function Is_Expression_Function_Or_Completion
13864 (Subp : Entity_Id) return Boolean
13866 Subp_Decl : Node_Id;
13868 begin
13869 if Ekind (Subp) = E_Function then
13870 Subp_Decl := Unit_Declaration_Node (Subp);
13872 -- The function declaration is either an expression function or is
13873 -- completed by an expression function body.
13875 return
13876 Is_Expression_Function (Subp)
13877 or else (Nkind (Subp_Decl) = N_Subprogram_Declaration
13878 and then Present (Corresponding_Body (Subp_Decl))
13879 and then Is_Expression_Function
13880 (Corresponding_Body (Subp_Decl)));
13882 elsif Ekind (Subp) = E_Subprogram_Body then
13883 return Is_Expression_Function (Subp);
13885 else
13886 return False;
13887 end if;
13888 end Is_Expression_Function_Or_Completion;
13890 -----------------------
13891 -- Is_EVF_Expression --
13892 -----------------------
13894 function Is_EVF_Expression (N : Node_Id) return Boolean is
13895 Orig_N : constant Node_Id := Original_Node (N);
13896 Alt : Node_Id;
13897 Expr : Node_Id;
13898 Id : Entity_Id;
13900 begin
13901 -- Detect a reference to a formal parameter of a specific tagged type
13902 -- whose related subprogram is subject to pragma Expresions_Visible with
13903 -- value "False".
13905 if Is_Entity_Name (N) and then Present (Entity (N)) then
13906 Id := Entity (N);
13908 return
13909 Is_Formal (Id)
13910 and then Is_Specific_Tagged_Type (Etype (Id))
13911 and then Extensions_Visible_Status (Id) =
13912 Extensions_Visible_False;
13914 -- A case expression is an EVF expression when it contains at least one
13915 -- EVF dependent_expression. Note that a case expression may have been
13916 -- expanded, hence the use of Original_Node.
13918 elsif Nkind (Orig_N) = N_Case_Expression then
13919 Alt := First (Alternatives (Orig_N));
13920 while Present (Alt) loop
13921 if Is_EVF_Expression (Expression (Alt)) then
13922 return True;
13923 end if;
13925 Next (Alt);
13926 end loop;
13928 -- An if expression is an EVF expression when it contains at least one
13929 -- EVF dependent_expression. Note that an if expression may have been
13930 -- expanded, hence the use of Original_Node.
13932 elsif Nkind (Orig_N) = N_If_Expression then
13933 Expr := Next (First (Expressions (Orig_N)));
13934 while Present (Expr) loop
13935 if Is_EVF_Expression (Expr) then
13936 return True;
13937 end if;
13939 Next (Expr);
13940 end loop;
13942 -- A qualified expression or a type conversion is an EVF expression when
13943 -- its operand is an EVF expression.
13945 elsif Nkind_In (N, N_Qualified_Expression,
13946 N_Unchecked_Type_Conversion,
13947 N_Type_Conversion)
13948 then
13949 return Is_EVF_Expression (Expression (N));
13951 -- Attributes 'Loop_Entry, 'Old, and 'Update are EVF expressions when
13952 -- their prefix denotes an EVF expression.
13954 elsif Nkind (N) = N_Attribute_Reference
13955 and then Nam_In (Attribute_Name (N), Name_Loop_Entry,
13956 Name_Old,
13957 Name_Update)
13958 then
13959 return Is_EVF_Expression (Prefix (N));
13960 end if;
13962 return False;
13963 end Is_EVF_Expression;
13965 --------------
13966 -- Is_False --
13967 --------------
13969 function Is_False (U : Uint) return Boolean is
13970 begin
13971 return (U = 0);
13972 end Is_False;
13974 ---------------------------
13975 -- Is_Fixed_Model_Number --
13976 ---------------------------
13978 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
13979 S : constant Ureal := Small_Value (T);
13980 M : Urealp.Save_Mark;
13981 R : Boolean;
13983 begin
13984 M := Urealp.Mark;
13985 R := (U = UR_Trunc (U / S) * S);
13986 Urealp.Release (M);
13987 return R;
13988 end Is_Fixed_Model_Number;
13990 -------------------------------
13991 -- Is_Fully_Initialized_Type --
13992 -------------------------------
13994 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
13995 begin
13996 -- Scalar types
13998 if Is_Scalar_Type (Typ) then
14000 -- A scalar type with an aspect Default_Value is fully initialized
14002 -- Note: Iniitalize/Normalize_Scalars also ensure full initialization
14003 -- of a scalar type, but we don't take that into account here, since
14004 -- we don't want these to affect warnings.
14006 return Has_Default_Aspect (Typ);
14008 elsif Is_Access_Type (Typ) then
14009 return True;
14011 elsif Is_Array_Type (Typ) then
14012 if Is_Fully_Initialized_Type (Component_Type (Typ))
14013 or else (Ada_Version >= Ada_2012 and then Has_Default_Aspect (Typ))
14014 then
14015 return True;
14016 end if;
14018 -- An interesting case, if we have a constrained type one of whose
14019 -- bounds is known to be null, then there are no elements to be
14020 -- initialized, so all the elements are initialized.
14022 if Is_Constrained (Typ) then
14023 declare
14024 Indx : Node_Id;
14025 Indx_Typ : Entity_Id;
14026 Lbd, Hbd : Node_Id;
14028 begin
14029 Indx := First_Index (Typ);
14030 while Present (Indx) loop
14031 if Etype (Indx) = Any_Type then
14032 return False;
14034 -- If index is a range, use directly
14036 elsif Nkind (Indx) = N_Range then
14037 Lbd := Low_Bound (Indx);
14038 Hbd := High_Bound (Indx);
14040 else
14041 Indx_Typ := Etype (Indx);
14043 if Is_Private_Type (Indx_Typ) then
14044 Indx_Typ := Full_View (Indx_Typ);
14045 end if;
14047 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
14048 return False;
14049 else
14050 Lbd := Type_Low_Bound (Indx_Typ);
14051 Hbd := Type_High_Bound (Indx_Typ);
14052 end if;
14053 end if;
14055 if Compile_Time_Known_Value (Lbd)
14056 and then
14057 Compile_Time_Known_Value (Hbd)
14058 then
14059 if Expr_Value (Hbd) < Expr_Value (Lbd) then
14060 return True;
14061 end if;
14062 end if;
14064 Next_Index (Indx);
14065 end loop;
14066 end;
14067 end if;
14069 -- If no null indexes, then type is not fully initialized
14071 return False;
14073 -- Record types
14075 elsif Is_Record_Type (Typ) then
14076 if Has_Discriminants (Typ)
14077 and then
14078 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
14079 and then Is_Fully_Initialized_Variant (Typ)
14080 then
14081 return True;
14082 end if;
14084 -- We consider bounded string types to be fully initialized, because
14085 -- otherwise we get false alarms when the Data component is not
14086 -- default-initialized.
14088 if Is_Bounded_String (Typ) then
14089 return True;
14090 end if;
14092 -- Controlled records are considered to be fully initialized if
14093 -- there is a user defined Initialize routine. This may not be
14094 -- entirely correct, but as the spec notes, we are guessing here
14095 -- what is best from the point of view of issuing warnings.
14097 if Is_Controlled (Typ) then
14098 declare
14099 Utyp : constant Entity_Id := Underlying_Type (Typ);
14101 begin
14102 if Present (Utyp) then
14103 declare
14104 Init : constant Entity_Id :=
14105 (Find_Optional_Prim_Op
14106 (Underlying_Type (Typ), Name_Initialize));
14108 begin
14109 if Present (Init)
14110 and then Comes_From_Source (Init)
14111 and then not In_Predefined_Unit (Init)
14112 then
14113 return True;
14115 elsif Has_Null_Extension (Typ)
14116 and then
14117 Is_Fully_Initialized_Type
14118 (Etype (Base_Type (Typ)))
14119 then
14120 return True;
14121 end if;
14122 end;
14123 end if;
14124 end;
14125 end if;
14127 -- Otherwise see if all record components are initialized
14129 declare
14130 Ent : Entity_Id;
14132 begin
14133 Ent := First_Entity (Typ);
14134 while Present (Ent) loop
14135 if Ekind (Ent) = E_Component
14136 and then (No (Parent (Ent))
14137 or else No (Expression (Parent (Ent))))
14138 and then not Is_Fully_Initialized_Type (Etype (Ent))
14140 -- Special VM case for tag components, which need to be
14141 -- defined in this case, but are never initialized as VMs
14142 -- are using other dispatching mechanisms. Ignore this
14143 -- uninitialized case. Note that this applies both to the
14144 -- uTag entry and the main vtable pointer (CPP_Class case).
14146 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
14147 then
14148 return False;
14149 end if;
14151 Next_Entity (Ent);
14152 end loop;
14153 end;
14155 -- No uninitialized components, so type is fully initialized.
14156 -- Note that this catches the case of no components as well.
14158 return True;
14160 elsif Is_Concurrent_Type (Typ) then
14161 return True;
14163 elsif Is_Private_Type (Typ) then
14164 declare
14165 U : constant Entity_Id := Underlying_Type (Typ);
14167 begin
14168 if No (U) then
14169 return False;
14170 else
14171 return Is_Fully_Initialized_Type (U);
14172 end if;
14173 end;
14175 else
14176 return False;
14177 end if;
14178 end Is_Fully_Initialized_Type;
14180 ----------------------------------
14181 -- Is_Fully_Initialized_Variant --
14182 ----------------------------------
14184 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
14185 Loc : constant Source_Ptr := Sloc (Typ);
14186 Constraints : constant List_Id := New_List;
14187 Components : constant Elist_Id := New_Elmt_List;
14188 Comp_Elmt : Elmt_Id;
14189 Comp_Id : Node_Id;
14190 Comp_List : Node_Id;
14191 Discr : Entity_Id;
14192 Discr_Val : Node_Id;
14194 Report_Errors : Boolean;
14195 pragma Warnings (Off, Report_Errors);
14197 begin
14198 if Serious_Errors_Detected > 0 then
14199 return False;
14200 end if;
14202 if Is_Record_Type (Typ)
14203 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
14204 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
14205 then
14206 Comp_List := Component_List (Type_Definition (Parent (Typ)));
14208 Discr := First_Discriminant (Typ);
14209 while Present (Discr) loop
14210 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
14211 Discr_Val := Expression (Parent (Discr));
14213 if Present (Discr_Val)
14214 and then Is_OK_Static_Expression (Discr_Val)
14215 then
14216 Append_To (Constraints,
14217 Make_Component_Association (Loc,
14218 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
14219 Expression => New_Copy (Discr_Val)));
14220 else
14221 return False;
14222 end if;
14223 else
14224 return False;
14225 end if;
14227 Next_Discriminant (Discr);
14228 end loop;
14230 Gather_Components
14231 (Typ => Typ,
14232 Comp_List => Comp_List,
14233 Governed_By => Constraints,
14234 Into => Components,
14235 Report_Errors => Report_Errors);
14237 -- Check that each component present is fully initialized
14239 Comp_Elmt := First_Elmt (Components);
14240 while Present (Comp_Elmt) loop
14241 Comp_Id := Node (Comp_Elmt);
14243 if Ekind (Comp_Id) = E_Component
14244 and then (No (Parent (Comp_Id))
14245 or else No (Expression (Parent (Comp_Id))))
14246 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
14247 then
14248 return False;
14249 end if;
14251 Next_Elmt (Comp_Elmt);
14252 end loop;
14254 return True;
14256 elsif Is_Private_Type (Typ) then
14257 declare
14258 U : constant Entity_Id := Underlying_Type (Typ);
14260 begin
14261 if No (U) then
14262 return False;
14263 else
14264 return Is_Fully_Initialized_Variant (U);
14265 end if;
14266 end;
14268 else
14269 return False;
14270 end if;
14271 end Is_Fully_Initialized_Variant;
14273 ------------------------------------
14274 -- Is_Generic_Declaration_Or_Body --
14275 ------------------------------------
14277 function Is_Generic_Declaration_Or_Body (Decl : Node_Id) return Boolean is
14278 Spec_Decl : Node_Id;
14280 begin
14281 -- Package/subprogram body
14283 if Nkind_In (Decl, N_Package_Body, N_Subprogram_Body)
14284 and then Present (Corresponding_Spec (Decl))
14285 then
14286 Spec_Decl := Unit_Declaration_Node (Corresponding_Spec (Decl));
14288 -- Package/subprogram body stub
14290 elsif Nkind_In (Decl, N_Package_Body_Stub, N_Subprogram_Body_Stub)
14291 and then Present (Corresponding_Spec_Of_Stub (Decl))
14292 then
14293 Spec_Decl :=
14294 Unit_Declaration_Node (Corresponding_Spec_Of_Stub (Decl));
14296 -- All other cases
14298 else
14299 Spec_Decl := Decl;
14300 end if;
14302 -- Rather than inspecting the defining entity of the spec declaration,
14303 -- look at its Nkind. This takes care of the case where the analysis of
14304 -- a generic body modifies the Ekind of its spec to allow for recursive
14305 -- calls.
14307 return
14308 Nkind_In (Spec_Decl, N_Generic_Package_Declaration,
14309 N_Generic_Subprogram_Declaration);
14310 end Is_Generic_Declaration_Or_Body;
14312 ----------------------------
14313 -- Is_Inherited_Operation --
14314 ----------------------------
14316 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
14317 pragma Assert (Is_Overloadable (E));
14318 Kind : constant Node_Kind := Nkind (Parent (E));
14319 begin
14320 return Kind = N_Full_Type_Declaration
14321 or else Kind = N_Private_Extension_Declaration
14322 or else Kind = N_Subtype_Declaration
14323 or else (Ekind (E) = E_Enumeration_Literal
14324 and then Is_Derived_Type (Etype (E)));
14325 end Is_Inherited_Operation;
14327 -------------------------------------
14328 -- Is_Inherited_Operation_For_Type --
14329 -------------------------------------
14331 function Is_Inherited_Operation_For_Type
14332 (E : Entity_Id;
14333 Typ : Entity_Id) return Boolean
14335 begin
14336 -- Check that the operation has been created by the type declaration
14338 return Is_Inherited_Operation (E)
14339 and then Defining_Identifier (Parent (E)) = Typ;
14340 end Is_Inherited_Operation_For_Type;
14342 --------------------------------------
14343 -- Is_Inlinable_Expression_Function --
14344 --------------------------------------
14346 function Is_Inlinable_Expression_Function
14347 (Subp : Entity_Id) return Boolean
14349 Return_Expr : Node_Id;
14351 begin
14352 if Is_Expression_Function_Or_Completion (Subp)
14353 and then Has_Pragma_Inline_Always (Subp)
14354 and then Needs_No_Actuals (Subp)
14355 and then No (Contract (Subp))
14356 and then not Is_Dispatching_Operation (Subp)
14357 and then Needs_Finalization (Etype (Subp))
14358 and then not Is_Class_Wide_Type (Etype (Subp))
14359 and then not (Has_Invariants (Etype (Subp)))
14360 and then Present (Subprogram_Body (Subp))
14361 and then Was_Expression_Function (Subprogram_Body (Subp))
14362 then
14363 Return_Expr := Expression_Of_Expression_Function (Subp);
14365 -- The returned object must not have a qualified expression and its
14366 -- nominal subtype must be statically compatible with the result
14367 -- subtype of the expression function.
14369 return
14370 Nkind (Return_Expr) = N_Identifier
14371 and then Etype (Return_Expr) = Etype (Subp);
14372 end if;
14374 return False;
14375 end Is_Inlinable_Expression_Function;
14377 -----------------
14378 -- Is_Iterator --
14379 -----------------
14381 function Is_Iterator (Typ : Entity_Id) return Boolean is
14382 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean;
14383 -- Determine whether type Iter_Typ is a predefined forward or reversible
14384 -- iterator.
14386 ----------------------
14387 -- Denotes_Iterator --
14388 ----------------------
14390 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean is
14391 begin
14392 -- Check that the name matches, and that the ultimate ancestor is in
14393 -- a predefined unit, i.e the one that declares iterator interfaces.
14395 return
14396 Nam_In (Chars (Iter_Typ), Name_Forward_Iterator,
14397 Name_Reversible_Iterator)
14398 and then In_Predefined_Unit (Root_Type (Iter_Typ));
14399 end Denotes_Iterator;
14401 -- Local variables
14403 Iface_Elmt : Elmt_Id;
14404 Ifaces : Elist_Id;
14406 -- Start of processing for Is_Iterator
14408 begin
14409 -- The type may be a subtype of a descendant of the proper instance of
14410 -- the predefined interface type, so we must use the root type of the
14411 -- given type. The same is done for Is_Reversible_Iterator.
14413 if Is_Class_Wide_Type (Typ)
14414 and then Denotes_Iterator (Root_Type (Typ))
14415 then
14416 return True;
14418 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
14419 return False;
14421 elsif Present (Find_Value_Of_Aspect (Typ, Aspect_Iterable)) then
14422 return True;
14424 else
14425 Collect_Interfaces (Typ, Ifaces);
14427 Iface_Elmt := First_Elmt (Ifaces);
14428 while Present (Iface_Elmt) loop
14429 if Denotes_Iterator (Node (Iface_Elmt)) then
14430 return True;
14431 end if;
14433 Next_Elmt (Iface_Elmt);
14434 end loop;
14436 return False;
14437 end if;
14438 end Is_Iterator;
14440 ----------------------------
14441 -- Is_Iterator_Over_Array --
14442 ----------------------------
14444 function Is_Iterator_Over_Array (N : Node_Id) return Boolean is
14445 Container : constant Node_Id := Name (N);
14446 Container_Typ : constant Entity_Id := Base_Type (Etype (Container));
14447 begin
14448 return Is_Array_Type (Container_Typ);
14449 end Is_Iterator_Over_Array;
14451 ------------
14452 -- Is_LHS --
14453 ------------
14455 -- We seem to have a lot of overlapping functions that do similar things
14456 -- (testing for left hand sides or lvalues???).
14458 function Is_LHS (N : Node_Id) return Is_LHS_Result is
14459 P : constant Node_Id := Parent (N);
14461 begin
14462 -- Return True if we are the left hand side of an assignment statement
14464 if Nkind (P) = N_Assignment_Statement then
14465 if Name (P) = N then
14466 return Yes;
14467 else
14468 return No;
14469 end if;
14471 -- Case of prefix of indexed or selected component or slice
14473 elsif Nkind_In (P, N_Indexed_Component, N_Selected_Component, N_Slice)
14474 and then N = Prefix (P)
14475 then
14476 -- Here we have the case where the parent P is N.Q or N(Q .. R).
14477 -- If P is an LHS, then N is also effectively an LHS, but there
14478 -- is an important exception. If N is of an access type, then
14479 -- what we really have is N.all.Q (or N.all(Q .. R)). In either
14480 -- case this makes N.all a left hand side but not N itself.
14482 -- If we don't know the type yet, this is the case where we return
14483 -- Unknown, since the answer depends on the type which is unknown.
14485 if No (Etype (N)) then
14486 return Unknown;
14488 -- We have an Etype set, so we can check it
14490 elsif Is_Access_Type (Etype (N)) then
14491 return No;
14493 -- OK, not access type case, so just test whole expression
14495 else
14496 return Is_LHS (P);
14497 end if;
14499 -- All other cases are not left hand sides
14501 else
14502 return No;
14503 end if;
14504 end Is_LHS;
14506 -----------------------------
14507 -- Is_Library_Level_Entity --
14508 -----------------------------
14510 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
14511 begin
14512 -- The following is a small optimization, and it also properly handles
14513 -- discriminals, which in task bodies might appear in expressions before
14514 -- the corresponding procedure has been created, and which therefore do
14515 -- not have an assigned scope.
14517 if Is_Formal (E) then
14518 return False;
14519 end if;
14521 -- Normal test is simply that the enclosing dynamic scope is Standard
14523 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
14524 end Is_Library_Level_Entity;
14526 --------------------------------
14527 -- Is_Limited_Class_Wide_Type --
14528 --------------------------------
14530 function Is_Limited_Class_Wide_Type (Typ : Entity_Id) return Boolean is
14531 begin
14532 return
14533 Is_Class_Wide_Type (Typ)
14534 and then (Is_Limited_Type (Typ) or else From_Limited_With (Typ));
14535 end Is_Limited_Class_Wide_Type;
14537 ---------------------------------
14538 -- Is_Local_Variable_Reference --
14539 ---------------------------------
14541 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
14542 begin
14543 if not Is_Entity_Name (Expr) then
14544 return False;
14546 else
14547 declare
14548 Ent : constant Entity_Id := Entity (Expr);
14549 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
14550 begin
14551 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
14552 return False;
14553 else
14554 return Present (Sub) and then Sub = Current_Subprogram;
14555 end if;
14556 end;
14557 end if;
14558 end Is_Local_Variable_Reference;
14560 -----------------------
14561 -- Is_Name_Reference --
14562 -----------------------
14564 function Is_Name_Reference (N : Node_Id) return Boolean is
14565 begin
14566 if Is_Entity_Name (N) then
14567 return Present (Entity (N)) and then Is_Object (Entity (N));
14568 end if;
14570 case Nkind (N) is
14571 when N_Indexed_Component
14572 | N_Slice
14574 return
14575 Is_Name_Reference (Prefix (N))
14576 or else Is_Access_Type (Etype (Prefix (N)));
14578 -- Attributes 'Input, 'Old and 'Result produce objects
14580 when N_Attribute_Reference =>
14581 return
14582 Nam_In (Attribute_Name (N), Name_Input, Name_Old, Name_Result);
14584 when N_Selected_Component =>
14585 return
14586 Is_Name_Reference (Selector_Name (N))
14587 and then
14588 (Is_Name_Reference (Prefix (N))
14589 or else Is_Access_Type (Etype (Prefix (N))));
14591 when N_Explicit_Dereference =>
14592 return True;
14594 -- A view conversion of a tagged name is a name reference
14596 when N_Type_Conversion =>
14597 return
14598 Is_Tagged_Type (Etype (Subtype_Mark (N)))
14599 and then Is_Tagged_Type (Etype (Expression (N)))
14600 and then Is_Name_Reference (Expression (N));
14602 -- An unchecked type conversion is considered to be a name if the
14603 -- operand is a name (this construction arises only as a result of
14604 -- expansion activities).
14606 when N_Unchecked_Type_Conversion =>
14607 return Is_Name_Reference (Expression (N));
14609 when others =>
14610 return False;
14611 end case;
14612 end Is_Name_Reference;
14614 ------------------------------------
14615 -- Is_Non_Preelaborable_Construct --
14616 ------------------------------------
14618 function Is_Non_Preelaborable_Construct (N : Node_Id) return Boolean is
14620 -- NOTE: the routines within Is_Non_Preelaborable_Construct are
14621 -- intentionally unnested to avoid deep indentation of code.
14623 Non_Preelaborable : exception;
14624 -- This exception is raised when the construct violates preelaborability
14625 -- to terminate the recursion.
14627 procedure Visit (Nod : Node_Id);
14628 -- Semantically inspect construct Nod to determine whether it violates
14629 -- preelaborability. This routine raises Non_Preelaborable.
14631 procedure Visit_List (List : List_Id);
14632 pragma Inline (Visit_List);
14633 -- Invoke Visit on each element of list List. This routine raises
14634 -- Non_Preelaborable.
14636 procedure Visit_Pragma (Prag : Node_Id);
14637 pragma Inline (Visit_Pragma);
14638 -- Semantically inspect pragma Prag to determine whether it violates
14639 -- preelaborability. This routine raises Non_Preelaborable.
14641 procedure Visit_Subexpression (Expr : Node_Id);
14642 pragma Inline (Visit_Subexpression);
14643 -- Semantically inspect expression Expr to determine whether it violates
14644 -- preelaborability. This routine raises Non_Preelaborable.
14646 -----------
14647 -- Visit --
14648 -----------
14650 procedure Visit (Nod : Node_Id) is
14651 begin
14652 case Nkind (Nod) is
14654 -- Declarations
14656 when N_Component_Declaration =>
14658 -- Defining_Identifier is left out because it is not relevant
14659 -- for preelaborability.
14661 Visit (Component_Definition (Nod));
14662 Visit (Expression (Nod));
14664 when N_Derived_Type_Definition =>
14666 -- Interface_List is left out because it is not relevant for
14667 -- preelaborability.
14669 Visit (Record_Extension_Part (Nod));
14670 Visit (Subtype_Indication (Nod));
14672 when N_Entry_Declaration =>
14674 -- A protected type with at leat one entry is not preelaborable
14675 -- while task types are never preelaborable. This renders entry
14676 -- declarations non-preelaborable.
14678 raise Non_Preelaborable;
14680 when N_Full_Type_Declaration =>
14682 -- Defining_Identifier and Discriminant_Specifications are left
14683 -- out because they are not relevant for preelaborability.
14685 Visit (Type_Definition (Nod));
14687 when N_Function_Instantiation
14688 | N_Package_Instantiation
14689 | N_Procedure_Instantiation
14691 -- Defining_Unit_Name and Name are left out because they are
14692 -- not relevant for preelaborability.
14694 Visit_List (Generic_Associations (Nod));
14696 when N_Object_Declaration =>
14698 -- Defining_Identifier is left out because it is not relevant
14699 -- for preelaborability.
14701 Visit (Object_Definition (Nod));
14703 if Has_Init_Expression (Nod) then
14704 Visit (Expression (Nod));
14706 elsif not Has_Preelaborable_Initialization
14707 (Etype (Defining_Entity (Nod)))
14708 then
14709 raise Non_Preelaborable;
14710 end if;
14712 when N_Private_Extension_Declaration
14713 | N_Subtype_Declaration
14715 -- Defining_Identifier, Discriminant_Specifications, and
14716 -- Interface_List are left out because they are not relevant
14717 -- for preelaborability.
14719 Visit (Subtype_Indication (Nod));
14721 when N_Protected_Type_Declaration
14722 | N_Single_Protected_Declaration
14724 -- Defining_Identifier, Discriminant_Specifications, and
14725 -- Interface_List are left out because they are not relevant
14726 -- for preelaborability.
14728 Visit (Protected_Definition (Nod));
14730 -- A [single] task type is never preelaborable
14732 when N_Single_Task_Declaration
14733 | N_Task_Type_Declaration
14735 raise Non_Preelaborable;
14737 -- Pragmas
14739 when N_Pragma =>
14740 Visit_Pragma (Nod);
14742 -- Statements
14744 when N_Statement_Other_Than_Procedure_Call =>
14745 if Nkind (Nod) /= N_Null_Statement then
14746 raise Non_Preelaborable;
14747 end if;
14749 -- Subexpressions
14751 when N_Subexpr =>
14752 Visit_Subexpression (Nod);
14754 -- Special
14756 when N_Access_To_Object_Definition =>
14757 Visit (Subtype_Indication (Nod));
14759 when N_Case_Expression_Alternative =>
14760 Visit (Expression (Nod));
14761 Visit_List (Discrete_Choices (Nod));
14763 when N_Component_Definition =>
14764 Visit (Access_Definition (Nod));
14765 Visit (Subtype_Indication (Nod));
14767 when N_Component_List =>
14768 Visit_List (Component_Items (Nod));
14769 Visit (Variant_Part (Nod));
14771 when N_Constrained_Array_Definition =>
14772 Visit_List (Discrete_Subtype_Definitions (Nod));
14773 Visit (Component_Definition (Nod));
14775 when N_Delta_Constraint
14776 | N_Digits_Constraint
14778 -- Delta_Expression and Digits_Expression are left out because
14779 -- they are not relevant for preelaborability.
14781 Visit (Range_Constraint (Nod));
14783 when N_Discriminant_Specification =>
14785 -- Defining_Identifier and Expression are left out because they
14786 -- are not relevant for preelaborability.
14788 Visit (Discriminant_Type (Nod));
14790 when N_Generic_Association =>
14792 -- Selector_Name is left out because it is not relevant for
14793 -- preelaborability.
14795 Visit (Explicit_Generic_Actual_Parameter (Nod));
14797 when N_Index_Or_Discriminant_Constraint =>
14798 Visit_List (Constraints (Nod));
14800 when N_Iterator_Specification =>
14802 -- Defining_Identifier is left out because it is not relevant
14803 -- for preelaborability.
14805 Visit (Name (Nod));
14806 Visit (Subtype_Indication (Nod));
14808 when N_Loop_Parameter_Specification =>
14810 -- Defining_Identifier is left out because it is not relevant
14811 -- for preelaborability.
14813 Visit (Discrete_Subtype_Definition (Nod));
14815 when N_Protected_Definition =>
14817 -- End_Label is left out because it is not relevant for
14818 -- preelaborability.
14820 Visit_List (Private_Declarations (Nod));
14821 Visit_List (Visible_Declarations (Nod));
14823 when N_Range_Constraint =>
14824 Visit (Range_Expression (Nod));
14826 when N_Record_Definition
14827 | N_Variant
14829 -- End_Label, Discrete_Choices, and Interface_List are left out
14830 -- because they are not relevant for preelaborability.
14832 Visit (Component_List (Nod));
14834 when N_Subtype_Indication =>
14836 -- Subtype_Mark is left out because it is not relevant for
14837 -- preelaborability.
14839 Visit (Constraint (Nod));
14841 when N_Unconstrained_Array_Definition =>
14843 -- Subtype_Marks is left out because it is not relevant for
14844 -- preelaborability.
14846 Visit (Component_Definition (Nod));
14848 when N_Variant_Part =>
14850 -- Name is left out because it is not relevant for
14851 -- preelaborability.
14853 Visit_List (Variants (Nod));
14855 -- Default
14857 when others =>
14858 null;
14859 end case;
14860 end Visit;
14862 ----------------
14863 -- Visit_List --
14864 ----------------
14866 procedure Visit_List (List : List_Id) is
14867 Nod : Node_Id;
14869 begin
14870 if Present (List) then
14871 Nod := First (List);
14872 while Present (Nod) loop
14873 Visit (Nod);
14874 Next (Nod);
14875 end loop;
14876 end if;
14877 end Visit_List;
14879 ------------------
14880 -- Visit_Pragma --
14881 ------------------
14883 procedure Visit_Pragma (Prag : Node_Id) is
14884 begin
14885 case Get_Pragma_Id (Prag) is
14886 when Pragma_Assert
14887 | Pragma_Assert_And_Cut
14888 | Pragma_Assume
14889 | Pragma_Async_Readers
14890 | Pragma_Async_Writers
14891 | Pragma_Attribute_Definition
14892 | Pragma_Check
14893 | Pragma_Constant_After_Elaboration
14894 | Pragma_CPU
14895 | Pragma_Deadline_Floor
14896 | Pragma_Dispatching_Domain
14897 | Pragma_Effective_Reads
14898 | Pragma_Effective_Writes
14899 | Pragma_Extensions_Visible
14900 | Pragma_Ghost
14901 | Pragma_Secondary_Stack_Size
14902 | Pragma_Task_Name
14903 | Pragma_Volatile_Function
14905 Visit_List (Pragma_Argument_Associations (Prag));
14907 -- Default
14909 when others =>
14910 null;
14911 end case;
14912 end Visit_Pragma;
14914 -------------------------
14915 -- Visit_Subexpression --
14916 -------------------------
14918 procedure Visit_Subexpression (Expr : Node_Id) is
14919 procedure Visit_Aggregate (Aggr : Node_Id);
14920 pragma Inline (Visit_Aggregate);
14921 -- Semantically inspect aggregate Aggr to determine whether it
14922 -- violates preelaborability.
14924 ---------------------
14925 -- Visit_Aggregate --
14926 ---------------------
14928 procedure Visit_Aggregate (Aggr : Node_Id) is
14929 begin
14930 if not Is_Preelaborable_Aggregate (Aggr) then
14931 raise Non_Preelaborable;
14932 end if;
14933 end Visit_Aggregate;
14935 -- Start of processing for Visit_Subexpression
14937 begin
14938 case Nkind (Expr) is
14939 when N_Allocator
14940 | N_Qualified_Expression
14941 | N_Type_Conversion
14942 | N_Unchecked_Expression
14943 | N_Unchecked_Type_Conversion
14945 -- Subpool_Handle_Name and Subtype_Mark are left out because
14946 -- they are not relevant for preelaborability.
14948 Visit (Expression (Expr));
14950 when N_Aggregate
14951 | N_Extension_Aggregate
14953 Visit_Aggregate (Expr);
14955 when N_Attribute_Reference
14956 | N_Explicit_Dereference
14957 | N_Reference
14959 -- Attribute_Name and Expressions are left out because they are
14960 -- not relevant for preelaborability.
14962 Visit (Prefix (Expr));
14964 when N_Case_Expression =>
14966 -- End_Span is left out because it is not relevant for
14967 -- preelaborability.
14969 Visit_List (Alternatives (Expr));
14970 Visit (Expression (Expr));
14972 when N_Delta_Aggregate =>
14973 Visit_Aggregate (Expr);
14974 Visit (Expression (Expr));
14976 when N_Expression_With_Actions =>
14977 Visit_List (Actions (Expr));
14978 Visit (Expression (Expr));
14980 when N_If_Expression =>
14981 Visit_List (Expressions (Expr));
14983 when N_Quantified_Expression =>
14984 Visit (Condition (Expr));
14985 Visit (Iterator_Specification (Expr));
14986 Visit (Loop_Parameter_Specification (Expr));
14988 when N_Range =>
14989 Visit (High_Bound (Expr));
14990 Visit (Low_Bound (Expr));
14992 when N_Slice =>
14993 Visit (Discrete_Range (Expr));
14994 Visit (Prefix (Expr));
14996 -- Default
14998 when others =>
15000 -- The evaluation of an object name is not preelaborable,
15001 -- unless the name is a static expression (checked further
15002 -- below), or statically denotes a discriminant.
15004 if Is_Entity_Name (Expr) then
15005 Object_Name : declare
15006 Id : constant Entity_Id := Entity (Expr);
15008 begin
15009 if Is_Object (Id) then
15010 if Ekind (Id) = E_Discriminant then
15011 null;
15013 elsif Ekind_In (Id, E_Constant, E_In_Parameter)
15014 and then Present (Discriminal_Link (Id))
15015 then
15016 null;
15018 else
15019 raise Non_Preelaborable;
15020 end if;
15021 end if;
15022 end Object_Name;
15024 -- A non-static expression is not preelaborable
15026 elsif not Is_OK_Static_Expression (Expr) then
15027 raise Non_Preelaborable;
15028 end if;
15029 end case;
15030 end Visit_Subexpression;
15032 -- Start of processing for Is_Non_Preelaborable_Construct
15034 begin
15035 Visit (N);
15037 -- At this point it is known that the construct is preelaborable
15039 return False;
15041 exception
15043 -- The elaboration of the construct performs an action which violates
15044 -- preelaborability.
15046 when Non_Preelaborable =>
15047 return True;
15048 end Is_Non_Preelaborable_Construct;
15050 ---------------------------------
15051 -- Is_Nontrivial_DIC_Procedure --
15052 ---------------------------------
15054 function Is_Nontrivial_DIC_Procedure (Id : Entity_Id) return Boolean is
15055 Body_Decl : Node_Id;
15056 Stmt : Node_Id;
15058 begin
15059 if Ekind (Id) = E_Procedure and then Is_DIC_Procedure (Id) then
15060 Body_Decl :=
15061 Unit_Declaration_Node
15062 (Corresponding_Body (Unit_Declaration_Node (Id)));
15064 -- The body of the Default_Initial_Condition procedure must contain
15065 -- at least one statement, otherwise the generation of the subprogram
15066 -- body failed.
15068 pragma Assert (Present (Handled_Statement_Sequence (Body_Decl)));
15070 -- To qualify as nontrivial, the first statement of the procedure
15071 -- must be a check in the form of an if statement. If the original
15072 -- Default_Initial_Condition expression was folded, then the first
15073 -- statement is not a check.
15075 Stmt := First (Statements (Handled_Statement_Sequence (Body_Decl)));
15077 return
15078 Nkind (Stmt) = N_If_Statement
15079 and then Nkind (Original_Node (Stmt)) = N_Pragma;
15080 end if;
15082 return False;
15083 end Is_Nontrivial_DIC_Procedure;
15085 -------------------------
15086 -- Is_Null_Record_Type --
15087 -------------------------
15089 function Is_Null_Record_Type (T : Entity_Id) return Boolean is
15090 Decl : constant Node_Id := Parent (T);
15091 begin
15092 return Nkind (Decl) = N_Full_Type_Declaration
15093 and then Nkind (Type_Definition (Decl)) = N_Record_Definition
15094 and then
15095 (No (Component_List (Type_Definition (Decl)))
15096 or else Null_Present (Component_List (Type_Definition (Decl))));
15097 end Is_Null_Record_Type;
15099 ---------------------
15100 -- Is_Object_Image --
15101 ---------------------
15103 function Is_Object_Image (Prefix : Node_Id) return Boolean is
15104 begin
15105 -- When the type of the prefix is not scalar, then the prefix is not
15106 -- valid in any scenario.
15108 if not Is_Scalar_Type (Etype (Prefix)) then
15109 return False;
15110 end if;
15112 -- Here we test for the case that the prefix is not a type and assume
15113 -- if it is not then it must be a named value or an object reference.
15114 -- This is because the parser always checks that prefixes of attributes
15115 -- are named.
15117 return not (Is_Entity_Name (Prefix) and then Is_Type (Entity (Prefix)));
15118 end Is_Object_Image;
15120 -------------------------
15121 -- Is_Object_Reference --
15122 -------------------------
15124 function Is_Object_Reference (N : Node_Id) return Boolean is
15125 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean;
15126 -- Determine whether N is the name of an internally-generated renaming
15128 --------------------------------------
15129 -- Is_Internally_Generated_Renaming --
15130 --------------------------------------
15132 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean is
15133 P : Node_Id;
15135 begin
15136 P := N;
15137 while Present (P) loop
15138 if Nkind (P) = N_Object_Renaming_Declaration then
15139 return not Comes_From_Source (P);
15140 elsif Is_List_Member (P) then
15141 return False;
15142 end if;
15144 P := Parent (P);
15145 end loop;
15147 return False;
15148 end Is_Internally_Generated_Renaming;
15150 -- Start of processing for Is_Object_Reference
15152 begin
15153 if Is_Entity_Name (N) then
15154 return Present (Entity (N)) and then Is_Object (Entity (N));
15156 else
15157 case Nkind (N) is
15158 when N_Indexed_Component
15159 | N_Slice
15161 return
15162 Is_Object_Reference (Prefix (N))
15163 or else Is_Access_Type (Etype (Prefix (N)));
15165 -- In Ada 95, a function call is a constant object; a procedure
15166 -- call is not.
15168 -- Note that predefined operators are functions as well, and so
15169 -- are attributes that are (can be renamed as) functions.
15171 when N_Binary_Op
15172 | N_Function_Call
15173 | N_Unary_Op
15175 return Etype (N) /= Standard_Void_Type;
15177 -- Attributes references 'Loop_Entry, 'Old, and 'Result yield
15178 -- objects, even though they are not functions.
15180 when N_Attribute_Reference =>
15181 return
15182 Nam_In (Attribute_Name (N), Name_Loop_Entry,
15183 Name_Old,
15184 Name_Result)
15185 or else Is_Function_Attribute_Name (Attribute_Name (N));
15187 when N_Selected_Component =>
15188 return
15189 Is_Object_Reference (Selector_Name (N))
15190 and then
15191 (Is_Object_Reference (Prefix (N))
15192 or else Is_Access_Type (Etype (Prefix (N))));
15194 -- An explicit dereference denotes an object, except that a
15195 -- conditional expression gets turned into an explicit dereference
15196 -- in some cases, and conditional expressions are not object
15197 -- names.
15199 when N_Explicit_Dereference =>
15200 return not Nkind_In (Original_Node (N), N_Case_Expression,
15201 N_If_Expression);
15203 -- A view conversion of a tagged object is an object reference
15205 when N_Type_Conversion =>
15206 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
15207 and then Is_Tagged_Type (Etype (Expression (N)))
15208 and then Is_Object_Reference (Expression (N));
15210 -- An unchecked type conversion is considered to be an object if
15211 -- the operand is an object (this construction arises only as a
15212 -- result of expansion activities).
15214 when N_Unchecked_Type_Conversion =>
15215 return True;
15217 -- Allow string literals to act as objects as long as they appear
15218 -- in internally-generated renamings. The expansion of iterators
15219 -- may generate such renamings when the range involves a string
15220 -- literal.
15222 when N_String_Literal =>
15223 return Is_Internally_Generated_Renaming (Parent (N));
15225 -- AI05-0003: In Ada 2012 a qualified expression is a name.
15226 -- This allows disambiguation of function calls and the use
15227 -- of aggregates in more contexts.
15229 when N_Qualified_Expression =>
15230 if Ada_Version < Ada_2012 then
15231 return False;
15232 else
15233 return Is_Object_Reference (Expression (N))
15234 or else Nkind (Expression (N)) = N_Aggregate;
15235 end if;
15237 when others =>
15238 return False;
15239 end case;
15240 end if;
15241 end Is_Object_Reference;
15243 -----------------------------------
15244 -- Is_OK_Variable_For_Out_Formal --
15245 -----------------------------------
15247 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
15248 begin
15249 Note_Possible_Modification (AV, Sure => True);
15251 -- We must reject parenthesized variable names. Comes_From_Source is
15252 -- checked because there are currently cases where the compiler violates
15253 -- this rule (e.g. passing a task object to its controlled Initialize
15254 -- routine). This should be properly documented in sinfo???
15256 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
15257 return False;
15259 -- A variable is always allowed
15261 elsif Is_Variable (AV) then
15262 return True;
15264 -- Generalized indexing operations are rewritten as explicit
15265 -- dereferences, and it is only during resolution that we can
15266 -- check whether the context requires an access_to_variable type.
15268 elsif Nkind (AV) = N_Explicit_Dereference
15269 and then Ada_Version >= Ada_2012
15270 and then Nkind (Original_Node (AV)) = N_Indexed_Component
15271 and then Present (Etype (Original_Node (AV)))
15272 and then Has_Implicit_Dereference (Etype (Original_Node (AV)))
15273 then
15274 return not Is_Access_Constant (Etype (Prefix (AV)));
15276 -- Unchecked conversions are allowed only if they come from the
15277 -- generated code, which sometimes uses unchecked conversions for out
15278 -- parameters in cases where code generation is unaffected. We tell
15279 -- source unchecked conversions by seeing if they are rewrites of
15280 -- an original Unchecked_Conversion function call, or of an explicit
15281 -- conversion of a function call or an aggregate (as may happen in the
15282 -- expansion of a packed array aggregate).
15284 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
15285 if Nkind_In (Original_Node (AV), N_Function_Call, N_Aggregate) then
15286 return False;
15288 elsif Comes_From_Source (AV)
15289 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
15290 then
15291 return False;
15293 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
15294 return Is_OK_Variable_For_Out_Formal (Expression (AV));
15296 else
15297 return True;
15298 end if;
15300 -- Normal type conversions are allowed if argument is a variable
15302 elsif Nkind (AV) = N_Type_Conversion then
15303 if Is_Variable (Expression (AV))
15304 and then Paren_Count (Expression (AV)) = 0
15305 then
15306 Note_Possible_Modification (Expression (AV), Sure => True);
15307 return True;
15309 -- We also allow a non-parenthesized expression that raises
15310 -- constraint error if it rewrites what used to be a variable
15312 elsif Raises_Constraint_Error (Expression (AV))
15313 and then Paren_Count (Expression (AV)) = 0
15314 and then Is_Variable (Original_Node (Expression (AV)))
15315 then
15316 return True;
15318 -- Type conversion of something other than a variable
15320 else
15321 return False;
15322 end if;
15324 -- If this node is rewritten, then test the original form, if that is
15325 -- OK, then we consider the rewritten node OK (for example, if the
15326 -- original node is a conversion, then Is_Variable will not be true
15327 -- but we still want to allow the conversion if it converts a variable).
15329 elsif Original_Node (AV) /= AV then
15331 -- In Ada 2012, the explicit dereference may be a rewritten call to a
15332 -- Reference function.
15334 if Ada_Version >= Ada_2012
15335 and then Nkind (Original_Node (AV)) = N_Function_Call
15336 and then
15337 Has_Implicit_Dereference (Etype (Name (Original_Node (AV))))
15338 then
15340 -- Check that this is not a constant reference.
15342 return not Is_Access_Constant (Etype (Prefix (AV)));
15344 elsif Has_Implicit_Dereference (Etype (Original_Node (AV))) then
15345 return
15346 not Is_Access_Constant (Etype
15347 (Get_Reference_Discriminant (Etype (Original_Node (AV)))));
15349 else
15350 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
15351 end if;
15353 -- All other non-variables are rejected
15355 else
15356 return False;
15357 end if;
15358 end Is_OK_Variable_For_Out_Formal;
15360 ----------------------------
15361 -- Is_OK_Volatile_Context --
15362 ----------------------------
15364 function Is_OK_Volatile_Context
15365 (Context : Node_Id;
15366 Obj_Ref : Node_Id) return Boolean
15368 function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean;
15369 -- Determine whether an arbitrary node denotes a call to a protected
15370 -- entry, function, or procedure in prefixed form where the prefix is
15371 -- Obj_Ref.
15373 function Within_Check (Nod : Node_Id) return Boolean;
15374 -- Determine whether an arbitrary node appears in a check node
15376 function Within_Volatile_Function (Id : Entity_Id) return Boolean;
15377 -- Determine whether an arbitrary entity appears in a volatile function
15379 ---------------------------------
15380 -- Is_Protected_Operation_Call --
15381 ---------------------------------
15383 function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean is
15384 Pref : Node_Id;
15385 Subp : Node_Id;
15387 begin
15388 -- A call to a protected operations retains its selected component
15389 -- form as opposed to other prefixed calls that are transformed in
15390 -- expanded names.
15392 if Nkind (Nod) = N_Selected_Component then
15393 Pref := Prefix (Nod);
15394 Subp := Selector_Name (Nod);
15396 return
15397 Pref = Obj_Ref
15398 and then Present (Etype (Pref))
15399 and then Is_Protected_Type (Etype (Pref))
15400 and then Is_Entity_Name (Subp)
15401 and then Present (Entity (Subp))
15402 and then Ekind_In (Entity (Subp), E_Entry,
15403 E_Entry_Family,
15404 E_Function,
15405 E_Procedure);
15406 else
15407 return False;
15408 end if;
15409 end Is_Protected_Operation_Call;
15411 ------------------
15412 -- Within_Check --
15413 ------------------
15415 function Within_Check (Nod : Node_Id) return Boolean is
15416 Par : Node_Id;
15418 begin
15419 -- Climb the parent chain looking for a check node
15421 Par := Nod;
15422 while Present (Par) loop
15423 if Nkind (Par) in N_Raise_xxx_Error then
15424 return True;
15426 -- Prevent the search from going too far
15428 elsif Is_Body_Or_Package_Declaration (Par) then
15429 exit;
15430 end if;
15432 Par := Parent (Par);
15433 end loop;
15435 return False;
15436 end Within_Check;
15438 ------------------------------
15439 -- Within_Volatile_Function --
15440 ------------------------------
15442 function Within_Volatile_Function (Id : Entity_Id) return Boolean is
15443 Func_Id : Entity_Id;
15445 begin
15446 -- Traverse the scope stack looking for a [generic] function
15448 Func_Id := Id;
15449 while Present (Func_Id) and then Func_Id /= Standard_Standard loop
15450 if Ekind_In (Func_Id, E_Function, E_Generic_Function) then
15451 return Is_Volatile_Function (Func_Id);
15452 end if;
15454 Func_Id := Scope (Func_Id);
15455 end loop;
15457 return False;
15458 end Within_Volatile_Function;
15460 -- Local variables
15462 Obj_Id : Entity_Id;
15464 -- Start of processing for Is_OK_Volatile_Context
15466 begin
15467 -- The volatile object appears on either side of an assignment
15469 if Nkind (Context) = N_Assignment_Statement then
15470 return True;
15472 -- The volatile object is part of the initialization expression of
15473 -- another object.
15475 elsif Nkind (Context) = N_Object_Declaration
15476 and then Present (Expression (Context))
15477 and then Expression (Context) = Obj_Ref
15478 then
15479 Obj_Id := Defining_Entity (Context);
15481 -- The volatile object acts as the initialization expression of an
15482 -- extended return statement. This is valid context as long as the
15483 -- function is volatile.
15485 if Is_Return_Object (Obj_Id) then
15486 return Within_Volatile_Function (Obj_Id);
15488 -- Otherwise this is a normal object initialization
15490 else
15491 return True;
15492 end if;
15494 -- The volatile object acts as the name of a renaming declaration
15496 elsif Nkind (Context) = N_Object_Renaming_Declaration
15497 and then Name (Context) = Obj_Ref
15498 then
15499 return True;
15501 -- The volatile object appears as an actual parameter in a call to an
15502 -- instance of Unchecked_Conversion whose result is renamed.
15504 elsif Nkind (Context) = N_Function_Call
15505 and then Is_Entity_Name (Name (Context))
15506 and then Is_Unchecked_Conversion_Instance (Entity (Name (Context)))
15507 and then Nkind (Parent (Context)) = N_Object_Renaming_Declaration
15508 then
15509 return True;
15511 -- The volatile object is actually the prefix in a protected entry,
15512 -- function, or procedure call.
15514 elsif Is_Protected_Operation_Call (Context) then
15515 return True;
15517 -- The volatile object appears as the expression of a simple return
15518 -- statement that applies to a volatile function.
15520 elsif Nkind (Context) = N_Simple_Return_Statement
15521 and then Expression (Context) = Obj_Ref
15522 then
15523 return
15524 Within_Volatile_Function (Return_Statement_Entity (Context));
15526 -- The volatile object appears as the prefix of a name occurring in a
15527 -- non-interfering context.
15529 elsif Nkind_In (Context, N_Attribute_Reference,
15530 N_Explicit_Dereference,
15531 N_Indexed_Component,
15532 N_Selected_Component,
15533 N_Slice)
15534 and then Prefix (Context) = Obj_Ref
15535 and then Is_OK_Volatile_Context
15536 (Context => Parent (Context),
15537 Obj_Ref => Context)
15538 then
15539 return True;
15541 -- The volatile object appears as the prefix of attributes Address,
15542 -- Alignment, Component_Size, First_Bit, Last_Bit, Position, Size,
15543 -- Storage_Size.
15545 elsif Nkind (Context) = N_Attribute_Reference
15546 and then Prefix (Context) = Obj_Ref
15547 and then Nam_In (Attribute_Name (Context), Name_Address,
15548 Name_Alignment,
15549 Name_Component_Size,
15550 Name_First_Bit,
15551 Name_Last_Bit,
15552 Name_Position,
15553 Name_Size,
15554 Name_Storage_Size)
15555 then
15556 return True;
15558 -- The volatile object appears as the expression of a type conversion
15559 -- occurring in a non-interfering context.
15561 elsif Nkind_In (Context, N_Type_Conversion,
15562 N_Unchecked_Type_Conversion)
15563 and then Expression (Context) = Obj_Ref
15564 and then Is_OK_Volatile_Context
15565 (Context => Parent (Context),
15566 Obj_Ref => Context)
15567 then
15568 return True;
15570 -- The volatile object appears as the expression in a delay statement
15572 elsif Nkind (Context) in N_Delay_Statement then
15573 return True;
15575 -- Allow references to volatile objects in various checks. This is not a
15576 -- direct SPARK 2014 requirement.
15578 elsif Within_Check (Context) then
15579 return True;
15581 -- Assume that references to effectively volatile objects that appear
15582 -- as actual parameters in a subprogram call are always legal. A full
15583 -- legality check is done when the actuals are resolved (see routine
15584 -- Resolve_Actuals).
15586 elsif Within_Subprogram_Call (Context) then
15587 return True;
15589 -- Otherwise the context is not suitable for an effectively volatile
15590 -- object.
15592 else
15593 return False;
15594 end if;
15595 end Is_OK_Volatile_Context;
15597 ------------------------------------
15598 -- Is_Package_Contract_Annotation --
15599 ------------------------------------
15601 function Is_Package_Contract_Annotation (Item : Node_Id) return Boolean is
15602 Nam : Name_Id;
15604 begin
15605 if Nkind (Item) = N_Aspect_Specification then
15606 Nam := Chars (Identifier (Item));
15608 else pragma Assert (Nkind (Item) = N_Pragma);
15609 Nam := Pragma_Name (Item);
15610 end if;
15612 return Nam = Name_Abstract_State
15613 or else Nam = Name_Initial_Condition
15614 or else Nam = Name_Initializes
15615 or else Nam = Name_Refined_State;
15616 end Is_Package_Contract_Annotation;
15618 -----------------------------------
15619 -- Is_Partially_Initialized_Type --
15620 -----------------------------------
15622 function Is_Partially_Initialized_Type
15623 (Typ : Entity_Id;
15624 Include_Implicit : Boolean := True) return Boolean
15626 begin
15627 if Is_Scalar_Type (Typ) then
15628 return False;
15630 elsif Is_Access_Type (Typ) then
15631 return Include_Implicit;
15633 elsif Is_Array_Type (Typ) then
15635 -- If component type is partially initialized, so is array type
15637 if Is_Partially_Initialized_Type
15638 (Component_Type (Typ), Include_Implicit)
15639 then
15640 return True;
15642 -- Otherwise we are only partially initialized if we are fully
15643 -- initialized (this is the empty array case, no point in us
15644 -- duplicating that code here).
15646 else
15647 return Is_Fully_Initialized_Type (Typ);
15648 end if;
15650 elsif Is_Record_Type (Typ) then
15652 -- A discriminated type is always partially initialized if in
15653 -- all mode
15655 if Has_Discriminants (Typ) and then Include_Implicit then
15656 return True;
15658 -- A tagged type is always partially initialized
15660 elsif Is_Tagged_Type (Typ) then
15661 return True;
15663 -- Case of non-discriminated record
15665 else
15666 declare
15667 Ent : Entity_Id;
15669 Component_Present : Boolean := False;
15670 -- Set True if at least one component is present. If no
15671 -- components are present, then record type is fully
15672 -- initialized (another odd case, like the null array).
15674 begin
15675 -- Loop through components
15677 Ent := First_Entity (Typ);
15678 while Present (Ent) loop
15679 if Ekind (Ent) = E_Component then
15680 Component_Present := True;
15682 -- If a component has an initialization expression then
15683 -- the enclosing record type is partially initialized
15685 if Present (Parent (Ent))
15686 and then Present (Expression (Parent (Ent)))
15687 then
15688 return True;
15690 -- If a component is of a type which is itself partially
15691 -- initialized, then the enclosing record type is also.
15693 elsif Is_Partially_Initialized_Type
15694 (Etype (Ent), Include_Implicit)
15695 then
15696 return True;
15697 end if;
15698 end if;
15700 Next_Entity (Ent);
15701 end loop;
15703 -- No initialized components found. If we found any components
15704 -- they were all uninitialized so the result is false.
15706 if Component_Present then
15707 return False;
15709 -- But if we found no components, then all the components are
15710 -- initialized so we consider the type to be initialized.
15712 else
15713 return True;
15714 end if;
15715 end;
15716 end if;
15718 -- Concurrent types are always fully initialized
15720 elsif Is_Concurrent_Type (Typ) then
15721 return True;
15723 -- For a private type, go to underlying type. If there is no underlying
15724 -- type then just assume this partially initialized. Not clear if this
15725 -- can happen in a non-error case, but no harm in testing for this.
15727 elsif Is_Private_Type (Typ) then
15728 declare
15729 U : constant Entity_Id := Underlying_Type (Typ);
15730 begin
15731 if No (U) then
15732 return True;
15733 else
15734 return Is_Partially_Initialized_Type (U, Include_Implicit);
15735 end if;
15736 end;
15738 -- For any other type (are there any?) assume partially initialized
15740 else
15741 return True;
15742 end if;
15743 end Is_Partially_Initialized_Type;
15745 ------------------------------------
15746 -- Is_Potentially_Persistent_Type --
15747 ------------------------------------
15749 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
15750 Comp : Entity_Id;
15751 Indx : Node_Id;
15753 begin
15754 -- For private type, test corresponding full type
15756 if Is_Private_Type (T) then
15757 return Is_Potentially_Persistent_Type (Full_View (T));
15759 -- Scalar types are potentially persistent
15761 elsif Is_Scalar_Type (T) then
15762 return True;
15764 -- Record type is potentially persistent if not tagged and the types of
15765 -- all it components are potentially persistent, and no component has
15766 -- an initialization expression.
15768 elsif Is_Record_Type (T)
15769 and then not Is_Tagged_Type (T)
15770 and then not Is_Partially_Initialized_Type (T)
15771 then
15772 Comp := First_Component (T);
15773 while Present (Comp) loop
15774 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
15775 return False;
15776 else
15777 Next_Entity (Comp);
15778 end if;
15779 end loop;
15781 return True;
15783 -- Array type is potentially persistent if its component type is
15784 -- potentially persistent and if all its constraints are static.
15786 elsif Is_Array_Type (T) then
15787 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
15788 return False;
15789 end if;
15791 Indx := First_Index (T);
15792 while Present (Indx) loop
15793 if not Is_OK_Static_Subtype (Etype (Indx)) then
15794 return False;
15795 else
15796 Next_Index (Indx);
15797 end if;
15798 end loop;
15800 return True;
15802 -- All other types are not potentially persistent
15804 else
15805 return False;
15806 end if;
15807 end Is_Potentially_Persistent_Type;
15809 --------------------------------
15810 -- Is_Potentially_Unevaluated --
15811 --------------------------------
15813 function Is_Potentially_Unevaluated (N : Node_Id) return Boolean is
15814 Par : Node_Id;
15815 Expr : Node_Id;
15817 begin
15818 Expr := N;
15819 Par := N;
15821 -- A postcondition whose expression is a short-circuit is broken down
15822 -- into individual aspects for better exception reporting. The original
15823 -- short-circuit expression is rewritten as the second operand, and an
15824 -- occurrence of 'Old in that operand is potentially unevaluated.
15825 -- See sem_ch13.adb for details of this transformation. The reference
15826 -- to 'Old may appear within an expression, so we must look for the
15827 -- enclosing pragma argument in the tree that contains the reference.
15829 while Present (Par)
15830 and then Nkind (Par) /= N_Pragma_Argument_Association
15831 loop
15832 if Nkind (Original_Node (Par)) = N_And_Then then
15833 return True;
15834 end if;
15836 Par := Parent (Par);
15837 end loop;
15839 -- Other cases; 'Old appears within other expression (not the top-level
15840 -- conjunct in a postcondition) with a potentially unevaluated operand.
15842 Par := Parent (Expr);
15844 while not Nkind_In (Par, N_If_Expression,
15845 N_Case_Expression,
15846 N_And_Then,
15847 N_Or_Else,
15848 N_In,
15849 N_Not_In,
15850 N_Quantified_Expression)
15851 loop
15852 Expr := Par;
15853 Par := Parent (Par);
15855 -- If the context is not an expression, or if is the result of
15856 -- expansion of an enclosing construct (such as another attribute)
15857 -- the predicate does not apply.
15859 if Nkind (Par) = N_Case_Expression_Alternative then
15860 null;
15862 elsif Nkind (Par) not in N_Subexpr
15863 or else not Comes_From_Source (Par)
15864 then
15865 return False;
15866 end if;
15867 end loop;
15869 if Nkind (Par) = N_If_Expression then
15870 return Is_Elsif (Par) or else Expr /= First (Expressions (Par));
15872 elsif Nkind (Par) = N_Case_Expression then
15873 return Expr /= Expression (Par);
15875 elsif Nkind_In (Par, N_And_Then, N_Or_Else) then
15876 return Expr = Right_Opnd (Par);
15878 elsif Nkind_In (Par, N_In, N_Not_In) then
15880 -- If the membership includes several alternatives, only the first is
15881 -- definitely evaluated.
15883 if Present (Alternatives (Par)) then
15884 return Expr /= First (Alternatives (Par));
15886 -- If this is a range membership both bounds are evaluated
15888 else
15889 return False;
15890 end if;
15892 elsif Nkind (Par) = N_Quantified_Expression then
15893 return Expr = Condition (Par);
15895 else
15896 return False;
15897 end if;
15898 end Is_Potentially_Unevaluated;
15900 --------------------------------
15901 -- Is_Preelaborable_Aggregate --
15902 --------------------------------
15904 function Is_Preelaborable_Aggregate (Aggr : Node_Id) return Boolean is
15905 Aggr_Typ : constant Entity_Id := Etype (Aggr);
15906 Array_Aggr : constant Boolean := Is_Array_Type (Aggr_Typ);
15908 Anc_Part : Node_Id;
15909 Assoc : Node_Id;
15910 Choice : Node_Id;
15911 Comp_Typ : Entity_Id := Empty; -- init to avoid warning
15912 Expr : Node_Id;
15914 begin
15915 if Array_Aggr then
15916 Comp_Typ := Component_Type (Aggr_Typ);
15917 end if;
15919 -- Inspect the ancestor part
15921 if Nkind (Aggr) = N_Extension_Aggregate then
15922 Anc_Part := Ancestor_Part (Aggr);
15924 -- The ancestor denotes a subtype mark
15926 if Is_Entity_Name (Anc_Part)
15927 and then Is_Type (Entity (Anc_Part))
15928 then
15929 if not Has_Preelaborable_Initialization (Entity (Anc_Part)) then
15930 return False;
15931 end if;
15933 -- Otherwise the ancestor denotes an expression
15935 elsif not Is_Preelaborable_Construct (Anc_Part) then
15936 return False;
15937 end if;
15938 end if;
15940 -- Inspect the positional associations
15942 Expr := First (Expressions (Aggr));
15943 while Present (Expr) loop
15944 if not Is_Preelaborable_Construct (Expr) then
15945 return False;
15946 end if;
15948 Next (Expr);
15949 end loop;
15951 -- Inspect the named associations
15953 Assoc := First (Component_Associations (Aggr));
15954 while Present (Assoc) loop
15956 -- Inspect the choices of the current named association
15958 Choice := First (Choices (Assoc));
15959 while Present (Choice) loop
15960 if Array_Aggr then
15962 -- For a choice to be preelaborable, it must denote either a
15963 -- static range or a static expression.
15965 if Nkind (Choice) = N_Others_Choice then
15966 null;
15968 elsif Nkind (Choice) = N_Range then
15969 if not Is_OK_Static_Range (Choice) then
15970 return False;
15971 end if;
15973 elsif not Is_OK_Static_Expression (Choice) then
15974 return False;
15975 end if;
15977 else
15978 Comp_Typ := Etype (Choice);
15979 end if;
15981 Next (Choice);
15982 end loop;
15984 -- The type of the choice must have preelaborable initialization if
15985 -- the association carries a <>.
15987 pragma Assert (Present (Comp_Typ));
15988 if Box_Present (Assoc) then
15989 if not Has_Preelaborable_Initialization (Comp_Typ) then
15990 return False;
15991 end if;
15993 -- The type of the expression must have preelaborable initialization
15995 elsif not Is_Preelaborable_Construct (Expression (Assoc)) then
15996 return False;
15997 end if;
15999 Next (Assoc);
16000 end loop;
16002 -- At this point the aggregate is preelaborable
16004 return True;
16005 end Is_Preelaborable_Aggregate;
16007 --------------------------------
16008 -- Is_Preelaborable_Construct --
16009 --------------------------------
16011 function Is_Preelaborable_Construct (N : Node_Id) return Boolean is
16012 begin
16013 -- Aggregates
16015 if Nkind_In (N, N_Aggregate, N_Extension_Aggregate) then
16016 return Is_Preelaborable_Aggregate (N);
16018 -- Attributes are allowed in general, even if their prefix is a formal
16019 -- type. It seems that certain attributes known not to be static might
16020 -- not be allowed, but there are no rules to prevent them.
16022 elsif Nkind (N) = N_Attribute_Reference then
16023 return True;
16025 -- Expressions
16027 elsif Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then
16028 return True;
16030 elsif Nkind (N) = N_Qualified_Expression then
16031 return Is_Preelaborable_Construct (Expression (N));
16033 -- Names are preelaborable when they denote a discriminant of an
16034 -- enclosing type. Discriminals are also considered for this check.
16036 elsif Is_Entity_Name (N)
16037 and then Present (Entity (N))
16038 and then
16039 (Ekind (Entity (N)) = E_Discriminant
16040 or else (Ekind_In (Entity (N), E_Constant, E_In_Parameter)
16041 and then Present (Discriminal_Link (Entity (N)))))
16042 then
16043 return True;
16045 -- Statements
16047 elsif Nkind (N) = N_Null then
16048 return True;
16050 -- Otherwise the construct is not preelaborable
16052 else
16053 return False;
16054 end if;
16055 end Is_Preelaborable_Construct;
16057 ---------------------------------
16058 -- Is_Protected_Self_Reference --
16059 ---------------------------------
16061 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
16063 function In_Access_Definition (N : Node_Id) return Boolean;
16064 -- Returns true if N belongs to an access definition
16066 --------------------------
16067 -- In_Access_Definition --
16068 --------------------------
16070 function In_Access_Definition (N : Node_Id) return Boolean is
16071 P : Node_Id;
16073 begin
16074 P := Parent (N);
16075 while Present (P) loop
16076 if Nkind (P) = N_Access_Definition then
16077 return True;
16078 end if;
16080 P := Parent (P);
16081 end loop;
16083 return False;
16084 end In_Access_Definition;
16086 -- Start of processing for Is_Protected_Self_Reference
16088 begin
16089 -- Verify that prefix is analyzed and has the proper form. Note that
16090 -- the attributes Elab_Spec, Elab_Body, and Elab_Subp_Body, which also
16091 -- produce the address of an entity, do not analyze their prefix
16092 -- because they denote entities that are not necessarily visible.
16093 -- Neither of them can apply to a protected type.
16095 return Ada_Version >= Ada_2005
16096 and then Is_Entity_Name (N)
16097 and then Present (Entity (N))
16098 and then Is_Protected_Type (Entity (N))
16099 and then In_Open_Scopes (Entity (N))
16100 and then not In_Access_Definition (N);
16101 end Is_Protected_Self_Reference;
16103 -----------------------------
16104 -- Is_RCI_Pkg_Spec_Or_Body --
16105 -----------------------------
16107 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
16109 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
16110 -- Return True if the unit of Cunit is an RCI package declaration
16112 ---------------------------
16113 -- Is_RCI_Pkg_Decl_Cunit --
16114 ---------------------------
16116 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
16117 The_Unit : constant Node_Id := Unit (Cunit);
16119 begin
16120 if Nkind (The_Unit) /= N_Package_Declaration then
16121 return False;
16122 end if;
16124 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
16125 end Is_RCI_Pkg_Decl_Cunit;
16127 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
16129 begin
16130 return Is_RCI_Pkg_Decl_Cunit (Cunit)
16131 or else
16132 (Nkind (Unit (Cunit)) = N_Package_Body
16133 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
16134 end Is_RCI_Pkg_Spec_Or_Body;
16136 -----------------------------------------
16137 -- Is_Remote_Access_To_Class_Wide_Type --
16138 -----------------------------------------
16140 function Is_Remote_Access_To_Class_Wide_Type
16141 (E : Entity_Id) return Boolean
16143 begin
16144 -- A remote access to class-wide type is a general access to object type
16145 -- declared in the visible part of a Remote_Types or Remote_Call_
16146 -- Interface unit.
16148 return Ekind (E) = E_General_Access_Type
16149 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
16150 end Is_Remote_Access_To_Class_Wide_Type;
16152 -----------------------------------------
16153 -- Is_Remote_Access_To_Subprogram_Type --
16154 -----------------------------------------
16156 function Is_Remote_Access_To_Subprogram_Type
16157 (E : Entity_Id) return Boolean
16159 begin
16160 return (Ekind (E) = E_Access_Subprogram_Type
16161 or else (Ekind (E) = E_Record_Type
16162 and then Present (Corresponding_Remote_Type (E))))
16163 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
16164 end Is_Remote_Access_To_Subprogram_Type;
16166 --------------------
16167 -- Is_Remote_Call --
16168 --------------------
16170 function Is_Remote_Call (N : Node_Id) return Boolean is
16171 begin
16172 if Nkind (N) not in N_Subprogram_Call then
16174 -- An entry call cannot be remote
16176 return False;
16178 elsif Nkind (Name (N)) in N_Has_Entity
16179 and then Is_Remote_Call_Interface (Entity (Name (N)))
16180 then
16181 -- A subprogram declared in the spec of a RCI package is remote
16183 return True;
16185 elsif Nkind (Name (N)) = N_Explicit_Dereference
16186 and then Is_Remote_Access_To_Subprogram_Type
16187 (Etype (Prefix (Name (N))))
16188 then
16189 -- The dereference of a RAS is a remote call
16191 return True;
16193 elsif Present (Controlling_Argument (N))
16194 and then Is_Remote_Access_To_Class_Wide_Type
16195 (Etype (Controlling_Argument (N)))
16196 then
16197 -- Any primitive operation call with a controlling argument of
16198 -- a RACW type is a remote call.
16200 return True;
16201 end if;
16203 -- All other calls are local calls
16205 return False;
16206 end Is_Remote_Call;
16208 ----------------------
16209 -- Is_Renamed_Entry --
16210 ----------------------
16212 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
16213 Orig_Node : Node_Id := Empty;
16214 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
16216 function Is_Entry (Nam : Node_Id) return Boolean;
16217 -- Determine whether Nam is an entry. Traverse selectors if there are
16218 -- nested selected components.
16220 --------------
16221 -- Is_Entry --
16222 --------------
16224 function Is_Entry (Nam : Node_Id) return Boolean is
16225 begin
16226 if Nkind (Nam) = N_Selected_Component then
16227 return Is_Entry (Selector_Name (Nam));
16228 end if;
16230 return Ekind (Entity (Nam)) = E_Entry;
16231 end Is_Entry;
16233 -- Start of processing for Is_Renamed_Entry
16235 begin
16236 if Present (Alias (Proc_Nam)) then
16237 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
16238 end if;
16240 -- Look for a rewritten subprogram renaming declaration
16242 if Nkind (Subp_Decl) = N_Subprogram_Declaration
16243 and then Present (Original_Node (Subp_Decl))
16244 then
16245 Orig_Node := Original_Node (Subp_Decl);
16246 end if;
16248 -- The rewritten subprogram is actually an entry
16250 if Present (Orig_Node)
16251 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
16252 and then Is_Entry (Name (Orig_Node))
16253 then
16254 return True;
16255 end if;
16257 return False;
16258 end Is_Renamed_Entry;
16260 -----------------------------
16261 -- Is_Renaming_Declaration --
16262 -----------------------------
16264 function Is_Renaming_Declaration (N : Node_Id) return Boolean is
16265 begin
16266 case Nkind (N) is
16267 when N_Exception_Renaming_Declaration
16268 | N_Generic_Function_Renaming_Declaration
16269 | N_Generic_Package_Renaming_Declaration
16270 | N_Generic_Procedure_Renaming_Declaration
16271 | N_Object_Renaming_Declaration
16272 | N_Package_Renaming_Declaration
16273 | N_Subprogram_Renaming_Declaration
16275 return True;
16277 when others =>
16278 return False;
16279 end case;
16280 end Is_Renaming_Declaration;
16282 ----------------------------
16283 -- Is_Reversible_Iterator --
16284 ----------------------------
16286 function Is_Reversible_Iterator (Typ : Entity_Id) return Boolean is
16287 Ifaces_List : Elist_Id;
16288 Iface_Elmt : Elmt_Id;
16289 Iface : Entity_Id;
16291 begin
16292 if Is_Class_Wide_Type (Typ)
16293 and then Chars (Root_Type (Typ)) = Name_Reversible_Iterator
16294 and then In_Predefined_Unit (Root_Type (Typ))
16295 then
16296 return True;
16298 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
16299 return False;
16301 else
16302 Collect_Interfaces (Typ, Ifaces_List);
16304 Iface_Elmt := First_Elmt (Ifaces_List);
16305 while Present (Iface_Elmt) loop
16306 Iface := Node (Iface_Elmt);
16307 if Chars (Iface) = Name_Reversible_Iterator
16308 and then In_Predefined_Unit (Iface)
16309 then
16310 return True;
16311 end if;
16313 Next_Elmt (Iface_Elmt);
16314 end loop;
16315 end if;
16317 return False;
16318 end Is_Reversible_Iterator;
16320 ----------------------
16321 -- Is_Selector_Name --
16322 ----------------------
16324 function Is_Selector_Name (N : Node_Id) return Boolean is
16325 begin
16326 if not Is_List_Member (N) then
16327 declare
16328 P : constant Node_Id := Parent (N);
16329 begin
16330 return Nkind_In (P, N_Expanded_Name,
16331 N_Generic_Association,
16332 N_Parameter_Association,
16333 N_Selected_Component)
16334 and then Selector_Name (P) = N;
16335 end;
16337 else
16338 declare
16339 L : constant List_Id := List_Containing (N);
16340 P : constant Node_Id := Parent (L);
16341 begin
16342 return (Nkind (P) = N_Discriminant_Association
16343 and then Selector_Names (P) = L)
16344 or else
16345 (Nkind (P) = N_Component_Association
16346 and then Choices (P) = L);
16347 end;
16348 end if;
16349 end Is_Selector_Name;
16351 ---------------------------------
16352 -- Is_Single_Concurrent_Object --
16353 ---------------------------------
16355 function Is_Single_Concurrent_Object (Id : Entity_Id) return Boolean is
16356 begin
16357 return
16358 Is_Single_Protected_Object (Id) or else Is_Single_Task_Object (Id);
16359 end Is_Single_Concurrent_Object;
16361 -------------------------------
16362 -- Is_Single_Concurrent_Type --
16363 -------------------------------
16365 function Is_Single_Concurrent_Type (Id : Entity_Id) return Boolean is
16366 begin
16367 return
16368 Ekind_In (Id, E_Protected_Type, E_Task_Type)
16369 and then Is_Single_Concurrent_Type_Declaration
16370 (Declaration_Node (Id));
16371 end Is_Single_Concurrent_Type;
16373 -------------------------------------------
16374 -- Is_Single_Concurrent_Type_Declaration --
16375 -------------------------------------------
16377 function Is_Single_Concurrent_Type_Declaration
16378 (N : Node_Id) return Boolean
16380 begin
16381 return Nkind_In (Original_Node (N), N_Single_Protected_Declaration,
16382 N_Single_Task_Declaration);
16383 end Is_Single_Concurrent_Type_Declaration;
16385 ---------------------------------------------
16386 -- Is_Single_Precision_Floating_Point_Type --
16387 ---------------------------------------------
16389 function Is_Single_Precision_Floating_Point_Type
16390 (E : Entity_Id) return Boolean is
16391 begin
16392 return Is_Floating_Point_Type (E)
16393 and then Machine_Radix_Value (E) = Uint_2
16394 and then Machine_Mantissa_Value (E) = Uint_24
16395 and then Machine_Emax_Value (E) = Uint_2 ** Uint_7
16396 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_7);
16397 end Is_Single_Precision_Floating_Point_Type;
16399 --------------------------------
16400 -- Is_Single_Protected_Object --
16401 --------------------------------
16403 function Is_Single_Protected_Object (Id : Entity_Id) return Boolean is
16404 begin
16405 return
16406 Ekind (Id) = E_Variable
16407 and then Ekind (Etype (Id)) = E_Protected_Type
16408 and then Is_Single_Concurrent_Type (Etype (Id));
16409 end Is_Single_Protected_Object;
16411 ---------------------------
16412 -- Is_Single_Task_Object --
16413 ---------------------------
16415 function Is_Single_Task_Object (Id : Entity_Id) return Boolean is
16416 begin
16417 return
16418 Ekind (Id) = E_Variable
16419 and then Ekind (Etype (Id)) = E_Task_Type
16420 and then Is_Single_Concurrent_Type (Etype (Id));
16421 end Is_Single_Task_Object;
16423 -------------------------------------
16424 -- Is_SPARK_05_Initialization_Expr --
16425 -------------------------------------
16427 function Is_SPARK_05_Initialization_Expr (N : Node_Id) return Boolean is
16428 Is_Ok : Boolean;
16429 Expr : Node_Id;
16430 Comp_Assn : Node_Id;
16431 Orig_N : constant Node_Id := Original_Node (N);
16433 begin
16434 Is_Ok := True;
16436 if not Comes_From_Source (Orig_N) then
16437 goto Done;
16438 end if;
16440 pragma Assert (Nkind (Orig_N) in N_Subexpr);
16442 case Nkind (Orig_N) is
16443 when N_Character_Literal
16444 | N_Integer_Literal
16445 | N_Real_Literal
16446 | N_String_Literal
16448 null;
16450 when N_Expanded_Name
16451 | N_Identifier
16453 if Is_Entity_Name (Orig_N)
16454 and then Present (Entity (Orig_N)) -- needed in some cases
16455 then
16456 case Ekind (Entity (Orig_N)) is
16457 when E_Constant
16458 | E_Enumeration_Literal
16459 | E_Named_Integer
16460 | E_Named_Real
16462 null;
16464 when others =>
16465 if Is_Type (Entity (Orig_N)) then
16466 null;
16467 else
16468 Is_Ok := False;
16469 end if;
16470 end case;
16471 end if;
16473 when N_Qualified_Expression
16474 | N_Type_Conversion
16476 Is_Ok := Is_SPARK_05_Initialization_Expr (Expression (Orig_N));
16478 when N_Unary_Op =>
16479 Is_Ok := Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
16481 when N_Binary_Op
16482 | N_Membership_Test
16483 | N_Short_Circuit
16485 Is_Ok := Is_SPARK_05_Initialization_Expr (Left_Opnd (Orig_N))
16486 and then
16487 Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
16489 when N_Aggregate
16490 | N_Extension_Aggregate
16492 if Nkind (Orig_N) = N_Extension_Aggregate then
16493 Is_Ok :=
16494 Is_SPARK_05_Initialization_Expr (Ancestor_Part (Orig_N));
16495 end if;
16497 Expr := First (Expressions (Orig_N));
16498 while Present (Expr) loop
16499 if not Is_SPARK_05_Initialization_Expr (Expr) then
16500 Is_Ok := False;
16501 goto Done;
16502 end if;
16504 Next (Expr);
16505 end loop;
16507 Comp_Assn := First (Component_Associations (Orig_N));
16508 while Present (Comp_Assn) loop
16509 Expr := Expression (Comp_Assn);
16511 -- Note: test for Present here needed for box assocation
16513 if Present (Expr)
16514 and then not Is_SPARK_05_Initialization_Expr (Expr)
16515 then
16516 Is_Ok := False;
16517 goto Done;
16518 end if;
16520 Next (Comp_Assn);
16521 end loop;
16523 when N_Attribute_Reference =>
16524 if Nkind (Prefix (Orig_N)) in N_Subexpr then
16525 Is_Ok := Is_SPARK_05_Initialization_Expr (Prefix (Orig_N));
16526 end if;
16528 Expr := First (Expressions (Orig_N));
16529 while Present (Expr) loop
16530 if not Is_SPARK_05_Initialization_Expr (Expr) then
16531 Is_Ok := False;
16532 goto Done;
16533 end if;
16535 Next (Expr);
16536 end loop;
16538 -- Selected components might be expanded named not yet resolved, so
16539 -- default on the safe side. (Eg on sparklex.ads)
16541 when N_Selected_Component =>
16542 null;
16544 when others =>
16545 Is_Ok := False;
16546 end case;
16548 <<Done>>
16549 return Is_Ok;
16550 end Is_SPARK_05_Initialization_Expr;
16552 ----------------------------------
16553 -- Is_SPARK_05_Object_Reference --
16554 ----------------------------------
16556 function Is_SPARK_05_Object_Reference (N : Node_Id) return Boolean is
16557 begin
16558 if Is_Entity_Name (N) then
16559 return Present (Entity (N))
16560 and then
16561 (Ekind_In (Entity (N), E_Constant, E_Variable)
16562 or else Ekind (Entity (N)) in Formal_Kind);
16564 else
16565 case Nkind (N) is
16566 when N_Selected_Component =>
16567 return Is_SPARK_05_Object_Reference (Prefix (N));
16569 when others =>
16570 return False;
16571 end case;
16572 end if;
16573 end Is_SPARK_05_Object_Reference;
16575 -----------------------------
16576 -- Is_Specific_Tagged_Type --
16577 -----------------------------
16579 function Is_Specific_Tagged_Type (Typ : Entity_Id) return Boolean is
16580 Full_Typ : Entity_Id;
16582 begin
16583 -- Handle private types
16585 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
16586 Full_Typ := Full_View (Typ);
16587 else
16588 Full_Typ := Typ;
16589 end if;
16591 -- A specific tagged type is a non-class-wide tagged type
16593 return Is_Tagged_Type (Full_Typ) and not Is_Class_Wide_Type (Full_Typ);
16594 end Is_Specific_Tagged_Type;
16596 ------------------
16597 -- Is_Statement --
16598 ------------------
16600 function Is_Statement (N : Node_Id) return Boolean is
16601 begin
16602 return
16603 Nkind (N) in N_Statement_Other_Than_Procedure_Call
16604 or else Nkind (N) = N_Procedure_Call_Statement;
16605 end Is_Statement;
16607 ---------------------------------------
16608 -- Is_Subprogram_Contract_Annotation --
16609 ---------------------------------------
16611 function Is_Subprogram_Contract_Annotation
16612 (Item : Node_Id) return Boolean
16614 Nam : Name_Id;
16616 begin
16617 if Nkind (Item) = N_Aspect_Specification then
16618 Nam := Chars (Identifier (Item));
16620 else pragma Assert (Nkind (Item) = N_Pragma);
16621 Nam := Pragma_Name (Item);
16622 end if;
16624 return Nam = Name_Contract_Cases
16625 or else Nam = Name_Depends
16626 or else Nam = Name_Extensions_Visible
16627 or else Nam = Name_Global
16628 or else Nam = Name_Post
16629 or else Nam = Name_Post_Class
16630 or else Nam = Name_Postcondition
16631 or else Nam = Name_Pre
16632 or else Nam = Name_Pre_Class
16633 or else Nam = Name_Precondition
16634 or else Nam = Name_Refined_Depends
16635 or else Nam = Name_Refined_Global
16636 or else Nam = Name_Refined_Post
16637 or else Nam = Name_Test_Case;
16638 end Is_Subprogram_Contract_Annotation;
16640 --------------------------------------------------
16641 -- Is_Subprogram_Stub_Without_Prior_Declaration --
16642 --------------------------------------------------
16644 function Is_Subprogram_Stub_Without_Prior_Declaration
16645 (N : Node_Id) return Boolean
16647 begin
16648 -- A subprogram stub without prior declaration serves as declaration for
16649 -- the actual subprogram body. As such, it has an attached defining
16650 -- entity of E_[Generic_]Function or E_[Generic_]Procedure.
16652 return Nkind (N) = N_Subprogram_Body_Stub
16653 and then Ekind (Defining_Entity (N)) /= E_Subprogram_Body;
16654 end Is_Subprogram_Stub_Without_Prior_Declaration;
16656 --------------------------
16657 -- Is_Suspension_Object --
16658 --------------------------
16660 function Is_Suspension_Object (Id : Entity_Id) return Boolean is
16661 begin
16662 -- This approach does an exact name match rather than to rely on
16663 -- RTSfind. Routine Is_Effectively_Volatile is used by clients of the
16664 -- front end at point where all auxiliary tables are locked and any
16665 -- modifications to them are treated as violations. Do not tamper with
16666 -- the tables, instead examine the Chars fields of all the scopes of Id.
16668 return
16669 Chars (Id) = Name_Suspension_Object
16670 and then Present (Scope (Id))
16671 and then Chars (Scope (Id)) = Name_Synchronous_Task_Control
16672 and then Present (Scope (Scope (Id)))
16673 and then Chars (Scope (Scope (Id))) = Name_Ada
16674 and then Present (Scope (Scope (Scope (Id))))
16675 and then Scope (Scope (Scope (Id))) = Standard_Standard;
16676 end Is_Suspension_Object;
16678 ----------------------------
16679 -- Is_Synchronized_Object --
16680 ----------------------------
16682 function Is_Synchronized_Object (Id : Entity_Id) return Boolean is
16683 Prag : Node_Id;
16685 begin
16686 if Is_Object (Id) then
16688 -- The object is synchronized if it is of a type that yields a
16689 -- synchronized object.
16691 if Yields_Synchronized_Object (Etype (Id)) then
16692 return True;
16694 -- The object is synchronized if it is atomic and Async_Writers is
16695 -- enabled.
16697 elsif Is_Atomic (Id) and then Async_Writers_Enabled (Id) then
16698 return True;
16700 -- A constant is a synchronized object by default
16702 elsif Ekind (Id) = E_Constant then
16703 return True;
16705 -- A variable is a synchronized object if it is subject to pragma
16706 -- Constant_After_Elaboration.
16708 elsif Ekind (Id) = E_Variable then
16709 Prag := Get_Pragma (Id, Pragma_Constant_After_Elaboration);
16711 return Present (Prag) and then Is_Enabled_Pragma (Prag);
16712 end if;
16713 end if;
16715 -- Otherwise the input is not an object or it does not qualify as a
16716 -- synchronized object.
16718 return False;
16719 end Is_Synchronized_Object;
16721 ---------------------------------
16722 -- Is_Synchronized_Tagged_Type --
16723 ---------------------------------
16725 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
16726 Kind : constant Entity_Kind := Ekind (Base_Type (E));
16728 begin
16729 -- A task or protected type derived from an interface is a tagged type.
16730 -- Such a tagged type is called a synchronized tagged type, as are
16731 -- synchronized interfaces and private extensions whose declaration
16732 -- includes the reserved word synchronized.
16734 return (Is_Tagged_Type (E)
16735 and then (Kind = E_Task_Type
16736 or else
16737 Kind = E_Protected_Type))
16738 or else
16739 (Is_Interface (E)
16740 and then Is_Synchronized_Interface (E))
16741 or else
16742 (Ekind (E) = E_Record_Type_With_Private
16743 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
16744 and then (Synchronized_Present (Parent (E))
16745 or else Is_Synchronized_Interface (Etype (E))));
16746 end Is_Synchronized_Tagged_Type;
16748 -----------------
16749 -- Is_Transfer --
16750 -----------------
16752 function Is_Transfer (N : Node_Id) return Boolean is
16753 Kind : constant Node_Kind := Nkind (N);
16755 begin
16756 if Kind = N_Simple_Return_Statement
16757 or else
16758 Kind = N_Extended_Return_Statement
16759 or else
16760 Kind = N_Goto_Statement
16761 or else
16762 Kind = N_Raise_Statement
16763 or else
16764 Kind = N_Requeue_Statement
16765 then
16766 return True;
16768 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
16769 and then No (Condition (N))
16770 then
16771 return True;
16773 elsif Kind = N_Procedure_Call_Statement
16774 and then Is_Entity_Name (Name (N))
16775 and then Present (Entity (Name (N)))
16776 and then No_Return (Entity (Name (N)))
16777 then
16778 return True;
16780 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
16781 return True;
16783 else
16784 return False;
16785 end if;
16786 end Is_Transfer;
16788 -------------
16789 -- Is_True --
16790 -------------
16792 function Is_True (U : Uint) return Boolean is
16793 begin
16794 return (U /= 0);
16795 end Is_True;
16797 --------------------------------------
16798 -- Is_Unchecked_Conversion_Instance --
16799 --------------------------------------
16801 function Is_Unchecked_Conversion_Instance (Id : Entity_Id) return Boolean is
16802 Par : Node_Id;
16804 begin
16805 -- Look for a function whose generic parent is the predefined intrinsic
16806 -- function Unchecked_Conversion, or for one that renames such an
16807 -- instance.
16809 if Ekind (Id) = E_Function then
16810 Par := Parent (Id);
16812 if Nkind (Par) = N_Function_Specification then
16813 Par := Generic_Parent (Par);
16815 if Present (Par) then
16816 return
16817 Chars (Par) = Name_Unchecked_Conversion
16818 and then Is_Intrinsic_Subprogram (Par)
16819 and then In_Predefined_Unit (Par);
16820 else
16821 return
16822 Present (Alias (Id))
16823 and then Is_Unchecked_Conversion_Instance (Alias (Id));
16824 end if;
16825 end if;
16826 end if;
16828 return False;
16829 end Is_Unchecked_Conversion_Instance;
16831 -------------------------------
16832 -- Is_Universal_Numeric_Type --
16833 -------------------------------
16835 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
16836 begin
16837 return T = Universal_Integer or else T = Universal_Real;
16838 end Is_Universal_Numeric_Type;
16840 ------------------------------
16841 -- Is_User_Defined_Equality --
16842 ------------------------------
16844 function Is_User_Defined_Equality (Id : Entity_Id) return Boolean is
16845 begin
16846 return Ekind (Id) = E_Function
16847 and then Chars (Id) = Name_Op_Eq
16848 and then Comes_From_Source (Id)
16850 -- Internally generated equalities have a full type declaration
16851 -- as their parent.
16853 and then Nkind (Parent (Id)) = N_Function_Specification;
16854 end Is_User_Defined_Equality;
16856 --------------------------------------
16857 -- Is_Validation_Variable_Reference --
16858 --------------------------------------
16860 function Is_Validation_Variable_Reference (N : Node_Id) return Boolean is
16861 Var : constant Node_Id := Unqual_Conv (N);
16862 Var_Id : Entity_Id;
16864 begin
16865 Var_Id := Empty;
16867 if Is_Entity_Name (Var) then
16868 Var_Id := Entity (Var);
16869 end if;
16871 return
16872 Present (Var_Id)
16873 and then Ekind (Var_Id) = E_Variable
16874 and then Present (Validated_Object (Var_Id));
16875 end Is_Validation_Variable_Reference;
16877 ----------------------------
16878 -- Is_Variable_Size_Array --
16879 ----------------------------
16881 function Is_Variable_Size_Array (E : Entity_Id) return Boolean is
16882 Idx : Node_Id;
16884 begin
16885 pragma Assert (Is_Array_Type (E));
16887 -- Check if some index is initialized with a non-constant value
16889 Idx := First_Index (E);
16890 while Present (Idx) loop
16891 if Nkind (Idx) = N_Range then
16892 if not Is_Constant_Bound (Low_Bound (Idx))
16893 or else not Is_Constant_Bound (High_Bound (Idx))
16894 then
16895 return True;
16896 end if;
16897 end if;
16899 Idx := Next_Index (Idx);
16900 end loop;
16902 return False;
16903 end Is_Variable_Size_Array;
16905 -----------------------------
16906 -- Is_Variable_Size_Record --
16907 -----------------------------
16909 function Is_Variable_Size_Record (E : Entity_Id) return Boolean is
16910 Comp : Entity_Id;
16911 Comp_Typ : Entity_Id;
16913 begin
16914 pragma Assert (Is_Record_Type (E));
16916 Comp := First_Entity (E);
16917 while Present (Comp) loop
16918 Comp_Typ := Etype (Comp);
16920 -- Recursive call if the record type has discriminants
16922 if Is_Record_Type (Comp_Typ)
16923 and then Has_Discriminants (Comp_Typ)
16924 and then Is_Variable_Size_Record (Comp_Typ)
16925 then
16926 return True;
16928 elsif Is_Array_Type (Comp_Typ)
16929 and then Is_Variable_Size_Array (Comp_Typ)
16930 then
16931 return True;
16932 end if;
16934 Next_Entity (Comp);
16935 end loop;
16937 return False;
16938 end Is_Variable_Size_Record;
16940 -----------------
16941 -- Is_Variable --
16942 -----------------
16944 function Is_Variable
16945 (N : Node_Id;
16946 Use_Original_Node : Boolean := True) return Boolean
16948 Orig_Node : Node_Id;
16950 function In_Protected_Function (E : Entity_Id) return Boolean;
16951 -- Within a protected function, the private components of the enclosing
16952 -- protected type are constants. A function nested within a (protected)
16953 -- procedure is not itself protected. Within the body of a protected
16954 -- function the current instance of the protected type is a constant.
16956 function Is_Variable_Prefix (P : Node_Id) return Boolean;
16957 -- Prefixes can involve implicit dereferences, in which case we must
16958 -- test for the case of a reference of a constant access type, which can
16959 -- can never be a variable.
16961 ---------------------------
16962 -- In_Protected_Function --
16963 ---------------------------
16965 function In_Protected_Function (E : Entity_Id) return Boolean is
16966 Prot : Entity_Id;
16967 S : Entity_Id;
16969 begin
16970 -- E is the current instance of a type
16972 if Is_Type (E) then
16973 Prot := E;
16975 -- E is an object
16977 else
16978 Prot := Scope (E);
16979 end if;
16981 if not Is_Protected_Type (Prot) then
16982 return False;
16984 else
16985 S := Current_Scope;
16986 while Present (S) and then S /= Prot loop
16987 if Ekind (S) = E_Function and then Scope (S) = Prot then
16988 return True;
16989 end if;
16991 S := Scope (S);
16992 end loop;
16994 return False;
16995 end if;
16996 end In_Protected_Function;
16998 ------------------------
16999 -- Is_Variable_Prefix --
17000 ------------------------
17002 function Is_Variable_Prefix (P : Node_Id) return Boolean is
17003 begin
17004 if Is_Access_Type (Etype (P)) then
17005 return not Is_Access_Constant (Root_Type (Etype (P)));
17007 -- For the case of an indexed component whose prefix has a packed
17008 -- array type, the prefix has been rewritten into a type conversion.
17009 -- Determine variable-ness from the converted expression.
17011 elsif Nkind (P) = N_Type_Conversion
17012 and then not Comes_From_Source (P)
17013 and then Is_Array_Type (Etype (P))
17014 and then Is_Packed (Etype (P))
17015 then
17016 return Is_Variable (Expression (P));
17018 else
17019 return Is_Variable (P);
17020 end if;
17021 end Is_Variable_Prefix;
17023 -- Start of processing for Is_Variable
17025 begin
17026 -- Special check, allow x'Deref(expr) as a variable
17028 if Nkind (N) = N_Attribute_Reference
17029 and then Attribute_Name (N) = Name_Deref
17030 then
17031 return True;
17032 end if;
17034 -- Check if we perform the test on the original node since this may be a
17035 -- test of syntactic categories which must not be disturbed by whatever
17036 -- rewriting might have occurred. For example, an aggregate, which is
17037 -- certainly NOT a variable, could be turned into a variable by
17038 -- expansion.
17040 if Use_Original_Node then
17041 Orig_Node := Original_Node (N);
17042 else
17043 Orig_Node := N;
17044 end if;
17046 -- Definitely OK if Assignment_OK is set. Since this is something that
17047 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
17049 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
17050 return True;
17052 -- Normally we go to the original node, but there is one exception where
17053 -- we use the rewritten node, namely when it is an explicit dereference.
17054 -- The generated code may rewrite a prefix which is an access type with
17055 -- an explicit dereference. The dereference is a variable, even though
17056 -- the original node may not be (since it could be a constant of the
17057 -- access type).
17059 -- In Ada 2005 we have a further case to consider: the prefix may be a
17060 -- function call given in prefix notation. The original node appears to
17061 -- be a selected component, but we need to examine the call.
17063 elsif Nkind (N) = N_Explicit_Dereference
17064 and then Nkind (Orig_Node) /= N_Explicit_Dereference
17065 and then Present (Etype (Orig_Node))
17066 and then Is_Access_Type (Etype (Orig_Node))
17067 then
17068 -- Note that if the prefix is an explicit dereference that does not
17069 -- come from source, we must check for a rewritten function call in
17070 -- prefixed notation before other forms of rewriting, to prevent a
17071 -- compiler crash.
17073 return
17074 (Nkind (Orig_Node) = N_Function_Call
17075 and then not Is_Access_Constant (Etype (Prefix (N))))
17076 or else
17077 Is_Variable_Prefix (Original_Node (Prefix (N)));
17079 -- in Ada 2012, the dereference may have been added for a type with
17080 -- a declared implicit dereference aspect. Check that it is not an
17081 -- access to constant.
17083 elsif Nkind (N) = N_Explicit_Dereference
17084 and then Present (Etype (Orig_Node))
17085 and then Ada_Version >= Ada_2012
17086 and then Has_Implicit_Dereference (Etype (Orig_Node))
17087 then
17088 return not Is_Access_Constant (Etype (Prefix (N)));
17090 -- A function call is never a variable
17092 elsif Nkind (N) = N_Function_Call then
17093 return False;
17095 -- All remaining checks use the original node
17097 elsif Is_Entity_Name (Orig_Node)
17098 and then Present (Entity (Orig_Node))
17099 then
17100 declare
17101 E : constant Entity_Id := Entity (Orig_Node);
17102 K : constant Entity_Kind := Ekind (E);
17104 begin
17105 return (K = E_Variable
17106 and then Nkind (Parent (E)) /= N_Exception_Handler)
17107 or else (K = E_Component
17108 and then not In_Protected_Function (E))
17109 or else K = E_Out_Parameter
17110 or else K = E_In_Out_Parameter
17111 or else K = E_Generic_In_Out_Parameter
17113 -- Current instance of type. If this is a protected type, check
17114 -- we are not within the body of one of its protected functions.
17116 or else (Is_Type (E)
17117 and then In_Open_Scopes (E)
17118 and then not In_Protected_Function (E))
17120 or else (Is_Incomplete_Or_Private_Type (E)
17121 and then In_Open_Scopes (Full_View (E)));
17122 end;
17124 else
17125 case Nkind (Orig_Node) is
17126 when N_Indexed_Component
17127 | N_Slice
17129 return Is_Variable_Prefix (Prefix (Orig_Node));
17131 when N_Selected_Component =>
17132 return (Is_Variable (Selector_Name (Orig_Node))
17133 and then Is_Variable_Prefix (Prefix (Orig_Node)))
17134 or else
17135 (Nkind (N) = N_Expanded_Name
17136 and then Scope (Entity (N)) = Entity (Prefix (N)));
17138 -- For an explicit dereference, the type of the prefix cannot
17139 -- be an access to constant or an access to subprogram.
17141 when N_Explicit_Dereference =>
17142 declare
17143 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
17144 begin
17145 return Is_Access_Type (Typ)
17146 and then not Is_Access_Constant (Root_Type (Typ))
17147 and then Ekind (Typ) /= E_Access_Subprogram_Type;
17148 end;
17150 -- The type conversion is the case where we do not deal with the
17151 -- context dependent special case of an actual parameter. Thus
17152 -- the type conversion is only considered a variable for the
17153 -- purposes of this routine if the target type is tagged. However,
17154 -- a type conversion is considered to be a variable if it does not
17155 -- come from source (this deals for example with the conversions
17156 -- of expressions to their actual subtypes).
17158 when N_Type_Conversion =>
17159 return Is_Variable (Expression (Orig_Node))
17160 and then
17161 (not Comes_From_Source (Orig_Node)
17162 or else
17163 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
17164 and then
17165 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
17167 -- GNAT allows an unchecked type conversion as a variable. This
17168 -- only affects the generation of internal expanded code, since
17169 -- calls to instantiations of Unchecked_Conversion are never
17170 -- considered variables (since they are function calls).
17172 when N_Unchecked_Type_Conversion =>
17173 return Is_Variable (Expression (Orig_Node));
17175 when others =>
17176 return False;
17177 end case;
17178 end if;
17179 end Is_Variable;
17181 ---------------------------
17182 -- Is_Visibly_Controlled --
17183 ---------------------------
17185 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
17186 Root : constant Entity_Id := Root_Type (T);
17187 begin
17188 return Chars (Scope (Root)) = Name_Finalization
17189 and then Chars (Scope (Scope (Root))) = Name_Ada
17190 and then Scope (Scope (Scope (Root))) = Standard_Standard;
17191 end Is_Visibly_Controlled;
17193 --------------------------
17194 -- Is_Volatile_Function --
17195 --------------------------
17197 function Is_Volatile_Function (Func_Id : Entity_Id) return Boolean is
17198 begin
17199 pragma Assert (Ekind_In (Func_Id, E_Function, E_Generic_Function));
17201 -- A function declared within a protected type is volatile
17203 if Is_Protected_Type (Scope (Func_Id)) then
17204 return True;
17206 -- An instance of Ada.Unchecked_Conversion is a volatile function if
17207 -- either the source or the target are effectively volatile.
17209 elsif Is_Unchecked_Conversion_Instance (Func_Id)
17210 and then Has_Effectively_Volatile_Profile (Func_Id)
17211 then
17212 return True;
17214 -- Otherwise the function is treated as volatile if it is subject to
17215 -- enabled pragma Volatile_Function.
17217 else
17218 return
17219 Is_Enabled_Pragma (Get_Pragma (Func_Id, Pragma_Volatile_Function));
17220 end if;
17221 end Is_Volatile_Function;
17223 ------------------------
17224 -- Is_Volatile_Object --
17225 ------------------------
17227 function Is_Volatile_Object (N : Node_Id) return Boolean is
17228 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
17229 -- If prefix is an implicit dereference, examine designated type
17231 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
17232 -- Determines if given object has volatile components
17234 ------------------------
17235 -- Is_Volatile_Prefix --
17236 ------------------------
17238 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
17239 Typ : constant Entity_Id := Etype (N);
17241 begin
17242 if Is_Access_Type (Typ) then
17243 declare
17244 Dtyp : constant Entity_Id := Designated_Type (Typ);
17246 begin
17247 return Is_Volatile (Dtyp)
17248 or else Has_Volatile_Components (Dtyp);
17249 end;
17251 else
17252 return Object_Has_Volatile_Components (N);
17253 end if;
17254 end Is_Volatile_Prefix;
17256 ------------------------------------
17257 -- Object_Has_Volatile_Components --
17258 ------------------------------------
17260 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
17261 Typ : constant Entity_Id := Etype (N);
17263 begin
17264 if Is_Volatile (Typ)
17265 or else Has_Volatile_Components (Typ)
17266 then
17267 return True;
17269 elsif Is_Entity_Name (N)
17270 and then (Has_Volatile_Components (Entity (N))
17271 or else Is_Volatile (Entity (N)))
17272 then
17273 return True;
17275 elsif Nkind (N) = N_Indexed_Component
17276 or else Nkind (N) = N_Selected_Component
17277 then
17278 return Is_Volatile_Prefix (Prefix (N));
17280 else
17281 return False;
17282 end if;
17283 end Object_Has_Volatile_Components;
17285 -- Start of processing for Is_Volatile_Object
17287 begin
17288 if Nkind (N) = N_Defining_Identifier then
17289 return Is_Volatile (N) or else Is_Volatile (Etype (N));
17291 elsif Nkind (N) = N_Expanded_Name then
17292 return Is_Volatile_Object (Entity (N));
17294 elsif Is_Volatile (Etype (N))
17295 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
17296 then
17297 return True;
17299 elsif Nkind_In (N, N_Indexed_Component, N_Selected_Component)
17300 and then Is_Volatile_Prefix (Prefix (N))
17301 then
17302 return True;
17304 elsif Nkind (N) = N_Selected_Component
17305 and then Is_Volatile (Entity (Selector_Name (N)))
17306 then
17307 return True;
17309 else
17310 return False;
17311 end if;
17312 end Is_Volatile_Object;
17314 -----------------------------
17315 -- Iterate_Call_Parameters --
17316 -----------------------------
17318 procedure Iterate_Call_Parameters (Call : Node_Id) is
17319 Formal : Entity_Id := First_Formal (Get_Called_Entity (Call));
17320 Actual : Node_Id := First_Actual (Call);
17322 begin
17323 while Present (Formal) and then Present (Actual) loop
17324 Handle_Parameter (Formal, Actual);
17325 Formal := Next_Formal (Formal);
17326 Actual := Next_Actual (Actual);
17327 end loop;
17328 end Iterate_Call_Parameters;
17330 ---------------------------
17331 -- Itype_Has_Declaration --
17332 ---------------------------
17334 function Itype_Has_Declaration (Id : Entity_Id) return Boolean is
17335 begin
17336 pragma Assert (Is_Itype (Id));
17337 return Present (Parent (Id))
17338 and then Nkind_In (Parent (Id), N_Full_Type_Declaration,
17339 N_Subtype_Declaration)
17340 and then Defining_Entity (Parent (Id)) = Id;
17341 end Itype_Has_Declaration;
17343 -------------------------
17344 -- Kill_Current_Values --
17345 -------------------------
17347 procedure Kill_Current_Values
17348 (Ent : Entity_Id;
17349 Last_Assignment_Only : Boolean := False)
17351 begin
17352 if Is_Assignable (Ent) then
17353 Set_Last_Assignment (Ent, Empty);
17354 end if;
17356 if Is_Object (Ent) then
17357 if not Last_Assignment_Only then
17358 Kill_Checks (Ent);
17359 Set_Current_Value (Ent, Empty);
17361 -- Do not reset the Is_Known_[Non_]Null and Is_Known_Valid flags
17362 -- for a constant. Once the constant is elaborated, its value is
17363 -- not changed, therefore the associated flags that describe the
17364 -- value should not be modified either.
17366 if Ekind (Ent) = E_Constant then
17367 null;
17369 -- Non-constant entities
17371 else
17372 if not Can_Never_Be_Null (Ent) then
17373 Set_Is_Known_Non_Null (Ent, False);
17374 end if;
17376 Set_Is_Known_Null (Ent, False);
17378 -- Reset the Is_Known_Valid flag unless the type is always
17379 -- valid. This does not apply to a loop parameter because its
17380 -- bounds are defined by the loop header and therefore always
17381 -- valid.
17383 if not Is_Known_Valid (Etype (Ent))
17384 and then Ekind (Ent) /= E_Loop_Parameter
17385 then
17386 Set_Is_Known_Valid (Ent, False);
17387 end if;
17388 end if;
17389 end if;
17390 end if;
17391 end Kill_Current_Values;
17393 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
17394 S : Entity_Id;
17396 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
17397 -- Clear current value for entity E and all entities chained to E
17399 ------------------------------------------
17400 -- Kill_Current_Values_For_Entity_Chain --
17401 ------------------------------------------
17403 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
17404 Ent : Entity_Id;
17405 begin
17406 Ent := E;
17407 while Present (Ent) loop
17408 Kill_Current_Values (Ent, Last_Assignment_Only);
17409 Next_Entity (Ent);
17410 end loop;
17411 end Kill_Current_Values_For_Entity_Chain;
17413 -- Start of processing for Kill_Current_Values
17415 begin
17416 -- Kill all saved checks, a special case of killing saved values
17418 if not Last_Assignment_Only then
17419 Kill_All_Checks;
17420 end if;
17422 -- Loop through relevant scopes, which includes the current scope and
17423 -- any parent scopes if the current scope is a block or a package.
17425 S := Current_Scope;
17426 Scope_Loop : loop
17428 -- Clear current values of all entities in current scope
17430 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
17432 -- If scope is a package, also clear current values of all private
17433 -- entities in the scope.
17435 if Is_Package_Or_Generic_Package (S)
17436 or else Is_Concurrent_Type (S)
17437 then
17438 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
17439 end if;
17441 -- If this is a not a subprogram, deal with parents
17443 if not Is_Subprogram (S) then
17444 S := Scope (S);
17445 exit Scope_Loop when S = Standard_Standard;
17446 else
17447 exit Scope_Loop;
17448 end if;
17449 end loop Scope_Loop;
17450 end Kill_Current_Values;
17452 --------------------------
17453 -- Kill_Size_Check_Code --
17454 --------------------------
17456 procedure Kill_Size_Check_Code (E : Entity_Id) is
17457 begin
17458 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
17459 and then Present (Size_Check_Code (E))
17460 then
17461 Remove (Size_Check_Code (E));
17462 Set_Size_Check_Code (E, Empty);
17463 end if;
17464 end Kill_Size_Check_Code;
17466 --------------------
17467 -- Known_Non_Null --
17468 --------------------
17470 function Known_Non_Null (N : Node_Id) return Boolean is
17471 Status : constant Null_Status_Kind := Null_Status (N);
17473 Id : Entity_Id;
17474 Op : Node_Kind;
17475 Val : Node_Id;
17477 begin
17478 -- The expression yields a non-null value ignoring simple flow analysis
17480 if Status = Is_Non_Null then
17481 return True;
17483 -- Otherwise check whether N is a reference to an entity that appears
17484 -- within a conditional construct.
17486 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
17488 -- First check if we are in decisive conditional
17490 Get_Current_Value_Condition (N, Op, Val);
17492 if Known_Null (Val) then
17493 if Op = N_Op_Eq then
17494 return False;
17495 elsif Op = N_Op_Ne then
17496 return True;
17497 end if;
17498 end if;
17500 -- If OK to do replacement, test Is_Known_Non_Null flag
17502 Id := Entity (N);
17504 if OK_To_Do_Constant_Replacement (Id) then
17505 return Is_Known_Non_Null (Id);
17506 end if;
17507 end if;
17509 -- Otherwise it is not possible to determine whether N yields a non-null
17510 -- value.
17512 return False;
17513 end Known_Non_Null;
17515 ----------------
17516 -- Known_Null --
17517 ----------------
17519 function Known_Null (N : Node_Id) return Boolean is
17520 Status : constant Null_Status_Kind := Null_Status (N);
17522 Id : Entity_Id;
17523 Op : Node_Kind;
17524 Val : Node_Id;
17526 begin
17527 -- The expression yields a null value ignoring simple flow analysis
17529 if Status = Is_Null then
17530 return True;
17532 -- Otherwise check whether N is a reference to an entity that appears
17533 -- within a conditional construct.
17535 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
17537 -- First check if we are in decisive conditional
17539 Get_Current_Value_Condition (N, Op, Val);
17541 if Known_Null (Val) then
17542 if Op = N_Op_Eq then
17543 return True;
17544 elsif Op = N_Op_Ne then
17545 return False;
17546 end if;
17547 end if;
17549 -- If OK to do replacement, test Is_Known_Null flag
17551 Id := Entity (N);
17553 if OK_To_Do_Constant_Replacement (Id) then
17554 return Is_Known_Null (Id);
17555 end if;
17556 end if;
17558 -- Otherwise it is not possible to determine whether N yields a null
17559 -- value.
17561 return False;
17562 end Known_Null;
17564 --------------------------
17565 -- Known_To_Be_Assigned --
17566 --------------------------
17568 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
17569 P : constant Node_Id := Parent (N);
17571 begin
17572 case Nkind (P) is
17574 -- Test left side of assignment
17576 when N_Assignment_Statement =>
17577 return N = Name (P);
17579 -- Function call arguments are never lvalues
17581 when N_Function_Call =>
17582 return False;
17584 -- Positional parameter for procedure or accept call
17586 when N_Accept_Statement
17587 | N_Procedure_Call_Statement
17589 declare
17590 Proc : Entity_Id;
17591 Form : Entity_Id;
17592 Act : Node_Id;
17594 begin
17595 Proc := Get_Subprogram_Entity (P);
17597 if No (Proc) then
17598 return False;
17599 end if;
17601 -- If we are not a list member, something is strange, so
17602 -- be conservative and return False.
17604 if not Is_List_Member (N) then
17605 return False;
17606 end if;
17608 -- We are going to find the right formal by stepping forward
17609 -- through the formals, as we step backwards in the actuals.
17611 Form := First_Formal (Proc);
17612 Act := N;
17613 loop
17614 -- If no formal, something is weird, so be conservative
17615 -- and return False.
17617 if No (Form) then
17618 return False;
17619 end if;
17621 Prev (Act);
17622 exit when No (Act);
17623 Next_Formal (Form);
17624 end loop;
17626 return Ekind (Form) /= E_In_Parameter;
17627 end;
17629 -- Named parameter for procedure or accept call
17631 when N_Parameter_Association =>
17632 declare
17633 Proc : Entity_Id;
17634 Form : Entity_Id;
17636 begin
17637 Proc := Get_Subprogram_Entity (Parent (P));
17639 if No (Proc) then
17640 return False;
17641 end if;
17643 -- Loop through formals to find the one that matches
17645 Form := First_Formal (Proc);
17646 loop
17647 -- If no matching formal, that's peculiar, some kind of
17648 -- previous error, so return False to be conservative.
17649 -- Actually this also happens in legal code in the case
17650 -- where P is a parameter association for an Extra_Formal???
17652 if No (Form) then
17653 return False;
17654 end if;
17656 -- Else test for match
17658 if Chars (Form) = Chars (Selector_Name (P)) then
17659 return Ekind (Form) /= E_In_Parameter;
17660 end if;
17662 Next_Formal (Form);
17663 end loop;
17664 end;
17666 -- Test for appearing in a conversion that itself appears
17667 -- in an lvalue context, since this should be an lvalue.
17669 when N_Type_Conversion =>
17670 return Known_To_Be_Assigned (P);
17672 -- All other references are definitely not known to be modifications
17674 when others =>
17675 return False;
17676 end case;
17677 end Known_To_Be_Assigned;
17679 ---------------------------
17680 -- Last_Source_Statement --
17681 ---------------------------
17683 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
17684 N : Node_Id;
17686 begin
17687 N := Last (Statements (HSS));
17688 while Present (N) loop
17689 exit when Comes_From_Source (N);
17690 Prev (N);
17691 end loop;
17693 return N;
17694 end Last_Source_Statement;
17696 -----------------------
17697 -- Mark_Coextensions --
17698 -----------------------
17700 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
17701 Is_Dynamic : Boolean;
17702 -- Indicates whether the context causes nested coextensions to be
17703 -- dynamic or static
17705 function Mark_Allocator (N : Node_Id) return Traverse_Result;
17706 -- Recognize an allocator node and label it as a dynamic coextension
17708 --------------------
17709 -- Mark_Allocator --
17710 --------------------
17712 function Mark_Allocator (N : Node_Id) return Traverse_Result is
17713 begin
17714 if Nkind (N) = N_Allocator then
17715 if Is_Dynamic then
17716 Set_Is_Dynamic_Coextension (N);
17718 -- If the allocator expression is potentially dynamic, it may
17719 -- be expanded out of order and require dynamic allocation
17720 -- anyway, so we treat the coextension itself as dynamic.
17721 -- Potential optimization ???
17723 elsif Nkind (Expression (N)) = N_Qualified_Expression
17724 and then Nkind (Expression (Expression (N))) = N_Op_Concat
17725 then
17726 Set_Is_Dynamic_Coextension (N);
17727 else
17728 Set_Is_Static_Coextension (N);
17729 end if;
17730 end if;
17732 return OK;
17733 end Mark_Allocator;
17735 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
17737 -- Start of processing for Mark_Coextensions
17739 begin
17740 -- An allocator that appears on the right-hand side of an assignment is
17741 -- treated as a potentially dynamic coextension when the right-hand side
17742 -- is an allocator or a qualified expression.
17744 -- Obj := new ...'(new Coextension ...);
17746 if Nkind (Context_Nod) = N_Assignment_Statement then
17747 Is_Dynamic :=
17748 Nkind_In (Expression (Context_Nod), N_Allocator,
17749 N_Qualified_Expression);
17751 -- An allocator that appears within the expression of a simple return
17752 -- statement is treated as a potentially dynamic coextension when the
17753 -- expression is either aggregate, allocator, or qualified expression.
17755 -- return (new Coextension ...);
17756 -- return new ...'(new Coextension ...);
17758 elsif Nkind (Context_Nod) = N_Simple_Return_Statement then
17759 Is_Dynamic :=
17760 Nkind_In (Expression (Context_Nod), N_Aggregate,
17761 N_Allocator,
17762 N_Qualified_Expression);
17764 -- An alloctor that appears within the initialization expression of an
17765 -- object declaration is considered a potentially dynamic coextension
17766 -- when the initialization expression is an allocator or a qualified
17767 -- expression.
17769 -- Obj : ... := new ...'(new Coextension ...);
17771 -- A similar case arises when the object declaration is part of an
17772 -- extended return statement.
17774 -- return Obj : ... := new ...'(new Coextension ...);
17775 -- return Obj : ... := (new Coextension ...);
17777 elsif Nkind (Context_Nod) = N_Object_Declaration then
17778 Is_Dynamic :=
17779 Nkind_In (Root_Nod, N_Allocator, N_Qualified_Expression)
17780 or else
17781 Nkind (Parent (Context_Nod)) = N_Extended_Return_Statement;
17783 -- This routine should not be called with constructs that cannot contain
17784 -- coextensions.
17786 else
17787 raise Program_Error;
17788 end if;
17790 Mark_Allocators (Root_Nod);
17791 end Mark_Coextensions;
17793 ---------------------------------
17794 -- Mark_Elaboration_Attributes --
17795 ---------------------------------
17797 procedure Mark_Elaboration_Attributes
17798 (N_Id : Node_Or_Entity_Id;
17799 Checks : Boolean := False;
17800 Level : Boolean := False;
17801 Modes : Boolean := False;
17802 Warnings : Boolean := False)
17804 function Elaboration_Checks_OK
17805 (Target_Id : Entity_Id;
17806 Context_Id : Entity_Id) return Boolean;
17807 -- Determine whether elaboration checks are enabled for target Target_Id
17808 -- which resides within context Context_Id.
17810 procedure Mark_Elaboration_Attributes_Id (Id : Entity_Id);
17811 -- Preserve relevant attributes of the context in arbitrary entity Id
17813 procedure Mark_Elaboration_Attributes_Node (N : Node_Id);
17814 -- Preserve relevant attributes of the context in arbitrary node N
17816 ---------------------------
17817 -- Elaboration_Checks_OK --
17818 ---------------------------
17820 function Elaboration_Checks_OK
17821 (Target_Id : Entity_Id;
17822 Context_Id : Entity_Id) return Boolean
17824 Encl_Scop : Entity_Id;
17826 begin
17827 -- Elaboration checks are suppressed for the target
17829 if Elaboration_Checks_Suppressed (Target_Id) then
17830 return False;
17831 end if;
17833 -- Otherwise elaboration checks are OK for the target, but may be
17834 -- suppressed for the context where the target is declared.
17836 Encl_Scop := Context_Id;
17837 while Present (Encl_Scop) and then Encl_Scop /= Standard_Standard loop
17838 if Elaboration_Checks_Suppressed (Encl_Scop) then
17839 return False;
17840 end if;
17842 Encl_Scop := Scope (Encl_Scop);
17843 end loop;
17845 -- Neither the target nor its declarative context have elaboration
17846 -- checks suppressed.
17848 return True;
17849 end Elaboration_Checks_OK;
17851 ------------------------------------
17852 -- Mark_Elaboration_Attributes_Id --
17853 ------------------------------------
17855 procedure Mark_Elaboration_Attributes_Id (Id : Entity_Id) is
17856 begin
17857 -- Mark the status of elaboration checks in effect. Do not reset the
17858 -- status in case the entity is reanalyzed with checks suppressed.
17860 if Checks and then not Is_Elaboration_Checks_OK_Id (Id) then
17861 Set_Is_Elaboration_Checks_OK_Id (Id,
17862 Elaboration_Checks_OK
17863 (Target_Id => Id,
17864 Context_Id => Scope (Id)));
17866 -- Entities do not need to capture their enclosing level. The Ghost
17867 -- and SPARK modes in effect are already marked during analysis.
17869 else
17870 null;
17871 end if;
17872 end Mark_Elaboration_Attributes_Id;
17874 --------------------------------------
17875 -- Mark_Elaboration_Attributes_Node --
17876 --------------------------------------
17878 procedure Mark_Elaboration_Attributes_Node (N : Node_Id) is
17879 function Extract_Name (N : Node_Id) return Node_Id;
17880 -- Obtain the Name attribute of call or instantiation N
17882 ------------------
17883 -- Extract_Name --
17884 ------------------
17886 function Extract_Name (N : Node_Id) return Node_Id is
17887 Nam : Node_Id;
17889 begin
17890 Nam := Name (N);
17892 -- A call to an entry family appears in indexed form
17894 if Nkind (Nam) = N_Indexed_Component then
17895 Nam := Prefix (Nam);
17896 end if;
17898 -- The name may also appear in qualified form
17900 if Nkind (Nam) = N_Selected_Component then
17901 Nam := Selector_Name (Nam);
17902 end if;
17904 return Nam;
17905 end Extract_Name;
17907 -- Local variables
17909 Context_Id : Entity_Id;
17910 Nam : Node_Id;
17912 -- Start of processing for Mark_Elaboration_Attributes_Node
17914 begin
17915 -- Mark the status of elaboration checks in effect. Do not reset the
17916 -- status in case the node is reanalyzed with checks suppressed.
17918 if Checks and then not Is_Elaboration_Checks_OK_Node (N) then
17920 -- Assignments, attribute references, and variable references do
17921 -- not have a "declarative" context.
17923 Context_Id := Empty;
17925 -- The status of elaboration checks for calls and instantiations
17926 -- depends on the most recent pragma Suppress/Unsuppress, as well
17927 -- as the suppression status of the context where the target is
17928 -- defined.
17930 -- package Pack is
17931 -- function Func ...;
17932 -- end Pack;
17934 -- with Pack;
17935 -- procedure Main is
17936 -- pragma Suppress (Elaboration_Checks, Pack);
17937 -- X : ... := Pack.Func;
17938 -- ...
17940 -- In the example above, the call to Func has elaboration checks
17941 -- enabled because there is no active general purpose suppression
17942 -- pragma, however the elaboration checks of Pack are explicitly
17943 -- suppressed. As a result the elaboration checks of the call must
17944 -- be disabled in order to preserve this dependency.
17946 if Nkind_In (N, N_Entry_Call_Statement,
17947 N_Function_Call,
17948 N_Function_Instantiation,
17949 N_Package_Instantiation,
17950 N_Procedure_Call_Statement,
17951 N_Procedure_Instantiation)
17952 then
17953 Nam := Extract_Name (N);
17955 if Is_Entity_Name (Nam) and then Present (Entity (Nam)) then
17956 Context_Id := Scope (Entity (Nam));
17957 end if;
17958 end if;
17960 Set_Is_Elaboration_Checks_OK_Node (N,
17961 Elaboration_Checks_OK
17962 (Target_Id => Empty,
17963 Context_Id => Context_Id));
17964 end if;
17966 -- Mark the enclosing level of the node. Do not reset the status in
17967 -- case the node is relocated and reanalyzed.
17969 if Level and then not Is_Declaration_Level_Node (N) then
17970 Set_Is_Declaration_Level_Node (N,
17971 Find_Enclosing_Level (N) = Declaration_Level);
17972 end if;
17974 -- Mark the Ghost and SPARK mode in effect
17976 if Modes then
17977 if Ghost_Mode = Ignore then
17978 Set_Is_Ignored_Ghost_Node (N);
17979 end if;
17981 if SPARK_Mode = On then
17982 Set_Is_SPARK_Mode_On_Node (N);
17983 end if;
17984 end if;
17986 -- Mark the status of elaboration warnings in effect. Do not reset
17987 -- the status in case the node is reanalyzed with warnings off.
17989 if Warnings and then not Is_Elaboration_Warnings_OK_Node (N) then
17990 Set_Is_Elaboration_Warnings_OK_Node (N, Elab_Warnings);
17991 end if;
17992 end Mark_Elaboration_Attributes_Node;
17994 -- Start of processing for Mark_Elaboration_Attributes
17996 begin
17997 -- Do not capture any elaboration-related attributes when switch -gnatH
17998 -- (legacy elaboration checking mode enabled) is in effect because the
17999 -- attributes are useless to the legacy model.
18001 if Legacy_Elaboration_Checks then
18002 return;
18003 end if;
18005 if Nkind (N_Id) in N_Entity then
18006 Mark_Elaboration_Attributes_Id (N_Id);
18007 else
18008 Mark_Elaboration_Attributes_Node (N_Id);
18009 end if;
18010 end Mark_Elaboration_Attributes;
18012 ----------------------------------
18013 -- Matching_Static_Array_Bounds --
18014 ----------------------------------
18016 function Matching_Static_Array_Bounds
18017 (L_Typ : Node_Id;
18018 R_Typ : Node_Id) return Boolean
18020 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
18021 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
18023 L_Index : Node_Id := Empty; -- init to ...
18024 R_Index : Node_Id := Empty; -- ...avoid warnings
18025 L_Low : Node_Id;
18026 L_High : Node_Id;
18027 L_Len : Uint;
18028 R_Low : Node_Id;
18029 R_High : Node_Id;
18030 R_Len : Uint;
18032 begin
18033 if L_Ndims /= R_Ndims then
18034 return False;
18035 end if;
18037 -- Unconstrained types do not have static bounds
18039 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
18040 return False;
18041 end if;
18043 -- First treat specially the first dimension, as the lower bound and
18044 -- length of string literals are not stored like those of arrays.
18046 if Ekind (L_Typ) = E_String_Literal_Subtype then
18047 L_Low := String_Literal_Low_Bound (L_Typ);
18048 L_Len := String_Literal_Length (L_Typ);
18049 else
18050 L_Index := First_Index (L_Typ);
18051 Get_Index_Bounds (L_Index, L_Low, L_High);
18053 if Is_OK_Static_Expression (L_Low)
18054 and then
18055 Is_OK_Static_Expression (L_High)
18056 then
18057 if Expr_Value (L_High) < Expr_Value (L_Low) then
18058 L_Len := Uint_0;
18059 else
18060 L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
18061 end if;
18062 else
18063 return False;
18064 end if;
18065 end if;
18067 if Ekind (R_Typ) = E_String_Literal_Subtype then
18068 R_Low := String_Literal_Low_Bound (R_Typ);
18069 R_Len := String_Literal_Length (R_Typ);
18070 else
18071 R_Index := First_Index (R_Typ);
18072 Get_Index_Bounds (R_Index, R_Low, R_High);
18074 if Is_OK_Static_Expression (R_Low)
18075 and then
18076 Is_OK_Static_Expression (R_High)
18077 then
18078 if Expr_Value (R_High) < Expr_Value (R_Low) then
18079 R_Len := Uint_0;
18080 else
18081 R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
18082 end if;
18083 else
18084 return False;
18085 end if;
18086 end if;
18088 if (Is_OK_Static_Expression (L_Low)
18089 and then
18090 Is_OK_Static_Expression (R_Low))
18091 and then Expr_Value (L_Low) = Expr_Value (R_Low)
18092 and then L_Len = R_Len
18093 then
18094 null;
18095 else
18096 return False;
18097 end if;
18099 -- Then treat all other dimensions
18101 for Indx in 2 .. L_Ndims loop
18102 Next (L_Index);
18103 Next (R_Index);
18105 Get_Index_Bounds (L_Index, L_Low, L_High);
18106 Get_Index_Bounds (R_Index, R_Low, R_High);
18108 if (Is_OK_Static_Expression (L_Low) and then
18109 Is_OK_Static_Expression (L_High) and then
18110 Is_OK_Static_Expression (R_Low) and then
18111 Is_OK_Static_Expression (R_High))
18112 and then (Expr_Value (L_Low) = Expr_Value (R_Low)
18113 and then
18114 Expr_Value (L_High) = Expr_Value (R_High))
18115 then
18116 null;
18117 else
18118 return False;
18119 end if;
18120 end loop;
18122 -- If we fall through the loop, all indexes matched
18124 return True;
18125 end Matching_Static_Array_Bounds;
18127 -------------------
18128 -- May_Be_Lvalue --
18129 -------------------
18131 function May_Be_Lvalue (N : Node_Id) return Boolean is
18132 P : constant Node_Id := Parent (N);
18134 begin
18135 case Nkind (P) is
18137 -- Test left side of assignment
18139 when N_Assignment_Statement =>
18140 return N = Name (P);
18142 -- Test prefix of component or attribute. Note that the prefix of an
18143 -- explicit or implicit dereference cannot be an l-value. In the case
18144 -- of a 'Read attribute, the reference can be an actual in the
18145 -- argument list of the attribute.
18147 when N_Attribute_Reference =>
18148 return (N = Prefix (P)
18149 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P)))
18150 or else
18151 Attribute_Name (P) = Name_Read;
18153 -- For an expanded name, the name is an lvalue if the expanded name
18154 -- is an lvalue, but the prefix is never an lvalue, since it is just
18155 -- the scope where the name is found.
18157 when N_Expanded_Name =>
18158 if N = Prefix (P) then
18159 return May_Be_Lvalue (P);
18160 else
18161 return False;
18162 end if;
18164 -- For a selected component A.B, A is certainly an lvalue if A.B is.
18165 -- B is a little interesting, if we have A.B := 3, there is some
18166 -- discussion as to whether B is an lvalue or not, we choose to say
18167 -- it is. Note however that A is not an lvalue if it is of an access
18168 -- type since this is an implicit dereference.
18170 when N_Selected_Component =>
18171 if N = Prefix (P)
18172 and then Present (Etype (N))
18173 and then Is_Access_Type (Etype (N))
18174 then
18175 return False;
18176 else
18177 return May_Be_Lvalue (P);
18178 end if;
18180 -- For an indexed component or slice, the index or slice bounds is
18181 -- never an lvalue. The prefix is an lvalue if the indexed component
18182 -- or slice is an lvalue, except if it is an access type, where we
18183 -- have an implicit dereference.
18185 when N_Indexed_Component
18186 | N_Slice
18188 if N /= Prefix (P)
18189 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
18190 then
18191 return False;
18192 else
18193 return May_Be_Lvalue (P);
18194 end if;
18196 -- Prefix of a reference is an lvalue if the reference is an lvalue
18198 when N_Reference =>
18199 return May_Be_Lvalue (P);
18201 -- Prefix of explicit dereference is never an lvalue
18203 when N_Explicit_Dereference =>
18204 return False;
18206 -- Positional parameter for subprogram, entry, or accept call.
18207 -- In older versions of Ada function call arguments are never
18208 -- lvalues. In Ada 2012 functions can have in-out parameters.
18210 when N_Accept_Statement
18211 | N_Entry_Call_Statement
18212 | N_Subprogram_Call
18214 if Nkind (P) = N_Function_Call and then Ada_Version < Ada_2012 then
18215 return False;
18216 end if;
18218 -- The following mechanism is clumsy and fragile. A single flag
18219 -- set in Resolve_Actuals would be preferable ???
18221 declare
18222 Proc : Entity_Id;
18223 Form : Entity_Id;
18224 Act : Node_Id;
18226 begin
18227 Proc := Get_Subprogram_Entity (P);
18229 if No (Proc) then
18230 return True;
18231 end if;
18233 -- If we are not a list member, something is strange, so be
18234 -- conservative and return True.
18236 if not Is_List_Member (N) then
18237 return True;
18238 end if;
18240 -- We are going to find the right formal by stepping forward
18241 -- through the formals, as we step backwards in the actuals.
18243 Form := First_Formal (Proc);
18244 Act := N;
18245 loop
18246 -- If no formal, something is weird, so be conservative and
18247 -- return True.
18249 if No (Form) then
18250 return True;
18251 end if;
18253 Prev (Act);
18254 exit when No (Act);
18255 Next_Formal (Form);
18256 end loop;
18258 return Ekind (Form) /= E_In_Parameter;
18259 end;
18261 -- Named parameter for procedure or accept call
18263 when N_Parameter_Association =>
18264 declare
18265 Proc : Entity_Id;
18266 Form : Entity_Id;
18268 begin
18269 Proc := Get_Subprogram_Entity (Parent (P));
18271 if No (Proc) then
18272 return True;
18273 end if;
18275 -- Loop through formals to find the one that matches
18277 Form := First_Formal (Proc);
18278 loop
18279 -- If no matching formal, that's peculiar, some kind of
18280 -- previous error, so return True to be conservative.
18281 -- Actually happens with legal code for an unresolved call
18282 -- where we may get the wrong homonym???
18284 if No (Form) then
18285 return True;
18286 end if;
18288 -- Else test for match
18290 if Chars (Form) = Chars (Selector_Name (P)) then
18291 return Ekind (Form) /= E_In_Parameter;
18292 end if;
18294 Next_Formal (Form);
18295 end loop;
18296 end;
18298 -- Test for appearing in a conversion that itself appears in an
18299 -- lvalue context, since this should be an lvalue.
18301 when N_Type_Conversion =>
18302 return May_Be_Lvalue (P);
18304 -- Test for appearance in object renaming declaration
18306 when N_Object_Renaming_Declaration =>
18307 return True;
18309 -- All other references are definitely not lvalues
18311 when others =>
18312 return False;
18313 end case;
18314 end May_Be_Lvalue;
18316 -----------------
18317 -- Might_Raise --
18318 -----------------
18320 function Might_Raise (N : Node_Id) return Boolean is
18321 Result : Boolean := False;
18323 function Process (N : Node_Id) return Traverse_Result;
18324 -- Set Result to True if we find something that could raise an exception
18326 -------------
18327 -- Process --
18328 -------------
18330 function Process (N : Node_Id) return Traverse_Result is
18331 begin
18332 if Nkind_In (N, N_Procedure_Call_Statement,
18333 N_Function_Call,
18334 N_Raise_Statement,
18335 N_Raise_Constraint_Error,
18336 N_Raise_Program_Error,
18337 N_Raise_Storage_Error)
18338 then
18339 Result := True;
18340 return Abandon;
18341 else
18342 return OK;
18343 end if;
18344 end Process;
18346 procedure Set_Result is new Traverse_Proc (Process);
18348 -- Start of processing for Might_Raise
18350 begin
18351 -- False if exceptions can't be propagated
18353 if No_Exception_Handlers_Set then
18354 return False;
18355 end if;
18357 -- If the checks handled by the back end are not disabled, we cannot
18358 -- ensure that no exception will be raised.
18360 if not Access_Checks_Suppressed (Empty)
18361 or else not Discriminant_Checks_Suppressed (Empty)
18362 or else not Range_Checks_Suppressed (Empty)
18363 or else not Index_Checks_Suppressed (Empty)
18364 or else Opt.Stack_Checking_Enabled
18365 then
18366 return True;
18367 end if;
18369 Set_Result (N);
18370 return Result;
18371 end Might_Raise;
18373 --------------------------------
18374 -- Nearest_Enclosing_Instance --
18375 --------------------------------
18377 function Nearest_Enclosing_Instance (E : Entity_Id) return Entity_Id is
18378 Inst : Entity_Id;
18380 begin
18381 Inst := Scope (E);
18382 while Present (Inst) and then Inst /= Standard_Standard loop
18383 if Is_Generic_Instance (Inst) then
18384 return Inst;
18385 end if;
18387 Inst := Scope (Inst);
18388 end loop;
18390 return Empty;
18391 end Nearest_Enclosing_Instance;
18393 ----------------------
18394 -- Needs_One_Actual --
18395 ----------------------
18397 function Needs_One_Actual (E : Entity_Id) return Boolean is
18398 Formal : Entity_Id;
18400 begin
18401 -- Ada 2005 or later, and formals present. The first formal must be
18402 -- of a type that supports prefix notation: a controlling argument,
18403 -- a class-wide type, or an access to such.
18405 if Ada_Version >= Ada_2005
18406 and then Present (First_Formal (E))
18407 and then No (Default_Value (First_Formal (E)))
18408 and then
18409 (Is_Controlling_Formal (First_Formal (E))
18410 or else Is_Class_Wide_Type (Etype (First_Formal (E)))
18411 or else Is_Anonymous_Access_Type (Etype (First_Formal (E))))
18412 then
18413 Formal := Next_Formal (First_Formal (E));
18414 while Present (Formal) loop
18415 if No (Default_Value (Formal)) then
18416 return False;
18417 end if;
18419 Next_Formal (Formal);
18420 end loop;
18422 return True;
18424 -- Ada 83/95 or no formals
18426 else
18427 return False;
18428 end if;
18429 end Needs_One_Actual;
18431 ------------------------
18432 -- New_Copy_List_Tree --
18433 ------------------------
18435 function New_Copy_List_Tree (List : List_Id) return List_Id is
18436 NL : List_Id;
18437 E : Node_Id;
18439 begin
18440 if List = No_List then
18441 return No_List;
18443 else
18444 NL := New_List;
18445 E := First (List);
18447 while Present (E) loop
18448 Append (New_Copy_Tree (E), NL);
18449 E := Next (E);
18450 end loop;
18452 return NL;
18453 end if;
18454 end New_Copy_List_Tree;
18456 -------------------
18457 -- New_Copy_Tree --
18458 -------------------
18460 -- The following tables play a key role in replicating entities and Itypes.
18461 -- They are intentionally declared at the library level rather than within
18462 -- New_Copy_Tree to avoid elaborating them on each call. This performance
18463 -- optimization saves up to 2% of the entire compilation time spent in the
18464 -- front end. Care should be taken to reset the tables on each new call to
18465 -- New_Copy_Tree.
18467 NCT_Table_Max : constant := 511;
18469 subtype NCT_Table_Index is Nat range 0 .. NCT_Table_Max - 1;
18471 function NCT_Table_Hash (Key : Node_Or_Entity_Id) return NCT_Table_Index;
18472 -- Obtain the hash value of node or entity Key
18474 --------------------
18475 -- NCT_Table_Hash --
18476 --------------------
18478 function NCT_Table_Hash (Key : Node_Or_Entity_Id) return NCT_Table_Index is
18479 begin
18480 return NCT_Table_Index (Key mod NCT_Table_Max);
18481 end NCT_Table_Hash;
18483 ----------------------
18484 -- NCT_New_Entities --
18485 ----------------------
18487 -- The following table maps old entities and Itypes to their corresponding
18488 -- new entities and Itypes.
18490 -- Aaa -> Xxx
18492 package NCT_New_Entities is new Simple_HTable (
18493 Header_Num => NCT_Table_Index,
18494 Element => Entity_Id,
18495 No_Element => Empty,
18496 Key => Entity_Id,
18497 Hash => NCT_Table_Hash,
18498 Equal => "=");
18500 ------------------------
18501 -- NCT_Pending_Itypes --
18502 ------------------------
18504 -- The following table maps old Associated_Node_For_Itype nodes to a set of
18505 -- new itypes. Given a set of old Itypes Aaa, Bbb, and Ccc, where all three
18506 -- have the same Associated_Node_For_Itype Ppp, and their corresponding new
18507 -- Itypes Xxx, Yyy, Zzz, the table contains the following mapping:
18509 -- Ppp -> (Xxx, Yyy, Zzz)
18511 -- The set is expressed as an Elist
18513 package NCT_Pending_Itypes is new Simple_HTable (
18514 Header_Num => NCT_Table_Index,
18515 Element => Elist_Id,
18516 No_Element => No_Elist,
18517 Key => Node_Id,
18518 Hash => NCT_Table_Hash,
18519 Equal => "=");
18521 NCT_Tables_In_Use : Boolean := False;
18522 -- This flag keeps track of whether the two tables NCT_New_Entities and
18523 -- NCT_Pending_Itypes are in use. The flag is part of an optimization
18524 -- where certain operations are not performed if the tables are not in
18525 -- use. This saves up to 8% of the entire compilation time spent in the
18526 -- front end.
18528 -------------------
18529 -- New_Copy_Tree --
18530 -------------------
18532 function New_Copy_Tree
18533 (Source : Node_Id;
18534 Map : Elist_Id := No_Elist;
18535 New_Sloc : Source_Ptr := No_Location;
18536 New_Scope : Entity_Id := Empty) return Node_Id
18538 -- This routine performs low-level tree manipulations and needs access
18539 -- to the internals of the tree.
18541 use Atree.Unchecked_Access;
18542 use Atree_Private_Part;
18544 EWA_Level : Nat := 0;
18545 -- This counter keeps track of how many N_Expression_With_Actions nodes
18546 -- are encountered during a depth-first traversal of the subtree. These
18547 -- nodes may define new entities in their Actions lists and thus require
18548 -- special processing.
18550 EWA_Inner_Scope_Level : Nat := 0;
18551 -- This counter keeps track of how many scoping constructs appear within
18552 -- an N_Expression_With_Actions node.
18554 procedure Add_New_Entity (Old_Id : Entity_Id; New_Id : Entity_Id);
18555 pragma Inline (Add_New_Entity);
18556 -- Add an entry in the NCT_New_Entities table which maps key Old_Id to
18557 -- value New_Id. Old_Id is an entity which appears within the Actions
18558 -- list of an N_Expression_With_Actions node, or within an entity map.
18559 -- New_Id is the corresponding new entity generated during Phase 1.
18561 procedure Add_Pending_Itype (Assoc_Nod : Node_Id; Itype : Entity_Id);
18562 pragma Inline (Add_New_Entity);
18563 -- Add an entry in the NCT_Pending_Itypes which maps key Assoc_Nod to
18564 -- value Itype. Assoc_Nod is the associated node of an itype. Itype is
18565 -- an itype.
18567 procedure Build_NCT_Tables (Entity_Map : Elist_Id);
18568 pragma Inline (Build_NCT_Tables);
18569 -- Populate tables NCT_New_Entities and NCT_Pending_Itypes with the
18570 -- information supplied in entity map Entity_Map. The format of the
18571 -- entity map must be as follows:
18573 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
18575 function Copy_Any_Node_With_Replacement
18576 (N : Node_Or_Entity_Id) return Node_Or_Entity_Id;
18577 pragma Inline (Copy_Any_Node_With_Replacement);
18578 -- Replicate entity or node N by invoking one of the following routines:
18580 -- Copy_Node_With_Replacement
18581 -- Corresponding_Entity
18583 function Copy_Elist_With_Replacement (List : Elist_Id) return Elist_Id;
18584 -- Replicate the elements of entity list List
18586 function Copy_Field_With_Replacement
18587 (Field : Union_Id;
18588 Old_Par : Node_Id := Empty;
18589 New_Par : Node_Id := Empty;
18590 Semantic : Boolean := False) return Union_Id;
18591 -- Replicate field Field by invoking one of the following routines:
18593 -- Copy_Elist_With_Replacement
18594 -- Copy_List_With_Replacement
18595 -- Copy_Node_With_Replacement
18596 -- Corresponding_Entity
18598 -- If the field is not an entity list, entity, itype, syntactic list,
18599 -- or node, then the field is returned unchanged. The routine always
18600 -- replicates entities, itypes, and valid syntactic fields. Old_Par is
18601 -- the expected parent of a syntactic field. New_Par is the new parent
18602 -- associated with a replicated syntactic field. Flag Semantic should
18603 -- be set when the input is a semantic field.
18605 function Copy_List_With_Replacement (List : List_Id) return List_Id;
18606 -- Replicate the elements of syntactic list List
18608 function Copy_Node_With_Replacement (N : Node_Id) return Node_Id;
18609 -- Replicate node N
18611 function Corresponding_Entity (Id : Entity_Id) return Entity_Id;
18612 pragma Inline (Corresponding_Entity);
18613 -- Return the corresponding new entity of Id generated during Phase 1.
18614 -- If there is no such entity, return Id.
18616 function In_Entity_Map
18617 (Id : Entity_Id;
18618 Entity_Map : Elist_Id) return Boolean;
18619 pragma Inline (In_Entity_Map);
18620 -- Determine whether entity Id is one of the old ids specified in entity
18621 -- map Entity_Map. The format of the entity map must be as follows:
18623 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
18625 procedure Update_CFS_Sloc (N : Node_Or_Entity_Id);
18626 pragma Inline (Update_CFS_Sloc);
18627 -- Update the Comes_From_Source and Sloc attributes of node or entity N
18629 procedure Update_First_Real_Statement
18630 (Old_HSS : Node_Id;
18631 New_HSS : Node_Id);
18632 pragma Inline (Update_First_Real_Statement);
18633 -- Update semantic attribute First_Real_Statement of handled sequence of
18634 -- statements New_HSS based on handled sequence of statements Old_HSS.
18636 procedure Update_Named_Associations
18637 (Old_Call : Node_Id;
18638 New_Call : Node_Id);
18639 pragma Inline (Update_Named_Associations);
18640 -- Update semantic chain First/Next_Named_Association of call New_call
18641 -- based on call Old_Call.
18643 procedure Update_New_Entities (Entity_Map : Elist_Id);
18644 pragma Inline (Update_New_Entities);
18645 -- Update the semantic attributes of all new entities generated during
18646 -- Phase 1 that do not appear in entity map Entity_Map. The format of
18647 -- the entity map must be as follows:
18649 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
18651 procedure Update_Pending_Itypes
18652 (Old_Assoc : Node_Id;
18653 New_Assoc : Node_Id);
18654 pragma Inline (Update_Pending_Itypes);
18655 -- Update semantic attribute Associated_Node_For_Itype to refer to node
18656 -- New_Assoc for all itypes whose associated node is Old_Assoc.
18658 procedure Update_Semantic_Fields (Id : Entity_Id);
18659 pragma Inline (Update_Semantic_Fields);
18660 -- Subsidiary to Update_New_Entities. Update semantic fields of entity
18661 -- or itype Id.
18663 procedure Visit_Any_Node (N : Node_Or_Entity_Id);
18664 pragma Inline (Visit_Any_Node);
18665 -- Visit entity of node N by invoking one of the following routines:
18667 -- Visit_Entity
18668 -- Visit_Itype
18669 -- Visit_Node
18671 procedure Visit_Elist (List : Elist_Id);
18672 -- Visit the elements of entity list List
18674 procedure Visit_Entity (Id : Entity_Id);
18675 -- Visit entity Id. This action may create a new entity of Id and save
18676 -- it in table NCT_New_Entities.
18678 procedure Visit_Field
18679 (Field : Union_Id;
18680 Par_Nod : Node_Id := Empty;
18681 Semantic : Boolean := False);
18682 -- Visit field Field by invoking one of the following routines:
18684 -- Visit_Elist
18685 -- Visit_Entity
18686 -- Visit_Itype
18687 -- Visit_List
18688 -- Visit_Node
18690 -- If the field is not an entity list, entity, itype, syntactic list,
18691 -- or node, then the field is not visited. The routine always visits
18692 -- valid syntactic fields. Par_Nod is the expected parent of the
18693 -- syntactic field. Flag Semantic should be set when the input is a
18694 -- semantic field.
18696 procedure Visit_Itype (Itype : Entity_Id);
18697 -- Visit itype Itype. This action may create a new entity for Itype and
18698 -- save it in table NCT_New_Entities. In addition, the routine may map
18699 -- the associated node of Itype to the new itype in NCT_Pending_Itypes.
18701 procedure Visit_List (List : List_Id);
18702 -- Visit the elements of syntactic list List
18704 procedure Visit_Node (N : Node_Id);
18705 -- Visit node N
18707 procedure Visit_Semantic_Fields (Id : Entity_Id);
18708 pragma Inline (Visit_Semantic_Fields);
18709 -- Subsidiary to Visit_Entity and Visit_Itype. Visit common semantic
18710 -- fields of entity or itype Id.
18712 --------------------
18713 -- Add_New_Entity --
18714 --------------------
18716 procedure Add_New_Entity (Old_Id : Entity_Id; New_Id : Entity_Id) is
18717 begin
18718 pragma Assert (Present (Old_Id));
18719 pragma Assert (Present (New_Id));
18720 pragma Assert (Nkind (Old_Id) in N_Entity);
18721 pragma Assert (Nkind (New_Id) in N_Entity);
18723 NCT_Tables_In_Use := True;
18725 -- Sanity check the NCT_New_Entities table. No previous mapping with
18726 -- key Old_Id should exist.
18728 pragma Assert (No (NCT_New_Entities.Get (Old_Id)));
18730 -- Establish the mapping
18732 -- Old_Id -> New_Id
18734 NCT_New_Entities.Set (Old_Id, New_Id);
18735 end Add_New_Entity;
18737 -----------------------
18738 -- Add_Pending_Itype --
18739 -----------------------
18741 procedure Add_Pending_Itype (Assoc_Nod : Node_Id; Itype : Entity_Id) is
18742 Itypes : Elist_Id;
18744 begin
18745 pragma Assert (Present (Assoc_Nod));
18746 pragma Assert (Present (Itype));
18747 pragma Assert (Nkind (Itype) in N_Entity);
18748 pragma Assert (Is_Itype (Itype));
18750 NCT_Tables_In_Use := True;
18752 -- It is not possible to sanity check the NCT_Pendint_Itypes table
18753 -- directly because a single node may act as the associated node for
18754 -- multiple itypes.
18756 Itypes := NCT_Pending_Itypes.Get (Assoc_Nod);
18758 if No (Itypes) then
18759 Itypes := New_Elmt_List;
18760 NCT_Pending_Itypes.Set (Assoc_Nod, Itypes);
18761 end if;
18763 -- Establish the mapping
18765 -- Assoc_Nod -> (Itype, ...)
18767 -- Avoid inserting the same itype multiple times. This involves a
18768 -- linear search, however the set of itypes with the same associated
18769 -- node is very small.
18771 Append_Unique_Elmt (Itype, Itypes);
18772 end Add_Pending_Itype;
18774 ----------------------
18775 -- Build_NCT_Tables --
18776 ----------------------
18778 procedure Build_NCT_Tables (Entity_Map : Elist_Id) is
18779 Elmt : Elmt_Id;
18780 Old_Id : Entity_Id;
18781 New_Id : Entity_Id;
18783 begin
18784 -- Nothing to do when there is no entity map
18786 if No (Entity_Map) then
18787 return;
18788 end if;
18790 Elmt := First_Elmt (Entity_Map);
18791 while Present (Elmt) loop
18793 -- Extract the (Old_Id, New_Id) pair from the entity map
18795 Old_Id := Node (Elmt);
18796 Next_Elmt (Elmt);
18798 New_Id := Node (Elmt);
18799 Next_Elmt (Elmt);
18801 -- Establish the following mapping within table NCT_New_Entities
18803 -- Old_Id -> New_Id
18805 Add_New_Entity (Old_Id, New_Id);
18807 -- Establish the following mapping within table NCT_Pending_Itypes
18808 -- when the new entity is an itype.
18810 -- Assoc_Nod -> (New_Id, ...)
18812 -- IMPORTANT: the associated node is that of the old itype because
18813 -- the node will be replicated in Phase 2.
18815 if Is_Itype (Old_Id) then
18816 Add_Pending_Itype
18817 (Assoc_Nod => Associated_Node_For_Itype (Old_Id),
18818 Itype => New_Id);
18819 end if;
18820 end loop;
18821 end Build_NCT_Tables;
18823 ------------------------------------
18824 -- Copy_Any_Node_With_Replacement --
18825 ------------------------------------
18827 function Copy_Any_Node_With_Replacement
18828 (N : Node_Or_Entity_Id) return Node_Or_Entity_Id
18830 begin
18831 if Nkind (N) in N_Entity then
18832 return Corresponding_Entity (N);
18833 else
18834 return Copy_Node_With_Replacement (N);
18835 end if;
18836 end Copy_Any_Node_With_Replacement;
18838 ---------------------------------
18839 -- Copy_Elist_With_Replacement --
18840 ---------------------------------
18842 function Copy_Elist_With_Replacement (List : Elist_Id) return Elist_Id is
18843 Elmt : Elmt_Id;
18844 Result : Elist_Id;
18846 begin
18847 -- Copy the contents of the old list. Note that the list itself may
18848 -- be empty, in which case the routine returns a new empty list. This
18849 -- avoids sharing lists between subtrees. The element of an entity
18850 -- list could be an entity or a node, hence the invocation of routine
18851 -- Copy_Any_Node_With_Replacement.
18853 if Present (List) then
18854 Result := New_Elmt_List;
18856 Elmt := First_Elmt (List);
18857 while Present (Elmt) loop
18858 Append_Elmt
18859 (Copy_Any_Node_With_Replacement (Node (Elmt)), Result);
18861 Next_Elmt (Elmt);
18862 end loop;
18864 -- Otherwise the list does not exist
18866 else
18867 Result := No_Elist;
18868 end if;
18870 return Result;
18871 end Copy_Elist_With_Replacement;
18873 ---------------------------------
18874 -- Copy_Field_With_Replacement --
18875 ---------------------------------
18877 function Copy_Field_With_Replacement
18878 (Field : Union_Id;
18879 Old_Par : Node_Id := Empty;
18880 New_Par : Node_Id := Empty;
18881 Semantic : Boolean := False) return Union_Id
18883 begin
18884 -- The field is empty
18886 if Field = Union_Id (Empty) then
18887 return Field;
18889 -- The field is an entity/itype/node
18891 elsif Field in Node_Range then
18892 declare
18893 Old_N : constant Node_Id := Node_Id (Field);
18894 Syntactic : constant Boolean := Parent (Old_N) = Old_Par;
18896 New_N : Node_Id;
18898 begin
18899 -- The field is an entity/itype
18901 if Nkind (Old_N) in N_Entity then
18903 -- An entity/itype is always replicated
18905 New_N := Corresponding_Entity (Old_N);
18907 -- Update the parent pointer when the entity is a syntactic
18908 -- field. Note that itypes do not have parent pointers.
18910 if Syntactic and then New_N /= Old_N then
18911 Set_Parent (New_N, New_Par);
18912 end if;
18914 -- The field is a node
18916 else
18917 -- A node is replicated when it is either a syntactic field
18918 -- or when the caller treats it as a semantic attribute.
18920 if Syntactic or else Semantic then
18921 New_N := Copy_Node_With_Replacement (Old_N);
18923 -- Update the parent pointer when the node is a syntactic
18924 -- field.
18926 if Syntactic and then New_N /= Old_N then
18927 Set_Parent (New_N, New_Par);
18928 end if;
18930 -- Otherwise the node is returned unchanged
18932 else
18933 New_N := Old_N;
18934 end if;
18935 end if;
18937 return Union_Id (New_N);
18938 end;
18940 -- The field is an entity list
18942 elsif Field in Elist_Range then
18943 return Union_Id (Copy_Elist_With_Replacement (Elist_Id (Field)));
18945 -- The field is a syntactic list
18947 elsif Field in List_Range then
18948 declare
18949 Old_List : constant List_Id := List_Id (Field);
18950 Syntactic : constant Boolean := Parent (Old_List) = Old_Par;
18952 New_List : List_Id;
18954 begin
18955 -- A list is replicated when it is either a syntactic field or
18956 -- when the caller treats it as a semantic attribute.
18958 if Syntactic or else Semantic then
18959 New_List := Copy_List_With_Replacement (Old_List);
18961 -- Update the parent pointer when the list is a syntactic
18962 -- field.
18964 if Syntactic and then New_List /= Old_List then
18965 Set_Parent (New_List, New_Par);
18966 end if;
18968 -- Otherwise the list is returned unchanged
18970 else
18971 New_List := Old_List;
18972 end if;
18974 return Union_Id (New_List);
18975 end;
18977 -- Otherwise the field denotes an attribute that does not need to be
18978 -- replicated (Chars, literals, etc).
18980 else
18981 return Field;
18982 end if;
18983 end Copy_Field_With_Replacement;
18985 --------------------------------
18986 -- Copy_List_With_Replacement --
18987 --------------------------------
18989 function Copy_List_With_Replacement (List : List_Id) return List_Id is
18990 Elmt : Node_Id;
18991 Result : List_Id;
18993 begin
18994 -- Copy the contents of the old list. Note that the list itself may
18995 -- be empty, in which case the routine returns a new empty list. This
18996 -- avoids sharing lists between subtrees. The element of a syntactic
18997 -- list is always a node, never an entity or itype, hence the call to
18998 -- routine Copy_Node_With_Replacement.
19000 if Present (List) then
19001 Result := New_List;
19003 Elmt := First (List);
19004 while Present (Elmt) loop
19005 Append (Copy_Node_With_Replacement (Elmt), Result);
19007 Next (Elmt);
19008 end loop;
19010 -- Otherwise the list does not exist
19012 else
19013 Result := No_List;
19014 end if;
19016 return Result;
19017 end Copy_List_With_Replacement;
19019 --------------------------------
19020 -- Copy_Node_With_Replacement --
19021 --------------------------------
19023 function Copy_Node_With_Replacement (N : Node_Id) return Node_Id is
19024 Result : Node_Id;
19026 begin
19027 -- Assume that the node must be returned unchanged
19029 Result := N;
19031 if N > Empty_Or_Error then
19032 pragma Assert (Nkind (N) not in N_Entity);
19034 Result := New_Copy (N);
19036 Set_Field1 (Result,
19037 Copy_Field_With_Replacement
19038 (Field => Field1 (Result),
19039 Old_Par => N,
19040 New_Par => Result));
19042 Set_Field2 (Result,
19043 Copy_Field_With_Replacement
19044 (Field => Field2 (Result),
19045 Old_Par => N,
19046 New_Par => Result));
19048 Set_Field3 (Result,
19049 Copy_Field_With_Replacement
19050 (Field => Field3 (Result),
19051 Old_Par => N,
19052 New_Par => Result));
19054 Set_Field4 (Result,
19055 Copy_Field_With_Replacement
19056 (Field => Field4 (Result),
19057 Old_Par => N,
19058 New_Par => Result));
19060 Set_Field5 (Result,
19061 Copy_Field_With_Replacement
19062 (Field => Field5 (Result),
19063 Old_Par => N,
19064 New_Par => Result));
19066 -- Update the Comes_From_Source and Sloc attributes of the node
19067 -- in case the caller has supplied new values.
19069 Update_CFS_Sloc (Result);
19071 -- Update the Associated_Node_For_Itype attribute of all itypes
19072 -- created during Phase 1 whose associated node is N. As a result
19073 -- the Associated_Node_For_Itype refers to the replicated node.
19074 -- No action needs to be taken when the Associated_Node_For_Itype
19075 -- refers to an entity because this was already handled during
19076 -- Phase 1, in Visit_Itype.
19078 Update_Pending_Itypes
19079 (Old_Assoc => N,
19080 New_Assoc => Result);
19082 -- Update the First/Next_Named_Association chain for a replicated
19083 -- call.
19085 if Nkind_In (N, N_Entry_Call_Statement,
19086 N_Function_Call,
19087 N_Procedure_Call_Statement)
19088 then
19089 Update_Named_Associations
19090 (Old_Call => N,
19091 New_Call => Result);
19093 -- Update the Renamed_Object attribute of a replicated object
19094 -- declaration.
19096 elsif Nkind (N) = N_Object_Renaming_Declaration then
19097 Set_Renamed_Object (Defining_Entity (Result), Name (Result));
19099 -- Update the First_Real_Statement attribute of a replicated
19100 -- handled sequence of statements.
19102 elsif Nkind (N) = N_Handled_Sequence_Of_Statements then
19103 Update_First_Real_Statement
19104 (Old_HSS => N,
19105 New_HSS => Result);
19106 end if;
19107 end if;
19109 return Result;
19110 end Copy_Node_With_Replacement;
19112 --------------------------
19113 -- Corresponding_Entity --
19114 --------------------------
19116 function Corresponding_Entity (Id : Entity_Id) return Entity_Id is
19117 New_Id : Entity_Id;
19118 Result : Entity_Id;
19120 begin
19121 -- Assume that the entity must be returned unchanged
19123 Result := Id;
19125 if Id > Empty_Or_Error then
19126 pragma Assert (Nkind (Id) in N_Entity);
19128 -- Determine whether the entity has a corresponding new entity
19129 -- generated during Phase 1 and if it does, use it.
19131 if NCT_Tables_In_Use then
19132 New_Id := NCT_New_Entities.Get (Id);
19134 if Present (New_Id) then
19135 Result := New_Id;
19136 end if;
19137 end if;
19138 end if;
19140 return Result;
19141 end Corresponding_Entity;
19143 -------------------
19144 -- In_Entity_Map --
19145 -------------------
19147 function In_Entity_Map
19148 (Id : Entity_Id;
19149 Entity_Map : Elist_Id) return Boolean
19151 Elmt : Elmt_Id;
19152 Old_Id : Entity_Id;
19154 begin
19155 -- The entity map contains pairs (Old_Id, New_Id). The advancement
19156 -- step always skips the New_Id portion of the pair.
19158 if Present (Entity_Map) then
19159 Elmt := First_Elmt (Entity_Map);
19160 while Present (Elmt) loop
19161 Old_Id := Node (Elmt);
19163 if Old_Id = Id then
19164 return True;
19165 end if;
19167 Next_Elmt (Elmt);
19168 Next_Elmt (Elmt);
19169 end loop;
19170 end if;
19172 return False;
19173 end In_Entity_Map;
19175 ---------------------
19176 -- Update_CFS_Sloc --
19177 ---------------------
19179 procedure Update_CFS_Sloc (N : Node_Or_Entity_Id) is
19180 begin
19181 -- A new source location defaults the Comes_From_Source attribute
19183 if New_Sloc /= No_Location then
19184 Set_Comes_From_Source (N, Default_Node.Comes_From_Source);
19185 Set_Sloc (N, New_Sloc);
19186 end if;
19187 end Update_CFS_Sloc;
19189 ---------------------------------
19190 -- Update_First_Real_Statement --
19191 ---------------------------------
19193 procedure Update_First_Real_Statement
19194 (Old_HSS : Node_Id;
19195 New_HSS : Node_Id)
19197 Old_First_Stmt : constant Node_Id := First_Real_Statement (Old_HSS);
19199 New_Stmt : Node_Id;
19200 Old_Stmt : Node_Id;
19202 begin
19203 -- Recreate the First_Real_Statement attribute of a handled sequence
19204 -- of statements by traversing the statement lists of both sequences
19205 -- in parallel.
19207 if Present (Old_First_Stmt) then
19208 New_Stmt := First (Statements (New_HSS));
19209 Old_Stmt := First (Statements (Old_HSS));
19210 while Present (Old_Stmt) and then Old_Stmt /= Old_First_Stmt loop
19211 Next (New_Stmt);
19212 Next (Old_Stmt);
19213 end loop;
19215 pragma Assert (Present (New_Stmt));
19216 pragma Assert (Present (Old_Stmt));
19218 Set_First_Real_Statement (New_HSS, New_Stmt);
19219 end if;
19220 end Update_First_Real_Statement;
19222 -------------------------------
19223 -- Update_Named_Associations --
19224 -------------------------------
19226 procedure Update_Named_Associations
19227 (Old_Call : Node_Id;
19228 New_Call : Node_Id)
19230 New_Act : Node_Id;
19231 New_Next : Node_Id;
19232 Old_Act : Node_Id;
19233 Old_Next : Node_Id;
19235 begin
19236 -- Recreate the First/Next_Named_Actual chain of a call by traversing
19237 -- the chains of both the old and new calls in parallel.
19239 New_Act := First (Parameter_Associations (New_Call));
19240 Old_Act := First (Parameter_Associations (Old_Call));
19241 while Present (Old_Act) loop
19242 if Nkind (Old_Act) = N_Parameter_Association
19243 and then Present (Next_Named_Actual (Old_Act))
19244 then
19245 if First_Named_Actual (Old_Call) =
19246 Explicit_Actual_Parameter (Old_Act)
19247 then
19248 Set_First_Named_Actual (New_Call,
19249 Explicit_Actual_Parameter (New_Act));
19250 end if;
19252 -- Scan the actual parameter list to find the next suitable
19253 -- named actual. Note that the list may be out of order.
19255 New_Next := First (Parameter_Associations (New_Call));
19256 Old_Next := First (Parameter_Associations (Old_Call));
19257 while Nkind (Old_Next) /= N_Parameter_Association
19258 or else Explicit_Actual_Parameter (Old_Next) /=
19259 Next_Named_Actual (Old_Act)
19260 loop
19261 Next (New_Next);
19262 Next (Old_Next);
19263 end loop;
19265 Set_Next_Named_Actual (New_Act,
19266 Explicit_Actual_Parameter (New_Next));
19267 end if;
19269 Next (New_Act);
19270 Next (Old_Act);
19271 end loop;
19272 end Update_Named_Associations;
19274 -------------------------
19275 -- Update_New_Entities --
19276 -------------------------
19278 procedure Update_New_Entities (Entity_Map : Elist_Id) is
19279 New_Id : Entity_Id := Empty;
19280 Old_Id : Entity_Id := Empty;
19282 begin
19283 if NCT_Tables_In_Use then
19284 NCT_New_Entities.Get_First (Old_Id, New_Id);
19286 -- Update the semantic fields of all new entities created during
19287 -- Phase 1 which were not supplied via an entity map.
19288 -- ??? Is there a better way of distinguishing those?
19290 while Present (Old_Id) and then Present (New_Id) loop
19291 if not (Present (Entity_Map)
19292 and then In_Entity_Map (Old_Id, Entity_Map))
19293 then
19294 Update_Semantic_Fields (New_Id);
19295 end if;
19297 NCT_New_Entities.Get_Next (Old_Id, New_Id);
19298 end loop;
19299 end if;
19300 end Update_New_Entities;
19302 ---------------------------
19303 -- Update_Pending_Itypes --
19304 ---------------------------
19306 procedure Update_Pending_Itypes
19307 (Old_Assoc : Node_Id;
19308 New_Assoc : Node_Id)
19310 Item : Elmt_Id;
19311 Itypes : Elist_Id;
19313 begin
19314 if NCT_Tables_In_Use then
19315 Itypes := NCT_Pending_Itypes.Get (Old_Assoc);
19317 -- Update the Associated_Node_For_Itype attribute for all itypes
19318 -- which originally refer to Old_Assoc to designate New_Assoc.
19320 if Present (Itypes) then
19321 Item := First_Elmt (Itypes);
19322 while Present (Item) loop
19323 Set_Associated_Node_For_Itype (Node (Item), New_Assoc);
19325 Next_Elmt (Item);
19326 end loop;
19327 end if;
19328 end if;
19329 end Update_Pending_Itypes;
19331 ----------------------------
19332 -- Update_Semantic_Fields --
19333 ----------------------------
19335 procedure Update_Semantic_Fields (Id : Entity_Id) is
19336 begin
19337 -- Discriminant_Constraint
19339 if Has_Discriminants (Base_Type (Id)) then
19340 Set_Discriminant_Constraint (Id, Elist_Id (
19341 Copy_Field_With_Replacement
19342 (Field => Union_Id (Discriminant_Constraint (Id)),
19343 Semantic => True)));
19344 end if;
19346 -- Etype
19348 Set_Etype (Id, Node_Id (
19349 Copy_Field_With_Replacement
19350 (Field => Union_Id (Etype (Id)),
19351 Semantic => True)));
19353 -- First_Index
19354 -- Packed_Array_Impl_Type
19356 if Is_Array_Type (Id) then
19357 if Present (First_Index (Id)) then
19358 Set_First_Index (Id, First (List_Id (
19359 Copy_Field_With_Replacement
19360 (Field => Union_Id (List_Containing (First_Index (Id))),
19361 Semantic => True))));
19362 end if;
19364 if Is_Packed (Id) then
19365 Set_Packed_Array_Impl_Type (Id, Node_Id (
19366 Copy_Field_With_Replacement
19367 (Field => Union_Id (Packed_Array_Impl_Type (Id)),
19368 Semantic => True)));
19369 end if;
19370 end if;
19372 -- Next_Entity
19374 Set_Next_Entity (Id, Node_Id (
19375 Copy_Field_With_Replacement
19376 (Field => Union_Id (Next_Entity (Id)),
19377 Semantic => True)));
19379 -- Scalar_Range
19381 if Is_Discrete_Type (Id) then
19382 Set_Scalar_Range (Id, Node_Id (
19383 Copy_Field_With_Replacement
19384 (Field => Union_Id (Scalar_Range (Id)),
19385 Semantic => True)));
19386 end if;
19388 -- Scope
19390 -- Update the scope when the caller specified an explicit one
19392 if Present (New_Scope) then
19393 Set_Scope (Id, New_Scope);
19394 else
19395 Set_Scope (Id, Node_Id (
19396 Copy_Field_With_Replacement
19397 (Field => Union_Id (Scope (Id)),
19398 Semantic => True)));
19399 end if;
19400 end Update_Semantic_Fields;
19402 --------------------
19403 -- Visit_Any_Node --
19404 --------------------
19406 procedure Visit_Any_Node (N : Node_Or_Entity_Id) is
19407 begin
19408 if Nkind (N) in N_Entity then
19409 if Is_Itype (N) then
19410 Visit_Itype (N);
19411 else
19412 Visit_Entity (N);
19413 end if;
19414 else
19415 Visit_Node (N);
19416 end if;
19417 end Visit_Any_Node;
19419 -----------------
19420 -- Visit_Elist --
19421 -----------------
19423 procedure Visit_Elist (List : Elist_Id) is
19424 Elmt : Elmt_Id;
19426 begin
19427 -- The element of an entity list could be an entity, itype, or a
19428 -- node, hence the call to Visit_Any_Node.
19430 if Present (List) then
19431 Elmt := First_Elmt (List);
19432 while Present (Elmt) loop
19433 Visit_Any_Node (Node (Elmt));
19435 Next_Elmt (Elmt);
19436 end loop;
19437 end if;
19438 end Visit_Elist;
19440 ------------------
19441 -- Visit_Entity --
19442 ------------------
19444 procedure Visit_Entity (Id : Entity_Id) is
19445 New_Id : Entity_Id;
19447 begin
19448 pragma Assert (Nkind (Id) in N_Entity);
19449 pragma Assert (not Is_Itype (Id));
19451 -- Nothing to do if the entity is not defined in the Actions list of
19452 -- an N_Expression_With_Actions node.
19454 if EWA_Level = 0 then
19455 return;
19457 -- Nothing to do if the entity is defined within a scoping construct
19458 -- of an N_Expression_With_Actions node.
19460 elsif EWA_Inner_Scope_Level > 0 then
19461 return;
19463 -- Nothing to do if the entity is not an object or a type. Relaxing
19464 -- this restriction leads to a performance penalty.
19466 elsif not Ekind_In (Id, E_Constant, E_Variable)
19467 and then not Is_Type (Id)
19468 then
19469 return;
19471 -- Nothing to do if the entity was already visited
19473 elsif NCT_Tables_In_Use
19474 and then Present (NCT_New_Entities.Get (Id))
19475 then
19476 return;
19478 -- Nothing to do if the declaration node of the entity is not within
19479 -- the subtree being replicated.
19481 elsif not In_Subtree
19482 (N => Declaration_Node (Id),
19483 Root => Source)
19484 then
19485 return;
19486 end if;
19488 -- Create a new entity by directly copying the old entity. This
19489 -- action causes all attributes of the old entity to be inherited.
19491 New_Id := New_Copy (Id);
19493 -- Create a new name for the new entity because the back end needs
19494 -- distinct names for debugging purposes.
19496 Set_Chars (New_Id, New_Internal_Name ('T'));
19498 -- Update the Comes_From_Source and Sloc attributes of the entity in
19499 -- case the caller has supplied new values.
19501 Update_CFS_Sloc (New_Id);
19503 -- Establish the following mapping within table NCT_New_Entities:
19505 -- Id -> New_Id
19507 Add_New_Entity (Id, New_Id);
19509 -- Deal with the semantic fields of entities. The fields are visited
19510 -- because they may mention entities which reside within the subtree
19511 -- being copied.
19513 Visit_Semantic_Fields (Id);
19514 end Visit_Entity;
19516 -----------------
19517 -- Visit_Field --
19518 -----------------
19520 procedure Visit_Field
19521 (Field : Union_Id;
19522 Par_Nod : Node_Id := Empty;
19523 Semantic : Boolean := False)
19525 begin
19526 -- The field is empty
19528 if Field = Union_Id (Empty) then
19529 return;
19531 -- The field is an entity/itype/node
19533 elsif Field in Node_Range then
19534 declare
19535 N : constant Node_Id := Node_Id (Field);
19537 begin
19538 -- The field is an entity/itype
19540 if Nkind (N) in N_Entity then
19542 -- Itypes are always visited
19544 if Is_Itype (N) then
19545 Visit_Itype (N);
19547 -- An entity is visited when it is either a syntactic field
19548 -- or when the caller treats it as a semantic attribute.
19550 elsif Parent (N) = Par_Nod or else Semantic then
19551 Visit_Entity (N);
19552 end if;
19554 -- The field is a node
19556 else
19557 -- A node is visited when it is either a syntactic field or
19558 -- when the caller treats it as a semantic attribute.
19560 if Parent (N) = Par_Nod or else Semantic then
19561 Visit_Node (N);
19562 end if;
19563 end if;
19564 end;
19566 -- The field is an entity list
19568 elsif Field in Elist_Range then
19569 Visit_Elist (Elist_Id (Field));
19571 -- The field is a syntax list
19573 elsif Field in List_Range then
19574 declare
19575 List : constant List_Id := List_Id (Field);
19577 begin
19578 -- A syntax list is visited when it is either a syntactic field
19579 -- or when the caller treats it as a semantic attribute.
19581 if Parent (List) = Par_Nod or else Semantic then
19582 Visit_List (List);
19583 end if;
19584 end;
19586 -- Otherwise the field denotes information which does not need to be
19587 -- visited (chars, literals, etc.).
19589 else
19590 null;
19591 end if;
19592 end Visit_Field;
19594 -----------------
19595 -- Visit_Itype --
19596 -----------------
19598 procedure Visit_Itype (Itype : Entity_Id) is
19599 New_Assoc : Node_Id;
19600 New_Itype : Entity_Id;
19601 Old_Assoc : Node_Id;
19603 begin
19604 pragma Assert (Nkind (Itype) in N_Entity);
19605 pragma Assert (Is_Itype (Itype));
19607 -- Itypes that describe the designated type of access to subprograms
19608 -- have the structure of subprogram declarations, with signatures,
19609 -- etc. Either we duplicate the signatures completely, or choose to
19610 -- share such itypes, which is fine because their elaboration will
19611 -- have no side effects.
19613 if Ekind (Itype) = E_Subprogram_Type then
19614 return;
19616 -- Nothing to do if the itype was already visited
19618 elsif NCT_Tables_In_Use
19619 and then Present (NCT_New_Entities.Get (Itype))
19620 then
19621 return;
19623 -- Nothing to do if the associated node of the itype is not within
19624 -- the subtree being replicated.
19626 elsif not In_Subtree
19627 (N => Associated_Node_For_Itype (Itype),
19628 Root => Source)
19629 then
19630 return;
19631 end if;
19633 -- Create a new itype by directly copying the old itype. This action
19634 -- causes all attributes of the old itype to be inherited.
19636 New_Itype := New_Copy (Itype);
19638 -- Create a new name for the new itype because the back end requires
19639 -- distinct names for debugging purposes.
19641 Set_Chars (New_Itype, New_Internal_Name ('T'));
19643 -- Update the Comes_From_Source and Sloc attributes of the itype in
19644 -- case the caller has supplied new values.
19646 Update_CFS_Sloc (New_Itype);
19648 -- Establish the following mapping within table NCT_New_Entities:
19650 -- Itype -> New_Itype
19652 Add_New_Entity (Itype, New_Itype);
19654 -- The new itype must be unfrozen because the resulting subtree may
19655 -- be inserted anywhere and cause an earlier or later freezing.
19657 if Present (Freeze_Node (New_Itype)) then
19658 Set_Freeze_Node (New_Itype, Empty);
19659 Set_Is_Frozen (New_Itype, False);
19660 end if;
19662 -- If a record subtype is simply copied, the entity list will be
19663 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
19664 -- ??? What does this do?
19666 if Ekind_In (Itype, E_Class_Wide_Subtype, E_Record_Subtype) then
19667 Set_Cloned_Subtype (New_Itype, Itype);
19668 end if;
19670 -- The associated node may denote an entity, in which case it may
19671 -- already have a new corresponding entity created during a prior
19672 -- call to Visit_Entity or Visit_Itype for the same subtree.
19674 -- Given
19675 -- Old_Assoc ---------> New_Assoc
19677 -- Created by Visit_Itype
19678 -- Itype -------------> New_Itype
19679 -- ANFI = Old_Assoc ANFI = Old_Assoc < must be updated
19681 -- In the example above, Old_Assoc is an arbitrary entity that was
19682 -- already visited for the same subtree and has a corresponding new
19683 -- entity New_Assoc. Old_Assoc was inherited by New_Itype by virtue
19684 -- of copying entities, however it must be updated to New_Assoc.
19686 Old_Assoc := Associated_Node_For_Itype (Itype);
19688 if Nkind (Old_Assoc) in N_Entity then
19689 if NCT_Tables_In_Use then
19690 New_Assoc := NCT_New_Entities.Get (Old_Assoc);
19692 if Present (New_Assoc) then
19693 Set_Associated_Node_For_Itype (New_Itype, New_Assoc);
19694 end if;
19695 end if;
19697 -- Otherwise the associated node denotes a node. Postpone the update
19698 -- until Phase 2 when the node is replicated. Establish the following
19699 -- mapping within table NCT_Pending_Itypes:
19701 -- Old_Assoc -> (New_Type, ...)
19703 else
19704 Add_Pending_Itype (Old_Assoc, New_Itype);
19705 end if;
19707 -- Deal with the semantic fields of itypes. The fields are visited
19708 -- because they may mention entities that reside within the subtree
19709 -- being copied.
19711 Visit_Semantic_Fields (Itype);
19712 end Visit_Itype;
19714 ----------------
19715 -- Visit_List --
19716 ----------------
19718 procedure Visit_List (List : List_Id) is
19719 Elmt : Node_Id;
19721 begin
19722 -- Note that the element of a syntactic list is always a node, never
19723 -- an entity or itype, hence the call to Visit_Node.
19725 if Present (List) then
19726 Elmt := First (List);
19727 while Present (Elmt) loop
19728 Visit_Node (Elmt);
19730 Next (Elmt);
19731 end loop;
19732 end if;
19733 end Visit_List;
19735 ----------------
19736 -- Visit_Node --
19737 ----------------
19739 procedure Visit_Node (N : Node_Or_Entity_Id) is
19740 begin
19741 pragma Assert (Nkind (N) not in N_Entity);
19743 if Nkind (N) = N_Expression_With_Actions then
19744 EWA_Level := EWA_Level + 1;
19746 elsif EWA_Level > 0
19747 and then Nkind_In (N, N_Block_Statement,
19748 N_Subprogram_Body,
19749 N_Subprogram_Declaration)
19750 then
19751 EWA_Inner_Scope_Level := EWA_Inner_Scope_Level + 1;
19752 end if;
19754 Visit_Field
19755 (Field => Field1 (N),
19756 Par_Nod => N);
19758 Visit_Field
19759 (Field => Field2 (N),
19760 Par_Nod => N);
19762 Visit_Field
19763 (Field => Field3 (N),
19764 Par_Nod => N);
19766 Visit_Field
19767 (Field => Field4 (N),
19768 Par_Nod => N);
19770 Visit_Field
19771 (Field => Field5 (N),
19772 Par_Nod => N);
19774 if EWA_Level > 0
19775 and then Nkind_In (N, N_Block_Statement,
19776 N_Subprogram_Body,
19777 N_Subprogram_Declaration)
19778 then
19779 EWA_Inner_Scope_Level := EWA_Inner_Scope_Level - 1;
19781 elsif Nkind (N) = N_Expression_With_Actions then
19782 EWA_Level := EWA_Level - 1;
19783 end if;
19784 end Visit_Node;
19786 ---------------------------
19787 -- Visit_Semantic_Fields --
19788 ---------------------------
19790 procedure Visit_Semantic_Fields (Id : Entity_Id) is
19791 begin
19792 pragma Assert (Nkind (Id) in N_Entity);
19794 -- Discriminant_Constraint
19796 if Has_Discriminants (Base_Type (Id)) then
19797 Visit_Field
19798 (Field => Union_Id (Discriminant_Constraint (Id)),
19799 Semantic => True);
19800 end if;
19802 -- Etype
19804 Visit_Field
19805 (Field => Union_Id (Etype (Id)),
19806 Semantic => True);
19808 -- First_Index
19809 -- Packed_Array_Impl_Type
19811 if Is_Array_Type (Id) then
19812 if Present (First_Index (Id)) then
19813 Visit_Field
19814 (Field => Union_Id (List_Containing (First_Index (Id))),
19815 Semantic => True);
19816 end if;
19818 if Is_Packed (Id) then
19819 Visit_Field
19820 (Field => Union_Id (Packed_Array_Impl_Type (Id)),
19821 Semantic => True);
19822 end if;
19823 end if;
19825 -- Scalar_Range
19827 if Is_Discrete_Type (Id) then
19828 Visit_Field
19829 (Field => Union_Id (Scalar_Range (Id)),
19830 Semantic => True);
19831 end if;
19832 end Visit_Semantic_Fields;
19834 -- Start of processing for New_Copy_Tree
19836 begin
19837 -- Routine New_Copy_Tree performs a deep copy of a subtree by creating
19838 -- shallow copies for each node within, and then updating the child and
19839 -- parent pointers accordingly. This process is straightforward, however
19840 -- the routine must deal with the following complications:
19842 -- * Entities defined within N_Expression_With_Actions nodes must be
19843 -- replicated rather than shared to avoid introducing two identical
19844 -- symbols within the same scope. Note that no other expression can
19845 -- currently define entities.
19847 -- do
19848 -- Source_Low : ...;
19849 -- Source_High : ...;
19851 -- <reference to Source_Low>
19852 -- <reference to Source_High>
19853 -- in ... end;
19855 -- New_Copy_Tree handles this case by first creating new entities
19856 -- and then updating all existing references to point to these new
19857 -- entities.
19859 -- do
19860 -- New_Low : ...;
19861 -- New_High : ...;
19863 -- <reference to New_Low>
19864 -- <reference to New_High>
19865 -- in ... end;
19867 -- * Itypes defined within the subtree must be replicated to avoid any
19868 -- dependencies on invalid or inaccessible data.
19870 -- subtype Source_Itype is ... range Source_Low .. Source_High;
19872 -- New_Copy_Tree handles this case by first creating a new itype in
19873 -- the same fashion as entities, and then updating various relevant
19874 -- constraints.
19876 -- subtype New_Itype is ... range New_Low .. New_High;
19878 -- * The Associated_Node_For_Itype field of itypes must be updated to
19879 -- reference the proper replicated entity or node.
19881 -- * Semantic fields of entities such as Etype and Scope must be
19882 -- updated to reference the proper replicated entities.
19884 -- * Semantic fields of nodes such as First_Real_Statement must be
19885 -- updated to reference the proper replicated nodes.
19887 -- To meet all these demands, routine New_Copy_Tree is split into two
19888 -- phases.
19890 -- Phase 1 traverses the tree in order to locate entities and itypes
19891 -- defined within the subtree. New entities are generated and saved in
19892 -- table NCT_New_Entities. The semantic fields of all new entities and
19893 -- itypes are then updated accordingly.
19895 -- Phase 2 traverses the tree in order to replicate each node. Various
19896 -- semantic fields of nodes and entities are updated accordingly.
19898 -- Preparatory phase. Clear the contents of tables NCT_New_Entities and
19899 -- NCT_Pending_Itypes in case a previous call to New_Copy_Tree left some
19900 -- data inside.
19902 if NCT_Tables_In_Use then
19903 NCT_Tables_In_Use := False;
19905 NCT_New_Entities.Reset;
19906 NCT_Pending_Itypes.Reset;
19907 end if;
19909 -- Populate tables NCT_New_Entities and NCT_Pending_Itypes with data
19910 -- supplied by a linear entity map. The tables offer faster access to
19911 -- the same data.
19913 Build_NCT_Tables (Map);
19915 -- Execute Phase 1. Traverse the subtree and generate new entities for
19916 -- the following cases:
19918 -- * An entity defined within an N_Expression_With_Actions node
19920 -- * An itype referenced within the subtree where the associated node
19921 -- is also in the subtree.
19923 -- All new entities are accessible via table NCT_New_Entities, which
19924 -- contains mappings of the form:
19926 -- Old_Entity -> New_Entity
19927 -- Old_Itype -> New_Itype
19929 -- In addition, the associated nodes of all new itypes are mapped in
19930 -- table NCT_Pending_Itypes:
19932 -- Assoc_Nod -> (New_Itype1, New_Itype2, .., New_ItypeN)
19934 Visit_Any_Node (Source);
19936 -- Update the semantic attributes of all new entities generated during
19937 -- Phase 1 before starting Phase 2. The updates could be performed in
19938 -- routine Corresponding_Entity, however this may cause the same entity
19939 -- to be updated multiple times, effectively generating useless nodes.
19940 -- Keeping the updates separates from Phase 2 ensures that only one set
19941 -- of attributes is generated for an entity at any one time.
19943 Update_New_Entities (Map);
19945 -- Execute Phase 2. Replicate the source subtree one node at a time.
19946 -- The following transformations take place:
19948 -- * References to entities and itypes are updated to refer to the
19949 -- new entities and itypes generated during Phase 1.
19951 -- * All Associated_Node_For_Itype attributes of itypes are updated
19952 -- to refer to the new replicated Associated_Node_For_Itype.
19954 return Copy_Node_With_Replacement (Source);
19955 end New_Copy_Tree;
19957 -------------------------
19958 -- New_External_Entity --
19959 -------------------------
19961 function New_External_Entity
19962 (Kind : Entity_Kind;
19963 Scope_Id : Entity_Id;
19964 Sloc_Value : Source_Ptr;
19965 Related_Id : Entity_Id;
19966 Suffix : Character;
19967 Suffix_Index : Nat := 0;
19968 Prefix : Character := ' ') return Entity_Id
19970 N : constant Entity_Id :=
19971 Make_Defining_Identifier (Sloc_Value,
19972 New_External_Name
19973 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
19975 begin
19976 Set_Ekind (N, Kind);
19977 Set_Is_Internal (N, True);
19978 Append_Entity (N, Scope_Id);
19979 Set_Public_Status (N);
19981 if Kind in Type_Kind then
19982 Init_Size_Align (N);
19983 end if;
19985 return N;
19986 end New_External_Entity;
19988 -------------------------
19989 -- New_Internal_Entity --
19990 -------------------------
19992 function New_Internal_Entity
19993 (Kind : Entity_Kind;
19994 Scope_Id : Entity_Id;
19995 Sloc_Value : Source_Ptr;
19996 Id_Char : Character) return Entity_Id
19998 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
20000 begin
20001 Set_Ekind (N, Kind);
20002 Set_Is_Internal (N, True);
20003 Append_Entity (N, Scope_Id);
20005 if Kind in Type_Kind then
20006 Init_Size_Align (N);
20007 end if;
20009 return N;
20010 end New_Internal_Entity;
20012 -----------------
20013 -- Next_Actual --
20014 -----------------
20016 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
20017 N : Node_Id;
20019 begin
20020 -- If we are pointing at a positional parameter, it is a member of a
20021 -- node list (the list of parameters), and the next parameter is the
20022 -- next node on the list, unless we hit a parameter association, then
20023 -- we shift to using the chain whose head is the First_Named_Actual in
20024 -- the parent, and then is threaded using the Next_Named_Actual of the
20025 -- Parameter_Association. All this fiddling is because the original node
20026 -- list is in the textual call order, and what we need is the
20027 -- declaration order.
20029 if Is_List_Member (Actual_Id) then
20030 N := Next (Actual_Id);
20032 if Nkind (N) = N_Parameter_Association then
20034 -- In case of a build-in-place call, the call will no longer be a
20035 -- call; it will have been rewritten.
20037 if Nkind_In (Parent (Actual_Id), N_Entry_Call_Statement,
20038 N_Function_Call,
20039 N_Procedure_Call_Statement)
20040 then
20041 return First_Named_Actual (Parent (Actual_Id));
20042 else
20043 return Empty;
20044 end if;
20045 else
20046 return N;
20047 end if;
20049 else
20050 return Next_Named_Actual (Parent (Actual_Id));
20051 end if;
20052 end Next_Actual;
20054 procedure Next_Actual (Actual_Id : in out Node_Id) is
20055 begin
20056 Actual_Id := Next_Actual (Actual_Id);
20057 end Next_Actual;
20059 -----------------
20060 -- Next_Global --
20061 -----------------
20063 function Next_Global (Node : Node_Id) return Node_Id is
20064 begin
20065 -- The global item may either be in a list, or by itself, in which case
20066 -- there is no next global item with the same mode.
20068 if Is_List_Member (Node) then
20069 return Next (Node);
20070 else
20071 return Empty;
20072 end if;
20073 end Next_Global;
20075 procedure Next_Global (Node : in out Node_Id) is
20076 begin
20077 Node := Next_Global (Node);
20078 end Next_Global;
20080 ----------------------------------
20081 -- New_Requires_Transient_Scope --
20082 ----------------------------------
20084 function New_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
20085 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean;
20086 -- This is called for untagged records and protected types, with
20087 -- nondefaulted discriminants. Returns True if the size of function
20088 -- results is known at the call site, False otherwise. Returns False
20089 -- if there is a variant part that depends on the discriminants of
20090 -- this type, or if there is an array constrained by the discriminants
20091 -- of this type. ???Currently, this is overly conservative (the array
20092 -- could be nested inside some other record that is constrained by
20093 -- nondiscriminants). That is, the recursive calls are too conservative.
20095 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean;
20096 -- Returns True if Typ is a nonlimited record with defaulted
20097 -- discriminants whose max size makes it unsuitable for allocating on
20098 -- the primary stack.
20100 ------------------------------
20101 -- Caller_Known_Size_Record --
20102 ------------------------------
20104 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean is
20105 pragma Assert (Typ = Underlying_Type (Typ));
20107 begin
20108 if Has_Variant_Part (Typ) and then not Is_Definite_Subtype (Typ) then
20109 return False;
20110 end if;
20112 declare
20113 Comp : Entity_Id;
20115 begin
20116 Comp := First_Entity (Typ);
20117 while Present (Comp) loop
20119 -- Only look at E_Component entities. No need to look at
20120 -- E_Discriminant entities, and we must ignore internal
20121 -- subtypes generated for constrained components.
20123 if Ekind (Comp) = E_Component then
20124 declare
20125 Comp_Type : constant Entity_Id :=
20126 Underlying_Type (Etype (Comp));
20128 begin
20129 if Is_Record_Type (Comp_Type)
20130 or else
20131 Is_Protected_Type (Comp_Type)
20132 then
20133 if not Caller_Known_Size_Record (Comp_Type) then
20134 return False;
20135 end if;
20137 elsif Is_Array_Type (Comp_Type) then
20138 if Size_Depends_On_Discriminant (Comp_Type) then
20139 return False;
20140 end if;
20141 end if;
20142 end;
20143 end if;
20145 Next_Entity (Comp);
20146 end loop;
20147 end;
20149 return True;
20150 end Caller_Known_Size_Record;
20152 ------------------------------
20153 -- Large_Max_Size_Mutable --
20154 ------------------------------
20156 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean is
20157 pragma Assert (Typ = Underlying_Type (Typ));
20159 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean;
20160 -- Returns true if the discrete type T has a large range
20162 ----------------------------
20163 -- Is_Large_Discrete_Type --
20164 ----------------------------
20166 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean is
20167 Threshold : constant Int := 16;
20168 -- Arbitrary threshold above which we consider it "large". We want
20169 -- a fairly large threshold, because these large types really
20170 -- shouldn't have default discriminants in the first place, in
20171 -- most cases.
20173 begin
20174 return UI_To_Int (RM_Size (T)) > Threshold;
20175 end Is_Large_Discrete_Type;
20177 -- Start of processing for Large_Max_Size_Mutable
20179 begin
20180 if Is_Record_Type (Typ)
20181 and then not Is_Limited_View (Typ)
20182 and then Has_Defaulted_Discriminants (Typ)
20183 then
20184 -- Loop through the components, looking for an array whose upper
20185 -- bound(s) depends on discriminants, where both the subtype of
20186 -- the discriminant and the index subtype are too large.
20188 declare
20189 Comp : Entity_Id;
20191 begin
20192 Comp := First_Entity (Typ);
20193 while Present (Comp) loop
20194 if Ekind (Comp) = E_Component then
20195 declare
20196 Comp_Type : constant Entity_Id :=
20197 Underlying_Type (Etype (Comp));
20199 Hi : Node_Id;
20200 Indx : Node_Id;
20201 Ityp : Entity_Id;
20203 begin
20204 if Is_Array_Type (Comp_Type) then
20205 Indx := First_Index (Comp_Type);
20207 while Present (Indx) loop
20208 Ityp := Etype (Indx);
20209 Hi := Type_High_Bound (Ityp);
20211 if Nkind (Hi) = N_Identifier
20212 and then Ekind (Entity (Hi)) = E_Discriminant
20213 and then Is_Large_Discrete_Type (Ityp)
20214 and then Is_Large_Discrete_Type
20215 (Etype (Entity (Hi)))
20216 then
20217 return True;
20218 end if;
20220 Next_Index (Indx);
20221 end loop;
20222 end if;
20223 end;
20224 end if;
20226 Next_Entity (Comp);
20227 end loop;
20228 end;
20229 end if;
20231 return False;
20232 end Large_Max_Size_Mutable;
20234 -- Local declarations
20236 Typ : constant Entity_Id := Underlying_Type (Id);
20238 -- Start of processing for New_Requires_Transient_Scope
20240 begin
20241 -- This is a private type which is not completed yet. This can only
20242 -- happen in a default expression (of a formal parameter or of a
20243 -- record component). Do not expand transient scope in this case.
20245 if No (Typ) then
20246 return False;
20248 -- Do not expand transient scope for non-existent procedure return or
20249 -- string literal types.
20251 elsif Typ = Standard_Void_Type
20252 or else Ekind (Typ) = E_String_Literal_Subtype
20253 then
20254 return False;
20256 -- If Typ is a generic formal incomplete type, then we want to look at
20257 -- the actual type.
20259 elsif Ekind (Typ) = E_Record_Subtype
20260 and then Present (Cloned_Subtype (Typ))
20261 then
20262 return New_Requires_Transient_Scope (Cloned_Subtype (Typ));
20264 -- Functions returning specific tagged types may dispatch on result, so
20265 -- their returned value is allocated on the secondary stack, even in the
20266 -- definite case. We must treat nondispatching functions the same way,
20267 -- because access-to-function types can point at both, so the calling
20268 -- conventions must be compatible. Is_Tagged_Type includes controlled
20269 -- types and class-wide types. Controlled type temporaries need
20270 -- finalization.
20272 -- ???It's not clear why we need to return noncontrolled types with
20273 -- controlled components on the secondary stack.
20275 elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
20276 return True;
20278 -- Untagged definite subtypes are known size. This includes all
20279 -- elementary [sub]types. Tasks are known size even if they have
20280 -- discriminants. So we return False here, with one exception:
20281 -- For a type like:
20282 -- type T (Last : Natural := 0) is
20283 -- X : String (1 .. Last);
20284 -- end record;
20285 -- we return True. That's because for "P(F(...));", where F returns T,
20286 -- we don't know the size of the result at the call site, so if we
20287 -- allocated it on the primary stack, we would have to allocate the
20288 -- maximum size, which is way too big.
20290 elsif Is_Definite_Subtype (Typ) or else Is_Task_Type (Typ) then
20291 return Large_Max_Size_Mutable (Typ);
20293 -- Indefinite (discriminated) untagged record or protected type
20295 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
20296 return not Caller_Known_Size_Record (Typ);
20298 -- Unconstrained array
20300 else
20301 pragma Assert (Is_Array_Type (Typ) and not Is_Definite_Subtype (Typ));
20302 return True;
20303 end if;
20304 end New_Requires_Transient_Scope;
20306 --------------------------
20307 -- No_Heap_Finalization --
20308 --------------------------
20310 function No_Heap_Finalization (Typ : Entity_Id) return Boolean is
20311 begin
20312 if Ekind_In (Typ, E_Access_Type, E_General_Access_Type)
20313 and then Is_Library_Level_Entity (Typ)
20314 then
20315 -- A global No_Heap_Finalization pragma applies to all library-level
20316 -- named access-to-object types.
20318 if Present (No_Heap_Finalization_Pragma) then
20319 return True;
20321 -- The library-level named access-to-object type itself is subject to
20322 -- pragma No_Heap_Finalization.
20324 elsif Present (Get_Pragma (Typ, Pragma_No_Heap_Finalization)) then
20325 return True;
20326 end if;
20327 end if;
20329 return False;
20330 end No_Heap_Finalization;
20332 -----------------------
20333 -- Normalize_Actuals --
20334 -----------------------
20336 -- Chain actuals according to formals of subprogram. If there are no named
20337 -- associations, the chain is simply the list of Parameter Associations,
20338 -- since the order is the same as the declaration order. If there are named
20339 -- associations, then the First_Named_Actual field in the N_Function_Call
20340 -- or N_Procedure_Call_Statement node points to the Parameter_Association
20341 -- node for the parameter that comes first in declaration order. The
20342 -- remaining named parameters are then chained in declaration order using
20343 -- Next_Named_Actual.
20345 -- This routine also verifies that the number of actuals is compatible with
20346 -- the number and default values of formals, but performs no type checking
20347 -- (type checking is done by the caller).
20349 -- If the matching succeeds, Success is set to True and the caller proceeds
20350 -- with type-checking. If the match is unsuccessful, then Success is set to
20351 -- False, and the caller attempts a different interpretation, if there is
20352 -- one.
20354 -- If the flag Report is on, the call is not overloaded, and a failure to
20355 -- match can be reported here, rather than in the caller.
20357 procedure Normalize_Actuals
20358 (N : Node_Id;
20359 S : Entity_Id;
20360 Report : Boolean;
20361 Success : out Boolean)
20363 Actuals : constant List_Id := Parameter_Associations (N);
20364 Actual : Node_Id := Empty;
20365 Formal : Entity_Id;
20366 Last : Node_Id := Empty;
20367 First_Named : Node_Id := Empty;
20368 Found : Boolean;
20370 Formals_To_Match : Integer := 0;
20371 Actuals_To_Match : Integer := 0;
20373 procedure Chain (A : Node_Id);
20374 -- Add named actual at the proper place in the list, using the
20375 -- Next_Named_Actual link.
20377 function Reporting return Boolean;
20378 -- Determines if an error is to be reported. To report an error, we
20379 -- need Report to be True, and also we do not report errors caused
20380 -- by calls to init procs that occur within other init procs. Such
20381 -- errors must always be cascaded errors, since if all the types are
20382 -- declared correctly, the compiler will certainly build decent calls.
20384 -----------
20385 -- Chain --
20386 -----------
20388 procedure Chain (A : Node_Id) is
20389 begin
20390 if No (Last) then
20392 -- Call node points to first actual in list
20394 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
20396 else
20397 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
20398 end if;
20400 Last := A;
20401 Set_Next_Named_Actual (Last, Empty);
20402 end Chain;
20404 ---------------
20405 -- Reporting --
20406 ---------------
20408 function Reporting return Boolean is
20409 begin
20410 if not Report then
20411 return False;
20413 elsif not Within_Init_Proc then
20414 return True;
20416 elsif Is_Init_Proc (Entity (Name (N))) then
20417 return False;
20419 else
20420 return True;
20421 end if;
20422 end Reporting;
20424 -- Start of processing for Normalize_Actuals
20426 begin
20427 if Is_Access_Type (S) then
20429 -- The name in the call is a function call that returns an access
20430 -- to subprogram. The designated type has the list of formals.
20432 Formal := First_Formal (Designated_Type (S));
20433 else
20434 Formal := First_Formal (S);
20435 end if;
20437 while Present (Formal) loop
20438 Formals_To_Match := Formals_To_Match + 1;
20439 Next_Formal (Formal);
20440 end loop;
20442 -- Find if there is a named association, and verify that no positional
20443 -- associations appear after named ones.
20445 if Present (Actuals) then
20446 Actual := First (Actuals);
20447 end if;
20449 while Present (Actual)
20450 and then Nkind (Actual) /= N_Parameter_Association
20451 loop
20452 Actuals_To_Match := Actuals_To_Match + 1;
20453 Next (Actual);
20454 end loop;
20456 if No (Actual) and Actuals_To_Match = Formals_To_Match then
20458 -- Most common case: positional notation, no defaults
20460 Success := True;
20461 return;
20463 elsif Actuals_To_Match > Formals_To_Match then
20465 -- Too many actuals: will not work
20467 if Reporting then
20468 if Is_Entity_Name (Name (N)) then
20469 Error_Msg_N ("too many arguments in call to&", Name (N));
20470 else
20471 Error_Msg_N ("too many arguments in call", N);
20472 end if;
20473 end if;
20475 Success := False;
20476 return;
20477 end if;
20479 First_Named := Actual;
20481 while Present (Actual) loop
20482 if Nkind (Actual) /= N_Parameter_Association then
20483 Error_Msg_N
20484 ("positional parameters not allowed after named ones", Actual);
20485 Success := False;
20486 return;
20488 else
20489 Actuals_To_Match := Actuals_To_Match + 1;
20490 end if;
20492 Next (Actual);
20493 end loop;
20495 if Present (Actuals) then
20496 Actual := First (Actuals);
20497 end if;
20499 Formal := First_Formal (S);
20500 while Present (Formal) loop
20502 -- Match the formals in order. If the corresponding actual is
20503 -- positional, nothing to do. Else scan the list of named actuals
20504 -- to find the one with the right name.
20506 if Present (Actual)
20507 and then Nkind (Actual) /= N_Parameter_Association
20508 then
20509 Next (Actual);
20510 Actuals_To_Match := Actuals_To_Match - 1;
20511 Formals_To_Match := Formals_To_Match - 1;
20513 else
20514 -- For named parameters, search the list of actuals to find
20515 -- one that matches the next formal name.
20517 Actual := First_Named;
20518 Found := False;
20519 while Present (Actual) loop
20520 if Chars (Selector_Name (Actual)) = Chars (Formal) then
20521 Found := True;
20522 Chain (Actual);
20523 Actuals_To_Match := Actuals_To_Match - 1;
20524 Formals_To_Match := Formals_To_Match - 1;
20525 exit;
20526 end if;
20528 Next (Actual);
20529 end loop;
20531 if not Found then
20532 if Ekind (Formal) /= E_In_Parameter
20533 or else No (Default_Value (Formal))
20534 then
20535 if Reporting then
20536 if (Comes_From_Source (S)
20537 or else Sloc (S) = Standard_Location)
20538 and then Is_Overloadable (S)
20539 then
20540 if No (Actuals)
20541 and then
20542 Nkind_In (Parent (N), N_Procedure_Call_Statement,
20543 N_Function_Call,
20544 N_Parameter_Association)
20545 and then Ekind (S) /= E_Function
20546 then
20547 Set_Etype (N, Etype (S));
20549 else
20550 Error_Msg_Name_1 := Chars (S);
20551 Error_Msg_Sloc := Sloc (S);
20552 Error_Msg_NE
20553 ("missing argument for parameter & "
20554 & "in call to % declared #", N, Formal);
20555 end if;
20557 elsif Is_Overloadable (S) then
20558 Error_Msg_Name_1 := Chars (S);
20560 -- Point to type derivation that generated the
20561 -- operation.
20563 Error_Msg_Sloc := Sloc (Parent (S));
20565 Error_Msg_NE
20566 ("missing argument for parameter & "
20567 & "in call to % (inherited) #", N, Formal);
20569 else
20570 Error_Msg_NE
20571 ("missing argument for parameter &", N, Formal);
20572 end if;
20573 end if;
20575 Success := False;
20576 return;
20578 else
20579 Formals_To_Match := Formals_To_Match - 1;
20580 end if;
20581 end if;
20582 end if;
20584 Next_Formal (Formal);
20585 end loop;
20587 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
20588 Success := True;
20589 return;
20591 else
20592 if Reporting then
20594 -- Find some superfluous named actual that did not get
20595 -- attached to the list of associations.
20597 Actual := First (Actuals);
20598 while Present (Actual) loop
20599 if Nkind (Actual) = N_Parameter_Association
20600 and then Actual /= Last
20601 and then No (Next_Named_Actual (Actual))
20602 then
20603 -- A validity check may introduce a copy of a call that
20604 -- includes an extra actual (for example for an unrelated
20605 -- accessibility check). Check that the extra actual matches
20606 -- some extra formal, which must exist already because
20607 -- subprogram must be frozen at this point.
20609 if Present (Extra_Formals (S))
20610 and then not Comes_From_Source (Actual)
20611 and then Nkind (Actual) = N_Parameter_Association
20612 and then Chars (Extra_Formals (S)) =
20613 Chars (Selector_Name (Actual))
20614 then
20615 null;
20616 else
20617 Error_Msg_N
20618 ("unmatched actual & in call", Selector_Name (Actual));
20619 exit;
20620 end if;
20621 end if;
20623 Next (Actual);
20624 end loop;
20625 end if;
20627 Success := False;
20628 return;
20629 end if;
20630 end Normalize_Actuals;
20632 --------------------------------
20633 -- Note_Possible_Modification --
20634 --------------------------------
20636 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
20637 Modification_Comes_From_Source : constant Boolean :=
20638 Comes_From_Source (Parent (N));
20640 Ent : Entity_Id;
20641 Exp : Node_Id;
20643 begin
20644 -- Loop to find referenced entity, if there is one
20646 Exp := N;
20647 loop
20648 Ent := Empty;
20650 if Is_Entity_Name (Exp) then
20651 Ent := Entity (Exp);
20653 -- If the entity is missing, it is an undeclared identifier,
20654 -- and there is nothing to annotate.
20656 if No (Ent) then
20657 return;
20658 end if;
20660 elsif Nkind (Exp) = N_Explicit_Dereference then
20661 declare
20662 P : constant Node_Id := Prefix (Exp);
20664 begin
20665 -- In formal verification mode, keep track of all reads and
20666 -- writes through explicit dereferences.
20668 if GNATprove_Mode then
20669 SPARK_Specific.Generate_Dereference (N, 'm');
20670 end if;
20672 if Nkind (P) = N_Selected_Component
20673 and then Present (Entry_Formal (Entity (Selector_Name (P))))
20674 then
20675 -- Case of a reference to an entry formal
20677 Ent := Entry_Formal (Entity (Selector_Name (P)));
20679 elsif Nkind (P) = N_Identifier
20680 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
20681 and then Present (Expression (Parent (Entity (P))))
20682 and then Nkind (Expression (Parent (Entity (P)))) =
20683 N_Reference
20684 then
20685 -- Case of a reference to a value on which side effects have
20686 -- been removed.
20688 Exp := Prefix (Expression (Parent (Entity (P))));
20689 goto Continue;
20691 else
20692 return;
20693 end if;
20694 end;
20696 elsif Nkind_In (Exp, N_Type_Conversion,
20697 N_Unchecked_Type_Conversion)
20698 then
20699 Exp := Expression (Exp);
20700 goto Continue;
20702 elsif Nkind_In (Exp, N_Slice,
20703 N_Indexed_Component,
20704 N_Selected_Component)
20705 then
20706 -- Special check, if the prefix is an access type, then return
20707 -- since we are modifying the thing pointed to, not the prefix.
20708 -- When we are expanding, most usually the prefix is replaced
20709 -- by an explicit dereference, and this test is not needed, but
20710 -- in some cases (notably -gnatc mode and generics) when we do
20711 -- not do full expansion, we need this special test.
20713 if Is_Access_Type (Etype (Prefix (Exp))) then
20714 return;
20716 -- Otherwise go to prefix and keep going
20718 else
20719 Exp := Prefix (Exp);
20720 goto Continue;
20721 end if;
20723 -- All other cases, not a modification
20725 else
20726 return;
20727 end if;
20729 -- Now look for entity being referenced
20731 if Present (Ent) then
20732 if Is_Object (Ent) then
20733 if Comes_From_Source (Exp)
20734 or else Modification_Comes_From_Source
20735 then
20736 -- Give warning if pragma unmodified is given and we are
20737 -- sure this is a modification.
20739 if Has_Pragma_Unmodified (Ent) and then Sure then
20741 -- Note that the entity may be present only as a result
20742 -- of pragma Unused.
20744 if Has_Pragma_Unused (Ent) then
20745 Error_Msg_NE ("??pragma Unused given for &!", N, Ent);
20746 else
20747 Error_Msg_NE
20748 ("??pragma Unmodified given for &!", N, Ent);
20749 end if;
20750 end if;
20752 Set_Never_Set_In_Source (Ent, False);
20753 end if;
20755 Set_Is_True_Constant (Ent, False);
20756 Set_Current_Value (Ent, Empty);
20757 Set_Is_Known_Null (Ent, False);
20759 if not Can_Never_Be_Null (Ent) then
20760 Set_Is_Known_Non_Null (Ent, False);
20761 end if;
20763 -- Follow renaming chain
20765 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
20766 and then Present (Renamed_Object (Ent))
20767 then
20768 Exp := Renamed_Object (Ent);
20770 -- If the entity is the loop variable in an iteration over
20771 -- a container, retrieve container expression to indicate
20772 -- possible modification.
20774 if Present (Related_Expression (Ent))
20775 and then Nkind (Parent (Related_Expression (Ent))) =
20776 N_Iterator_Specification
20777 then
20778 Exp := Original_Node (Related_Expression (Ent));
20779 end if;
20781 goto Continue;
20783 -- The expression may be the renaming of a subcomponent of an
20784 -- array or container. The assignment to the subcomponent is
20785 -- a modification of the container.
20787 elsif Comes_From_Source (Original_Node (Exp))
20788 and then Nkind_In (Original_Node (Exp), N_Selected_Component,
20789 N_Indexed_Component)
20790 then
20791 Exp := Prefix (Original_Node (Exp));
20792 goto Continue;
20793 end if;
20795 -- Generate a reference only if the assignment comes from
20796 -- source. This excludes, for example, calls to a dispatching
20797 -- assignment operation when the left-hand side is tagged. In
20798 -- GNATprove mode, we need those references also on generated
20799 -- code, as these are used to compute the local effects of
20800 -- subprograms.
20802 if Modification_Comes_From_Source or GNATprove_Mode then
20803 Generate_Reference (Ent, Exp, 'm');
20805 -- If the target of the assignment is the bound variable
20806 -- in an iterator, indicate that the corresponding array
20807 -- or container is also modified.
20809 if Ada_Version >= Ada_2012
20810 and then Nkind (Parent (Ent)) = N_Iterator_Specification
20811 then
20812 declare
20813 Domain : constant Node_Id := Name (Parent (Ent));
20815 begin
20816 -- TBD : in the full version of the construct, the
20817 -- domain of iteration can be given by an expression.
20819 if Is_Entity_Name (Domain) then
20820 Generate_Reference (Entity (Domain), Exp, 'm');
20821 Set_Is_True_Constant (Entity (Domain), False);
20822 Set_Never_Set_In_Source (Entity (Domain), False);
20823 end if;
20824 end;
20825 end if;
20826 end if;
20827 end if;
20829 Kill_Checks (Ent);
20831 -- If we are sure this is a modification from source, and we know
20832 -- this modifies a constant, then give an appropriate warning.
20834 if Sure
20835 and then Modification_Comes_From_Source
20836 and then Overlays_Constant (Ent)
20837 and then Address_Clause_Overlay_Warnings
20838 then
20839 declare
20840 Addr : constant Node_Id := Address_Clause (Ent);
20841 O_Ent : Entity_Id;
20842 Off : Boolean;
20844 begin
20845 Find_Overlaid_Entity (Addr, O_Ent, Off);
20847 Error_Msg_Sloc := Sloc (Addr);
20848 Error_Msg_NE
20849 ("??constant& may be modified via address clause#",
20850 N, O_Ent);
20851 end;
20852 end if;
20854 return;
20855 end if;
20857 <<Continue>>
20858 null;
20859 end loop;
20860 end Note_Possible_Modification;
20862 -----------------
20863 -- Null_Status --
20864 -----------------
20866 function Null_Status (N : Node_Id) return Null_Status_Kind is
20867 function Is_Null_Excluding_Def (Def : Node_Id) return Boolean;
20868 -- Determine whether definition Def carries a null exclusion
20870 function Null_Status_Of_Entity (Id : Entity_Id) return Null_Status_Kind;
20871 -- Determine the null status of arbitrary entity Id
20873 function Null_Status_Of_Type (Typ : Entity_Id) return Null_Status_Kind;
20874 -- Determine the null status of type Typ
20876 ---------------------------
20877 -- Is_Null_Excluding_Def --
20878 ---------------------------
20880 function Is_Null_Excluding_Def (Def : Node_Id) return Boolean is
20881 begin
20882 return
20883 Nkind_In (Def, N_Access_Definition,
20884 N_Access_Function_Definition,
20885 N_Access_Procedure_Definition,
20886 N_Access_To_Object_Definition,
20887 N_Component_Definition,
20888 N_Derived_Type_Definition)
20889 and then Null_Exclusion_Present (Def);
20890 end Is_Null_Excluding_Def;
20892 ---------------------------
20893 -- Null_Status_Of_Entity --
20894 ---------------------------
20896 function Null_Status_Of_Entity
20897 (Id : Entity_Id) return Null_Status_Kind
20899 Decl : constant Node_Id := Declaration_Node (Id);
20900 Def : Node_Id;
20902 begin
20903 -- The value of an imported or exported entity may be set externally
20904 -- regardless of a null exclusion. As a result, the value cannot be
20905 -- determined statically.
20907 if Is_Imported (Id) or else Is_Exported (Id) then
20908 return Unknown;
20910 elsif Nkind_In (Decl, N_Component_Declaration,
20911 N_Discriminant_Specification,
20912 N_Formal_Object_Declaration,
20913 N_Object_Declaration,
20914 N_Object_Renaming_Declaration,
20915 N_Parameter_Specification)
20916 then
20917 -- A component declaration yields a non-null value when either
20918 -- its component definition or access definition carries a null
20919 -- exclusion.
20921 if Nkind (Decl) = N_Component_Declaration then
20922 Def := Component_Definition (Decl);
20924 if Is_Null_Excluding_Def (Def) then
20925 return Is_Non_Null;
20926 end if;
20928 Def := Access_Definition (Def);
20930 if Present (Def) and then Is_Null_Excluding_Def (Def) then
20931 return Is_Non_Null;
20932 end if;
20934 -- A formal object declaration yields a non-null value if its
20935 -- access definition carries a null exclusion. If the object is
20936 -- default initialized, then the value depends on the expression.
20938 elsif Nkind (Decl) = N_Formal_Object_Declaration then
20939 Def := Access_Definition (Decl);
20941 if Present (Def) and then Is_Null_Excluding_Def (Def) then
20942 return Is_Non_Null;
20943 end if;
20945 -- A constant may yield a null or non-null value depending on its
20946 -- initialization expression.
20948 elsif Ekind (Id) = E_Constant then
20949 return Null_Status (Constant_Value (Id));
20951 -- The construct yields a non-null value when it has a null
20952 -- exclusion.
20954 elsif Null_Exclusion_Present (Decl) then
20955 return Is_Non_Null;
20957 -- An object renaming declaration yields a non-null value if its
20958 -- access definition carries a null exclusion. Otherwise the value
20959 -- depends on the renamed name.
20961 elsif Nkind (Decl) = N_Object_Renaming_Declaration then
20962 Def := Access_Definition (Decl);
20964 if Present (Def) and then Is_Null_Excluding_Def (Def) then
20965 return Is_Non_Null;
20967 else
20968 return Null_Status (Name (Decl));
20969 end if;
20970 end if;
20971 end if;
20973 -- At this point the declaration of the entity does not carry a null
20974 -- exclusion and lacks an initialization expression. Check the status
20975 -- of its type.
20977 return Null_Status_Of_Type (Etype (Id));
20978 end Null_Status_Of_Entity;
20980 -------------------------
20981 -- Null_Status_Of_Type --
20982 -------------------------
20984 function Null_Status_Of_Type (Typ : Entity_Id) return Null_Status_Kind is
20985 Curr : Entity_Id;
20986 Decl : Node_Id;
20988 begin
20989 -- Traverse the type chain looking for types with null exclusion
20991 Curr := Typ;
20992 while Present (Curr) and then Etype (Curr) /= Curr loop
20993 Decl := Parent (Curr);
20995 -- Guard against itypes which do not always have declarations. A
20996 -- type yields a non-null value if it carries a null exclusion.
20998 if Present (Decl) then
20999 if Nkind (Decl) = N_Full_Type_Declaration
21000 and then Is_Null_Excluding_Def (Type_Definition (Decl))
21001 then
21002 return Is_Non_Null;
21004 elsif Nkind (Decl) = N_Subtype_Declaration
21005 and then Null_Exclusion_Present (Decl)
21006 then
21007 return Is_Non_Null;
21008 end if;
21009 end if;
21011 Curr := Etype (Curr);
21012 end loop;
21014 -- The type chain does not contain any null excluding types
21016 return Unknown;
21017 end Null_Status_Of_Type;
21019 -- Start of processing for Null_Status
21021 begin
21022 -- An allocator always creates a non-null value
21024 if Nkind (N) = N_Allocator then
21025 return Is_Non_Null;
21027 -- Taking the 'Access of something yields a non-null value
21029 elsif Nkind (N) = N_Attribute_Reference
21030 and then Nam_In (Attribute_Name (N), Name_Access,
21031 Name_Unchecked_Access,
21032 Name_Unrestricted_Access)
21033 then
21034 return Is_Non_Null;
21036 -- "null" yields null
21038 elsif Nkind (N) = N_Null then
21039 return Is_Null;
21041 -- Check the status of the operand of a type conversion
21043 elsif Nkind (N) = N_Type_Conversion then
21044 return Null_Status (Expression (N));
21046 -- The input denotes a reference to an entity. Determine whether the
21047 -- entity or its type yields a null or non-null value.
21049 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
21050 return Null_Status_Of_Entity (Entity (N));
21051 end if;
21053 -- Otherwise it is not possible to determine the null status of the
21054 -- subexpression at compile time without resorting to simple flow
21055 -- analysis.
21057 return Unknown;
21058 end Null_Status;
21060 --------------------------------------
21061 -- Null_To_Null_Address_Convert_OK --
21062 --------------------------------------
21064 function Null_To_Null_Address_Convert_OK
21065 (N : Node_Id;
21066 Typ : Entity_Id := Empty) return Boolean
21068 begin
21069 if not Relaxed_RM_Semantics then
21070 return False;
21071 end if;
21073 if Nkind (N) = N_Null then
21074 return Present (Typ) and then Is_Descendant_Of_Address (Typ);
21076 elsif Nkind_In (N, N_Op_Eq, N_Op_Ge, N_Op_Gt, N_Op_Le, N_Op_Lt, N_Op_Ne)
21077 then
21078 declare
21079 L : constant Node_Id := Left_Opnd (N);
21080 R : constant Node_Id := Right_Opnd (N);
21082 begin
21083 -- We check the Etype of the complementary operand since the
21084 -- N_Null node is not decorated at this stage.
21086 return
21087 ((Nkind (L) = N_Null
21088 and then Is_Descendant_Of_Address (Etype (R)))
21089 or else
21090 (Nkind (R) = N_Null
21091 and then Is_Descendant_Of_Address (Etype (L))));
21092 end;
21093 end if;
21095 return False;
21096 end Null_To_Null_Address_Convert_OK;
21098 ---------------------------------
21099 -- Number_Of_Elements_In_Array --
21100 ---------------------------------
21102 function Number_Of_Elements_In_Array (T : Entity_Id) return Int is
21103 Indx : Node_Id;
21104 Typ : Entity_Id;
21105 Low : Node_Id;
21106 High : Node_Id;
21107 Num : Int := 1;
21109 begin
21110 pragma Assert (Is_Array_Type (T));
21112 Indx := First_Index (T);
21113 while Present (Indx) loop
21114 Typ := Underlying_Type (Etype (Indx));
21116 -- Never look at junk bounds of a generic type
21118 if Is_Generic_Type (Typ) then
21119 return 0;
21120 end if;
21122 -- Check the array bounds are known at compile time and return zero
21123 -- if they are not.
21125 Low := Type_Low_Bound (Typ);
21126 High := Type_High_Bound (Typ);
21128 if not Compile_Time_Known_Value (Low) then
21129 return 0;
21130 elsif not Compile_Time_Known_Value (High) then
21131 return 0;
21132 else
21133 Num :=
21134 Num * UI_To_Int ((Expr_Value (High) - Expr_Value (Low) + 1));
21135 end if;
21137 Next_Index (Indx);
21138 end loop;
21140 return Num;
21141 end Number_Of_Elements_In_Array;
21143 -------------------------
21144 -- Object_Access_Level --
21145 -------------------------
21147 -- Returns the static accessibility level of the view denoted by Obj. Note
21148 -- that the value returned is the result of a call to Scope_Depth. Only
21149 -- scope depths associated with dynamic scopes can actually be returned.
21150 -- Since only relative levels matter for accessibility checking, the fact
21151 -- that the distance between successive levels of accessibility is not
21152 -- always one is immaterial (invariant: if level(E2) is deeper than
21153 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
21155 function Object_Access_Level (Obj : Node_Id) return Uint is
21156 function Is_Interface_Conversion (N : Node_Id) return Boolean;
21157 -- Determine whether N is a construct of the form
21158 -- Some_Type (Operand._tag'Address)
21159 -- This construct appears in the context of dispatching calls.
21161 function Reference_To (Obj : Node_Id) return Node_Id;
21162 -- An explicit dereference is created when removing side effects from
21163 -- expressions for constraint checking purposes. In this case a local
21164 -- access type is created for it. The correct access level is that of
21165 -- the original source node. We detect this case by noting that the
21166 -- prefix of the dereference is created by an object declaration whose
21167 -- initial expression is a reference.
21169 -----------------------------
21170 -- Is_Interface_Conversion --
21171 -----------------------------
21173 function Is_Interface_Conversion (N : Node_Id) return Boolean is
21174 begin
21175 return Nkind (N) = N_Unchecked_Type_Conversion
21176 and then Nkind (Expression (N)) = N_Attribute_Reference
21177 and then Attribute_Name (Expression (N)) = Name_Address;
21178 end Is_Interface_Conversion;
21180 ------------------
21181 -- Reference_To --
21182 ------------------
21184 function Reference_To (Obj : Node_Id) return Node_Id is
21185 Pref : constant Node_Id := Prefix (Obj);
21186 begin
21187 if Is_Entity_Name (Pref)
21188 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
21189 and then Present (Expression (Parent (Entity (Pref))))
21190 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
21191 then
21192 return (Prefix (Expression (Parent (Entity (Pref)))));
21193 else
21194 return Empty;
21195 end if;
21196 end Reference_To;
21198 -- Local variables
21200 E : Entity_Id;
21202 -- Start of processing for Object_Access_Level
21204 begin
21205 if Nkind (Obj) = N_Defining_Identifier
21206 or else Is_Entity_Name (Obj)
21207 then
21208 if Nkind (Obj) = N_Defining_Identifier then
21209 E := Obj;
21210 else
21211 E := Entity (Obj);
21212 end if;
21214 if Is_Prival (E) then
21215 E := Prival_Link (E);
21216 end if;
21218 -- If E is a type then it denotes a current instance. For this case
21219 -- we add one to the normal accessibility level of the type to ensure
21220 -- that current instances are treated as always being deeper than
21221 -- than the level of any visible named access type (see 3.10.2(21)).
21223 if Is_Type (E) then
21224 return Type_Access_Level (E) + 1;
21226 elsif Present (Renamed_Object (E)) then
21227 return Object_Access_Level (Renamed_Object (E));
21229 -- Similarly, if E is a component of the current instance of a
21230 -- protected type, any instance of it is assumed to be at a deeper
21231 -- level than the type. For a protected object (whose type is an
21232 -- anonymous protected type) its components are at the same level
21233 -- as the type itself.
21235 elsif not Is_Overloadable (E)
21236 and then Ekind (Scope (E)) = E_Protected_Type
21237 and then Comes_From_Source (Scope (E))
21238 then
21239 return Type_Access_Level (Scope (E)) + 1;
21241 else
21242 -- Aliased formals of functions take their access level from the
21243 -- point of call, i.e. require a dynamic check. For static check
21244 -- purposes, this is smaller than the level of the subprogram
21245 -- itself. For procedures the aliased makes no difference.
21247 if Is_Formal (E)
21248 and then Is_Aliased (E)
21249 and then Ekind (Scope (E)) = E_Function
21250 then
21251 return Type_Access_Level (Etype (E));
21253 else
21254 return Scope_Depth (Enclosing_Dynamic_Scope (E));
21255 end if;
21256 end if;
21258 elsif Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
21259 if Is_Access_Type (Etype (Prefix (Obj))) then
21260 return Type_Access_Level (Etype (Prefix (Obj)));
21261 else
21262 return Object_Access_Level (Prefix (Obj));
21263 end if;
21265 elsif Nkind (Obj) = N_Explicit_Dereference then
21267 -- If the prefix is a selected access discriminant then we make a
21268 -- recursive call on the prefix, which will in turn check the level
21269 -- of the prefix object of the selected discriminant.
21271 -- In Ada 2012, if the discriminant has implicit dereference and
21272 -- the context is a selected component, treat this as an object of
21273 -- unknown scope (see below). This is necessary in compile-only mode;
21274 -- otherwise expansion will already have transformed the prefix into
21275 -- a temporary.
21277 if Nkind (Prefix (Obj)) = N_Selected_Component
21278 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
21279 and then
21280 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
21281 and then
21282 (not Has_Implicit_Dereference
21283 (Entity (Selector_Name (Prefix (Obj))))
21284 or else Nkind (Parent (Obj)) /= N_Selected_Component)
21285 then
21286 return Object_Access_Level (Prefix (Obj));
21288 -- Detect an interface conversion in the context of a dispatching
21289 -- call. Use the original form of the conversion to find the access
21290 -- level of the operand.
21292 elsif Is_Interface (Etype (Obj))
21293 and then Is_Interface_Conversion (Prefix (Obj))
21294 and then Nkind (Original_Node (Obj)) = N_Type_Conversion
21295 then
21296 return Object_Access_Level (Original_Node (Obj));
21298 elsif not Comes_From_Source (Obj) then
21299 declare
21300 Ref : constant Node_Id := Reference_To (Obj);
21301 begin
21302 if Present (Ref) then
21303 return Object_Access_Level (Ref);
21304 else
21305 return Type_Access_Level (Etype (Prefix (Obj)));
21306 end if;
21307 end;
21309 else
21310 return Type_Access_Level (Etype (Prefix (Obj)));
21311 end if;
21313 elsif Nkind_In (Obj, N_Type_Conversion, N_Unchecked_Type_Conversion) then
21314 return Object_Access_Level (Expression (Obj));
21316 elsif Nkind (Obj) = N_Function_Call then
21318 -- Function results are objects, so we get either the access level of
21319 -- the function or, in the case of an indirect call, the level of the
21320 -- access-to-subprogram type. (This code is used for Ada 95, but it
21321 -- looks wrong, because it seems that we should be checking the level
21322 -- of the call itself, even for Ada 95. However, using the Ada 2005
21323 -- version of the code causes regressions in several tests that are
21324 -- compiled with -gnat95. ???)
21326 if Ada_Version < Ada_2005 then
21327 if Is_Entity_Name (Name (Obj)) then
21328 return Subprogram_Access_Level (Entity (Name (Obj)));
21329 else
21330 return Type_Access_Level (Etype (Prefix (Name (Obj))));
21331 end if;
21333 -- For Ada 2005, the level of the result object of a function call is
21334 -- defined to be the level of the call's innermost enclosing master.
21335 -- We determine that by querying the depth of the innermost enclosing
21336 -- dynamic scope.
21338 else
21339 Return_Master_Scope_Depth_Of_Call : declare
21340 function Innermost_Master_Scope_Depth
21341 (N : Node_Id) return Uint;
21342 -- Returns the scope depth of the given node's innermost
21343 -- enclosing dynamic scope (effectively the accessibility
21344 -- level of the innermost enclosing master).
21346 ----------------------------------
21347 -- Innermost_Master_Scope_Depth --
21348 ----------------------------------
21350 function Innermost_Master_Scope_Depth
21351 (N : Node_Id) return Uint
21353 Node_Par : Node_Id := Parent (N);
21355 begin
21356 -- Locate the nearest enclosing node (by traversing Parents)
21357 -- that Defining_Entity can be applied to, and return the
21358 -- depth of that entity's nearest enclosing dynamic scope.
21360 while Present (Node_Par) loop
21361 case Nkind (Node_Par) is
21362 when N_Abstract_Subprogram_Declaration
21363 | N_Block_Statement
21364 | N_Body_Stub
21365 | N_Component_Declaration
21366 | N_Entry_Body
21367 | N_Entry_Declaration
21368 | N_Exception_Declaration
21369 | N_Formal_Object_Declaration
21370 | N_Formal_Package_Declaration
21371 | N_Formal_Subprogram_Declaration
21372 | N_Formal_Type_Declaration
21373 | N_Full_Type_Declaration
21374 | N_Function_Specification
21375 | N_Generic_Declaration
21376 | N_Generic_Instantiation
21377 | N_Implicit_Label_Declaration
21378 | N_Incomplete_Type_Declaration
21379 | N_Loop_Parameter_Specification
21380 | N_Number_Declaration
21381 | N_Object_Declaration
21382 | N_Package_Declaration
21383 | N_Package_Specification
21384 | N_Parameter_Specification
21385 | N_Private_Extension_Declaration
21386 | N_Private_Type_Declaration
21387 | N_Procedure_Specification
21388 | N_Proper_Body
21389 | N_Protected_Type_Declaration
21390 | N_Renaming_Declaration
21391 | N_Single_Protected_Declaration
21392 | N_Single_Task_Declaration
21393 | N_Subprogram_Declaration
21394 | N_Subtype_Declaration
21395 | N_Subunit
21396 | N_Task_Type_Declaration
21398 return Scope_Depth
21399 (Nearest_Dynamic_Scope
21400 (Defining_Entity (Node_Par)));
21402 -- For a return statement within a function, return
21403 -- the depth of the function itself. This is not just
21404 -- a small optimization, but matters when analyzing
21405 -- the expression in an expression function before
21406 -- the body is created.
21408 when N_Simple_Return_Statement =>
21409 if Ekind (Current_Scope) = E_Function then
21410 return Scope_Depth (Current_Scope);
21411 end if;
21413 when others =>
21414 null;
21415 end case;
21417 Node_Par := Parent (Node_Par);
21418 end loop;
21420 pragma Assert (False);
21422 -- Should never reach the following return
21424 return Scope_Depth (Current_Scope) + 1;
21425 end Innermost_Master_Scope_Depth;
21427 -- Start of processing for Return_Master_Scope_Depth_Of_Call
21429 begin
21430 return Innermost_Master_Scope_Depth (Obj);
21431 end Return_Master_Scope_Depth_Of_Call;
21432 end if;
21434 -- For convenience we handle qualified expressions, even though they
21435 -- aren't technically object names.
21437 elsif Nkind (Obj) = N_Qualified_Expression then
21438 return Object_Access_Level (Expression (Obj));
21440 -- Ditto for aggregates. They have the level of the temporary that
21441 -- will hold their value.
21443 elsif Nkind (Obj) = N_Aggregate then
21444 return Object_Access_Level (Current_Scope);
21446 -- Otherwise return the scope level of Standard. (If there are cases
21447 -- that fall through to this point they will be treated as having
21448 -- global accessibility for now. ???)
21450 else
21451 return Scope_Depth (Standard_Standard);
21452 end if;
21453 end Object_Access_Level;
21455 ----------------------------------
21456 -- Old_Requires_Transient_Scope --
21457 ----------------------------------
21459 function Old_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
21460 Typ : constant Entity_Id := Underlying_Type (Id);
21462 begin
21463 -- This is a private type which is not completed yet. This can only
21464 -- happen in a default expression (of a formal parameter or of a
21465 -- record component). Do not expand transient scope in this case.
21467 if No (Typ) then
21468 return False;
21470 -- Do not expand transient scope for non-existent procedure return
21472 elsif Typ = Standard_Void_Type then
21473 return False;
21475 -- Elementary types do not require a transient scope
21477 elsif Is_Elementary_Type (Typ) then
21478 return False;
21480 -- Generally, indefinite subtypes require a transient scope, since the
21481 -- back end cannot generate temporaries, since this is not a valid type
21482 -- for declaring an object. It might be possible to relax this in the
21483 -- future, e.g. by declaring the maximum possible space for the type.
21485 elsif not Is_Definite_Subtype (Typ) then
21486 return True;
21488 -- Functions returning tagged types may dispatch on result so their
21489 -- returned value is allocated on the secondary stack. Controlled
21490 -- type temporaries need finalization.
21492 elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
21493 return True;
21495 -- Record type
21497 elsif Is_Record_Type (Typ) then
21498 declare
21499 Comp : Entity_Id;
21501 begin
21502 Comp := First_Entity (Typ);
21503 while Present (Comp) loop
21504 if Ekind (Comp) = E_Component then
21506 -- ???It's not clear we need a full recursive call to
21507 -- Old_Requires_Transient_Scope here. Note that the
21508 -- following can't happen.
21510 pragma Assert (Is_Definite_Subtype (Etype (Comp)));
21511 pragma Assert (not Has_Controlled_Component (Etype (Comp)));
21513 if Old_Requires_Transient_Scope (Etype (Comp)) then
21514 return True;
21515 end if;
21516 end if;
21518 Next_Entity (Comp);
21519 end loop;
21520 end;
21522 return False;
21524 -- String literal types never require transient scope
21526 elsif Ekind (Typ) = E_String_Literal_Subtype then
21527 return False;
21529 -- Array type. Note that we already know that this is a constrained
21530 -- array, since unconstrained arrays will fail the indefinite test.
21532 elsif Is_Array_Type (Typ) then
21534 -- If component type requires a transient scope, the array does too
21536 if Old_Requires_Transient_Scope (Component_Type (Typ)) then
21537 return True;
21539 -- Otherwise, we only need a transient scope if the size depends on
21540 -- the value of one or more discriminants.
21542 else
21543 return Size_Depends_On_Discriminant (Typ);
21544 end if;
21546 -- All other cases do not require a transient scope
21548 else
21549 pragma Assert (Is_Protected_Type (Typ) or else Is_Task_Type (Typ));
21550 return False;
21551 end if;
21552 end Old_Requires_Transient_Scope;
21554 ---------------------------------
21555 -- Original_Aspect_Pragma_Name --
21556 ---------------------------------
21558 function Original_Aspect_Pragma_Name (N : Node_Id) return Name_Id is
21559 Item : Node_Id;
21560 Item_Nam : Name_Id;
21562 begin
21563 pragma Assert (Nkind_In (N, N_Aspect_Specification, N_Pragma));
21565 Item := N;
21567 -- The pragma was generated to emulate an aspect, use the original
21568 -- aspect specification.
21570 if Nkind (Item) = N_Pragma and then From_Aspect_Specification (Item) then
21571 Item := Corresponding_Aspect (Item);
21572 end if;
21574 -- Retrieve the name of the aspect/pragma. Note that Pre, Pre_Class,
21575 -- Post and Post_Class rewrite their pragma identifier to preserve the
21576 -- original name.
21577 -- ??? this is kludgey
21579 if Nkind (Item) = N_Pragma then
21580 Item_Nam := Chars (Original_Node (Pragma_Identifier (Item)));
21582 else
21583 pragma Assert (Nkind (Item) = N_Aspect_Specification);
21584 Item_Nam := Chars (Identifier (Item));
21585 end if;
21587 -- Deal with 'Class by converting the name to its _XXX form
21589 if Class_Present (Item) then
21590 if Item_Nam = Name_Invariant then
21591 Item_Nam := Name_uInvariant;
21593 elsif Item_Nam = Name_Post then
21594 Item_Nam := Name_uPost;
21596 elsif Item_Nam = Name_Pre then
21597 Item_Nam := Name_uPre;
21599 elsif Nam_In (Item_Nam, Name_Type_Invariant,
21600 Name_Type_Invariant_Class)
21601 then
21602 Item_Nam := Name_uType_Invariant;
21604 -- Nothing to do for other cases (e.g. a Check that derived from
21605 -- Pre_Class and has the flag set). Also we do nothing if the name
21606 -- is already in special _xxx form.
21608 end if;
21609 end if;
21611 return Item_Nam;
21612 end Original_Aspect_Pragma_Name;
21614 --------------------------------------
21615 -- Original_Corresponding_Operation --
21616 --------------------------------------
21618 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
21620 Typ : constant Entity_Id := Find_Dispatching_Type (S);
21622 begin
21623 -- If S is an inherited primitive S2 the original corresponding
21624 -- operation of S is the original corresponding operation of S2
21626 if Present (Alias (S))
21627 and then Find_Dispatching_Type (Alias (S)) /= Typ
21628 then
21629 return Original_Corresponding_Operation (Alias (S));
21631 -- If S overrides an inherited subprogram S2 the original corresponding
21632 -- operation of S is the original corresponding operation of S2
21634 elsif Present (Overridden_Operation (S)) then
21635 return Original_Corresponding_Operation (Overridden_Operation (S));
21637 -- otherwise it is S itself
21639 else
21640 return S;
21641 end if;
21642 end Original_Corresponding_Operation;
21644 -------------------
21645 -- Output_Entity --
21646 -------------------
21648 procedure Output_Entity (Id : Entity_Id) is
21649 Scop : Entity_Id;
21651 begin
21652 Scop := Scope (Id);
21654 -- The entity may lack a scope when it is in the process of being
21655 -- analyzed. Use the current scope as an approximation.
21657 if No (Scop) then
21658 Scop := Current_Scope;
21659 end if;
21661 Output_Name (Chars (Id), Scop);
21662 end Output_Entity;
21664 -----------------
21665 -- Output_Name --
21666 -----------------
21668 procedure Output_Name (Nam : Name_Id; Scop : Entity_Id := Current_Scope) is
21669 begin
21670 Write_Str
21671 (Get_Name_String
21672 (Get_Qualified_Name
21673 (Nam => Nam,
21674 Suffix => No_Name,
21675 Scop => Scop)));
21676 Write_Eol;
21677 end Output_Name;
21679 ----------------------
21680 -- Policy_In_Effect --
21681 ----------------------
21683 function Policy_In_Effect (Policy : Name_Id) return Name_Id is
21684 function Policy_In_List (List : Node_Id) return Name_Id;
21685 -- Determine the mode of a policy in a N_Pragma list
21687 --------------------
21688 -- Policy_In_List --
21689 --------------------
21691 function Policy_In_List (List : Node_Id) return Name_Id is
21692 Arg1 : Node_Id;
21693 Arg2 : Node_Id;
21694 Prag : Node_Id;
21696 begin
21697 Prag := List;
21698 while Present (Prag) loop
21699 Arg1 := First (Pragma_Argument_Associations (Prag));
21700 Arg2 := Next (Arg1);
21702 Arg1 := Get_Pragma_Arg (Arg1);
21703 Arg2 := Get_Pragma_Arg (Arg2);
21705 -- The current Check_Policy pragma matches the requested policy or
21706 -- appears in the single argument form (Assertion, policy_id).
21708 if Nam_In (Chars (Arg1), Name_Assertion, Policy) then
21709 return Chars (Arg2);
21710 end if;
21712 Prag := Next_Pragma (Prag);
21713 end loop;
21715 return No_Name;
21716 end Policy_In_List;
21718 -- Local variables
21720 Kind : Name_Id;
21722 -- Start of processing for Policy_In_Effect
21724 begin
21725 if not Is_Valid_Assertion_Kind (Policy) then
21726 raise Program_Error;
21727 end if;
21729 -- Inspect all policy pragmas that appear within scopes (if any)
21731 Kind := Policy_In_List (Check_Policy_List);
21733 -- Inspect all configuration policy pragmas (if any)
21735 if Kind = No_Name then
21736 Kind := Policy_In_List (Check_Policy_List_Config);
21737 end if;
21739 -- The context lacks policy pragmas, determine the mode based on whether
21740 -- assertions are enabled at the configuration level. This ensures that
21741 -- the policy is preserved when analyzing generics.
21743 if Kind = No_Name then
21744 if Assertions_Enabled_Config then
21745 Kind := Name_Check;
21746 else
21747 Kind := Name_Ignore;
21748 end if;
21749 end if;
21751 return Kind;
21752 end Policy_In_Effect;
21754 ----------------------------------
21755 -- Predicate_Tests_On_Arguments --
21756 ----------------------------------
21758 function Predicate_Tests_On_Arguments (Subp : Entity_Id) return Boolean is
21759 begin
21760 -- Always test predicates on indirect call
21762 if Ekind (Subp) = E_Subprogram_Type then
21763 return True;
21765 -- Do not test predicates on call to generated default Finalize, since
21766 -- we are not interested in whether something we are finalizing (and
21767 -- typically destroying) satisfies its predicates.
21769 elsif Chars (Subp) = Name_Finalize
21770 and then not Comes_From_Source (Subp)
21771 then
21772 return False;
21774 -- Do not test predicates on any internally generated routines
21776 elsif Is_Internal_Name (Chars (Subp)) then
21777 return False;
21779 -- Do not test predicates on call to Init_Proc, since if needed the
21780 -- predicate test will occur at some other point.
21782 elsif Is_Init_Proc (Subp) then
21783 return False;
21785 -- Do not test predicates on call to predicate function, since this
21786 -- would cause infinite recursion.
21788 elsif Ekind (Subp) = E_Function
21789 and then (Is_Predicate_Function (Subp)
21790 or else
21791 Is_Predicate_Function_M (Subp))
21792 then
21793 return False;
21795 -- For now, no other exceptions
21797 else
21798 return True;
21799 end if;
21800 end Predicate_Tests_On_Arguments;
21802 -----------------------
21803 -- Private_Component --
21804 -----------------------
21806 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
21807 Ancestor : constant Entity_Id := Base_Type (Type_Id);
21809 function Trace_Components
21810 (T : Entity_Id;
21811 Check : Boolean) return Entity_Id;
21812 -- Recursive function that does the work, and checks against circular
21813 -- definition for each subcomponent type.
21815 ----------------------
21816 -- Trace_Components --
21817 ----------------------
21819 function Trace_Components
21820 (T : Entity_Id;
21821 Check : Boolean) return Entity_Id
21823 Btype : constant Entity_Id := Base_Type (T);
21824 Component : Entity_Id;
21825 P : Entity_Id;
21826 Candidate : Entity_Id := Empty;
21828 begin
21829 if Check and then Btype = Ancestor then
21830 Error_Msg_N ("circular type definition", Type_Id);
21831 return Any_Type;
21832 end if;
21834 if Is_Private_Type (Btype) and then not Is_Generic_Type (Btype) then
21835 if Present (Full_View (Btype))
21836 and then Is_Record_Type (Full_View (Btype))
21837 and then not Is_Frozen (Btype)
21838 then
21839 -- To indicate that the ancestor depends on a private type, the
21840 -- current Btype is sufficient. However, to check for circular
21841 -- definition we must recurse on the full view.
21843 Candidate := Trace_Components (Full_View (Btype), True);
21845 if Candidate = Any_Type then
21846 return Any_Type;
21847 else
21848 return Btype;
21849 end if;
21851 else
21852 return Btype;
21853 end if;
21855 elsif Is_Array_Type (Btype) then
21856 return Trace_Components (Component_Type (Btype), True);
21858 elsif Is_Record_Type (Btype) then
21859 Component := First_Entity (Btype);
21860 while Present (Component)
21861 and then Comes_From_Source (Component)
21862 loop
21863 -- Skip anonymous types generated by constrained components
21865 if not Is_Type (Component) then
21866 P := Trace_Components (Etype (Component), True);
21868 if Present (P) then
21869 if P = Any_Type then
21870 return P;
21871 else
21872 Candidate := P;
21873 end if;
21874 end if;
21875 end if;
21877 Next_Entity (Component);
21878 end loop;
21880 return Candidate;
21882 else
21883 return Empty;
21884 end if;
21885 end Trace_Components;
21887 -- Start of processing for Private_Component
21889 begin
21890 return Trace_Components (Type_Id, False);
21891 end Private_Component;
21893 ---------------------------
21894 -- Primitive_Names_Match --
21895 ---------------------------
21897 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
21898 function Non_Internal_Name (E : Entity_Id) return Name_Id;
21899 -- Given an internal name, returns the corresponding non-internal name
21901 ------------------------
21902 -- Non_Internal_Name --
21903 ------------------------
21905 function Non_Internal_Name (E : Entity_Id) return Name_Id is
21906 begin
21907 Get_Name_String (Chars (E));
21908 Name_Len := Name_Len - 1;
21909 return Name_Find;
21910 end Non_Internal_Name;
21912 -- Start of processing for Primitive_Names_Match
21914 begin
21915 pragma Assert (Present (E1) and then Present (E2));
21917 return Chars (E1) = Chars (E2)
21918 or else
21919 (not Is_Internal_Name (Chars (E1))
21920 and then Is_Internal_Name (Chars (E2))
21921 and then Non_Internal_Name (E2) = Chars (E1))
21922 or else
21923 (not Is_Internal_Name (Chars (E2))
21924 and then Is_Internal_Name (Chars (E1))
21925 and then Non_Internal_Name (E1) = Chars (E2))
21926 or else
21927 (Is_Predefined_Dispatching_Operation (E1)
21928 and then Is_Predefined_Dispatching_Operation (E2)
21929 and then Same_TSS (E1, E2))
21930 or else
21931 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
21932 end Primitive_Names_Match;
21934 -----------------------
21935 -- Process_End_Label --
21936 -----------------------
21938 procedure Process_End_Label
21939 (N : Node_Id;
21940 Typ : Character;
21941 Ent : Entity_Id)
21943 Loc : Source_Ptr;
21944 Nam : Node_Id;
21945 Scop : Entity_Id;
21947 Label_Ref : Boolean;
21948 -- Set True if reference to end label itself is required
21950 Endl : Node_Id;
21951 -- Gets set to the operator symbol or identifier that references the
21952 -- entity Ent. For the child unit case, this is the identifier from the
21953 -- designator. For other cases, this is simply Endl.
21955 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
21956 -- N is an identifier node that appears as a parent unit reference in
21957 -- the case where Ent is a child unit. This procedure generates an
21958 -- appropriate cross-reference entry. E is the corresponding entity.
21960 -------------------------
21961 -- Generate_Parent_Ref --
21962 -------------------------
21964 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
21965 begin
21966 -- If names do not match, something weird, skip reference
21968 if Chars (E) = Chars (N) then
21970 -- Generate the reference. We do NOT consider this as a reference
21971 -- for unreferenced symbol purposes.
21973 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
21975 if Style_Check then
21976 Style.Check_Identifier (N, E);
21977 end if;
21978 end if;
21979 end Generate_Parent_Ref;
21981 -- Start of processing for Process_End_Label
21983 begin
21984 -- If no node, ignore. This happens in some error situations, and
21985 -- also for some internally generated structures where no end label
21986 -- references are required in any case.
21988 if No (N) then
21989 return;
21990 end if;
21992 -- Nothing to do if no End_Label, happens for internally generated
21993 -- constructs where we don't want an end label reference anyway. Also
21994 -- nothing to do if Endl is a string literal, which means there was
21995 -- some prior error (bad operator symbol)
21997 Endl := End_Label (N);
21999 if No (Endl) or else Nkind (Endl) = N_String_Literal then
22000 return;
22001 end if;
22003 -- Reference node is not in extended main source unit
22005 if not In_Extended_Main_Source_Unit (N) then
22007 -- Generally we do not collect references except for the extended
22008 -- main source unit. The one exception is the 'e' entry for a
22009 -- package spec, where it is useful for a client to have the
22010 -- ending information to define scopes.
22012 if Typ /= 'e' then
22013 return;
22015 else
22016 Label_Ref := False;
22018 -- For this case, we can ignore any parent references, but we
22019 -- need the package name itself for the 'e' entry.
22021 if Nkind (Endl) = N_Designator then
22022 Endl := Identifier (Endl);
22023 end if;
22024 end if;
22026 -- Reference is in extended main source unit
22028 else
22029 Label_Ref := True;
22031 -- For designator, generate references for the parent entries
22033 if Nkind (Endl) = N_Designator then
22035 -- Generate references for the prefix if the END line comes from
22036 -- source (otherwise we do not need these references) We climb the
22037 -- scope stack to find the expected entities.
22039 if Comes_From_Source (Endl) then
22040 Nam := Name (Endl);
22041 Scop := Current_Scope;
22042 while Nkind (Nam) = N_Selected_Component loop
22043 Scop := Scope (Scop);
22044 exit when No (Scop);
22045 Generate_Parent_Ref (Selector_Name (Nam), Scop);
22046 Nam := Prefix (Nam);
22047 end loop;
22049 if Present (Scop) then
22050 Generate_Parent_Ref (Nam, Scope (Scop));
22051 end if;
22052 end if;
22054 Endl := Identifier (Endl);
22055 end if;
22056 end if;
22058 -- If the end label is not for the given entity, then either we have
22059 -- some previous error, or this is a generic instantiation for which
22060 -- we do not need to make a cross-reference in this case anyway. In
22061 -- either case we simply ignore the call.
22063 if Chars (Ent) /= Chars (Endl) then
22064 return;
22065 end if;
22067 -- If label was really there, then generate a normal reference and then
22068 -- adjust the location in the end label to point past the name (which
22069 -- should almost always be the semicolon).
22071 Loc := Sloc (Endl);
22073 if Comes_From_Source (Endl) then
22075 -- If a label reference is required, then do the style check and
22076 -- generate an l-type cross-reference entry for the label
22078 if Label_Ref then
22079 if Style_Check then
22080 Style.Check_Identifier (Endl, Ent);
22081 end if;
22083 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
22084 end if;
22086 -- Set the location to point past the label (normally this will
22087 -- mean the semicolon immediately following the label). This is
22088 -- done for the sake of the 'e' or 't' entry generated below.
22090 Get_Decoded_Name_String (Chars (Endl));
22091 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
22093 else
22094 -- In SPARK mode, no missing label is allowed for packages and
22095 -- subprogram bodies. Detect those cases by testing whether
22096 -- Process_End_Label was called for a body (Typ = 't') or a package.
22098 if Restriction_Check_Required (SPARK_05)
22099 and then (Typ = 't' or else Ekind (Ent) = E_Package)
22100 then
22101 Error_Msg_Node_1 := Endl;
22102 Check_SPARK_05_Restriction
22103 ("`END &` required", Endl, Force => True);
22104 end if;
22105 end if;
22107 -- Now generate the e/t reference
22109 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
22111 -- Restore Sloc, in case modified above, since we have an identifier
22112 -- and the normal Sloc should be left set in the tree.
22114 Set_Sloc (Endl, Loc);
22115 end Process_End_Label;
22117 --------------------------------
22118 -- Propagate_Concurrent_Flags --
22119 --------------------------------
22121 procedure Propagate_Concurrent_Flags
22122 (Typ : Entity_Id;
22123 Comp_Typ : Entity_Id)
22125 begin
22126 if Has_Task (Comp_Typ) then
22127 Set_Has_Task (Typ);
22128 end if;
22130 if Has_Protected (Comp_Typ) then
22131 Set_Has_Protected (Typ);
22132 end if;
22134 if Has_Timing_Event (Comp_Typ) then
22135 Set_Has_Timing_Event (Typ);
22136 end if;
22137 end Propagate_Concurrent_Flags;
22139 ------------------------------
22140 -- Propagate_DIC_Attributes --
22141 ------------------------------
22143 procedure Propagate_DIC_Attributes
22144 (Typ : Entity_Id;
22145 From_Typ : Entity_Id)
22147 DIC_Proc : Entity_Id;
22149 begin
22150 if Present (Typ) and then Present (From_Typ) then
22151 pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
22153 -- Nothing to do if both the source and the destination denote the
22154 -- same type.
22156 if From_Typ = Typ then
22157 return;
22158 end if;
22160 DIC_Proc := DIC_Procedure (From_Typ);
22162 -- The setting of the attributes is intentionally conservative. This
22163 -- prevents accidental clobbering of enabled attributes.
22165 if Has_Inherited_DIC (From_Typ)
22166 and then not Has_Inherited_DIC (Typ)
22167 then
22168 Set_Has_Inherited_DIC (Typ);
22169 end if;
22171 if Has_Own_DIC (From_Typ) and then not Has_Own_DIC (Typ) then
22172 Set_Has_Own_DIC (Typ);
22173 end if;
22175 if Present (DIC_Proc) and then No (DIC_Procedure (Typ)) then
22176 Set_DIC_Procedure (Typ, DIC_Proc);
22177 end if;
22178 end if;
22179 end Propagate_DIC_Attributes;
22181 ------------------------------------
22182 -- Propagate_Invariant_Attributes --
22183 ------------------------------------
22185 procedure Propagate_Invariant_Attributes
22186 (Typ : Entity_Id;
22187 From_Typ : Entity_Id)
22189 Full_IP : Entity_Id;
22190 Part_IP : Entity_Id;
22192 begin
22193 if Present (Typ) and then Present (From_Typ) then
22194 pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
22196 -- Nothing to do if both the source and the destination denote the
22197 -- same type.
22199 if From_Typ = Typ then
22200 return;
22201 end if;
22203 Full_IP := Invariant_Procedure (From_Typ);
22204 Part_IP := Partial_Invariant_Procedure (From_Typ);
22206 -- The setting of the attributes is intentionally conservative. This
22207 -- prevents accidental clobbering of enabled attributes.
22209 if Has_Inheritable_Invariants (From_Typ)
22210 and then not Has_Inheritable_Invariants (Typ)
22211 then
22212 Set_Has_Inheritable_Invariants (Typ, True);
22213 end if;
22215 if Has_Inherited_Invariants (From_Typ)
22216 and then not Has_Inherited_Invariants (Typ)
22217 then
22218 Set_Has_Inherited_Invariants (Typ, True);
22219 end if;
22221 if Has_Own_Invariants (From_Typ)
22222 and then not Has_Own_Invariants (Typ)
22223 then
22224 Set_Has_Own_Invariants (Typ, True);
22225 end if;
22227 if Present (Full_IP) and then No (Invariant_Procedure (Typ)) then
22228 Set_Invariant_Procedure (Typ, Full_IP);
22229 end if;
22231 if Present (Part_IP) and then No (Partial_Invariant_Procedure (Typ))
22232 then
22233 Set_Partial_Invariant_Procedure (Typ, Part_IP);
22234 end if;
22235 end if;
22236 end Propagate_Invariant_Attributes;
22238 ---------------------------------------
22239 -- Record_Possible_Part_Of_Reference --
22240 ---------------------------------------
22242 procedure Record_Possible_Part_Of_Reference
22243 (Var_Id : Entity_Id;
22244 Ref : Node_Id)
22246 Encap : constant Entity_Id := Encapsulating_State (Var_Id);
22247 Refs : Elist_Id;
22249 begin
22250 -- The variable is a constituent of a single protected/task type. Such
22251 -- a variable acts as a component of the type and must appear within a
22252 -- specific region (SPARK RM 9(3)). Instead of recording the reference,
22253 -- verify its legality now.
22255 if Present (Encap) and then Is_Single_Concurrent_Object (Encap) then
22256 Check_Part_Of_Reference (Var_Id, Ref);
22258 -- The variable is subject to pragma Part_Of and may eventually become a
22259 -- constituent of a single protected/task type. Record the reference to
22260 -- verify its placement when the contract of the variable is analyzed.
22262 elsif Present (Get_Pragma (Var_Id, Pragma_Part_Of)) then
22263 Refs := Part_Of_References (Var_Id);
22265 if No (Refs) then
22266 Refs := New_Elmt_List;
22267 Set_Part_Of_References (Var_Id, Refs);
22268 end if;
22270 Append_Elmt (Ref, Refs);
22271 end if;
22272 end Record_Possible_Part_Of_Reference;
22274 ----------------
22275 -- Referenced --
22276 ----------------
22278 function Referenced (Id : Entity_Id; Expr : Node_Id) return Boolean is
22279 Seen : Boolean := False;
22281 function Is_Reference (N : Node_Id) return Traverse_Result;
22282 -- Determine whether node N denotes a reference to Id. If this is the
22283 -- case, set global flag Seen to True and stop the traversal.
22285 ------------------
22286 -- Is_Reference --
22287 ------------------
22289 function Is_Reference (N : Node_Id) return Traverse_Result is
22290 begin
22291 if Is_Entity_Name (N)
22292 and then Present (Entity (N))
22293 and then Entity (N) = Id
22294 then
22295 Seen := True;
22296 return Abandon;
22297 else
22298 return OK;
22299 end if;
22300 end Is_Reference;
22302 procedure Inspect_Expression is new Traverse_Proc (Is_Reference);
22304 -- Start of processing for Referenced
22306 begin
22307 Inspect_Expression (Expr);
22308 return Seen;
22309 end Referenced;
22311 ------------------------------------
22312 -- References_Generic_Formal_Type --
22313 ------------------------------------
22315 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
22317 function Process (N : Node_Id) return Traverse_Result;
22318 -- Process one node in search for generic formal type
22320 -------------
22321 -- Process --
22322 -------------
22324 function Process (N : Node_Id) return Traverse_Result is
22325 begin
22326 if Nkind (N) in N_Has_Entity then
22327 declare
22328 E : constant Entity_Id := Entity (N);
22329 begin
22330 if Present (E) then
22331 if Is_Generic_Type (E) then
22332 return Abandon;
22333 elsif Present (Etype (E))
22334 and then Is_Generic_Type (Etype (E))
22335 then
22336 return Abandon;
22337 end if;
22338 end if;
22339 end;
22340 end if;
22342 return Atree.OK;
22343 end Process;
22345 function Traverse is new Traverse_Func (Process);
22346 -- Traverse tree to look for generic type
22348 begin
22349 if Inside_A_Generic then
22350 return Traverse (N) = Abandon;
22351 else
22352 return False;
22353 end if;
22354 end References_Generic_Formal_Type;
22356 -------------------
22357 -- Remove_Entity --
22358 -------------------
22360 procedure Remove_Entity (Id : Entity_Id) is
22361 Scop : constant Entity_Id := Scope (Id);
22362 Prev_Id : Entity_Id;
22364 begin
22365 -- Remove the entity from the homonym chain. When the entity is the
22366 -- head of the chain, associate the entry in the name table with its
22367 -- homonym effectively making it the new head of the chain.
22369 if Current_Entity (Id) = Id then
22370 Set_Name_Entity_Id (Chars (Id), Homonym (Id));
22372 -- Otherwise link the previous and next homonyms
22374 else
22375 Prev_Id := Current_Entity (Id);
22376 while Present (Prev_Id) and then Homonym (Prev_Id) /= Id loop
22377 Prev_Id := Homonym (Prev_Id);
22378 end loop;
22380 Set_Homonym (Prev_Id, Homonym (Id));
22381 end if;
22383 -- Remove the entity from the scope entity chain. When the entity is
22384 -- the head of the chain, set the next entity as the new head of the
22385 -- chain.
22387 if First_Entity (Scop) = Id then
22388 Prev_Id := Empty;
22389 Set_First_Entity (Scop, Next_Entity (Id));
22391 -- Otherwise the entity is either in the middle of the chain or it acts
22392 -- as its tail. Traverse and link the previous and next entities.
22394 else
22395 Prev_Id := First_Entity (Scop);
22396 while Present (Prev_Id) and then Next_Entity (Prev_Id) /= Id loop
22397 Next_Entity (Prev_Id);
22398 end loop;
22400 Set_Next_Entity (Prev_Id, Next_Entity (Id));
22401 end if;
22403 -- Handle the case where the entity acts as the tail of the scope entity
22404 -- chain.
22406 if Last_Entity (Scop) = Id then
22407 Set_Last_Entity (Scop, Prev_Id);
22408 end if;
22409 end Remove_Entity;
22411 --------------------
22412 -- Remove_Homonym --
22413 --------------------
22415 procedure Remove_Homonym (E : Entity_Id) is
22416 Prev : Entity_Id := Empty;
22417 H : Entity_Id;
22419 begin
22420 if E = Current_Entity (E) then
22421 if Present (Homonym (E)) then
22422 Set_Current_Entity (Homonym (E));
22423 else
22424 Set_Name_Entity_Id (Chars (E), Empty);
22425 end if;
22427 else
22428 H := Current_Entity (E);
22429 while Present (H) and then H /= E loop
22430 Prev := H;
22431 H := Homonym (H);
22432 end loop;
22434 -- If E is not on the homonym chain, nothing to do
22436 if Present (H) then
22437 Set_Homonym (Prev, Homonym (E));
22438 end if;
22439 end if;
22440 end Remove_Homonym;
22442 ------------------------------
22443 -- Remove_Overloaded_Entity --
22444 ------------------------------
22446 procedure Remove_Overloaded_Entity (Id : Entity_Id) is
22447 procedure Remove_Primitive_Of (Typ : Entity_Id);
22448 -- Remove primitive subprogram Id from the list of primitives that
22449 -- belong to type Typ.
22451 -------------------------
22452 -- Remove_Primitive_Of --
22453 -------------------------
22455 procedure Remove_Primitive_Of (Typ : Entity_Id) is
22456 Prims : Elist_Id;
22458 begin
22459 if Is_Tagged_Type (Typ) then
22460 Prims := Direct_Primitive_Operations (Typ);
22462 if Present (Prims) then
22463 Remove (Prims, Id);
22464 end if;
22465 end if;
22466 end Remove_Primitive_Of;
22468 -- Local variables
22470 Formal : Entity_Id;
22472 -- Start of processing for Remove_Overloaded_Entity
22474 begin
22475 -- Remove the entity from both the homonym and scope chains
22477 Remove_Entity (Id);
22479 -- The entity denotes a primitive subprogram. Remove it from the list of
22480 -- primitives of the associated controlling type.
22482 if Ekind_In (Id, E_Function, E_Procedure) and then Is_Primitive (Id) then
22483 Formal := First_Formal (Id);
22484 while Present (Formal) loop
22485 if Is_Controlling_Formal (Formal) then
22486 Remove_Primitive_Of (Etype (Formal));
22487 exit;
22488 end if;
22490 Next_Formal (Formal);
22491 end loop;
22493 if Ekind (Id) = E_Function and then Has_Controlling_Result (Id) then
22494 Remove_Primitive_Of (Etype (Id));
22495 end if;
22496 end if;
22497 end Remove_Overloaded_Entity;
22499 ---------------------
22500 -- Rep_To_Pos_Flag --
22501 ---------------------
22503 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
22504 begin
22505 return New_Occurrence_Of
22506 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
22507 end Rep_To_Pos_Flag;
22509 --------------------
22510 -- Require_Entity --
22511 --------------------
22513 procedure Require_Entity (N : Node_Id) is
22514 begin
22515 if Is_Entity_Name (N) and then No (Entity (N)) then
22516 if Total_Errors_Detected /= 0 then
22517 Set_Entity (N, Any_Id);
22518 else
22519 raise Program_Error;
22520 end if;
22521 end if;
22522 end Require_Entity;
22524 ------------------------------
22525 -- Requires_Transient_Scope --
22526 ------------------------------
22528 -- A transient scope is required when variable-sized temporaries are
22529 -- allocated on the secondary stack, or when finalization actions must be
22530 -- generated before the next instruction.
22532 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
22533 Old_Result : constant Boolean := Old_Requires_Transient_Scope (Id);
22535 begin
22536 if Debug_Flag_QQ then
22537 return Old_Result;
22538 end if;
22540 declare
22541 New_Result : constant Boolean := New_Requires_Transient_Scope (Id);
22543 begin
22544 -- Assert that we're not putting things on the secondary stack if we
22545 -- didn't before; we are trying to AVOID secondary stack when
22546 -- possible.
22548 if not Old_Result then
22549 pragma Assert (not New_Result);
22550 null;
22551 end if;
22553 if New_Result /= Old_Result then
22554 Results_Differ (Id, Old_Result, New_Result);
22555 end if;
22557 return New_Result;
22558 end;
22559 end Requires_Transient_Scope;
22561 --------------------
22562 -- Results_Differ --
22563 --------------------
22565 procedure Results_Differ
22566 (Id : Entity_Id;
22567 Old_Val : Boolean;
22568 New_Val : Boolean)
22570 begin
22571 if False then -- False to disable; True for debugging
22572 Treepr.Print_Tree_Node (Id);
22574 if Old_Val = New_Val then
22575 raise Program_Error;
22576 end if;
22577 end if;
22578 end Results_Differ;
22580 --------------------------
22581 -- Reset_Analyzed_Flags --
22582 --------------------------
22584 procedure Reset_Analyzed_Flags (N : Node_Id) is
22585 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
22586 -- Function used to reset Analyzed flags in tree. Note that we do
22587 -- not reset Analyzed flags in entities, since there is no need to
22588 -- reanalyze entities, and indeed, it is wrong to do so, since it
22589 -- can result in generating auxiliary stuff more than once.
22591 --------------------
22592 -- Clear_Analyzed --
22593 --------------------
22595 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
22596 begin
22597 if Nkind (N) not in N_Entity then
22598 Set_Analyzed (N, False);
22599 end if;
22601 return OK;
22602 end Clear_Analyzed;
22604 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
22606 -- Start of processing for Reset_Analyzed_Flags
22608 begin
22609 Reset_Analyzed (N);
22610 end Reset_Analyzed_Flags;
22612 ------------------------
22613 -- Restore_SPARK_Mode --
22614 ------------------------
22616 procedure Restore_SPARK_Mode
22617 (Mode : SPARK_Mode_Type;
22618 Prag : Node_Id)
22620 begin
22621 SPARK_Mode := Mode;
22622 SPARK_Mode_Pragma := Prag;
22623 end Restore_SPARK_Mode;
22625 --------------------------------
22626 -- Returns_Unconstrained_Type --
22627 --------------------------------
22629 function Returns_Unconstrained_Type (Subp : Entity_Id) return Boolean is
22630 begin
22631 return Ekind (Subp) = E_Function
22632 and then not Is_Scalar_Type (Etype (Subp))
22633 and then not Is_Access_Type (Etype (Subp))
22634 and then not Is_Constrained (Etype (Subp));
22635 end Returns_Unconstrained_Type;
22637 ----------------------------
22638 -- Root_Type_Of_Full_View --
22639 ----------------------------
22641 function Root_Type_Of_Full_View (T : Entity_Id) return Entity_Id is
22642 Rtyp : constant Entity_Id := Root_Type (T);
22644 begin
22645 -- The root type of the full view may itself be a private type. Keep
22646 -- looking for the ultimate derivation parent.
22648 if Is_Private_Type (Rtyp) and then Present (Full_View (Rtyp)) then
22649 return Root_Type_Of_Full_View (Full_View (Rtyp));
22650 else
22651 return Rtyp;
22652 end if;
22653 end Root_Type_Of_Full_View;
22655 ---------------------------
22656 -- Safe_To_Capture_Value --
22657 ---------------------------
22659 function Safe_To_Capture_Value
22660 (N : Node_Id;
22661 Ent : Entity_Id;
22662 Cond : Boolean := False) return Boolean
22664 begin
22665 -- The only entities for which we track constant values are variables
22666 -- which are not renamings, constants, out parameters, and in out
22667 -- parameters, so check if we have this case.
22669 -- Note: it may seem odd to track constant values for constants, but in
22670 -- fact this routine is used for other purposes than simply capturing
22671 -- the value. In particular, the setting of Known[_Non]_Null.
22673 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
22674 or else
22675 Ekind_In (Ent, E_Constant, E_Out_Parameter, E_In_Out_Parameter)
22676 then
22677 null;
22679 -- For conditionals, we also allow loop parameters and all formals,
22680 -- including in parameters.
22682 elsif Cond and then Ekind_In (Ent, E_Loop_Parameter, E_In_Parameter) then
22683 null;
22685 -- For all other cases, not just unsafe, but impossible to capture
22686 -- Current_Value, since the above are the only entities which have
22687 -- Current_Value fields.
22689 else
22690 return False;
22691 end if;
22693 -- Skip if volatile or aliased, since funny things might be going on in
22694 -- these cases which we cannot necessarily track. Also skip any variable
22695 -- for which an address clause is given, or whose address is taken. Also
22696 -- never capture value of library level variables (an attempt to do so
22697 -- can occur in the case of package elaboration code).
22699 if Treat_As_Volatile (Ent)
22700 or else Is_Aliased (Ent)
22701 or else Present (Address_Clause (Ent))
22702 or else Address_Taken (Ent)
22703 or else (Is_Library_Level_Entity (Ent)
22704 and then Ekind (Ent) = E_Variable)
22705 then
22706 return False;
22707 end if;
22709 -- OK, all above conditions are met. We also require that the scope of
22710 -- the reference be the same as the scope of the entity, not counting
22711 -- packages and blocks and loops.
22713 declare
22714 E_Scope : constant Entity_Id := Scope (Ent);
22715 R_Scope : Entity_Id;
22717 begin
22718 R_Scope := Current_Scope;
22719 while R_Scope /= Standard_Standard loop
22720 exit when R_Scope = E_Scope;
22722 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
22723 return False;
22724 else
22725 R_Scope := Scope (R_Scope);
22726 end if;
22727 end loop;
22728 end;
22730 -- We also require that the reference does not appear in a context
22731 -- where it is not sure to be executed (i.e. a conditional context
22732 -- or an exception handler). We skip this if Cond is True, since the
22733 -- capturing of values from conditional tests handles this ok.
22735 if Cond then
22736 return True;
22737 end if;
22739 declare
22740 Desc : Node_Id;
22741 P : Node_Id;
22743 begin
22744 Desc := N;
22746 -- Seems dubious that case expressions are not handled here ???
22748 P := Parent (N);
22749 while Present (P) loop
22750 if Nkind (P) = N_If_Statement
22751 or else Nkind (P) = N_Case_Statement
22752 or else (Nkind (P) in N_Short_Circuit
22753 and then Desc = Right_Opnd (P))
22754 or else (Nkind (P) = N_If_Expression
22755 and then Desc /= First (Expressions (P)))
22756 or else Nkind (P) = N_Exception_Handler
22757 or else Nkind (P) = N_Selective_Accept
22758 or else Nkind (P) = N_Conditional_Entry_Call
22759 or else Nkind (P) = N_Timed_Entry_Call
22760 or else Nkind (P) = N_Asynchronous_Select
22761 then
22762 return False;
22764 else
22765 Desc := P;
22766 P := Parent (P);
22768 -- A special Ada 2012 case: the original node may be part
22769 -- of the else_actions of a conditional expression, in which
22770 -- case it might not have been expanded yet, and appears in
22771 -- a non-syntactic list of actions. In that case it is clearly
22772 -- not safe to save a value.
22774 if No (P)
22775 and then Is_List_Member (Desc)
22776 and then No (Parent (List_Containing (Desc)))
22777 then
22778 return False;
22779 end if;
22780 end if;
22781 end loop;
22782 end;
22784 -- OK, looks safe to set value
22786 return True;
22787 end Safe_To_Capture_Value;
22789 ---------------
22790 -- Same_Name --
22791 ---------------
22793 function Same_Name (N1, N2 : Node_Id) return Boolean is
22794 K1 : constant Node_Kind := Nkind (N1);
22795 K2 : constant Node_Kind := Nkind (N2);
22797 begin
22798 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
22799 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
22800 then
22801 return Chars (N1) = Chars (N2);
22803 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
22804 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
22805 then
22806 return Same_Name (Selector_Name (N1), Selector_Name (N2))
22807 and then Same_Name (Prefix (N1), Prefix (N2));
22809 else
22810 return False;
22811 end if;
22812 end Same_Name;
22814 -----------------
22815 -- Same_Object --
22816 -----------------
22818 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
22819 N1 : constant Node_Id := Original_Node (Node1);
22820 N2 : constant Node_Id := Original_Node (Node2);
22821 -- We do the tests on original nodes, since we are most interested
22822 -- in the original source, not any expansion that got in the way.
22824 K1 : constant Node_Kind := Nkind (N1);
22825 K2 : constant Node_Kind := Nkind (N2);
22827 begin
22828 -- First case, both are entities with same entity
22830 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
22831 declare
22832 EN1 : constant Entity_Id := Entity (N1);
22833 EN2 : constant Entity_Id := Entity (N2);
22834 begin
22835 if Present (EN1) and then Present (EN2)
22836 and then (Ekind_In (EN1, E_Variable, E_Constant)
22837 or else Is_Formal (EN1))
22838 and then EN1 = EN2
22839 then
22840 return True;
22841 end if;
22842 end;
22843 end if;
22845 -- Second case, selected component with same selector, same record
22847 if K1 = N_Selected_Component
22848 and then K2 = N_Selected_Component
22849 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
22850 then
22851 return Same_Object (Prefix (N1), Prefix (N2));
22853 -- Third case, indexed component with same subscripts, same array
22855 elsif K1 = N_Indexed_Component
22856 and then K2 = N_Indexed_Component
22857 and then Same_Object (Prefix (N1), Prefix (N2))
22858 then
22859 declare
22860 E1, E2 : Node_Id;
22861 begin
22862 E1 := First (Expressions (N1));
22863 E2 := First (Expressions (N2));
22864 while Present (E1) loop
22865 if not Same_Value (E1, E2) then
22866 return False;
22867 else
22868 Next (E1);
22869 Next (E2);
22870 end if;
22871 end loop;
22873 return True;
22874 end;
22876 -- Fourth case, slice of same array with same bounds
22878 elsif K1 = N_Slice
22879 and then K2 = N_Slice
22880 and then Nkind (Discrete_Range (N1)) = N_Range
22881 and then Nkind (Discrete_Range (N2)) = N_Range
22882 and then Same_Value (Low_Bound (Discrete_Range (N1)),
22883 Low_Bound (Discrete_Range (N2)))
22884 and then Same_Value (High_Bound (Discrete_Range (N1)),
22885 High_Bound (Discrete_Range (N2)))
22886 then
22887 return Same_Name (Prefix (N1), Prefix (N2));
22889 -- All other cases, not clearly the same object
22891 else
22892 return False;
22893 end if;
22894 end Same_Object;
22896 ---------------
22897 -- Same_Type --
22898 ---------------
22900 function Same_Type (T1, T2 : Entity_Id) return Boolean is
22901 begin
22902 if T1 = T2 then
22903 return True;
22905 elsif not Is_Constrained (T1)
22906 and then not Is_Constrained (T2)
22907 and then Base_Type (T1) = Base_Type (T2)
22908 then
22909 return True;
22911 -- For now don't bother with case of identical constraints, to be
22912 -- fiddled with later on perhaps (this is only used for optimization
22913 -- purposes, so it is not critical to do a best possible job)
22915 else
22916 return False;
22917 end if;
22918 end Same_Type;
22920 ----------------
22921 -- Same_Value --
22922 ----------------
22924 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
22925 begin
22926 if Compile_Time_Known_Value (Node1)
22927 and then Compile_Time_Known_Value (Node2)
22928 then
22929 -- Handle properly compile-time expressions that are not
22930 -- scalar.
22932 if Is_String_Type (Etype (Node1)) then
22933 return Expr_Value_S (Node1) = Expr_Value_S (Node2);
22935 else
22936 return Expr_Value (Node1) = Expr_Value (Node2);
22937 end if;
22939 elsif Same_Object (Node1, Node2) then
22940 return True;
22941 else
22942 return False;
22943 end if;
22944 end Same_Value;
22946 --------------------
22947 -- Set_SPARK_Mode --
22948 --------------------
22950 procedure Set_SPARK_Mode (Context : Entity_Id) is
22951 begin
22952 -- Do not consider illegal or partially decorated constructs
22954 if Ekind (Context) = E_Void or else Error_Posted (Context) then
22955 null;
22957 elsif Present (SPARK_Pragma (Context)) then
22958 Install_SPARK_Mode
22959 (Mode => Get_SPARK_Mode_From_Annotation (SPARK_Pragma (Context)),
22960 Prag => SPARK_Pragma (Context));
22961 end if;
22962 end Set_SPARK_Mode;
22964 -------------------------
22965 -- Scalar_Part_Present --
22966 -------------------------
22968 function Scalar_Part_Present (T : Entity_Id) return Boolean is
22969 C : Entity_Id;
22971 begin
22972 if Is_Scalar_Type (T) then
22973 return True;
22975 elsif Is_Array_Type (T) then
22976 return Scalar_Part_Present (Component_Type (T));
22978 elsif Is_Record_Type (T) or else Has_Discriminants (T) then
22979 C := First_Component_Or_Discriminant (T);
22980 while Present (C) loop
22981 if Scalar_Part_Present (Etype (C)) then
22982 return True;
22983 else
22984 Next_Component_Or_Discriminant (C);
22985 end if;
22986 end loop;
22987 end if;
22989 return False;
22990 end Scalar_Part_Present;
22992 ------------------------
22993 -- Scope_Is_Transient --
22994 ------------------------
22996 function Scope_Is_Transient return Boolean is
22997 begin
22998 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
22999 end Scope_Is_Transient;
23001 ------------------
23002 -- Scope_Within --
23003 ------------------
23005 function Scope_Within
23006 (Inner : Entity_Id;
23007 Outer : Entity_Id) return Boolean
23009 Curr : Entity_Id;
23011 begin
23012 Curr := Inner;
23013 while Present (Curr) and then Curr /= Standard_Standard loop
23014 Curr := Scope (Curr);
23016 if Curr = Outer then
23017 return True;
23018 end if;
23019 end loop;
23021 return False;
23022 end Scope_Within;
23024 --------------------------
23025 -- Scope_Within_Or_Same --
23026 --------------------------
23028 function Scope_Within_Or_Same
23029 (Inner : Entity_Id;
23030 Outer : Entity_Id) return Boolean
23032 Curr : Entity_Id;
23034 begin
23035 Curr := Inner;
23036 while Present (Curr) and then Curr /= Standard_Standard loop
23037 if Curr = Outer then
23038 return True;
23039 end if;
23041 Curr := Scope (Curr);
23042 end loop;
23044 return False;
23045 end Scope_Within_Or_Same;
23047 --------------------
23048 -- Set_Convention --
23049 --------------------
23051 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
23052 begin
23053 Basic_Set_Convention (E, Val);
23055 if Is_Type (E)
23056 and then Is_Access_Subprogram_Type (Base_Type (E))
23057 and then Has_Foreign_Convention (E)
23058 then
23059 Set_Can_Use_Internal_Rep (E, False);
23060 end if;
23062 -- If E is an object, including a component, and the type of E is an
23063 -- anonymous access type with no convention set, then also set the
23064 -- convention of the anonymous access type. We do not do this for
23065 -- anonymous protected types, since protected types always have the
23066 -- default convention.
23068 if Present (Etype (E))
23069 and then (Is_Object (E)
23071 -- Allow E_Void (happens for pragma Convention appearing
23072 -- in the middle of a record applying to a component)
23074 or else Ekind (E) = E_Void)
23075 then
23076 declare
23077 Typ : constant Entity_Id := Etype (E);
23079 begin
23080 if Ekind_In (Typ, E_Anonymous_Access_Type,
23081 E_Anonymous_Access_Subprogram_Type)
23082 and then not Has_Convention_Pragma (Typ)
23083 then
23084 Basic_Set_Convention (Typ, Val);
23085 Set_Has_Convention_Pragma (Typ);
23087 -- And for the access subprogram type, deal similarly with the
23088 -- designated E_Subprogram_Type, which is always internal.
23090 if Ekind (Typ) = E_Anonymous_Access_Subprogram_Type then
23091 declare
23092 Dtype : constant Entity_Id := Designated_Type (Typ);
23093 begin
23094 if Ekind (Dtype) = E_Subprogram_Type
23095 and then not Has_Convention_Pragma (Dtype)
23096 then
23097 Basic_Set_Convention (Dtype, Val);
23098 Set_Has_Convention_Pragma (Dtype);
23099 end if;
23100 end;
23101 end if;
23102 end if;
23103 end;
23104 end if;
23105 end Set_Convention;
23107 ------------------------
23108 -- Set_Current_Entity --
23109 ------------------------
23111 -- The given entity is to be set as the currently visible definition of its
23112 -- associated name (i.e. the Node_Id associated with its name). All we have
23113 -- to do is to get the name from the identifier, and then set the
23114 -- associated Node_Id to point to the given entity.
23116 procedure Set_Current_Entity (E : Entity_Id) is
23117 begin
23118 Set_Name_Entity_Id (Chars (E), E);
23119 end Set_Current_Entity;
23121 ---------------------------
23122 -- Set_Debug_Info_Needed --
23123 ---------------------------
23125 procedure Set_Debug_Info_Needed (T : Entity_Id) is
23127 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
23128 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
23129 -- Used to set debug info in a related node if not set already
23131 --------------------------------------
23132 -- Set_Debug_Info_Needed_If_Not_Set --
23133 --------------------------------------
23135 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
23136 begin
23137 if Present (E) and then not Needs_Debug_Info (E) then
23138 Set_Debug_Info_Needed (E);
23140 -- For a private type, indicate that the full view also needs
23141 -- debug information.
23143 if Is_Type (E)
23144 and then Is_Private_Type (E)
23145 and then Present (Full_View (E))
23146 then
23147 Set_Debug_Info_Needed (Full_View (E));
23148 end if;
23149 end if;
23150 end Set_Debug_Info_Needed_If_Not_Set;
23152 -- Start of processing for Set_Debug_Info_Needed
23154 begin
23155 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
23156 -- indicates that Debug_Info_Needed is never required for the entity.
23157 -- Nothing to do if entity comes from a predefined file. Library files
23158 -- are compiled without debug information, but inlined bodies of these
23159 -- routines may appear in user code, and debug information on them ends
23160 -- up complicating debugging the user code.
23162 if No (T)
23163 or else Debug_Info_Off (T)
23164 then
23165 return;
23167 elsif In_Inlined_Body and then In_Predefined_Unit (T) then
23168 Set_Needs_Debug_Info (T, False);
23169 end if;
23171 -- Set flag in entity itself. Note that we will go through the following
23172 -- circuitry even if the flag is already set on T. That's intentional,
23173 -- it makes sure that the flag will be set in subsidiary entities.
23175 Set_Needs_Debug_Info (T);
23177 -- Set flag on subsidiary entities if not set already
23179 if Is_Object (T) then
23180 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
23182 elsif Is_Type (T) then
23183 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
23185 if Is_Record_Type (T) then
23186 declare
23187 Ent : Entity_Id := First_Entity (T);
23188 begin
23189 while Present (Ent) loop
23190 Set_Debug_Info_Needed_If_Not_Set (Ent);
23191 Next_Entity (Ent);
23192 end loop;
23193 end;
23195 -- For a class wide subtype, we also need debug information
23196 -- for the equivalent type.
23198 if Ekind (T) = E_Class_Wide_Subtype then
23199 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
23200 end if;
23202 elsif Is_Array_Type (T) then
23203 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
23205 declare
23206 Indx : Node_Id := First_Index (T);
23207 begin
23208 while Present (Indx) loop
23209 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
23210 Indx := Next_Index (Indx);
23211 end loop;
23212 end;
23214 -- For a packed array type, we also need debug information for
23215 -- the type used to represent the packed array. Conversely, we
23216 -- also need it for the former if we need it for the latter.
23218 if Is_Packed (T) then
23219 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Impl_Type (T));
23220 end if;
23222 if Is_Packed_Array_Impl_Type (T) then
23223 Set_Debug_Info_Needed_If_Not_Set (Original_Array_Type (T));
23224 end if;
23226 elsif Is_Access_Type (T) then
23227 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
23229 elsif Is_Private_Type (T) then
23230 declare
23231 FV : constant Entity_Id := Full_View (T);
23233 begin
23234 Set_Debug_Info_Needed_If_Not_Set (FV);
23236 -- If the full view is itself a derived private type, we need
23237 -- debug information on its underlying type.
23239 if Present (FV)
23240 and then Is_Private_Type (FV)
23241 and then Present (Underlying_Full_View (FV))
23242 then
23243 Set_Needs_Debug_Info (Underlying_Full_View (FV));
23244 end if;
23245 end;
23247 elsif Is_Protected_Type (T) then
23248 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
23250 elsif Is_Scalar_Type (T) then
23252 -- If the subrange bounds are materialized by dedicated constant
23253 -- objects, also include them in the debug info to make sure the
23254 -- debugger can properly use them.
23256 if Present (Scalar_Range (T))
23257 and then Nkind (Scalar_Range (T)) = N_Range
23258 then
23259 declare
23260 Low_Bnd : constant Node_Id := Type_Low_Bound (T);
23261 High_Bnd : constant Node_Id := Type_High_Bound (T);
23263 begin
23264 if Is_Entity_Name (Low_Bnd) then
23265 Set_Debug_Info_Needed_If_Not_Set (Entity (Low_Bnd));
23266 end if;
23268 if Is_Entity_Name (High_Bnd) then
23269 Set_Debug_Info_Needed_If_Not_Set (Entity (High_Bnd));
23270 end if;
23271 end;
23272 end if;
23273 end if;
23274 end if;
23275 end Set_Debug_Info_Needed;
23277 ----------------------------
23278 -- Set_Entity_With_Checks --
23279 ----------------------------
23281 procedure Set_Entity_With_Checks (N : Node_Id; Val : Entity_Id) is
23282 Val_Actual : Entity_Id;
23283 Nod : Node_Id;
23284 Post_Node : Node_Id;
23286 begin
23287 -- Unconditionally set the entity
23289 Set_Entity (N, Val);
23291 -- The node to post on is the selector in the case of an expanded name,
23292 -- and otherwise the node itself.
23294 if Nkind (N) = N_Expanded_Name then
23295 Post_Node := Selector_Name (N);
23296 else
23297 Post_Node := N;
23298 end if;
23300 -- Check for violation of No_Fixed_IO
23302 if Restriction_Check_Required (No_Fixed_IO)
23303 and then
23304 ((RTU_Loaded (Ada_Text_IO)
23305 and then (Is_RTE (Val, RE_Decimal_IO)
23306 or else
23307 Is_RTE (Val, RE_Fixed_IO)))
23309 or else
23310 (RTU_Loaded (Ada_Wide_Text_IO)
23311 and then (Is_RTE (Val, RO_WT_Decimal_IO)
23312 or else
23313 Is_RTE (Val, RO_WT_Fixed_IO)))
23315 or else
23316 (RTU_Loaded (Ada_Wide_Wide_Text_IO)
23317 and then (Is_RTE (Val, RO_WW_Decimal_IO)
23318 or else
23319 Is_RTE (Val, RO_WW_Fixed_IO))))
23321 -- A special extra check, don't complain about a reference from within
23322 -- the Ada.Interrupts package itself!
23324 and then not In_Same_Extended_Unit (N, Val)
23325 then
23326 Check_Restriction (No_Fixed_IO, Post_Node);
23327 end if;
23329 -- Remaining checks are only done on source nodes. Note that we test
23330 -- for violation of No_Fixed_IO even on non-source nodes, because the
23331 -- cases for checking violations of this restriction are instantiations
23332 -- where the reference in the instance has Comes_From_Source False.
23334 if not Comes_From_Source (N) then
23335 return;
23336 end if;
23338 -- Check for violation of No_Abort_Statements, which is triggered by
23339 -- call to Ada.Task_Identification.Abort_Task.
23341 if Restriction_Check_Required (No_Abort_Statements)
23342 and then (Is_RTE (Val, RE_Abort_Task))
23344 -- A special extra check, don't complain about a reference from within
23345 -- the Ada.Task_Identification package itself!
23347 and then not In_Same_Extended_Unit (N, Val)
23348 then
23349 Check_Restriction (No_Abort_Statements, Post_Node);
23350 end if;
23352 if Val = Standard_Long_Long_Integer then
23353 Check_Restriction (No_Long_Long_Integers, Post_Node);
23354 end if;
23356 -- Check for violation of No_Dynamic_Attachment
23358 if Restriction_Check_Required (No_Dynamic_Attachment)
23359 and then RTU_Loaded (Ada_Interrupts)
23360 and then (Is_RTE (Val, RE_Is_Reserved) or else
23361 Is_RTE (Val, RE_Is_Attached) or else
23362 Is_RTE (Val, RE_Current_Handler) or else
23363 Is_RTE (Val, RE_Attach_Handler) or else
23364 Is_RTE (Val, RE_Exchange_Handler) or else
23365 Is_RTE (Val, RE_Detach_Handler) or else
23366 Is_RTE (Val, RE_Reference))
23368 -- A special extra check, don't complain about a reference from within
23369 -- the Ada.Interrupts package itself!
23371 and then not In_Same_Extended_Unit (N, Val)
23372 then
23373 Check_Restriction (No_Dynamic_Attachment, Post_Node);
23374 end if;
23376 -- Check for No_Implementation_Identifiers
23378 if Restriction_Check_Required (No_Implementation_Identifiers) then
23380 -- We have an implementation defined entity if it is marked as
23381 -- implementation defined, or is defined in a package marked as
23382 -- implementation defined. However, library packages themselves
23383 -- are excluded (we don't want to flag Interfaces itself, just
23384 -- the entities within it).
23386 if (Is_Implementation_Defined (Val)
23387 or else
23388 (Present (Scope (Val))
23389 and then Is_Implementation_Defined (Scope (Val))))
23390 and then not (Ekind_In (Val, E_Package, E_Generic_Package)
23391 and then Is_Library_Level_Entity (Val))
23392 then
23393 Check_Restriction (No_Implementation_Identifiers, Post_Node);
23394 end if;
23395 end if;
23397 -- Do the style check
23399 if Style_Check
23400 and then not Suppress_Style_Checks (Val)
23401 and then not In_Instance
23402 then
23403 if Nkind (N) = N_Identifier then
23404 Nod := N;
23405 elsif Nkind (N) = N_Expanded_Name then
23406 Nod := Selector_Name (N);
23407 else
23408 return;
23409 end if;
23411 -- A special situation arises for derived operations, where we want
23412 -- to do the check against the parent (since the Sloc of the derived
23413 -- operation points to the derived type declaration itself).
23415 Val_Actual := Val;
23416 while not Comes_From_Source (Val_Actual)
23417 and then Nkind (Val_Actual) in N_Entity
23418 and then (Ekind (Val_Actual) = E_Enumeration_Literal
23419 or else Is_Subprogram_Or_Generic_Subprogram (Val_Actual))
23420 and then Present (Alias (Val_Actual))
23421 loop
23422 Val_Actual := Alias (Val_Actual);
23423 end loop;
23425 -- Renaming declarations for generic actuals do not come from source,
23426 -- and have a different name from that of the entity they rename, so
23427 -- there is no style check to perform here.
23429 if Chars (Nod) = Chars (Val_Actual) then
23430 Style.Check_Identifier (Nod, Val_Actual);
23431 end if;
23432 end if;
23434 Set_Entity (N, Val);
23435 end Set_Entity_With_Checks;
23437 ------------------------
23438 -- Set_Name_Entity_Id --
23439 ------------------------
23441 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
23442 begin
23443 Set_Name_Table_Int (Id, Int (Val));
23444 end Set_Name_Entity_Id;
23446 ---------------------
23447 -- Set_Next_Actual --
23448 ---------------------
23450 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
23451 begin
23452 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
23453 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
23454 end if;
23455 end Set_Next_Actual;
23457 ----------------------------------
23458 -- Set_Optimize_Alignment_Flags --
23459 ----------------------------------
23461 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
23462 begin
23463 if Optimize_Alignment = 'S' then
23464 Set_Optimize_Alignment_Space (E);
23465 elsif Optimize_Alignment = 'T' then
23466 Set_Optimize_Alignment_Time (E);
23467 end if;
23468 end Set_Optimize_Alignment_Flags;
23470 -----------------------
23471 -- Set_Public_Status --
23472 -----------------------
23474 procedure Set_Public_Status (Id : Entity_Id) is
23475 S : constant Entity_Id := Current_Scope;
23477 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
23478 -- Determines if E is defined within handled statement sequence or
23479 -- an if statement, returns True if so, False otherwise.
23481 ----------------------
23482 -- Within_HSS_Or_If --
23483 ----------------------
23485 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
23486 N : Node_Id;
23487 begin
23488 N := Declaration_Node (E);
23489 loop
23490 N := Parent (N);
23492 if No (N) then
23493 return False;
23495 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
23496 N_If_Statement)
23497 then
23498 return True;
23499 end if;
23500 end loop;
23501 end Within_HSS_Or_If;
23503 -- Start of processing for Set_Public_Status
23505 begin
23506 -- Everything in the scope of Standard is public
23508 if S = Standard_Standard then
23509 Set_Is_Public (Id);
23511 -- Entity is definitely not public if enclosing scope is not public
23513 elsif not Is_Public (S) then
23514 return;
23516 -- An object or function declaration that occurs in a handled sequence
23517 -- of statements or within an if statement is the declaration for a
23518 -- temporary object or local subprogram generated by the expander. It
23519 -- never needs to be made public and furthermore, making it public can
23520 -- cause back end problems.
23522 elsif Nkind_In (Parent (Id), N_Object_Declaration,
23523 N_Function_Specification)
23524 and then Within_HSS_Or_If (Id)
23525 then
23526 return;
23528 -- Entities in public packages or records are public
23530 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
23531 Set_Is_Public (Id);
23533 -- The bounds of an entry family declaration can generate object
23534 -- declarations that are visible to the back-end, e.g. in the
23535 -- the declaration of a composite type that contains tasks.
23537 elsif Is_Concurrent_Type (S)
23538 and then not Has_Completion (S)
23539 and then Nkind (Parent (Id)) = N_Object_Declaration
23540 then
23541 Set_Is_Public (Id);
23542 end if;
23543 end Set_Public_Status;
23545 -----------------------------
23546 -- Set_Referenced_Modified --
23547 -----------------------------
23549 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
23550 Pref : Node_Id;
23552 begin
23553 -- Deal with indexed or selected component where prefix is modified
23555 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
23556 Pref := Prefix (N);
23558 -- If prefix is access type, then it is the designated object that is
23559 -- being modified, which means we have no entity to set the flag on.
23561 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
23562 return;
23564 -- Otherwise chase the prefix
23566 else
23567 Set_Referenced_Modified (Pref, Out_Param);
23568 end if;
23570 -- Otherwise see if we have an entity name (only other case to process)
23572 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
23573 Set_Referenced_As_LHS (Entity (N), not Out_Param);
23574 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
23575 end if;
23576 end Set_Referenced_Modified;
23578 ------------------
23579 -- Set_Rep_Info --
23580 ------------------
23582 procedure Set_Rep_Info (T1 : Entity_Id; T2 : Entity_Id) is
23583 begin
23584 Set_Is_Atomic (T1, Is_Atomic (T2));
23585 Set_Is_Independent (T1, Is_Independent (T2));
23586 Set_Is_Volatile_Full_Access (T1, Is_Volatile_Full_Access (T2));
23588 if Is_Base_Type (T1) then
23589 Set_Is_Volatile (T1, Is_Volatile (T2));
23590 end if;
23591 end Set_Rep_Info;
23593 ----------------------------
23594 -- Set_Scope_Is_Transient --
23595 ----------------------------
23597 procedure Set_Scope_Is_Transient (V : Boolean := True) is
23598 begin
23599 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
23600 end Set_Scope_Is_Transient;
23602 -------------------
23603 -- Set_Size_Info --
23604 -------------------
23606 procedure Set_Size_Info (T1, T2 : Entity_Id) is
23607 begin
23608 -- We copy Esize, but not RM_Size, since in general RM_Size is
23609 -- subtype specific and does not get inherited by all subtypes.
23611 Set_Esize (T1, Esize (T2));
23612 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
23614 if Is_Discrete_Or_Fixed_Point_Type (T1)
23615 and then
23616 Is_Discrete_Or_Fixed_Point_Type (T2)
23617 then
23618 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
23619 end if;
23621 Set_Alignment (T1, Alignment (T2));
23622 end Set_Size_Info;
23624 ------------------------------
23625 -- Should_Ignore_Pragma_Par --
23626 ------------------------------
23628 function Should_Ignore_Pragma_Par (Prag_Name : Name_Id) return Boolean is
23629 pragma Assert (Compiler_State = Parsing);
23630 -- This one can't work during semantic analysis, because we don't have a
23631 -- correct Current_Source_File.
23633 Result : constant Boolean :=
23634 Get_Name_Table_Boolean3 (Prag_Name)
23635 and then not Is_Internal_File_Name
23636 (File_Name (Current_Source_File));
23637 begin
23638 return Result;
23639 end Should_Ignore_Pragma_Par;
23641 ------------------------------
23642 -- Should_Ignore_Pragma_Sem --
23643 ------------------------------
23645 function Should_Ignore_Pragma_Sem (N : Node_Id) return Boolean is
23646 pragma Assert (Compiler_State = Analyzing);
23647 Prag_Name : constant Name_Id := Pragma_Name (N);
23648 Result : constant Boolean :=
23649 Get_Name_Table_Boolean3 (Prag_Name)
23650 and then not In_Internal_Unit (N);
23652 begin
23653 return Result;
23654 end Should_Ignore_Pragma_Sem;
23656 --------------------
23657 -- Static_Boolean --
23658 --------------------
23660 function Static_Boolean (N : Node_Id) return Uint is
23661 begin
23662 Analyze_And_Resolve (N, Standard_Boolean);
23664 if N = Error
23665 or else Error_Posted (N)
23666 or else Etype (N) = Any_Type
23667 then
23668 return No_Uint;
23669 end if;
23671 if Is_OK_Static_Expression (N) then
23672 if not Raises_Constraint_Error (N) then
23673 return Expr_Value (N);
23674 else
23675 return No_Uint;
23676 end if;
23678 elsif Etype (N) = Any_Type then
23679 return No_Uint;
23681 else
23682 Flag_Non_Static_Expr
23683 ("static boolean expression required here", N);
23684 return No_Uint;
23685 end if;
23686 end Static_Boolean;
23688 --------------------
23689 -- Static_Integer --
23690 --------------------
23692 function Static_Integer (N : Node_Id) return Uint is
23693 begin
23694 Analyze_And_Resolve (N, Any_Integer);
23696 if N = Error
23697 or else Error_Posted (N)
23698 or else Etype (N) = Any_Type
23699 then
23700 return No_Uint;
23701 end if;
23703 if Is_OK_Static_Expression (N) then
23704 if not Raises_Constraint_Error (N) then
23705 return Expr_Value (N);
23706 else
23707 return No_Uint;
23708 end if;
23710 elsif Etype (N) = Any_Type then
23711 return No_Uint;
23713 else
23714 Flag_Non_Static_Expr
23715 ("static integer expression required here", N);
23716 return No_Uint;
23717 end if;
23718 end Static_Integer;
23720 --------------------------
23721 -- Statically_Different --
23722 --------------------------
23724 function Statically_Different (E1, E2 : Node_Id) return Boolean is
23725 R1 : constant Node_Id := Get_Referenced_Object (E1);
23726 R2 : constant Node_Id := Get_Referenced_Object (E2);
23727 begin
23728 return Is_Entity_Name (R1)
23729 and then Is_Entity_Name (R2)
23730 and then Entity (R1) /= Entity (R2)
23731 and then not Is_Formal (Entity (R1))
23732 and then not Is_Formal (Entity (R2));
23733 end Statically_Different;
23735 --------------------------------------
23736 -- Subject_To_Loop_Entry_Attributes --
23737 --------------------------------------
23739 function Subject_To_Loop_Entry_Attributes (N : Node_Id) return Boolean is
23740 Stmt : Node_Id;
23742 begin
23743 Stmt := N;
23745 -- The expansion mechanism transform a loop subject to at least one
23746 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
23747 -- the conditional part.
23749 if Nkind_In (Stmt, N_Block_Statement, N_If_Statement)
23750 and then Nkind (Original_Node (N)) = N_Loop_Statement
23751 then
23752 Stmt := Original_Node (N);
23753 end if;
23755 return
23756 Nkind (Stmt) = N_Loop_Statement
23757 and then Present (Identifier (Stmt))
23758 and then Present (Entity (Identifier (Stmt)))
23759 and then Has_Loop_Entry_Attributes (Entity (Identifier (Stmt)));
23760 end Subject_To_Loop_Entry_Attributes;
23762 -----------------------------
23763 -- Subprogram_Access_Level --
23764 -----------------------------
23766 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
23767 begin
23768 if Present (Alias (Subp)) then
23769 return Subprogram_Access_Level (Alias (Subp));
23770 else
23771 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
23772 end if;
23773 end Subprogram_Access_Level;
23775 ---------------------
23776 -- Subprogram_Name --
23777 ---------------------
23779 function Subprogram_Name (N : Node_Id) return String is
23780 Buf : Bounded_String;
23781 Ent : Node_Id := N;
23782 Nod : Node_Id;
23784 begin
23785 while Present (Ent) loop
23786 case Nkind (Ent) is
23787 when N_Subprogram_Body =>
23788 Ent := Defining_Unit_Name (Specification (Ent));
23789 exit;
23791 when N_Subprogram_Declaration =>
23792 Nod := Corresponding_Body (Ent);
23794 if Present (Nod) then
23795 Ent := Nod;
23796 else
23797 Ent := Defining_Unit_Name (Specification (Ent));
23798 end if;
23800 exit;
23802 when N_Subprogram_Instantiation
23803 | N_Package_Body
23804 | N_Package_Specification
23806 Ent := Defining_Unit_Name (Ent);
23807 exit;
23809 when N_Protected_Type_Declaration =>
23810 Ent := Corresponding_Body (Ent);
23811 exit;
23813 when N_Protected_Body
23814 | N_Task_Body
23816 Ent := Defining_Identifier (Ent);
23817 exit;
23819 when others =>
23820 null;
23821 end case;
23823 Ent := Parent (Ent);
23824 end loop;
23826 if No (Ent) then
23827 return "unknown subprogram:unknown file:0:0";
23828 end if;
23830 -- If the subprogram is a child unit, use its simple name to start the
23831 -- construction of the fully qualified name.
23833 if Nkind (Ent) = N_Defining_Program_Unit_Name then
23834 Ent := Defining_Identifier (Ent);
23835 end if;
23837 Append_Entity_Name (Buf, Ent);
23839 -- Append homonym number if needed
23841 if Nkind (N) in N_Entity and then Has_Homonym (N) then
23842 declare
23843 H : Entity_Id := Homonym (N);
23844 Nr : Nat := 1;
23846 begin
23847 while Present (H) loop
23848 if Scope (H) = Scope (N) then
23849 Nr := Nr + 1;
23850 end if;
23852 H := Homonym (H);
23853 end loop;
23855 if Nr > 1 then
23856 Append (Buf, '#');
23857 Append (Buf, Nr);
23858 end if;
23859 end;
23860 end if;
23862 -- Append source location of Ent to Buf so that the string will
23863 -- look like "subp:file:line:col".
23865 declare
23866 Loc : constant Source_Ptr := Sloc (Ent);
23867 begin
23868 Append (Buf, ':');
23869 Append (Buf, Reference_Name (Get_Source_File_Index (Loc)));
23870 Append (Buf, ':');
23871 Append (Buf, Nat (Get_Logical_Line_Number (Loc)));
23872 Append (Buf, ':');
23873 Append (Buf, Nat (Get_Column_Number (Loc)));
23874 end;
23876 return +Buf;
23877 end Subprogram_Name;
23879 -------------------------------
23880 -- Support_Atomic_Primitives --
23881 -------------------------------
23883 function Support_Atomic_Primitives (Typ : Entity_Id) return Boolean is
23884 Size : Int;
23886 begin
23887 -- Verify the alignment of Typ is known
23889 if not Known_Alignment (Typ) then
23890 return False;
23891 end if;
23893 if Known_Static_Esize (Typ) then
23894 Size := UI_To_Int (Esize (Typ));
23896 -- If the Esize (Object_Size) is unknown at compile time, look at the
23897 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
23899 elsif Known_Static_RM_Size (Typ) then
23900 Size := UI_To_Int (RM_Size (Typ));
23902 -- Otherwise, the size is considered to be unknown.
23904 else
23905 return False;
23906 end if;
23908 -- Check that the size of the component is 8, 16, 32, or 64 bits and
23909 -- that Typ is properly aligned.
23911 case Size is
23912 when 8 | 16 | 32 | 64 =>
23913 return Size = UI_To_Int (Alignment (Typ)) * 8;
23915 when others =>
23916 return False;
23917 end case;
23918 end Support_Atomic_Primitives;
23920 -----------------
23921 -- Trace_Scope --
23922 -----------------
23924 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
23925 begin
23926 if Debug_Flag_W then
23927 for J in 0 .. Scope_Stack.Last loop
23928 Write_Str (" ");
23929 end loop;
23931 Write_Str (Msg);
23932 Write_Name (Chars (E));
23933 Write_Str (" from ");
23934 Write_Location (Sloc (N));
23935 Write_Eol;
23936 end if;
23937 end Trace_Scope;
23939 -----------------------
23940 -- Transfer_Entities --
23941 -----------------------
23943 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
23944 procedure Set_Public_Status_Of (Id : Entity_Id);
23945 -- Set the Is_Public attribute of arbitrary entity Id by calling routine
23946 -- Set_Public_Status. If successful and Id denotes a record type, set
23947 -- the Is_Public attribute of its fields.
23949 --------------------------
23950 -- Set_Public_Status_Of --
23951 --------------------------
23953 procedure Set_Public_Status_Of (Id : Entity_Id) is
23954 Field : Entity_Id;
23956 begin
23957 if not Is_Public (Id) then
23958 Set_Public_Status (Id);
23960 -- When the input entity is a public record type, ensure that all
23961 -- its internal fields are also exposed to the linker. The fields
23962 -- of a class-wide type are never made public.
23964 if Is_Public (Id)
23965 and then Is_Record_Type (Id)
23966 and then not Is_Class_Wide_Type (Id)
23967 then
23968 Field := First_Entity (Id);
23969 while Present (Field) loop
23970 Set_Is_Public (Field);
23971 Next_Entity (Field);
23972 end loop;
23973 end if;
23974 end if;
23975 end Set_Public_Status_Of;
23977 -- Local variables
23979 Full_Id : Entity_Id;
23980 Id : Entity_Id;
23982 -- Start of processing for Transfer_Entities
23984 begin
23985 Id := First_Entity (From);
23987 if Present (Id) then
23989 -- Merge the entity chain of the source scope with that of the
23990 -- destination scope.
23992 if Present (Last_Entity (To)) then
23993 Set_Next_Entity (Last_Entity (To), Id);
23994 else
23995 Set_First_Entity (To, Id);
23996 end if;
23998 Set_Last_Entity (To, Last_Entity (From));
24000 -- Inspect the entities of the source scope and update their Scope
24001 -- attribute.
24003 while Present (Id) loop
24004 Set_Scope (Id, To);
24005 Set_Public_Status_Of (Id);
24007 -- Handle an internally generated full view for a private type
24009 if Is_Private_Type (Id)
24010 and then Present (Full_View (Id))
24011 and then Is_Itype (Full_View (Id))
24012 then
24013 Full_Id := Full_View (Id);
24015 Set_Scope (Full_Id, To);
24016 Set_Public_Status_Of (Full_Id);
24017 end if;
24019 Next_Entity (Id);
24020 end loop;
24022 Set_First_Entity (From, Empty);
24023 Set_Last_Entity (From, Empty);
24024 end if;
24025 end Transfer_Entities;
24027 -----------------------
24028 -- Type_Access_Level --
24029 -----------------------
24031 function Type_Access_Level (Typ : Entity_Id) return Uint is
24032 Btyp : Entity_Id;
24034 begin
24035 Btyp := Base_Type (Typ);
24037 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
24038 -- simply use the level where the type is declared. This is true for
24039 -- stand-alone object declarations, and for anonymous access types
24040 -- associated with components the level is the same as that of the
24041 -- enclosing composite type. However, special treatment is needed for
24042 -- the cases of access parameters, return objects of an anonymous access
24043 -- type, and, in Ada 95, access discriminants of limited types.
24045 if Is_Access_Type (Btyp) then
24046 if Ekind (Btyp) = E_Anonymous_Access_Type then
24048 -- If the type is a nonlocal anonymous access type (such as for
24049 -- an access parameter) we treat it as being declared at the
24050 -- library level to ensure that names such as X.all'access don't
24051 -- fail static accessibility checks.
24053 if not Is_Local_Anonymous_Access (Typ) then
24054 return Scope_Depth (Standard_Standard);
24056 -- If this is a return object, the accessibility level is that of
24057 -- the result subtype of the enclosing function. The test here is
24058 -- little complicated, because we have to account for extended
24059 -- return statements that have been rewritten as blocks, in which
24060 -- case we have to find and the Is_Return_Object attribute of the
24061 -- itype's associated object. It would be nice to find a way to
24062 -- simplify this test, but it doesn't seem worthwhile to add a new
24063 -- flag just for purposes of this test. ???
24065 elsif Ekind (Scope (Btyp)) = E_Return_Statement
24066 or else
24067 (Is_Itype (Btyp)
24068 and then Nkind (Associated_Node_For_Itype (Btyp)) =
24069 N_Object_Declaration
24070 and then Is_Return_Object
24071 (Defining_Identifier
24072 (Associated_Node_For_Itype (Btyp))))
24073 then
24074 declare
24075 Scop : Entity_Id;
24077 begin
24078 Scop := Scope (Scope (Btyp));
24079 while Present (Scop) loop
24080 exit when Ekind (Scop) = E_Function;
24081 Scop := Scope (Scop);
24082 end loop;
24084 -- Treat the return object's type as having the level of the
24085 -- function's result subtype (as per RM05-6.5(5.3/2)).
24087 return Type_Access_Level (Etype (Scop));
24088 end;
24089 end if;
24090 end if;
24092 Btyp := Root_Type (Btyp);
24094 -- The accessibility level of anonymous access types associated with
24095 -- discriminants is that of the current instance of the type, and
24096 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
24098 -- AI-402: access discriminants have accessibility based on the
24099 -- object rather than the type in Ada 2005, so the above paragraph
24100 -- doesn't apply.
24102 -- ??? Needs completion with rules from AI-416
24104 if Ada_Version <= Ada_95
24105 and then Ekind (Typ) = E_Anonymous_Access_Type
24106 and then Present (Associated_Node_For_Itype (Typ))
24107 and then Nkind (Associated_Node_For_Itype (Typ)) =
24108 N_Discriminant_Specification
24109 then
24110 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
24111 end if;
24112 end if;
24114 -- Return library level for a generic formal type. This is done because
24115 -- RM(10.3.2) says that "The statically deeper relationship does not
24116 -- apply to ... a descendant of a generic formal type". Rather than
24117 -- checking at each point where a static accessibility check is
24118 -- performed to see if we are dealing with a formal type, this rule is
24119 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
24120 -- return extreme values for a formal type; Deepest_Type_Access_Level
24121 -- returns Int'Last. By calling the appropriate function from among the
24122 -- two, we ensure that the static accessibility check will pass if we
24123 -- happen to run into a formal type. More specifically, we should call
24124 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
24125 -- call occurs as part of a static accessibility check and the error
24126 -- case is the case where the type's level is too shallow (as opposed
24127 -- to too deep).
24129 if Is_Generic_Type (Root_Type (Btyp)) then
24130 return Scope_Depth (Standard_Standard);
24131 end if;
24133 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
24134 end Type_Access_Level;
24136 ------------------------------------
24137 -- Type_Without_Stream_Operation --
24138 ------------------------------------
24140 function Type_Without_Stream_Operation
24141 (T : Entity_Id;
24142 Op : TSS_Name_Type := TSS_Null) return Entity_Id
24144 BT : constant Entity_Id := Base_Type (T);
24145 Op_Missing : Boolean;
24147 begin
24148 if not Restriction_Active (No_Default_Stream_Attributes) then
24149 return Empty;
24150 end if;
24152 if Is_Elementary_Type (T) then
24153 if Op = TSS_Null then
24154 Op_Missing :=
24155 No (TSS (BT, TSS_Stream_Read))
24156 or else No (TSS (BT, TSS_Stream_Write));
24158 else
24159 Op_Missing := No (TSS (BT, Op));
24160 end if;
24162 if Op_Missing then
24163 return T;
24164 else
24165 return Empty;
24166 end if;
24168 elsif Is_Array_Type (T) then
24169 return Type_Without_Stream_Operation (Component_Type (T), Op);
24171 elsif Is_Record_Type (T) then
24172 declare
24173 Comp : Entity_Id;
24174 C_Typ : Entity_Id;
24176 begin
24177 Comp := First_Component (T);
24178 while Present (Comp) loop
24179 C_Typ := Type_Without_Stream_Operation (Etype (Comp), Op);
24181 if Present (C_Typ) then
24182 return C_Typ;
24183 end if;
24185 Next_Component (Comp);
24186 end loop;
24188 return Empty;
24189 end;
24191 elsif Is_Private_Type (T) and then Present (Full_View (T)) then
24192 return Type_Without_Stream_Operation (Full_View (T), Op);
24193 else
24194 return Empty;
24195 end if;
24196 end Type_Without_Stream_Operation;
24198 ----------------------------
24199 -- Unique_Defining_Entity --
24200 ----------------------------
24202 function Unique_Defining_Entity (N : Node_Id) return Entity_Id is
24203 begin
24204 return Unique_Entity (Defining_Entity (N));
24205 end Unique_Defining_Entity;
24207 -------------------
24208 -- Unique_Entity --
24209 -------------------
24211 function Unique_Entity (E : Entity_Id) return Entity_Id is
24212 U : Entity_Id := E;
24213 P : Node_Id;
24215 begin
24216 case Ekind (E) is
24217 when E_Constant =>
24218 if Present (Full_View (E)) then
24219 U := Full_View (E);
24220 end if;
24222 when Entry_Kind =>
24223 if Nkind (Parent (E)) = N_Entry_Body then
24224 declare
24225 Prot_Item : Entity_Id;
24226 Prot_Type : Entity_Id;
24228 begin
24229 if Ekind (E) = E_Entry then
24230 Prot_Type := Scope (E);
24232 -- Bodies of entry families are nested within an extra scope
24233 -- that contains an entry index declaration.
24235 else
24236 Prot_Type := Scope (Scope (E));
24237 end if;
24239 -- A protected type may be declared as a private type, in
24240 -- which case we need to get its full view.
24242 if Is_Private_Type (Prot_Type) then
24243 Prot_Type := Full_View (Prot_Type);
24244 end if;
24246 -- Full view may not be present on error, in which case
24247 -- return E by default.
24249 if Present (Prot_Type) then
24250 pragma Assert (Ekind (Prot_Type) = E_Protected_Type);
24252 -- Traverse the entity list of the protected type and
24253 -- locate an entry declaration which matches the entry
24254 -- body.
24256 Prot_Item := First_Entity (Prot_Type);
24257 while Present (Prot_Item) loop
24258 if Ekind (Prot_Item) in Entry_Kind
24259 and then Corresponding_Body (Parent (Prot_Item)) = E
24260 then
24261 U := Prot_Item;
24262 exit;
24263 end if;
24265 Next_Entity (Prot_Item);
24266 end loop;
24267 end if;
24268 end;
24269 end if;
24271 when Formal_Kind =>
24272 if Present (Spec_Entity (E)) then
24273 U := Spec_Entity (E);
24274 end if;
24276 when E_Package_Body =>
24277 P := Parent (E);
24279 if Nkind (P) = N_Defining_Program_Unit_Name then
24280 P := Parent (P);
24281 end if;
24283 if Nkind (P) = N_Package_Body
24284 and then Present (Corresponding_Spec (P))
24285 then
24286 U := Corresponding_Spec (P);
24288 elsif Nkind (P) = N_Package_Body_Stub
24289 and then Present (Corresponding_Spec_Of_Stub (P))
24290 then
24291 U := Corresponding_Spec_Of_Stub (P);
24292 end if;
24294 when E_Protected_Body =>
24295 P := Parent (E);
24297 if Nkind (P) = N_Protected_Body
24298 and then Present (Corresponding_Spec (P))
24299 then
24300 U := Corresponding_Spec (P);
24302 elsif Nkind (P) = N_Protected_Body_Stub
24303 and then Present (Corresponding_Spec_Of_Stub (P))
24304 then
24305 U := Corresponding_Spec_Of_Stub (P);
24307 if Is_Single_Protected_Object (U) then
24308 U := Etype (U);
24309 end if;
24310 end if;
24312 if Is_Private_Type (U) then
24313 U := Full_View (U);
24314 end if;
24316 when E_Subprogram_Body =>
24317 P := Parent (E);
24319 if Nkind (P) = N_Defining_Program_Unit_Name then
24320 P := Parent (P);
24321 end if;
24323 P := Parent (P);
24325 if Nkind (P) = N_Subprogram_Body
24326 and then Present (Corresponding_Spec (P))
24327 then
24328 U := Corresponding_Spec (P);
24330 elsif Nkind (P) = N_Subprogram_Body_Stub
24331 and then Present (Corresponding_Spec_Of_Stub (P))
24332 then
24333 U := Corresponding_Spec_Of_Stub (P);
24335 elsif Nkind (P) = N_Subprogram_Renaming_Declaration then
24336 U := Corresponding_Spec (P);
24337 end if;
24339 when E_Task_Body =>
24340 P := Parent (E);
24342 if Nkind (P) = N_Task_Body
24343 and then Present (Corresponding_Spec (P))
24344 then
24345 U := Corresponding_Spec (P);
24347 elsif Nkind (P) = N_Task_Body_Stub
24348 and then Present (Corresponding_Spec_Of_Stub (P))
24349 then
24350 U := Corresponding_Spec_Of_Stub (P);
24352 if Is_Single_Task_Object (U) then
24353 U := Etype (U);
24354 end if;
24355 end if;
24357 if Is_Private_Type (U) then
24358 U := Full_View (U);
24359 end if;
24361 when Type_Kind =>
24362 if Present (Full_View (E)) then
24363 U := Full_View (E);
24364 end if;
24366 when others =>
24367 null;
24368 end case;
24370 return U;
24371 end Unique_Entity;
24373 -----------------
24374 -- Unique_Name --
24375 -----------------
24377 function Unique_Name (E : Entity_Id) return String is
24379 -- Names in E_Subprogram_Body or E_Package_Body entities are not
24380 -- reliable, as they may not include the overloading suffix. Instead,
24381 -- when looking for the name of E or one of its enclosing scope, we get
24382 -- the name of the corresponding Unique_Entity.
24384 U : constant Entity_Id := Unique_Entity (E);
24386 function This_Name return String;
24388 ---------------
24389 -- This_Name --
24390 ---------------
24392 function This_Name return String is
24393 begin
24394 return Get_Name_String (Chars (U));
24395 end This_Name;
24397 -- Start of processing for Unique_Name
24399 begin
24400 if E = Standard_Standard
24401 or else Has_Fully_Qualified_Name (E)
24402 then
24403 return This_Name;
24405 elsif Ekind (E) = E_Enumeration_Literal then
24406 return Unique_Name (Etype (E)) & "__" & This_Name;
24408 else
24409 declare
24410 S : constant Entity_Id := Scope (U);
24411 pragma Assert (Present (S));
24413 begin
24414 -- Prefix names of predefined types with standard__, but leave
24415 -- names of user-defined packages and subprograms without prefix
24416 -- (even if technically they are nested in the Standard package).
24418 if S = Standard_Standard then
24419 if Ekind (U) = E_Package or else Is_Subprogram (U) then
24420 return This_Name;
24421 else
24422 return Unique_Name (S) & "__" & This_Name;
24423 end if;
24425 -- For intances of generic subprograms use the name of the related
24426 -- instace and skip the scope of its wrapper package.
24428 elsif Is_Wrapper_Package (S) then
24429 pragma Assert (Scope (S) = Scope (Related_Instance (S)));
24430 -- Wrapper package and the instantiation are in the same scope
24432 declare
24433 Enclosing_Name : constant String :=
24434 Unique_Name (Scope (S)) & "__" &
24435 Get_Name_String (Chars (Related_Instance (S)));
24437 begin
24438 if Is_Subprogram (U)
24439 and then not Is_Generic_Actual_Subprogram (U)
24440 then
24441 return Enclosing_Name;
24442 else
24443 return Enclosing_Name & "__" & This_Name;
24444 end if;
24445 end;
24447 else
24448 return Unique_Name (S) & "__" & This_Name;
24449 end if;
24450 end;
24451 end if;
24452 end Unique_Name;
24454 ---------------------
24455 -- Unit_Is_Visible --
24456 ---------------------
24458 function Unit_Is_Visible (U : Entity_Id) return Boolean is
24459 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
24460 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
24462 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
24463 -- For a child unit, check whether unit appears in a with_clause
24464 -- of a parent.
24466 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
24467 -- Scan the context clause of one compilation unit looking for a
24468 -- with_clause for the unit in question.
24470 ----------------------------
24471 -- Unit_In_Parent_Context --
24472 ----------------------------
24474 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
24475 begin
24476 if Unit_In_Context (Par_Unit) then
24477 return True;
24479 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
24480 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
24482 else
24483 return False;
24484 end if;
24485 end Unit_In_Parent_Context;
24487 ---------------------
24488 -- Unit_In_Context --
24489 ---------------------
24491 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
24492 Clause : Node_Id;
24494 begin
24495 Clause := First (Context_Items (Comp_Unit));
24496 while Present (Clause) loop
24497 if Nkind (Clause) = N_With_Clause then
24498 if Library_Unit (Clause) = U then
24499 return True;
24501 -- The with_clause may denote a renaming of the unit we are
24502 -- looking for, eg. Text_IO which renames Ada.Text_IO.
24504 elsif
24505 Renamed_Entity (Entity (Name (Clause))) =
24506 Defining_Entity (Unit (U))
24507 then
24508 return True;
24509 end if;
24510 end if;
24512 Next (Clause);
24513 end loop;
24515 return False;
24516 end Unit_In_Context;
24518 -- Start of processing for Unit_Is_Visible
24520 begin
24521 -- The currrent unit is directly visible
24523 if Curr = U then
24524 return True;
24526 elsif Unit_In_Context (Curr) then
24527 return True;
24529 -- If the current unit is a body, check the context of the spec
24531 elsif Nkind (Unit (Curr)) = N_Package_Body
24532 or else
24533 (Nkind (Unit (Curr)) = N_Subprogram_Body
24534 and then not Acts_As_Spec (Unit (Curr)))
24535 then
24536 if Unit_In_Context (Library_Unit (Curr)) then
24537 return True;
24538 end if;
24539 end if;
24541 -- If the spec is a child unit, examine the parents
24543 if Is_Child_Unit (Curr_Entity) then
24544 if Nkind (Unit (Curr)) in N_Unit_Body then
24545 return
24546 Unit_In_Parent_Context
24547 (Parent_Spec (Unit (Library_Unit (Curr))));
24548 else
24549 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
24550 end if;
24552 else
24553 return False;
24554 end if;
24555 end Unit_Is_Visible;
24557 ------------------------------
24558 -- Universal_Interpretation --
24559 ------------------------------
24561 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
24562 Index : Interp_Index;
24563 It : Interp;
24565 begin
24566 -- The argument may be a formal parameter of an operator or subprogram
24567 -- with multiple interpretations, or else an expression for an actual.
24569 if Nkind (Opnd) = N_Defining_Identifier
24570 or else not Is_Overloaded (Opnd)
24571 then
24572 if Etype (Opnd) = Universal_Integer
24573 or else Etype (Opnd) = Universal_Real
24574 then
24575 return Etype (Opnd);
24576 else
24577 return Empty;
24578 end if;
24580 else
24581 Get_First_Interp (Opnd, Index, It);
24582 while Present (It.Typ) loop
24583 if It.Typ = Universal_Integer
24584 or else It.Typ = Universal_Real
24585 then
24586 return It.Typ;
24587 end if;
24589 Get_Next_Interp (Index, It);
24590 end loop;
24592 return Empty;
24593 end if;
24594 end Universal_Interpretation;
24596 ---------------
24597 -- Unqualify --
24598 ---------------
24600 function Unqualify (Expr : Node_Id) return Node_Id is
24601 begin
24602 -- Recurse to handle unlikely case of multiple levels of qualification
24604 if Nkind (Expr) = N_Qualified_Expression then
24605 return Unqualify (Expression (Expr));
24607 -- Normal case, not a qualified expression
24609 else
24610 return Expr;
24611 end if;
24612 end Unqualify;
24614 -----------------
24615 -- Unqual_Conv --
24616 -----------------
24618 function Unqual_Conv (Expr : Node_Id) return Node_Id is
24619 begin
24620 -- Recurse to handle unlikely case of multiple levels of qualification
24621 -- and/or conversion.
24623 if Nkind_In (Expr, N_Qualified_Expression,
24624 N_Type_Conversion,
24625 N_Unchecked_Type_Conversion)
24626 then
24627 return Unqual_Conv (Expression (Expr));
24629 -- Normal case, not a qualified expression
24631 else
24632 return Expr;
24633 end if;
24634 end Unqual_Conv;
24636 -----------------------
24637 -- Visible_Ancestors --
24638 -----------------------
24640 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
24641 List_1 : Elist_Id;
24642 List_2 : Elist_Id;
24643 Elmt : Elmt_Id;
24645 begin
24646 pragma Assert (Is_Record_Type (Typ) and then Is_Tagged_Type (Typ));
24648 -- Collect all the parents and progenitors of Typ. If the full-view of
24649 -- private parents and progenitors is available then it is used to
24650 -- generate the list of visible ancestors; otherwise their partial
24651 -- view is added to the resulting list.
24653 Collect_Parents
24654 (T => Typ,
24655 List => List_1,
24656 Use_Full_View => True);
24658 Collect_Interfaces
24659 (T => Typ,
24660 Ifaces_List => List_2,
24661 Exclude_Parents => True,
24662 Use_Full_View => True);
24664 -- Join the two lists. Avoid duplications because an interface may
24665 -- simultaneously be parent and progenitor of a type.
24667 Elmt := First_Elmt (List_2);
24668 while Present (Elmt) loop
24669 Append_Unique_Elmt (Node (Elmt), List_1);
24670 Next_Elmt (Elmt);
24671 end loop;
24673 return List_1;
24674 end Visible_Ancestors;
24676 ----------------------
24677 -- Within_Init_Proc --
24678 ----------------------
24680 function Within_Init_Proc return Boolean is
24681 S : Entity_Id;
24683 begin
24684 S := Current_Scope;
24685 while not Is_Overloadable (S) loop
24686 if S = Standard_Standard then
24687 return False;
24688 else
24689 S := Scope (S);
24690 end if;
24691 end loop;
24693 return Is_Init_Proc (S);
24694 end Within_Init_Proc;
24696 ---------------------------
24697 -- Within_Protected_Type --
24698 ---------------------------
24700 function Within_Protected_Type (E : Entity_Id) return Boolean is
24701 Scop : Entity_Id := Scope (E);
24703 begin
24704 while Present (Scop) loop
24705 if Ekind (Scop) = E_Protected_Type then
24706 return True;
24707 end if;
24709 Scop := Scope (Scop);
24710 end loop;
24712 return False;
24713 end Within_Protected_Type;
24715 ------------------
24716 -- Within_Scope --
24717 ------------------
24719 function Within_Scope (E : Entity_Id; S : Entity_Id) return Boolean is
24720 begin
24721 return Scope_Within_Or_Same (Scope (E), S);
24722 end Within_Scope;
24724 ----------------------------
24725 -- Within_Subprogram_Call --
24726 ----------------------------
24728 function Within_Subprogram_Call (N : Node_Id) return Boolean is
24729 Par : Node_Id;
24731 begin
24732 -- Climb the parent chain looking for a function or procedure call
24734 Par := N;
24735 while Present (Par) loop
24736 if Nkind_In (Par, N_Entry_Call_Statement,
24737 N_Function_Call,
24738 N_Procedure_Call_Statement)
24739 then
24740 return True;
24742 -- Prevent the search from going too far
24744 elsif Is_Body_Or_Package_Declaration (Par) then
24745 exit;
24746 end if;
24748 Par := Parent (Par);
24749 end loop;
24751 return False;
24752 end Within_Subprogram_Call;
24754 ----------------
24755 -- Wrong_Type --
24756 ----------------
24758 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
24759 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
24760 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
24762 Matching_Field : Entity_Id;
24763 -- Entity to give a more precise suggestion on how to write a one-
24764 -- element positional aggregate.
24766 function Has_One_Matching_Field return Boolean;
24767 -- Determines if Expec_Type is a record type with a single component or
24768 -- discriminant whose type matches the found type or is one dimensional
24769 -- array whose component type matches the found type. In the case of
24770 -- one discriminant, we ignore the variant parts. That's not accurate,
24771 -- but good enough for the warning.
24773 ----------------------------
24774 -- Has_One_Matching_Field --
24775 ----------------------------
24777 function Has_One_Matching_Field return Boolean is
24778 E : Entity_Id;
24780 begin
24781 Matching_Field := Empty;
24783 if Is_Array_Type (Expec_Type)
24784 and then Number_Dimensions (Expec_Type) = 1
24785 and then Covers (Etype (Component_Type (Expec_Type)), Found_Type)
24786 then
24787 -- Use type name if available. This excludes multidimensional
24788 -- arrays and anonymous arrays.
24790 if Comes_From_Source (Expec_Type) then
24791 Matching_Field := Expec_Type;
24793 -- For an assignment, use name of target
24795 elsif Nkind (Parent (Expr)) = N_Assignment_Statement
24796 and then Is_Entity_Name (Name (Parent (Expr)))
24797 then
24798 Matching_Field := Entity (Name (Parent (Expr)));
24799 end if;
24801 return True;
24803 elsif not Is_Record_Type (Expec_Type) then
24804 return False;
24806 else
24807 E := First_Entity (Expec_Type);
24808 loop
24809 if No (E) then
24810 return False;
24812 elsif not Ekind_In (E, E_Discriminant, E_Component)
24813 or else Nam_In (Chars (E), Name_uTag, Name_uParent)
24814 then
24815 Next_Entity (E);
24817 else
24818 exit;
24819 end if;
24820 end loop;
24822 if not Covers (Etype (E), Found_Type) then
24823 return False;
24825 elsif Present (Next_Entity (E))
24826 and then (Ekind (E) = E_Component
24827 or else Ekind (Next_Entity (E)) = E_Discriminant)
24828 then
24829 return False;
24831 else
24832 Matching_Field := E;
24833 return True;
24834 end if;
24835 end if;
24836 end Has_One_Matching_Field;
24838 -- Start of processing for Wrong_Type
24840 begin
24841 -- Don't output message if either type is Any_Type, or if a message
24842 -- has already been posted for this node. We need to do the latter
24843 -- check explicitly (it is ordinarily done in Errout), because we
24844 -- are using ! to force the output of the error messages.
24846 if Expec_Type = Any_Type
24847 or else Found_Type = Any_Type
24848 or else Error_Posted (Expr)
24849 then
24850 return;
24852 -- If one of the types is a Taft-Amendment type and the other it its
24853 -- completion, it must be an illegal use of a TAT in the spec, for
24854 -- which an error was already emitted. Avoid cascaded errors.
24856 elsif Is_Incomplete_Type (Expec_Type)
24857 and then Has_Completion_In_Body (Expec_Type)
24858 and then Full_View (Expec_Type) = Etype (Expr)
24859 then
24860 return;
24862 elsif Is_Incomplete_Type (Etype (Expr))
24863 and then Has_Completion_In_Body (Etype (Expr))
24864 and then Full_View (Etype (Expr)) = Expec_Type
24865 then
24866 return;
24868 -- In an instance, there is an ongoing problem with completion of
24869 -- type derived from private types. Their structure is what Gigi
24870 -- expects, but the Etype is the parent type rather than the
24871 -- derived private type itself. Do not flag error in this case. The
24872 -- private completion is an entity without a parent, like an Itype.
24873 -- Similarly, full and partial views may be incorrect in the instance.
24874 -- There is no simple way to insure that it is consistent ???
24876 -- A similar view discrepancy can happen in an inlined body, for the
24877 -- same reason: inserted body may be outside of the original package
24878 -- and only partial views are visible at the point of insertion.
24880 elsif In_Instance or else In_Inlined_Body then
24881 if Etype (Etype (Expr)) = Etype (Expected_Type)
24882 and then
24883 (Has_Private_Declaration (Expected_Type)
24884 or else Has_Private_Declaration (Etype (Expr)))
24885 and then No (Parent (Expected_Type))
24886 then
24887 return;
24889 elsif Nkind (Parent (Expr)) = N_Qualified_Expression
24890 and then Entity (Subtype_Mark (Parent (Expr))) = Expected_Type
24891 then
24892 return;
24894 elsif Is_Private_Type (Expected_Type)
24895 and then Present (Full_View (Expected_Type))
24896 and then Covers (Full_View (Expected_Type), Etype (Expr))
24897 then
24898 return;
24900 -- Conversely, type of expression may be the private one
24902 elsif Is_Private_Type (Base_Type (Etype (Expr)))
24903 and then Full_View (Base_Type (Etype (Expr))) = Expected_Type
24904 then
24905 return;
24906 end if;
24907 end if;
24909 -- An interesting special check. If the expression is parenthesized
24910 -- and its type corresponds to the type of the sole component of the
24911 -- expected record type, or to the component type of the expected one
24912 -- dimensional array type, then assume we have a bad aggregate attempt.
24914 if Nkind (Expr) in N_Subexpr
24915 and then Paren_Count (Expr) /= 0
24916 and then Has_One_Matching_Field
24917 then
24918 Error_Msg_N ("positional aggregate cannot have one component", Expr);
24920 if Present (Matching_Field) then
24921 if Is_Array_Type (Expec_Type) then
24922 Error_Msg_NE
24923 ("\write instead `&''First ='> ...`", Expr, Matching_Field);
24924 else
24925 Error_Msg_NE
24926 ("\write instead `& ='> ...`", Expr, Matching_Field);
24927 end if;
24928 end if;
24930 -- Another special check, if we are looking for a pool-specific access
24931 -- type and we found an E_Access_Attribute_Type, then we have the case
24932 -- of an Access attribute being used in a context which needs a pool-
24933 -- specific type, which is never allowed. The one extra check we make
24934 -- is that the expected designated type covers the Found_Type.
24936 elsif Is_Access_Type (Expec_Type)
24937 and then Ekind (Found_Type) = E_Access_Attribute_Type
24938 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
24939 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
24940 and then Covers
24941 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
24942 then
24943 Error_Msg_N -- CODEFIX
24944 ("result must be general access type!", Expr);
24945 Error_Msg_NE -- CODEFIX
24946 ("add ALL to }!", Expr, Expec_Type);
24948 -- Another special check, if the expected type is an integer type,
24949 -- but the expression is of type System.Address, and the parent is
24950 -- an addition or subtraction operation whose left operand is the
24951 -- expression in question and whose right operand is of an integral
24952 -- type, then this is an attempt at address arithmetic, so give
24953 -- appropriate message.
24955 elsif Is_Integer_Type (Expec_Type)
24956 and then Is_RTE (Found_Type, RE_Address)
24957 and then Nkind_In (Parent (Expr), N_Op_Add, N_Op_Subtract)
24958 and then Expr = Left_Opnd (Parent (Expr))
24959 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
24960 then
24961 Error_Msg_N
24962 ("address arithmetic not predefined in package System",
24963 Parent (Expr));
24964 Error_Msg_N
24965 ("\possible missing with/use of System.Storage_Elements",
24966 Parent (Expr));
24967 return;
24969 -- If the expected type is an anonymous access type, as for access
24970 -- parameters and discriminants, the error is on the designated types.
24972 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
24973 if Comes_From_Source (Expec_Type) then
24974 Error_Msg_NE ("expected}!", Expr, Expec_Type);
24975 else
24976 Error_Msg_NE
24977 ("expected an access type with designated}",
24978 Expr, Designated_Type (Expec_Type));
24979 end if;
24981 if Is_Access_Type (Found_Type)
24982 and then not Comes_From_Source (Found_Type)
24983 then
24984 Error_Msg_NE
24985 ("\\found an access type with designated}!",
24986 Expr, Designated_Type (Found_Type));
24987 else
24988 if From_Limited_With (Found_Type) then
24989 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
24990 Error_Msg_Qual_Level := 99;
24991 Error_Msg_NE -- CODEFIX
24992 ("\\missing `WITH &;", Expr, Scope (Found_Type));
24993 Error_Msg_Qual_Level := 0;
24994 else
24995 Error_Msg_NE ("found}!", Expr, Found_Type);
24996 end if;
24997 end if;
24999 -- Normal case of one type found, some other type expected
25001 else
25002 -- If the names of the two types are the same, see if some number
25003 -- of levels of qualification will help. Don't try more than three
25004 -- levels, and if we get to standard, it's no use (and probably
25005 -- represents an error in the compiler) Also do not bother with
25006 -- internal scope names.
25008 declare
25009 Expec_Scope : Entity_Id;
25010 Found_Scope : Entity_Id;
25012 begin
25013 Expec_Scope := Expec_Type;
25014 Found_Scope := Found_Type;
25016 for Levels in Nat range 0 .. 3 loop
25017 if Chars (Expec_Scope) /= Chars (Found_Scope) then
25018 Error_Msg_Qual_Level := Levels;
25019 exit;
25020 end if;
25022 Expec_Scope := Scope (Expec_Scope);
25023 Found_Scope := Scope (Found_Scope);
25025 exit when Expec_Scope = Standard_Standard
25026 or else Found_Scope = Standard_Standard
25027 or else not Comes_From_Source (Expec_Scope)
25028 or else not Comes_From_Source (Found_Scope);
25029 end loop;
25030 end;
25032 if Is_Record_Type (Expec_Type)
25033 and then Present (Corresponding_Remote_Type (Expec_Type))
25034 then
25035 Error_Msg_NE ("expected}!", Expr,
25036 Corresponding_Remote_Type (Expec_Type));
25037 else
25038 Error_Msg_NE ("expected}!", Expr, Expec_Type);
25039 end if;
25041 if Is_Entity_Name (Expr)
25042 and then Is_Package_Or_Generic_Package (Entity (Expr))
25043 then
25044 Error_Msg_N ("\\found package name!", Expr);
25046 elsif Is_Entity_Name (Expr)
25047 and then Ekind_In (Entity (Expr), E_Procedure, E_Generic_Procedure)
25048 then
25049 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
25050 Error_Msg_N
25051 ("found procedure name, possibly missing Access attribute!",
25052 Expr);
25053 else
25054 Error_Msg_N
25055 ("\\found procedure name instead of function!", Expr);
25056 end if;
25058 elsif Nkind (Expr) = N_Function_Call
25059 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
25060 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
25061 and then No (Parameter_Associations (Expr))
25062 then
25063 Error_Msg_N
25064 ("found function name, possibly missing Access attribute!",
25065 Expr);
25067 -- Catch common error: a prefix or infix operator which is not
25068 -- directly visible because the type isn't.
25070 elsif Nkind (Expr) in N_Op
25071 and then Is_Overloaded (Expr)
25072 and then not Is_Immediately_Visible (Expec_Type)
25073 and then not Is_Potentially_Use_Visible (Expec_Type)
25074 and then not In_Use (Expec_Type)
25075 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
25076 then
25077 Error_Msg_N
25078 ("operator of the type is not directly visible!", Expr);
25080 elsif Ekind (Found_Type) = E_Void
25081 and then Present (Parent (Found_Type))
25082 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
25083 then
25084 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
25086 else
25087 Error_Msg_NE ("\\found}!", Expr, Found_Type);
25088 end if;
25090 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
25091 -- of the same modular type, and (M1 and M2) = 0 was intended.
25093 if Expec_Type = Standard_Boolean
25094 and then Is_Modular_Integer_Type (Found_Type)
25095 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
25096 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
25097 then
25098 declare
25099 Op : constant Node_Id := Right_Opnd (Parent (Expr));
25100 L : constant Node_Id := Left_Opnd (Op);
25101 R : constant Node_Id := Right_Opnd (Op);
25103 begin
25104 -- The case for the message is when the left operand of the
25105 -- comparison is the same modular type, or when it is an
25106 -- integer literal (or other universal integer expression),
25107 -- which would have been typed as the modular type if the
25108 -- parens had been there.
25110 if (Etype (L) = Found_Type
25111 or else
25112 Etype (L) = Universal_Integer)
25113 and then Is_Integer_Type (Etype (R))
25114 then
25115 Error_Msg_N
25116 ("\\possible missing parens for modular operation", Expr);
25117 end if;
25118 end;
25119 end if;
25121 -- Reset error message qualification indication
25123 Error_Msg_Qual_Level := 0;
25124 end if;
25125 end Wrong_Type;
25127 --------------------------------
25128 -- Yields_Synchronized_Object --
25129 --------------------------------
25131 function Yields_Synchronized_Object (Typ : Entity_Id) return Boolean is
25132 Has_Sync_Comp : Boolean := False;
25133 Id : Entity_Id;
25135 begin
25136 -- An array type yields a synchronized object if its component type
25137 -- yields a synchronized object.
25139 if Is_Array_Type (Typ) then
25140 return Yields_Synchronized_Object (Component_Type (Typ));
25142 -- A descendant of type Ada.Synchronous_Task_Control.Suspension_Object
25143 -- yields a synchronized object by default.
25145 elsif Is_Descendant_Of_Suspension_Object (Typ) then
25146 return True;
25148 -- A protected type yields a synchronized object by default
25150 elsif Is_Protected_Type (Typ) then
25151 return True;
25153 -- A record type or type extension yields a synchronized object when its
25154 -- discriminants (if any) lack default values and all components are of
25155 -- a type that yelds a synchronized object.
25157 elsif Is_Record_Type (Typ) then
25159 -- Inspect all entities defined in the scope of the type, looking for
25160 -- components of a type that does not yeld a synchronized object or
25161 -- for discriminants with default values.
25163 Id := First_Entity (Typ);
25164 while Present (Id) loop
25165 if Comes_From_Source (Id) then
25166 if Ekind (Id) = E_Component then
25167 if Yields_Synchronized_Object (Etype (Id)) then
25168 Has_Sync_Comp := True;
25170 -- The component does not yield a synchronized object
25172 else
25173 return False;
25174 end if;
25176 elsif Ekind (Id) = E_Discriminant
25177 and then Present (Expression (Parent (Id)))
25178 then
25179 return False;
25180 end if;
25181 end if;
25183 Next_Entity (Id);
25184 end loop;
25186 -- Ensure that the parent type of a type extension yields a
25187 -- synchronized object.
25189 if Etype (Typ) /= Typ
25190 and then not Yields_Synchronized_Object (Etype (Typ))
25191 then
25192 return False;
25193 end if;
25195 -- If we get here, then all discriminants lack default values and all
25196 -- components are of a type that yields a synchronized object.
25198 return Has_Sync_Comp;
25200 -- A synchronized interface type yields a synchronized object by default
25202 elsif Is_Synchronized_Interface (Typ) then
25203 return True;
25205 -- A task type yelds a synchronized object by default
25207 elsif Is_Task_Type (Typ) then
25208 return True;
25210 -- Otherwise the type does not yield a synchronized object
25212 else
25213 return False;
25214 end if;
25215 end Yields_Synchronized_Object;
25217 ---------------------------
25218 -- Yields_Universal_Type --
25219 ---------------------------
25221 function Yields_Universal_Type (N : Node_Id) return Boolean is
25222 begin
25223 -- Integer and real literals are of a universal type
25225 if Nkind_In (N, N_Integer_Literal, N_Real_Literal) then
25226 return True;
25228 -- The values of certain attributes are of a universal type
25230 elsif Nkind (N) = N_Attribute_Reference then
25231 return
25232 Universal_Type_Attribute (Get_Attribute_Id (Attribute_Name (N)));
25234 -- ??? There are possibly other cases to consider
25236 else
25237 return False;
25238 end if;
25239 end Yields_Universal_Type;
25241 begin
25242 Erroutc.Subprogram_Name_Ptr := Subprogram_Name'Access;
25243 end Sem_Util;