Fix GNU coding style for G_.
[official-gcc.git] / gcc / ada / sem_util.adb
blob5fa02ddde1c42b9914bc41f0e31d0db0ff081670
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-2018, 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;
7852 begin
7853 -- Examine the parent chain looking for a construct which defines a
7854 -- scope.
7856 Par := Parent (N);
7857 while Present (Par) loop
7858 case Nkind (Par) is
7860 -- The construct denotes a declaration, the proper scope is its
7861 -- entity.
7863 when N_Entry_Declaration
7864 | N_Expression_Function
7865 | N_Full_Type_Declaration
7866 | N_Generic_Package_Declaration
7867 | N_Generic_Subprogram_Declaration
7868 | N_Package_Declaration
7869 | N_Private_Extension_Declaration
7870 | N_Protected_Type_Declaration
7871 | N_Single_Protected_Declaration
7872 | N_Single_Task_Declaration
7873 | N_Subprogram_Declaration
7874 | N_Task_Type_Declaration
7876 return Defining_Entity (Par);
7878 -- The construct denotes a body, the proper scope is the entity of
7879 -- the corresponding spec or that of the body if the body does not
7880 -- complete a previous declaration.
7882 when N_Entry_Body
7883 | N_Package_Body
7884 | N_Protected_Body
7885 | N_Subprogram_Body
7886 | N_Task_Body
7888 return Unique_Defining_Entity (Par);
7890 -- Special cases
7892 -- Blocks carry either a source or an internally-generated scope,
7893 -- unless the block is a byproduct of exception handling.
7895 when N_Block_Statement =>
7896 if not Exception_Junk (Par) then
7897 return Entity (Identifier (Par));
7898 end if;
7900 -- Loops carry an internally-generated scope
7902 when N_Loop_Statement =>
7903 return Entity (Identifier (Par));
7905 -- Extended return statements carry an internally-generated scope
7907 when N_Extended_Return_Statement =>
7908 return Return_Statement_Entity (Par);
7910 -- A traversal from a subunit continues via the corresponding stub
7912 when N_Subunit =>
7913 Par := Corresponding_Stub (Par);
7915 when others =>
7916 null;
7917 end case;
7919 Par := Parent (Par);
7920 end loop;
7922 return Standard_Standard;
7923 end Find_Enclosing_Scope;
7925 ------------------------------------
7926 -- Find_Loop_In_Conditional_Block --
7927 ------------------------------------
7929 function Find_Loop_In_Conditional_Block (N : Node_Id) return Node_Id is
7930 Stmt : Node_Id;
7932 begin
7933 Stmt := N;
7935 if Nkind (Stmt) = N_If_Statement then
7936 Stmt := First (Then_Statements (Stmt));
7937 end if;
7939 pragma Assert (Nkind (Stmt) = N_Block_Statement);
7941 -- Inspect the statements of the conditional block. In general the loop
7942 -- should be the first statement in the statement sequence of the block,
7943 -- but the finalization machinery may have introduced extra object
7944 -- declarations.
7946 Stmt := First (Statements (Handled_Statement_Sequence (Stmt)));
7947 while Present (Stmt) loop
7948 if Nkind (Stmt) = N_Loop_Statement then
7949 return Stmt;
7950 end if;
7952 Next (Stmt);
7953 end loop;
7955 -- The expansion of attribute 'Loop_Entry produced a malformed block
7957 raise Program_Error;
7958 end Find_Loop_In_Conditional_Block;
7960 --------------------------
7961 -- Find_Overlaid_Entity --
7962 --------------------------
7964 procedure Find_Overlaid_Entity
7965 (N : Node_Id;
7966 Ent : out Entity_Id;
7967 Off : out Boolean)
7969 Expr : Node_Id;
7971 begin
7972 -- We are looking for one of the two following forms:
7974 -- for X'Address use Y'Address
7976 -- or
7978 -- Const : constant Address := expr;
7979 -- ...
7980 -- for X'Address use Const;
7982 -- In the second case, the expr is either Y'Address, or recursively a
7983 -- constant that eventually references Y'Address.
7985 Ent := Empty;
7986 Off := False;
7988 if Nkind (N) = N_Attribute_Definition_Clause
7989 and then Chars (N) = Name_Address
7990 then
7991 Expr := Expression (N);
7993 -- This loop checks the form of the expression for Y'Address,
7994 -- using recursion to deal with intermediate constants.
7996 loop
7997 -- Check for Y'Address
7999 if Nkind (Expr) = N_Attribute_Reference
8000 and then Attribute_Name (Expr) = Name_Address
8001 then
8002 Expr := Prefix (Expr);
8003 exit;
8005 -- Check for Const where Const is a constant entity
8007 elsif Is_Entity_Name (Expr)
8008 and then Ekind (Entity (Expr)) = E_Constant
8009 then
8010 Expr := Constant_Value (Entity (Expr));
8012 -- Anything else does not need checking
8014 else
8015 return;
8016 end if;
8017 end loop;
8019 -- This loop checks the form of the prefix for an entity, using
8020 -- recursion to deal with intermediate components.
8022 loop
8023 -- Check for Y where Y is an entity
8025 if Is_Entity_Name (Expr) then
8026 Ent := Entity (Expr);
8027 return;
8029 -- Check for components
8031 elsif
8032 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component)
8033 then
8034 Expr := Prefix (Expr);
8035 Off := True;
8037 -- Anything else does not need checking
8039 else
8040 return;
8041 end if;
8042 end loop;
8043 end if;
8044 end Find_Overlaid_Entity;
8046 -------------------------
8047 -- Find_Parameter_Type --
8048 -------------------------
8050 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
8051 begin
8052 if Nkind (Param) /= N_Parameter_Specification then
8053 return Empty;
8055 -- For an access parameter, obtain the type from the formal entity
8056 -- itself, because access to subprogram nodes do not carry a type.
8057 -- Shouldn't we always use the formal entity ???
8059 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
8060 return Etype (Defining_Identifier (Param));
8062 else
8063 return Etype (Parameter_Type (Param));
8064 end if;
8065 end Find_Parameter_Type;
8067 -----------------------------------
8068 -- Find_Placement_In_State_Space --
8069 -----------------------------------
8071 procedure Find_Placement_In_State_Space
8072 (Item_Id : Entity_Id;
8073 Placement : out State_Space_Kind;
8074 Pack_Id : out Entity_Id)
8076 Context : Entity_Id;
8078 begin
8079 -- Assume that the item does not appear in the state space of a package
8081 Placement := Not_In_Package;
8082 Pack_Id := Empty;
8084 -- Climb the scope stack and examine the enclosing context
8086 Context := Scope (Item_Id);
8087 while Present (Context) and then Context /= Standard_Standard loop
8088 if Is_Package_Or_Generic_Package (Context) then
8089 Pack_Id := Context;
8091 -- A package body is a cut off point for the traversal as the item
8092 -- cannot be visible to the outside from this point on. Note that
8093 -- this test must be done first as a body is also classified as a
8094 -- private part.
8096 if In_Package_Body (Context) then
8097 Placement := Body_State_Space;
8098 return;
8100 -- The private part of a package is a cut off point for the
8101 -- traversal as the item cannot be visible to the outside from
8102 -- this point on.
8104 elsif In_Private_Part (Context) then
8105 Placement := Private_State_Space;
8106 return;
8108 -- When the item appears in the visible state space of a package,
8109 -- continue to climb the scope stack as this may not be the final
8110 -- state space.
8112 else
8113 Placement := Visible_State_Space;
8115 -- The visible state space of a child unit acts as the proper
8116 -- placement of an item.
8118 if Is_Child_Unit (Context) then
8119 return;
8120 end if;
8121 end if;
8123 -- The item or its enclosing package appear in a construct that has
8124 -- no state space.
8126 else
8127 Placement := Not_In_Package;
8128 return;
8129 end if;
8131 Context := Scope (Context);
8132 end loop;
8133 end Find_Placement_In_State_Space;
8135 ------------------------
8136 -- Find_Specific_Type --
8137 ------------------------
8139 function Find_Specific_Type (CW : Entity_Id) return Entity_Id is
8140 Typ : Entity_Id := Root_Type (CW);
8142 begin
8143 if Ekind (Typ) = E_Incomplete_Type then
8144 if From_Limited_With (Typ) then
8145 Typ := Non_Limited_View (Typ);
8146 else
8147 Typ := Full_View (Typ);
8148 end if;
8149 end if;
8151 if Is_Private_Type (Typ)
8152 and then not Is_Tagged_Type (Typ)
8153 and then Present (Full_View (Typ))
8154 then
8155 return Full_View (Typ);
8156 else
8157 return Typ;
8158 end if;
8159 end Find_Specific_Type;
8161 -----------------------------
8162 -- Find_Static_Alternative --
8163 -----------------------------
8165 function Find_Static_Alternative (N : Node_Id) return Node_Id is
8166 Expr : constant Node_Id := Expression (N);
8167 Val : constant Uint := Expr_Value (Expr);
8168 Alt : Node_Id;
8169 Choice : Node_Id;
8171 begin
8172 Alt := First (Alternatives (N));
8174 Search : loop
8175 if Nkind (Alt) /= N_Pragma then
8176 Choice := First (Discrete_Choices (Alt));
8177 while Present (Choice) loop
8179 -- Others choice, always matches
8181 if Nkind (Choice) = N_Others_Choice then
8182 exit Search;
8184 -- Range, check if value is in the range
8186 elsif Nkind (Choice) = N_Range then
8187 exit Search when
8188 Val >= Expr_Value (Low_Bound (Choice))
8189 and then
8190 Val <= Expr_Value (High_Bound (Choice));
8192 -- Choice is a subtype name. Note that we know it must
8193 -- be a static subtype, since otherwise it would have
8194 -- been diagnosed as illegal.
8196 elsif Is_Entity_Name (Choice)
8197 and then Is_Type (Entity (Choice))
8198 then
8199 exit Search when Is_In_Range (Expr, Etype (Choice),
8200 Assume_Valid => False);
8202 -- Choice is a subtype indication
8204 elsif Nkind (Choice) = N_Subtype_Indication then
8205 declare
8206 C : constant Node_Id := Constraint (Choice);
8207 R : constant Node_Id := Range_Expression (C);
8209 begin
8210 exit Search when
8211 Val >= Expr_Value (Low_Bound (R))
8212 and then
8213 Val <= Expr_Value (High_Bound (R));
8214 end;
8216 -- Choice is a simple expression
8218 else
8219 exit Search when Val = Expr_Value (Choice);
8220 end if;
8222 Next (Choice);
8223 end loop;
8224 end if;
8226 Next (Alt);
8227 pragma Assert (Present (Alt));
8228 end loop Search;
8230 -- The above loop *must* terminate by finding a match, since we know the
8231 -- case statement is valid, and the value of the expression is known at
8232 -- compile time. When we fall out of the loop, Alt points to the
8233 -- alternative that we know will be selected at run time.
8235 return Alt;
8236 end Find_Static_Alternative;
8238 ------------------
8239 -- First_Actual --
8240 ------------------
8242 function First_Actual (Node : Node_Id) return Node_Id is
8243 N : Node_Id;
8245 begin
8246 if No (Parameter_Associations (Node)) then
8247 return Empty;
8248 end if;
8250 N := First (Parameter_Associations (Node));
8252 if Nkind (N) = N_Parameter_Association then
8253 return First_Named_Actual (Node);
8254 else
8255 return N;
8256 end if;
8257 end First_Actual;
8259 ------------------
8260 -- First_Global --
8261 ------------------
8263 function First_Global
8264 (Subp : Entity_Id;
8265 Global_Mode : Name_Id;
8266 Refined : Boolean := False) return Node_Id
8268 function First_From_Global_List
8269 (List : Node_Id;
8270 Global_Mode : Name_Id := Name_Input) return Entity_Id;
8271 -- Get the first item with suitable mode from List
8273 ----------------------------
8274 -- First_From_Global_List --
8275 ----------------------------
8277 function First_From_Global_List
8278 (List : Node_Id;
8279 Global_Mode : Name_Id := Name_Input) return Entity_Id
8281 Assoc : Node_Id;
8283 begin
8284 -- Empty list (no global items)
8286 if Nkind (List) = N_Null then
8287 return Empty;
8289 -- Single global item declaration (only input items)
8291 elsif Nkind_In (List, N_Expanded_Name,
8292 N_Identifier,
8293 N_Selected_Component)
8294 then
8295 if Global_Mode = Name_Input then
8296 return List;
8297 else
8298 return Empty;
8299 end if;
8301 -- Simple global list (only input items) or moded global list
8302 -- declaration.
8304 elsif Nkind (List) = N_Aggregate then
8305 if Present (Expressions (List)) then
8306 if Global_Mode = Name_Input then
8307 return First (Expressions (List));
8308 else
8309 return Empty;
8310 end if;
8312 else
8313 Assoc := First (Component_Associations (List));
8314 while Present (Assoc) loop
8316 -- When we find the desired mode in an association, call
8317 -- recursively First_From_Global_List as if the mode was
8318 -- Name_Input, in order to reuse the existing machinery
8319 -- for the other cases.
8321 if Chars (First (Choices (Assoc))) = Global_Mode then
8322 return First_From_Global_List (Expression (Assoc));
8323 end if;
8325 Next (Assoc);
8326 end loop;
8328 return Empty;
8329 end if;
8331 -- To accommodate partial decoration of disabled SPARK features,
8332 -- this routine may be called with illegal input. If this is the
8333 -- case, do not raise Program_Error.
8335 else
8336 return Empty;
8337 end if;
8338 end First_From_Global_List;
8340 -- Local variables
8342 Global : Node_Id := Empty;
8343 Body_Id : Entity_Id;
8345 begin
8346 pragma Assert (Global_Mode = Name_Input
8347 or else Global_Mode = Name_Output
8348 or else Global_Mode = Name_In_Out
8349 or else Global_Mode = Name_Proof_In);
8351 -- Retrieve the suitable pragma Global or Refined_Global. In the second
8352 -- case, it can only be located on the body entity.
8354 if Refined then
8355 Body_Id := Subprogram_Body_Entity (Subp);
8356 if Present (Body_Id) then
8357 Global := Get_Pragma (Body_Id, Pragma_Refined_Global);
8358 end if;
8359 else
8360 Global := Get_Pragma (Subp, Pragma_Global);
8361 end if;
8363 -- No corresponding global if pragma is not present
8365 if No (Global) then
8366 return Empty;
8368 -- Otherwise retrieve the corresponding list of items depending on the
8369 -- Global_Mode.
8371 else
8372 return First_From_Global_List
8373 (Expression (Get_Argument (Global, Subp)), Global_Mode);
8374 end if;
8375 end First_Global;
8377 -------------
8378 -- Fix_Msg --
8379 -------------
8381 function Fix_Msg (Id : Entity_Id; Msg : String) return String is
8382 Is_Task : constant Boolean :=
8383 Ekind_In (Id, E_Task_Body, E_Task_Type)
8384 or else Is_Single_Task_Object (Id);
8385 Msg_Last : constant Natural := Msg'Last;
8386 Msg_Index : Natural;
8387 Res : String (Msg'Range) := (others => ' ');
8388 Res_Index : Natural;
8390 begin
8391 -- Copy all characters from the input message Msg to result Res with
8392 -- suitable replacements.
8394 Msg_Index := Msg'First;
8395 Res_Index := Res'First;
8396 while Msg_Index <= Msg_Last loop
8398 -- Replace "subprogram" with a different word
8400 if Msg_Index <= Msg_Last - 10
8401 and then Msg (Msg_Index .. Msg_Index + 9) = "subprogram"
8402 then
8403 if Ekind_In (Id, E_Entry, E_Entry_Family) then
8404 Res (Res_Index .. Res_Index + 4) := "entry";
8405 Res_Index := Res_Index + 5;
8407 elsif Is_Task then
8408 Res (Res_Index .. Res_Index + 8) := "task type";
8409 Res_Index := Res_Index + 9;
8411 else
8412 Res (Res_Index .. Res_Index + 9) := "subprogram";
8413 Res_Index := Res_Index + 10;
8414 end if;
8416 Msg_Index := Msg_Index + 10;
8418 -- Replace "protected" with a different word
8420 elsif Msg_Index <= Msg_Last - 9
8421 and then Msg (Msg_Index .. Msg_Index + 8) = "protected"
8422 and then Is_Task
8423 then
8424 Res (Res_Index .. Res_Index + 3) := "task";
8425 Res_Index := Res_Index + 4;
8426 Msg_Index := Msg_Index + 9;
8428 -- Otherwise copy the character
8430 else
8431 Res (Res_Index) := Msg (Msg_Index);
8432 Msg_Index := Msg_Index + 1;
8433 Res_Index := Res_Index + 1;
8434 end if;
8435 end loop;
8437 return Res (Res'First .. Res_Index - 1);
8438 end Fix_Msg;
8440 -------------------------
8441 -- From_Nested_Package --
8442 -------------------------
8444 function From_Nested_Package (T : Entity_Id) return Boolean is
8445 Pack : constant Entity_Id := Scope (T);
8447 begin
8448 return
8449 Ekind (Pack) = E_Package
8450 and then not Is_Frozen (Pack)
8451 and then not Scope_Within_Or_Same (Current_Scope, Pack)
8452 and then In_Open_Scopes (Scope (Pack));
8453 end From_Nested_Package;
8455 -----------------------
8456 -- Gather_Components --
8457 -----------------------
8459 procedure Gather_Components
8460 (Typ : Entity_Id;
8461 Comp_List : Node_Id;
8462 Governed_By : List_Id;
8463 Into : Elist_Id;
8464 Report_Errors : out Boolean)
8466 Assoc : Node_Id;
8467 Variant : Node_Id;
8468 Discrete_Choice : Node_Id;
8469 Comp_Item : Node_Id;
8471 Discrim : Entity_Id;
8472 Discrim_Name : Node_Id;
8473 Discrim_Value : Node_Id;
8475 begin
8476 Report_Errors := False;
8478 if No (Comp_List) or else Null_Present (Comp_List) then
8479 return;
8481 elsif Present (Component_Items (Comp_List)) then
8482 Comp_Item := First (Component_Items (Comp_List));
8484 else
8485 Comp_Item := Empty;
8486 end if;
8488 while Present (Comp_Item) loop
8490 -- Skip the tag of a tagged record, the interface tags, as well
8491 -- as all items that are not user components (anonymous types,
8492 -- rep clauses, Parent field, controller field).
8494 if Nkind (Comp_Item) = N_Component_Declaration then
8495 declare
8496 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
8497 begin
8498 if not Is_Tag (Comp) and then Chars (Comp) /= Name_uParent then
8499 Append_Elmt (Comp, Into);
8500 end if;
8501 end;
8502 end if;
8504 Next (Comp_Item);
8505 end loop;
8507 if No (Variant_Part (Comp_List)) then
8508 return;
8509 else
8510 Discrim_Name := Name (Variant_Part (Comp_List));
8511 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
8512 end if;
8514 -- Look for the discriminant that governs this variant part.
8515 -- The discriminant *must* be in the Governed_By List
8517 Assoc := First (Governed_By);
8518 Find_Constraint : loop
8519 Discrim := First (Choices (Assoc));
8520 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
8521 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
8522 and then
8523 Chars (Corresponding_Discriminant (Entity (Discrim))) =
8524 Chars (Discrim_Name))
8525 or else Chars (Original_Record_Component (Entity (Discrim)))
8526 = Chars (Discrim_Name);
8528 if No (Next (Assoc)) then
8529 if not Is_Constrained (Typ)
8530 and then Is_Derived_Type (Typ)
8531 and then Present (Stored_Constraint (Typ))
8532 then
8533 -- If the type is a tagged type with inherited discriminants,
8534 -- use the stored constraint on the parent in order to find
8535 -- the values of discriminants that are otherwise hidden by an
8536 -- explicit constraint. Renamed discriminants are handled in
8537 -- the code above.
8539 -- If several parent discriminants are renamed by a single
8540 -- discriminant of the derived type, the call to obtain the
8541 -- Corresponding_Discriminant field only retrieves the last
8542 -- of them. We recover the constraint on the others from the
8543 -- Stored_Constraint as well.
8545 declare
8546 D : Entity_Id;
8547 C : Elmt_Id;
8549 begin
8550 D := First_Discriminant (Etype (Typ));
8551 C := First_Elmt (Stored_Constraint (Typ));
8552 while Present (D) and then Present (C) loop
8553 if Chars (Discrim_Name) = Chars (D) then
8554 if Is_Entity_Name (Node (C))
8555 and then Entity (Node (C)) = Entity (Discrim)
8556 then
8557 -- D is renamed by Discrim, whose value is given in
8558 -- Assoc.
8560 null;
8562 else
8563 Assoc :=
8564 Make_Component_Association (Sloc (Typ),
8565 New_List
8566 (New_Occurrence_Of (D, Sloc (Typ))),
8567 Duplicate_Subexpr_No_Checks (Node (C)));
8568 end if;
8569 exit Find_Constraint;
8570 end if;
8572 Next_Discriminant (D);
8573 Next_Elmt (C);
8574 end loop;
8575 end;
8576 end if;
8577 end if;
8579 if No (Next (Assoc)) then
8580 Error_Msg_NE (" missing value for discriminant&",
8581 First (Governed_By), Discrim_Name);
8582 Report_Errors := True;
8583 return;
8584 end if;
8586 Next (Assoc);
8587 end loop Find_Constraint;
8589 Discrim_Value := Expression (Assoc);
8591 if not Is_OK_Static_Expression (Discrim_Value) then
8593 -- If the variant part is governed by a discriminant of the type
8594 -- this is an error. If the variant part and the discriminant are
8595 -- inherited from an ancestor this is legal (AI05-120) unless the
8596 -- components are being gathered for an aggregate, in which case
8597 -- the caller must check Report_Errors.
8599 if Scope (Original_Record_Component
8600 ((Entity (First (Choices (Assoc)))))) = Typ
8601 then
8602 Error_Msg_FE
8603 ("value for discriminant & must be static!",
8604 Discrim_Value, Discrim);
8605 Why_Not_Static (Discrim_Value);
8606 end if;
8608 Report_Errors := True;
8609 return;
8610 end if;
8612 Search_For_Discriminant_Value : declare
8613 Low : Node_Id;
8614 High : Node_Id;
8616 UI_High : Uint;
8617 UI_Low : Uint;
8618 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
8620 begin
8621 Find_Discrete_Value : while Present (Variant) loop
8622 Discrete_Choice := First (Discrete_Choices (Variant));
8623 while Present (Discrete_Choice) loop
8624 exit Find_Discrete_Value when
8625 Nkind (Discrete_Choice) = N_Others_Choice;
8627 Get_Index_Bounds (Discrete_Choice, Low, High);
8629 UI_Low := Expr_Value (Low);
8630 UI_High := Expr_Value (High);
8632 exit Find_Discrete_Value when
8633 UI_Low <= UI_Discrim_Value
8634 and then
8635 UI_High >= UI_Discrim_Value;
8637 Next (Discrete_Choice);
8638 end loop;
8640 Next_Non_Pragma (Variant);
8641 end loop Find_Discrete_Value;
8642 end Search_For_Discriminant_Value;
8644 -- The case statement must include a variant that corresponds to the
8645 -- value of the discriminant, unless the discriminant type has a
8646 -- static predicate. In that case the absence of an others_choice that
8647 -- would cover this value becomes a run-time error (3.8,1 (21.1/2)).
8649 if No (Variant)
8650 and then not Has_Static_Predicate (Etype (Discrim_Name))
8651 then
8652 Error_Msg_NE
8653 ("value of discriminant & is out of range", Discrim_Value, Discrim);
8654 Report_Errors := True;
8655 return;
8656 end if;
8658 -- If we have found the corresponding choice, recursively add its
8659 -- components to the Into list. The nested components are part of
8660 -- the same record type.
8662 if Present (Variant) then
8663 Gather_Components
8664 (Typ, Component_List (Variant), Governed_By, Into, Report_Errors);
8665 end if;
8666 end Gather_Components;
8668 ------------------------
8669 -- Get_Actual_Subtype --
8670 ------------------------
8672 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
8673 Typ : constant Entity_Id := Etype (N);
8674 Utyp : Entity_Id := Underlying_Type (Typ);
8675 Decl : Node_Id;
8676 Atyp : Entity_Id;
8678 begin
8679 if No (Utyp) then
8680 Utyp := Typ;
8681 end if;
8683 -- If what we have is an identifier that references a subprogram
8684 -- formal, or a variable or constant object, then we get the actual
8685 -- subtype from the referenced entity if one has been built.
8687 if Nkind (N) = N_Identifier
8688 and then
8689 (Is_Formal (Entity (N))
8690 or else Ekind (Entity (N)) = E_Constant
8691 or else Ekind (Entity (N)) = E_Variable)
8692 and then Present (Actual_Subtype (Entity (N)))
8693 then
8694 return Actual_Subtype (Entity (N));
8696 -- Actual subtype of unchecked union is always itself. We never need
8697 -- the "real" actual subtype. If we did, we couldn't get it anyway
8698 -- because the discriminant is not available. The restrictions on
8699 -- Unchecked_Union are designed to make sure that this is OK.
8701 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
8702 return Typ;
8704 -- Here for the unconstrained case, we must find actual subtype
8705 -- No actual subtype is available, so we must build it on the fly.
8707 -- Checking the type, not the underlying type, for constrainedness
8708 -- seems to be necessary. Maybe all the tests should be on the type???
8710 elsif (not Is_Constrained (Typ))
8711 and then (Is_Array_Type (Utyp)
8712 or else (Is_Record_Type (Utyp)
8713 and then Has_Discriminants (Utyp)))
8714 and then not Has_Unknown_Discriminants (Utyp)
8715 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
8716 then
8717 -- Nothing to do if in spec expression (why not???)
8719 if In_Spec_Expression then
8720 return Typ;
8722 elsif Is_Private_Type (Typ) and then not Has_Discriminants (Typ) then
8724 -- If the type has no discriminants, there is no subtype to
8725 -- build, even if the underlying type is discriminated.
8727 return Typ;
8729 -- Else build the actual subtype
8731 else
8732 Decl := Build_Actual_Subtype (Typ, N);
8733 Atyp := Defining_Identifier (Decl);
8735 -- If Build_Actual_Subtype generated a new declaration then use it
8737 if Atyp /= Typ then
8739 -- The actual subtype is an Itype, so analyze the declaration,
8740 -- but do not attach it to the tree, to get the type defined.
8742 Set_Parent (Decl, N);
8743 Set_Is_Itype (Atyp);
8744 Analyze (Decl, Suppress => All_Checks);
8745 Set_Associated_Node_For_Itype (Atyp, N);
8746 Set_Has_Delayed_Freeze (Atyp, False);
8748 -- We need to freeze the actual subtype immediately. This is
8749 -- needed, because otherwise this Itype will not get frozen
8750 -- at all, and it is always safe to freeze on creation because
8751 -- any associated types must be frozen at this point.
8753 Freeze_Itype (Atyp, N);
8754 return Atyp;
8756 -- Otherwise we did not build a declaration, so return original
8758 else
8759 return Typ;
8760 end if;
8761 end if;
8763 -- For all remaining cases, the actual subtype is the same as
8764 -- the nominal type.
8766 else
8767 return Typ;
8768 end if;
8769 end Get_Actual_Subtype;
8771 -------------------------------------
8772 -- Get_Actual_Subtype_If_Available --
8773 -------------------------------------
8775 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
8776 Typ : constant Entity_Id := Etype (N);
8778 begin
8779 -- If what we have is an identifier that references a subprogram
8780 -- formal, or a variable or constant object, then we get the actual
8781 -- subtype from the referenced entity if one has been built.
8783 if Nkind (N) = N_Identifier
8784 and then
8785 (Is_Formal (Entity (N))
8786 or else Ekind (Entity (N)) = E_Constant
8787 or else Ekind (Entity (N)) = E_Variable)
8788 and then Present (Actual_Subtype (Entity (N)))
8789 then
8790 return Actual_Subtype (Entity (N));
8792 -- Otherwise the Etype of N is returned unchanged
8794 else
8795 return Typ;
8796 end if;
8797 end Get_Actual_Subtype_If_Available;
8799 ------------------------
8800 -- Get_Body_From_Stub --
8801 ------------------------
8803 function Get_Body_From_Stub (N : Node_Id) return Node_Id is
8804 begin
8805 return Proper_Body (Unit (Library_Unit (N)));
8806 end Get_Body_From_Stub;
8808 ---------------------
8809 -- Get_Cursor_Type --
8810 ---------------------
8812 function Get_Cursor_Type
8813 (Aspect : Node_Id;
8814 Typ : Entity_Id) return Entity_Id
8816 Assoc : Node_Id;
8817 Func : Entity_Id;
8818 First_Op : Entity_Id;
8819 Cursor : Entity_Id;
8821 begin
8822 -- If error already detected, return
8824 if Error_Posted (Aspect) then
8825 return Any_Type;
8826 end if;
8828 -- The cursor type for an Iterable aspect is the return type of a
8829 -- non-overloaded First primitive operation. Locate association for
8830 -- First.
8832 Assoc := First (Component_Associations (Expression (Aspect)));
8833 First_Op := Any_Id;
8834 while Present (Assoc) loop
8835 if Chars (First (Choices (Assoc))) = Name_First then
8836 First_Op := Expression (Assoc);
8837 exit;
8838 end if;
8840 Next (Assoc);
8841 end loop;
8843 if First_Op = Any_Id then
8844 Error_Msg_N ("aspect Iterable must specify First operation", Aspect);
8845 return Any_Type;
8846 end if;
8848 Cursor := Any_Type;
8850 -- Locate function with desired name and profile in scope of type
8851 -- In the rare case where the type is an integer type, a base type
8852 -- is created for it, check that the base type of the first formal
8853 -- of First matches the base type of the domain.
8855 Func := First_Entity (Scope (Typ));
8856 while Present (Func) loop
8857 if Chars (Func) = Chars (First_Op)
8858 and then Ekind (Func) = E_Function
8859 and then Present (First_Formal (Func))
8860 and then Base_Type (Etype (First_Formal (Func))) = Base_Type (Typ)
8861 and then No (Next_Formal (First_Formal (Func)))
8862 then
8863 if Cursor /= Any_Type then
8864 Error_Msg_N
8865 ("Operation First for iterable type must be unique", Aspect);
8866 return Any_Type;
8867 else
8868 Cursor := Etype (Func);
8869 end if;
8870 end if;
8872 Next_Entity (Func);
8873 end loop;
8875 -- If not found, no way to resolve remaining primitives.
8877 if Cursor = Any_Type then
8878 Error_Msg_N
8879 ("No legal primitive operation First for Iterable type", Aspect);
8880 end if;
8882 return Cursor;
8883 end Get_Cursor_Type;
8885 function Get_Cursor_Type (Typ : Entity_Id) return Entity_Id is
8886 begin
8887 return Etype (Get_Iterable_Type_Primitive (Typ, Name_First));
8888 end Get_Cursor_Type;
8890 -------------------------------
8891 -- Get_Default_External_Name --
8892 -------------------------------
8894 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
8895 begin
8896 Get_Decoded_Name_String (Chars (E));
8898 if Opt.External_Name_Imp_Casing = Uppercase then
8899 Set_Casing (All_Upper_Case);
8900 else
8901 Set_Casing (All_Lower_Case);
8902 end if;
8904 return
8905 Make_String_Literal (Sloc (E),
8906 Strval => String_From_Name_Buffer);
8907 end Get_Default_External_Name;
8909 --------------------------
8910 -- Get_Enclosing_Object --
8911 --------------------------
8913 function Get_Enclosing_Object (N : Node_Id) return Entity_Id is
8914 begin
8915 if Is_Entity_Name (N) then
8916 return Entity (N);
8917 else
8918 case Nkind (N) is
8919 when N_Indexed_Component
8920 | N_Selected_Component
8921 | N_Slice
8923 -- If not generating code, a dereference may be left implicit.
8924 -- In thoses cases, return Empty.
8926 if Is_Access_Type (Etype (Prefix (N))) then
8927 return Empty;
8928 else
8929 return Get_Enclosing_Object (Prefix (N));
8930 end if;
8932 when N_Type_Conversion =>
8933 return Get_Enclosing_Object (Expression (N));
8935 when others =>
8936 return Empty;
8937 end case;
8938 end if;
8939 end Get_Enclosing_Object;
8941 ---------------------------
8942 -- Get_Enum_Lit_From_Pos --
8943 ---------------------------
8945 function Get_Enum_Lit_From_Pos
8946 (T : Entity_Id;
8947 Pos : Uint;
8948 Loc : Source_Ptr) return Node_Id
8950 Btyp : Entity_Id := Base_Type (T);
8951 Lit : Node_Id;
8952 LLoc : Source_Ptr;
8954 begin
8955 -- In the case where the literal is of type Character, Wide_Character
8956 -- or Wide_Wide_Character or of a type derived from them, there needs
8957 -- to be some special handling since there is no explicit chain of
8958 -- literals to search. Instead, an N_Character_Literal node is created
8959 -- with the appropriate Char_Code and Chars fields.
8961 if Is_Standard_Character_Type (T) then
8962 Set_Character_Literal_Name (UI_To_CC (Pos));
8964 return
8965 Make_Character_Literal (Loc,
8966 Chars => Name_Find,
8967 Char_Literal_Value => Pos);
8969 -- For all other cases, we have a complete table of literals, and
8970 -- we simply iterate through the chain of literal until the one
8971 -- with the desired position value is found.
8973 else
8974 if Is_Private_Type (Btyp) and then Present (Full_View (Btyp)) then
8975 Btyp := Full_View (Btyp);
8976 end if;
8978 Lit := First_Literal (Btyp);
8980 -- Position in the enumeration type starts at 0
8982 if UI_To_Int (Pos) < 0 then
8983 raise Constraint_Error;
8984 end if;
8986 for J in 1 .. UI_To_Int (Pos) loop
8987 Next_Literal (Lit);
8989 -- If Lit is Empty, Pos is not in range, so raise Constraint_Error
8990 -- inside the loop to avoid calling Next_Literal on Empty.
8992 if No (Lit) then
8993 raise Constraint_Error;
8994 end if;
8995 end loop;
8997 -- Create a new node from Lit, with source location provided by Loc
8998 -- if not equal to No_Location, or by copying the source location of
8999 -- Lit otherwise.
9001 LLoc := Loc;
9003 if LLoc = No_Location then
9004 LLoc := Sloc (Lit);
9005 end if;
9007 return New_Occurrence_Of (Lit, LLoc);
9008 end if;
9009 end Get_Enum_Lit_From_Pos;
9011 ------------------------
9012 -- Get_Generic_Entity --
9013 ------------------------
9015 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
9016 Ent : constant Entity_Id := Entity (Name (N));
9017 begin
9018 if Present (Renamed_Object (Ent)) then
9019 return Renamed_Object (Ent);
9020 else
9021 return Ent;
9022 end if;
9023 end Get_Generic_Entity;
9025 -------------------------------------
9026 -- Get_Incomplete_View_Of_Ancestor --
9027 -------------------------------------
9029 function Get_Incomplete_View_Of_Ancestor (E : Entity_Id) return Entity_Id is
9030 Cur_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
9031 Par_Scope : Entity_Id;
9032 Par_Type : Entity_Id;
9034 begin
9035 -- The incomplete view of an ancestor is only relevant for private
9036 -- derived types in child units.
9038 if not Is_Derived_Type (E)
9039 or else not Is_Child_Unit (Cur_Unit)
9040 then
9041 return Empty;
9043 else
9044 Par_Scope := Scope (Cur_Unit);
9045 if No (Par_Scope) then
9046 return Empty;
9047 end if;
9049 Par_Type := Etype (Base_Type (E));
9051 -- Traverse list of ancestor types until we find one declared in
9052 -- a parent or grandparent unit (two levels seem sufficient).
9054 while Present (Par_Type) loop
9055 if Scope (Par_Type) = Par_Scope
9056 or else Scope (Par_Type) = Scope (Par_Scope)
9057 then
9058 return Par_Type;
9060 elsif not Is_Derived_Type (Par_Type) then
9061 return Empty;
9063 else
9064 Par_Type := Etype (Base_Type (Par_Type));
9065 end if;
9066 end loop;
9068 -- If none found, there is no relevant ancestor type.
9070 return Empty;
9071 end if;
9072 end Get_Incomplete_View_Of_Ancestor;
9074 ----------------------
9075 -- Get_Index_Bounds --
9076 ----------------------
9078 procedure Get_Index_Bounds
9079 (N : Node_Id;
9080 L : out Node_Id;
9081 H : out Node_Id;
9082 Use_Full_View : Boolean := False)
9084 function Scalar_Range_Of_Type (Typ : Entity_Id) return Node_Id;
9085 -- Obtain the scalar range of type Typ. If flag Use_Full_View is set and
9086 -- Typ qualifies, the scalar range is obtained from the full view of the
9087 -- type.
9089 --------------------------
9090 -- Scalar_Range_Of_Type --
9091 --------------------------
9093 function Scalar_Range_Of_Type (Typ : Entity_Id) return Node_Id is
9094 T : Entity_Id := Typ;
9096 begin
9097 if Use_Full_View and then Present (Full_View (T)) then
9098 T := Full_View (T);
9099 end if;
9101 return Scalar_Range (T);
9102 end Scalar_Range_Of_Type;
9104 -- Local variables
9106 Kind : constant Node_Kind := Nkind (N);
9107 Rng : Node_Id;
9109 -- Start of processing for Get_Index_Bounds
9111 begin
9112 if Kind = N_Range then
9113 L := Low_Bound (N);
9114 H := High_Bound (N);
9116 elsif Kind = N_Subtype_Indication then
9117 Rng := Range_Expression (Constraint (N));
9119 if Rng = Error then
9120 L := Error;
9121 H := Error;
9122 return;
9124 else
9125 L := Low_Bound (Range_Expression (Constraint (N)));
9126 H := High_Bound (Range_Expression (Constraint (N)));
9127 end if;
9129 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
9130 Rng := Scalar_Range_Of_Type (Entity (N));
9132 if Error_Posted (Rng) then
9133 L := Error;
9134 H := Error;
9136 elsif Nkind (Rng) = N_Subtype_Indication then
9137 Get_Index_Bounds (Rng, L, H);
9139 else
9140 L := Low_Bound (Rng);
9141 H := High_Bound (Rng);
9142 end if;
9144 else
9145 -- N is an expression, indicating a range with one value
9147 L := N;
9148 H := N;
9149 end if;
9150 end Get_Index_Bounds;
9152 -----------------------------
9153 -- Get_Interfacing_Aspects --
9154 -----------------------------
9156 procedure Get_Interfacing_Aspects
9157 (Iface_Asp : Node_Id;
9158 Conv_Asp : out Node_Id;
9159 EN_Asp : out Node_Id;
9160 Expo_Asp : out Node_Id;
9161 Imp_Asp : out Node_Id;
9162 LN_Asp : out Node_Id;
9163 Do_Checks : Boolean := False)
9165 procedure Save_Or_Duplication_Error
9166 (Asp : Node_Id;
9167 To : in out Node_Id);
9168 -- Save the value of aspect Asp in node To. If To already has a value,
9169 -- then this is considered a duplicate use of aspect. Emit an error if
9170 -- flag Do_Checks is set.
9172 -------------------------------
9173 -- Save_Or_Duplication_Error --
9174 -------------------------------
9176 procedure Save_Or_Duplication_Error
9177 (Asp : Node_Id;
9178 To : in out Node_Id)
9180 begin
9181 -- Detect an extra aspect and issue an error
9183 if Present (To) then
9184 if Do_Checks then
9185 Error_Msg_Name_1 := Chars (Identifier (Asp));
9186 Error_Msg_Sloc := Sloc (To);
9187 Error_Msg_N ("aspect % previously given #", Asp);
9188 end if;
9190 -- Otherwise capture the aspect
9192 else
9193 To := Asp;
9194 end if;
9195 end Save_Or_Duplication_Error;
9197 -- Local variables
9199 Asp : Node_Id;
9200 Asp_Id : Aspect_Id;
9202 -- The following variables capture each individual aspect
9204 Conv : Node_Id := Empty;
9205 EN : Node_Id := Empty;
9206 Expo : Node_Id := Empty;
9207 Imp : Node_Id := Empty;
9208 LN : Node_Id := Empty;
9210 -- Start of processing for Get_Interfacing_Aspects
9212 begin
9213 -- The input interfacing aspect should reside in an aspect specification
9214 -- list.
9216 pragma Assert (Is_List_Member (Iface_Asp));
9218 -- Examine the aspect specifications of the related entity. Find and
9219 -- capture all interfacing aspects. Detect duplicates and emit errors
9220 -- if applicable.
9222 Asp := First (List_Containing (Iface_Asp));
9223 while Present (Asp) loop
9224 Asp_Id := Get_Aspect_Id (Asp);
9226 if Asp_Id = Aspect_Convention then
9227 Save_Or_Duplication_Error (Asp, Conv);
9229 elsif Asp_Id = Aspect_External_Name then
9230 Save_Or_Duplication_Error (Asp, EN);
9232 elsif Asp_Id = Aspect_Export then
9233 Save_Or_Duplication_Error (Asp, Expo);
9235 elsif Asp_Id = Aspect_Import then
9236 Save_Or_Duplication_Error (Asp, Imp);
9238 elsif Asp_Id = Aspect_Link_Name then
9239 Save_Or_Duplication_Error (Asp, LN);
9240 end if;
9242 Next (Asp);
9243 end loop;
9245 Conv_Asp := Conv;
9246 EN_Asp := EN;
9247 Expo_Asp := Expo;
9248 Imp_Asp := Imp;
9249 LN_Asp := LN;
9250 end Get_Interfacing_Aspects;
9252 ---------------------------------
9253 -- Get_Iterable_Type_Primitive --
9254 ---------------------------------
9256 function Get_Iterable_Type_Primitive
9257 (Typ : Entity_Id;
9258 Nam : Name_Id) return Entity_Id
9260 Funcs : constant Node_Id := Find_Value_Of_Aspect (Typ, Aspect_Iterable);
9261 Assoc : Node_Id;
9263 begin
9264 if No (Funcs) then
9265 return Empty;
9267 else
9268 Assoc := First (Component_Associations (Funcs));
9269 while Present (Assoc) loop
9270 if Chars (First (Choices (Assoc))) = Nam then
9271 return Entity (Expression (Assoc));
9272 end if;
9274 Assoc := Next (Assoc);
9275 end loop;
9277 return Empty;
9278 end if;
9279 end Get_Iterable_Type_Primitive;
9281 ----------------------------------
9282 -- Get_Library_Unit_Name_string --
9283 ----------------------------------
9285 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
9286 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
9288 begin
9289 Get_Unit_Name_String (Unit_Name_Id);
9291 -- Remove seven last character (" (spec)" or " (body)")
9293 Name_Len := Name_Len - 7;
9294 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
9295 end Get_Library_Unit_Name_String;
9297 --------------------------
9298 -- Get_Max_Queue_Length --
9299 --------------------------
9301 function Get_Max_Queue_Length (Id : Entity_Id) return Uint is
9302 pragma Assert (Is_Entry (Id));
9303 Prag : constant Entity_Id := Get_Pragma (Id, Pragma_Max_Queue_Length);
9305 begin
9306 -- A value of 0 represents no maximum specified, and entries and entry
9307 -- families with no Max_Queue_Length aspect or pragma default to it.
9309 if not Present (Prag) then
9310 return Uint_0;
9311 end if;
9313 return Intval (Expression (First (Pragma_Argument_Associations (Prag))));
9314 end Get_Max_Queue_Length;
9316 ------------------------
9317 -- Get_Name_Entity_Id --
9318 ------------------------
9320 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
9321 begin
9322 return Entity_Id (Get_Name_Table_Int (Id));
9323 end Get_Name_Entity_Id;
9325 ------------------------------
9326 -- Get_Name_From_CTC_Pragma --
9327 ------------------------------
9329 function Get_Name_From_CTC_Pragma (N : Node_Id) return String_Id is
9330 Arg : constant Node_Id :=
9331 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
9332 begin
9333 return Strval (Expr_Value_S (Arg));
9334 end Get_Name_From_CTC_Pragma;
9336 -----------------------
9337 -- Get_Parent_Entity --
9338 -----------------------
9340 function Get_Parent_Entity (Unit : Node_Id) return Entity_Id is
9341 begin
9342 if Nkind (Unit) = N_Package_Body
9343 and then Nkind (Original_Node (Unit)) = N_Package_Instantiation
9344 then
9345 return Defining_Entity
9346 (Specification (Instance_Spec (Original_Node (Unit))));
9347 elsif Nkind (Unit) = N_Package_Instantiation then
9348 return Defining_Entity (Specification (Instance_Spec (Unit)));
9349 else
9350 return Defining_Entity (Unit);
9351 end if;
9352 end Get_Parent_Entity;
9354 -------------------
9355 -- Get_Pragma_Id --
9356 -------------------
9358 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
9359 begin
9360 return Get_Pragma_Id (Pragma_Name_Unmapped (N));
9361 end Get_Pragma_Id;
9363 ------------------------
9364 -- Get_Qualified_Name --
9365 ------------------------
9367 function Get_Qualified_Name
9368 (Id : Entity_Id;
9369 Suffix : Entity_Id := Empty) return Name_Id
9371 Suffix_Nam : Name_Id := No_Name;
9373 begin
9374 if Present (Suffix) then
9375 Suffix_Nam := Chars (Suffix);
9376 end if;
9378 return Get_Qualified_Name (Chars (Id), Suffix_Nam, Scope (Id));
9379 end Get_Qualified_Name;
9381 function Get_Qualified_Name
9382 (Nam : Name_Id;
9383 Suffix : Name_Id := No_Name;
9384 Scop : Entity_Id := Current_Scope) return Name_Id
9386 procedure Add_Scope (S : Entity_Id);
9387 -- Add the fully qualified form of scope S to the name buffer. The
9388 -- format is:
9389 -- s-1__s__
9391 ---------------
9392 -- Add_Scope --
9393 ---------------
9395 procedure Add_Scope (S : Entity_Id) is
9396 begin
9397 if S = Empty then
9398 null;
9400 elsif S = Standard_Standard then
9401 null;
9403 else
9404 Add_Scope (Scope (S));
9405 Get_Name_String_And_Append (Chars (S));
9406 Add_Str_To_Name_Buffer ("__");
9407 end if;
9408 end Add_Scope;
9410 -- Start of processing for Get_Qualified_Name
9412 begin
9413 Name_Len := 0;
9414 Add_Scope (Scop);
9416 -- Append the base name after all scopes have been chained
9418 Get_Name_String_And_Append (Nam);
9420 -- Append the suffix (if present)
9422 if Suffix /= No_Name then
9423 Add_Str_To_Name_Buffer ("__");
9424 Get_Name_String_And_Append (Suffix);
9425 end if;
9427 return Name_Find;
9428 end Get_Qualified_Name;
9430 -----------------------
9431 -- Get_Reason_String --
9432 -----------------------
9434 procedure Get_Reason_String (N : Node_Id) is
9435 begin
9436 if Nkind (N) = N_String_Literal then
9437 Store_String_Chars (Strval (N));
9439 elsif Nkind (N) = N_Op_Concat then
9440 Get_Reason_String (Left_Opnd (N));
9441 Get_Reason_String (Right_Opnd (N));
9443 -- If not of required form, error
9445 else
9446 Error_Msg_N
9447 ("Reason for pragma Warnings has wrong form", N);
9448 Error_Msg_N
9449 ("\must be string literal or concatenation of string literals", N);
9450 return;
9451 end if;
9452 end Get_Reason_String;
9454 --------------------------------
9455 -- Get_Reference_Discriminant --
9456 --------------------------------
9458 function Get_Reference_Discriminant (Typ : Entity_Id) return Entity_Id is
9459 D : Entity_Id;
9461 begin
9462 D := First_Discriminant (Typ);
9463 while Present (D) loop
9464 if Has_Implicit_Dereference (D) then
9465 return D;
9466 end if;
9467 Next_Discriminant (D);
9468 end loop;
9470 return Empty;
9471 end Get_Reference_Discriminant;
9473 ---------------------------
9474 -- Get_Referenced_Object --
9475 ---------------------------
9477 function Get_Referenced_Object (N : Node_Id) return Node_Id is
9478 R : Node_Id;
9480 begin
9481 R := N;
9482 while Is_Entity_Name (R)
9483 and then Present (Renamed_Object (Entity (R)))
9484 loop
9485 R := Renamed_Object (Entity (R));
9486 end loop;
9488 return R;
9489 end Get_Referenced_Object;
9491 ------------------------
9492 -- Get_Renamed_Entity --
9493 ------------------------
9495 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
9496 R : Entity_Id;
9498 begin
9499 R := E;
9500 while Present (Renamed_Entity (R)) loop
9501 R := Renamed_Entity (R);
9502 end loop;
9504 return R;
9505 end Get_Renamed_Entity;
9507 -----------------------
9508 -- Get_Return_Object --
9509 -----------------------
9511 function Get_Return_Object (N : Node_Id) return Entity_Id is
9512 Decl : Node_Id;
9514 begin
9515 Decl := First (Return_Object_Declarations (N));
9516 while Present (Decl) loop
9517 exit when Nkind (Decl) = N_Object_Declaration
9518 and then Is_Return_Object (Defining_Identifier (Decl));
9519 Next (Decl);
9520 end loop;
9522 pragma Assert (Present (Decl));
9523 return Defining_Identifier (Decl);
9524 end Get_Return_Object;
9526 ---------------------------
9527 -- Get_Subprogram_Entity --
9528 ---------------------------
9530 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
9531 Subp : Node_Id;
9532 Subp_Id : Entity_Id;
9534 begin
9535 if Nkind (Nod) = N_Accept_Statement then
9536 Subp := Entry_Direct_Name (Nod);
9538 elsif Nkind (Nod) = N_Slice then
9539 Subp := Prefix (Nod);
9541 else
9542 Subp := Name (Nod);
9543 end if;
9545 -- Strip the subprogram call
9547 loop
9548 if Nkind_In (Subp, N_Explicit_Dereference,
9549 N_Indexed_Component,
9550 N_Selected_Component)
9551 then
9552 Subp := Prefix (Subp);
9554 elsif Nkind_In (Subp, N_Type_Conversion,
9555 N_Unchecked_Type_Conversion)
9556 then
9557 Subp := Expression (Subp);
9559 else
9560 exit;
9561 end if;
9562 end loop;
9564 -- Extract the entity of the subprogram call
9566 if Is_Entity_Name (Subp) then
9567 Subp_Id := Entity (Subp);
9569 if Ekind (Subp_Id) = E_Access_Subprogram_Type then
9570 Subp_Id := Directly_Designated_Type (Subp_Id);
9571 end if;
9573 if Is_Subprogram (Subp_Id) then
9574 return Subp_Id;
9575 else
9576 return Empty;
9577 end if;
9579 -- The search did not find a construct that denotes a subprogram
9581 else
9582 return Empty;
9583 end if;
9584 end Get_Subprogram_Entity;
9586 -----------------------------
9587 -- Get_Task_Body_Procedure --
9588 -----------------------------
9590 function Get_Task_Body_Procedure (E : Entity_Id) return Entity_Id is
9591 begin
9592 -- Note: A task type may be the completion of a private type with
9593 -- discriminants. When performing elaboration checks on a task
9594 -- declaration, the current view of the type may be the private one,
9595 -- and the procedure that holds the body of the task is held in its
9596 -- underlying type.
9598 -- This is an odd function, why not have Task_Body_Procedure do
9599 -- the following digging???
9601 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
9602 end Get_Task_Body_Procedure;
9604 -------------------------
9605 -- Get_User_Defined_Eq --
9606 -------------------------
9608 function Get_User_Defined_Eq (E : Entity_Id) return Entity_Id is
9609 Prim : Elmt_Id;
9610 Op : Entity_Id;
9612 begin
9613 Prim := First_Elmt (Collect_Primitive_Operations (E));
9614 while Present (Prim) loop
9615 Op := Node (Prim);
9617 if Chars (Op) = Name_Op_Eq
9618 and then Etype (Op) = Standard_Boolean
9619 and then Etype (First_Formal (Op)) = E
9620 and then Etype (Next_Formal (First_Formal (Op))) = E
9621 then
9622 return Op;
9623 end if;
9625 Next_Elmt (Prim);
9626 end loop;
9628 return Empty;
9629 end Get_User_Defined_Eq;
9631 ---------------
9632 -- Get_Views --
9633 ---------------
9635 procedure Get_Views
9636 (Typ : Entity_Id;
9637 Priv_Typ : out Entity_Id;
9638 Full_Typ : out Entity_Id;
9639 Full_Base : out Entity_Id;
9640 CRec_Typ : out Entity_Id)
9642 IP_View : Entity_Id;
9644 begin
9645 -- Assume that none of the views can be recovered
9647 Priv_Typ := Empty;
9648 Full_Typ := Empty;
9649 Full_Base := Empty;
9650 CRec_Typ := Empty;
9652 -- The input type is the corresponding record type of a protected or a
9653 -- task type.
9655 if Ekind (Typ) = E_Record_Type
9656 and then Is_Concurrent_Record_Type (Typ)
9657 then
9658 CRec_Typ := Typ;
9659 Full_Typ := Corresponding_Concurrent_Type (CRec_Typ);
9660 Full_Base := Base_Type (Full_Typ);
9661 Priv_Typ := Incomplete_Or_Partial_View (Full_Typ);
9663 -- Otherwise the input type denotes an arbitrary type
9665 else
9666 IP_View := Incomplete_Or_Partial_View (Typ);
9668 -- The input type denotes the full view of a private type
9670 if Present (IP_View) then
9671 Priv_Typ := IP_View;
9672 Full_Typ := Typ;
9674 -- The input type is a private type
9676 elsif Is_Private_Type (Typ) then
9677 Priv_Typ := Typ;
9678 Full_Typ := Full_View (Priv_Typ);
9680 -- Otherwise the input type does not have any views
9682 else
9683 Full_Typ := Typ;
9684 end if;
9686 if Present (Full_Typ) then
9687 Full_Base := Base_Type (Full_Typ);
9689 if Ekind_In (Full_Typ, E_Protected_Type, E_Task_Type) then
9690 CRec_Typ := Corresponding_Record_Type (Full_Typ);
9691 end if;
9692 end if;
9693 end if;
9694 end Get_Views;
9696 -----------------------
9697 -- Has_Access_Values --
9698 -----------------------
9700 function Has_Access_Values (T : Entity_Id) return Boolean is
9701 Typ : constant Entity_Id := Underlying_Type (T);
9703 begin
9704 -- Case of a private type which is not completed yet. This can only
9705 -- happen in the case of a generic format type appearing directly, or
9706 -- as a component of the type to which this function is being applied
9707 -- at the top level. Return False in this case, since we certainly do
9708 -- not know that the type contains access types.
9710 if No (Typ) then
9711 return False;
9713 elsif Is_Access_Type (Typ) then
9714 return True;
9716 elsif Is_Array_Type (Typ) then
9717 return Has_Access_Values (Component_Type (Typ));
9719 elsif Is_Record_Type (Typ) then
9720 declare
9721 Comp : Entity_Id;
9723 begin
9724 -- Loop to Check components
9726 Comp := First_Component_Or_Discriminant (Typ);
9727 while Present (Comp) loop
9729 -- Check for access component, tag field does not count, even
9730 -- though it is implemented internally using an access type.
9732 if Has_Access_Values (Etype (Comp))
9733 and then Chars (Comp) /= Name_uTag
9734 then
9735 return True;
9736 end if;
9738 Next_Component_Or_Discriminant (Comp);
9739 end loop;
9740 end;
9742 return False;
9744 else
9745 return False;
9746 end if;
9747 end Has_Access_Values;
9749 ------------------------------
9750 -- Has_Compatible_Alignment --
9751 ------------------------------
9753 function Has_Compatible_Alignment
9754 (Obj : Entity_Id;
9755 Expr : Node_Id;
9756 Layout_Done : Boolean) return Alignment_Result
9758 function Has_Compatible_Alignment_Internal
9759 (Obj : Entity_Id;
9760 Expr : Node_Id;
9761 Layout_Done : Boolean;
9762 Default : Alignment_Result) return Alignment_Result;
9763 -- This is the internal recursive function that actually does the work.
9764 -- There is one additional parameter, which says what the result should
9765 -- be if no alignment information is found, and there is no definite
9766 -- indication of compatible alignments. At the outer level, this is set
9767 -- to Unknown, but for internal recursive calls in the case where types
9768 -- are known to be correct, it is set to Known_Compatible.
9770 ---------------------------------------
9771 -- Has_Compatible_Alignment_Internal --
9772 ---------------------------------------
9774 function Has_Compatible_Alignment_Internal
9775 (Obj : Entity_Id;
9776 Expr : Node_Id;
9777 Layout_Done : Boolean;
9778 Default : Alignment_Result) return Alignment_Result
9780 Result : Alignment_Result := Known_Compatible;
9781 -- Holds the current status of the result. Note that once a value of
9782 -- Known_Incompatible is set, it is sticky and does not get changed
9783 -- to Unknown (the value in Result only gets worse as we go along,
9784 -- never better).
9786 Offs : Uint := No_Uint;
9787 -- Set to a factor of the offset from the base object when Expr is a
9788 -- selected or indexed component, based on Component_Bit_Offset and
9789 -- Component_Size respectively. A negative value is used to represent
9790 -- a value which is not known at compile time.
9792 procedure Check_Prefix;
9793 -- Checks the prefix recursively in the case where the expression
9794 -- is an indexed or selected component.
9796 procedure Set_Result (R : Alignment_Result);
9797 -- If R represents a worse outcome (unknown instead of known
9798 -- compatible, or known incompatible), then set Result to R.
9800 ------------------
9801 -- Check_Prefix --
9802 ------------------
9804 procedure Check_Prefix is
9805 begin
9806 -- The subtlety here is that in doing a recursive call to check
9807 -- the prefix, we have to decide what to do in the case where we
9808 -- don't find any specific indication of an alignment problem.
9810 -- At the outer level, we normally set Unknown as the result in
9811 -- this case, since we can only set Known_Compatible if we really
9812 -- know that the alignment value is OK, but for the recursive
9813 -- call, in the case where the types match, and we have not
9814 -- specified a peculiar alignment for the object, we are only
9815 -- concerned about suspicious rep clauses, the default case does
9816 -- not affect us, since the compiler will, in the absence of such
9817 -- rep clauses, ensure that the alignment is correct.
9819 if Default = Known_Compatible
9820 or else
9821 (Etype (Obj) = Etype (Expr)
9822 and then (Unknown_Alignment (Obj)
9823 or else
9824 Alignment (Obj) = Alignment (Etype (Obj))))
9825 then
9826 Set_Result
9827 (Has_Compatible_Alignment_Internal
9828 (Obj, Prefix (Expr), Layout_Done, Known_Compatible));
9830 -- In all other cases, we need a full check on the prefix
9832 else
9833 Set_Result
9834 (Has_Compatible_Alignment_Internal
9835 (Obj, Prefix (Expr), Layout_Done, Unknown));
9836 end if;
9837 end Check_Prefix;
9839 ----------------
9840 -- Set_Result --
9841 ----------------
9843 procedure Set_Result (R : Alignment_Result) is
9844 begin
9845 if R > Result then
9846 Result := R;
9847 end if;
9848 end Set_Result;
9850 -- Start of processing for Has_Compatible_Alignment_Internal
9852 begin
9853 -- If Expr is a selected component, we must make sure there is no
9854 -- potentially troublesome component clause and that the record is
9855 -- not packed if the layout is not done.
9857 if Nkind (Expr) = N_Selected_Component then
9859 -- Packing generates unknown alignment if layout is not done
9861 if Is_Packed (Etype (Prefix (Expr))) and then not Layout_Done then
9862 Set_Result (Unknown);
9863 end if;
9865 -- Check prefix and component offset
9867 Check_Prefix;
9868 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
9870 -- If Expr is an indexed component, we must make sure there is no
9871 -- potentially troublesome Component_Size clause and that the array
9872 -- is not bit-packed if the layout is not done.
9874 elsif Nkind (Expr) = N_Indexed_Component then
9875 declare
9876 Typ : constant Entity_Id := Etype (Prefix (Expr));
9878 begin
9879 -- Packing generates unknown alignment if layout is not done
9881 if Is_Bit_Packed_Array (Typ) and then not Layout_Done then
9882 Set_Result (Unknown);
9883 end if;
9885 -- Check prefix and component offset (or at least size)
9887 Check_Prefix;
9888 Offs := Indexed_Component_Bit_Offset (Expr);
9889 if Offs = No_Uint then
9890 Offs := Component_Size (Typ);
9891 end if;
9892 end;
9893 end if;
9895 -- If we have a null offset, the result is entirely determined by
9896 -- the base object and has already been computed recursively.
9898 if Offs = Uint_0 then
9899 null;
9901 -- Case where we know the alignment of the object
9903 elsif Known_Alignment (Obj) then
9904 declare
9905 ObjA : constant Uint := Alignment (Obj);
9906 ExpA : Uint := No_Uint;
9907 SizA : Uint := No_Uint;
9909 begin
9910 -- If alignment of Obj is 1, then we are always OK
9912 if ObjA = 1 then
9913 Set_Result (Known_Compatible);
9915 -- Alignment of Obj is greater than 1, so we need to check
9917 else
9918 -- If we have an offset, see if it is compatible
9920 if Offs /= No_Uint and Offs > Uint_0 then
9921 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
9922 Set_Result (Known_Incompatible);
9923 end if;
9925 -- See if Expr is an object with known alignment
9927 elsif Is_Entity_Name (Expr)
9928 and then Known_Alignment (Entity (Expr))
9929 then
9930 ExpA := Alignment (Entity (Expr));
9932 -- Otherwise, we can use the alignment of the type of
9933 -- Expr given that we already checked for
9934 -- discombobulating rep clauses for the cases of indexed
9935 -- and selected components above.
9937 elsif Known_Alignment (Etype (Expr)) then
9938 ExpA := Alignment (Etype (Expr));
9940 -- Otherwise the alignment is unknown
9942 else
9943 Set_Result (Default);
9944 end if;
9946 -- If we got an alignment, see if it is acceptable
9948 if ExpA /= No_Uint and then ExpA < ObjA then
9949 Set_Result (Known_Incompatible);
9950 end if;
9952 -- If Expr is not a piece of a larger object, see if size
9953 -- is given. If so, check that it is not too small for the
9954 -- required alignment.
9956 if Offs /= No_Uint then
9957 null;
9959 -- See if Expr is an object with known size
9961 elsif Is_Entity_Name (Expr)
9962 and then Known_Static_Esize (Entity (Expr))
9963 then
9964 SizA := Esize (Entity (Expr));
9966 -- Otherwise, we check the object size of the Expr type
9968 elsif Known_Static_Esize (Etype (Expr)) then
9969 SizA := Esize (Etype (Expr));
9970 end if;
9972 -- If we got a size, see if it is a multiple of the Obj
9973 -- alignment, if not, then the alignment cannot be
9974 -- acceptable, since the size is always a multiple of the
9975 -- alignment.
9977 if SizA /= No_Uint then
9978 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
9979 Set_Result (Known_Incompatible);
9980 end if;
9981 end if;
9982 end if;
9983 end;
9985 -- If we do not know required alignment, any non-zero offset is a
9986 -- potential problem (but certainly may be OK, so result is unknown).
9988 elsif Offs /= No_Uint then
9989 Set_Result (Unknown);
9991 -- If we can't find the result by direct comparison of alignment
9992 -- values, then there is still one case that we can determine known
9993 -- result, and that is when we can determine that the types are the
9994 -- same, and no alignments are specified. Then we known that the
9995 -- alignments are compatible, even if we don't know the alignment
9996 -- value in the front end.
9998 elsif Etype (Obj) = Etype (Expr) then
10000 -- Types are the same, but we have to check for possible size
10001 -- and alignments on the Expr object that may make the alignment
10002 -- different, even though the types are the same.
10004 if Is_Entity_Name (Expr) then
10006 -- First check alignment of the Expr object. Any alignment less
10007 -- than Maximum_Alignment is worrisome since this is the case
10008 -- where we do not know the alignment of Obj.
10010 if Known_Alignment (Entity (Expr))
10011 and then UI_To_Int (Alignment (Entity (Expr))) <
10012 Ttypes.Maximum_Alignment
10013 then
10014 Set_Result (Unknown);
10016 -- Now check size of Expr object. Any size that is not an
10017 -- even multiple of Maximum_Alignment is also worrisome
10018 -- since it may cause the alignment of the object to be less
10019 -- than the alignment of the type.
10021 elsif Known_Static_Esize (Entity (Expr))
10022 and then
10023 (UI_To_Int (Esize (Entity (Expr))) mod
10024 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
10025 /= 0
10026 then
10027 Set_Result (Unknown);
10029 -- Otherwise same type is decisive
10031 else
10032 Set_Result (Known_Compatible);
10033 end if;
10034 end if;
10036 -- Another case to deal with is when there is an explicit size or
10037 -- alignment clause when the types are not the same. If so, then the
10038 -- result is Unknown. We don't need to do this test if the Default is
10039 -- Unknown, since that result will be set in any case.
10041 elsif Default /= Unknown
10042 and then (Has_Size_Clause (Etype (Expr))
10043 or else
10044 Has_Alignment_Clause (Etype (Expr)))
10045 then
10046 Set_Result (Unknown);
10048 -- If no indication found, set default
10050 else
10051 Set_Result (Default);
10052 end if;
10054 -- Return worst result found
10056 return Result;
10057 end Has_Compatible_Alignment_Internal;
10059 -- Start of processing for Has_Compatible_Alignment
10061 begin
10062 -- If Obj has no specified alignment, then set alignment from the type
10063 -- alignment. Perhaps we should always do this, but for sure we should
10064 -- do it when there is an address clause since we can do more if the
10065 -- alignment is known.
10067 if Unknown_Alignment (Obj) then
10068 Set_Alignment (Obj, Alignment (Etype (Obj)));
10069 end if;
10071 -- Now do the internal call that does all the work
10073 return
10074 Has_Compatible_Alignment_Internal (Obj, Expr, Layout_Done, Unknown);
10075 end Has_Compatible_Alignment;
10077 ----------------------
10078 -- Has_Declarations --
10079 ----------------------
10081 function Has_Declarations (N : Node_Id) return Boolean is
10082 begin
10083 return Nkind_In (Nkind (N), N_Accept_Statement,
10084 N_Block_Statement,
10085 N_Compilation_Unit_Aux,
10086 N_Entry_Body,
10087 N_Package_Body,
10088 N_Protected_Body,
10089 N_Subprogram_Body,
10090 N_Task_Body,
10091 N_Package_Specification);
10092 end Has_Declarations;
10094 ---------------------------------
10095 -- Has_Defaulted_Discriminants --
10096 ---------------------------------
10098 function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean is
10099 begin
10100 return Has_Discriminants (Typ)
10101 and then Present (First_Discriminant (Typ))
10102 and then Present (Discriminant_Default_Value
10103 (First_Discriminant (Typ)));
10104 end Has_Defaulted_Discriminants;
10106 -------------------
10107 -- Has_Denormals --
10108 -------------------
10110 function Has_Denormals (E : Entity_Id) return Boolean is
10111 begin
10112 return Is_Floating_Point_Type (E) and then Denorm_On_Target;
10113 end Has_Denormals;
10115 -------------------------------------------
10116 -- Has_Discriminant_Dependent_Constraint --
10117 -------------------------------------------
10119 function Has_Discriminant_Dependent_Constraint
10120 (Comp : Entity_Id) return Boolean
10122 Comp_Decl : constant Node_Id := Parent (Comp);
10123 Subt_Indic : Node_Id;
10124 Constr : Node_Id;
10125 Assn : Node_Id;
10127 begin
10128 -- Discriminants can't depend on discriminants
10130 if Ekind (Comp) = E_Discriminant then
10131 return False;
10133 else
10134 Subt_Indic := Subtype_Indication (Component_Definition (Comp_Decl));
10136 if Nkind (Subt_Indic) = N_Subtype_Indication then
10137 Constr := Constraint (Subt_Indic);
10139 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
10140 Assn := First (Constraints (Constr));
10141 while Present (Assn) loop
10142 case Nkind (Assn) is
10143 when N_Identifier
10144 | N_Range
10145 | N_Subtype_Indication
10147 if Depends_On_Discriminant (Assn) then
10148 return True;
10149 end if;
10151 when N_Discriminant_Association =>
10152 if Depends_On_Discriminant (Expression (Assn)) then
10153 return True;
10154 end if;
10156 when others =>
10157 null;
10158 end case;
10160 Next (Assn);
10161 end loop;
10162 end if;
10163 end if;
10164 end if;
10166 return False;
10167 end Has_Discriminant_Dependent_Constraint;
10169 --------------------------------------
10170 -- Has_Effectively_Volatile_Profile --
10171 --------------------------------------
10173 function Has_Effectively_Volatile_Profile
10174 (Subp_Id : Entity_Id) return Boolean
10176 Formal : Entity_Id;
10178 begin
10179 -- Inspect the formal parameters looking for an effectively volatile
10180 -- type.
10182 Formal := First_Formal (Subp_Id);
10183 while Present (Formal) loop
10184 if Is_Effectively_Volatile (Etype (Formal)) then
10185 return True;
10186 end if;
10188 Next_Formal (Formal);
10189 end loop;
10191 -- Inspect the return type of functions
10193 if Ekind_In (Subp_Id, E_Function, E_Generic_Function)
10194 and then Is_Effectively_Volatile (Etype (Subp_Id))
10195 then
10196 return True;
10197 end if;
10199 return False;
10200 end Has_Effectively_Volatile_Profile;
10202 --------------------------
10203 -- Has_Enabled_Property --
10204 --------------------------
10206 function Has_Enabled_Property
10207 (Item_Id : Entity_Id;
10208 Property : Name_Id) return Boolean
10210 function Protected_Object_Has_Enabled_Property return Boolean;
10211 -- Determine whether a protected object denoted by Item_Id has the
10212 -- property enabled.
10214 function State_Has_Enabled_Property return Boolean;
10215 -- Determine whether a state denoted by Item_Id has the property enabled
10217 function Variable_Has_Enabled_Property return Boolean;
10218 -- Determine whether a variable denoted by Item_Id has the property
10219 -- enabled.
10221 -------------------------------------------
10222 -- Protected_Object_Has_Enabled_Property --
10223 -------------------------------------------
10225 function Protected_Object_Has_Enabled_Property return Boolean is
10226 Constits : constant Elist_Id := Part_Of_Constituents (Item_Id);
10227 Constit_Elmt : Elmt_Id;
10228 Constit_Id : Entity_Id;
10230 begin
10231 -- Protected objects always have the properties Async_Readers and
10232 -- Async_Writers (SPARK RM 7.1.2(16)).
10234 if Property = Name_Async_Readers
10235 or else Property = Name_Async_Writers
10236 then
10237 return True;
10239 -- Protected objects that have Part_Of components also inherit their
10240 -- properties Effective_Reads and Effective_Writes
10241 -- (SPARK RM 7.1.2(16)).
10243 elsif Present (Constits) then
10244 Constit_Elmt := First_Elmt (Constits);
10245 while Present (Constit_Elmt) loop
10246 Constit_Id := Node (Constit_Elmt);
10248 if Has_Enabled_Property (Constit_Id, Property) then
10249 return True;
10250 end if;
10252 Next_Elmt (Constit_Elmt);
10253 end loop;
10254 end if;
10256 return False;
10257 end Protected_Object_Has_Enabled_Property;
10259 --------------------------------
10260 -- State_Has_Enabled_Property --
10261 --------------------------------
10263 function State_Has_Enabled_Property return Boolean is
10264 Decl : constant Node_Id := Parent (Item_Id);
10265 Opt : Node_Id;
10266 Opt_Nam : Node_Id;
10267 Prop : Node_Id;
10268 Prop_Nam : Node_Id;
10269 Props : Node_Id;
10271 begin
10272 -- The declaration of an external abstract state appears as an
10273 -- extension aggregate. If this is not the case, properties can never
10274 -- be set.
10276 if Nkind (Decl) /= N_Extension_Aggregate then
10277 return False;
10278 end if;
10280 -- When External appears as a simple option, it automatically enables
10281 -- all properties.
10283 Opt := First (Expressions (Decl));
10284 while Present (Opt) loop
10285 if Nkind (Opt) = N_Identifier
10286 and then Chars (Opt) = Name_External
10287 then
10288 return True;
10289 end if;
10291 Next (Opt);
10292 end loop;
10294 -- When External specifies particular properties, inspect those and
10295 -- find the desired one (if any).
10297 Opt := First (Component_Associations (Decl));
10298 while Present (Opt) loop
10299 Opt_Nam := First (Choices (Opt));
10301 if Nkind (Opt_Nam) = N_Identifier
10302 and then Chars (Opt_Nam) = Name_External
10303 then
10304 Props := Expression (Opt);
10306 -- Multiple properties appear as an aggregate
10308 if Nkind (Props) = N_Aggregate then
10310 -- Simple property form
10312 Prop := First (Expressions (Props));
10313 while Present (Prop) loop
10314 if Chars (Prop) = Property then
10315 return True;
10316 end if;
10318 Next (Prop);
10319 end loop;
10321 -- Property with expression form
10323 Prop := First (Component_Associations (Props));
10324 while Present (Prop) loop
10325 Prop_Nam := First (Choices (Prop));
10327 -- The property can be represented in two ways:
10328 -- others => <value>
10329 -- <property> => <value>
10331 if Nkind (Prop_Nam) = N_Others_Choice
10332 or else (Nkind (Prop_Nam) = N_Identifier
10333 and then Chars (Prop_Nam) = Property)
10334 then
10335 return Is_True (Expr_Value (Expression (Prop)));
10336 end if;
10338 Next (Prop);
10339 end loop;
10341 -- Single property
10343 else
10344 return Chars (Props) = Property;
10345 end if;
10346 end if;
10348 Next (Opt);
10349 end loop;
10351 return False;
10352 end State_Has_Enabled_Property;
10354 -----------------------------------
10355 -- Variable_Has_Enabled_Property --
10356 -----------------------------------
10358 function Variable_Has_Enabled_Property return Boolean is
10359 function Is_Enabled (Prag : Node_Id) return Boolean;
10360 -- Determine whether property pragma Prag (if present) denotes an
10361 -- enabled property.
10363 ----------------
10364 -- Is_Enabled --
10365 ----------------
10367 function Is_Enabled (Prag : Node_Id) return Boolean is
10368 Arg1 : Node_Id;
10370 begin
10371 if Present (Prag) then
10372 Arg1 := First (Pragma_Argument_Associations (Prag));
10374 -- The pragma has an optional Boolean expression, the related
10375 -- property is enabled only when the expression evaluates to
10376 -- True.
10378 if Present (Arg1) then
10379 return Is_True (Expr_Value (Get_Pragma_Arg (Arg1)));
10381 -- Otherwise the lack of expression enables the property by
10382 -- default.
10384 else
10385 return True;
10386 end if;
10388 -- The property was never set in the first place
10390 else
10391 return False;
10392 end if;
10393 end Is_Enabled;
10395 -- Local variables
10397 AR : constant Node_Id :=
10398 Get_Pragma (Item_Id, Pragma_Async_Readers);
10399 AW : constant Node_Id :=
10400 Get_Pragma (Item_Id, Pragma_Async_Writers);
10401 ER : constant Node_Id :=
10402 Get_Pragma (Item_Id, Pragma_Effective_Reads);
10403 EW : constant Node_Id :=
10404 Get_Pragma (Item_Id, Pragma_Effective_Writes);
10406 -- Start of processing for Variable_Has_Enabled_Property
10408 begin
10409 -- A non-effectively volatile object can never possess external
10410 -- properties.
10412 if not Is_Effectively_Volatile (Item_Id) then
10413 return False;
10415 -- External properties related to variables come in two flavors -
10416 -- explicit and implicit. The explicit case is characterized by the
10417 -- presence of a property pragma with an optional Boolean flag. The
10418 -- property is enabled when the flag evaluates to True or the flag is
10419 -- missing altogether.
10421 elsif Property = Name_Async_Readers and then Is_Enabled (AR) then
10422 return True;
10424 elsif Property = Name_Async_Writers and then Is_Enabled (AW) then
10425 return True;
10427 elsif Property = Name_Effective_Reads and then Is_Enabled (ER) then
10428 return True;
10430 elsif Property = Name_Effective_Writes and then Is_Enabled (EW) then
10431 return True;
10433 -- The implicit case lacks all property pragmas
10435 elsif No (AR) and then No (AW) and then No (ER) and then No (EW) then
10436 if Is_Protected_Type (Etype (Item_Id)) then
10437 return Protected_Object_Has_Enabled_Property;
10438 else
10439 return True;
10440 end if;
10442 else
10443 return False;
10444 end if;
10445 end Variable_Has_Enabled_Property;
10447 -- Start of processing for Has_Enabled_Property
10449 begin
10450 -- Abstract states and variables have a flexible scheme of specifying
10451 -- external properties.
10453 if Ekind (Item_Id) = E_Abstract_State then
10454 return State_Has_Enabled_Property;
10456 elsif Ekind (Item_Id) = E_Variable then
10457 return Variable_Has_Enabled_Property;
10459 -- By default, protected objects only have the properties Async_Readers
10460 -- and Async_Writers. If they have Part_Of components, they also inherit
10461 -- their properties Effective_Reads and Effective_Writes
10462 -- (SPARK RM 7.1.2(16)).
10464 elsif Ekind (Item_Id) = E_Protected_Object then
10465 return Protected_Object_Has_Enabled_Property;
10467 -- Otherwise a property is enabled when the related item is effectively
10468 -- volatile.
10470 else
10471 return Is_Effectively_Volatile (Item_Id);
10472 end if;
10473 end Has_Enabled_Property;
10475 -------------------------------------
10476 -- Has_Full_Default_Initialization --
10477 -------------------------------------
10479 function Has_Full_Default_Initialization (Typ : Entity_Id) return Boolean is
10480 Comp : Entity_Id;
10482 begin
10483 -- A type subject to pragma Default_Initial_Condition may be fully
10484 -- default initialized depending on inheritance and the argument of
10485 -- the pragma. Since any type may act as the full view of a private
10486 -- type, this check must be performed prior to the specialized tests
10487 -- below.
10489 if Has_Fully_Default_Initializing_DIC_Pragma (Typ) then
10490 return True;
10491 end if;
10493 -- A scalar type is fully default initialized if it is subject to aspect
10494 -- Default_Value.
10496 if Is_Scalar_Type (Typ) then
10497 return Has_Default_Aspect (Typ);
10499 -- An array type is fully default initialized if its element type is
10500 -- scalar and the array type carries aspect Default_Component_Value or
10501 -- the element type is fully default initialized.
10503 elsif Is_Array_Type (Typ) then
10504 return
10505 Has_Default_Aspect (Typ)
10506 or else Has_Full_Default_Initialization (Component_Type (Typ));
10508 -- A protected type, record type, or type extension is fully default
10509 -- initialized if all its components either carry an initialization
10510 -- expression or have a type that is fully default initialized. The
10511 -- parent type of a type extension must be fully default initialized.
10513 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
10515 -- Inspect all entities defined in the scope of the type, looking for
10516 -- uninitialized components.
10518 Comp := First_Entity (Typ);
10519 while Present (Comp) loop
10520 if Ekind (Comp) = E_Component
10521 and then Comes_From_Source (Comp)
10522 and then No (Expression (Parent (Comp)))
10523 and then not Has_Full_Default_Initialization (Etype (Comp))
10524 then
10525 return False;
10526 end if;
10528 Next_Entity (Comp);
10529 end loop;
10531 -- Ensure that the parent type of a type extension is fully default
10532 -- initialized.
10534 if Etype (Typ) /= Typ
10535 and then not Has_Full_Default_Initialization (Etype (Typ))
10536 then
10537 return False;
10538 end if;
10540 -- If we get here, then all components and parent portion are fully
10541 -- default initialized.
10543 return True;
10545 -- A task type is fully default initialized by default
10547 elsif Is_Task_Type (Typ) then
10548 return True;
10550 -- Otherwise the type is not fully default initialized
10552 else
10553 return False;
10554 end if;
10555 end Has_Full_Default_Initialization;
10557 -----------------------------------------------
10558 -- Has_Fully_Default_Initializing_DIC_Pragma --
10559 -----------------------------------------------
10561 function Has_Fully_Default_Initializing_DIC_Pragma
10562 (Typ : Entity_Id) return Boolean
10564 Args : List_Id;
10565 Prag : Node_Id;
10567 begin
10568 -- A type that inherits pragma Default_Initial_Condition from a parent
10569 -- type is automatically fully default initialized.
10571 if Has_Inherited_DIC (Typ) then
10572 return True;
10574 -- Otherwise the type is fully default initialized only when the pragma
10575 -- appears without an argument, or the argument is non-null.
10577 elsif Has_Own_DIC (Typ) then
10578 Prag := Get_Pragma (Typ, Pragma_Default_Initial_Condition);
10579 pragma Assert (Present (Prag));
10580 Args := Pragma_Argument_Associations (Prag);
10582 -- The pragma appears without an argument in which case it defaults
10583 -- to True.
10585 if No (Args) then
10586 return True;
10588 -- The pragma appears with a non-null expression
10590 elsif Nkind (Get_Pragma_Arg (First (Args))) /= N_Null then
10591 return True;
10592 end if;
10593 end if;
10595 return False;
10596 end Has_Fully_Default_Initializing_DIC_Pragma;
10598 --------------------
10599 -- Has_Infinities --
10600 --------------------
10602 function Has_Infinities (E : Entity_Id) return Boolean is
10603 begin
10604 return
10605 Is_Floating_Point_Type (E)
10606 and then Nkind (Scalar_Range (E)) = N_Range
10607 and then Includes_Infinities (Scalar_Range (E));
10608 end Has_Infinities;
10610 --------------------
10611 -- Has_Interfaces --
10612 --------------------
10614 function Has_Interfaces
10615 (T : Entity_Id;
10616 Use_Full_View : Boolean := True) return Boolean
10618 Typ : Entity_Id := Base_Type (T);
10620 begin
10621 -- Handle concurrent types
10623 if Is_Concurrent_Type (Typ) then
10624 Typ := Corresponding_Record_Type (Typ);
10625 end if;
10627 if not Present (Typ)
10628 or else not Is_Record_Type (Typ)
10629 or else not Is_Tagged_Type (Typ)
10630 then
10631 return False;
10632 end if;
10634 -- Handle private types
10636 if Use_Full_View and then Present (Full_View (Typ)) then
10637 Typ := Full_View (Typ);
10638 end if;
10640 -- Handle concurrent record types
10642 if Is_Concurrent_Record_Type (Typ)
10643 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
10644 then
10645 return True;
10646 end if;
10648 loop
10649 if Is_Interface (Typ)
10650 or else
10651 (Is_Record_Type (Typ)
10652 and then Present (Interfaces (Typ))
10653 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
10654 then
10655 return True;
10656 end if;
10658 exit when Etype (Typ) = Typ
10660 -- Handle private types
10662 or else (Present (Full_View (Etype (Typ)))
10663 and then Full_View (Etype (Typ)) = Typ)
10665 -- Protect frontend against wrong sources with cyclic derivations
10667 or else Etype (Typ) = T;
10669 -- Climb to the ancestor type handling private types
10671 if Present (Full_View (Etype (Typ))) then
10672 Typ := Full_View (Etype (Typ));
10673 else
10674 Typ := Etype (Typ);
10675 end if;
10676 end loop;
10678 return False;
10679 end Has_Interfaces;
10681 --------------------------
10682 -- Has_Max_Queue_Length --
10683 --------------------------
10685 function Has_Max_Queue_Length (Id : Entity_Id) return Boolean is
10686 begin
10687 return
10688 Ekind (Id) = E_Entry
10689 and then Present (Get_Pragma (Id, Pragma_Max_Queue_Length));
10690 end Has_Max_Queue_Length;
10692 ---------------------------------
10693 -- Has_No_Obvious_Side_Effects --
10694 ---------------------------------
10696 function Has_No_Obvious_Side_Effects (N : Node_Id) return Boolean is
10697 begin
10698 -- For now handle literals, constants, and non-volatile variables and
10699 -- expressions combining these with operators or short circuit forms.
10701 if Nkind (N) in N_Numeric_Or_String_Literal then
10702 return True;
10704 elsif Nkind (N) = N_Character_Literal then
10705 return True;
10707 elsif Nkind (N) in N_Unary_Op then
10708 return Has_No_Obvious_Side_Effects (Right_Opnd (N));
10710 elsif Nkind (N) in N_Binary_Op or else Nkind (N) in N_Short_Circuit then
10711 return Has_No_Obvious_Side_Effects (Left_Opnd (N))
10712 and then
10713 Has_No_Obvious_Side_Effects (Right_Opnd (N));
10715 elsif Nkind (N) = N_Expression_With_Actions
10716 and then Is_Empty_List (Actions (N))
10717 then
10718 return Has_No_Obvious_Side_Effects (Expression (N));
10720 elsif Nkind (N) in N_Has_Entity then
10721 return Present (Entity (N))
10722 and then Ekind_In (Entity (N), E_Variable,
10723 E_Constant,
10724 E_Enumeration_Literal,
10725 E_In_Parameter,
10726 E_Out_Parameter,
10727 E_In_Out_Parameter)
10728 and then not Is_Volatile (Entity (N));
10730 else
10731 return False;
10732 end if;
10733 end Has_No_Obvious_Side_Effects;
10735 -----------------------------
10736 -- Has_Non_Null_Refinement --
10737 -----------------------------
10739 function Has_Non_Null_Refinement (Id : Entity_Id) return Boolean is
10740 Constits : Elist_Id;
10742 begin
10743 pragma Assert (Ekind (Id) = E_Abstract_State);
10744 Constits := Refinement_Constituents (Id);
10746 -- For a refinement to be non-null, the first constituent must be
10747 -- anything other than null.
10749 return
10750 Present (Constits)
10751 and then Nkind (Node (First_Elmt (Constits))) /= N_Null;
10752 end Has_Non_Null_Refinement;
10754 -----------------------------
10755 -- Has_Non_Null_Statements --
10756 -----------------------------
10758 function Has_Non_Null_Statements (L : List_Id) return Boolean is
10759 Node : Node_Id;
10761 begin
10762 if Is_Non_Empty_List (L) then
10763 Node := First (L);
10765 loop
10766 if Nkind (Node) /= N_Null_Statement then
10767 return True;
10768 end if;
10770 Next (Node);
10771 exit when Node = Empty;
10772 end loop;
10773 end if;
10775 return False;
10776 end Has_Non_Null_Statements;
10778 ----------------------------------
10779 -- Has_Non_Trivial_Precondition --
10780 ----------------------------------
10782 function Has_Non_Trivial_Precondition (Subp : Entity_Id) return Boolean is
10783 Pre : constant Node_Id := Find_Aspect (Subp, Aspect_Pre);
10785 begin
10786 return
10787 Present (Pre)
10788 and then Class_Present (Pre)
10789 and then not Is_Entity_Name (Expression (Pre));
10790 end Has_Non_Trivial_Precondition;
10792 -------------------
10793 -- Has_Null_Body --
10794 -------------------
10796 function Has_Null_Body (Proc_Id : Entity_Id) return Boolean is
10797 Body_Id : Entity_Id;
10798 Decl : Node_Id;
10799 Spec : Node_Id;
10800 Stmt1 : Node_Id;
10801 Stmt2 : Node_Id;
10803 begin
10804 Spec := Parent (Proc_Id);
10805 Decl := Parent (Spec);
10807 -- Retrieve the entity of the procedure body (e.g. invariant proc).
10809 if Nkind (Spec) = N_Procedure_Specification
10810 and then Nkind (Decl) = N_Subprogram_Declaration
10811 then
10812 Body_Id := Corresponding_Body (Decl);
10814 -- The body acts as a spec
10816 else
10817 Body_Id := Proc_Id;
10818 end if;
10820 -- The body will be generated later
10822 if No (Body_Id) then
10823 return False;
10824 end if;
10826 Spec := Parent (Body_Id);
10827 Decl := Parent (Spec);
10829 pragma Assert
10830 (Nkind (Spec) = N_Procedure_Specification
10831 and then Nkind (Decl) = N_Subprogram_Body);
10833 Stmt1 := First (Statements (Handled_Statement_Sequence (Decl)));
10835 -- Look for a null statement followed by an optional return
10836 -- statement.
10838 if Nkind (Stmt1) = N_Null_Statement then
10839 Stmt2 := Next (Stmt1);
10841 if Present (Stmt2) then
10842 return Nkind (Stmt2) = N_Simple_Return_Statement;
10843 else
10844 return True;
10845 end if;
10846 end if;
10848 return False;
10849 end Has_Null_Body;
10851 ------------------------
10852 -- Has_Null_Exclusion --
10853 ------------------------
10855 function Has_Null_Exclusion (N : Node_Id) return Boolean is
10856 begin
10857 case Nkind (N) is
10858 when N_Access_Definition
10859 | N_Access_Function_Definition
10860 | N_Access_Procedure_Definition
10861 | N_Access_To_Object_Definition
10862 | N_Allocator
10863 | N_Derived_Type_Definition
10864 | N_Function_Specification
10865 | N_Subtype_Declaration
10867 return Null_Exclusion_Present (N);
10869 when N_Component_Definition
10870 | N_Formal_Object_Declaration
10871 | N_Object_Renaming_Declaration
10873 if Present (Subtype_Mark (N)) then
10874 return Null_Exclusion_Present (N);
10875 else pragma Assert (Present (Access_Definition (N)));
10876 return Null_Exclusion_Present (Access_Definition (N));
10877 end if;
10879 when N_Discriminant_Specification =>
10880 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
10881 return Null_Exclusion_Present (Discriminant_Type (N));
10882 else
10883 return Null_Exclusion_Present (N);
10884 end if;
10886 when N_Object_Declaration =>
10887 if Nkind (Object_Definition (N)) = N_Access_Definition then
10888 return Null_Exclusion_Present (Object_Definition (N));
10889 else
10890 return Null_Exclusion_Present (N);
10891 end if;
10893 when N_Parameter_Specification =>
10894 if Nkind (Parameter_Type (N)) = N_Access_Definition then
10895 return Null_Exclusion_Present (Parameter_Type (N));
10896 else
10897 return Null_Exclusion_Present (N);
10898 end if;
10900 when others =>
10901 return False;
10902 end case;
10903 end Has_Null_Exclusion;
10905 ------------------------
10906 -- Has_Null_Extension --
10907 ------------------------
10909 function Has_Null_Extension (T : Entity_Id) return Boolean is
10910 B : constant Entity_Id := Base_Type (T);
10911 Comps : Node_Id;
10912 Ext : Node_Id;
10914 begin
10915 if Nkind (Parent (B)) = N_Full_Type_Declaration
10916 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
10917 then
10918 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
10920 if Present (Ext) then
10921 if Null_Present (Ext) then
10922 return True;
10923 else
10924 Comps := Component_List (Ext);
10926 -- The null component list is rewritten during analysis to
10927 -- include the parent component. Any other component indicates
10928 -- that the extension was not originally null.
10930 return Null_Present (Comps)
10931 or else No (Next (First (Component_Items (Comps))));
10932 end if;
10933 else
10934 return False;
10935 end if;
10937 else
10938 return False;
10939 end if;
10940 end Has_Null_Extension;
10942 -------------------------
10943 -- Has_Null_Refinement --
10944 -------------------------
10946 function Has_Null_Refinement (Id : Entity_Id) return Boolean is
10947 Constits : Elist_Id;
10949 begin
10950 pragma Assert (Ekind (Id) = E_Abstract_State);
10951 Constits := Refinement_Constituents (Id);
10953 -- For a refinement to be null, the state's sole constituent must be a
10954 -- null.
10956 return
10957 Present (Constits)
10958 and then Nkind (Node (First_Elmt (Constits))) = N_Null;
10959 end Has_Null_Refinement;
10961 -------------------------------
10962 -- Has_Overriding_Initialize --
10963 -------------------------------
10965 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
10966 BT : constant Entity_Id := Base_Type (T);
10967 P : Elmt_Id;
10969 begin
10970 if Is_Controlled (BT) then
10971 if Is_RTU (Scope (BT), Ada_Finalization) then
10972 return False;
10974 elsif Present (Primitive_Operations (BT)) then
10975 P := First_Elmt (Primitive_Operations (BT));
10976 while Present (P) loop
10977 declare
10978 Init : constant Entity_Id := Node (P);
10979 Formal : constant Entity_Id := First_Formal (Init);
10980 begin
10981 if Ekind (Init) = E_Procedure
10982 and then Chars (Init) = Name_Initialize
10983 and then Comes_From_Source (Init)
10984 and then Present (Formal)
10985 and then Etype (Formal) = BT
10986 and then No (Next_Formal (Formal))
10987 and then (Ada_Version < Ada_2012
10988 or else not Null_Present (Parent (Init)))
10989 then
10990 return True;
10991 end if;
10992 end;
10994 Next_Elmt (P);
10995 end loop;
10996 end if;
10998 -- Here if type itself does not have a non-null Initialize operation:
10999 -- check immediate ancestor.
11001 if Is_Derived_Type (BT)
11002 and then Has_Overriding_Initialize (Etype (BT))
11003 then
11004 return True;
11005 end if;
11006 end if;
11008 return False;
11009 end Has_Overriding_Initialize;
11011 --------------------------------------
11012 -- Has_Preelaborable_Initialization --
11013 --------------------------------------
11015 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
11016 Has_PE : Boolean;
11018 procedure Check_Components (E : Entity_Id);
11019 -- Check component/discriminant chain, sets Has_PE False if a component
11020 -- or discriminant does not meet the preelaborable initialization rules.
11022 ----------------------
11023 -- Check_Components --
11024 ----------------------
11026 procedure Check_Components (E : Entity_Id) is
11027 Ent : Entity_Id;
11028 Exp : Node_Id;
11030 begin
11031 -- Loop through entities of record or protected type
11033 Ent := E;
11034 while Present (Ent) loop
11036 -- We are interested only in components and discriminants
11038 Exp := Empty;
11040 case Ekind (Ent) is
11041 when E_Component =>
11043 -- Get default expression if any. If there is no declaration
11044 -- node, it means we have an internal entity. The parent and
11045 -- tag fields are examples of such entities. For such cases,
11046 -- we just test the type of the entity.
11048 if Present (Declaration_Node (Ent)) then
11049 Exp := Expression (Declaration_Node (Ent));
11050 end if;
11052 when E_Discriminant =>
11054 -- Note: for a renamed discriminant, the Declaration_Node
11055 -- may point to the one from the ancestor, and have a
11056 -- different expression, so use the proper attribute to
11057 -- retrieve the expression from the derived constraint.
11059 Exp := Discriminant_Default_Value (Ent);
11061 when others =>
11062 goto Check_Next_Entity;
11063 end case;
11065 -- A component has PI if it has no default expression and the
11066 -- component type has PI.
11068 if No (Exp) then
11069 if not Has_Preelaborable_Initialization (Etype (Ent)) then
11070 Has_PE := False;
11071 exit;
11072 end if;
11074 -- Require the default expression to be preelaborable
11076 elsif not Is_Preelaborable_Construct (Exp) then
11077 Has_PE := False;
11078 exit;
11079 end if;
11081 <<Check_Next_Entity>>
11082 Next_Entity (Ent);
11083 end loop;
11084 end Check_Components;
11086 -- Start of processing for Has_Preelaborable_Initialization
11088 begin
11089 -- Immediate return if already marked as known preelaborable init. This
11090 -- covers types for which this function has already been called once
11091 -- and returned True (in which case the result is cached), and also
11092 -- types to which a pragma Preelaborable_Initialization applies.
11094 if Known_To_Have_Preelab_Init (E) then
11095 return True;
11096 end if;
11098 -- If the type is a subtype representing a generic actual type, then
11099 -- test whether its base type has preelaborable initialization since
11100 -- the subtype representing the actual does not inherit this attribute
11101 -- from the actual or formal. (but maybe it should???)
11103 if Is_Generic_Actual_Type (E) then
11104 return Has_Preelaborable_Initialization (Base_Type (E));
11105 end if;
11107 -- All elementary types have preelaborable initialization
11109 if Is_Elementary_Type (E) then
11110 Has_PE := True;
11112 -- Array types have PI if the component type has PI
11114 elsif Is_Array_Type (E) then
11115 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
11117 -- A derived type has preelaborable initialization if its parent type
11118 -- has preelaborable initialization and (in the case of a derived record
11119 -- extension) if the non-inherited components all have preelaborable
11120 -- initialization. However, a user-defined controlled type with an
11121 -- overriding Initialize procedure does not have preelaborable
11122 -- initialization.
11124 elsif Is_Derived_Type (E) then
11126 -- If the derived type is a private extension then it doesn't have
11127 -- preelaborable initialization.
11129 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
11130 return False;
11131 end if;
11133 -- First check whether ancestor type has preelaborable initialization
11135 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
11137 -- If OK, check extension components (if any)
11139 if Has_PE and then Is_Record_Type (E) then
11140 Check_Components (First_Entity (E));
11141 end if;
11143 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
11144 -- with a user defined Initialize procedure does not have PI. If
11145 -- the type is untagged, the control primitives come from a component
11146 -- that has already been checked.
11148 if Has_PE
11149 and then Is_Controlled (E)
11150 and then Is_Tagged_Type (E)
11151 and then Has_Overriding_Initialize (E)
11152 then
11153 Has_PE := False;
11154 end if;
11156 -- Private types not derived from a type having preelaborable init and
11157 -- that are not marked with pragma Preelaborable_Initialization do not
11158 -- have preelaborable initialization.
11160 elsif Is_Private_Type (E) then
11161 return False;
11163 -- Record type has PI if it is non private and all components have PI
11165 elsif Is_Record_Type (E) then
11166 Has_PE := True;
11167 Check_Components (First_Entity (E));
11169 -- Protected types must not have entries, and components must meet
11170 -- same set of rules as for record components.
11172 elsif Is_Protected_Type (E) then
11173 if Has_Entries (E) then
11174 Has_PE := False;
11175 else
11176 Has_PE := True;
11177 Check_Components (First_Entity (E));
11178 Check_Components (First_Private_Entity (E));
11179 end if;
11181 -- Type System.Address always has preelaborable initialization
11183 elsif Is_RTE (E, RE_Address) then
11184 Has_PE := True;
11186 -- In all other cases, type does not have preelaborable initialization
11188 else
11189 return False;
11190 end if;
11192 -- If type has preelaborable initialization, cache result
11194 if Has_PE then
11195 Set_Known_To_Have_Preelab_Init (E);
11196 end if;
11198 return Has_PE;
11199 end Has_Preelaborable_Initialization;
11201 ---------------------------
11202 -- Has_Private_Component --
11203 ---------------------------
11205 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
11206 Btype : Entity_Id := Base_Type (Type_Id);
11207 Component : Entity_Id;
11209 begin
11210 if Error_Posted (Type_Id)
11211 or else Error_Posted (Btype)
11212 then
11213 return False;
11214 end if;
11216 if Is_Class_Wide_Type (Btype) then
11217 Btype := Root_Type (Btype);
11218 end if;
11220 if Is_Private_Type (Btype) then
11221 declare
11222 UT : constant Entity_Id := Underlying_Type (Btype);
11223 begin
11224 if No (UT) then
11225 if No (Full_View (Btype)) then
11226 return not Is_Generic_Type (Btype)
11227 and then
11228 not Is_Generic_Type (Root_Type (Btype));
11229 else
11230 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
11231 end if;
11232 else
11233 return not Is_Frozen (UT) and then Has_Private_Component (UT);
11234 end if;
11235 end;
11237 elsif Is_Array_Type (Btype) then
11238 return Has_Private_Component (Component_Type (Btype));
11240 elsif Is_Record_Type (Btype) then
11241 Component := First_Component (Btype);
11242 while Present (Component) loop
11243 if Has_Private_Component (Etype (Component)) then
11244 return True;
11245 end if;
11247 Next_Component (Component);
11248 end loop;
11250 return False;
11252 elsif Is_Protected_Type (Btype)
11253 and then Present (Corresponding_Record_Type (Btype))
11254 then
11255 return Has_Private_Component (Corresponding_Record_Type (Btype));
11257 else
11258 return False;
11259 end if;
11260 end Has_Private_Component;
11262 ----------------------
11263 -- Has_Signed_Zeros --
11264 ----------------------
11266 function Has_Signed_Zeros (E : Entity_Id) return Boolean is
11267 begin
11268 return Is_Floating_Point_Type (E) and then Signed_Zeros_On_Target;
11269 end Has_Signed_Zeros;
11271 ------------------------------
11272 -- Has_Significant_Contract --
11273 ------------------------------
11275 function Has_Significant_Contract (Subp_Id : Entity_Id) return Boolean is
11276 Subp_Nam : constant Name_Id := Chars (Subp_Id);
11278 begin
11279 -- _Finalizer procedure
11281 if Subp_Nam = Name_uFinalizer then
11282 return False;
11284 -- _Postconditions procedure
11286 elsif Subp_Nam = Name_uPostconditions then
11287 return False;
11289 -- Predicate function
11291 elsif Ekind (Subp_Id) = E_Function
11292 and then Is_Predicate_Function (Subp_Id)
11293 then
11294 return False;
11296 -- TSS subprogram
11298 elsif Get_TSS_Name (Subp_Id) /= TSS_Null then
11299 return False;
11301 else
11302 return True;
11303 end if;
11304 end Has_Significant_Contract;
11306 -----------------------------
11307 -- Has_Static_Array_Bounds --
11308 -----------------------------
11310 function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is
11311 Ndims : constant Nat := Number_Dimensions (Typ);
11313 Index : Node_Id;
11314 Low : Node_Id;
11315 High : Node_Id;
11317 begin
11318 -- Unconstrained types do not have static bounds
11320 if not Is_Constrained (Typ) then
11321 return False;
11322 end if;
11324 -- First treat string literals specially, as the lower bound and length
11325 -- of string literals are not stored like those of arrays.
11327 -- A string literal always has static bounds
11329 if Ekind (Typ) = E_String_Literal_Subtype then
11330 return True;
11331 end if;
11333 -- Treat all dimensions in turn
11335 Index := First_Index (Typ);
11336 for Indx in 1 .. Ndims loop
11338 -- In case of an illegal index which is not a discrete type, return
11339 -- that the type is not static.
11341 if not Is_Discrete_Type (Etype (Index))
11342 or else Etype (Index) = Any_Type
11343 then
11344 return False;
11345 end if;
11347 Get_Index_Bounds (Index, Low, High);
11349 if Error_Posted (Low) or else Error_Posted (High) then
11350 return False;
11351 end if;
11353 if Is_OK_Static_Expression (Low)
11354 and then
11355 Is_OK_Static_Expression (High)
11356 then
11357 null;
11358 else
11359 return False;
11360 end if;
11362 Next (Index);
11363 end loop;
11365 -- If we fall through the loop, all indexes matched
11367 return True;
11368 end Has_Static_Array_Bounds;
11370 ----------------
11371 -- Has_Stream --
11372 ----------------
11374 function Has_Stream (T : Entity_Id) return Boolean is
11375 E : Entity_Id;
11377 begin
11378 if No (T) then
11379 return False;
11381 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
11382 return True;
11384 elsif Is_Array_Type (T) then
11385 return Has_Stream (Component_Type (T));
11387 elsif Is_Record_Type (T) then
11388 E := First_Component (T);
11389 while Present (E) loop
11390 if Has_Stream (Etype (E)) then
11391 return True;
11392 else
11393 Next_Component (E);
11394 end if;
11395 end loop;
11397 return False;
11399 elsif Is_Private_Type (T) then
11400 return Has_Stream (Underlying_Type (T));
11402 else
11403 return False;
11404 end if;
11405 end Has_Stream;
11407 ----------------
11408 -- Has_Suffix --
11409 ----------------
11411 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
11412 begin
11413 Get_Name_String (Chars (E));
11414 return Name_Buffer (Name_Len) = Suffix;
11415 end Has_Suffix;
11417 ----------------
11418 -- Add_Suffix --
11419 ----------------
11421 function Add_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
11422 begin
11423 Get_Name_String (Chars (E));
11424 Add_Char_To_Name_Buffer (Suffix);
11425 return Name_Find;
11426 end Add_Suffix;
11428 -------------------
11429 -- Remove_Suffix --
11430 -------------------
11432 function Remove_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
11433 begin
11434 pragma Assert (Has_Suffix (E, Suffix));
11435 Get_Name_String (Chars (E));
11436 Name_Len := Name_Len - 1;
11437 return Name_Find;
11438 end Remove_Suffix;
11440 ----------------------------------
11441 -- Replace_Null_By_Null_Address --
11442 ----------------------------------
11444 procedure Replace_Null_By_Null_Address (N : Node_Id) is
11445 procedure Replace_Null_Operand (Op : Node_Id; Other_Op : Node_Id);
11446 -- Replace operand Op with a reference to Null_Address when the operand
11447 -- denotes a null Address. Other_Op denotes the other operand.
11449 --------------------------
11450 -- Replace_Null_Operand --
11451 --------------------------
11453 procedure Replace_Null_Operand (Op : Node_Id; Other_Op : Node_Id) is
11454 begin
11455 -- Check the type of the complementary operand since the N_Null node
11456 -- has not been decorated yet.
11458 if Nkind (Op) = N_Null
11459 and then Is_Descendant_Of_Address (Etype (Other_Op))
11460 then
11461 Rewrite (Op, New_Occurrence_Of (RTE (RE_Null_Address), Sloc (Op)));
11462 end if;
11463 end Replace_Null_Operand;
11465 -- Start of processing for Replace_Null_By_Null_Address
11467 begin
11468 pragma Assert (Relaxed_RM_Semantics);
11469 pragma Assert (Nkind_In (N, N_Null,
11470 N_Op_Eq,
11471 N_Op_Ge,
11472 N_Op_Gt,
11473 N_Op_Le,
11474 N_Op_Lt,
11475 N_Op_Ne));
11477 if Nkind (N) = N_Null then
11478 Rewrite (N, New_Occurrence_Of (RTE (RE_Null_Address), Sloc (N)));
11480 else
11481 declare
11482 L : constant Node_Id := Left_Opnd (N);
11483 R : constant Node_Id := Right_Opnd (N);
11485 begin
11486 Replace_Null_Operand (L, Other_Op => R);
11487 Replace_Null_Operand (R, Other_Op => L);
11488 end;
11489 end if;
11490 end Replace_Null_By_Null_Address;
11492 --------------------------
11493 -- Has_Tagged_Component --
11494 --------------------------
11496 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
11497 Comp : Entity_Id;
11499 begin
11500 if Is_Private_Type (Typ) and then Present (Underlying_Type (Typ)) then
11501 return Has_Tagged_Component (Underlying_Type (Typ));
11503 elsif Is_Array_Type (Typ) then
11504 return Has_Tagged_Component (Component_Type (Typ));
11506 elsif Is_Tagged_Type (Typ) then
11507 return True;
11509 elsif Is_Record_Type (Typ) then
11510 Comp := First_Component (Typ);
11511 while Present (Comp) loop
11512 if Has_Tagged_Component (Etype (Comp)) then
11513 return True;
11514 end if;
11516 Next_Component (Comp);
11517 end loop;
11519 return False;
11521 else
11522 return False;
11523 end if;
11524 end Has_Tagged_Component;
11526 -----------------------------
11527 -- Has_Undefined_Reference --
11528 -----------------------------
11530 function Has_Undefined_Reference (Expr : Node_Id) return Boolean is
11531 Has_Undef_Ref : Boolean := False;
11532 -- Flag set when expression Expr contains at least one undefined
11533 -- reference.
11535 function Is_Undefined_Reference (N : Node_Id) return Traverse_Result;
11536 -- Determine whether N denotes a reference and if it does, whether it is
11537 -- undefined.
11539 ----------------------------
11540 -- Is_Undefined_Reference --
11541 ----------------------------
11543 function Is_Undefined_Reference (N : Node_Id) return Traverse_Result is
11544 begin
11545 if Is_Entity_Name (N)
11546 and then Present (Entity (N))
11547 and then Entity (N) = Any_Id
11548 then
11549 Has_Undef_Ref := True;
11550 return Abandon;
11551 end if;
11553 return OK;
11554 end Is_Undefined_Reference;
11556 procedure Find_Undefined_References is
11557 new Traverse_Proc (Is_Undefined_Reference);
11559 -- Start of processing for Has_Undefined_Reference
11561 begin
11562 Find_Undefined_References (Expr);
11564 return Has_Undef_Ref;
11565 end Has_Undefined_Reference;
11567 ----------------------------
11568 -- Has_Volatile_Component --
11569 ----------------------------
11571 function Has_Volatile_Component (Typ : Entity_Id) return Boolean is
11572 Comp : Entity_Id;
11574 begin
11575 if Has_Volatile_Components (Typ) then
11576 return True;
11578 elsif Is_Array_Type (Typ) then
11579 return Is_Volatile (Component_Type (Typ));
11581 elsif Is_Record_Type (Typ) then
11582 Comp := First_Component (Typ);
11583 while Present (Comp) loop
11584 if Is_Volatile_Object (Comp) then
11585 return True;
11586 end if;
11588 Comp := Next_Component (Comp);
11589 end loop;
11590 end if;
11592 return False;
11593 end Has_Volatile_Component;
11595 -------------------------
11596 -- Implementation_Kind --
11597 -------------------------
11599 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
11600 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
11601 Arg : Node_Id;
11602 begin
11603 pragma Assert (Present (Impl_Prag));
11604 Arg := Last (Pragma_Argument_Associations (Impl_Prag));
11605 return Chars (Get_Pragma_Arg (Arg));
11606 end Implementation_Kind;
11608 --------------------------
11609 -- Implements_Interface --
11610 --------------------------
11612 function Implements_Interface
11613 (Typ_Ent : Entity_Id;
11614 Iface_Ent : Entity_Id;
11615 Exclude_Parents : Boolean := False) return Boolean
11617 Ifaces_List : Elist_Id;
11618 Elmt : Elmt_Id;
11619 Iface : Entity_Id := Base_Type (Iface_Ent);
11620 Typ : Entity_Id := Base_Type (Typ_Ent);
11622 begin
11623 if Is_Class_Wide_Type (Typ) then
11624 Typ := Root_Type (Typ);
11625 end if;
11627 if not Has_Interfaces (Typ) then
11628 return False;
11629 end if;
11631 if Is_Class_Wide_Type (Iface) then
11632 Iface := Root_Type (Iface);
11633 end if;
11635 Collect_Interfaces (Typ, Ifaces_List);
11637 Elmt := First_Elmt (Ifaces_List);
11638 while Present (Elmt) loop
11639 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
11640 and then Exclude_Parents
11641 then
11642 null;
11644 elsif Node (Elmt) = Iface then
11645 return True;
11646 end if;
11648 Next_Elmt (Elmt);
11649 end loop;
11651 return False;
11652 end Implements_Interface;
11654 ------------------------------------
11655 -- In_Assertion_Expression_Pragma --
11656 ------------------------------------
11658 function In_Assertion_Expression_Pragma (N : Node_Id) return Boolean is
11659 Par : Node_Id;
11660 Prag : Node_Id := Empty;
11662 begin
11663 -- Climb the parent chain looking for an enclosing pragma
11665 Par := N;
11666 while Present (Par) loop
11667 if Nkind (Par) = N_Pragma then
11668 Prag := Par;
11669 exit;
11671 -- Precondition-like pragmas are expanded into if statements, check
11672 -- the original node instead.
11674 elsif Nkind (Original_Node (Par)) = N_Pragma then
11675 Prag := Original_Node (Par);
11676 exit;
11678 -- The expansion of attribute 'Old generates a constant to capture
11679 -- the result of the prefix. If the parent traversal reaches
11680 -- one of these constants, then the node technically came from a
11681 -- postcondition-like pragma. Note that the Ekind is not tested here
11682 -- because N may be the expression of an object declaration which is
11683 -- currently being analyzed. Such objects carry Ekind of E_Void.
11685 elsif Nkind (Par) = N_Object_Declaration
11686 and then Constant_Present (Par)
11687 and then Stores_Attribute_Old_Prefix (Defining_Entity (Par))
11688 then
11689 return True;
11691 -- Prevent the search from going too far
11693 elsif Is_Body_Or_Package_Declaration (Par) then
11694 return False;
11695 end if;
11697 Par := Parent (Par);
11698 end loop;
11700 return
11701 Present (Prag)
11702 and then Assertion_Expression_Pragma (Get_Pragma_Id (Prag));
11703 end In_Assertion_Expression_Pragma;
11705 ----------------------
11706 -- In_Generic_Scope --
11707 ----------------------
11709 function In_Generic_Scope (E : Entity_Id) return Boolean is
11710 S : Entity_Id;
11712 begin
11713 S := Scope (E);
11714 while Present (S) and then S /= Standard_Standard loop
11715 if Is_Generic_Unit (S) then
11716 return True;
11717 end if;
11719 S := Scope (S);
11720 end loop;
11722 return False;
11723 end In_Generic_Scope;
11725 -----------------
11726 -- In_Instance --
11727 -----------------
11729 function In_Instance return Boolean is
11730 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
11731 S : Entity_Id;
11733 begin
11734 S := Current_Scope;
11735 while Present (S) and then S /= Standard_Standard loop
11736 if Is_Generic_Instance (S) then
11738 -- A child instance is always compiled in the context of a parent
11739 -- instance. Nevertheless, the actuals are not analyzed in an
11740 -- instance context. We detect this case by examining the current
11741 -- compilation unit, which must be a child instance, and checking
11742 -- that it is not currently on the scope stack.
11744 if Is_Child_Unit (Curr_Unit)
11745 and then Nkind (Unit (Cunit (Current_Sem_Unit))) =
11746 N_Package_Instantiation
11747 and then not In_Open_Scopes (Curr_Unit)
11748 then
11749 return False;
11750 else
11751 return True;
11752 end if;
11753 end if;
11755 S := Scope (S);
11756 end loop;
11758 return False;
11759 end In_Instance;
11761 ----------------------
11762 -- In_Instance_Body --
11763 ----------------------
11765 function In_Instance_Body return Boolean is
11766 S : Entity_Id;
11768 begin
11769 S := Current_Scope;
11770 while Present (S) and then S /= Standard_Standard loop
11771 if Ekind_In (S, E_Function, E_Procedure)
11772 and then Is_Generic_Instance (S)
11773 then
11774 return True;
11776 elsif Ekind (S) = E_Package
11777 and then In_Package_Body (S)
11778 and then Is_Generic_Instance (S)
11779 then
11780 return True;
11781 end if;
11783 S := Scope (S);
11784 end loop;
11786 return False;
11787 end In_Instance_Body;
11789 -----------------------------
11790 -- In_Instance_Not_Visible --
11791 -----------------------------
11793 function In_Instance_Not_Visible return Boolean is
11794 S : Entity_Id;
11796 begin
11797 S := Current_Scope;
11798 while Present (S) and then S /= Standard_Standard loop
11799 if Ekind_In (S, E_Function, E_Procedure)
11800 and then Is_Generic_Instance (S)
11801 then
11802 return True;
11804 elsif Ekind (S) = E_Package
11805 and then (In_Package_Body (S) or else In_Private_Part (S))
11806 and then Is_Generic_Instance (S)
11807 then
11808 return True;
11809 end if;
11811 S := Scope (S);
11812 end loop;
11814 return False;
11815 end In_Instance_Not_Visible;
11817 ------------------------------
11818 -- In_Instance_Visible_Part --
11819 ------------------------------
11821 function In_Instance_Visible_Part
11822 (Id : Entity_Id := Current_Scope) return Boolean
11824 Inst : Entity_Id;
11826 begin
11827 Inst := Id;
11828 while Present (Inst) and then Inst /= Standard_Standard loop
11829 if Ekind (Inst) = E_Package
11830 and then Is_Generic_Instance (Inst)
11831 and then not In_Package_Body (Inst)
11832 and then not In_Private_Part (Inst)
11833 then
11834 return True;
11835 end if;
11837 Inst := Scope (Inst);
11838 end loop;
11840 return False;
11841 end In_Instance_Visible_Part;
11843 ---------------------
11844 -- In_Package_Body --
11845 ---------------------
11847 function In_Package_Body return Boolean is
11848 S : Entity_Id;
11850 begin
11851 S := Current_Scope;
11852 while Present (S) and then S /= Standard_Standard loop
11853 if Ekind (S) = E_Package and then In_Package_Body (S) then
11854 return True;
11855 else
11856 S := Scope (S);
11857 end if;
11858 end loop;
11860 return False;
11861 end In_Package_Body;
11863 --------------------------
11864 -- In_Pragma_Expression --
11865 --------------------------
11867 function In_Pragma_Expression (N : Node_Id; Nam : Name_Id) return Boolean is
11868 P : Node_Id;
11869 begin
11870 P := Parent (N);
11871 loop
11872 if No (P) then
11873 return False;
11874 elsif Nkind (P) = N_Pragma and then Pragma_Name (P) = Nam then
11875 return True;
11876 else
11877 P := Parent (P);
11878 end if;
11879 end loop;
11880 end In_Pragma_Expression;
11882 ---------------------------
11883 -- In_Pre_Post_Condition --
11884 ---------------------------
11886 function In_Pre_Post_Condition (N : Node_Id) return Boolean is
11887 Par : Node_Id;
11888 Prag : Node_Id := Empty;
11889 Prag_Id : Pragma_Id;
11891 begin
11892 -- Climb the parent chain looking for an enclosing pragma
11894 Par := N;
11895 while Present (Par) loop
11896 if Nkind (Par) = N_Pragma then
11897 Prag := Par;
11898 exit;
11900 -- Prevent the search from going too far
11902 elsif Is_Body_Or_Package_Declaration (Par) then
11903 exit;
11904 end if;
11906 Par := Parent (Par);
11907 end loop;
11909 if Present (Prag) then
11910 Prag_Id := Get_Pragma_Id (Prag);
11912 return
11913 Prag_Id = Pragma_Post
11914 or else Prag_Id = Pragma_Post_Class
11915 or else Prag_Id = Pragma_Postcondition
11916 or else Prag_Id = Pragma_Pre
11917 or else Prag_Id = Pragma_Pre_Class
11918 or else Prag_Id = Pragma_Precondition;
11920 -- Otherwise the node is not enclosed by a pre/postcondition pragma
11922 else
11923 return False;
11924 end if;
11925 end In_Pre_Post_Condition;
11927 -------------------------------------
11928 -- In_Reverse_Storage_Order_Object --
11929 -------------------------------------
11931 function In_Reverse_Storage_Order_Object (N : Node_Id) return Boolean is
11932 Pref : Node_Id;
11933 Btyp : Entity_Id := Empty;
11935 begin
11936 -- Climb up indexed components
11938 Pref := N;
11939 loop
11940 case Nkind (Pref) is
11941 when N_Selected_Component =>
11942 Pref := Prefix (Pref);
11943 exit;
11945 when N_Indexed_Component =>
11946 Pref := Prefix (Pref);
11948 when others =>
11949 Pref := Empty;
11950 exit;
11951 end case;
11952 end loop;
11954 if Present (Pref) then
11955 Btyp := Base_Type (Etype (Pref));
11956 end if;
11958 return Present (Btyp)
11959 and then (Is_Record_Type (Btyp) or else Is_Array_Type (Btyp))
11960 and then Reverse_Storage_Order (Btyp);
11961 end In_Reverse_Storage_Order_Object;
11963 --------------------------------------
11964 -- In_Subprogram_Or_Concurrent_Unit --
11965 --------------------------------------
11967 function In_Subprogram_Or_Concurrent_Unit return Boolean is
11968 E : Entity_Id;
11969 K : Entity_Kind;
11971 begin
11972 -- Use scope chain to check successively outer scopes
11974 E := Current_Scope;
11975 loop
11976 K := Ekind (E);
11978 if K in Subprogram_Kind
11979 or else K in Concurrent_Kind
11980 or else K in Generic_Subprogram_Kind
11981 then
11982 return True;
11984 elsif E = Standard_Standard then
11985 return False;
11986 end if;
11988 E := Scope (E);
11989 end loop;
11990 end In_Subprogram_Or_Concurrent_Unit;
11992 ----------------
11993 -- In_Subtree --
11994 ----------------
11996 function In_Subtree (N : Node_Id; Root : Node_Id) return Boolean is
11997 Curr : Node_Id;
11999 begin
12000 Curr := N;
12001 while Present (Curr) loop
12002 if Curr = Root then
12003 return True;
12004 end if;
12006 Curr := Parent (Curr);
12007 end loop;
12009 return False;
12010 end In_Subtree;
12012 ----------------
12013 -- In_Subtree --
12014 ----------------
12016 function In_Subtree
12017 (N : Node_Id;
12018 Root1 : Node_Id;
12019 Root2 : Node_Id) return Boolean
12021 Curr : Node_Id;
12023 begin
12024 Curr := N;
12025 while Present (Curr) loop
12026 if Curr = Root1 or else Curr = Root2 then
12027 return True;
12028 end if;
12030 Curr := Parent (Curr);
12031 end loop;
12033 return False;
12034 end In_Subtree;
12036 ---------------------
12037 -- In_Visible_Part --
12038 ---------------------
12040 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
12041 begin
12042 return Is_Package_Or_Generic_Package (Scope_Id)
12043 and then In_Open_Scopes (Scope_Id)
12044 and then not In_Package_Body (Scope_Id)
12045 and then not In_Private_Part (Scope_Id);
12046 end In_Visible_Part;
12048 --------------------------------
12049 -- Incomplete_Or_Partial_View --
12050 --------------------------------
12052 function Incomplete_Or_Partial_View (Id : Entity_Id) return Entity_Id is
12053 function Inspect_Decls
12054 (Decls : List_Id;
12055 Taft : Boolean := False) return Entity_Id;
12056 -- Check whether a declarative region contains the incomplete or partial
12057 -- view of Id.
12059 -------------------
12060 -- Inspect_Decls --
12061 -------------------
12063 function Inspect_Decls
12064 (Decls : List_Id;
12065 Taft : Boolean := False) return Entity_Id
12067 Decl : Node_Id;
12068 Match : Node_Id;
12070 begin
12071 Decl := First (Decls);
12072 while Present (Decl) loop
12073 Match := Empty;
12075 -- The partial view of a Taft-amendment type is an incomplete
12076 -- type.
12078 if Taft then
12079 if Nkind (Decl) = N_Incomplete_Type_Declaration then
12080 Match := Defining_Identifier (Decl);
12081 end if;
12083 -- Otherwise look for a private type whose full view matches the
12084 -- input type. Note that this checks full_type_declaration nodes
12085 -- to account for derivations from a private type where the type
12086 -- declaration hold the partial view and the full view is an
12087 -- itype.
12089 elsif Nkind_In (Decl, N_Full_Type_Declaration,
12090 N_Private_Extension_Declaration,
12091 N_Private_Type_Declaration)
12092 then
12093 Match := Defining_Identifier (Decl);
12094 end if;
12096 -- Guard against unanalyzed entities
12098 if Present (Match)
12099 and then Is_Type (Match)
12100 and then Present (Full_View (Match))
12101 and then Full_View (Match) = Id
12102 then
12103 return Match;
12104 end if;
12106 Next (Decl);
12107 end loop;
12109 return Empty;
12110 end Inspect_Decls;
12112 -- Local variables
12114 Prev : Entity_Id;
12116 -- Start of processing for Incomplete_Or_Partial_View
12118 begin
12119 -- Deferred constant or incomplete type case
12121 Prev := Current_Entity_In_Scope (Id);
12123 if Present (Prev)
12124 and then (Is_Incomplete_Type (Prev) or else Ekind (Prev) = E_Constant)
12125 and then Present (Full_View (Prev))
12126 and then Full_View (Prev) = Id
12127 then
12128 return Prev;
12129 end if;
12131 -- Private or Taft amendment type case
12133 declare
12134 Pkg : constant Entity_Id := Scope (Id);
12135 Pkg_Decl : Node_Id := Pkg;
12137 begin
12138 if Present (Pkg)
12139 and then Ekind_In (Pkg, E_Generic_Package, E_Package)
12140 then
12141 while Nkind (Pkg_Decl) /= N_Package_Specification loop
12142 Pkg_Decl := Parent (Pkg_Decl);
12143 end loop;
12145 -- It is knows that Typ has a private view, look for it in the
12146 -- visible declarations of the enclosing scope. A special case
12147 -- of this is when the two views have been exchanged - the full
12148 -- appears earlier than the private.
12150 if Has_Private_Declaration (Id) then
12151 Prev := Inspect_Decls (Visible_Declarations (Pkg_Decl));
12153 -- Exchanged view case, look in the private declarations
12155 if No (Prev) then
12156 Prev := Inspect_Decls (Private_Declarations (Pkg_Decl));
12157 end if;
12159 return Prev;
12161 -- Otherwise if this is the package body, then Typ is a potential
12162 -- Taft amendment type. The incomplete view should be located in
12163 -- the private declarations of the enclosing scope.
12165 elsif In_Package_Body (Pkg) then
12166 return Inspect_Decls (Private_Declarations (Pkg_Decl), True);
12167 end if;
12168 end if;
12169 end;
12171 -- The type has no incomplete or private view
12173 return Empty;
12174 end Incomplete_Or_Partial_View;
12176 ---------------------------------------
12177 -- Incomplete_View_From_Limited_With --
12178 ---------------------------------------
12180 function Incomplete_View_From_Limited_With
12181 (Typ : Entity_Id) return Entity_Id
12183 begin
12184 -- It might make sense to make this an attribute in Einfo, and set it
12185 -- in Sem_Ch10 in Build_Shadow_Entity. However, we're running short on
12186 -- slots for new attributes, and it seems a bit simpler to just search
12187 -- the Limited_View (if it exists) for an incomplete type whose
12188 -- Non_Limited_View is Typ.
12190 if Ekind (Scope (Typ)) = E_Package
12191 and then Present (Limited_View (Scope (Typ)))
12192 then
12193 declare
12194 Ent : Entity_Id := First_Entity (Limited_View (Scope (Typ)));
12195 begin
12196 while Present (Ent) loop
12197 if Ekind (Ent) in Incomplete_Kind
12198 and then Non_Limited_View (Ent) = Typ
12199 then
12200 return Ent;
12201 end if;
12203 Ent := Next_Entity (Ent);
12204 end loop;
12205 end;
12206 end if;
12208 return Typ;
12209 end Incomplete_View_From_Limited_With;
12211 ----------------------------------
12212 -- Indexed_Component_Bit_Offset --
12213 ----------------------------------
12215 function Indexed_Component_Bit_Offset (N : Node_Id) return Uint is
12216 Exp : constant Node_Id := First (Expressions (N));
12217 Typ : constant Entity_Id := Etype (Prefix (N));
12218 Off : constant Uint := Component_Size (Typ);
12219 Ind : Node_Id;
12221 begin
12222 -- Return early if the component size is not known or variable
12224 if Off = No_Uint or else Off < Uint_0 then
12225 return No_Uint;
12226 end if;
12228 -- Deal with the degenerate case of an empty component
12230 if Off = Uint_0 then
12231 return Off;
12232 end if;
12234 -- Check that both the index value and the low bound are known
12236 if not Compile_Time_Known_Value (Exp) then
12237 return No_Uint;
12238 end if;
12240 Ind := First_Index (Typ);
12241 if No (Ind) then
12242 return No_Uint;
12243 end if;
12245 if Nkind (Ind) = N_Subtype_Indication then
12246 Ind := Constraint (Ind);
12248 if Nkind (Ind) = N_Range_Constraint then
12249 Ind := Range_Expression (Ind);
12250 end if;
12251 end if;
12253 if Nkind (Ind) /= N_Range
12254 or else not Compile_Time_Known_Value (Low_Bound (Ind))
12255 then
12256 return No_Uint;
12257 end if;
12259 -- Return the scaled offset
12261 return Off * (Expr_Value (Exp) - Expr_Value (Low_Bound ((Ind))));
12262 end Indexed_Component_Bit_Offset;
12264 ----------------------------
12265 -- Inherit_Rep_Item_Chain --
12266 ----------------------------
12268 procedure Inherit_Rep_Item_Chain (Typ : Entity_Id; From_Typ : Entity_Id) is
12269 Item : Node_Id;
12270 Next_Item : Node_Id;
12272 begin
12273 -- There are several inheritance scenarios to consider depending on
12274 -- whether both types have rep item chains and whether the destination
12275 -- type already inherits part of the source type's rep item chain.
12277 -- 1) The source type lacks a rep item chain
12278 -- From_Typ ---> Empty
12280 -- Typ --------> Item (or Empty)
12282 -- In this case inheritance cannot take place because there are no items
12283 -- to inherit.
12285 -- 2) The destination type lacks a rep item chain
12286 -- From_Typ ---> Item ---> ...
12288 -- Typ --------> Empty
12290 -- Inheritance takes place by setting the First_Rep_Item of the
12291 -- destination type to the First_Rep_Item of the source type.
12292 -- From_Typ ---> Item ---> ...
12293 -- ^
12294 -- Typ -----------+
12296 -- 3.1) Both source and destination types have at least one rep item.
12297 -- The destination type does NOT inherit a rep item from the source
12298 -- type.
12299 -- From_Typ ---> Item ---> Item
12301 -- Typ --------> Item ---> Item
12303 -- Inheritance takes place by setting the Next_Rep_Item of the last item
12304 -- of the destination type to the First_Rep_Item of the source type.
12305 -- From_Typ -------------------> Item ---> Item
12306 -- ^
12307 -- Typ --------> Item ---> Item --+
12309 -- 3.2) Both source and destination types have at least one rep item.
12310 -- The destination type DOES inherit part of the rep item chain of the
12311 -- source type.
12312 -- From_Typ ---> Item ---> Item ---> Item
12313 -- ^
12314 -- Typ --------> Item ------+
12316 -- This rare case arises when the full view of a private extension must
12317 -- inherit the rep item chain from the full view of its parent type and
12318 -- the full view of the parent type contains extra rep items. Currently
12319 -- only invariants may lead to such form of inheritance.
12321 -- type From_Typ is tagged private
12322 -- with Type_Invariant'Class => Item_2;
12324 -- type Typ is new From_Typ with private
12325 -- with Type_Invariant => Item_4;
12327 -- At this point the rep item chains contain the following items
12329 -- From_Typ -----------> Item_2 ---> Item_3
12330 -- ^
12331 -- Typ --------> Item_4 --+
12333 -- The full views of both types may introduce extra invariants
12335 -- type From_Typ is tagged null record
12336 -- with Type_Invariant => Item_1;
12338 -- type Typ is new From_Typ with null record;
12340 -- The full view of Typ would have to inherit any new rep items added to
12341 -- the full view of From_Typ.
12343 -- From_Typ -----------> Item_1 ---> Item_2 ---> Item_3
12344 -- ^
12345 -- Typ --------> Item_4 --+
12347 -- To achieve this form of inheritance, the destination type must first
12348 -- sever the link between its own rep chain and that of the source type,
12349 -- then inheritance 3.1 takes place.
12351 -- Case 1: The source type lacks a rep item chain
12353 if No (First_Rep_Item (From_Typ)) then
12354 return;
12356 -- Case 2: The destination type lacks a rep item chain
12358 elsif No (First_Rep_Item (Typ)) then
12359 Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ));
12361 -- Case 3: Both the source and destination types have at least one rep
12362 -- item. Traverse the rep item chain of the destination type to find the
12363 -- last rep item.
12365 else
12366 Item := Empty;
12367 Next_Item := First_Rep_Item (Typ);
12368 while Present (Next_Item) loop
12370 -- Detect a link between the destination type's rep chain and that
12371 -- of the source type. There are two possibilities:
12373 -- Variant 1
12374 -- Next_Item
12375 -- V
12376 -- From_Typ ---> Item_1 --->
12377 -- ^
12378 -- Typ -----------+
12380 -- Item is Empty
12382 -- Variant 2
12383 -- Next_Item
12384 -- V
12385 -- From_Typ ---> Item_1 ---> Item_2 --->
12386 -- ^
12387 -- Typ --------> Item_3 ------+
12388 -- ^
12389 -- Item
12391 if Has_Rep_Item (From_Typ, Next_Item) then
12392 exit;
12393 end if;
12395 Item := Next_Item;
12396 Next_Item := Next_Rep_Item (Next_Item);
12397 end loop;
12399 -- Inherit the source type's rep item chain
12401 if Present (Item) then
12402 Set_Next_Rep_Item (Item, First_Rep_Item (From_Typ));
12403 else
12404 Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ));
12405 end if;
12406 end if;
12407 end Inherit_Rep_Item_Chain;
12409 ---------------------------------
12410 -- Insert_Explicit_Dereference --
12411 ---------------------------------
12413 procedure Insert_Explicit_Dereference (N : Node_Id) is
12414 New_Prefix : constant Node_Id := Relocate_Node (N);
12415 Ent : Entity_Id := Empty;
12416 Pref : Node_Id;
12417 I : Interp_Index;
12418 It : Interp;
12419 T : Entity_Id;
12421 begin
12422 Save_Interps (N, New_Prefix);
12424 Rewrite (N,
12425 Make_Explicit_Dereference (Sloc (Parent (N)),
12426 Prefix => New_Prefix));
12428 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
12430 if Is_Overloaded (New_Prefix) then
12432 -- The dereference is also overloaded, and its interpretations are
12433 -- the designated types of the interpretations of the original node.
12435 Set_Etype (N, Any_Type);
12437 Get_First_Interp (New_Prefix, I, It);
12438 while Present (It.Nam) loop
12439 T := It.Typ;
12441 if Is_Access_Type (T) then
12442 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
12443 end if;
12445 Get_Next_Interp (I, It);
12446 end loop;
12448 End_Interp_List;
12450 else
12451 -- Prefix is unambiguous: mark the original prefix (which might
12452 -- Come_From_Source) as a reference, since the new (relocated) one
12453 -- won't be taken into account.
12455 if Is_Entity_Name (New_Prefix) then
12456 Ent := Entity (New_Prefix);
12457 Pref := New_Prefix;
12459 -- For a retrieval of a subcomponent of some composite object,
12460 -- retrieve the ultimate entity if there is one.
12462 elsif Nkind_In (New_Prefix, N_Selected_Component,
12463 N_Indexed_Component)
12464 then
12465 Pref := Prefix (New_Prefix);
12466 while Present (Pref)
12467 and then Nkind_In (Pref, N_Selected_Component,
12468 N_Indexed_Component)
12469 loop
12470 Pref := Prefix (Pref);
12471 end loop;
12473 if Present (Pref) and then Is_Entity_Name (Pref) then
12474 Ent := Entity (Pref);
12475 end if;
12476 end if;
12478 -- Place the reference on the entity node
12480 if Present (Ent) then
12481 Generate_Reference (Ent, Pref);
12482 end if;
12483 end if;
12484 end Insert_Explicit_Dereference;
12486 ------------------------------------------
12487 -- Inspect_Deferred_Constant_Completion --
12488 ------------------------------------------
12490 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
12491 Decl : Node_Id;
12493 begin
12494 Decl := First (Decls);
12495 while Present (Decl) loop
12497 -- Deferred constant signature
12499 if Nkind (Decl) = N_Object_Declaration
12500 and then Constant_Present (Decl)
12501 and then No (Expression (Decl))
12503 -- No need to check internally generated constants
12505 and then Comes_From_Source (Decl)
12507 -- The constant is not completed. A full object declaration or a
12508 -- pragma Import complete a deferred constant.
12510 and then not Has_Completion (Defining_Identifier (Decl))
12511 then
12512 Error_Msg_N
12513 ("constant declaration requires initialization expression",
12514 Defining_Identifier (Decl));
12515 end if;
12517 Decl := Next (Decl);
12518 end loop;
12519 end Inspect_Deferred_Constant_Completion;
12521 -----------------------------
12522 -- Install_Generic_Formals --
12523 -----------------------------
12525 procedure Install_Generic_Formals (Subp_Id : Entity_Id) is
12526 E : Entity_Id;
12528 begin
12529 pragma Assert (Is_Generic_Subprogram (Subp_Id));
12531 E := First_Entity (Subp_Id);
12532 while Present (E) loop
12533 Install_Entity (E);
12534 Next_Entity (E);
12535 end loop;
12536 end Install_Generic_Formals;
12538 ------------------------
12539 -- Install_SPARK_Mode --
12540 ------------------------
12542 procedure Install_SPARK_Mode (Mode : SPARK_Mode_Type; Prag : Node_Id) is
12543 begin
12544 SPARK_Mode := Mode;
12545 SPARK_Mode_Pragma := Prag;
12546 end Install_SPARK_Mode;
12548 -----------------------------
12549 -- Is_Actual_Out_Parameter --
12550 -----------------------------
12552 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
12553 Formal : Entity_Id;
12554 Call : Node_Id;
12555 begin
12556 Find_Actual (N, Formal, Call);
12557 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
12558 end Is_Actual_Out_Parameter;
12560 -------------------------
12561 -- Is_Actual_Parameter --
12562 -------------------------
12564 function Is_Actual_Parameter (N : Node_Id) return Boolean is
12565 PK : constant Node_Kind := Nkind (Parent (N));
12567 begin
12568 case PK is
12569 when N_Parameter_Association =>
12570 return N = Explicit_Actual_Parameter (Parent (N));
12572 when N_Subprogram_Call =>
12573 return Is_List_Member (N)
12574 and then
12575 List_Containing (N) = Parameter_Associations (Parent (N));
12577 when others =>
12578 return False;
12579 end case;
12580 end Is_Actual_Parameter;
12582 --------------------------------
12583 -- Is_Actual_Tagged_Parameter --
12584 --------------------------------
12586 function Is_Actual_Tagged_Parameter (N : Node_Id) return Boolean is
12587 Formal : Entity_Id;
12588 Call : Node_Id;
12589 begin
12590 Find_Actual (N, Formal, Call);
12591 return Present (Formal) and then Is_Tagged_Type (Etype (Formal));
12592 end Is_Actual_Tagged_Parameter;
12594 ---------------------
12595 -- Is_Aliased_View --
12596 ---------------------
12598 function Is_Aliased_View (Obj : Node_Id) return Boolean is
12599 E : Entity_Id;
12601 begin
12602 if Is_Entity_Name (Obj) then
12603 E := Entity (Obj);
12605 return
12606 (Is_Object (E)
12607 and then
12608 (Is_Aliased (E)
12609 or else (Present (Renamed_Object (E))
12610 and then Is_Aliased_View (Renamed_Object (E)))))
12612 or else ((Is_Formal (E) or else Is_Formal_Object (E))
12613 and then Is_Tagged_Type (Etype (E)))
12615 or else (Is_Concurrent_Type (E) and then In_Open_Scopes (E))
12617 -- Current instance of type, either directly or as rewritten
12618 -- reference to the current object.
12620 or else (Is_Entity_Name (Original_Node (Obj))
12621 and then Present (Entity (Original_Node (Obj)))
12622 and then Is_Type (Entity (Original_Node (Obj))))
12624 or else (Is_Type (E) and then E = Current_Scope)
12626 or else (Is_Incomplete_Or_Private_Type (E)
12627 and then Full_View (E) = Current_Scope)
12629 -- Ada 2012 AI05-0053: the return object of an extended return
12630 -- statement is aliased if its type is immutably limited.
12632 or else (Is_Return_Object (E)
12633 and then Is_Limited_View (Etype (E)));
12635 elsif Nkind (Obj) = N_Selected_Component then
12636 return Is_Aliased (Entity (Selector_Name (Obj)));
12638 elsif Nkind (Obj) = N_Indexed_Component then
12639 return Has_Aliased_Components (Etype (Prefix (Obj)))
12640 or else
12641 (Is_Access_Type (Etype (Prefix (Obj)))
12642 and then Has_Aliased_Components
12643 (Designated_Type (Etype (Prefix (Obj)))));
12645 elsif Nkind_In (Obj, N_Unchecked_Type_Conversion, N_Type_Conversion) then
12646 return Is_Tagged_Type (Etype (Obj))
12647 and then Is_Aliased_View (Expression (Obj));
12649 elsif Nkind (Obj) = N_Explicit_Dereference then
12650 return Nkind (Original_Node (Obj)) /= N_Function_Call;
12652 else
12653 return False;
12654 end if;
12655 end Is_Aliased_View;
12657 -------------------------
12658 -- Is_Ancestor_Package --
12659 -------------------------
12661 function Is_Ancestor_Package
12662 (E1 : Entity_Id;
12663 E2 : Entity_Id) return Boolean
12665 Par : Entity_Id;
12667 begin
12668 Par := E2;
12669 while Present (Par) and then Par /= Standard_Standard loop
12670 if Par = E1 then
12671 return True;
12672 end if;
12674 Par := Scope (Par);
12675 end loop;
12677 return False;
12678 end Is_Ancestor_Package;
12680 ----------------------
12681 -- Is_Atomic_Object --
12682 ----------------------
12684 function Is_Atomic_Object (N : Node_Id) return Boolean is
12686 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
12687 -- Determines if given object has atomic components
12689 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
12690 -- If prefix is an implicit dereference, examine designated type
12692 ----------------------
12693 -- Is_Atomic_Prefix --
12694 ----------------------
12696 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
12697 begin
12698 if Is_Access_Type (Etype (N)) then
12699 return
12700 Has_Atomic_Components (Designated_Type (Etype (N)));
12701 else
12702 return Object_Has_Atomic_Components (N);
12703 end if;
12704 end Is_Atomic_Prefix;
12706 ----------------------------------
12707 -- Object_Has_Atomic_Components --
12708 ----------------------------------
12710 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
12711 begin
12712 if Has_Atomic_Components (Etype (N))
12713 or else Is_Atomic (Etype (N))
12714 then
12715 return True;
12717 elsif Is_Entity_Name (N)
12718 and then (Has_Atomic_Components (Entity (N))
12719 or else Is_Atomic (Entity (N)))
12720 then
12721 return True;
12723 elsif Nkind (N) = N_Selected_Component
12724 and then Is_Atomic (Entity (Selector_Name (N)))
12725 then
12726 return True;
12728 elsif Nkind (N) = N_Indexed_Component
12729 or else Nkind (N) = N_Selected_Component
12730 then
12731 return Is_Atomic_Prefix (Prefix (N));
12733 else
12734 return False;
12735 end if;
12736 end Object_Has_Atomic_Components;
12738 -- Start of processing for Is_Atomic_Object
12740 begin
12741 -- Predicate is not relevant to subprograms
12743 if Is_Entity_Name (N) and then Is_Overloadable (Entity (N)) then
12744 return False;
12746 elsif Is_Atomic (Etype (N))
12747 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
12748 then
12749 return True;
12751 elsif Nkind (N) = N_Selected_Component
12752 and then Is_Atomic (Entity (Selector_Name (N)))
12753 then
12754 return True;
12756 elsif Nkind (N) = N_Indexed_Component
12757 or else Nkind (N) = N_Selected_Component
12758 then
12759 return Is_Atomic_Prefix (Prefix (N));
12761 else
12762 return False;
12763 end if;
12764 end Is_Atomic_Object;
12766 -----------------------------
12767 -- Is_Atomic_Or_VFA_Object --
12768 -----------------------------
12770 function Is_Atomic_Or_VFA_Object (N : Node_Id) return Boolean is
12771 begin
12772 return Is_Atomic_Object (N)
12773 or else (Is_Object_Reference (N)
12774 and then Is_Entity_Name (N)
12775 and then (Is_Volatile_Full_Access (Entity (N))
12776 or else
12777 Is_Volatile_Full_Access (Etype (Entity (N)))));
12778 end Is_Atomic_Or_VFA_Object;
12780 -------------------------
12781 -- Is_Attribute_Result --
12782 -------------------------
12784 function Is_Attribute_Result (N : Node_Id) return Boolean is
12785 begin
12786 return Nkind (N) = N_Attribute_Reference
12787 and then Attribute_Name (N) = Name_Result;
12788 end Is_Attribute_Result;
12790 -------------------------
12791 -- Is_Attribute_Update --
12792 -------------------------
12794 function Is_Attribute_Update (N : Node_Id) return Boolean is
12795 begin
12796 return Nkind (N) = N_Attribute_Reference
12797 and then Attribute_Name (N) = Name_Update;
12798 end Is_Attribute_Update;
12800 ------------------------------------
12801 -- Is_Body_Or_Package_Declaration --
12802 ------------------------------------
12804 function Is_Body_Or_Package_Declaration (N : Node_Id) return Boolean is
12805 begin
12806 return Nkind_In (N, N_Entry_Body,
12807 N_Package_Body,
12808 N_Package_Declaration,
12809 N_Protected_Body,
12810 N_Subprogram_Body,
12811 N_Task_Body);
12812 end Is_Body_Or_Package_Declaration;
12814 -----------------------
12815 -- Is_Bounded_String --
12816 -----------------------
12818 function Is_Bounded_String (T : Entity_Id) return Boolean is
12819 Under : constant Entity_Id := Underlying_Type (Root_Type (T));
12821 begin
12822 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
12823 -- Super_String, or one of the [Wide_]Wide_ versions. This will
12824 -- be True for all the Bounded_String types in instances of the
12825 -- Generic_Bounded_Length generics, and for types derived from those.
12827 return Present (Under)
12828 and then (Is_RTE (Root_Type (Under), RO_SU_Super_String) or else
12829 Is_RTE (Root_Type (Under), RO_WI_Super_String) or else
12830 Is_RTE (Root_Type (Under), RO_WW_Super_String));
12831 end Is_Bounded_String;
12833 ---------------------
12834 -- Is_CCT_Instance --
12835 ---------------------
12837 function Is_CCT_Instance
12838 (Ref_Id : Entity_Id;
12839 Context_Id : Entity_Id) return Boolean
12841 begin
12842 pragma Assert (Ekind_In (Ref_Id, E_Protected_Type, E_Task_Type));
12844 if Is_Single_Task_Object (Context_Id) then
12845 return Scope_Within_Or_Same (Etype (Context_Id), Ref_Id);
12847 else
12848 pragma Assert (Ekind_In (Context_Id, E_Entry,
12849 E_Entry_Family,
12850 E_Function,
12851 E_Package,
12852 E_Procedure,
12853 E_Protected_Type,
12854 E_Task_Type)
12855 or else
12856 Is_Record_Type (Context_Id));
12857 return Scope_Within_Or_Same (Context_Id, Ref_Id);
12858 end if;
12859 end Is_CCT_Instance;
12861 -------------------------
12862 -- Is_Child_Or_Sibling --
12863 -------------------------
12865 function Is_Child_Or_Sibling
12866 (Pack_1 : Entity_Id;
12867 Pack_2 : Entity_Id) return Boolean
12869 function Distance_From_Standard (Pack : Entity_Id) return Nat;
12870 -- Given an arbitrary package, return the number of "climbs" necessary
12871 -- to reach scope Standard_Standard.
12873 procedure Equalize_Depths
12874 (Pack : in out Entity_Id;
12875 Depth : in out Nat;
12876 Depth_To_Reach : Nat);
12877 -- Given an arbitrary package, its depth and a target depth to reach,
12878 -- climb the scope chain until the said depth is reached. The pointer
12879 -- to the package and its depth a modified during the climb.
12881 ----------------------------
12882 -- Distance_From_Standard --
12883 ----------------------------
12885 function Distance_From_Standard (Pack : Entity_Id) return Nat is
12886 Dist : Nat;
12887 Scop : Entity_Id;
12889 begin
12890 Dist := 0;
12891 Scop := Pack;
12892 while Present (Scop) and then Scop /= Standard_Standard loop
12893 Dist := Dist + 1;
12894 Scop := Scope (Scop);
12895 end loop;
12897 return Dist;
12898 end Distance_From_Standard;
12900 ---------------------
12901 -- Equalize_Depths --
12902 ---------------------
12904 procedure Equalize_Depths
12905 (Pack : in out Entity_Id;
12906 Depth : in out Nat;
12907 Depth_To_Reach : Nat)
12909 begin
12910 -- The package must be at a greater or equal depth
12912 if Depth < Depth_To_Reach then
12913 raise Program_Error;
12914 end if;
12916 -- Climb the scope chain until the desired depth is reached
12918 while Present (Pack) and then Depth /= Depth_To_Reach loop
12919 Pack := Scope (Pack);
12920 Depth := Depth - 1;
12921 end loop;
12922 end Equalize_Depths;
12924 -- Local variables
12926 P_1 : Entity_Id := Pack_1;
12927 P_1_Child : Boolean := False;
12928 P_1_Depth : Nat := Distance_From_Standard (P_1);
12929 P_2 : Entity_Id := Pack_2;
12930 P_2_Child : Boolean := False;
12931 P_2_Depth : Nat := Distance_From_Standard (P_2);
12933 -- Start of processing for Is_Child_Or_Sibling
12935 begin
12936 pragma Assert
12937 (Ekind (Pack_1) = E_Package and then Ekind (Pack_2) = E_Package);
12939 -- Both packages denote the same entity, therefore they cannot be
12940 -- children or siblings.
12942 if P_1 = P_2 then
12943 return False;
12945 -- One of the packages is at a deeper level than the other. Note that
12946 -- both may still come from different hierarchies.
12948 -- (root) P_2
12949 -- / \ :
12950 -- X P_2 or X
12951 -- : :
12952 -- P_1 P_1
12954 elsif P_1_Depth > P_2_Depth then
12955 Equalize_Depths
12956 (Pack => P_1,
12957 Depth => P_1_Depth,
12958 Depth_To_Reach => P_2_Depth);
12959 P_1_Child := True;
12961 -- (root) P_1
12962 -- / \ :
12963 -- P_1 X or X
12964 -- : :
12965 -- P_2 P_2
12967 elsif P_2_Depth > P_1_Depth then
12968 Equalize_Depths
12969 (Pack => P_2,
12970 Depth => P_2_Depth,
12971 Depth_To_Reach => P_1_Depth);
12972 P_2_Child := True;
12973 end if;
12975 -- At this stage the package pointers have been elevated to the same
12976 -- depth. If the related entities are the same, then one package is a
12977 -- potential child of the other:
12979 -- P_1
12980 -- :
12981 -- X became P_1 P_2 or vice versa
12982 -- :
12983 -- P_2
12985 if P_1 = P_2 then
12986 if P_1_Child then
12987 return Is_Child_Unit (Pack_1);
12989 else pragma Assert (P_2_Child);
12990 return Is_Child_Unit (Pack_2);
12991 end if;
12993 -- The packages may come from the same package chain or from entirely
12994 -- different hierarcies. To determine this, climb the scope stack until
12995 -- a common root is found.
12997 -- (root) (root 1) (root 2)
12998 -- / \ | |
12999 -- P_1 P_2 P_1 P_2
13001 else
13002 while Present (P_1) and then Present (P_2) loop
13004 -- The two packages may be siblings
13006 if P_1 = P_2 then
13007 return Is_Child_Unit (Pack_1) and then Is_Child_Unit (Pack_2);
13008 end if;
13010 P_1 := Scope (P_1);
13011 P_2 := Scope (P_2);
13012 end loop;
13013 end if;
13015 return False;
13016 end Is_Child_Or_Sibling;
13018 -----------------------------
13019 -- Is_Concurrent_Interface --
13020 -----------------------------
13022 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
13023 begin
13024 return Is_Interface (T)
13025 and then
13026 (Is_Protected_Interface (T)
13027 or else Is_Synchronized_Interface (T)
13028 or else Is_Task_Interface (T));
13029 end Is_Concurrent_Interface;
13031 -----------------------
13032 -- Is_Constant_Bound --
13033 -----------------------
13035 function Is_Constant_Bound (Exp : Node_Id) return Boolean is
13036 begin
13037 if Compile_Time_Known_Value (Exp) then
13038 return True;
13040 elsif Is_Entity_Name (Exp) and then Present (Entity (Exp)) then
13041 return Is_Constant_Object (Entity (Exp))
13042 or else Ekind (Entity (Exp)) = E_Enumeration_Literal;
13044 elsif Nkind (Exp) in N_Binary_Op then
13045 return Is_Constant_Bound (Left_Opnd (Exp))
13046 and then Is_Constant_Bound (Right_Opnd (Exp))
13047 and then Scope (Entity (Exp)) = Standard_Standard;
13049 else
13050 return False;
13051 end if;
13052 end Is_Constant_Bound;
13054 ---------------------------
13055 -- Is_Container_Element --
13056 ---------------------------
13058 function Is_Container_Element (Exp : Node_Id) return Boolean is
13059 Loc : constant Source_Ptr := Sloc (Exp);
13060 Pref : constant Node_Id := Prefix (Exp);
13062 Call : Node_Id;
13063 -- Call to an indexing aspect
13065 Cont_Typ : Entity_Id;
13066 -- The type of the container being accessed
13068 Elem_Typ : Entity_Id;
13069 -- Its element type
13071 Indexing : Entity_Id;
13072 Is_Const : Boolean;
13073 -- Indicates that constant indexing is used, and the element is thus
13074 -- a constant.
13076 Ref_Typ : Entity_Id;
13077 -- The reference type returned by the indexing operation
13079 begin
13080 -- If C is a container, in a context that imposes the element type of
13081 -- that container, the indexing notation C (X) is rewritten as:
13083 -- Indexing (C, X).Discr.all
13085 -- where Indexing is one of the indexing aspects of the container.
13086 -- If the context does not require a reference, the construct can be
13087 -- rewritten as
13089 -- Element (C, X)
13091 -- First, verify that the construct has the proper form
13093 if not Expander_Active then
13094 return False;
13096 elsif Nkind (Pref) /= N_Selected_Component then
13097 return False;
13099 elsif Nkind (Prefix (Pref)) /= N_Function_Call then
13100 return False;
13102 else
13103 Call := Prefix (Pref);
13104 Ref_Typ := Etype (Call);
13105 end if;
13107 if not Has_Implicit_Dereference (Ref_Typ)
13108 or else No (First (Parameter_Associations (Call)))
13109 or else not Is_Entity_Name (Name (Call))
13110 then
13111 return False;
13112 end if;
13114 -- Retrieve type of container object, and its iterator aspects
13116 Cont_Typ := Etype (First (Parameter_Associations (Call)));
13117 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Constant_Indexing);
13118 Is_Const := False;
13120 if No (Indexing) then
13122 -- Container should have at least one indexing operation
13124 return False;
13126 elsif Entity (Name (Call)) /= Entity (Indexing) then
13128 -- This may be a variable indexing operation
13130 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Variable_Indexing);
13132 if No (Indexing)
13133 or else Entity (Name (Call)) /= Entity (Indexing)
13134 then
13135 return False;
13136 end if;
13138 else
13139 Is_Const := True;
13140 end if;
13142 Elem_Typ := Find_Value_Of_Aspect (Cont_Typ, Aspect_Iterator_Element);
13144 if No (Elem_Typ) or else Entity (Elem_Typ) /= Etype (Exp) then
13145 return False;
13146 end if;
13148 -- Check that the expression is not the target of an assignment, in
13149 -- which case the rewriting is not possible.
13151 if not Is_Const then
13152 declare
13153 Par : Node_Id;
13155 begin
13156 Par := Exp;
13157 while Present (Par)
13158 loop
13159 if Nkind (Parent (Par)) = N_Assignment_Statement
13160 and then Par = Name (Parent (Par))
13161 then
13162 return False;
13164 -- A renaming produces a reference, and the transformation
13165 -- does not apply.
13167 elsif Nkind (Parent (Par)) = N_Object_Renaming_Declaration then
13168 return False;
13170 elsif Nkind_In
13171 (Nkind (Parent (Par)), N_Function_Call,
13172 N_Procedure_Call_Statement,
13173 N_Entry_Call_Statement)
13174 then
13175 -- Check that the element is not part of an actual for an
13176 -- in-out parameter.
13178 declare
13179 F : Entity_Id;
13180 A : Node_Id;
13182 begin
13183 F := First_Formal (Entity (Name (Parent (Par))));
13184 A := First (Parameter_Associations (Parent (Par)));
13185 while Present (F) loop
13186 if A = Par and then Ekind (F) /= E_In_Parameter then
13187 return False;
13188 end if;
13190 Next_Formal (F);
13191 Next (A);
13192 end loop;
13193 end;
13195 -- E_In_Parameter in a call: element is not modified.
13197 exit;
13198 end if;
13200 Par := Parent (Par);
13201 end loop;
13202 end;
13203 end if;
13205 -- The expression has the proper form and the context requires the
13206 -- element type. Retrieve the Element function of the container and
13207 -- rewrite the construct as a call to it.
13209 declare
13210 Op : Elmt_Id;
13212 begin
13213 Op := First_Elmt (Primitive_Operations (Cont_Typ));
13214 while Present (Op) loop
13215 exit when Chars (Node (Op)) = Name_Element;
13216 Next_Elmt (Op);
13217 end loop;
13219 if No (Op) then
13220 return False;
13222 else
13223 Rewrite (Exp,
13224 Make_Function_Call (Loc,
13225 Name => New_Occurrence_Of (Node (Op), Loc),
13226 Parameter_Associations => Parameter_Associations (Call)));
13227 Analyze_And_Resolve (Exp, Entity (Elem_Typ));
13228 return True;
13229 end if;
13230 end;
13231 end Is_Container_Element;
13233 ----------------------------
13234 -- Is_Contract_Annotation --
13235 ----------------------------
13237 function Is_Contract_Annotation (Item : Node_Id) return Boolean is
13238 begin
13239 return Is_Package_Contract_Annotation (Item)
13240 or else
13241 Is_Subprogram_Contract_Annotation (Item);
13242 end Is_Contract_Annotation;
13244 --------------------------------------
13245 -- Is_Controlling_Limited_Procedure --
13246 --------------------------------------
13248 function Is_Controlling_Limited_Procedure
13249 (Proc_Nam : Entity_Id) return Boolean
13251 Param : Node_Id;
13252 Param_Typ : Entity_Id := Empty;
13254 begin
13255 if Ekind (Proc_Nam) = E_Procedure
13256 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
13257 then
13258 Param :=
13259 Parameter_Type
13260 (First (Parameter_Specifications (Parent (Proc_Nam))));
13262 -- The formal may be an anonymous access type
13264 if Nkind (Param) = N_Access_Definition then
13265 Param_Typ := Entity (Subtype_Mark (Param));
13266 else
13267 Param_Typ := Etype (Param);
13268 end if;
13270 -- In the case where an Itype was created for a dispatchin call, the
13271 -- procedure call has been rewritten. The actual may be an access to
13272 -- interface type in which case it is the designated type that is the
13273 -- controlling type.
13275 elsif Present (Associated_Node_For_Itype (Proc_Nam))
13276 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
13277 and then
13278 Present (Parameter_Associations
13279 (Associated_Node_For_Itype (Proc_Nam)))
13280 then
13281 Param_Typ :=
13282 Etype (First (Parameter_Associations
13283 (Associated_Node_For_Itype (Proc_Nam))));
13285 if Ekind (Param_Typ) = E_Anonymous_Access_Type then
13286 Param_Typ := Directly_Designated_Type (Param_Typ);
13287 end if;
13288 end if;
13290 if Present (Param_Typ) then
13291 return
13292 Is_Interface (Param_Typ)
13293 and then Is_Limited_Record (Param_Typ);
13294 end if;
13296 return False;
13297 end Is_Controlling_Limited_Procedure;
13299 -----------------------------
13300 -- Is_CPP_Constructor_Call --
13301 -----------------------------
13303 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
13304 begin
13305 return Nkind (N) = N_Function_Call
13306 and then Is_CPP_Class (Etype (Etype (N)))
13307 and then Is_Constructor (Entity (Name (N)))
13308 and then Is_Imported (Entity (Name (N)));
13309 end Is_CPP_Constructor_Call;
13311 -------------------------
13312 -- Is_Current_Instance --
13313 -------------------------
13315 function Is_Current_Instance (N : Node_Id) return Boolean is
13316 Typ : constant Entity_Id := Entity (N);
13317 P : Node_Id;
13319 begin
13320 -- Simplest case: entity is a concurrent type and we are currently
13321 -- inside the body. This will eventually be expanded into a call to
13322 -- Self (for tasks) or _object (for protected objects).
13324 if Is_Concurrent_Type (Typ) and then In_Open_Scopes (Typ) then
13325 return True;
13327 else
13328 -- Check whether the context is a (sub)type declaration for the
13329 -- type entity.
13331 P := Parent (N);
13332 while Present (P) loop
13333 if Nkind_In (P, N_Full_Type_Declaration,
13334 N_Private_Type_Declaration,
13335 N_Subtype_Declaration)
13336 and then Comes_From_Source (P)
13337 and then Defining_Entity (P) = Typ
13338 then
13339 return True;
13341 -- A subtype name may appear in an aspect specification for a
13342 -- Predicate_Failure aspect, for which we do not construct a
13343 -- wrapper procedure. The subtype will be replaced by the
13344 -- expression being tested when the corresponding predicate
13345 -- check is expanded.
13347 elsif Nkind (P) = N_Aspect_Specification
13348 and then Nkind (Parent (P)) = N_Subtype_Declaration
13349 then
13350 return True;
13352 elsif Nkind (P) = N_Pragma
13353 and then Get_Pragma_Id (P) = Pragma_Predicate_Failure
13354 then
13355 return True;
13356 end if;
13358 P := Parent (P);
13359 end loop;
13360 end if;
13362 -- In any other context this is not a current occurrence
13364 return False;
13365 end Is_Current_Instance;
13367 --------------------
13368 -- Is_Declaration --
13369 --------------------
13371 function Is_Declaration
13372 (N : Node_Id;
13373 Body_OK : Boolean := True;
13374 Concurrent_OK : Boolean := True;
13375 Formal_OK : Boolean := True;
13376 Generic_OK : Boolean := True;
13377 Instantiation_OK : Boolean := True;
13378 Renaming_OK : Boolean := True;
13379 Stub_OK : Boolean := True;
13380 Subprogram_OK : Boolean := True;
13381 Type_OK : Boolean := True) return Boolean
13383 begin
13384 case Nkind (N) is
13386 -- Body declarations
13388 when N_Proper_Body =>
13389 return Body_OK;
13391 -- Concurrent type declarations
13393 when N_Protected_Type_Declaration
13394 | N_Single_Protected_Declaration
13395 | N_Single_Task_Declaration
13396 | N_Task_Type_Declaration
13398 return Concurrent_OK or Type_OK;
13400 -- Formal declarations
13402 when N_Formal_Abstract_Subprogram_Declaration
13403 | N_Formal_Concrete_Subprogram_Declaration
13404 | N_Formal_Object_Declaration
13405 | N_Formal_Package_Declaration
13406 | N_Formal_Type_Declaration
13408 return Formal_OK;
13410 -- Generic declarations
13412 when N_Generic_Package_Declaration
13413 | N_Generic_Subprogram_Declaration
13415 return Generic_OK;
13417 -- Generic instantiations
13419 when N_Function_Instantiation
13420 | N_Package_Instantiation
13421 | N_Procedure_Instantiation
13423 return Instantiation_OK;
13425 -- Generic renaming declarations
13427 when N_Generic_Renaming_Declaration =>
13428 return Generic_OK or Renaming_OK;
13430 -- Renaming declarations
13432 when N_Exception_Renaming_Declaration
13433 | N_Object_Renaming_Declaration
13434 | N_Package_Renaming_Declaration
13435 | N_Subprogram_Renaming_Declaration
13437 return Renaming_OK;
13439 -- Stub declarations
13441 when N_Body_Stub =>
13442 return Stub_OK;
13444 -- Subprogram declarations
13446 when N_Abstract_Subprogram_Declaration
13447 | N_Entry_Declaration
13448 | N_Expression_Function
13449 | N_Subprogram_Declaration
13451 return Subprogram_OK;
13453 -- Type declarations
13455 when N_Full_Type_Declaration
13456 | N_Incomplete_Type_Declaration
13457 | N_Private_Extension_Declaration
13458 | N_Private_Type_Declaration
13459 | N_Subtype_Declaration
13461 return Type_OK;
13463 -- Miscellaneous
13465 when N_Component_Declaration
13466 | N_Exception_Declaration
13467 | N_Implicit_Label_Declaration
13468 | N_Number_Declaration
13469 | N_Object_Declaration
13470 | N_Package_Declaration
13472 return True;
13474 when others =>
13475 return False;
13476 end case;
13477 end Is_Declaration;
13479 --------------------------------
13480 -- Is_Declared_Within_Variant --
13481 --------------------------------
13483 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
13484 Comp_Decl : constant Node_Id := Parent (Comp);
13485 Comp_List : constant Node_Id := Parent (Comp_Decl);
13486 begin
13487 return Nkind (Parent (Comp_List)) = N_Variant;
13488 end Is_Declared_Within_Variant;
13490 ----------------------------------------------
13491 -- Is_Dependent_Component_Of_Mutable_Object --
13492 ----------------------------------------------
13494 function Is_Dependent_Component_Of_Mutable_Object
13495 (Object : Node_Id) return Boolean
13497 P : Node_Id;
13498 Prefix_Type : Entity_Id;
13499 P_Aliased : Boolean := False;
13500 Comp : Entity_Id;
13502 Deref : Node_Id := Object;
13503 -- Dereference node, in something like X.all.Y(2)
13505 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
13507 begin
13508 -- Find the dereference node if any
13510 while Nkind_In (Deref, N_Indexed_Component,
13511 N_Selected_Component,
13512 N_Slice)
13513 loop
13514 Deref := Prefix (Deref);
13515 end loop;
13517 -- Ada 2005: If we have a component or slice of a dereference,
13518 -- something like X.all.Y (2), and the type of X is access-to-constant,
13519 -- Is_Variable will return False, because it is indeed a constant
13520 -- view. But it might be a view of a variable object, so we want the
13521 -- following condition to be True in that case.
13523 if Is_Variable (Object)
13524 or else (Ada_Version >= Ada_2005
13525 and then Nkind (Deref) = N_Explicit_Dereference)
13526 then
13527 if Nkind (Object) = N_Selected_Component then
13528 P := Prefix (Object);
13529 Prefix_Type := Etype (P);
13531 if Is_Entity_Name (P) then
13532 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
13533 Prefix_Type := Base_Type (Prefix_Type);
13534 end if;
13536 if Is_Aliased (Entity (P)) then
13537 P_Aliased := True;
13538 end if;
13540 -- A discriminant check on a selected component may be expanded
13541 -- into a dereference when removing side effects. Recover the
13542 -- original node and its type, which may be unconstrained.
13544 elsif Nkind (P) = N_Explicit_Dereference
13545 and then not (Comes_From_Source (P))
13546 then
13547 P := Original_Node (P);
13548 Prefix_Type := Etype (P);
13550 else
13551 -- Check for prefix being an aliased component???
13553 null;
13555 end if;
13557 -- A heap object is constrained by its initial value
13559 -- Ada 2005 (AI-363): Always assume the object could be mutable in
13560 -- the dereferenced case, since the access value might denote an
13561 -- unconstrained aliased object, whereas in Ada 95 the designated
13562 -- object is guaranteed to be constrained. A worst-case assumption
13563 -- has to apply in Ada 2005 because we can't tell at compile
13564 -- time whether the object is "constrained by its initial value",
13565 -- despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are semantic
13566 -- rules (these rules are acknowledged to need fixing). We don't
13567 -- impose this more stringent checking for earlier Ada versions or
13568 -- when Relaxed_RM_Semantics applies (the latter for CodePeer's
13569 -- benefit, though it's unclear on why using -gnat95 would not be
13570 -- sufficient???).
13572 if Ada_Version < Ada_2005 or else Relaxed_RM_Semantics then
13573 if Is_Access_Type (Prefix_Type)
13574 or else Nkind (P) = N_Explicit_Dereference
13575 then
13576 return False;
13577 end if;
13579 else pragma Assert (Ada_Version >= Ada_2005);
13580 if Is_Access_Type (Prefix_Type) then
13582 -- If the access type is pool-specific, and there is no
13583 -- constrained partial view of the designated type, then the
13584 -- designated object is known to be constrained.
13586 if Ekind (Prefix_Type) = E_Access_Type
13587 and then not Object_Type_Has_Constrained_Partial_View
13588 (Typ => Designated_Type (Prefix_Type),
13589 Scop => Current_Scope)
13590 then
13591 return False;
13593 -- Otherwise (general access type, or there is a constrained
13594 -- partial view of the designated type), we need to check
13595 -- based on the designated type.
13597 else
13598 Prefix_Type := Designated_Type (Prefix_Type);
13599 end if;
13600 end if;
13601 end if;
13603 Comp :=
13604 Original_Record_Component (Entity (Selector_Name (Object)));
13606 -- As per AI-0017, the renaming is illegal in a generic body, even
13607 -- if the subtype is indefinite.
13609 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
13611 if not Is_Constrained (Prefix_Type)
13612 and then (Is_Definite_Subtype (Prefix_Type)
13613 or else
13614 (Is_Generic_Type (Prefix_Type)
13615 and then Ekind (Current_Scope) = E_Generic_Package
13616 and then In_Package_Body (Current_Scope)))
13618 and then (Is_Declared_Within_Variant (Comp)
13619 or else Has_Discriminant_Dependent_Constraint (Comp))
13620 and then (not P_Aliased or else Ada_Version >= Ada_2005)
13621 then
13622 return True;
13624 -- If the prefix is of an access type at this point, then we want
13625 -- to return False, rather than calling this function recursively
13626 -- on the access object (which itself might be a discriminant-
13627 -- dependent component of some other object, but that isn't
13628 -- relevant to checking the object passed to us). This avoids
13629 -- issuing wrong errors when compiling with -gnatc, where there
13630 -- can be implicit dereferences that have not been expanded.
13632 elsif Is_Access_Type (Etype (Prefix (Object))) then
13633 return False;
13635 else
13636 return
13637 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
13638 end if;
13640 elsif Nkind (Object) = N_Indexed_Component
13641 or else Nkind (Object) = N_Slice
13642 then
13643 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
13645 -- A type conversion that Is_Variable is a view conversion:
13646 -- go back to the denoted object.
13648 elsif Nkind (Object) = N_Type_Conversion then
13649 return
13650 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
13651 end if;
13652 end if;
13654 return False;
13655 end Is_Dependent_Component_Of_Mutable_Object;
13657 ---------------------
13658 -- Is_Dereferenced --
13659 ---------------------
13661 function Is_Dereferenced (N : Node_Id) return Boolean is
13662 P : constant Node_Id := Parent (N);
13663 begin
13664 return Nkind_In (P, N_Selected_Component,
13665 N_Explicit_Dereference,
13666 N_Indexed_Component,
13667 N_Slice)
13668 and then Prefix (P) = N;
13669 end Is_Dereferenced;
13671 ----------------------
13672 -- Is_Descendant_Of --
13673 ----------------------
13675 function Is_Descendant_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
13676 T : Entity_Id;
13677 Etyp : Entity_Id;
13679 begin
13680 pragma Assert (Nkind (T1) in N_Entity);
13681 pragma Assert (Nkind (T2) in N_Entity);
13683 T := Base_Type (T1);
13685 -- Immediate return if the types match
13687 if T = T2 then
13688 return True;
13690 -- Comment needed here ???
13692 elsif Ekind (T) = E_Class_Wide_Type then
13693 return Etype (T) = T2;
13695 -- All other cases
13697 else
13698 loop
13699 Etyp := Etype (T);
13701 -- Done if we found the type we are looking for
13703 if Etyp = T2 then
13704 return True;
13706 -- Done if no more derivations to check
13708 elsif T = T1
13709 or else T = Etyp
13710 then
13711 return False;
13713 -- Following test catches error cases resulting from prev errors
13715 elsif No (Etyp) then
13716 return False;
13718 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
13719 return False;
13721 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
13722 return False;
13723 end if;
13725 T := Base_Type (Etyp);
13726 end loop;
13727 end if;
13728 end Is_Descendant_Of;
13730 ----------------------------------------
13731 -- Is_Descendant_Of_Suspension_Object --
13732 ----------------------------------------
13734 function Is_Descendant_Of_Suspension_Object
13735 (Typ : Entity_Id) return Boolean
13737 Cur_Typ : Entity_Id;
13738 Par_Typ : Entity_Id;
13740 begin
13741 -- Climb the type derivation chain checking each parent type against
13742 -- Suspension_Object.
13744 Cur_Typ := Base_Type (Typ);
13745 while Present (Cur_Typ) loop
13746 Par_Typ := Etype (Cur_Typ);
13748 -- The current type is a match
13750 if Is_Suspension_Object (Cur_Typ) then
13751 return True;
13753 -- Stop the traversal once the root of the derivation chain has been
13754 -- reached. In that case the current type is its own base type.
13756 elsif Cur_Typ = Par_Typ then
13757 exit;
13758 end if;
13760 Cur_Typ := Base_Type (Par_Typ);
13761 end loop;
13763 return False;
13764 end Is_Descendant_Of_Suspension_Object;
13766 ---------------------------------------------
13767 -- Is_Double_Precision_Floating_Point_Type --
13768 ---------------------------------------------
13770 function Is_Double_Precision_Floating_Point_Type
13771 (E : Entity_Id) return Boolean is
13772 begin
13773 return Is_Floating_Point_Type (E)
13774 and then Machine_Radix_Value (E) = Uint_2
13775 and then Machine_Mantissa_Value (E) = UI_From_Int (53)
13776 and then Machine_Emax_Value (E) = Uint_2 ** Uint_10
13777 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_10);
13778 end Is_Double_Precision_Floating_Point_Type;
13780 -----------------------------
13781 -- Is_Effectively_Volatile --
13782 -----------------------------
13784 function Is_Effectively_Volatile (Id : Entity_Id) return Boolean is
13785 begin
13786 if Is_Type (Id) then
13788 -- An arbitrary type is effectively volatile when it is subject to
13789 -- pragma Atomic or Volatile.
13791 if Is_Volatile (Id) then
13792 return True;
13794 -- An array type is effectively volatile when it is subject to pragma
13795 -- Atomic_Components or Volatile_Components or its component type is
13796 -- effectively volatile.
13798 elsif Is_Array_Type (Id) then
13799 declare
13800 Anc : Entity_Id := Base_Type (Id);
13801 begin
13802 if Is_Private_Type (Anc) then
13803 Anc := Full_View (Anc);
13804 end if;
13806 -- Test for presence of ancestor, as the full view of a private
13807 -- type may be missing in case of error.
13809 return
13810 Has_Volatile_Components (Id)
13811 or else
13812 (Present (Anc)
13813 and then Is_Effectively_Volatile (Component_Type (Anc)));
13814 end;
13816 -- A protected type is always volatile
13818 elsif Is_Protected_Type (Id) then
13819 return True;
13821 -- A descendant of Ada.Synchronous_Task_Control.Suspension_Object is
13822 -- automatically volatile.
13824 elsif Is_Descendant_Of_Suspension_Object (Id) then
13825 return True;
13827 -- Otherwise the type is not effectively volatile
13829 else
13830 return False;
13831 end if;
13833 -- Otherwise Id denotes an object
13835 else
13836 return
13837 Is_Volatile (Id)
13838 or else Has_Volatile_Components (Id)
13839 or else Is_Effectively_Volatile (Etype (Id));
13840 end if;
13841 end Is_Effectively_Volatile;
13843 ------------------------------------
13844 -- Is_Effectively_Volatile_Object --
13845 ------------------------------------
13847 function Is_Effectively_Volatile_Object (N : Node_Id) return Boolean is
13848 begin
13849 if Is_Entity_Name (N) then
13850 return Is_Effectively_Volatile (Entity (N));
13852 elsif Nkind (N) = N_Indexed_Component then
13853 return Is_Effectively_Volatile_Object (Prefix (N));
13855 elsif Nkind (N) = N_Selected_Component then
13856 return
13857 Is_Effectively_Volatile_Object (Prefix (N))
13858 or else
13859 Is_Effectively_Volatile_Object (Selector_Name (N));
13861 else
13862 return False;
13863 end if;
13864 end Is_Effectively_Volatile_Object;
13866 -------------------
13867 -- Is_Entry_Body --
13868 -------------------
13870 function Is_Entry_Body (Id : Entity_Id) return Boolean is
13871 begin
13872 return
13873 Ekind_In (Id, E_Entry, E_Entry_Family)
13874 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Body;
13875 end Is_Entry_Body;
13877 --------------------------
13878 -- Is_Entry_Declaration --
13879 --------------------------
13881 function Is_Entry_Declaration (Id : Entity_Id) return Boolean is
13882 begin
13883 return
13884 Ekind_In (Id, E_Entry, E_Entry_Family)
13885 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Declaration;
13886 end Is_Entry_Declaration;
13888 ------------------------------------
13889 -- Is_Expanded_Priority_Attribute --
13890 ------------------------------------
13892 function Is_Expanded_Priority_Attribute (E : Entity_Id) return Boolean is
13893 begin
13894 return
13895 Nkind (E) = N_Function_Call
13896 and then not Configurable_Run_Time_Mode
13897 and then (Entity (Name (E)) = RTE (RE_Get_Ceiling)
13898 or else Entity (Name (E)) = RTE (RO_PE_Get_Ceiling));
13899 end Is_Expanded_Priority_Attribute;
13901 ----------------------------
13902 -- Is_Expression_Function --
13903 ----------------------------
13905 function Is_Expression_Function (Subp : Entity_Id) return Boolean is
13906 begin
13907 if Ekind_In (Subp, E_Function, E_Subprogram_Body) then
13908 return
13909 Nkind (Original_Node (Unit_Declaration_Node (Subp))) =
13910 N_Expression_Function;
13911 else
13912 return False;
13913 end if;
13914 end Is_Expression_Function;
13916 ------------------------------------------
13917 -- Is_Expression_Function_Or_Completion --
13918 ------------------------------------------
13920 function Is_Expression_Function_Or_Completion
13921 (Subp : Entity_Id) return Boolean
13923 Subp_Decl : Node_Id;
13925 begin
13926 if Ekind (Subp) = E_Function then
13927 Subp_Decl := Unit_Declaration_Node (Subp);
13929 -- The function declaration is either an expression function or is
13930 -- completed by an expression function body.
13932 return
13933 Is_Expression_Function (Subp)
13934 or else (Nkind (Subp_Decl) = N_Subprogram_Declaration
13935 and then Present (Corresponding_Body (Subp_Decl))
13936 and then Is_Expression_Function
13937 (Corresponding_Body (Subp_Decl)));
13939 elsif Ekind (Subp) = E_Subprogram_Body then
13940 return Is_Expression_Function (Subp);
13942 else
13943 return False;
13944 end if;
13945 end Is_Expression_Function_Or_Completion;
13947 -----------------------
13948 -- Is_EVF_Expression --
13949 -----------------------
13951 function Is_EVF_Expression (N : Node_Id) return Boolean is
13952 Orig_N : constant Node_Id := Original_Node (N);
13953 Alt : Node_Id;
13954 Expr : Node_Id;
13955 Id : Entity_Id;
13957 begin
13958 -- Detect a reference to a formal parameter of a specific tagged type
13959 -- whose related subprogram is subject to pragma Expresions_Visible with
13960 -- value "False".
13962 if Is_Entity_Name (N) and then Present (Entity (N)) then
13963 Id := Entity (N);
13965 return
13966 Is_Formal (Id)
13967 and then Is_Specific_Tagged_Type (Etype (Id))
13968 and then Extensions_Visible_Status (Id) =
13969 Extensions_Visible_False;
13971 -- A case expression is an EVF expression when it contains at least one
13972 -- EVF dependent_expression. Note that a case expression may have been
13973 -- expanded, hence the use of Original_Node.
13975 elsif Nkind (Orig_N) = N_Case_Expression then
13976 Alt := First (Alternatives (Orig_N));
13977 while Present (Alt) loop
13978 if Is_EVF_Expression (Expression (Alt)) then
13979 return True;
13980 end if;
13982 Next (Alt);
13983 end loop;
13985 -- An if expression is an EVF expression when it contains at least one
13986 -- EVF dependent_expression. Note that an if expression may have been
13987 -- expanded, hence the use of Original_Node.
13989 elsif Nkind (Orig_N) = N_If_Expression then
13990 Expr := Next (First (Expressions (Orig_N)));
13991 while Present (Expr) loop
13992 if Is_EVF_Expression (Expr) then
13993 return True;
13994 end if;
13996 Next (Expr);
13997 end loop;
13999 -- A qualified expression or a type conversion is an EVF expression when
14000 -- its operand is an EVF expression.
14002 elsif Nkind_In (N, N_Qualified_Expression,
14003 N_Unchecked_Type_Conversion,
14004 N_Type_Conversion)
14005 then
14006 return Is_EVF_Expression (Expression (N));
14008 -- Attributes 'Loop_Entry, 'Old, and 'Update are EVF expressions when
14009 -- their prefix denotes an EVF expression.
14011 elsif Nkind (N) = N_Attribute_Reference
14012 and then Nam_In (Attribute_Name (N), Name_Loop_Entry,
14013 Name_Old,
14014 Name_Update)
14015 then
14016 return Is_EVF_Expression (Prefix (N));
14017 end if;
14019 return False;
14020 end Is_EVF_Expression;
14022 --------------
14023 -- Is_False --
14024 --------------
14026 function Is_False (U : Uint) return Boolean is
14027 begin
14028 return (U = 0);
14029 end Is_False;
14031 ---------------------------
14032 -- Is_Fixed_Model_Number --
14033 ---------------------------
14035 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
14036 S : constant Ureal := Small_Value (T);
14037 M : Urealp.Save_Mark;
14038 R : Boolean;
14040 begin
14041 M := Urealp.Mark;
14042 R := (U = UR_Trunc (U / S) * S);
14043 Urealp.Release (M);
14044 return R;
14045 end Is_Fixed_Model_Number;
14047 -------------------------------
14048 -- Is_Fully_Initialized_Type --
14049 -------------------------------
14051 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
14052 begin
14053 -- Scalar types
14055 if Is_Scalar_Type (Typ) then
14057 -- A scalar type with an aspect Default_Value is fully initialized
14059 -- Note: Iniitalize/Normalize_Scalars also ensure full initialization
14060 -- of a scalar type, but we don't take that into account here, since
14061 -- we don't want these to affect warnings.
14063 return Has_Default_Aspect (Typ);
14065 elsif Is_Access_Type (Typ) then
14066 return True;
14068 elsif Is_Array_Type (Typ) then
14069 if Is_Fully_Initialized_Type (Component_Type (Typ))
14070 or else (Ada_Version >= Ada_2012 and then Has_Default_Aspect (Typ))
14071 then
14072 return True;
14073 end if;
14075 -- An interesting case, if we have a constrained type one of whose
14076 -- bounds is known to be null, then there are no elements to be
14077 -- initialized, so all the elements are initialized.
14079 if Is_Constrained (Typ) then
14080 declare
14081 Indx : Node_Id;
14082 Indx_Typ : Entity_Id;
14083 Lbd, Hbd : Node_Id;
14085 begin
14086 Indx := First_Index (Typ);
14087 while Present (Indx) loop
14088 if Etype (Indx) = Any_Type then
14089 return False;
14091 -- If index is a range, use directly
14093 elsif Nkind (Indx) = N_Range then
14094 Lbd := Low_Bound (Indx);
14095 Hbd := High_Bound (Indx);
14097 else
14098 Indx_Typ := Etype (Indx);
14100 if Is_Private_Type (Indx_Typ) then
14101 Indx_Typ := Full_View (Indx_Typ);
14102 end if;
14104 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
14105 return False;
14106 else
14107 Lbd := Type_Low_Bound (Indx_Typ);
14108 Hbd := Type_High_Bound (Indx_Typ);
14109 end if;
14110 end if;
14112 if Compile_Time_Known_Value (Lbd)
14113 and then
14114 Compile_Time_Known_Value (Hbd)
14115 then
14116 if Expr_Value (Hbd) < Expr_Value (Lbd) then
14117 return True;
14118 end if;
14119 end if;
14121 Next_Index (Indx);
14122 end loop;
14123 end;
14124 end if;
14126 -- If no null indexes, then type is not fully initialized
14128 return False;
14130 -- Record types
14132 elsif Is_Record_Type (Typ) then
14133 if Has_Discriminants (Typ)
14134 and then
14135 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
14136 and then Is_Fully_Initialized_Variant (Typ)
14137 then
14138 return True;
14139 end if;
14141 -- We consider bounded string types to be fully initialized, because
14142 -- otherwise we get false alarms when the Data component is not
14143 -- default-initialized.
14145 if Is_Bounded_String (Typ) then
14146 return True;
14147 end if;
14149 -- Controlled records are considered to be fully initialized if
14150 -- there is a user defined Initialize routine. This may not be
14151 -- entirely correct, but as the spec notes, we are guessing here
14152 -- what is best from the point of view of issuing warnings.
14154 if Is_Controlled (Typ) then
14155 declare
14156 Utyp : constant Entity_Id := Underlying_Type (Typ);
14158 begin
14159 if Present (Utyp) then
14160 declare
14161 Init : constant Entity_Id :=
14162 (Find_Optional_Prim_Op
14163 (Underlying_Type (Typ), Name_Initialize));
14165 begin
14166 if Present (Init)
14167 and then Comes_From_Source (Init)
14168 and then not In_Predefined_Unit (Init)
14169 then
14170 return True;
14172 elsif Has_Null_Extension (Typ)
14173 and then
14174 Is_Fully_Initialized_Type
14175 (Etype (Base_Type (Typ)))
14176 then
14177 return True;
14178 end if;
14179 end;
14180 end if;
14181 end;
14182 end if;
14184 -- Otherwise see if all record components are initialized
14186 declare
14187 Ent : Entity_Id;
14189 begin
14190 Ent := First_Entity (Typ);
14191 while Present (Ent) loop
14192 if Ekind (Ent) = E_Component
14193 and then (No (Parent (Ent))
14194 or else No (Expression (Parent (Ent))))
14195 and then not Is_Fully_Initialized_Type (Etype (Ent))
14197 -- Special VM case for tag components, which need to be
14198 -- defined in this case, but are never initialized as VMs
14199 -- are using other dispatching mechanisms. Ignore this
14200 -- uninitialized case. Note that this applies both to the
14201 -- uTag entry and the main vtable pointer (CPP_Class case).
14203 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
14204 then
14205 return False;
14206 end if;
14208 Next_Entity (Ent);
14209 end loop;
14210 end;
14212 -- No uninitialized components, so type is fully initialized.
14213 -- Note that this catches the case of no components as well.
14215 return True;
14217 elsif Is_Concurrent_Type (Typ) then
14218 return True;
14220 elsif Is_Private_Type (Typ) then
14221 declare
14222 U : constant Entity_Id := Underlying_Type (Typ);
14224 begin
14225 if No (U) then
14226 return False;
14227 else
14228 return Is_Fully_Initialized_Type (U);
14229 end if;
14230 end;
14232 else
14233 return False;
14234 end if;
14235 end Is_Fully_Initialized_Type;
14237 ----------------------------------
14238 -- Is_Fully_Initialized_Variant --
14239 ----------------------------------
14241 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
14242 Loc : constant Source_Ptr := Sloc (Typ);
14243 Constraints : constant List_Id := New_List;
14244 Components : constant Elist_Id := New_Elmt_List;
14245 Comp_Elmt : Elmt_Id;
14246 Comp_Id : Node_Id;
14247 Comp_List : Node_Id;
14248 Discr : Entity_Id;
14249 Discr_Val : Node_Id;
14251 Report_Errors : Boolean;
14252 pragma Warnings (Off, Report_Errors);
14254 begin
14255 if Serious_Errors_Detected > 0 then
14256 return False;
14257 end if;
14259 if Is_Record_Type (Typ)
14260 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
14261 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
14262 then
14263 Comp_List := Component_List (Type_Definition (Parent (Typ)));
14265 Discr := First_Discriminant (Typ);
14266 while Present (Discr) loop
14267 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
14268 Discr_Val := Expression (Parent (Discr));
14270 if Present (Discr_Val)
14271 and then Is_OK_Static_Expression (Discr_Val)
14272 then
14273 Append_To (Constraints,
14274 Make_Component_Association (Loc,
14275 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
14276 Expression => New_Copy (Discr_Val)));
14277 else
14278 return False;
14279 end if;
14280 else
14281 return False;
14282 end if;
14284 Next_Discriminant (Discr);
14285 end loop;
14287 Gather_Components
14288 (Typ => Typ,
14289 Comp_List => Comp_List,
14290 Governed_By => Constraints,
14291 Into => Components,
14292 Report_Errors => Report_Errors);
14294 -- Check that each component present is fully initialized
14296 Comp_Elmt := First_Elmt (Components);
14297 while Present (Comp_Elmt) loop
14298 Comp_Id := Node (Comp_Elmt);
14300 if Ekind (Comp_Id) = E_Component
14301 and then (No (Parent (Comp_Id))
14302 or else No (Expression (Parent (Comp_Id))))
14303 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
14304 then
14305 return False;
14306 end if;
14308 Next_Elmt (Comp_Elmt);
14309 end loop;
14311 return True;
14313 elsif Is_Private_Type (Typ) then
14314 declare
14315 U : constant Entity_Id := Underlying_Type (Typ);
14317 begin
14318 if No (U) then
14319 return False;
14320 else
14321 return Is_Fully_Initialized_Variant (U);
14322 end if;
14323 end;
14325 else
14326 return False;
14327 end if;
14328 end Is_Fully_Initialized_Variant;
14330 ------------------------------------
14331 -- Is_Generic_Declaration_Or_Body --
14332 ------------------------------------
14334 function Is_Generic_Declaration_Or_Body (Decl : Node_Id) return Boolean is
14335 Spec_Decl : Node_Id;
14337 begin
14338 -- Package/subprogram body
14340 if Nkind_In (Decl, N_Package_Body, N_Subprogram_Body)
14341 and then Present (Corresponding_Spec (Decl))
14342 then
14343 Spec_Decl := Unit_Declaration_Node (Corresponding_Spec (Decl));
14345 -- Package/subprogram body stub
14347 elsif Nkind_In (Decl, N_Package_Body_Stub, N_Subprogram_Body_Stub)
14348 and then Present (Corresponding_Spec_Of_Stub (Decl))
14349 then
14350 Spec_Decl :=
14351 Unit_Declaration_Node (Corresponding_Spec_Of_Stub (Decl));
14353 -- All other cases
14355 else
14356 Spec_Decl := Decl;
14357 end if;
14359 -- Rather than inspecting the defining entity of the spec declaration,
14360 -- look at its Nkind. This takes care of the case where the analysis of
14361 -- a generic body modifies the Ekind of its spec to allow for recursive
14362 -- calls.
14364 return
14365 Nkind_In (Spec_Decl, N_Generic_Package_Declaration,
14366 N_Generic_Subprogram_Declaration);
14367 end Is_Generic_Declaration_Or_Body;
14369 ----------------------------
14370 -- Is_Inherited_Operation --
14371 ----------------------------
14373 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
14374 pragma Assert (Is_Overloadable (E));
14375 Kind : constant Node_Kind := Nkind (Parent (E));
14376 begin
14377 return Kind = N_Full_Type_Declaration
14378 or else Kind = N_Private_Extension_Declaration
14379 or else Kind = N_Subtype_Declaration
14380 or else (Ekind (E) = E_Enumeration_Literal
14381 and then Is_Derived_Type (Etype (E)));
14382 end Is_Inherited_Operation;
14384 -------------------------------------
14385 -- Is_Inherited_Operation_For_Type --
14386 -------------------------------------
14388 function Is_Inherited_Operation_For_Type
14389 (E : Entity_Id;
14390 Typ : Entity_Id) return Boolean
14392 begin
14393 -- Check that the operation has been created by the type declaration
14395 return Is_Inherited_Operation (E)
14396 and then Defining_Identifier (Parent (E)) = Typ;
14397 end Is_Inherited_Operation_For_Type;
14399 --------------------------------------
14400 -- Is_Inlinable_Expression_Function --
14401 --------------------------------------
14403 function Is_Inlinable_Expression_Function
14404 (Subp : Entity_Id) return Boolean
14406 Return_Expr : Node_Id;
14408 begin
14409 if Is_Expression_Function_Or_Completion (Subp)
14410 and then Has_Pragma_Inline_Always (Subp)
14411 and then Needs_No_Actuals (Subp)
14412 and then No (Contract (Subp))
14413 and then not Is_Dispatching_Operation (Subp)
14414 and then Needs_Finalization (Etype (Subp))
14415 and then not Is_Class_Wide_Type (Etype (Subp))
14416 and then not (Has_Invariants (Etype (Subp)))
14417 and then Present (Subprogram_Body (Subp))
14418 and then Was_Expression_Function (Subprogram_Body (Subp))
14419 then
14420 Return_Expr := Expression_Of_Expression_Function (Subp);
14422 -- The returned object must not have a qualified expression and its
14423 -- nominal subtype must be statically compatible with the result
14424 -- subtype of the expression function.
14426 return
14427 Nkind (Return_Expr) = N_Identifier
14428 and then Etype (Return_Expr) = Etype (Subp);
14429 end if;
14431 return False;
14432 end Is_Inlinable_Expression_Function;
14434 -----------------
14435 -- Is_Iterator --
14436 -----------------
14438 function Is_Iterator (Typ : Entity_Id) return Boolean is
14439 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean;
14440 -- Determine whether type Iter_Typ is a predefined forward or reversible
14441 -- iterator.
14443 ----------------------
14444 -- Denotes_Iterator --
14445 ----------------------
14447 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean is
14448 begin
14449 -- Check that the name matches, and that the ultimate ancestor is in
14450 -- a predefined unit, i.e the one that declares iterator interfaces.
14452 return
14453 Nam_In (Chars (Iter_Typ), Name_Forward_Iterator,
14454 Name_Reversible_Iterator)
14455 and then In_Predefined_Unit (Root_Type (Iter_Typ));
14456 end Denotes_Iterator;
14458 -- Local variables
14460 Iface_Elmt : Elmt_Id;
14461 Ifaces : Elist_Id;
14463 -- Start of processing for Is_Iterator
14465 begin
14466 -- The type may be a subtype of a descendant of the proper instance of
14467 -- the predefined interface type, so we must use the root type of the
14468 -- given type. The same is done for Is_Reversible_Iterator.
14470 if Is_Class_Wide_Type (Typ)
14471 and then Denotes_Iterator (Root_Type (Typ))
14472 then
14473 return True;
14475 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
14476 return False;
14478 elsif Present (Find_Value_Of_Aspect (Typ, Aspect_Iterable)) then
14479 return True;
14481 else
14482 Collect_Interfaces (Typ, Ifaces);
14484 Iface_Elmt := First_Elmt (Ifaces);
14485 while Present (Iface_Elmt) loop
14486 if Denotes_Iterator (Node (Iface_Elmt)) then
14487 return True;
14488 end if;
14490 Next_Elmt (Iface_Elmt);
14491 end loop;
14493 return False;
14494 end if;
14495 end Is_Iterator;
14497 ----------------------------
14498 -- Is_Iterator_Over_Array --
14499 ----------------------------
14501 function Is_Iterator_Over_Array (N : Node_Id) return Boolean is
14502 Container : constant Node_Id := Name (N);
14503 Container_Typ : constant Entity_Id := Base_Type (Etype (Container));
14504 begin
14505 return Is_Array_Type (Container_Typ);
14506 end Is_Iterator_Over_Array;
14508 ------------
14509 -- Is_LHS --
14510 ------------
14512 -- We seem to have a lot of overlapping functions that do similar things
14513 -- (testing for left hand sides or lvalues???).
14515 function Is_LHS (N : Node_Id) return Is_LHS_Result is
14516 P : constant Node_Id := Parent (N);
14518 begin
14519 -- Return True if we are the left hand side of an assignment statement
14521 if Nkind (P) = N_Assignment_Statement then
14522 if Name (P) = N then
14523 return Yes;
14524 else
14525 return No;
14526 end if;
14528 -- Case of prefix of indexed or selected component or slice
14530 elsif Nkind_In (P, N_Indexed_Component, N_Selected_Component, N_Slice)
14531 and then N = Prefix (P)
14532 then
14533 -- Here we have the case where the parent P is N.Q or N(Q .. R).
14534 -- If P is an LHS, then N is also effectively an LHS, but there
14535 -- is an important exception. If N is of an access type, then
14536 -- what we really have is N.all.Q (or N.all(Q .. R)). In either
14537 -- case this makes N.all a left hand side but not N itself.
14539 -- If we don't know the type yet, this is the case where we return
14540 -- Unknown, since the answer depends on the type which is unknown.
14542 if No (Etype (N)) then
14543 return Unknown;
14545 -- We have an Etype set, so we can check it
14547 elsif Is_Access_Type (Etype (N)) then
14548 return No;
14550 -- OK, not access type case, so just test whole expression
14552 else
14553 return Is_LHS (P);
14554 end if;
14556 -- All other cases are not left hand sides
14558 else
14559 return No;
14560 end if;
14561 end Is_LHS;
14563 -----------------------------
14564 -- Is_Library_Level_Entity --
14565 -----------------------------
14567 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
14568 begin
14569 -- The following is a small optimization, and it also properly handles
14570 -- discriminals, which in task bodies might appear in expressions before
14571 -- the corresponding procedure has been created, and which therefore do
14572 -- not have an assigned scope.
14574 if Is_Formal (E) then
14575 return False;
14576 end if;
14578 -- Normal test is simply that the enclosing dynamic scope is Standard
14580 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
14581 end Is_Library_Level_Entity;
14583 --------------------------------
14584 -- Is_Limited_Class_Wide_Type --
14585 --------------------------------
14587 function Is_Limited_Class_Wide_Type (Typ : Entity_Id) return Boolean is
14588 begin
14589 return
14590 Is_Class_Wide_Type (Typ)
14591 and then (Is_Limited_Type (Typ) or else From_Limited_With (Typ));
14592 end Is_Limited_Class_Wide_Type;
14594 ---------------------------------
14595 -- Is_Local_Variable_Reference --
14596 ---------------------------------
14598 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
14599 begin
14600 if not Is_Entity_Name (Expr) then
14601 return False;
14603 else
14604 declare
14605 Ent : constant Entity_Id := Entity (Expr);
14606 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
14607 begin
14608 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
14609 return False;
14610 else
14611 return Present (Sub) and then Sub = Current_Subprogram;
14612 end if;
14613 end;
14614 end if;
14615 end Is_Local_Variable_Reference;
14617 -----------------------
14618 -- Is_Name_Reference --
14619 -----------------------
14621 function Is_Name_Reference (N : Node_Id) return Boolean is
14622 begin
14623 if Is_Entity_Name (N) then
14624 return Present (Entity (N)) and then Is_Object (Entity (N));
14625 end if;
14627 case Nkind (N) is
14628 when N_Indexed_Component
14629 | N_Slice
14631 return
14632 Is_Name_Reference (Prefix (N))
14633 or else Is_Access_Type (Etype (Prefix (N)));
14635 -- Attributes 'Input, 'Old and 'Result produce objects
14637 when N_Attribute_Reference =>
14638 return
14639 Nam_In (Attribute_Name (N), Name_Input, Name_Old, Name_Result);
14641 when N_Selected_Component =>
14642 return
14643 Is_Name_Reference (Selector_Name (N))
14644 and then
14645 (Is_Name_Reference (Prefix (N))
14646 or else Is_Access_Type (Etype (Prefix (N))));
14648 when N_Explicit_Dereference =>
14649 return True;
14651 -- A view conversion of a tagged name is a name reference
14653 when N_Type_Conversion =>
14654 return
14655 Is_Tagged_Type (Etype (Subtype_Mark (N)))
14656 and then Is_Tagged_Type (Etype (Expression (N)))
14657 and then Is_Name_Reference (Expression (N));
14659 -- An unchecked type conversion is considered to be a name if the
14660 -- operand is a name (this construction arises only as a result of
14661 -- expansion activities).
14663 when N_Unchecked_Type_Conversion =>
14664 return Is_Name_Reference (Expression (N));
14666 when others =>
14667 return False;
14668 end case;
14669 end Is_Name_Reference;
14671 ------------------------------------
14672 -- Is_Non_Preelaborable_Construct --
14673 ------------------------------------
14675 function Is_Non_Preelaborable_Construct (N : Node_Id) return Boolean is
14677 -- NOTE: the routines within Is_Non_Preelaborable_Construct are
14678 -- intentionally unnested to avoid deep indentation of code.
14680 Non_Preelaborable : exception;
14681 -- This exception is raised when the construct violates preelaborability
14682 -- to terminate the recursion.
14684 procedure Visit (Nod : Node_Id);
14685 -- Semantically inspect construct Nod to determine whether it violates
14686 -- preelaborability. This routine raises Non_Preelaborable.
14688 procedure Visit_List (List : List_Id);
14689 pragma Inline (Visit_List);
14690 -- Invoke Visit on each element of list List. This routine raises
14691 -- Non_Preelaborable.
14693 procedure Visit_Pragma (Prag : Node_Id);
14694 pragma Inline (Visit_Pragma);
14695 -- Semantically inspect pragma Prag to determine whether it violates
14696 -- preelaborability. This routine raises Non_Preelaborable.
14698 procedure Visit_Subexpression (Expr : Node_Id);
14699 pragma Inline (Visit_Subexpression);
14700 -- Semantically inspect expression Expr to determine whether it violates
14701 -- preelaborability. This routine raises Non_Preelaborable.
14703 -----------
14704 -- Visit --
14705 -----------
14707 procedure Visit (Nod : Node_Id) is
14708 begin
14709 case Nkind (Nod) is
14711 -- Declarations
14713 when N_Component_Declaration =>
14715 -- Defining_Identifier is left out because it is not relevant
14716 -- for preelaborability.
14718 Visit (Component_Definition (Nod));
14719 Visit (Expression (Nod));
14721 when N_Derived_Type_Definition =>
14723 -- Interface_List is left out because it is not relevant for
14724 -- preelaborability.
14726 Visit (Record_Extension_Part (Nod));
14727 Visit (Subtype_Indication (Nod));
14729 when N_Entry_Declaration =>
14731 -- A protected type with at leat one entry is not preelaborable
14732 -- while task types are never preelaborable. This renders entry
14733 -- declarations non-preelaborable.
14735 raise Non_Preelaborable;
14737 when N_Full_Type_Declaration =>
14739 -- Defining_Identifier and Discriminant_Specifications are left
14740 -- out because they are not relevant for preelaborability.
14742 Visit (Type_Definition (Nod));
14744 when N_Function_Instantiation
14745 | N_Package_Instantiation
14746 | N_Procedure_Instantiation
14748 -- Defining_Unit_Name and Name are left out because they are
14749 -- not relevant for preelaborability.
14751 Visit_List (Generic_Associations (Nod));
14753 when N_Object_Declaration =>
14755 -- Defining_Identifier is left out because it is not relevant
14756 -- for preelaborability.
14758 Visit (Object_Definition (Nod));
14760 if Has_Init_Expression (Nod) then
14761 Visit (Expression (Nod));
14763 elsif not Has_Preelaborable_Initialization
14764 (Etype (Defining_Entity (Nod)))
14765 then
14766 raise Non_Preelaborable;
14767 end if;
14769 when N_Private_Extension_Declaration
14770 | N_Subtype_Declaration
14772 -- Defining_Identifier, Discriminant_Specifications, and
14773 -- Interface_List are left out because they are not relevant
14774 -- for preelaborability.
14776 Visit (Subtype_Indication (Nod));
14778 when N_Protected_Type_Declaration
14779 | N_Single_Protected_Declaration
14781 -- Defining_Identifier, Discriminant_Specifications, and
14782 -- Interface_List are left out because they are not relevant
14783 -- for preelaborability.
14785 Visit (Protected_Definition (Nod));
14787 -- A [single] task type is never preelaborable
14789 when N_Single_Task_Declaration
14790 | N_Task_Type_Declaration
14792 raise Non_Preelaborable;
14794 -- Pragmas
14796 when N_Pragma =>
14797 Visit_Pragma (Nod);
14799 -- Statements
14801 when N_Statement_Other_Than_Procedure_Call =>
14802 if Nkind (Nod) /= N_Null_Statement then
14803 raise Non_Preelaborable;
14804 end if;
14806 -- Subexpressions
14808 when N_Subexpr =>
14809 Visit_Subexpression (Nod);
14811 -- Special
14813 when N_Access_To_Object_Definition =>
14814 Visit (Subtype_Indication (Nod));
14816 when N_Case_Expression_Alternative =>
14817 Visit (Expression (Nod));
14818 Visit_List (Discrete_Choices (Nod));
14820 when N_Component_Definition =>
14821 Visit (Access_Definition (Nod));
14822 Visit (Subtype_Indication (Nod));
14824 when N_Component_List =>
14825 Visit_List (Component_Items (Nod));
14826 Visit (Variant_Part (Nod));
14828 when N_Constrained_Array_Definition =>
14829 Visit_List (Discrete_Subtype_Definitions (Nod));
14830 Visit (Component_Definition (Nod));
14832 when N_Delta_Constraint
14833 | N_Digits_Constraint
14835 -- Delta_Expression and Digits_Expression are left out because
14836 -- they are not relevant for preelaborability.
14838 Visit (Range_Constraint (Nod));
14840 when N_Discriminant_Specification =>
14842 -- Defining_Identifier and Expression are left out because they
14843 -- are not relevant for preelaborability.
14845 Visit (Discriminant_Type (Nod));
14847 when N_Generic_Association =>
14849 -- Selector_Name is left out because it is not relevant for
14850 -- preelaborability.
14852 Visit (Explicit_Generic_Actual_Parameter (Nod));
14854 when N_Index_Or_Discriminant_Constraint =>
14855 Visit_List (Constraints (Nod));
14857 when N_Iterator_Specification =>
14859 -- Defining_Identifier is left out because it is not relevant
14860 -- for preelaborability.
14862 Visit (Name (Nod));
14863 Visit (Subtype_Indication (Nod));
14865 when N_Loop_Parameter_Specification =>
14867 -- Defining_Identifier is left out because it is not relevant
14868 -- for preelaborability.
14870 Visit (Discrete_Subtype_Definition (Nod));
14872 when N_Protected_Definition =>
14874 -- End_Label is left out because it is not relevant for
14875 -- preelaborability.
14877 Visit_List (Private_Declarations (Nod));
14878 Visit_List (Visible_Declarations (Nod));
14880 when N_Range_Constraint =>
14881 Visit (Range_Expression (Nod));
14883 when N_Record_Definition
14884 | N_Variant
14886 -- End_Label, Discrete_Choices, and Interface_List are left out
14887 -- because they are not relevant for preelaborability.
14889 Visit (Component_List (Nod));
14891 when N_Subtype_Indication =>
14893 -- Subtype_Mark is left out because it is not relevant for
14894 -- preelaborability.
14896 Visit (Constraint (Nod));
14898 when N_Unconstrained_Array_Definition =>
14900 -- Subtype_Marks is left out because it is not relevant for
14901 -- preelaborability.
14903 Visit (Component_Definition (Nod));
14905 when N_Variant_Part =>
14907 -- Name is left out because it is not relevant for
14908 -- preelaborability.
14910 Visit_List (Variants (Nod));
14912 -- Default
14914 when others =>
14915 null;
14916 end case;
14917 end Visit;
14919 ----------------
14920 -- Visit_List --
14921 ----------------
14923 procedure Visit_List (List : List_Id) is
14924 Nod : Node_Id;
14926 begin
14927 if Present (List) then
14928 Nod := First (List);
14929 while Present (Nod) loop
14930 Visit (Nod);
14931 Next (Nod);
14932 end loop;
14933 end if;
14934 end Visit_List;
14936 ------------------
14937 -- Visit_Pragma --
14938 ------------------
14940 procedure Visit_Pragma (Prag : Node_Id) is
14941 begin
14942 case Get_Pragma_Id (Prag) is
14943 when Pragma_Assert
14944 | Pragma_Assert_And_Cut
14945 | Pragma_Assume
14946 | Pragma_Async_Readers
14947 | Pragma_Async_Writers
14948 | Pragma_Attribute_Definition
14949 | Pragma_Check
14950 | Pragma_Constant_After_Elaboration
14951 | Pragma_CPU
14952 | Pragma_Deadline_Floor
14953 | Pragma_Dispatching_Domain
14954 | Pragma_Effective_Reads
14955 | Pragma_Effective_Writes
14956 | Pragma_Extensions_Visible
14957 | Pragma_Ghost
14958 | Pragma_Secondary_Stack_Size
14959 | Pragma_Task_Name
14960 | Pragma_Volatile_Function
14962 Visit_List (Pragma_Argument_Associations (Prag));
14964 -- Default
14966 when others =>
14967 null;
14968 end case;
14969 end Visit_Pragma;
14971 -------------------------
14972 -- Visit_Subexpression --
14973 -------------------------
14975 procedure Visit_Subexpression (Expr : Node_Id) is
14976 procedure Visit_Aggregate (Aggr : Node_Id);
14977 pragma Inline (Visit_Aggregate);
14978 -- Semantically inspect aggregate Aggr to determine whether it
14979 -- violates preelaborability.
14981 ---------------------
14982 -- Visit_Aggregate --
14983 ---------------------
14985 procedure Visit_Aggregate (Aggr : Node_Id) is
14986 begin
14987 if not Is_Preelaborable_Aggregate (Aggr) then
14988 raise Non_Preelaborable;
14989 end if;
14990 end Visit_Aggregate;
14992 -- Start of processing for Visit_Subexpression
14994 begin
14995 case Nkind (Expr) is
14996 when N_Allocator
14997 | N_Qualified_Expression
14998 | N_Type_Conversion
14999 | N_Unchecked_Expression
15000 | N_Unchecked_Type_Conversion
15002 -- Subpool_Handle_Name and Subtype_Mark are left out because
15003 -- they are not relevant for preelaborability.
15005 Visit (Expression (Expr));
15007 when N_Aggregate
15008 | N_Extension_Aggregate
15010 Visit_Aggregate (Expr);
15012 when N_Attribute_Reference
15013 | N_Explicit_Dereference
15014 | N_Reference
15016 -- Attribute_Name and Expressions are left out because they are
15017 -- not relevant for preelaborability.
15019 Visit (Prefix (Expr));
15021 when N_Case_Expression =>
15023 -- End_Span is left out because it is not relevant for
15024 -- preelaborability.
15026 Visit_List (Alternatives (Expr));
15027 Visit (Expression (Expr));
15029 when N_Delta_Aggregate =>
15030 Visit_Aggregate (Expr);
15031 Visit (Expression (Expr));
15033 when N_Expression_With_Actions =>
15034 Visit_List (Actions (Expr));
15035 Visit (Expression (Expr));
15037 when N_If_Expression =>
15038 Visit_List (Expressions (Expr));
15040 when N_Quantified_Expression =>
15041 Visit (Condition (Expr));
15042 Visit (Iterator_Specification (Expr));
15043 Visit (Loop_Parameter_Specification (Expr));
15045 when N_Range =>
15046 Visit (High_Bound (Expr));
15047 Visit (Low_Bound (Expr));
15049 when N_Slice =>
15050 Visit (Discrete_Range (Expr));
15051 Visit (Prefix (Expr));
15053 -- Default
15055 when others =>
15057 -- The evaluation of an object name is not preelaborable,
15058 -- unless the name is a static expression (checked further
15059 -- below), or statically denotes a discriminant.
15061 if Is_Entity_Name (Expr) then
15062 Object_Name : declare
15063 Id : constant Entity_Id := Entity (Expr);
15065 begin
15066 if Is_Object (Id) then
15067 if Ekind (Id) = E_Discriminant then
15068 null;
15070 elsif Ekind_In (Id, E_Constant, E_In_Parameter)
15071 and then Present (Discriminal_Link (Id))
15072 then
15073 null;
15075 else
15076 raise Non_Preelaborable;
15077 end if;
15078 end if;
15079 end Object_Name;
15081 -- A non-static expression is not preelaborable
15083 elsif not Is_OK_Static_Expression (Expr) then
15084 raise Non_Preelaborable;
15085 end if;
15086 end case;
15087 end Visit_Subexpression;
15089 -- Start of processing for Is_Non_Preelaborable_Construct
15091 begin
15092 Visit (N);
15094 -- At this point it is known that the construct is preelaborable
15096 return False;
15098 exception
15100 -- The elaboration of the construct performs an action which violates
15101 -- preelaborability.
15103 when Non_Preelaborable =>
15104 return True;
15105 end Is_Non_Preelaborable_Construct;
15107 ---------------------------------
15108 -- Is_Nontrivial_DIC_Procedure --
15109 ---------------------------------
15111 function Is_Nontrivial_DIC_Procedure (Id : Entity_Id) return Boolean is
15112 Body_Decl : Node_Id;
15113 Stmt : Node_Id;
15115 begin
15116 if Ekind (Id) = E_Procedure and then Is_DIC_Procedure (Id) then
15117 Body_Decl :=
15118 Unit_Declaration_Node
15119 (Corresponding_Body (Unit_Declaration_Node (Id)));
15121 -- The body of the Default_Initial_Condition procedure must contain
15122 -- at least one statement, otherwise the generation of the subprogram
15123 -- body failed.
15125 pragma Assert (Present (Handled_Statement_Sequence (Body_Decl)));
15127 -- To qualify as nontrivial, the first statement of the procedure
15128 -- must be a check in the form of an if statement. If the original
15129 -- Default_Initial_Condition expression was folded, then the first
15130 -- statement is not a check.
15132 Stmt := First (Statements (Handled_Statement_Sequence (Body_Decl)));
15134 return
15135 Nkind (Stmt) = N_If_Statement
15136 and then Nkind (Original_Node (Stmt)) = N_Pragma;
15137 end if;
15139 return False;
15140 end Is_Nontrivial_DIC_Procedure;
15142 -------------------------
15143 -- Is_Null_Record_Type --
15144 -------------------------
15146 function Is_Null_Record_Type (T : Entity_Id) return Boolean is
15147 Decl : constant Node_Id := Parent (T);
15148 begin
15149 return Nkind (Decl) = N_Full_Type_Declaration
15150 and then Nkind (Type_Definition (Decl)) = N_Record_Definition
15151 and then
15152 (No (Component_List (Type_Definition (Decl)))
15153 or else Null_Present (Component_List (Type_Definition (Decl))));
15154 end Is_Null_Record_Type;
15156 ---------------------
15157 -- Is_Object_Image --
15158 ---------------------
15160 function Is_Object_Image (Prefix : Node_Id) return Boolean is
15161 begin
15162 -- When the type of the prefix is not scalar, then the prefix is not
15163 -- valid in any scenario.
15165 if not Is_Scalar_Type (Etype (Prefix)) then
15166 return False;
15167 end if;
15169 -- Here we test for the case that the prefix is not a type and assume
15170 -- if it is not then it must be a named value or an object reference.
15171 -- This is because the parser always checks that prefixes of attributes
15172 -- are named.
15174 return not (Is_Entity_Name (Prefix) and then Is_Type (Entity (Prefix)));
15175 end Is_Object_Image;
15177 -------------------------
15178 -- Is_Object_Reference --
15179 -------------------------
15181 function Is_Object_Reference (N : Node_Id) return Boolean is
15182 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean;
15183 -- Determine whether N is the name of an internally-generated renaming
15185 --------------------------------------
15186 -- Is_Internally_Generated_Renaming --
15187 --------------------------------------
15189 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean is
15190 P : Node_Id;
15192 begin
15193 P := N;
15194 while Present (P) loop
15195 if Nkind (P) = N_Object_Renaming_Declaration then
15196 return not Comes_From_Source (P);
15197 elsif Is_List_Member (P) then
15198 return False;
15199 end if;
15201 P := Parent (P);
15202 end loop;
15204 return False;
15205 end Is_Internally_Generated_Renaming;
15207 -- Start of processing for Is_Object_Reference
15209 begin
15210 if Is_Entity_Name (N) then
15211 return Present (Entity (N)) and then Is_Object (Entity (N));
15213 else
15214 case Nkind (N) is
15215 when N_Indexed_Component
15216 | N_Slice
15218 return
15219 Is_Object_Reference (Prefix (N))
15220 or else Is_Access_Type (Etype (Prefix (N)));
15222 -- In Ada 95, a function call is a constant object; a procedure
15223 -- call is not.
15225 -- Note that predefined operators are functions as well, and so
15226 -- are attributes that are (can be renamed as) functions.
15228 when N_Binary_Op
15229 | N_Function_Call
15230 | N_Unary_Op
15232 return Etype (N) /= Standard_Void_Type;
15234 -- Attributes references 'Loop_Entry, 'Old, and 'Result yield
15235 -- objects, even though they are not functions.
15237 when N_Attribute_Reference =>
15238 return
15239 Nam_In (Attribute_Name (N), Name_Loop_Entry,
15240 Name_Old,
15241 Name_Result)
15242 or else Is_Function_Attribute_Name (Attribute_Name (N));
15244 when N_Selected_Component =>
15245 return
15246 Is_Object_Reference (Selector_Name (N))
15247 and then
15248 (Is_Object_Reference (Prefix (N))
15249 or else Is_Access_Type (Etype (Prefix (N))));
15251 -- An explicit dereference denotes an object, except that a
15252 -- conditional expression gets turned into an explicit dereference
15253 -- in some cases, and conditional expressions are not object
15254 -- names.
15256 when N_Explicit_Dereference =>
15257 return not Nkind_In (Original_Node (N), N_Case_Expression,
15258 N_If_Expression);
15260 -- A view conversion of a tagged object is an object reference
15262 when N_Type_Conversion =>
15263 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
15264 and then Is_Tagged_Type (Etype (Expression (N)))
15265 and then Is_Object_Reference (Expression (N));
15267 -- An unchecked type conversion is considered to be an object if
15268 -- the operand is an object (this construction arises only as a
15269 -- result of expansion activities).
15271 when N_Unchecked_Type_Conversion =>
15272 return True;
15274 -- Allow string literals to act as objects as long as they appear
15275 -- in internally-generated renamings. The expansion of iterators
15276 -- may generate such renamings when the range involves a string
15277 -- literal.
15279 when N_String_Literal =>
15280 return Is_Internally_Generated_Renaming (Parent (N));
15282 -- AI05-0003: In Ada 2012 a qualified expression is a name.
15283 -- This allows disambiguation of function calls and the use
15284 -- of aggregates in more contexts.
15286 when N_Qualified_Expression =>
15287 if Ada_Version < Ada_2012 then
15288 return False;
15289 else
15290 return Is_Object_Reference (Expression (N))
15291 or else Nkind (Expression (N)) = N_Aggregate;
15292 end if;
15294 when others =>
15295 return False;
15296 end case;
15297 end if;
15298 end Is_Object_Reference;
15300 -----------------------------------
15301 -- Is_OK_Variable_For_Out_Formal --
15302 -----------------------------------
15304 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
15305 begin
15306 Note_Possible_Modification (AV, Sure => True);
15308 -- We must reject parenthesized variable names. Comes_From_Source is
15309 -- checked because there are currently cases where the compiler violates
15310 -- this rule (e.g. passing a task object to its controlled Initialize
15311 -- routine). This should be properly documented in sinfo???
15313 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
15314 return False;
15316 -- A variable is always allowed
15318 elsif Is_Variable (AV) then
15319 return True;
15321 -- Generalized indexing operations are rewritten as explicit
15322 -- dereferences, and it is only during resolution that we can
15323 -- check whether the context requires an access_to_variable type.
15325 elsif Nkind (AV) = N_Explicit_Dereference
15326 and then Ada_Version >= Ada_2012
15327 and then Nkind (Original_Node (AV)) = N_Indexed_Component
15328 and then Present (Etype (Original_Node (AV)))
15329 and then Has_Implicit_Dereference (Etype (Original_Node (AV)))
15330 then
15331 return not Is_Access_Constant (Etype (Prefix (AV)));
15333 -- Unchecked conversions are allowed only if they come from the
15334 -- generated code, which sometimes uses unchecked conversions for out
15335 -- parameters in cases where code generation is unaffected. We tell
15336 -- source unchecked conversions by seeing if they are rewrites of
15337 -- an original Unchecked_Conversion function call, or of an explicit
15338 -- conversion of a function call or an aggregate (as may happen in the
15339 -- expansion of a packed array aggregate).
15341 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
15342 if Nkind_In (Original_Node (AV), N_Function_Call, N_Aggregate) then
15343 return False;
15345 elsif Comes_From_Source (AV)
15346 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
15347 then
15348 return False;
15350 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
15351 return Is_OK_Variable_For_Out_Formal (Expression (AV));
15353 else
15354 return True;
15355 end if;
15357 -- Normal type conversions are allowed if argument is a variable
15359 elsif Nkind (AV) = N_Type_Conversion then
15360 if Is_Variable (Expression (AV))
15361 and then Paren_Count (Expression (AV)) = 0
15362 then
15363 Note_Possible_Modification (Expression (AV), Sure => True);
15364 return True;
15366 -- We also allow a non-parenthesized expression that raises
15367 -- constraint error if it rewrites what used to be a variable
15369 elsif Raises_Constraint_Error (Expression (AV))
15370 and then Paren_Count (Expression (AV)) = 0
15371 and then Is_Variable (Original_Node (Expression (AV)))
15372 then
15373 return True;
15375 -- Type conversion of something other than a variable
15377 else
15378 return False;
15379 end if;
15381 -- If this node is rewritten, then test the original form, if that is
15382 -- OK, then we consider the rewritten node OK (for example, if the
15383 -- original node is a conversion, then Is_Variable will not be true
15384 -- but we still want to allow the conversion if it converts a variable).
15386 elsif Original_Node (AV) /= AV then
15388 -- In Ada 2012, the explicit dereference may be a rewritten call to a
15389 -- Reference function.
15391 if Ada_Version >= Ada_2012
15392 and then Nkind (Original_Node (AV)) = N_Function_Call
15393 and then
15394 Has_Implicit_Dereference (Etype (Name (Original_Node (AV))))
15395 then
15397 -- Check that this is not a constant reference.
15399 return not Is_Access_Constant (Etype (Prefix (AV)));
15401 elsif Has_Implicit_Dereference (Etype (Original_Node (AV))) then
15402 return
15403 not Is_Access_Constant (Etype
15404 (Get_Reference_Discriminant (Etype (Original_Node (AV)))));
15406 else
15407 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
15408 end if;
15410 -- All other non-variables are rejected
15412 else
15413 return False;
15414 end if;
15415 end Is_OK_Variable_For_Out_Formal;
15417 ----------------------------
15418 -- Is_OK_Volatile_Context --
15419 ----------------------------
15421 function Is_OK_Volatile_Context
15422 (Context : Node_Id;
15423 Obj_Ref : Node_Id) return Boolean
15425 function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean;
15426 -- Determine whether an arbitrary node denotes a call to a protected
15427 -- entry, function, or procedure in prefixed form where the prefix is
15428 -- Obj_Ref.
15430 function Within_Check (Nod : Node_Id) return Boolean;
15431 -- Determine whether an arbitrary node appears in a check node
15433 function Within_Volatile_Function (Id : Entity_Id) return Boolean;
15434 -- Determine whether an arbitrary entity appears in a volatile function
15436 ---------------------------------
15437 -- Is_Protected_Operation_Call --
15438 ---------------------------------
15440 function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean is
15441 Pref : Node_Id;
15442 Subp : Node_Id;
15444 begin
15445 -- A call to a protected operations retains its selected component
15446 -- form as opposed to other prefixed calls that are transformed in
15447 -- expanded names.
15449 if Nkind (Nod) = N_Selected_Component then
15450 Pref := Prefix (Nod);
15451 Subp := Selector_Name (Nod);
15453 return
15454 Pref = Obj_Ref
15455 and then Present (Etype (Pref))
15456 and then Is_Protected_Type (Etype (Pref))
15457 and then Is_Entity_Name (Subp)
15458 and then Present (Entity (Subp))
15459 and then Ekind_In (Entity (Subp), E_Entry,
15460 E_Entry_Family,
15461 E_Function,
15462 E_Procedure);
15463 else
15464 return False;
15465 end if;
15466 end Is_Protected_Operation_Call;
15468 ------------------
15469 -- Within_Check --
15470 ------------------
15472 function Within_Check (Nod : Node_Id) return Boolean is
15473 Par : Node_Id;
15475 begin
15476 -- Climb the parent chain looking for a check node
15478 Par := Nod;
15479 while Present (Par) loop
15480 if Nkind (Par) in N_Raise_xxx_Error then
15481 return True;
15483 -- Prevent the search from going too far
15485 elsif Is_Body_Or_Package_Declaration (Par) then
15486 exit;
15487 end if;
15489 Par := Parent (Par);
15490 end loop;
15492 return False;
15493 end Within_Check;
15495 ------------------------------
15496 -- Within_Volatile_Function --
15497 ------------------------------
15499 function Within_Volatile_Function (Id : Entity_Id) return Boolean is
15500 Func_Id : Entity_Id;
15502 begin
15503 -- Traverse the scope stack looking for a [generic] function
15505 Func_Id := Id;
15506 while Present (Func_Id) and then Func_Id /= Standard_Standard loop
15507 if Ekind_In (Func_Id, E_Function, E_Generic_Function) then
15508 return Is_Volatile_Function (Func_Id);
15509 end if;
15511 Func_Id := Scope (Func_Id);
15512 end loop;
15514 return False;
15515 end Within_Volatile_Function;
15517 -- Local variables
15519 Obj_Id : Entity_Id;
15521 -- Start of processing for Is_OK_Volatile_Context
15523 begin
15524 -- The volatile object appears on either side of an assignment
15526 if Nkind (Context) = N_Assignment_Statement then
15527 return True;
15529 -- The volatile object is part of the initialization expression of
15530 -- another object.
15532 elsif Nkind (Context) = N_Object_Declaration
15533 and then Present (Expression (Context))
15534 and then Expression (Context) = Obj_Ref
15535 then
15536 Obj_Id := Defining_Entity (Context);
15538 -- The volatile object acts as the initialization expression of an
15539 -- extended return statement. This is valid context as long as the
15540 -- function is volatile.
15542 if Is_Return_Object (Obj_Id) then
15543 return Within_Volatile_Function (Obj_Id);
15545 -- Otherwise this is a normal object initialization
15547 else
15548 return True;
15549 end if;
15551 -- The volatile object acts as the name of a renaming declaration
15553 elsif Nkind (Context) = N_Object_Renaming_Declaration
15554 and then Name (Context) = Obj_Ref
15555 then
15556 return True;
15558 -- The volatile object appears as an actual parameter in a call to an
15559 -- instance of Unchecked_Conversion whose result is renamed.
15561 elsif Nkind (Context) = N_Function_Call
15562 and then Is_Entity_Name (Name (Context))
15563 and then Is_Unchecked_Conversion_Instance (Entity (Name (Context)))
15564 and then Nkind (Parent (Context)) = N_Object_Renaming_Declaration
15565 then
15566 return True;
15568 -- The volatile object is actually the prefix in a protected entry,
15569 -- function, or procedure call.
15571 elsif Is_Protected_Operation_Call (Context) then
15572 return True;
15574 -- The volatile object appears as the expression of a simple return
15575 -- statement that applies to a volatile function.
15577 elsif Nkind (Context) = N_Simple_Return_Statement
15578 and then Expression (Context) = Obj_Ref
15579 then
15580 return
15581 Within_Volatile_Function (Return_Statement_Entity (Context));
15583 -- The volatile object appears as the prefix of a name occurring in a
15584 -- non-interfering context.
15586 elsif Nkind_In (Context, N_Attribute_Reference,
15587 N_Explicit_Dereference,
15588 N_Indexed_Component,
15589 N_Selected_Component,
15590 N_Slice)
15591 and then Prefix (Context) = Obj_Ref
15592 and then Is_OK_Volatile_Context
15593 (Context => Parent (Context),
15594 Obj_Ref => Context)
15595 then
15596 return True;
15598 -- The volatile object appears as the prefix of attributes Address,
15599 -- Alignment, Component_Size, First_Bit, Last_Bit, Position, Size,
15600 -- Storage_Size.
15602 elsif Nkind (Context) = N_Attribute_Reference
15603 and then Prefix (Context) = Obj_Ref
15604 and then Nam_In (Attribute_Name (Context), Name_Address,
15605 Name_Alignment,
15606 Name_Component_Size,
15607 Name_First_Bit,
15608 Name_Last_Bit,
15609 Name_Position,
15610 Name_Size,
15611 Name_Storage_Size)
15612 then
15613 return True;
15615 -- The volatile object appears as the expression of a type conversion
15616 -- occurring in a non-interfering context.
15618 elsif Nkind_In (Context, N_Type_Conversion,
15619 N_Unchecked_Type_Conversion)
15620 and then Expression (Context) = Obj_Ref
15621 and then Is_OK_Volatile_Context
15622 (Context => Parent (Context),
15623 Obj_Ref => Context)
15624 then
15625 return True;
15627 -- The volatile object appears as the expression in a delay statement
15629 elsif Nkind (Context) in N_Delay_Statement then
15630 return True;
15632 -- Allow references to volatile objects in various checks. This is not a
15633 -- direct SPARK 2014 requirement.
15635 elsif Within_Check (Context) then
15636 return True;
15638 -- Assume that references to effectively volatile objects that appear
15639 -- as actual parameters in a subprogram call are always legal. A full
15640 -- legality check is done when the actuals are resolved (see routine
15641 -- Resolve_Actuals).
15643 elsif Within_Subprogram_Call (Context) then
15644 return True;
15646 -- Otherwise the context is not suitable for an effectively volatile
15647 -- object.
15649 else
15650 return False;
15651 end if;
15652 end Is_OK_Volatile_Context;
15654 ------------------------------------
15655 -- Is_Package_Contract_Annotation --
15656 ------------------------------------
15658 function Is_Package_Contract_Annotation (Item : Node_Id) return Boolean is
15659 Nam : Name_Id;
15661 begin
15662 if Nkind (Item) = N_Aspect_Specification then
15663 Nam := Chars (Identifier (Item));
15665 else pragma Assert (Nkind (Item) = N_Pragma);
15666 Nam := Pragma_Name (Item);
15667 end if;
15669 return Nam = Name_Abstract_State
15670 or else Nam = Name_Initial_Condition
15671 or else Nam = Name_Initializes
15672 or else Nam = Name_Refined_State;
15673 end Is_Package_Contract_Annotation;
15675 -----------------------------------
15676 -- Is_Partially_Initialized_Type --
15677 -----------------------------------
15679 function Is_Partially_Initialized_Type
15680 (Typ : Entity_Id;
15681 Include_Implicit : Boolean := True) return Boolean
15683 begin
15684 if Is_Scalar_Type (Typ) then
15685 return False;
15687 elsif Is_Access_Type (Typ) then
15688 return Include_Implicit;
15690 elsif Is_Array_Type (Typ) then
15692 -- If component type is partially initialized, so is array type
15694 if Is_Partially_Initialized_Type
15695 (Component_Type (Typ), Include_Implicit)
15696 then
15697 return True;
15699 -- Otherwise we are only partially initialized if we are fully
15700 -- initialized (this is the empty array case, no point in us
15701 -- duplicating that code here).
15703 else
15704 return Is_Fully_Initialized_Type (Typ);
15705 end if;
15707 elsif Is_Record_Type (Typ) then
15709 -- A discriminated type is always partially initialized if in
15710 -- all mode
15712 if Has_Discriminants (Typ) and then Include_Implicit then
15713 return True;
15715 -- A tagged type is always partially initialized
15717 elsif Is_Tagged_Type (Typ) then
15718 return True;
15720 -- Case of non-discriminated record
15722 else
15723 declare
15724 Ent : Entity_Id;
15726 Component_Present : Boolean := False;
15727 -- Set True if at least one component is present. If no
15728 -- components are present, then record type is fully
15729 -- initialized (another odd case, like the null array).
15731 begin
15732 -- Loop through components
15734 Ent := First_Entity (Typ);
15735 while Present (Ent) loop
15736 if Ekind (Ent) = E_Component then
15737 Component_Present := True;
15739 -- If a component has an initialization expression then
15740 -- the enclosing record type is partially initialized
15742 if Present (Parent (Ent))
15743 and then Present (Expression (Parent (Ent)))
15744 then
15745 return True;
15747 -- If a component is of a type which is itself partially
15748 -- initialized, then the enclosing record type is also.
15750 elsif Is_Partially_Initialized_Type
15751 (Etype (Ent), Include_Implicit)
15752 then
15753 return True;
15754 end if;
15755 end if;
15757 Next_Entity (Ent);
15758 end loop;
15760 -- No initialized components found. If we found any components
15761 -- they were all uninitialized so the result is false.
15763 if Component_Present then
15764 return False;
15766 -- But if we found no components, then all the components are
15767 -- initialized so we consider the type to be initialized.
15769 else
15770 return True;
15771 end if;
15772 end;
15773 end if;
15775 -- Concurrent types are always fully initialized
15777 elsif Is_Concurrent_Type (Typ) then
15778 return True;
15780 -- For a private type, go to underlying type. If there is no underlying
15781 -- type then just assume this partially initialized. Not clear if this
15782 -- can happen in a non-error case, but no harm in testing for this.
15784 elsif Is_Private_Type (Typ) then
15785 declare
15786 U : constant Entity_Id := Underlying_Type (Typ);
15787 begin
15788 if No (U) then
15789 return True;
15790 else
15791 return Is_Partially_Initialized_Type (U, Include_Implicit);
15792 end if;
15793 end;
15795 -- For any other type (are there any?) assume partially initialized
15797 else
15798 return True;
15799 end if;
15800 end Is_Partially_Initialized_Type;
15802 ------------------------------------
15803 -- Is_Potentially_Persistent_Type --
15804 ------------------------------------
15806 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
15807 Comp : Entity_Id;
15808 Indx : Node_Id;
15810 begin
15811 -- For private type, test corresponding full type
15813 if Is_Private_Type (T) then
15814 return Is_Potentially_Persistent_Type (Full_View (T));
15816 -- Scalar types are potentially persistent
15818 elsif Is_Scalar_Type (T) then
15819 return True;
15821 -- Record type is potentially persistent if not tagged and the types of
15822 -- all it components are potentially persistent, and no component has
15823 -- an initialization expression.
15825 elsif Is_Record_Type (T)
15826 and then not Is_Tagged_Type (T)
15827 and then not Is_Partially_Initialized_Type (T)
15828 then
15829 Comp := First_Component (T);
15830 while Present (Comp) loop
15831 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
15832 return False;
15833 else
15834 Next_Entity (Comp);
15835 end if;
15836 end loop;
15838 return True;
15840 -- Array type is potentially persistent if its component type is
15841 -- potentially persistent and if all its constraints are static.
15843 elsif Is_Array_Type (T) then
15844 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
15845 return False;
15846 end if;
15848 Indx := First_Index (T);
15849 while Present (Indx) loop
15850 if not Is_OK_Static_Subtype (Etype (Indx)) then
15851 return False;
15852 else
15853 Next_Index (Indx);
15854 end if;
15855 end loop;
15857 return True;
15859 -- All other types are not potentially persistent
15861 else
15862 return False;
15863 end if;
15864 end Is_Potentially_Persistent_Type;
15866 --------------------------------
15867 -- Is_Potentially_Unevaluated --
15868 --------------------------------
15870 function Is_Potentially_Unevaluated (N : Node_Id) return Boolean is
15871 Par : Node_Id;
15872 Expr : Node_Id;
15874 begin
15875 Expr := N;
15876 Par := N;
15878 -- A postcondition whose expression is a short-circuit is broken down
15879 -- into individual aspects for better exception reporting. The original
15880 -- short-circuit expression is rewritten as the second operand, and an
15881 -- occurrence of 'Old in that operand is potentially unevaluated.
15882 -- See sem_ch13.adb for details of this transformation. The reference
15883 -- to 'Old may appear within an expression, so we must look for the
15884 -- enclosing pragma argument in the tree that contains the reference.
15886 while Present (Par)
15887 and then Nkind (Par) /= N_Pragma_Argument_Association
15888 loop
15889 if Nkind (Original_Node (Par)) = N_And_Then then
15890 return True;
15891 end if;
15893 Par := Parent (Par);
15894 end loop;
15896 -- Other cases; 'Old appears within other expression (not the top-level
15897 -- conjunct in a postcondition) with a potentially unevaluated operand.
15899 Par := Parent (Expr);
15900 while not Nkind_In (Par, N_And_Then,
15901 N_Case_Expression,
15902 N_If_Expression,
15903 N_In,
15904 N_Not_In,
15905 N_Or_Else,
15906 N_Quantified_Expression)
15907 loop
15908 Expr := Par;
15909 Par := Parent (Par);
15911 -- If the context is not an expression, or if is the result of
15912 -- expansion of an enclosing construct (such as another attribute)
15913 -- the predicate does not apply.
15915 if Nkind (Par) = N_Case_Expression_Alternative then
15916 null;
15918 elsif Nkind (Par) not in N_Subexpr
15919 or else not Comes_From_Source (Par)
15920 then
15921 return False;
15922 end if;
15923 end loop;
15925 if Nkind (Par) = N_If_Expression then
15926 return Is_Elsif (Par) or else Expr /= First (Expressions (Par));
15928 elsif Nkind (Par) = N_Case_Expression then
15929 return Expr /= Expression (Par);
15931 elsif Nkind_In (Par, N_And_Then, N_Or_Else) then
15932 return Expr = Right_Opnd (Par);
15934 elsif Nkind_In (Par, N_In, N_Not_In) then
15936 -- If the membership includes several alternatives, only the first is
15937 -- definitely evaluated.
15939 if Present (Alternatives (Par)) then
15940 return Expr /= First (Alternatives (Par));
15942 -- If this is a range membership both bounds are evaluated
15944 else
15945 return False;
15946 end if;
15948 elsif Nkind (Par) = N_Quantified_Expression then
15949 return Expr = Condition (Par);
15951 else
15952 return False;
15953 end if;
15954 end Is_Potentially_Unevaluated;
15956 --------------------------------
15957 -- Is_Preelaborable_Aggregate --
15958 --------------------------------
15960 function Is_Preelaborable_Aggregate (Aggr : Node_Id) return Boolean is
15961 Aggr_Typ : constant Entity_Id := Etype (Aggr);
15962 Array_Aggr : constant Boolean := Is_Array_Type (Aggr_Typ);
15964 Anc_Part : Node_Id;
15965 Assoc : Node_Id;
15966 Choice : Node_Id;
15967 Comp_Typ : Entity_Id := Empty; -- init to avoid warning
15968 Expr : Node_Id;
15970 begin
15971 if Array_Aggr then
15972 Comp_Typ := Component_Type (Aggr_Typ);
15973 end if;
15975 -- Inspect the ancestor part
15977 if Nkind (Aggr) = N_Extension_Aggregate then
15978 Anc_Part := Ancestor_Part (Aggr);
15980 -- The ancestor denotes a subtype mark
15982 if Is_Entity_Name (Anc_Part)
15983 and then Is_Type (Entity (Anc_Part))
15984 then
15985 if not Has_Preelaborable_Initialization (Entity (Anc_Part)) then
15986 return False;
15987 end if;
15989 -- Otherwise the ancestor denotes an expression
15991 elsif not Is_Preelaborable_Construct (Anc_Part) then
15992 return False;
15993 end if;
15994 end if;
15996 -- Inspect the positional associations
15998 Expr := First (Expressions (Aggr));
15999 while Present (Expr) loop
16000 if not Is_Preelaborable_Construct (Expr) then
16001 return False;
16002 end if;
16004 Next (Expr);
16005 end loop;
16007 -- Inspect the named associations
16009 Assoc := First (Component_Associations (Aggr));
16010 while Present (Assoc) loop
16012 -- Inspect the choices of the current named association
16014 Choice := First (Choices (Assoc));
16015 while Present (Choice) loop
16016 if Array_Aggr then
16018 -- For a choice to be preelaborable, it must denote either a
16019 -- static range or a static expression.
16021 if Nkind (Choice) = N_Others_Choice then
16022 null;
16024 elsif Nkind (Choice) = N_Range then
16025 if not Is_OK_Static_Range (Choice) then
16026 return False;
16027 end if;
16029 elsif not Is_OK_Static_Expression (Choice) then
16030 return False;
16031 end if;
16033 else
16034 Comp_Typ := Etype (Choice);
16035 end if;
16037 Next (Choice);
16038 end loop;
16040 -- The type of the choice must have preelaborable initialization if
16041 -- the association carries a <>.
16043 pragma Assert (Present (Comp_Typ));
16044 if Box_Present (Assoc) then
16045 if not Has_Preelaborable_Initialization (Comp_Typ) then
16046 return False;
16047 end if;
16049 -- The type of the expression must have preelaborable initialization
16051 elsif not Is_Preelaborable_Construct (Expression (Assoc)) then
16052 return False;
16053 end if;
16055 Next (Assoc);
16056 end loop;
16058 -- At this point the aggregate is preelaborable
16060 return True;
16061 end Is_Preelaborable_Aggregate;
16063 --------------------------------
16064 -- Is_Preelaborable_Construct --
16065 --------------------------------
16067 function Is_Preelaborable_Construct (N : Node_Id) return Boolean is
16068 begin
16069 -- Aggregates
16071 if Nkind_In (N, N_Aggregate, N_Extension_Aggregate) then
16072 return Is_Preelaborable_Aggregate (N);
16074 -- Attributes are allowed in general, even if their prefix is a formal
16075 -- type. It seems that certain attributes known not to be static might
16076 -- not be allowed, but there are no rules to prevent them.
16078 elsif Nkind (N) = N_Attribute_Reference then
16079 return True;
16081 -- Expressions
16083 elsif Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then
16084 return True;
16086 elsif Nkind (N) = N_Qualified_Expression then
16087 return Is_Preelaborable_Construct (Expression (N));
16089 -- Names are preelaborable when they denote a discriminant of an
16090 -- enclosing type. Discriminals are also considered for this check.
16092 elsif Is_Entity_Name (N)
16093 and then Present (Entity (N))
16094 and then
16095 (Ekind (Entity (N)) = E_Discriminant
16096 or else (Ekind_In (Entity (N), E_Constant, E_In_Parameter)
16097 and then Present (Discriminal_Link (Entity (N)))))
16098 then
16099 return True;
16101 -- Statements
16103 elsif Nkind (N) = N_Null then
16104 return True;
16106 -- Otherwise the construct is not preelaborable
16108 else
16109 return False;
16110 end if;
16111 end Is_Preelaborable_Construct;
16113 ---------------------------------
16114 -- Is_Protected_Self_Reference --
16115 ---------------------------------
16117 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
16119 function In_Access_Definition (N : Node_Id) return Boolean;
16120 -- Returns true if N belongs to an access definition
16122 --------------------------
16123 -- In_Access_Definition --
16124 --------------------------
16126 function In_Access_Definition (N : Node_Id) return Boolean is
16127 P : Node_Id;
16129 begin
16130 P := Parent (N);
16131 while Present (P) loop
16132 if Nkind (P) = N_Access_Definition then
16133 return True;
16134 end if;
16136 P := Parent (P);
16137 end loop;
16139 return False;
16140 end In_Access_Definition;
16142 -- Start of processing for Is_Protected_Self_Reference
16144 begin
16145 -- Verify that prefix is analyzed and has the proper form. Note that
16146 -- the attributes Elab_Spec, Elab_Body, and Elab_Subp_Body, which also
16147 -- produce the address of an entity, do not analyze their prefix
16148 -- because they denote entities that are not necessarily visible.
16149 -- Neither of them can apply to a protected type.
16151 return Ada_Version >= Ada_2005
16152 and then Is_Entity_Name (N)
16153 and then Present (Entity (N))
16154 and then Is_Protected_Type (Entity (N))
16155 and then In_Open_Scopes (Entity (N))
16156 and then not In_Access_Definition (N);
16157 end Is_Protected_Self_Reference;
16159 -----------------------------
16160 -- Is_RCI_Pkg_Spec_Or_Body --
16161 -----------------------------
16163 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
16165 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
16166 -- Return True if the unit of Cunit is an RCI package declaration
16168 ---------------------------
16169 -- Is_RCI_Pkg_Decl_Cunit --
16170 ---------------------------
16172 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
16173 The_Unit : constant Node_Id := Unit (Cunit);
16175 begin
16176 if Nkind (The_Unit) /= N_Package_Declaration then
16177 return False;
16178 end if;
16180 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
16181 end Is_RCI_Pkg_Decl_Cunit;
16183 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
16185 begin
16186 return Is_RCI_Pkg_Decl_Cunit (Cunit)
16187 or else
16188 (Nkind (Unit (Cunit)) = N_Package_Body
16189 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
16190 end Is_RCI_Pkg_Spec_Or_Body;
16192 -----------------------------------------
16193 -- Is_Remote_Access_To_Class_Wide_Type --
16194 -----------------------------------------
16196 function Is_Remote_Access_To_Class_Wide_Type
16197 (E : Entity_Id) return Boolean
16199 begin
16200 -- A remote access to class-wide type is a general access to object type
16201 -- declared in the visible part of a Remote_Types or Remote_Call_
16202 -- Interface unit.
16204 return Ekind (E) = E_General_Access_Type
16205 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
16206 end Is_Remote_Access_To_Class_Wide_Type;
16208 -----------------------------------------
16209 -- Is_Remote_Access_To_Subprogram_Type --
16210 -----------------------------------------
16212 function Is_Remote_Access_To_Subprogram_Type
16213 (E : Entity_Id) return Boolean
16215 begin
16216 return (Ekind (E) = E_Access_Subprogram_Type
16217 or else (Ekind (E) = E_Record_Type
16218 and then Present (Corresponding_Remote_Type (E))))
16219 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
16220 end Is_Remote_Access_To_Subprogram_Type;
16222 --------------------
16223 -- Is_Remote_Call --
16224 --------------------
16226 function Is_Remote_Call (N : Node_Id) return Boolean is
16227 begin
16228 if Nkind (N) not in N_Subprogram_Call then
16230 -- An entry call cannot be remote
16232 return False;
16234 elsif Nkind (Name (N)) in N_Has_Entity
16235 and then Is_Remote_Call_Interface (Entity (Name (N)))
16236 then
16237 -- A subprogram declared in the spec of a RCI package is remote
16239 return True;
16241 elsif Nkind (Name (N)) = N_Explicit_Dereference
16242 and then Is_Remote_Access_To_Subprogram_Type
16243 (Etype (Prefix (Name (N))))
16244 then
16245 -- The dereference of a RAS is a remote call
16247 return True;
16249 elsif Present (Controlling_Argument (N))
16250 and then Is_Remote_Access_To_Class_Wide_Type
16251 (Etype (Controlling_Argument (N)))
16252 then
16253 -- Any primitive operation call with a controlling argument of
16254 -- a RACW type is a remote call.
16256 return True;
16257 end if;
16259 -- All other calls are local calls
16261 return False;
16262 end Is_Remote_Call;
16264 ----------------------
16265 -- Is_Renamed_Entry --
16266 ----------------------
16268 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
16269 Orig_Node : Node_Id := Empty;
16270 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
16272 function Is_Entry (Nam : Node_Id) return Boolean;
16273 -- Determine whether Nam is an entry. Traverse selectors if there are
16274 -- nested selected components.
16276 --------------
16277 -- Is_Entry --
16278 --------------
16280 function Is_Entry (Nam : Node_Id) return Boolean is
16281 begin
16282 if Nkind (Nam) = N_Selected_Component then
16283 return Is_Entry (Selector_Name (Nam));
16284 end if;
16286 return Ekind (Entity (Nam)) = E_Entry;
16287 end Is_Entry;
16289 -- Start of processing for Is_Renamed_Entry
16291 begin
16292 if Present (Alias (Proc_Nam)) then
16293 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
16294 end if;
16296 -- Look for a rewritten subprogram renaming declaration
16298 if Nkind (Subp_Decl) = N_Subprogram_Declaration
16299 and then Present (Original_Node (Subp_Decl))
16300 then
16301 Orig_Node := Original_Node (Subp_Decl);
16302 end if;
16304 -- The rewritten subprogram is actually an entry
16306 if Present (Orig_Node)
16307 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
16308 and then Is_Entry (Name (Orig_Node))
16309 then
16310 return True;
16311 end if;
16313 return False;
16314 end Is_Renamed_Entry;
16316 -----------------------------
16317 -- Is_Renaming_Declaration --
16318 -----------------------------
16320 function Is_Renaming_Declaration (N : Node_Id) return Boolean is
16321 begin
16322 case Nkind (N) is
16323 when N_Exception_Renaming_Declaration
16324 | N_Generic_Function_Renaming_Declaration
16325 | N_Generic_Package_Renaming_Declaration
16326 | N_Generic_Procedure_Renaming_Declaration
16327 | N_Object_Renaming_Declaration
16328 | N_Package_Renaming_Declaration
16329 | N_Subprogram_Renaming_Declaration
16331 return True;
16333 when others =>
16334 return False;
16335 end case;
16336 end Is_Renaming_Declaration;
16338 ----------------------------
16339 -- Is_Reversible_Iterator --
16340 ----------------------------
16342 function Is_Reversible_Iterator (Typ : Entity_Id) return Boolean is
16343 Ifaces_List : Elist_Id;
16344 Iface_Elmt : Elmt_Id;
16345 Iface : Entity_Id;
16347 begin
16348 if Is_Class_Wide_Type (Typ)
16349 and then Chars (Root_Type (Typ)) = Name_Reversible_Iterator
16350 and then In_Predefined_Unit (Root_Type (Typ))
16351 then
16352 return True;
16354 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
16355 return False;
16357 else
16358 Collect_Interfaces (Typ, Ifaces_List);
16360 Iface_Elmt := First_Elmt (Ifaces_List);
16361 while Present (Iface_Elmt) loop
16362 Iface := Node (Iface_Elmt);
16363 if Chars (Iface) = Name_Reversible_Iterator
16364 and then In_Predefined_Unit (Iface)
16365 then
16366 return True;
16367 end if;
16369 Next_Elmt (Iface_Elmt);
16370 end loop;
16371 end if;
16373 return False;
16374 end Is_Reversible_Iterator;
16376 ----------------------
16377 -- Is_Selector_Name --
16378 ----------------------
16380 function Is_Selector_Name (N : Node_Id) return Boolean is
16381 begin
16382 if not Is_List_Member (N) then
16383 declare
16384 P : constant Node_Id := Parent (N);
16385 begin
16386 return Nkind_In (P, N_Expanded_Name,
16387 N_Generic_Association,
16388 N_Parameter_Association,
16389 N_Selected_Component)
16390 and then Selector_Name (P) = N;
16391 end;
16393 else
16394 declare
16395 L : constant List_Id := List_Containing (N);
16396 P : constant Node_Id := Parent (L);
16397 begin
16398 return (Nkind (P) = N_Discriminant_Association
16399 and then Selector_Names (P) = L)
16400 or else
16401 (Nkind (P) = N_Component_Association
16402 and then Choices (P) = L);
16403 end;
16404 end if;
16405 end Is_Selector_Name;
16407 ---------------------------------
16408 -- Is_Single_Concurrent_Object --
16409 ---------------------------------
16411 function Is_Single_Concurrent_Object (Id : Entity_Id) return Boolean is
16412 begin
16413 return
16414 Is_Single_Protected_Object (Id) or else Is_Single_Task_Object (Id);
16415 end Is_Single_Concurrent_Object;
16417 -------------------------------
16418 -- Is_Single_Concurrent_Type --
16419 -------------------------------
16421 function Is_Single_Concurrent_Type (Id : Entity_Id) return Boolean is
16422 begin
16423 return
16424 Ekind_In (Id, E_Protected_Type, E_Task_Type)
16425 and then Is_Single_Concurrent_Type_Declaration
16426 (Declaration_Node (Id));
16427 end Is_Single_Concurrent_Type;
16429 -------------------------------------------
16430 -- Is_Single_Concurrent_Type_Declaration --
16431 -------------------------------------------
16433 function Is_Single_Concurrent_Type_Declaration
16434 (N : Node_Id) return Boolean
16436 begin
16437 return Nkind_In (Original_Node (N), N_Single_Protected_Declaration,
16438 N_Single_Task_Declaration);
16439 end Is_Single_Concurrent_Type_Declaration;
16441 ---------------------------------------------
16442 -- Is_Single_Precision_Floating_Point_Type --
16443 ---------------------------------------------
16445 function Is_Single_Precision_Floating_Point_Type
16446 (E : Entity_Id) return Boolean is
16447 begin
16448 return Is_Floating_Point_Type (E)
16449 and then Machine_Radix_Value (E) = Uint_2
16450 and then Machine_Mantissa_Value (E) = Uint_24
16451 and then Machine_Emax_Value (E) = Uint_2 ** Uint_7
16452 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_7);
16453 end Is_Single_Precision_Floating_Point_Type;
16455 --------------------------------
16456 -- Is_Single_Protected_Object --
16457 --------------------------------
16459 function Is_Single_Protected_Object (Id : Entity_Id) return Boolean is
16460 begin
16461 return
16462 Ekind (Id) = E_Variable
16463 and then Ekind (Etype (Id)) = E_Protected_Type
16464 and then Is_Single_Concurrent_Type (Etype (Id));
16465 end Is_Single_Protected_Object;
16467 ---------------------------
16468 -- Is_Single_Task_Object --
16469 ---------------------------
16471 function Is_Single_Task_Object (Id : Entity_Id) return Boolean is
16472 begin
16473 return
16474 Ekind (Id) = E_Variable
16475 and then Ekind (Etype (Id)) = E_Task_Type
16476 and then Is_Single_Concurrent_Type (Etype (Id));
16477 end Is_Single_Task_Object;
16479 -------------------------------------
16480 -- Is_SPARK_05_Initialization_Expr --
16481 -------------------------------------
16483 function Is_SPARK_05_Initialization_Expr (N : Node_Id) return Boolean is
16484 Is_Ok : Boolean;
16485 Expr : Node_Id;
16486 Comp_Assn : Node_Id;
16487 Orig_N : constant Node_Id := Original_Node (N);
16489 begin
16490 Is_Ok := True;
16492 if not Comes_From_Source (Orig_N) then
16493 goto Done;
16494 end if;
16496 pragma Assert (Nkind (Orig_N) in N_Subexpr);
16498 case Nkind (Orig_N) is
16499 when N_Character_Literal
16500 | N_Integer_Literal
16501 | N_Real_Literal
16502 | N_String_Literal
16504 null;
16506 when N_Expanded_Name
16507 | N_Identifier
16509 if Is_Entity_Name (Orig_N)
16510 and then Present (Entity (Orig_N)) -- needed in some cases
16511 then
16512 case Ekind (Entity (Orig_N)) is
16513 when E_Constant
16514 | E_Enumeration_Literal
16515 | E_Named_Integer
16516 | E_Named_Real
16518 null;
16520 when others =>
16521 if Is_Type (Entity (Orig_N)) then
16522 null;
16523 else
16524 Is_Ok := False;
16525 end if;
16526 end case;
16527 end if;
16529 when N_Qualified_Expression
16530 | N_Type_Conversion
16532 Is_Ok := Is_SPARK_05_Initialization_Expr (Expression (Orig_N));
16534 when N_Unary_Op =>
16535 Is_Ok := Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
16537 when N_Binary_Op
16538 | N_Membership_Test
16539 | N_Short_Circuit
16541 Is_Ok := Is_SPARK_05_Initialization_Expr (Left_Opnd (Orig_N))
16542 and then
16543 Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
16545 when N_Aggregate
16546 | N_Extension_Aggregate
16548 if Nkind (Orig_N) = N_Extension_Aggregate then
16549 Is_Ok :=
16550 Is_SPARK_05_Initialization_Expr (Ancestor_Part (Orig_N));
16551 end if;
16553 Expr := First (Expressions (Orig_N));
16554 while Present (Expr) loop
16555 if not Is_SPARK_05_Initialization_Expr (Expr) then
16556 Is_Ok := False;
16557 goto Done;
16558 end if;
16560 Next (Expr);
16561 end loop;
16563 Comp_Assn := First (Component_Associations (Orig_N));
16564 while Present (Comp_Assn) loop
16565 Expr := Expression (Comp_Assn);
16567 -- Note: test for Present here needed for box assocation
16569 if Present (Expr)
16570 and then not Is_SPARK_05_Initialization_Expr (Expr)
16571 then
16572 Is_Ok := False;
16573 goto Done;
16574 end if;
16576 Next (Comp_Assn);
16577 end loop;
16579 when N_Attribute_Reference =>
16580 if Nkind (Prefix (Orig_N)) in N_Subexpr then
16581 Is_Ok := Is_SPARK_05_Initialization_Expr (Prefix (Orig_N));
16582 end if;
16584 Expr := First (Expressions (Orig_N));
16585 while Present (Expr) loop
16586 if not Is_SPARK_05_Initialization_Expr (Expr) then
16587 Is_Ok := False;
16588 goto Done;
16589 end if;
16591 Next (Expr);
16592 end loop;
16594 -- Selected components might be expanded named not yet resolved, so
16595 -- default on the safe side. (Eg on sparklex.ads)
16597 when N_Selected_Component =>
16598 null;
16600 when others =>
16601 Is_Ok := False;
16602 end case;
16604 <<Done>>
16605 return Is_Ok;
16606 end Is_SPARK_05_Initialization_Expr;
16608 ----------------------------------
16609 -- Is_SPARK_05_Object_Reference --
16610 ----------------------------------
16612 function Is_SPARK_05_Object_Reference (N : Node_Id) return Boolean is
16613 begin
16614 if Is_Entity_Name (N) then
16615 return Present (Entity (N))
16616 and then
16617 (Ekind_In (Entity (N), E_Constant, E_Variable)
16618 or else Ekind (Entity (N)) in Formal_Kind);
16620 else
16621 case Nkind (N) is
16622 when N_Selected_Component =>
16623 return Is_SPARK_05_Object_Reference (Prefix (N));
16625 when others =>
16626 return False;
16627 end case;
16628 end if;
16629 end Is_SPARK_05_Object_Reference;
16631 -----------------------------
16632 -- Is_Specific_Tagged_Type --
16633 -----------------------------
16635 function Is_Specific_Tagged_Type (Typ : Entity_Id) return Boolean is
16636 Full_Typ : Entity_Id;
16638 begin
16639 -- Handle private types
16641 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
16642 Full_Typ := Full_View (Typ);
16643 else
16644 Full_Typ := Typ;
16645 end if;
16647 -- A specific tagged type is a non-class-wide tagged type
16649 return Is_Tagged_Type (Full_Typ) and not Is_Class_Wide_Type (Full_Typ);
16650 end Is_Specific_Tagged_Type;
16652 ------------------
16653 -- Is_Statement --
16654 ------------------
16656 function Is_Statement (N : Node_Id) return Boolean is
16657 begin
16658 return
16659 Nkind (N) in N_Statement_Other_Than_Procedure_Call
16660 or else Nkind (N) = N_Procedure_Call_Statement;
16661 end Is_Statement;
16663 ---------------------------------------
16664 -- Is_Subprogram_Contract_Annotation --
16665 ---------------------------------------
16667 function Is_Subprogram_Contract_Annotation
16668 (Item : Node_Id) return Boolean
16670 Nam : Name_Id;
16672 begin
16673 if Nkind (Item) = N_Aspect_Specification then
16674 Nam := Chars (Identifier (Item));
16676 else pragma Assert (Nkind (Item) = N_Pragma);
16677 Nam := Pragma_Name (Item);
16678 end if;
16680 return Nam = Name_Contract_Cases
16681 or else Nam = Name_Depends
16682 or else Nam = Name_Extensions_Visible
16683 or else Nam = Name_Global
16684 or else Nam = Name_Post
16685 or else Nam = Name_Post_Class
16686 or else Nam = Name_Postcondition
16687 or else Nam = Name_Pre
16688 or else Nam = Name_Pre_Class
16689 or else Nam = Name_Precondition
16690 or else Nam = Name_Refined_Depends
16691 or else Nam = Name_Refined_Global
16692 or else Nam = Name_Refined_Post
16693 or else Nam = Name_Test_Case;
16694 end Is_Subprogram_Contract_Annotation;
16696 --------------------------------------------------
16697 -- Is_Subprogram_Stub_Without_Prior_Declaration --
16698 --------------------------------------------------
16700 function Is_Subprogram_Stub_Without_Prior_Declaration
16701 (N : Node_Id) return Boolean
16703 begin
16704 -- A subprogram stub without prior declaration serves as declaration for
16705 -- the actual subprogram body. As such, it has an attached defining
16706 -- entity of E_[Generic_]Function or E_[Generic_]Procedure.
16708 return Nkind (N) = N_Subprogram_Body_Stub
16709 and then Ekind (Defining_Entity (N)) /= E_Subprogram_Body;
16710 end Is_Subprogram_Stub_Without_Prior_Declaration;
16712 --------------------------
16713 -- Is_Suspension_Object --
16714 --------------------------
16716 function Is_Suspension_Object (Id : Entity_Id) return Boolean is
16717 begin
16718 -- This approach does an exact name match rather than to rely on
16719 -- RTSfind. Routine Is_Effectively_Volatile is used by clients of the
16720 -- front end at point where all auxiliary tables are locked and any
16721 -- modifications to them are treated as violations. Do not tamper with
16722 -- the tables, instead examine the Chars fields of all the scopes of Id.
16724 return
16725 Chars (Id) = Name_Suspension_Object
16726 and then Present (Scope (Id))
16727 and then Chars (Scope (Id)) = Name_Synchronous_Task_Control
16728 and then Present (Scope (Scope (Id)))
16729 and then Chars (Scope (Scope (Id))) = Name_Ada
16730 and then Present (Scope (Scope (Scope (Id))))
16731 and then Scope (Scope (Scope (Id))) = Standard_Standard;
16732 end Is_Suspension_Object;
16734 ----------------------------
16735 -- Is_Synchronized_Object --
16736 ----------------------------
16738 function Is_Synchronized_Object (Id : Entity_Id) return Boolean is
16739 Prag : Node_Id;
16741 begin
16742 if Is_Object (Id) then
16744 -- The object is synchronized if it is of a type that yields a
16745 -- synchronized object.
16747 if Yields_Synchronized_Object (Etype (Id)) then
16748 return True;
16750 -- The object is synchronized if it is atomic and Async_Writers is
16751 -- enabled.
16753 elsif Is_Atomic (Id) and then Async_Writers_Enabled (Id) then
16754 return True;
16756 -- A constant is a synchronized object by default
16758 elsif Ekind (Id) = E_Constant then
16759 return True;
16761 -- A variable is a synchronized object if it is subject to pragma
16762 -- Constant_After_Elaboration.
16764 elsif Ekind (Id) = E_Variable then
16765 Prag := Get_Pragma (Id, Pragma_Constant_After_Elaboration);
16767 return Present (Prag) and then Is_Enabled_Pragma (Prag);
16768 end if;
16769 end if;
16771 -- Otherwise the input is not an object or it does not qualify as a
16772 -- synchronized object.
16774 return False;
16775 end Is_Synchronized_Object;
16777 ---------------------------------
16778 -- Is_Synchronized_Tagged_Type --
16779 ---------------------------------
16781 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
16782 Kind : constant Entity_Kind := Ekind (Base_Type (E));
16784 begin
16785 -- A task or protected type derived from an interface is a tagged type.
16786 -- Such a tagged type is called a synchronized tagged type, as are
16787 -- synchronized interfaces and private extensions whose declaration
16788 -- includes the reserved word synchronized.
16790 return (Is_Tagged_Type (E)
16791 and then (Kind = E_Task_Type
16792 or else
16793 Kind = E_Protected_Type))
16794 or else
16795 (Is_Interface (E)
16796 and then Is_Synchronized_Interface (E))
16797 or else
16798 (Ekind (E) = E_Record_Type_With_Private
16799 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
16800 and then (Synchronized_Present (Parent (E))
16801 or else Is_Synchronized_Interface (Etype (E))));
16802 end Is_Synchronized_Tagged_Type;
16804 -----------------
16805 -- Is_Transfer --
16806 -----------------
16808 function Is_Transfer (N : Node_Id) return Boolean is
16809 Kind : constant Node_Kind := Nkind (N);
16811 begin
16812 if Kind = N_Simple_Return_Statement
16813 or else
16814 Kind = N_Extended_Return_Statement
16815 or else
16816 Kind = N_Goto_Statement
16817 or else
16818 Kind = N_Raise_Statement
16819 or else
16820 Kind = N_Requeue_Statement
16821 then
16822 return True;
16824 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
16825 and then No (Condition (N))
16826 then
16827 return True;
16829 elsif Kind = N_Procedure_Call_Statement
16830 and then Is_Entity_Name (Name (N))
16831 and then Present (Entity (Name (N)))
16832 and then No_Return (Entity (Name (N)))
16833 then
16834 return True;
16836 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
16837 return True;
16839 else
16840 return False;
16841 end if;
16842 end Is_Transfer;
16844 -------------
16845 -- Is_True --
16846 -------------
16848 function Is_True (U : Uint) return Boolean is
16849 begin
16850 return (U /= 0);
16851 end Is_True;
16853 --------------------------------------
16854 -- Is_Unchecked_Conversion_Instance --
16855 --------------------------------------
16857 function Is_Unchecked_Conversion_Instance (Id : Entity_Id) return Boolean is
16858 Par : Node_Id;
16860 begin
16861 -- Look for a function whose generic parent is the predefined intrinsic
16862 -- function Unchecked_Conversion, or for one that renames such an
16863 -- instance.
16865 if Ekind (Id) = E_Function then
16866 Par := Parent (Id);
16868 if Nkind (Par) = N_Function_Specification then
16869 Par := Generic_Parent (Par);
16871 if Present (Par) then
16872 return
16873 Chars (Par) = Name_Unchecked_Conversion
16874 and then Is_Intrinsic_Subprogram (Par)
16875 and then In_Predefined_Unit (Par);
16876 else
16877 return
16878 Present (Alias (Id))
16879 and then Is_Unchecked_Conversion_Instance (Alias (Id));
16880 end if;
16881 end if;
16882 end if;
16884 return False;
16885 end Is_Unchecked_Conversion_Instance;
16887 -------------------------------
16888 -- Is_Universal_Numeric_Type --
16889 -------------------------------
16891 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
16892 begin
16893 return T = Universal_Integer or else T = Universal_Real;
16894 end Is_Universal_Numeric_Type;
16896 ------------------------------
16897 -- Is_User_Defined_Equality --
16898 ------------------------------
16900 function Is_User_Defined_Equality (Id : Entity_Id) return Boolean is
16901 begin
16902 return Ekind (Id) = E_Function
16903 and then Chars (Id) = Name_Op_Eq
16904 and then Comes_From_Source (Id)
16906 -- Internally generated equalities have a full type declaration
16907 -- as their parent.
16909 and then Nkind (Parent (Id)) = N_Function_Specification;
16910 end Is_User_Defined_Equality;
16912 --------------------------------------
16913 -- Is_Validation_Variable_Reference --
16914 --------------------------------------
16916 function Is_Validation_Variable_Reference (N : Node_Id) return Boolean is
16917 Var : constant Node_Id := Unqual_Conv (N);
16918 Var_Id : Entity_Id;
16920 begin
16921 Var_Id := Empty;
16923 if Is_Entity_Name (Var) then
16924 Var_Id := Entity (Var);
16925 end if;
16927 return
16928 Present (Var_Id)
16929 and then Ekind (Var_Id) = E_Variable
16930 and then Present (Validated_Object (Var_Id));
16931 end Is_Validation_Variable_Reference;
16933 ----------------------------
16934 -- Is_Variable_Size_Array --
16935 ----------------------------
16937 function Is_Variable_Size_Array (E : Entity_Id) return Boolean is
16938 Idx : Node_Id;
16940 begin
16941 pragma Assert (Is_Array_Type (E));
16943 -- Check if some index is initialized with a non-constant value
16945 Idx := First_Index (E);
16946 while Present (Idx) loop
16947 if Nkind (Idx) = N_Range then
16948 if not Is_Constant_Bound (Low_Bound (Idx))
16949 or else not Is_Constant_Bound (High_Bound (Idx))
16950 then
16951 return True;
16952 end if;
16953 end if;
16955 Idx := Next_Index (Idx);
16956 end loop;
16958 return False;
16959 end Is_Variable_Size_Array;
16961 -----------------------------
16962 -- Is_Variable_Size_Record --
16963 -----------------------------
16965 function Is_Variable_Size_Record (E : Entity_Id) return Boolean is
16966 Comp : Entity_Id;
16967 Comp_Typ : Entity_Id;
16969 begin
16970 pragma Assert (Is_Record_Type (E));
16972 Comp := First_Entity (E);
16973 while Present (Comp) loop
16974 Comp_Typ := Etype (Comp);
16976 -- Recursive call if the record type has discriminants
16978 if Is_Record_Type (Comp_Typ)
16979 and then Has_Discriminants (Comp_Typ)
16980 and then Is_Variable_Size_Record (Comp_Typ)
16981 then
16982 return True;
16984 elsif Is_Array_Type (Comp_Typ)
16985 and then Is_Variable_Size_Array (Comp_Typ)
16986 then
16987 return True;
16988 end if;
16990 Next_Entity (Comp);
16991 end loop;
16993 return False;
16994 end Is_Variable_Size_Record;
16996 -----------------
16997 -- Is_Variable --
16998 -----------------
17000 function Is_Variable
17001 (N : Node_Id;
17002 Use_Original_Node : Boolean := True) return Boolean
17004 Orig_Node : Node_Id;
17006 function In_Protected_Function (E : Entity_Id) return Boolean;
17007 -- Within a protected function, the private components of the enclosing
17008 -- protected type are constants. A function nested within a (protected)
17009 -- procedure is not itself protected. Within the body of a protected
17010 -- function the current instance of the protected type is a constant.
17012 function Is_Variable_Prefix (P : Node_Id) return Boolean;
17013 -- Prefixes can involve implicit dereferences, in which case we must
17014 -- test for the case of a reference of a constant access type, which can
17015 -- can never be a variable.
17017 ---------------------------
17018 -- In_Protected_Function --
17019 ---------------------------
17021 function In_Protected_Function (E : Entity_Id) return Boolean is
17022 Prot : Entity_Id;
17023 S : Entity_Id;
17025 begin
17026 -- E is the current instance of a type
17028 if Is_Type (E) then
17029 Prot := E;
17031 -- E is an object
17033 else
17034 Prot := Scope (E);
17035 end if;
17037 if not Is_Protected_Type (Prot) then
17038 return False;
17040 else
17041 S := Current_Scope;
17042 while Present (S) and then S /= Prot loop
17043 if Ekind (S) = E_Function and then Scope (S) = Prot then
17044 return True;
17045 end if;
17047 S := Scope (S);
17048 end loop;
17050 return False;
17051 end if;
17052 end In_Protected_Function;
17054 ------------------------
17055 -- Is_Variable_Prefix --
17056 ------------------------
17058 function Is_Variable_Prefix (P : Node_Id) return Boolean is
17059 begin
17060 if Is_Access_Type (Etype (P)) then
17061 return not Is_Access_Constant (Root_Type (Etype (P)));
17063 -- For the case of an indexed component whose prefix has a packed
17064 -- array type, the prefix has been rewritten into a type conversion.
17065 -- Determine variable-ness from the converted expression.
17067 elsif Nkind (P) = N_Type_Conversion
17068 and then not Comes_From_Source (P)
17069 and then Is_Array_Type (Etype (P))
17070 and then Is_Packed (Etype (P))
17071 then
17072 return Is_Variable (Expression (P));
17074 else
17075 return Is_Variable (P);
17076 end if;
17077 end Is_Variable_Prefix;
17079 -- Start of processing for Is_Variable
17081 begin
17082 -- Special check, allow x'Deref(expr) as a variable
17084 if Nkind (N) = N_Attribute_Reference
17085 and then Attribute_Name (N) = Name_Deref
17086 then
17087 return True;
17088 end if;
17090 -- Check if we perform the test on the original node since this may be a
17091 -- test of syntactic categories which must not be disturbed by whatever
17092 -- rewriting might have occurred. For example, an aggregate, which is
17093 -- certainly NOT a variable, could be turned into a variable by
17094 -- expansion.
17096 if Use_Original_Node then
17097 Orig_Node := Original_Node (N);
17098 else
17099 Orig_Node := N;
17100 end if;
17102 -- Definitely OK if Assignment_OK is set. Since this is something that
17103 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
17105 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
17106 return True;
17108 -- Normally we go to the original node, but there is one exception where
17109 -- we use the rewritten node, namely when it is an explicit dereference.
17110 -- The generated code may rewrite a prefix which is an access type with
17111 -- an explicit dereference. The dereference is a variable, even though
17112 -- the original node may not be (since it could be a constant of the
17113 -- access type).
17115 -- In Ada 2005 we have a further case to consider: the prefix may be a
17116 -- function call given in prefix notation. The original node appears to
17117 -- be a selected component, but we need to examine the call.
17119 elsif Nkind (N) = N_Explicit_Dereference
17120 and then Nkind (Orig_Node) /= N_Explicit_Dereference
17121 and then Present (Etype (Orig_Node))
17122 and then Is_Access_Type (Etype (Orig_Node))
17123 then
17124 -- Note that if the prefix is an explicit dereference that does not
17125 -- come from source, we must check for a rewritten function call in
17126 -- prefixed notation before other forms of rewriting, to prevent a
17127 -- compiler crash.
17129 return
17130 (Nkind (Orig_Node) = N_Function_Call
17131 and then not Is_Access_Constant (Etype (Prefix (N))))
17132 or else
17133 Is_Variable_Prefix (Original_Node (Prefix (N)));
17135 -- in Ada 2012, the dereference may have been added for a type with
17136 -- a declared implicit dereference aspect. Check that it is not an
17137 -- access to constant.
17139 elsif Nkind (N) = N_Explicit_Dereference
17140 and then Present (Etype (Orig_Node))
17141 and then Ada_Version >= Ada_2012
17142 and then Has_Implicit_Dereference (Etype (Orig_Node))
17143 then
17144 return not Is_Access_Constant (Etype (Prefix (N)));
17146 -- A function call is never a variable
17148 elsif Nkind (N) = N_Function_Call then
17149 return False;
17151 -- All remaining checks use the original node
17153 elsif Is_Entity_Name (Orig_Node)
17154 and then Present (Entity (Orig_Node))
17155 then
17156 declare
17157 E : constant Entity_Id := Entity (Orig_Node);
17158 K : constant Entity_Kind := Ekind (E);
17160 begin
17161 return (K = E_Variable
17162 and then Nkind (Parent (E)) /= N_Exception_Handler)
17163 or else (K = E_Component
17164 and then not In_Protected_Function (E))
17165 or else K = E_Out_Parameter
17166 or else K = E_In_Out_Parameter
17167 or else K = E_Generic_In_Out_Parameter
17169 -- Current instance of type. If this is a protected type, check
17170 -- we are not within the body of one of its protected functions.
17172 or else (Is_Type (E)
17173 and then In_Open_Scopes (E)
17174 and then not In_Protected_Function (E))
17176 or else (Is_Incomplete_Or_Private_Type (E)
17177 and then In_Open_Scopes (Full_View (E)));
17178 end;
17180 else
17181 case Nkind (Orig_Node) is
17182 when N_Indexed_Component
17183 | N_Slice
17185 return Is_Variable_Prefix (Prefix (Orig_Node));
17187 when N_Selected_Component =>
17188 return (Is_Variable (Selector_Name (Orig_Node))
17189 and then Is_Variable_Prefix (Prefix (Orig_Node)))
17190 or else
17191 (Nkind (N) = N_Expanded_Name
17192 and then Scope (Entity (N)) = Entity (Prefix (N)));
17194 -- For an explicit dereference, the type of the prefix cannot
17195 -- be an access to constant or an access to subprogram.
17197 when N_Explicit_Dereference =>
17198 declare
17199 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
17200 begin
17201 return Is_Access_Type (Typ)
17202 and then not Is_Access_Constant (Root_Type (Typ))
17203 and then Ekind (Typ) /= E_Access_Subprogram_Type;
17204 end;
17206 -- The type conversion is the case where we do not deal with the
17207 -- context dependent special case of an actual parameter. Thus
17208 -- the type conversion is only considered a variable for the
17209 -- purposes of this routine if the target type is tagged. However,
17210 -- a type conversion is considered to be a variable if it does not
17211 -- come from source (this deals for example with the conversions
17212 -- of expressions to their actual subtypes).
17214 when N_Type_Conversion =>
17215 return Is_Variable (Expression (Orig_Node))
17216 and then
17217 (not Comes_From_Source (Orig_Node)
17218 or else
17219 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
17220 and then
17221 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
17223 -- GNAT allows an unchecked type conversion as a variable. This
17224 -- only affects the generation of internal expanded code, since
17225 -- calls to instantiations of Unchecked_Conversion are never
17226 -- considered variables (since they are function calls).
17228 when N_Unchecked_Type_Conversion =>
17229 return Is_Variable (Expression (Orig_Node));
17231 when others =>
17232 return False;
17233 end case;
17234 end if;
17235 end Is_Variable;
17237 ---------------------------
17238 -- Is_Visibly_Controlled --
17239 ---------------------------
17241 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
17242 Root : constant Entity_Id := Root_Type (T);
17243 begin
17244 return Chars (Scope (Root)) = Name_Finalization
17245 and then Chars (Scope (Scope (Root))) = Name_Ada
17246 and then Scope (Scope (Scope (Root))) = Standard_Standard;
17247 end Is_Visibly_Controlled;
17249 --------------------------
17250 -- Is_Volatile_Function --
17251 --------------------------
17253 function Is_Volatile_Function (Func_Id : Entity_Id) return Boolean is
17254 begin
17255 pragma Assert (Ekind_In (Func_Id, E_Function, E_Generic_Function));
17257 -- A function declared within a protected type is volatile
17259 if Is_Protected_Type (Scope (Func_Id)) then
17260 return True;
17262 -- An instance of Ada.Unchecked_Conversion is a volatile function if
17263 -- either the source or the target are effectively volatile.
17265 elsif Is_Unchecked_Conversion_Instance (Func_Id)
17266 and then Has_Effectively_Volatile_Profile (Func_Id)
17267 then
17268 return True;
17270 -- Otherwise the function is treated as volatile if it is subject to
17271 -- enabled pragma Volatile_Function.
17273 else
17274 return
17275 Is_Enabled_Pragma (Get_Pragma (Func_Id, Pragma_Volatile_Function));
17276 end if;
17277 end Is_Volatile_Function;
17279 ------------------------
17280 -- Is_Volatile_Object --
17281 ------------------------
17283 function Is_Volatile_Object (N : Node_Id) return Boolean is
17284 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
17285 -- If prefix is an implicit dereference, examine designated type
17287 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
17288 -- Determines if given object has volatile components
17290 ------------------------
17291 -- Is_Volatile_Prefix --
17292 ------------------------
17294 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
17295 Typ : constant Entity_Id := Etype (N);
17297 begin
17298 if Is_Access_Type (Typ) then
17299 declare
17300 Dtyp : constant Entity_Id := Designated_Type (Typ);
17302 begin
17303 return Is_Volatile (Dtyp)
17304 or else Has_Volatile_Components (Dtyp);
17305 end;
17307 else
17308 return Object_Has_Volatile_Components (N);
17309 end if;
17310 end Is_Volatile_Prefix;
17312 ------------------------------------
17313 -- Object_Has_Volatile_Components --
17314 ------------------------------------
17316 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
17317 Typ : constant Entity_Id := Etype (N);
17319 begin
17320 if Is_Volatile (Typ)
17321 or else Has_Volatile_Components (Typ)
17322 then
17323 return True;
17325 elsif Is_Entity_Name (N)
17326 and then (Has_Volatile_Components (Entity (N))
17327 or else Is_Volatile (Entity (N)))
17328 then
17329 return True;
17331 elsif Nkind (N) = N_Indexed_Component
17332 or else Nkind (N) = N_Selected_Component
17333 then
17334 return Is_Volatile_Prefix (Prefix (N));
17336 else
17337 return False;
17338 end if;
17339 end Object_Has_Volatile_Components;
17341 -- Start of processing for Is_Volatile_Object
17343 begin
17344 if Nkind (N) = N_Defining_Identifier then
17345 return Is_Volatile (N) or else Is_Volatile (Etype (N));
17347 elsif Nkind (N) = N_Expanded_Name then
17348 return Is_Volatile_Object (Entity (N));
17350 elsif Is_Volatile (Etype (N))
17351 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
17352 then
17353 return True;
17355 elsif Nkind_In (N, N_Indexed_Component, N_Selected_Component)
17356 and then Is_Volatile_Prefix (Prefix (N))
17357 then
17358 return True;
17360 elsif Nkind (N) = N_Selected_Component
17361 and then Is_Volatile (Entity (Selector_Name (N)))
17362 then
17363 return True;
17365 else
17366 return False;
17367 end if;
17368 end Is_Volatile_Object;
17370 -----------------------------
17371 -- Iterate_Call_Parameters --
17372 -----------------------------
17374 procedure Iterate_Call_Parameters (Call : Node_Id) is
17375 Formal : Entity_Id := First_Formal (Get_Called_Entity (Call));
17376 Actual : Node_Id := First_Actual (Call);
17378 begin
17379 while Present (Formal) and then Present (Actual) loop
17380 Handle_Parameter (Formal, Actual);
17381 Formal := Next_Formal (Formal);
17382 Actual := Next_Actual (Actual);
17383 end loop;
17384 end Iterate_Call_Parameters;
17386 ---------------------------
17387 -- Itype_Has_Declaration --
17388 ---------------------------
17390 function Itype_Has_Declaration (Id : Entity_Id) return Boolean is
17391 begin
17392 pragma Assert (Is_Itype (Id));
17393 return Present (Parent (Id))
17394 and then Nkind_In (Parent (Id), N_Full_Type_Declaration,
17395 N_Subtype_Declaration)
17396 and then Defining_Entity (Parent (Id)) = Id;
17397 end Itype_Has_Declaration;
17399 -------------------------
17400 -- Kill_Current_Values --
17401 -------------------------
17403 procedure Kill_Current_Values
17404 (Ent : Entity_Id;
17405 Last_Assignment_Only : Boolean := False)
17407 begin
17408 if Is_Assignable (Ent) then
17409 Set_Last_Assignment (Ent, Empty);
17410 end if;
17412 if Is_Object (Ent) then
17413 if not Last_Assignment_Only then
17414 Kill_Checks (Ent);
17415 Set_Current_Value (Ent, Empty);
17417 -- Do not reset the Is_Known_[Non_]Null and Is_Known_Valid flags
17418 -- for a constant. Once the constant is elaborated, its value is
17419 -- not changed, therefore the associated flags that describe the
17420 -- value should not be modified either.
17422 if Ekind (Ent) = E_Constant then
17423 null;
17425 -- Non-constant entities
17427 else
17428 if not Can_Never_Be_Null (Ent) then
17429 Set_Is_Known_Non_Null (Ent, False);
17430 end if;
17432 Set_Is_Known_Null (Ent, False);
17434 -- Reset the Is_Known_Valid flag unless the type is always
17435 -- valid. This does not apply to a loop parameter because its
17436 -- bounds are defined by the loop header and therefore always
17437 -- valid.
17439 if not Is_Known_Valid (Etype (Ent))
17440 and then Ekind (Ent) /= E_Loop_Parameter
17441 then
17442 Set_Is_Known_Valid (Ent, False);
17443 end if;
17444 end if;
17445 end if;
17446 end if;
17447 end Kill_Current_Values;
17449 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
17450 S : Entity_Id;
17452 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
17453 -- Clear current value for entity E and all entities chained to E
17455 ------------------------------------------
17456 -- Kill_Current_Values_For_Entity_Chain --
17457 ------------------------------------------
17459 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
17460 Ent : Entity_Id;
17461 begin
17462 Ent := E;
17463 while Present (Ent) loop
17464 Kill_Current_Values (Ent, Last_Assignment_Only);
17465 Next_Entity (Ent);
17466 end loop;
17467 end Kill_Current_Values_For_Entity_Chain;
17469 -- Start of processing for Kill_Current_Values
17471 begin
17472 -- Kill all saved checks, a special case of killing saved values
17474 if not Last_Assignment_Only then
17475 Kill_All_Checks;
17476 end if;
17478 -- Loop through relevant scopes, which includes the current scope and
17479 -- any parent scopes if the current scope is a block or a package.
17481 S := Current_Scope;
17482 Scope_Loop : loop
17484 -- Clear current values of all entities in current scope
17486 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
17488 -- If scope is a package, also clear current values of all private
17489 -- entities in the scope.
17491 if Is_Package_Or_Generic_Package (S)
17492 or else Is_Concurrent_Type (S)
17493 then
17494 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
17495 end if;
17497 -- If this is a not a subprogram, deal with parents
17499 if not Is_Subprogram (S) then
17500 S := Scope (S);
17501 exit Scope_Loop when S = Standard_Standard;
17502 else
17503 exit Scope_Loop;
17504 end if;
17505 end loop Scope_Loop;
17506 end Kill_Current_Values;
17508 --------------------------
17509 -- Kill_Size_Check_Code --
17510 --------------------------
17512 procedure Kill_Size_Check_Code (E : Entity_Id) is
17513 begin
17514 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
17515 and then Present (Size_Check_Code (E))
17516 then
17517 Remove (Size_Check_Code (E));
17518 Set_Size_Check_Code (E, Empty);
17519 end if;
17520 end Kill_Size_Check_Code;
17522 --------------------
17523 -- Known_Non_Null --
17524 --------------------
17526 function Known_Non_Null (N : Node_Id) return Boolean is
17527 Status : constant Null_Status_Kind := Null_Status (N);
17529 Id : Entity_Id;
17530 Op : Node_Kind;
17531 Val : Node_Id;
17533 begin
17534 -- The expression yields a non-null value ignoring simple flow analysis
17536 if Status = Is_Non_Null then
17537 return True;
17539 -- Otherwise check whether N is a reference to an entity that appears
17540 -- within a conditional construct.
17542 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
17544 -- First check if we are in decisive conditional
17546 Get_Current_Value_Condition (N, Op, Val);
17548 if Known_Null (Val) then
17549 if Op = N_Op_Eq then
17550 return False;
17551 elsif Op = N_Op_Ne then
17552 return True;
17553 end if;
17554 end if;
17556 -- If OK to do replacement, test Is_Known_Non_Null flag
17558 Id := Entity (N);
17560 if OK_To_Do_Constant_Replacement (Id) then
17561 return Is_Known_Non_Null (Id);
17562 end if;
17563 end if;
17565 -- Otherwise it is not possible to determine whether N yields a non-null
17566 -- value.
17568 return False;
17569 end Known_Non_Null;
17571 ----------------
17572 -- Known_Null --
17573 ----------------
17575 function Known_Null (N : Node_Id) return Boolean is
17576 Status : constant Null_Status_Kind := Null_Status (N);
17578 Id : Entity_Id;
17579 Op : Node_Kind;
17580 Val : Node_Id;
17582 begin
17583 -- The expression yields a null value ignoring simple flow analysis
17585 if Status = Is_Null then
17586 return True;
17588 -- Otherwise check whether N is a reference to an entity that appears
17589 -- within a conditional construct.
17591 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
17593 -- First check if we are in decisive conditional
17595 Get_Current_Value_Condition (N, Op, Val);
17597 if Known_Null (Val) then
17598 if Op = N_Op_Eq then
17599 return True;
17600 elsif Op = N_Op_Ne then
17601 return False;
17602 end if;
17603 end if;
17605 -- If OK to do replacement, test Is_Known_Null flag
17607 Id := Entity (N);
17609 if OK_To_Do_Constant_Replacement (Id) then
17610 return Is_Known_Null (Id);
17611 end if;
17612 end if;
17614 -- Otherwise it is not possible to determine whether N yields a null
17615 -- value.
17617 return False;
17618 end Known_Null;
17620 --------------------------
17621 -- Known_To_Be_Assigned --
17622 --------------------------
17624 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
17625 P : constant Node_Id := Parent (N);
17627 begin
17628 case Nkind (P) is
17630 -- Test left side of assignment
17632 when N_Assignment_Statement =>
17633 return N = Name (P);
17635 -- Function call arguments are never lvalues
17637 when N_Function_Call =>
17638 return False;
17640 -- Positional parameter for procedure or accept call
17642 when N_Accept_Statement
17643 | N_Procedure_Call_Statement
17645 declare
17646 Proc : Entity_Id;
17647 Form : Entity_Id;
17648 Act : Node_Id;
17650 begin
17651 Proc := Get_Subprogram_Entity (P);
17653 if No (Proc) then
17654 return False;
17655 end if;
17657 -- If we are not a list member, something is strange, so
17658 -- be conservative and return False.
17660 if not Is_List_Member (N) then
17661 return False;
17662 end if;
17664 -- We are going to find the right formal by stepping forward
17665 -- through the formals, as we step backwards in the actuals.
17667 Form := First_Formal (Proc);
17668 Act := N;
17669 loop
17670 -- If no formal, something is weird, so be conservative
17671 -- and return False.
17673 if No (Form) then
17674 return False;
17675 end if;
17677 Prev (Act);
17678 exit when No (Act);
17679 Next_Formal (Form);
17680 end loop;
17682 return Ekind (Form) /= E_In_Parameter;
17683 end;
17685 -- Named parameter for procedure or accept call
17687 when N_Parameter_Association =>
17688 declare
17689 Proc : Entity_Id;
17690 Form : Entity_Id;
17692 begin
17693 Proc := Get_Subprogram_Entity (Parent (P));
17695 if No (Proc) then
17696 return False;
17697 end if;
17699 -- Loop through formals to find the one that matches
17701 Form := First_Formal (Proc);
17702 loop
17703 -- If no matching formal, that's peculiar, some kind of
17704 -- previous error, so return False to be conservative.
17705 -- Actually this also happens in legal code in the case
17706 -- where P is a parameter association for an Extra_Formal???
17708 if No (Form) then
17709 return False;
17710 end if;
17712 -- Else test for match
17714 if Chars (Form) = Chars (Selector_Name (P)) then
17715 return Ekind (Form) /= E_In_Parameter;
17716 end if;
17718 Next_Formal (Form);
17719 end loop;
17720 end;
17722 -- Test for appearing in a conversion that itself appears
17723 -- in an lvalue context, since this should be an lvalue.
17725 when N_Type_Conversion =>
17726 return Known_To_Be_Assigned (P);
17728 -- All other references are definitely not known to be modifications
17730 when others =>
17731 return False;
17732 end case;
17733 end Known_To_Be_Assigned;
17735 ---------------------------
17736 -- Last_Source_Statement --
17737 ---------------------------
17739 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
17740 N : Node_Id;
17742 begin
17743 N := Last (Statements (HSS));
17744 while Present (N) loop
17745 exit when Comes_From_Source (N);
17746 Prev (N);
17747 end loop;
17749 return N;
17750 end Last_Source_Statement;
17752 -----------------------
17753 -- Mark_Coextensions --
17754 -----------------------
17756 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
17757 Is_Dynamic : Boolean;
17758 -- Indicates whether the context causes nested coextensions to be
17759 -- dynamic or static
17761 function Mark_Allocator (N : Node_Id) return Traverse_Result;
17762 -- Recognize an allocator node and label it as a dynamic coextension
17764 --------------------
17765 -- Mark_Allocator --
17766 --------------------
17768 function Mark_Allocator (N : Node_Id) return Traverse_Result is
17769 begin
17770 if Nkind (N) = N_Allocator then
17771 if Is_Dynamic then
17772 Set_Is_Dynamic_Coextension (N);
17774 -- If the allocator expression is potentially dynamic, it may
17775 -- be expanded out of order and require dynamic allocation
17776 -- anyway, so we treat the coextension itself as dynamic.
17777 -- Potential optimization ???
17779 elsif Nkind (Expression (N)) = N_Qualified_Expression
17780 and then Nkind (Expression (Expression (N))) = N_Op_Concat
17781 then
17782 Set_Is_Dynamic_Coextension (N);
17783 else
17784 Set_Is_Static_Coextension (N);
17785 end if;
17786 end if;
17788 return OK;
17789 end Mark_Allocator;
17791 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
17793 -- Start of processing for Mark_Coextensions
17795 begin
17796 -- An allocator that appears on the right-hand side of an assignment is
17797 -- treated as a potentially dynamic coextension when the right-hand side
17798 -- is an allocator or a qualified expression.
17800 -- Obj := new ...'(new Coextension ...);
17802 if Nkind (Context_Nod) = N_Assignment_Statement then
17803 Is_Dynamic :=
17804 Nkind_In (Expression (Context_Nod), N_Allocator,
17805 N_Qualified_Expression);
17807 -- An allocator that appears within the expression of a simple return
17808 -- statement is treated as a potentially dynamic coextension when the
17809 -- expression is either aggregate, allocator, or qualified expression.
17811 -- return (new Coextension ...);
17812 -- return new ...'(new Coextension ...);
17814 elsif Nkind (Context_Nod) = N_Simple_Return_Statement then
17815 Is_Dynamic :=
17816 Nkind_In (Expression (Context_Nod), N_Aggregate,
17817 N_Allocator,
17818 N_Qualified_Expression);
17820 -- An alloctor that appears within the initialization expression of an
17821 -- object declaration is considered a potentially dynamic coextension
17822 -- when the initialization expression is an allocator or a qualified
17823 -- expression.
17825 -- Obj : ... := new ...'(new Coextension ...);
17827 -- A similar case arises when the object declaration is part of an
17828 -- extended return statement.
17830 -- return Obj : ... := new ...'(new Coextension ...);
17831 -- return Obj : ... := (new Coextension ...);
17833 elsif Nkind (Context_Nod) = N_Object_Declaration then
17834 Is_Dynamic :=
17835 Nkind_In (Root_Nod, N_Allocator, N_Qualified_Expression)
17836 or else
17837 Nkind (Parent (Context_Nod)) = N_Extended_Return_Statement;
17839 -- This routine should not be called with constructs that cannot contain
17840 -- coextensions.
17842 else
17843 raise Program_Error;
17844 end if;
17846 Mark_Allocators (Root_Nod);
17847 end Mark_Coextensions;
17849 ---------------------------------
17850 -- Mark_Elaboration_Attributes --
17851 ---------------------------------
17853 procedure Mark_Elaboration_Attributes
17854 (N_Id : Node_Or_Entity_Id;
17855 Checks : Boolean := False;
17856 Level : Boolean := False;
17857 Modes : Boolean := False;
17858 Warnings : Boolean := False)
17860 function Elaboration_Checks_OK
17861 (Target_Id : Entity_Id;
17862 Context_Id : Entity_Id) return Boolean;
17863 -- Determine whether elaboration checks are enabled for target Target_Id
17864 -- which resides within context Context_Id.
17866 procedure Mark_Elaboration_Attributes_Id (Id : Entity_Id);
17867 -- Preserve relevant attributes of the context in arbitrary entity Id
17869 procedure Mark_Elaboration_Attributes_Node (N : Node_Id);
17870 -- Preserve relevant attributes of the context in arbitrary node N
17872 ---------------------------
17873 -- Elaboration_Checks_OK --
17874 ---------------------------
17876 function Elaboration_Checks_OK
17877 (Target_Id : Entity_Id;
17878 Context_Id : Entity_Id) return Boolean
17880 Encl_Scop : Entity_Id;
17882 begin
17883 -- Elaboration checks are suppressed for the target
17885 if Elaboration_Checks_Suppressed (Target_Id) then
17886 return False;
17887 end if;
17889 -- Otherwise elaboration checks are OK for the target, but may be
17890 -- suppressed for the context where the target is declared.
17892 Encl_Scop := Context_Id;
17893 while Present (Encl_Scop) and then Encl_Scop /= Standard_Standard loop
17894 if Elaboration_Checks_Suppressed (Encl_Scop) then
17895 return False;
17896 end if;
17898 Encl_Scop := Scope (Encl_Scop);
17899 end loop;
17901 -- Neither the target nor its declarative context have elaboration
17902 -- checks suppressed.
17904 return True;
17905 end Elaboration_Checks_OK;
17907 ------------------------------------
17908 -- Mark_Elaboration_Attributes_Id --
17909 ------------------------------------
17911 procedure Mark_Elaboration_Attributes_Id (Id : Entity_Id) is
17912 begin
17913 -- Mark the status of elaboration checks in effect. Do not reset the
17914 -- status in case the entity is reanalyzed with checks suppressed.
17916 if Checks and then not Is_Elaboration_Checks_OK_Id (Id) then
17917 Set_Is_Elaboration_Checks_OK_Id (Id,
17918 Elaboration_Checks_OK
17919 (Target_Id => Id,
17920 Context_Id => Scope (Id)));
17922 -- Entities do not need to capture their enclosing level. The Ghost
17923 -- and SPARK modes in effect are already marked during analysis.
17925 else
17926 null;
17927 end if;
17928 end Mark_Elaboration_Attributes_Id;
17930 --------------------------------------
17931 -- Mark_Elaboration_Attributes_Node --
17932 --------------------------------------
17934 procedure Mark_Elaboration_Attributes_Node (N : Node_Id) is
17935 function Extract_Name (N : Node_Id) return Node_Id;
17936 -- Obtain the Name attribute of call or instantiation N
17938 ------------------
17939 -- Extract_Name --
17940 ------------------
17942 function Extract_Name (N : Node_Id) return Node_Id is
17943 Nam : Node_Id;
17945 begin
17946 Nam := Name (N);
17948 -- A call to an entry family appears in indexed form
17950 if Nkind (Nam) = N_Indexed_Component then
17951 Nam := Prefix (Nam);
17952 end if;
17954 -- The name may also appear in qualified form
17956 if Nkind (Nam) = N_Selected_Component then
17957 Nam := Selector_Name (Nam);
17958 end if;
17960 return Nam;
17961 end Extract_Name;
17963 -- Local variables
17965 Context_Id : Entity_Id;
17966 Nam : Node_Id;
17968 -- Start of processing for Mark_Elaboration_Attributes_Node
17970 begin
17971 -- Mark the status of elaboration checks in effect. Do not reset the
17972 -- status in case the node is reanalyzed with checks suppressed.
17974 if Checks and then not Is_Elaboration_Checks_OK_Node (N) then
17976 -- Assignments, attribute references, and variable references do
17977 -- not have a "declarative" context.
17979 Context_Id := Empty;
17981 -- The status of elaboration checks for calls and instantiations
17982 -- depends on the most recent pragma Suppress/Unsuppress, as well
17983 -- as the suppression status of the context where the target is
17984 -- defined.
17986 -- package Pack is
17987 -- function Func ...;
17988 -- end Pack;
17990 -- with Pack;
17991 -- procedure Main is
17992 -- pragma Suppress (Elaboration_Checks, Pack);
17993 -- X : ... := Pack.Func;
17994 -- ...
17996 -- In the example above, the call to Func has elaboration checks
17997 -- enabled because there is no active general purpose suppression
17998 -- pragma, however the elaboration checks of Pack are explicitly
17999 -- suppressed. As a result the elaboration checks of the call must
18000 -- be disabled in order to preserve this dependency.
18002 if Nkind_In (N, N_Entry_Call_Statement,
18003 N_Function_Call,
18004 N_Function_Instantiation,
18005 N_Package_Instantiation,
18006 N_Procedure_Call_Statement,
18007 N_Procedure_Instantiation)
18008 then
18009 Nam := Extract_Name (N);
18011 if Is_Entity_Name (Nam) and then Present (Entity (Nam)) then
18012 Context_Id := Scope (Entity (Nam));
18013 end if;
18014 end if;
18016 Set_Is_Elaboration_Checks_OK_Node (N,
18017 Elaboration_Checks_OK
18018 (Target_Id => Empty,
18019 Context_Id => Context_Id));
18020 end if;
18022 -- Mark the enclosing level of the node. Do not reset the status in
18023 -- case the node is relocated and reanalyzed.
18025 if Level and then not Is_Declaration_Level_Node (N) then
18026 Set_Is_Declaration_Level_Node (N,
18027 Find_Enclosing_Level (N) = Declaration_Level);
18028 end if;
18030 -- Mark the Ghost and SPARK mode in effect
18032 if Modes then
18033 if Ghost_Mode = Ignore then
18034 Set_Is_Ignored_Ghost_Node (N);
18035 end if;
18037 if SPARK_Mode = On then
18038 Set_Is_SPARK_Mode_On_Node (N);
18039 end if;
18040 end if;
18042 -- Mark the status of elaboration warnings in effect. Do not reset
18043 -- the status in case the node is reanalyzed with warnings off.
18045 if Warnings and then not Is_Elaboration_Warnings_OK_Node (N) then
18046 Set_Is_Elaboration_Warnings_OK_Node (N, Elab_Warnings);
18047 end if;
18048 end Mark_Elaboration_Attributes_Node;
18050 -- Start of processing for Mark_Elaboration_Attributes
18052 begin
18053 -- Do not capture any elaboration-related attributes when switch -gnatH
18054 -- (legacy elaboration checking mode enabled) is in effect because the
18055 -- attributes are useless to the legacy model.
18057 if Legacy_Elaboration_Checks then
18058 return;
18059 end if;
18061 if Nkind (N_Id) in N_Entity then
18062 Mark_Elaboration_Attributes_Id (N_Id);
18063 else
18064 Mark_Elaboration_Attributes_Node (N_Id);
18065 end if;
18066 end Mark_Elaboration_Attributes;
18068 ----------------------------------
18069 -- Matching_Static_Array_Bounds --
18070 ----------------------------------
18072 function Matching_Static_Array_Bounds
18073 (L_Typ : Node_Id;
18074 R_Typ : Node_Id) return Boolean
18076 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
18077 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
18079 L_Index : Node_Id := Empty; -- init to ...
18080 R_Index : Node_Id := Empty; -- ...avoid warnings
18081 L_Low : Node_Id;
18082 L_High : Node_Id;
18083 L_Len : Uint;
18084 R_Low : Node_Id;
18085 R_High : Node_Id;
18086 R_Len : Uint;
18088 begin
18089 if L_Ndims /= R_Ndims then
18090 return False;
18091 end if;
18093 -- Unconstrained types do not have static bounds
18095 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
18096 return False;
18097 end if;
18099 -- First treat specially the first dimension, as the lower bound and
18100 -- length of string literals are not stored like those of arrays.
18102 if Ekind (L_Typ) = E_String_Literal_Subtype then
18103 L_Low := String_Literal_Low_Bound (L_Typ);
18104 L_Len := String_Literal_Length (L_Typ);
18105 else
18106 L_Index := First_Index (L_Typ);
18107 Get_Index_Bounds (L_Index, L_Low, L_High);
18109 if Is_OK_Static_Expression (L_Low)
18110 and then
18111 Is_OK_Static_Expression (L_High)
18112 then
18113 if Expr_Value (L_High) < Expr_Value (L_Low) then
18114 L_Len := Uint_0;
18115 else
18116 L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
18117 end if;
18118 else
18119 return False;
18120 end if;
18121 end if;
18123 if Ekind (R_Typ) = E_String_Literal_Subtype then
18124 R_Low := String_Literal_Low_Bound (R_Typ);
18125 R_Len := String_Literal_Length (R_Typ);
18126 else
18127 R_Index := First_Index (R_Typ);
18128 Get_Index_Bounds (R_Index, R_Low, R_High);
18130 if Is_OK_Static_Expression (R_Low)
18131 and then
18132 Is_OK_Static_Expression (R_High)
18133 then
18134 if Expr_Value (R_High) < Expr_Value (R_Low) then
18135 R_Len := Uint_0;
18136 else
18137 R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
18138 end if;
18139 else
18140 return False;
18141 end if;
18142 end if;
18144 if (Is_OK_Static_Expression (L_Low)
18145 and then
18146 Is_OK_Static_Expression (R_Low))
18147 and then Expr_Value (L_Low) = Expr_Value (R_Low)
18148 and then L_Len = R_Len
18149 then
18150 null;
18151 else
18152 return False;
18153 end if;
18155 -- Then treat all other dimensions
18157 for Indx in 2 .. L_Ndims loop
18158 Next (L_Index);
18159 Next (R_Index);
18161 Get_Index_Bounds (L_Index, L_Low, L_High);
18162 Get_Index_Bounds (R_Index, R_Low, R_High);
18164 if (Is_OK_Static_Expression (L_Low) and then
18165 Is_OK_Static_Expression (L_High) and then
18166 Is_OK_Static_Expression (R_Low) and then
18167 Is_OK_Static_Expression (R_High))
18168 and then (Expr_Value (L_Low) = Expr_Value (R_Low)
18169 and then
18170 Expr_Value (L_High) = Expr_Value (R_High))
18171 then
18172 null;
18173 else
18174 return False;
18175 end if;
18176 end loop;
18178 -- If we fall through the loop, all indexes matched
18180 return True;
18181 end Matching_Static_Array_Bounds;
18183 -------------------
18184 -- May_Be_Lvalue --
18185 -------------------
18187 function May_Be_Lvalue (N : Node_Id) return Boolean is
18188 P : constant Node_Id := Parent (N);
18190 begin
18191 case Nkind (P) is
18193 -- Test left side of assignment
18195 when N_Assignment_Statement =>
18196 return N = Name (P);
18198 -- Test prefix of component or attribute. Note that the prefix of an
18199 -- explicit or implicit dereference cannot be an l-value. In the case
18200 -- of a 'Read attribute, the reference can be an actual in the
18201 -- argument list of the attribute.
18203 when N_Attribute_Reference =>
18204 return (N = Prefix (P)
18205 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P)))
18206 or else
18207 Attribute_Name (P) = Name_Read;
18209 -- For an expanded name, the name is an lvalue if the expanded name
18210 -- is an lvalue, but the prefix is never an lvalue, since it is just
18211 -- the scope where the name is found.
18213 when N_Expanded_Name =>
18214 if N = Prefix (P) then
18215 return May_Be_Lvalue (P);
18216 else
18217 return False;
18218 end if;
18220 -- For a selected component A.B, A is certainly an lvalue if A.B is.
18221 -- B is a little interesting, if we have A.B := 3, there is some
18222 -- discussion as to whether B is an lvalue or not, we choose to say
18223 -- it is. Note however that A is not an lvalue if it is of an access
18224 -- type since this is an implicit dereference.
18226 when N_Selected_Component =>
18227 if N = Prefix (P)
18228 and then Present (Etype (N))
18229 and then Is_Access_Type (Etype (N))
18230 then
18231 return False;
18232 else
18233 return May_Be_Lvalue (P);
18234 end if;
18236 -- For an indexed component or slice, the index or slice bounds is
18237 -- never an lvalue. The prefix is an lvalue if the indexed component
18238 -- or slice is an lvalue, except if it is an access type, where we
18239 -- have an implicit dereference.
18241 when N_Indexed_Component
18242 | N_Slice
18244 if N /= Prefix (P)
18245 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
18246 then
18247 return False;
18248 else
18249 return May_Be_Lvalue (P);
18250 end if;
18252 -- Prefix of a reference is an lvalue if the reference is an lvalue
18254 when N_Reference =>
18255 return May_Be_Lvalue (P);
18257 -- Prefix of explicit dereference is never an lvalue
18259 when N_Explicit_Dereference =>
18260 return False;
18262 -- Positional parameter for subprogram, entry, or accept call.
18263 -- In older versions of Ada function call arguments are never
18264 -- lvalues. In Ada 2012 functions can have in-out parameters.
18266 when N_Accept_Statement
18267 | N_Entry_Call_Statement
18268 | N_Subprogram_Call
18270 if Nkind (P) = N_Function_Call and then Ada_Version < Ada_2012 then
18271 return False;
18272 end if;
18274 -- The following mechanism is clumsy and fragile. A single flag
18275 -- set in Resolve_Actuals would be preferable ???
18277 declare
18278 Proc : Entity_Id;
18279 Form : Entity_Id;
18280 Act : Node_Id;
18282 begin
18283 Proc := Get_Subprogram_Entity (P);
18285 if No (Proc) then
18286 return True;
18287 end if;
18289 -- If we are not a list member, something is strange, so be
18290 -- conservative and return True.
18292 if not Is_List_Member (N) then
18293 return True;
18294 end if;
18296 -- We are going to find the right formal by stepping forward
18297 -- through the formals, as we step backwards in the actuals.
18299 Form := First_Formal (Proc);
18300 Act := N;
18301 loop
18302 -- If no formal, something is weird, so be conservative and
18303 -- return True.
18305 if No (Form) then
18306 return True;
18307 end if;
18309 Prev (Act);
18310 exit when No (Act);
18311 Next_Formal (Form);
18312 end loop;
18314 return Ekind (Form) /= E_In_Parameter;
18315 end;
18317 -- Named parameter for procedure or accept call
18319 when N_Parameter_Association =>
18320 declare
18321 Proc : Entity_Id;
18322 Form : Entity_Id;
18324 begin
18325 Proc := Get_Subprogram_Entity (Parent (P));
18327 if No (Proc) then
18328 return True;
18329 end if;
18331 -- Loop through formals to find the one that matches
18333 Form := First_Formal (Proc);
18334 loop
18335 -- If no matching formal, that's peculiar, some kind of
18336 -- previous error, so return True to be conservative.
18337 -- Actually happens with legal code for an unresolved call
18338 -- where we may get the wrong homonym???
18340 if No (Form) then
18341 return True;
18342 end if;
18344 -- Else test for match
18346 if Chars (Form) = Chars (Selector_Name (P)) then
18347 return Ekind (Form) /= E_In_Parameter;
18348 end if;
18350 Next_Formal (Form);
18351 end loop;
18352 end;
18354 -- Test for appearing in a conversion that itself appears in an
18355 -- lvalue context, since this should be an lvalue.
18357 when N_Type_Conversion =>
18358 return May_Be_Lvalue (P);
18360 -- Test for appearance in object renaming declaration
18362 when N_Object_Renaming_Declaration =>
18363 return True;
18365 -- All other references are definitely not lvalues
18367 when others =>
18368 return False;
18369 end case;
18370 end May_Be_Lvalue;
18372 -----------------
18373 -- Might_Raise --
18374 -----------------
18376 function Might_Raise (N : Node_Id) return Boolean is
18377 Result : Boolean := False;
18379 function Process (N : Node_Id) return Traverse_Result;
18380 -- Set Result to True if we find something that could raise an exception
18382 -------------
18383 -- Process --
18384 -------------
18386 function Process (N : Node_Id) return Traverse_Result is
18387 begin
18388 if Nkind_In (N, N_Procedure_Call_Statement,
18389 N_Function_Call,
18390 N_Raise_Statement,
18391 N_Raise_Constraint_Error,
18392 N_Raise_Program_Error,
18393 N_Raise_Storage_Error)
18394 then
18395 Result := True;
18396 return Abandon;
18397 else
18398 return OK;
18399 end if;
18400 end Process;
18402 procedure Set_Result is new Traverse_Proc (Process);
18404 -- Start of processing for Might_Raise
18406 begin
18407 -- False if exceptions can't be propagated
18409 if No_Exception_Handlers_Set then
18410 return False;
18411 end if;
18413 -- If the checks handled by the back end are not disabled, we cannot
18414 -- ensure that no exception will be raised.
18416 if not Access_Checks_Suppressed (Empty)
18417 or else not Discriminant_Checks_Suppressed (Empty)
18418 or else not Range_Checks_Suppressed (Empty)
18419 or else not Index_Checks_Suppressed (Empty)
18420 or else Opt.Stack_Checking_Enabled
18421 then
18422 return True;
18423 end if;
18425 Set_Result (N);
18426 return Result;
18427 end Might_Raise;
18429 --------------------------------
18430 -- Nearest_Enclosing_Instance --
18431 --------------------------------
18433 function Nearest_Enclosing_Instance (E : Entity_Id) return Entity_Id is
18434 Inst : Entity_Id;
18436 begin
18437 Inst := Scope (E);
18438 while Present (Inst) and then Inst /= Standard_Standard loop
18439 if Is_Generic_Instance (Inst) then
18440 return Inst;
18441 end if;
18443 Inst := Scope (Inst);
18444 end loop;
18446 return Empty;
18447 end Nearest_Enclosing_Instance;
18449 ----------------------
18450 -- Needs_One_Actual --
18451 ----------------------
18453 function Needs_One_Actual (E : Entity_Id) return Boolean is
18454 Formal : Entity_Id;
18456 begin
18457 -- Ada 2005 or later, and formals present. The first formal must be
18458 -- of a type that supports prefix notation: a controlling argument,
18459 -- a class-wide type, or an access to such.
18461 if Ada_Version >= Ada_2005
18462 and then Present (First_Formal (E))
18463 and then No (Default_Value (First_Formal (E)))
18464 and then
18465 (Is_Controlling_Formal (First_Formal (E))
18466 or else Is_Class_Wide_Type (Etype (First_Formal (E)))
18467 or else Is_Anonymous_Access_Type (Etype (First_Formal (E))))
18468 then
18469 Formal := Next_Formal (First_Formal (E));
18470 while Present (Formal) loop
18471 if No (Default_Value (Formal)) then
18472 return False;
18473 end if;
18475 Next_Formal (Formal);
18476 end loop;
18478 return True;
18480 -- Ada 83/95 or no formals
18482 else
18483 return False;
18484 end if;
18485 end Needs_One_Actual;
18487 ------------------------
18488 -- New_Copy_List_Tree --
18489 ------------------------
18491 function New_Copy_List_Tree (List : List_Id) return List_Id is
18492 NL : List_Id;
18493 E : Node_Id;
18495 begin
18496 if List = No_List then
18497 return No_List;
18499 else
18500 NL := New_List;
18501 E := First (List);
18503 while Present (E) loop
18504 Append (New_Copy_Tree (E), NL);
18505 E := Next (E);
18506 end loop;
18508 return NL;
18509 end if;
18510 end New_Copy_List_Tree;
18512 -------------------
18513 -- New_Copy_Tree --
18514 -------------------
18516 -- The following tables play a key role in replicating entities and Itypes.
18517 -- They are intentionally declared at the library level rather than within
18518 -- New_Copy_Tree to avoid elaborating them on each call. This performance
18519 -- optimization saves up to 2% of the entire compilation time spent in the
18520 -- front end. Care should be taken to reset the tables on each new call to
18521 -- New_Copy_Tree.
18523 NCT_Table_Max : constant := 511;
18525 subtype NCT_Table_Index is Nat range 0 .. NCT_Table_Max - 1;
18527 function NCT_Table_Hash (Key : Node_Or_Entity_Id) return NCT_Table_Index;
18528 -- Obtain the hash value of node or entity Key
18530 --------------------
18531 -- NCT_Table_Hash --
18532 --------------------
18534 function NCT_Table_Hash (Key : Node_Or_Entity_Id) return NCT_Table_Index is
18535 begin
18536 return NCT_Table_Index (Key mod NCT_Table_Max);
18537 end NCT_Table_Hash;
18539 ----------------------
18540 -- NCT_New_Entities --
18541 ----------------------
18543 -- The following table maps old entities and Itypes to their corresponding
18544 -- new entities and Itypes.
18546 -- Aaa -> Xxx
18548 package NCT_New_Entities is new Simple_HTable (
18549 Header_Num => NCT_Table_Index,
18550 Element => Entity_Id,
18551 No_Element => Empty,
18552 Key => Entity_Id,
18553 Hash => NCT_Table_Hash,
18554 Equal => "=");
18556 ------------------------
18557 -- NCT_Pending_Itypes --
18558 ------------------------
18560 -- The following table maps old Associated_Node_For_Itype nodes to a set of
18561 -- new itypes. Given a set of old Itypes Aaa, Bbb, and Ccc, where all three
18562 -- have the same Associated_Node_For_Itype Ppp, and their corresponding new
18563 -- Itypes Xxx, Yyy, Zzz, the table contains the following mapping:
18565 -- Ppp -> (Xxx, Yyy, Zzz)
18567 -- The set is expressed as an Elist
18569 package NCT_Pending_Itypes is new Simple_HTable (
18570 Header_Num => NCT_Table_Index,
18571 Element => Elist_Id,
18572 No_Element => No_Elist,
18573 Key => Node_Id,
18574 Hash => NCT_Table_Hash,
18575 Equal => "=");
18577 NCT_Tables_In_Use : Boolean := False;
18578 -- This flag keeps track of whether the two tables NCT_New_Entities and
18579 -- NCT_Pending_Itypes are in use. The flag is part of an optimization
18580 -- where certain operations are not performed if the tables are not in
18581 -- use. This saves up to 8% of the entire compilation time spent in the
18582 -- front end.
18584 -------------------
18585 -- New_Copy_Tree --
18586 -------------------
18588 function New_Copy_Tree
18589 (Source : Node_Id;
18590 Map : Elist_Id := No_Elist;
18591 New_Sloc : Source_Ptr := No_Location;
18592 New_Scope : Entity_Id := Empty) return Node_Id
18594 -- This routine performs low-level tree manipulations and needs access
18595 -- to the internals of the tree.
18597 use Atree.Unchecked_Access;
18598 use Atree_Private_Part;
18600 EWA_Level : Nat := 0;
18601 -- This counter keeps track of how many N_Expression_With_Actions nodes
18602 -- are encountered during a depth-first traversal of the subtree. These
18603 -- nodes may define new entities in their Actions lists and thus require
18604 -- special processing.
18606 EWA_Inner_Scope_Level : Nat := 0;
18607 -- This counter keeps track of how many scoping constructs appear within
18608 -- an N_Expression_With_Actions node.
18610 procedure Add_New_Entity (Old_Id : Entity_Id; New_Id : Entity_Id);
18611 pragma Inline (Add_New_Entity);
18612 -- Add an entry in the NCT_New_Entities table which maps key Old_Id to
18613 -- value New_Id. Old_Id is an entity which appears within the Actions
18614 -- list of an N_Expression_With_Actions node, or within an entity map.
18615 -- New_Id is the corresponding new entity generated during Phase 1.
18617 procedure Add_Pending_Itype (Assoc_Nod : Node_Id; Itype : Entity_Id);
18618 pragma Inline (Add_New_Entity);
18619 -- Add an entry in the NCT_Pending_Itypes which maps key Assoc_Nod to
18620 -- value Itype. Assoc_Nod is the associated node of an itype. Itype is
18621 -- an itype.
18623 procedure Build_NCT_Tables (Entity_Map : Elist_Id);
18624 pragma Inline (Build_NCT_Tables);
18625 -- Populate tables NCT_New_Entities and NCT_Pending_Itypes with the
18626 -- information supplied in entity map Entity_Map. The format of the
18627 -- entity map must be as follows:
18629 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
18631 function Copy_Any_Node_With_Replacement
18632 (N : Node_Or_Entity_Id) return Node_Or_Entity_Id;
18633 pragma Inline (Copy_Any_Node_With_Replacement);
18634 -- Replicate entity or node N by invoking one of the following routines:
18636 -- Copy_Node_With_Replacement
18637 -- Corresponding_Entity
18639 function Copy_Elist_With_Replacement (List : Elist_Id) return Elist_Id;
18640 -- Replicate the elements of entity list List
18642 function Copy_Field_With_Replacement
18643 (Field : Union_Id;
18644 Old_Par : Node_Id := Empty;
18645 New_Par : Node_Id := Empty;
18646 Semantic : Boolean := False) return Union_Id;
18647 -- Replicate field Field by invoking one of the following routines:
18649 -- Copy_Elist_With_Replacement
18650 -- Copy_List_With_Replacement
18651 -- Copy_Node_With_Replacement
18652 -- Corresponding_Entity
18654 -- If the field is not an entity list, entity, itype, syntactic list,
18655 -- or node, then the field is returned unchanged. The routine always
18656 -- replicates entities, itypes, and valid syntactic fields. Old_Par is
18657 -- the expected parent of a syntactic field. New_Par is the new parent
18658 -- associated with a replicated syntactic field. Flag Semantic should
18659 -- be set when the input is a semantic field.
18661 function Copy_List_With_Replacement (List : List_Id) return List_Id;
18662 -- Replicate the elements of syntactic list List
18664 function Copy_Node_With_Replacement (N : Node_Id) return Node_Id;
18665 -- Replicate node N
18667 function Corresponding_Entity (Id : Entity_Id) return Entity_Id;
18668 pragma Inline (Corresponding_Entity);
18669 -- Return the corresponding new entity of Id generated during Phase 1.
18670 -- If there is no such entity, return Id.
18672 function In_Entity_Map
18673 (Id : Entity_Id;
18674 Entity_Map : Elist_Id) return Boolean;
18675 pragma Inline (In_Entity_Map);
18676 -- Determine whether entity Id is one of the old ids specified in entity
18677 -- map Entity_Map. The format of the entity map must be as follows:
18679 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
18681 procedure Update_CFS_Sloc (N : Node_Or_Entity_Id);
18682 pragma Inline (Update_CFS_Sloc);
18683 -- Update the Comes_From_Source and Sloc attributes of node or entity N
18685 procedure Update_First_Real_Statement
18686 (Old_HSS : Node_Id;
18687 New_HSS : Node_Id);
18688 pragma Inline (Update_First_Real_Statement);
18689 -- Update semantic attribute First_Real_Statement of handled sequence of
18690 -- statements New_HSS based on handled sequence of statements Old_HSS.
18692 procedure Update_Named_Associations
18693 (Old_Call : Node_Id;
18694 New_Call : Node_Id);
18695 pragma Inline (Update_Named_Associations);
18696 -- Update semantic chain First/Next_Named_Association of call New_call
18697 -- based on call Old_Call.
18699 procedure Update_New_Entities (Entity_Map : Elist_Id);
18700 pragma Inline (Update_New_Entities);
18701 -- Update the semantic attributes of all new entities generated during
18702 -- Phase 1 that do not appear in entity map Entity_Map. The format of
18703 -- the entity map must be as follows:
18705 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
18707 procedure Update_Pending_Itypes
18708 (Old_Assoc : Node_Id;
18709 New_Assoc : Node_Id);
18710 pragma Inline (Update_Pending_Itypes);
18711 -- Update semantic attribute Associated_Node_For_Itype to refer to node
18712 -- New_Assoc for all itypes whose associated node is Old_Assoc.
18714 procedure Update_Semantic_Fields (Id : Entity_Id);
18715 pragma Inline (Update_Semantic_Fields);
18716 -- Subsidiary to Update_New_Entities. Update semantic fields of entity
18717 -- or itype Id.
18719 procedure Visit_Any_Node (N : Node_Or_Entity_Id);
18720 pragma Inline (Visit_Any_Node);
18721 -- Visit entity of node N by invoking one of the following routines:
18723 -- Visit_Entity
18724 -- Visit_Itype
18725 -- Visit_Node
18727 procedure Visit_Elist (List : Elist_Id);
18728 -- Visit the elements of entity list List
18730 procedure Visit_Entity (Id : Entity_Id);
18731 -- Visit entity Id. This action may create a new entity of Id and save
18732 -- it in table NCT_New_Entities.
18734 procedure Visit_Field
18735 (Field : Union_Id;
18736 Par_Nod : Node_Id := Empty;
18737 Semantic : Boolean := False);
18738 -- Visit field Field by invoking one of the following routines:
18740 -- Visit_Elist
18741 -- Visit_Entity
18742 -- Visit_Itype
18743 -- Visit_List
18744 -- Visit_Node
18746 -- If the field is not an entity list, entity, itype, syntactic list,
18747 -- or node, then the field is not visited. The routine always visits
18748 -- valid syntactic fields. Par_Nod is the expected parent of the
18749 -- syntactic field. Flag Semantic should be set when the input is a
18750 -- semantic field.
18752 procedure Visit_Itype (Itype : Entity_Id);
18753 -- Visit itype Itype. This action may create a new entity for Itype and
18754 -- save it in table NCT_New_Entities. In addition, the routine may map
18755 -- the associated node of Itype to the new itype in NCT_Pending_Itypes.
18757 procedure Visit_List (List : List_Id);
18758 -- Visit the elements of syntactic list List
18760 procedure Visit_Node (N : Node_Id);
18761 -- Visit node N
18763 procedure Visit_Semantic_Fields (Id : Entity_Id);
18764 pragma Inline (Visit_Semantic_Fields);
18765 -- Subsidiary to Visit_Entity and Visit_Itype. Visit common semantic
18766 -- fields of entity or itype Id.
18768 --------------------
18769 -- Add_New_Entity --
18770 --------------------
18772 procedure Add_New_Entity (Old_Id : Entity_Id; New_Id : Entity_Id) is
18773 begin
18774 pragma Assert (Present (Old_Id));
18775 pragma Assert (Present (New_Id));
18776 pragma Assert (Nkind (Old_Id) in N_Entity);
18777 pragma Assert (Nkind (New_Id) in N_Entity);
18779 NCT_Tables_In_Use := True;
18781 -- Sanity check the NCT_New_Entities table. No previous mapping with
18782 -- key Old_Id should exist.
18784 pragma Assert (No (NCT_New_Entities.Get (Old_Id)));
18786 -- Establish the mapping
18788 -- Old_Id -> New_Id
18790 NCT_New_Entities.Set (Old_Id, New_Id);
18791 end Add_New_Entity;
18793 -----------------------
18794 -- Add_Pending_Itype --
18795 -----------------------
18797 procedure Add_Pending_Itype (Assoc_Nod : Node_Id; Itype : Entity_Id) is
18798 Itypes : Elist_Id;
18800 begin
18801 pragma Assert (Present (Assoc_Nod));
18802 pragma Assert (Present (Itype));
18803 pragma Assert (Nkind (Itype) in N_Entity);
18804 pragma Assert (Is_Itype (Itype));
18806 NCT_Tables_In_Use := True;
18808 -- It is not possible to sanity check the NCT_Pendint_Itypes table
18809 -- directly because a single node may act as the associated node for
18810 -- multiple itypes.
18812 Itypes := NCT_Pending_Itypes.Get (Assoc_Nod);
18814 if No (Itypes) then
18815 Itypes := New_Elmt_List;
18816 NCT_Pending_Itypes.Set (Assoc_Nod, Itypes);
18817 end if;
18819 -- Establish the mapping
18821 -- Assoc_Nod -> (Itype, ...)
18823 -- Avoid inserting the same itype multiple times. This involves a
18824 -- linear search, however the set of itypes with the same associated
18825 -- node is very small.
18827 Append_Unique_Elmt (Itype, Itypes);
18828 end Add_Pending_Itype;
18830 ----------------------
18831 -- Build_NCT_Tables --
18832 ----------------------
18834 procedure Build_NCT_Tables (Entity_Map : Elist_Id) is
18835 Elmt : Elmt_Id;
18836 Old_Id : Entity_Id;
18837 New_Id : Entity_Id;
18839 begin
18840 -- Nothing to do when there is no entity map
18842 if No (Entity_Map) then
18843 return;
18844 end if;
18846 Elmt := First_Elmt (Entity_Map);
18847 while Present (Elmt) loop
18849 -- Extract the (Old_Id, New_Id) pair from the entity map
18851 Old_Id := Node (Elmt);
18852 Next_Elmt (Elmt);
18854 New_Id := Node (Elmt);
18855 Next_Elmt (Elmt);
18857 -- Establish the following mapping within table NCT_New_Entities
18859 -- Old_Id -> New_Id
18861 Add_New_Entity (Old_Id, New_Id);
18863 -- Establish the following mapping within table NCT_Pending_Itypes
18864 -- when the new entity is an itype.
18866 -- Assoc_Nod -> (New_Id, ...)
18868 -- IMPORTANT: the associated node is that of the old itype because
18869 -- the node will be replicated in Phase 2.
18871 if Is_Itype (Old_Id) then
18872 Add_Pending_Itype
18873 (Assoc_Nod => Associated_Node_For_Itype (Old_Id),
18874 Itype => New_Id);
18875 end if;
18876 end loop;
18877 end Build_NCT_Tables;
18879 ------------------------------------
18880 -- Copy_Any_Node_With_Replacement --
18881 ------------------------------------
18883 function Copy_Any_Node_With_Replacement
18884 (N : Node_Or_Entity_Id) return Node_Or_Entity_Id
18886 begin
18887 if Nkind (N) in N_Entity then
18888 return Corresponding_Entity (N);
18889 else
18890 return Copy_Node_With_Replacement (N);
18891 end if;
18892 end Copy_Any_Node_With_Replacement;
18894 ---------------------------------
18895 -- Copy_Elist_With_Replacement --
18896 ---------------------------------
18898 function Copy_Elist_With_Replacement (List : Elist_Id) return Elist_Id is
18899 Elmt : Elmt_Id;
18900 Result : Elist_Id;
18902 begin
18903 -- Copy the contents of the old list. Note that the list itself may
18904 -- be empty, in which case the routine returns a new empty list. This
18905 -- avoids sharing lists between subtrees. The element of an entity
18906 -- list could be an entity or a node, hence the invocation of routine
18907 -- Copy_Any_Node_With_Replacement.
18909 if Present (List) then
18910 Result := New_Elmt_List;
18912 Elmt := First_Elmt (List);
18913 while Present (Elmt) loop
18914 Append_Elmt
18915 (Copy_Any_Node_With_Replacement (Node (Elmt)), Result);
18917 Next_Elmt (Elmt);
18918 end loop;
18920 -- Otherwise the list does not exist
18922 else
18923 Result := No_Elist;
18924 end if;
18926 return Result;
18927 end Copy_Elist_With_Replacement;
18929 ---------------------------------
18930 -- Copy_Field_With_Replacement --
18931 ---------------------------------
18933 function Copy_Field_With_Replacement
18934 (Field : Union_Id;
18935 Old_Par : Node_Id := Empty;
18936 New_Par : Node_Id := Empty;
18937 Semantic : Boolean := False) return Union_Id
18939 begin
18940 -- The field is empty
18942 if Field = Union_Id (Empty) then
18943 return Field;
18945 -- The field is an entity/itype/node
18947 elsif Field in Node_Range then
18948 declare
18949 Old_N : constant Node_Id := Node_Id (Field);
18950 Syntactic : constant Boolean := Parent (Old_N) = Old_Par;
18952 New_N : Node_Id;
18954 begin
18955 -- The field is an entity/itype
18957 if Nkind (Old_N) in N_Entity then
18959 -- An entity/itype is always replicated
18961 New_N := Corresponding_Entity (Old_N);
18963 -- Update the parent pointer when the entity is a syntactic
18964 -- field. Note that itypes do not have parent pointers.
18966 if Syntactic and then New_N /= Old_N then
18967 Set_Parent (New_N, New_Par);
18968 end if;
18970 -- The field is a node
18972 else
18973 -- A node is replicated when it is either a syntactic field
18974 -- or when the caller treats it as a semantic attribute.
18976 if Syntactic or else Semantic then
18977 New_N := Copy_Node_With_Replacement (Old_N);
18979 -- Update the parent pointer when the node is a syntactic
18980 -- field.
18982 if Syntactic and then New_N /= Old_N then
18983 Set_Parent (New_N, New_Par);
18984 end if;
18986 -- Otherwise the node is returned unchanged
18988 else
18989 New_N := Old_N;
18990 end if;
18991 end if;
18993 return Union_Id (New_N);
18994 end;
18996 -- The field is an entity list
18998 elsif Field in Elist_Range then
18999 return Union_Id (Copy_Elist_With_Replacement (Elist_Id (Field)));
19001 -- The field is a syntactic list
19003 elsif Field in List_Range then
19004 declare
19005 Old_List : constant List_Id := List_Id (Field);
19006 Syntactic : constant Boolean := Parent (Old_List) = Old_Par;
19008 New_List : List_Id;
19010 begin
19011 -- A list is replicated when it is either a syntactic field or
19012 -- when the caller treats it as a semantic attribute.
19014 if Syntactic or else Semantic then
19015 New_List := Copy_List_With_Replacement (Old_List);
19017 -- Update the parent pointer when the list is a syntactic
19018 -- field.
19020 if Syntactic and then New_List /= Old_List then
19021 Set_Parent (New_List, New_Par);
19022 end if;
19024 -- Otherwise the list is returned unchanged
19026 else
19027 New_List := Old_List;
19028 end if;
19030 return Union_Id (New_List);
19031 end;
19033 -- Otherwise the field denotes an attribute that does not need to be
19034 -- replicated (Chars, literals, etc).
19036 else
19037 return Field;
19038 end if;
19039 end Copy_Field_With_Replacement;
19041 --------------------------------
19042 -- Copy_List_With_Replacement --
19043 --------------------------------
19045 function Copy_List_With_Replacement (List : List_Id) return List_Id is
19046 Elmt : Node_Id;
19047 Result : List_Id;
19049 begin
19050 -- Copy the contents of the old list. Note that the list itself may
19051 -- be empty, in which case the routine returns a new empty list. This
19052 -- avoids sharing lists between subtrees. The element of a syntactic
19053 -- list is always a node, never an entity or itype, hence the call to
19054 -- routine Copy_Node_With_Replacement.
19056 if Present (List) then
19057 Result := New_List;
19059 Elmt := First (List);
19060 while Present (Elmt) loop
19061 Append (Copy_Node_With_Replacement (Elmt), Result);
19063 Next (Elmt);
19064 end loop;
19066 -- Otherwise the list does not exist
19068 else
19069 Result := No_List;
19070 end if;
19072 return Result;
19073 end Copy_List_With_Replacement;
19075 --------------------------------
19076 -- Copy_Node_With_Replacement --
19077 --------------------------------
19079 function Copy_Node_With_Replacement (N : Node_Id) return Node_Id is
19080 Result : Node_Id;
19082 begin
19083 -- Assume that the node must be returned unchanged
19085 Result := N;
19087 if N > Empty_Or_Error then
19088 pragma Assert (Nkind (N) not in N_Entity);
19090 Result := New_Copy (N);
19092 Set_Field1 (Result,
19093 Copy_Field_With_Replacement
19094 (Field => Field1 (Result),
19095 Old_Par => N,
19096 New_Par => Result));
19098 Set_Field2 (Result,
19099 Copy_Field_With_Replacement
19100 (Field => Field2 (Result),
19101 Old_Par => N,
19102 New_Par => Result));
19104 Set_Field3 (Result,
19105 Copy_Field_With_Replacement
19106 (Field => Field3 (Result),
19107 Old_Par => N,
19108 New_Par => Result));
19110 Set_Field4 (Result,
19111 Copy_Field_With_Replacement
19112 (Field => Field4 (Result),
19113 Old_Par => N,
19114 New_Par => Result));
19116 Set_Field5 (Result,
19117 Copy_Field_With_Replacement
19118 (Field => Field5 (Result),
19119 Old_Par => N,
19120 New_Par => Result));
19122 -- Update the Comes_From_Source and Sloc attributes of the node
19123 -- in case the caller has supplied new values.
19125 Update_CFS_Sloc (Result);
19127 -- Update the Associated_Node_For_Itype attribute of all itypes
19128 -- created during Phase 1 whose associated node is N. As a result
19129 -- the Associated_Node_For_Itype refers to the replicated node.
19130 -- No action needs to be taken when the Associated_Node_For_Itype
19131 -- refers to an entity because this was already handled during
19132 -- Phase 1, in Visit_Itype.
19134 Update_Pending_Itypes
19135 (Old_Assoc => N,
19136 New_Assoc => Result);
19138 -- Update the First/Next_Named_Association chain for a replicated
19139 -- call.
19141 if Nkind_In (N, N_Entry_Call_Statement,
19142 N_Function_Call,
19143 N_Procedure_Call_Statement)
19144 then
19145 Update_Named_Associations
19146 (Old_Call => N,
19147 New_Call => Result);
19149 -- Update the Renamed_Object attribute of a replicated object
19150 -- declaration.
19152 elsif Nkind (N) = N_Object_Renaming_Declaration then
19153 Set_Renamed_Object (Defining_Entity (Result), Name (Result));
19155 -- Update the First_Real_Statement attribute of a replicated
19156 -- handled sequence of statements.
19158 elsif Nkind (N) = N_Handled_Sequence_Of_Statements then
19159 Update_First_Real_Statement
19160 (Old_HSS => N,
19161 New_HSS => Result);
19162 end if;
19163 end if;
19165 return Result;
19166 end Copy_Node_With_Replacement;
19168 --------------------------
19169 -- Corresponding_Entity --
19170 --------------------------
19172 function Corresponding_Entity (Id : Entity_Id) return Entity_Id is
19173 New_Id : Entity_Id;
19174 Result : Entity_Id;
19176 begin
19177 -- Assume that the entity must be returned unchanged
19179 Result := Id;
19181 if Id > Empty_Or_Error then
19182 pragma Assert (Nkind (Id) in N_Entity);
19184 -- Determine whether the entity has a corresponding new entity
19185 -- generated during Phase 1 and if it does, use it.
19187 if NCT_Tables_In_Use then
19188 New_Id := NCT_New_Entities.Get (Id);
19190 if Present (New_Id) then
19191 Result := New_Id;
19192 end if;
19193 end if;
19194 end if;
19196 return Result;
19197 end Corresponding_Entity;
19199 -------------------
19200 -- In_Entity_Map --
19201 -------------------
19203 function In_Entity_Map
19204 (Id : Entity_Id;
19205 Entity_Map : Elist_Id) return Boolean
19207 Elmt : Elmt_Id;
19208 Old_Id : Entity_Id;
19210 begin
19211 -- The entity map contains pairs (Old_Id, New_Id). The advancement
19212 -- step always skips the New_Id portion of the pair.
19214 if Present (Entity_Map) then
19215 Elmt := First_Elmt (Entity_Map);
19216 while Present (Elmt) loop
19217 Old_Id := Node (Elmt);
19219 if Old_Id = Id then
19220 return True;
19221 end if;
19223 Next_Elmt (Elmt);
19224 Next_Elmt (Elmt);
19225 end loop;
19226 end if;
19228 return False;
19229 end In_Entity_Map;
19231 ---------------------
19232 -- Update_CFS_Sloc --
19233 ---------------------
19235 procedure Update_CFS_Sloc (N : Node_Or_Entity_Id) is
19236 begin
19237 -- A new source location defaults the Comes_From_Source attribute
19239 if New_Sloc /= No_Location then
19240 Set_Comes_From_Source (N, Default_Node.Comes_From_Source);
19241 Set_Sloc (N, New_Sloc);
19242 end if;
19243 end Update_CFS_Sloc;
19245 ---------------------------------
19246 -- Update_First_Real_Statement --
19247 ---------------------------------
19249 procedure Update_First_Real_Statement
19250 (Old_HSS : Node_Id;
19251 New_HSS : Node_Id)
19253 Old_First_Stmt : constant Node_Id := First_Real_Statement (Old_HSS);
19255 New_Stmt : Node_Id;
19256 Old_Stmt : Node_Id;
19258 begin
19259 -- Recreate the First_Real_Statement attribute of a handled sequence
19260 -- of statements by traversing the statement lists of both sequences
19261 -- in parallel.
19263 if Present (Old_First_Stmt) then
19264 New_Stmt := First (Statements (New_HSS));
19265 Old_Stmt := First (Statements (Old_HSS));
19266 while Present (Old_Stmt) and then Old_Stmt /= Old_First_Stmt loop
19267 Next (New_Stmt);
19268 Next (Old_Stmt);
19269 end loop;
19271 pragma Assert (Present (New_Stmt));
19272 pragma Assert (Present (Old_Stmt));
19274 Set_First_Real_Statement (New_HSS, New_Stmt);
19275 end if;
19276 end Update_First_Real_Statement;
19278 -------------------------------
19279 -- Update_Named_Associations --
19280 -------------------------------
19282 procedure Update_Named_Associations
19283 (Old_Call : Node_Id;
19284 New_Call : Node_Id)
19286 New_Act : Node_Id;
19287 New_Next : Node_Id;
19288 Old_Act : Node_Id;
19289 Old_Next : Node_Id;
19291 begin
19292 -- Recreate the First/Next_Named_Actual chain of a call by traversing
19293 -- the chains of both the old and new calls in parallel.
19295 New_Act := First (Parameter_Associations (New_Call));
19296 Old_Act := First (Parameter_Associations (Old_Call));
19297 while Present (Old_Act) loop
19298 if Nkind (Old_Act) = N_Parameter_Association
19299 and then Present (Next_Named_Actual (Old_Act))
19300 then
19301 if First_Named_Actual (Old_Call) =
19302 Explicit_Actual_Parameter (Old_Act)
19303 then
19304 Set_First_Named_Actual (New_Call,
19305 Explicit_Actual_Parameter (New_Act));
19306 end if;
19308 -- Scan the actual parameter list to find the next suitable
19309 -- named actual. Note that the list may be out of order.
19311 New_Next := First (Parameter_Associations (New_Call));
19312 Old_Next := First (Parameter_Associations (Old_Call));
19313 while Nkind (Old_Next) /= N_Parameter_Association
19314 or else Explicit_Actual_Parameter (Old_Next) /=
19315 Next_Named_Actual (Old_Act)
19316 loop
19317 Next (New_Next);
19318 Next (Old_Next);
19319 end loop;
19321 Set_Next_Named_Actual (New_Act,
19322 Explicit_Actual_Parameter (New_Next));
19323 end if;
19325 Next (New_Act);
19326 Next (Old_Act);
19327 end loop;
19328 end Update_Named_Associations;
19330 -------------------------
19331 -- Update_New_Entities --
19332 -------------------------
19334 procedure Update_New_Entities (Entity_Map : Elist_Id) is
19335 New_Id : Entity_Id := Empty;
19336 Old_Id : Entity_Id := Empty;
19338 begin
19339 if NCT_Tables_In_Use then
19340 NCT_New_Entities.Get_First (Old_Id, New_Id);
19342 -- Update the semantic fields of all new entities created during
19343 -- Phase 1 which were not supplied via an entity map.
19344 -- ??? Is there a better way of distinguishing those?
19346 while Present (Old_Id) and then Present (New_Id) loop
19347 if not (Present (Entity_Map)
19348 and then In_Entity_Map (Old_Id, Entity_Map))
19349 then
19350 Update_Semantic_Fields (New_Id);
19351 end if;
19353 NCT_New_Entities.Get_Next (Old_Id, New_Id);
19354 end loop;
19355 end if;
19356 end Update_New_Entities;
19358 ---------------------------
19359 -- Update_Pending_Itypes --
19360 ---------------------------
19362 procedure Update_Pending_Itypes
19363 (Old_Assoc : Node_Id;
19364 New_Assoc : Node_Id)
19366 Item : Elmt_Id;
19367 Itypes : Elist_Id;
19369 begin
19370 if NCT_Tables_In_Use then
19371 Itypes := NCT_Pending_Itypes.Get (Old_Assoc);
19373 -- Update the Associated_Node_For_Itype attribute for all itypes
19374 -- which originally refer to Old_Assoc to designate New_Assoc.
19376 if Present (Itypes) then
19377 Item := First_Elmt (Itypes);
19378 while Present (Item) loop
19379 Set_Associated_Node_For_Itype (Node (Item), New_Assoc);
19381 Next_Elmt (Item);
19382 end loop;
19383 end if;
19384 end if;
19385 end Update_Pending_Itypes;
19387 ----------------------------
19388 -- Update_Semantic_Fields --
19389 ----------------------------
19391 procedure Update_Semantic_Fields (Id : Entity_Id) is
19392 begin
19393 -- Discriminant_Constraint
19395 if Has_Discriminants (Base_Type (Id)) then
19396 Set_Discriminant_Constraint (Id, Elist_Id (
19397 Copy_Field_With_Replacement
19398 (Field => Union_Id (Discriminant_Constraint (Id)),
19399 Semantic => True)));
19400 end if;
19402 -- Etype
19404 Set_Etype (Id, Node_Id (
19405 Copy_Field_With_Replacement
19406 (Field => Union_Id (Etype (Id)),
19407 Semantic => True)));
19409 -- First_Index
19410 -- Packed_Array_Impl_Type
19412 if Is_Array_Type (Id) then
19413 if Present (First_Index (Id)) then
19414 Set_First_Index (Id, First (List_Id (
19415 Copy_Field_With_Replacement
19416 (Field => Union_Id (List_Containing (First_Index (Id))),
19417 Semantic => True))));
19418 end if;
19420 if Is_Packed (Id) then
19421 Set_Packed_Array_Impl_Type (Id, Node_Id (
19422 Copy_Field_With_Replacement
19423 (Field => Union_Id (Packed_Array_Impl_Type (Id)),
19424 Semantic => True)));
19425 end if;
19426 end if;
19428 -- Next_Entity
19430 Set_Next_Entity (Id, Node_Id (
19431 Copy_Field_With_Replacement
19432 (Field => Union_Id (Next_Entity (Id)),
19433 Semantic => True)));
19435 -- Scalar_Range
19437 if Is_Discrete_Type (Id) then
19438 Set_Scalar_Range (Id, Node_Id (
19439 Copy_Field_With_Replacement
19440 (Field => Union_Id (Scalar_Range (Id)),
19441 Semantic => True)));
19442 end if;
19444 -- Scope
19446 -- Update the scope when the caller specified an explicit one
19448 if Present (New_Scope) then
19449 Set_Scope (Id, New_Scope);
19450 else
19451 Set_Scope (Id, Node_Id (
19452 Copy_Field_With_Replacement
19453 (Field => Union_Id (Scope (Id)),
19454 Semantic => True)));
19455 end if;
19456 end Update_Semantic_Fields;
19458 --------------------
19459 -- Visit_Any_Node --
19460 --------------------
19462 procedure Visit_Any_Node (N : Node_Or_Entity_Id) is
19463 begin
19464 if Nkind (N) in N_Entity then
19465 if Is_Itype (N) then
19466 Visit_Itype (N);
19467 else
19468 Visit_Entity (N);
19469 end if;
19470 else
19471 Visit_Node (N);
19472 end if;
19473 end Visit_Any_Node;
19475 -----------------
19476 -- Visit_Elist --
19477 -----------------
19479 procedure Visit_Elist (List : Elist_Id) is
19480 Elmt : Elmt_Id;
19482 begin
19483 -- The element of an entity list could be an entity, itype, or a
19484 -- node, hence the call to Visit_Any_Node.
19486 if Present (List) then
19487 Elmt := First_Elmt (List);
19488 while Present (Elmt) loop
19489 Visit_Any_Node (Node (Elmt));
19491 Next_Elmt (Elmt);
19492 end loop;
19493 end if;
19494 end Visit_Elist;
19496 ------------------
19497 -- Visit_Entity --
19498 ------------------
19500 procedure Visit_Entity (Id : Entity_Id) is
19501 New_Id : Entity_Id;
19503 begin
19504 pragma Assert (Nkind (Id) in N_Entity);
19505 pragma Assert (not Is_Itype (Id));
19507 -- Nothing to do if the entity is not defined in the Actions list of
19508 -- an N_Expression_With_Actions node.
19510 if EWA_Level = 0 then
19511 return;
19513 -- Nothing to do if the entity is defined within a scoping construct
19514 -- of an N_Expression_With_Actions node.
19516 elsif EWA_Inner_Scope_Level > 0 then
19517 return;
19519 -- Nothing to do if the entity is not an object or a type. Relaxing
19520 -- this restriction leads to a performance penalty.
19522 elsif not Ekind_In (Id, E_Constant, E_Variable)
19523 and then not Is_Type (Id)
19524 then
19525 return;
19527 -- Nothing to do if the entity was already visited
19529 elsif NCT_Tables_In_Use
19530 and then Present (NCT_New_Entities.Get (Id))
19531 then
19532 return;
19534 -- Nothing to do if the declaration node of the entity is not within
19535 -- the subtree being replicated.
19537 elsif not In_Subtree
19538 (N => Declaration_Node (Id),
19539 Root => Source)
19540 then
19541 return;
19542 end if;
19544 -- Create a new entity by directly copying the old entity. This
19545 -- action causes all attributes of the old entity to be inherited.
19547 New_Id := New_Copy (Id);
19549 -- Create a new name for the new entity because the back end needs
19550 -- distinct names for debugging purposes.
19552 Set_Chars (New_Id, New_Internal_Name ('T'));
19554 -- Update the Comes_From_Source and Sloc attributes of the entity in
19555 -- case the caller has supplied new values.
19557 Update_CFS_Sloc (New_Id);
19559 -- Establish the following mapping within table NCT_New_Entities:
19561 -- Id -> New_Id
19563 Add_New_Entity (Id, New_Id);
19565 -- Deal with the semantic fields of entities. The fields are visited
19566 -- because they may mention entities which reside within the subtree
19567 -- being copied.
19569 Visit_Semantic_Fields (Id);
19570 end Visit_Entity;
19572 -----------------
19573 -- Visit_Field --
19574 -----------------
19576 procedure Visit_Field
19577 (Field : Union_Id;
19578 Par_Nod : Node_Id := Empty;
19579 Semantic : Boolean := False)
19581 begin
19582 -- The field is empty
19584 if Field = Union_Id (Empty) then
19585 return;
19587 -- The field is an entity/itype/node
19589 elsif Field in Node_Range then
19590 declare
19591 N : constant Node_Id := Node_Id (Field);
19593 begin
19594 -- The field is an entity/itype
19596 if Nkind (N) in N_Entity then
19598 -- Itypes are always visited
19600 if Is_Itype (N) then
19601 Visit_Itype (N);
19603 -- An entity is visited when it is either a syntactic field
19604 -- or when the caller treats it as a semantic attribute.
19606 elsif Parent (N) = Par_Nod or else Semantic then
19607 Visit_Entity (N);
19608 end if;
19610 -- The field is a node
19612 else
19613 -- A node is visited when it is either a syntactic field or
19614 -- when the caller treats it as a semantic attribute.
19616 if Parent (N) = Par_Nod or else Semantic then
19617 Visit_Node (N);
19618 end if;
19619 end if;
19620 end;
19622 -- The field is an entity list
19624 elsif Field in Elist_Range then
19625 Visit_Elist (Elist_Id (Field));
19627 -- The field is a syntax list
19629 elsif Field in List_Range then
19630 declare
19631 List : constant List_Id := List_Id (Field);
19633 begin
19634 -- A syntax list is visited when it is either a syntactic field
19635 -- or when the caller treats it as a semantic attribute.
19637 if Parent (List) = Par_Nod or else Semantic then
19638 Visit_List (List);
19639 end if;
19640 end;
19642 -- Otherwise the field denotes information which does not need to be
19643 -- visited (chars, literals, etc.).
19645 else
19646 null;
19647 end if;
19648 end Visit_Field;
19650 -----------------
19651 -- Visit_Itype --
19652 -----------------
19654 procedure Visit_Itype (Itype : Entity_Id) is
19655 New_Assoc : Node_Id;
19656 New_Itype : Entity_Id;
19657 Old_Assoc : Node_Id;
19659 begin
19660 pragma Assert (Nkind (Itype) in N_Entity);
19661 pragma Assert (Is_Itype (Itype));
19663 -- Itypes that describe the designated type of access to subprograms
19664 -- have the structure of subprogram declarations, with signatures,
19665 -- etc. Either we duplicate the signatures completely, or choose to
19666 -- share such itypes, which is fine because their elaboration will
19667 -- have no side effects.
19669 if Ekind (Itype) = E_Subprogram_Type then
19670 return;
19672 -- Nothing to do if the itype was already visited
19674 elsif NCT_Tables_In_Use
19675 and then Present (NCT_New_Entities.Get (Itype))
19676 then
19677 return;
19679 -- Nothing to do if the associated node of the itype is not within
19680 -- the subtree being replicated.
19682 elsif not In_Subtree
19683 (N => Associated_Node_For_Itype (Itype),
19684 Root => Source)
19685 then
19686 return;
19687 end if;
19689 -- Create a new itype by directly copying the old itype. This action
19690 -- causes all attributes of the old itype to be inherited.
19692 New_Itype := New_Copy (Itype);
19694 -- Create a new name for the new itype because the back end requires
19695 -- distinct names for debugging purposes.
19697 Set_Chars (New_Itype, New_Internal_Name ('T'));
19699 -- Update the Comes_From_Source and Sloc attributes of the itype in
19700 -- case the caller has supplied new values.
19702 Update_CFS_Sloc (New_Itype);
19704 -- Establish the following mapping within table NCT_New_Entities:
19706 -- Itype -> New_Itype
19708 Add_New_Entity (Itype, New_Itype);
19710 -- The new itype must be unfrozen because the resulting subtree may
19711 -- be inserted anywhere and cause an earlier or later freezing.
19713 if Present (Freeze_Node (New_Itype)) then
19714 Set_Freeze_Node (New_Itype, Empty);
19715 Set_Is_Frozen (New_Itype, False);
19716 end if;
19718 -- If a record subtype is simply copied, the entity list will be
19719 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
19720 -- ??? What does this do?
19722 if Ekind_In (Itype, E_Class_Wide_Subtype, E_Record_Subtype) then
19723 Set_Cloned_Subtype (New_Itype, Itype);
19724 end if;
19726 -- The associated node may denote an entity, in which case it may
19727 -- already have a new corresponding entity created during a prior
19728 -- call to Visit_Entity or Visit_Itype for the same subtree.
19730 -- Given
19731 -- Old_Assoc ---------> New_Assoc
19733 -- Created by Visit_Itype
19734 -- Itype -------------> New_Itype
19735 -- ANFI = Old_Assoc ANFI = Old_Assoc < must be updated
19737 -- In the example above, Old_Assoc is an arbitrary entity that was
19738 -- already visited for the same subtree and has a corresponding new
19739 -- entity New_Assoc. Old_Assoc was inherited by New_Itype by virtue
19740 -- of copying entities, however it must be updated to New_Assoc.
19742 Old_Assoc := Associated_Node_For_Itype (Itype);
19744 if Nkind (Old_Assoc) in N_Entity then
19745 if NCT_Tables_In_Use then
19746 New_Assoc := NCT_New_Entities.Get (Old_Assoc);
19748 if Present (New_Assoc) then
19749 Set_Associated_Node_For_Itype (New_Itype, New_Assoc);
19750 end if;
19751 end if;
19753 -- Otherwise the associated node denotes a node. Postpone the update
19754 -- until Phase 2 when the node is replicated. Establish the following
19755 -- mapping within table NCT_Pending_Itypes:
19757 -- Old_Assoc -> (New_Type, ...)
19759 else
19760 Add_Pending_Itype (Old_Assoc, New_Itype);
19761 end if;
19763 -- Deal with the semantic fields of itypes. The fields are visited
19764 -- because they may mention entities that reside within the subtree
19765 -- being copied.
19767 Visit_Semantic_Fields (Itype);
19768 end Visit_Itype;
19770 ----------------
19771 -- Visit_List --
19772 ----------------
19774 procedure Visit_List (List : List_Id) is
19775 Elmt : Node_Id;
19777 begin
19778 -- Note that the element of a syntactic list is always a node, never
19779 -- an entity or itype, hence the call to Visit_Node.
19781 if Present (List) then
19782 Elmt := First (List);
19783 while Present (Elmt) loop
19784 Visit_Node (Elmt);
19786 Next (Elmt);
19787 end loop;
19788 end if;
19789 end Visit_List;
19791 ----------------
19792 -- Visit_Node --
19793 ----------------
19795 procedure Visit_Node (N : Node_Or_Entity_Id) is
19796 begin
19797 pragma Assert (Nkind (N) not in N_Entity);
19799 if Nkind (N) = N_Expression_With_Actions then
19800 EWA_Level := EWA_Level + 1;
19802 elsif EWA_Level > 0
19803 and then Nkind_In (N, N_Block_Statement,
19804 N_Subprogram_Body,
19805 N_Subprogram_Declaration)
19806 then
19807 EWA_Inner_Scope_Level := EWA_Inner_Scope_Level + 1;
19808 end if;
19810 Visit_Field
19811 (Field => Field1 (N),
19812 Par_Nod => N);
19814 Visit_Field
19815 (Field => Field2 (N),
19816 Par_Nod => N);
19818 Visit_Field
19819 (Field => Field3 (N),
19820 Par_Nod => N);
19822 Visit_Field
19823 (Field => Field4 (N),
19824 Par_Nod => N);
19826 Visit_Field
19827 (Field => Field5 (N),
19828 Par_Nod => N);
19830 if EWA_Level > 0
19831 and then Nkind_In (N, N_Block_Statement,
19832 N_Subprogram_Body,
19833 N_Subprogram_Declaration)
19834 then
19835 EWA_Inner_Scope_Level := EWA_Inner_Scope_Level - 1;
19837 elsif Nkind (N) = N_Expression_With_Actions then
19838 EWA_Level := EWA_Level - 1;
19839 end if;
19840 end Visit_Node;
19842 ---------------------------
19843 -- Visit_Semantic_Fields --
19844 ---------------------------
19846 procedure Visit_Semantic_Fields (Id : Entity_Id) is
19847 begin
19848 pragma Assert (Nkind (Id) in N_Entity);
19850 -- Discriminant_Constraint
19852 if Has_Discriminants (Base_Type (Id)) then
19853 Visit_Field
19854 (Field => Union_Id (Discriminant_Constraint (Id)),
19855 Semantic => True);
19856 end if;
19858 -- Etype
19860 Visit_Field
19861 (Field => Union_Id (Etype (Id)),
19862 Semantic => True);
19864 -- First_Index
19865 -- Packed_Array_Impl_Type
19867 if Is_Array_Type (Id) then
19868 if Present (First_Index (Id)) then
19869 Visit_Field
19870 (Field => Union_Id (List_Containing (First_Index (Id))),
19871 Semantic => True);
19872 end if;
19874 if Is_Packed (Id) then
19875 Visit_Field
19876 (Field => Union_Id (Packed_Array_Impl_Type (Id)),
19877 Semantic => True);
19878 end if;
19879 end if;
19881 -- Scalar_Range
19883 if Is_Discrete_Type (Id) then
19884 Visit_Field
19885 (Field => Union_Id (Scalar_Range (Id)),
19886 Semantic => True);
19887 end if;
19888 end Visit_Semantic_Fields;
19890 -- Start of processing for New_Copy_Tree
19892 begin
19893 -- Routine New_Copy_Tree performs a deep copy of a subtree by creating
19894 -- shallow copies for each node within, and then updating the child and
19895 -- parent pointers accordingly. This process is straightforward, however
19896 -- the routine must deal with the following complications:
19898 -- * Entities defined within N_Expression_With_Actions nodes must be
19899 -- replicated rather than shared to avoid introducing two identical
19900 -- symbols within the same scope. Note that no other expression can
19901 -- currently define entities.
19903 -- do
19904 -- Source_Low : ...;
19905 -- Source_High : ...;
19907 -- <reference to Source_Low>
19908 -- <reference to Source_High>
19909 -- in ... end;
19911 -- New_Copy_Tree handles this case by first creating new entities
19912 -- and then updating all existing references to point to these new
19913 -- entities.
19915 -- do
19916 -- New_Low : ...;
19917 -- New_High : ...;
19919 -- <reference to New_Low>
19920 -- <reference to New_High>
19921 -- in ... end;
19923 -- * Itypes defined within the subtree must be replicated to avoid any
19924 -- dependencies on invalid or inaccessible data.
19926 -- subtype Source_Itype is ... range Source_Low .. Source_High;
19928 -- New_Copy_Tree handles this case by first creating a new itype in
19929 -- the same fashion as entities, and then updating various relevant
19930 -- constraints.
19932 -- subtype New_Itype is ... range New_Low .. New_High;
19934 -- * The Associated_Node_For_Itype field of itypes must be updated to
19935 -- reference the proper replicated entity or node.
19937 -- * Semantic fields of entities such as Etype and Scope must be
19938 -- updated to reference the proper replicated entities.
19940 -- * Semantic fields of nodes such as First_Real_Statement must be
19941 -- updated to reference the proper replicated nodes.
19943 -- To meet all these demands, routine New_Copy_Tree is split into two
19944 -- phases.
19946 -- Phase 1 traverses the tree in order to locate entities and itypes
19947 -- defined within the subtree. New entities are generated and saved in
19948 -- table NCT_New_Entities. The semantic fields of all new entities and
19949 -- itypes are then updated accordingly.
19951 -- Phase 2 traverses the tree in order to replicate each node. Various
19952 -- semantic fields of nodes and entities are updated accordingly.
19954 -- Preparatory phase. Clear the contents of tables NCT_New_Entities and
19955 -- NCT_Pending_Itypes in case a previous call to New_Copy_Tree left some
19956 -- data inside.
19958 if NCT_Tables_In_Use then
19959 NCT_Tables_In_Use := False;
19961 NCT_New_Entities.Reset;
19962 NCT_Pending_Itypes.Reset;
19963 end if;
19965 -- Populate tables NCT_New_Entities and NCT_Pending_Itypes with data
19966 -- supplied by a linear entity map. The tables offer faster access to
19967 -- the same data.
19969 Build_NCT_Tables (Map);
19971 -- Execute Phase 1. Traverse the subtree and generate new entities for
19972 -- the following cases:
19974 -- * An entity defined within an N_Expression_With_Actions node
19976 -- * An itype referenced within the subtree where the associated node
19977 -- is also in the subtree.
19979 -- All new entities are accessible via table NCT_New_Entities, which
19980 -- contains mappings of the form:
19982 -- Old_Entity -> New_Entity
19983 -- Old_Itype -> New_Itype
19985 -- In addition, the associated nodes of all new itypes are mapped in
19986 -- table NCT_Pending_Itypes:
19988 -- Assoc_Nod -> (New_Itype1, New_Itype2, .., New_ItypeN)
19990 Visit_Any_Node (Source);
19992 -- Update the semantic attributes of all new entities generated during
19993 -- Phase 1 before starting Phase 2. The updates could be performed in
19994 -- routine Corresponding_Entity, however this may cause the same entity
19995 -- to be updated multiple times, effectively generating useless nodes.
19996 -- Keeping the updates separates from Phase 2 ensures that only one set
19997 -- of attributes is generated for an entity at any one time.
19999 Update_New_Entities (Map);
20001 -- Execute Phase 2. Replicate the source subtree one node at a time.
20002 -- The following transformations take place:
20004 -- * References to entities and itypes are updated to refer to the
20005 -- new entities and itypes generated during Phase 1.
20007 -- * All Associated_Node_For_Itype attributes of itypes are updated
20008 -- to refer to the new replicated Associated_Node_For_Itype.
20010 return Copy_Node_With_Replacement (Source);
20011 end New_Copy_Tree;
20013 -------------------------
20014 -- New_External_Entity --
20015 -------------------------
20017 function New_External_Entity
20018 (Kind : Entity_Kind;
20019 Scope_Id : Entity_Id;
20020 Sloc_Value : Source_Ptr;
20021 Related_Id : Entity_Id;
20022 Suffix : Character;
20023 Suffix_Index : Nat := 0;
20024 Prefix : Character := ' ') return Entity_Id
20026 N : constant Entity_Id :=
20027 Make_Defining_Identifier (Sloc_Value,
20028 New_External_Name
20029 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
20031 begin
20032 Set_Ekind (N, Kind);
20033 Set_Is_Internal (N, True);
20034 Append_Entity (N, Scope_Id);
20035 Set_Public_Status (N);
20037 if Kind in Type_Kind then
20038 Init_Size_Align (N);
20039 end if;
20041 return N;
20042 end New_External_Entity;
20044 -------------------------
20045 -- New_Internal_Entity --
20046 -------------------------
20048 function New_Internal_Entity
20049 (Kind : Entity_Kind;
20050 Scope_Id : Entity_Id;
20051 Sloc_Value : Source_Ptr;
20052 Id_Char : Character) return Entity_Id
20054 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
20056 begin
20057 Set_Ekind (N, Kind);
20058 Set_Is_Internal (N, True);
20059 Append_Entity (N, Scope_Id);
20061 if Kind in Type_Kind then
20062 Init_Size_Align (N);
20063 end if;
20065 return N;
20066 end New_Internal_Entity;
20068 -----------------
20069 -- Next_Actual --
20070 -----------------
20072 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
20073 N : Node_Id;
20075 begin
20076 -- If we are pointing at a positional parameter, it is a member of a
20077 -- node list (the list of parameters), and the next parameter is the
20078 -- next node on the list, unless we hit a parameter association, then
20079 -- we shift to using the chain whose head is the First_Named_Actual in
20080 -- the parent, and then is threaded using the Next_Named_Actual of the
20081 -- Parameter_Association. All this fiddling is because the original node
20082 -- list is in the textual call order, and what we need is the
20083 -- declaration order.
20085 if Is_List_Member (Actual_Id) then
20086 N := Next (Actual_Id);
20088 if Nkind (N) = N_Parameter_Association then
20090 -- In case of a build-in-place call, the call will no longer be a
20091 -- call; it will have been rewritten.
20093 if Nkind_In (Parent (Actual_Id), N_Entry_Call_Statement,
20094 N_Function_Call,
20095 N_Procedure_Call_Statement)
20096 then
20097 return First_Named_Actual (Parent (Actual_Id));
20098 else
20099 return Empty;
20100 end if;
20101 else
20102 return N;
20103 end if;
20105 else
20106 return Next_Named_Actual (Parent (Actual_Id));
20107 end if;
20108 end Next_Actual;
20110 procedure Next_Actual (Actual_Id : in out Node_Id) is
20111 begin
20112 Actual_Id := Next_Actual (Actual_Id);
20113 end Next_Actual;
20115 -----------------
20116 -- Next_Global --
20117 -----------------
20119 function Next_Global (Node : Node_Id) return Node_Id is
20120 begin
20121 -- The global item may either be in a list, or by itself, in which case
20122 -- there is no next global item with the same mode.
20124 if Is_List_Member (Node) then
20125 return Next (Node);
20126 else
20127 return Empty;
20128 end if;
20129 end Next_Global;
20131 procedure Next_Global (Node : in out Node_Id) is
20132 begin
20133 Node := Next_Global (Node);
20134 end Next_Global;
20136 ----------------------------------
20137 -- New_Requires_Transient_Scope --
20138 ----------------------------------
20140 function New_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
20141 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean;
20142 -- This is called for untagged records and protected types, with
20143 -- nondefaulted discriminants. Returns True if the size of function
20144 -- results is known at the call site, False otherwise. Returns False
20145 -- if there is a variant part that depends on the discriminants of
20146 -- this type, or if there is an array constrained by the discriminants
20147 -- of this type. ???Currently, this is overly conservative (the array
20148 -- could be nested inside some other record that is constrained by
20149 -- nondiscriminants). That is, the recursive calls are too conservative.
20151 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean;
20152 -- Returns True if Typ is a nonlimited record with defaulted
20153 -- discriminants whose max size makes it unsuitable for allocating on
20154 -- the primary stack.
20156 ------------------------------
20157 -- Caller_Known_Size_Record --
20158 ------------------------------
20160 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean is
20161 pragma Assert (Typ = Underlying_Type (Typ));
20163 begin
20164 if Has_Variant_Part (Typ) and then not Is_Definite_Subtype (Typ) then
20165 return False;
20166 end if;
20168 declare
20169 Comp : Entity_Id;
20171 begin
20172 Comp := First_Entity (Typ);
20173 while Present (Comp) loop
20175 -- Only look at E_Component entities. No need to look at
20176 -- E_Discriminant entities, and we must ignore internal
20177 -- subtypes generated for constrained components.
20179 if Ekind (Comp) = E_Component then
20180 declare
20181 Comp_Type : constant Entity_Id :=
20182 Underlying_Type (Etype (Comp));
20184 begin
20185 if Is_Record_Type (Comp_Type)
20186 or else
20187 Is_Protected_Type (Comp_Type)
20188 then
20189 if not Caller_Known_Size_Record (Comp_Type) then
20190 return False;
20191 end if;
20193 elsif Is_Array_Type (Comp_Type) then
20194 if Size_Depends_On_Discriminant (Comp_Type) then
20195 return False;
20196 end if;
20197 end if;
20198 end;
20199 end if;
20201 Next_Entity (Comp);
20202 end loop;
20203 end;
20205 return True;
20206 end Caller_Known_Size_Record;
20208 ------------------------------
20209 -- Large_Max_Size_Mutable --
20210 ------------------------------
20212 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean is
20213 pragma Assert (Typ = Underlying_Type (Typ));
20215 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean;
20216 -- Returns true if the discrete type T has a large range
20218 ----------------------------
20219 -- Is_Large_Discrete_Type --
20220 ----------------------------
20222 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean is
20223 Threshold : constant Int := 16;
20224 -- Arbitrary threshold above which we consider it "large". We want
20225 -- a fairly large threshold, because these large types really
20226 -- shouldn't have default discriminants in the first place, in
20227 -- most cases.
20229 begin
20230 return UI_To_Int (RM_Size (T)) > Threshold;
20231 end Is_Large_Discrete_Type;
20233 -- Start of processing for Large_Max_Size_Mutable
20235 begin
20236 if Is_Record_Type (Typ)
20237 and then not Is_Limited_View (Typ)
20238 and then Has_Defaulted_Discriminants (Typ)
20239 then
20240 -- Loop through the components, looking for an array whose upper
20241 -- bound(s) depends on discriminants, where both the subtype of
20242 -- the discriminant and the index subtype are too large.
20244 declare
20245 Comp : Entity_Id;
20247 begin
20248 Comp := First_Entity (Typ);
20249 while Present (Comp) loop
20250 if Ekind (Comp) = E_Component then
20251 declare
20252 Comp_Type : constant Entity_Id :=
20253 Underlying_Type (Etype (Comp));
20255 Hi : Node_Id;
20256 Indx : Node_Id;
20257 Ityp : Entity_Id;
20259 begin
20260 if Is_Array_Type (Comp_Type) then
20261 Indx := First_Index (Comp_Type);
20263 while Present (Indx) loop
20264 Ityp := Etype (Indx);
20265 Hi := Type_High_Bound (Ityp);
20267 if Nkind (Hi) = N_Identifier
20268 and then Ekind (Entity (Hi)) = E_Discriminant
20269 and then Is_Large_Discrete_Type (Ityp)
20270 and then Is_Large_Discrete_Type
20271 (Etype (Entity (Hi)))
20272 then
20273 return True;
20274 end if;
20276 Next_Index (Indx);
20277 end loop;
20278 end if;
20279 end;
20280 end if;
20282 Next_Entity (Comp);
20283 end loop;
20284 end;
20285 end if;
20287 return False;
20288 end Large_Max_Size_Mutable;
20290 -- Local declarations
20292 Typ : constant Entity_Id := Underlying_Type (Id);
20294 -- Start of processing for New_Requires_Transient_Scope
20296 begin
20297 -- This is a private type which is not completed yet. This can only
20298 -- happen in a default expression (of a formal parameter or of a
20299 -- record component). Do not expand transient scope in this case.
20301 if No (Typ) then
20302 return False;
20304 -- Do not expand transient scope for non-existent procedure return or
20305 -- string literal types.
20307 elsif Typ = Standard_Void_Type
20308 or else Ekind (Typ) = E_String_Literal_Subtype
20309 then
20310 return False;
20312 -- If Typ is a generic formal incomplete type, then we want to look at
20313 -- the actual type.
20315 elsif Ekind (Typ) = E_Record_Subtype
20316 and then Present (Cloned_Subtype (Typ))
20317 then
20318 return New_Requires_Transient_Scope (Cloned_Subtype (Typ));
20320 -- Functions returning specific tagged types may dispatch on result, so
20321 -- their returned value is allocated on the secondary stack, even in the
20322 -- definite case. We must treat nondispatching functions the same way,
20323 -- because access-to-function types can point at both, so the calling
20324 -- conventions must be compatible. Is_Tagged_Type includes controlled
20325 -- types and class-wide types. Controlled type temporaries need
20326 -- finalization.
20328 -- ???It's not clear why we need to return noncontrolled types with
20329 -- controlled components on the secondary stack.
20331 elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
20332 return True;
20334 -- Untagged definite subtypes are known size. This includes all
20335 -- elementary [sub]types. Tasks are known size even if they have
20336 -- discriminants. So we return False here, with one exception:
20337 -- For a type like:
20338 -- type T (Last : Natural := 0) is
20339 -- X : String (1 .. Last);
20340 -- end record;
20341 -- we return True. That's because for "P(F(...));", where F returns T,
20342 -- we don't know the size of the result at the call site, so if we
20343 -- allocated it on the primary stack, we would have to allocate the
20344 -- maximum size, which is way too big.
20346 elsif Is_Definite_Subtype (Typ) or else Is_Task_Type (Typ) then
20347 return Large_Max_Size_Mutable (Typ);
20349 -- Indefinite (discriminated) untagged record or protected type
20351 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
20352 return not Caller_Known_Size_Record (Typ);
20354 -- Unconstrained array
20356 else
20357 pragma Assert (Is_Array_Type (Typ) and not Is_Definite_Subtype (Typ));
20358 return True;
20359 end if;
20360 end New_Requires_Transient_Scope;
20362 --------------------------
20363 -- No_Heap_Finalization --
20364 --------------------------
20366 function No_Heap_Finalization (Typ : Entity_Id) return Boolean is
20367 begin
20368 if Ekind_In (Typ, E_Access_Type, E_General_Access_Type)
20369 and then Is_Library_Level_Entity (Typ)
20370 then
20371 -- A global No_Heap_Finalization pragma applies to all library-level
20372 -- named access-to-object types.
20374 if Present (No_Heap_Finalization_Pragma) then
20375 return True;
20377 -- The library-level named access-to-object type itself is subject to
20378 -- pragma No_Heap_Finalization.
20380 elsif Present (Get_Pragma (Typ, Pragma_No_Heap_Finalization)) then
20381 return True;
20382 end if;
20383 end if;
20385 return False;
20386 end No_Heap_Finalization;
20388 -----------------------
20389 -- Normalize_Actuals --
20390 -----------------------
20392 -- Chain actuals according to formals of subprogram. If there are no named
20393 -- associations, the chain is simply the list of Parameter Associations,
20394 -- since the order is the same as the declaration order. If there are named
20395 -- associations, then the First_Named_Actual field in the N_Function_Call
20396 -- or N_Procedure_Call_Statement node points to the Parameter_Association
20397 -- node for the parameter that comes first in declaration order. The
20398 -- remaining named parameters are then chained in declaration order using
20399 -- Next_Named_Actual.
20401 -- This routine also verifies that the number of actuals is compatible with
20402 -- the number and default values of formals, but performs no type checking
20403 -- (type checking is done by the caller).
20405 -- If the matching succeeds, Success is set to True and the caller proceeds
20406 -- with type-checking. If the match is unsuccessful, then Success is set to
20407 -- False, and the caller attempts a different interpretation, if there is
20408 -- one.
20410 -- If the flag Report is on, the call is not overloaded, and a failure to
20411 -- match can be reported here, rather than in the caller.
20413 procedure Normalize_Actuals
20414 (N : Node_Id;
20415 S : Entity_Id;
20416 Report : Boolean;
20417 Success : out Boolean)
20419 Actuals : constant List_Id := Parameter_Associations (N);
20420 Actual : Node_Id := Empty;
20421 Formal : Entity_Id;
20422 Last : Node_Id := Empty;
20423 First_Named : Node_Id := Empty;
20424 Found : Boolean;
20426 Formals_To_Match : Integer := 0;
20427 Actuals_To_Match : Integer := 0;
20429 procedure Chain (A : Node_Id);
20430 -- Add named actual at the proper place in the list, using the
20431 -- Next_Named_Actual link.
20433 function Reporting return Boolean;
20434 -- Determines if an error is to be reported. To report an error, we
20435 -- need Report to be True, and also we do not report errors caused
20436 -- by calls to init procs that occur within other init procs. Such
20437 -- errors must always be cascaded errors, since if all the types are
20438 -- declared correctly, the compiler will certainly build decent calls.
20440 -----------
20441 -- Chain --
20442 -----------
20444 procedure Chain (A : Node_Id) is
20445 begin
20446 if No (Last) then
20448 -- Call node points to first actual in list
20450 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
20452 else
20453 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
20454 end if;
20456 Last := A;
20457 Set_Next_Named_Actual (Last, Empty);
20458 end Chain;
20460 ---------------
20461 -- Reporting --
20462 ---------------
20464 function Reporting return Boolean is
20465 begin
20466 if not Report then
20467 return False;
20469 elsif not Within_Init_Proc then
20470 return True;
20472 elsif Is_Init_Proc (Entity (Name (N))) then
20473 return False;
20475 else
20476 return True;
20477 end if;
20478 end Reporting;
20480 -- Start of processing for Normalize_Actuals
20482 begin
20483 if Is_Access_Type (S) then
20485 -- The name in the call is a function call that returns an access
20486 -- to subprogram. The designated type has the list of formals.
20488 Formal := First_Formal (Designated_Type (S));
20489 else
20490 Formal := First_Formal (S);
20491 end if;
20493 while Present (Formal) loop
20494 Formals_To_Match := Formals_To_Match + 1;
20495 Next_Formal (Formal);
20496 end loop;
20498 -- Find if there is a named association, and verify that no positional
20499 -- associations appear after named ones.
20501 if Present (Actuals) then
20502 Actual := First (Actuals);
20503 end if;
20505 while Present (Actual)
20506 and then Nkind (Actual) /= N_Parameter_Association
20507 loop
20508 Actuals_To_Match := Actuals_To_Match + 1;
20509 Next (Actual);
20510 end loop;
20512 if No (Actual) and Actuals_To_Match = Formals_To_Match then
20514 -- Most common case: positional notation, no defaults
20516 Success := True;
20517 return;
20519 elsif Actuals_To_Match > Formals_To_Match then
20521 -- Too many actuals: will not work
20523 if Reporting then
20524 if Is_Entity_Name (Name (N)) then
20525 Error_Msg_N ("too many arguments in call to&", Name (N));
20526 else
20527 Error_Msg_N ("too many arguments in call", N);
20528 end if;
20529 end if;
20531 Success := False;
20532 return;
20533 end if;
20535 First_Named := Actual;
20537 while Present (Actual) loop
20538 if Nkind (Actual) /= N_Parameter_Association then
20539 Error_Msg_N
20540 ("positional parameters not allowed after named ones", Actual);
20541 Success := False;
20542 return;
20544 else
20545 Actuals_To_Match := Actuals_To_Match + 1;
20546 end if;
20548 Next (Actual);
20549 end loop;
20551 if Present (Actuals) then
20552 Actual := First (Actuals);
20553 end if;
20555 Formal := First_Formal (S);
20556 while Present (Formal) loop
20558 -- Match the formals in order. If the corresponding actual is
20559 -- positional, nothing to do. Else scan the list of named actuals
20560 -- to find the one with the right name.
20562 if Present (Actual)
20563 and then Nkind (Actual) /= N_Parameter_Association
20564 then
20565 Next (Actual);
20566 Actuals_To_Match := Actuals_To_Match - 1;
20567 Formals_To_Match := Formals_To_Match - 1;
20569 else
20570 -- For named parameters, search the list of actuals to find
20571 -- one that matches the next formal name.
20573 Actual := First_Named;
20574 Found := False;
20575 while Present (Actual) loop
20576 if Chars (Selector_Name (Actual)) = Chars (Formal) then
20577 Found := True;
20578 Chain (Actual);
20579 Actuals_To_Match := Actuals_To_Match - 1;
20580 Formals_To_Match := Formals_To_Match - 1;
20581 exit;
20582 end if;
20584 Next (Actual);
20585 end loop;
20587 if not Found then
20588 if Ekind (Formal) /= E_In_Parameter
20589 or else No (Default_Value (Formal))
20590 then
20591 if Reporting then
20592 if (Comes_From_Source (S)
20593 or else Sloc (S) = Standard_Location)
20594 and then Is_Overloadable (S)
20595 then
20596 if No (Actuals)
20597 and then
20598 Nkind_In (Parent (N), N_Procedure_Call_Statement,
20599 N_Function_Call,
20600 N_Parameter_Association)
20601 and then Ekind (S) /= E_Function
20602 then
20603 Set_Etype (N, Etype (S));
20605 else
20606 Error_Msg_Name_1 := Chars (S);
20607 Error_Msg_Sloc := Sloc (S);
20608 Error_Msg_NE
20609 ("missing argument for parameter & "
20610 & "in call to % declared #", N, Formal);
20611 end if;
20613 elsif Is_Overloadable (S) then
20614 Error_Msg_Name_1 := Chars (S);
20616 -- Point to type derivation that generated the
20617 -- operation.
20619 Error_Msg_Sloc := Sloc (Parent (S));
20621 Error_Msg_NE
20622 ("missing argument for parameter & "
20623 & "in call to % (inherited) #", N, Formal);
20625 else
20626 Error_Msg_NE
20627 ("missing argument for parameter &", N, Formal);
20628 end if;
20629 end if;
20631 Success := False;
20632 return;
20634 else
20635 Formals_To_Match := Formals_To_Match - 1;
20636 end if;
20637 end if;
20638 end if;
20640 Next_Formal (Formal);
20641 end loop;
20643 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
20644 Success := True;
20645 return;
20647 else
20648 if Reporting then
20650 -- Find some superfluous named actual that did not get
20651 -- attached to the list of associations.
20653 Actual := First (Actuals);
20654 while Present (Actual) loop
20655 if Nkind (Actual) = N_Parameter_Association
20656 and then Actual /= Last
20657 and then No (Next_Named_Actual (Actual))
20658 then
20659 -- A validity check may introduce a copy of a call that
20660 -- includes an extra actual (for example for an unrelated
20661 -- accessibility check). Check that the extra actual matches
20662 -- some extra formal, which must exist already because
20663 -- subprogram must be frozen at this point.
20665 if Present (Extra_Formals (S))
20666 and then not Comes_From_Source (Actual)
20667 and then Nkind (Actual) = N_Parameter_Association
20668 and then Chars (Extra_Formals (S)) =
20669 Chars (Selector_Name (Actual))
20670 then
20671 null;
20672 else
20673 Error_Msg_N
20674 ("unmatched actual & in call", Selector_Name (Actual));
20675 exit;
20676 end if;
20677 end if;
20679 Next (Actual);
20680 end loop;
20681 end if;
20683 Success := False;
20684 return;
20685 end if;
20686 end Normalize_Actuals;
20688 --------------------------------
20689 -- Note_Possible_Modification --
20690 --------------------------------
20692 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
20693 Modification_Comes_From_Source : constant Boolean :=
20694 Comes_From_Source (Parent (N));
20696 Ent : Entity_Id;
20697 Exp : Node_Id;
20699 begin
20700 -- Loop to find referenced entity, if there is one
20702 Exp := N;
20703 loop
20704 Ent := Empty;
20706 if Is_Entity_Name (Exp) then
20707 Ent := Entity (Exp);
20709 -- If the entity is missing, it is an undeclared identifier,
20710 -- and there is nothing to annotate.
20712 if No (Ent) then
20713 return;
20714 end if;
20716 elsif Nkind (Exp) = N_Explicit_Dereference then
20717 declare
20718 P : constant Node_Id := Prefix (Exp);
20720 begin
20721 -- In formal verification mode, keep track of all reads and
20722 -- writes through explicit dereferences.
20724 if GNATprove_Mode then
20725 SPARK_Specific.Generate_Dereference (N, 'm');
20726 end if;
20728 if Nkind (P) = N_Selected_Component
20729 and then Present (Entry_Formal (Entity (Selector_Name (P))))
20730 then
20731 -- Case of a reference to an entry formal
20733 Ent := Entry_Formal (Entity (Selector_Name (P)));
20735 elsif Nkind (P) = N_Identifier
20736 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
20737 and then Present (Expression (Parent (Entity (P))))
20738 and then Nkind (Expression (Parent (Entity (P)))) =
20739 N_Reference
20740 then
20741 -- Case of a reference to a value on which side effects have
20742 -- been removed.
20744 Exp := Prefix (Expression (Parent (Entity (P))));
20745 goto Continue;
20747 else
20748 return;
20749 end if;
20750 end;
20752 elsif Nkind_In (Exp, N_Type_Conversion,
20753 N_Unchecked_Type_Conversion)
20754 then
20755 Exp := Expression (Exp);
20756 goto Continue;
20758 elsif Nkind_In (Exp, N_Slice,
20759 N_Indexed_Component,
20760 N_Selected_Component)
20761 then
20762 -- Special check, if the prefix is an access type, then return
20763 -- since we are modifying the thing pointed to, not the prefix.
20764 -- When we are expanding, most usually the prefix is replaced
20765 -- by an explicit dereference, and this test is not needed, but
20766 -- in some cases (notably -gnatc mode and generics) when we do
20767 -- not do full expansion, we need this special test.
20769 if Is_Access_Type (Etype (Prefix (Exp))) then
20770 return;
20772 -- Otherwise go to prefix and keep going
20774 else
20775 Exp := Prefix (Exp);
20776 goto Continue;
20777 end if;
20779 -- All other cases, not a modification
20781 else
20782 return;
20783 end if;
20785 -- Now look for entity being referenced
20787 if Present (Ent) then
20788 if Is_Object (Ent) then
20789 if Comes_From_Source (Exp)
20790 or else Modification_Comes_From_Source
20791 then
20792 -- Give warning if pragma unmodified is given and we are
20793 -- sure this is a modification.
20795 if Has_Pragma_Unmodified (Ent) and then Sure then
20797 -- Note that the entity may be present only as a result
20798 -- of pragma Unused.
20800 if Has_Pragma_Unused (Ent) then
20801 Error_Msg_NE ("??pragma Unused given for &!", N, Ent);
20802 else
20803 Error_Msg_NE
20804 ("??pragma Unmodified given for &!", N, Ent);
20805 end if;
20806 end if;
20808 Set_Never_Set_In_Source (Ent, False);
20809 end if;
20811 Set_Is_True_Constant (Ent, False);
20812 Set_Current_Value (Ent, Empty);
20813 Set_Is_Known_Null (Ent, False);
20815 if not Can_Never_Be_Null (Ent) then
20816 Set_Is_Known_Non_Null (Ent, False);
20817 end if;
20819 -- Follow renaming chain
20821 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
20822 and then Present (Renamed_Object (Ent))
20823 then
20824 Exp := Renamed_Object (Ent);
20826 -- If the entity is the loop variable in an iteration over
20827 -- a container, retrieve container expression to indicate
20828 -- possible modification.
20830 if Present (Related_Expression (Ent))
20831 and then Nkind (Parent (Related_Expression (Ent))) =
20832 N_Iterator_Specification
20833 then
20834 Exp := Original_Node (Related_Expression (Ent));
20835 end if;
20837 goto Continue;
20839 -- The expression may be the renaming of a subcomponent of an
20840 -- array or container. The assignment to the subcomponent is
20841 -- a modification of the container.
20843 elsif Comes_From_Source (Original_Node (Exp))
20844 and then Nkind_In (Original_Node (Exp), N_Selected_Component,
20845 N_Indexed_Component)
20846 then
20847 Exp := Prefix (Original_Node (Exp));
20848 goto Continue;
20849 end if;
20851 -- Generate a reference only if the assignment comes from
20852 -- source. This excludes, for example, calls to a dispatching
20853 -- assignment operation when the left-hand side is tagged. In
20854 -- GNATprove mode, we need those references also on generated
20855 -- code, as these are used to compute the local effects of
20856 -- subprograms.
20858 if Modification_Comes_From_Source or GNATprove_Mode then
20859 Generate_Reference (Ent, Exp, 'm');
20861 -- If the target of the assignment is the bound variable
20862 -- in an iterator, indicate that the corresponding array
20863 -- or container is also modified.
20865 if Ada_Version >= Ada_2012
20866 and then Nkind (Parent (Ent)) = N_Iterator_Specification
20867 then
20868 declare
20869 Domain : constant Node_Id := Name (Parent (Ent));
20871 begin
20872 -- TBD : in the full version of the construct, the
20873 -- domain of iteration can be given by an expression.
20875 if Is_Entity_Name (Domain) then
20876 Generate_Reference (Entity (Domain), Exp, 'm');
20877 Set_Is_True_Constant (Entity (Domain), False);
20878 Set_Never_Set_In_Source (Entity (Domain), False);
20879 end if;
20880 end;
20881 end if;
20882 end if;
20883 end if;
20885 Kill_Checks (Ent);
20887 -- If we are sure this is a modification from source, and we know
20888 -- this modifies a constant, then give an appropriate warning.
20890 if Sure
20891 and then Modification_Comes_From_Source
20892 and then Overlays_Constant (Ent)
20893 and then Address_Clause_Overlay_Warnings
20894 then
20895 declare
20896 Addr : constant Node_Id := Address_Clause (Ent);
20897 O_Ent : Entity_Id;
20898 Off : Boolean;
20900 begin
20901 Find_Overlaid_Entity (Addr, O_Ent, Off);
20903 Error_Msg_Sloc := Sloc (Addr);
20904 Error_Msg_NE
20905 ("??constant& may be modified via address clause#",
20906 N, O_Ent);
20907 end;
20908 end if;
20910 return;
20911 end if;
20913 <<Continue>>
20914 null;
20915 end loop;
20916 end Note_Possible_Modification;
20918 -----------------
20919 -- Null_Status --
20920 -----------------
20922 function Null_Status (N : Node_Id) return Null_Status_Kind is
20923 function Is_Null_Excluding_Def (Def : Node_Id) return Boolean;
20924 -- Determine whether definition Def carries a null exclusion
20926 function Null_Status_Of_Entity (Id : Entity_Id) return Null_Status_Kind;
20927 -- Determine the null status of arbitrary entity Id
20929 function Null_Status_Of_Type (Typ : Entity_Id) return Null_Status_Kind;
20930 -- Determine the null status of type Typ
20932 ---------------------------
20933 -- Is_Null_Excluding_Def --
20934 ---------------------------
20936 function Is_Null_Excluding_Def (Def : Node_Id) return Boolean is
20937 begin
20938 return
20939 Nkind_In (Def, N_Access_Definition,
20940 N_Access_Function_Definition,
20941 N_Access_Procedure_Definition,
20942 N_Access_To_Object_Definition,
20943 N_Component_Definition,
20944 N_Derived_Type_Definition)
20945 and then Null_Exclusion_Present (Def);
20946 end Is_Null_Excluding_Def;
20948 ---------------------------
20949 -- Null_Status_Of_Entity --
20950 ---------------------------
20952 function Null_Status_Of_Entity
20953 (Id : Entity_Id) return Null_Status_Kind
20955 Decl : constant Node_Id := Declaration_Node (Id);
20956 Def : Node_Id;
20958 begin
20959 -- The value of an imported or exported entity may be set externally
20960 -- regardless of a null exclusion. As a result, the value cannot be
20961 -- determined statically.
20963 if Is_Imported (Id) or else Is_Exported (Id) then
20964 return Unknown;
20966 elsif Nkind_In (Decl, N_Component_Declaration,
20967 N_Discriminant_Specification,
20968 N_Formal_Object_Declaration,
20969 N_Object_Declaration,
20970 N_Object_Renaming_Declaration,
20971 N_Parameter_Specification)
20972 then
20973 -- A component declaration yields a non-null value when either
20974 -- its component definition or access definition carries a null
20975 -- exclusion.
20977 if Nkind (Decl) = N_Component_Declaration then
20978 Def := Component_Definition (Decl);
20980 if Is_Null_Excluding_Def (Def) then
20981 return Is_Non_Null;
20982 end if;
20984 Def := Access_Definition (Def);
20986 if Present (Def) and then Is_Null_Excluding_Def (Def) then
20987 return Is_Non_Null;
20988 end if;
20990 -- A formal object declaration yields a non-null value if its
20991 -- access definition carries a null exclusion. If the object is
20992 -- default initialized, then the value depends on the expression.
20994 elsif Nkind (Decl) = N_Formal_Object_Declaration then
20995 Def := Access_Definition (Decl);
20997 if Present (Def) and then Is_Null_Excluding_Def (Def) then
20998 return Is_Non_Null;
20999 end if;
21001 -- A constant may yield a null or non-null value depending on its
21002 -- initialization expression.
21004 elsif Ekind (Id) = E_Constant then
21005 return Null_Status (Constant_Value (Id));
21007 -- The construct yields a non-null value when it has a null
21008 -- exclusion.
21010 elsif Null_Exclusion_Present (Decl) then
21011 return Is_Non_Null;
21013 -- An object renaming declaration yields a non-null value if its
21014 -- access definition carries a null exclusion. Otherwise the value
21015 -- depends on the renamed name.
21017 elsif Nkind (Decl) = N_Object_Renaming_Declaration then
21018 Def := Access_Definition (Decl);
21020 if Present (Def) and then Is_Null_Excluding_Def (Def) then
21021 return Is_Non_Null;
21023 else
21024 return Null_Status (Name (Decl));
21025 end if;
21026 end if;
21027 end if;
21029 -- At this point the declaration of the entity does not carry a null
21030 -- exclusion and lacks an initialization expression. Check the status
21031 -- of its type.
21033 return Null_Status_Of_Type (Etype (Id));
21034 end Null_Status_Of_Entity;
21036 -------------------------
21037 -- Null_Status_Of_Type --
21038 -------------------------
21040 function Null_Status_Of_Type (Typ : Entity_Id) return Null_Status_Kind is
21041 Curr : Entity_Id;
21042 Decl : Node_Id;
21044 begin
21045 -- Traverse the type chain looking for types with null exclusion
21047 Curr := Typ;
21048 while Present (Curr) and then Etype (Curr) /= Curr loop
21049 Decl := Parent (Curr);
21051 -- Guard against itypes which do not always have declarations. A
21052 -- type yields a non-null value if it carries a null exclusion.
21054 if Present (Decl) then
21055 if Nkind (Decl) = N_Full_Type_Declaration
21056 and then Is_Null_Excluding_Def (Type_Definition (Decl))
21057 then
21058 return Is_Non_Null;
21060 elsif Nkind (Decl) = N_Subtype_Declaration
21061 and then Null_Exclusion_Present (Decl)
21062 then
21063 return Is_Non_Null;
21064 end if;
21065 end if;
21067 Curr := Etype (Curr);
21068 end loop;
21070 -- The type chain does not contain any null excluding types
21072 return Unknown;
21073 end Null_Status_Of_Type;
21075 -- Start of processing for Null_Status
21077 begin
21078 -- An allocator always creates a non-null value
21080 if Nkind (N) = N_Allocator then
21081 return Is_Non_Null;
21083 -- Taking the 'Access of something yields a non-null value
21085 elsif Nkind (N) = N_Attribute_Reference
21086 and then Nam_In (Attribute_Name (N), Name_Access,
21087 Name_Unchecked_Access,
21088 Name_Unrestricted_Access)
21089 then
21090 return Is_Non_Null;
21092 -- "null" yields null
21094 elsif Nkind (N) = N_Null then
21095 return Is_Null;
21097 -- Check the status of the operand of a type conversion
21099 elsif Nkind (N) = N_Type_Conversion then
21100 return Null_Status (Expression (N));
21102 -- The input denotes a reference to an entity. Determine whether the
21103 -- entity or its type yields a null or non-null value.
21105 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
21106 return Null_Status_Of_Entity (Entity (N));
21107 end if;
21109 -- Otherwise it is not possible to determine the null status of the
21110 -- subexpression at compile time without resorting to simple flow
21111 -- analysis.
21113 return Unknown;
21114 end Null_Status;
21116 --------------------------------------
21117 -- Null_To_Null_Address_Convert_OK --
21118 --------------------------------------
21120 function Null_To_Null_Address_Convert_OK
21121 (N : Node_Id;
21122 Typ : Entity_Id := Empty) return Boolean
21124 begin
21125 if not Relaxed_RM_Semantics then
21126 return False;
21127 end if;
21129 if Nkind (N) = N_Null then
21130 return Present (Typ) and then Is_Descendant_Of_Address (Typ);
21132 elsif Nkind_In (N, N_Op_Eq, N_Op_Ge, N_Op_Gt, N_Op_Le, N_Op_Lt, N_Op_Ne)
21133 then
21134 declare
21135 L : constant Node_Id := Left_Opnd (N);
21136 R : constant Node_Id := Right_Opnd (N);
21138 begin
21139 -- We check the Etype of the complementary operand since the
21140 -- N_Null node is not decorated at this stage.
21142 return
21143 ((Nkind (L) = N_Null
21144 and then Is_Descendant_Of_Address (Etype (R)))
21145 or else
21146 (Nkind (R) = N_Null
21147 and then Is_Descendant_Of_Address (Etype (L))));
21148 end;
21149 end if;
21151 return False;
21152 end Null_To_Null_Address_Convert_OK;
21154 ---------------------------------
21155 -- Number_Of_Elements_In_Array --
21156 ---------------------------------
21158 function Number_Of_Elements_In_Array (T : Entity_Id) return Int is
21159 Indx : Node_Id;
21160 Typ : Entity_Id;
21161 Low : Node_Id;
21162 High : Node_Id;
21163 Num : Int := 1;
21165 begin
21166 pragma Assert (Is_Array_Type (T));
21168 Indx := First_Index (T);
21169 while Present (Indx) loop
21170 Typ := Underlying_Type (Etype (Indx));
21172 -- Never look at junk bounds of a generic type
21174 if Is_Generic_Type (Typ) then
21175 return 0;
21176 end if;
21178 -- Check the array bounds are known at compile time and return zero
21179 -- if they are not.
21181 Low := Type_Low_Bound (Typ);
21182 High := Type_High_Bound (Typ);
21184 if not Compile_Time_Known_Value (Low) then
21185 return 0;
21186 elsif not Compile_Time_Known_Value (High) then
21187 return 0;
21188 else
21189 Num :=
21190 Num * UI_To_Int ((Expr_Value (High) - Expr_Value (Low) + 1));
21191 end if;
21193 Next_Index (Indx);
21194 end loop;
21196 return Num;
21197 end Number_Of_Elements_In_Array;
21199 -------------------------
21200 -- Object_Access_Level --
21201 -------------------------
21203 -- Returns the static accessibility level of the view denoted by Obj. Note
21204 -- that the value returned is the result of a call to Scope_Depth. Only
21205 -- scope depths associated with dynamic scopes can actually be returned.
21206 -- Since only relative levels matter for accessibility checking, the fact
21207 -- that the distance between successive levels of accessibility is not
21208 -- always one is immaterial (invariant: if level(E2) is deeper than
21209 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
21211 function Object_Access_Level (Obj : Node_Id) return Uint is
21212 function Is_Interface_Conversion (N : Node_Id) return Boolean;
21213 -- Determine whether N is a construct of the form
21214 -- Some_Type (Operand._tag'Address)
21215 -- This construct appears in the context of dispatching calls.
21217 function Reference_To (Obj : Node_Id) return Node_Id;
21218 -- An explicit dereference is created when removing side effects from
21219 -- expressions for constraint checking purposes. In this case a local
21220 -- access type is created for it. The correct access level is that of
21221 -- the original source node. We detect this case by noting that the
21222 -- prefix of the dereference is created by an object declaration whose
21223 -- initial expression is a reference.
21225 -----------------------------
21226 -- Is_Interface_Conversion --
21227 -----------------------------
21229 function Is_Interface_Conversion (N : Node_Id) return Boolean is
21230 begin
21231 return Nkind (N) = N_Unchecked_Type_Conversion
21232 and then Nkind (Expression (N)) = N_Attribute_Reference
21233 and then Attribute_Name (Expression (N)) = Name_Address;
21234 end Is_Interface_Conversion;
21236 ------------------
21237 -- Reference_To --
21238 ------------------
21240 function Reference_To (Obj : Node_Id) return Node_Id is
21241 Pref : constant Node_Id := Prefix (Obj);
21242 begin
21243 if Is_Entity_Name (Pref)
21244 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
21245 and then Present (Expression (Parent (Entity (Pref))))
21246 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
21247 then
21248 return (Prefix (Expression (Parent (Entity (Pref)))));
21249 else
21250 return Empty;
21251 end if;
21252 end Reference_To;
21254 -- Local variables
21256 E : Entity_Id;
21258 -- Start of processing for Object_Access_Level
21260 begin
21261 if Nkind (Obj) = N_Defining_Identifier
21262 or else Is_Entity_Name (Obj)
21263 then
21264 if Nkind (Obj) = N_Defining_Identifier then
21265 E := Obj;
21266 else
21267 E := Entity (Obj);
21268 end if;
21270 if Is_Prival (E) then
21271 E := Prival_Link (E);
21272 end if;
21274 -- If E is a type then it denotes a current instance. For this case
21275 -- we add one to the normal accessibility level of the type to ensure
21276 -- that current instances are treated as always being deeper than
21277 -- than the level of any visible named access type (see 3.10.2(21)).
21279 if Is_Type (E) then
21280 return Type_Access_Level (E) + 1;
21282 elsif Present (Renamed_Object (E)) then
21283 return Object_Access_Level (Renamed_Object (E));
21285 -- Similarly, if E is a component of the current instance of a
21286 -- protected type, any instance of it is assumed to be at a deeper
21287 -- level than the type. For a protected object (whose type is an
21288 -- anonymous protected type) its components are at the same level
21289 -- as the type itself.
21291 elsif not Is_Overloadable (E)
21292 and then Ekind (Scope (E)) = E_Protected_Type
21293 and then Comes_From_Source (Scope (E))
21294 then
21295 return Type_Access_Level (Scope (E)) + 1;
21297 else
21298 -- Aliased formals of functions take their access level from the
21299 -- point of call, i.e. require a dynamic check. For static check
21300 -- purposes, this is smaller than the level of the subprogram
21301 -- itself. For procedures the aliased makes no difference.
21303 if Is_Formal (E)
21304 and then Is_Aliased (E)
21305 and then Ekind (Scope (E)) = E_Function
21306 then
21307 return Type_Access_Level (Etype (E));
21309 else
21310 return Scope_Depth (Enclosing_Dynamic_Scope (E));
21311 end if;
21312 end if;
21314 elsif Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
21315 if Is_Access_Type (Etype (Prefix (Obj))) then
21316 return Type_Access_Level (Etype (Prefix (Obj)));
21317 else
21318 return Object_Access_Level (Prefix (Obj));
21319 end if;
21321 elsif Nkind (Obj) = N_Explicit_Dereference then
21323 -- If the prefix is a selected access discriminant then we make a
21324 -- recursive call on the prefix, which will in turn check the level
21325 -- of the prefix object of the selected discriminant.
21327 -- In Ada 2012, if the discriminant has implicit dereference and
21328 -- the context is a selected component, treat this as an object of
21329 -- unknown scope (see below). This is necessary in compile-only mode;
21330 -- otherwise expansion will already have transformed the prefix into
21331 -- a temporary.
21333 if Nkind (Prefix (Obj)) = N_Selected_Component
21334 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
21335 and then
21336 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
21337 and then
21338 (not Has_Implicit_Dereference
21339 (Entity (Selector_Name (Prefix (Obj))))
21340 or else Nkind (Parent (Obj)) /= N_Selected_Component)
21341 then
21342 return Object_Access_Level (Prefix (Obj));
21344 -- Detect an interface conversion in the context of a dispatching
21345 -- call. Use the original form of the conversion to find the access
21346 -- level of the operand.
21348 elsif Is_Interface (Etype (Obj))
21349 and then Is_Interface_Conversion (Prefix (Obj))
21350 and then Nkind (Original_Node (Obj)) = N_Type_Conversion
21351 then
21352 return Object_Access_Level (Original_Node (Obj));
21354 elsif not Comes_From_Source (Obj) then
21355 declare
21356 Ref : constant Node_Id := Reference_To (Obj);
21357 begin
21358 if Present (Ref) then
21359 return Object_Access_Level (Ref);
21360 else
21361 return Type_Access_Level (Etype (Prefix (Obj)));
21362 end if;
21363 end;
21365 else
21366 return Type_Access_Level (Etype (Prefix (Obj)));
21367 end if;
21369 elsif Nkind_In (Obj, N_Type_Conversion, N_Unchecked_Type_Conversion) then
21370 return Object_Access_Level (Expression (Obj));
21372 elsif Nkind (Obj) = N_Function_Call then
21374 -- Function results are objects, so we get either the access level of
21375 -- the function or, in the case of an indirect call, the level of the
21376 -- access-to-subprogram type. (This code is used for Ada 95, but it
21377 -- looks wrong, because it seems that we should be checking the level
21378 -- of the call itself, even for Ada 95. However, using the Ada 2005
21379 -- version of the code causes regressions in several tests that are
21380 -- compiled with -gnat95. ???)
21382 if Ada_Version < Ada_2005 then
21383 if Is_Entity_Name (Name (Obj)) then
21384 return Subprogram_Access_Level (Entity (Name (Obj)));
21385 else
21386 return Type_Access_Level (Etype (Prefix (Name (Obj))));
21387 end if;
21389 -- For Ada 2005, the level of the result object of a function call is
21390 -- defined to be the level of the call's innermost enclosing master.
21391 -- We determine that by querying the depth of the innermost enclosing
21392 -- dynamic scope.
21394 else
21395 Return_Master_Scope_Depth_Of_Call : declare
21396 function Innermost_Master_Scope_Depth
21397 (N : Node_Id) return Uint;
21398 -- Returns the scope depth of the given node's innermost
21399 -- enclosing dynamic scope (effectively the accessibility
21400 -- level of the innermost enclosing master).
21402 ----------------------------------
21403 -- Innermost_Master_Scope_Depth --
21404 ----------------------------------
21406 function Innermost_Master_Scope_Depth
21407 (N : Node_Id) return Uint
21409 Node_Par : Node_Id := Parent (N);
21411 begin
21412 -- Locate the nearest enclosing node (by traversing Parents)
21413 -- that Defining_Entity can be applied to, and return the
21414 -- depth of that entity's nearest enclosing dynamic scope.
21416 while Present (Node_Par) loop
21417 case Nkind (Node_Par) is
21418 when N_Abstract_Subprogram_Declaration
21419 | N_Block_Statement
21420 | N_Body_Stub
21421 | N_Component_Declaration
21422 | N_Entry_Body
21423 | N_Entry_Declaration
21424 | N_Exception_Declaration
21425 | N_Formal_Object_Declaration
21426 | N_Formal_Package_Declaration
21427 | N_Formal_Subprogram_Declaration
21428 | N_Formal_Type_Declaration
21429 | N_Full_Type_Declaration
21430 | N_Function_Specification
21431 | N_Generic_Declaration
21432 | N_Generic_Instantiation
21433 | N_Implicit_Label_Declaration
21434 | N_Incomplete_Type_Declaration
21435 | N_Loop_Parameter_Specification
21436 | N_Number_Declaration
21437 | N_Object_Declaration
21438 | N_Package_Declaration
21439 | N_Package_Specification
21440 | N_Parameter_Specification
21441 | N_Private_Extension_Declaration
21442 | N_Private_Type_Declaration
21443 | N_Procedure_Specification
21444 | N_Proper_Body
21445 | N_Protected_Type_Declaration
21446 | N_Renaming_Declaration
21447 | N_Single_Protected_Declaration
21448 | N_Single_Task_Declaration
21449 | N_Subprogram_Declaration
21450 | N_Subtype_Declaration
21451 | N_Subunit
21452 | N_Task_Type_Declaration
21454 return Scope_Depth
21455 (Nearest_Dynamic_Scope
21456 (Defining_Entity (Node_Par)));
21458 -- For a return statement within a function, return
21459 -- the depth of the function itself. This is not just
21460 -- a small optimization, but matters when analyzing
21461 -- the expression in an expression function before
21462 -- the body is created.
21464 when N_Simple_Return_Statement =>
21465 if Ekind (Current_Scope) = E_Function then
21466 return Scope_Depth (Current_Scope);
21467 end if;
21469 when others =>
21470 null;
21471 end case;
21473 Node_Par := Parent (Node_Par);
21474 end loop;
21476 pragma Assert (False);
21478 -- Should never reach the following return
21480 return Scope_Depth (Current_Scope) + 1;
21481 end Innermost_Master_Scope_Depth;
21483 -- Start of processing for Return_Master_Scope_Depth_Of_Call
21485 begin
21486 return Innermost_Master_Scope_Depth (Obj);
21487 end Return_Master_Scope_Depth_Of_Call;
21488 end if;
21490 -- For convenience we handle qualified expressions, even though they
21491 -- aren't technically object names.
21493 elsif Nkind (Obj) = N_Qualified_Expression then
21494 return Object_Access_Level (Expression (Obj));
21496 -- Ditto for aggregates. They have the level of the temporary that
21497 -- will hold their value.
21499 elsif Nkind (Obj) = N_Aggregate then
21500 return Object_Access_Level (Current_Scope);
21502 -- Otherwise return the scope level of Standard. (If there are cases
21503 -- that fall through to this point they will be treated as having
21504 -- global accessibility for now. ???)
21506 else
21507 return Scope_Depth (Standard_Standard);
21508 end if;
21509 end Object_Access_Level;
21511 ----------------------------------
21512 -- Old_Requires_Transient_Scope --
21513 ----------------------------------
21515 function Old_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
21516 Typ : constant Entity_Id := Underlying_Type (Id);
21518 begin
21519 -- This is a private type which is not completed yet. This can only
21520 -- happen in a default expression (of a formal parameter or of a
21521 -- record component). Do not expand transient scope in this case.
21523 if No (Typ) then
21524 return False;
21526 -- Do not expand transient scope for non-existent procedure return
21528 elsif Typ = Standard_Void_Type then
21529 return False;
21531 -- Elementary types do not require a transient scope
21533 elsif Is_Elementary_Type (Typ) then
21534 return False;
21536 -- Generally, indefinite subtypes require a transient scope, since the
21537 -- back end cannot generate temporaries, since this is not a valid type
21538 -- for declaring an object. It might be possible to relax this in the
21539 -- future, e.g. by declaring the maximum possible space for the type.
21541 elsif not Is_Definite_Subtype (Typ) then
21542 return True;
21544 -- Functions returning tagged types may dispatch on result so their
21545 -- returned value is allocated on the secondary stack. Controlled
21546 -- type temporaries need finalization.
21548 elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
21549 return True;
21551 -- Record type
21553 elsif Is_Record_Type (Typ) then
21554 declare
21555 Comp : Entity_Id;
21557 begin
21558 Comp := First_Entity (Typ);
21559 while Present (Comp) loop
21560 if Ekind (Comp) = E_Component then
21562 -- ???It's not clear we need a full recursive call to
21563 -- Old_Requires_Transient_Scope here. Note that the
21564 -- following can't happen.
21566 pragma Assert (Is_Definite_Subtype (Etype (Comp)));
21567 pragma Assert (not Has_Controlled_Component (Etype (Comp)));
21569 if Old_Requires_Transient_Scope (Etype (Comp)) then
21570 return True;
21571 end if;
21572 end if;
21574 Next_Entity (Comp);
21575 end loop;
21576 end;
21578 return False;
21580 -- String literal types never require transient scope
21582 elsif Ekind (Typ) = E_String_Literal_Subtype then
21583 return False;
21585 -- Array type. Note that we already know that this is a constrained
21586 -- array, since unconstrained arrays will fail the indefinite test.
21588 elsif Is_Array_Type (Typ) then
21590 -- If component type requires a transient scope, the array does too
21592 if Old_Requires_Transient_Scope (Component_Type (Typ)) then
21593 return True;
21595 -- Otherwise, we only need a transient scope if the size depends on
21596 -- the value of one or more discriminants.
21598 else
21599 return Size_Depends_On_Discriminant (Typ);
21600 end if;
21602 -- All other cases do not require a transient scope
21604 else
21605 pragma Assert (Is_Protected_Type (Typ) or else Is_Task_Type (Typ));
21606 return False;
21607 end if;
21608 end Old_Requires_Transient_Scope;
21610 ---------------------------------
21611 -- Original_Aspect_Pragma_Name --
21612 ---------------------------------
21614 function Original_Aspect_Pragma_Name (N : Node_Id) return Name_Id is
21615 Item : Node_Id;
21616 Item_Nam : Name_Id;
21618 begin
21619 pragma Assert (Nkind_In (N, N_Aspect_Specification, N_Pragma));
21621 Item := N;
21623 -- The pragma was generated to emulate an aspect, use the original
21624 -- aspect specification.
21626 if Nkind (Item) = N_Pragma and then From_Aspect_Specification (Item) then
21627 Item := Corresponding_Aspect (Item);
21628 end if;
21630 -- Retrieve the name of the aspect/pragma. Note that Pre, Pre_Class,
21631 -- Post and Post_Class rewrite their pragma identifier to preserve the
21632 -- original name.
21633 -- ??? this is kludgey
21635 if Nkind (Item) = N_Pragma then
21636 Item_Nam := Chars (Original_Node (Pragma_Identifier (Item)));
21638 else
21639 pragma Assert (Nkind (Item) = N_Aspect_Specification);
21640 Item_Nam := Chars (Identifier (Item));
21641 end if;
21643 -- Deal with 'Class by converting the name to its _XXX form
21645 if Class_Present (Item) then
21646 if Item_Nam = Name_Invariant then
21647 Item_Nam := Name_uInvariant;
21649 elsif Item_Nam = Name_Post then
21650 Item_Nam := Name_uPost;
21652 elsif Item_Nam = Name_Pre then
21653 Item_Nam := Name_uPre;
21655 elsif Nam_In (Item_Nam, Name_Type_Invariant,
21656 Name_Type_Invariant_Class)
21657 then
21658 Item_Nam := Name_uType_Invariant;
21660 -- Nothing to do for other cases (e.g. a Check that derived from
21661 -- Pre_Class and has the flag set). Also we do nothing if the name
21662 -- is already in special _xxx form.
21664 end if;
21665 end if;
21667 return Item_Nam;
21668 end Original_Aspect_Pragma_Name;
21670 --------------------------------------
21671 -- Original_Corresponding_Operation --
21672 --------------------------------------
21674 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
21676 Typ : constant Entity_Id := Find_Dispatching_Type (S);
21678 begin
21679 -- If S is an inherited primitive S2 the original corresponding
21680 -- operation of S is the original corresponding operation of S2
21682 if Present (Alias (S))
21683 and then Find_Dispatching_Type (Alias (S)) /= Typ
21684 then
21685 return Original_Corresponding_Operation (Alias (S));
21687 -- If S overrides an inherited subprogram S2 the original corresponding
21688 -- operation of S is the original corresponding operation of S2
21690 elsif Present (Overridden_Operation (S)) then
21691 return Original_Corresponding_Operation (Overridden_Operation (S));
21693 -- otherwise it is S itself
21695 else
21696 return S;
21697 end if;
21698 end Original_Corresponding_Operation;
21700 -------------------
21701 -- Output_Entity --
21702 -------------------
21704 procedure Output_Entity (Id : Entity_Id) is
21705 Scop : Entity_Id;
21707 begin
21708 Scop := Scope (Id);
21710 -- The entity may lack a scope when it is in the process of being
21711 -- analyzed. Use the current scope as an approximation.
21713 if No (Scop) then
21714 Scop := Current_Scope;
21715 end if;
21717 Output_Name (Chars (Id), Scop);
21718 end Output_Entity;
21720 -----------------
21721 -- Output_Name --
21722 -----------------
21724 procedure Output_Name (Nam : Name_Id; Scop : Entity_Id := Current_Scope) is
21725 begin
21726 Write_Str
21727 (Get_Name_String
21728 (Get_Qualified_Name
21729 (Nam => Nam,
21730 Suffix => No_Name,
21731 Scop => Scop)));
21732 Write_Eol;
21733 end Output_Name;
21735 ----------------------
21736 -- Policy_In_Effect --
21737 ----------------------
21739 function Policy_In_Effect (Policy : Name_Id) return Name_Id is
21740 function Policy_In_List (List : Node_Id) return Name_Id;
21741 -- Determine the mode of a policy in a N_Pragma list
21743 --------------------
21744 -- Policy_In_List --
21745 --------------------
21747 function Policy_In_List (List : Node_Id) return Name_Id is
21748 Arg1 : Node_Id;
21749 Arg2 : Node_Id;
21750 Prag : Node_Id;
21752 begin
21753 Prag := List;
21754 while Present (Prag) loop
21755 Arg1 := First (Pragma_Argument_Associations (Prag));
21756 Arg2 := Next (Arg1);
21758 Arg1 := Get_Pragma_Arg (Arg1);
21759 Arg2 := Get_Pragma_Arg (Arg2);
21761 -- The current Check_Policy pragma matches the requested policy or
21762 -- appears in the single argument form (Assertion, policy_id).
21764 if Nam_In (Chars (Arg1), Name_Assertion, Policy) then
21765 return Chars (Arg2);
21766 end if;
21768 Prag := Next_Pragma (Prag);
21769 end loop;
21771 return No_Name;
21772 end Policy_In_List;
21774 -- Local variables
21776 Kind : Name_Id;
21778 -- Start of processing for Policy_In_Effect
21780 begin
21781 if not Is_Valid_Assertion_Kind (Policy) then
21782 raise Program_Error;
21783 end if;
21785 -- Inspect all policy pragmas that appear within scopes (if any)
21787 Kind := Policy_In_List (Check_Policy_List);
21789 -- Inspect all configuration policy pragmas (if any)
21791 if Kind = No_Name then
21792 Kind := Policy_In_List (Check_Policy_List_Config);
21793 end if;
21795 -- The context lacks policy pragmas, determine the mode based on whether
21796 -- assertions are enabled at the configuration level. This ensures that
21797 -- the policy is preserved when analyzing generics.
21799 if Kind = No_Name then
21800 if Assertions_Enabled_Config then
21801 Kind := Name_Check;
21802 else
21803 Kind := Name_Ignore;
21804 end if;
21805 end if;
21807 return Kind;
21808 end Policy_In_Effect;
21810 ----------------------------------
21811 -- Predicate_Tests_On_Arguments --
21812 ----------------------------------
21814 function Predicate_Tests_On_Arguments (Subp : Entity_Id) return Boolean is
21815 begin
21816 -- Always test predicates on indirect call
21818 if Ekind (Subp) = E_Subprogram_Type then
21819 return True;
21821 -- Do not test predicates on call to generated default Finalize, since
21822 -- we are not interested in whether something we are finalizing (and
21823 -- typically destroying) satisfies its predicates.
21825 elsif Chars (Subp) = Name_Finalize
21826 and then not Comes_From_Source (Subp)
21827 then
21828 return False;
21830 -- Do not test predicates on any internally generated routines
21832 elsif Is_Internal_Name (Chars (Subp)) then
21833 return False;
21835 -- Do not test predicates on call to Init_Proc, since if needed the
21836 -- predicate test will occur at some other point.
21838 elsif Is_Init_Proc (Subp) then
21839 return False;
21841 -- Do not test predicates on call to predicate function, since this
21842 -- would cause infinite recursion.
21844 elsif Ekind (Subp) = E_Function
21845 and then (Is_Predicate_Function (Subp)
21846 or else
21847 Is_Predicate_Function_M (Subp))
21848 then
21849 return False;
21851 -- For now, no other exceptions
21853 else
21854 return True;
21855 end if;
21856 end Predicate_Tests_On_Arguments;
21858 -----------------------
21859 -- Private_Component --
21860 -----------------------
21862 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
21863 Ancestor : constant Entity_Id := Base_Type (Type_Id);
21865 function Trace_Components
21866 (T : Entity_Id;
21867 Check : Boolean) return Entity_Id;
21868 -- Recursive function that does the work, and checks against circular
21869 -- definition for each subcomponent type.
21871 ----------------------
21872 -- Trace_Components --
21873 ----------------------
21875 function Trace_Components
21876 (T : Entity_Id;
21877 Check : Boolean) return Entity_Id
21879 Btype : constant Entity_Id := Base_Type (T);
21880 Component : Entity_Id;
21881 P : Entity_Id;
21882 Candidate : Entity_Id := Empty;
21884 begin
21885 if Check and then Btype = Ancestor then
21886 Error_Msg_N ("circular type definition", Type_Id);
21887 return Any_Type;
21888 end if;
21890 if Is_Private_Type (Btype) and then not Is_Generic_Type (Btype) then
21891 if Present (Full_View (Btype))
21892 and then Is_Record_Type (Full_View (Btype))
21893 and then not Is_Frozen (Btype)
21894 then
21895 -- To indicate that the ancestor depends on a private type, the
21896 -- current Btype is sufficient. However, to check for circular
21897 -- definition we must recurse on the full view.
21899 Candidate := Trace_Components (Full_View (Btype), True);
21901 if Candidate = Any_Type then
21902 return Any_Type;
21903 else
21904 return Btype;
21905 end if;
21907 else
21908 return Btype;
21909 end if;
21911 elsif Is_Array_Type (Btype) then
21912 return Trace_Components (Component_Type (Btype), True);
21914 elsif Is_Record_Type (Btype) then
21915 Component := First_Entity (Btype);
21916 while Present (Component)
21917 and then Comes_From_Source (Component)
21918 loop
21919 -- Skip anonymous types generated by constrained components
21921 if not Is_Type (Component) then
21922 P := Trace_Components (Etype (Component), True);
21924 if Present (P) then
21925 if P = Any_Type then
21926 return P;
21927 else
21928 Candidate := P;
21929 end if;
21930 end if;
21931 end if;
21933 Next_Entity (Component);
21934 end loop;
21936 return Candidate;
21938 else
21939 return Empty;
21940 end if;
21941 end Trace_Components;
21943 -- Start of processing for Private_Component
21945 begin
21946 return Trace_Components (Type_Id, False);
21947 end Private_Component;
21949 ---------------------------
21950 -- Primitive_Names_Match --
21951 ---------------------------
21953 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
21954 function Non_Internal_Name (E : Entity_Id) return Name_Id;
21955 -- Given an internal name, returns the corresponding non-internal name
21957 ------------------------
21958 -- Non_Internal_Name --
21959 ------------------------
21961 function Non_Internal_Name (E : Entity_Id) return Name_Id is
21962 begin
21963 Get_Name_String (Chars (E));
21964 Name_Len := Name_Len - 1;
21965 return Name_Find;
21966 end Non_Internal_Name;
21968 -- Start of processing for Primitive_Names_Match
21970 begin
21971 pragma Assert (Present (E1) and then Present (E2));
21973 return Chars (E1) = Chars (E2)
21974 or else
21975 (not Is_Internal_Name (Chars (E1))
21976 and then Is_Internal_Name (Chars (E2))
21977 and then Non_Internal_Name (E2) = Chars (E1))
21978 or else
21979 (not Is_Internal_Name (Chars (E2))
21980 and then Is_Internal_Name (Chars (E1))
21981 and then Non_Internal_Name (E1) = Chars (E2))
21982 or else
21983 (Is_Predefined_Dispatching_Operation (E1)
21984 and then Is_Predefined_Dispatching_Operation (E2)
21985 and then Same_TSS (E1, E2))
21986 or else
21987 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
21988 end Primitive_Names_Match;
21990 -----------------------
21991 -- Process_End_Label --
21992 -----------------------
21994 procedure Process_End_Label
21995 (N : Node_Id;
21996 Typ : Character;
21997 Ent : Entity_Id)
21999 Loc : Source_Ptr;
22000 Nam : Node_Id;
22001 Scop : Entity_Id;
22003 Label_Ref : Boolean;
22004 -- Set True if reference to end label itself is required
22006 Endl : Node_Id;
22007 -- Gets set to the operator symbol or identifier that references the
22008 -- entity Ent. For the child unit case, this is the identifier from the
22009 -- designator. For other cases, this is simply Endl.
22011 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
22012 -- N is an identifier node that appears as a parent unit reference in
22013 -- the case where Ent is a child unit. This procedure generates an
22014 -- appropriate cross-reference entry. E is the corresponding entity.
22016 -------------------------
22017 -- Generate_Parent_Ref --
22018 -------------------------
22020 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
22021 begin
22022 -- If names do not match, something weird, skip reference
22024 if Chars (E) = Chars (N) then
22026 -- Generate the reference. We do NOT consider this as a reference
22027 -- for unreferenced symbol purposes.
22029 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
22031 if Style_Check then
22032 Style.Check_Identifier (N, E);
22033 end if;
22034 end if;
22035 end Generate_Parent_Ref;
22037 -- Start of processing for Process_End_Label
22039 begin
22040 -- If no node, ignore. This happens in some error situations, and
22041 -- also for some internally generated structures where no end label
22042 -- references are required in any case.
22044 if No (N) then
22045 return;
22046 end if;
22048 -- Nothing to do if no End_Label, happens for internally generated
22049 -- constructs where we don't want an end label reference anyway. Also
22050 -- nothing to do if Endl is a string literal, which means there was
22051 -- some prior error (bad operator symbol)
22053 Endl := End_Label (N);
22055 if No (Endl) or else Nkind (Endl) = N_String_Literal then
22056 return;
22057 end if;
22059 -- Reference node is not in extended main source unit
22061 if not In_Extended_Main_Source_Unit (N) then
22063 -- Generally we do not collect references except for the extended
22064 -- main source unit. The one exception is the 'e' entry for a
22065 -- package spec, where it is useful for a client to have the
22066 -- ending information to define scopes.
22068 if Typ /= 'e' then
22069 return;
22071 else
22072 Label_Ref := False;
22074 -- For this case, we can ignore any parent references, but we
22075 -- need the package name itself for the 'e' entry.
22077 if Nkind (Endl) = N_Designator then
22078 Endl := Identifier (Endl);
22079 end if;
22080 end if;
22082 -- Reference is in extended main source unit
22084 else
22085 Label_Ref := True;
22087 -- For designator, generate references for the parent entries
22089 if Nkind (Endl) = N_Designator then
22091 -- Generate references for the prefix if the END line comes from
22092 -- source (otherwise we do not need these references) We climb the
22093 -- scope stack to find the expected entities.
22095 if Comes_From_Source (Endl) then
22096 Nam := Name (Endl);
22097 Scop := Current_Scope;
22098 while Nkind (Nam) = N_Selected_Component loop
22099 Scop := Scope (Scop);
22100 exit when No (Scop);
22101 Generate_Parent_Ref (Selector_Name (Nam), Scop);
22102 Nam := Prefix (Nam);
22103 end loop;
22105 if Present (Scop) then
22106 Generate_Parent_Ref (Nam, Scope (Scop));
22107 end if;
22108 end if;
22110 Endl := Identifier (Endl);
22111 end if;
22112 end if;
22114 -- If the end label is not for the given entity, then either we have
22115 -- some previous error, or this is a generic instantiation for which
22116 -- we do not need to make a cross-reference in this case anyway. In
22117 -- either case we simply ignore the call.
22119 if Chars (Ent) /= Chars (Endl) then
22120 return;
22121 end if;
22123 -- If label was really there, then generate a normal reference and then
22124 -- adjust the location in the end label to point past the name (which
22125 -- should almost always be the semicolon).
22127 Loc := Sloc (Endl);
22129 if Comes_From_Source (Endl) then
22131 -- If a label reference is required, then do the style check and
22132 -- generate an l-type cross-reference entry for the label
22134 if Label_Ref then
22135 if Style_Check then
22136 Style.Check_Identifier (Endl, Ent);
22137 end if;
22139 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
22140 end if;
22142 -- Set the location to point past the label (normally this will
22143 -- mean the semicolon immediately following the label). This is
22144 -- done for the sake of the 'e' or 't' entry generated below.
22146 Get_Decoded_Name_String (Chars (Endl));
22147 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
22149 else
22150 -- In SPARK mode, no missing label is allowed for packages and
22151 -- subprogram bodies. Detect those cases by testing whether
22152 -- Process_End_Label was called for a body (Typ = 't') or a package.
22154 if Restriction_Check_Required (SPARK_05)
22155 and then (Typ = 't' or else Ekind (Ent) = E_Package)
22156 then
22157 Error_Msg_Node_1 := Endl;
22158 Check_SPARK_05_Restriction
22159 ("`END &` required", Endl, Force => True);
22160 end if;
22161 end if;
22163 -- Now generate the e/t reference
22165 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
22167 -- Restore Sloc, in case modified above, since we have an identifier
22168 -- and the normal Sloc should be left set in the tree.
22170 Set_Sloc (Endl, Loc);
22171 end Process_End_Label;
22173 --------------------------------
22174 -- Propagate_Concurrent_Flags --
22175 --------------------------------
22177 procedure Propagate_Concurrent_Flags
22178 (Typ : Entity_Id;
22179 Comp_Typ : Entity_Id)
22181 begin
22182 if Has_Task (Comp_Typ) then
22183 Set_Has_Task (Typ);
22184 end if;
22186 if Has_Protected (Comp_Typ) then
22187 Set_Has_Protected (Typ);
22188 end if;
22190 if Has_Timing_Event (Comp_Typ) then
22191 Set_Has_Timing_Event (Typ);
22192 end if;
22193 end Propagate_Concurrent_Flags;
22195 ------------------------------
22196 -- Propagate_DIC_Attributes --
22197 ------------------------------
22199 procedure Propagate_DIC_Attributes
22200 (Typ : Entity_Id;
22201 From_Typ : Entity_Id)
22203 DIC_Proc : Entity_Id;
22205 begin
22206 if Present (Typ) and then Present (From_Typ) then
22207 pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
22209 -- Nothing to do if both the source and the destination denote the
22210 -- same type.
22212 if From_Typ = Typ then
22213 return;
22214 end if;
22216 DIC_Proc := DIC_Procedure (From_Typ);
22218 -- The setting of the attributes is intentionally conservative. This
22219 -- prevents accidental clobbering of enabled attributes.
22221 if Has_Inherited_DIC (From_Typ)
22222 and then not Has_Inherited_DIC (Typ)
22223 then
22224 Set_Has_Inherited_DIC (Typ);
22225 end if;
22227 if Has_Own_DIC (From_Typ) and then not Has_Own_DIC (Typ) then
22228 Set_Has_Own_DIC (Typ);
22229 end if;
22231 if Present (DIC_Proc) and then No (DIC_Procedure (Typ)) then
22232 Set_DIC_Procedure (Typ, DIC_Proc);
22233 end if;
22234 end if;
22235 end Propagate_DIC_Attributes;
22237 ------------------------------------
22238 -- Propagate_Invariant_Attributes --
22239 ------------------------------------
22241 procedure Propagate_Invariant_Attributes
22242 (Typ : Entity_Id;
22243 From_Typ : Entity_Id)
22245 Full_IP : Entity_Id;
22246 Part_IP : Entity_Id;
22248 begin
22249 if Present (Typ) and then Present (From_Typ) then
22250 pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
22252 -- Nothing to do if both the source and the destination denote the
22253 -- same type.
22255 if From_Typ = Typ then
22256 return;
22257 end if;
22259 Full_IP := Invariant_Procedure (From_Typ);
22260 Part_IP := Partial_Invariant_Procedure (From_Typ);
22262 -- The setting of the attributes is intentionally conservative. This
22263 -- prevents accidental clobbering of enabled attributes.
22265 if Has_Inheritable_Invariants (From_Typ)
22266 and then not Has_Inheritable_Invariants (Typ)
22267 then
22268 Set_Has_Inheritable_Invariants (Typ, True);
22269 end if;
22271 if Has_Inherited_Invariants (From_Typ)
22272 and then not Has_Inherited_Invariants (Typ)
22273 then
22274 Set_Has_Inherited_Invariants (Typ, True);
22275 end if;
22277 if Has_Own_Invariants (From_Typ)
22278 and then not Has_Own_Invariants (Typ)
22279 then
22280 Set_Has_Own_Invariants (Typ, True);
22281 end if;
22283 if Present (Full_IP) and then No (Invariant_Procedure (Typ)) then
22284 Set_Invariant_Procedure (Typ, Full_IP);
22285 end if;
22287 if Present (Part_IP) and then No (Partial_Invariant_Procedure (Typ))
22288 then
22289 Set_Partial_Invariant_Procedure (Typ, Part_IP);
22290 end if;
22291 end if;
22292 end Propagate_Invariant_Attributes;
22294 ---------------------------------------
22295 -- Record_Possible_Part_Of_Reference --
22296 ---------------------------------------
22298 procedure Record_Possible_Part_Of_Reference
22299 (Var_Id : Entity_Id;
22300 Ref : Node_Id)
22302 Encap : constant Entity_Id := Encapsulating_State (Var_Id);
22303 Refs : Elist_Id;
22305 begin
22306 -- The variable is a constituent of a single protected/task type. Such
22307 -- a variable acts as a component of the type and must appear within a
22308 -- specific region (SPARK RM 9(3)). Instead of recording the reference,
22309 -- verify its legality now.
22311 if Present (Encap) and then Is_Single_Concurrent_Object (Encap) then
22312 Check_Part_Of_Reference (Var_Id, Ref);
22314 -- The variable is subject to pragma Part_Of and may eventually become a
22315 -- constituent of a single protected/task type. Record the reference to
22316 -- verify its placement when the contract of the variable is analyzed.
22318 elsif Present (Get_Pragma (Var_Id, Pragma_Part_Of)) then
22319 Refs := Part_Of_References (Var_Id);
22321 if No (Refs) then
22322 Refs := New_Elmt_List;
22323 Set_Part_Of_References (Var_Id, Refs);
22324 end if;
22326 Append_Elmt (Ref, Refs);
22327 end if;
22328 end Record_Possible_Part_Of_Reference;
22330 ----------------
22331 -- Referenced --
22332 ----------------
22334 function Referenced (Id : Entity_Id; Expr : Node_Id) return Boolean is
22335 Seen : Boolean := False;
22337 function Is_Reference (N : Node_Id) return Traverse_Result;
22338 -- Determine whether node N denotes a reference to Id. If this is the
22339 -- case, set global flag Seen to True and stop the traversal.
22341 ------------------
22342 -- Is_Reference --
22343 ------------------
22345 function Is_Reference (N : Node_Id) return Traverse_Result is
22346 begin
22347 if Is_Entity_Name (N)
22348 and then Present (Entity (N))
22349 and then Entity (N) = Id
22350 then
22351 Seen := True;
22352 return Abandon;
22353 else
22354 return OK;
22355 end if;
22356 end Is_Reference;
22358 procedure Inspect_Expression is new Traverse_Proc (Is_Reference);
22360 -- Start of processing for Referenced
22362 begin
22363 Inspect_Expression (Expr);
22364 return Seen;
22365 end Referenced;
22367 ------------------------------------
22368 -- References_Generic_Formal_Type --
22369 ------------------------------------
22371 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
22373 function Process (N : Node_Id) return Traverse_Result;
22374 -- Process one node in search for generic formal type
22376 -------------
22377 -- Process --
22378 -------------
22380 function Process (N : Node_Id) return Traverse_Result is
22381 begin
22382 if Nkind (N) in N_Has_Entity then
22383 declare
22384 E : constant Entity_Id := Entity (N);
22385 begin
22386 if Present (E) then
22387 if Is_Generic_Type (E) then
22388 return Abandon;
22389 elsif Present (Etype (E))
22390 and then Is_Generic_Type (Etype (E))
22391 then
22392 return Abandon;
22393 end if;
22394 end if;
22395 end;
22396 end if;
22398 return Atree.OK;
22399 end Process;
22401 function Traverse is new Traverse_Func (Process);
22402 -- Traverse tree to look for generic type
22404 begin
22405 if Inside_A_Generic then
22406 return Traverse (N) = Abandon;
22407 else
22408 return False;
22409 end if;
22410 end References_Generic_Formal_Type;
22412 -------------------
22413 -- Remove_Entity --
22414 -------------------
22416 procedure Remove_Entity (Id : Entity_Id) is
22417 Scop : constant Entity_Id := Scope (Id);
22418 Prev_Id : Entity_Id;
22420 begin
22421 -- Remove the entity from the homonym chain. When the entity is the
22422 -- head of the chain, associate the entry in the name table with its
22423 -- homonym effectively making it the new head of the chain.
22425 if Current_Entity (Id) = Id then
22426 Set_Name_Entity_Id (Chars (Id), Homonym (Id));
22428 -- Otherwise link the previous and next homonyms
22430 else
22431 Prev_Id := Current_Entity (Id);
22432 if Present (Prev_Id) then
22433 while Present (Prev_Id) and then Homonym (Prev_Id) /= Id loop
22434 Prev_Id := Homonym (Prev_Id);
22435 end loop;
22437 Set_Homonym (Prev_Id, Homonym (Id));
22438 end if;
22439 end if;
22441 -- Remove the entity from the scope entity chain. When the entity is
22442 -- the head of the chain, set the next entity as the new head of the
22443 -- chain.
22445 if First_Entity (Scop) = Id then
22446 Prev_Id := Empty;
22447 Set_First_Entity (Scop, Next_Entity (Id));
22449 -- Otherwise the entity is either in the middle of the chain or it acts
22450 -- as its tail. Traverse and link the previous and next entities.
22452 else
22453 Prev_Id := First_Entity (Scop);
22454 while Present (Prev_Id) and then Next_Entity (Prev_Id) /= Id loop
22455 Next_Entity (Prev_Id);
22456 end loop;
22458 if Present (Prev_Id) then
22459 Set_Next_Entity (Prev_Id, Next_Entity (Id));
22460 end if;
22461 end if;
22463 -- Handle the case where the entity acts as the tail of the scope entity
22464 -- chain.
22466 if Last_Entity (Scop) = Id then
22467 Set_Last_Entity (Scop, Prev_Id);
22468 end if;
22469 end Remove_Entity;
22471 --------------------
22472 -- Remove_Homonym --
22473 --------------------
22475 procedure Remove_Homonym (E : Entity_Id) is
22476 Prev : Entity_Id := Empty;
22477 H : Entity_Id;
22479 begin
22480 if E = Current_Entity (E) then
22481 if Present (Homonym (E)) then
22482 Set_Current_Entity (Homonym (E));
22483 else
22484 Set_Name_Entity_Id (Chars (E), Empty);
22485 end if;
22487 else
22488 H := Current_Entity (E);
22489 while Present (H) and then H /= E loop
22490 Prev := H;
22491 H := Homonym (H);
22492 end loop;
22494 -- If E is not on the homonym chain, nothing to do
22496 if Present (H) then
22497 Set_Homonym (Prev, Homonym (E));
22498 end if;
22499 end if;
22500 end Remove_Homonym;
22502 ------------------------------
22503 -- Remove_Overloaded_Entity --
22504 ------------------------------
22506 procedure Remove_Overloaded_Entity (Id : Entity_Id) is
22507 procedure Remove_Primitive_Of (Typ : Entity_Id);
22508 -- Remove primitive subprogram Id from the list of primitives that
22509 -- belong to type Typ.
22511 -------------------------
22512 -- Remove_Primitive_Of --
22513 -------------------------
22515 procedure Remove_Primitive_Of (Typ : Entity_Id) is
22516 Prims : Elist_Id;
22518 begin
22519 if Is_Tagged_Type (Typ) then
22520 Prims := Direct_Primitive_Operations (Typ);
22522 if Present (Prims) then
22523 Remove (Prims, Id);
22524 end if;
22525 end if;
22526 end Remove_Primitive_Of;
22528 -- Local variables
22530 Formal : Entity_Id;
22532 -- Start of processing for Remove_Overloaded_Entity
22534 begin
22535 -- Remove the entity from both the homonym and scope chains
22537 Remove_Entity (Id);
22539 -- The entity denotes a primitive subprogram. Remove it from the list of
22540 -- primitives of the associated controlling type.
22542 if Ekind_In (Id, E_Function, E_Procedure) and then Is_Primitive (Id) then
22543 Formal := First_Formal (Id);
22544 while Present (Formal) loop
22545 if Is_Controlling_Formal (Formal) then
22546 Remove_Primitive_Of (Etype (Formal));
22547 exit;
22548 end if;
22550 Next_Formal (Formal);
22551 end loop;
22553 if Ekind (Id) = E_Function and then Has_Controlling_Result (Id) then
22554 Remove_Primitive_Of (Etype (Id));
22555 end if;
22556 end if;
22557 end Remove_Overloaded_Entity;
22559 ---------------------
22560 -- Rep_To_Pos_Flag --
22561 ---------------------
22563 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
22564 begin
22565 return New_Occurrence_Of
22566 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
22567 end Rep_To_Pos_Flag;
22569 --------------------
22570 -- Require_Entity --
22571 --------------------
22573 procedure Require_Entity (N : Node_Id) is
22574 begin
22575 if Is_Entity_Name (N) and then No (Entity (N)) then
22576 if Total_Errors_Detected /= 0 then
22577 Set_Entity (N, Any_Id);
22578 else
22579 raise Program_Error;
22580 end if;
22581 end if;
22582 end Require_Entity;
22584 ------------------------------
22585 -- Requires_Transient_Scope --
22586 ------------------------------
22588 -- A transient scope is required when variable-sized temporaries are
22589 -- allocated on the secondary stack, or when finalization actions must be
22590 -- generated before the next instruction.
22592 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
22593 Old_Result : constant Boolean := Old_Requires_Transient_Scope (Id);
22595 begin
22596 if Debug_Flag_QQ then
22597 return Old_Result;
22598 end if;
22600 declare
22601 New_Result : constant Boolean := New_Requires_Transient_Scope (Id);
22603 begin
22604 -- Assert that we're not putting things on the secondary stack if we
22605 -- didn't before; we are trying to AVOID secondary stack when
22606 -- possible.
22608 if not Old_Result then
22609 pragma Assert (not New_Result);
22610 null;
22611 end if;
22613 if New_Result /= Old_Result then
22614 Results_Differ (Id, Old_Result, New_Result);
22615 end if;
22617 return New_Result;
22618 end;
22619 end Requires_Transient_Scope;
22621 --------------------
22622 -- Results_Differ --
22623 --------------------
22625 procedure Results_Differ
22626 (Id : Entity_Id;
22627 Old_Val : Boolean;
22628 New_Val : Boolean)
22630 begin
22631 if False then -- False to disable; True for debugging
22632 Treepr.Print_Tree_Node (Id);
22634 if Old_Val = New_Val then
22635 raise Program_Error;
22636 end if;
22637 end if;
22638 end Results_Differ;
22640 --------------------------
22641 -- Reset_Analyzed_Flags --
22642 --------------------------
22644 procedure Reset_Analyzed_Flags (N : Node_Id) is
22645 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
22646 -- Function used to reset Analyzed flags in tree. Note that we do
22647 -- not reset Analyzed flags in entities, since there is no need to
22648 -- reanalyze entities, and indeed, it is wrong to do so, since it
22649 -- can result in generating auxiliary stuff more than once.
22651 --------------------
22652 -- Clear_Analyzed --
22653 --------------------
22655 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
22656 begin
22657 if Nkind (N) not in N_Entity then
22658 Set_Analyzed (N, False);
22659 end if;
22661 return OK;
22662 end Clear_Analyzed;
22664 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
22666 -- Start of processing for Reset_Analyzed_Flags
22668 begin
22669 Reset_Analyzed (N);
22670 end Reset_Analyzed_Flags;
22672 ------------------------
22673 -- Restore_SPARK_Mode --
22674 ------------------------
22676 procedure Restore_SPARK_Mode
22677 (Mode : SPARK_Mode_Type;
22678 Prag : Node_Id)
22680 begin
22681 SPARK_Mode := Mode;
22682 SPARK_Mode_Pragma := Prag;
22683 end Restore_SPARK_Mode;
22685 --------------------------------
22686 -- Returns_Unconstrained_Type --
22687 --------------------------------
22689 function Returns_Unconstrained_Type (Subp : Entity_Id) return Boolean is
22690 begin
22691 return Ekind (Subp) = E_Function
22692 and then not Is_Scalar_Type (Etype (Subp))
22693 and then not Is_Access_Type (Etype (Subp))
22694 and then not Is_Constrained (Etype (Subp));
22695 end Returns_Unconstrained_Type;
22697 ----------------------------
22698 -- Root_Type_Of_Full_View --
22699 ----------------------------
22701 function Root_Type_Of_Full_View (T : Entity_Id) return Entity_Id is
22702 Rtyp : constant Entity_Id := Root_Type (T);
22704 begin
22705 -- The root type of the full view may itself be a private type. Keep
22706 -- looking for the ultimate derivation parent.
22708 if Is_Private_Type (Rtyp) and then Present (Full_View (Rtyp)) then
22709 return Root_Type_Of_Full_View (Full_View (Rtyp));
22710 else
22711 return Rtyp;
22712 end if;
22713 end Root_Type_Of_Full_View;
22715 ---------------------------
22716 -- Safe_To_Capture_Value --
22717 ---------------------------
22719 function Safe_To_Capture_Value
22720 (N : Node_Id;
22721 Ent : Entity_Id;
22722 Cond : Boolean := False) return Boolean
22724 begin
22725 -- The only entities for which we track constant values are variables
22726 -- which are not renamings, constants, out parameters, and in out
22727 -- parameters, so check if we have this case.
22729 -- Note: it may seem odd to track constant values for constants, but in
22730 -- fact this routine is used for other purposes than simply capturing
22731 -- the value. In particular, the setting of Known[_Non]_Null.
22733 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
22734 or else
22735 Ekind_In (Ent, E_Constant, E_Out_Parameter, E_In_Out_Parameter)
22736 then
22737 null;
22739 -- For conditionals, we also allow loop parameters and all formals,
22740 -- including in parameters.
22742 elsif Cond and then Ekind_In (Ent, E_Loop_Parameter, E_In_Parameter) then
22743 null;
22745 -- For all other cases, not just unsafe, but impossible to capture
22746 -- Current_Value, since the above are the only entities which have
22747 -- Current_Value fields.
22749 else
22750 return False;
22751 end if;
22753 -- Skip if volatile or aliased, since funny things might be going on in
22754 -- these cases which we cannot necessarily track. Also skip any variable
22755 -- for which an address clause is given, or whose address is taken. Also
22756 -- never capture value of library level variables (an attempt to do so
22757 -- can occur in the case of package elaboration code).
22759 if Treat_As_Volatile (Ent)
22760 or else Is_Aliased (Ent)
22761 or else Present (Address_Clause (Ent))
22762 or else Address_Taken (Ent)
22763 or else (Is_Library_Level_Entity (Ent)
22764 and then Ekind (Ent) = E_Variable)
22765 then
22766 return False;
22767 end if;
22769 -- OK, all above conditions are met. We also require that the scope of
22770 -- the reference be the same as the scope of the entity, not counting
22771 -- packages and blocks and loops.
22773 declare
22774 E_Scope : constant Entity_Id := Scope (Ent);
22775 R_Scope : Entity_Id;
22777 begin
22778 R_Scope := Current_Scope;
22779 while R_Scope /= Standard_Standard loop
22780 exit when R_Scope = E_Scope;
22782 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
22783 return False;
22784 else
22785 R_Scope := Scope (R_Scope);
22786 end if;
22787 end loop;
22788 end;
22790 -- We also require that the reference does not appear in a context
22791 -- where it is not sure to be executed (i.e. a conditional context
22792 -- or an exception handler). We skip this if Cond is True, since the
22793 -- capturing of values from conditional tests handles this ok.
22795 if Cond then
22796 return True;
22797 end if;
22799 declare
22800 Desc : Node_Id;
22801 P : Node_Id;
22803 begin
22804 Desc := N;
22806 -- Seems dubious that case expressions are not handled here ???
22808 P := Parent (N);
22809 while Present (P) loop
22810 if Nkind (P) = N_If_Statement
22811 or else Nkind (P) = N_Case_Statement
22812 or else (Nkind (P) in N_Short_Circuit
22813 and then Desc = Right_Opnd (P))
22814 or else (Nkind (P) = N_If_Expression
22815 and then Desc /= First (Expressions (P)))
22816 or else Nkind (P) = N_Exception_Handler
22817 or else Nkind (P) = N_Selective_Accept
22818 or else Nkind (P) = N_Conditional_Entry_Call
22819 or else Nkind (P) = N_Timed_Entry_Call
22820 or else Nkind (P) = N_Asynchronous_Select
22821 then
22822 return False;
22824 else
22825 Desc := P;
22826 P := Parent (P);
22828 -- A special Ada 2012 case: the original node may be part
22829 -- of the else_actions of a conditional expression, in which
22830 -- case it might not have been expanded yet, and appears in
22831 -- a non-syntactic list of actions. In that case it is clearly
22832 -- not safe to save a value.
22834 if No (P)
22835 and then Is_List_Member (Desc)
22836 and then No (Parent (List_Containing (Desc)))
22837 then
22838 return False;
22839 end if;
22840 end if;
22841 end loop;
22842 end;
22844 -- OK, looks safe to set value
22846 return True;
22847 end Safe_To_Capture_Value;
22849 ---------------
22850 -- Same_Name --
22851 ---------------
22853 function Same_Name (N1, N2 : Node_Id) return Boolean is
22854 K1 : constant Node_Kind := Nkind (N1);
22855 K2 : constant Node_Kind := Nkind (N2);
22857 begin
22858 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
22859 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
22860 then
22861 return Chars (N1) = Chars (N2);
22863 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
22864 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
22865 then
22866 return Same_Name (Selector_Name (N1), Selector_Name (N2))
22867 and then Same_Name (Prefix (N1), Prefix (N2));
22869 else
22870 return False;
22871 end if;
22872 end Same_Name;
22874 -----------------
22875 -- Same_Object --
22876 -----------------
22878 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
22879 N1 : constant Node_Id := Original_Node (Node1);
22880 N2 : constant Node_Id := Original_Node (Node2);
22881 -- We do the tests on original nodes, since we are most interested
22882 -- in the original source, not any expansion that got in the way.
22884 K1 : constant Node_Kind := Nkind (N1);
22885 K2 : constant Node_Kind := Nkind (N2);
22887 begin
22888 -- First case, both are entities with same entity
22890 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
22891 declare
22892 EN1 : constant Entity_Id := Entity (N1);
22893 EN2 : constant Entity_Id := Entity (N2);
22894 begin
22895 if Present (EN1) and then Present (EN2)
22896 and then (Ekind_In (EN1, E_Variable, E_Constant)
22897 or else Is_Formal (EN1))
22898 and then EN1 = EN2
22899 then
22900 return True;
22901 end if;
22902 end;
22903 end if;
22905 -- Second case, selected component with same selector, same record
22907 if K1 = N_Selected_Component
22908 and then K2 = N_Selected_Component
22909 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
22910 then
22911 return Same_Object (Prefix (N1), Prefix (N2));
22913 -- Third case, indexed component with same subscripts, same array
22915 elsif K1 = N_Indexed_Component
22916 and then K2 = N_Indexed_Component
22917 and then Same_Object (Prefix (N1), Prefix (N2))
22918 then
22919 declare
22920 E1, E2 : Node_Id;
22921 begin
22922 E1 := First (Expressions (N1));
22923 E2 := First (Expressions (N2));
22924 while Present (E1) loop
22925 if not Same_Value (E1, E2) then
22926 return False;
22927 else
22928 Next (E1);
22929 Next (E2);
22930 end if;
22931 end loop;
22933 return True;
22934 end;
22936 -- Fourth case, slice of same array with same bounds
22938 elsif K1 = N_Slice
22939 and then K2 = N_Slice
22940 and then Nkind (Discrete_Range (N1)) = N_Range
22941 and then Nkind (Discrete_Range (N2)) = N_Range
22942 and then Same_Value (Low_Bound (Discrete_Range (N1)),
22943 Low_Bound (Discrete_Range (N2)))
22944 and then Same_Value (High_Bound (Discrete_Range (N1)),
22945 High_Bound (Discrete_Range (N2)))
22946 then
22947 return Same_Name (Prefix (N1), Prefix (N2));
22949 -- All other cases, not clearly the same object
22951 else
22952 return False;
22953 end if;
22954 end Same_Object;
22956 ---------------
22957 -- Same_Type --
22958 ---------------
22960 function Same_Type (T1, T2 : Entity_Id) return Boolean is
22961 begin
22962 if T1 = T2 then
22963 return True;
22965 elsif not Is_Constrained (T1)
22966 and then not Is_Constrained (T2)
22967 and then Base_Type (T1) = Base_Type (T2)
22968 then
22969 return True;
22971 -- For now don't bother with case of identical constraints, to be
22972 -- fiddled with later on perhaps (this is only used for optimization
22973 -- purposes, so it is not critical to do a best possible job)
22975 else
22976 return False;
22977 end if;
22978 end Same_Type;
22980 ----------------
22981 -- Same_Value --
22982 ----------------
22984 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
22985 begin
22986 if Compile_Time_Known_Value (Node1)
22987 and then Compile_Time_Known_Value (Node2)
22988 then
22989 -- Handle properly compile-time expressions that are not
22990 -- scalar.
22992 if Is_String_Type (Etype (Node1)) then
22993 return Expr_Value_S (Node1) = Expr_Value_S (Node2);
22995 else
22996 return Expr_Value (Node1) = Expr_Value (Node2);
22997 end if;
22999 elsif Same_Object (Node1, Node2) then
23000 return True;
23001 else
23002 return False;
23003 end if;
23004 end Same_Value;
23006 --------------------
23007 -- Set_SPARK_Mode --
23008 --------------------
23010 procedure Set_SPARK_Mode (Context : Entity_Id) is
23011 begin
23012 -- Do not consider illegal or partially decorated constructs
23014 if Ekind (Context) = E_Void or else Error_Posted (Context) then
23015 null;
23017 elsif Present (SPARK_Pragma (Context)) then
23018 Install_SPARK_Mode
23019 (Mode => Get_SPARK_Mode_From_Annotation (SPARK_Pragma (Context)),
23020 Prag => SPARK_Pragma (Context));
23021 end if;
23022 end Set_SPARK_Mode;
23024 -------------------------
23025 -- Scalar_Part_Present --
23026 -------------------------
23028 function Scalar_Part_Present (T : Entity_Id) return Boolean is
23029 C : Entity_Id;
23031 begin
23032 if Is_Scalar_Type (T) then
23033 return True;
23035 elsif Is_Array_Type (T) then
23036 return Scalar_Part_Present (Component_Type (T));
23038 elsif Is_Record_Type (T) or else Has_Discriminants (T) then
23039 C := First_Component_Or_Discriminant (T);
23040 while Present (C) loop
23041 if Scalar_Part_Present (Etype (C)) then
23042 return True;
23043 else
23044 Next_Component_Or_Discriminant (C);
23045 end if;
23046 end loop;
23047 end if;
23049 return False;
23050 end Scalar_Part_Present;
23052 ------------------------
23053 -- Scope_Is_Transient --
23054 ------------------------
23056 function Scope_Is_Transient return Boolean is
23057 begin
23058 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
23059 end Scope_Is_Transient;
23061 ------------------
23062 -- Scope_Within --
23063 ------------------
23065 function Scope_Within
23066 (Inner : Entity_Id;
23067 Outer : Entity_Id) return Boolean
23069 Curr : Entity_Id;
23071 begin
23072 Curr := Inner;
23073 while Present (Curr) and then Curr /= Standard_Standard loop
23074 Curr := Scope (Curr);
23076 if Curr = Outer then
23077 return True;
23078 end if;
23079 end loop;
23081 return False;
23082 end Scope_Within;
23084 --------------------------
23085 -- Scope_Within_Or_Same --
23086 --------------------------
23088 function Scope_Within_Or_Same
23089 (Inner : Entity_Id;
23090 Outer : Entity_Id) return Boolean
23092 Curr : Entity_Id;
23094 begin
23095 Curr := Inner;
23096 while Present (Curr) and then Curr /= Standard_Standard loop
23097 if Curr = Outer then
23098 return True;
23099 end if;
23101 Curr := Scope (Curr);
23102 end loop;
23104 return False;
23105 end Scope_Within_Or_Same;
23107 --------------------
23108 -- Set_Convention --
23109 --------------------
23111 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
23112 begin
23113 Basic_Set_Convention (E, Val);
23115 if Is_Type (E)
23116 and then Is_Access_Subprogram_Type (Base_Type (E))
23117 and then Has_Foreign_Convention (E)
23118 then
23119 Set_Can_Use_Internal_Rep (E, False);
23120 end if;
23122 -- If E is an object, including a component, and the type of E is an
23123 -- anonymous access type with no convention set, then also set the
23124 -- convention of the anonymous access type. We do not do this for
23125 -- anonymous protected types, since protected types always have the
23126 -- default convention.
23128 if Present (Etype (E))
23129 and then (Is_Object (E)
23131 -- Allow E_Void (happens for pragma Convention appearing
23132 -- in the middle of a record applying to a component)
23134 or else Ekind (E) = E_Void)
23135 then
23136 declare
23137 Typ : constant Entity_Id := Etype (E);
23139 begin
23140 if Ekind_In (Typ, E_Anonymous_Access_Type,
23141 E_Anonymous_Access_Subprogram_Type)
23142 and then not Has_Convention_Pragma (Typ)
23143 then
23144 Basic_Set_Convention (Typ, Val);
23145 Set_Has_Convention_Pragma (Typ);
23147 -- And for the access subprogram type, deal similarly with the
23148 -- designated E_Subprogram_Type, which is always internal.
23150 if Ekind (Typ) = E_Anonymous_Access_Subprogram_Type then
23151 declare
23152 Dtype : constant Entity_Id := Designated_Type (Typ);
23153 begin
23154 if Ekind (Dtype) = E_Subprogram_Type
23155 and then not Has_Convention_Pragma (Dtype)
23156 then
23157 Basic_Set_Convention (Dtype, Val);
23158 Set_Has_Convention_Pragma (Dtype);
23159 end if;
23160 end;
23161 end if;
23162 end if;
23163 end;
23164 end if;
23165 end Set_Convention;
23167 ------------------------
23168 -- Set_Current_Entity --
23169 ------------------------
23171 -- The given entity is to be set as the currently visible definition of its
23172 -- associated name (i.e. the Node_Id associated with its name). All we have
23173 -- to do is to get the name from the identifier, and then set the
23174 -- associated Node_Id to point to the given entity.
23176 procedure Set_Current_Entity (E : Entity_Id) is
23177 begin
23178 Set_Name_Entity_Id (Chars (E), E);
23179 end Set_Current_Entity;
23181 ---------------------------
23182 -- Set_Debug_Info_Needed --
23183 ---------------------------
23185 procedure Set_Debug_Info_Needed (T : Entity_Id) is
23187 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
23188 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
23189 -- Used to set debug info in a related node if not set already
23191 --------------------------------------
23192 -- Set_Debug_Info_Needed_If_Not_Set --
23193 --------------------------------------
23195 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
23196 begin
23197 if Present (E) and then not Needs_Debug_Info (E) then
23198 Set_Debug_Info_Needed (E);
23200 -- For a private type, indicate that the full view also needs
23201 -- debug information.
23203 if Is_Type (E)
23204 and then Is_Private_Type (E)
23205 and then Present (Full_View (E))
23206 then
23207 Set_Debug_Info_Needed (Full_View (E));
23208 end if;
23209 end if;
23210 end Set_Debug_Info_Needed_If_Not_Set;
23212 -- Start of processing for Set_Debug_Info_Needed
23214 begin
23215 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
23216 -- indicates that Debug_Info_Needed is never required for the entity.
23217 -- Nothing to do if entity comes from a predefined file. Library files
23218 -- are compiled without debug information, but inlined bodies of these
23219 -- routines may appear in user code, and debug information on them ends
23220 -- up complicating debugging the user code.
23222 if No (T)
23223 or else Debug_Info_Off (T)
23224 then
23225 return;
23227 elsif In_Inlined_Body and then In_Predefined_Unit (T) then
23228 Set_Needs_Debug_Info (T, False);
23229 end if;
23231 -- Set flag in entity itself. Note that we will go through the following
23232 -- circuitry even if the flag is already set on T. That's intentional,
23233 -- it makes sure that the flag will be set in subsidiary entities.
23235 Set_Needs_Debug_Info (T);
23237 -- Set flag on subsidiary entities if not set already
23239 if Is_Object (T) then
23240 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
23242 elsif Is_Type (T) then
23243 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
23245 if Is_Record_Type (T) then
23246 declare
23247 Ent : Entity_Id := First_Entity (T);
23248 begin
23249 while Present (Ent) loop
23250 Set_Debug_Info_Needed_If_Not_Set (Ent);
23251 Next_Entity (Ent);
23252 end loop;
23253 end;
23255 -- For a class wide subtype, we also need debug information
23256 -- for the equivalent type.
23258 if Ekind (T) = E_Class_Wide_Subtype then
23259 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
23260 end if;
23262 elsif Is_Array_Type (T) then
23263 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
23265 declare
23266 Indx : Node_Id := First_Index (T);
23267 begin
23268 while Present (Indx) loop
23269 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
23270 Indx := Next_Index (Indx);
23271 end loop;
23272 end;
23274 -- For a packed array type, we also need debug information for
23275 -- the type used to represent the packed array. Conversely, we
23276 -- also need it for the former if we need it for the latter.
23278 if Is_Packed (T) then
23279 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Impl_Type (T));
23280 end if;
23282 if Is_Packed_Array_Impl_Type (T) then
23283 Set_Debug_Info_Needed_If_Not_Set (Original_Array_Type (T));
23284 end if;
23286 elsif Is_Access_Type (T) then
23287 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
23289 elsif Is_Private_Type (T) then
23290 declare
23291 FV : constant Entity_Id := Full_View (T);
23293 begin
23294 Set_Debug_Info_Needed_If_Not_Set (FV);
23296 -- If the full view is itself a derived private type, we need
23297 -- debug information on its underlying type.
23299 if Present (FV)
23300 and then Is_Private_Type (FV)
23301 and then Present (Underlying_Full_View (FV))
23302 then
23303 Set_Needs_Debug_Info (Underlying_Full_View (FV));
23304 end if;
23305 end;
23307 elsif Is_Protected_Type (T) then
23308 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
23310 elsif Is_Scalar_Type (T) then
23312 -- If the subrange bounds are materialized by dedicated constant
23313 -- objects, also include them in the debug info to make sure the
23314 -- debugger can properly use them.
23316 if Present (Scalar_Range (T))
23317 and then Nkind (Scalar_Range (T)) = N_Range
23318 then
23319 declare
23320 Low_Bnd : constant Node_Id := Type_Low_Bound (T);
23321 High_Bnd : constant Node_Id := Type_High_Bound (T);
23323 begin
23324 if Is_Entity_Name (Low_Bnd) then
23325 Set_Debug_Info_Needed_If_Not_Set (Entity (Low_Bnd));
23326 end if;
23328 if Is_Entity_Name (High_Bnd) then
23329 Set_Debug_Info_Needed_If_Not_Set (Entity (High_Bnd));
23330 end if;
23331 end;
23332 end if;
23333 end if;
23334 end if;
23335 end Set_Debug_Info_Needed;
23337 ----------------------------
23338 -- Set_Entity_With_Checks --
23339 ----------------------------
23341 procedure Set_Entity_With_Checks (N : Node_Id; Val : Entity_Id) is
23342 Val_Actual : Entity_Id;
23343 Nod : Node_Id;
23344 Post_Node : Node_Id;
23346 begin
23347 -- Unconditionally set the entity
23349 Set_Entity (N, Val);
23351 -- The node to post on is the selector in the case of an expanded name,
23352 -- and otherwise the node itself.
23354 if Nkind (N) = N_Expanded_Name then
23355 Post_Node := Selector_Name (N);
23356 else
23357 Post_Node := N;
23358 end if;
23360 -- Check for violation of No_Fixed_IO
23362 if Restriction_Check_Required (No_Fixed_IO)
23363 and then
23364 ((RTU_Loaded (Ada_Text_IO)
23365 and then (Is_RTE (Val, RE_Decimal_IO)
23366 or else
23367 Is_RTE (Val, RE_Fixed_IO)))
23369 or else
23370 (RTU_Loaded (Ada_Wide_Text_IO)
23371 and then (Is_RTE (Val, RO_WT_Decimal_IO)
23372 or else
23373 Is_RTE (Val, RO_WT_Fixed_IO)))
23375 or else
23376 (RTU_Loaded (Ada_Wide_Wide_Text_IO)
23377 and then (Is_RTE (Val, RO_WW_Decimal_IO)
23378 or else
23379 Is_RTE (Val, RO_WW_Fixed_IO))))
23381 -- A special extra check, don't complain about a reference from within
23382 -- the Ada.Interrupts package itself!
23384 and then not In_Same_Extended_Unit (N, Val)
23385 then
23386 Check_Restriction (No_Fixed_IO, Post_Node);
23387 end if;
23389 -- Remaining checks are only done on source nodes. Note that we test
23390 -- for violation of No_Fixed_IO even on non-source nodes, because the
23391 -- cases for checking violations of this restriction are instantiations
23392 -- where the reference in the instance has Comes_From_Source False.
23394 if not Comes_From_Source (N) then
23395 return;
23396 end if;
23398 -- Check for violation of No_Abort_Statements, which is triggered by
23399 -- call to Ada.Task_Identification.Abort_Task.
23401 if Restriction_Check_Required (No_Abort_Statements)
23402 and then (Is_RTE (Val, RE_Abort_Task))
23404 -- A special extra check, don't complain about a reference from within
23405 -- the Ada.Task_Identification package itself!
23407 and then not In_Same_Extended_Unit (N, Val)
23408 then
23409 Check_Restriction (No_Abort_Statements, Post_Node);
23410 end if;
23412 if Val = Standard_Long_Long_Integer then
23413 Check_Restriction (No_Long_Long_Integers, Post_Node);
23414 end if;
23416 -- Check for violation of No_Dynamic_Attachment
23418 if Restriction_Check_Required (No_Dynamic_Attachment)
23419 and then RTU_Loaded (Ada_Interrupts)
23420 and then (Is_RTE (Val, RE_Is_Reserved) or else
23421 Is_RTE (Val, RE_Is_Attached) or else
23422 Is_RTE (Val, RE_Current_Handler) or else
23423 Is_RTE (Val, RE_Attach_Handler) or else
23424 Is_RTE (Val, RE_Exchange_Handler) or else
23425 Is_RTE (Val, RE_Detach_Handler) or else
23426 Is_RTE (Val, RE_Reference))
23428 -- A special extra check, don't complain about a reference from within
23429 -- the Ada.Interrupts package itself!
23431 and then not In_Same_Extended_Unit (N, Val)
23432 then
23433 Check_Restriction (No_Dynamic_Attachment, Post_Node);
23434 end if;
23436 -- Check for No_Implementation_Identifiers
23438 if Restriction_Check_Required (No_Implementation_Identifiers) then
23440 -- We have an implementation defined entity if it is marked as
23441 -- implementation defined, or is defined in a package marked as
23442 -- implementation defined. However, library packages themselves
23443 -- are excluded (we don't want to flag Interfaces itself, just
23444 -- the entities within it).
23446 if (Is_Implementation_Defined (Val)
23447 or else
23448 (Present (Scope (Val))
23449 and then Is_Implementation_Defined (Scope (Val))))
23450 and then not (Ekind_In (Val, E_Package, E_Generic_Package)
23451 and then Is_Library_Level_Entity (Val))
23452 then
23453 Check_Restriction (No_Implementation_Identifiers, Post_Node);
23454 end if;
23455 end if;
23457 -- Do the style check
23459 if Style_Check
23460 and then not Suppress_Style_Checks (Val)
23461 and then not In_Instance
23462 then
23463 if Nkind (N) = N_Identifier then
23464 Nod := N;
23465 elsif Nkind (N) = N_Expanded_Name then
23466 Nod := Selector_Name (N);
23467 else
23468 return;
23469 end if;
23471 -- A special situation arises for derived operations, where we want
23472 -- to do the check against the parent (since the Sloc of the derived
23473 -- operation points to the derived type declaration itself).
23475 Val_Actual := Val;
23476 while not Comes_From_Source (Val_Actual)
23477 and then Nkind (Val_Actual) in N_Entity
23478 and then (Ekind (Val_Actual) = E_Enumeration_Literal
23479 or else Is_Subprogram_Or_Generic_Subprogram (Val_Actual))
23480 and then Present (Alias (Val_Actual))
23481 loop
23482 Val_Actual := Alias (Val_Actual);
23483 end loop;
23485 -- Renaming declarations for generic actuals do not come from source,
23486 -- and have a different name from that of the entity they rename, so
23487 -- there is no style check to perform here.
23489 if Chars (Nod) = Chars (Val_Actual) then
23490 Style.Check_Identifier (Nod, Val_Actual);
23491 end if;
23492 end if;
23494 Set_Entity (N, Val);
23495 end Set_Entity_With_Checks;
23497 ------------------------
23498 -- Set_Name_Entity_Id --
23499 ------------------------
23501 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
23502 begin
23503 Set_Name_Table_Int (Id, Int (Val));
23504 end Set_Name_Entity_Id;
23506 ---------------------
23507 -- Set_Next_Actual --
23508 ---------------------
23510 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
23511 begin
23512 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
23513 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
23514 end if;
23515 end Set_Next_Actual;
23517 ----------------------------------
23518 -- Set_Optimize_Alignment_Flags --
23519 ----------------------------------
23521 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
23522 begin
23523 if Optimize_Alignment = 'S' then
23524 Set_Optimize_Alignment_Space (E);
23525 elsif Optimize_Alignment = 'T' then
23526 Set_Optimize_Alignment_Time (E);
23527 end if;
23528 end Set_Optimize_Alignment_Flags;
23530 -----------------------
23531 -- Set_Public_Status --
23532 -----------------------
23534 procedure Set_Public_Status (Id : Entity_Id) is
23535 S : constant Entity_Id := Current_Scope;
23537 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
23538 -- Determines if E is defined within handled statement sequence or
23539 -- an if statement, returns True if so, False otherwise.
23541 ----------------------
23542 -- Within_HSS_Or_If --
23543 ----------------------
23545 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
23546 N : Node_Id;
23547 begin
23548 N := Declaration_Node (E);
23549 loop
23550 N := Parent (N);
23552 if No (N) then
23553 return False;
23555 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
23556 N_If_Statement)
23557 then
23558 return True;
23559 end if;
23560 end loop;
23561 end Within_HSS_Or_If;
23563 -- Start of processing for Set_Public_Status
23565 begin
23566 -- Everything in the scope of Standard is public
23568 if S = Standard_Standard then
23569 Set_Is_Public (Id);
23571 -- Entity is definitely not public if enclosing scope is not public
23573 elsif not Is_Public (S) then
23574 return;
23576 -- An object or function declaration that occurs in a handled sequence
23577 -- of statements or within an if statement is the declaration for a
23578 -- temporary object or local subprogram generated by the expander. It
23579 -- never needs to be made public and furthermore, making it public can
23580 -- cause back end problems.
23582 elsif Nkind_In (Parent (Id), N_Object_Declaration,
23583 N_Function_Specification)
23584 and then Within_HSS_Or_If (Id)
23585 then
23586 return;
23588 -- Entities in public packages or records are public
23590 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
23591 Set_Is_Public (Id);
23593 -- The bounds of an entry family declaration can generate object
23594 -- declarations that are visible to the back-end, e.g. in the
23595 -- the declaration of a composite type that contains tasks.
23597 elsif Is_Concurrent_Type (S)
23598 and then not Has_Completion (S)
23599 and then Nkind (Parent (Id)) = N_Object_Declaration
23600 then
23601 Set_Is_Public (Id);
23602 end if;
23603 end Set_Public_Status;
23605 -----------------------------
23606 -- Set_Referenced_Modified --
23607 -----------------------------
23609 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
23610 Pref : Node_Id;
23612 begin
23613 -- Deal with indexed or selected component where prefix is modified
23615 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
23616 Pref := Prefix (N);
23618 -- If prefix is access type, then it is the designated object that is
23619 -- being modified, which means we have no entity to set the flag on.
23621 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
23622 return;
23624 -- Otherwise chase the prefix
23626 else
23627 Set_Referenced_Modified (Pref, Out_Param);
23628 end if;
23630 -- Otherwise see if we have an entity name (only other case to process)
23632 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
23633 Set_Referenced_As_LHS (Entity (N), not Out_Param);
23634 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
23635 end if;
23636 end Set_Referenced_Modified;
23638 ------------------
23639 -- Set_Rep_Info --
23640 ------------------
23642 procedure Set_Rep_Info (T1 : Entity_Id; T2 : Entity_Id) is
23643 begin
23644 Set_Is_Atomic (T1, Is_Atomic (T2));
23645 Set_Is_Independent (T1, Is_Independent (T2));
23646 Set_Is_Volatile_Full_Access (T1, Is_Volatile_Full_Access (T2));
23648 if Is_Base_Type (T1) then
23649 Set_Is_Volatile (T1, Is_Volatile (T2));
23650 end if;
23651 end Set_Rep_Info;
23653 ----------------------------
23654 -- Set_Scope_Is_Transient --
23655 ----------------------------
23657 procedure Set_Scope_Is_Transient (V : Boolean := True) is
23658 begin
23659 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
23660 end Set_Scope_Is_Transient;
23662 -------------------
23663 -- Set_Size_Info --
23664 -------------------
23666 procedure Set_Size_Info (T1, T2 : Entity_Id) is
23667 begin
23668 -- We copy Esize, but not RM_Size, since in general RM_Size is
23669 -- subtype specific and does not get inherited by all subtypes.
23671 Set_Esize (T1, Esize (T2));
23672 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
23674 if Is_Discrete_Or_Fixed_Point_Type (T1)
23675 and then
23676 Is_Discrete_Or_Fixed_Point_Type (T2)
23677 then
23678 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
23679 end if;
23681 Set_Alignment (T1, Alignment (T2));
23682 end Set_Size_Info;
23684 ------------------------------
23685 -- Should_Ignore_Pragma_Par --
23686 ------------------------------
23688 function Should_Ignore_Pragma_Par (Prag_Name : Name_Id) return Boolean is
23689 pragma Assert (Compiler_State = Parsing);
23690 -- This one can't work during semantic analysis, because we don't have a
23691 -- correct Current_Source_File.
23693 Result : constant Boolean :=
23694 Get_Name_Table_Boolean3 (Prag_Name)
23695 and then not Is_Internal_File_Name
23696 (File_Name (Current_Source_File));
23697 begin
23698 return Result;
23699 end Should_Ignore_Pragma_Par;
23701 ------------------------------
23702 -- Should_Ignore_Pragma_Sem --
23703 ------------------------------
23705 function Should_Ignore_Pragma_Sem (N : Node_Id) return Boolean is
23706 pragma Assert (Compiler_State = Analyzing);
23707 Prag_Name : constant Name_Id := Pragma_Name (N);
23708 Result : constant Boolean :=
23709 Get_Name_Table_Boolean3 (Prag_Name)
23710 and then not In_Internal_Unit (N);
23712 begin
23713 return Result;
23714 end Should_Ignore_Pragma_Sem;
23716 --------------------
23717 -- Static_Boolean --
23718 --------------------
23720 function Static_Boolean (N : Node_Id) return Uint is
23721 begin
23722 Analyze_And_Resolve (N, Standard_Boolean);
23724 if N = Error
23725 or else Error_Posted (N)
23726 or else Etype (N) = Any_Type
23727 then
23728 return No_Uint;
23729 end if;
23731 if Is_OK_Static_Expression (N) then
23732 if not Raises_Constraint_Error (N) then
23733 return Expr_Value (N);
23734 else
23735 return No_Uint;
23736 end if;
23738 elsif Etype (N) = Any_Type then
23739 return No_Uint;
23741 else
23742 Flag_Non_Static_Expr
23743 ("static boolean expression required here", N);
23744 return No_Uint;
23745 end if;
23746 end Static_Boolean;
23748 --------------------
23749 -- Static_Integer --
23750 --------------------
23752 function Static_Integer (N : Node_Id) return Uint is
23753 begin
23754 Analyze_And_Resolve (N, Any_Integer);
23756 if N = Error
23757 or else Error_Posted (N)
23758 or else Etype (N) = Any_Type
23759 then
23760 return No_Uint;
23761 end if;
23763 if Is_OK_Static_Expression (N) then
23764 if not Raises_Constraint_Error (N) then
23765 return Expr_Value (N);
23766 else
23767 return No_Uint;
23768 end if;
23770 elsif Etype (N) = Any_Type then
23771 return No_Uint;
23773 else
23774 Flag_Non_Static_Expr
23775 ("static integer expression required here", N);
23776 return No_Uint;
23777 end if;
23778 end Static_Integer;
23780 --------------------------
23781 -- Statically_Different --
23782 --------------------------
23784 function Statically_Different (E1, E2 : Node_Id) return Boolean is
23785 R1 : constant Node_Id := Get_Referenced_Object (E1);
23786 R2 : constant Node_Id := Get_Referenced_Object (E2);
23787 begin
23788 return Is_Entity_Name (R1)
23789 and then Is_Entity_Name (R2)
23790 and then Entity (R1) /= Entity (R2)
23791 and then not Is_Formal (Entity (R1))
23792 and then not Is_Formal (Entity (R2));
23793 end Statically_Different;
23795 --------------------------------------
23796 -- Subject_To_Loop_Entry_Attributes --
23797 --------------------------------------
23799 function Subject_To_Loop_Entry_Attributes (N : Node_Id) return Boolean is
23800 Stmt : Node_Id;
23802 begin
23803 Stmt := N;
23805 -- The expansion mechanism transform a loop subject to at least one
23806 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
23807 -- the conditional part.
23809 if Nkind_In (Stmt, N_Block_Statement, N_If_Statement)
23810 and then Nkind (Original_Node (N)) = N_Loop_Statement
23811 then
23812 Stmt := Original_Node (N);
23813 end if;
23815 return
23816 Nkind (Stmt) = N_Loop_Statement
23817 and then Present (Identifier (Stmt))
23818 and then Present (Entity (Identifier (Stmt)))
23819 and then Has_Loop_Entry_Attributes (Entity (Identifier (Stmt)));
23820 end Subject_To_Loop_Entry_Attributes;
23822 -----------------------------
23823 -- Subprogram_Access_Level --
23824 -----------------------------
23826 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
23827 begin
23828 if Present (Alias (Subp)) then
23829 return Subprogram_Access_Level (Alias (Subp));
23830 else
23831 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
23832 end if;
23833 end Subprogram_Access_Level;
23835 ---------------------
23836 -- Subprogram_Name --
23837 ---------------------
23839 function Subprogram_Name (N : Node_Id) return String is
23840 Buf : Bounded_String;
23841 Ent : Node_Id := N;
23842 Nod : Node_Id;
23844 begin
23845 while Present (Ent) loop
23846 case Nkind (Ent) is
23847 when N_Subprogram_Body =>
23848 Ent := Defining_Unit_Name (Specification (Ent));
23849 exit;
23851 when N_Subprogram_Declaration =>
23852 Nod := Corresponding_Body (Ent);
23854 if Present (Nod) then
23855 Ent := Nod;
23856 else
23857 Ent := Defining_Unit_Name (Specification (Ent));
23858 end if;
23860 exit;
23862 when N_Subprogram_Instantiation
23863 | N_Package_Body
23864 | N_Package_Specification
23866 Ent := Defining_Unit_Name (Ent);
23867 exit;
23869 when N_Protected_Type_Declaration =>
23870 Ent := Corresponding_Body (Ent);
23871 exit;
23873 when N_Protected_Body
23874 | N_Task_Body
23876 Ent := Defining_Identifier (Ent);
23877 exit;
23879 when others =>
23880 null;
23881 end case;
23883 Ent := Parent (Ent);
23884 end loop;
23886 if No (Ent) then
23887 return "unknown subprogram:unknown file:0:0";
23888 end if;
23890 -- If the subprogram is a child unit, use its simple name to start the
23891 -- construction of the fully qualified name.
23893 if Nkind (Ent) = N_Defining_Program_Unit_Name then
23894 Ent := Defining_Identifier (Ent);
23895 end if;
23897 Append_Entity_Name (Buf, Ent);
23899 -- Append homonym number if needed
23901 if Nkind (N) in N_Entity and then Has_Homonym (N) then
23902 declare
23903 H : Entity_Id := Homonym (N);
23904 Nr : Nat := 1;
23906 begin
23907 while Present (H) loop
23908 if Scope (H) = Scope (N) then
23909 Nr := Nr + 1;
23910 end if;
23912 H := Homonym (H);
23913 end loop;
23915 if Nr > 1 then
23916 Append (Buf, '#');
23917 Append (Buf, Nr);
23918 end if;
23919 end;
23920 end if;
23922 -- Append source location of Ent to Buf so that the string will
23923 -- look like "subp:file:line:col".
23925 declare
23926 Loc : constant Source_Ptr := Sloc (Ent);
23927 begin
23928 Append (Buf, ':');
23929 Append (Buf, Reference_Name (Get_Source_File_Index (Loc)));
23930 Append (Buf, ':');
23931 Append (Buf, Nat (Get_Logical_Line_Number (Loc)));
23932 Append (Buf, ':');
23933 Append (Buf, Nat (Get_Column_Number (Loc)));
23934 end;
23936 return +Buf;
23937 end Subprogram_Name;
23939 -------------------------------
23940 -- Support_Atomic_Primitives --
23941 -------------------------------
23943 function Support_Atomic_Primitives (Typ : Entity_Id) return Boolean is
23944 Size : Int;
23946 begin
23947 -- Verify the alignment of Typ is known
23949 if not Known_Alignment (Typ) then
23950 return False;
23951 end if;
23953 if Known_Static_Esize (Typ) then
23954 Size := UI_To_Int (Esize (Typ));
23956 -- If the Esize (Object_Size) is unknown at compile time, look at the
23957 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
23959 elsif Known_Static_RM_Size (Typ) then
23960 Size := UI_To_Int (RM_Size (Typ));
23962 -- Otherwise, the size is considered to be unknown.
23964 else
23965 return False;
23966 end if;
23968 -- Check that the size of the component is 8, 16, 32, or 64 bits and
23969 -- that Typ is properly aligned.
23971 case Size is
23972 when 8 | 16 | 32 | 64 =>
23973 return Size = UI_To_Int (Alignment (Typ)) * 8;
23975 when others =>
23976 return False;
23977 end case;
23978 end Support_Atomic_Primitives;
23980 -----------------
23981 -- Trace_Scope --
23982 -----------------
23984 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
23985 begin
23986 if Debug_Flag_W then
23987 for J in 0 .. Scope_Stack.Last loop
23988 Write_Str (" ");
23989 end loop;
23991 Write_Str (Msg);
23992 Write_Name (Chars (E));
23993 Write_Str (" from ");
23994 Write_Location (Sloc (N));
23995 Write_Eol;
23996 end if;
23997 end Trace_Scope;
23999 -----------------------
24000 -- Transfer_Entities --
24001 -----------------------
24003 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
24004 procedure Set_Public_Status_Of (Id : Entity_Id);
24005 -- Set the Is_Public attribute of arbitrary entity Id by calling routine
24006 -- Set_Public_Status. If successful and Id denotes a record type, set
24007 -- the Is_Public attribute of its fields.
24009 --------------------------
24010 -- Set_Public_Status_Of --
24011 --------------------------
24013 procedure Set_Public_Status_Of (Id : Entity_Id) is
24014 Field : Entity_Id;
24016 begin
24017 if not Is_Public (Id) then
24018 Set_Public_Status (Id);
24020 -- When the input entity is a public record type, ensure that all
24021 -- its internal fields are also exposed to the linker. The fields
24022 -- of a class-wide type are never made public.
24024 if Is_Public (Id)
24025 and then Is_Record_Type (Id)
24026 and then not Is_Class_Wide_Type (Id)
24027 then
24028 Field := First_Entity (Id);
24029 while Present (Field) loop
24030 Set_Is_Public (Field);
24031 Next_Entity (Field);
24032 end loop;
24033 end if;
24034 end if;
24035 end Set_Public_Status_Of;
24037 -- Local variables
24039 Full_Id : Entity_Id;
24040 Id : Entity_Id;
24042 -- Start of processing for Transfer_Entities
24044 begin
24045 Id := First_Entity (From);
24047 if Present (Id) then
24049 -- Merge the entity chain of the source scope with that of the
24050 -- destination scope.
24052 if Present (Last_Entity (To)) then
24053 Set_Next_Entity (Last_Entity (To), Id);
24054 else
24055 Set_First_Entity (To, Id);
24056 end if;
24058 Set_Last_Entity (To, Last_Entity (From));
24060 -- Inspect the entities of the source scope and update their Scope
24061 -- attribute.
24063 while Present (Id) loop
24064 Set_Scope (Id, To);
24065 Set_Public_Status_Of (Id);
24067 -- Handle an internally generated full view for a private type
24069 if Is_Private_Type (Id)
24070 and then Present (Full_View (Id))
24071 and then Is_Itype (Full_View (Id))
24072 then
24073 Full_Id := Full_View (Id);
24075 Set_Scope (Full_Id, To);
24076 Set_Public_Status_Of (Full_Id);
24077 end if;
24079 Next_Entity (Id);
24080 end loop;
24082 Set_First_Entity (From, Empty);
24083 Set_Last_Entity (From, Empty);
24084 end if;
24085 end Transfer_Entities;
24087 -----------------------
24088 -- Type_Access_Level --
24089 -----------------------
24091 function Type_Access_Level (Typ : Entity_Id) return Uint is
24092 Btyp : Entity_Id;
24094 begin
24095 Btyp := Base_Type (Typ);
24097 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
24098 -- simply use the level where the type is declared. This is true for
24099 -- stand-alone object declarations, and for anonymous access types
24100 -- associated with components the level is the same as that of the
24101 -- enclosing composite type. However, special treatment is needed for
24102 -- the cases of access parameters, return objects of an anonymous access
24103 -- type, and, in Ada 95, access discriminants of limited types.
24105 if Is_Access_Type (Btyp) then
24106 if Ekind (Btyp) = E_Anonymous_Access_Type then
24108 -- If the type is a nonlocal anonymous access type (such as for
24109 -- an access parameter) we treat it as being declared at the
24110 -- library level to ensure that names such as X.all'access don't
24111 -- fail static accessibility checks.
24113 if not Is_Local_Anonymous_Access (Typ) then
24114 return Scope_Depth (Standard_Standard);
24116 -- If this is a return object, the accessibility level is that of
24117 -- the result subtype of the enclosing function. The test here is
24118 -- little complicated, because we have to account for extended
24119 -- return statements that have been rewritten as blocks, in which
24120 -- case we have to find and the Is_Return_Object attribute of the
24121 -- itype's associated object. It would be nice to find a way to
24122 -- simplify this test, but it doesn't seem worthwhile to add a new
24123 -- flag just for purposes of this test. ???
24125 elsif Ekind (Scope (Btyp)) = E_Return_Statement
24126 or else
24127 (Is_Itype (Btyp)
24128 and then Nkind (Associated_Node_For_Itype (Btyp)) =
24129 N_Object_Declaration
24130 and then Is_Return_Object
24131 (Defining_Identifier
24132 (Associated_Node_For_Itype (Btyp))))
24133 then
24134 declare
24135 Scop : Entity_Id;
24137 begin
24138 Scop := Scope (Scope (Btyp));
24139 while Present (Scop) loop
24140 exit when Ekind (Scop) = E_Function;
24141 Scop := Scope (Scop);
24142 end loop;
24144 -- Treat the return object's type as having the level of the
24145 -- function's result subtype (as per RM05-6.5(5.3/2)).
24147 return Type_Access_Level (Etype (Scop));
24148 end;
24149 end if;
24150 end if;
24152 Btyp := Root_Type (Btyp);
24154 -- The accessibility level of anonymous access types associated with
24155 -- discriminants is that of the current instance of the type, and
24156 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
24158 -- AI-402: access discriminants have accessibility based on the
24159 -- object rather than the type in Ada 2005, so the above paragraph
24160 -- doesn't apply.
24162 -- ??? Needs completion with rules from AI-416
24164 if Ada_Version <= Ada_95
24165 and then Ekind (Typ) = E_Anonymous_Access_Type
24166 and then Present (Associated_Node_For_Itype (Typ))
24167 and then Nkind (Associated_Node_For_Itype (Typ)) =
24168 N_Discriminant_Specification
24169 then
24170 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
24171 end if;
24172 end if;
24174 -- Return library level for a generic formal type. This is done because
24175 -- RM(10.3.2) says that "The statically deeper relationship does not
24176 -- apply to ... a descendant of a generic formal type". Rather than
24177 -- checking at each point where a static accessibility check is
24178 -- performed to see if we are dealing with a formal type, this rule is
24179 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
24180 -- return extreme values for a formal type; Deepest_Type_Access_Level
24181 -- returns Int'Last. By calling the appropriate function from among the
24182 -- two, we ensure that the static accessibility check will pass if we
24183 -- happen to run into a formal type. More specifically, we should call
24184 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
24185 -- call occurs as part of a static accessibility check and the error
24186 -- case is the case where the type's level is too shallow (as opposed
24187 -- to too deep).
24189 if Is_Generic_Type (Root_Type (Btyp)) then
24190 return Scope_Depth (Standard_Standard);
24191 end if;
24193 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
24194 end Type_Access_Level;
24196 ------------------------------------
24197 -- Type_Without_Stream_Operation --
24198 ------------------------------------
24200 function Type_Without_Stream_Operation
24201 (T : Entity_Id;
24202 Op : TSS_Name_Type := TSS_Null) return Entity_Id
24204 BT : constant Entity_Id := Base_Type (T);
24205 Op_Missing : Boolean;
24207 begin
24208 if not Restriction_Active (No_Default_Stream_Attributes) then
24209 return Empty;
24210 end if;
24212 if Is_Elementary_Type (T) then
24213 if Op = TSS_Null then
24214 Op_Missing :=
24215 No (TSS (BT, TSS_Stream_Read))
24216 or else No (TSS (BT, TSS_Stream_Write));
24218 else
24219 Op_Missing := No (TSS (BT, Op));
24220 end if;
24222 if Op_Missing then
24223 return T;
24224 else
24225 return Empty;
24226 end if;
24228 elsif Is_Array_Type (T) then
24229 return Type_Without_Stream_Operation (Component_Type (T), Op);
24231 elsif Is_Record_Type (T) then
24232 declare
24233 Comp : Entity_Id;
24234 C_Typ : Entity_Id;
24236 begin
24237 Comp := First_Component (T);
24238 while Present (Comp) loop
24239 C_Typ := Type_Without_Stream_Operation (Etype (Comp), Op);
24241 if Present (C_Typ) then
24242 return C_Typ;
24243 end if;
24245 Next_Component (Comp);
24246 end loop;
24248 return Empty;
24249 end;
24251 elsif Is_Private_Type (T) and then Present (Full_View (T)) then
24252 return Type_Without_Stream_Operation (Full_View (T), Op);
24253 else
24254 return Empty;
24255 end if;
24256 end Type_Without_Stream_Operation;
24258 ----------------------------
24259 -- Unique_Defining_Entity --
24260 ----------------------------
24262 function Unique_Defining_Entity (N : Node_Id) return Entity_Id is
24263 begin
24264 return Unique_Entity (Defining_Entity (N));
24265 end Unique_Defining_Entity;
24267 -------------------
24268 -- Unique_Entity --
24269 -------------------
24271 function Unique_Entity (E : Entity_Id) return Entity_Id is
24272 U : Entity_Id := E;
24273 P : Node_Id;
24275 begin
24276 case Ekind (E) is
24277 when E_Constant =>
24278 if Present (Full_View (E)) then
24279 U := Full_View (E);
24280 end if;
24282 when Entry_Kind =>
24283 if Nkind (Parent (E)) = N_Entry_Body then
24284 declare
24285 Prot_Item : Entity_Id;
24286 Prot_Type : Entity_Id;
24288 begin
24289 if Ekind (E) = E_Entry then
24290 Prot_Type := Scope (E);
24292 -- Bodies of entry families are nested within an extra scope
24293 -- that contains an entry index declaration.
24295 else
24296 Prot_Type := Scope (Scope (E));
24297 end if;
24299 -- A protected type may be declared as a private type, in
24300 -- which case we need to get its full view.
24302 if Is_Private_Type (Prot_Type) then
24303 Prot_Type := Full_View (Prot_Type);
24304 end if;
24306 -- Full view may not be present on error, in which case
24307 -- return E by default.
24309 if Present (Prot_Type) then
24310 pragma Assert (Ekind (Prot_Type) = E_Protected_Type);
24312 -- Traverse the entity list of the protected type and
24313 -- locate an entry declaration which matches the entry
24314 -- body.
24316 Prot_Item := First_Entity (Prot_Type);
24317 while Present (Prot_Item) loop
24318 if Ekind (Prot_Item) in Entry_Kind
24319 and then Corresponding_Body (Parent (Prot_Item)) = E
24320 then
24321 U := Prot_Item;
24322 exit;
24323 end if;
24325 Next_Entity (Prot_Item);
24326 end loop;
24327 end if;
24328 end;
24329 end if;
24331 when Formal_Kind =>
24332 if Present (Spec_Entity (E)) then
24333 U := Spec_Entity (E);
24334 end if;
24336 when E_Package_Body =>
24337 P := Parent (E);
24339 if Nkind (P) = N_Defining_Program_Unit_Name then
24340 P := Parent (P);
24341 end if;
24343 if Nkind (P) = N_Package_Body
24344 and then Present (Corresponding_Spec (P))
24345 then
24346 U := Corresponding_Spec (P);
24348 elsif Nkind (P) = N_Package_Body_Stub
24349 and then Present (Corresponding_Spec_Of_Stub (P))
24350 then
24351 U := Corresponding_Spec_Of_Stub (P);
24352 end if;
24354 when E_Protected_Body =>
24355 P := Parent (E);
24357 if Nkind (P) = N_Protected_Body
24358 and then Present (Corresponding_Spec (P))
24359 then
24360 U := Corresponding_Spec (P);
24362 elsif Nkind (P) = N_Protected_Body_Stub
24363 and then Present (Corresponding_Spec_Of_Stub (P))
24364 then
24365 U := Corresponding_Spec_Of_Stub (P);
24367 if Is_Single_Protected_Object (U) then
24368 U := Etype (U);
24369 end if;
24370 end if;
24372 if Is_Private_Type (U) then
24373 U := Full_View (U);
24374 end if;
24376 when E_Subprogram_Body =>
24377 P := Parent (E);
24379 if Nkind (P) = N_Defining_Program_Unit_Name then
24380 P := Parent (P);
24381 end if;
24383 P := Parent (P);
24385 if Nkind (P) = N_Subprogram_Body
24386 and then Present (Corresponding_Spec (P))
24387 then
24388 U := Corresponding_Spec (P);
24390 elsif Nkind (P) = N_Subprogram_Body_Stub
24391 and then Present (Corresponding_Spec_Of_Stub (P))
24392 then
24393 U := Corresponding_Spec_Of_Stub (P);
24395 elsif Nkind (P) = N_Subprogram_Renaming_Declaration then
24396 U := Corresponding_Spec (P);
24397 end if;
24399 when E_Task_Body =>
24400 P := Parent (E);
24402 if Nkind (P) = N_Task_Body
24403 and then Present (Corresponding_Spec (P))
24404 then
24405 U := Corresponding_Spec (P);
24407 elsif Nkind (P) = N_Task_Body_Stub
24408 and then Present (Corresponding_Spec_Of_Stub (P))
24409 then
24410 U := Corresponding_Spec_Of_Stub (P);
24412 if Is_Single_Task_Object (U) then
24413 U := Etype (U);
24414 end if;
24415 end if;
24417 if Is_Private_Type (U) then
24418 U := Full_View (U);
24419 end if;
24421 when Type_Kind =>
24422 if Present (Full_View (E)) then
24423 U := Full_View (E);
24424 end if;
24426 when others =>
24427 null;
24428 end case;
24430 return U;
24431 end Unique_Entity;
24433 -----------------
24434 -- Unique_Name --
24435 -----------------
24437 function Unique_Name (E : Entity_Id) return String is
24439 -- Names in E_Subprogram_Body or E_Package_Body entities are not
24440 -- reliable, as they may not include the overloading suffix. Instead,
24441 -- when looking for the name of E or one of its enclosing scope, we get
24442 -- the name of the corresponding Unique_Entity.
24444 U : constant Entity_Id := Unique_Entity (E);
24446 function This_Name return String;
24448 ---------------
24449 -- This_Name --
24450 ---------------
24452 function This_Name return String is
24453 begin
24454 return Get_Name_String (Chars (U));
24455 end This_Name;
24457 -- Start of processing for Unique_Name
24459 begin
24460 if E = Standard_Standard
24461 or else Has_Fully_Qualified_Name (E)
24462 then
24463 return This_Name;
24465 elsif Ekind (E) = E_Enumeration_Literal then
24466 return Unique_Name (Etype (E)) & "__" & This_Name;
24468 else
24469 declare
24470 S : constant Entity_Id := Scope (U);
24471 pragma Assert (Present (S));
24473 begin
24474 -- Prefix names of predefined types with standard__, but leave
24475 -- names of user-defined packages and subprograms without prefix
24476 -- (even if technically they are nested in the Standard package).
24478 if S = Standard_Standard then
24479 if Ekind (U) = E_Package or else Is_Subprogram (U) then
24480 return This_Name;
24481 else
24482 return Unique_Name (S) & "__" & This_Name;
24483 end if;
24485 -- For intances of generic subprograms use the name of the related
24486 -- instace and skip the scope of its wrapper package.
24488 elsif Is_Wrapper_Package (S) then
24489 pragma Assert (Scope (S) = Scope (Related_Instance (S)));
24490 -- Wrapper package and the instantiation are in the same scope
24492 declare
24493 Enclosing_Name : constant String :=
24494 Unique_Name (Scope (S)) & "__" &
24495 Get_Name_String (Chars (Related_Instance (S)));
24497 begin
24498 if Is_Subprogram (U)
24499 and then not Is_Generic_Actual_Subprogram (U)
24500 then
24501 return Enclosing_Name;
24502 else
24503 return Enclosing_Name & "__" & This_Name;
24504 end if;
24505 end;
24507 else
24508 return Unique_Name (S) & "__" & This_Name;
24509 end if;
24510 end;
24511 end if;
24512 end Unique_Name;
24514 ---------------------
24515 -- Unit_Is_Visible --
24516 ---------------------
24518 function Unit_Is_Visible (U : Entity_Id) return Boolean is
24519 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
24520 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
24522 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
24523 -- For a child unit, check whether unit appears in a with_clause
24524 -- of a parent.
24526 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
24527 -- Scan the context clause of one compilation unit looking for a
24528 -- with_clause for the unit in question.
24530 ----------------------------
24531 -- Unit_In_Parent_Context --
24532 ----------------------------
24534 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
24535 begin
24536 if Unit_In_Context (Par_Unit) then
24537 return True;
24539 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
24540 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
24542 else
24543 return False;
24544 end if;
24545 end Unit_In_Parent_Context;
24547 ---------------------
24548 -- Unit_In_Context --
24549 ---------------------
24551 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
24552 Clause : Node_Id;
24554 begin
24555 Clause := First (Context_Items (Comp_Unit));
24556 while Present (Clause) loop
24557 if Nkind (Clause) = N_With_Clause then
24558 if Library_Unit (Clause) = U then
24559 return True;
24561 -- The with_clause may denote a renaming of the unit we are
24562 -- looking for, eg. Text_IO which renames Ada.Text_IO.
24564 elsif
24565 Renamed_Entity (Entity (Name (Clause))) =
24566 Defining_Entity (Unit (U))
24567 then
24568 return True;
24569 end if;
24570 end if;
24572 Next (Clause);
24573 end loop;
24575 return False;
24576 end Unit_In_Context;
24578 -- Start of processing for Unit_Is_Visible
24580 begin
24581 -- The currrent unit is directly visible
24583 if Curr = U then
24584 return True;
24586 elsif Unit_In_Context (Curr) then
24587 return True;
24589 -- If the current unit is a body, check the context of the spec
24591 elsif Nkind (Unit (Curr)) = N_Package_Body
24592 or else
24593 (Nkind (Unit (Curr)) = N_Subprogram_Body
24594 and then not Acts_As_Spec (Unit (Curr)))
24595 then
24596 if Unit_In_Context (Library_Unit (Curr)) then
24597 return True;
24598 end if;
24599 end if;
24601 -- If the spec is a child unit, examine the parents
24603 if Is_Child_Unit (Curr_Entity) then
24604 if Nkind (Unit (Curr)) in N_Unit_Body then
24605 return
24606 Unit_In_Parent_Context
24607 (Parent_Spec (Unit (Library_Unit (Curr))));
24608 else
24609 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
24610 end if;
24612 else
24613 return False;
24614 end if;
24615 end Unit_Is_Visible;
24617 ------------------------------
24618 -- Universal_Interpretation --
24619 ------------------------------
24621 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
24622 Index : Interp_Index;
24623 It : Interp;
24625 begin
24626 -- The argument may be a formal parameter of an operator or subprogram
24627 -- with multiple interpretations, or else an expression for an actual.
24629 if Nkind (Opnd) = N_Defining_Identifier
24630 or else not Is_Overloaded (Opnd)
24631 then
24632 if Etype (Opnd) = Universal_Integer
24633 or else Etype (Opnd) = Universal_Real
24634 then
24635 return Etype (Opnd);
24636 else
24637 return Empty;
24638 end if;
24640 else
24641 Get_First_Interp (Opnd, Index, It);
24642 while Present (It.Typ) loop
24643 if It.Typ = Universal_Integer
24644 or else It.Typ = Universal_Real
24645 then
24646 return It.Typ;
24647 end if;
24649 Get_Next_Interp (Index, It);
24650 end loop;
24652 return Empty;
24653 end if;
24654 end Universal_Interpretation;
24656 ---------------
24657 -- Unqualify --
24658 ---------------
24660 function Unqualify (Expr : Node_Id) return Node_Id is
24661 begin
24662 -- Recurse to handle unlikely case of multiple levels of qualification
24664 if Nkind (Expr) = N_Qualified_Expression then
24665 return Unqualify (Expression (Expr));
24667 -- Normal case, not a qualified expression
24669 else
24670 return Expr;
24671 end if;
24672 end Unqualify;
24674 -----------------
24675 -- Unqual_Conv --
24676 -----------------
24678 function Unqual_Conv (Expr : Node_Id) return Node_Id is
24679 begin
24680 -- Recurse to handle unlikely case of multiple levels of qualification
24681 -- and/or conversion.
24683 if Nkind_In (Expr, N_Qualified_Expression,
24684 N_Type_Conversion,
24685 N_Unchecked_Type_Conversion)
24686 then
24687 return Unqual_Conv (Expression (Expr));
24689 -- Normal case, not a qualified expression
24691 else
24692 return Expr;
24693 end if;
24694 end Unqual_Conv;
24696 -----------------------
24697 -- Visible_Ancestors --
24698 -----------------------
24700 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
24701 List_1 : Elist_Id;
24702 List_2 : Elist_Id;
24703 Elmt : Elmt_Id;
24705 begin
24706 pragma Assert (Is_Record_Type (Typ) and then Is_Tagged_Type (Typ));
24708 -- Collect all the parents and progenitors of Typ. If the full-view of
24709 -- private parents and progenitors is available then it is used to
24710 -- generate the list of visible ancestors; otherwise their partial
24711 -- view is added to the resulting list.
24713 Collect_Parents
24714 (T => Typ,
24715 List => List_1,
24716 Use_Full_View => True);
24718 Collect_Interfaces
24719 (T => Typ,
24720 Ifaces_List => List_2,
24721 Exclude_Parents => True,
24722 Use_Full_View => True);
24724 -- Join the two lists. Avoid duplications because an interface may
24725 -- simultaneously be parent and progenitor of a type.
24727 Elmt := First_Elmt (List_2);
24728 while Present (Elmt) loop
24729 Append_Unique_Elmt (Node (Elmt), List_1);
24730 Next_Elmt (Elmt);
24731 end loop;
24733 return List_1;
24734 end Visible_Ancestors;
24736 ----------------------
24737 -- Within_Init_Proc --
24738 ----------------------
24740 function Within_Init_Proc return Boolean is
24741 S : Entity_Id;
24743 begin
24744 S := Current_Scope;
24745 while not Is_Overloadable (S) loop
24746 if S = Standard_Standard then
24747 return False;
24748 else
24749 S := Scope (S);
24750 end if;
24751 end loop;
24753 return Is_Init_Proc (S);
24754 end Within_Init_Proc;
24756 ---------------------------
24757 -- Within_Protected_Type --
24758 ---------------------------
24760 function Within_Protected_Type (E : Entity_Id) return Boolean is
24761 Scop : Entity_Id := Scope (E);
24763 begin
24764 while Present (Scop) loop
24765 if Ekind (Scop) = E_Protected_Type then
24766 return True;
24767 end if;
24769 Scop := Scope (Scop);
24770 end loop;
24772 return False;
24773 end Within_Protected_Type;
24775 ------------------
24776 -- Within_Scope --
24777 ------------------
24779 function Within_Scope (E : Entity_Id; S : Entity_Id) return Boolean is
24780 begin
24781 return Scope_Within_Or_Same (Scope (E), S);
24782 end Within_Scope;
24784 ----------------------------
24785 -- Within_Subprogram_Call --
24786 ----------------------------
24788 function Within_Subprogram_Call (N : Node_Id) return Boolean is
24789 Par : Node_Id;
24791 begin
24792 -- Climb the parent chain looking for a function or procedure call
24794 Par := N;
24795 while Present (Par) loop
24796 if Nkind_In (Par, N_Entry_Call_Statement,
24797 N_Function_Call,
24798 N_Procedure_Call_Statement)
24799 then
24800 return True;
24802 -- Prevent the search from going too far
24804 elsif Is_Body_Or_Package_Declaration (Par) then
24805 exit;
24806 end if;
24808 Par := Parent (Par);
24809 end loop;
24811 return False;
24812 end Within_Subprogram_Call;
24814 ----------------
24815 -- Wrong_Type --
24816 ----------------
24818 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
24819 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
24820 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
24822 Matching_Field : Entity_Id;
24823 -- Entity to give a more precise suggestion on how to write a one-
24824 -- element positional aggregate.
24826 function Has_One_Matching_Field return Boolean;
24827 -- Determines if Expec_Type is a record type with a single component or
24828 -- discriminant whose type matches the found type or is one dimensional
24829 -- array whose component type matches the found type. In the case of
24830 -- one discriminant, we ignore the variant parts. That's not accurate,
24831 -- but good enough for the warning.
24833 ----------------------------
24834 -- Has_One_Matching_Field --
24835 ----------------------------
24837 function Has_One_Matching_Field return Boolean is
24838 E : Entity_Id;
24840 begin
24841 Matching_Field := Empty;
24843 if Is_Array_Type (Expec_Type)
24844 and then Number_Dimensions (Expec_Type) = 1
24845 and then Covers (Etype (Component_Type (Expec_Type)), Found_Type)
24846 then
24847 -- Use type name if available. This excludes multidimensional
24848 -- arrays and anonymous arrays.
24850 if Comes_From_Source (Expec_Type) then
24851 Matching_Field := Expec_Type;
24853 -- For an assignment, use name of target
24855 elsif Nkind (Parent (Expr)) = N_Assignment_Statement
24856 and then Is_Entity_Name (Name (Parent (Expr)))
24857 then
24858 Matching_Field := Entity (Name (Parent (Expr)));
24859 end if;
24861 return True;
24863 elsif not Is_Record_Type (Expec_Type) then
24864 return False;
24866 else
24867 E := First_Entity (Expec_Type);
24868 loop
24869 if No (E) then
24870 return False;
24872 elsif not Ekind_In (E, E_Discriminant, E_Component)
24873 or else Nam_In (Chars (E), Name_uTag, Name_uParent)
24874 then
24875 Next_Entity (E);
24877 else
24878 exit;
24879 end if;
24880 end loop;
24882 if not Covers (Etype (E), Found_Type) then
24883 return False;
24885 elsif Present (Next_Entity (E))
24886 and then (Ekind (E) = E_Component
24887 or else Ekind (Next_Entity (E)) = E_Discriminant)
24888 then
24889 return False;
24891 else
24892 Matching_Field := E;
24893 return True;
24894 end if;
24895 end if;
24896 end Has_One_Matching_Field;
24898 -- Start of processing for Wrong_Type
24900 begin
24901 -- Don't output message if either type is Any_Type, or if a message
24902 -- has already been posted for this node. We need to do the latter
24903 -- check explicitly (it is ordinarily done in Errout), because we
24904 -- are using ! to force the output of the error messages.
24906 if Expec_Type = Any_Type
24907 or else Found_Type = Any_Type
24908 or else Error_Posted (Expr)
24909 then
24910 return;
24912 -- If one of the types is a Taft-Amendment type and the other it its
24913 -- completion, it must be an illegal use of a TAT in the spec, for
24914 -- which an error was already emitted. Avoid cascaded errors.
24916 elsif Is_Incomplete_Type (Expec_Type)
24917 and then Has_Completion_In_Body (Expec_Type)
24918 and then Full_View (Expec_Type) = Etype (Expr)
24919 then
24920 return;
24922 elsif Is_Incomplete_Type (Etype (Expr))
24923 and then Has_Completion_In_Body (Etype (Expr))
24924 and then Full_View (Etype (Expr)) = Expec_Type
24925 then
24926 return;
24928 -- In an instance, there is an ongoing problem with completion of
24929 -- type derived from private types. Their structure is what Gigi
24930 -- expects, but the Etype is the parent type rather than the
24931 -- derived private type itself. Do not flag error in this case. The
24932 -- private completion is an entity without a parent, like an Itype.
24933 -- Similarly, full and partial views may be incorrect in the instance.
24934 -- There is no simple way to insure that it is consistent ???
24936 -- A similar view discrepancy can happen in an inlined body, for the
24937 -- same reason: inserted body may be outside of the original package
24938 -- and only partial views are visible at the point of insertion.
24940 elsif In_Instance or else In_Inlined_Body then
24941 if Etype (Etype (Expr)) = Etype (Expected_Type)
24942 and then
24943 (Has_Private_Declaration (Expected_Type)
24944 or else Has_Private_Declaration (Etype (Expr)))
24945 and then No (Parent (Expected_Type))
24946 then
24947 return;
24949 elsif Nkind (Parent (Expr)) = N_Qualified_Expression
24950 and then Entity (Subtype_Mark (Parent (Expr))) = Expected_Type
24951 then
24952 return;
24954 elsif Is_Private_Type (Expected_Type)
24955 and then Present (Full_View (Expected_Type))
24956 and then Covers (Full_View (Expected_Type), Etype (Expr))
24957 then
24958 return;
24960 -- Conversely, type of expression may be the private one
24962 elsif Is_Private_Type (Base_Type (Etype (Expr)))
24963 and then Full_View (Base_Type (Etype (Expr))) = Expected_Type
24964 then
24965 return;
24966 end if;
24967 end if;
24969 -- An interesting special check. If the expression is parenthesized
24970 -- and its type corresponds to the type of the sole component of the
24971 -- expected record type, or to the component type of the expected one
24972 -- dimensional array type, then assume we have a bad aggregate attempt.
24974 if Nkind (Expr) in N_Subexpr
24975 and then Paren_Count (Expr) /= 0
24976 and then Has_One_Matching_Field
24977 then
24978 Error_Msg_N ("positional aggregate cannot have one component", Expr);
24980 if Present (Matching_Field) then
24981 if Is_Array_Type (Expec_Type) then
24982 Error_Msg_NE
24983 ("\write instead `&''First ='> ...`", Expr, Matching_Field);
24984 else
24985 Error_Msg_NE
24986 ("\write instead `& ='> ...`", Expr, Matching_Field);
24987 end if;
24988 end if;
24990 -- Another special check, if we are looking for a pool-specific access
24991 -- type and we found an E_Access_Attribute_Type, then we have the case
24992 -- of an Access attribute being used in a context which needs a pool-
24993 -- specific type, which is never allowed. The one extra check we make
24994 -- is that the expected designated type covers the Found_Type.
24996 elsif Is_Access_Type (Expec_Type)
24997 and then Ekind (Found_Type) = E_Access_Attribute_Type
24998 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
24999 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
25000 and then Covers
25001 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
25002 then
25003 Error_Msg_N -- CODEFIX
25004 ("result must be general access type!", Expr);
25005 Error_Msg_NE -- CODEFIX
25006 ("add ALL to }!", Expr, Expec_Type);
25008 -- Another special check, if the expected type is an integer type,
25009 -- but the expression is of type System.Address, and the parent is
25010 -- an addition or subtraction operation whose left operand is the
25011 -- expression in question and whose right operand is of an integral
25012 -- type, then this is an attempt at address arithmetic, so give
25013 -- appropriate message.
25015 elsif Is_Integer_Type (Expec_Type)
25016 and then Is_RTE (Found_Type, RE_Address)
25017 and then Nkind_In (Parent (Expr), N_Op_Add, N_Op_Subtract)
25018 and then Expr = Left_Opnd (Parent (Expr))
25019 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
25020 then
25021 Error_Msg_N
25022 ("address arithmetic not predefined in package System",
25023 Parent (Expr));
25024 Error_Msg_N
25025 ("\possible missing with/use of System.Storage_Elements",
25026 Parent (Expr));
25027 return;
25029 -- If the expected type is an anonymous access type, as for access
25030 -- parameters and discriminants, the error is on the designated types.
25032 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
25033 if Comes_From_Source (Expec_Type) then
25034 Error_Msg_NE ("expected}!", Expr, Expec_Type);
25035 else
25036 Error_Msg_NE
25037 ("expected an access type with designated}",
25038 Expr, Designated_Type (Expec_Type));
25039 end if;
25041 if Is_Access_Type (Found_Type)
25042 and then not Comes_From_Source (Found_Type)
25043 then
25044 Error_Msg_NE
25045 ("\\found an access type with designated}!",
25046 Expr, Designated_Type (Found_Type));
25047 else
25048 if From_Limited_With (Found_Type) then
25049 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
25050 Error_Msg_Qual_Level := 99;
25051 Error_Msg_NE -- CODEFIX
25052 ("\\missing `WITH &;", Expr, Scope (Found_Type));
25053 Error_Msg_Qual_Level := 0;
25054 else
25055 Error_Msg_NE ("found}!", Expr, Found_Type);
25056 end if;
25057 end if;
25059 -- Normal case of one type found, some other type expected
25061 else
25062 -- If the names of the two types are the same, see if some number
25063 -- of levels of qualification will help. Don't try more than three
25064 -- levels, and if we get to standard, it's no use (and probably
25065 -- represents an error in the compiler) Also do not bother with
25066 -- internal scope names.
25068 declare
25069 Expec_Scope : Entity_Id;
25070 Found_Scope : Entity_Id;
25072 begin
25073 Expec_Scope := Expec_Type;
25074 Found_Scope := Found_Type;
25076 for Levels in Nat range 0 .. 3 loop
25077 if Chars (Expec_Scope) /= Chars (Found_Scope) then
25078 Error_Msg_Qual_Level := Levels;
25079 exit;
25080 end if;
25082 Expec_Scope := Scope (Expec_Scope);
25083 Found_Scope := Scope (Found_Scope);
25085 exit when Expec_Scope = Standard_Standard
25086 or else Found_Scope = Standard_Standard
25087 or else not Comes_From_Source (Expec_Scope)
25088 or else not Comes_From_Source (Found_Scope);
25089 end loop;
25090 end;
25092 if Is_Record_Type (Expec_Type)
25093 and then Present (Corresponding_Remote_Type (Expec_Type))
25094 then
25095 Error_Msg_NE ("expected}!", Expr,
25096 Corresponding_Remote_Type (Expec_Type));
25097 else
25098 Error_Msg_NE ("expected}!", Expr, Expec_Type);
25099 end if;
25101 if Is_Entity_Name (Expr)
25102 and then Is_Package_Or_Generic_Package (Entity (Expr))
25103 then
25104 Error_Msg_N ("\\found package name!", Expr);
25106 elsif Is_Entity_Name (Expr)
25107 and then Ekind_In (Entity (Expr), E_Procedure, E_Generic_Procedure)
25108 then
25109 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
25110 Error_Msg_N
25111 ("found procedure name, possibly missing Access attribute!",
25112 Expr);
25113 else
25114 Error_Msg_N
25115 ("\\found procedure name instead of function!", Expr);
25116 end if;
25118 elsif Nkind (Expr) = N_Function_Call
25119 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
25120 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
25121 and then No (Parameter_Associations (Expr))
25122 then
25123 Error_Msg_N
25124 ("found function name, possibly missing Access attribute!",
25125 Expr);
25127 -- Catch common error: a prefix or infix operator which is not
25128 -- directly visible because the type isn't.
25130 elsif Nkind (Expr) in N_Op
25131 and then Is_Overloaded (Expr)
25132 and then not Is_Immediately_Visible (Expec_Type)
25133 and then not Is_Potentially_Use_Visible (Expec_Type)
25134 and then not In_Use (Expec_Type)
25135 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
25136 then
25137 Error_Msg_N
25138 ("operator of the type is not directly visible!", Expr);
25140 elsif Ekind (Found_Type) = E_Void
25141 and then Present (Parent (Found_Type))
25142 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
25143 then
25144 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
25146 else
25147 Error_Msg_NE ("\\found}!", Expr, Found_Type);
25148 end if;
25150 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
25151 -- of the same modular type, and (M1 and M2) = 0 was intended.
25153 if Expec_Type = Standard_Boolean
25154 and then Is_Modular_Integer_Type (Found_Type)
25155 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
25156 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
25157 then
25158 declare
25159 Op : constant Node_Id := Right_Opnd (Parent (Expr));
25160 L : constant Node_Id := Left_Opnd (Op);
25161 R : constant Node_Id := Right_Opnd (Op);
25163 begin
25164 -- The case for the message is when the left operand of the
25165 -- comparison is the same modular type, or when it is an
25166 -- integer literal (or other universal integer expression),
25167 -- which would have been typed as the modular type if the
25168 -- parens had been there.
25170 if (Etype (L) = Found_Type
25171 or else
25172 Etype (L) = Universal_Integer)
25173 and then Is_Integer_Type (Etype (R))
25174 then
25175 Error_Msg_N
25176 ("\\possible missing parens for modular operation", Expr);
25177 end if;
25178 end;
25179 end if;
25181 -- Reset error message qualification indication
25183 Error_Msg_Qual_Level := 0;
25184 end if;
25185 end Wrong_Type;
25187 --------------------------------
25188 -- Yields_Synchronized_Object --
25189 --------------------------------
25191 function Yields_Synchronized_Object (Typ : Entity_Id) return Boolean is
25192 Has_Sync_Comp : Boolean := False;
25193 Id : Entity_Id;
25195 begin
25196 -- An array type yields a synchronized object if its component type
25197 -- yields a synchronized object.
25199 if Is_Array_Type (Typ) then
25200 return Yields_Synchronized_Object (Component_Type (Typ));
25202 -- A descendant of type Ada.Synchronous_Task_Control.Suspension_Object
25203 -- yields a synchronized object by default.
25205 elsif Is_Descendant_Of_Suspension_Object (Typ) then
25206 return True;
25208 -- A protected type yields a synchronized object by default
25210 elsif Is_Protected_Type (Typ) then
25211 return True;
25213 -- A record type or type extension yields a synchronized object when its
25214 -- discriminants (if any) lack default values and all components are of
25215 -- a type that yelds a synchronized object.
25217 elsif Is_Record_Type (Typ) then
25219 -- Inspect all entities defined in the scope of the type, looking for
25220 -- components of a type that does not yeld a synchronized object or
25221 -- for discriminants with default values.
25223 Id := First_Entity (Typ);
25224 while Present (Id) loop
25225 if Comes_From_Source (Id) then
25226 if Ekind (Id) = E_Component then
25227 if Yields_Synchronized_Object (Etype (Id)) then
25228 Has_Sync_Comp := True;
25230 -- The component does not yield a synchronized object
25232 else
25233 return False;
25234 end if;
25236 elsif Ekind (Id) = E_Discriminant
25237 and then Present (Expression (Parent (Id)))
25238 then
25239 return False;
25240 end if;
25241 end if;
25243 Next_Entity (Id);
25244 end loop;
25246 -- Ensure that the parent type of a type extension yields a
25247 -- synchronized object.
25249 if Etype (Typ) /= Typ
25250 and then not Yields_Synchronized_Object (Etype (Typ))
25251 then
25252 return False;
25253 end if;
25255 -- If we get here, then all discriminants lack default values and all
25256 -- components are of a type that yields a synchronized object.
25258 return Has_Sync_Comp;
25260 -- A synchronized interface type yields a synchronized object by default
25262 elsif Is_Synchronized_Interface (Typ) then
25263 return True;
25265 -- A task type yelds a synchronized object by default
25267 elsif Is_Task_Type (Typ) then
25268 return True;
25270 -- Otherwise the type does not yield a synchronized object
25272 else
25273 return False;
25274 end if;
25275 end Yields_Synchronized_Object;
25277 ---------------------------
25278 -- Yields_Universal_Type --
25279 ---------------------------
25281 function Yields_Universal_Type (N : Node_Id) return Boolean is
25282 begin
25283 -- Integer and real literals are of a universal type
25285 if Nkind_In (N, N_Integer_Literal, N_Real_Literal) then
25286 return True;
25288 -- The values of certain attributes are of a universal type
25290 elsif Nkind (N) = N_Attribute_Reference then
25291 return
25292 Universal_Type_Attribute (Get_Attribute_Id (Attribute_Name (N)));
25294 -- ??? There are possibly other cases to consider
25296 else
25297 return False;
25298 end if;
25299 end Yields_Universal_Type;
25301 begin
25302 Erroutc.Subprogram_Name_Ptr := Subprogram_Name'Access;
25303 end Sem_Util;