d: Merge upstream dmd, druntime c8ae4adb2e, phobos 792c8b7c1.
[official-gcc.git] / gcc / ada / sem_util.adb
bloba1cebb082916685631e6525621d9183cc49d1408
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-2022, 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 Accessibility; use Accessibility;
27 with Casing; use Casing;
28 with Checks; use Checks;
29 with Debug; use Debug;
30 with Einfo.Utils; use Einfo.Utils;
31 with Elists; use Elists;
32 with Errout; use Errout;
33 with Erroutc; use Erroutc;
34 with Exp_Ch6; use Exp_Ch6;
35 with Exp_Ch11; use Exp_Ch11;
36 with Exp_Util; use Exp_Util;
37 with Fname; use Fname;
38 with Freeze; use Freeze;
39 with Itypes; use Itypes;
40 with Lib; use Lib;
41 with Lib.Xref; use Lib.Xref;
42 with Namet.Sp; use Namet.Sp;
43 with Nlists; use Nlists;
44 with Nmake; use Nmake;
45 with Output; use Output;
46 with Restrict; use Restrict;
47 with Rident; use Rident;
48 with Rtsfind; use Rtsfind;
49 with Sem; use Sem;
50 with Sem_Aux; use Sem_Aux;
51 with Sem_Attr; use Sem_Attr;
52 with Sem_Cat; use Sem_Cat;
53 with Sem_Ch6; use Sem_Ch6;
54 with Sem_Ch8; use Sem_Ch8;
55 with Sem_Ch13; use Sem_Ch13;
56 with Sem_Disp; use Sem_Disp;
57 with Sem_Elab; use Sem_Elab;
58 with Sem_Eval; use Sem_Eval;
59 with Sem_Prag; use Sem_Prag;
60 with Sem_Res; use Sem_Res;
61 with Sem_Warn; use Sem_Warn;
62 with Sem_Type; use Sem_Type;
63 with Sinfo; use Sinfo;
64 with Sinfo.Nodes; use Sinfo.Nodes;
65 with Sinfo.Utils; use Sinfo.Utils;
66 with Sinput; use Sinput;
67 with Stand; use Stand;
68 with Style;
69 with Stringt; use Stringt;
70 with Targparm; use Targparm;
71 with Tbuild; use Tbuild;
72 with Ttypes; use Ttypes;
73 with Uname; use Uname;
74 with Warnsw; use Warnsw;
76 with GNAT.Heap_Sort_G;
77 with GNAT.HTable; use GNAT.HTable;
79 package body Sem_Util is
81 ---------------------------
82 -- Local Data Structures --
83 ---------------------------
85 Invalid_Binder_Values : array (Scalar_Id) of Entity_Id := (others => Empty);
86 -- A collection to hold the entities of the variables declared in package
87 -- System.Scalar_Values which describe the invalid values of scalar types.
89 Invalid_Binder_Values_Set : Boolean := False;
90 -- This flag prevents multiple attempts to initialize Invalid_Binder_Values
92 Invalid_Floats : array (Float_Scalar_Id) of Ureal := (others => No_Ureal);
93 -- A collection to hold the invalid values of float types as specified by
94 -- pragma Initialize_Scalars.
96 Invalid_Integers : array (Integer_Scalar_Id) of Uint := (others => No_Uint);
97 -- A collection to hold the invalid values of integer types as specified
98 -- by pragma Initialize_Scalars.
100 -----------------------
101 -- Local Subprograms --
102 -----------------------
104 function Build_Component_Subtype
105 (C : List_Id;
106 Loc : Source_Ptr;
107 T : Entity_Id) return Node_Id;
108 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
109 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
110 -- Loc is the source location, T is the original subtype.
112 procedure Examine_Array_Bounds
113 (Typ : Entity_Id;
114 All_Static : out Boolean;
115 Has_Empty : out Boolean);
116 -- Inspect the index constraints of array type Typ. Flag All_Static is set
117 -- when all ranges are static. Flag Has_Empty is set only when All_Static
118 -- is set and indicates that at least one range is empty.
120 function Has_Enabled_Property
121 (Item_Id : Entity_Id;
122 Property : Name_Id) return Boolean;
123 -- Subsidiary to routines Async_xxx_Enabled and Effective_xxx_Enabled.
124 -- Determine whether the state abstraction, object, or type denoted by
125 -- entity Item_Id has enabled property Property.
127 function Has_Null_Extension (T : Entity_Id) return Boolean;
128 -- T is a derived tagged type. Check whether the type extension is null.
129 -- If the parent type is fully initialized, T can be treated as such.
131 function Is_Atomic_Object_Entity (Id : Entity_Id) return Boolean;
132 -- Determine whether arbitrary entity Id denotes an atomic object as per
133 -- RM C.6(7).
135 function Is_Container_Aggregate (Exp : Node_Id) return Boolean;
136 -- Is the given expression a container aggregate?
138 generic
139 with function Is_Effectively_Volatile_Entity
140 (Id : Entity_Id) return Boolean;
141 -- Function to use on object and type entities
142 function Is_Effectively_Volatile_Object_Shared
143 (N : Node_Id) return Boolean;
144 -- Shared function used to detect effectively volatile objects and
145 -- effectively volatile objects for reading.
147 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
148 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
149 -- with discriminants whose default values are static, examine only the
150 -- components in the selected variant to determine whether all of them
151 -- have a default.
153 function Is_Preelaborable_Function (Id : Entity_Id) return Boolean;
154 -- Ada 2022: Determine whether the specified function is suitable as the
155 -- name of a call in a preelaborable construct (RM 10.2.1(7/5)).
157 type Null_Status_Kind is
158 (Is_Null,
159 -- This value indicates that a subexpression is known to have a null
160 -- value at compile time.
162 Is_Non_Null,
163 -- This value indicates that a subexpression is known to have a non-null
164 -- value at compile time.
166 Unknown);
167 -- This value indicates that it cannot be determined at compile time
168 -- whether a subexpression yields a null or non-null value.
170 function Null_Status (N : Node_Id) return Null_Status_Kind;
171 -- Determine whether subexpression N of an access type yields a null value,
172 -- a non-null value, or the value cannot be determined at compile time. The
173 -- routine does not take simple flow diagnostics into account, it relies on
174 -- static facts such as the presence of null exclusions.
176 function Subprogram_Name (N : Node_Id) return String;
177 -- Return the fully qualified name of the enclosing subprogram for the
178 -- given node N, with file:line:col information appended, e.g.
179 -- "subp:file:line:col", corresponding to the source location of the
180 -- body of the subprogram.
182 -----------------------------
183 -- Abstract_Interface_List --
184 -----------------------------
186 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
187 Nod : Node_Id;
189 begin
190 if Is_Concurrent_Type (Typ) then
192 -- If we are dealing with a synchronized subtype, go to the base
193 -- type, whose declaration has the interface list.
195 Nod := Declaration_Node (Base_Type (Typ));
197 if Nkind (Nod) in N_Full_Type_Declaration | N_Private_Type_Declaration
198 then
199 return Empty_List;
200 end if;
202 elsif Ekind (Typ) = E_Record_Type_With_Private then
203 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
204 Nod := Type_Definition (Parent (Typ));
206 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
207 if Present (Full_View (Typ))
208 and then
209 Nkind (Parent (Full_View (Typ))) = N_Full_Type_Declaration
210 then
211 Nod := Type_Definition (Parent (Full_View (Typ)));
213 -- If the full-view is not available we cannot do anything else
214 -- here (the source has errors).
216 else
217 return Empty_List;
218 end if;
220 -- Support for generic formals with interfaces is still missing ???
222 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
223 return Empty_List;
225 else
226 pragma Assert
227 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
228 Nod := Parent (Typ);
229 end if;
231 elsif Ekind (Typ) = E_Record_Subtype then
232 Nod := Type_Definition (Parent (Etype (Typ)));
234 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
236 -- Recurse, because parent may still be a private extension. Also
237 -- note that the full view of the subtype or the full view of its
238 -- base type may (both) be unavailable.
240 return Abstract_Interface_List (Etype (Typ));
242 elsif Ekind (Typ) = E_Record_Type then
243 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
244 Nod := Formal_Type_Definition (Parent (Typ));
245 else
246 Nod := Type_Definition (Parent (Typ));
247 end if;
249 -- Otherwise the type is of a kind which does not implement interfaces
251 else
252 return Empty_List;
253 end if;
255 return Interface_List (Nod);
256 end Abstract_Interface_List;
258 ----------------------------------
259 -- Acquire_Warning_Match_String --
260 ----------------------------------
262 function Acquire_Warning_Match_String (Str_Lit : Node_Id) return String is
263 S : constant String := To_String (Strval (Str_Lit));
264 begin
265 if S = "" then
266 return "";
267 else
268 -- Put "*" before or after or both, if it's not already there
270 declare
271 F : constant Boolean := S (S'First) = '*';
272 L : constant Boolean := S (S'Last) = '*';
273 begin
274 if F then
275 if L then
276 return S;
277 else
278 return S & "*";
279 end if;
280 else
281 if L then
282 return "*" & S;
283 else
284 return "*" & S & "*";
285 end if;
286 end if;
287 end;
288 end if;
289 end Acquire_Warning_Match_String;
291 --------------------------------
292 -- Add_Access_Type_To_Process --
293 --------------------------------
295 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
296 L : Elist_Id;
298 begin
299 Ensure_Freeze_Node (E);
300 L := Access_Types_To_Process (Freeze_Node (E));
302 if No (L) then
303 L := New_Elmt_List;
304 Set_Access_Types_To_Process (Freeze_Node (E), L);
305 end if;
307 Append_Elmt (A, L);
308 end Add_Access_Type_To_Process;
310 --------------------------
311 -- Add_Block_Identifier --
312 --------------------------
314 procedure Add_Block_Identifier
315 (N : Node_Id;
316 Id : out Entity_Id;
317 Scope : Entity_Id := Current_Scope)
319 Loc : constant Source_Ptr := Sloc (N);
320 begin
321 pragma Assert (Nkind (N) = N_Block_Statement);
323 -- The block already has a label, return its entity
325 if Present (Identifier (N)) then
326 Id := Entity (Identifier (N));
328 -- Create a new block label and set its attributes
330 else
331 Id := New_Internal_Entity (E_Block, Scope, Loc, 'B');
332 Set_Etype (Id, Standard_Void_Type);
333 Set_Parent (Id, N);
335 Set_Identifier (N, New_Occurrence_Of (Id, Loc));
336 Set_Block_Node (Id, Identifier (N));
337 end if;
338 end Add_Block_Identifier;
340 ----------------------------
341 -- Add_Global_Declaration --
342 ----------------------------
344 procedure Add_Global_Declaration (N : Node_Id) is
345 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
347 begin
348 if No (Declarations (Aux_Node)) then
349 Set_Declarations (Aux_Node, New_List);
350 end if;
352 Append_To (Declarations (Aux_Node), N);
353 Analyze (N);
354 end Add_Global_Declaration;
356 --------------------------------
357 -- Address_Integer_Convert_OK --
358 --------------------------------
360 function Address_Integer_Convert_OK (T1, T2 : Entity_Id) return Boolean is
361 begin
362 if Allow_Integer_Address
363 and then ((Is_Descendant_Of_Address (T1)
364 and then Is_Private_Type (T1)
365 and then Is_Integer_Type (T2))
366 or else
367 (Is_Descendant_Of_Address (T2)
368 and then Is_Private_Type (T2)
369 and then Is_Integer_Type (T1)))
370 then
371 return True;
372 else
373 return False;
374 end if;
375 end Address_Integer_Convert_OK;
377 -------------------
378 -- Address_Value --
379 -------------------
381 function Address_Value (N : Node_Id) return Node_Id is
382 Expr : Node_Id := N;
384 begin
385 loop
386 -- For constant, get constant expression
388 if Is_Entity_Name (Expr)
389 and then Ekind (Entity (Expr)) = E_Constant
390 then
391 Expr := Constant_Value (Entity (Expr));
393 -- For unchecked conversion, get result to convert
395 elsif Nkind (Expr) = N_Unchecked_Type_Conversion then
396 Expr := Expression (Expr);
398 -- For (common case) of To_Address call, get argument
400 elsif Nkind (Expr) = N_Function_Call
401 and then Is_Entity_Name (Name (Expr))
402 and then Is_RTE (Entity (Name (Expr)), RE_To_Address)
403 then
404 Expr := First_Actual (Expr);
406 -- We finally have the real expression
408 else
409 exit;
410 end if;
411 end loop;
413 return Expr;
414 end Address_Value;
416 -----------------
417 -- Addressable --
418 -----------------
420 function Addressable (V : Uint) return Boolean is
421 begin
422 if No (V) then
423 return False;
424 end if;
426 return V = Uint_8 or else
427 V = Uint_16 or else
428 V = Uint_32 or else
429 V = Uint_64 or else
430 (V = Uint_128 and then System_Max_Integer_Size = 128);
431 end Addressable;
433 function Addressable (V : Int) return Boolean is
434 begin
435 return V = 8 or else
436 V = 16 or else
437 V = 32 or else
438 V = 64 or else
439 V = System_Max_Integer_Size;
440 end Addressable;
442 ---------------------------------
443 -- Aggregate_Constraint_Checks --
444 ---------------------------------
446 procedure Aggregate_Constraint_Checks
447 (Exp : Node_Id;
448 Check_Typ : Entity_Id)
450 Exp_Typ : constant Entity_Id := Etype (Exp);
452 begin
453 if Raises_Constraint_Error (Exp) then
454 return;
455 end if;
457 -- Ada 2005 (AI-230): Generate a conversion to an anonymous access
458 -- component's type to force the appropriate accessibility checks.
460 -- Ada 2005 (AI-231): Generate conversion to the null-excluding type to
461 -- force the corresponding run-time check
463 if Is_Access_Type (Check_Typ)
464 and then Is_Local_Anonymous_Access (Check_Typ)
465 then
466 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
467 Analyze_And_Resolve (Exp, Check_Typ);
468 Check_Unset_Reference (Exp);
469 end if;
471 -- What follows is really expansion activity, so check that expansion
472 -- is on and is allowed. In GNATprove mode, we also want check flags to
473 -- be added in the tree, so that the formal verification can rely on
474 -- those to be present. In GNATprove mode for formal verification, some
475 -- treatment typically only done during expansion needs to be performed
476 -- on the tree, but it should not be applied inside generics. Otherwise,
477 -- this breaks the name resolution mechanism for generic instances.
479 if not Expander_Active
480 and (Inside_A_Generic or not Full_Analysis or not GNATprove_Mode)
481 then
482 return;
483 end if;
485 if Is_Access_Type (Check_Typ)
486 and then Can_Never_Be_Null (Check_Typ)
487 and then not Can_Never_Be_Null (Exp_Typ)
488 then
489 Install_Null_Excluding_Check (Exp);
490 end if;
492 -- First check if we have to insert discriminant checks
494 if Has_Discriminants (Exp_Typ) then
495 Apply_Discriminant_Check (Exp, Check_Typ);
497 -- Next emit length checks for array aggregates
499 elsif Is_Array_Type (Exp_Typ) then
500 Apply_Length_Check (Exp, Check_Typ);
502 -- Finally emit scalar and string checks. If we are dealing with a
503 -- scalar literal we need to check by hand because the Etype of
504 -- literals is not necessarily correct.
506 elsif Is_Scalar_Type (Exp_Typ)
507 and then Compile_Time_Known_Value (Exp)
508 then
509 if Is_Out_Of_Range (Exp, Base_Type (Check_Typ)) then
510 Apply_Compile_Time_Constraint_Error
511 (Exp, "value not in range of}??", CE_Range_Check_Failed,
512 Ent => Base_Type (Check_Typ),
513 Typ => Base_Type (Check_Typ));
515 elsif Is_Out_Of_Range (Exp, Check_Typ) then
516 Apply_Compile_Time_Constraint_Error
517 (Exp, "value not in range of}??", CE_Range_Check_Failed,
518 Ent => Check_Typ,
519 Typ => Check_Typ);
521 elsif not Range_Checks_Suppressed (Check_Typ) then
522 Apply_Scalar_Range_Check (Exp, Check_Typ);
523 end if;
525 -- Verify that target type is also scalar, to prevent view anomalies
526 -- in instantiations.
528 elsif (Is_Scalar_Type (Exp_Typ)
529 or else Nkind (Exp) = N_String_Literal)
530 and then Is_Scalar_Type (Check_Typ)
531 and then Exp_Typ /= Check_Typ
532 then
533 -- If expression is a constant, it is worthwhile checking whether it
534 -- is a bound of the type.
536 if Is_Entity_Name (Exp)
537 and then Ekind (Entity (Exp)) = E_Constant
538 then
539 if (Is_Entity_Name (Type_Low_Bound (Check_Typ))
540 and then Entity (Exp) = Entity (Type_Low_Bound (Check_Typ)))
541 or else
542 (Is_Entity_Name (Type_High_Bound (Check_Typ))
543 and then Entity (Exp) = Entity (Type_High_Bound (Check_Typ)))
544 then
545 return;
546 end if;
547 end if;
549 -- Change Exp into Check_Typ'(Exp) to ensure that range checks are
550 -- performed at run time.
552 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
553 Analyze_And_Resolve (Exp, Check_Typ);
554 Check_Unset_Reference (Exp);
556 end if;
557 end Aggregate_Constraint_Checks;
559 -----------------------
560 -- Alignment_In_Bits --
561 -----------------------
563 function Alignment_In_Bits (E : Entity_Id) return Uint is
564 begin
565 return Alignment (E) * System_Storage_Unit;
566 end Alignment_In_Bits;
568 --------------------------------------
569 -- All_Composite_Constraints_Static --
570 --------------------------------------
572 function All_Composite_Constraints_Static
573 (Constr : Node_Id) return Boolean
575 begin
576 if No (Constr) or else Error_Posted (Constr) then
577 return True;
578 end if;
580 case Nkind (Constr) is
581 when N_Subexpr =>
582 if Nkind (Constr) in N_Has_Entity
583 and then Present (Entity (Constr))
584 then
585 if Is_Type (Entity (Constr)) then
586 return
587 not Is_Discrete_Type (Entity (Constr))
588 or else Is_OK_Static_Subtype (Entity (Constr));
589 end if;
591 elsif Nkind (Constr) = N_Range then
592 return
593 Is_OK_Static_Expression (Low_Bound (Constr))
594 and then
595 Is_OK_Static_Expression (High_Bound (Constr));
597 elsif Nkind (Constr) = N_Attribute_Reference
598 and then Attribute_Name (Constr) = Name_Range
599 then
600 return
601 Is_OK_Static_Expression
602 (Type_Low_Bound (Etype (Prefix (Constr))))
603 and then
604 Is_OK_Static_Expression
605 (Type_High_Bound (Etype (Prefix (Constr))));
606 end if;
608 return
609 No (Etype (Constr)) -- previous error
610 or else not Is_Discrete_Type (Etype (Constr))
611 or else Is_OK_Static_Expression (Constr);
613 when N_Discriminant_Association =>
614 return All_Composite_Constraints_Static (Expression (Constr));
616 when N_Range_Constraint =>
617 return
618 All_Composite_Constraints_Static (Range_Expression (Constr));
620 when N_Index_Or_Discriminant_Constraint =>
621 declare
622 One_Cstr : Entity_Id;
623 begin
624 One_Cstr := First (Constraints (Constr));
625 while Present (One_Cstr) loop
626 if not All_Composite_Constraints_Static (One_Cstr) then
627 return False;
628 end if;
630 Next (One_Cstr);
631 end loop;
632 end;
634 return True;
636 when N_Subtype_Indication =>
637 return
638 All_Composite_Constraints_Static (Subtype_Mark (Constr))
639 and then
640 All_Composite_Constraints_Static (Constraint (Constr));
642 when others =>
643 raise Program_Error;
644 end case;
645 end All_Composite_Constraints_Static;
647 ------------------------
648 -- Append_Entity_Name --
649 ------------------------
651 procedure Append_Entity_Name (Buf : in out Bounded_String; E : Entity_Id) is
652 Temp : Bounded_String;
654 procedure Inner (E : Entity_Id);
655 -- Inner recursive routine, keep outer routine nonrecursive to ease
656 -- debugging when we get strange results from this routine.
658 -----------
659 -- Inner --
660 -----------
662 procedure Inner (E : Entity_Id) is
663 Scop : Node_Id;
665 begin
666 -- If entity has an internal name, skip by it, and print its scope.
667 -- Note that we strip a final R from the name before the test; this
668 -- is needed for some cases of instantiations.
670 declare
671 E_Name : Bounded_String;
673 begin
674 Append (E_Name, Chars (E));
676 if E_Name.Chars (E_Name.Length) = 'R' then
677 E_Name.Length := E_Name.Length - 1;
678 end if;
680 if Is_Internal_Name (E_Name) then
681 Inner (Scope (E));
682 return;
683 end if;
684 end;
686 Scop := Scope (E);
688 -- Just print entity name if its scope is at the outer level
690 if Scop = Standard_Standard then
691 null;
693 -- If scope comes from source, write scope and entity
695 elsif Comes_From_Source (Scop) then
696 Append_Entity_Name (Temp, Scop);
697 Append (Temp, '.');
699 -- If in wrapper package skip past it
701 elsif Present (Scop) and then Is_Wrapper_Package (Scop) then
702 Append_Entity_Name (Temp, Scope (Scop));
703 Append (Temp, '.');
705 -- Otherwise nothing to output (happens in unnamed block statements)
707 else
708 null;
709 end if;
711 -- Output the name
713 declare
714 E_Name : Bounded_String;
716 begin
717 Append_Unqualified_Decoded (E_Name, Chars (E));
719 -- Remove trailing upper-case letters from the name (useful for
720 -- dealing with some cases of internal names generated in the case
721 -- of references from within a generic).
723 while E_Name.Length > 1
724 and then E_Name.Chars (E_Name.Length) in 'A' .. 'Z'
725 loop
726 E_Name.Length := E_Name.Length - 1;
727 end loop;
729 -- Adjust casing appropriately (gets name from source if possible)
731 Adjust_Name_Case (E_Name, Sloc (E));
732 Append (Temp, E_Name);
733 end;
734 end Inner;
736 -- Start of processing for Append_Entity_Name
738 begin
739 Inner (E);
740 Append (Buf, Temp);
741 end Append_Entity_Name;
743 ---------------------------------
744 -- Append_Inherited_Subprogram --
745 ---------------------------------
747 procedure Append_Inherited_Subprogram (S : Entity_Id) is
748 Par : constant Entity_Id := Alias (S);
749 -- The parent subprogram
751 Scop : constant Entity_Id := Scope (Par);
752 -- The scope of definition of the parent subprogram
754 Typ : constant Entity_Id := Defining_Entity (Parent (S));
755 -- The derived type of which S is a primitive operation
757 Decl : Node_Id;
758 Next_E : Entity_Id;
760 begin
761 if Ekind (Current_Scope) = E_Package
762 and then In_Private_Part (Current_Scope)
763 and then Has_Private_Declaration (Typ)
764 and then Is_Tagged_Type (Typ)
765 and then Scop = Current_Scope
766 then
767 -- The inherited operation is available at the earliest place after
768 -- the derived type declaration (RM 7.3.1 (6/1)). This is only
769 -- relevant for type extensions. If the parent operation appears
770 -- after the type extension, the operation is not visible.
772 Decl := First
773 (Visible_Declarations
774 (Package_Specification (Current_Scope)));
775 while Present (Decl) loop
776 if Nkind (Decl) = N_Private_Extension_Declaration
777 and then Defining_Entity (Decl) = Typ
778 then
779 if Sloc (Decl) > Sloc (Par) then
780 Next_E := Next_Entity (Par);
781 Link_Entities (Par, S);
782 Link_Entities (S, Next_E);
783 return;
785 else
786 exit;
787 end if;
788 end if;
790 Next (Decl);
791 end loop;
792 end if;
794 -- If partial view is not a type extension, or it appears before the
795 -- subprogram declaration, insert normally at end of entity list.
797 Append_Entity (S, Current_Scope);
798 end Append_Inherited_Subprogram;
800 -----------------------------------------
801 -- Apply_Compile_Time_Constraint_Error --
802 -----------------------------------------
804 procedure Apply_Compile_Time_Constraint_Error
805 (N : Node_Id;
806 Msg : String;
807 Reason : RT_Exception_Code;
808 Ent : Entity_Id := Empty;
809 Typ : Entity_Id := Empty;
810 Loc : Source_Ptr := No_Location;
811 Warn : Boolean := False;
812 Emit_Message : Boolean := True)
814 Stat : constant Boolean := Is_Static_Expression (N);
815 R_Stat : constant Node_Id :=
816 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
817 Rtyp : Entity_Id;
819 begin
820 if No (Typ) then
821 Rtyp := Etype (N);
822 else
823 Rtyp := Typ;
824 end if;
826 if Emit_Message then
827 Discard_Node
828 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
829 end if;
831 -- Now we replace the node by an N_Raise_Constraint_Error node
832 -- This does not need reanalyzing, so set it as analyzed now.
834 Rewrite (N, R_Stat);
835 Set_Analyzed (N, True);
837 Set_Etype (N, Rtyp);
838 Set_Raises_Constraint_Error (N);
840 -- Now deal with possible local raise handling
842 Possible_Local_Raise (N, Standard_Constraint_Error);
844 -- If the original expression was marked as static, the result is
845 -- still marked as static, but the Raises_Constraint_Error flag is
846 -- always set so that further static evaluation is not attempted.
848 if Stat then
849 Set_Is_Static_Expression (N);
850 end if;
851 end Apply_Compile_Time_Constraint_Error;
853 ---------------------------
854 -- Async_Readers_Enabled --
855 ---------------------------
857 function Async_Readers_Enabled (Id : Entity_Id) return Boolean is
858 begin
859 return Has_Enabled_Property (Id, Name_Async_Readers);
860 end Async_Readers_Enabled;
862 ---------------------------
863 -- Async_Writers_Enabled --
864 ---------------------------
866 function Async_Writers_Enabled (Id : Entity_Id) return Boolean is
867 begin
868 return Has_Enabled_Property (Id, Name_Async_Writers);
869 end Async_Writers_Enabled;
871 --------------------------------------
872 -- Available_Full_View_Of_Component --
873 --------------------------------------
875 function Available_Full_View_Of_Component (T : Entity_Id) return Boolean is
876 ST : constant Entity_Id := Scope (T);
877 SCT : constant Entity_Id := Scope (Component_Type (T));
878 begin
879 return In_Open_Scopes (ST)
880 and then In_Open_Scopes (SCT)
881 and then Scope_Depth (ST) >= Scope_Depth (SCT);
882 end Available_Full_View_Of_Component;
884 ----------------
885 -- Bad_Aspect --
886 ----------------
888 procedure Bad_Aspect
889 (N : Node_Id;
890 Nam : Name_Id;
891 Warn : Boolean := False)
893 begin
894 Error_Msg_Warn := Warn;
895 Error_Msg_N ("<<& is not a valid aspect identifier", N);
897 -- Check bad spelling
898 Error_Msg_Name_1 := Aspect_Spell_Check (Nam);
899 if Error_Msg_Name_1 /= No_Name then
900 Error_Msg_N -- CODEFIX
901 ("\<<possible misspelling of %", N);
902 end if;
903 end Bad_Aspect;
905 -------------------
906 -- Bad_Attribute --
907 -------------------
909 procedure Bad_Attribute
910 (N : Node_Id;
911 Nam : Name_Id;
912 Warn : Boolean := False)
914 begin
915 Error_Msg_Warn := Warn;
916 Error_Msg_N ("<<unrecognized attribute&", N);
918 -- Check for possible misspelling
920 Error_Msg_Name_1 := Attribute_Spell_Check (Nam);
921 if Error_Msg_Name_1 /= No_Name then
922 Error_Msg_N -- CODEFIX
923 ("\<<possible misspelling of %", N);
924 end if;
925 end Bad_Attribute;
927 --------------------------------
928 -- Bad_Predicated_Subtype_Use --
929 --------------------------------
931 procedure Bad_Predicated_Subtype_Use
932 (Msg : String;
933 N : Node_Id;
934 Typ : Entity_Id;
935 Suggest_Static : Boolean := False)
937 Gen : Entity_Id;
939 begin
940 -- Avoid cascaded errors
942 if Error_Posted (N) then
943 return;
944 end if;
946 if Inside_A_Generic then
947 Gen := Current_Scope;
948 while Present (Gen) and then Ekind (Gen) /= E_Generic_Package loop
949 Gen := Scope (Gen);
950 end loop;
952 if No (Gen) then
953 return;
954 end if;
956 if Is_Generic_Formal (Typ) and then Is_Discrete_Type (Typ) then
957 Set_No_Predicate_On_Actual (Typ);
958 end if;
960 elsif Has_Predicates (Typ) then
961 if Is_Generic_Actual_Type (Typ) then
963 -- The restriction on loop parameters is only that the type
964 -- should have no dynamic predicates.
966 if Nkind (Parent (N)) = N_Loop_Parameter_Specification
967 and then not Has_Dynamic_Predicate_Aspect (Typ)
968 and then Is_OK_Static_Subtype (Typ)
969 then
970 return;
971 end if;
973 Gen := Current_Scope;
974 while not Is_Generic_Instance (Gen) loop
975 Gen := Scope (Gen);
976 end loop;
978 pragma Assert (Present (Gen));
980 if Ekind (Gen) = E_Package and then In_Package_Body (Gen) then
981 Error_Msg_Warn := SPARK_Mode /= On;
982 Error_Msg_FE (Msg & "<<", N, Typ);
983 Error_Msg_F ("\Program_Error [<<", N);
985 Insert_Action (N,
986 Make_Raise_Program_Error (Sloc (N),
987 Reason => PE_Bad_Predicated_Generic_Type));
989 else
990 Error_Msg_FE (Msg, N, Typ);
991 end if;
993 else
994 Error_Msg_FE (Msg, N, Typ);
995 end if;
997 -- Suggest to use First_Valid/Last_Valid instead of First/Last/Range
998 -- if the predicate is static.
1000 if not Has_Dynamic_Predicate_Aspect (Typ)
1001 and then Has_Static_Predicate (Typ)
1002 and then Nkind (N) = N_Attribute_Reference
1003 then
1004 declare
1005 Aname : constant Name_Id := Attribute_Name (N);
1006 Attr_Id : constant Attribute_Id := Get_Attribute_Id (Aname);
1007 begin
1008 case Attr_Id is
1009 when Attribute_First =>
1010 Error_Msg_F ("\use attribute First_Valid instead", N);
1011 when Attribute_Last =>
1012 Error_Msg_F ("\use attribute Last_Valid instead", N);
1013 when Attribute_Range =>
1014 Error_Msg_F ("\use attributes First_Valid and "
1015 & "Last_Valid instead", N);
1016 when others =>
1017 null;
1018 end case;
1019 end;
1020 end if;
1022 -- Emit an optional suggestion on how to remedy the error if the
1023 -- context warrants it.
1025 if Suggest_Static and then Has_Static_Predicate (Typ) then
1026 Error_Msg_FE ("\predicate of & should be marked static", N, Typ);
1027 end if;
1028 end if;
1029 end Bad_Predicated_Subtype_Use;
1031 -----------------------------------------
1032 -- Bad_Unordered_Enumeration_Reference --
1033 -----------------------------------------
1035 function Bad_Unordered_Enumeration_Reference
1036 (N : Node_Id;
1037 T : Entity_Id) return Boolean
1039 begin
1040 return Is_Enumeration_Type (T)
1041 and then Warn_On_Unordered_Enumeration_Type
1042 and then not Is_Generic_Type (T)
1043 and then Comes_From_Source (N)
1044 and then not Has_Pragma_Ordered (T)
1045 and then not In_Same_Extended_Unit (N, T);
1046 end Bad_Unordered_Enumeration_Reference;
1048 ----------------------------
1049 -- Begin_Keyword_Location --
1050 ----------------------------
1052 function Begin_Keyword_Location (N : Node_Id) return Source_Ptr is
1053 HSS : Node_Id;
1055 begin
1056 pragma Assert
1057 (Nkind (N) in
1058 N_Block_Statement |
1059 N_Entry_Body |
1060 N_Package_Body |
1061 N_Subprogram_Body |
1062 N_Task_Body);
1064 HSS := Handled_Statement_Sequence (N);
1066 -- When the handled sequence of statements comes from source, the
1067 -- location of the "begin" keyword is that of the sequence itself.
1068 -- Note that an internal construct may inherit a source sequence.
1070 if Comes_From_Source (HSS) then
1071 return Sloc (HSS);
1073 -- The parser generates an internal handled sequence of statements to
1074 -- capture the location of the "begin" keyword if present in the source.
1075 -- Since there are no source statements, the location of the "begin"
1076 -- keyword is effectively that of the "end" keyword.
1078 elsif Comes_From_Source (N) then
1079 return Sloc (HSS);
1081 -- Otherwise the construct is internal and should carry the location of
1082 -- the original construct which prompted its creation.
1084 else
1085 return Sloc (N);
1086 end if;
1087 end Begin_Keyword_Location;
1089 --------------------------
1090 -- Build_Actual_Subtype --
1091 --------------------------
1093 function Build_Actual_Subtype
1094 (T : Entity_Id;
1095 N : Node_Or_Entity_Id) return Node_Id
1097 Loc : Source_Ptr;
1098 -- Normally Sloc (N), but may point to corresponding body in some cases
1100 Constraints : List_Id;
1101 Decl : Node_Id;
1102 Discr : Entity_Id;
1103 Hi : Node_Id;
1104 Lo : Node_Id;
1105 Subt : Entity_Id;
1106 Disc_Type : Entity_Id;
1107 Obj : Node_Id;
1108 Index : Node_Id;
1110 begin
1111 Loc := Sloc (N);
1113 if Nkind (N) = N_Defining_Identifier then
1114 Obj := New_Occurrence_Of (N, Loc);
1116 -- If this is a formal parameter of a subprogram declaration, and
1117 -- we are compiling the body, we want the declaration for the
1118 -- actual subtype to carry the source position of the body, to
1119 -- prevent anomalies in gdb when stepping through the code.
1121 if Is_Formal (N) then
1122 declare
1123 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
1124 begin
1125 if Nkind (Decl) = N_Subprogram_Declaration
1126 and then Present (Corresponding_Body (Decl))
1127 then
1128 Loc := Sloc (Corresponding_Body (Decl));
1129 end if;
1130 end;
1131 end if;
1133 else
1134 Obj := N;
1135 end if;
1137 if Is_Array_Type (T) then
1138 Constraints := New_List;
1139 Index := First_Index (T);
1141 for J in 1 .. Number_Dimensions (T) loop
1143 -- Build an array subtype declaration with the nominal subtype and
1144 -- the bounds of the actual. Add the declaration in front of the
1145 -- local declarations for the subprogram, for analysis before any
1146 -- reference to the formal in the body.
1148 -- If this is for an index with a fixed lower bound, then use
1149 -- the fixed lower bound as the lower bound of the actual
1150 -- subtype's corresponding index.
1152 if not Is_Constrained (T)
1153 and then Is_Fixed_Lower_Bound_Index_Subtype (Etype (Index))
1154 then
1155 Lo := New_Copy_Tree (Type_Low_Bound (Etype (Index)));
1157 else
1158 Lo :=
1159 Make_Attribute_Reference (Loc,
1160 Prefix =>
1161 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
1162 Attribute_Name => Name_First,
1163 Expressions => New_List (
1164 Make_Integer_Literal (Loc, J)));
1165 end if;
1167 Hi :=
1168 Make_Attribute_Reference (Loc,
1169 Prefix =>
1170 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
1171 Attribute_Name => Name_Last,
1172 Expressions => New_List (
1173 Make_Integer_Literal (Loc, J)));
1175 Append (Make_Range (Loc, Lo, Hi), Constraints);
1177 Next_Index (Index);
1178 end loop;
1180 -- If the type has unknown discriminants there is no constrained
1181 -- subtype to build. This is never called for a formal or for a
1182 -- lhs, so returning the type is ok ???
1184 elsif Has_Unknown_Discriminants (T) then
1185 return T;
1187 else
1188 Constraints := New_List;
1190 -- Type T is a generic derived type, inherit the discriminants from
1191 -- the parent type.
1193 if Is_Private_Type (T)
1194 and then No (Full_View (T))
1196 -- T was flagged as an error if it was declared as a formal
1197 -- derived type with known discriminants. In this case there
1198 -- is no need to look at the parent type since T already carries
1199 -- its own discriminants.
1201 and then not Error_Posted (T)
1202 then
1203 Disc_Type := Etype (Base_Type (T));
1204 else
1205 Disc_Type := T;
1206 end if;
1208 Discr := First_Discriminant (Disc_Type);
1209 while Present (Discr) loop
1210 Append_To (Constraints,
1211 Make_Selected_Component (Loc,
1212 Prefix =>
1213 Duplicate_Subexpr_No_Checks (Obj),
1214 Selector_Name => New_Occurrence_Of (Discr, Loc)));
1215 Next_Discriminant (Discr);
1216 end loop;
1217 end if;
1219 Subt := Make_Temporary (Loc, 'S', Related_Node => N);
1220 Set_Is_Internal (Subt);
1222 Decl :=
1223 Make_Subtype_Declaration (Loc,
1224 Defining_Identifier => Subt,
1225 Subtype_Indication =>
1226 Make_Subtype_Indication (Loc,
1227 Subtype_Mark => New_Occurrence_Of (T, Loc),
1228 Constraint =>
1229 Make_Index_Or_Discriminant_Constraint (Loc,
1230 Constraints => Constraints)));
1232 Mark_Rewrite_Insertion (Decl);
1233 return Decl;
1234 end Build_Actual_Subtype;
1236 ---------------------------------------
1237 -- Build_Actual_Subtype_Of_Component --
1238 ---------------------------------------
1240 function Build_Actual_Subtype_Of_Component
1241 (T : Entity_Id;
1242 N : Node_Id) return Node_Id
1244 Loc : constant Source_Ptr := Sloc (N);
1245 P : constant Node_Id := Prefix (N);
1247 D : Elmt_Id;
1248 Id : Node_Id;
1249 Index_Typ : Entity_Id;
1250 Sel : Entity_Id := Empty;
1252 Desig_Typ : Entity_Id;
1253 -- This is either a copy of T, or if T is an access type, then it is
1254 -- the directly designated type of this access type.
1256 function Build_Access_Record_Constraint (C : List_Id) return List_Id;
1257 -- If the record component is a constrained access to the current
1258 -- record, the subtype has not been constructed during analysis of
1259 -- the enclosing record type (see Analyze_Access). In that case, build
1260 -- a constrained access subtype after replacing references to the
1261 -- enclosing discriminants with the corresponding discriminant values
1262 -- of the prefix.
1264 function Build_Actual_Array_Constraint return List_Id;
1265 -- If one or more of the bounds of the component depends on
1266 -- discriminants, build actual constraint using the discriminants
1267 -- of the prefix, as above.
1269 function Build_Actual_Record_Constraint return List_Id;
1270 -- Similar to previous one, for discriminated components constrained
1271 -- by the discriminant of the enclosing object.
1273 function Build_Discriminant_Reference
1274 (Discrim_Name : Node_Id; Obj : Node_Id := P) return Node_Id;
1275 -- Build a reference to the discriminant denoted by Discrim_Name.
1276 -- The prefix of the result is usually Obj, but it could be
1277 -- a prefix of Obj in some corner cases.
1279 function Copy_And_Maybe_Dereference (N : Node_Id) return Node_Id;
1280 -- Copy the subtree rooted at N and insert an explicit dereference if it
1281 -- is of an access type.
1283 -----------------------------------
1284 -- Build_Actual_Array_Constraint --
1285 -----------------------------------
1287 function Build_Actual_Array_Constraint return List_Id is
1288 Constraints : constant List_Id := New_List;
1289 Indx : Node_Id;
1290 Hi : Node_Id;
1291 Lo : Node_Id;
1292 Old_Hi : Node_Id;
1293 Old_Lo : Node_Id;
1295 begin
1296 Indx := First_Index (Desig_Typ);
1297 while Present (Indx) loop
1298 Old_Lo := Type_Low_Bound (Etype (Indx));
1299 Old_Hi := Type_High_Bound (Etype (Indx));
1301 if Denotes_Discriminant (Old_Lo) then
1302 Lo := Build_Discriminant_Reference (Old_Lo);
1303 else
1304 Lo := New_Copy_Tree (Old_Lo);
1306 -- The new bound will be reanalyzed in the enclosing
1307 -- declaration. For literal bounds that come from a type
1308 -- declaration, the type of the context must be imposed, so
1309 -- insure that analysis will take place. For non-universal
1310 -- types this is not strictly necessary.
1312 Set_Analyzed (Lo, False);
1313 end if;
1315 if Denotes_Discriminant (Old_Hi) then
1316 Hi := Build_Discriminant_Reference (Old_Hi);
1317 else
1318 Hi := New_Copy_Tree (Old_Hi);
1319 Set_Analyzed (Hi, False);
1320 end if;
1322 Append (Make_Range (Loc, Lo, Hi), Constraints);
1323 Next_Index (Indx);
1324 end loop;
1326 return Constraints;
1327 end Build_Actual_Array_Constraint;
1329 ------------------------------------
1330 -- Build_Actual_Record_Constraint --
1331 ------------------------------------
1333 function Build_Actual_Record_Constraint return List_Id is
1334 Constraints : constant List_Id := New_List;
1335 D : Elmt_Id;
1336 D_Val : Node_Id;
1338 begin
1339 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1340 while Present (D) loop
1341 if Denotes_Discriminant (Node (D)) then
1342 D_Val := Build_Discriminant_Reference (Node (D));
1343 else
1344 D_Val := New_Copy_Tree (Node (D));
1345 end if;
1347 Append (D_Val, Constraints);
1348 Next_Elmt (D);
1349 end loop;
1351 return Constraints;
1352 end Build_Actual_Record_Constraint;
1354 ----------------------------------
1355 -- Build_Discriminant_Reference --
1356 ----------------------------------
1358 function Build_Discriminant_Reference
1359 (Discrim_Name : Node_Id; Obj : Node_Id := P) return Node_Id
1361 Discrim : constant Entity_Id := Entity (Discrim_Name);
1363 function Obj_Is_Good_Prefix return Boolean;
1364 -- Returns True if Obj.Discrim makes sense; that is, if
1365 -- Obj has Discrim as one of its discriminants (or is an
1366 -- access value that designates such an object).
1368 ------------------------
1369 -- Obj_Is_Good_Prefix --
1370 ------------------------
1372 function Obj_Is_Good_Prefix return Boolean is
1373 Obj_Type : Entity_Id :=
1374 Implementation_Base_Type (Etype (Obj));
1376 Discriminated_Type : constant Entity_Id :=
1377 Implementation_Base_Type
1378 (Scope (Original_Record_Component (Discrim)));
1379 begin
1380 -- The order of the following two tests matters in the
1381 -- access-to-class-wide case.
1383 if Is_Access_Type (Obj_Type) then
1384 Obj_Type := Implementation_Base_Type
1385 (Designated_Type (Obj_Type));
1386 end if;
1388 if Is_Class_Wide_Type (Obj_Type) then
1389 Obj_Type := Implementation_Base_Type
1390 (Find_Specific_Type (Obj_Type));
1391 end if;
1393 -- If a type T1 defines a discriminant D1, then Obj.D1 is ok (for
1394 -- our purposes here) if T1 is an ancestor of the type of Obj.
1395 -- So that's what we would like to test for here.
1396 -- The bad news: Is_Ancestor is only defined in the tagged case.
1397 -- The good news: in the untagged case, Implementation_Base_Type
1398 -- looks through derived types so we can use a simpler test.
1400 if Is_Tagged_Type (Discriminated_Type) then
1401 return Is_Ancestor (Discriminated_Type, Obj_Type);
1402 else
1403 return Discriminated_Type = Obj_Type;
1404 end if;
1405 end Obj_Is_Good_Prefix;
1407 -- Start of processing for Build_Discriminant_Reference
1409 begin
1410 if not Obj_Is_Good_Prefix then
1411 -- If the given discriminant is not a component of the given
1412 -- object, then try the enclosing object.
1414 if Nkind (Obj) = N_Selected_Component then
1415 return Build_Discriminant_Reference
1416 (Discrim_Name => Discrim_Name,
1417 Obj => Prefix (Obj));
1418 elsif Nkind (Obj) in N_Has_Entity
1419 and then Nkind (Parent (Entity (Obj))) =
1420 N_Object_Renaming_Declaration
1421 then
1422 -- Look through a renaming (a corner case of a corner case).
1423 return Build_Discriminant_Reference
1424 (Discrim_Name => Discrim_Name,
1425 Obj => Name (Parent (Entity (Obj))));
1426 else
1427 -- We are in some unexpected case here, so revert to the
1428 -- old behavior (by falling through to it).
1429 null;
1430 end if;
1431 end if;
1433 return Make_Selected_Component (Loc,
1434 Prefix => Copy_And_Maybe_Dereference (Obj),
1435 Selector_Name => New_Occurrence_Of (Discrim, Loc));
1436 end Build_Discriminant_Reference;
1438 ------------------------------------
1439 -- Build_Access_Record_Constraint --
1440 ------------------------------------
1442 function Build_Access_Record_Constraint (C : List_Id) return List_Id is
1443 Constraints : constant List_Id := New_List;
1444 D : Node_Id;
1445 D_Val : Node_Id;
1447 begin
1448 -- Retrieve the constraint from the component declaration, because
1449 -- the component subtype has not been constructed and the component
1450 -- type is an unconstrained access.
1452 D := First (C);
1453 while Present (D) loop
1454 if Nkind (D) = N_Discriminant_Association
1455 and then Denotes_Discriminant (Expression (D))
1456 then
1457 D_Val := New_Copy_Tree (D);
1458 Set_Expression (D_Val,
1459 Make_Selected_Component (Loc,
1460 Prefix => Copy_And_Maybe_Dereference (P),
1461 Selector_Name =>
1462 New_Occurrence_Of (Entity (Expression (D)), Loc)));
1464 elsif Denotes_Discriminant (D) then
1465 D_Val := Make_Selected_Component (Loc,
1466 Prefix => Copy_And_Maybe_Dereference (P),
1467 Selector_Name => New_Occurrence_Of (Entity (D), Loc));
1469 else
1470 D_Val := New_Copy_Tree (D);
1471 end if;
1473 Append (D_Val, Constraints);
1474 Next (D);
1475 end loop;
1477 return Constraints;
1478 end Build_Access_Record_Constraint;
1480 --------------------------------
1481 -- Copy_And_Maybe_Dereference --
1482 --------------------------------
1484 function Copy_And_Maybe_Dereference (N : Node_Id) return Node_Id is
1485 New_N : constant Node_Id := New_Copy_Tree (N);
1487 begin
1488 if Is_Access_Type (Etype (N)) then
1489 return Make_Explicit_Dereference (Sloc (Parent (N)), New_N);
1491 else
1492 return New_N;
1493 end if;
1494 end Copy_And_Maybe_Dereference;
1496 -- Start of processing for Build_Actual_Subtype_Of_Component
1498 begin
1499 -- The subtype does not need to be created for a selected component
1500 -- in a Spec_Expression.
1502 if In_Spec_Expression then
1503 return Empty;
1505 -- More comments for the rest of this body would be good ???
1507 elsif Nkind (N) = N_Explicit_Dereference then
1508 if Is_Composite_Type (T)
1509 and then not Is_Constrained (T)
1510 and then not (Is_Class_Wide_Type (T)
1511 and then Is_Constrained (Root_Type (T)))
1512 and then not Has_Unknown_Discriminants (T)
1513 then
1514 -- If the type of the dereference is already constrained, it is an
1515 -- actual subtype.
1517 if Is_Array_Type (Etype (N))
1518 and then Is_Constrained (Etype (N))
1519 then
1520 return Empty;
1521 else
1522 Remove_Side_Effects (P);
1523 return Build_Actual_Subtype (T, N);
1524 end if;
1526 else
1527 return Empty;
1528 end if;
1530 elsif Nkind (N) = N_Selected_Component then
1531 -- The entity of the selected component allows us to retrieve
1532 -- the original constraint from its component declaration.
1534 Sel := Entity (Selector_Name (N));
1535 if Parent_Kind (Sel) /= N_Component_Declaration then
1536 return Empty;
1537 end if;
1538 end if;
1540 if Is_Access_Type (T) then
1541 Desig_Typ := Designated_Type (T);
1543 else
1544 Desig_Typ := T;
1545 end if;
1547 if Ekind (Desig_Typ) = E_Array_Subtype then
1548 Id := First_Index (Desig_Typ);
1550 -- Check whether an index bound is constrained by a discriminant
1552 while Present (Id) loop
1553 Index_Typ := Underlying_Type (Etype (Id));
1555 if Denotes_Discriminant (Type_Low_Bound (Index_Typ))
1556 or else
1557 Denotes_Discriminant (Type_High_Bound (Index_Typ))
1558 then
1559 Remove_Side_Effects (P);
1560 return
1561 Build_Component_Subtype
1562 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
1563 end if;
1565 Next_Index (Id);
1566 end loop;
1568 elsif Is_Composite_Type (Desig_Typ)
1569 and then Has_Discriminants (Desig_Typ)
1570 and then not Is_Empty_Elmt_List (Discriminant_Constraint (Desig_Typ))
1571 and then not Has_Unknown_Discriminants (Desig_Typ)
1572 then
1573 if Is_Private_Type (Desig_Typ)
1574 and then No (Discriminant_Constraint (Desig_Typ))
1575 then
1576 Desig_Typ := Full_View (Desig_Typ);
1577 end if;
1579 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1580 while Present (D) loop
1581 if Denotes_Discriminant (Node (D)) then
1582 Remove_Side_Effects (P);
1583 return
1584 Build_Component_Subtype (
1585 Build_Actual_Record_Constraint, Loc, Base_Type (T));
1586 end if;
1588 Next_Elmt (D);
1589 end loop;
1591 -- Special processing for an access record component that is
1592 -- the target of an assignment. If the designated type is an
1593 -- unconstrained discriminated record we create its actual
1594 -- subtype now.
1596 elsif Ekind (T) = E_Access_Type
1597 and then Present (Sel)
1598 and then Has_Per_Object_Constraint (Sel)
1599 and then Nkind (Parent (N)) = N_Assignment_Statement
1600 and then N = Name (Parent (N))
1601 -- and then not Inside_Init_Proc
1602 -- and then Has_Discriminants (Desig_Typ)
1603 -- and then not Is_Constrained (Desig_Typ)
1604 then
1605 declare
1606 S_Indic : constant Node_Id :=
1607 (Subtype_Indication
1608 (Component_Definition (Parent (Sel))));
1609 Discs : List_Id;
1610 begin
1611 if Nkind (S_Indic) = N_Subtype_Indication then
1612 Discs := Constraints (Constraint (S_Indic));
1614 Remove_Side_Effects (P);
1615 return Build_Component_Subtype
1616 (Build_Access_Record_Constraint (Discs), Loc, T);
1617 else
1618 return Empty;
1619 end if;
1620 end;
1621 end if;
1623 -- If none of the above, the actual and nominal subtypes are the same
1625 return Empty;
1626 end Build_Actual_Subtype_Of_Component;
1628 -----------------------------
1629 -- Build_Component_Subtype --
1630 -----------------------------
1632 function Build_Component_Subtype
1633 (C : List_Id;
1634 Loc : Source_Ptr;
1635 T : Entity_Id) return Node_Id
1637 Subt : Entity_Id;
1638 Decl : Node_Id;
1640 begin
1641 -- Unchecked_Union components do not require component subtypes
1643 if Is_Unchecked_Union (T) then
1644 return Empty;
1645 end if;
1647 Subt := Make_Temporary (Loc, 'S');
1648 Set_Is_Internal (Subt);
1650 Decl :=
1651 Make_Subtype_Declaration (Loc,
1652 Defining_Identifier => Subt,
1653 Subtype_Indication =>
1654 Make_Subtype_Indication (Loc,
1655 Subtype_Mark => New_Occurrence_Of (Base_Type (T), Loc),
1656 Constraint =>
1657 Make_Index_Or_Discriminant_Constraint (Loc,
1658 Constraints => C)));
1660 Mark_Rewrite_Insertion (Decl);
1661 return Decl;
1662 end Build_Component_Subtype;
1664 -----------------------------
1665 -- Build_Constrained_Itype --
1666 -----------------------------
1668 procedure Build_Constrained_Itype
1669 (N : Node_Id;
1670 Typ : Entity_Id;
1671 New_Assoc_List : List_Id)
1673 Constrs : constant List_Id := New_List;
1674 Loc : constant Source_Ptr := Sloc (N);
1675 Def_Id : Entity_Id;
1676 Indic : Node_Id;
1677 New_Assoc : Node_Id;
1678 Subtyp_Decl : Node_Id;
1680 begin
1681 New_Assoc := First (New_Assoc_List);
1682 while Present (New_Assoc) loop
1684 -- There is exactly one choice in the component association (and
1685 -- it is either a discriminant, a component or the others clause).
1686 pragma Assert (List_Length (Choices (New_Assoc)) = 1);
1688 -- Duplicate expression for the discriminant and put it on the
1689 -- list of constraints for the itype declaration.
1691 if Is_Entity_Name (First (Choices (New_Assoc)))
1692 and then
1693 Ekind (Entity (First (Choices (New_Assoc)))) = E_Discriminant
1694 then
1695 Append_To (Constrs, Duplicate_Subexpr (Expression (New_Assoc)));
1696 end if;
1698 Next (New_Assoc);
1699 end loop;
1701 if Has_Unknown_Discriminants (Typ)
1702 and then Present (Underlying_Record_View (Typ))
1703 then
1704 Indic :=
1705 Make_Subtype_Indication (Loc,
1706 Subtype_Mark =>
1707 New_Occurrence_Of (Underlying_Record_View (Typ), Loc),
1708 Constraint =>
1709 Make_Index_Or_Discriminant_Constraint (Loc,
1710 Constraints => Constrs));
1711 else
1712 Indic :=
1713 Make_Subtype_Indication (Loc,
1714 Subtype_Mark =>
1715 New_Occurrence_Of (Base_Type (Typ), Loc),
1716 Constraint =>
1717 Make_Index_Or_Discriminant_Constraint (Loc,
1718 Constraints => Constrs));
1719 end if;
1721 Def_Id := Create_Itype (Ekind (Typ), N);
1723 Subtyp_Decl :=
1724 Make_Subtype_Declaration (Loc,
1725 Defining_Identifier => Def_Id,
1726 Subtype_Indication => Indic);
1727 Set_Parent (Subtyp_Decl, Parent (N));
1729 -- Itypes must be analyzed with checks off (see itypes.ads)
1731 Analyze (Subtyp_Decl, Suppress => All_Checks);
1733 Set_Etype (N, Def_Id);
1734 end Build_Constrained_Itype;
1736 ---------------------------
1737 -- Build_Default_Subtype --
1738 ---------------------------
1740 function Build_Default_Subtype
1741 (T : Entity_Id;
1742 N : Node_Id) return Entity_Id
1744 Loc : constant Source_Ptr := Sloc (N);
1745 Disc : Entity_Id;
1747 Bas : Entity_Id;
1748 -- The base type that is to be constrained by the defaults
1750 begin
1751 if not Has_Discriminants (T) or else Is_Constrained (T) then
1752 return T;
1753 end if;
1755 Bas := Base_Type (T);
1757 -- If T is non-private but its base type is private, this is the
1758 -- completion of a subtype declaration whose parent type is private
1759 -- (see Complete_Private_Subtype in Sem_Ch3). The proper discriminants
1760 -- are to be found in the full view of the base. Check that the private
1761 -- status of T and its base differ.
1763 if Is_Private_Type (Bas)
1764 and then not Is_Private_Type (T)
1765 and then Present (Full_View (Bas))
1766 then
1767 Bas := Full_View (Bas);
1768 end if;
1770 Disc := First_Discriminant (T);
1772 if No (Discriminant_Default_Value (Disc)) then
1773 return T;
1774 end if;
1776 declare
1777 Act : constant Entity_Id := Make_Temporary (Loc, 'S');
1778 Constraints : constant List_Id := New_List;
1779 Decl : Node_Id;
1781 begin
1782 while Present (Disc) loop
1783 Append_To (Constraints,
1784 New_Copy_Tree (Discriminant_Default_Value (Disc)));
1785 Next_Discriminant (Disc);
1786 end loop;
1788 Decl :=
1789 Make_Subtype_Declaration (Loc,
1790 Defining_Identifier => Act,
1791 Subtype_Indication =>
1792 Make_Subtype_Indication (Loc,
1793 Subtype_Mark => New_Occurrence_Of (Bas, Loc),
1794 Constraint =>
1795 Make_Index_Or_Discriminant_Constraint (Loc,
1796 Constraints => Constraints)));
1798 Insert_Action (N, Decl);
1800 -- If the context is a component declaration the subtype declaration
1801 -- will be analyzed when the enclosing type is frozen, otherwise do
1802 -- it now.
1804 if Ekind (Current_Scope) /= E_Record_Type then
1805 Analyze (Decl);
1806 end if;
1808 return Act;
1809 end;
1810 end Build_Default_Subtype;
1812 ------------------------------
1813 -- Build_Default_Subtype_OK --
1814 ------------------------------
1816 function Build_Default_Subtype_OK (T : Entity_Id) return Boolean is
1818 function Default_Discriminant_Values_Known_At_Compile_Time
1819 (T : Entity_Id) return Boolean;
1820 -- For an unconstrained type T, return False if the given type has a
1821 -- discriminant with default value not known at compile time. Return
1822 -- True otherwise.
1824 ---------------------------------------------------------
1825 -- Default_Discriminant_Values_Known_At_Compile_Time --
1826 ---------------------------------------------------------
1828 function Default_Discriminant_Values_Known_At_Compile_Time
1829 (T : Entity_Id) return Boolean
1831 Discr : Entity_Id;
1832 DDV : Node_Id;
1834 begin
1836 -- If the type has no discriminant, we know them all at compile time
1838 if not Has_Discriminants (T) then
1839 return True;
1840 end if;
1842 -- The type has discriminants, check that none of them has a default
1843 -- value not known at compile time.
1845 Discr := First_Discriminant (T);
1847 while Present (Discr) loop
1848 DDV := Discriminant_Default_Value (Discr);
1850 if Present (DDV) and then not Compile_Time_Known_Value (DDV) then
1851 return False;
1852 end if;
1854 Next_Discriminant (Discr);
1855 end loop;
1857 return True;
1858 end Default_Discriminant_Values_Known_At_Compile_Time;
1860 -- Start of processing for Build_Default_Subtype_OK
1862 begin
1864 if Is_Constrained (T) then
1866 -- We won't build a new subtype if T is constrained
1868 return False;
1869 end if;
1871 if not Default_Discriminant_Values_Known_At_Compile_Time (T) then
1873 -- This is a special case of definite subtypes. To allocate a
1874 -- specific size to the subtype, we need to know the value at compile
1875 -- time. This might not be the case if the default value is the
1876 -- result of a function. In that case, the object might be definite
1877 -- and limited but the needed size might not be statically known or
1878 -- too tricky to obtain. In that case, we will not build the subtype.
1880 return False;
1881 end if;
1883 return Is_Definite_Subtype (T) and then Is_Limited_View (T);
1884 end Build_Default_Subtype_OK;
1886 --------------------------------------------
1887 -- Build_Discriminal_Subtype_Of_Component --
1888 --------------------------------------------
1890 function Build_Discriminal_Subtype_Of_Component
1891 (T : Entity_Id) return Node_Id
1893 Loc : constant Source_Ptr := Sloc (T);
1894 D : Elmt_Id;
1895 Id : Node_Id;
1897 function Build_Discriminal_Array_Constraint return List_Id;
1898 -- If one or more of the bounds of the component depends on
1899 -- discriminants, build actual constraint using the discriminants
1900 -- of the prefix.
1902 function Build_Discriminal_Record_Constraint return List_Id;
1903 -- Similar to previous one, for discriminated components constrained by
1904 -- the discriminant of the enclosing object.
1906 ----------------------------------------
1907 -- Build_Discriminal_Array_Constraint --
1908 ----------------------------------------
1910 function Build_Discriminal_Array_Constraint return List_Id is
1911 Constraints : constant List_Id := New_List;
1912 Indx : Node_Id;
1913 Hi : Node_Id;
1914 Lo : Node_Id;
1915 Old_Hi : Node_Id;
1916 Old_Lo : Node_Id;
1918 begin
1919 Indx := First_Index (T);
1920 while Present (Indx) loop
1921 Old_Lo := Type_Low_Bound (Etype (Indx));
1922 Old_Hi := Type_High_Bound (Etype (Indx));
1924 if Denotes_Discriminant (Old_Lo) then
1925 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
1927 else
1928 Lo := New_Copy_Tree (Old_Lo);
1929 end if;
1931 if Denotes_Discriminant (Old_Hi) then
1932 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
1934 else
1935 Hi := New_Copy_Tree (Old_Hi);
1936 end if;
1938 Append (Make_Range (Loc, Lo, Hi), Constraints);
1939 Next_Index (Indx);
1940 end loop;
1942 return Constraints;
1943 end Build_Discriminal_Array_Constraint;
1945 -----------------------------------------
1946 -- Build_Discriminal_Record_Constraint --
1947 -----------------------------------------
1949 function Build_Discriminal_Record_Constraint return List_Id is
1950 Constraints : constant List_Id := New_List;
1951 D : Elmt_Id;
1952 D_Val : Node_Id;
1954 begin
1955 D := First_Elmt (Discriminant_Constraint (T));
1956 while Present (D) loop
1957 if Denotes_Discriminant (Node (D)) then
1958 D_Val :=
1959 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
1960 else
1961 D_Val := New_Copy_Tree (Node (D));
1962 end if;
1964 Append (D_Val, Constraints);
1965 Next_Elmt (D);
1966 end loop;
1968 return Constraints;
1969 end Build_Discriminal_Record_Constraint;
1971 -- Start of processing for Build_Discriminal_Subtype_Of_Component
1973 begin
1974 if Ekind (T) = E_Array_Subtype then
1975 Id := First_Index (T);
1976 while Present (Id) loop
1977 if Denotes_Discriminant (Type_Low_Bound (Etype (Id)))
1978 or else
1979 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
1980 then
1981 return Build_Component_Subtype
1982 (Build_Discriminal_Array_Constraint, Loc, T);
1983 end if;
1985 Next_Index (Id);
1986 end loop;
1988 elsif Ekind (T) = E_Record_Subtype
1989 and then Has_Discriminants (T)
1990 and then not Has_Unknown_Discriminants (T)
1991 then
1992 D := First_Elmt (Discriminant_Constraint (T));
1993 while Present (D) loop
1994 if Denotes_Discriminant (Node (D)) then
1995 return Build_Component_Subtype
1996 (Build_Discriminal_Record_Constraint, Loc, T);
1997 end if;
1999 Next_Elmt (D);
2000 end loop;
2001 end if;
2003 -- If none of the above, the actual and nominal subtypes are the same
2005 return Empty;
2006 end Build_Discriminal_Subtype_Of_Component;
2008 ------------------------------
2009 -- Build_Elaboration_Entity --
2010 ------------------------------
2012 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
2013 Loc : constant Source_Ptr := Sloc (N);
2014 Decl : Node_Id;
2015 Elab_Ent : Entity_Id;
2017 procedure Set_Package_Name (Ent : Entity_Id);
2018 -- Given an entity, sets the fully qualified name of the entity in
2019 -- Name_Buffer, with components separated by double underscores. This
2020 -- is a recursive routine that climbs the scope chain to Standard.
2022 ----------------------
2023 -- Set_Package_Name --
2024 ----------------------
2026 procedure Set_Package_Name (Ent : Entity_Id) is
2027 begin
2028 if Scope (Ent) /= Standard_Standard then
2029 Set_Package_Name (Scope (Ent));
2031 declare
2032 Nam : constant String := Get_Name_String (Chars (Ent));
2033 begin
2034 Name_Buffer (Name_Len + 1) := '_';
2035 Name_Buffer (Name_Len + 2) := '_';
2036 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
2037 Name_Len := Name_Len + Nam'Length + 2;
2038 end;
2040 else
2041 Get_Name_String (Chars (Ent));
2042 end if;
2043 end Set_Package_Name;
2045 -- Start of processing for Build_Elaboration_Entity
2047 begin
2048 -- Ignore call if already constructed
2050 if Present (Elaboration_Entity (Spec_Id)) then
2051 return;
2053 -- Do not generate an elaboration entity in GNATprove move because the
2054 -- elaboration counter is a form of expansion.
2056 elsif GNATprove_Mode then
2057 return;
2059 -- See if we need elaboration entity
2061 -- We always need an elaboration entity when preserving control flow, as
2062 -- we want to remain explicit about the unit's elaboration order.
2064 elsif Opt.Suppress_Control_Flow_Optimizations then
2065 null;
2067 -- We always need an elaboration entity for the dynamic elaboration
2068 -- model, since it is needed to properly generate the PE exception for
2069 -- access before elaboration.
2071 elsif Dynamic_Elaboration_Checks then
2072 null;
2074 -- For the static model, we don't need the elaboration counter if this
2075 -- unit is sure to have no elaboration code, since that means there
2076 -- is no elaboration unit to be called. Note that we can't just decide
2077 -- after the fact by looking to see whether there was elaboration code,
2078 -- because that's too late to make this decision.
2080 elsif Restriction_Active (No_Elaboration_Code) then
2081 return;
2083 -- Similarly, for the static model, we can skip the elaboration counter
2084 -- if we have the No_Multiple_Elaboration restriction, since for the
2085 -- static model, that's the only purpose of the counter (to avoid
2086 -- multiple elaboration).
2088 elsif Restriction_Active (No_Multiple_Elaboration) then
2089 return;
2090 end if;
2092 -- Here we need the elaboration entity
2094 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
2095 -- name with dots replaced by double underscore. We have to manually
2096 -- construct this name, since it will be elaborated in the outer scope,
2097 -- and thus will not have the unit name automatically prepended.
2099 Set_Package_Name (Spec_Id);
2100 Add_Str_To_Name_Buffer ("_E");
2102 -- Create elaboration counter
2104 Elab_Ent := Make_Defining_Identifier (Loc, Chars => Name_Find);
2105 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
2107 Decl :=
2108 Make_Object_Declaration (Loc,
2109 Defining_Identifier => Elab_Ent,
2110 Object_Definition =>
2111 New_Occurrence_Of (Standard_Short_Integer, Loc),
2112 Expression => Make_Integer_Literal (Loc, Uint_0));
2114 Push_Scope (Standard_Standard);
2115 Add_Global_Declaration (Decl);
2116 Pop_Scope;
2118 -- Reset True_Constant indication, since we will indeed assign a value
2119 -- to the variable in the binder main. We also kill the Current_Value
2120 -- and Last_Assignment fields for the same reason.
2122 Set_Is_True_Constant (Elab_Ent, False);
2123 Set_Current_Value (Elab_Ent, Empty);
2124 Set_Last_Assignment (Elab_Ent, Empty);
2126 -- We do not want any further qualification of the name (if we did not
2127 -- do this, we would pick up the name of the generic package in the case
2128 -- of a library level generic instantiation).
2130 Set_Has_Qualified_Name (Elab_Ent);
2131 Set_Has_Fully_Qualified_Name (Elab_Ent);
2132 end Build_Elaboration_Entity;
2134 --------------------------------
2135 -- Build_Explicit_Dereference --
2136 --------------------------------
2138 procedure Build_Explicit_Dereference
2139 (Expr : Node_Id;
2140 Disc : Entity_Id)
2142 Loc : constant Source_Ptr := Sloc (Expr);
2143 I : Interp_Index;
2144 It : Interp;
2146 begin
2147 -- An entity of a type with a reference aspect is overloaded with
2148 -- both interpretations: with and without the dereference. Now that
2149 -- the dereference is made explicit, set the type of the node properly,
2150 -- to prevent anomalies in the backend. Same if the expression is an
2151 -- overloaded function call whose return type has a reference aspect.
2153 if Is_Entity_Name (Expr) then
2154 Set_Etype (Expr, Etype (Entity (Expr)));
2156 -- The designated entity will not be examined again when resolving
2157 -- the dereference, so generate a reference to it now.
2159 Generate_Reference (Entity (Expr), Expr);
2161 elsif Nkind (Expr) = N_Function_Call then
2163 -- If the name of the indexing function is overloaded, locate the one
2164 -- whose return type has an implicit dereference on the desired
2165 -- discriminant, and set entity and type of function call.
2167 if Is_Overloaded (Name (Expr)) then
2168 Get_First_Interp (Name (Expr), I, It);
2170 while Present (It.Nam) loop
2171 if Ekind ((It.Typ)) = E_Record_Type
2172 and then First_Entity ((It.Typ)) = Disc
2173 then
2174 Set_Entity (Name (Expr), It.Nam);
2175 Set_Etype (Name (Expr), Etype (It.Nam));
2176 exit;
2177 end if;
2179 Get_Next_Interp (I, It);
2180 end loop;
2181 end if;
2183 -- Set type of call from resolved function name.
2185 Set_Etype (Expr, Etype (Name (Expr)));
2186 end if;
2188 Set_Is_Overloaded (Expr, False);
2190 -- The expression will often be a generalized indexing that yields a
2191 -- container element that is then dereferenced, in which case the
2192 -- generalized indexing call is also non-overloaded.
2194 if Nkind (Expr) = N_Indexed_Component
2195 and then Present (Generalized_Indexing (Expr))
2196 then
2197 Set_Is_Overloaded (Generalized_Indexing (Expr), False);
2198 end if;
2200 Rewrite (Expr,
2201 Make_Explicit_Dereference (Loc,
2202 Prefix =>
2203 Make_Selected_Component (Loc,
2204 Prefix => Relocate_Node (Expr),
2205 Selector_Name => New_Occurrence_Of (Disc, Loc))));
2206 Set_Etype (Prefix (Expr), Etype (Disc));
2207 Set_Etype (Expr, Designated_Type (Etype (Disc)));
2208 end Build_Explicit_Dereference;
2210 ---------------------------
2211 -- Build_Overriding_Spec --
2212 ---------------------------
2214 function Build_Overriding_Spec
2215 (Op : Entity_Id;
2216 Typ : Entity_Id) return Node_Id
2218 Loc : constant Source_Ptr := Sloc (Typ);
2219 Par_Typ : constant Entity_Id := Find_Dispatching_Type (Op);
2220 Spec : constant Node_Id := Specification (Unit_Declaration_Node (Op));
2222 Formal_Spec : Node_Id;
2223 Formal_Type : Node_Id;
2224 New_Spec : Node_Id;
2226 begin
2227 New_Spec := Copy_Subprogram_Spec (Spec);
2229 Formal_Spec := First (Parameter_Specifications (New_Spec));
2230 while Present (Formal_Spec) loop
2231 Formal_Type := Parameter_Type (Formal_Spec);
2233 if Is_Entity_Name (Formal_Type)
2234 and then Entity (Formal_Type) = Par_Typ
2235 then
2236 Rewrite (Formal_Type, New_Occurrence_Of (Typ, Loc));
2237 end if;
2239 -- Nothing needs to be done for access parameters
2241 Next (Formal_Spec);
2242 end loop;
2244 return New_Spec;
2245 end Build_Overriding_Spec;
2247 -------------------
2248 -- Build_Subtype --
2249 -------------------
2251 function Build_Subtype
2252 (Related_Node : Node_Id;
2253 Loc : Source_Ptr;
2254 Typ : Entity_Id;
2255 Constraints : List_Id)
2256 return Entity_Id
2258 Indic : Node_Id;
2259 Subtyp_Decl : Node_Id;
2260 Def_Id : Entity_Id;
2261 Btyp : Entity_Id := Base_Type (Typ);
2263 begin
2264 -- The Related_Node better be here or else we won't be able to
2265 -- attach new itypes to a node in the tree.
2267 pragma Assert (Present (Related_Node));
2269 -- If the view of the component's type is incomplete or private
2270 -- with unknown discriminants, then the constraint must be applied
2271 -- to the full type.
2273 if Has_Unknown_Discriminants (Btyp)
2274 and then Present (Underlying_Type (Btyp))
2275 then
2276 Btyp := Underlying_Type (Btyp);
2277 end if;
2279 Indic :=
2280 Make_Subtype_Indication (Loc,
2281 Subtype_Mark => New_Occurrence_Of (Btyp, Loc),
2282 Constraint =>
2283 Make_Index_Or_Discriminant_Constraint (Loc, Constraints));
2285 Def_Id := Create_Itype (Ekind (Typ), Related_Node);
2287 Subtyp_Decl :=
2288 Make_Subtype_Declaration (Loc,
2289 Defining_Identifier => Def_Id,
2290 Subtype_Indication => Indic);
2292 Set_Parent (Subtyp_Decl, Parent (Related_Node));
2294 -- Itypes must be analyzed with checks off (see package Itypes)
2296 Analyze (Subtyp_Decl, Suppress => All_Checks);
2298 if Is_Itype (Def_Id) and then Has_Predicates (Typ) then
2299 Inherit_Predicate_Flags (Def_Id, Typ);
2301 -- Indicate where the predicate function may be found
2303 if Is_Itype (Typ) then
2304 if Present (Predicate_Function (Def_Id)) then
2305 null;
2307 elsif Present (Predicate_Function (Typ)) then
2308 Set_Predicate_Function (Def_Id, Predicate_Function (Typ));
2310 else
2311 Set_Predicated_Parent (Def_Id, Predicated_Parent (Typ));
2312 end if;
2314 elsif No (Predicate_Function (Def_Id)) then
2315 Set_Predicated_Parent (Def_Id, Typ);
2316 end if;
2317 end if;
2319 return Def_Id;
2320 end Build_Subtype;
2322 -----------------------------------
2323 -- Cannot_Raise_Constraint_Error --
2324 -----------------------------------
2326 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
2328 function List_Cannot_Raise_CE (L : List_Id) return Boolean;
2329 -- Returns True if none of the list members cannot possibly raise
2330 -- Constraint_Error.
2332 --------------------------
2333 -- List_Cannot_Raise_CE --
2334 --------------------------
2336 function List_Cannot_Raise_CE (L : List_Id) return Boolean is
2337 N : Node_Id;
2338 begin
2339 N := First (L);
2340 while Present (N) loop
2341 if Cannot_Raise_Constraint_Error (N) then
2342 Next (N);
2343 else
2344 return False;
2345 end if;
2346 end loop;
2348 return True;
2349 end List_Cannot_Raise_CE;
2351 -- Start of processing for Cannot_Raise_Constraint_Error
2353 begin
2354 if Compile_Time_Known_Value (Expr) then
2355 return True;
2357 elsif Do_Range_Check (Expr) then
2358 return False;
2360 elsif Raises_Constraint_Error (Expr) then
2361 return False;
2363 else
2364 case Nkind (Expr) is
2365 when N_Identifier =>
2366 return True;
2368 when N_Expanded_Name =>
2369 return True;
2371 when N_Indexed_Component =>
2372 return not Do_Range_Check (Expr)
2373 and then Cannot_Raise_Constraint_Error (Prefix (Expr))
2374 and then List_Cannot_Raise_CE (Expressions (Expr));
2376 when N_Selected_Component =>
2377 return not Do_Discriminant_Check (Expr)
2378 and then Cannot_Raise_Constraint_Error (Prefix (Expr));
2380 when N_Attribute_Reference =>
2381 if Do_Overflow_Check (Expr) then
2382 return False;
2384 elsif No (Expressions (Expr)) then
2385 return True;
2387 else
2388 return List_Cannot_Raise_CE (Expressions (Expr));
2389 end if;
2391 when N_Type_Conversion =>
2392 if Do_Overflow_Check (Expr)
2393 or else Do_Length_Check (Expr)
2394 then
2395 return False;
2396 else
2397 return Cannot_Raise_Constraint_Error (Expression (Expr));
2398 end if;
2400 when N_Unchecked_Type_Conversion =>
2401 return Cannot_Raise_Constraint_Error (Expression (Expr));
2403 when N_Unary_Op =>
2404 if Do_Overflow_Check (Expr) then
2405 return False;
2406 else
2407 return Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
2408 end if;
2410 when N_Op_Divide
2411 | N_Op_Mod
2412 | N_Op_Rem
2414 if Do_Division_Check (Expr)
2415 or else
2416 Do_Overflow_Check (Expr)
2417 then
2418 return False;
2419 else
2420 return
2421 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
2422 and then
2423 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
2424 end if;
2426 when N_Op_Add
2427 | N_Op_And
2428 | N_Op_Concat
2429 | N_Op_Eq
2430 | N_Op_Expon
2431 | N_Op_Ge
2432 | N_Op_Gt
2433 | N_Op_Le
2434 | N_Op_Lt
2435 | N_Op_Multiply
2436 | N_Op_Ne
2437 | N_Op_Or
2438 | N_Op_Rotate_Left
2439 | N_Op_Rotate_Right
2440 | N_Op_Shift_Left
2441 | N_Op_Shift_Right
2442 | N_Op_Shift_Right_Arithmetic
2443 | N_Op_Subtract
2444 | N_Op_Xor
2446 if Do_Overflow_Check (Expr) then
2447 return False;
2448 else
2449 return
2450 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
2451 and then
2452 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
2453 end if;
2455 when others =>
2456 return False;
2457 end case;
2458 end if;
2459 end Cannot_Raise_Constraint_Error;
2461 -------------------------------
2462 -- Check_Ambiguous_Aggregate --
2463 -------------------------------
2465 procedure Check_Ambiguous_Aggregate (Call : Node_Id) is
2466 Actual : Node_Id;
2468 begin
2469 if All_Extensions_Allowed then
2470 Actual := First_Actual (Call);
2471 while Present (Actual) loop
2472 if Nkind (Actual) = N_Aggregate then
2473 Error_Msg_N
2474 ("\add type qualification to aggregate actual", Actual);
2475 exit;
2476 end if;
2477 Next_Actual (Actual);
2478 end loop;
2479 end if;
2480 end Check_Ambiguous_Aggregate;
2482 -----------------------------------------
2483 -- Check_Dynamically_Tagged_Expression --
2484 -----------------------------------------
2486 procedure Check_Dynamically_Tagged_Expression
2487 (Expr : Node_Id;
2488 Typ : Entity_Id;
2489 Related_Nod : Node_Id)
2491 begin
2492 pragma Assert (Is_Tagged_Type (Typ));
2494 -- In order to avoid spurious errors when analyzing the expanded code,
2495 -- this check is done only for nodes that come from source and for
2496 -- actuals of generic instantiations.
2498 if (Comes_From_Source (Related_Nod)
2499 or else In_Generic_Actual (Expr))
2500 and then (Is_Class_Wide_Type (Etype (Expr))
2501 or else Is_Dynamically_Tagged (Expr))
2502 and then not Is_Class_Wide_Type (Typ)
2503 then
2504 Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
2505 end if;
2506 end Check_Dynamically_Tagged_Expression;
2508 --------------------------
2509 -- Check_Fully_Declared --
2510 --------------------------
2512 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
2513 begin
2514 if Ekind (T) = E_Incomplete_Type then
2516 -- Ada 2005 (AI-50217): If the type is available through a limited
2517 -- with_clause, verify that its full view has been analyzed.
2519 if From_Limited_With (T)
2520 and then Present (Non_Limited_View (T))
2521 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
2522 then
2523 -- The non-limited view is fully declared
2525 null;
2527 else
2528 Error_Msg_NE
2529 ("premature usage of incomplete}", N, First_Subtype (T));
2530 end if;
2532 -- Need comments for these tests ???
2534 elsif Has_Private_Component (T)
2535 and then not Is_Generic_Type (Root_Type (T))
2536 and then not In_Spec_Expression
2537 then
2538 -- Special case: if T is the anonymous type created for a single
2539 -- task or protected object, use the name of the source object.
2541 if Is_Concurrent_Type (T)
2542 and then not Comes_From_Source (T)
2543 and then Nkind (N) = N_Object_Declaration
2544 then
2545 Error_Msg_NE
2546 ("type of& has incomplete component",
2547 N, Defining_Identifier (N));
2548 else
2549 Error_Msg_NE
2550 ("premature usage of incomplete}",
2551 N, First_Subtype (T));
2552 end if;
2553 end if;
2554 end Check_Fully_Declared;
2556 -------------------------------------------
2557 -- Check_Function_With_Address_Parameter --
2558 -------------------------------------------
2560 procedure Check_Function_With_Address_Parameter (Subp_Id : Entity_Id) is
2561 F : Entity_Id;
2562 T : Entity_Id;
2564 begin
2565 F := First_Formal (Subp_Id);
2566 while Present (F) loop
2567 T := Etype (F);
2569 if Is_Private_Type (T) and then Present (Full_View (T)) then
2570 T := Full_View (T);
2571 end if;
2573 if Is_Descendant_Of_Address (T) or else Is_Limited_Type (T) then
2574 Set_Is_Pure (Subp_Id, False);
2575 exit;
2576 end if;
2578 Next_Formal (F);
2579 end loop;
2580 end Check_Function_With_Address_Parameter;
2582 -------------------------------------
2583 -- Check_Function_Writable_Actuals --
2584 -------------------------------------
2586 procedure Check_Function_Writable_Actuals (N : Node_Id) is
2587 Writable_Actuals_List : Elist_Id := No_Elist;
2588 Identifiers_List : Elist_Id := No_Elist;
2589 Aggr_Error_Node : Node_Id := Empty;
2590 Error_Node : Node_Id := Empty;
2592 procedure Collect_Identifiers (N : Node_Id);
2593 -- In a single traversal of subtree N collect in Writable_Actuals_List
2594 -- all the actuals of functions with writable actuals, and in the list
2595 -- Identifiers_List collect all the identifiers that are not actuals of
2596 -- functions with writable actuals. If a writable actual is referenced
2597 -- twice as writable actual then Error_Node is set to reference its
2598 -- second occurrence, the error is reported, and the tree traversal
2599 -- is abandoned.
2601 -------------------------
2602 -- Collect_Identifiers --
2603 -------------------------
2605 procedure Collect_Identifiers (N : Node_Id) is
2607 function Check_Node (N : Node_Id) return Traverse_Result;
2608 -- Process a single node during the tree traversal to collect the
2609 -- writable actuals of functions and all the identifiers which are
2610 -- not writable actuals of functions.
2612 function Contains (List : Elist_Id; N : Node_Id) return Boolean;
2613 -- Returns True if List has a node whose Entity is Entity (N)
2615 ----------------
2616 -- Check_Node --
2617 ----------------
2619 function Check_Node (N : Node_Id) return Traverse_Result is
2620 Is_Writable_Actual : Boolean := False;
2621 Id : Entity_Id;
2623 begin
2624 if Nkind (N) = N_Identifier then
2626 -- No analysis possible if the entity is not decorated
2628 if No (Entity (N)) then
2629 return Skip;
2631 -- Don't collect identifiers of packages, called functions, etc
2633 elsif Ekind (Entity (N)) in
2634 E_Package | E_Function | E_Procedure | E_Entry
2635 then
2636 return Skip;
2638 -- For rewritten nodes, continue the traversal in the original
2639 -- subtree. Needed to handle aggregates in original expressions
2640 -- extracted from the tree by Remove_Side_Effects.
2642 elsif Is_Rewrite_Substitution (N) then
2643 Collect_Identifiers (Original_Node (N));
2644 return Skip;
2646 -- For now we skip aggregate discriminants, since they require
2647 -- performing the analysis in two phases to identify conflicts:
2648 -- first one analyzing discriminants and second one analyzing
2649 -- the rest of components (since at run time, discriminants are
2650 -- evaluated prior to components): too much computation cost
2651 -- to identify a corner case???
2653 elsif Nkind (Parent (N)) = N_Component_Association
2654 and then Nkind (Parent (Parent (N))) in
2655 N_Aggregate | N_Extension_Aggregate
2656 then
2657 declare
2658 Choice : constant Node_Id := First (Choices (Parent (N)));
2660 begin
2661 if Ekind (Entity (N)) = E_Discriminant then
2662 return Skip;
2664 elsif Expression (Parent (N)) = N
2665 and then Nkind (Choice) = N_Identifier
2666 and then Ekind (Entity (Choice)) = E_Discriminant
2667 then
2668 return Skip;
2669 end if;
2670 end;
2672 -- Analyze if N is a writable actual of a function
2674 elsif Nkind (Parent (N)) = N_Function_Call then
2675 declare
2676 Call : constant Node_Id := Parent (N);
2677 Actual : Node_Id;
2678 Formal : Node_Id;
2680 begin
2681 Id := Get_Called_Entity (Call);
2683 -- In case of previous error, no check is possible
2685 if No (Id) then
2686 return Abandon;
2687 end if;
2689 if Ekind (Id) in E_Function | E_Generic_Function
2690 and then Has_Out_Or_In_Out_Parameter (Id)
2691 then
2692 Formal := First_Formal (Id);
2693 Actual := First_Actual (Call);
2694 while Present (Actual) and then Present (Formal) loop
2695 if Actual = N then
2696 if Ekind (Formal) in E_Out_Parameter
2697 | E_In_Out_Parameter
2698 then
2699 Is_Writable_Actual := True;
2700 end if;
2702 exit;
2703 end if;
2705 Next_Formal (Formal);
2706 Next_Actual (Actual);
2707 end loop;
2708 end if;
2709 end;
2710 end if;
2712 if Is_Writable_Actual then
2714 -- Skip checking the error in non-elementary types since
2715 -- RM 6.4.1(6.15/3) is restricted to elementary types, but
2716 -- store this actual in Writable_Actuals_List since it is
2717 -- needed to perform checks on other constructs that have
2718 -- arbitrary order of evaluation (for example, aggregates).
2720 if not Is_Elementary_Type (Etype (N)) then
2721 if not Contains (Writable_Actuals_List, N) then
2722 Append_New_Elmt (N, To => Writable_Actuals_List);
2723 end if;
2725 -- Second occurrence of an elementary type writable actual
2727 elsif Contains (Writable_Actuals_List, N) then
2729 -- Report the error on the second occurrence of the
2730 -- identifier. We cannot assume that N is the second
2731 -- occurrence (according to their location in the
2732 -- sources), since Traverse_Func walks through Field2
2733 -- last (see comment in the body of Traverse_Func).
2735 declare
2736 Elmt : Elmt_Id;
2738 begin
2739 Elmt := First_Elmt (Writable_Actuals_List);
2740 while Present (Elmt)
2741 and then Entity (Node (Elmt)) /= Entity (N)
2742 loop
2743 Next_Elmt (Elmt);
2744 end loop;
2746 if Sloc (N) > Sloc (Node (Elmt)) then
2747 Error_Node := N;
2748 else
2749 Error_Node := Node (Elmt);
2750 end if;
2752 Error_Msg_NE
2753 ("value may be affected by call to & "
2754 & "because order of evaluation is arbitrary",
2755 Error_Node, Id);
2756 return Abandon;
2757 end;
2759 -- First occurrence of a elementary type writable actual
2761 else
2762 Append_New_Elmt (N, To => Writable_Actuals_List);
2763 end if;
2765 else
2766 if No (Identifiers_List) then
2767 Identifiers_List := New_Elmt_List;
2768 end if;
2770 Append_Unique_Elmt (N, Identifiers_List);
2771 end if;
2772 end if;
2774 return OK;
2775 end Check_Node;
2777 --------------
2778 -- Contains --
2779 --------------
2781 function Contains
2782 (List : Elist_Id;
2783 N : Node_Id) return Boolean
2785 pragma Assert (Nkind (N) in N_Has_Entity);
2787 Elmt : Elmt_Id;
2789 begin
2790 if No (List) then
2791 return False;
2792 end if;
2794 Elmt := First_Elmt (List);
2795 while Present (Elmt) loop
2796 if Entity (Node (Elmt)) = Entity (N) then
2797 return True;
2798 else
2799 Next_Elmt (Elmt);
2800 end if;
2801 end loop;
2803 return False;
2804 end Contains;
2806 ------------------
2807 -- Do_Traversal --
2808 ------------------
2810 procedure Do_Traversal is new Traverse_Proc (Check_Node);
2811 -- The traversal procedure
2813 -- Start of processing for Collect_Identifiers
2815 begin
2816 if Present (Error_Node) then
2817 return;
2818 end if;
2820 if Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then
2821 return;
2822 end if;
2824 Do_Traversal (N);
2825 end Collect_Identifiers;
2827 -- Start of processing for Check_Function_Writable_Actuals
2829 begin
2830 -- The check only applies to Ada 2012 code on which Check_Actuals has
2831 -- been set, and only to constructs that have multiple constituents
2832 -- whose order of evaluation is not specified by the language.
2834 if Ada_Version < Ada_2012
2835 or else not Check_Actuals (N)
2836 or else Nkind (N) not in N_Op
2837 | N_Membership_Test
2838 | N_Range
2839 | N_Aggregate
2840 | N_Extension_Aggregate
2841 | N_Full_Type_Declaration
2842 | N_Function_Call
2843 | N_Procedure_Call_Statement
2844 | N_Entry_Call_Statement
2845 or else (Nkind (N) = N_Full_Type_Declaration
2846 and then not Is_Record_Type (Defining_Identifier (N)))
2848 -- In addition, this check only applies to source code, not to code
2849 -- generated by constraint checks.
2851 or else not Comes_From_Source (N)
2852 then
2853 return;
2854 end if;
2856 -- If a construct C has two or more direct constituents that are names
2857 -- or expressions whose evaluation may occur in an arbitrary order, at
2858 -- least one of which contains a function call with an in out or out
2859 -- parameter, then the construct is legal only if: for each name N that
2860 -- is passed as a parameter of mode in out or out to some inner function
2861 -- call C2 (not including the construct C itself), there is no other
2862 -- name anywhere within a direct constituent of the construct C other
2863 -- than the one containing C2, that is known to refer to the same
2864 -- object (RM 6.4.1(6.17/3)).
2866 case Nkind (N) is
2867 when N_Range =>
2868 Collect_Identifiers (Low_Bound (N));
2869 Collect_Identifiers (High_Bound (N));
2871 when N_Membership_Test
2872 | N_Op
2874 declare
2875 Expr : Node_Id;
2877 begin
2878 Collect_Identifiers (Left_Opnd (N));
2880 if Present (Right_Opnd (N)) then
2881 Collect_Identifiers (Right_Opnd (N));
2882 end if;
2884 if Nkind (N) in N_In | N_Not_In
2885 and then Present (Alternatives (N))
2886 then
2887 Expr := First (Alternatives (N));
2888 while Present (Expr) loop
2889 Collect_Identifiers (Expr);
2891 Next (Expr);
2892 end loop;
2893 end if;
2894 end;
2896 when N_Full_Type_Declaration =>
2897 declare
2898 function Get_Record_Part (N : Node_Id) return Node_Id;
2899 -- Return the record part of this record type definition
2901 function Get_Record_Part (N : Node_Id) return Node_Id is
2902 Type_Def : constant Node_Id := Type_Definition (N);
2903 begin
2904 if Nkind (Type_Def) = N_Derived_Type_Definition then
2905 return Record_Extension_Part (Type_Def);
2906 else
2907 return Type_Def;
2908 end if;
2909 end Get_Record_Part;
2911 Comp : Node_Id;
2912 Def_Id : Entity_Id := Defining_Identifier (N);
2913 Rec : Node_Id := Get_Record_Part (N);
2915 begin
2916 -- No need to perform any analysis if the record has no
2917 -- components
2919 if No (Rec) or else No (Component_List (Rec)) then
2920 return;
2921 end if;
2923 -- Collect the identifiers starting from the deepest
2924 -- derivation. Done to report the error in the deepest
2925 -- derivation.
2927 loop
2928 if Present (Component_List (Rec)) then
2929 Comp := First (Component_Items (Component_List (Rec)));
2930 while Present (Comp) loop
2931 if Nkind (Comp) = N_Component_Declaration
2932 and then Present (Expression (Comp))
2933 then
2934 Collect_Identifiers (Expression (Comp));
2935 end if;
2937 Next (Comp);
2938 end loop;
2939 end if;
2941 exit when No (Underlying_Type (Etype (Def_Id)))
2942 or else Base_Type (Underlying_Type (Etype (Def_Id)))
2943 = Def_Id;
2945 Def_Id := Base_Type (Underlying_Type (Etype (Def_Id)));
2946 Rec := Get_Record_Part (Parent (Def_Id));
2947 end loop;
2948 end;
2950 when N_Entry_Call_Statement
2951 | N_Subprogram_Call
2953 declare
2954 Id : constant Entity_Id := Get_Called_Entity (N);
2955 Formal : Node_Id;
2956 Actual : Node_Id;
2958 begin
2959 Formal := First_Formal (Id);
2960 Actual := First_Actual (N);
2961 while Present (Actual) and then Present (Formal) loop
2962 if Ekind (Formal) in E_Out_Parameter | E_In_Out_Parameter
2963 then
2964 Collect_Identifiers (Actual);
2965 end if;
2967 Next_Formal (Formal);
2968 Next_Actual (Actual);
2969 end loop;
2970 end;
2972 when N_Aggregate
2973 | N_Extension_Aggregate
2975 declare
2976 Assoc : Node_Id;
2977 Choice : Node_Id;
2978 Comp_Expr : Node_Id;
2980 begin
2981 -- Handle the N_Others_Choice of array aggregates with static
2982 -- bounds. There is no need to perform this analysis in
2983 -- aggregates without static bounds since we cannot evaluate
2984 -- if the N_Others_Choice covers several elements. There is
2985 -- no need to handle the N_Others choice of record aggregates
2986 -- since at this stage it has been already expanded by
2987 -- Resolve_Record_Aggregate.
2989 if Is_Array_Type (Etype (N))
2990 and then Nkind (N) = N_Aggregate
2991 and then Present (Aggregate_Bounds (N))
2992 and then Compile_Time_Known_Bounds (Etype (N))
2993 and then Expr_Value (High_Bound (Aggregate_Bounds (N)))
2995 Expr_Value (Low_Bound (Aggregate_Bounds (N)))
2996 then
2997 declare
2998 Count_Components : Uint := Uint_0;
2999 Num_Components : Uint;
3000 Others_Assoc : Node_Id := Empty;
3001 Others_Choice : Node_Id := Empty;
3002 Others_Box_Present : Boolean := False;
3004 begin
3005 -- Count positional associations
3007 if Present (Expressions (N)) then
3008 Comp_Expr := First (Expressions (N));
3009 while Present (Comp_Expr) loop
3010 Count_Components := Count_Components + 1;
3011 Next (Comp_Expr);
3012 end loop;
3013 end if;
3015 -- Count the rest of elements and locate the N_Others
3016 -- choice (if any)
3018 Assoc := First (Component_Associations (N));
3019 while Present (Assoc) loop
3020 Choice := First (Choices (Assoc));
3021 while Present (Choice) loop
3022 if Nkind (Choice) = N_Others_Choice then
3023 Others_Assoc := Assoc;
3024 Others_Choice := Choice;
3025 Others_Box_Present := Box_Present (Assoc);
3027 -- Count several components
3029 elsif Nkind (Choice) in
3030 N_Range | N_Subtype_Indication
3031 or else (Is_Entity_Name (Choice)
3032 and then Is_Type (Entity (Choice)))
3033 then
3034 declare
3035 L, H : Node_Id;
3036 begin
3037 Get_Index_Bounds (Choice, L, H);
3038 pragma Assert
3039 (Compile_Time_Known_Value (L)
3040 and then Compile_Time_Known_Value (H));
3041 Count_Components :=
3042 Count_Components
3043 + Expr_Value (H) - Expr_Value (L) + 1;
3044 end;
3046 -- Count single component. No other case available
3047 -- since we are handling an aggregate with static
3048 -- bounds.
3050 else
3051 pragma Assert (Is_OK_Static_Expression (Choice)
3052 or else Nkind (Choice) = N_Identifier
3053 or else Nkind (Choice) = N_Integer_Literal);
3055 Count_Components := Count_Components + 1;
3056 end if;
3058 Next (Choice);
3059 end loop;
3061 Next (Assoc);
3062 end loop;
3064 Num_Components :=
3065 Expr_Value (High_Bound (Aggregate_Bounds (N))) -
3066 Expr_Value (Low_Bound (Aggregate_Bounds (N))) + 1;
3068 pragma Assert (Count_Components <= Num_Components);
3070 -- Handle the N_Others choice if it covers several
3071 -- components
3073 if Present (Others_Choice)
3074 and then (Num_Components - Count_Components) > 1
3075 then
3076 if not Others_Box_Present then
3078 -- At this stage, if expansion is active, the
3079 -- expression of the others choice has not been
3080 -- analyzed. Hence we generate a duplicate and
3081 -- we analyze it silently to have available the
3082 -- minimum decoration required to collect the
3083 -- identifiers.
3085 pragma Assert (Present (Others_Assoc));
3087 if not Expander_Active then
3088 Comp_Expr := Expression (Others_Assoc);
3089 else
3090 Comp_Expr :=
3091 New_Copy_Tree (Expression (Others_Assoc));
3092 Preanalyze_Without_Errors (Comp_Expr);
3093 end if;
3095 Collect_Identifiers (Comp_Expr);
3097 if Present (Writable_Actuals_List) then
3099 -- As suggested by Robert, at current stage we
3100 -- report occurrences of this case as warnings.
3102 Error_Msg_N
3103 ("writable function parameter may affect "
3104 & "value in other component because order "
3105 & "of evaluation is unspecified??",
3106 Node (First_Elmt (Writable_Actuals_List)));
3107 end if;
3108 end if;
3109 end if;
3110 end;
3112 -- For an array aggregate, a discrete_choice_list that has
3113 -- a nonstatic range is considered as two or more separate
3114 -- occurrences of the expression (RM 6.4.1(20/3)).
3116 elsif Is_Array_Type (Etype (N))
3117 and then Nkind (N) = N_Aggregate
3118 and then Present (Aggregate_Bounds (N))
3119 and then not Compile_Time_Known_Bounds (Etype (N))
3120 then
3121 -- Collect identifiers found in the dynamic bounds
3123 declare
3124 Count_Components : Natural := 0;
3125 Low, High : Node_Id;
3127 begin
3128 Assoc := First (Component_Associations (N));
3129 while Present (Assoc) loop
3130 Choice := First (Choices (Assoc));
3131 while Present (Choice) loop
3132 if Nkind (Choice) in
3133 N_Range | N_Subtype_Indication
3134 or else (Is_Entity_Name (Choice)
3135 and then Is_Type (Entity (Choice)))
3136 then
3137 Get_Index_Bounds (Choice, Low, High);
3139 if not Compile_Time_Known_Value (Low) then
3140 Collect_Identifiers (Low);
3142 if No (Aggr_Error_Node) then
3143 Aggr_Error_Node := Low;
3144 end if;
3145 end if;
3147 if not Compile_Time_Known_Value (High) then
3148 Collect_Identifiers (High);
3150 if No (Aggr_Error_Node) then
3151 Aggr_Error_Node := High;
3152 end if;
3153 end if;
3155 -- The RM rule is violated if there is more than
3156 -- a single choice in a component association.
3158 else
3159 Count_Components := Count_Components + 1;
3161 if No (Aggr_Error_Node)
3162 and then Count_Components > 1
3163 then
3164 Aggr_Error_Node := Choice;
3165 end if;
3167 if not Compile_Time_Known_Value (Choice) then
3168 Collect_Identifiers (Choice);
3169 end if;
3170 end if;
3172 Next (Choice);
3173 end loop;
3175 Next (Assoc);
3176 end loop;
3177 end;
3178 end if;
3180 -- Handle ancestor part of extension aggregates
3182 if Nkind (N) = N_Extension_Aggregate then
3183 Collect_Identifiers (Ancestor_Part (N));
3184 end if;
3186 -- Handle positional associations
3188 if Present (Expressions (N)) then
3189 Comp_Expr := First (Expressions (N));
3190 while Present (Comp_Expr) loop
3191 if not Is_OK_Static_Expression (Comp_Expr) then
3192 Collect_Identifiers (Comp_Expr);
3193 end if;
3195 Next (Comp_Expr);
3196 end loop;
3197 end if;
3199 -- Handle discrete associations
3201 if Present (Component_Associations (N)) then
3202 Assoc := First (Component_Associations (N));
3203 while Present (Assoc) loop
3205 if not Box_Present (Assoc) then
3206 Choice := First (Choices (Assoc));
3207 while Present (Choice) loop
3209 -- For now we skip discriminants since it requires
3210 -- performing the analysis in two phases: first one
3211 -- analyzing discriminants and second one analyzing
3212 -- the rest of components since discriminants are
3213 -- evaluated prior to components: too much extra
3214 -- work to detect a corner case???
3216 if Nkind (Choice) in N_Has_Entity
3217 and then Present (Entity (Choice))
3218 and then Ekind (Entity (Choice)) = E_Discriminant
3219 then
3220 null;
3222 elsif Box_Present (Assoc) then
3223 null;
3225 else
3226 if not Analyzed (Expression (Assoc)) then
3227 Comp_Expr :=
3228 New_Copy_Tree (Expression (Assoc));
3229 Set_Parent (Comp_Expr, Parent (N));
3230 Preanalyze_Without_Errors (Comp_Expr);
3231 else
3232 Comp_Expr := Expression (Assoc);
3233 end if;
3235 Collect_Identifiers (Comp_Expr);
3236 end if;
3238 Next (Choice);
3239 end loop;
3240 end if;
3242 Next (Assoc);
3243 end loop;
3244 end if;
3245 end;
3247 when others =>
3248 return;
3249 end case;
3251 -- No further action needed if we already reported an error
3253 if Present (Error_Node) then
3254 return;
3255 end if;
3257 -- Check violation of RM 6.20/3 in aggregates
3259 if Present (Aggr_Error_Node)
3260 and then Present (Writable_Actuals_List)
3261 then
3262 Error_Msg_N
3263 ("value may be affected by call in other component because they "
3264 & "are evaluated in unspecified order",
3265 Node (First_Elmt (Writable_Actuals_List)));
3266 return;
3267 end if;
3269 -- Check if some writable argument of a function is referenced
3271 if Present (Writable_Actuals_List)
3272 and then Present (Identifiers_List)
3273 then
3274 declare
3275 Elmt_1 : Elmt_Id;
3276 Elmt_2 : Elmt_Id;
3278 begin
3279 Elmt_1 := First_Elmt (Writable_Actuals_List);
3280 while Present (Elmt_1) loop
3281 Elmt_2 := First_Elmt (Identifiers_List);
3282 while Present (Elmt_2) loop
3283 if Entity (Node (Elmt_1)) = Entity (Node (Elmt_2)) then
3284 case Nkind (Parent (Node (Elmt_2))) is
3285 when N_Aggregate
3286 | N_Component_Association
3287 | N_Component_Declaration
3289 Error_Msg_N
3290 ("value may be affected by call in other "
3291 & "component because they are evaluated "
3292 & "in unspecified order",
3293 Node (Elmt_2));
3295 when N_In
3296 | N_Not_In
3298 Error_Msg_N
3299 ("value may be affected by call in other "
3300 & "alternative because they are evaluated "
3301 & "in unspecified order",
3302 Node (Elmt_2));
3304 when others =>
3305 Error_Msg_N
3306 ("value of actual may be affected by call in "
3307 & "other actual because they are evaluated "
3308 & "in unspecified order",
3309 Node (Elmt_2));
3310 end case;
3311 end if;
3313 Next_Elmt (Elmt_2);
3314 end loop;
3316 Next_Elmt (Elmt_1);
3317 end loop;
3318 end;
3319 end if;
3320 end Check_Function_Writable_Actuals;
3322 --------------------------------
3323 -- Check_Implicit_Dereference --
3324 --------------------------------
3326 procedure Check_Implicit_Dereference (N : Node_Id; Typ : Entity_Id) is
3327 Disc : Entity_Id;
3328 Desig : Entity_Id;
3329 Nam : Node_Id;
3331 begin
3332 if Nkind (N) = N_Indexed_Component
3333 and then Present (Generalized_Indexing (N))
3334 then
3335 Nam := Generalized_Indexing (N);
3336 else
3337 Nam := N;
3338 end if;
3340 if Ada_Version < Ada_2012
3341 or else not Has_Implicit_Dereference (Base_Type (Typ))
3342 then
3343 return;
3345 elsif not Comes_From_Source (N)
3346 and then Nkind (N) /= N_Indexed_Component
3347 then
3348 return;
3350 elsif Is_Entity_Name (Nam) and then Is_Type (Entity (Nam)) then
3351 null;
3353 else
3354 Disc := First_Discriminant (Typ);
3355 while Present (Disc) loop
3356 if Has_Implicit_Dereference (Disc) then
3357 Desig := Designated_Type (Etype (Disc));
3358 Add_One_Interp (Nam, Disc, Desig);
3360 -- If the node is a generalized indexing, add interpretation
3361 -- to that node as well, for subsequent resolution.
3363 if Nkind (N) = N_Indexed_Component then
3364 Add_One_Interp (N, Disc, Desig);
3365 end if;
3367 -- If the operation comes from a generic unit and the context
3368 -- is a selected component, the selector name may be global
3369 -- and set in the instance already. Remove the entity to
3370 -- force resolution of the selected component, and the
3371 -- generation of an explicit dereference if needed.
3373 if In_Instance
3374 and then Nkind (Parent (Nam)) = N_Selected_Component
3375 then
3376 Set_Entity (Selector_Name (Parent (Nam)), Empty);
3377 end if;
3379 exit;
3380 end if;
3382 Next_Discriminant (Disc);
3383 end loop;
3384 end if;
3385 end Check_Implicit_Dereference;
3387 ----------------------------------
3388 -- Check_Internal_Protected_Use --
3389 ----------------------------------
3391 procedure Check_Internal_Protected_Use (N : Node_Id; Nam : Entity_Id) is
3392 S : Entity_Id;
3393 Prot : Entity_Id;
3395 begin
3396 Prot := Empty;
3398 S := Current_Scope;
3399 while Present (S) loop
3400 if S = Standard_Standard then
3401 exit;
3403 elsif Ekind (S) = E_Function
3404 and then Ekind (Scope (S)) = E_Protected_Type
3405 then
3406 Prot := Scope (S);
3407 exit;
3408 end if;
3410 S := Scope (S);
3411 end loop;
3413 if Present (Prot)
3414 and then Scope (Nam) = Prot
3415 and then Ekind (Nam) /= E_Function
3416 then
3417 -- An indirect function call (e.g. a callback within a protected
3418 -- function body) is not statically illegal. If the access type is
3419 -- anonymous and is the type of an access parameter, the scope of Nam
3420 -- will be the protected type, but it is not a protected operation.
3422 if Ekind (Nam) = E_Subprogram_Type
3423 and then Nkind (Associated_Node_For_Itype (Nam)) =
3424 N_Function_Specification
3425 then
3426 null;
3428 elsif Nkind (N) = N_Subprogram_Renaming_Declaration then
3429 Error_Msg_N
3430 ("within protected function cannot use protected procedure in "
3431 & "renaming or as generic actual", N);
3433 elsif Nkind (N) = N_Attribute_Reference then
3434 Error_Msg_N
3435 ("within protected function cannot take access of protected "
3436 & "procedure", N);
3438 else
3439 Error_Msg_N
3440 ("within protected function, protected object is constant", N);
3441 Error_Msg_N
3442 ("\cannot call operation that may modify it", N);
3443 end if;
3444 end if;
3446 -- Verify that an internal call does not appear within a precondition
3447 -- of a protected operation. This implements AI12-0166.
3448 -- The precondition aspect has been rewritten as a pragma Precondition
3449 -- and we check whether the scope of the called subprogram is the same
3450 -- as that of the entity to which the aspect applies.
3452 if Convention (Nam) = Convention_Protected then
3453 declare
3454 P : Node_Id;
3456 begin
3457 P := Parent (N);
3458 while Present (P) loop
3459 if Nkind (P) = N_Pragma
3460 and then Chars (Pragma_Identifier (P)) = Name_Precondition
3461 and then From_Aspect_Specification (P)
3462 and then
3463 Scope (Entity (Corresponding_Aspect (P))) = Scope (Nam)
3464 then
3465 Error_Msg_N
3466 ("internal call cannot appear in precondition of "
3467 & "protected operation", N);
3468 return;
3470 elsif Nkind (P) = N_Pragma
3471 and then Chars (Pragma_Identifier (P)) = Name_Contract_Cases
3472 then
3473 -- Check whether call is in a case guard. It is legal in a
3474 -- consequence.
3476 P := N;
3477 while Present (P) loop
3478 if Nkind (Parent (P)) = N_Component_Association
3479 and then P /= Expression (Parent (P))
3480 then
3481 Error_Msg_N
3482 ("internal call cannot appear in case guard in a "
3483 & "contract case", N);
3484 end if;
3486 P := Parent (P);
3487 end loop;
3489 return;
3491 elsif Nkind (P) = N_Parameter_Specification
3492 and then Scope (Current_Scope) = Scope (Nam)
3493 and then Nkind (Parent (P)) in
3494 N_Entry_Declaration | N_Subprogram_Declaration
3495 then
3496 Error_Msg_N
3497 ("internal call cannot appear in default for formal of "
3498 & "protected operation", N);
3499 return;
3500 end if;
3502 P := Parent (P);
3503 end loop;
3504 end;
3505 end if;
3506 end Check_Internal_Protected_Use;
3508 ---------------------------------------
3509 -- Check_Later_Vs_Basic_Declarations --
3510 ---------------------------------------
3512 procedure Check_Later_Vs_Basic_Declarations
3513 (Decls : List_Id;
3514 During_Parsing : Boolean)
3516 Body_Sloc : Source_Ptr;
3517 Decl : Node_Id;
3519 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean;
3520 -- Return whether Decl is considered as a declarative item.
3521 -- When During_Parsing is True, the semantics of Ada 83 is followed.
3522 -- When During_Parsing is False, the semantics of SPARK is followed.
3524 -------------------------------
3525 -- Is_Later_Declarative_Item --
3526 -------------------------------
3528 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean is
3529 begin
3530 if Nkind (Decl) in N_Later_Decl_Item then
3531 return True;
3533 elsif Nkind (Decl) = N_Pragma then
3534 return True;
3536 elsif During_Parsing then
3537 return False;
3539 -- In SPARK, a package declaration is not considered as a later
3540 -- declarative item.
3542 elsif Nkind (Decl) = N_Package_Declaration then
3543 return False;
3545 -- In SPARK, a renaming is considered as a later declarative item
3547 elsif Nkind (Decl) in N_Renaming_Declaration then
3548 return True;
3550 else
3551 return False;
3552 end if;
3553 end Is_Later_Declarative_Item;
3555 -- Start of processing for Check_Later_Vs_Basic_Declarations
3557 begin
3558 Decl := First (Decls);
3560 -- Loop through sequence of basic declarative items
3562 Outer : while Present (Decl) loop
3563 if Nkind (Decl) not in
3564 N_Subprogram_Body | N_Package_Body | N_Task_Body
3565 and then Nkind (Decl) not in N_Body_Stub
3566 then
3567 Next (Decl);
3569 -- Once a body is encountered, we only allow later declarative
3570 -- items. The inner loop checks the rest of the list.
3572 else
3573 Body_Sloc := Sloc (Decl);
3575 Inner : while Present (Decl) loop
3576 if not Is_Later_Declarative_Item (Decl) then
3577 if During_Parsing then
3578 if Ada_Version = Ada_83 then
3579 Error_Msg_Sloc := Body_Sloc;
3580 Error_Msg_N
3581 ("(Ada 83) decl cannot appear after body#", Decl);
3582 end if;
3583 end if;
3584 end if;
3586 Next (Decl);
3587 end loop Inner;
3588 end if;
3589 end loop Outer;
3590 end Check_Later_Vs_Basic_Declarations;
3592 ---------------------------
3593 -- Check_No_Hidden_State --
3594 ---------------------------
3596 procedure Check_No_Hidden_State (Id : Entity_Id) is
3597 Context : Entity_Id := Empty;
3598 Not_Visible : Boolean := False;
3599 Scop : Entity_Id;
3601 begin
3602 pragma Assert (Ekind (Id) in E_Abstract_State | E_Variable);
3604 -- Nothing to do for internally-generated abstract states and variables
3605 -- because they do not represent the hidden state of the source unit.
3607 if not Comes_From_Source (Id) then
3608 return;
3609 end if;
3611 -- Find the proper context where the object or state appears
3613 Scop := Scope (Id);
3614 while Present (Scop) loop
3615 Context := Scop;
3617 -- Keep track of the context's visibility
3619 Not_Visible := Not_Visible or else In_Private_Part (Context);
3621 -- Prevent the search from going too far
3623 if Context = Standard_Standard then
3624 return;
3626 -- Objects and states that appear immediately within a subprogram or
3627 -- entry inside a construct nested within a subprogram do not
3628 -- introduce a hidden state. They behave as local variable
3629 -- declarations. The same is true for elaboration code inside a block
3630 -- or a task.
3632 elsif Is_Subprogram_Or_Entry (Context)
3633 or else Ekind (Context) in E_Block | E_Task_Type
3634 then
3635 return;
3636 end if;
3638 -- Stop the traversal when a package subject to a null abstract state
3639 -- has been found.
3641 if Is_Package_Or_Generic_Package (Context)
3642 and then Has_Null_Abstract_State (Context)
3643 then
3644 exit;
3645 end if;
3647 Scop := Scope (Scop);
3648 end loop;
3650 -- At this point we know that there is at least one package with a null
3651 -- abstract state in visibility. Emit an error message unconditionally
3652 -- if the entity being processed is a state because the placement of the
3653 -- related package is irrelevant. This is not the case for objects as
3654 -- the intermediate context matters.
3656 if Present (Context)
3657 and then (Ekind (Id) = E_Abstract_State or else Not_Visible)
3658 then
3659 Error_Msg_N ("cannot introduce hidden state &", Id);
3660 Error_Msg_NE ("\package & has null abstract state", Id, Context);
3661 end if;
3662 end Check_No_Hidden_State;
3664 ---------------------------------------------
3665 -- Check_Nonoverridable_Aspect_Consistency --
3666 ---------------------------------------------
3668 procedure Check_Inherited_Nonoverridable_Aspects
3669 (Inheritor : Entity_Id;
3670 Interface_List : List_Id;
3671 Parent_Type : Entity_Id) is
3673 -- array needed for iterating over subtype values
3674 Nonoverridable_Aspects : constant array (Positive range <>) of
3675 Nonoverridable_Aspect_Id :=
3676 (Aspect_Default_Iterator,
3677 Aspect_Iterator_Element,
3678 Aspect_Implicit_Dereference,
3679 Aspect_Constant_Indexing,
3680 Aspect_Variable_Indexing,
3681 Aspect_Aggregate,
3682 Aspect_Max_Entry_Queue_Length
3683 -- , Aspect_No_Controlled_Parts
3686 -- Note that none of these 8 aspects can be specified (for a type)
3687 -- via a pragma. For 7 of them, the corresponding pragma does not
3688 -- exist. The Pragma_Id enumeration type does include
3689 -- Pragma_Max_Entry_Queue_Length, but that pragma is only use to
3690 -- specify the aspect for a protected entry or entry family, not for
3691 -- a type, and therefore cannot introduce the sorts of inheritance
3692 -- issues that we are concerned with in this procedure.
3694 type Entity_Array is array (Nat range <>) of Entity_Id;
3696 function Ancestor_Entities return Entity_Array;
3697 -- Returns all progenitors (including parent type, if present)
3699 procedure Check_Consistency_For_One_Aspect_Of_Two_Ancestors
3700 (Aspect : Nonoverridable_Aspect_Id;
3701 Ancestor_1 : Entity_Id;
3702 Aspect_Spec_1 : Node_Id;
3703 Ancestor_2 : Entity_Id;
3704 Aspect_Spec_2 : Node_Id);
3705 -- A given aspect has been specified for each of two ancestors;
3706 -- check that the two aspect specifications are compatible (see
3707 -- RM 13.1.1(18.5) and AI12-0211).
3709 -----------------------
3710 -- Ancestor_Entities --
3711 -----------------------
3713 function Ancestor_Entities return Entity_Array is
3714 Ifc_Count : constant Nat := List_Length (Interface_List);
3715 Ifc_Ancestors : Entity_Array (1 .. Ifc_Count);
3716 Ifc : Node_Id := First (Interface_List);
3717 begin
3718 for Idx in Ifc_Ancestors'Range loop
3719 Ifc_Ancestors (Idx) := Entity (Ifc);
3720 pragma Assert (Present (Ifc_Ancestors (Idx)));
3721 Ifc := Next (Ifc);
3722 end loop;
3723 pragma Assert (No (Ifc));
3724 if Present (Parent_Type) then
3725 return Parent_Type & Ifc_Ancestors;
3726 else
3727 return Ifc_Ancestors;
3728 end if;
3729 end Ancestor_Entities;
3731 -------------------------------------------------------
3732 -- Check_Consistency_For_One_Aspect_Of_Two_Ancestors --
3733 -------------------------------------------------------
3735 procedure Check_Consistency_For_One_Aspect_Of_Two_Ancestors
3736 (Aspect : Nonoverridable_Aspect_Id;
3737 Ancestor_1 : Entity_Id;
3738 Aspect_Spec_1 : Node_Id;
3739 Ancestor_2 : Entity_Id;
3740 Aspect_Spec_2 : Node_Id) is
3741 begin
3742 if not Is_Confirming (Aspect, Aspect_Spec_1, Aspect_Spec_2) then
3743 Error_Msg_Name_1 := Aspect_Names (Aspect);
3744 Error_Msg_Name_2 := Chars (Ancestor_1);
3745 Error_Msg_Name_3 := Chars (Ancestor_2);
3747 Error_Msg (
3748 "incompatible % aspects inherited from ancestors % and %",
3749 Sloc (Inheritor));
3750 end if;
3751 end Check_Consistency_For_One_Aspect_Of_Two_Ancestors;
3753 Ancestors : constant Entity_Array := Ancestor_Entities;
3755 -- start of processing for Check_Inherited_Nonoverridable_Aspects
3756 begin
3757 -- No Ada_Version check here; AI12-0211 is a binding interpretation.
3759 if Ancestors'Length < 2 then
3760 return; -- Inconsistency impossible; it takes 2 to disagree.
3761 elsif In_Instance_Body then
3762 return; -- No legality checking in an instance body.
3763 end if;
3765 for Aspect of Nonoverridable_Aspects loop
3766 declare
3767 First_Ancestor_With_Aspect : Entity_Id := Empty;
3768 First_Aspect_Spec, Current_Aspect_Spec : Node_Id := Empty;
3769 begin
3770 for Ancestor of Ancestors loop
3771 Current_Aspect_Spec := Find_Aspect (Ancestor, Aspect);
3772 if Present (Current_Aspect_Spec) then
3773 if Present (First_Ancestor_With_Aspect) then
3774 Check_Consistency_For_One_Aspect_Of_Two_Ancestors
3775 (Aspect => Aspect,
3776 Ancestor_1 => First_Ancestor_With_Aspect,
3777 Aspect_Spec_1 => First_Aspect_Spec,
3778 Ancestor_2 => Ancestor,
3779 Aspect_Spec_2 => Current_Aspect_Spec);
3780 else
3781 First_Ancestor_With_Aspect := Ancestor;
3782 First_Aspect_Spec := Current_Aspect_Spec;
3783 end if;
3784 end if;
3785 end loop;
3786 end;
3787 end loop;
3788 end Check_Inherited_Nonoverridable_Aspects;
3790 ----------------------------------------
3791 -- Check_Nonvolatile_Function_Profile --
3792 ----------------------------------------
3794 procedure Check_Nonvolatile_Function_Profile (Func_Id : Entity_Id) is
3795 Formal : Entity_Id;
3797 begin
3798 -- Inspect all formal parameters
3800 Formal := First_Formal (Func_Id);
3801 while Present (Formal) loop
3802 if Is_Effectively_Volatile_For_Reading (Etype (Formal)) then
3803 Error_Msg_NE
3804 ("nonvolatile function & cannot have a volatile parameter",
3805 Formal, Func_Id);
3806 end if;
3808 Next_Formal (Formal);
3809 end loop;
3811 -- Inspect the return type
3813 if Is_Effectively_Volatile_For_Reading (Etype (Func_Id)) then
3814 Error_Msg_NE
3815 ("nonvolatile function & cannot have a volatile return type",
3816 Result_Definition (Parent (Func_Id)), Func_Id);
3817 end if;
3818 end Check_Nonvolatile_Function_Profile;
3820 -------------------
3821 -- Check_Parents --
3822 -------------------
3824 function Check_Parents (N : Node_Id; List : Elist_Id) return Boolean is
3826 function Check_Node
3827 (Parent_Node : Node_Id;
3828 N : Node_Id) return Traverse_Result;
3829 -- Process a single node.
3831 ----------------
3832 -- Check_Node --
3833 ----------------
3835 function Check_Node
3836 (Parent_Node : Node_Id;
3837 N : Node_Id) return Traverse_Result is
3838 begin
3839 if Nkind (N) = N_Identifier
3840 and then Parent (N) /= Parent_Node
3841 and then Present (Entity (N))
3842 and then Contains (List, Entity (N))
3843 then
3844 return Abandon;
3845 end if;
3847 return OK;
3848 end Check_Node;
3850 function Traverse is new Traverse_Func_With_Parent (Check_Node);
3852 -- Start of processing for Check_Parents
3854 begin
3855 return Traverse (N) = OK;
3856 end Check_Parents;
3858 -----------------------------
3859 -- Check_Part_Of_Reference --
3860 -----------------------------
3862 procedure Check_Part_Of_Reference (Var_Id : Entity_Id; Ref : Node_Id) is
3863 function Is_Enclosing_Package_Body
3864 (Body_Decl : Node_Id;
3865 Obj_Id : Entity_Id) return Boolean;
3866 pragma Inline (Is_Enclosing_Package_Body);
3867 -- Determine whether package body Body_Decl or its corresponding spec
3868 -- immediately encloses the declaration of object Obj_Id.
3870 function Is_Internal_Declaration_Or_Body
3871 (Decl : Node_Id) return Boolean;
3872 pragma Inline (Is_Internal_Declaration_Or_Body);
3873 -- Determine whether declaration or body denoted by Decl is internal
3875 function Is_Single_Declaration_Or_Body
3876 (Decl : Node_Id;
3877 Conc_Typ : Entity_Id) return Boolean;
3878 pragma Inline (Is_Single_Declaration_Or_Body);
3879 -- Determine whether protected/task declaration or body denoted by Decl
3880 -- belongs to single concurrent type Conc_Typ.
3882 function Is_Single_Task_Pragma
3883 (Prag : Node_Id;
3884 Task_Typ : Entity_Id) return Boolean;
3885 pragma Inline (Is_Single_Task_Pragma);
3886 -- Determine whether pragma Prag belongs to single task type Task_Typ
3888 -------------------------------
3889 -- Is_Enclosing_Package_Body --
3890 -------------------------------
3892 function Is_Enclosing_Package_Body
3893 (Body_Decl : Node_Id;
3894 Obj_Id : Entity_Id) return Boolean
3896 Obj_Context : Node_Id;
3898 begin
3899 -- Find the context of the object declaration
3901 Obj_Context := Parent (Declaration_Node (Obj_Id));
3903 if Nkind (Obj_Context) = N_Package_Specification then
3904 Obj_Context := Parent (Obj_Context);
3905 end if;
3907 -- The object appears immediately within the package body
3909 if Obj_Context = Body_Decl then
3910 return True;
3912 -- The object appears immediately within the corresponding spec
3914 elsif Nkind (Obj_Context) = N_Package_Declaration
3915 and then Unit_Declaration_Node (Corresponding_Spec (Body_Decl)) =
3916 Obj_Context
3917 then
3918 return True;
3919 end if;
3921 return False;
3922 end Is_Enclosing_Package_Body;
3924 -------------------------------------
3925 -- Is_Internal_Declaration_Or_Body --
3926 -------------------------------------
3928 function Is_Internal_Declaration_Or_Body
3929 (Decl : Node_Id) return Boolean
3931 begin
3932 if Comes_From_Source (Decl) then
3933 return False;
3935 -- A body generated for an expression function which has not been
3936 -- inserted into the tree yet (In_Spec_Expression is True) is not
3937 -- considered internal.
3939 elsif Nkind (Decl) = N_Subprogram_Body
3940 and then Was_Expression_Function (Decl)
3941 and then not In_Spec_Expression
3942 then
3943 return False;
3944 end if;
3946 return True;
3947 end Is_Internal_Declaration_Or_Body;
3949 -----------------------------------
3950 -- Is_Single_Declaration_Or_Body --
3951 -----------------------------------
3953 function Is_Single_Declaration_Or_Body
3954 (Decl : Node_Id;
3955 Conc_Typ : Entity_Id) return Boolean
3957 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Decl);
3959 begin
3960 return
3961 Present (Anonymous_Object (Spec_Id))
3962 and then Anonymous_Object (Spec_Id) = Conc_Typ;
3963 end Is_Single_Declaration_Or_Body;
3965 ---------------------------
3966 -- Is_Single_Task_Pragma --
3967 ---------------------------
3969 function Is_Single_Task_Pragma
3970 (Prag : Node_Id;
3971 Task_Typ : Entity_Id) return Boolean
3973 Decl : constant Node_Id := Find_Related_Declaration_Or_Body (Prag);
3975 begin
3976 -- To qualify, the pragma must be associated with single task type
3977 -- Task_Typ.
3979 return
3980 Is_Single_Task_Object (Task_Typ)
3981 and then Nkind (Decl) = N_Object_Declaration
3982 and then Defining_Entity (Decl) = Task_Typ;
3983 end Is_Single_Task_Pragma;
3985 -- Local variables
3987 Conc_Obj : constant Entity_Id := Encapsulating_State (Var_Id);
3988 Par : Node_Id;
3989 Prag_Nam : Name_Id;
3990 Prev : Node_Id;
3992 -- Start of processing for Check_Part_Of_Reference
3994 begin
3995 -- Nothing to do when the variable was recorded, but did not become a
3996 -- constituent of a single concurrent type.
3998 if No (Conc_Obj) then
3999 return;
4000 end if;
4002 -- Traverse the parent chain looking for a suitable context for the
4003 -- reference to the concurrent constituent.
4005 Prev := Ref;
4006 Par := Parent (Prev);
4007 while Present (Par) loop
4008 if Nkind (Par) = N_Pragma then
4009 Prag_Nam := Pragma_Name (Par);
4011 -- A concurrent constituent is allowed to appear in pragmas
4012 -- Initial_Condition and Initializes as this is part of the
4013 -- elaboration checks for the constituent (SPARK RM 9(3)).
4015 if Prag_Nam in Name_Initial_Condition | Name_Initializes then
4016 return;
4018 -- When the reference appears within pragma Depends or Global,
4019 -- check whether the pragma applies to a single task type. Note
4020 -- that the pragma may not encapsulated by the type definition,
4021 -- but this is still a valid context.
4023 elsif Prag_Nam in Name_Depends | Name_Global
4024 and then Is_Single_Task_Pragma (Par, Conc_Obj)
4025 then
4026 return;
4027 end if;
4029 -- The reference appears somewhere in the definition of a single
4030 -- concurrent type (SPARK RM 9(3)).
4032 elsif Nkind (Par) in
4033 N_Single_Protected_Declaration | N_Single_Task_Declaration
4034 and then Defining_Entity (Par) = Conc_Obj
4035 then
4036 return;
4038 -- The reference appears within the declaration or body of a single
4039 -- concurrent type (SPARK RM 9(3)).
4041 elsif Nkind (Par) in N_Protected_Body
4042 | N_Protected_Type_Declaration
4043 | N_Task_Body
4044 | N_Task_Type_Declaration
4045 and then Is_Single_Declaration_Or_Body (Par, Conc_Obj)
4046 then
4047 return;
4049 -- The reference appears within the statement list of the object's
4050 -- immediately enclosing package (SPARK RM 9(3)).
4052 elsif Nkind (Par) = N_Package_Body
4053 and then Nkind (Prev) = N_Handled_Sequence_Of_Statements
4054 and then Is_Enclosing_Package_Body (Par, Var_Id)
4055 then
4056 return;
4058 -- The reference has been relocated within an internally generated
4059 -- package or subprogram. Assume that the reference is legal as the
4060 -- real check was already performed in the original context of the
4061 -- reference.
4063 elsif Nkind (Par) in N_Package_Body
4064 | N_Package_Declaration
4065 | N_Subprogram_Body
4066 | N_Subprogram_Declaration
4067 and then Is_Internal_Declaration_Or_Body (Par)
4068 then
4069 return;
4071 -- The reference has been relocated to an inlined body for GNATprove.
4072 -- Assume that the reference is legal as the real check was already
4073 -- performed in the original context of the reference.
4075 elsif GNATprove_Mode
4076 and then Nkind (Par) = N_Subprogram_Body
4077 and then Chars (Defining_Entity (Par)) = Name_uParent
4078 then
4079 return;
4080 end if;
4082 Prev := Par;
4083 Par := Parent (Prev);
4084 end loop;
4086 -- At this point it is known that the reference does not appear within a
4087 -- legal context.
4089 Error_Msg_NE
4090 ("reference to variable & cannot appear in this context", Ref, Var_Id);
4091 Error_Msg_Name_1 := Chars (Var_Id);
4093 if Is_Single_Protected_Object (Conc_Obj) then
4094 Error_Msg_NE
4095 ("\% is constituent of single protected type &", Ref, Conc_Obj);
4097 else
4098 Error_Msg_NE
4099 ("\% is constituent of single task type &", Ref, Conc_Obj);
4100 end if;
4101 end Check_Part_Of_Reference;
4103 ------------------------------------------
4104 -- Check_Potentially_Blocking_Operation --
4105 ------------------------------------------
4107 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
4108 S : Entity_Id;
4110 begin
4111 -- N is one of the potentially blocking operations listed in 9.5.1(8).
4112 -- When pragma Detect_Blocking is active, the run time will raise
4113 -- Program_Error. Here we only issue a warning, since we generally
4114 -- support the use of potentially blocking operations in the absence
4115 -- of the pragma.
4117 -- Indirect blocking through a subprogram call cannot be diagnosed
4118 -- statically without interprocedural analysis, so we do not attempt
4119 -- to do it here.
4121 S := Scope (Current_Scope);
4122 while Present (S) and then S /= Standard_Standard loop
4123 if Is_Protected_Type (S) then
4124 Error_Msg_N
4125 ("potentially blocking operation in protected operation??", N);
4126 return;
4127 end if;
4129 S := Scope (S);
4130 end loop;
4131 end Check_Potentially_Blocking_Operation;
4133 ------------------------------------
4134 -- Check_Previous_Null_Procedure --
4135 ------------------------------------
4137 procedure Check_Previous_Null_Procedure
4138 (Decl : Node_Id;
4139 Prev : Entity_Id)
4141 begin
4142 if Ekind (Prev) = E_Procedure
4143 and then Nkind (Parent (Prev)) = N_Procedure_Specification
4144 and then Null_Present (Parent (Prev))
4145 then
4146 Error_Msg_Sloc := Sloc (Prev);
4147 Error_Msg_N
4148 ("declaration cannot complete previous null procedure#", Decl);
4149 end if;
4150 end Check_Previous_Null_Procedure;
4152 ---------------------------------
4153 -- Check_Result_And_Post_State --
4154 ---------------------------------
4156 procedure Check_Result_And_Post_State (Subp_Id : Entity_Id) is
4157 procedure Check_Result_And_Post_State_In_Pragma
4158 (Prag : Node_Id;
4159 Result_Seen : in out Boolean);
4160 -- Determine whether pragma Prag mentions attribute 'Result and whether
4161 -- the pragma contains an expression that evaluates differently in pre-
4162 -- and post-state. Prag is a [refined] postcondition or a contract-cases
4163 -- pragma. Result_Seen is set when the pragma mentions attribute 'Result
4165 -------------------------------------------
4166 -- Check_Result_And_Post_State_In_Pragma --
4167 -------------------------------------------
4169 procedure Check_Result_And_Post_State_In_Pragma
4170 (Prag : Node_Id;
4171 Result_Seen : in out Boolean)
4173 procedure Check_Conjunct (Expr : Node_Id);
4174 -- Check an individual conjunct in a conjunction of Boolean
4175 -- expressions, connected by "and" or "and then" operators.
4177 procedure Check_Conjuncts (Expr : Node_Id);
4178 -- Apply the post-state check to every conjunct in an expression, in
4179 -- case this is a conjunction of Boolean expressions. Otherwise apply
4180 -- it to the expression as a whole.
4182 procedure Check_Expression (Expr : Node_Id);
4183 -- Perform the 'Result and post-state checks on a given expression
4185 function Is_Function_Result (N : Node_Id) return Traverse_Result;
4186 -- Attempt to find attribute 'Result in a subtree denoted by N
4188 function Mentions_Post_State (N : Node_Id) return Boolean;
4189 -- Determine whether a subtree denoted by N mentions any construct
4190 -- that denotes a post-state.
4192 procedure Check_Function_Result is
4193 new Traverse_Proc (Is_Function_Result);
4195 --------------------
4196 -- Check_Conjunct --
4197 --------------------
4199 procedure Check_Conjunct (Expr : Node_Id) is
4200 function Adjust_Message (Msg : String) return String;
4201 -- Prepend a prefix to the input message Msg denoting that the
4202 -- message applies to a conjunct in the expression, when this
4203 -- is the case.
4205 function Applied_On_Conjunct return Boolean;
4206 -- Returns True if the message applies to a conjunct in the
4207 -- expression, instead of the whole expression.
4209 function Has_Global_Output (Subp : Entity_Id) return Boolean;
4210 -- Returns True if Subp has an output in its Global contract
4212 function Has_No_Output (Subp : Entity_Id) return Boolean;
4213 -- Returns True if Subp has no declared output: no function
4214 -- result, no output parameter, and no output in its Global
4215 -- contract.
4217 --------------------
4218 -- Adjust_Message --
4219 --------------------
4221 function Adjust_Message (Msg : String) return String is
4222 begin
4223 if Applied_On_Conjunct then
4224 return "conjunct in " & Msg;
4225 else
4226 return Msg;
4227 end if;
4228 end Adjust_Message;
4230 -------------------------
4231 -- Applied_On_Conjunct --
4232 -------------------------
4234 function Applied_On_Conjunct return Boolean is
4235 begin
4236 -- Expr is the conjunct of an enclosing "and" expression
4238 return Nkind (Parent (Expr)) in N_Subexpr
4240 -- or Expr is a conjunct of an enclosing "and then"
4241 -- expression in a postcondition aspect that was split into
4242 -- multiple pragmas. The first conjunct has the "and then"
4243 -- expression as Original_Node, and other conjuncts have
4244 -- Split_PCC set to True.
4246 or else Nkind (Original_Node (Expr)) = N_And_Then
4247 or else Split_PPC (Prag);
4248 end Applied_On_Conjunct;
4250 -----------------------
4251 -- Has_Global_Output --
4252 -----------------------
4254 function Has_Global_Output (Subp : Entity_Id) return Boolean is
4255 Global : constant Node_Id := Get_Pragma (Subp, Pragma_Global);
4256 List : Node_Id;
4257 Assoc : Node_Id;
4259 begin
4260 if No (Global) then
4261 return False;
4262 end if;
4264 List := Expression (Get_Argument (Global, Subp));
4266 -- Empty list (no global items) or single global item
4267 -- declaration (only input items).
4269 if Nkind (List) in N_Null
4270 | N_Expanded_Name
4271 | N_Identifier
4272 | N_Selected_Component
4273 then
4274 return False;
4276 -- Simple global list (only input items) or moded global list
4277 -- declaration.
4279 elsif Nkind (List) = N_Aggregate then
4280 if Present (Expressions (List)) then
4281 return False;
4283 else
4284 Assoc := First (Component_Associations (List));
4285 while Present (Assoc) loop
4286 if Chars (First (Choices (Assoc))) /= Name_Input then
4287 return True;
4288 end if;
4290 Next (Assoc);
4291 end loop;
4293 return False;
4294 end if;
4296 -- To accommodate partial decoration of disabled SPARK
4297 -- features, this routine may be called with illegal input.
4298 -- If this is the case, do not raise Program_Error.
4300 else
4301 return False;
4302 end if;
4303 end Has_Global_Output;
4305 -------------------
4306 -- Has_No_Output --
4307 -------------------
4309 function Has_No_Output (Subp : Entity_Id) return Boolean is
4310 Param : Node_Id;
4312 begin
4313 -- A function has its result as output
4315 if Ekind (Subp) = E_Function then
4316 return False;
4317 end if;
4319 -- An OUT or IN OUT parameter is an output
4321 Param := First_Formal (Subp);
4322 while Present (Param) loop
4323 if Ekind (Param) in E_Out_Parameter | E_In_Out_Parameter then
4324 return False;
4325 end if;
4327 Next_Formal (Param);
4328 end loop;
4330 -- An item of mode Output or In_Out in the Global contract is
4331 -- an output.
4333 if Has_Global_Output (Subp) then
4334 return False;
4335 end if;
4337 return True;
4338 end Has_No_Output;
4340 -- Local variables
4342 Err_Node : Node_Id;
4343 -- Error node when reporting a warning on a (refined)
4344 -- postcondition.
4346 -- Start of processing for Check_Conjunct
4348 begin
4349 if Applied_On_Conjunct then
4350 Err_Node := Expr;
4351 else
4352 Err_Node := Prag;
4353 end if;
4355 -- Do not report missing reference to outcome in postcondition if
4356 -- either the postcondition is trivially True or False, or if the
4357 -- subprogram is ghost and has no declared output.
4359 if not Is_Trivial_Boolean (Expr)
4360 and then not Mentions_Post_State (Expr)
4361 and then not (Is_Ghost_Entity (Subp_Id)
4362 and then Has_No_Output (Subp_Id))
4363 and then not Is_Wrapper (Subp_Id)
4364 then
4365 if Pragma_Name (Prag) = Name_Contract_Cases then
4366 Error_Msg_NE (Adjust_Message
4367 ("contract case does not check the outcome of calling "
4368 & "&?.t?"), Expr, Subp_Id);
4370 elsif Pragma_Name (Prag) = Name_Refined_Post then
4371 Error_Msg_NE (Adjust_Message
4372 ("refined postcondition does not check the outcome of "
4373 & "calling &?.t?"), Err_Node, Subp_Id);
4375 else
4376 Error_Msg_NE (Adjust_Message
4377 ("postcondition does not check the outcome of calling "
4378 & "&?.t?"), Err_Node, Subp_Id);
4379 end if;
4380 end if;
4381 end Check_Conjunct;
4383 ---------------------
4384 -- Check_Conjuncts --
4385 ---------------------
4387 procedure Check_Conjuncts (Expr : Node_Id) is
4388 begin
4389 if Nkind (Expr) in N_Op_And | N_And_Then then
4390 Check_Conjuncts (Left_Opnd (Expr));
4391 Check_Conjuncts (Right_Opnd (Expr));
4392 else
4393 Check_Conjunct (Expr);
4394 end if;
4395 end Check_Conjuncts;
4397 ----------------------
4398 -- Check_Expression --
4399 ----------------------
4401 procedure Check_Expression (Expr : Node_Id) is
4402 begin
4403 if not Is_Trivial_Boolean (Expr) then
4404 Check_Function_Result (Expr);
4405 Check_Conjuncts (Expr);
4406 end if;
4407 end Check_Expression;
4409 ------------------------
4410 -- Is_Function_Result --
4411 ------------------------
4413 function Is_Function_Result (N : Node_Id) return Traverse_Result is
4414 begin
4415 if Is_Attribute_Result (N) then
4416 Result_Seen := True;
4417 return Abandon;
4419 -- Warn on infinite recursion if call is to current function
4421 elsif Nkind (N) = N_Function_Call
4422 and then Is_Entity_Name (Name (N))
4423 and then Entity (Name (N)) = Subp_Id
4424 and then not Is_Potentially_Unevaluated (N)
4425 then
4426 Error_Msg_NE
4427 ("call to & within its postcondition will lead to infinite "
4428 & "recursion?", N, Subp_Id);
4429 return OK;
4431 -- Continue the traversal
4433 else
4434 return OK;
4435 end if;
4436 end Is_Function_Result;
4438 -------------------------
4439 -- Mentions_Post_State --
4440 -------------------------
4442 function Mentions_Post_State (N : Node_Id) return Boolean is
4443 Post_State_Seen : Boolean := False;
4445 function Is_Post_State (N : Node_Id) return Traverse_Result;
4446 -- Attempt to find a construct that denotes a post-state. If this
4447 -- is the case, set flag Post_State_Seen.
4449 -------------------
4450 -- Is_Post_State --
4451 -------------------
4453 function Is_Post_State (N : Node_Id) return Traverse_Result is
4454 Ent : Entity_Id;
4456 begin
4457 if Nkind (N) in N_Explicit_Dereference | N_Function_Call then
4458 Post_State_Seen := True;
4459 return Abandon;
4461 elsif Nkind (N) in N_Expanded_Name | N_Identifier then
4462 Ent := Entity (N);
4464 -- Treat an undecorated reference as OK
4466 if No (Ent)
4468 -- A reference to an assignable entity is considered a
4469 -- change in the post-state of a subprogram.
4471 or else Ekind (Ent) in E_Generic_In_Out_Parameter
4472 | E_In_Out_Parameter
4473 | E_Out_Parameter
4474 | E_Variable
4476 -- The reference may be modified through a dereference
4478 or else (Is_Access_Type (Etype (Ent))
4479 and then Nkind (Parent (N)) =
4480 N_Selected_Component)
4481 then
4482 Post_State_Seen := True;
4483 return Abandon;
4484 end if;
4486 elsif Nkind (N) = N_Attribute_Reference then
4487 if Attribute_Name (N) = Name_Old then
4488 return Skip;
4490 elsif Attribute_Name (N) = Name_Result then
4491 Post_State_Seen := True;
4492 return Abandon;
4493 end if;
4494 end if;
4496 return OK;
4497 end Is_Post_State;
4499 procedure Find_Post_State is new Traverse_Proc (Is_Post_State);
4501 -- Start of processing for Mentions_Post_State
4503 begin
4504 Find_Post_State (N);
4506 return Post_State_Seen;
4507 end Mentions_Post_State;
4509 -- Local variables
4511 Expr : constant Node_Id :=
4512 Get_Pragma_Arg
4513 (First (Pragma_Argument_Associations (Prag)));
4514 Nam : constant Name_Id := Pragma_Name (Prag);
4515 CCase : Node_Id;
4517 -- Start of processing for Check_Result_And_Post_State_In_Pragma
4519 begin
4520 -- Examine all consequences
4522 if Nam = Name_Contract_Cases then
4523 CCase := First (Component_Associations (Expr));
4524 while Present (CCase) loop
4525 Check_Expression (Expression (CCase));
4527 Next (CCase);
4528 end loop;
4530 -- Examine the expression of a postcondition
4532 else pragma Assert (Nam in Name_Postcondition | Name_Refined_Post);
4533 Check_Expression (Expr);
4534 end if;
4535 end Check_Result_And_Post_State_In_Pragma;
4537 -- Local variables
4539 Items : constant Node_Id := Contract (Subp_Id);
4540 Subp_Decl : constant Node_Id := Unit_Declaration_Node (Subp_Id);
4541 Case_Prag : Node_Id := Empty;
4542 Post_Prag : Node_Id := Empty;
4543 Prag : Node_Id;
4544 Seen_In_Case : Boolean := False;
4545 Seen_In_Post : Boolean := False;
4546 Spec_Id : Entity_Id;
4548 -- Start of processing for Check_Result_And_Post_State
4550 begin
4551 -- The lack of attribute 'Result or a post-state is classified as a
4552 -- suspicious contract. Do not perform the check if the corresponding
4553 -- swich is not set.
4555 if not Warn_On_Suspicious_Contract then
4556 return;
4558 -- Nothing to do if there is no contract
4560 elsif No (Items) then
4561 return;
4562 end if;
4564 -- Retrieve the entity of the subprogram spec (if any)
4566 if Nkind (Subp_Decl) = N_Subprogram_Body
4567 and then Present (Corresponding_Spec (Subp_Decl))
4568 then
4569 Spec_Id := Corresponding_Spec (Subp_Decl);
4571 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
4572 and then Present (Corresponding_Spec_Of_Stub (Subp_Decl))
4573 then
4574 Spec_Id := Corresponding_Spec_Of_Stub (Subp_Decl);
4576 else
4577 Spec_Id := Subp_Id;
4578 end if;
4580 -- Examine all postconditions for attribute 'Result and a post-state
4582 Prag := Pre_Post_Conditions (Items);
4583 while Present (Prag) loop
4584 if Pragma_Name_Unmapped (Prag)
4585 in Name_Postcondition | Name_Refined_Post
4586 and then not Error_Posted (Prag)
4587 then
4588 Post_Prag := Prag;
4589 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Post);
4590 end if;
4592 Prag := Next_Pragma (Prag);
4593 end loop;
4595 -- Examine the contract cases of the subprogram for attribute 'Result
4596 -- and a post-state.
4598 Prag := Contract_Test_Cases (Items);
4599 while Present (Prag) loop
4600 if Pragma_Name (Prag) = Name_Contract_Cases
4601 and then not Error_Posted (Prag)
4602 then
4603 Case_Prag := Prag;
4604 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Case);
4605 end if;
4607 Prag := Next_Pragma (Prag);
4608 end loop;
4610 -- Do not emit any errors if the subprogram is not a function
4612 if Ekind (Spec_Id) not in E_Function | E_Generic_Function then
4613 null;
4615 -- Regardless of whether the function has postconditions or contract
4616 -- cases, or whether they mention attribute 'Result, an [IN] OUT formal
4617 -- parameter is always treated as a result.
4619 elsif Has_Out_Or_In_Out_Parameter (Spec_Id) then
4620 null;
4622 -- The function has both a postcondition and contract cases and they do
4623 -- not mention attribute 'Result.
4625 elsif Present (Case_Prag)
4626 and then not Seen_In_Case
4627 and then Present (Post_Prag)
4628 and then not Seen_In_Post
4629 then
4630 Error_Msg_N
4631 ("neither postcondition nor contract cases mention function "
4632 & "result?.t?", Post_Prag);
4634 -- The function has contract cases only and they do not mention
4635 -- attribute 'Result.
4637 elsif Present (Case_Prag) and then not Seen_In_Case then
4638 Error_Msg_N ("contract cases do not mention result?.t?", Case_Prag);
4640 -- The function has non-trivial postconditions only and they do not
4641 -- mention attribute 'Result.
4643 elsif Present (Post_Prag)
4644 and then not Seen_In_Post
4645 and then not Is_Trivial_Boolean
4646 (Get_Pragma_Arg (First (Pragma_Argument_Associations (Post_Prag))))
4647 then
4648 Error_Msg_N
4649 ("postcondition does not mention function result?.t?", Post_Prag);
4650 end if;
4651 end Check_Result_And_Post_State;
4653 -----------------------------
4654 -- Check_State_Refinements --
4655 -----------------------------
4657 procedure Check_State_Refinements
4658 (Context : Node_Id;
4659 Is_Main_Unit : Boolean := False)
4661 procedure Check_Package (Pack : Node_Id);
4662 -- Verify that all abstract states of a [generic] package denoted by its
4663 -- declarative node Pack have proper refinement. Recursively verify the
4664 -- visible and private declarations of the [generic] package for other
4665 -- nested packages.
4667 procedure Check_Packages_In (Decls : List_Id);
4668 -- Seek out [generic] package declarations within declarative list Decls
4669 -- and verify the status of their abstract state refinement.
4671 function SPARK_Mode_Is_Off (N : Node_Id) return Boolean;
4672 -- Determine whether construct N is subject to pragma SPARK_Mode Off
4674 -------------------
4675 -- Check_Package --
4676 -------------------
4678 procedure Check_Package (Pack : Node_Id) is
4679 Body_Id : constant Entity_Id := Corresponding_Body (Pack);
4680 Spec : constant Node_Id := Specification (Pack);
4681 States : constant Elist_Id :=
4682 Abstract_States (Defining_Entity (Pack));
4684 State_Elmt : Elmt_Id;
4685 State_Id : Entity_Id;
4687 begin
4688 -- Do not verify proper state refinement when the package is subject
4689 -- to pragma SPARK_Mode Off because this disables the requirement for
4690 -- state refinement.
4692 if SPARK_Mode_Is_Off (Pack) then
4693 null;
4695 -- State refinement can only occur in a completing package body. Do
4696 -- not verify proper state refinement when the body is subject to
4697 -- pragma SPARK_Mode Off because this disables the requirement for
4698 -- state refinement.
4700 elsif Present (Body_Id)
4701 and then SPARK_Mode_Is_Off (Unit_Declaration_Node (Body_Id))
4702 then
4703 null;
4705 -- Do not verify proper state refinement when the package is an
4706 -- instance as this check was already performed in the generic.
4708 elsif Present (Generic_Parent (Spec)) then
4709 null;
4711 -- Otherwise examine the contents of the package
4713 else
4714 if Present (States) then
4715 State_Elmt := First_Elmt (States);
4716 while Present (State_Elmt) loop
4717 State_Id := Node (State_Elmt);
4719 -- Emit an error when a non-null state lacks refinement,
4720 -- but has Part_Of constituents or there is a package
4721 -- body (SPARK RM 7.1.4(4)). Constituents in private
4722 -- child packages, which are not known at this stage,
4723 -- independently require the existence of a package body.
4725 if not Is_Null_State (State_Id)
4726 and then No (Refinement_Constituents (State_Id))
4727 and then
4728 (Present (Part_Of_Constituents (State_Id))
4729 or else
4730 Present (Body_Id))
4731 then
4732 Error_Msg_N ("state & requires refinement", State_Id);
4733 Error_Msg_N ("\package body should have Refined_State "
4734 & "for state & with constituents", State_Id);
4735 end if;
4737 Next_Elmt (State_Elmt);
4738 end loop;
4739 end if;
4741 Check_Packages_In (Visible_Declarations (Spec));
4742 Check_Packages_In (Private_Declarations (Spec));
4743 end if;
4744 end Check_Package;
4746 -----------------------
4747 -- Check_Packages_In --
4748 -----------------------
4750 procedure Check_Packages_In (Decls : List_Id) is
4751 Decl : Node_Id;
4753 begin
4754 if Present (Decls) then
4755 Decl := First (Decls);
4756 while Present (Decl) loop
4757 if Nkind (Decl) in N_Generic_Package_Declaration
4758 | N_Package_Declaration
4759 then
4760 Check_Package (Decl);
4761 end if;
4763 Next (Decl);
4764 end loop;
4765 end if;
4766 end Check_Packages_In;
4768 -----------------------
4769 -- SPARK_Mode_Is_Off --
4770 -----------------------
4772 function SPARK_Mode_Is_Off (N : Node_Id) return Boolean is
4773 Id : constant Entity_Id := Defining_Entity (N);
4774 Prag : constant Node_Id := SPARK_Pragma (Id);
4776 begin
4777 -- Default the mode to "off" when the context is an instance and all
4778 -- SPARK_Mode pragmas found within are to be ignored.
4780 if Ignore_SPARK_Mode_Pragmas (Id) then
4781 return True;
4783 else
4784 return
4785 Present (Prag)
4786 and then Get_SPARK_Mode_From_Annotation (Prag) = Off;
4787 end if;
4788 end SPARK_Mode_Is_Off;
4790 -- Start of processing for Check_State_Refinements
4792 begin
4793 -- A block may declare a nested package
4795 if Nkind (Context) = N_Block_Statement then
4796 Check_Packages_In (Declarations (Context));
4798 -- An entry, protected, subprogram, or task body may declare a nested
4799 -- package.
4801 elsif Nkind (Context) in N_Entry_Body
4802 | N_Protected_Body
4803 | N_Subprogram_Body
4804 | N_Task_Body
4805 then
4806 -- Do not verify proper state refinement when the body is subject to
4807 -- pragma SPARK_Mode Off because this disables the requirement for
4808 -- state refinement.
4810 if not SPARK_Mode_Is_Off (Context) then
4811 Check_Packages_In (Declarations (Context));
4812 end if;
4814 -- A package body may declare a nested package
4816 elsif Nkind (Context) = N_Package_Body then
4817 Check_Package (Unit_Declaration_Node (Corresponding_Spec (Context)));
4819 -- Do not verify proper state refinement when the body is subject to
4820 -- pragma SPARK_Mode Off because this disables the requirement for
4821 -- state refinement.
4823 if not SPARK_Mode_Is_Off (Context) then
4824 Check_Packages_In (Declarations (Context));
4825 end if;
4827 -- A library level [generic] package may declare a nested package
4829 elsif Nkind (Context) in
4830 N_Generic_Package_Declaration | N_Package_Declaration
4831 and then Is_Main_Unit
4832 then
4833 Check_Package (Context);
4834 end if;
4835 end Check_State_Refinements;
4837 ------------------------------
4838 -- Check_Unprotected_Access --
4839 ------------------------------
4841 procedure Check_Unprotected_Access
4842 (Context : Node_Id;
4843 Expr : Node_Id)
4845 Cont_Encl_Typ : Entity_Id;
4846 Pref_Encl_Typ : Entity_Id;
4848 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
4849 -- Check whether Obj is a private component of a protected object.
4850 -- Return the protected type where the component resides, Empty
4851 -- otherwise.
4853 function Is_Public_Operation return Boolean;
4854 -- Verify that the enclosing operation is callable from outside the
4855 -- protected object, to minimize false positives.
4857 ------------------------------
4858 -- Enclosing_Protected_Type --
4859 ------------------------------
4861 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
4862 begin
4863 if Is_Entity_Name (Obj) then
4864 declare
4865 Ent : Entity_Id := Entity (Obj);
4867 begin
4868 -- The object can be a renaming of a private component, use
4869 -- the original record component.
4871 if Is_Prival (Ent) then
4872 Ent := Prival_Link (Ent);
4873 end if;
4875 if Is_Protected_Type (Scope (Ent)) then
4876 return Scope (Ent);
4877 end if;
4878 end;
4879 end if;
4881 -- For indexed and selected components, recursively check the prefix
4883 if Nkind (Obj) in N_Indexed_Component | N_Selected_Component then
4884 return Enclosing_Protected_Type (Prefix (Obj));
4886 -- The object does not denote a protected component
4888 else
4889 return Empty;
4890 end if;
4891 end Enclosing_Protected_Type;
4893 -------------------------
4894 -- Is_Public_Operation --
4895 -------------------------
4897 function Is_Public_Operation return Boolean is
4898 S : Entity_Id;
4899 E : Entity_Id;
4901 begin
4902 S := Current_Scope;
4903 while Present (S) and then S /= Pref_Encl_Typ loop
4904 if Scope (S) = Pref_Encl_Typ then
4905 E := First_Entity (Pref_Encl_Typ);
4906 while Present (E)
4907 and then E /= First_Private_Entity (Pref_Encl_Typ)
4908 loop
4909 if E = S then
4910 return True;
4911 end if;
4913 Next_Entity (E);
4914 end loop;
4915 end if;
4917 S := Scope (S);
4918 end loop;
4920 return False;
4921 end Is_Public_Operation;
4923 -- Start of processing for Check_Unprotected_Access
4925 begin
4926 if Nkind (Expr) = N_Attribute_Reference
4927 and then Attribute_Name (Expr) = Name_Unchecked_Access
4928 then
4929 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
4930 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
4932 -- Check whether we are trying to export a protected component to a
4933 -- context with an equal or lower access level.
4935 if Present (Pref_Encl_Typ)
4936 and then No (Cont_Encl_Typ)
4937 and then Is_Public_Operation
4938 and then Scope_Depth (Pref_Encl_Typ)
4939 >= Static_Accessibility_Level
4940 (Context, Object_Decl_Level)
4941 then
4942 Error_Msg_N
4943 ("??possible unprotected access to protected data", Expr);
4944 end if;
4945 end if;
4946 end Check_Unprotected_Access;
4948 ------------------------------
4949 -- Check_Unused_Body_States --
4950 ------------------------------
4952 procedure Check_Unused_Body_States (Body_Id : Entity_Id) is
4953 procedure Process_Refinement_Clause
4954 (Clause : Node_Id;
4955 States : Elist_Id);
4956 -- Inspect all constituents of refinement clause Clause and remove any
4957 -- matches from body state list States.
4959 procedure Report_Unused_Body_States (States : Elist_Id);
4960 -- Emit errors for each abstract state or object found in list States
4962 -------------------------------
4963 -- Process_Refinement_Clause --
4964 -------------------------------
4966 procedure Process_Refinement_Clause
4967 (Clause : Node_Id;
4968 States : Elist_Id)
4970 procedure Process_Constituent (Constit : Node_Id);
4971 -- Remove constituent Constit from body state list States
4973 -------------------------
4974 -- Process_Constituent --
4975 -------------------------
4977 procedure Process_Constituent (Constit : Node_Id) is
4978 Constit_Id : Entity_Id;
4980 begin
4981 -- Guard against illegal constituents. Only abstract states and
4982 -- objects can appear on the right hand side of a refinement.
4984 if Is_Entity_Name (Constit) then
4985 Constit_Id := Entity_Of (Constit);
4987 if Present (Constit_Id)
4988 and then Ekind (Constit_Id) in
4989 E_Abstract_State | E_Constant | E_Variable
4990 then
4991 Remove (States, Constit_Id);
4992 end if;
4993 end if;
4994 end Process_Constituent;
4996 -- Local variables
4998 Constit : Node_Id;
5000 -- Start of processing for Process_Refinement_Clause
5002 begin
5003 if Nkind (Clause) = N_Component_Association then
5004 Constit := Expression (Clause);
5006 -- Multiple constituents appear as an aggregate
5008 if Nkind (Constit) = N_Aggregate then
5009 Constit := First (Expressions (Constit));
5010 while Present (Constit) loop
5011 Process_Constituent (Constit);
5012 Next (Constit);
5013 end loop;
5015 -- Various forms of a single constituent
5017 else
5018 Process_Constituent (Constit);
5019 end if;
5020 end if;
5021 end Process_Refinement_Clause;
5023 -------------------------------
5024 -- Report_Unused_Body_States --
5025 -------------------------------
5027 procedure Report_Unused_Body_States (States : Elist_Id) is
5028 Posted : Boolean := False;
5029 State_Elmt : Elmt_Id;
5030 State_Id : Entity_Id;
5032 begin
5033 if Present (States) then
5034 State_Elmt := First_Elmt (States);
5035 while Present (State_Elmt) loop
5036 State_Id := Node (State_Elmt);
5038 -- Constants are part of the hidden state of a package, but the
5039 -- compiler cannot determine whether they have variable input
5040 -- (SPARK RM 7.1.1(2)) and cannot classify them properly as a
5041 -- hidden state. Do not emit an error when a constant does not
5042 -- participate in a state refinement, even though it acts as a
5043 -- hidden state.
5045 if Ekind (State_Id) = E_Constant then
5046 null;
5048 -- Overlays do not contribute to package state
5050 elsif Ekind (State_Id) = E_Variable
5051 and then Present (Ultimate_Overlaid_Entity (State_Id))
5052 then
5053 null;
5055 -- Generate an error message of the form:
5057 -- body of package ... has unused hidden states
5058 -- abstract state ... defined at ...
5059 -- variable ... defined at ...
5061 else
5062 if not Posted then
5063 Posted := True;
5064 SPARK_Msg_N
5065 ("body of package & has unused hidden states", Body_Id);
5066 end if;
5068 Error_Msg_Sloc := Sloc (State_Id);
5070 if Ekind (State_Id) = E_Abstract_State then
5071 SPARK_Msg_NE
5072 ("\abstract state & defined #", Body_Id, State_Id);
5074 else
5075 SPARK_Msg_NE ("\variable & defined #", Body_Id, State_Id);
5076 end if;
5077 end if;
5079 Next_Elmt (State_Elmt);
5080 end loop;
5081 end if;
5082 end Report_Unused_Body_States;
5084 -- Local variables
5086 Prag : constant Node_Id := Get_Pragma (Body_Id, Pragma_Refined_State);
5087 Spec_Id : constant Entity_Id := Spec_Entity (Body_Id);
5088 Clause : Node_Id;
5089 States : Elist_Id;
5091 -- Start of processing for Check_Unused_Body_States
5093 begin
5094 -- Inspect the clauses of pragma Refined_State and determine whether all
5095 -- visible states declared within the package body participate in the
5096 -- refinement.
5098 if Present (Prag) then
5099 Clause := Expression (Get_Argument (Prag, Spec_Id));
5100 States := Collect_Body_States (Body_Id);
5102 -- Multiple non-null state refinements appear as an aggregate
5104 if Nkind (Clause) = N_Aggregate then
5105 Clause := First (Component_Associations (Clause));
5106 while Present (Clause) loop
5107 Process_Refinement_Clause (Clause, States);
5108 Next (Clause);
5109 end loop;
5111 -- Various forms of a single state refinement
5113 else
5114 Process_Refinement_Clause (Clause, States);
5115 end if;
5117 -- Ensure that all abstract states and objects declared in the
5118 -- package body state space are utilized as constituents.
5120 Report_Unused_Body_States (States);
5121 end if;
5122 end Check_Unused_Body_States;
5124 ------------------------------------
5125 -- Check_Volatility_Compatibility --
5126 ------------------------------------
5128 procedure Check_Volatility_Compatibility
5129 (Id1, Id2 : Entity_Id;
5130 Description_1, Description_2 : String;
5131 Srcpos_Bearer : Node_Id) is
5133 begin
5134 if SPARK_Mode /= On then
5135 return;
5136 end if;
5138 declare
5139 AR1 : constant Boolean := Async_Readers_Enabled (Id1);
5140 AW1 : constant Boolean := Async_Writers_Enabled (Id1);
5141 ER1 : constant Boolean := Effective_Reads_Enabled (Id1);
5142 EW1 : constant Boolean := Effective_Writes_Enabled (Id1);
5143 AR2 : constant Boolean := Async_Readers_Enabled (Id2);
5144 AW2 : constant Boolean := Async_Writers_Enabled (Id2);
5145 ER2 : constant Boolean := Effective_Reads_Enabled (Id2);
5146 EW2 : constant Boolean := Effective_Writes_Enabled (Id2);
5148 AR_Check_Failed : constant Boolean := AR1 and not AR2;
5149 AW_Check_Failed : constant Boolean := AW1 and not AW2;
5150 ER_Check_Failed : constant Boolean := ER1 and not ER2;
5151 EW_Check_Failed : constant Boolean := EW1 and not EW2;
5153 package Failure_Description is
5154 procedure Note_If_Failure
5155 (Failed : Boolean; Aspect_Name : String);
5156 -- If Failed is False, do nothing.
5157 -- If Failed is True, add Aspect_Name to the failure description.
5159 function Failure_Text return String;
5160 -- returns accumulated list of failing aspects
5161 end Failure_Description;
5163 package body Failure_Description is
5164 Description_Buffer : Bounded_String;
5166 ---------------------
5167 -- Note_If_Failure --
5168 ---------------------
5170 procedure Note_If_Failure
5171 (Failed : Boolean; Aspect_Name : String) is
5172 begin
5173 if Failed then
5174 if Description_Buffer.Length /= 0 then
5175 Append (Description_Buffer, ", ");
5176 end if;
5177 Append (Description_Buffer, Aspect_Name);
5178 end if;
5179 end Note_If_Failure;
5181 ------------------
5182 -- Failure_Text --
5183 ------------------
5185 function Failure_Text return String is
5186 begin
5187 return +Description_Buffer;
5188 end Failure_Text;
5189 end Failure_Description;
5191 use Failure_Description;
5192 begin
5193 if AR_Check_Failed
5194 or AW_Check_Failed
5195 or ER_Check_Failed
5196 or EW_Check_Failed
5197 then
5198 Note_If_Failure (AR_Check_Failed, "Async_Readers");
5199 Note_If_Failure (AW_Check_Failed, "Async_Writers");
5200 Note_If_Failure (ER_Check_Failed, "Effective_Reads");
5201 Note_If_Failure (EW_Check_Failed, "Effective_Writes");
5203 Error_Msg_N
5204 (Description_1
5205 & " and "
5206 & Description_2
5207 & " are not compatible with respect to volatility due to "
5208 & Failure_Text,
5209 Srcpos_Bearer);
5210 end if;
5211 end;
5212 end Check_Volatility_Compatibility;
5214 -----------------
5215 -- Choice_List --
5216 -----------------
5218 function Choice_List (N : Node_Id) return List_Id is
5219 begin
5220 if Nkind (N) = N_Iterated_Component_Association then
5221 return Discrete_Choices (N);
5222 else
5223 return Choices (N);
5224 end if;
5225 end Choice_List;
5227 ---------------------
5228 -- Class_Condition --
5229 ---------------------
5231 function Class_Condition
5232 (Kind : Condition_Kind;
5233 Subp : Entity_Id) return Node_Id is
5235 begin
5236 case Kind is
5237 when Class_Postcondition =>
5238 return Class_Postconditions (Subp);
5240 when Class_Precondition =>
5241 return Class_Preconditions (Subp);
5243 when Ignored_Class_Postcondition =>
5244 return Ignored_Class_Postconditions (Subp);
5246 when Ignored_Class_Precondition =>
5247 return Ignored_Class_Preconditions (Subp);
5248 end case;
5249 end Class_Condition;
5251 -------------------------
5252 -- Collect_Body_States --
5253 -------------------------
5255 function Collect_Body_States (Body_Id : Entity_Id) return Elist_Id is
5256 function Is_Visible_Object (Obj_Id : Entity_Id) return Boolean;
5257 -- Determine whether object Obj_Id is a suitable visible state of a
5258 -- package body.
5260 procedure Collect_Visible_States
5261 (Pack_Id : Entity_Id;
5262 States : in out Elist_Id);
5263 -- Gather the entities of all abstract states and objects declared in
5264 -- the visible state space of package Pack_Id.
5266 ----------------------------
5267 -- Collect_Visible_States --
5268 ----------------------------
5270 procedure Collect_Visible_States
5271 (Pack_Id : Entity_Id;
5272 States : in out Elist_Id)
5274 Item_Id : Entity_Id;
5276 begin
5277 -- Traverse the entity chain of the package and inspect all visible
5278 -- items.
5280 Item_Id := First_Entity (Pack_Id);
5281 while Present (Item_Id) and then not In_Private_Part (Item_Id) loop
5283 -- Do not consider internally generated items as those cannot be
5284 -- named and participate in refinement.
5286 if not Comes_From_Source (Item_Id) then
5287 null;
5289 elsif Ekind (Item_Id) = E_Abstract_State then
5290 Append_New_Elmt (Item_Id, States);
5292 elsif Ekind (Item_Id) in E_Constant | E_Variable
5293 and then Is_Visible_Object (Item_Id)
5294 then
5295 Append_New_Elmt (Item_Id, States);
5297 -- Recursively gather the visible states of a nested package
5298 -- except for nested package renamings.
5300 elsif Ekind (Item_Id) = E_Package
5301 and then No (Renamed_Entity (Item_Id))
5302 then
5303 Collect_Visible_States (Item_Id, States);
5304 end if;
5306 Next_Entity (Item_Id);
5307 end loop;
5308 end Collect_Visible_States;
5310 -----------------------
5311 -- Is_Visible_Object --
5312 -----------------------
5314 function Is_Visible_Object (Obj_Id : Entity_Id) return Boolean is
5315 begin
5316 -- Objects that map generic formals to their actuals are not visible
5317 -- from outside the generic instantiation.
5319 if Present (Corresponding_Generic_Association
5320 (Declaration_Node (Obj_Id)))
5321 then
5322 return False;
5324 -- Constituents of a single protected/task type act as components of
5325 -- the type and are not visible from outside the type.
5327 elsif Ekind (Obj_Id) = E_Variable
5328 and then Present (Encapsulating_State (Obj_Id))
5329 and then Is_Single_Concurrent_Object (Encapsulating_State (Obj_Id))
5330 then
5331 return False;
5333 else
5334 return True;
5335 end if;
5336 end Is_Visible_Object;
5338 -- Local variables
5340 Body_Decl : constant Node_Id := Unit_Declaration_Node (Body_Id);
5341 Decl : Node_Id;
5342 Item_Id : Entity_Id;
5343 States : Elist_Id := No_Elist;
5345 -- Start of processing for Collect_Body_States
5347 begin
5348 -- Inspect the declarations of the body looking for source objects,
5349 -- packages and package instantiations. Note that even though this
5350 -- processing is very similar to Collect_Visible_States, a package
5351 -- body does not have a First/Next_Entity list.
5353 Decl := First (Declarations (Body_Decl));
5354 while Present (Decl) loop
5356 -- Capture source objects as internally generated temporaries cannot
5357 -- be named and participate in refinement.
5359 if Nkind (Decl) = N_Object_Declaration then
5360 Item_Id := Defining_Entity (Decl);
5362 if Comes_From_Source (Item_Id)
5363 and then Is_Visible_Object (Item_Id)
5364 then
5365 Append_New_Elmt (Item_Id, States);
5366 end if;
5368 -- Capture the visible abstract states and objects of a source
5369 -- package [instantiation].
5371 elsif Nkind (Decl) = N_Package_Declaration then
5372 Item_Id := Defining_Entity (Decl);
5374 if Comes_From_Source (Item_Id) then
5375 Collect_Visible_States (Item_Id, States);
5376 end if;
5377 end if;
5379 Next (Decl);
5380 end loop;
5382 return States;
5383 end Collect_Body_States;
5385 ------------------------
5386 -- Collect_Interfaces --
5387 ------------------------
5389 procedure Collect_Interfaces
5390 (T : Entity_Id;
5391 Ifaces_List : out Elist_Id;
5392 Exclude_Parents : Boolean := False;
5393 Use_Full_View : Boolean := True)
5395 procedure Collect (Typ : Entity_Id);
5396 -- Subsidiary subprogram used to traverse the whole list
5397 -- of directly and indirectly implemented interfaces
5399 -------------
5400 -- Collect --
5401 -------------
5403 procedure Collect (Typ : Entity_Id) is
5404 Ancestor : Entity_Id;
5405 Full_T : Entity_Id;
5406 Id : Node_Id;
5407 Iface : Entity_Id;
5409 begin
5410 Full_T := Typ;
5412 -- Handle private types and subtypes
5414 if Use_Full_View
5415 and then Is_Private_Type (Typ)
5416 and then Present (Full_View (Typ))
5417 then
5418 Full_T := Full_View (Typ);
5420 if Ekind (Full_T) = E_Record_Subtype then
5421 Full_T := Etype (Typ);
5423 if Present (Full_View (Full_T)) then
5424 Full_T := Full_View (Full_T);
5425 end if;
5426 end if;
5427 end if;
5429 -- Include the ancestor if we are generating the whole list of
5430 -- abstract interfaces.
5432 if Etype (Full_T) /= Typ
5434 -- Protect the frontend against wrong sources. For example:
5436 -- package P is
5437 -- type A is tagged null record;
5438 -- type B is new A with private;
5439 -- type C is new A with private;
5440 -- private
5441 -- type B is new C with null record;
5442 -- type C is new B with null record;
5443 -- end P;
5445 and then Etype (Full_T) /= T
5446 then
5447 Ancestor := Etype (Full_T);
5448 Collect (Ancestor);
5450 if Is_Interface (Ancestor) and then not Exclude_Parents then
5451 Append_Unique_Elmt (Ancestor, Ifaces_List);
5452 end if;
5453 end if;
5455 -- Traverse the graph of ancestor interfaces
5457 Id := First (Abstract_Interface_List (Full_T));
5458 while Present (Id) loop
5459 Iface := Etype (Id);
5461 -- Protect against wrong uses. For example:
5462 -- type I is interface;
5463 -- type O is tagged null record;
5464 -- type Wrong is new I and O with null record; -- ERROR
5466 if Is_Interface (Iface) then
5467 if Exclude_Parents
5468 and then Etype (T) /= T
5469 and then Interface_Present_In_Ancestor (Etype (T), Iface)
5470 then
5471 null;
5472 else
5473 Collect (Iface);
5474 Append_Unique_Elmt (Iface, Ifaces_List);
5475 end if;
5476 end if;
5478 Next (Id);
5479 end loop;
5480 end Collect;
5482 -- Start of processing for Collect_Interfaces
5484 begin
5485 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
5486 Ifaces_List := New_Elmt_List;
5487 Collect (T);
5488 end Collect_Interfaces;
5490 ----------------------------------
5491 -- Collect_Interface_Components --
5492 ----------------------------------
5494 procedure Collect_Interface_Components
5495 (Tagged_Type : Entity_Id;
5496 Components_List : out Elist_Id)
5498 procedure Collect (Typ : Entity_Id);
5499 -- Subsidiary subprogram used to climb to the parents
5501 -------------
5502 -- Collect --
5503 -------------
5505 procedure Collect (Typ : Entity_Id) is
5506 Tag_Comp : Entity_Id;
5507 Parent_Typ : Entity_Id;
5509 begin
5510 -- Handle private types
5512 if Present (Full_View (Etype (Typ))) then
5513 Parent_Typ := Full_View (Etype (Typ));
5514 else
5515 Parent_Typ := Etype (Typ);
5516 end if;
5518 if Parent_Typ /= Typ
5520 -- Protect the frontend against wrong sources. For example:
5522 -- package P is
5523 -- type A is tagged null record;
5524 -- type B is new A with private;
5525 -- type C is new A with private;
5526 -- private
5527 -- type B is new C with null record;
5528 -- type C is new B with null record;
5529 -- end P;
5531 and then Parent_Typ /= Tagged_Type
5532 then
5533 Collect (Parent_Typ);
5534 end if;
5536 -- Collect the components containing tags of secondary dispatch
5537 -- tables.
5539 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
5540 while Present (Tag_Comp) loop
5541 pragma Assert (Present (Related_Type (Tag_Comp)));
5542 Append_Elmt (Tag_Comp, Components_List);
5544 Tag_Comp := Next_Tag_Component (Tag_Comp);
5545 end loop;
5546 end Collect;
5548 -- Start of processing for Collect_Interface_Components
5550 begin
5551 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
5552 and then Is_Tagged_Type (Tagged_Type));
5554 Components_List := New_Elmt_List;
5555 Collect (Tagged_Type);
5556 end Collect_Interface_Components;
5558 -----------------------------
5559 -- Collect_Interfaces_Info --
5560 -----------------------------
5562 procedure Collect_Interfaces_Info
5563 (T : Entity_Id;
5564 Ifaces_List : out Elist_Id;
5565 Components_List : out Elist_Id;
5566 Tags_List : out Elist_Id)
5568 Comps_List : Elist_Id;
5569 Comp_Elmt : Elmt_Id;
5570 Comp_Iface : Entity_Id;
5571 Iface_Elmt : Elmt_Id;
5572 Iface : Entity_Id;
5574 function Search_Tag (Iface : Entity_Id) return Entity_Id;
5575 -- Search for the secondary tag associated with the interface type
5576 -- Iface that is implemented by T.
5578 ----------------
5579 -- Search_Tag --
5580 ----------------
5582 function Search_Tag (Iface : Entity_Id) return Entity_Id is
5583 ADT : Elmt_Id;
5584 begin
5585 if not Is_CPP_Class (T) then
5586 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
5587 else
5588 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
5589 end if;
5591 while Present (ADT)
5592 and then Is_Tag (Node (ADT))
5593 and then Related_Type (Node (ADT)) /= Iface
5594 loop
5595 -- Skip secondary dispatch table referencing thunks to user
5596 -- defined primitives covered by this interface.
5598 pragma Assert (Has_Suffix (Node (ADT), 'P'));
5599 Next_Elmt (ADT);
5601 -- Skip secondary dispatch tables of Ada types
5603 if not Is_CPP_Class (T) then
5605 -- Skip secondary dispatch table referencing thunks to
5606 -- predefined primitives.
5608 pragma Assert (Has_Suffix (Node (ADT), 'Y'));
5609 Next_Elmt (ADT);
5611 -- Skip secondary dispatch table referencing user-defined
5612 -- primitives covered by this interface.
5614 pragma Assert (Has_Suffix (Node (ADT), 'D'));
5615 Next_Elmt (ADT);
5617 -- Skip secondary dispatch table referencing predefined
5618 -- primitives.
5620 pragma Assert (Has_Suffix (Node (ADT), 'Z'));
5621 Next_Elmt (ADT);
5622 end if;
5623 end loop;
5625 pragma Assert (Is_Tag (Node (ADT)));
5626 return Node (ADT);
5627 end Search_Tag;
5629 -- Start of processing for Collect_Interfaces_Info
5631 begin
5632 Collect_Interfaces (T, Ifaces_List);
5633 Collect_Interface_Components (T, Comps_List);
5635 -- Search for the record component and tag associated with each
5636 -- interface type of T.
5638 Components_List := New_Elmt_List;
5639 Tags_List := New_Elmt_List;
5641 Iface_Elmt := First_Elmt (Ifaces_List);
5642 while Present (Iface_Elmt) loop
5643 Iface := Node (Iface_Elmt);
5645 -- Associate the primary tag component and the primary dispatch table
5646 -- with all the interfaces that are parents of T
5648 if Is_Ancestor (Iface, T, Use_Full_View => True) then
5649 Append_Elmt (First_Tag_Component (T), Components_List);
5650 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
5652 -- Otherwise search for the tag component and secondary dispatch
5653 -- table of Iface
5655 else
5656 Comp_Elmt := First_Elmt (Comps_List);
5657 while Present (Comp_Elmt) loop
5658 Comp_Iface := Related_Type (Node (Comp_Elmt));
5660 if Comp_Iface = Iface
5661 or else Is_Ancestor (Iface, Comp_Iface, Use_Full_View => True)
5662 then
5663 Append_Elmt (Node (Comp_Elmt), Components_List);
5664 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
5665 exit;
5666 end if;
5668 Next_Elmt (Comp_Elmt);
5669 end loop;
5670 pragma Assert (Present (Comp_Elmt));
5671 end if;
5673 Next_Elmt (Iface_Elmt);
5674 end loop;
5675 end Collect_Interfaces_Info;
5677 ---------------------
5678 -- Collect_Parents --
5679 ---------------------
5681 procedure Collect_Parents
5682 (T : Entity_Id;
5683 List : out Elist_Id;
5684 Use_Full_View : Boolean := True)
5686 Current_Typ : Entity_Id := T;
5687 Parent_Typ : Entity_Id;
5689 begin
5690 List := New_Elmt_List;
5692 -- No action if the if the type has no parents
5694 if T = Etype (T) then
5695 return;
5696 end if;
5698 loop
5699 Parent_Typ := Etype (Current_Typ);
5701 if Is_Private_Type (Parent_Typ)
5702 and then Present (Full_View (Parent_Typ))
5703 and then Use_Full_View
5704 then
5705 Parent_Typ := Full_View (Base_Type (Parent_Typ));
5706 end if;
5708 Append_Elmt (Parent_Typ, List);
5710 exit when Parent_Typ = Current_Typ;
5711 Current_Typ := Parent_Typ;
5712 end loop;
5713 end Collect_Parents;
5715 ----------------------------------
5716 -- Collect_Primitive_Operations --
5717 ----------------------------------
5719 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
5720 B_Type : constant Entity_Id := Base_Type (T);
5722 function Match (E : Entity_Id) return Boolean;
5723 -- True if E's base type is B_Type, or E is of an anonymous access type
5724 -- and the base type of its designated type is B_Type.
5726 -----------
5727 -- Match --
5728 -----------
5730 function Match (E : Entity_Id) return Boolean is
5731 Etyp : Entity_Id := Etype (E);
5733 begin
5734 if Ekind (Etyp) = E_Anonymous_Access_Type then
5735 Etyp := Designated_Type (Etyp);
5736 end if;
5738 -- In Ada 2012 a primitive operation may have a formal of an
5739 -- incomplete view of the parent type.
5741 return Base_Type (Etyp) = B_Type
5742 or else
5743 (Ada_Version >= Ada_2012
5744 and then Ekind (Etyp) = E_Incomplete_Type
5745 and then Full_View (Etyp) = B_Type);
5746 end Match;
5748 -- Local variables
5750 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
5751 B_Scope : Entity_Id := Scope (B_Type);
5752 Op_List : Elist_Id;
5753 Eq_Prims_List : Elist_Id := No_Elist;
5754 Formal : Entity_Id;
5755 Is_Prim : Boolean;
5756 Is_Type_In_Pkg : Boolean;
5757 Formal_Derived : Boolean := False;
5758 Id : Entity_Id;
5760 -- Start of processing for Collect_Primitive_Operations
5762 begin
5763 -- For tagged types, the primitive operations are collected as they
5764 -- are declared, and held in an explicit list which is simply returned.
5766 if Is_Tagged_Type (B_Type) then
5767 return Primitive_Operations (B_Type);
5769 -- An untagged generic type that is a derived type inherits the
5770 -- primitive operations of its parent type. Other formal types only
5771 -- have predefined operators, which are not explicitly represented.
5773 elsif Is_Generic_Type (B_Type) then
5774 if Nkind (B_Decl) = N_Formal_Type_Declaration
5775 and then Nkind (Formal_Type_Definition (B_Decl)) =
5776 N_Formal_Derived_Type_Definition
5777 then
5778 Formal_Derived := True;
5779 else
5780 return New_Elmt_List;
5781 end if;
5782 end if;
5784 Op_List := New_Elmt_List;
5786 if B_Scope = Standard_Standard then
5787 if B_Type = Standard_String then
5788 Append_Elmt (Standard_Op_Concat, Op_List);
5790 elsif B_Type = Standard_Wide_String then
5791 Append_Elmt (Standard_Op_Concatw, Op_List);
5793 else
5794 null;
5795 end if;
5797 -- Locate the primitive subprograms of the type
5799 else
5800 -- The primitive operations appear after the base type, except if the
5801 -- derivation happens within the private part of B_Scope and the type
5802 -- is a private type, in which case both the type and some primitive
5803 -- operations may appear before the base type, and the list of
5804 -- candidates starts after the type.
5806 if In_Open_Scopes (B_Scope)
5807 and then Scope (T) = B_Scope
5808 and then In_Private_Part (B_Scope)
5809 then
5810 Id := Next_Entity (T);
5812 -- In Ada 2012, If the type has an incomplete partial view, there may
5813 -- be primitive operations declared before the full view, so we need
5814 -- to start scanning from the incomplete view, which is earlier on
5815 -- the entity chain.
5817 elsif Nkind (Parent (B_Type)) = N_Full_Type_Declaration
5818 and then Present (Incomplete_View (Parent (B_Type)))
5819 then
5820 Id := Incomplete_View (Parent (B_Type));
5822 -- If T is a derived from a type with an incomplete view declared
5823 -- elsewhere, that incomplete view is irrelevant, we want the
5824 -- operations in the scope of T.
5826 if Scope (Id) /= Scope (B_Type) then
5827 Id := Next_Entity (B_Type);
5828 end if;
5830 else
5831 Id := Next_Entity (B_Type);
5832 end if;
5834 -- Set flag if this is a type in a package spec
5836 Is_Type_In_Pkg :=
5837 Is_Package_Or_Generic_Package (B_Scope)
5838 and then
5839 Parent_Kind (Declaration_Node (First_Subtype (T))) /=
5840 N_Package_Body;
5842 while Present (Id) loop
5844 -- Test whether the result type or any of the parameter types of
5845 -- each subprogram following the type match that type when the
5846 -- type is declared in a package spec, is a derived type, or the
5847 -- subprogram is marked as primitive. (The Is_Primitive test is
5848 -- needed to find primitives of nonderived types in declarative
5849 -- parts that happen to override the predefined "=" operator.)
5851 -- Note that generic formal subprograms are not considered to be
5852 -- primitive operations and thus are never inherited.
5854 if Is_Overloadable (Id)
5855 and then (Is_Type_In_Pkg
5856 or else Is_Derived_Type (B_Type)
5857 or else Is_Primitive (Id))
5858 and then Parent_Kind (Parent (Id))
5859 not in N_Formal_Subprogram_Declaration
5860 then
5861 Is_Prim := False;
5863 if Match (Id) then
5864 Is_Prim := True;
5866 else
5867 Formal := First_Formal (Id);
5868 while Present (Formal) loop
5869 if Match (Formal) then
5870 Is_Prim := True;
5871 exit;
5872 end if;
5874 Next_Formal (Formal);
5875 end loop;
5876 end if;
5878 -- For a formal derived type, the only primitives are the ones
5879 -- inherited from the parent type. Operations appearing in the
5880 -- package declaration are not primitive for it.
5882 if Is_Prim
5883 and then (not Formal_Derived or else Present (Alias (Id)))
5884 then
5885 -- In the special case of an equality operator aliased to
5886 -- an overriding dispatching equality belonging to the same
5887 -- type, we don't include it in the list of primitives.
5888 -- This avoids inheriting multiple equality operators when
5889 -- deriving from untagged private types whose full type is
5890 -- tagged, which can otherwise cause ambiguities. Note that
5891 -- this should only happen for this kind of untagged parent
5892 -- type, since normally dispatching operations are inherited
5893 -- using the type's Primitive_Operations list.
5895 if Chars (Id) = Name_Op_Eq
5896 and then Is_Dispatching_Operation (Id)
5897 and then Present (Alias (Id))
5898 and then Present (Overridden_Operation (Alias (Id)))
5899 and then Base_Type (Etype (First_Entity (Id))) =
5900 Base_Type (Etype (First_Entity (Alias (Id))))
5901 then
5902 null;
5904 -- Include the subprogram in the list of primitives
5906 else
5907 Append_Elmt (Id, Op_List);
5909 -- Save collected equality primitives for later filtering
5910 -- (if we are processing a private type for which we can
5911 -- collect several candidates).
5913 if Inherits_From_Tagged_Full_View (T)
5914 and then Chars (Id) = Name_Op_Eq
5915 and then Etype (First_Formal (Id)) =
5916 Etype (Next_Formal (First_Formal (Id)))
5917 then
5918 Append_New_Elmt (Id, Eq_Prims_List);
5919 end if;
5920 end if;
5921 end if;
5922 end if;
5924 Next_Entity (Id);
5926 -- For a type declared in System, some of its operations may
5927 -- appear in the target-specific extension to System.
5929 if No (Id)
5930 and then Is_RTU (B_Scope, System)
5931 and then Present_System_Aux
5932 then
5933 B_Scope := System_Aux_Id;
5934 Id := First_Entity (System_Aux_Id);
5935 end if;
5936 end loop;
5938 -- Filter collected equality primitives
5940 if Inherits_From_Tagged_Full_View (T)
5941 and then Present (Eq_Prims_List)
5942 then
5943 declare
5944 First : constant Elmt_Id := First_Elmt (Eq_Prims_List);
5945 Second : Elmt_Id;
5947 begin
5948 pragma Assert (No (Next_Elmt (First))
5949 or else No (Next_Elmt (Next_Elmt (First))));
5951 -- No action needed if we have collected a single equality
5952 -- primitive
5954 if Present (Next_Elmt (First)) then
5955 Second := Next_Elmt (First);
5957 if Is_Dispatching_Operation
5958 (Ultimate_Alias (Node (First)))
5959 then
5960 Remove (Op_List, Node (First));
5962 elsif Is_Dispatching_Operation
5963 (Ultimate_Alias (Node (Second)))
5964 then
5965 Remove (Op_List, Node (Second));
5967 else
5968 raise Program_Error;
5969 end if;
5970 end if;
5971 end;
5972 end if;
5973 end if;
5975 return Op_List;
5976 end Collect_Primitive_Operations;
5978 -----------------------------------
5979 -- Compile_Time_Constraint_Error --
5980 -----------------------------------
5982 function Compile_Time_Constraint_Error
5983 (N : Node_Id;
5984 Msg : String;
5985 Ent : Entity_Id := Empty;
5986 Loc : Source_Ptr := No_Location;
5987 Warn : Boolean := False;
5988 Extra_Msg : String := "") return Node_Id
5990 Msgc : String (1 .. Msg'Length + 3);
5991 -- Copy of message, with room for possible ?? or << and ! at end
5993 Msgl : Natural;
5994 Wmsg : Boolean;
5995 Eloc : Source_Ptr;
5997 begin
5998 -- If this is a warning, convert it into an error if we are in code
5999 -- subject to SPARK_Mode being set On, unless Warn is True to force a
6000 -- warning. The rationale is that a compile-time constraint error should
6001 -- lead to an error instead of a warning when SPARK_Mode is On, but in
6002 -- a few cases we prefer to issue a warning and generate both a suitable
6003 -- run-time error in GNAT and a suitable check message in GNATprove.
6004 -- Those cases are those that likely correspond to deactivated SPARK
6005 -- code, so that this kind of code can be compiled and analyzed instead
6006 -- of being rejected.
6008 Error_Msg_Warn := Warn or SPARK_Mode /= On;
6010 -- A static constraint error in an instance body is not a fatal error.
6011 -- We choose to inhibit the message altogether, because there is no
6012 -- obvious node (for now) on which to post it. On the other hand the
6013 -- offending node must be replaced with a constraint_error in any case.
6015 -- No messages are generated if we already posted an error on this node
6017 if not Error_Posted (N) then
6018 if Loc /= No_Location then
6019 Eloc := Loc;
6020 else
6021 Eloc := Sloc (N);
6022 end if;
6024 -- Copy message to Msgc, converting any ? in the message into <
6025 -- instead, so that we have an error in GNATprove mode.
6027 Msgl := Msg'Length;
6029 for J in 1 .. Msgl loop
6030 if Msg (J) = '?' and then (J = 1 or else Msg (J - 1) /= ''') then
6031 Msgc (J) := '<';
6032 else
6033 Msgc (J) := Msg (J);
6034 end if;
6035 end loop;
6037 -- Message is a warning, even in Ada 95 case
6039 if Msg (Msg'Last) = '?' or else Msg (Msg'Last) = '<' then
6040 Wmsg := True;
6042 -- In Ada 83, all messages are warnings. In the private part and the
6043 -- body of an instance, constraint_checks are only warnings. We also
6044 -- make this a warning if the Warn parameter is set.
6046 elsif Warn
6047 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
6048 or else In_Instance_Not_Visible
6049 then
6050 Msgl := Msgl + 1;
6051 Msgc (Msgl) := '<';
6052 Msgl := Msgl + 1;
6053 Msgc (Msgl) := '<';
6054 Wmsg := True;
6056 -- Otherwise we have a real error message (Ada 95 static case) and we
6057 -- make this an unconditional message. Note that in the warning case
6058 -- we do not make the message unconditional, it seems reasonable to
6059 -- delete messages like this (about exceptions that will be raised)
6060 -- in dead code.
6062 else
6063 Wmsg := False;
6064 Msgl := Msgl + 1;
6065 Msgc (Msgl) := '!';
6066 end if;
6068 -- One more test, skip the warning if the related expression is
6069 -- statically unevaluated, since we don't want to warn about what
6070 -- will happen when something is evaluated if it never will be
6071 -- evaluated.
6073 -- Suppress error reporting when checking that the expression of a
6074 -- static expression function is a potentially static expression,
6075 -- because we don't want additional errors being reported during the
6076 -- preanalysis of the expression (see Analyze_Expression_Function).
6078 if not Is_Statically_Unevaluated (N)
6079 and then not Checking_Potentially_Static_Expression
6080 then
6081 if Present (Ent) then
6082 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
6083 else
6084 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
6085 end if;
6087 -- Emit any extra message as a continuation
6089 if Extra_Msg /= "" then
6090 Error_Msg_N ('\' & Extra_Msg, N);
6091 end if;
6093 if Wmsg then
6095 -- Check whether the context is an Init_Proc
6097 if Inside_Init_Proc then
6098 declare
6099 Init_Proc_Type : constant Entity_Id :=
6100 Etype (First_Formal (Current_Scope_No_Loops));
6102 Conc_Typ : constant Entity_Id :=
6103 (if Present (Init_Proc_Type)
6104 and then Init_Proc_Type in E_Record_Type_Id
6105 then Corresponding_Concurrent_Type (Init_Proc_Type)
6106 else Empty);
6108 begin
6109 -- Don't complain if the corresponding concurrent type
6110 -- doesn't come from source (i.e. a single task/protected
6111 -- object).
6113 if Present (Conc_Typ)
6114 and then not Comes_From_Source (Conc_Typ)
6115 then
6116 Error_Msg ("\& [<<", Eloc, N);
6118 else
6119 if GNATprove_Mode then
6120 Error_Msg
6121 ("\Constraint_Error would have been raised"
6122 & " for objects of this type", Eloc, N);
6123 else
6124 Error_Msg
6125 ("\Constraint_Error will be raised"
6126 & " for objects of this type??", Eloc, N);
6127 end if;
6128 end if;
6129 end;
6131 else
6132 Error_Msg ("\Constraint_Error [<<", Eloc, N);
6133 end if;
6135 else
6136 Error_Msg ("\static expression fails Constraint_Check", Eloc);
6137 Set_Error_Posted (N);
6138 end if;
6139 end if;
6140 end if;
6142 return N;
6143 end Compile_Time_Constraint_Error;
6145 ----------------------------
6146 -- Compute_Returns_By_Ref --
6147 ----------------------------
6149 procedure Compute_Returns_By_Ref (Func : Entity_Id) is
6150 Kind : constant Entity_Kind := Ekind (Func);
6151 Typ : constant Entity_Id := Etype (Func);
6153 begin
6154 -- Nothing to do for procedures
6156 if Kind in E_Procedure | E_Generic_Procedure
6157 or else (Kind = E_Subprogram_Type and then Typ = Standard_Void_Type)
6158 then
6159 null;
6161 -- The build-in-place protocols return a reference to the result
6163 elsif Is_Build_In_Place_Function (Func) then
6164 Set_Returns_By_Ref (Func);
6166 -- In Ada 95, limited types are returned by reference
6168 elsif Is_Limited_View (Typ) then
6169 Set_Returns_By_Ref (Func);
6170 end if;
6171 end Compute_Returns_By_Ref;
6173 --------------------------------
6174 -- Collect_Types_In_Hierarchy --
6175 --------------------------------
6177 function Collect_Types_In_Hierarchy
6178 (Typ : Entity_Id;
6179 Examine_Components : Boolean := False) return Elist_Id
6181 Results : Elist_Id;
6183 procedure Process_Type (Typ : Entity_Id);
6184 -- Collect type Typ if it satisfies function Predicate. Do so for its
6185 -- parent type, base type, progenitor types, and any component types.
6187 ------------------
6188 -- Process_Type --
6189 ------------------
6191 procedure Process_Type (Typ : Entity_Id) is
6192 Comp : Entity_Id;
6193 Iface_Elmt : Elmt_Id;
6195 begin
6196 if not Is_Type (Typ) or else Error_Posted (Typ) then
6197 return;
6198 end if;
6200 -- Collect the current type if it satisfies the predicate
6202 if Predicate (Typ) then
6203 Append_Elmt (Typ, Results);
6204 end if;
6206 -- Process component types
6208 if Examine_Components then
6210 -- Examine components and discriminants
6212 if Is_Concurrent_Type (Typ)
6213 or else Is_Incomplete_Or_Private_Type (Typ)
6214 or else Is_Record_Type (Typ)
6215 or else Has_Discriminants (Typ)
6216 then
6217 Comp := First_Component_Or_Discriminant (Typ);
6219 while Present (Comp) loop
6220 Process_Type (Etype (Comp));
6222 Next_Component_Or_Discriminant (Comp);
6223 end loop;
6225 -- Examine array components
6227 elsif Ekind (Typ) = E_Array_Type then
6228 Process_Type (Component_Type (Typ));
6229 end if;
6230 end if;
6232 -- Examine parent type
6234 if Etype (Typ) /= Typ then
6235 Process_Type (Etype (Typ));
6236 end if;
6238 -- Examine base type
6240 if Base_Type (Typ) /= Typ then
6241 Process_Type (Base_Type (Typ));
6242 end if;
6244 -- Examine interfaces
6246 if Is_Record_Type (Typ)
6247 and then Present (Interfaces (Typ))
6248 then
6249 Iface_Elmt := First_Elmt (Interfaces (Typ));
6250 while Present (Iface_Elmt) loop
6251 Process_Type (Node (Iface_Elmt));
6253 Next_Elmt (Iface_Elmt);
6254 end loop;
6255 end if;
6256 end Process_Type;
6258 -- Start of processing for Collect_Types_In_Hierarchy
6260 begin
6261 Results := New_Elmt_List;
6262 Process_Type (Typ);
6263 return Results;
6264 end Collect_Types_In_Hierarchy;
6266 -----------------------
6267 -- Conditional_Delay --
6268 -----------------------
6270 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
6271 begin
6272 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
6273 Set_Has_Delayed_Freeze (New_Ent);
6274 end if;
6275 end Conditional_Delay;
6277 -------------------------
6278 -- Copy_Component_List --
6279 -------------------------
6281 function Copy_Component_List
6282 (R_Typ : Entity_Id;
6283 Loc : Source_Ptr) return List_Id
6285 Comp : Node_Id;
6286 Comps : constant List_Id := New_List;
6288 begin
6289 Comp := First_Component (Underlying_Type (R_Typ));
6290 while Present (Comp) loop
6291 if Comes_From_Source (Comp) then
6292 declare
6293 Comp_Decl : constant Node_Id := Declaration_Node (Comp);
6294 begin
6295 Append_To (Comps,
6296 Make_Component_Declaration (Loc,
6297 Defining_Identifier =>
6298 Make_Defining_Identifier (Loc, Chars (Comp)),
6299 Component_Definition =>
6300 New_Copy_Tree
6301 (Component_Definition (Comp_Decl), New_Sloc => Loc)));
6302 end;
6303 end if;
6305 Next_Component (Comp);
6306 end loop;
6308 return Comps;
6309 end Copy_Component_List;
6311 -----------------------
6312 -- Copy_Ghost_Aspect --
6313 -----------------------
6315 procedure Copy_Ghost_Aspect (From : Node_Id; To : Node_Id) is
6316 pragma Assert (not Has_Aspects (To));
6317 Asp : Node_Id;
6319 begin
6320 if Has_Aspects (From) then
6321 Asp := Find_Aspect (Defining_Entity (From), Aspect_Ghost);
6323 if Present (Asp) then
6324 Set_Aspect_Specifications (To, New_List (New_Copy_Tree (Asp)));
6325 end if;
6326 end if;
6327 end Copy_Ghost_Aspect;
6329 -------------------------
6330 -- Copy_Parameter_List --
6331 -------------------------
6333 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
6334 Loc : constant Source_Ptr := Sloc (Subp_Id);
6335 Plist : List_Id;
6336 Formal : Entity_Id := First_Formal (Subp_Id);
6338 begin
6339 if Present (Formal) then
6340 Plist := New_List;
6341 while Present (Formal) loop
6342 Append_To (Plist,
6343 Make_Parameter_Specification (Loc,
6344 Defining_Identifier =>
6345 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)),
6346 In_Present => In_Present (Parent (Formal)),
6347 Out_Present => Out_Present (Parent (Formal)),
6348 Parameter_Type =>
6349 New_Occurrence_Of (Etype (Formal), Loc),
6350 Expression =>
6351 New_Copy_Tree (Expression (Parent (Formal)))));
6353 Next_Formal (Formal);
6354 end loop;
6355 else
6356 Plist := No_List;
6357 end if;
6359 return Plist;
6360 end Copy_Parameter_List;
6362 ----------------------------
6363 -- Copy_SPARK_Mode_Aspect --
6364 ----------------------------
6366 procedure Copy_SPARK_Mode_Aspect (From : Node_Id; To : Node_Id) is
6367 pragma Assert (not Has_Aspects (To));
6368 Asp : Node_Id;
6370 begin
6371 if Has_Aspects (From) then
6372 Asp := Find_Aspect (Defining_Entity (From), Aspect_SPARK_Mode);
6374 if Present (Asp) then
6375 Set_Aspect_Specifications (To, New_List (New_Copy_Tree (Asp)));
6376 end if;
6377 end if;
6378 end Copy_SPARK_Mode_Aspect;
6380 --------------------------
6381 -- Copy_Subprogram_Spec --
6382 --------------------------
6384 function Copy_Subprogram_Spec
6385 (Spec : Node_Id;
6386 New_Sloc : Source_Ptr := No_Location) return Node_Id
6388 Def_Id : Node_Id;
6389 Formal_Spec : Node_Id;
6390 Result : Node_Id;
6392 begin
6393 -- The structure of the original tree must be replicated without any
6394 -- alterations. Use New_Copy_Tree for this purpose.
6396 Result := New_Copy_Tree (Spec, New_Sloc => New_Sloc);
6398 -- However, the spec of a null procedure carries the corresponding null
6399 -- statement of the body (created by the parser), and this cannot be
6400 -- shared with the new subprogram spec.
6402 if Nkind (Result) = N_Procedure_Specification then
6403 Set_Null_Statement (Result, Empty);
6404 end if;
6406 -- Create a new entity for the defining unit name
6408 Def_Id := Defining_Unit_Name (Result);
6409 Set_Defining_Unit_Name (Result,
6410 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
6412 -- Create new entities for the formal parameters
6414 Formal_Spec := First (Parameter_Specifications (Result));
6415 while Present (Formal_Spec) loop
6416 Def_Id := Defining_Identifier (Formal_Spec);
6417 Set_Defining_Identifier (Formal_Spec,
6418 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
6420 Next (Formal_Spec);
6421 end loop;
6423 return Result;
6424 end Copy_Subprogram_Spec;
6426 --------------------------------
6427 -- Corresponding_Generic_Type --
6428 --------------------------------
6430 function Corresponding_Generic_Type (T : Entity_Id) return Entity_Id is
6431 Inst : Entity_Id;
6432 Gen : Entity_Id;
6433 Typ : Entity_Id;
6435 begin
6436 if not Is_Generic_Actual_Type (T) then
6437 return Any_Type;
6439 -- If the actual is the actual of an enclosing instance, resolution
6440 -- was correct in the generic.
6442 elsif Nkind (Parent (T)) = N_Subtype_Declaration
6443 and then Is_Entity_Name (Subtype_Indication (Parent (T)))
6444 and then
6445 Is_Generic_Actual_Type (Entity (Subtype_Indication (Parent (T))))
6446 then
6447 return Any_Type;
6449 else
6450 Inst := Scope (T);
6452 if Is_Wrapper_Package (Inst) then
6453 Inst := Related_Instance (Inst);
6454 end if;
6456 Gen :=
6457 Generic_Parent
6458 (Specification (Unit_Declaration_Node (Inst)));
6460 -- Generic actual has the same name as the corresponding formal
6462 Typ := First_Entity (Gen);
6463 while Present (Typ) loop
6464 if Chars (Typ) = Chars (T) then
6465 return Typ;
6466 end if;
6468 Next_Entity (Typ);
6469 end loop;
6471 return Any_Type;
6472 end if;
6473 end Corresponding_Generic_Type;
6475 --------------------------------
6476 -- Corresponding_Primitive_Op --
6477 --------------------------------
6479 function Corresponding_Primitive_Op
6480 (Ancestor_Op : Entity_Id;
6481 Descendant_Type : Entity_Id) return Entity_Id
6483 Typ : constant Entity_Id := Find_Dispatching_Type (Ancestor_Op);
6484 Elmt : Elmt_Id;
6485 Subp : Entity_Id;
6487 function Profile_Matches_Ancestor (S : Entity_Id) return Boolean;
6488 -- Returns True if subprogram S has the proper profile for an
6489 -- overriding of Ancestor_Op (that is, corresponding formals either
6490 -- have the same type, or are corresponding controlling formals,
6491 -- and similarly for result types).
6493 ------------------------------
6494 -- Profile_Matches_Ancestor --
6495 ------------------------------
6497 function Profile_Matches_Ancestor (S : Entity_Id) return Boolean is
6498 F1 : Entity_Id := First_Formal (Ancestor_Op);
6499 F2 : Entity_Id := First_Formal (S);
6501 begin
6502 if Ekind (Ancestor_Op) /= Ekind (S) then
6503 return False;
6504 end if;
6506 -- ??? This should probably account for anonymous access formals,
6507 -- but the parent function (Corresponding_Primitive_Op) is currently
6508 -- only called for user-defined literal functions, which can't have
6509 -- such formals. But if this is ever used in a more general context
6510 -- it should be extended to handle such formals (and result types).
6512 while Present (F1) and then Present (F2) loop
6513 if Etype (F1) = Etype (F2)
6514 or else Is_Ancestor (Typ, Etype (F2))
6515 then
6516 Next_Formal (F1);
6517 Next_Formal (F2);
6518 else
6519 return False;
6520 end if;
6521 end loop;
6523 return No (F1)
6524 and then No (F2)
6525 and then (Etype (Ancestor_Op) = Etype (S)
6526 or else Is_Ancestor (Typ, Etype (S)));
6527 end Profile_Matches_Ancestor;
6529 -- Start of processing for Corresponding_Primitive_Op
6531 begin
6532 pragma Assert (Is_Dispatching_Operation (Ancestor_Op));
6533 pragma Assert (Is_Ancestor (Typ, Descendant_Type)
6534 or else Is_Progenitor (Typ, Descendant_Type));
6536 Elmt := First_Elmt (Primitive_Operations (Descendant_Type));
6538 while Present (Elmt) loop
6539 Subp := Node (Elmt);
6541 -- For regular primitives we need to check the profile against
6542 -- the ancestor when the name matches the name of Ancestor_Op,
6543 -- but for predefined dispatching operations we cannot rely on
6544 -- the name of the primitive to identify a candidate since their
6545 -- name is internally built by adding a suffix to the name of the
6546 -- tagged type.
6548 if Chars (Subp) = Chars (Ancestor_Op)
6549 or else Is_Predefined_Dispatching_Operation (Subp)
6550 then
6551 -- Handle case where Ancestor_Op is a primitive of a progenitor.
6552 -- We rely on internal entities that map interface primitives:
6553 -- their attribute Interface_Alias references the interface
6554 -- primitive, and their Alias attribute references the primitive
6555 -- of Descendant_Type implementing that interface primitive.
6557 if Present (Interface_Alias (Subp)) then
6558 if Interface_Alias (Subp) = Ancestor_Op then
6559 return Alias (Subp);
6560 end if;
6562 -- Otherwise, return subprogram when profile matches its ancestor
6564 elsif Profile_Matches_Ancestor (Subp) then
6565 return Subp;
6566 end if;
6567 end if;
6569 Next_Elmt (Elmt);
6570 end loop;
6572 pragma Assert (False);
6573 return Empty;
6574 end Corresponding_Primitive_Op;
6576 --------------------
6577 -- Current_Entity --
6578 --------------------
6580 -- The currently visible definition for a given identifier is the
6581 -- one most chained at the start of the visibility chain, i.e. the
6582 -- one that is referenced by the Node_Id value of the name of the
6583 -- given identifier.
6585 function Current_Entity (N : Node_Id) return Entity_Id is
6586 begin
6587 return Get_Name_Entity_Id (Chars (N));
6588 end Current_Entity;
6590 -----------------------------
6591 -- Current_Entity_In_Scope --
6592 -----------------------------
6594 function Current_Entity_In_Scope (N : Name_Id) return Entity_Id is
6595 CS : constant Entity_Id := Current_Scope;
6597 E : Entity_Id;
6599 begin
6600 E := Get_Name_Entity_Id (N);
6602 if No (E) then
6603 null;
6605 elsif Scope_Is_Transient then
6606 while Present (E) loop
6607 exit when Scope (E) = CS or else Scope (E) = Scope (CS);
6609 E := Homonym (E);
6610 end loop;
6612 else
6613 while Present (E) loop
6614 exit when Scope (E) = CS;
6616 E := Homonym (E);
6617 end loop;
6618 end if;
6620 return E;
6621 end Current_Entity_In_Scope;
6623 -----------------------------
6624 -- Current_Entity_In_Scope --
6625 -----------------------------
6627 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
6628 begin
6629 return Current_Entity_In_Scope (Chars (N));
6630 end Current_Entity_In_Scope;
6632 -------------------
6633 -- Current_Scope --
6634 -------------------
6636 function Current_Scope return Entity_Id is
6637 begin
6638 if Scope_Stack.Last = -1 then
6639 return Standard_Standard;
6640 else
6641 declare
6642 C : constant Entity_Id :=
6643 Scope_Stack.Table (Scope_Stack.Last).Entity;
6644 begin
6645 if Present (C) then
6646 return C;
6647 else
6648 return Standard_Standard;
6649 end if;
6650 end;
6651 end if;
6652 end Current_Scope;
6654 ----------------------------
6655 -- Current_Scope_No_Loops --
6656 ----------------------------
6658 function Current_Scope_No_Loops return Entity_Id is
6659 S : Entity_Id;
6661 begin
6662 -- Examine the scope stack starting from the current scope and skip any
6663 -- internally generated loops.
6665 S := Current_Scope;
6666 while Present (S) and then S /= Standard_Standard loop
6667 if Ekind (S) = E_Loop and then not Comes_From_Source (S) then
6668 S := Scope (S);
6669 else
6670 exit;
6671 end if;
6672 end loop;
6674 return S;
6675 end Current_Scope_No_Loops;
6677 ------------------------
6678 -- Current_Subprogram --
6679 ------------------------
6681 function Current_Subprogram return Entity_Id is
6682 Scop : constant Entity_Id := Current_Scope;
6683 begin
6684 if Is_Subprogram_Or_Generic_Subprogram (Scop) then
6685 return Scop;
6686 else
6687 return Enclosing_Subprogram (Scop);
6688 end if;
6689 end Current_Subprogram;
6691 ------------------------------
6692 -- CW_Or_Needs_Finalization --
6693 ------------------------------
6695 function CW_Or_Needs_Finalization (Typ : Entity_Id) return Boolean is
6696 begin
6697 return Is_Class_Wide_Type (Typ) or else Needs_Finalization (Typ);
6698 end CW_Or_Needs_Finalization;
6700 ---------------------
6701 -- Defining_Entity --
6702 ---------------------
6704 function Defining_Entity (N : Node_Id) return Entity_Id is
6705 Ent : constant Entity_Id := Defining_Entity_Or_Empty (N);
6707 begin
6708 if Present (Ent) then
6709 return Ent;
6711 else
6712 raise Program_Error;
6713 end if;
6714 end Defining_Entity;
6716 ------------------------------
6717 -- Defining_Entity_Or_Empty --
6718 ------------------------------
6720 function Defining_Entity_Or_Empty (N : Node_Id) return Entity_Id is
6721 begin
6722 case Nkind (N) is
6723 when N_Abstract_Subprogram_Declaration
6724 | N_Expression_Function
6725 | N_Formal_Subprogram_Declaration
6726 | N_Generic_Package_Declaration
6727 | N_Generic_Subprogram_Declaration
6728 | N_Package_Declaration
6729 | N_Subprogram_Body
6730 | N_Subprogram_Body_Stub
6731 | N_Subprogram_Declaration
6732 | N_Subprogram_Renaming_Declaration
6734 return Defining_Entity (Specification (N));
6736 when N_Component_Declaration
6737 | N_Defining_Program_Unit_Name
6738 | N_Discriminant_Specification
6739 | N_Entry_Body
6740 | N_Entry_Declaration
6741 | N_Entry_Index_Specification
6742 | N_Exception_Declaration
6743 | N_Exception_Renaming_Declaration
6744 | N_Formal_Object_Declaration
6745 | N_Formal_Package_Declaration
6746 | N_Formal_Type_Declaration
6747 | N_Full_Type_Declaration
6748 | N_Implicit_Label_Declaration
6749 | N_Incomplete_Type_Declaration
6750 | N_Iterator_Specification
6751 | N_Loop_Parameter_Specification
6752 | N_Number_Declaration
6753 | N_Object_Declaration
6754 | N_Object_Renaming_Declaration
6755 | N_Package_Body_Stub
6756 | N_Parameter_Specification
6757 | N_Private_Extension_Declaration
6758 | N_Private_Type_Declaration
6759 | N_Protected_Body
6760 | N_Protected_Body_Stub
6761 | N_Protected_Type_Declaration
6762 | N_Single_Protected_Declaration
6763 | N_Single_Task_Declaration
6764 | N_Subtype_Declaration
6765 | N_Task_Body
6766 | N_Task_Body_Stub
6767 | N_Task_Type_Declaration
6769 return Defining_Identifier (N);
6771 when N_Compilation_Unit =>
6772 return Defining_Entity (Unit (N));
6774 when N_Subunit =>
6775 return Defining_Entity (Proper_Body (N));
6777 when N_Function_Instantiation
6778 | N_Function_Specification
6779 | N_Generic_Function_Renaming_Declaration
6780 | N_Generic_Package_Renaming_Declaration
6781 | N_Generic_Procedure_Renaming_Declaration
6782 | N_Package_Body
6783 | N_Package_Instantiation
6784 | N_Package_Renaming_Declaration
6785 | N_Package_Specification
6786 | N_Procedure_Instantiation
6787 | N_Procedure_Specification
6789 declare
6790 Nam : constant Node_Id := Defining_Unit_Name (N);
6791 Err : Entity_Id := Empty;
6793 begin
6794 if Nkind (Nam) in N_Entity then
6795 return Nam;
6797 -- For Error, make up a name and attach to declaration so we
6798 -- can continue semantic analysis.
6800 elsif Nam = Error then
6801 Err := Make_Temporary (Sloc (N), 'T');
6802 Set_Defining_Unit_Name (N, Err);
6804 return Err;
6806 -- If not an entity, get defining identifier
6808 else
6809 return Defining_Identifier (Nam);
6810 end if;
6811 end;
6813 when N_Block_Statement
6814 | N_Loop_Statement
6816 return Entity (Identifier (N));
6818 when others =>
6819 return Empty;
6820 end case;
6821 end Defining_Entity_Or_Empty;
6823 --------------------------
6824 -- Denotes_Discriminant --
6825 --------------------------
6827 function Denotes_Discriminant
6828 (N : Node_Id;
6829 Check_Concurrent : Boolean := False) return Boolean
6831 E : Entity_Id;
6833 begin
6834 if not Is_Entity_Name (N) or else No (Entity (N)) then
6835 return False;
6836 else
6837 E := Entity (N);
6838 end if;
6840 -- If we are checking for a protected type, the discriminant may have
6841 -- been rewritten as the corresponding discriminal of the original type
6842 -- or of the corresponding concurrent record, depending on whether we
6843 -- are in the spec or body of the protected type.
6845 return Ekind (E) = E_Discriminant
6846 or else
6847 (Check_Concurrent
6848 and then Ekind (E) = E_In_Parameter
6849 and then Present (Discriminal_Link (E))
6850 and then
6851 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
6852 or else
6853 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
6854 end Denotes_Discriminant;
6856 -------------------------
6857 -- Denotes_Same_Object --
6858 -------------------------
6860 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
6861 function Is_Object_Renaming (N : Node_Id) return Boolean;
6862 -- Return true if N names an object renaming entity
6864 function Is_Valid_Renaming (N : Node_Id) return Boolean;
6865 -- For renamings, return False if the prefix of any dereference within
6866 -- the renamed object_name is a variable, or any expression within the
6867 -- renamed object_name contains references to variables or calls on
6868 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
6870 ------------------------
6871 -- Is_Object_Renaming --
6872 ------------------------
6874 function Is_Object_Renaming (N : Node_Id) return Boolean is
6875 begin
6876 return Is_Entity_Name (N)
6877 and then Ekind (Entity (N)) in E_Variable | E_Constant
6878 and then Present (Renamed_Object (Entity (N)));
6879 end Is_Object_Renaming;
6881 -----------------------
6882 -- Is_Valid_Renaming --
6883 -----------------------
6885 function Is_Valid_Renaming (N : Node_Id) return Boolean is
6886 begin
6887 if Is_Object_Renaming (N)
6888 and then not Is_Valid_Renaming (Renamed_Object (Entity (N)))
6889 then
6890 return False;
6891 end if;
6893 -- Check if any expression within the renamed object_name contains no
6894 -- references to variables nor calls on nonstatic functions.
6896 if Nkind (N) = N_Indexed_Component then
6897 declare
6898 Indx : Node_Id;
6900 begin
6901 Indx := First (Expressions (N));
6902 while Present (Indx) loop
6903 if not Is_OK_Static_Expression (Indx) then
6904 return False;
6905 end if;
6907 Next (Indx);
6908 end loop;
6909 end;
6911 elsif Nkind (N) = N_Slice then
6912 declare
6913 Rng : constant Node_Id := Discrete_Range (N);
6914 begin
6915 -- Bounds specified as a range
6917 if Nkind (Rng) = N_Range then
6918 if not Is_OK_Static_Range (Rng) then
6919 return False;
6920 end if;
6922 -- Bounds specified as a constrained subtype indication
6924 elsif Nkind (Rng) = N_Subtype_Indication then
6925 if not Is_OK_Static_Range
6926 (Range_Expression (Constraint (Rng)))
6927 then
6928 return False;
6929 end if;
6931 -- Bounds specified as a subtype name
6933 elsif not Is_OK_Static_Expression (Rng) then
6934 return False;
6935 end if;
6936 end;
6937 end if;
6939 if Has_Prefix (N) then
6940 declare
6941 P : constant Node_Id := Prefix (N);
6943 begin
6944 if Nkind (N) = N_Explicit_Dereference
6945 and then Is_Variable (P)
6946 then
6947 return False;
6949 elsif Is_Entity_Name (P)
6950 and then Ekind (Entity (P)) = E_Function
6951 then
6952 return False;
6954 elsif Nkind (P) = N_Function_Call then
6955 return False;
6956 end if;
6958 -- Recursion to continue traversing the prefix of the
6959 -- renaming expression
6961 return Is_Valid_Renaming (P);
6962 end;
6963 end if;
6965 return True;
6966 end Is_Valid_Renaming;
6968 -- Start of processing for Denotes_Same_Object
6970 begin
6971 -- Both names statically denote the same stand-alone object or
6972 -- parameter (RM 6.4.1(6.6/3)).
6974 if Is_Entity_Name (A1)
6975 and then Is_Entity_Name (A2)
6976 and then Entity (A1) = Entity (A2)
6977 then
6978 return True;
6980 -- Both names are selected_components, their prefixes are known to
6981 -- denote the same object, and their selector_names denote the same
6982 -- component (RM 6.4.1(6.7/3)).
6984 elsif Nkind (A1) = N_Selected_Component
6985 and then Nkind (A2) = N_Selected_Component
6986 then
6987 return Denotes_Same_Object (Prefix (A1), Prefix (A2))
6988 and then
6989 Entity (Selector_Name (A1)) = Entity (Selector_Name (A2));
6991 -- Both names are dereferences and the dereferenced names are known to
6992 -- denote the same object (RM 6.4.1(6.8/3)).
6994 elsif Nkind (A1) = N_Explicit_Dereference
6995 and then Nkind (A2) = N_Explicit_Dereference
6996 then
6997 return Denotes_Same_Object (Prefix (A1), Prefix (A2));
6999 -- Both names are indexed_components, their prefixes are known to denote
7000 -- the same object, and each of the pairs of corresponding index values
7001 -- are either both static expressions with the same static value or both
7002 -- names that are known to denote the same object (RM 6.4.1(6.9/3)).
7004 elsif Nkind (A1) = N_Indexed_Component
7005 and then Nkind (A2) = N_Indexed_Component
7006 then
7007 if not Denotes_Same_Object (Prefix (A1), Prefix (A2)) then
7008 return False;
7009 else
7010 declare
7011 Indx1 : Node_Id;
7012 Indx2 : Node_Id;
7014 begin
7015 Indx1 := First (Expressions (A1));
7016 Indx2 := First (Expressions (A2));
7017 while Present (Indx1) loop
7019 -- Indexes must denote the same static value or same object
7021 if Is_OK_Static_Expression (Indx1) then
7022 if not Is_OK_Static_Expression (Indx2) then
7023 return False;
7025 elsif Expr_Value (Indx1) /= Expr_Value (Indx2) then
7026 return False;
7027 end if;
7029 elsif not Denotes_Same_Object (Indx1, Indx2) then
7030 return False;
7031 end if;
7033 Next (Indx1);
7034 Next (Indx2);
7035 end loop;
7037 return True;
7038 end;
7039 end if;
7041 -- Both names are slices, their prefixes are known to denote the same
7042 -- object, and the two slices have statically matching index constraints
7043 -- (RM 6.4.1(6.10/3)).
7045 elsif Nkind (A1) = N_Slice
7046 and then Nkind (A2) = N_Slice
7047 then
7048 if not Denotes_Same_Object (Prefix (A1), Prefix (A2)) then
7049 return False;
7050 else
7051 declare
7052 Lo1, Lo2, Hi1, Hi2 : Node_Id;
7054 begin
7055 Get_Index_Bounds (Discrete_Range (A1), Lo1, Hi1);
7056 Get_Index_Bounds (Discrete_Range (A2), Lo2, Hi2);
7058 -- Check whether bounds are statically identical. There is no
7059 -- attempt to detect partial overlap of slices.
7061 return Is_OK_Static_Expression (Lo1)
7062 and then Is_OK_Static_Expression (Lo2)
7063 and then Is_OK_Static_Expression (Hi1)
7064 and then Is_OK_Static_Expression (Hi2)
7065 and then Expr_Value (Lo1) = Expr_Value (Lo2)
7066 and then Expr_Value (Hi1) = Expr_Value (Hi2);
7067 end;
7068 end if;
7070 -- One of the two names statically denotes a renaming declaration whose
7071 -- renamed object_name is known to denote the same object as the other;
7072 -- the prefix of any dereference within the renamed object_name is not a
7073 -- variable, and any expression within the renamed object_name contains
7074 -- no references to variables nor calls on nonstatic functions (RM
7075 -- 6.4.1(6.11/3)).
7077 elsif Is_Object_Renaming (A1)
7078 and then Is_Valid_Renaming (A1)
7079 then
7080 return Denotes_Same_Object (Renamed_Object (Entity (A1)), A2);
7082 elsif Is_Object_Renaming (A2)
7083 and then Is_Valid_Renaming (A2)
7084 then
7085 return Denotes_Same_Object (A1, Renamed_Object (Entity (A2)));
7087 else
7088 return False;
7089 end if;
7090 end Denotes_Same_Object;
7092 -------------------------
7093 -- Denotes_Same_Prefix --
7094 -------------------------
7096 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
7097 begin
7098 if Is_Entity_Name (A1) then
7099 if Nkind (A2) in N_Selected_Component | N_Indexed_Component
7100 and then not Is_Access_Type (Etype (A1))
7101 then
7102 return Denotes_Same_Object (A1, Prefix (A2))
7103 or else Denotes_Same_Prefix (A1, Prefix (A2));
7104 else
7105 return False;
7106 end if;
7108 elsif Is_Entity_Name (A2) then
7109 return Denotes_Same_Prefix (A1 => A2, A2 => A1);
7111 elsif Nkind (A1) in N_Selected_Component | N_Indexed_Component | N_Slice
7112 and then
7113 Nkind (A2) in N_Selected_Component | N_Indexed_Component | N_Slice
7114 then
7115 declare
7116 Root1, Root2 : Node_Id;
7117 Depth1, Depth2 : Nat := 0;
7119 begin
7120 Root1 := Prefix (A1);
7121 while not Is_Entity_Name (Root1) loop
7122 if Nkind (Root1) not in
7123 N_Selected_Component | N_Indexed_Component
7124 then
7125 return False;
7126 else
7127 Root1 := Prefix (Root1);
7128 end if;
7130 Depth1 := Depth1 + 1;
7131 end loop;
7133 Root2 := Prefix (A2);
7134 while not Is_Entity_Name (Root2) loop
7135 if Nkind (Root2) not in
7136 N_Selected_Component | N_Indexed_Component
7137 then
7138 return False;
7139 else
7140 Root2 := Prefix (Root2);
7141 end if;
7143 Depth2 := Depth2 + 1;
7144 end loop;
7146 -- If both have the same depth and they do not denote the same
7147 -- object, they are disjoint and no warning is needed.
7149 if Depth1 = Depth2 then
7150 return False;
7152 elsif Depth1 > Depth2 then
7153 Root1 := Prefix (A1);
7154 for J in 1 .. Depth1 - Depth2 - 1 loop
7155 Root1 := Prefix (Root1);
7156 end loop;
7158 return Denotes_Same_Object (Root1, A2);
7160 else
7161 Root2 := Prefix (A2);
7162 for J in 1 .. Depth2 - Depth1 - 1 loop
7163 Root2 := Prefix (Root2);
7164 end loop;
7166 return Denotes_Same_Object (A1, Root2);
7167 end if;
7168 end;
7170 else
7171 return False;
7172 end if;
7173 end Denotes_Same_Prefix;
7175 ----------------------
7176 -- Denotes_Variable --
7177 ----------------------
7179 function Denotes_Variable (N : Node_Id) return Boolean is
7180 begin
7181 return Is_Variable (N) and then Paren_Count (N) = 0;
7182 end Denotes_Variable;
7184 -----------------------------
7185 -- Depends_On_Discriminant --
7186 -----------------------------
7188 function Depends_On_Discriminant (N : Node_Id) return Boolean is
7189 L : Node_Id;
7190 H : Node_Id;
7192 begin
7193 Get_Index_Bounds (N, L, H);
7194 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
7195 end Depends_On_Discriminant;
7197 -------------------------------------
7198 -- Derivation_Too_Early_To_Inherit --
7199 -------------------------------------
7201 function Derivation_Too_Early_To_Inherit
7202 (Typ : Entity_Id; Streaming_Op : TSS_Name_Type) return Boolean is
7204 Btyp : constant Entity_Id := Implementation_Base_Type (Typ);
7205 Parent_Type : Entity_Id;
7207 Real_Rep : Node_Id;
7209 -- Start of processing for Derivation_Too_Early_To_Inherit
7211 begin
7212 if Is_Derived_Type (Btyp) then
7213 Parent_Type := Implementation_Base_Type (Etype (Btyp));
7214 pragma Assert (Parent_Type /= Btyp);
7216 if Has_Stream_Attribute_Definition
7217 (Parent_Type, Streaming_Op, Real_Rep => Real_Rep)
7219 and then In_Same_Extended_Unit (Btyp, Parent_Type)
7220 and then Instantiation (Get_Source_File_Index (Sloc (Btyp))) =
7221 Instantiation (Get_Source_File_Index (Sloc (Parent_Type)))
7222 then
7223 return Earlier_In_Extended_Unit (Btyp, Real_Rep);
7224 end if;
7225 end if;
7227 return False;
7228 end Derivation_Too_Early_To_Inherit;
7230 -------------------------
7231 -- Designate_Same_Unit --
7232 -------------------------
7234 function Designate_Same_Unit
7235 (Name1 : Node_Id;
7236 Name2 : Node_Id) return Boolean
7238 K1 : constant Node_Kind := Nkind (Name1);
7239 K2 : constant Node_Kind := Nkind (Name2);
7241 function Prefix_Node (N : Node_Id) return Node_Id;
7242 -- Returns the parent unit name node of a defining program unit name
7243 -- or the prefix if N is a selected component or an expanded name.
7245 function Select_Node (N : Node_Id) return Node_Id;
7246 -- Returns the defining identifier node of a defining program unit
7247 -- name or the selector node if N is a selected component or an
7248 -- expanded name.
7250 -----------------
7251 -- Prefix_Node --
7252 -----------------
7254 function Prefix_Node (N : Node_Id) return Node_Id is
7255 begin
7256 if Nkind (N) = N_Defining_Program_Unit_Name then
7257 return Name (N);
7258 else
7259 return Prefix (N);
7260 end if;
7261 end Prefix_Node;
7263 -----------------
7264 -- Select_Node --
7265 -----------------
7267 function Select_Node (N : Node_Id) return Node_Id is
7268 begin
7269 if Nkind (N) = N_Defining_Program_Unit_Name then
7270 return Defining_Identifier (N);
7271 else
7272 return Selector_Name (N);
7273 end if;
7274 end Select_Node;
7276 -- Start of processing for Designate_Same_Unit
7278 begin
7279 if K1 in N_Identifier | N_Defining_Identifier
7280 and then
7281 K2 in N_Identifier | N_Defining_Identifier
7282 then
7283 return Chars (Name1) = Chars (Name2);
7285 elsif K1 in N_Expanded_Name
7286 | N_Selected_Component
7287 | N_Defining_Program_Unit_Name
7288 and then
7289 K2 in N_Expanded_Name
7290 | N_Selected_Component
7291 | N_Defining_Program_Unit_Name
7292 then
7293 return
7294 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
7295 and then
7296 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
7298 else
7299 return False;
7300 end if;
7301 end Designate_Same_Unit;
7303 ---------------------------------------------
7304 -- Diagnose_Iterated_Component_Association --
7305 ---------------------------------------------
7307 procedure Diagnose_Iterated_Component_Association (N : Node_Id) is
7308 Def_Id : constant Entity_Id := Defining_Identifier (N);
7309 Aggr : Node_Id;
7311 begin
7312 -- Determine whether the iterated component association appears within
7313 -- an aggregate. If this is the case, raise Program_Error because the
7314 -- iterated component association cannot be left in the tree as is and
7315 -- must always be processed by the related aggregate.
7317 Aggr := N;
7318 while Present (Aggr) loop
7319 if Nkind (Aggr) = N_Aggregate then
7320 raise Program_Error;
7322 -- Prevent the search from going too far
7324 elsif Is_Body_Or_Package_Declaration (Aggr) then
7325 exit;
7326 end if;
7328 Aggr := Parent (Aggr);
7329 end loop;
7331 -- At this point it is known that the iterated component association is
7332 -- not within an aggregate. This is really a quantified expression with
7333 -- a missing "all" or "some" quantifier.
7335 Error_Msg_N ("missing quantifier", Def_Id);
7337 -- Rewrite the iterated component association as True to prevent any
7338 -- cascaded errors.
7340 Rewrite (N, New_Occurrence_Of (Standard_True, Sloc (N)));
7341 Analyze (N);
7342 end Diagnose_Iterated_Component_Association;
7344 ------------------------
7345 -- Discriminated_Size --
7346 ------------------------
7348 function Discriminated_Size (Comp : Entity_Id) return Boolean is
7349 function Non_Static_Bound (Bound : Node_Id) return Boolean;
7350 -- Check whether the bound of an index is non-static and does denote
7351 -- a discriminant, in which case any object of the type (protected or
7352 -- otherwise) will have a non-static size.
7354 ----------------------
7355 -- Non_Static_Bound --
7356 ----------------------
7358 function Non_Static_Bound (Bound : Node_Id) return Boolean is
7359 begin
7360 if Is_OK_Static_Expression (Bound) then
7361 return False;
7363 -- If the bound is given by a discriminant it is non-static
7364 -- (A static constraint replaces the reference with the value).
7365 -- In an protected object the discriminant has been replaced by
7366 -- the corresponding discriminal within the protected operation.
7368 elsif Is_Entity_Name (Bound)
7369 and then
7370 (Ekind (Entity (Bound)) = E_Discriminant
7371 or else Present (Discriminal_Link (Entity (Bound))))
7372 then
7373 return False;
7375 else
7376 return True;
7377 end if;
7378 end Non_Static_Bound;
7380 -- Local variables
7382 Typ : constant Entity_Id := Etype (Comp);
7383 Index : Node_Id;
7385 -- Start of processing for Discriminated_Size
7387 begin
7388 if not Is_Array_Type (Typ) then
7389 return False;
7390 end if;
7392 if Ekind (Typ) = E_Array_Subtype then
7393 Index := First_Index (Typ);
7394 while Present (Index) loop
7395 if Non_Static_Bound (Low_Bound (Index))
7396 or else Non_Static_Bound (High_Bound (Index))
7397 then
7398 return False;
7399 end if;
7401 Next_Index (Index);
7402 end loop;
7404 return True;
7405 end if;
7407 return False;
7408 end Discriminated_Size;
7410 -----------------------------
7411 -- Effective_Reads_Enabled --
7412 -----------------------------
7414 function Effective_Reads_Enabled (Id : Entity_Id) return Boolean is
7415 begin
7416 return Has_Enabled_Property (Id, Name_Effective_Reads);
7417 end Effective_Reads_Enabled;
7419 ------------------------------
7420 -- Effective_Writes_Enabled --
7421 ------------------------------
7423 function Effective_Writes_Enabled (Id : Entity_Id) return Boolean is
7424 begin
7425 return Has_Enabled_Property (Id, Name_Effective_Writes);
7426 end Effective_Writes_Enabled;
7428 ------------------------------
7429 -- Enclosing_Comp_Unit_Node --
7430 ------------------------------
7432 function Enclosing_Comp_Unit_Node (N : Node_Id) return Node_Id is
7433 Current_Node : Node_Id;
7435 begin
7436 Current_Node := N;
7437 while Present (Current_Node)
7438 and then Nkind (Current_Node) /= N_Compilation_Unit
7439 loop
7440 Current_Node := Parent (Current_Node);
7441 end loop;
7443 return Current_Node;
7444 end Enclosing_Comp_Unit_Node;
7446 --------------------------
7447 -- Enclosing_CPP_Parent --
7448 --------------------------
7450 function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is
7451 Parent_Typ : Entity_Id := Typ;
7453 begin
7454 while not Is_CPP_Class (Parent_Typ)
7455 and then Etype (Parent_Typ) /= Parent_Typ
7456 loop
7457 Parent_Typ := Etype (Parent_Typ);
7459 if Is_Private_Type (Parent_Typ) then
7460 Parent_Typ := Full_View (Base_Type (Parent_Typ));
7461 end if;
7462 end loop;
7464 pragma Assert (Is_CPP_Class (Parent_Typ));
7465 return Parent_Typ;
7466 end Enclosing_CPP_Parent;
7468 ---------------------------
7469 -- Enclosing_Declaration --
7470 ---------------------------
7472 function Enclosing_Declaration (N : Node_Id) return Node_Id is
7473 Decl : Node_Id := N;
7475 begin
7476 while Present (Decl)
7477 and then not (Nkind (Decl) in N_Declaration
7478 or else
7479 Nkind (Decl) in N_Later_Decl_Item
7480 or else
7481 Nkind (Decl) in N_Renaming_Declaration
7482 or else
7483 Nkind (Decl) = N_Number_Declaration)
7484 loop
7485 Decl := Parent (Decl);
7486 end loop;
7488 return Decl;
7489 end Enclosing_Declaration;
7491 ----------------------------------------
7492 -- Enclosing_Declaration_Or_Statement --
7493 ----------------------------------------
7495 function Enclosing_Declaration_Or_Statement
7496 (N : Node_Id) return Node_Id
7498 Par : Node_Id;
7500 begin
7501 Par := N;
7502 while Present (Par) loop
7503 if Is_Declaration (Par) or else Is_Statement (Par) then
7504 return Par;
7506 -- Prevent the search from going too far
7508 elsif Is_Body_Or_Package_Declaration (Par) then
7509 exit;
7510 end if;
7512 Par := Parent (Par);
7513 end loop;
7515 return N;
7516 end Enclosing_Declaration_Or_Statement;
7518 ----------------------------
7519 -- Enclosing_Generic_Body --
7520 ----------------------------
7522 function Enclosing_Generic_Body (N : Node_Id) return Node_Id is
7523 Par : Node_Id;
7524 Spec_Id : Entity_Id;
7526 begin
7527 Par := Parent (N);
7528 while Present (Par) loop
7529 if Nkind (Par) in N_Package_Body | N_Subprogram_Body then
7530 Spec_Id := Corresponding_Spec (Par);
7532 if Present (Spec_Id)
7533 and then Nkind (Unit_Declaration_Node (Spec_Id)) in
7534 N_Generic_Declaration
7535 then
7536 return Par;
7537 end if;
7538 end if;
7540 Par := Parent (Par);
7541 end loop;
7543 return Empty;
7544 end Enclosing_Generic_Body;
7546 ----------------------------
7547 -- Enclosing_Generic_Unit --
7548 ----------------------------
7550 function Enclosing_Generic_Unit (N : Node_Id) return Node_Id is
7551 Par : Node_Id;
7552 Spec_Decl : Node_Id;
7553 Spec_Id : Entity_Id;
7555 begin
7556 Par := Parent (N);
7557 while Present (Par) loop
7558 if Nkind (Par) in N_Generic_Declaration then
7559 return Par;
7561 elsif Nkind (Par) in N_Package_Body | N_Subprogram_Body then
7562 Spec_Id := Corresponding_Spec (Par);
7564 if Present (Spec_Id) then
7565 Spec_Decl := Unit_Declaration_Node (Spec_Id);
7567 if Nkind (Spec_Decl) in N_Generic_Declaration then
7568 return Spec_Decl;
7569 end if;
7570 end if;
7571 end if;
7573 Par := Parent (Par);
7574 end loop;
7576 return Empty;
7577 end Enclosing_Generic_Unit;
7579 -------------------
7580 -- Enclosing_HSS --
7581 -------------------
7583 function Enclosing_HSS (Stmt : Node_Id) return Node_Id is
7584 Par : Node_Id;
7585 begin
7586 pragma Assert (Is_Statement (Stmt));
7588 Par := Parent (Stmt);
7589 while Present (Par) loop
7591 if Nkind (Par) = N_Handled_Sequence_Of_Statements then
7592 return Par;
7594 -- Prevent the search from going too far
7596 elsif Is_Body_Or_Package_Declaration (Par) then
7597 return Empty;
7599 end if;
7601 Par := Parent (Par);
7602 end loop;
7604 return Par;
7605 end Enclosing_HSS;
7607 -------------------------------
7608 -- Enclosing_Lib_Unit_Entity --
7609 -------------------------------
7611 function Enclosing_Lib_Unit_Entity
7612 (E : Entity_Id := Current_Scope) return Entity_Id
7614 Unit_Entity : Entity_Id;
7616 begin
7617 -- Look for enclosing library unit entity by following scope links.
7618 -- Equivalent to, but faster than indexing through the scope stack.
7620 Unit_Entity := E;
7621 while (Present (Scope (Unit_Entity))
7622 and then Scope (Unit_Entity) /= Standard_Standard)
7623 and not Is_Child_Unit (Unit_Entity)
7624 loop
7625 Unit_Entity := Scope (Unit_Entity);
7626 end loop;
7628 return Unit_Entity;
7629 end Enclosing_Lib_Unit_Entity;
7631 -----------------------------
7632 -- Enclosing_Lib_Unit_Node --
7633 -----------------------------
7635 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
7636 Encl_Unit : Node_Id;
7638 begin
7639 Encl_Unit := Enclosing_Comp_Unit_Node (N);
7640 while Present (Encl_Unit)
7641 and then Nkind (Unit (Encl_Unit)) = N_Subunit
7642 loop
7643 Encl_Unit := Library_Unit (Encl_Unit);
7644 end loop;
7646 pragma Assert (Nkind (Encl_Unit) = N_Compilation_Unit);
7647 return Encl_Unit;
7648 end Enclosing_Lib_Unit_Node;
7650 -----------------------
7651 -- Enclosing_Package --
7652 -----------------------
7654 function Enclosing_Package (N : Node_Or_Entity_Id) return Entity_Id is
7655 Dynamic_Scope : Entity_Id;
7657 begin
7658 -- Obtain the enclosing scope when N is a Node_Id - taking care to
7659 -- handle the case when the enclosing scope is already a package.
7661 if Nkind (N) not in N_Entity then
7662 declare
7663 Encl_Scop : constant Entity_Id := Find_Enclosing_Scope (N);
7664 begin
7665 if No (Encl_Scop) then
7666 return Empty;
7667 elsif Ekind (Encl_Scop) in
7668 E_Generic_Package | E_Package | E_Package_Body
7669 then
7670 return Encl_Scop;
7671 end if;
7673 return Enclosing_Package (Encl_Scop);
7674 end;
7675 end if;
7677 -- When N is already an Entity_Id proceed
7679 Dynamic_Scope := Enclosing_Dynamic_Scope (N);
7680 if Dynamic_Scope = Standard_Standard then
7681 return Standard_Standard;
7683 elsif Dynamic_Scope = Empty then
7684 return Empty;
7686 elsif Ekind (Dynamic_Scope) in
7687 E_Generic_Package | E_Package | E_Package_Body
7688 then
7689 return Dynamic_Scope;
7691 else
7692 return Enclosing_Package (Dynamic_Scope);
7693 end if;
7694 end Enclosing_Package;
7696 -------------------------------------
7697 -- Enclosing_Package_Or_Subprogram --
7698 -------------------------------------
7700 function Enclosing_Package_Or_Subprogram (E : Entity_Id) return Entity_Id is
7701 S : Entity_Id;
7703 begin
7704 S := Scope (E);
7705 while Present (S) loop
7706 if Is_Package_Or_Generic_Package (S)
7707 or else Is_Subprogram_Or_Generic_Subprogram (S)
7708 then
7709 return S;
7711 else
7712 S := Scope (S);
7713 end if;
7714 end loop;
7716 return Empty;
7717 end Enclosing_Package_Or_Subprogram;
7719 --------------------------
7720 -- Enclosing_Subprogram --
7721 --------------------------
7723 function Enclosing_Subprogram (N : Node_Or_Entity_Id) return Entity_Id is
7724 Dyn_Scop : Entity_Id;
7725 Encl_Scop : Entity_Id;
7727 begin
7728 -- Obtain the enclosing scope when N is a Node_Id - taking care to
7729 -- handle the case when the enclosing scope is already a subprogram.
7731 if Nkind (N) not in N_Entity then
7732 Encl_Scop := Find_Enclosing_Scope (N);
7734 if No (Encl_Scop) then
7735 return Empty;
7736 elsif Ekind (Encl_Scop) in Subprogram_Kind then
7737 return Encl_Scop;
7738 end if;
7740 return Enclosing_Subprogram (Encl_Scop);
7741 end if;
7743 -- When N is already an Entity_Id proceed
7745 Dyn_Scop := Enclosing_Dynamic_Scope (N);
7746 if Dyn_Scop = Standard_Standard then
7747 return Empty;
7749 elsif Dyn_Scop = Empty then
7750 return Empty;
7752 elsif Ekind (Dyn_Scop) = E_Subprogram_Body then
7753 return Corresponding_Spec (Parent (Parent (Dyn_Scop)));
7755 elsif Ekind (Dyn_Scop) in E_Block | E_Loop | E_Return_Statement then
7756 return Enclosing_Subprogram (Dyn_Scop);
7758 elsif Ekind (Dyn_Scop) in E_Entry | E_Entry_Family then
7760 -- For a task entry or entry family, return the enclosing subprogram
7761 -- of the task itself.
7763 if Ekind (Scope (Dyn_Scop)) = E_Task_Type then
7764 return Enclosing_Subprogram (Dyn_Scop);
7766 -- A protected entry or entry family is rewritten as a protected
7767 -- procedure which is the desired enclosing subprogram. This is
7768 -- relevant when unnesting a procedure local to an entry body.
7770 else
7771 return Protected_Body_Subprogram (Dyn_Scop);
7772 end if;
7774 elsif Ekind (Dyn_Scop) = E_Task_Type then
7775 return Get_Task_Body_Procedure (Dyn_Scop);
7777 -- The scope may appear as a private type or as a private extension
7778 -- whose completion is a task or protected type.
7780 elsif Ekind (Dyn_Scop) in
7781 E_Limited_Private_Type | E_Record_Type_With_Private
7782 and then Present (Full_View (Dyn_Scop))
7783 and then Ekind (Full_View (Dyn_Scop)) in E_Task_Type | E_Protected_Type
7784 then
7785 return Get_Task_Body_Procedure (Full_View (Dyn_Scop));
7787 -- No body is generated if the protected operation is eliminated
7789 elsif not Is_Eliminated (Dyn_Scop)
7790 and then Present (Protected_Body_Subprogram (Dyn_Scop))
7791 then
7792 return Protected_Body_Subprogram (Dyn_Scop);
7794 else
7795 return Dyn_Scop;
7796 end if;
7797 end Enclosing_Subprogram;
7799 --------------------------
7800 -- End_Keyword_Location --
7801 --------------------------
7803 function End_Keyword_Location (N : Node_Id) return Source_Ptr is
7804 function End_Label_Loc (Nod : Node_Id) return Source_Ptr;
7805 -- Return the source location of Nod's end label according to the
7806 -- following precedence rules:
7808 -- 1) If the end label exists, return its location
7809 -- 2) If Nod exists, return its location
7810 -- 3) Return the location of N
7812 -------------------
7813 -- End_Label_Loc --
7814 -------------------
7816 function End_Label_Loc (Nod : Node_Id) return Source_Ptr is
7817 Label : Node_Id;
7819 begin
7820 if Present (Nod) then
7821 Label := End_Label (Nod);
7823 if Present (Label) then
7824 return Sloc (Label);
7825 else
7826 return Sloc (Nod);
7827 end if;
7829 else
7830 return Sloc (N);
7831 end if;
7832 end End_Label_Loc;
7834 -- Local variables
7836 Owner : Node_Id := Empty;
7838 -- Start of processing for End_Keyword_Location
7840 begin
7841 if Nkind (N) in N_Block_Statement
7842 | N_Entry_Body
7843 | N_Package_Body
7844 | N_Subprogram_Body
7845 | N_Task_Body
7846 then
7847 Owner := Handled_Statement_Sequence (N);
7849 elsif Nkind (N) = N_Package_Declaration then
7850 Owner := Specification (N);
7852 elsif Nkind (N) = N_Protected_Body then
7853 Owner := N;
7855 elsif Nkind (N) in N_Protected_Type_Declaration
7856 | N_Single_Protected_Declaration
7857 then
7858 Owner := Protected_Definition (N);
7860 elsif Nkind (N) in N_Single_Task_Declaration | N_Task_Type_Declaration
7861 then
7862 Owner := Task_Definition (N);
7864 -- This routine should not be called with other contexts
7866 else
7867 pragma Assert (False);
7868 null;
7869 end if;
7871 return End_Label_Loc (Owner);
7872 end End_Keyword_Location;
7874 ------------------------
7875 -- Ensure_Freeze_Node --
7876 ------------------------
7878 procedure Ensure_Freeze_Node (E : Entity_Id) is
7879 FN : Node_Id;
7880 begin
7881 if No (Freeze_Node (E)) then
7882 FN := Make_Freeze_Entity (Sloc (E));
7883 Set_Has_Delayed_Freeze (E);
7884 Set_Freeze_Node (E, FN);
7885 Set_Access_Types_To_Process (FN, No_Elist);
7886 Set_TSS_Elist (FN, No_Elist);
7887 Set_Entity (FN, E);
7888 end if;
7889 end Ensure_Freeze_Node;
7891 ----------------
7892 -- Enter_Name --
7893 ----------------
7895 procedure Enter_Name (Def_Id : Entity_Id) is
7896 C : constant Entity_Id := Current_Entity (Def_Id);
7897 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
7898 S : constant Entity_Id := Current_Scope;
7900 begin
7901 Generate_Definition (Def_Id);
7903 -- Add new name to current scope declarations. Check for duplicate
7904 -- declaration, which may or may not be a genuine error.
7906 if Present (E) then
7908 -- Case of previous entity entered because of a missing declaration
7909 -- or else a bad subtype indication. Best is to use the new entity,
7910 -- and make the previous one invisible.
7912 if Etype (E) = Any_Type then
7913 Set_Is_Immediately_Visible (E, False);
7915 -- Case of renaming declaration constructed for package instances.
7916 -- if there is an explicit declaration with the same identifier,
7917 -- the renaming is not immediately visible any longer, but remains
7918 -- visible through selected component notation.
7920 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
7921 and then not Comes_From_Source (E)
7922 then
7923 Set_Is_Immediately_Visible (E, False);
7925 -- The new entity may be the package renaming, which has the same
7926 -- same name as a generic formal which has been seen already.
7928 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
7929 and then not Comes_From_Source (Def_Id)
7930 then
7931 Set_Is_Immediately_Visible (E, False);
7933 -- For a fat pointer corresponding to a remote access to subprogram,
7934 -- we use the same identifier as the RAS type, so that the proper
7935 -- name appears in the stub. This type is only retrieved through
7936 -- the RAS type and never by visibility, and is not added to the
7937 -- visibility list (see below).
7939 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
7940 and then Ekind (Def_Id) = E_Record_Type
7941 and then Present (Corresponding_Remote_Type (Def_Id))
7942 then
7943 null;
7945 -- Case of an implicit operation or derived literal. The new entity
7946 -- hides the implicit one, which is removed from all visibility,
7947 -- i.e. the entity list of its scope, and homonym chain of its name.
7949 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
7950 or else Is_Internal (E)
7951 then
7952 declare
7953 Decl : constant Node_Id := Parent (E);
7954 Prev : Entity_Id;
7955 Prev_Vis : Entity_Id;
7957 begin
7958 -- If E is an implicit declaration, it cannot be the first
7959 -- entity in the scope.
7961 Prev := First_Entity (Current_Scope);
7962 while Present (Prev) and then Next_Entity (Prev) /= E loop
7963 Next_Entity (Prev);
7964 end loop;
7966 if No (Prev) then
7968 -- If E is not on the entity chain of the current scope,
7969 -- it is an implicit declaration in the generic formal
7970 -- part of a generic subprogram. When analyzing the body,
7971 -- the generic formals are visible but not on the entity
7972 -- chain of the subprogram. The new entity will become
7973 -- the visible one in the body.
7975 pragma Assert
7976 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
7977 null;
7979 else
7980 Link_Entities (Prev, Next_Entity (E));
7982 if No (Next_Entity (Prev)) then
7983 Set_Last_Entity (Current_Scope, Prev);
7984 end if;
7986 if E = Current_Entity (E) then
7987 Prev_Vis := Empty;
7989 else
7990 Prev_Vis := Current_Entity (E);
7991 while Homonym (Prev_Vis) /= E loop
7992 Prev_Vis := Homonym (Prev_Vis);
7993 end loop;
7994 end if;
7996 if Present (Prev_Vis) then
7998 -- Skip E in the visibility chain
8000 Set_Homonym (Prev_Vis, Homonym (E));
8002 else
8003 Set_Name_Entity_Id (Chars (E), Homonym (E));
8004 end if;
8006 -- The inherited operation cannot be retrieved
8007 -- by name, even though it may remain accesssible
8008 -- in some cases involving subprogram bodies without
8009 -- specs appearing in with_clauses..
8011 Set_Is_Immediately_Visible (E, False);
8012 end if;
8013 end;
8015 -- This section of code could use a comment ???
8017 elsif Present (Etype (E))
8018 and then Is_Concurrent_Type (Etype (E))
8019 and then E = Def_Id
8020 then
8021 return;
8023 -- If the homograph is a protected component renaming, it should not
8024 -- be hiding the current entity. Such renamings are treated as weak
8025 -- declarations.
8027 elsif Is_Prival (E) then
8028 Set_Is_Immediately_Visible (E, False);
8030 -- In this case the current entity is a protected component renaming.
8031 -- Perform minimal decoration by setting the scope and return since
8032 -- the prival should not be hiding other visible entities.
8034 elsif Is_Prival (Def_Id) then
8035 Set_Scope (Def_Id, Current_Scope);
8036 return;
8038 -- Analogous to privals, the discriminal generated for an entry index
8039 -- parameter acts as a weak declaration. Perform minimal decoration
8040 -- to avoid bogus errors.
8042 elsif Is_Discriminal (Def_Id)
8043 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
8044 then
8045 Set_Scope (Def_Id, Current_Scope);
8046 return;
8048 -- In the body or private part of an instance, a type extension may
8049 -- introduce a component with the same name as that of an actual. The
8050 -- legality rule is not enforced, but the semantics of the full type
8051 -- with two components of same name are not clear at this point???
8053 elsif In_Instance_Not_Visible then
8054 null;
8056 -- When compiling a package body, some child units may have become
8057 -- visible. They cannot conflict with local entities that hide them.
8059 elsif Is_Child_Unit (E)
8060 and then In_Open_Scopes (Scope (E))
8061 and then not Is_Immediately_Visible (E)
8062 then
8063 null;
8065 -- Conversely, with front-end inlining we may compile the parent body
8066 -- first, and a child unit subsequently. The context is now the
8067 -- parent spec, and body entities are not visible.
8069 elsif Is_Child_Unit (Def_Id)
8070 and then Is_Package_Body_Entity (E)
8071 and then not In_Package_Body (Current_Scope)
8072 then
8073 null;
8075 -- Case of genuine duplicate declaration
8077 else
8078 Error_Msg_Sloc := Sloc (E);
8080 -- If the previous declaration is an incomplete type declaration
8081 -- this may be an attempt to complete it with a private type. The
8082 -- following avoids confusing cascaded errors.
8084 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
8085 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
8086 then
8087 Error_Msg_N
8088 ("incomplete type cannot be completed with a private " &
8089 "declaration", Parent (Def_Id));
8090 Set_Is_Immediately_Visible (E, False);
8091 Set_Full_View (E, Def_Id);
8093 -- An inherited component of a record conflicts with a new
8094 -- discriminant. The discriminant is inserted first in the scope,
8095 -- but the error should be posted on it, not on the component.
8097 elsif Ekind (E) = E_Discriminant
8098 and then Present (Scope (Def_Id))
8099 and then Scope (Def_Id) /= Current_Scope
8100 then
8101 Error_Msg_Sloc := Sloc (Def_Id);
8102 Error_Msg_N ("& conflicts with declaration#", E);
8103 return;
8105 -- If the name of the unit appears in its own context clause, a
8106 -- dummy package with the name has already been created, and the
8107 -- error emitted. Try to continue quietly.
8109 elsif Error_Posted (E)
8110 and then Sloc (E) = No_Location
8111 and then Nkind (Parent (E)) = N_Package_Specification
8112 and then Current_Scope = Standard_Standard
8113 then
8114 Set_Scope (Def_Id, Current_Scope);
8115 return;
8117 else
8118 Error_Msg_N ("& conflicts with declaration#", Def_Id);
8120 -- Avoid cascaded messages with duplicate components in
8121 -- derived types.
8123 if Ekind (E) in E_Component | E_Discriminant then
8124 return;
8125 end if;
8126 end if;
8128 if Nkind (Parent (Parent (Def_Id))) =
8129 N_Generic_Subprogram_Declaration
8130 and then Def_Id =
8131 Defining_Entity (Specification (Parent (Parent (Def_Id))))
8132 then
8133 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
8134 end if;
8136 -- If entity is in standard, then we are in trouble, because it
8137 -- means that we have a library package with a duplicated name.
8138 -- That's hard to recover from, so abort.
8140 if S = Standard_Standard then
8141 raise Unrecoverable_Error;
8143 -- Otherwise we continue with the declaration. Having two
8144 -- identical declarations should not cause us too much trouble.
8146 else
8147 null;
8148 end if;
8149 end if;
8150 end if;
8152 -- If we fall through, declaration is OK, at least OK enough to continue
8154 -- If Def_Id is a discriminant or a record component we are in the midst
8155 -- of inheriting components in a derived record definition. Preserve
8156 -- their Ekind and Etype.
8158 if Ekind (Def_Id) in E_Discriminant | E_Component then
8159 null;
8161 -- If a type is already set, leave it alone (happens when a type
8162 -- declaration is reanalyzed following a call to the optimizer).
8164 elsif Present (Etype (Def_Id)) then
8165 null;
8167 -- Otherwise, the kind E_Void insures that premature uses of the entity
8168 -- will be detected. Any_Type insures that no cascaded errors will occur
8170 else
8171 Mutate_Ekind (Def_Id, E_Void);
8172 Set_Etype (Def_Id, Any_Type);
8173 end if;
8175 -- All entities except Itypes are immediately visible
8177 if not Is_Itype (Def_Id) then
8178 Set_Is_Immediately_Visible (Def_Id);
8179 Set_Current_Entity (Def_Id);
8180 end if;
8182 Set_Homonym (Def_Id, C);
8183 Append_Entity (Def_Id, S);
8184 Set_Public_Status (Def_Id);
8186 -- Warn if new entity hides an old one
8188 if Warn_On_Hiding and then Present (C) then
8189 Warn_On_Hiding_Entity (Def_Id, Hidden => C, Visible => Def_Id,
8190 On_Use_Clause => False);
8191 end if;
8192 end Enter_Name;
8194 ---------------
8195 -- Entity_Of --
8196 ---------------
8198 function Entity_Of (N : Node_Id) return Entity_Id is
8199 Id : Entity_Id;
8200 Ren : Node_Id;
8202 begin
8203 -- Assume that the arbitrary node does not have an entity
8205 Id := Empty;
8207 if Is_Entity_Name (N) then
8208 Id := Entity (N);
8210 -- Follow a possible chain of renamings to reach the earliest renamed
8211 -- source object.
8213 while Present (Id)
8214 and then Is_Object (Id)
8215 and then Present (Renamed_Object (Id))
8216 loop
8217 Ren := Renamed_Object (Id);
8219 -- The reference renames an abstract state or a whole object
8221 -- Obj : ...;
8222 -- Ren : ... renames Obj;
8224 if Is_Entity_Name (Ren) then
8226 -- Do not follow a renaming that goes through a generic formal,
8227 -- because these entities are hidden and must not be referenced
8228 -- from outside the generic.
8230 if Is_Hidden (Entity (Ren)) then
8231 exit;
8233 else
8234 Id := Entity (Ren);
8235 end if;
8237 -- The reference renames a function result. Check the original
8238 -- node in case expansion relocates the function call.
8240 -- Ren : ... renames Func_Call;
8242 elsif Nkind (Original_Node (Ren)) = N_Function_Call then
8243 exit;
8245 -- Otherwise the reference renames something which does not yield
8246 -- an abstract state or a whole object. Treat the reference as not
8247 -- having a proper entity for SPARK legality purposes.
8249 else
8250 Id := Empty;
8251 exit;
8252 end if;
8253 end loop;
8254 end if;
8256 return Id;
8257 end Entity_Of;
8259 --------------------------
8260 -- Examine_Array_Bounds --
8261 --------------------------
8263 procedure Examine_Array_Bounds
8264 (Typ : Entity_Id;
8265 All_Static : out Boolean;
8266 Has_Empty : out Boolean)
8268 function Is_OK_Static_Bound (Bound : Node_Id) return Boolean;
8269 -- Determine whether bound Bound is a suitable static bound
8271 ------------------------
8272 -- Is_OK_Static_Bound --
8273 ------------------------
8275 function Is_OK_Static_Bound (Bound : Node_Id) return Boolean is
8276 begin
8277 return
8278 not Error_Posted (Bound)
8279 and then Is_OK_Static_Expression (Bound);
8280 end Is_OK_Static_Bound;
8282 -- Local variables
8284 Hi_Bound : Node_Id;
8285 Index : Node_Id;
8286 Lo_Bound : Node_Id;
8288 -- Start of processing for Examine_Array_Bounds
8290 begin
8291 -- An unconstrained array type does not have static bounds, and it is
8292 -- not known whether they are empty or not.
8294 if not Is_Constrained (Typ) then
8295 All_Static := False;
8296 Has_Empty := False;
8298 -- A string literal has static bounds, and is not empty as long as it
8299 -- contains at least one character.
8301 elsif Ekind (Typ) = E_String_Literal_Subtype then
8302 All_Static := True;
8303 Has_Empty := String_Literal_Length (Typ) > 0;
8304 end if;
8306 -- Assume that all bounds are static and not empty
8308 All_Static := True;
8309 Has_Empty := False;
8311 -- Examine each index
8313 Index := First_Index (Typ);
8314 while Present (Index) loop
8315 if Is_Discrete_Type (Etype (Index)) then
8316 Get_Index_Bounds (Index, Lo_Bound, Hi_Bound);
8318 if Is_OK_Static_Bound (Lo_Bound)
8319 and then
8320 Is_OK_Static_Bound (Hi_Bound)
8321 then
8322 -- The static bounds produce an empty range
8324 if Is_Null_Range (Lo_Bound, Hi_Bound) then
8325 Has_Empty := True;
8326 end if;
8328 -- Otherwise at least one of the bounds is not static
8330 else
8331 All_Static := False;
8332 end if;
8334 -- Otherwise the index is non-discrete, therefore not static
8336 else
8337 All_Static := False;
8338 end if;
8340 Next_Index (Index);
8341 end loop;
8342 end Examine_Array_Bounds;
8344 -------------------
8345 -- Exceptions_OK --
8346 -------------------
8348 function Exceptions_OK return Boolean is
8349 begin
8350 return
8351 not (Restriction_Active (No_Exception_Handlers) or else
8352 Restriction_Active (No_Exception_Propagation) or else
8353 Restriction_Active (No_Exceptions));
8354 end Exceptions_OK;
8356 --------------------------
8357 -- Explain_Limited_Type --
8358 --------------------------
8360 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
8361 C : Entity_Id;
8363 begin
8364 -- For array, component type must be limited
8366 if Is_Array_Type (T) then
8367 Error_Msg_Node_2 := T;
8368 Error_Msg_NE
8369 ("\component type& of type& is limited", N, Component_Type (T));
8370 Explain_Limited_Type (Component_Type (T), N);
8372 elsif Is_Record_Type (T) then
8374 -- No need for extra messages if explicit limited record
8376 if Is_Limited_Record (Base_Type (T)) then
8377 return;
8378 end if;
8380 -- Otherwise find a limited component. Check only components that
8381 -- come from source, or inherited components that appear in the
8382 -- source of the ancestor.
8384 C := First_Component (T);
8385 while Present (C) loop
8386 if Is_Limited_Type (Etype (C))
8387 and then
8388 (Comes_From_Source (C)
8389 or else
8390 (Present (Original_Record_Component (C))
8391 and then
8392 Comes_From_Source (Original_Record_Component (C))))
8393 then
8394 Error_Msg_Node_2 := T;
8395 Error_Msg_NE ("\component& of type& has limited type", N, C);
8396 Explain_Limited_Type (Etype (C), N);
8397 return;
8398 end if;
8400 Next_Component (C);
8401 end loop;
8403 -- The type may be declared explicitly limited, even if no component
8404 -- of it is limited, in which case we fall out of the loop.
8405 return;
8406 end if;
8407 end Explain_Limited_Type;
8409 ---------------------------------------
8410 -- Expression_Of_Expression_Function --
8411 ---------------------------------------
8413 function Expression_Of_Expression_Function
8414 (Subp : Entity_Id) return Node_Id
8416 Expr_Func : Node_Id := Empty;
8418 begin
8419 pragma Assert (Is_Expression_Function_Or_Completion (Subp));
8421 if Nkind (Original_Node (Subprogram_Spec (Subp))) =
8422 N_Expression_Function
8423 then
8424 Expr_Func := Original_Node (Subprogram_Spec (Subp));
8426 elsif Nkind (Original_Node (Subprogram_Body (Subp))) =
8427 N_Expression_Function
8428 then
8429 Expr_Func := Original_Node (Subprogram_Body (Subp));
8431 else
8432 pragma Assert (False);
8433 null;
8434 end if;
8436 return Original_Node (Expression (Expr_Func));
8437 end Expression_Of_Expression_Function;
8439 -------------------------------
8440 -- Extensions_Visible_Status --
8441 -------------------------------
8443 function Extensions_Visible_Status
8444 (Id : Entity_Id) return Extensions_Visible_Mode
8446 Arg : Node_Id;
8447 Decl : Node_Id;
8448 Expr : Node_Id;
8449 Prag : Node_Id;
8450 Subp : Entity_Id;
8452 begin
8453 -- When a formal parameter is subject to Extensions_Visible, the pragma
8454 -- is stored in the contract of related subprogram.
8456 if Is_Formal (Id) then
8457 Subp := Scope (Id);
8459 elsif Is_Subprogram_Or_Generic_Subprogram (Id) then
8460 Subp := Id;
8462 -- No other construct carries this pragma
8464 else
8465 return Extensions_Visible_None;
8466 end if;
8468 Prag := Get_Pragma (Subp, Pragma_Extensions_Visible);
8470 -- In certain cases analysis may request the Extensions_Visible status
8471 -- of an expression function before the pragma has been analyzed yet.
8472 -- Inspect the declarative items after the expression function looking
8473 -- for the pragma (if any).
8475 if No (Prag) and then Is_Expression_Function (Subp) then
8476 Decl := Next (Unit_Declaration_Node (Subp));
8477 while Present (Decl) loop
8478 if Nkind (Decl) = N_Pragma
8479 and then Pragma_Name (Decl) = Name_Extensions_Visible
8480 then
8481 Prag := Decl;
8482 exit;
8484 -- A source construct ends the region where Extensions_Visible may
8485 -- appear, stop the traversal. An expanded expression function is
8486 -- no longer a source construct, but it must still be recognized.
8488 elsif Comes_From_Source (Decl)
8489 or else
8490 (Nkind (Decl) in N_Subprogram_Body | N_Subprogram_Declaration
8491 and then Is_Expression_Function (Defining_Entity (Decl)))
8492 then
8493 exit;
8494 end if;
8496 Next (Decl);
8497 end loop;
8498 end if;
8500 -- Extract the value from the Boolean expression (if any)
8502 if Present (Prag) then
8503 Arg := First (Pragma_Argument_Associations (Prag));
8505 if Present (Arg) then
8506 Expr := Get_Pragma_Arg (Arg);
8508 -- When the associated subprogram is an expression function, the
8509 -- argument of the pragma may not have been analyzed.
8511 if not Analyzed (Expr) then
8512 Preanalyze_And_Resolve (Expr, Standard_Boolean);
8513 end if;
8515 -- Guard against cascading errors when the argument of pragma
8516 -- Extensions_Visible is not a valid static Boolean expression.
8518 if Error_Posted (Expr) then
8519 return Extensions_Visible_None;
8521 elsif Is_True (Expr_Value (Expr)) then
8522 return Extensions_Visible_True;
8524 else
8525 return Extensions_Visible_False;
8526 end if;
8528 -- Otherwise the aspect or pragma defaults to True
8530 else
8531 return Extensions_Visible_True;
8532 end if;
8534 -- Otherwise aspect or pragma Extensions_Visible is not inherited or
8535 -- directly specified. In SPARK code, its value defaults to "False".
8537 elsif SPARK_Mode = On then
8538 return Extensions_Visible_False;
8540 -- In non-SPARK code, aspect or pragma Extensions_Visible defaults to
8541 -- "True".
8543 else
8544 return Extensions_Visible_True;
8545 end if;
8546 end Extensions_Visible_Status;
8548 -----------------
8549 -- Find_Actual --
8550 -----------------
8552 procedure Find_Actual
8553 (N : Node_Id;
8554 Formal : out Entity_Id;
8555 Call : out Node_Id)
8557 Context : constant Node_Id := Parent (N);
8558 Actual : Node_Id;
8559 Call_Nam : Node_Id;
8561 begin
8562 if Nkind (Context) in N_Indexed_Component | N_Selected_Component
8563 and then N = Prefix (Context)
8564 then
8565 Find_Actual (Context, Formal, Call);
8566 return;
8568 elsif Nkind (Context) = N_Parameter_Association
8569 and then N = Explicit_Actual_Parameter (Context)
8570 then
8571 Call := Parent (Context);
8573 elsif Nkind (Context) in N_Entry_Call_Statement
8574 | N_Function_Call
8575 | N_Procedure_Call_Statement
8576 then
8577 Call := Context;
8579 else
8580 Formal := Empty;
8581 Call := Empty;
8582 return;
8583 end if;
8585 -- If we have a call to a subprogram look for the parameter. Note that
8586 -- we exclude overloaded calls, since we don't know enough to be sure
8587 -- of giving the right answer in this case.
8589 if Nkind (Call) in N_Entry_Call_Statement
8590 | N_Function_Call
8591 | N_Procedure_Call_Statement
8592 then
8593 Call_Nam := Name (Call);
8595 -- A call to an entry family may appear as an indexed component
8597 if Nkind (Call_Nam) = N_Indexed_Component then
8598 Call_Nam := Prefix (Call_Nam);
8599 end if;
8601 -- A call to a protected or task entry appears as a selected
8602 -- component rather than an expanded name.
8604 if Nkind (Call_Nam) = N_Selected_Component then
8605 Call_Nam := Selector_Name (Call_Nam);
8606 end if;
8608 if Is_Entity_Name (Call_Nam)
8609 and then Present (Entity (Call_Nam))
8610 and then (Is_Generic_Subprogram (Entity (Call_Nam))
8611 or else Is_Overloadable (Entity (Call_Nam))
8612 or else Ekind (Entity (Call_Nam)) in E_Entry_Family
8613 | E_Subprogram_Body
8614 | E_Subprogram_Type)
8615 and then not Is_Overloaded (Call_Nam)
8616 then
8617 -- If node is name in call it is not an actual
8619 if N = Call_Nam then
8620 Formal := Empty;
8621 Call := Empty;
8622 return;
8623 end if;
8625 -- Fall here if we are definitely a parameter
8627 Actual := First_Actual (Call);
8628 Formal := First_Formal (Entity (Call_Nam));
8629 while Present (Formal) and then Present (Actual) loop
8630 if Actual = N then
8631 return;
8633 -- An actual that is the prefix in a prefixed call may have
8634 -- been rewritten in the call. Check if sloc and kinds and
8635 -- names match.
8637 elsif Sloc (Actual) = Sloc (N)
8638 and then Nkind (Actual) = N_Identifier
8639 and then Nkind (Actual) = Nkind (N)
8640 and then Chars (Actual) = Chars (N)
8641 then
8642 return;
8644 else
8645 Next_Actual (Actual);
8646 Next_Formal (Formal);
8647 end if;
8648 end loop;
8649 end if;
8650 end if;
8652 -- Fall through here if we did not find matching actual
8654 Formal := Empty;
8655 Call := Empty;
8656 end Find_Actual;
8658 ---------------------------
8659 -- Find_Body_Discriminal --
8660 ---------------------------
8662 function Find_Body_Discriminal
8663 (Spec_Discriminant : Entity_Id) return Entity_Id
8665 Tsk : Entity_Id;
8666 Disc : Entity_Id;
8668 begin
8669 -- If expansion is suppressed, then the scope can be the concurrent type
8670 -- itself rather than a corresponding concurrent record type.
8672 if Is_Concurrent_Type (Scope (Spec_Discriminant)) then
8673 Tsk := Scope (Spec_Discriminant);
8675 else
8676 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
8678 Tsk := Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
8679 end if;
8681 -- Find discriminant of original concurrent type, and use its current
8682 -- discriminal, which is the renaming within the task/protected body.
8684 Disc := First_Discriminant (Tsk);
8685 while Present (Disc) loop
8686 if Chars (Disc) = Chars (Spec_Discriminant) then
8687 return Discriminal (Disc);
8688 end if;
8690 Next_Discriminant (Disc);
8691 end loop;
8693 -- That loop should always succeed in finding a matching entry and
8694 -- returning. Fatal error if not.
8696 raise Program_Error;
8697 end Find_Body_Discriminal;
8699 -------------------------------------
8700 -- Find_Corresponding_Discriminant --
8701 -------------------------------------
8703 function Find_Corresponding_Discriminant
8704 (Id : Node_Id;
8705 Typ : Entity_Id) return Entity_Id
8707 Par_Disc : Entity_Id;
8708 Old_Disc : Entity_Id;
8709 New_Disc : Entity_Id;
8711 begin
8712 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
8714 -- The original type may currently be private, and the discriminant
8715 -- only appear on its full view.
8717 if Is_Private_Type (Scope (Par_Disc))
8718 and then not Has_Discriminants (Scope (Par_Disc))
8719 and then Present (Full_View (Scope (Par_Disc)))
8720 then
8721 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
8722 else
8723 Old_Disc := First_Discriminant (Scope (Par_Disc));
8724 end if;
8726 if Is_Class_Wide_Type (Typ) then
8727 New_Disc := First_Discriminant (Root_Type (Typ));
8728 else
8729 New_Disc := First_Discriminant (Typ);
8730 end if;
8732 while Present (Old_Disc) and then Present (New_Disc) loop
8733 if Old_Disc = Par_Disc then
8734 return New_Disc;
8735 end if;
8737 Next_Discriminant (Old_Disc);
8738 Next_Discriminant (New_Disc);
8739 end loop;
8741 -- Should always find it
8743 raise Program_Error;
8744 end Find_Corresponding_Discriminant;
8746 -------------------
8747 -- Find_DIC_Type --
8748 -------------------
8750 function Find_DIC_Type (Typ : Entity_Id) return Entity_Id is
8751 Curr_Typ : Entity_Id;
8752 -- The current type being examined in the parent hierarchy traversal
8754 DIC_Typ : Entity_Id;
8755 -- The type which carries the DIC pragma. This variable denotes the
8756 -- partial view when private types are involved.
8758 Par_Typ : Entity_Id;
8759 -- The parent type of the current type. This variable denotes the full
8760 -- view when private types are involved.
8762 begin
8763 -- The input type defines its own DIC pragma, therefore it is the owner
8765 if Has_Own_DIC (Typ) then
8766 DIC_Typ := Typ;
8768 -- Otherwise the DIC pragma is inherited from a parent type
8770 else
8771 pragma Assert (Has_Inherited_DIC (Typ));
8773 -- Climb the parent chain
8775 Curr_Typ := Typ;
8776 loop
8777 -- Inspect the parent type. Do not consider subtypes as they
8778 -- inherit the DIC attributes from their base types.
8780 DIC_Typ := Base_Type (Etype (Curr_Typ));
8782 -- Look at the full view of a private type because the type may
8783 -- have a hidden parent introduced in the full view.
8785 Par_Typ := DIC_Typ;
8787 if Is_Private_Type (Par_Typ)
8788 and then Present (Full_View (Par_Typ))
8789 then
8790 Par_Typ := Full_View (Par_Typ);
8791 end if;
8793 -- Stop the climb once the nearest parent type which defines a DIC
8794 -- pragma of its own is encountered or when the root of the parent
8795 -- chain is reached.
8797 exit when Has_Own_DIC (DIC_Typ) or else Curr_Typ = Par_Typ;
8799 Curr_Typ := Par_Typ;
8800 end loop;
8801 end if;
8803 return DIC_Typ;
8804 end Find_DIC_Type;
8806 ----------------------------------
8807 -- Find_Enclosing_Iterator_Loop --
8808 ----------------------------------
8810 function Find_Enclosing_Iterator_Loop (Id : Entity_Id) return Entity_Id is
8811 Constr : Node_Id;
8812 S : Entity_Id;
8814 begin
8815 -- Traverse the scope chain looking for an iterator loop. Such loops are
8816 -- usually transformed into blocks, hence the use of Original_Node.
8818 S := Id;
8819 while Present (S) and then S /= Standard_Standard loop
8820 if Ekind (S) = E_Loop
8821 and then Nkind (Parent (S)) = N_Implicit_Label_Declaration
8822 then
8823 Constr := Original_Node (Label_Construct (Parent (S)));
8825 if Nkind (Constr) = N_Loop_Statement
8826 and then Present (Iteration_Scheme (Constr))
8827 and then Nkind (Iterator_Specification
8828 (Iteration_Scheme (Constr))) =
8829 N_Iterator_Specification
8830 then
8831 return S;
8832 end if;
8833 end if;
8835 S := Scope (S);
8836 end loop;
8838 return Empty;
8839 end Find_Enclosing_Iterator_Loop;
8841 --------------------------
8842 -- Find_Enclosing_Scope --
8843 --------------------------
8845 function Find_Enclosing_Scope (N : Node_Id) return Entity_Id is
8846 Par : Node_Id;
8848 begin
8849 -- Examine the parent chain looking for a construct which defines a
8850 -- scope.
8852 Par := Parent (N);
8853 while Present (Par) loop
8854 case Nkind (Par) is
8856 -- The construct denotes a declaration, the proper scope is its
8857 -- entity.
8859 when N_Entry_Declaration
8860 | N_Expression_Function
8861 | N_Full_Type_Declaration
8862 | N_Generic_Package_Declaration
8863 | N_Generic_Subprogram_Declaration
8864 | N_Package_Declaration
8865 | N_Private_Extension_Declaration
8866 | N_Protected_Type_Declaration
8867 | N_Single_Protected_Declaration
8868 | N_Single_Task_Declaration
8869 | N_Subprogram_Declaration
8870 | N_Task_Type_Declaration
8872 return Defining_Entity (Par);
8874 -- The construct denotes a body, the proper scope is the entity of
8875 -- the corresponding spec or that of the body if the body does not
8876 -- complete a previous declaration.
8878 when N_Entry_Body
8879 | N_Package_Body
8880 | N_Protected_Body
8881 | N_Subprogram_Body
8882 | N_Task_Body
8884 return Unique_Defining_Entity (Par);
8886 -- Special cases
8888 -- Blocks carry either a source or an internally-generated scope,
8889 -- unless the block is a byproduct of exception handling.
8891 when N_Block_Statement =>
8892 if not Exception_Junk (Par) then
8893 return Entity (Identifier (Par));
8894 end if;
8896 -- Loops carry an internally-generated scope
8898 when N_Loop_Statement =>
8899 return Entity (Identifier (Par));
8901 -- Extended return statements carry an internally-generated scope
8903 when N_Extended_Return_Statement =>
8904 return Return_Statement_Entity (Par);
8906 -- A traversal from a subunit continues via the corresponding stub
8908 when N_Subunit =>
8909 Par := Corresponding_Stub (Par);
8911 when others =>
8912 null;
8913 end case;
8915 Par := Parent (Par);
8916 end loop;
8918 return Standard_Standard;
8919 end Find_Enclosing_Scope;
8921 ------------------------------------
8922 -- Find_Loop_In_Conditional_Block --
8923 ------------------------------------
8925 function Find_Loop_In_Conditional_Block (N : Node_Id) return Node_Id is
8926 Stmt : Node_Id;
8928 begin
8929 Stmt := N;
8931 if Nkind (Stmt) = N_If_Statement then
8932 Stmt := First (Then_Statements (Stmt));
8933 end if;
8935 pragma Assert (Nkind (Stmt) = N_Block_Statement);
8937 -- Inspect the statements of the conditional block. In general the loop
8938 -- should be the first statement in the statement sequence of the block,
8939 -- but the finalization machinery may have introduced extra object
8940 -- declarations.
8942 Stmt := First (Statements (Handled_Statement_Sequence (Stmt)));
8943 while Present (Stmt) loop
8944 if Nkind (Stmt) = N_Loop_Statement then
8945 return Stmt;
8946 end if;
8948 Next (Stmt);
8949 end loop;
8951 -- The expansion of attribute 'Loop_Entry produced a malformed block
8953 raise Program_Error;
8954 end Find_Loop_In_Conditional_Block;
8956 --------------------------
8957 -- Find_Overlaid_Entity --
8958 --------------------------
8960 procedure Find_Overlaid_Entity
8961 (N : Node_Id;
8962 Ent : out Entity_Id;
8963 Off : out Boolean)
8965 pragma Assert
8966 (Nkind (N) = N_Attribute_Definition_Clause
8967 and then Chars (N) = Name_Address);
8969 Expr : Node_Id;
8971 begin
8972 -- We are looking for one of the two following forms:
8974 -- for X'Address use Y'Address
8976 -- or
8978 -- Const : constant Address := expr;
8979 -- ...
8980 -- for X'Address use Const;
8982 -- In the second case, the expr is either Y'Address, or recursively a
8983 -- constant that eventually references Y'Address.
8985 Ent := Empty;
8986 Off := False;
8988 Expr := Expression (N);
8990 -- This loop checks the form of the expression for Y'Address, using
8991 -- recursion to deal with intermediate constants.
8993 loop
8994 -- Check for Y'Address
8996 if Nkind (Expr) = N_Attribute_Reference
8997 and then Attribute_Name (Expr) = Name_Address
8998 then
8999 Expr := Prefix (Expr);
9000 exit;
9002 -- Check for Const where Const is a constant entity
9004 elsif Is_Entity_Name (Expr)
9005 and then Ekind (Entity (Expr)) = E_Constant
9006 then
9007 Expr := Constant_Value (Entity (Expr));
9009 -- Anything else does not need checking
9011 else
9012 return;
9013 end if;
9014 end loop;
9016 -- This loop checks the form of the prefix for an entity, using
9017 -- recursion to deal with intermediate components.
9019 loop
9020 -- Check for Y where Y is an entity
9022 if Is_Entity_Name (Expr) then
9023 Ent := Entity (Expr);
9025 -- If expansion is disabled, then we might see an entity of a
9026 -- protected component or of a discriminant of a concurrent unit.
9027 -- Ignore such entities, because further warnings for overlays
9028 -- expect this routine to only collect entities of entire objects.
9030 if Ekind (Ent) in E_Component | E_Discriminant then
9031 pragma Assert
9032 (not Expander_Active
9033 and then Is_Concurrent_Type (Scope (Ent)));
9034 Ent := Empty;
9035 end if;
9036 return;
9038 -- Check for components
9040 elsif Nkind (Expr) in N_Selected_Component | N_Indexed_Component then
9041 Expr := Prefix (Expr);
9042 Off := True;
9044 -- Anything else does not need checking
9046 else
9047 return;
9048 end if;
9049 end loop;
9050 end Find_Overlaid_Entity;
9052 -------------------------
9053 -- Find_Parameter_Type --
9054 -------------------------
9056 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
9057 begin
9058 if Nkind (Param) /= N_Parameter_Specification then
9059 return Empty;
9061 -- For an access parameter, obtain the type from the formal entity
9062 -- itself, because access to subprogram nodes do not carry a type.
9063 -- Shouldn't we always use the formal entity ???
9065 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
9066 return Etype (Defining_Identifier (Param));
9068 else
9069 return Etype (Parameter_Type (Param));
9070 end if;
9071 end Find_Parameter_Type;
9073 -----------------------------------
9074 -- Find_Placement_In_State_Space --
9075 -----------------------------------
9077 procedure Find_Placement_In_State_Space
9078 (Item_Id : Entity_Id;
9079 Placement : out State_Space_Kind;
9080 Pack_Id : out Entity_Id)
9082 function Inside_Package_Body (Id : Entity_Id) return Boolean;
9083 function Inside_Private_Part (Id : Entity_Id) return Boolean;
9084 -- Return True if Id is declared directly within the package body
9085 -- and the package private parts, respectively. We cannot use
9086 -- In_Private_Part/In_Body_Part flags, as these are only set during the
9087 -- analysis of the package itself, while Find_Placement_In_State_Space
9088 -- can be called on an entity of another package.
9090 ------------------------
9091 -- Inside_Package_Body --
9092 ------------------------
9094 function Inside_Package_Body (Id : Entity_Id) return Boolean is
9095 Spec_Id : constant Entity_Id := Scope (Id);
9096 Body_Decl : constant Opt_N_Package_Body_Id := Package_Body (Spec_Id);
9097 Decl : constant Node_Id := Enclosing_Declaration (Id);
9098 begin
9099 if Present (Body_Decl)
9100 and then Is_List_Member (Decl)
9101 and then List_Containing (Decl) = Declarations (Body_Decl)
9102 then
9103 return True;
9104 else
9105 return False;
9106 end if;
9107 end Inside_Package_Body;
9109 -------------------------
9110 -- Inside_Private_Part --
9111 -------------------------
9113 function Inside_Private_Part (Id : Entity_Id) return Boolean is
9114 Spec_Id : constant Entity_Id := Scope (Id);
9115 Private_Decls : constant List_Id :=
9116 Private_Declarations (Package_Specification (Spec_Id));
9117 Decl : constant Node_Id := Enclosing_Declaration (Id);
9118 begin
9119 if Is_List_Member (Decl)
9120 and then List_Containing (Decl) = Private_Decls
9121 then
9122 return True;
9124 elsif Ekind (Id) = E_Package
9125 and then Is_Private_Library_Unit (Id)
9126 then
9127 return True;
9129 else
9130 return False;
9131 end if;
9132 end Inside_Private_Part;
9134 -- Local variables
9136 Context : Entity_Id;
9138 -- Start of processing for Find_Placement_In_State_Space
9140 begin
9141 -- Assume that the item does not appear in the state space of a package
9143 Placement := Not_In_Package;
9145 -- Climb the scope stack and examine the enclosing context
9147 Context := Item_Id;
9148 Pack_Id := Scope (Context);
9149 while Present (Pack_Id) and then Pack_Id /= Standard_Standard loop
9150 if Is_Package_Or_Generic_Package (Pack_Id) then
9152 -- A package body is a cut off point for the traversal as the
9153 -- item cannot be visible to the outside from this point on.
9155 if Inside_Package_Body (Context) then
9156 Placement := Body_State_Space;
9157 return;
9159 -- The private part of a package is a cut off point for the
9160 -- traversal as the item cannot be visible to the outside
9161 -- from this point on.
9163 elsif Inside_Private_Part (Context) then
9164 Placement := Private_State_Space;
9165 return;
9167 -- When the item appears in the visible state space of a package,
9168 -- continue to climb the scope stack as this may not be the final
9169 -- state space.
9171 else
9172 Placement := Visible_State_Space;
9174 -- The visible state space of a child unit acts as the proper
9175 -- placement of an item, unless this is a private child unit.
9177 if Is_Child_Unit (Pack_Id)
9178 and then not Is_Private_Library_Unit (Pack_Id)
9179 then
9180 return;
9181 end if;
9182 end if;
9184 -- The item or its enclosing package appear in a construct that has
9185 -- no state space.
9187 else
9188 Placement := Not_In_Package;
9189 Pack_Id := Empty;
9190 return;
9191 end if;
9193 Context := Scope (Context);
9194 Pack_Id := Scope (Context);
9195 end loop;
9196 end Find_Placement_In_State_Space;
9198 -----------------------
9199 -- Find_Primitive_Eq --
9200 -----------------------
9202 function Find_Primitive_Eq (Typ : Entity_Id) return Entity_Id is
9203 function Find_Eq_Prim (Prims_List : Elist_Id) return Entity_Id;
9204 -- Search for the equality primitive; return Empty if the primitive is
9205 -- not found.
9207 ------------------
9208 -- Find_Eq_Prim --
9209 ------------------
9211 function Find_Eq_Prim (Prims_List : Elist_Id) return Entity_Id is
9212 Prim : Entity_Id;
9213 Prim_Elmt : Elmt_Id;
9215 begin
9216 Prim_Elmt := First_Elmt (Prims_List);
9217 while Present (Prim_Elmt) loop
9218 Prim := Node (Prim_Elmt);
9220 -- Locate primitive equality with the right signature
9222 if Chars (Prim) = Name_Op_Eq
9223 and then Etype (First_Formal (Prim)) =
9224 Etype (Next_Formal (First_Formal (Prim)))
9225 and then Base_Type (Etype (Prim)) = Standard_Boolean
9226 then
9227 return Prim;
9228 end if;
9230 Next_Elmt (Prim_Elmt);
9231 end loop;
9233 return Empty;
9234 end Find_Eq_Prim;
9236 -- Local Variables
9238 Eq_Prim : Entity_Id;
9239 Full_Type : Entity_Id;
9241 -- Start of processing for Find_Primitive_Eq
9243 begin
9244 if Is_Private_Type (Typ) then
9245 Full_Type := Underlying_Type (Typ);
9246 else
9247 Full_Type := Typ;
9248 end if;
9250 if No (Full_Type) then
9251 return Empty;
9252 end if;
9254 Full_Type := Base_Type (Full_Type);
9256 -- When the base type itself is private, use the full view
9258 if Is_Private_Type (Full_Type) then
9259 Full_Type := Underlying_Type (Full_Type);
9260 end if;
9262 if Is_Class_Wide_Type (Full_Type) then
9263 Full_Type := Root_Type (Full_Type);
9264 end if;
9266 if not Is_Tagged_Type (Full_Type) then
9267 Eq_Prim := Find_Eq_Prim (Collect_Primitive_Operations (Typ));
9269 -- If this is an untagged private type completed with a derivation of
9270 -- an untagged private type whose full view is a tagged type, we use
9271 -- the primitive operations of the private parent type (since it does
9272 -- not have a full view, and also because its equality primitive may
9273 -- have been overridden in its untagged full view). If no equality was
9274 -- defined for it then take its dispatching equality primitive.
9276 elsif Inherits_From_Tagged_Full_View (Typ) then
9277 Eq_Prim := Find_Eq_Prim (Collect_Primitive_Operations (Typ));
9279 if No (Eq_Prim) then
9280 Eq_Prim := Find_Eq_Prim (Primitive_Operations (Full_Type));
9281 end if;
9283 else
9284 Eq_Prim := Find_Eq_Prim (Primitive_Operations (Full_Type));
9285 end if;
9287 return Eq_Prim;
9288 end Find_Primitive_Eq;
9290 ------------------------
9291 -- Find_Specific_Type --
9292 ------------------------
9294 function Find_Specific_Type (CW : Entity_Id) return Entity_Id is
9295 Typ : Entity_Id := Root_Type (CW);
9297 begin
9298 if Ekind (Typ) = E_Incomplete_Type then
9299 if From_Limited_With (Typ) then
9300 Typ := Non_Limited_View (Typ);
9301 else
9302 Typ := Full_View (Typ);
9303 end if;
9304 end if;
9306 if Is_Private_Type (Typ)
9307 and then not Is_Tagged_Type (Typ)
9308 and then Present (Full_View (Typ))
9309 then
9310 return Full_View (Typ);
9311 else
9312 return Typ;
9313 end if;
9314 end Find_Specific_Type;
9316 -----------------------------
9317 -- Find_Static_Alternative --
9318 -----------------------------
9320 function Find_Static_Alternative (N : Node_Id) return Node_Id is
9321 Expr : constant Node_Id := Expression (N);
9322 Val : constant Uint := Expr_Value (Expr);
9323 Alt : Node_Id;
9324 Choice : Node_Id;
9326 begin
9327 Alt := First (Alternatives (N));
9329 Search : loop
9330 if Nkind (Alt) /= N_Pragma then
9331 Choice := First (Discrete_Choices (Alt));
9332 while Present (Choice) loop
9334 -- Others choice, always matches
9336 if Nkind (Choice) = N_Others_Choice then
9337 exit Search;
9339 -- Range, check if value is in the range
9341 elsif Nkind (Choice) = N_Range then
9342 exit Search when
9343 Val >= Expr_Value (Low_Bound (Choice))
9344 and then
9345 Val <= Expr_Value (High_Bound (Choice));
9347 -- Choice is a subtype name. Note that we know it must
9348 -- be a static subtype, since otherwise it would have
9349 -- been diagnosed as illegal.
9351 elsif Is_Entity_Name (Choice)
9352 and then Is_Type (Entity (Choice))
9353 then
9354 exit Search when Is_In_Range (Expr, Etype (Choice),
9355 Assume_Valid => False);
9357 -- Choice is a subtype indication
9359 elsif Nkind (Choice) = N_Subtype_Indication then
9360 declare
9361 C : constant Node_Id := Constraint (Choice);
9362 R : constant Node_Id := Range_Expression (C);
9364 begin
9365 exit Search when
9366 Val >= Expr_Value (Low_Bound (R))
9367 and then
9368 Val <= Expr_Value (High_Bound (R));
9369 end;
9371 -- Choice is a simple expression
9373 else
9374 exit Search when Val = Expr_Value (Choice);
9375 end if;
9377 Next (Choice);
9378 end loop;
9379 end if;
9381 Next (Alt);
9382 pragma Assert (Present (Alt));
9383 end loop Search;
9385 -- The above loop *must* terminate by finding a match, since we know the
9386 -- case statement is valid, and the value of the expression is known at
9387 -- compile time. When we fall out of the loop, Alt points to the
9388 -- alternative that we know will be selected at run time.
9390 return Alt;
9391 end Find_Static_Alternative;
9393 ------------------
9394 -- First_Actual --
9395 ------------------
9397 function First_Actual (Node : Node_Id) return Node_Id is
9398 N : Node_Id;
9400 begin
9401 if No (Parameter_Associations (Node)) then
9402 return Empty;
9403 end if;
9405 N := First (Parameter_Associations (Node));
9407 if Nkind (N) = N_Parameter_Association then
9408 return First_Named_Actual (Node);
9409 else
9410 return N;
9411 end if;
9412 end First_Actual;
9414 ------------------
9415 -- First_Global --
9416 ------------------
9418 function First_Global
9419 (Subp : Entity_Id;
9420 Global_Mode : Name_Id;
9421 Refined : Boolean := False) return Node_Id
9423 function First_From_Global_List
9424 (List : Node_Id;
9425 Global_Mode : Name_Id := Name_Input) return Entity_Id;
9426 -- Get the first item with suitable mode from List
9428 ----------------------------
9429 -- First_From_Global_List --
9430 ----------------------------
9432 function First_From_Global_List
9433 (List : Node_Id;
9434 Global_Mode : Name_Id := Name_Input) return Entity_Id
9436 Assoc : Node_Id;
9438 begin
9439 -- Empty list (no global items)
9441 if Nkind (List) = N_Null then
9442 return Empty;
9444 -- Single global item declaration (only input items)
9446 elsif Nkind (List) in N_Expanded_Name | N_Identifier then
9447 if Global_Mode = Name_Input then
9448 return List;
9449 else
9450 return Empty;
9451 end if;
9453 -- Simple global list (only input items) or moded global list
9454 -- declaration.
9456 elsif Nkind (List) = N_Aggregate then
9457 if Present (Expressions (List)) then
9458 if Global_Mode = Name_Input then
9459 return First (Expressions (List));
9460 else
9461 return Empty;
9462 end if;
9464 else
9465 Assoc := First (Component_Associations (List));
9466 while Present (Assoc) loop
9468 -- When we find the desired mode in an association, call
9469 -- recursively First_From_Global_List as if the mode was
9470 -- Name_Input, in order to reuse the existing machinery
9471 -- for the other cases.
9473 if Chars (First (Choices (Assoc))) = Global_Mode then
9474 return First_From_Global_List (Expression (Assoc));
9475 end if;
9477 Next (Assoc);
9478 end loop;
9480 return Empty;
9481 end if;
9483 -- To accommodate partial decoration of disabled SPARK features,
9484 -- this routine may be called with illegal input. If this is the
9485 -- case, do not raise Program_Error.
9487 else
9488 return Empty;
9489 end if;
9490 end First_From_Global_List;
9492 -- Local variables
9494 Global : Node_Id := Empty;
9495 Body_Id : Entity_Id;
9497 -- Start of processing for First_Global
9499 begin
9500 pragma Assert (Global_Mode in Name_In_Out
9501 | Name_Input
9502 | Name_Output
9503 | Name_Proof_In);
9505 -- Retrieve the suitable pragma Global or Refined_Global. In the second
9506 -- case, it can only be located on the body entity.
9508 if Refined then
9509 if Is_Subprogram_Or_Generic_Subprogram (Subp) then
9510 Body_Id := Subprogram_Body_Entity (Subp);
9512 elsif Is_Entry (Subp) or else Is_Task_Type (Subp) then
9513 Body_Id := Corresponding_Body (Parent (Subp));
9515 -- ??? It should be possible to retrieve the Refined_Global on the
9516 -- task body associated to the task object. This is not yet possible.
9518 elsif Is_Single_Task_Object (Subp) then
9519 Body_Id := Empty;
9521 else
9522 Body_Id := Empty;
9523 end if;
9525 if Present (Body_Id) then
9526 Global := Get_Pragma (Body_Id, Pragma_Refined_Global);
9527 end if;
9528 else
9529 Global := Get_Pragma (Subp, Pragma_Global);
9530 end if;
9532 -- No corresponding global if pragma is not present
9534 if No (Global) then
9535 return Empty;
9537 -- Otherwise retrieve the corresponding list of items depending on the
9538 -- Global_Mode.
9540 else
9541 return First_From_Global_List
9542 (Expression (Get_Argument (Global, Subp)), Global_Mode);
9543 end if;
9544 end First_Global;
9546 -------------
9547 -- Fix_Msg --
9548 -------------
9550 function Fix_Msg (Id : Entity_Id; Msg : String) return String is
9551 Is_Task : constant Boolean :=
9552 Ekind (Id) in E_Task_Body | E_Task_Type
9553 or else Is_Single_Task_Object (Id);
9554 Msg_Last : constant Natural := Msg'Last;
9555 Msg_Index : Natural;
9556 Res : String (Msg'Range) := (others => ' ');
9557 Res_Index : Natural;
9559 begin
9560 -- Copy all characters from the input message Msg to result Res with
9561 -- suitable replacements.
9563 Msg_Index := Msg'First;
9564 Res_Index := Res'First;
9565 while Msg_Index <= Msg_Last loop
9567 -- Replace "subprogram" with a different word
9569 if Msg_Index <= Msg_Last - 10
9570 and then Msg (Msg_Index .. Msg_Index + 9) = "subprogram"
9571 then
9572 if Is_Entry (Id) then
9573 Res (Res_Index .. Res_Index + 4) := "entry";
9574 Res_Index := Res_Index + 5;
9576 elsif Is_Task then
9577 Res (Res_Index .. Res_Index + 8) := "task type";
9578 Res_Index := Res_Index + 9;
9580 else
9581 Res (Res_Index .. Res_Index + 9) := "subprogram";
9582 Res_Index := Res_Index + 10;
9583 end if;
9585 Msg_Index := Msg_Index + 10;
9587 -- Replace "protected" with a different word
9589 elsif Msg_Index <= Msg_Last - 9
9590 and then Msg (Msg_Index .. Msg_Index + 8) = "protected"
9591 and then Is_Task
9592 then
9593 Res (Res_Index .. Res_Index + 3) := "task";
9594 Res_Index := Res_Index + 4;
9595 Msg_Index := Msg_Index + 9;
9597 -- Otherwise copy the character
9599 else
9600 Res (Res_Index) := Msg (Msg_Index);
9601 Msg_Index := Msg_Index + 1;
9602 Res_Index := Res_Index + 1;
9603 end if;
9604 end loop;
9606 return Res (Res'First .. Res_Index - 1);
9607 end Fix_Msg;
9609 -------------------------
9610 -- From_Nested_Package --
9611 -------------------------
9613 function From_Nested_Package (T : Entity_Id) return Boolean is
9614 Pack : constant Entity_Id := Scope (T);
9616 begin
9617 return
9618 Ekind (Pack) = E_Package
9619 and then not Is_Frozen (Pack)
9620 and then not Scope_Within_Or_Same (Current_Scope, Pack)
9621 and then In_Open_Scopes (Scope (Pack));
9622 end From_Nested_Package;
9624 -----------------------
9625 -- Gather_Components --
9626 -----------------------
9628 procedure Gather_Components
9629 (Typ : Entity_Id;
9630 Comp_List : Node_Id;
9631 Governed_By : List_Id;
9632 Into : Elist_Id;
9633 Report_Errors : out Boolean;
9634 Allow_Compile_Time : Boolean := False;
9635 Include_Interface_Tag : Boolean := False)
9637 Assoc : Node_Id;
9638 Variant : Node_Id;
9639 Discrete_Choice : Node_Id;
9640 Comp_Item : Node_Id;
9641 Discrim : Entity_Id;
9642 Discrim_Name : Node_Id;
9644 type Discriminant_Value_Status is
9645 (Static_Expr, Static_Subtype, Bad);
9646 subtype Good_Discrim_Value_Status is Discriminant_Value_Status
9647 range Static_Expr .. Static_Subtype; -- range excludes Bad
9649 Discrim_Value : Node_Id;
9650 Discrim_Value_Subtype : Node_Id;
9651 Discrim_Value_Status : Discriminant_Value_Status := Bad;
9653 function OK_Scope_For_Discrim_Value_Error_Messages return Boolean is
9654 (Scope (Original_Record_Component
9655 (Entity (First (Choices (Assoc))))) = Typ);
9656 -- Used to avoid generating error messages having a source position
9657 -- which refers to somewhere (e.g., a discriminant value in a derived
9658 -- tagged type declaration) unrelated to the offending construct. This
9659 -- is required for correctness - clients of Gather_Components such as
9660 -- Sem_Ch3.Create_Constrained_Components depend on this function
9661 -- returning True while processing semantically correct examples;
9662 -- generating an error message in this case would be wrong.
9664 begin
9665 Report_Errors := False;
9667 if No (Comp_List) or else Null_Present (Comp_List) then
9668 return;
9670 elsif Present (Component_Items (Comp_List)) then
9671 Comp_Item := First (Component_Items (Comp_List));
9673 else
9674 Comp_Item := Empty;
9675 end if;
9677 while Present (Comp_Item) loop
9679 -- Skip the tag of a tagged record, as well as all items that are not
9680 -- user components (anonymous types, rep clauses, Parent field,
9681 -- controller field).
9683 if Nkind (Comp_Item) = N_Component_Declaration then
9684 declare
9685 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
9686 begin
9687 if not (Is_Tag (Comp)
9688 and then not
9689 (Include_Interface_Tag
9690 and then Etype (Comp) = RTE (RE_Interface_Tag)))
9691 and then Chars (Comp) /= Name_uParent
9692 then
9693 Append_Elmt (Comp, Into);
9694 end if;
9695 end;
9696 end if;
9698 Next (Comp_Item);
9699 end loop;
9701 if No (Variant_Part (Comp_List)) then
9702 return;
9703 else
9704 Discrim_Name := Name (Variant_Part (Comp_List));
9705 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
9706 end if;
9708 -- Look for the discriminant that governs this variant part.
9709 -- The discriminant *must* be in the Governed_By List
9711 Assoc := First (Governed_By);
9712 Find_Constraint : loop
9713 Discrim := First (Choices (Assoc));
9714 exit Find_Constraint when
9715 Chars (Discrim_Name) = Chars (Discrim)
9716 or else
9717 (Present (Corresponding_Discriminant (Entity (Discrim)))
9718 and then Chars (Corresponding_Discriminant
9719 (Entity (Discrim))) = Chars (Discrim_Name))
9720 or else
9721 Chars (Original_Record_Component (Entity (Discrim))) =
9722 Chars (Discrim_Name);
9724 if No (Next (Assoc)) then
9725 if not Is_Constrained (Typ) and then Is_Derived_Type (Typ) then
9727 -- If the type is a tagged type with inherited discriminants,
9728 -- use the stored constraint on the parent in order to find
9729 -- the values of discriminants that are otherwise hidden by an
9730 -- explicit constraint. Renamed discriminants are handled in
9731 -- the code above.
9733 -- If several parent discriminants are renamed by a single
9734 -- discriminant of the derived type, the call to obtain the
9735 -- Corresponding_Discriminant field only retrieves the last
9736 -- of them. We recover the constraint on the others from the
9737 -- Stored_Constraint as well.
9739 -- An inherited discriminant may have been constrained in a
9740 -- later ancestor (not the immediate parent) so we must examine
9741 -- the stored constraint of all of them to locate the inherited
9742 -- value.
9744 declare
9745 C : Elmt_Id;
9746 D : Entity_Id;
9747 T : Entity_Id := Typ;
9749 begin
9750 while Is_Derived_Type (T) loop
9751 if Present (Stored_Constraint (T)) then
9752 D := First_Discriminant (Etype (T));
9753 C := First_Elmt (Stored_Constraint (T));
9754 while Present (D) and then Present (C) loop
9755 if Chars (Discrim_Name) = Chars (D) then
9756 if Is_Entity_Name (Node (C))
9757 and then Entity (Node (C)) = Entity (Discrim)
9758 then
9759 -- D is renamed by Discrim, whose value is
9760 -- given in Assoc.
9762 null;
9764 else
9765 Assoc :=
9766 Make_Component_Association (Sloc (Typ),
9767 New_List
9768 (New_Occurrence_Of (D, Sloc (Typ))),
9769 Duplicate_Subexpr_No_Checks (Node (C)));
9770 end if;
9772 exit Find_Constraint;
9773 end if;
9775 Next_Discriminant (D);
9776 Next_Elmt (C);
9777 end loop;
9778 end if;
9780 -- Discriminant may be inherited from ancestor
9782 T := Etype (T);
9783 end loop;
9784 end;
9785 end if;
9786 end if;
9788 if No (Next (Assoc)) then
9789 Error_Msg_NE
9790 (" missing value for discriminant&",
9791 First (Governed_By), Discrim_Name);
9793 Report_Errors := True;
9794 return;
9795 end if;
9797 Next (Assoc);
9798 end loop Find_Constraint;
9800 Discrim_Value := Expression (Assoc);
9802 if Is_OK_Static_Expression (Discrim_Value)
9803 or else (Allow_Compile_Time
9804 and then Compile_Time_Known_Value (Discrim_Value))
9805 then
9806 Discrim_Value_Status := Static_Expr;
9807 else
9808 if Ada_Version >= Ada_2022 then
9809 if Is_Rewrite_Substitution (Discrim_Value)
9810 and then Nkind (Discrim_Value) = N_Type_Conversion
9811 and then Etype (Original_Node (Discrim_Value))
9812 = Etype (Expression (Discrim_Value))
9813 then
9814 Discrim_Value_Subtype := Etype (Original_Node (Discrim_Value));
9815 -- An unhelpful (for this code) type conversion may be
9816 -- introduced in some cases; deal with it.
9817 else
9818 Discrim_Value_Subtype := Etype (Discrim_Value);
9819 end if;
9821 if Is_OK_Static_Subtype (Discrim_Value_Subtype) and then
9822 not Is_Null_Range (Type_Low_Bound (Discrim_Value_Subtype),
9823 Type_High_Bound (Discrim_Value_Subtype))
9824 then
9825 -- Is_Null_Range test doesn't account for predicates, as in
9826 -- subtype Null_By_Predicate is Natural
9827 -- with Static_Predicate => Null_By_Predicate < 0;
9828 -- so test for that null case separately.
9830 if (not Has_Static_Predicate (Discrim_Value_Subtype))
9831 or else Present (First (Static_Discrete_Predicate
9832 (Discrim_Value_Subtype)))
9833 then
9834 Discrim_Value_Status := Static_Subtype;
9835 end if;
9836 end if;
9837 end if;
9839 if Discrim_Value_Status = Bad then
9841 -- If the variant part is governed by a discriminant of the type
9842 -- this is an error. If the variant part and the discriminant are
9843 -- inherited from an ancestor this is legal (AI05-220) unless the
9844 -- components are being gathered for an aggregate, in which case
9845 -- the caller must check Report_Errors.
9847 -- In Ada 2022 the above rules are relaxed. A nonstatic governing
9848 -- discriminant is OK as long as it has a static subtype and
9849 -- every value of that subtype (and there must be at least one)
9850 -- selects the same variant.
9852 if OK_Scope_For_Discrim_Value_Error_Messages then
9853 if Ada_Version >= Ada_2022 then
9854 Error_Msg_FE
9855 ("value for discriminant & must be static or " &
9856 "discriminant's nominal subtype must be static " &
9857 "and non-null!",
9858 Discrim_Value, Discrim);
9859 else
9860 Error_Msg_FE
9861 ("value for discriminant & must be static!",
9862 Discrim_Value, Discrim);
9863 end if;
9864 Why_Not_Static (Discrim_Value);
9865 end if;
9867 Report_Errors := True;
9868 return;
9869 end if;
9870 end if;
9872 Search_For_Discriminant_Value : declare
9873 Low : Node_Id;
9874 High : Node_Id;
9876 UI_High : Uint;
9877 UI_Low : Uint;
9878 UI_Discrim_Value : Uint;
9880 begin
9881 case Good_Discrim_Value_Status'(Discrim_Value_Status) is
9882 when Static_Expr =>
9883 UI_Discrim_Value := Expr_Value (Discrim_Value);
9884 when Static_Subtype =>
9885 -- Arbitrarily pick one value of the subtype and look
9886 -- for the variant associated with that value; we will
9887 -- check later that the same variant is associated with
9888 -- all of the other values of the subtype.
9889 if Has_Static_Predicate (Discrim_Value_Subtype) then
9890 declare
9891 Range_Or_Expr : constant Node_Id :=
9892 First (Static_Discrete_Predicate
9893 (Discrim_Value_Subtype));
9894 begin
9895 if Nkind (Range_Or_Expr) = N_Range then
9896 UI_Discrim_Value :=
9897 Expr_Value (Low_Bound (Range_Or_Expr));
9898 else
9899 UI_Discrim_Value := Expr_Value (Range_Or_Expr);
9900 end if;
9901 end;
9902 else
9903 UI_Discrim_Value
9904 := Expr_Value (Type_Low_Bound (Discrim_Value_Subtype));
9905 end if;
9906 end case;
9908 Find_Discrete_Value : while Present (Variant) loop
9910 -- If a choice is a subtype with a static predicate, it must
9911 -- be rewritten as an explicit list of non-predicated choices.
9913 Expand_Static_Predicates_In_Choices (Variant);
9915 Discrete_Choice := First (Discrete_Choices (Variant));
9916 while Present (Discrete_Choice) loop
9917 exit Find_Discrete_Value when
9918 Nkind (Discrete_Choice) = N_Others_Choice;
9920 Get_Index_Bounds (Discrete_Choice, Low, High);
9922 UI_Low := Expr_Value (Low);
9923 UI_High := Expr_Value (High);
9925 exit Find_Discrete_Value when
9926 UI_Low <= UI_Discrim_Value
9927 and then
9928 UI_High >= UI_Discrim_Value;
9930 Next (Discrete_Choice);
9931 end loop;
9933 Next_Non_Pragma (Variant);
9934 end loop Find_Discrete_Value;
9935 end Search_For_Discriminant_Value;
9937 -- The case statement must include a variant that corresponds to the
9938 -- value of the discriminant, unless the discriminant type has a
9939 -- static predicate. In that case the absence of an others_choice that
9940 -- would cover this value becomes a run-time error (3.8.1 (21.1/2)).
9942 if No (Variant)
9943 and then not Has_Static_Predicate (Etype (Discrim_Name))
9944 then
9945 Error_Msg_NE
9946 ("value of discriminant & is out of range", Discrim_Value, Discrim);
9947 Report_Errors := True;
9948 return;
9949 end if;
9951 -- If we have found the corresponding choice, recursively add its
9952 -- components to the Into list. The nested components are part of
9953 -- the same record type.
9955 if Present (Variant) then
9956 if Discrim_Value_Status = Static_Subtype then
9957 declare
9958 Discrim_Value_Subtype_Intervals
9959 : constant Interval_Lists.Discrete_Interval_List
9960 := Interval_Lists.Type_Intervals (Discrim_Value_Subtype);
9962 Variant_Intervals
9963 : constant Interval_Lists.Discrete_Interval_List
9964 := Interval_Lists.Choice_List_Intervals
9965 (Discrete_Choices => Discrete_Choices (Variant));
9966 begin
9967 if not Interval_Lists.Is_Subset
9968 (Subset => Discrim_Value_Subtype_Intervals,
9969 Of_Set => Variant_Intervals)
9970 then
9971 if OK_Scope_For_Discrim_Value_Error_Messages then
9972 Error_Msg_NE
9973 ("no single variant is associated with all values of " &
9974 "the subtype of discriminant value &",
9975 Discrim_Value, Discrim);
9976 end if;
9977 Report_Errors := True;
9978 return;
9979 end if;
9980 end;
9981 end if;
9983 Gather_Components
9984 (Typ, Component_List (Variant), Governed_By, Into,
9985 Report_Errors, Allow_Compile_Time);
9986 end if;
9987 end Gather_Components;
9989 ------------------------
9990 -- Get_Actual_Subtype --
9991 ------------------------
9993 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
9994 Typ : constant Entity_Id := Etype (N);
9995 Utyp : Entity_Id := Underlying_Type (Typ);
9996 Decl : Node_Id;
9997 Atyp : Entity_Id;
9999 begin
10000 if No (Utyp) then
10001 Utyp := Typ;
10002 end if;
10004 -- If what we have is an identifier that references a subprogram
10005 -- formal, or a variable or constant object, then we get the actual
10006 -- subtype from the referenced entity if one has been built.
10008 if Nkind (N) = N_Identifier
10009 and then
10010 (Is_Formal (Entity (N))
10011 or else Ekind (Entity (N)) = E_Constant
10012 or else Ekind (Entity (N)) = E_Variable)
10013 and then Present (Actual_Subtype (Entity (N)))
10014 then
10015 return Actual_Subtype (Entity (N));
10017 -- Actual subtype of unchecked union is always itself. We never need
10018 -- the "real" actual subtype. If we did, we couldn't get it anyway
10019 -- because the discriminant is not available. The restrictions on
10020 -- Unchecked_Union are designed to make sure that this is OK.
10022 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
10023 return Typ;
10025 -- Here for the unconstrained case, we must find actual subtype
10026 -- No actual subtype is available, so we must build it on the fly.
10028 -- Checking the type, not the underlying type, for constrainedness
10029 -- seems to be necessary. Maybe all the tests should be on the type???
10031 elsif (not Is_Constrained (Typ))
10032 and then (Is_Array_Type (Utyp)
10033 or else (Is_Record_Type (Utyp)
10034 and then Has_Discriminants (Utyp)))
10035 and then not Has_Unknown_Discriminants (Utyp)
10036 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
10037 then
10038 -- Nothing to do if in spec expression (why not???)
10040 if In_Spec_Expression then
10041 return Typ;
10043 elsif Is_Private_Type (Typ) and then not Has_Discriminants (Typ) then
10045 -- If the type has no discriminants, there is no subtype to
10046 -- build, even if the underlying type is discriminated.
10048 return Typ;
10050 -- Else build the actual subtype
10052 else
10053 Decl := Build_Actual_Subtype (Typ, N);
10055 -- The call may yield a declaration, or just return the entity
10057 if Decl = Typ then
10058 return Typ;
10059 end if;
10061 Atyp := Defining_Identifier (Decl);
10063 -- If Build_Actual_Subtype generated a new declaration then use it
10065 if Atyp /= Typ then
10067 -- The actual subtype is an Itype, so analyze the declaration,
10068 -- but do not attach it to the tree, to get the type defined.
10070 Set_Parent (Decl, N);
10071 Set_Is_Itype (Atyp);
10072 Analyze (Decl, Suppress => All_Checks);
10073 Set_Associated_Node_For_Itype (Atyp, N);
10074 if Expander_Active then
10075 Set_Has_Delayed_Freeze (Atyp, False);
10077 -- We need to freeze the actual subtype immediately. This is
10078 -- needed because otherwise this Itype will not get frozen
10079 -- at all; it is always safe to freeze on creation because
10080 -- any associated types must be frozen at this point.
10082 -- On the other hand, if we are performing preanalysis on
10083 -- a conjured-up copy of a name (see calls to
10084 -- Preanalyze_Range in sem_ch5.adb) then we don't want
10085 -- to freeze Atyp, now or ever. In this case, the tree
10086 -- we eventually pass to the back end should contain no
10087 -- references to Atyp (and a freeze node would contain
10088 -- such a reference). That's why Expander_Active is tested.
10090 Freeze_Itype (Atyp, N);
10091 end if;
10092 return Atyp;
10094 -- Otherwise we did not build a declaration, so return original
10096 else
10097 return Typ;
10098 end if;
10099 end if;
10101 -- For all remaining cases, the actual subtype is the same as
10102 -- the nominal type.
10104 else
10105 return Typ;
10106 end if;
10107 end Get_Actual_Subtype;
10109 -------------------------------------
10110 -- Get_Actual_Subtype_If_Available --
10111 -------------------------------------
10113 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
10114 Typ : constant Entity_Id := Etype (N);
10116 begin
10117 -- If what we have is an identifier that references a subprogram
10118 -- formal, or a variable or constant object, then we get the actual
10119 -- subtype from the referenced entity if one has been built.
10121 if Nkind (N) = N_Identifier
10122 and then
10123 (Is_Formal (Entity (N))
10124 or else Ekind (Entity (N)) = E_Constant
10125 or else Ekind (Entity (N)) = E_Variable)
10126 and then Present (Actual_Subtype (Entity (N)))
10127 then
10128 return Actual_Subtype (Entity (N));
10130 -- Otherwise the Etype of N is returned unchanged
10132 else
10133 return Typ;
10134 end if;
10135 end Get_Actual_Subtype_If_Available;
10137 ------------------------
10138 -- Get_Body_From_Stub --
10139 ------------------------
10141 function Get_Body_From_Stub (N : Node_Id) return Node_Id is
10142 begin
10143 return Proper_Body (Unit (Library_Unit (N)));
10144 end Get_Body_From_Stub;
10146 ---------------------
10147 -- Get_Cursor_Type --
10148 ---------------------
10150 function Get_Cursor_Type
10151 (Aspect : Node_Id;
10152 Typ : Entity_Id) return Entity_Id
10154 Assoc : Node_Id;
10155 Func : Entity_Id;
10156 First_Op : Entity_Id;
10157 Cursor : Entity_Id;
10159 begin
10160 -- If error already detected, return
10162 if Error_Posted (Aspect) then
10163 return Any_Type;
10164 end if;
10166 -- The cursor type for an Iterable aspect is the return type of a
10167 -- non-overloaded First primitive operation. Locate association for
10168 -- First.
10170 Assoc := First (Component_Associations (Expression (Aspect)));
10171 First_Op := Any_Id;
10172 while Present (Assoc) loop
10173 if Chars (First (Choices (Assoc))) = Name_First then
10174 First_Op := Expression (Assoc);
10175 exit;
10176 end if;
10178 Next (Assoc);
10179 end loop;
10181 if First_Op = Any_Id then
10182 Error_Msg_N ("aspect Iterable must specify First operation", Aspect);
10183 return Any_Type;
10185 elsif not Analyzed (First_Op) then
10186 Analyze (First_Op);
10187 end if;
10189 Cursor := Any_Type;
10191 -- Locate function with desired name and profile in scope of type
10192 -- In the rare case where the type is an integer type, a base type
10193 -- is created for it, check that the base type of the first formal
10194 -- of First matches the base type of the domain.
10196 Func := First_Entity (Scope (Typ));
10197 while Present (Func) loop
10198 if Chars (Func) = Chars (First_Op)
10199 and then Ekind (Func) = E_Function
10200 and then Present (First_Formal (Func))
10201 and then Base_Type (Etype (First_Formal (Func))) = Base_Type (Typ)
10202 and then No (Next_Formal (First_Formal (Func)))
10203 then
10204 if Cursor /= Any_Type then
10205 Error_Msg_N
10206 ("operation First for iterable type must be unique", Aspect);
10207 return Any_Type;
10208 else
10209 Cursor := Etype (Func);
10210 end if;
10211 end if;
10213 Next_Entity (Func);
10214 end loop;
10216 -- If not found, no way to resolve remaining primitives
10218 if Cursor = Any_Type then
10219 Error_Msg_N
10220 ("primitive operation for Iterable type must appear in the same "
10221 & "list of declarations as the type", Aspect);
10222 end if;
10224 return Cursor;
10225 end Get_Cursor_Type;
10227 function Get_Cursor_Type (Typ : Entity_Id) return Entity_Id is
10228 begin
10229 return Etype (Get_Iterable_Type_Primitive (Typ, Name_First));
10230 end Get_Cursor_Type;
10232 -------------------------------
10233 -- Get_Default_External_Name --
10234 -------------------------------
10236 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
10237 begin
10238 Get_Decoded_Name_String (Chars (E));
10240 if Opt.External_Name_Imp_Casing = Uppercase then
10241 Set_Casing (All_Upper_Case);
10242 else
10243 Set_Casing (All_Lower_Case);
10244 end if;
10246 return
10247 Make_String_Literal (Sloc (E),
10248 Strval => String_From_Name_Buffer);
10249 end Get_Default_External_Name;
10251 --------------------------
10252 -- Get_Enclosing_Object --
10253 --------------------------
10255 function Get_Enclosing_Object (N : Node_Id) return Entity_Id is
10256 begin
10257 if Is_Entity_Name (N) then
10258 return Entity (N);
10259 else
10260 case Nkind (N) is
10261 when N_Indexed_Component
10262 | N_Selected_Component
10263 | N_Slice
10265 -- If not generating code, a dereference may be left implicit.
10266 -- In thoses cases, return Empty.
10268 if Is_Access_Type (Etype (Prefix (N))) then
10269 return Empty;
10270 else
10271 return Get_Enclosing_Object (Prefix (N));
10272 end if;
10274 when N_Type_Conversion =>
10275 return Get_Enclosing_Object (Expression (N));
10277 when others =>
10278 return Empty;
10279 end case;
10280 end if;
10281 end Get_Enclosing_Object;
10283 -------------------------------
10284 -- Get_Enclosing_Deep_Object --
10285 -------------------------------
10287 function Get_Enclosing_Deep_Object (N : Node_Id) return Entity_Id is
10288 begin
10289 if Is_Entity_Name (N) then
10290 return Entity (N);
10291 else
10292 case Nkind (N) is
10293 when N_Explicit_Dereference
10294 | N_Indexed_Component
10295 | N_Selected_Component
10296 | N_Slice
10298 return Get_Enclosing_Deep_Object (Prefix (N));
10300 when N_Type_Conversion =>
10301 return Get_Enclosing_Deep_Object (Expression (N));
10303 when others =>
10304 return Empty;
10305 end case;
10306 end if;
10307 end Get_Enclosing_Deep_Object;
10309 ---------------------------
10310 -- Get_Enum_Lit_From_Pos --
10311 ---------------------------
10313 function Get_Enum_Lit_From_Pos
10314 (T : Entity_Id;
10315 Pos : Uint;
10316 Loc : Source_Ptr) return Node_Id
10318 Btyp : Entity_Id := Base_Type (T);
10319 Lit : Node_Id;
10320 LLoc : Source_Ptr;
10322 begin
10323 -- In the case where the literal is of type Character, Wide_Character
10324 -- or Wide_Wide_Character or of a type derived from them, there needs
10325 -- to be some special handling since there is no explicit chain of
10326 -- literals to search. Instead, an N_Character_Literal node is created
10327 -- with the appropriate Char_Code and Chars fields.
10329 if Is_Standard_Character_Type (T) then
10330 Set_Character_Literal_Name (UI_To_CC (Pos));
10332 return
10333 Make_Character_Literal (Loc,
10334 Chars => Name_Find,
10335 Char_Literal_Value => Pos);
10337 -- For all other cases, we have a complete table of literals, and
10338 -- we simply iterate through the chain of literal until the one
10339 -- with the desired position value is found.
10341 else
10342 if Is_Private_Type (Btyp) and then Present (Full_View (Btyp)) then
10343 Btyp := Full_View (Btyp);
10344 end if;
10346 Lit := First_Literal (Btyp);
10348 -- Position in the enumeration type starts at 0
10350 if Pos < 0 then
10351 raise Constraint_Error;
10352 end if;
10354 for J in 1 .. UI_To_Int (Pos) loop
10355 Next_Literal (Lit);
10357 -- If Lit is Empty, Pos is not in range, so raise Constraint_Error
10358 -- inside the loop to avoid calling Next_Literal on Empty.
10360 if No (Lit) then
10361 raise Constraint_Error;
10362 end if;
10363 end loop;
10365 -- Create a new node from Lit, with source location provided by Loc
10366 -- if not equal to No_Location, or by copying the source location of
10367 -- Lit otherwise.
10369 LLoc := Loc;
10371 if LLoc = No_Location then
10372 LLoc := Sloc (Lit);
10373 end if;
10375 return New_Occurrence_Of (Lit, LLoc);
10376 end if;
10377 end Get_Enum_Lit_From_Pos;
10379 ----------------------
10380 -- Get_Fullest_View --
10381 ----------------------
10383 function Get_Fullest_View
10384 (E : Entity_Id;
10385 Include_PAT : Boolean := True;
10386 Recurse : Boolean := True) return Entity_Id
10388 New_E : Entity_Id := Empty;
10390 begin
10391 -- Prevent cascaded errors
10393 if No (E) then
10394 return E;
10395 end if;
10397 -- Look at each kind of entity to see where we may need to go deeper.
10399 case Ekind (E) is
10400 when Incomplete_Kind =>
10401 if From_Limited_With (E) then
10402 New_E := Non_Limited_View (E);
10403 elsif Present (Full_View (E)) then
10404 New_E := Full_View (E);
10405 elsif Ekind (E) = E_Incomplete_Subtype then
10406 New_E := Etype (E);
10407 end if;
10409 when Private_Kind =>
10410 if Present (Underlying_Full_View (E)) then
10411 New_E := Underlying_Full_View (E);
10412 elsif Present (Full_View (E)) then
10413 New_E := Full_View (E);
10414 elsif Etype (E) /= E then
10415 New_E := Etype (E);
10416 end if;
10418 when Array_Kind =>
10419 if Include_PAT and then Present (Packed_Array_Impl_Type (E)) then
10420 New_E := Packed_Array_Impl_Type (E);
10421 end if;
10423 when E_Record_Subtype =>
10424 if Present (Cloned_Subtype (E)) then
10425 New_E := Cloned_Subtype (E);
10426 end if;
10428 when E_Class_Wide_Type =>
10429 New_E := Root_Type (E);
10431 when E_Class_Wide_Subtype =>
10432 if Present (Equivalent_Type (E)) then
10433 New_E := Equivalent_Type (E);
10434 elsif Present (Cloned_Subtype (E)) then
10435 New_E := Cloned_Subtype (E);
10436 end if;
10438 when E_Protected_Subtype
10439 | E_Protected_Type
10440 | E_Task_Subtype
10441 | E_Task_Type
10443 if Present (Corresponding_Record_Type (E)) then
10444 New_E := Corresponding_Record_Type (E);
10445 end if;
10447 when E_Access_Protected_Subprogram_Type
10448 | E_Anonymous_Access_Protected_Subprogram_Type
10450 if Present (Equivalent_Type (E)) then
10451 New_E := Equivalent_Type (E);
10452 end if;
10454 when E_Access_Subtype =>
10455 New_E := Base_Type (E);
10457 when others =>
10458 null;
10459 end case;
10461 -- If we found a fuller view, either return it or recurse. Otherwise,
10462 -- return our input.
10464 return (if No (New_E) then E
10465 elsif Recurse then Get_Fullest_View (New_E, Include_PAT, Recurse)
10466 else New_E);
10467 end Get_Fullest_View;
10469 ------------------------
10470 -- Get_Generic_Entity --
10471 ------------------------
10473 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
10474 Ent : constant Entity_Id := Entity (Name (N));
10475 begin
10476 if Present (Renamed_Entity (Ent)) then
10477 return Renamed_Entity (Ent);
10478 else
10479 return Ent;
10480 end if;
10481 end Get_Generic_Entity;
10483 -------------------------------------
10484 -- Get_Incomplete_View_Of_Ancestor --
10485 -------------------------------------
10487 function Get_Incomplete_View_Of_Ancestor (E : Entity_Id) return Entity_Id is
10488 Cur_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
10489 Par_Scope : Entity_Id;
10490 Par_Type : Entity_Id;
10492 begin
10493 -- The incomplete view of an ancestor is only relevant for private
10494 -- derived types in child units.
10496 if not Is_Derived_Type (E)
10497 or else not Is_Child_Unit (Cur_Unit)
10498 then
10499 return Empty;
10501 else
10502 Par_Scope := Scope (Cur_Unit);
10503 if No (Par_Scope) then
10504 return Empty;
10505 end if;
10507 Par_Type := Etype (Base_Type (E));
10509 -- Traverse list of ancestor types until we find one declared in
10510 -- a parent or grandparent unit (two levels seem sufficient).
10512 while Present (Par_Type) loop
10513 if Scope (Par_Type) = Par_Scope
10514 or else Scope (Par_Type) = Scope (Par_Scope)
10515 then
10516 return Par_Type;
10518 elsif not Is_Derived_Type (Par_Type) then
10519 return Empty;
10521 else
10522 Par_Type := Etype (Base_Type (Par_Type));
10523 end if;
10524 end loop;
10526 -- If none found, there is no relevant ancestor type.
10528 return Empty;
10529 end if;
10530 end Get_Incomplete_View_Of_Ancestor;
10532 ----------------------
10533 -- Get_Index_Bounds --
10534 ----------------------
10536 procedure Get_Index_Bounds
10537 (N : Node_Id;
10538 L : out Node_Id;
10539 H : out Node_Id;
10540 Use_Full_View : Boolean := False)
10542 function Scalar_Range_Of_Type (Typ : Entity_Id) return Node_Id;
10543 -- Obtain the scalar range of type Typ. If flag Use_Full_View is set and
10544 -- Typ qualifies, the scalar range is obtained from the full view of the
10545 -- type.
10547 --------------------------
10548 -- Scalar_Range_Of_Type --
10549 --------------------------
10551 function Scalar_Range_Of_Type (Typ : Entity_Id) return Node_Id is
10552 T : Entity_Id := Typ;
10554 begin
10555 if Use_Full_View and then Present (Full_View (T)) then
10556 T := Full_View (T);
10557 end if;
10559 return Scalar_Range (T);
10560 end Scalar_Range_Of_Type;
10562 -- Local variables
10564 Kind : constant Node_Kind := Nkind (N);
10565 Rng : Node_Id;
10567 -- Start of processing for Get_Index_Bounds
10569 begin
10570 if Kind = N_Range then
10571 L := Low_Bound (N);
10572 H := High_Bound (N);
10574 elsif Kind = N_Subtype_Indication then
10575 Rng := Range_Expression (Constraint (N));
10577 if Rng = Error then
10578 L := Error;
10579 H := Error;
10580 return;
10582 else
10583 L := Low_Bound (Range_Expression (Constraint (N)));
10584 H := High_Bound (Range_Expression (Constraint (N)));
10585 end if;
10587 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
10588 Rng := Scalar_Range_Of_Type (Entity (N));
10590 if Error_Posted (Rng) then
10591 L := Error;
10592 H := Error;
10594 elsif Nkind (Rng) = N_Subtype_Indication then
10595 Get_Index_Bounds (Rng, L, H);
10597 else
10598 L := Low_Bound (Rng);
10599 H := High_Bound (Rng);
10600 end if;
10602 else
10603 -- N is an expression, indicating a range with one value
10605 L := N;
10606 H := N;
10607 end if;
10608 end Get_Index_Bounds;
10610 function Get_Index_Bounds
10611 (N : Node_Id;
10612 Use_Full_View : Boolean := False) return Range_Nodes is
10613 Result : Range_Nodes;
10614 begin
10615 Get_Index_Bounds (N, Result.First, Result.Last, Use_Full_View);
10616 return Result;
10617 end Get_Index_Bounds;
10619 function Get_Index_Bounds
10620 (N : Node_Id;
10621 Use_Full_View : Boolean := False) return Range_Values is
10622 Nodes : constant Range_Nodes := Get_Index_Bounds (N, Use_Full_View);
10623 begin
10624 return (Expr_Value (Nodes.First), Expr_Value (Nodes.Last));
10625 end Get_Index_Bounds;
10627 -----------------------------
10628 -- Get_Interfacing_Aspects --
10629 -----------------------------
10631 procedure Get_Interfacing_Aspects
10632 (Iface_Asp : Node_Id;
10633 Conv_Asp : out Node_Id;
10634 EN_Asp : out Node_Id;
10635 Expo_Asp : out Node_Id;
10636 Imp_Asp : out Node_Id;
10637 LN_Asp : out Node_Id;
10638 Do_Checks : Boolean := False)
10640 procedure Save_Or_Duplication_Error
10641 (Asp : Node_Id;
10642 To : in out Node_Id);
10643 -- Save the value of aspect Asp in node To. If To already has a value,
10644 -- then this is considered a duplicate use of aspect. Emit an error if
10645 -- flag Do_Checks is set.
10647 -------------------------------
10648 -- Save_Or_Duplication_Error --
10649 -------------------------------
10651 procedure Save_Or_Duplication_Error
10652 (Asp : Node_Id;
10653 To : in out Node_Id)
10655 begin
10656 -- Detect an extra aspect and issue an error
10658 if Present (To) then
10659 if Do_Checks then
10660 Error_Msg_Name_1 := Chars (Identifier (Asp));
10661 Error_Msg_Sloc := Sloc (To);
10662 Error_Msg_N ("aspect % previously given #", Asp);
10663 end if;
10665 -- Otherwise capture the aspect
10667 else
10668 To := Asp;
10669 end if;
10670 end Save_Or_Duplication_Error;
10672 -- Local variables
10674 Asp : Node_Id;
10675 Asp_Id : Aspect_Id;
10677 -- The following variables capture each individual aspect
10679 Conv : Node_Id := Empty;
10680 EN : Node_Id := Empty;
10681 Expo : Node_Id := Empty;
10682 Imp : Node_Id := Empty;
10683 LN : Node_Id := Empty;
10685 -- Start of processing for Get_Interfacing_Aspects
10687 begin
10688 -- The input interfacing aspect should reside in an aspect specification
10689 -- list.
10691 pragma Assert (Is_List_Member (Iface_Asp));
10693 -- Examine the aspect specifications of the related entity. Find and
10694 -- capture all interfacing aspects. Detect duplicates and emit errors
10695 -- if applicable.
10697 Asp := First (List_Containing (Iface_Asp));
10698 while Present (Asp) loop
10699 Asp_Id := Get_Aspect_Id (Asp);
10701 if Asp_Id = Aspect_Convention then
10702 Save_Or_Duplication_Error (Asp, Conv);
10704 elsif Asp_Id = Aspect_External_Name then
10705 Save_Or_Duplication_Error (Asp, EN);
10707 elsif Asp_Id = Aspect_Export then
10708 Save_Or_Duplication_Error (Asp, Expo);
10710 elsif Asp_Id = Aspect_Import then
10711 Save_Or_Duplication_Error (Asp, Imp);
10713 elsif Asp_Id = Aspect_Link_Name then
10714 Save_Or_Duplication_Error (Asp, LN);
10715 end if;
10717 Next (Asp);
10718 end loop;
10720 Conv_Asp := Conv;
10721 EN_Asp := EN;
10722 Expo_Asp := Expo;
10723 Imp_Asp := Imp;
10724 LN_Asp := LN;
10725 end Get_Interfacing_Aspects;
10727 ---------------------------------
10728 -- Get_Iterable_Type_Primitive --
10729 ---------------------------------
10731 function Get_Iterable_Type_Primitive
10732 (Typ : Entity_Id;
10733 Nam : Name_Id) return Entity_Id
10735 pragma Assert
10736 (Is_Type (Typ)
10737 and then
10738 Nam in Name_Element
10739 | Name_First
10740 | Name_Has_Element
10741 | Name_Last
10742 | Name_Next
10743 | Name_Previous);
10745 Funcs : constant Node_Id := Find_Value_Of_Aspect (Typ, Aspect_Iterable);
10746 Assoc : Node_Id;
10748 begin
10749 if No (Funcs) then
10750 return Empty;
10752 else
10753 Assoc := First (Component_Associations (Funcs));
10754 while Present (Assoc) loop
10755 if Chars (First (Choices (Assoc))) = Nam then
10756 return Entity (Expression (Assoc));
10757 end if;
10759 Next (Assoc);
10760 end loop;
10762 return Empty;
10763 end if;
10764 end Get_Iterable_Type_Primitive;
10766 ---------------------------
10767 -- Get_Library_Unit_Name --
10768 ---------------------------
10770 function Get_Library_Unit_Name (Decl_Node : Node_Id) return String_Id is
10771 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
10772 Buf : Bounded_String;
10773 begin
10774 Get_Unit_Name_String (Buf, Unit_Name_Id);
10776 -- Remove the last seven characters (" (spec)" or " (body)")
10778 Buf.Length := Buf.Length - 7;
10779 pragma Assert (Buf.Chars (Buf.Length + 1) = ' ');
10781 return String_From_Name_Buffer (Buf);
10782 end Get_Library_Unit_Name;
10784 --------------------------
10785 -- Get_Max_Queue_Length --
10786 --------------------------
10788 function Get_Max_Queue_Length (Id : Entity_Id) return Uint is
10789 pragma Assert (Is_Entry (Id));
10790 Prag : constant Entity_Id := Get_Pragma (Id, Pragma_Max_Queue_Length);
10791 Max : Uint;
10793 begin
10794 -- A value of 0 or -1 represents no maximum specified, and entries and
10795 -- entry families with no Max_Queue_Length aspect or pragma default to
10796 -- it.
10798 if No (Prag) then
10799 return Uint_0;
10800 end if;
10802 Max := Expr_Value
10803 (Expression (First (Pragma_Argument_Associations (Prag))));
10805 -- Since -1 and 0 are equivalent, return 0 for instances of -1 for
10806 -- uniformity.
10808 if Max = -1 then
10809 return Uint_0;
10810 end if;
10812 return Max;
10813 end Get_Max_Queue_Length;
10815 ------------------------
10816 -- Get_Name_Entity_Id --
10817 ------------------------
10819 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
10820 begin
10821 return Entity_Id (Get_Name_Table_Int (Id));
10822 end Get_Name_Entity_Id;
10824 ------------------------------
10825 -- Get_Name_From_CTC_Pragma --
10826 ------------------------------
10828 function Get_Name_From_CTC_Pragma (N : Node_Id) return String_Id is
10829 Arg : constant Node_Id :=
10830 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
10831 begin
10832 return Strval (Expr_Value_S (Arg));
10833 end Get_Name_From_CTC_Pragma;
10835 -----------------------
10836 -- Get_Parent_Entity --
10837 -----------------------
10839 function Get_Parent_Entity (Unit : Node_Id) return Entity_Id is
10840 begin
10841 if Nkind (Unit) = N_Package_Body
10842 and then Nkind (Original_Node (Unit)) = N_Package_Instantiation
10843 then
10844 return Defining_Entity
10845 (Specification (Instance_Spec (Original_Node (Unit))));
10846 elsif Nkind (Unit) = N_Package_Instantiation then
10847 return Defining_Entity (Specification (Instance_Spec (Unit)));
10848 else
10849 return Defining_Entity (Unit);
10850 end if;
10851 end Get_Parent_Entity;
10853 -------------------
10854 -- Get_Pragma_Id --
10855 -------------------
10857 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
10858 begin
10859 return Get_Pragma_Id (Pragma_Name_Unmapped (N));
10860 end Get_Pragma_Id;
10862 ------------------------
10863 -- Get_Qualified_Name --
10864 ------------------------
10866 function Get_Qualified_Name
10867 (Id : Entity_Id;
10868 Suffix : Entity_Id := Empty) return Name_Id
10870 Suffix_Nam : Name_Id := No_Name;
10872 begin
10873 if Present (Suffix) then
10874 Suffix_Nam := Chars (Suffix);
10875 end if;
10877 return Get_Qualified_Name (Chars (Id), Suffix_Nam, Scope (Id));
10878 end Get_Qualified_Name;
10880 function Get_Qualified_Name
10881 (Nam : Name_Id;
10882 Suffix : Name_Id := No_Name;
10883 Scop : Entity_Id := Current_Scope) return Name_Id
10885 procedure Add_Scope (S : Entity_Id);
10886 -- Add the fully qualified form of scope S to the name buffer. The
10887 -- format is:
10888 -- s-1__s__
10890 ---------------
10891 -- Add_Scope --
10892 ---------------
10894 procedure Add_Scope (S : Entity_Id) is
10895 begin
10896 if S = Empty then
10897 null;
10899 elsif S = Standard_Standard then
10900 null;
10902 else
10903 Add_Scope (Scope (S));
10904 Get_Name_String_And_Append (Chars (S));
10905 Add_Str_To_Name_Buffer ("__");
10906 end if;
10907 end Add_Scope;
10909 -- Start of processing for Get_Qualified_Name
10911 begin
10912 Name_Len := 0;
10913 Add_Scope (Scop);
10915 -- Append the base name after all scopes have been chained
10917 Get_Name_String_And_Append (Nam);
10919 -- Append the suffix (if present)
10921 if Suffix /= No_Name then
10922 Add_Str_To_Name_Buffer ("__");
10923 Get_Name_String_And_Append (Suffix);
10924 end if;
10926 return Name_Find;
10927 end Get_Qualified_Name;
10929 -----------------------
10930 -- Get_Reason_String --
10931 -----------------------
10933 procedure Get_Reason_String (N : Node_Id) is
10934 begin
10935 if Nkind (N) = N_String_Literal then
10936 Store_String_Chars (Strval (N));
10938 elsif Nkind (N) = N_Op_Concat then
10939 Get_Reason_String (Left_Opnd (N));
10940 Get_Reason_String (Right_Opnd (N));
10942 -- If not of required form, error
10944 else
10945 Error_Msg_N
10946 ("Reason for pragma Warnings has wrong form", N);
10947 Error_Msg_N
10948 ("\must be string literal or concatenation of string literals", N);
10949 return;
10950 end if;
10951 end Get_Reason_String;
10953 --------------------------------
10954 -- Get_Reference_Discriminant --
10955 --------------------------------
10957 function Get_Reference_Discriminant (Typ : Entity_Id) return Entity_Id is
10958 D : Entity_Id;
10960 begin
10961 D := First_Discriminant (Typ);
10962 while Present (D) loop
10963 if Has_Implicit_Dereference (D) then
10964 return D;
10965 end if;
10966 Next_Discriminant (D);
10967 end loop;
10969 return Empty;
10970 end Get_Reference_Discriminant;
10972 ---------------------------
10973 -- Get_Referenced_Object --
10974 ---------------------------
10976 function Get_Referenced_Object (N : Node_Id) return Node_Id is
10977 R : Node_Id;
10979 begin
10980 R := N;
10981 while Is_Entity_Name (R)
10982 and then Is_Object (Entity (R))
10983 and then Present (Renamed_Object (Entity (R)))
10984 loop
10985 R := Renamed_Object (Entity (R));
10986 end loop;
10988 return R;
10989 end Get_Referenced_Object;
10991 ------------------------
10992 -- Get_Renamed_Entity --
10993 ------------------------
10995 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
10996 R : Entity_Id := E;
10997 begin
10998 while Present (Renamed_Entity (R)) loop
10999 R := Renamed_Entity (R);
11000 end loop;
11002 return R;
11003 end Get_Renamed_Entity;
11005 -----------------------
11006 -- Get_Return_Object --
11007 -----------------------
11009 function Get_Return_Object (N : Node_Id) return Entity_Id is
11010 Decl : Node_Id;
11012 begin
11013 Decl := First (Return_Object_Declarations (N));
11014 while Present (Decl) loop
11015 exit when Nkind (Decl) = N_Object_Declaration
11016 and then Is_Return_Object (Defining_Identifier (Decl));
11017 Next (Decl);
11018 end loop;
11020 pragma Assert (Present (Decl));
11021 return Defining_Identifier (Decl);
11022 end Get_Return_Object;
11024 ---------------------------
11025 -- Get_Subprogram_Entity --
11026 ---------------------------
11028 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
11029 Subp : Node_Id;
11030 Subp_Id : Entity_Id;
11032 begin
11033 if Nkind (Nod) = N_Accept_Statement then
11034 Subp := Entry_Direct_Name (Nod);
11036 elsif Nkind (Nod) = N_Slice then
11037 Subp := Prefix (Nod);
11039 else
11040 Subp := Name (Nod);
11041 end if;
11043 -- Strip the subprogram call
11045 loop
11046 if Nkind (Subp) in N_Explicit_Dereference
11047 | N_Indexed_Component
11048 | N_Selected_Component
11049 then
11050 Subp := Prefix (Subp);
11052 elsif Nkind (Subp) in N_Type_Conversion
11053 | N_Unchecked_Type_Conversion
11054 then
11055 Subp := Expression (Subp);
11057 else
11058 exit;
11059 end if;
11060 end loop;
11062 -- Extract the entity of the subprogram call
11064 if Is_Entity_Name (Subp) then
11065 Subp_Id := Entity (Subp);
11067 if Ekind (Subp_Id) = E_Access_Subprogram_Type then
11068 Subp_Id := Directly_Designated_Type (Subp_Id);
11069 end if;
11071 if Is_Subprogram (Subp_Id) then
11072 return Subp_Id;
11073 else
11074 return Empty;
11075 end if;
11077 -- The search did not find a construct that denotes a subprogram
11079 else
11080 return Empty;
11081 end if;
11082 end Get_Subprogram_Entity;
11084 -----------------------------
11085 -- Get_Task_Body_Procedure --
11086 -----------------------------
11088 function Get_Task_Body_Procedure (E : Entity_Id) return Entity_Id is
11089 begin
11090 -- Note: A task type may be the completion of a private type with
11091 -- discriminants. When performing elaboration checks on a task
11092 -- declaration, the current view of the type may be the private one,
11093 -- and the procedure that holds the body of the task is held in its
11094 -- underlying type.
11096 -- This is an odd function, why not have Task_Body_Procedure do
11097 -- the following digging???
11099 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
11100 end Get_Task_Body_Procedure;
11102 -------------------------------
11103 -- Get_User_Defined_Equality --
11104 -------------------------------
11106 function Get_User_Defined_Equality (E : Entity_Id) return Entity_Id is
11107 Prim : Elmt_Id;
11109 begin
11110 Prim := First_Elmt (Collect_Primitive_Operations (E));
11111 while Present (Prim) loop
11112 if Is_User_Defined_Equality (Node (Prim)) then
11113 return Node (Prim);
11114 end if;
11116 Next_Elmt (Prim);
11117 end loop;
11119 return Empty;
11120 end Get_User_Defined_Equality;
11122 ---------------
11123 -- Get_Views --
11124 ---------------
11126 procedure Get_Views
11127 (Typ : Entity_Id;
11128 Priv_Typ : out Entity_Id;
11129 Full_Typ : out Entity_Id;
11130 UFull_Typ : out Entity_Id;
11131 CRec_Typ : out Entity_Id)
11133 IP_View : Entity_Id;
11135 begin
11136 -- Assume that none of the views can be recovered
11138 Priv_Typ := Empty;
11139 Full_Typ := Empty;
11140 UFull_Typ := Empty;
11141 CRec_Typ := Empty;
11143 -- The input type is the corresponding record type of a protected or a
11144 -- task type.
11146 if Ekind (Typ) = E_Record_Type
11147 and then Is_Concurrent_Record_Type (Typ)
11148 then
11149 CRec_Typ := Typ;
11150 Full_Typ := Corresponding_Concurrent_Type (CRec_Typ);
11151 Priv_Typ := Incomplete_Or_Partial_View (Full_Typ);
11153 -- Otherwise the input type denotes an arbitrary type
11155 else
11156 IP_View := Incomplete_Or_Partial_View (Typ);
11158 -- The input type denotes the full view of a private type
11160 if Present (IP_View) then
11161 Priv_Typ := IP_View;
11162 Full_Typ := Typ;
11164 -- The input type is a private type
11166 elsif Is_Private_Type (Typ) then
11167 Priv_Typ := Typ;
11168 Full_Typ := Full_View (Priv_Typ);
11170 -- Otherwise the input type does not have any views
11172 else
11173 Full_Typ := Typ;
11174 end if;
11176 if Present (Full_Typ) and then Is_Private_Type (Full_Typ) then
11177 UFull_Typ := Underlying_Full_View (Full_Typ);
11179 if Present (UFull_Typ)
11180 and then Ekind (UFull_Typ) in E_Protected_Type | E_Task_Type
11181 then
11182 CRec_Typ := Corresponding_Record_Type (UFull_Typ);
11183 end if;
11185 else
11186 if Present (Full_Typ)
11187 and then Ekind (Full_Typ) in E_Protected_Type | E_Task_Type
11188 then
11189 CRec_Typ := Corresponding_Record_Type (Full_Typ);
11190 end if;
11191 end if;
11192 end if;
11193 end Get_Views;
11195 ------------------------------
11196 -- Has_Compatible_Alignment --
11197 ------------------------------
11199 function Has_Compatible_Alignment
11200 (Obj : Entity_Id;
11201 Expr : Node_Id;
11202 Layout_Done : Boolean) return Alignment_Result
11204 function Has_Compatible_Alignment_Internal
11205 (Obj : Entity_Id;
11206 Expr : Node_Id;
11207 Layout_Done : Boolean;
11208 Default : Alignment_Result) return Alignment_Result;
11209 -- This is the internal recursive function that actually does the work.
11210 -- There is one additional parameter, which says what the result should
11211 -- be if no alignment information is found, and there is no definite
11212 -- indication of compatible alignments. At the outer level, this is set
11213 -- to Unknown, but for internal recursive calls in the case where types
11214 -- are known to be correct, it is set to Known_Compatible.
11216 ---------------------------------------
11217 -- Has_Compatible_Alignment_Internal --
11218 ---------------------------------------
11220 function Has_Compatible_Alignment_Internal
11221 (Obj : Entity_Id;
11222 Expr : Node_Id;
11223 Layout_Done : Boolean;
11224 Default : Alignment_Result) return Alignment_Result
11226 Result : Alignment_Result := Known_Compatible;
11227 -- Holds the current status of the result. Note that once a value of
11228 -- Known_Incompatible is set, it is sticky and does not get changed
11229 -- to Unknown (the value in Result only gets worse as we go along,
11230 -- never better).
11232 Offs : Uint := No_Uint;
11233 -- Set to a factor of the offset from the base object when Expr is a
11234 -- selected or indexed component, based on Component_Bit_Offset and
11235 -- Component_Size respectively. A negative value is used to represent
11236 -- a value that is not known at compile time.
11238 procedure Check_Prefix;
11239 -- Checks the prefix recursively in the case where the expression
11240 -- is an indexed or selected component.
11242 procedure Set_Result (R : Alignment_Result);
11243 -- If R represents a worse outcome (unknown instead of known
11244 -- compatible, or known incompatible), then set Result to R.
11246 ------------------
11247 -- Check_Prefix --
11248 ------------------
11250 procedure Check_Prefix is
11251 begin
11252 -- The subtlety here is that in doing a recursive call to check
11253 -- the prefix, we have to decide what to do in the case where we
11254 -- don't find any specific indication of an alignment problem.
11256 -- At the outer level, we normally set Unknown as the result in
11257 -- this case, since we can only set Known_Compatible if we really
11258 -- know that the alignment value is OK, but for the recursive
11259 -- call, in the case where the types match, and we have not
11260 -- specified a peculiar alignment for the object, we are only
11261 -- concerned about suspicious rep clauses, the default case does
11262 -- not affect us, since the compiler will, in the absence of such
11263 -- rep clauses, ensure that the alignment is correct.
11265 if Default = Known_Compatible
11266 or else
11267 (Etype (Obj) = Etype (Expr)
11268 and then (not Known_Alignment (Obj)
11269 or else
11270 Alignment (Obj) = Alignment (Etype (Obj))))
11271 then
11272 Set_Result
11273 (Has_Compatible_Alignment_Internal
11274 (Obj, Prefix (Expr), Layout_Done, Known_Compatible));
11276 -- In all other cases, we need a full check on the prefix
11278 else
11279 Set_Result
11280 (Has_Compatible_Alignment_Internal
11281 (Obj, Prefix (Expr), Layout_Done, Unknown));
11282 end if;
11283 end Check_Prefix;
11285 ----------------
11286 -- Set_Result --
11287 ----------------
11289 procedure Set_Result (R : Alignment_Result) is
11290 begin
11291 if R > Result then
11292 Result := R;
11293 end if;
11294 end Set_Result;
11296 -- Start of processing for Has_Compatible_Alignment_Internal
11298 begin
11299 -- If Expr is a selected component, we must make sure there is no
11300 -- potentially troublesome component clause and that the record is
11301 -- not packed if the layout is not done.
11303 if Nkind (Expr) = N_Selected_Component then
11305 -- Packing generates unknown alignment if layout is not done
11307 if Is_Packed (Etype (Prefix (Expr))) and then not Layout_Done then
11308 Set_Result (Unknown);
11309 end if;
11311 -- Check prefix and component offset
11313 Check_Prefix;
11314 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
11316 -- If Expr is an indexed component, we must make sure there is no
11317 -- potentially troublesome Component_Size clause and that the array
11318 -- is not bit-packed if the layout is not done.
11320 elsif Nkind (Expr) = N_Indexed_Component then
11321 declare
11322 Typ : constant Entity_Id := Etype (Prefix (Expr));
11324 begin
11325 -- Packing generates unknown alignment if layout is not done
11327 if Is_Bit_Packed_Array (Typ) and then not Layout_Done then
11328 Set_Result (Unknown);
11329 end if;
11331 -- Check prefix and component offset (or at least size)
11333 Check_Prefix;
11334 Offs := Indexed_Component_Bit_Offset (Expr);
11335 if No (Offs) then
11336 Offs := Component_Size (Typ);
11337 end if;
11338 end;
11339 end if;
11341 -- If we have a null offset, the result is entirely determined by
11342 -- the base object and has already been computed recursively.
11344 if Present (Offs) and then Offs = Uint_0 then
11345 null;
11347 -- Case where we know the alignment of the object
11349 elsif Known_Alignment (Obj) then
11350 declare
11351 ObjA : constant Uint := Alignment (Obj);
11352 ExpA : Uint := No_Uint;
11353 SizA : Uint := No_Uint;
11355 begin
11356 -- If alignment of Obj is 1, then we are always OK
11358 if ObjA = 1 then
11359 Set_Result (Known_Compatible);
11361 -- Alignment of Obj is greater than 1, so we need to check
11363 else
11364 -- If we have an offset, see if it is compatible
11366 if Present (Offs) and then Offs > Uint_0 then
11367 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
11368 Set_Result (Known_Incompatible);
11369 end if;
11371 -- See if Expr is an object with known alignment
11373 elsif Is_Entity_Name (Expr)
11374 and then Known_Alignment (Entity (Expr))
11375 then
11376 Offs := Uint_0;
11377 ExpA := Alignment (Entity (Expr));
11379 -- Otherwise, we can use the alignment of the type of Expr
11380 -- given that we already checked for discombobulating rep
11381 -- clauses for the cases of indexed and selected components
11382 -- above.
11384 elsif Known_Alignment (Etype (Expr)) then
11385 ExpA := Alignment (Etype (Expr));
11387 -- Otherwise the alignment is unknown
11389 else
11390 Set_Result (Default);
11391 end if;
11393 -- If we got an alignment, see if it is acceptable
11395 if Present (ExpA) and then ExpA < ObjA then
11396 Set_Result (Known_Incompatible);
11397 end if;
11399 -- If Expr is a component or an entire object with a known
11400 -- alignment, then we are fine. Otherwise, if its size is
11401 -- known, it must be big enough for the required alignment.
11403 if Present (Offs) then
11404 null;
11406 -- See if Expr is an object with known size
11408 elsif Is_Entity_Name (Expr)
11409 and then Known_Static_Esize (Entity (Expr))
11410 then
11411 SizA := Esize (Entity (Expr));
11413 -- Otherwise, we check the object size of the Expr type
11415 elsif Known_Static_Esize (Etype (Expr)) then
11416 SizA := Esize (Etype (Expr));
11417 end if;
11419 -- If we got a size, see if it is a multiple of the Obj
11420 -- alignment; if not, then the alignment cannot be
11421 -- acceptable, since the size is always a multiple of the
11422 -- alignment.
11424 if Present (SizA) then
11425 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
11426 Set_Result (Known_Incompatible);
11427 end if;
11428 end if;
11429 end if;
11430 end;
11432 -- If we do not know required alignment, any non-zero offset is a
11433 -- potential problem (but certainly may be OK, so result is unknown).
11435 elsif Present (Offs) then
11436 Set_Result (Unknown);
11438 -- If we can't find the result by direct comparison of alignment
11439 -- values, then there is still one case that we can determine known
11440 -- result, and that is when we can determine that the types are the
11441 -- same, and no alignments are specified. Then we known that the
11442 -- alignments are compatible, even if we don't know the alignment
11443 -- value in the front end.
11445 elsif Etype (Obj) = Etype (Expr) then
11447 -- Types are the same, but we have to check for possible size
11448 -- and alignments on the Expr object that may make the alignment
11449 -- different, even though the types are the same.
11451 if Is_Entity_Name (Expr) then
11453 -- First check alignment of the Expr object. Any alignment less
11454 -- than Maximum_Alignment is worrisome since this is the case
11455 -- where we do not know the alignment of Obj.
11457 if Known_Alignment (Entity (Expr))
11458 and then Alignment (Entity (Expr)) < Ttypes.Maximum_Alignment
11459 then
11460 Set_Result (Unknown);
11462 -- Now check size of Expr object. Any size that is not an even
11463 -- multiple of Maximum_Alignment is also worrisome since it
11464 -- may cause the alignment of the object to be less than the
11465 -- alignment of the type.
11467 elsif Known_Static_Esize (Entity (Expr))
11468 and then
11469 Esize (Entity (Expr)) mod
11470 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit)
11471 /= 0
11472 then
11473 Set_Result (Unknown);
11475 -- Otherwise same type is decisive
11477 else
11478 Set_Result (Known_Compatible);
11479 end if;
11480 end if;
11482 -- Another case to deal with is when there is an explicit size or
11483 -- alignment clause when the types are not the same. If so, then the
11484 -- result is Unknown. We don't need to do this test if the Default is
11485 -- Unknown, since that result will be set in any case.
11487 elsif Default /= Unknown
11488 and then (Has_Size_Clause (Etype (Expr))
11489 or else
11490 Has_Alignment_Clause (Etype (Expr)))
11491 then
11492 Set_Result (Unknown);
11494 -- If no indication found, set default
11496 else
11497 Set_Result (Default);
11498 end if;
11500 -- Return worst result found
11502 return Result;
11503 end Has_Compatible_Alignment_Internal;
11505 -- Start of processing for Has_Compatible_Alignment
11507 begin
11508 -- If Obj has no specified alignment, then set alignment from the type
11509 -- alignment. Perhaps we should always do this, but for sure we should
11510 -- do it when there is an address clause since we can do more if the
11511 -- alignment is known.
11513 if not Known_Alignment (Obj) and then Known_Alignment (Etype (Obj)) then
11514 Set_Alignment (Obj, Alignment (Etype (Obj)));
11515 end if;
11517 -- Now do the internal call that does all the work
11519 return
11520 Has_Compatible_Alignment_Internal (Obj, Expr, Layout_Done, Unknown);
11521 end Has_Compatible_Alignment;
11523 ----------------------
11524 -- Has_Declarations --
11525 ----------------------
11527 function Has_Declarations (N : Node_Id) return Boolean is
11528 begin
11529 return Nkind (N) in N_Accept_Statement
11530 | N_Block_Statement
11531 | N_Compilation_Unit_Aux
11532 | N_Entry_Body
11533 | N_Package_Body
11534 | N_Protected_Body
11535 | N_Subprogram_Body
11536 | N_Task_Body
11537 | N_Package_Specification;
11538 end Has_Declarations;
11540 ---------------------------------
11541 -- Has_Defaulted_Discriminants --
11542 ---------------------------------
11544 function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean is
11545 begin
11546 return Has_Discriminants (Typ)
11547 and then Present (Discriminant_Default_Value
11548 (First_Discriminant (Typ)));
11549 end Has_Defaulted_Discriminants;
11551 -------------------
11552 -- Has_Denormals --
11553 -------------------
11555 function Has_Denormals (E : Entity_Id) return Boolean is
11556 begin
11557 return Is_Floating_Point_Type (E) and then Denorm_On_Target;
11558 end Has_Denormals;
11560 -------------------------------------------
11561 -- Has_Discriminant_Dependent_Constraint --
11562 -------------------------------------------
11564 function Has_Discriminant_Dependent_Constraint
11565 (Comp : Entity_Id) return Boolean
11567 Comp_Decl : constant Node_Id := Parent (Comp);
11568 Subt_Indic : Node_Id;
11569 Constr : Node_Id;
11570 Assn : Node_Id;
11572 begin
11573 -- Discriminants can't depend on discriminants
11575 if Ekind (Comp) = E_Discriminant then
11576 return False;
11578 else
11579 Subt_Indic := Subtype_Indication (Component_Definition (Comp_Decl));
11581 if Nkind (Subt_Indic) = N_Subtype_Indication then
11582 Constr := Constraint (Subt_Indic);
11584 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
11585 Assn := First (Constraints (Constr));
11586 while Present (Assn) loop
11587 case Nkind (Assn) is
11588 when N_Identifier
11589 | N_Range
11590 | N_Subtype_Indication
11592 if Depends_On_Discriminant (Assn) then
11593 return True;
11594 end if;
11596 when N_Discriminant_Association =>
11597 if Depends_On_Discriminant (Expression (Assn)) then
11598 return True;
11599 end if;
11601 when others =>
11602 null;
11603 end case;
11605 Next (Assn);
11606 end loop;
11607 end if;
11608 end if;
11609 end if;
11611 return False;
11612 end Has_Discriminant_Dependent_Constraint;
11614 --------------------------------------
11615 -- Has_Effectively_Volatile_Profile --
11616 --------------------------------------
11618 function Has_Effectively_Volatile_Profile
11619 (Subp_Id : Entity_Id) return Boolean
11621 Formal : Entity_Id;
11623 begin
11624 -- Inspect the formal parameters looking for an effectively volatile
11625 -- type for reading.
11627 Formal := First_Formal (Subp_Id);
11628 while Present (Formal) loop
11629 if Is_Effectively_Volatile_For_Reading (Etype (Formal)) then
11630 return True;
11631 end if;
11633 Next_Formal (Formal);
11634 end loop;
11636 -- Inspect the return type of functions
11638 if Ekind (Subp_Id) in E_Function | E_Generic_Function
11639 and then Is_Effectively_Volatile_For_Reading (Etype (Subp_Id))
11640 then
11641 return True;
11642 end if;
11644 return False;
11645 end Has_Effectively_Volatile_Profile;
11647 --------------------------
11648 -- Has_Enabled_Property --
11649 --------------------------
11651 function Has_Enabled_Property
11652 (Item_Id : Entity_Id;
11653 Property : Name_Id) return Boolean
11655 function Protected_Type_Or_Variable_Has_Enabled_Property return Boolean;
11656 -- Determine whether a protected type or variable denoted by Item_Id
11657 -- has the property enabled.
11659 function State_Has_Enabled_Property return Boolean;
11660 -- Determine whether a state denoted by Item_Id has the property enabled
11662 function Type_Or_Variable_Has_Enabled_Property
11663 (Item_Id : Entity_Id) return Boolean;
11664 -- Determine whether type or variable denoted by Item_Id has the
11665 -- property enabled.
11667 -----------------------------------------------------
11668 -- Protected_Type_Or_Variable_Has_Enabled_Property --
11669 -----------------------------------------------------
11671 function Protected_Type_Or_Variable_Has_Enabled_Property return Boolean
11673 begin
11674 -- Protected entities always have the properties Async_Readers and
11675 -- Async_Writers (SPARK RM 7.1.2(16)).
11677 if Property = Name_Async_Readers
11678 or else Property = Name_Async_Writers
11679 then
11680 return True;
11682 -- Protected objects that have Part_Of components also inherit their
11683 -- properties Effective_Reads and Effective_Writes
11684 -- (SPARK RM 7.1.2(16)).
11686 elsif Is_Single_Protected_Object (Item_Id) then
11687 declare
11688 Constit_Elmt : Elmt_Id;
11689 Constit_Id : Entity_Id;
11690 Constits : constant Elist_Id
11691 := Part_Of_Constituents (Item_Id);
11692 begin
11693 if Present (Constits) then
11694 Constit_Elmt := First_Elmt (Constits);
11695 while Present (Constit_Elmt) loop
11696 Constit_Id := Node (Constit_Elmt);
11698 if Has_Enabled_Property (Constit_Id, Property) then
11699 return True;
11700 end if;
11702 Next_Elmt (Constit_Elmt);
11703 end loop;
11704 end if;
11705 end;
11706 end if;
11708 return False;
11709 end Protected_Type_Or_Variable_Has_Enabled_Property;
11711 --------------------------------
11712 -- State_Has_Enabled_Property --
11713 --------------------------------
11715 function State_Has_Enabled_Property return Boolean is
11716 Decl : constant Node_Id := Parent (Item_Id);
11718 procedure Find_Simple_Properties
11719 (Has_External : out Boolean;
11720 Has_Synchronous : out Boolean);
11721 -- Extract the simple properties associated with declaration Decl
11723 function Is_Enabled_External_Property return Boolean;
11724 -- Determine whether property Property appears within the external
11725 -- property list of declaration Decl, and return its status.
11727 ----------------------------
11728 -- Find_Simple_Properties --
11729 ----------------------------
11731 procedure Find_Simple_Properties
11732 (Has_External : out Boolean;
11733 Has_Synchronous : out Boolean)
11735 Opt : Node_Id;
11737 begin
11738 -- Assume that none of the properties are available
11740 Has_External := False;
11741 Has_Synchronous := False;
11743 Opt := First (Expressions (Decl));
11744 while Present (Opt) loop
11745 if Nkind (Opt) = N_Identifier then
11746 if Chars (Opt) = Name_External then
11747 Has_External := True;
11749 elsif Chars (Opt) = Name_Synchronous then
11750 Has_Synchronous := True;
11751 end if;
11752 end if;
11754 Next (Opt);
11755 end loop;
11756 end Find_Simple_Properties;
11758 ----------------------------------
11759 -- Is_Enabled_External_Property --
11760 ----------------------------------
11762 function Is_Enabled_External_Property return Boolean is
11763 Opt : Node_Id;
11764 Opt_Nam : Node_Id;
11765 Prop : Node_Id;
11766 Prop_Nam : Node_Id;
11767 Props : Node_Id;
11769 begin
11770 Opt := First (Component_Associations (Decl));
11771 while Present (Opt) loop
11772 Opt_Nam := First (Choices (Opt));
11774 if Nkind (Opt_Nam) = N_Identifier
11775 and then Chars (Opt_Nam) = Name_External
11776 then
11777 Props := Expression (Opt);
11779 -- Multiple properties appear as an aggregate
11781 if Nkind (Props) = N_Aggregate then
11783 -- Simple property form
11785 Prop := First (Expressions (Props));
11786 while Present (Prop) loop
11787 if Chars (Prop) = Property then
11788 return True;
11789 end if;
11791 Next (Prop);
11792 end loop;
11794 -- Property with expression form
11796 Prop := First (Component_Associations (Props));
11797 while Present (Prop) loop
11798 Prop_Nam := First (Choices (Prop));
11800 -- The property can be represented in two ways:
11801 -- others => <value>
11802 -- <property> => <value>
11804 if Nkind (Prop_Nam) = N_Others_Choice
11805 or else (Nkind (Prop_Nam) = N_Identifier
11806 and then Chars (Prop_Nam) = Property)
11807 then
11808 return Is_True (Expr_Value (Expression (Prop)));
11809 end if;
11811 Next (Prop);
11812 end loop;
11814 -- Single property
11816 else
11817 return Chars (Props) = Property;
11818 end if;
11819 end if;
11821 Next (Opt);
11822 end loop;
11824 return False;
11825 end Is_Enabled_External_Property;
11827 -- Local variables
11829 Has_External : Boolean;
11830 Has_Synchronous : Boolean;
11832 -- Start of processing for State_Has_Enabled_Property
11834 begin
11835 -- The declaration of an external abstract state appears as an
11836 -- extension aggregate. If this is not the case, properties can
11837 -- never be set.
11839 if Nkind (Decl) /= N_Extension_Aggregate then
11840 return False;
11841 end if;
11843 Find_Simple_Properties (Has_External, Has_Synchronous);
11845 -- Simple option External enables all properties (SPARK RM 7.1.2(2))
11847 if Has_External then
11848 return True;
11850 -- Option External may enable or disable specific properties
11852 elsif Is_Enabled_External_Property then
11853 return True;
11855 -- Simple option Synchronous
11857 -- enables disables
11858 -- Async_Readers Effective_Reads
11859 -- Async_Writers Effective_Writes
11861 -- Note that both forms of External have higher precedence than
11862 -- Synchronous (SPARK RM 7.1.4(9)).
11864 elsif Has_Synchronous then
11865 return Property in Name_Async_Readers | Name_Async_Writers;
11866 end if;
11868 return False;
11869 end State_Has_Enabled_Property;
11871 -------------------------------------------
11872 -- Type_Or_Variable_Has_Enabled_Property --
11873 -------------------------------------------
11875 function Type_Or_Variable_Has_Enabled_Property
11876 (Item_Id : Entity_Id) return Boolean
11878 AR : constant Node_Id :=
11879 Get_Pragma (Item_Id, Pragma_Async_Readers);
11880 AW : constant Node_Id :=
11881 Get_Pragma (Item_Id, Pragma_Async_Writers);
11882 ER : constant Node_Id :=
11883 Get_Pragma (Item_Id, Pragma_Effective_Reads);
11884 EW : constant Node_Id :=
11885 Get_Pragma (Item_Id, Pragma_Effective_Writes);
11887 Is_Derived_Type_With_Volatile_Parent_Type : constant Boolean :=
11888 Is_Derived_Type (Item_Id)
11889 and then Is_Effectively_Volatile (Etype (Base_Type (Item_Id)));
11891 begin
11892 -- A non-effectively volatile object can never possess external
11893 -- properties.
11895 if not Is_Effectively_Volatile (Item_Id) then
11896 return False;
11898 -- External properties related to variables come in two flavors -
11899 -- explicit and implicit. The explicit case is characterized by the
11900 -- presence of a property pragma with an optional Boolean flag. The
11901 -- property is enabled when the flag evaluates to True or the flag is
11902 -- missing altogether.
11904 elsif Property = Name_Async_Readers and then Present (AR) then
11905 return Is_Enabled_Pragma (AR);
11907 elsif Property = Name_Async_Writers and then Present (AW) then
11908 return Is_Enabled_Pragma (AW);
11910 elsif Property = Name_Effective_Reads and then Present (ER) then
11911 return Is_Enabled_Pragma (ER);
11913 elsif Property = Name_Effective_Writes and then Present (EW) then
11914 return Is_Enabled_Pragma (EW);
11916 -- If other properties are set explicitly, then this one is set
11917 -- implicitly to False, except in the case of a derived type
11918 -- whose parent type is volatile (in that case, we will inherit
11919 -- from the parent type, below).
11921 elsif (Present (AR)
11922 or else Present (AW)
11923 or else Present (ER)
11924 or else Present (EW))
11925 and then not Is_Derived_Type_With_Volatile_Parent_Type
11926 then
11927 return False;
11929 -- For a private type (including subtype of a private types), look at
11930 -- the full view.
11932 elsif Is_Private_Type (Item_Id) and then Present (Full_View (Item_Id))
11933 then
11934 return Type_Or_Variable_Has_Enabled_Property (Full_View (Item_Id));
11936 -- For a derived type whose parent type is volatile, the
11937 -- property may be inherited (but ignore a non-volatile parent).
11939 elsif Is_Derived_Type_With_Volatile_Parent_Type then
11940 return Type_Or_Variable_Has_Enabled_Property
11941 (First_Subtype (Etype (Base_Type (Item_Id))));
11943 -- For a subtype, the property will be inherited from its base type.
11945 elsif Is_Type (Item_Id)
11946 and then not Is_Base_Type (Item_Id)
11947 then
11948 return Type_Or_Variable_Has_Enabled_Property (Etype (Item_Id));
11950 -- If not specified explicitly for an object and its type
11951 -- is effectively volatile, then take result from the type.
11953 elsif Is_Object (Item_Id)
11954 and then Is_Effectively_Volatile (Etype (Item_Id))
11955 then
11956 return Has_Enabled_Property (Etype (Item_Id), Property);
11958 -- The implicit case lacks all property pragmas
11960 elsif No (AR) and then No (AW) and then No (ER) and then No (EW) then
11961 if Is_Protected_Type (Etype (Item_Id)) then
11962 return Protected_Type_Or_Variable_Has_Enabled_Property;
11963 else
11964 return True;
11965 end if;
11967 else
11968 return False;
11969 end if;
11970 end Type_Or_Variable_Has_Enabled_Property;
11972 -- Start of processing for Has_Enabled_Property
11974 begin
11975 -- Abstract states and variables have a flexible scheme of specifying
11976 -- external properties.
11978 if Ekind (Item_Id) = E_Abstract_State then
11979 return State_Has_Enabled_Property;
11981 elsif Ekind (Item_Id) in E_Variable | E_Constant then
11982 return Type_Or_Variable_Has_Enabled_Property (Item_Id);
11984 -- Other objects can only inherit properties through their type. We
11985 -- cannot call directly Type_Or_Variable_Has_Enabled_Property on
11986 -- these as they don't have contracts attached, which is expected by
11987 -- this function.
11989 elsif Is_Object (Item_Id) then
11990 return Type_Or_Variable_Has_Enabled_Property (Etype (Item_Id));
11992 elsif Is_Type (Item_Id) then
11993 return Type_Or_Variable_Has_Enabled_Property
11994 (Item_Id => First_Subtype (Item_Id));
11996 -- Otherwise a property is enabled when the related item is effectively
11997 -- volatile.
11999 else
12000 return Is_Effectively_Volatile (Item_Id);
12001 end if;
12002 end Has_Enabled_Property;
12004 -------------------------------------
12005 -- Has_Full_Default_Initialization --
12006 -------------------------------------
12008 function Has_Full_Default_Initialization (Typ : Entity_Id) return Boolean is
12009 Comp : Entity_Id;
12011 begin
12012 -- A type subject to pragma Default_Initial_Condition may be fully
12013 -- default initialized depending on inheritance and the argument of
12014 -- the pragma. Since any type may act as the full view of a private
12015 -- type, this check must be performed prior to the specialized tests
12016 -- below.
12018 if Has_Fully_Default_Initializing_DIC_Pragma (Typ) then
12019 return True;
12020 end if;
12022 -- A scalar type is fully default initialized if it is subject to aspect
12023 -- Default_Value.
12025 if Is_Scalar_Type (Typ) then
12026 return Has_Default_Aspect (Typ);
12028 -- An access type is fully default initialized by default
12030 elsif Is_Access_Type (Typ) then
12031 return True;
12033 -- An array type is fully default initialized if its element type is
12034 -- scalar and the array type carries aspect Default_Component_Value or
12035 -- the element type is fully default initialized.
12037 elsif Is_Array_Type (Typ) then
12038 return
12039 Has_Default_Aspect (Typ)
12040 or else Has_Full_Default_Initialization (Component_Type (Typ));
12042 -- A protected type, record type, or type extension is fully default
12043 -- initialized if all its components either carry an initialization
12044 -- expression or have a type that is fully default initialized. The
12045 -- parent type of a type extension must be fully default initialized.
12047 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
12049 -- Inspect all entities defined in the scope of the type, looking for
12050 -- uninitialized components.
12052 Comp := First_Component (Typ);
12053 while Present (Comp) loop
12054 if Comes_From_Source (Comp)
12055 and then No (Expression (Parent (Comp)))
12056 and then not Has_Full_Default_Initialization (Etype (Comp))
12057 then
12058 return False;
12059 end if;
12061 Next_Component (Comp);
12062 end loop;
12064 -- Ensure that the parent type of a type extension is fully default
12065 -- initialized.
12067 if Etype (Typ) /= Typ
12068 and then not Has_Full_Default_Initialization (Etype (Typ))
12069 then
12070 return False;
12071 end if;
12073 -- If we get here, then all components and parent portion are fully
12074 -- default initialized.
12076 return True;
12078 -- A task type is fully default initialized by default
12080 elsif Is_Task_Type (Typ) then
12081 return True;
12083 -- Otherwise the type is not fully default initialized
12085 else
12086 return False;
12087 end if;
12088 end Has_Full_Default_Initialization;
12090 -----------------------------------------------
12091 -- Has_Fully_Default_Initializing_DIC_Pragma --
12092 -----------------------------------------------
12094 function Has_Fully_Default_Initializing_DIC_Pragma
12095 (Typ : Entity_Id) return Boolean
12097 Args : List_Id;
12098 Prag : Node_Id;
12100 begin
12101 -- A type that inherits pragma Default_Initial_Condition from a parent
12102 -- type is automatically fully default initialized.
12104 if Has_Inherited_DIC (Typ) then
12105 return True;
12107 -- Otherwise the type is fully default initialized only when the pragma
12108 -- appears without an argument, or the argument is non-null.
12110 elsif Has_Own_DIC (Typ) then
12111 Prag := Get_Pragma (Typ, Pragma_Default_Initial_Condition);
12112 pragma Assert (Present (Prag));
12113 Args := Pragma_Argument_Associations (Prag);
12115 -- The pragma appears without an argument in which case it defaults
12116 -- to True.
12118 if No (Args) then
12119 return True;
12121 -- The pragma appears with a non-null expression
12123 elsif Nkind (Get_Pragma_Arg (First (Args))) /= N_Null then
12124 return True;
12125 end if;
12126 end if;
12128 return False;
12129 end Has_Fully_Default_Initializing_DIC_Pragma;
12131 ---------------------------------
12132 -- Has_Inferable_Discriminants --
12133 ---------------------------------
12135 function Has_Inferable_Discriminants (N : Node_Id) return Boolean is
12137 function Prefix_Is_Formal_Parameter (N : Node_Id) return Boolean;
12138 -- Determines whether the left-most prefix of a selected component is a
12139 -- formal parameter in a subprogram. Assumes N is a selected component.
12141 --------------------------------
12142 -- Prefix_Is_Formal_Parameter --
12143 --------------------------------
12145 function Prefix_Is_Formal_Parameter (N : Node_Id) return Boolean is
12146 Sel_Comp : Node_Id;
12148 begin
12149 -- Move to the left-most prefix by climbing up the tree
12151 Sel_Comp := N;
12152 while Present (Parent (Sel_Comp))
12153 and then Nkind (Parent (Sel_Comp)) = N_Selected_Component
12154 loop
12155 Sel_Comp := Parent (Sel_Comp);
12156 end loop;
12158 return Is_Formal (Entity (Prefix (Sel_Comp)));
12159 end Prefix_Is_Formal_Parameter;
12161 -- Start of processing for Has_Inferable_Discriminants
12163 begin
12164 -- For selected components, the subtype of the selector must be a
12165 -- constrained Unchecked_Union. If the component is subject to a
12166 -- per-object constraint, then the enclosing object must have inferable
12167 -- discriminants.
12169 if Nkind (N) = N_Selected_Component then
12170 if Has_Per_Object_Constraint (Entity (Selector_Name (N))) then
12172 -- A small hack. If we have a per-object constrained selected
12173 -- component of a formal parameter, return True since we do not
12174 -- know the actual parameter association yet.
12176 if Prefix_Is_Formal_Parameter (N) then
12177 return True;
12179 -- Otherwise, check the enclosing object and the selector
12181 else
12182 return Has_Inferable_Discriminants (Prefix (N))
12183 and then Has_Inferable_Discriminants (Selector_Name (N));
12184 end if;
12186 -- The call to Has_Inferable_Discriminants will determine whether
12187 -- the selector has a constrained Unchecked_Union nominal type.
12189 else
12190 return Has_Inferable_Discriminants (Selector_Name (N));
12191 end if;
12193 -- A qualified expression has inferable discriminants if its subtype
12194 -- mark is a constrained Unchecked_Union subtype.
12196 elsif Nkind (N) = N_Qualified_Expression then
12197 return Is_Unchecked_Union (Etype (Subtype_Mark (N)))
12198 and then Is_Constrained (Etype (Subtype_Mark (N)));
12200 -- For all other names, it is sufficient to have a constrained
12201 -- Unchecked_Union nominal subtype.
12203 else
12204 return Is_Unchecked_Union (Base_Type (Etype (N)))
12205 and then Is_Constrained (Etype (N));
12206 end if;
12207 end Has_Inferable_Discriminants;
12209 --------------------
12210 -- Has_Infinities --
12211 --------------------
12213 function Has_Infinities (E : Entity_Id) return Boolean is
12214 begin
12215 return
12216 Is_Floating_Point_Type (E)
12217 and then Nkind (Scalar_Range (E)) = N_Range
12218 and then Includes_Infinities (Scalar_Range (E));
12219 end Has_Infinities;
12221 --------------------
12222 -- Has_Interfaces --
12223 --------------------
12225 function Has_Interfaces
12226 (T : Entity_Id;
12227 Use_Full_View : Boolean := True) return Boolean
12229 Typ : Entity_Id := Base_Type (T);
12231 begin
12232 -- Handle concurrent types
12234 if Is_Concurrent_Type (Typ) then
12235 Typ := Corresponding_Record_Type (Typ);
12236 end if;
12238 if No (Typ)
12239 or else not Is_Record_Type (Typ)
12240 or else not Is_Tagged_Type (Typ)
12241 then
12242 return False;
12243 end if;
12245 -- Handle private types
12247 if Use_Full_View and then Present (Full_View (Typ)) then
12248 Typ := Full_View (Typ);
12249 end if;
12251 -- Handle concurrent record types
12253 if Is_Concurrent_Record_Type (Typ)
12254 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
12255 then
12256 return True;
12257 end if;
12259 loop
12260 if Is_Interface (Typ)
12261 or else
12262 (Is_Record_Type (Typ)
12263 and then Present (Interfaces (Typ))
12264 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
12265 then
12266 return True;
12267 end if;
12269 exit when Etype (Typ) = Typ
12271 -- Handle private types
12273 or else (Present (Full_View (Etype (Typ)))
12274 and then Full_View (Etype (Typ)) = Typ)
12276 -- Protect frontend against wrong sources with cyclic derivations
12278 or else Etype (Typ) = T;
12280 -- Climb to the ancestor type handling private types
12282 if Present (Full_View (Etype (Typ))) then
12283 Typ := Full_View (Etype (Typ));
12284 else
12285 Typ := Etype (Typ);
12286 end if;
12287 end loop;
12289 return False;
12290 end Has_Interfaces;
12292 --------------------------
12293 -- Has_Max_Queue_Length --
12294 --------------------------
12296 function Has_Max_Queue_Length (Id : Entity_Id) return Boolean is
12297 begin
12298 return
12299 Ekind (Id) = E_Entry
12300 and then Present (Get_Pragma (Id, Pragma_Max_Queue_Length));
12301 end Has_Max_Queue_Length;
12303 ---------------------------------
12304 -- Has_No_Obvious_Side_Effects --
12305 ---------------------------------
12307 function Has_No_Obvious_Side_Effects (N : Node_Id) return Boolean is
12308 begin
12309 -- For now handle literals, constants, and non-volatile variables and
12310 -- expressions combining these with operators or short circuit forms.
12312 if Nkind (N) in N_Numeric_Or_String_Literal then
12313 return True;
12315 elsif Nkind (N) = N_Character_Literal then
12316 return True;
12318 elsif Nkind (N) in N_Unary_Op then
12319 return Has_No_Obvious_Side_Effects (Right_Opnd (N));
12321 elsif Nkind (N) in N_Binary_Op or else Nkind (N) in N_Short_Circuit then
12322 return Has_No_Obvious_Side_Effects (Left_Opnd (N))
12323 and then
12324 Has_No_Obvious_Side_Effects (Right_Opnd (N));
12326 elsif Nkind (N) = N_Expression_With_Actions
12327 and then Is_Empty_List (Actions (N))
12328 then
12329 return Has_No_Obvious_Side_Effects (Expression (N));
12331 elsif Nkind (N) in N_Has_Entity then
12332 return Present (Entity (N))
12333 and then
12334 Ekind (Entity (N)) in
12335 E_Variable | E_Constant | E_Enumeration_Literal |
12336 E_In_Parameter | E_Out_Parameter | E_In_Out_Parameter
12337 and then not Is_Volatile (Entity (N));
12339 else
12340 return False;
12341 end if;
12342 end Has_No_Obvious_Side_Effects;
12344 -----------------------------
12345 -- Has_Non_Null_Refinement --
12346 -----------------------------
12348 function Has_Non_Null_Refinement (Id : Entity_Id) return Boolean is
12349 Constits : Elist_Id;
12351 begin
12352 pragma Assert (Ekind (Id) = E_Abstract_State);
12353 Constits := Refinement_Constituents (Id);
12355 -- For a refinement to be non-null, the first constituent must be
12356 -- anything other than null.
12358 return
12359 Present (Constits)
12360 and then Nkind (Node (First_Elmt (Constits))) /= N_Null;
12361 end Has_Non_Null_Refinement;
12363 -----------------------------
12364 -- Has_Non_Null_Statements --
12365 -----------------------------
12367 function Has_Non_Null_Statements (L : List_Id) return Boolean is
12368 Node : Node_Id;
12370 begin
12371 Node := First (L);
12373 while Present (Node) loop
12374 if Nkind (Node) not in N_Null_Statement | N_Call_Marker then
12375 return True;
12376 end if;
12378 Next (Node);
12379 end loop;
12381 return False;
12382 end Has_Non_Null_Statements;
12384 ----------------------------------
12385 -- Is_Access_Subprogram_Wrapper --
12386 ----------------------------------
12388 function Is_Access_Subprogram_Wrapper (E : Entity_Id) return Boolean is
12389 Formal : constant Entity_Id := Last_Formal (E);
12390 begin
12391 return Present (Formal)
12392 and then Ekind (Etype (Formal)) in Access_Subprogram_Kind
12393 and then Access_Subprogram_Wrapper
12394 (Directly_Designated_Type (Etype (Formal))) = E;
12395 end Is_Access_Subprogram_Wrapper;
12397 ---------------------------
12398 -- Is_Explicitly_Aliased --
12399 ---------------------------
12401 function Is_Explicitly_Aliased (N : Node_Id) return Boolean is
12402 begin
12403 return Is_Formal (N)
12404 and then Present (Parent (N))
12405 and then Nkind (Parent (N)) = N_Parameter_Specification
12406 and then Aliased_Present (Parent (N));
12407 end Is_Explicitly_Aliased;
12409 ----------------------------
12410 -- Is_Container_Aggregate --
12411 ----------------------------
12413 function Is_Container_Aggregate (Exp : Node_Id) return Boolean is
12415 function Is_Record_Aggregate return Boolean is (False);
12416 -- ??? Unimplemented. Given an aggregate whose type is a
12417 -- record type with specified Aggregate aspect, how do we
12418 -- determine whether it is a record aggregate or a container
12419 -- aggregate? If the code where the aggregate occurs can see only
12420 -- a partial view of the aggregate's type then the aggregate
12421 -- cannot be a record type; an aggregate of a private type has to
12422 -- be a container aggregate.
12424 begin
12425 return Nkind (Exp) = N_Aggregate
12426 and then Has_Aspect (Etype (Exp), Aspect_Aggregate)
12427 and then not Is_Record_Aggregate;
12428 end Is_Container_Aggregate;
12430 ---------------------------------
12431 -- Side_Effect_Free_Statements --
12432 ---------------------------------
12434 function Side_Effect_Free_Statements (L : List_Id) return Boolean is
12435 Node : Node_Id;
12437 begin
12438 Node := First (L);
12440 while Present (Node) loop
12441 case Nkind (Node) is
12442 when N_Null_Statement | N_Call_Marker | N_Raise_xxx_Error =>
12443 null;
12445 when N_Object_Declaration =>
12446 if Present (Expression (Node))
12447 and then not Side_Effect_Free (Expression (Node))
12448 then
12449 return False;
12450 end if;
12452 when others =>
12453 return False;
12454 end case;
12456 Next (Node);
12457 end loop;
12459 return True;
12460 end Side_Effect_Free_Statements;
12462 ---------------------------
12463 -- Side_Effect_Free_Loop --
12464 ---------------------------
12466 function Side_Effect_Free_Loop (N : Node_Id) return Boolean is
12467 Scheme : Node_Id;
12468 Spec : Node_Id;
12469 Subt : Node_Id;
12471 begin
12472 -- If this is not a loop (e.g. because the loop has been rewritten),
12473 -- then return false.
12475 if Nkind (N) /= N_Loop_Statement then
12476 return False;
12477 end if;
12479 -- First check the statements
12481 if Side_Effect_Free_Statements (Statements (N)) then
12483 -- Then check the loop condition/indexes
12485 if Present (Iteration_Scheme (N)) then
12486 Scheme := Iteration_Scheme (N);
12488 if Present (Condition (Scheme))
12489 or else Present (Iterator_Specification (Scheme))
12490 then
12491 return False;
12492 elsif Present (Loop_Parameter_Specification (Scheme)) then
12493 Spec := Loop_Parameter_Specification (Scheme);
12494 Subt := Discrete_Subtype_Definition (Spec);
12496 if Present (Subt) then
12497 if Nkind (Subt) = N_Range then
12498 return Side_Effect_Free (Low_Bound (Subt))
12499 and then Side_Effect_Free (High_Bound (Subt));
12500 else
12501 -- subtype indication
12503 return True;
12504 end if;
12505 end if;
12506 end if;
12507 end if;
12508 end if;
12510 return False;
12511 end Side_Effect_Free_Loop;
12513 ----------------------------------
12514 -- Has_Non_Trivial_Precondition --
12515 ----------------------------------
12517 function Has_Non_Trivial_Precondition (Subp : Entity_Id) return Boolean is
12518 Pre : constant Node_Id := Find_Aspect (Subp, Aspect_Pre,
12519 Class_Present => True);
12520 begin
12521 return
12522 Present (Pre)
12523 and then not Is_Entity_Name (Expression (Pre));
12524 end Has_Non_Trivial_Precondition;
12526 -------------------
12527 -- Has_Null_Body --
12528 -------------------
12530 function Has_Null_Body (Proc_Id : Entity_Id) return Boolean is
12531 Body_Id : Entity_Id;
12532 Decl : Node_Id;
12533 Spec : Node_Id;
12534 Stmt1 : Node_Id;
12535 Stmt2 : Node_Id;
12537 begin
12538 Spec := Parent (Proc_Id);
12539 Decl := Parent (Spec);
12541 -- Retrieve the entity of the procedure body (e.g. invariant proc).
12543 if Nkind (Spec) = N_Procedure_Specification
12544 and then Nkind (Decl) = N_Subprogram_Declaration
12545 then
12546 Body_Id := Corresponding_Body (Decl);
12548 -- The body acts as a spec
12550 else
12551 Body_Id := Proc_Id;
12552 end if;
12554 -- The body will be generated later
12556 if No (Body_Id) then
12557 return False;
12558 end if;
12560 Spec := Parent (Body_Id);
12561 Decl := Parent (Spec);
12563 pragma Assert
12564 (Nkind (Spec) = N_Procedure_Specification
12565 and then Nkind (Decl) = N_Subprogram_Body);
12567 Stmt1 := First (Statements (Handled_Statement_Sequence (Decl)));
12569 -- Look for a null statement followed by an optional return
12570 -- statement.
12572 if Nkind (Stmt1) = N_Null_Statement then
12573 Stmt2 := Next (Stmt1);
12575 if Present (Stmt2) then
12576 return Nkind (Stmt2) = N_Simple_Return_Statement;
12577 else
12578 return True;
12579 end if;
12580 end if;
12582 return False;
12583 end Has_Null_Body;
12585 ------------------------
12586 -- Has_Null_Exclusion --
12587 ------------------------
12589 function Has_Null_Exclusion (N : Node_Id) return Boolean is
12590 begin
12591 case Nkind (N) is
12592 when N_Access_Definition
12593 | N_Access_Function_Definition
12594 | N_Access_Procedure_Definition
12595 | N_Access_To_Object_Definition
12596 | N_Allocator
12597 | N_Derived_Type_Definition
12598 | N_Function_Specification
12599 | N_Subtype_Declaration
12601 return Null_Exclusion_Present (N);
12603 when N_Component_Definition
12604 | N_Formal_Object_Declaration
12606 if Present (Subtype_Mark (N)) then
12607 return Null_Exclusion_Present (N);
12608 else pragma Assert (Present (Access_Definition (N)));
12609 return Null_Exclusion_Present (Access_Definition (N));
12610 end if;
12612 when N_Object_Renaming_Declaration =>
12613 if Present (Subtype_Mark (N)) then
12614 return Null_Exclusion_Present (N);
12615 elsif Present (Access_Definition (N)) then
12616 return Null_Exclusion_Present (Access_Definition (N));
12617 else
12618 return False; -- Case of no subtype in renaming (AI12-0275)
12619 end if;
12621 when N_Discriminant_Specification =>
12622 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
12623 return Null_Exclusion_Present (Discriminant_Type (N));
12624 else
12625 return Null_Exclusion_Present (N);
12626 end if;
12628 when N_Object_Declaration =>
12629 if Nkind (Object_Definition (N)) = N_Access_Definition then
12630 return Null_Exclusion_Present (Object_Definition (N));
12631 else
12632 return Null_Exclusion_Present (N);
12633 end if;
12635 when N_Parameter_Specification =>
12636 if Nkind (Parameter_Type (N)) = N_Access_Definition then
12637 return Null_Exclusion_Present (Parameter_Type (N))
12638 or else Null_Exclusion_Present (N);
12639 else
12640 return Null_Exclusion_Present (N);
12641 end if;
12643 when others =>
12644 return False;
12645 end case;
12646 end Has_Null_Exclusion;
12648 ------------------------
12649 -- Has_Null_Extension --
12650 ------------------------
12652 function Has_Null_Extension (T : Entity_Id) return Boolean is
12653 B : constant Entity_Id := Base_Type (T);
12654 Comps : Node_Id;
12655 Ext : Node_Id;
12657 begin
12658 if Nkind (Parent (B)) = N_Full_Type_Declaration
12659 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
12660 then
12661 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
12663 if Present (Ext) then
12664 if Null_Present (Ext) then
12665 return True;
12666 else
12667 Comps := Component_List (Ext);
12669 -- The null component list is rewritten during analysis to
12670 -- include the parent component. Any other component indicates
12671 -- that the extension was not originally null.
12673 return Null_Present (Comps)
12674 or else No (Next (First (Component_Items (Comps))));
12675 end if;
12676 else
12677 return False;
12678 end if;
12680 else
12681 return False;
12682 end if;
12683 end Has_Null_Extension;
12685 -------------------------
12686 -- Has_Null_Refinement --
12687 -------------------------
12689 function Has_Null_Refinement (Id : Entity_Id) return Boolean is
12690 Constits : Elist_Id;
12692 begin
12693 pragma Assert (Ekind (Id) = E_Abstract_State);
12694 Constits := Refinement_Constituents (Id);
12696 -- For a refinement to be null, the state's sole constituent must be a
12697 -- null.
12699 return
12700 Present (Constits)
12701 and then Nkind (Node (First_Elmt (Constits))) = N_Null;
12702 end Has_Null_Refinement;
12704 ------------------------------------------
12705 -- Has_Nonstatic_Class_Wide_Pre_Or_Post --
12706 ------------------------------------------
12708 function Is_Prim_Of_Abst_Type_With_Nonstatic_CW_Pre_Post
12709 (Subp : Entity_Id) return Boolean
12711 Disp_Type : constant Entity_Id := Find_Dispatching_Type (Subp);
12712 Prag : Node_Id;
12713 Pragma_Arg : Node_Id;
12715 begin
12716 if Present (Disp_Type)
12717 and then Is_Abstract_Type (Disp_Type)
12718 and then Present (Contract (Subp))
12719 then
12720 Prag := Pre_Post_Conditions (Contract (Subp));
12722 while Present (Prag) loop
12723 if Pragma_Name (Prag) in Name_Precondition | Name_Postcondition
12724 and then Class_Present (Prag)
12725 then
12726 Pragma_Arg :=
12727 Nlists.First
12728 (Pragma_Argument_Associations (Prag));
12730 if not Is_Static_Expression (Expression (Pragma_Arg)) then
12731 return True;
12732 end if;
12733 end if;
12735 Prag := Next_Pragma (Prag);
12736 end loop;
12737 end if;
12739 return False;
12740 end Is_Prim_Of_Abst_Type_With_Nonstatic_CW_Pre_Post;
12742 -------------------------------
12743 -- Has_Overriding_Initialize --
12744 -------------------------------
12746 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
12747 BT : constant Entity_Id := Base_Type (T);
12748 P : Elmt_Id;
12750 begin
12751 if Is_Controlled (BT) then
12752 if Is_RTU (Scope (BT), Ada_Finalization) then
12753 return False;
12755 elsif Present (Primitive_Operations (BT)) then
12756 P := First_Elmt (Primitive_Operations (BT));
12757 while Present (P) loop
12758 declare
12759 Init : constant Entity_Id := Node (P);
12760 Formal : constant Entity_Id := First_Formal (Init);
12761 begin
12762 if Ekind (Init) = E_Procedure
12763 and then Chars (Init) = Name_Initialize
12764 and then Comes_From_Source (Init)
12765 and then Present (Formal)
12766 and then Etype (Formal) = BT
12767 and then No (Next_Formal (Formal))
12768 and then (Ada_Version < Ada_2012
12769 or else not Null_Present (Parent (Init)))
12770 then
12771 return True;
12772 end if;
12773 end;
12775 Next_Elmt (P);
12776 end loop;
12777 end if;
12779 -- Here if type itself does not have a non-null Initialize operation:
12780 -- check immediate ancestor.
12782 if Is_Derived_Type (BT)
12783 and then Has_Overriding_Initialize (Etype (BT))
12784 then
12785 return True;
12786 end if;
12787 end if;
12789 return False;
12790 end Has_Overriding_Initialize;
12792 --------------------------------------
12793 -- Has_Preelaborable_Initialization --
12794 --------------------------------------
12796 function Has_Preelaborable_Initialization
12797 (E : Entity_Id;
12798 Preelab_Init_Expr : Node_Id := Empty) return Boolean
12800 Has_PE : Boolean;
12802 procedure Check_Components (E : Entity_Id);
12803 -- Check component/discriminant chain, sets Has_PE False if a component
12804 -- or discriminant does not meet the preelaborable initialization rules.
12806 function Type_Named_In_Preelab_Init_Expression
12807 (Typ : Entity_Id;
12808 Expr : Node_Id) return Boolean;
12809 -- Returns True iff Typ'Preelaborable_Initialization occurs in Expr
12810 -- (where Expr may be a conjunction of one or more P_I attributes).
12812 ----------------------
12813 -- Check_Components --
12814 ----------------------
12816 procedure Check_Components (E : Entity_Id) is
12817 Ent : Entity_Id;
12818 Exp : Node_Id;
12820 begin
12821 -- Loop through components and discriminants of record or protected
12822 -- type.
12824 Ent := First_Component_Or_Discriminant (E);
12825 while Present (Ent) loop
12827 case Ekind (Ent) is
12828 when E_Component =>
12830 -- Get default expression if any. If there is no declaration
12831 -- node, it means we have an internal entity. The parent and
12832 -- tag fields are examples of such entities. For such cases,
12833 -- we just test the type of the entity.
12835 if Present (Declaration_Node (Ent)) then
12836 Exp := Expression (Declaration_Node (Ent));
12837 else
12838 Exp := Empty;
12839 end if;
12841 when E_Discriminant =>
12843 -- Note: for a renamed discriminant, the Declaration_Node
12844 -- may point to the one from the ancestor, and have a
12845 -- different expression, so use the proper attribute to
12846 -- retrieve the expression from the derived constraint.
12848 Exp := Discriminant_Default_Value (Ent);
12850 when others =>
12851 raise Program_Error;
12852 end case;
12854 -- A component has PI if it has no default expression and the
12855 -- component type has PI.
12857 if No (Exp) then
12858 if not Has_Preelaborable_Initialization
12859 (Etype (Ent), Preelab_Init_Expr)
12860 then
12861 Has_PE := False;
12862 exit;
12863 end if;
12865 -- Require the default expression to be preelaborable
12867 elsif not Is_Preelaborable_Construct (Exp) then
12868 Has_PE := False;
12869 exit;
12870 end if;
12872 Next_Component_Or_Discriminant (Ent);
12873 end loop;
12874 end Check_Components;
12876 --------------------------------------
12877 -- Type_Named_In_Preelab_Expression --
12878 --------------------------------------
12880 function Type_Named_In_Preelab_Init_Expression
12881 (Typ : Entity_Id;
12882 Expr : Node_Id) return Boolean
12884 begin
12885 -- Return True if Expr is a Preelaborable_Initialization attribute
12886 -- and the prefix is a subtype that has the same type as Typ.
12888 if Nkind (Expr) = N_Attribute_Reference
12889 and then Attribute_Name (Expr) = Name_Preelaborable_Initialization
12890 and then Is_Entity_Name (Prefix (Expr))
12891 and then Base_Type (Entity (Prefix (Expr))) = Base_Type (Typ)
12892 then
12893 return True;
12895 -- In the case where Expr is a conjunction, test whether either
12896 -- operand is a Preelaborable_Initialization attribute whose prefix
12897 -- has the same type as Typ, and return True if so.
12899 elsif Nkind (Expr) = N_Op_And
12900 and then
12901 (Type_Named_In_Preelab_Init_Expression (Typ, Left_Opnd (Expr))
12902 or else
12903 Type_Named_In_Preelab_Init_Expression (Typ, Right_Opnd (Expr)))
12904 then
12905 return True;
12907 -- Typ not named in a Preelaborable_Initialization attribute of Expr
12909 else
12910 return False;
12911 end if;
12912 end Type_Named_In_Preelab_Init_Expression;
12914 -- Start of processing for Has_Preelaborable_Initialization
12916 begin
12917 -- Immediate return if already marked as known preelaborable init. This
12918 -- covers types for which this function has already been called once
12919 -- and returned True (in which case the result is cached), and also
12920 -- types to which a pragma Preelaborable_Initialization applies.
12922 if Known_To_Have_Preelab_Init (E) then
12923 return True;
12924 end if;
12926 -- If the type is a subtype representing a generic actual type, then
12927 -- test whether its base type has preelaborable initialization since
12928 -- the subtype representing the actual does not inherit this attribute
12929 -- from the actual or formal. (but maybe it should???)
12931 if Is_Generic_Actual_Type (E) then
12932 return Has_Preelaborable_Initialization (Base_Type (E));
12933 end if;
12935 -- All elementary types have preelaborable initialization
12937 if Is_Elementary_Type (E) then
12938 Has_PE := True;
12940 -- Array types have PI if the component type has PI
12942 elsif Is_Array_Type (E) then
12943 Has_PE := Has_Preelaborable_Initialization
12944 (Component_Type (E), Preelab_Init_Expr);
12946 -- A derived type has preelaborable initialization if its parent type
12947 -- has preelaborable initialization and (in the case of a derived record
12948 -- extension) if the non-inherited components all have preelaborable
12949 -- initialization. However, a user-defined controlled type with an
12950 -- overriding Initialize procedure does not have preelaborable
12951 -- initialization.
12953 elsif Is_Derived_Type (E) then
12955 -- When the rule of RM 10.2.1(11.8/5) applies, we presume a component
12956 -- of a generic formal derived type has preelaborable initialization.
12957 -- (See comment on spec of Has_Preelaborable_Initialization.)
12959 if Is_Generic_Type (E)
12960 and then Present (Preelab_Init_Expr)
12961 and then
12962 Type_Named_In_Preelab_Init_Expression (E, Preelab_Init_Expr)
12963 then
12964 return True;
12965 end if;
12967 -- If the derived type is a private extension then it doesn't have
12968 -- preelaborable initialization.
12970 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
12971 return False;
12972 end if;
12974 -- First check whether ancestor type has preelaborable initialization
12976 Has_PE := Has_Preelaborable_Initialization
12977 (Etype (Base_Type (E)), Preelab_Init_Expr);
12979 -- If OK, check extension components (if any)
12981 if Has_PE and then Is_Record_Type (E) then
12982 Check_Components (E);
12983 end if;
12985 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
12986 -- with a user defined Initialize procedure does not have PI. If
12987 -- the type is untagged, the control primitives come from a component
12988 -- that has already been checked.
12990 if Has_PE
12991 and then Is_Controlled (E)
12992 and then Is_Tagged_Type (E)
12993 and then Has_Overriding_Initialize (E)
12994 then
12995 Has_PE := False;
12996 end if;
12998 -- Private types not derived from a type having preelaborable init and
12999 -- that are not marked with pragma Preelaborable_Initialization do not
13000 -- have preelaborable initialization.
13002 elsif Is_Private_Type (E) then
13004 -- When the rule of RM 10.2.1(11.8/5) applies, we presume a component
13005 -- of a generic formal private type has preelaborable initialization.
13006 -- (See comment on spec of Has_Preelaborable_Initialization.)
13008 if Is_Generic_Type (E)
13009 and then Present (Preelab_Init_Expr)
13010 and then
13011 Type_Named_In_Preelab_Init_Expression (E, Preelab_Init_Expr)
13012 then
13013 return True;
13014 else
13015 return False;
13016 end if;
13018 -- Record type has PI if it is non private and all components have PI
13020 elsif Is_Record_Type (E) then
13021 Has_PE := True;
13022 Check_Components (E);
13024 -- Protected types must not have entries, and components must meet
13025 -- same set of rules as for record components.
13027 elsif Is_Protected_Type (E) then
13028 if Has_Entries (E) then
13029 Has_PE := False;
13030 else
13031 Has_PE := True;
13032 Check_Components (E);
13033 end if;
13035 -- Type System.Address always has preelaborable initialization
13037 elsif Is_RTE (E, RE_Address) then
13038 Has_PE := True;
13040 -- In all other cases, type does not have preelaborable initialization
13042 else
13043 return False;
13044 end if;
13046 -- If type has preelaborable initialization, cache result
13048 if Has_PE then
13049 Set_Known_To_Have_Preelab_Init (E);
13050 end if;
13052 return Has_PE;
13053 end Has_Preelaborable_Initialization;
13055 ----------------
13056 -- Has_Prefix --
13057 ----------------
13059 function Has_Prefix (N : Node_Id) return Boolean is
13060 begin
13061 return Nkind (N) in
13062 N_Attribute_Reference | N_Expanded_Name | N_Explicit_Dereference |
13063 N_Indexed_Component | N_Reference | N_Selected_Component |
13064 N_Slice;
13065 end Has_Prefix;
13067 ---------------------------
13068 -- Has_Private_Component --
13069 ---------------------------
13071 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
13072 Btype : Entity_Id := Base_Type (Type_Id);
13073 Component : Entity_Id;
13075 begin
13076 if Error_Posted (Type_Id)
13077 or else Error_Posted (Btype)
13078 then
13079 return False;
13080 end if;
13082 if Is_Class_Wide_Type (Btype) then
13083 Btype := Root_Type (Btype);
13084 end if;
13086 if Is_Private_Type (Btype) then
13087 declare
13088 UT : constant Entity_Id := Underlying_Type (Btype);
13089 begin
13090 if No (UT) then
13091 if No (Full_View (Btype)) then
13092 return not Is_Generic_Type (Btype)
13093 and then
13094 not Is_Generic_Type (Root_Type (Btype));
13095 else
13096 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
13097 end if;
13098 else
13099 return not Is_Frozen (UT) and then Has_Private_Component (UT);
13100 end if;
13101 end;
13103 elsif Is_Array_Type (Btype) then
13104 return Has_Private_Component (Component_Type (Btype));
13106 elsif Is_Record_Type (Btype) then
13107 Component := First_Component (Btype);
13108 while Present (Component) loop
13109 if Has_Private_Component (Etype (Component)) then
13110 return True;
13111 end if;
13113 Next_Component (Component);
13114 end loop;
13116 return False;
13118 elsif Is_Protected_Type (Btype)
13119 and then Present (Corresponding_Record_Type (Btype))
13120 then
13121 return Has_Private_Component (Corresponding_Record_Type (Btype));
13123 else
13124 return False;
13125 end if;
13126 end Has_Private_Component;
13128 --------------------------------
13129 -- Has_Relaxed_Initialization --
13130 --------------------------------
13132 function Has_Relaxed_Initialization (E : Entity_Id) return Boolean is
13134 function Denotes_Relaxed_Parameter
13135 (Expr : Node_Id;
13136 Param : Entity_Id)
13137 return Boolean;
13138 -- Returns True iff expression Expr denotes a formal parameter or
13139 -- function Param (through its attribute Result).
13141 -------------------------------
13142 -- Denotes_Relaxed_Parameter --
13143 -------------------------------
13145 function Denotes_Relaxed_Parameter
13146 (Expr : Node_Id;
13147 Param : Entity_Id) return Boolean is
13148 begin
13149 if Nkind (Expr) in N_Identifier | N_Expanded_Name then
13150 return Entity (Expr) = Param;
13151 else
13152 pragma Assert (Is_Attribute_Result (Expr));
13153 return Entity (Prefix (Expr)) = Param;
13154 end if;
13155 end Denotes_Relaxed_Parameter;
13157 -- Start of processing for Has_Relaxed_Initialization
13159 begin
13160 -- When analyzing, we checked all syntax legality rules for the aspect
13161 -- Relaxed_Initialization, but didn't store the property anywhere (e.g.
13162 -- as an Einfo flag). To query the property we look directly at the AST,
13163 -- but now without any syntactic checks.
13165 case Ekind (E) is
13166 -- Abstract states have option Relaxed_Initialization
13168 when E_Abstract_State =>
13169 return Is_Relaxed_Initialization_State (E);
13171 -- Constants have this aspect attached directly; for deferred
13172 -- constants, the aspect is attached to the partial view.
13174 when E_Constant =>
13175 return Has_Aspect (E, Aspect_Relaxed_Initialization);
13177 -- Variables have this aspect attached directly
13179 when E_Variable =>
13180 return Has_Aspect (E, Aspect_Relaxed_Initialization);
13182 -- Types have this aspect attached directly (though we only allow it
13183 -- to be specified for the first subtype). For private types, the
13184 -- aspect is attached to the partial view.
13186 when Type_Kind =>
13187 pragma Assert (Is_First_Subtype (E));
13188 return Has_Aspect (E, Aspect_Relaxed_Initialization);
13190 -- Formal parameters and functions have the Relaxed_Initialization
13191 -- aspect attached to the subprogram entity and must be listed in
13192 -- the aspect expression.
13194 when Formal_Kind
13195 | E_Function
13197 declare
13198 Subp_Id : Entity_Id;
13199 Aspect_Expr : Node_Id;
13200 Param_Expr : Node_Id;
13201 Assoc : Node_Id;
13203 begin
13204 if Is_Formal (E) then
13205 Subp_Id := Scope (E);
13206 else
13207 Subp_Id := E;
13208 end if;
13210 if Has_Aspect (Subp_Id, Aspect_Relaxed_Initialization) then
13211 Aspect_Expr :=
13212 Find_Value_Of_Aspect
13213 (Subp_Id, Aspect_Relaxed_Initialization);
13215 -- Aspect expression is either an aggregate with an optional
13216 -- Boolean expression (which defaults to True), e.g.:
13218 -- function F (X : Integer) return Integer
13219 -- with Relaxed_Initialization => (X => True, F'Result);
13221 if Nkind (Aspect_Expr) = N_Aggregate then
13223 if Present (Component_Associations (Aspect_Expr)) then
13224 Assoc := First (Component_Associations (Aspect_Expr));
13226 while Present (Assoc) loop
13227 if Denotes_Relaxed_Parameter
13228 (First (Choices (Assoc)), E)
13229 then
13230 return
13231 Is_True
13232 (Static_Boolean (Expression (Assoc)));
13233 end if;
13235 Next (Assoc);
13236 end loop;
13237 end if;
13239 Param_Expr := First (Expressions (Aspect_Expr));
13241 while Present (Param_Expr) loop
13242 if Denotes_Relaxed_Parameter (Param_Expr, E) then
13243 return True;
13244 end if;
13246 Next (Param_Expr);
13247 end loop;
13249 return False;
13251 -- or it is a single identifier, e.g.:
13253 -- function F (X : Integer) return Integer
13254 -- with Relaxed_Initialization => X;
13256 else
13257 return Denotes_Relaxed_Parameter (Aspect_Expr, E);
13258 end if;
13259 else
13260 return False;
13261 end if;
13262 end;
13264 when others =>
13265 raise Program_Error;
13266 end case;
13267 end Has_Relaxed_Initialization;
13269 ----------------------
13270 -- Has_Signed_Zeros --
13271 ----------------------
13273 function Has_Signed_Zeros (E : Entity_Id) return Boolean is
13274 begin
13275 return Is_Floating_Point_Type (E) and then Signed_Zeros_On_Target;
13276 end Has_Signed_Zeros;
13278 ------------------------------
13279 -- Has_Significant_Contract --
13280 ------------------------------
13282 function Has_Significant_Contract (Subp_Id : Entity_Id) return Boolean is
13283 Subp_Nam : constant Name_Id := Chars (Subp_Id);
13285 begin
13286 -- _Finalizer procedure
13288 if Subp_Nam = Name_uFinalizer then
13289 return False;
13291 -- _Wrapped_Statements procedure which gets generated as part of the
13292 -- expansion of postconditions.
13294 elsif Subp_Nam = Name_uWrapped_Statements then
13295 return False;
13297 -- Predicate function
13299 elsif Ekind (Subp_Id) = E_Function
13300 and then Is_Predicate_Function (Subp_Id)
13301 then
13302 return False;
13304 -- TSS subprogram
13306 elsif Get_TSS_Name (Subp_Id) /= TSS_Null then
13307 return False;
13309 else
13310 return True;
13311 end if;
13312 end Has_Significant_Contract;
13314 -----------------------------
13315 -- Has_Static_Array_Bounds --
13316 -----------------------------
13318 function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is
13319 All_Static : Boolean;
13320 Dummy : Boolean;
13322 begin
13323 Examine_Array_Bounds (Typ, All_Static, Dummy);
13325 return All_Static;
13326 end Has_Static_Array_Bounds;
13328 ---------------------------------------
13329 -- Has_Static_Non_Empty_Array_Bounds --
13330 ---------------------------------------
13332 function Has_Static_Non_Empty_Array_Bounds (Typ : Node_Id) return Boolean is
13333 All_Static : Boolean;
13334 Has_Empty : Boolean;
13336 begin
13337 Examine_Array_Bounds (Typ, All_Static, Has_Empty);
13339 return All_Static and not Has_Empty;
13340 end Has_Static_Non_Empty_Array_Bounds;
13342 ----------------
13343 -- Has_Stream --
13344 ----------------
13346 function Has_Stream (T : Entity_Id) return Boolean is
13347 E : Entity_Id;
13349 begin
13350 if No (T) then
13351 return False;
13353 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
13354 return True;
13356 elsif Is_Array_Type (T) then
13357 return Has_Stream (Component_Type (T));
13359 elsif Is_Record_Type (T) then
13360 E := First_Component (T);
13361 while Present (E) loop
13362 if Has_Stream (Etype (E)) then
13363 return True;
13364 else
13365 Next_Component (E);
13366 end if;
13367 end loop;
13369 return False;
13371 elsif Is_Private_Type (T) then
13372 return Has_Stream (Underlying_Type (T));
13374 else
13375 return False;
13376 end if;
13377 end Has_Stream;
13379 ----------------
13380 -- Has_Suffix --
13381 ----------------
13383 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
13384 begin
13385 Get_Name_String (Chars (E));
13386 return Name_Buffer (Name_Len) = Suffix;
13387 end Has_Suffix;
13389 ----------------
13390 -- Add_Suffix --
13391 ----------------
13393 function Add_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
13394 begin
13395 Get_Name_String (Chars (E));
13396 Add_Char_To_Name_Buffer (Suffix);
13397 return Name_Find;
13398 end Add_Suffix;
13400 -------------------
13401 -- Remove_Suffix --
13402 -------------------
13404 function Remove_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
13405 begin
13406 pragma Assert (Has_Suffix (E, Suffix));
13407 Get_Name_String (Chars (E));
13408 Name_Len := Name_Len - 1;
13409 return Name_Find;
13410 end Remove_Suffix;
13412 ----------------------------------
13413 -- Replace_Null_By_Null_Address --
13414 ----------------------------------
13416 procedure Replace_Null_By_Null_Address (N : Node_Id) is
13417 procedure Replace_Null_Operand (Op : Node_Id; Other_Op : Node_Id);
13418 -- Replace operand Op with a reference to Null_Address when the operand
13419 -- denotes a null Address. Other_Op denotes the other operand.
13421 --------------------------
13422 -- Replace_Null_Operand --
13423 --------------------------
13425 procedure Replace_Null_Operand (Op : Node_Id; Other_Op : Node_Id) is
13426 begin
13427 -- Check the type of the complementary operand since the N_Null node
13428 -- has not been decorated yet.
13430 if Nkind (Op) = N_Null
13431 and then Is_Descendant_Of_Address (Etype (Other_Op))
13432 then
13433 Rewrite (Op, New_Occurrence_Of (RTE (RE_Null_Address), Sloc (Op)));
13434 end if;
13435 end Replace_Null_Operand;
13437 -- Start of processing for Replace_Null_By_Null_Address
13439 begin
13440 pragma Assert (Relaxed_RM_Semantics);
13441 pragma Assert (Nkind (N) in N_Null | N_Op_Compare);
13443 if Nkind (N) = N_Null then
13444 Rewrite (N, New_Occurrence_Of (RTE (RE_Null_Address), Sloc (N)));
13446 else
13447 declare
13448 L : constant Node_Id := Left_Opnd (N);
13449 R : constant Node_Id := Right_Opnd (N);
13451 begin
13452 Replace_Null_Operand (L, Other_Op => R);
13453 Replace_Null_Operand (R, Other_Op => L);
13454 end;
13455 end if;
13456 end Replace_Null_By_Null_Address;
13458 --------------------------
13459 -- Has_Tagged_Component --
13460 --------------------------
13462 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
13463 Comp : Entity_Id;
13465 begin
13466 if Is_Private_Type (Typ) and then Present (Underlying_Type (Typ)) then
13467 return Has_Tagged_Component (Underlying_Type (Typ));
13469 elsif Is_Array_Type (Typ) then
13470 return Has_Tagged_Component (Component_Type (Typ));
13472 elsif Is_Tagged_Type (Typ) then
13473 return True;
13475 elsif Is_Record_Type (Typ) then
13476 Comp := First_Component (Typ);
13477 while Present (Comp) loop
13478 if Has_Tagged_Component (Etype (Comp)) then
13479 return True;
13480 end if;
13482 Next_Component (Comp);
13483 end loop;
13485 return False;
13487 else
13488 return False;
13489 end if;
13490 end Has_Tagged_Component;
13492 -----------------------------
13493 -- Has_Undefined_Reference --
13494 -----------------------------
13496 function Has_Undefined_Reference (Expr : Node_Id) return Boolean is
13497 Has_Undef_Ref : Boolean := False;
13498 -- Flag set when expression Expr contains at least one undefined
13499 -- reference.
13501 function Is_Undefined_Reference (N : Node_Id) return Traverse_Result;
13502 -- Determine whether N denotes a reference and if it does, whether it is
13503 -- undefined.
13505 ----------------------------
13506 -- Is_Undefined_Reference --
13507 ----------------------------
13509 function Is_Undefined_Reference (N : Node_Id) return Traverse_Result is
13510 begin
13511 if Is_Entity_Name (N)
13512 and then Present (Entity (N))
13513 and then Entity (N) = Any_Id
13514 then
13515 Has_Undef_Ref := True;
13516 return Abandon;
13517 end if;
13519 return OK;
13520 end Is_Undefined_Reference;
13522 procedure Find_Undefined_References is
13523 new Traverse_Proc (Is_Undefined_Reference);
13525 -- Start of processing for Has_Undefined_Reference
13527 begin
13528 Find_Undefined_References (Expr);
13530 return Has_Undef_Ref;
13531 end Has_Undefined_Reference;
13533 ----------------------------------------
13534 -- Has_Effectively_Volatile_Component --
13535 ----------------------------------------
13537 function Has_Effectively_Volatile_Component
13538 (Typ : Entity_Id) return Boolean
13540 Comp : Entity_Id;
13542 begin
13543 if Has_Volatile_Components (Typ) then
13544 return True;
13546 elsif Is_Array_Type (Typ) then
13547 return Is_Effectively_Volatile (Component_Type (Typ));
13549 elsif Is_Record_Type (Typ) then
13550 Comp := First_Component (Typ);
13551 while Present (Comp) loop
13552 if Is_Effectively_Volatile (Etype (Comp)) then
13553 return True;
13554 end if;
13556 Next_Component (Comp);
13557 end loop;
13558 end if;
13560 return False;
13561 end Has_Effectively_Volatile_Component;
13563 ----------------------------
13564 -- Has_Volatile_Component --
13565 ----------------------------
13567 function Has_Volatile_Component (Typ : Entity_Id) return Boolean is
13568 Comp : Entity_Id;
13570 begin
13571 if Has_Volatile_Components (Typ) then
13572 return True;
13574 elsif Is_Array_Type (Typ) then
13575 return Is_Volatile (Component_Type (Typ));
13577 elsif Is_Record_Type (Typ) then
13578 Comp := First_Component (Typ);
13579 while Present (Comp) loop
13580 if Is_Volatile_Object_Ref (Comp) then
13581 return True;
13582 end if;
13584 Next_Component (Comp);
13585 end loop;
13586 end if;
13588 return False;
13589 end Has_Volatile_Component;
13591 -------------------------
13592 -- Implementation_Kind --
13593 -------------------------
13595 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
13596 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
13597 Arg : Node_Id;
13598 begin
13599 pragma Assert (Present (Impl_Prag));
13600 Arg := Last (Pragma_Argument_Associations (Impl_Prag));
13601 return Chars (Get_Pragma_Arg (Arg));
13602 end Implementation_Kind;
13604 --------------------------
13605 -- Implements_Interface --
13606 --------------------------
13608 function Implements_Interface
13609 (Typ_Ent : Entity_Id;
13610 Iface_Ent : Entity_Id;
13611 Exclude_Parents : Boolean := False) return Boolean
13613 Ifaces_List : Elist_Id;
13614 Elmt : Elmt_Id;
13615 Iface : Entity_Id := Base_Type (Iface_Ent);
13616 Typ : Entity_Id := Base_Type (Typ_Ent);
13618 begin
13619 if Is_Class_Wide_Type (Typ) then
13620 Typ := Root_Type (Typ);
13621 end if;
13623 if not Has_Interfaces (Typ) then
13624 return False;
13625 end if;
13627 if Is_Class_Wide_Type (Iface) then
13628 Iface := Root_Type (Iface);
13629 end if;
13631 Collect_Interfaces (Typ, Ifaces_List);
13633 Elmt := First_Elmt (Ifaces_List);
13634 while Present (Elmt) loop
13635 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
13636 and then Exclude_Parents
13637 then
13638 null;
13640 elsif Node (Elmt) = Iface then
13641 return True;
13642 end if;
13644 Next_Elmt (Elmt);
13645 end loop;
13647 return False;
13648 end Implements_Interface;
13650 --------------------------------
13651 -- Implicitly_Designated_Type --
13652 --------------------------------
13654 function Implicitly_Designated_Type (Typ : Entity_Id) return Entity_Id is
13655 Desig : constant Entity_Id := Designated_Type (Typ);
13657 begin
13658 -- An implicit dereference is a legal occurrence of an incomplete type
13659 -- imported through a limited_with clause, if the full view is visible.
13661 if Is_Incomplete_Type (Desig)
13662 and then From_Limited_With (Desig)
13663 and then not From_Limited_With (Scope (Desig))
13664 and then
13665 (Is_Immediately_Visible (Scope (Desig))
13666 or else
13667 (Is_Child_Unit (Scope (Desig))
13668 and then Is_Visible_Lib_Unit (Scope (Desig))))
13669 then
13670 return Available_View (Desig);
13671 else
13672 return Desig;
13673 end if;
13674 end Implicitly_Designated_Type;
13676 ------------------------------------
13677 -- In_Assertion_Expression_Pragma --
13678 ------------------------------------
13680 function In_Assertion_Expression_Pragma (N : Node_Id) return Boolean is
13681 Par : Node_Id;
13682 Prag : Node_Id := Empty;
13684 begin
13685 -- Climb the parent chain looking for an enclosing pragma
13687 Par := N;
13688 while Present (Par) loop
13689 if Nkind (Par) = N_Pragma then
13690 Prag := Par;
13691 exit;
13693 -- Precondition-like pragmas are expanded into if statements, check
13694 -- the original node instead.
13696 elsif Nkind (Original_Node (Par)) = N_Pragma then
13697 Prag := Original_Node (Par);
13698 exit;
13700 -- The expansion of attribute 'Old generates a constant to capture
13701 -- the result of the prefix. If the parent traversal reaches
13702 -- one of these constants, then the node technically came from a
13703 -- postcondition-like pragma. Note that the Ekind is not tested here
13704 -- because N may be the expression of an object declaration which is
13705 -- currently being analyzed. Such objects carry Ekind of E_Void.
13707 elsif Nkind (Par) = N_Object_Declaration
13708 and then Constant_Present (Par)
13709 and then Stores_Attribute_Old_Prefix (Defining_Entity (Par))
13710 then
13711 return True;
13713 -- Prevent the search from going too far
13715 elsif Is_Body_Or_Package_Declaration (Par) then
13716 return False;
13717 end if;
13719 Par := Parent (Par);
13720 end loop;
13722 return
13723 Present (Prag)
13724 and then Assertion_Expression_Pragma (Get_Pragma_Id (Prag));
13725 end In_Assertion_Expression_Pragma;
13727 -------------------
13728 -- In_Check_Node --
13729 -------------------
13731 function In_Check_Node (N : Node_Id) return Boolean is
13732 Par : Node_Id := Parent (N);
13733 begin
13734 while Present (Par) loop
13735 if Nkind (Par) in N_Raise_xxx_Error then
13736 return True;
13738 -- Prevent the search from going too far
13740 elsif Is_Body_Or_Package_Declaration (Par) then
13741 return False;
13743 else
13744 Par := Parent (Par);
13745 end if;
13746 end loop;
13748 return False;
13749 end In_Check_Node;
13751 -------------------------------
13752 -- In_Generic_Formal_Package --
13753 -------------------------------
13755 function In_Generic_Formal_Package (E : Entity_Id) return Boolean is
13756 Par : Node_Id;
13758 begin
13759 Par := Parent (E);
13760 while Present (Par) loop
13761 if Nkind (Par) = N_Formal_Package_Declaration
13762 or else Nkind (Original_Node (Par)) = N_Formal_Package_Declaration
13763 then
13764 return True;
13765 end if;
13767 Par := Parent (Par);
13768 end loop;
13770 return False;
13771 end In_Generic_Formal_Package;
13773 ----------------------
13774 -- In_Generic_Scope --
13775 ----------------------
13777 function In_Generic_Scope (E : Entity_Id) return Boolean is
13778 S : Entity_Id;
13780 begin
13781 S := Scope (E);
13782 while Present (S) and then S /= Standard_Standard loop
13783 if Is_Generic_Unit (S) then
13784 return True;
13785 end if;
13787 S := Scope (S);
13788 end loop;
13790 return False;
13791 end In_Generic_Scope;
13793 -----------------
13794 -- In_Instance --
13795 -----------------
13797 function In_Instance return Boolean is
13798 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
13799 S : Entity_Id;
13801 begin
13802 S := Current_Scope;
13803 while Present (S) and then S /= Standard_Standard loop
13804 if Is_Generic_Instance (S) then
13806 -- A child instance is always compiled in the context of a parent
13807 -- instance. Nevertheless, its actuals must not be analyzed in an
13808 -- instance context. We detect this case by examining the current
13809 -- compilation unit, which must be a child instance, and checking
13810 -- that it has not been analyzed yet.
13812 if Is_Child_Unit (Curr_Unit)
13813 and then Nkind (Unit (Cunit (Current_Sem_Unit))) =
13814 N_Package_Instantiation
13815 and then Ekind (Curr_Unit) = E_Void
13816 then
13817 return False;
13818 else
13819 return True;
13820 end if;
13821 end if;
13823 S := Scope (S);
13824 end loop;
13826 return False;
13827 end In_Instance;
13829 ----------------------
13830 -- In_Instance_Body --
13831 ----------------------
13833 function In_Instance_Body return Boolean is
13834 S : Entity_Id;
13836 begin
13837 S := Current_Scope;
13838 while Present (S) and then S /= Standard_Standard loop
13839 if Ekind (S) in E_Function | E_Procedure
13840 and then Is_Generic_Instance (S)
13841 then
13842 return True;
13844 elsif Ekind (S) = E_Package
13845 and then In_Package_Body (S)
13846 and then Is_Generic_Instance (S)
13847 then
13848 return True;
13849 end if;
13851 S := Scope (S);
13852 end loop;
13854 return False;
13855 end In_Instance_Body;
13857 -----------------------------
13858 -- In_Instance_Not_Visible --
13859 -----------------------------
13861 function In_Instance_Not_Visible return Boolean is
13862 S : Entity_Id;
13864 begin
13865 S := Current_Scope;
13866 while Present (S) and then S /= Standard_Standard loop
13867 if Ekind (S) in E_Function | E_Procedure
13868 and then Is_Generic_Instance (S)
13869 then
13870 return True;
13872 elsif Ekind (S) = E_Package
13873 and then (In_Package_Body (S) or else In_Private_Part (S))
13874 and then Is_Generic_Instance (S)
13875 then
13876 return True;
13877 end if;
13879 S := Scope (S);
13880 end loop;
13882 return False;
13883 end In_Instance_Not_Visible;
13885 ------------------------------
13886 -- In_Instance_Visible_Part --
13887 ------------------------------
13889 function In_Instance_Visible_Part
13890 (Id : Entity_Id := Current_Scope) return Boolean
13892 Inst : Entity_Id;
13894 begin
13895 Inst := Id;
13896 while Present (Inst) and then Inst /= Standard_Standard loop
13897 if Ekind (Inst) = E_Package
13898 and then Is_Generic_Instance (Inst)
13899 and then not In_Package_Body (Inst)
13900 and then not In_Private_Part (Inst)
13901 then
13902 return True;
13903 end if;
13905 Inst := Scope (Inst);
13906 end loop;
13908 return False;
13909 end In_Instance_Visible_Part;
13911 ---------------------
13912 -- In_Package_Body --
13913 ---------------------
13915 function In_Package_Body return Boolean is
13916 S : Entity_Id;
13918 begin
13919 S := Current_Scope;
13920 while Present (S) and then S /= Standard_Standard loop
13921 if Ekind (S) = E_Package and then In_Package_Body (S) then
13922 return True;
13923 else
13924 S := Scope (S);
13925 end if;
13926 end loop;
13928 return False;
13929 end In_Package_Body;
13931 --------------------------
13932 -- In_Pragma_Expression --
13933 --------------------------
13935 function In_Pragma_Expression (N : Node_Id; Nam : Name_Id) return Boolean is
13936 P : Node_Id;
13937 begin
13938 P := Parent (N);
13939 loop
13940 if No (P) then
13941 return False;
13943 -- Prevent the search from going too far
13945 elsif Is_Body_Or_Package_Declaration (P) then
13946 return False;
13948 elsif Nkind (P) = N_Pragma and then Pragma_Name (P) = Nam then
13949 return True;
13951 else
13952 P := Parent (P);
13953 end if;
13954 end loop;
13955 end In_Pragma_Expression;
13957 ---------------------------
13958 -- In_Pre_Post_Condition --
13959 ---------------------------
13961 function In_Pre_Post_Condition
13962 (N : Node_Id; Class_Wide_Only : Boolean := False) return Boolean
13964 Par : Node_Id;
13965 Prag : Node_Id := Empty;
13966 Prag_Id : Pragma_Id;
13968 begin
13969 -- Climb the parent chain looking for an enclosing pragma
13971 Par := N;
13972 while Present (Par) loop
13973 if Nkind (Par) = N_Pragma then
13974 Prag := Par;
13975 exit;
13977 -- Prevent the search from going too far
13979 elsif Is_Body_Or_Package_Declaration (Par) then
13980 exit;
13981 end if;
13983 Par := Parent (Par);
13984 end loop;
13986 if Present (Prag) then
13987 Prag_Id := Get_Pragma_Id (Prag);
13989 if Class_Wide_Only then
13990 return
13991 Prag_Id = Pragma_Post_Class
13992 or else Prag_Id = Pragma_Pre_Class
13993 or else (Class_Present (Prag)
13994 and then (Prag_Id = Pragma_Post
13995 or else Prag_Id = Pragma_Postcondition
13996 or else Prag_Id = Pragma_Pre
13997 or else Prag_Id = Pragma_Precondition));
13998 else
13999 return
14000 Prag_Id = Pragma_Post
14001 or else Prag_Id = Pragma_Post_Class
14002 or else Prag_Id = Pragma_Postcondition
14003 or else Prag_Id = Pragma_Pre
14004 or else Prag_Id = Pragma_Pre_Class
14005 or else Prag_Id = Pragma_Precondition;
14006 end if;
14008 -- Otherwise the node is not enclosed by a pre/postcondition pragma
14010 else
14011 return False;
14012 end if;
14013 end In_Pre_Post_Condition;
14015 ------------------------------
14016 -- In_Quantified_Expression --
14017 ------------------------------
14019 function In_Quantified_Expression (N : Node_Id) return Boolean is
14020 P : Node_Id;
14021 begin
14022 P := Parent (N);
14023 loop
14024 if No (P) then
14025 return False;
14027 -- Prevent the search from going too far
14029 elsif Is_Body_Or_Package_Declaration (P) then
14030 return False;
14032 elsif Nkind (P) = N_Quantified_Expression then
14033 return True;
14034 else
14035 P := Parent (P);
14036 end if;
14037 end loop;
14038 end In_Quantified_Expression;
14040 -------------------------------------
14041 -- In_Reverse_Storage_Order_Object --
14042 -------------------------------------
14044 function In_Reverse_Storage_Order_Object (N : Node_Id) return Boolean is
14045 Pref : Node_Id;
14046 Btyp : Entity_Id := Empty;
14048 begin
14049 -- Climb up indexed components
14051 Pref := N;
14052 loop
14053 case Nkind (Pref) is
14054 when N_Selected_Component =>
14055 Pref := Prefix (Pref);
14056 exit;
14058 when N_Indexed_Component =>
14059 Pref := Prefix (Pref);
14061 when others =>
14062 Pref := Empty;
14063 exit;
14064 end case;
14065 end loop;
14067 if Present (Pref) then
14068 Btyp := Base_Type (Etype (Pref));
14069 end if;
14071 return Present (Btyp)
14072 and then (Is_Record_Type (Btyp) or else Is_Array_Type (Btyp))
14073 and then Reverse_Storage_Order (Btyp);
14074 end In_Reverse_Storage_Order_Object;
14076 ------------------------------
14077 -- In_Same_Declarative_Part --
14078 ------------------------------
14080 function In_Same_Declarative_Part
14081 (Context : Node_Id;
14082 N : Node_Id) return Boolean
14084 Cont : Node_Id := Context;
14085 Nod : Node_Id;
14087 begin
14088 if Nkind (Cont) = N_Compilation_Unit_Aux then
14089 Cont := Parent (Cont);
14090 end if;
14092 Nod := Parent (N);
14093 while Present (Nod) loop
14094 if Nod = Cont then
14095 return True;
14097 elsif Nkind (Nod) in N_Accept_Statement
14098 | N_Block_Statement
14099 | N_Compilation_Unit
14100 | N_Entry_Body
14101 | N_Package_Body
14102 | N_Package_Declaration
14103 | N_Protected_Body
14104 | N_Subprogram_Body
14105 | N_Task_Body
14106 then
14107 return False;
14109 elsif Nkind (Nod) = N_Subunit then
14110 Nod := Corresponding_Stub (Nod);
14112 else
14113 Nod := Parent (Nod);
14114 end if;
14115 end loop;
14117 return False;
14118 end In_Same_Declarative_Part;
14120 --------------------------------------
14121 -- In_Subprogram_Or_Concurrent_Unit --
14122 --------------------------------------
14124 function In_Subprogram_Or_Concurrent_Unit return Boolean is
14125 E : Entity_Id;
14126 K : Entity_Kind;
14128 begin
14129 -- Use scope chain to check successively outer scopes
14131 E := Current_Scope;
14132 loop
14133 K := Ekind (E);
14135 if K in Subprogram_Kind
14136 or else K in Concurrent_Kind
14137 or else K in Generic_Subprogram_Kind
14138 then
14139 return True;
14141 elsif E = Standard_Standard then
14142 return False;
14143 end if;
14145 E := Scope (E);
14146 end loop;
14147 end In_Subprogram_Or_Concurrent_Unit;
14149 ----------------
14150 -- In_Subtree --
14151 ----------------
14153 function In_Subtree (N : Node_Id; Root : Node_Id) return Boolean is
14154 Curr : Node_Id;
14156 begin
14157 Curr := N;
14158 while Present (Curr) loop
14159 if Curr = Root then
14160 return True;
14161 end if;
14163 Curr := Parent (Curr);
14164 end loop;
14166 return False;
14167 end In_Subtree;
14169 ----------------
14170 -- In_Subtree --
14171 ----------------
14173 function In_Subtree
14174 (N : Node_Id;
14175 Root1 : Node_Id;
14176 Root2 : Node_Id) return Boolean
14178 Curr : Node_Id;
14180 begin
14181 Curr := N;
14182 while Present (Curr) loop
14183 if Curr = Root1 or else Curr = Root2 then
14184 return True;
14185 end if;
14187 Curr := Parent (Curr);
14188 end loop;
14190 return False;
14191 end In_Subtree;
14193 ---------------------
14194 -- In_Return_Value --
14195 ---------------------
14197 function In_Return_Value (Expr : Node_Id) return Boolean is
14198 Par : Node_Id;
14199 Prev_Par : Node_Id;
14200 Pre : Node_Id;
14201 In_Function_Call : Boolean := False;
14203 begin
14204 -- Move through parent nodes to determine if Expr contributes to the
14205 -- return value of the current subprogram.
14207 Par := Expr;
14208 Prev_Par := Empty;
14209 while Present (Par) loop
14211 case Nkind (Par) is
14212 -- Ignore ranges and they don't contribute to the result
14214 when N_Range =>
14215 return False;
14217 -- An object declaration whose parent is an extended return
14218 -- statement is a return object.
14220 when N_Object_Declaration =>
14221 if Present (Parent (Par))
14222 and then Nkind (Parent (Par)) = N_Extended_Return_Statement
14223 then
14224 return True;
14225 end if;
14227 -- We hit a simple return statement, so we know we are in one
14229 when N_Simple_Return_Statement =>
14230 return True;
14232 -- Only include one nexting level of function calls
14234 when N_Function_Call =>
14235 if not In_Function_Call then
14236 In_Function_Call := True;
14238 -- When the function return type has implicit dereference
14239 -- specified we know it cannot directly contribute to the
14240 -- return value.
14242 if Present (Etype (Par))
14243 and then Has_Implicit_Dereference
14244 (Get_Full_View (Etype (Par)))
14245 then
14246 return False;
14247 end if;
14248 else
14249 return False;
14250 end if;
14252 -- Check if we are on the right-hand side of an assignment
14253 -- statement to a return object.
14255 -- This is not specified in the RM ???
14257 when N_Assignment_Statement =>
14258 if Prev_Par = Name (Par) then
14259 return False;
14260 end if;
14262 Pre := Name (Par);
14263 while Present (Pre) loop
14264 if Is_Entity_Name (Pre)
14265 and then Is_Return_Object (Entity (Pre))
14266 then
14267 return True;
14268 end if;
14270 exit when Nkind (Pre) not in N_Selected_Component
14271 | N_Indexed_Component
14272 | N_Slice;
14274 Pre := Prefix (Pre);
14275 end loop;
14277 -- Otherwise, we hit a master which was not relevant
14279 when others =>
14280 if Is_Master (Par) then
14281 return False;
14282 end if;
14283 end case;
14285 -- Iterate up to the next parent, keeping track of the previous one
14287 Prev_Par := Par;
14288 Par := Parent (Par);
14289 end loop;
14291 return False;
14292 end In_Return_Value;
14294 -----------------------------------------
14295 -- In_Statement_Condition_With_Actions --
14296 -----------------------------------------
14298 function In_Statement_Condition_With_Actions (N : Node_Id) return Boolean is
14299 Prev : Node_Id := N;
14300 P : Node_Id := Parent (N);
14301 -- P and Prev will be used for traversing the AST, while maintaining an
14302 -- invariant that P = Parent (Prev).
14303 begin
14304 while Present (P) loop
14305 if Nkind (P) = N_Iteration_Scheme
14306 and then Prev = Condition (P)
14307 then
14308 return True;
14310 elsif Nkind (P) = N_Elsif_Part
14311 and then Prev = Condition (P)
14312 then
14313 return True;
14315 -- No point in going beyond statements
14317 elsif Nkind (N) in N_Statement_Other_Than_Procedure_Call
14318 | N_Procedure_Call_Statement
14319 then
14320 exit;
14322 -- Prevent the search from going too far
14324 elsif Is_Body_Or_Package_Declaration (P) then
14325 exit;
14326 end if;
14328 Prev := P;
14329 P := Parent (P);
14330 end loop;
14332 return False;
14333 end In_Statement_Condition_With_Actions;
14335 ---------------------
14336 -- In_Visible_Part --
14337 ---------------------
14339 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
14340 begin
14341 return Is_Package_Or_Generic_Package (Scope_Id)
14342 and then In_Open_Scopes (Scope_Id)
14343 and then not In_Package_Body (Scope_Id)
14344 and then not In_Private_Part (Scope_Id);
14345 end In_Visible_Part;
14347 --------------------------------
14348 -- Incomplete_Or_Partial_View --
14349 --------------------------------
14351 function Incomplete_Or_Partial_View (Id : Entity_Id) return Entity_Id is
14352 S : constant Entity_Id := Scope (Id);
14354 function Inspect_Decls
14355 (Decls : List_Id;
14356 Taft : Boolean := False) return Entity_Id;
14357 -- Check whether a declarative region contains the incomplete or partial
14358 -- view of Id.
14360 -------------------
14361 -- Inspect_Decls --
14362 -------------------
14364 function Inspect_Decls
14365 (Decls : List_Id;
14366 Taft : Boolean := False) return Entity_Id
14368 Decl : Node_Id;
14369 Match : Node_Id;
14371 begin
14372 Decl := First (Decls);
14373 while Present (Decl) loop
14374 Match := Empty;
14376 -- The partial view of a Taft-amendment type is an incomplete
14377 -- type.
14379 if Taft then
14380 if Nkind (Decl) = N_Incomplete_Type_Declaration then
14381 Match := Defining_Identifier (Decl);
14382 end if;
14384 -- Otherwise look for a private type whose full view matches the
14385 -- input type. Note that this checks full_type_declaration nodes
14386 -- to account for derivations from a private type where the type
14387 -- declaration hold the partial view and the full view is an
14388 -- itype.
14390 elsif Nkind (Decl) in N_Full_Type_Declaration
14391 | N_Private_Extension_Declaration
14392 | N_Private_Type_Declaration
14393 then
14394 Match := Defining_Identifier (Decl);
14395 end if;
14397 -- Guard against unanalyzed entities
14399 if Present (Match)
14400 and then Is_Type (Match)
14401 and then Present (Full_View (Match))
14402 and then Full_View (Match) = Id
14403 then
14404 return Match;
14405 end if;
14407 Next (Decl);
14408 end loop;
14410 return Empty;
14411 end Inspect_Decls;
14413 -- Local variables
14415 Prev : Entity_Id;
14417 -- Start of processing for Incomplete_Or_Partial_View
14419 begin
14420 -- Deferred constant or incomplete type case
14422 Prev := Current_Entity (Id);
14424 while Present (Prev) loop
14425 exit when Scope (Prev) = S;
14427 Prev := Homonym (Prev);
14428 end loop;
14430 if Present (Prev)
14431 and then (Is_Incomplete_Type (Prev) or else Ekind (Prev) = E_Constant)
14432 and then Present (Full_View (Prev))
14433 and then Full_View (Prev) = Id
14434 then
14435 return Prev;
14436 end if;
14438 -- Private or Taft amendment type case
14440 if Present (S) and then Is_Package_Or_Generic_Package (S) then
14441 declare
14442 Pkg_Decl : constant Node_Id := Package_Specification (S);
14444 begin
14445 -- It is knows that Typ has a private view, look for it in the
14446 -- visible declarations of the enclosing scope. A special case
14447 -- of this is when the two views have been exchanged - the full
14448 -- appears earlier than the private.
14450 if Has_Private_Declaration (Id) then
14451 Prev := Inspect_Decls (Visible_Declarations (Pkg_Decl));
14453 -- Exchanged view case, look in the private declarations
14455 if No (Prev) then
14456 Prev := Inspect_Decls (Private_Declarations (Pkg_Decl));
14457 end if;
14459 return Prev;
14461 -- Otherwise if this is the package body, then Typ is a potential
14462 -- Taft amendment type. The incomplete view should be located in
14463 -- the private declarations of the enclosing scope.
14465 elsif In_Package_Body (S) then
14466 return Inspect_Decls (Private_Declarations (Pkg_Decl), True);
14467 end if;
14468 end;
14469 end if;
14471 -- The type has no incomplete or private view
14473 return Empty;
14474 end Incomplete_Or_Partial_View;
14476 ---------------------------------------
14477 -- Incomplete_View_From_Limited_With --
14478 ---------------------------------------
14480 function Incomplete_View_From_Limited_With
14481 (Typ : Entity_Id) return Entity_Id
14483 begin
14484 -- It might make sense to make this an attribute in Einfo, and set it
14485 -- in Sem_Ch10 in Build_Shadow_Entity. However, we're running short on
14486 -- slots for new attributes, and it seems a bit simpler to just search
14487 -- the Limited_View (if it exists) for an incomplete type whose
14488 -- Non_Limited_View is Typ.
14490 if Ekind (Scope (Typ)) = E_Package
14491 and then Present (Limited_View (Scope (Typ)))
14492 then
14493 declare
14494 Ent : Entity_Id := First_Entity (Limited_View (Scope (Typ)));
14495 begin
14496 while Present (Ent) loop
14497 if Is_Incomplete_Type (Ent)
14498 and then Non_Limited_View (Ent) = Typ
14499 then
14500 return Ent;
14501 end if;
14503 Next_Entity (Ent);
14504 end loop;
14505 end;
14506 end if;
14508 return Typ;
14509 end Incomplete_View_From_Limited_With;
14511 ----------------------------------
14512 -- Indexed_Component_Bit_Offset --
14513 ----------------------------------
14515 function Indexed_Component_Bit_Offset (N : Node_Id) return Uint is
14516 Exp : constant Node_Id := First (Expressions (N));
14517 Typ : constant Entity_Id := Etype (Prefix (N));
14518 Off : constant Uint := Component_Size (Typ);
14519 Ind : Node_Id;
14521 begin
14522 -- Return early if the component size is not known or variable
14524 if No (Off) or else Off < Uint_0 then
14525 return No_Uint;
14526 end if;
14528 -- Deal with the degenerate case of an empty component
14530 if Off = Uint_0 then
14531 return Off;
14532 end if;
14534 -- Check that both the index value and the low bound are known
14536 if not Compile_Time_Known_Value (Exp) then
14537 return No_Uint;
14538 end if;
14540 Ind := First_Index (Typ);
14541 if No (Ind) then
14542 return No_Uint;
14543 end if;
14545 -- Do not attempt to compute offsets within multi-dimensional arrays
14547 if Present (Next_Index (Ind)) then
14548 return No_Uint;
14549 end if;
14551 if Nkind (Ind) = N_Subtype_Indication then
14552 Ind := Constraint (Ind);
14554 if Nkind (Ind) = N_Range_Constraint then
14555 Ind := Range_Expression (Ind);
14556 end if;
14557 end if;
14559 if Nkind (Ind) /= N_Range
14560 or else not Compile_Time_Known_Value (Low_Bound (Ind))
14561 then
14562 return No_Uint;
14563 end if;
14565 -- Return the scaled offset
14567 return Off * (Expr_Value (Exp) - Expr_Value (Low_Bound (Ind)));
14568 end Indexed_Component_Bit_Offset;
14570 -----------------------------
14571 -- Inherit_Predicate_Flags --
14572 -----------------------------
14574 procedure Inherit_Predicate_Flags (Subt, Par : Entity_Id) is
14575 begin
14576 if Ada_Version < Ada_2012
14577 or else Present (Predicate_Function (Subt))
14578 then
14579 return;
14580 end if;
14582 Set_Has_Predicates (Subt, Has_Predicates (Par));
14583 Set_Has_Static_Predicate_Aspect
14584 (Subt, Has_Static_Predicate_Aspect (Par));
14585 Set_Has_Dynamic_Predicate_Aspect
14586 (Subt, Has_Dynamic_Predicate_Aspect (Par));
14588 -- A named subtype does not inherit the predicate function of its
14589 -- parent but an itype declared for a loop index needs the discrete
14590 -- predicate information of its parent to execute the loop properly.
14591 -- A non-discrete type may has a static predicate (for example True)
14592 -- but has no static_discrete_predicate.
14594 if Is_Itype (Subt) and then Present (Predicate_Function (Par)) then
14595 Set_Subprograms_For_Type (Subt, Subprograms_For_Type (Par));
14597 if Has_Static_Predicate (Par) and then Is_Discrete_Type (Par) then
14598 Set_Static_Discrete_Predicate
14599 (Subt, Static_Discrete_Predicate (Par));
14600 end if;
14601 end if;
14602 end Inherit_Predicate_Flags;
14604 ----------------------------
14605 -- Inherit_Rep_Item_Chain --
14606 ----------------------------
14608 procedure Inherit_Rep_Item_Chain (Typ : Entity_Id; From_Typ : Entity_Id) is
14609 Item : Node_Id;
14610 Next_Item : Node_Id;
14612 begin
14613 -- There are several inheritance scenarios to consider depending on
14614 -- whether both types have rep item chains and whether the destination
14615 -- type already inherits part of the source type's rep item chain.
14617 -- 1) The source type lacks a rep item chain
14618 -- From_Typ ---> Empty
14620 -- Typ --------> Item (or Empty)
14622 -- In this case inheritance cannot take place because there are no items
14623 -- to inherit.
14625 -- 2) The destination type lacks a rep item chain
14626 -- From_Typ ---> Item ---> ...
14628 -- Typ --------> Empty
14630 -- Inheritance takes place by setting the First_Rep_Item of the
14631 -- destination type to the First_Rep_Item of the source type.
14632 -- From_Typ ---> Item ---> ...
14633 -- ^
14634 -- Typ -----------+
14636 -- 3.1) Both source and destination types have at least one rep item.
14637 -- The destination type does NOT inherit a rep item from the source
14638 -- type.
14639 -- From_Typ ---> Item ---> Item
14641 -- Typ --------> Item ---> Item
14643 -- Inheritance takes place by setting the Next_Rep_Item of the last item
14644 -- of the destination type to the First_Rep_Item of the source type.
14645 -- From_Typ -------------------> Item ---> Item
14646 -- ^
14647 -- Typ --------> Item ---> Item --+
14649 -- 3.2) Both source and destination types have at least one rep item.
14650 -- The destination type DOES inherit part of the rep item chain of the
14651 -- source type.
14652 -- From_Typ ---> Item ---> Item ---> Item
14653 -- ^
14654 -- Typ --------> Item ------+
14656 -- This rare case arises when the full view of a private extension must
14657 -- inherit the rep item chain from the full view of its parent type and
14658 -- the full view of the parent type contains extra rep items. Currently
14659 -- only invariants may lead to such form of inheritance.
14661 -- type From_Typ is tagged private
14662 -- with Type_Invariant'Class => Item_2;
14664 -- type Typ is new From_Typ with private
14665 -- with Type_Invariant => Item_4;
14667 -- At this point the rep item chains contain the following items
14669 -- From_Typ -----------> Item_2 ---> Item_3
14670 -- ^
14671 -- Typ --------> Item_4 --+
14673 -- The full views of both types may introduce extra invariants
14675 -- type From_Typ is tagged null record
14676 -- with Type_Invariant => Item_1;
14678 -- type Typ is new From_Typ with null record;
14680 -- The full view of Typ would have to inherit any new rep items added to
14681 -- the full view of From_Typ.
14683 -- From_Typ -----------> Item_1 ---> Item_2 ---> Item_3
14684 -- ^
14685 -- Typ --------> Item_4 --+
14687 -- To achieve this form of inheritance, the destination type must first
14688 -- sever the link between its own rep chain and that of the source type,
14689 -- then inheritance 3.1 takes place.
14691 -- Case 1: The source type lacks a rep item chain
14693 if No (First_Rep_Item (From_Typ)) then
14694 return;
14696 -- Case 2: The destination type lacks a rep item chain
14698 elsif No (First_Rep_Item (Typ)) then
14699 Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ));
14701 -- Case 3: Both the source and destination types have at least one rep
14702 -- item. Traverse the rep item chain of the destination type to find the
14703 -- last rep item.
14705 else
14706 Item := Empty;
14707 Next_Item := First_Rep_Item (Typ);
14708 while Present (Next_Item) loop
14710 -- Detect a link between the destination type's rep chain and that
14711 -- of the source type. There are two possibilities:
14713 -- Variant 1
14714 -- Next_Item
14715 -- V
14716 -- From_Typ ---> Item_1 --->
14717 -- ^
14718 -- Typ -----------+
14720 -- Item is Empty
14722 -- Variant 2
14723 -- Next_Item
14724 -- V
14725 -- From_Typ ---> Item_1 ---> Item_2 --->
14726 -- ^
14727 -- Typ --------> Item_3 ------+
14728 -- ^
14729 -- Item
14731 if Present_In_Rep_Item (From_Typ, Next_Item) then
14732 exit;
14733 end if;
14735 Item := Next_Item;
14736 Next_Item := Next_Rep_Item (Next_Item);
14737 end loop;
14739 -- Inherit the source type's rep item chain
14741 if Present (Item) then
14742 Set_Next_Rep_Item (Item, First_Rep_Item (From_Typ));
14743 else
14744 Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ));
14745 end if;
14746 end if;
14747 end Inherit_Rep_Item_Chain;
14749 ------------------------------------
14750 -- Inherits_From_Tagged_Full_View --
14751 ------------------------------------
14753 function Inherits_From_Tagged_Full_View (Typ : Entity_Id) return Boolean is
14754 begin
14755 return Is_Private_Type (Typ)
14756 and then Present (Full_View (Typ))
14757 and then Is_Private_Type (Full_View (Typ))
14758 and then not Is_Tagged_Type (Full_View (Typ))
14759 and then Present (Underlying_Type (Full_View (Typ)))
14760 and then Is_Tagged_Type (Underlying_Type (Full_View (Typ)));
14761 end Inherits_From_Tagged_Full_View;
14763 ---------------------------------
14764 -- Insert_Explicit_Dereference --
14765 ---------------------------------
14767 procedure Insert_Explicit_Dereference (N : Node_Id) is
14768 New_Prefix : constant Node_Id := Relocate_Node (N);
14769 Ent : Entity_Id := Empty;
14770 Pref : Node_Id := Empty;
14771 I : Interp_Index;
14772 It : Interp;
14773 T : Entity_Id;
14775 begin
14776 Save_Interps (N, New_Prefix);
14778 Rewrite (N,
14779 Make_Explicit_Dereference (Sloc (Parent (N)),
14780 Prefix => New_Prefix));
14782 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
14784 if Is_Overloaded (New_Prefix) then
14786 -- The dereference is also overloaded, and its interpretations are
14787 -- the designated types of the interpretations of the original node.
14789 Set_Etype (N, Any_Type);
14791 Get_First_Interp (New_Prefix, I, It);
14792 while Present (It.Nam) loop
14793 T := It.Typ;
14795 if Is_Access_Type (T) then
14796 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
14797 end if;
14799 Get_Next_Interp (I, It);
14800 end loop;
14802 else
14803 -- Prefix is unambiguous: mark the original prefix (which might
14804 -- Come_From_Source) as a reference, since the new (relocated) one
14805 -- won't be taken into account.
14807 if Is_Entity_Name (New_Prefix) then
14808 Ent := Entity (New_Prefix);
14809 Pref := New_Prefix;
14811 -- For a retrieval of a subcomponent of some composite object,
14812 -- retrieve the ultimate entity if there is one.
14814 elsif Nkind (New_Prefix) in N_Selected_Component | N_Indexed_Component
14815 then
14816 Pref := Prefix (New_Prefix);
14817 while Present (Pref)
14818 and then Nkind (Pref) in
14819 N_Selected_Component | N_Indexed_Component
14820 loop
14821 Pref := Prefix (Pref);
14822 end loop;
14824 if Present (Pref) and then Is_Entity_Name (Pref) then
14825 Ent := Entity (Pref);
14826 end if;
14827 end if;
14829 -- Place the reference on the entity node
14831 if Present (Ent) then
14832 Generate_Reference (Ent, Pref);
14833 end if;
14834 end if;
14835 end Insert_Explicit_Dereference;
14837 ------------------------------------------
14838 -- Inspect_Deferred_Constant_Completion --
14839 ------------------------------------------
14841 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
14842 Decl : Node_Id;
14844 begin
14845 Decl := First (Decls);
14846 while Present (Decl) loop
14848 -- Deferred constant signature
14850 if Nkind (Decl) = N_Object_Declaration
14851 and then Constant_Present (Decl)
14852 and then No (Expression (Decl))
14854 -- No need to check internally generated constants
14856 and then Comes_From_Source (Decl)
14858 -- The constant is not completed. A full object declaration or a
14859 -- pragma Import complete a deferred constant.
14861 and then not Has_Completion (Defining_Identifier (Decl))
14862 then
14863 Error_Msg_N
14864 ("constant declaration requires initialization expression",
14865 Defining_Identifier (Decl));
14866 end if;
14868 Next (Decl);
14869 end loop;
14870 end Inspect_Deferred_Constant_Completion;
14872 -------------------------------
14873 -- Install_Elaboration_Model --
14874 -------------------------------
14876 procedure Install_Elaboration_Model (Unit_Id : Entity_Id) is
14877 function Find_Elaboration_Checks_Pragma (L : List_Id) return Node_Id;
14878 -- Try to find pragma Elaboration_Checks in arbitrary list L. Return
14879 -- Empty if there is no such pragma.
14881 ------------------------------------
14882 -- Find_Elaboration_Checks_Pragma --
14883 ------------------------------------
14885 function Find_Elaboration_Checks_Pragma (L : List_Id) return Node_Id is
14886 Item : Node_Id;
14888 begin
14889 Item := First (L);
14890 while Present (Item) loop
14891 if Nkind (Item) = N_Pragma
14892 and then Pragma_Name (Item) = Name_Elaboration_Checks
14893 then
14894 return Item;
14895 end if;
14897 Next (Item);
14898 end loop;
14900 return Empty;
14901 end Find_Elaboration_Checks_Pragma;
14903 -- Local variables
14905 Args : List_Id;
14906 Model : Node_Id;
14907 Prag : Node_Id;
14908 Unit : Node_Id;
14910 -- Start of processing for Install_Elaboration_Model
14912 begin
14913 -- Nothing to do when the unit does not exist
14915 if No (Unit_Id) then
14916 return;
14917 end if;
14919 Unit := Parent (Unit_Declaration_Node (Unit_Id));
14921 -- Nothing to do when the unit is not a library unit
14923 if Nkind (Unit) /= N_Compilation_Unit then
14924 return;
14925 end if;
14927 Prag := Find_Elaboration_Checks_Pragma (Context_Items (Unit));
14929 -- The compilation unit is subject to pragma Elaboration_Checks. Set the
14930 -- elaboration model as specified by the pragma.
14932 if Present (Prag) then
14933 Args := Pragma_Argument_Associations (Prag);
14935 -- Guard against an illegal pragma. The sole argument must be an
14936 -- identifier which specifies either Dynamic or Static model.
14938 if Present (Args) then
14939 Model := Get_Pragma_Arg (First (Args));
14941 if Nkind (Model) = N_Identifier then
14942 Dynamic_Elaboration_Checks := Chars (Model) = Name_Dynamic;
14943 end if;
14944 end if;
14945 end if;
14946 end Install_Elaboration_Model;
14948 -----------------------------
14949 -- Install_Generic_Formals --
14950 -----------------------------
14952 procedure Install_Generic_Formals (Subp_Id : Entity_Id) is
14953 E : Entity_Id;
14955 begin
14956 pragma Assert (Is_Generic_Subprogram (Subp_Id));
14958 E := First_Entity (Subp_Id);
14959 while Present (E) loop
14960 Install_Entity (E);
14961 Next_Entity (E);
14962 end loop;
14963 end Install_Generic_Formals;
14965 ------------------------
14966 -- Install_SPARK_Mode --
14967 ------------------------
14969 procedure Install_SPARK_Mode (Mode : SPARK_Mode_Type; Prag : Node_Id) is
14970 begin
14971 SPARK_Mode := Mode;
14972 SPARK_Mode_Pragma := Prag;
14973 end Install_SPARK_Mode;
14975 --------------------------
14976 -- Invalid_Scalar_Value --
14977 --------------------------
14979 function Invalid_Scalar_Value
14980 (Loc : Source_Ptr;
14981 Scal_Typ : Scalar_Id) return Node_Id
14983 function Invalid_Binder_Value return Node_Id;
14984 -- Return a reference to the corresponding invalid value for type
14985 -- Scal_Typ as defined in unit System.Scalar_Values.
14987 function Invalid_Float_Value return Node_Id;
14988 -- Return the invalid value of float type Scal_Typ
14990 function Invalid_Integer_Value return Node_Id;
14991 -- Return the invalid value of integer type Scal_Typ
14993 procedure Set_Invalid_Binder_Values;
14994 -- Set the contents of collection Invalid_Binder_Values
14996 --------------------------
14997 -- Invalid_Binder_Value --
14998 --------------------------
15000 function Invalid_Binder_Value return Node_Id is
15001 Val_Id : Entity_Id;
15003 begin
15004 -- Initialize the collection of invalid binder values the first time
15005 -- around.
15007 Set_Invalid_Binder_Values;
15009 -- Obtain the corresponding variable from System.Scalar_Values which
15010 -- holds the invalid value for this type.
15012 Val_Id := Invalid_Binder_Values (Scal_Typ);
15013 pragma Assert (Present (Val_Id));
15015 return New_Occurrence_Of (Val_Id, Loc);
15016 end Invalid_Binder_Value;
15018 -------------------------
15019 -- Invalid_Float_Value --
15020 -------------------------
15022 function Invalid_Float_Value return Node_Id is
15023 Value : constant Ureal := Invalid_Floats (Scal_Typ);
15025 begin
15026 -- Pragma Invalid_Scalars did not specify an invalid value for this
15027 -- type. Fall back to the value provided by the binder.
15029 if Value = No_Ureal then
15030 return Invalid_Binder_Value;
15031 else
15032 return Make_Real_Literal (Loc, Realval => Value);
15033 end if;
15034 end Invalid_Float_Value;
15036 ---------------------------
15037 -- Invalid_Integer_Value --
15038 ---------------------------
15040 function Invalid_Integer_Value return Node_Id is
15041 Value : constant Uint := Invalid_Integers (Scal_Typ);
15043 begin
15044 -- Pragma Invalid_Scalars did not specify an invalid value for this
15045 -- type. Fall back to the value provided by the binder.
15047 if No (Value) then
15048 return Invalid_Binder_Value;
15049 else
15050 return Make_Integer_Literal (Loc, Intval => Value);
15051 end if;
15052 end Invalid_Integer_Value;
15054 -------------------------------
15055 -- Set_Invalid_Binder_Values --
15056 -------------------------------
15058 procedure Set_Invalid_Binder_Values is
15059 begin
15060 if not Invalid_Binder_Values_Set then
15061 Invalid_Binder_Values_Set := True;
15063 -- Initialize the contents of the collection once since RTE calls
15064 -- are not cheap.
15066 Invalid_Binder_Values :=
15067 (Name_Short_Float => RTE (RE_IS_Isf),
15068 Name_Float => RTE (RE_IS_Ifl),
15069 Name_Long_Float => RTE (RE_IS_Ilf),
15070 Name_Long_Long_Float => RTE (RE_IS_Ill),
15071 Name_Signed_8 => RTE (RE_IS_Is1),
15072 Name_Signed_16 => RTE (RE_IS_Is2),
15073 Name_Signed_32 => RTE (RE_IS_Is4),
15074 Name_Signed_64 => RTE (RE_IS_Is8),
15075 Name_Signed_128 => Empty,
15076 Name_Unsigned_8 => RTE (RE_IS_Iu1),
15077 Name_Unsigned_16 => RTE (RE_IS_Iu2),
15078 Name_Unsigned_32 => RTE (RE_IS_Iu4),
15079 Name_Unsigned_64 => RTE (RE_IS_Iu8),
15080 Name_Unsigned_128 => Empty);
15082 if System_Max_Integer_Size < 128 then
15083 Invalid_Binder_Values (Name_Signed_128) := RTE (RE_IS_Is8);
15084 Invalid_Binder_Values (Name_Unsigned_128) := RTE (RE_IS_Iu8);
15085 else
15086 Invalid_Binder_Values (Name_Signed_128) := RTE (RE_IS_Is16);
15087 Invalid_Binder_Values (Name_Unsigned_128) := RTE (RE_IS_Iu16);
15088 end if;
15089 end if;
15090 end Set_Invalid_Binder_Values;
15092 -- Start of processing for Invalid_Scalar_Value
15094 begin
15095 if Scal_Typ in Float_Scalar_Id then
15096 return Invalid_Float_Value;
15098 else pragma Assert (Scal_Typ in Integer_Scalar_Id);
15099 return Invalid_Integer_Value;
15100 end if;
15101 end Invalid_Scalar_Value;
15103 ------------------------
15104 -- Is_Access_Variable --
15105 ------------------------
15107 function Is_Access_Variable (E : Entity_Id) return Boolean is
15108 begin
15109 return Is_Access_Type (E)
15110 and then not Is_Access_Constant (E)
15111 and then Ekind (Directly_Designated_Type (E)) /= E_Subprogram_Type;
15112 end Is_Access_Variable;
15114 -----------------------------
15115 -- Is_Actual_Out_Parameter --
15116 -----------------------------
15118 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
15119 Formal : Entity_Id;
15120 Call : Node_Id;
15121 begin
15122 Find_Actual (N, Formal, Call);
15123 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
15124 end Is_Actual_Out_Parameter;
15126 --------------------------------
15127 -- Is_Actual_In_Out_Parameter --
15128 --------------------------------
15130 function Is_Actual_In_Out_Parameter (N : Node_Id) return Boolean is
15131 Formal : Entity_Id;
15132 Call : Node_Id;
15133 begin
15134 Find_Actual (N, Formal, Call);
15135 return Present (Formal) and then Ekind (Formal) = E_In_Out_Parameter;
15136 end Is_Actual_In_Out_Parameter;
15138 ---------------------------------------
15139 -- Is_Actual_Out_Or_In_Out_Parameter --
15140 ---------------------------------------
15142 function Is_Actual_Out_Or_In_Out_Parameter (N : Node_Id) return Boolean is
15143 Formal : Entity_Id;
15144 Call : Node_Id;
15145 begin
15146 Find_Actual (N, Formal, Call);
15147 return Present (Formal)
15148 and then Ekind (Formal) in E_Out_Parameter | E_In_Out_Parameter;
15149 end Is_Actual_Out_Or_In_Out_Parameter;
15151 -------------------------
15152 -- Is_Actual_Parameter --
15153 -------------------------
15155 function Is_Actual_Parameter (N : Node_Id) return Boolean is
15156 PK : constant Node_Kind := Nkind (Parent (N));
15158 begin
15159 case PK is
15160 when N_Parameter_Association =>
15161 return N = Explicit_Actual_Parameter (Parent (N));
15163 when N_Entry_Call_Statement
15164 | N_Subprogram_Call
15166 return Is_List_Member (N)
15167 and then
15168 List_Containing (N) = Parameter_Associations (Parent (N));
15170 when others =>
15171 return False;
15172 end case;
15173 end Is_Actual_Parameter;
15175 --------------------------------
15176 -- Is_Actual_Tagged_Parameter --
15177 --------------------------------
15179 function Is_Actual_Tagged_Parameter (N : Node_Id) return Boolean is
15180 Formal : Entity_Id;
15181 Call : Node_Id;
15182 begin
15183 Find_Actual (N, Formal, Call);
15184 return Present (Formal) and then Is_Tagged_Type (Etype (Formal));
15185 end Is_Actual_Tagged_Parameter;
15187 ---------------------
15188 -- Is_Aliased_View --
15189 ---------------------
15191 function Is_Aliased_View (Obj : Node_Id) return Boolean is
15192 E : Entity_Id;
15194 begin
15195 if Is_Entity_Name (Obj) then
15196 E := Entity (Obj);
15198 return
15199 (Is_Object (E)
15200 and then
15201 (Is_Aliased (E)
15202 or else (Present (Renamed_Object (E))
15203 and then Is_Aliased_View (Renamed_Object (E)))))
15205 or else ((Is_Formal (E) or else Is_Formal_Object (E))
15206 and then Is_Tagged_Type (Etype (E)))
15208 or else (Is_Concurrent_Type (E) and then In_Open_Scopes (E))
15210 -- Current instance of type, either directly or as rewritten
15211 -- reference to the current object.
15213 or else (Is_Entity_Name (Original_Node (Obj))
15214 and then Present (Entity (Original_Node (Obj)))
15215 and then Is_Type (Entity (Original_Node (Obj))))
15217 or else (Is_Type (E) and then E = Current_Scope)
15219 or else (Is_Incomplete_Or_Private_Type (E)
15220 and then Full_View (E) = Current_Scope)
15222 -- Ada 2012 AI05-0053: the return object of an extended return
15223 -- statement is aliased if its type is immutably limited.
15225 or else (Is_Return_Object (E)
15226 and then Is_Limited_View (Etype (E)))
15228 -- The current instance of a limited type is aliased, so
15229 -- we want to allow uses of T'Access in the init proc for
15230 -- a limited type T. However, we don't want to mark the formal
15231 -- parameter as being aliased since that could impact callers.
15233 or else (Is_Formal (E)
15234 and then Chars (E) = Name_uInit
15235 and then Is_Limited_View (Etype (E)));
15237 elsif Nkind (Obj) = N_Selected_Component then
15238 return Is_Aliased (Entity (Selector_Name (Obj)));
15240 elsif Nkind (Obj) = N_Indexed_Component then
15241 return Has_Aliased_Components (Etype (Prefix (Obj)))
15242 or else
15243 (Is_Access_Type (Etype (Prefix (Obj)))
15244 and then Has_Aliased_Components
15245 (Designated_Type (Etype (Prefix (Obj)))));
15247 elsif Nkind (Obj) in N_Unchecked_Type_Conversion | N_Type_Conversion then
15248 return Is_Tagged_Type (Etype (Obj))
15249 and then Is_Aliased_View (Expression (Obj));
15251 -- Ada 2022 AI12-0228
15253 elsif Nkind (Obj) = N_Qualified_Expression
15254 and then Ada_Version >= Ada_2012
15255 then
15256 return Is_Aliased_View (Expression (Obj));
15258 elsif Nkind (Obj) = N_Explicit_Dereference then
15259 return Nkind (Original_Node (Obj)) /= N_Function_Call;
15261 else
15262 return False;
15263 end if;
15264 end Is_Aliased_View;
15266 -------------------------
15267 -- Is_Ancestor_Package --
15268 -------------------------
15270 function Is_Ancestor_Package
15271 (E1 : Entity_Id;
15272 E2 : Entity_Id) return Boolean
15274 Par : Entity_Id;
15276 begin
15277 Par := E2;
15278 while Present (Par) and then Par /= Standard_Standard loop
15279 if Par = E1 then
15280 return True;
15281 end if;
15283 Par := Scope (Par);
15284 end loop;
15286 return False;
15287 end Is_Ancestor_Package;
15289 ----------------------
15290 -- Is_Atomic_Object --
15291 ----------------------
15293 function Is_Atomic_Object (N : Node_Id) return Boolean is
15294 function Prefix_Has_Atomic_Components (P : Node_Id) return Boolean;
15295 -- Determine whether prefix P has atomic components. This requires the
15296 -- presence of an Atomic_Components aspect/pragma.
15298 ---------------------------------
15299 -- Prefix_Has_Atomic_Components --
15300 ---------------------------------
15302 function Prefix_Has_Atomic_Components (P : Node_Id) return Boolean is
15303 Typ : constant Entity_Id := Etype (P);
15305 begin
15306 if Is_Access_Type (Typ) then
15307 return Has_Atomic_Components (Designated_Type (Typ));
15309 elsif Has_Atomic_Components (Typ) then
15310 return True;
15312 elsif Is_Entity_Name (P)
15313 and then Has_Atomic_Components (Entity (P))
15314 then
15315 return True;
15317 else
15318 return False;
15319 end if;
15320 end Prefix_Has_Atomic_Components;
15322 -- Start of processing for Is_Atomic_Object
15324 begin
15325 if Is_Entity_Name (N) then
15326 return Is_Atomic_Object_Entity (Entity (N));
15328 elsif Is_Atomic (Etype (N)) then
15329 return True;
15331 elsif Nkind (N) = N_Indexed_Component then
15332 return Prefix_Has_Atomic_Components (Prefix (N));
15334 elsif Nkind (N) = N_Selected_Component then
15335 return Is_Atomic (Entity (Selector_Name (N)));
15337 else
15338 return False;
15339 end if;
15340 end Is_Atomic_Object;
15342 -----------------------------
15343 -- Is_Atomic_Object_Entity --
15344 -----------------------------
15346 function Is_Atomic_Object_Entity (Id : Entity_Id) return Boolean is
15347 begin
15348 return
15349 Is_Object (Id)
15350 and then (Is_Atomic (Id) or else Is_Atomic (Etype (Id)));
15351 end Is_Atomic_Object_Entity;
15353 -----------------------------
15354 -- Is_Attribute_Loop_Entry --
15355 -----------------------------
15357 function Is_Attribute_Loop_Entry (N : Node_Id) return Boolean is
15358 begin
15359 return Nkind (N) = N_Attribute_Reference
15360 and then Attribute_Name (N) = Name_Loop_Entry;
15361 end Is_Attribute_Loop_Entry;
15363 ----------------------
15364 -- Is_Attribute_Old --
15365 ----------------------
15367 function Is_Attribute_Old (N : Node_Id) return Boolean is
15368 begin
15369 return Nkind (N) = N_Attribute_Reference
15370 and then Attribute_Name (N) = Name_Old;
15371 end Is_Attribute_Old;
15373 -------------------------
15374 -- Is_Attribute_Result --
15375 -------------------------
15377 function Is_Attribute_Result (N : Node_Id) return Boolean is
15378 begin
15379 return Nkind (N) = N_Attribute_Reference
15380 and then Attribute_Name (N) = Name_Result;
15381 end Is_Attribute_Result;
15383 -------------------------
15384 -- Is_Attribute_Update --
15385 -------------------------
15387 function Is_Attribute_Update (N : Node_Id) return Boolean is
15388 begin
15389 return Nkind (N) = N_Attribute_Reference
15390 and then Attribute_Name (N) = Name_Update;
15391 end Is_Attribute_Update;
15393 ------------------------------------
15394 -- Is_Body_Or_Package_Declaration --
15395 ------------------------------------
15397 function Is_Body_Or_Package_Declaration (N : Node_Id) return Boolean is
15398 begin
15399 return Is_Body (N) or else Nkind (N) = N_Package_Declaration;
15400 end Is_Body_Or_Package_Declaration;
15402 -----------------------
15403 -- Is_Bounded_String --
15404 -----------------------
15406 function Is_Bounded_String (T : Entity_Id) return Boolean is
15407 Under : constant Entity_Id := Underlying_Type (Root_Type (T));
15409 begin
15410 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
15411 -- Super_String, or one of the [Wide_]Wide_ versions. This will
15412 -- be True for all the Bounded_String types in instances of the
15413 -- Generic_Bounded_Length generics, and for types derived from those.
15415 return Present (Under)
15416 and then (Is_RTE (Root_Type (Under), RO_SU_Super_String) or else
15417 Is_RTE (Root_Type (Under), RO_WI_Super_String) or else
15418 Is_RTE (Root_Type (Under), RO_WW_Super_String));
15419 end Is_Bounded_String;
15421 -------------------------------
15422 -- Is_By_Protected_Procedure --
15423 -------------------------------
15425 function Is_By_Protected_Procedure (Id : Entity_Id) return Boolean is
15426 begin
15427 return Ekind (Id) = E_Procedure
15428 and then Present (Get_Rep_Pragma (Id, Name_Implemented))
15429 and then Implementation_Kind (Id) = Name_By_Protected_Procedure;
15430 end Is_By_Protected_Procedure;
15432 ---------------------
15433 -- Is_CCT_Instance --
15434 ---------------------
15436 function Is_CCT_Instance
15437 (Ref_Id : Entity_Id;
15438 Context_Id : Entity_Id) return Boolean
15440 begin
15441 pragma Assert (Ekind (Ref_Id) in E_Protected_Type | E_Task_Type);
15443 if Is_Single_Task_Object (Context_Id) then
15444 return Scope_Within_Or_Same (Etype (Context_Id), Ref_Id);
15446 else
15447 pragma Assert
15448 (Ekind (Context_Id) in
15449 E_Entry | E_Entry_Family | E_Function | E_Package |
15450 E_Procedure | E_Protected_Type | E_Task_Type
15451 or else Is_Record_Type (Context_Id));
15452 return Scope_Within_Or_Same (Context_Id, Ref_Id);
15453 end if;
15454 end Is_CCT_Instance;
15456 -------------------------
15457 -- Is_Child_Or_Sibling --
15458 -------------------------
15460 function Is_Child_Or_Sibling
15461 (Pack_1 : Entity_Id;
15462 Pack_2 : Entity_Id) return Boolean
15464 function Distance_From_Standard (Pack : Entity_Id) return Nat;
15465 -- Given an arbitrary package, return the number of "climbs" necessary
15466 -- to reach scope Standard_Standard.
15468 procedure Equalize_Depths
15469 (Pack : in out Entity_Id;
15470 Depth : in out Nat;
15471 Depth_To_Reach : Nat);
15472 -- Given an arbitrary package, its depth and a target depth to reach,
15473 -- climb the scope chain until the said depth is reached. The pointer
15474 -- to the package and its depth a modified during the climb.
15476 ----------------------------
15477 -- Distance_From_Standard --
15478 ----------------------------
15480 function Distance_From_Standard (Pack : Entity_Id) return Nat is
15481 Dist : Nat;
15482 Scop : Entity_Id;
15484 begin
15485 Dist := 0;
15486 Scop := Pack;
15487 while Present (Scop) and then Scop /= Standard_Standard loop
15488 Dist := Dist + 1;
15489 Scop := Scope (Scop);
15490 end loop;
15492 return Dist;
15493 end Distance_From_Standard;
15495 ---------------------
15496 -- Equalize_Depths --
15497 ---------------------
15499 procedure Equalize_Depths
15500 (Pack : in out Entity_Id;
15501 Depth : in out Nat;
15502 Depth_To_Reach : Nat)
15504 begin
15505 -- The package must be at a greater or equal depth
15507 if Depth < Depth_To_Reach then
15508 raise Program_Error;
15509 end if;
15511 -- Climb the scope chain until the desired depth is reached
15513 while Present (Pack) and then Depth /= Depth_To_Reach loop
15514 Pack := Scope (Pack);
15515 Depth := Depth - 1;
15516 end loop;
15517 end Equalize_Depths;
15519 -- Local variables
15521 P_1 : Entity_Id := Pack_1;
15522 P_1_Child : Boolean := False;
15523 P_1_Depth : Nat := Distance_From_Standard (P_1);
15524 P_2 : Entity_Id := Pack_2;
15525 P_2_Child : Boolean := False;
15526 P_2_Depth : Nat := Distance_From_Standard (P_2);
15528 -- Start of processing for Is_Child_Or_Sibling
15530 begin
15531 pragma Assert
15532 (Ekind (Pack_1) = E_Package and then Ekind (Pack_2) = E_Package);
15534 -- Both packages denote the same entity, therefore they cannot be
15535 -- children or siblings.
15537 if P_1 = P_2 then
15538 return False;
15540 -- One of the packages is at a deeper level than the other. Note that
15541 -- both may still come from different hierarchies.
15543 -- (root) P_2
15544 -- / \ :
15545 -- X P_2 or X
15546 -- : :
15547 -- P_1 P_1
15549 elsif P_1_Depth > P_2_Depth then
15550 Equalize_Depths
15551 (Pack => P_1,
15552 Depth => P_1_Depth,
15553 Depth_To_Reach => P_2_Depth);
15554 P_1_Child := True;
15556 -- (root) P_1
15557 -- / \ :
15558 -- P_1 X or X
15559 -- : :
15560 -- P_2 P_2
15562 elsif P_2_Depth > P_1_Depth then
15563 Equalize_Depths
15564 (Pack => P_2,
15565 Depth => P_2_Depth,
15566 Depth_To_Reach => P_1_Depth);
15567 P_2_Child := True;
15568 end if;
15570 -- At this stage the package pointers have been elevated to the same
15571 -- depth. If the related entities are the same, then one package is a
15572 -- potential child of the other:
15574 -- P_1
15575 -- :
15576 -- X became P_1 P_2 or vice versa
15577 -- :
15578 -- P_2
15580 if P_1 = P_2 then
15581 if P_1_Child then
15582 return Is_Child_Unit (Pack_1);
15584 else pragma Assert (P_2_Child);
15585 return Is_Child_Unit (Pack_2);
15586 end if;
15588 -- The packages may come from the same package chain or from entirely
15589 -- different hierarchies. To determine this, climb the scope stack until
15590 -- a common root is found.
15592 -- (root) (root 1) (root 2)
15593 -- / \ | |
15594 -- P_1 P_2 P_1 P_2
15596 else
15597 while Present (P_1) and then Present (P_2) loop
15599 -- The two packages may be siblings
15601 if P_1 = P_2 then
15602 return Is_Child_Unit (Pack_1) and then Is_Child_Unit (Pack_2);
15603 end if;
15605 P_1 := Scope (P_1);
15606 P_2 := Scope (P_2);
15607 end loop;
15608 end if;
15610 return False;
15611 end Is_Child_Or_Sibling;
15613 -------------------
15614 -- Is_Confirming --
15615 -------------------
15617 function Is_Confirming (Aspect : Nonoverridable_Aspect_Id;
15618 Aspect_Spec_1, Aspect_Spec_2 : Node_Id)
15619 return Boolean is
15620 function Names_Match (Nm1, Nm2 : Node_Id) return Boolean;
15622 -----------------
15623 -- Names_Match --
15624 -----------------
15626 function Names_Match (Nm1, Nm2 : Node_Id) return Boolean is
15627 begin
15628 if Nkind (Nm1) /= Nkind (Nm2) then
15629 return False;
15630 -- This may be too restrictive given that visibility
15631 -- may allow an identifier in one case and an expanded
15632 -- name in the other.
15633 end if;
15634 case Nkind (Nm1) is
15635 when N_Identifier =>
15636 return Name_Equals (Chars (Nm1), Chars (Nm2));
15638 when N_Expanded_Name =>
15639 -- An inherited operation has the same name as its
15640 -- ancestor, but they may have different scopes.
15641 -- This may be too permissive for Iterator_Element, which
15642 -- is intended to be identical in parent and derived type.
15644 return Names_Match (Selector_Name (Nm1),
15645 Selector_Name (Nm2));
15647 when N_Empty =>
15648 return True; -- needed for Aggregate aspect checking
15650 when others =>
15651 -- e.g., 'Class attribute references
15652 if Is_Entity_Name (Nm1) and Is_Entity_Name (Nm2) then
15653 return Entity (Nm1) = Entity (Nm2);
15654 end if;
15656 raise Program_Error;
15657 end case;
15658 end Names_Match;
15659 begin
15660 -- allow users to disable "shall be confirming" check, at least for now
15661 if Relaxed_RM_Semantics then
15662 return True;
15663 end if;
15665 -- ??? Type conversion here (along with "when others =>" below) is a
15666 -- workaround for a bootstrapping problem related to casing on a
15667 -- static-predicate-bearing subtype.
15669 case Aspect_Id (Aspect) is
15670 -- name-valued aspects; compare text of names, not resolution.
15671 when Aspect_Default_Iterator
15672 | Aspect_Iterator_Element
15673 | Aspect_Constant_Indexing
15674 | Aspect_Variable_Indexing =>
15675 declare
15676 Item_1 : constant Node_Id := Aspect_Rep_Item (Aspect_Spec_1);
15677 Item_2 : constant Node_Id := Aspect_Rep_Item (Aspect_Spec_2);
15678 begin
15679 if (Nkind (Item_1) /= N_Attribute_Definition_Clause)
15680 or (Nkind (Item_2) /= N_Attribute_Definition_Clause)
15681 then
15682 pragma Assert (Serious_Errors_Detected > 0);
15683 return True;
15684 end if;
15686 return Names_Match (Expression (Item_1),
15687 Expression (Item_2));
15688 end;
15690 -- A confirming aspect for Implicit_Derenfence on a derived type
15691 -- has already been checked in Analyze_Aspect_Implicit_Dereference,
15692 -- including the presence of renamed discriminants.
15694 when Aspect_Implicit_Dereference =>
15695 return True;
15697 -- one of a kind
15698 when Aspect_Aggregate =>
15699 declare
15700 Empty_1,
15701 Add_Named_1,
15702 Add_Unnamed_1,
15703 New_Indexed_1,
15704 Assign_Indexed_1,
15705 Empty_2,
15706 Add_Named_2,
15707 Add_Unnamed_2,
15708 New_Indexed_2,
15709 Assign_Indexed_2 : Node_Id := Empty;
15710 begin
15711 Parse_Aspect_Aggregate
15712 (N => Expression (Aspect_Spec_1),
15713 Empty_Subp => Empty_1,
15714 Add_Named_Subp => Add_Named_1,
15715 Add_Unnamed_Subp => Add_Unnamed_1,
15716 New_Indexed_Subp => New_Indexed_1,
15717 Assign_Indexed_Subp => Assign_Indexed_1);
15718 Parse_Aspect_Aggregate
15719 (N => Expression (Aspect_Spec_2),
15720 Empty_Subp => Empty_2,
15721 Add_Named_Subp => Add_Named_2,
15722 Add_Unnamed_Subp => Add_Unnamed_2,
15723 New_Indexed_Subp => New_Indexed_2,
15724 Assign_Indexed_Subp => Assign_Indexed_2);
15725 return
15726 Names_Match (Empty_1, Empty_2) and then
15727 Names_Match (Add_Named_1, Add_Named_2) and then
15728 Names_Match (Add_Unnamed_1, Add_Unnamed_2) and then
15729 Names_Match (New_Indexed_1, New_Indexed_2) and then
15730 Names_Match (Assign_Indexed_1, Assign_Indexed_2);
15731 end;
15733 -- Checking for this aspect is performed elsewhere during freezing
15734 when Aspect_No_Controlled_Parts =>
15735 return True;
15737 -- scalar-valued aspects; compare (static) values.
15738 when Aspect_Max_Entry_Queue_Length =>
15739 -- This should be unreachable. Max_Entry_Queue_Length is
15740 -- supported only for protected entries, not for types.
15741 pragma Assert (Serious_Errors_Detected /= 0);
15742 return True;
15744 when others =>
15745 raise Program_Error;
15746 end case;
15747 end Is_Confirming;
15749 -----------------------------
15750 -- Is_Concurrent_Interface --
15751 -----------------------------
15753 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
15754 begin
15755 return Is_Protected_Interface (T)
15756 or else Is_Synchronized_Interface (T)
15757 or else Is_Task_Interface (T);
15758 end Is_Concurrent_Interface;
15760 ------------------------------------------------------
15761 -- Is_Conjunction_Of_Formal_Preelab_Init_Attributes --
15762 ------------------------------------------------------
15764 function Is_Conjunction_Of_Formal_Preelab_Init_Attributes
15765 (Expr : Node_Id) return Boolean
15768 function Is_Formal_Preelab_Init_Attribute
15769 (N : Node_Id) return Boolean;
15770 -- Returns True if N is a Preelaborable_Initialization attribute
15771 -- applied to a generic formal type, or N's Original_Node is such
15772 -- an attribute.
15774 --------------------------------------
15775 -- Is_Formal_Preelab_Init_Attribute --
15776 --------------------------------------
15778 function Is_Formal_Preelab_Init_Attribute
15779 (N : Node_Id) return Boolean
15781 Orig_N : constant Node_Id := Original_Node (N);
15783 begin
15784 return Nkind (Orig_N) = N_Attribute_Reference
15785 and then Attribute_Name (Orig_N) = Name_Preelaborable_Initialization
15786 and then Is_Entity_Name (Prefix (Orig_N))
15787 and then Is_Generic_Type (Entity (Prefix (Orig_N)));
15788 end Is_Formal_Preelab_Init_Attribute;
15790 -- Start of Is_Conjunction_Of_Formal_Preelab_Init_Attributes
15792 begin
15793 return Is_Formal_Preelab_Init_Attribute (Expr)
15794 or else (Nkind (Expr) = N_Op_And
15795 and then
15796 Is_Conjunction_Of_Formal_Preelab_Init_Attributes
15797 (Left_Opnd (Expr))
15798 and then
15799 Is_Conjunction_Of_Formal_Preelab_Init_Attributes
15800 (Right_Opnd (Expr)));
15801 end Is_Conjunction_Of_Formal_Preelab_Init_Attributes;
15803 -----------------------
15804 -- Is_Constant_Bound --
15805 -----------------------
15807 function Is_Constant_Bound (Exp : Node_Id) return Boolean is
15808 begin
15809 if Compile_Time_Known_Value (Exp) then
15810 return True;
15812 elsif Is_Entity_Name (Exp) and then Present (Entity (Exp)) then
15813 return Is_Constant_Object (Entity (Exp))
15814 or else Ekind (Entity (Exp)) = E_Enumeration_Literal;
15816 elsif Nkind (Exp) in N_Binary_Op then
15817 return Is_Constant_Bound (Left_Opnd (Exp))
15818 and then Is_Constant_Bound (Right_Opnd (Exp))
15819 and then Scope (Entity (Exp)) = Standard_Standard;
15821 else
15822 return False;
15823 end if;
15824 end Is_Constant_Bound;
15826 ---------------------------
15827 -- Is_Container_Element --
15828 ---------------------------
15830 function Is_Container_Element (Exp : Node_Id) return Boolean is
15831 Loc : constant Source_Ptr := Sloc (Exp);
15832 Pref : constant Node_Id := Prefix (Exp);
15834 Call : Node_Id;
15835 -- Call to an indexing aspect
15837 Cont_Typ : Entity_Id;
15838 -- The type of the container being accessed
15840 Elem_Typ : Entity_Id;
15841 -- Its element type
15843 Indexing : Entity_Id;
15844 Is_Const : Boolean;
15845 -- Indicates that constant indexing is used, and the element is thus
15846 -- a constant.
15848 Ref_Typ : Entity_Id;
15849 -- The reference type returned by the indexing operation
15851 begin
15852 -- If C is a container, in a context that imposes the element type of
15853 -- that container, the indexing notation C (X) is rewritten as:
15855 -- Indexing (C, X).Discr.all
15857 -- where Indexing is one of the indexing aspects of the container.
15858 -- If the context does not require a reference, the construct can be
15859 -- rewritten as
15861 -- Element (C, X)
15863 -- First, verify that the construct has the proper form
15865 if not Expander_Active then
15866 return False;
15868 elsif Nkind (Pref) /= N_Selected_Component then
15869 return False;
15871 elsif Nkind (Prefix (Pref)) /= N_Function_Call then
15872 return False;
15874 else
15875 Call := Prefix (Pref);
15876 Ref_Typ := Etype (Call);
15877 end if;
15879 if not Has_Implicit_Dereference (Ref_Typ)
15880 or else No (First (Parameter_Associations (Call)))
15881 or else not Is_Entity_Name (Name (Call))
15882 then
15883 return False;
15884 end if;
15886 -- Retrieve type of container object, and its iterator aspects
15888 Cont_Typ := Etype (First (Parameter_Associations (Call)));
15889 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Constant_Indexing);
15890 Is_Const := False;
15892 if No (Indexing) then
15894 -- Container should have at least one indexing operation
15896 return False;
15898 elsif Entity (Name (Call)) /= Entity (Indexing) then
15900 -- This may be a variable indexing operation
15902 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Variable_Indexing);
15904 if No (Indexing)
15905 or else Entity (Name (Call)) /= Entity (Indexing)
15906 then
15907 return False;
15908 end if;
15910 else
15911 Is_Const := True;
15912 end if;
15914 Elem_Typ := Find_Value_Of_Aspect (Cont_Typ, Aspect_Iterator_Element);
15916 if No (Elem_Typ) or else Entity (Elem_Typ) /= Etype (Exp) then
15917 return False;
15918 end if;
15920 -- Check that the expression is not the target of an assignment, in
15921 -- which case the rewriting is not possible.
15923 if not Is_Const then
15924 declare
15925 Par : Node_Id;
15927 begin
15928 Par := Exp;
15929 while Present (Par)
15930 loop
15931 if Nkind (Parent (Par)) = N_Assignment_Statement
15932 and then Par = Name (Parent (Par))
15933 then
15934 return False;
15936 -- A renaming produces a reference, and the transformation
15937 -- does not apply.
15939 elsif Nkind (Parent (Par)) = N_Object_Renaming_Declaration then
15940 return False;
15942 elsif Nkind (Parent (Par)) in
15943 N_Function_Call |
15944 N_Procedure_Call_Statement |
15945 N_Entry_Call_Statement
15946 then
15947 -- Check that the element is not part of an actual for an
15948 -- in-out parameter.
15950 declare
15951 F : Entity_Id;
15952 A : Node_Id;
15954 begin
15955 F := First_Formal (Entity (Name (Parent (Par))));
15956 A := First (Parameter_Associations (Parent (Par)));
15957 while Present (F) loop
15958 if A = Par and then Ekind (F) /= E_In_Parameter then
15959 return False;
15960 end if;
15962 Next_Formal (F);
15963 Next (A);
15964 end loop;
15965 end;
15967 -- E_In_Parameter in a call: element is not modified.
15969 exit;
15970 end if;
15972 Par := Parent (Par);
15973 end loop;
15974 end;
15975 end if;
15977 -- The expression has the proper form and the context requires the
15978 -- element type. Retrieve the Element function of the container and
15979 -- rewrite the construct as a call to it.
15981 declare
15982 Op : Elmt_Id;
15984 begin
15985 Op := First_Elmt (Primitive_Operations (Cont_Typ));
15986 while Present (Op) loop
15987 exit when Chars (Node (Op)) = Name_Element;
15988 Next_Elmt (Op);
15989 end loop;
15991 if No (Op) then
15992 return False;
15994 else
15995 Rewrite (Exp,
15996 Make_Function_Call (Loc,
15997 Name => New_Occurrence_Of (Node (Op), Loc),
15998 Parameter_Associations => Parameter_Associations (Call)));
15999 Analyze_And_Resolve (Exp, Entity (Elem_Typ));
16000 return True;
16001 end if;
16002 end;
16003 end Is_Container_Element;
16005 ----------------------------
16006 -- Is_Contract_Annotation --
16007 ----------------------------
16009 function Is_Contract_Annotation (Item : Node_Id) return Boolean is
16010 begin
16011 return Is_Package_Contract_Annotation (Item)
16012 or else
16013 Is_Subprogram_Contract_Annotation (Item);
16014 end Is_Contract_Annotation;
16016 --------------------------------------
16017 -- Is_Controlling_Limited_Procedure --
16018 --------------------------------------
16020 function Is_Controlling_Limited_Procedure
16021 (Proc_Nam : Entity_Id) return Boolean
16023 Param : Node_Id;
16024 Param_Typ : Entity_Id := Empty;
16026 begin
16027 if Ekind (Proc_Nam) = E_Procedure
16028 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
16029 then
16030 Param :=
16031 Parameter_Type
16032 (First (Parameter_Specifications (Parent (Proc_Nam))));
16034 -- The formal may be an anonymous access type
16036 if Nkind (Param) = N_Access_Definition then
16037 Param_Typ := Entity (Subtype_Mark (Param));
16038 else
16039 Param_Typ := Etype (Param);
16040 end if;
16042 -- In the case where an Itype was created for a dispatchin call, the
16043 -- procedure call has been rewritten. The actual may be an access to
16044 -- interface type in which case it is the designated type that is the
16045 -- controlling type.
16047 elsif Present (Associated_Node_For_Itype (Proc_Nam))
16048 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
16049 and then
16050 Present (Parameter_Associations
16051 (Associated_Node_For_Itype (Proc_Nam)))
16052 then
16053 Param_Typ :=
16054 Etype (First (Parameter_Associations
16055 (Associated_Node_For_Itype (Proc_Nam))));
16057 if Ekind (Param_Typ) = E_Anonymous_Access_Type then
16058 Param_Typ := Directly_Designated_Type (Param_Typ);
16059 end if;
16060 end if;
16062 if Present (Param_Typ) then
16063 return
16064 Is_Interface (Param_Typ)
16065 and then Is_Limited_Record (Param_Typ);
16066 end if;
16068 return False;
16069 end Is_Controlling_Limited_Procedure;
16071 -----------------------------
16072 -- Is_CPP_Constructor_Call --
16073 -----------------------------
16075 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
16076 begin
16077 return Nkind (N) = N_Function_Call
16078 and then Is_CPP_Class (Etype (Etype (N)))
16079 and then Is_Constructor (Entity (Name (N)))
16080 and then Is_Imported (Entity (Name (N)));
16081 end Is_CPP_Constructor_Call;
16083 -------------------------
16084 -- Is_Current_Instance --
16085 -------------------------
16087 function Is_Current_Instance (N : Node_Id) return Boolean is
16088 Typ : constant Entity_Id := Entity (N);
16089 P : Node_Id;
16091 begin
16092 -- Simplest case: entity is a concurrent type and we are currently
16093 -- inside the body. This will eventually be expanded into a call to
16094 -- Self (for tasks) or _object (for protected objects).
16096 if Is_Concurrent_Type (Typ) and then In_Open_Scopes (Typ) then
16097 return True;
16099 else
16100 -- Check whether the context is a (sub)type declaration for the
16101 -- type entity.
16103 P := Parent (N);
16104 while Present (P) loop
16105 if Nkind (P) in N_Full_Type_Declaration
16106 | N_Private_Type_Declaration
16107 | N_Subtype_Declaration
16108 and then Comes_From_Source (P)
16110 -- If the type has a previous incomplete declaration, the
16111 -- reference in the type definition may have the incomplete
16112 -- view. So, here we detect if this incomplete view is a current
16113 -- instance by checking if its full view is the entity of the
16114 -- full declaration begin analyzed.
16116 and then
16117 (Defining_Entity (P) = Typ
16118 or else
16119 (Ekind (Typ) = E_Incomplete_Type
16120 and then Full_View (Typ) = Defining_Entity (P)))
16121 then
16122 return True;
16124 -- A subtype name may appear in an aspect specification for a
16125 -- Predicate_Failure aspect, for which we do not construct a
16126 -- wrapper procedure. The subtype will be replaced by the
16127 -- expression being tested when the corresponding predicate
16128 -- check is expanded. It may also appear in the pragma Predicate
16129 -- expression during legality checking.
16131 elsif Nkind (P) = N_Aspect_Specification
16132 and then Nkind (Parent (P)) = N_Subtype_Declaration
16133 and then Underlying_Type (Defining_Identifier (Parent (P))) =
16134 Underlying_Type (Typ)
16135 then
16136 return True;
16138 elsif Nkind (P) = N_Pragma
16139 and then Get_Pragma_Id (P) in Pragma_Predicate
16140 | Pragma_Predicate_Failure
16141 then
16142 declare
16143 Arg : constant Entity_Id :=
16144 Entity (Expression (Get_Argument (P)));
16145 begin
16146 if Underlying_Type (Arg) = Underlying_Type (Typ) then
16147 return True;
16148 end if;
16149 end;
16150 end if;
16152 P := Parent (P);
16153 end loop;
16154 end if;
16156 -- In any other context this is not a current occurrence
16158 return False;
16159 end Is_Current_Instance;
16161 --------------------------------------------------
16162 -- Is_Current_Instance_Reference_In_Type_Aspect --
16163 --------------------------------------------------
16165 function Is_Current_Instance_Reference_In_Type_Aspect
16166 (N : Node_Id) return Boolean
16168 begin
16169 -- When a current_instance is referenced within an aspect_specification
16170 -- of a type or subtype, it will show up as a reference to the formal
16171 -- parameter of the aspect's associated subprogram rather than as a
16172 -- reference to the type or subtype itself (in fact, the original name
16173 -- is never even analyzed). We check for predicate, invariant, and
16174 -- Default_Initial_Condition subprograms (in theory there could be
16175 -- other cases added, in which case this function will need updating).
16177 if Is_Entity_Name (N) then
16178 return Present (Entity (N))
16179 and then Ekind (Entity (N)) = E_In_Parameter
16180 and then Ekind (Scope (Entity (N))) in E_Function | E_Procedure
16181 and then
16182 (Is_Predicate_Function (Scope (Entity (N)))
16183 or else Is_Invariant_Procedure (Scope (Entity (N)))
16184 or else Is_Partial_Invariant_Procedure (Scope (Entity (N)))
16185 or else Is_DIC_Procedure (Scope (Entity (N))));
16187 else
16188 case Nkind (N) is
16189 when N_Indexed_Component
16190 | N_Slice
16192 return
16193 Is_Current_Instance_Reference_In_Type_Aspect (Prefix (N));
16195 when N_Selected_Component =>
16196 return
16197 Is_Current_Instance_Reference_In_Type_Aspect (Prefix (N));
16199 when N_Type_Conversion =>
16200 return Is_Current_Instance_Reference_In_Type_Aspect
16201 (Expression (N));
16203 when N_Qualified_Expression =>
16204 return Is_Current_Instance_Reference_In_Type_Aspect
16205 (Expression (N));
16207 when others =>
16208 return False;
16209 end case;
16210 end if;
16211 end Is_Current_Instance_Reference_In_Type_Aspect;
16213 --------------------
16214 -- Is_Declaration --
16215 --------------------
16217 function Is_Declaration
16218 (N : Node_Id;
16219 Body_OK : Boolean := True;
16220 Concurrent_OK : Boolean := True;
16221 Formal_OK : Boolean := True;
16222 Generic_OK : Boolean := True;
16223 Instantiation_OK : Boolean := True;
16224 Renaming_OK : Boolean := True;
16225 Stub_OK : Boolean := True;
16226 Subprogram_OK : Boolean := True;
16227 Type_OK : Boolean := True) return Boolean
16229 begin
16230 case Nkind (N) is
16232 -- Body declarations
16234 when N_Proper_Body =>
16235 return Body_OK;
16237 -- Concurrent type declarations
16239 when N_Protected_Type_Declaration
16240 | N_Single_Protected_Declaration
16241 | N_Single_Task_Declaration
16242 | N_Task_Type_Declaration
16244 return Concurrent_OK or Type_OK;
16246 -- Formal declarations
16248 when N_Formal_Abstract_Subprogram_Declaration
16249 | N_Formal_Concrete_Subprogram_Declaration
16250 | N_Formal_Object_Declaration
16251 | N_Formal_Package_Declaration
16252 | N_Formal_Type_Declaration
16254 return Formal_OK;
16256 -- Generic declarations
16258 when N_Generic_Package_Declaration
16259 | N_Generic_Subprogram_Declaration
16261 return Generic_OK;
16263 -- Generic instantiations
16265 when N_Function_Instantiation
16266 | N_Package_Instantiation
16267 | N_Procedure_Instantiation
16269 return Instantiation_OK;
16271 -- Generic renaming declarations
16273 when N_Generic_Renaming_Declaration =>
16274 return Generic_OK or Renaming_OK;
16276 -- Renaming declarations
16278 when N_Exception_Renaming_Declaration
16279 | N_Object_Renaming_Declaration
16280 | N_Package_Renaming_Declaration
16281 | N_Subprogram_Renaming_Declaration
16283 return Renaming_OK;
16285 -- Stub declarations
16287 when N_Body_Stub =>
16288 return Stub_OK;
16290 -- Subprogram declarations
16292 when N_Abstract_Subprogram_Declaration
16293 | N_Entry_Declaration
16294 | N_Expression_Function
16295 | N_Subprogram_Declaration
16297 return Subprogram_OK;
16299 -- Type declarations
16301 when N_Full_Type_Declaration
16302 | N_Incomplete_Type_Declaration
16303 | N_Private_Extension_Declaration
16304 | N_Private_Type_Declaration
16305 | N_Subtype_Declaration
16307 return Type_OK;
16309 -- Miscellaneous
16311 when N_Component_Declaration
16312 | N_Exception_Declaration
16313 | N_Implicit_Label_Declaration
16314 | N_Number_Declaration
16315 | N_Object_Declaration
16316 | N_Package_Declaration
16318 return True;
16320 when others =>
16321 return False;
16322 end case;
16323 end Is_Declaration;
16325 --------------------------------
16326 -- Is_Declared_Within_Variant --
16327 --------------------------------
16329 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
16330 Comp_Decl : constant Node_Id := Parent (Comp);
16331 Comp_List : constant Node_Id := Parent (Comp_Decl);
16332 begin
16333 return Nkind (Parent (Comp_List)) = N_Variant;
16334 end Is_Declared_Within_Variant;
16336 ----------------------------------------------
16337 -- Is_Dependent_Component_Of_Mutable_Object --
16338 ----------------------------------------------
16340 function Is_Dependent_Component_Of_Mutable_Object
16341 (Object : Node_Id) return Boolean
16343 P : Node_Id;
16344 Prefix_Type : Entity_Id;
16345 P_Aliased : Boolean := False;
16346 Comp : Entity_Id;
16348 Deref : Node_Id := Original_Node (Object);
16349 -- Dereference node, in something like X.all.Y(2)
16351 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
16353 begin
16354 -- Find the dereference node if any
16356 while Nkind (Deref) in
16357 N_Indexed_Component | N_Selected_Component | N_Slice
16358 loop
16359 Deref := Original_Node (Prefix (Deref));
16360 end loop;
16362 -- If the prefix is a qualified expression of a variable, then function
16363 -- Is_Variable will return False for that because a qualified expression
16364 -- denotes a constant view, so we need to get the name being qualified
16365 -- so we can test below whether that's a variable (or a dereference).
16367 if Nkind (Deref) = N_Qualified_Expression then
16368 Deref := Expression (Deref);
16369 end if;
16371 -- Ada 2005: If we have a component or slice of a dereference, something
16372 -- like X.all.Y (2) and the type of X is access-to-constant, Is_Variable
16373 -- will return False, because it is indeed a constant view. But it might
16374 -- be a view of a variable object, so we want the following condition to
16375 -- be True in that case.
16377 if Is_Variable (Object)
16378 or else Is_Variable (Deref)
16379 or else
16380 (Ada_Version >= Ada_2005
16381 and then (Nkind (Deref) = N_Explicit_Dereference
16382 or else (Present (Etype (Deref))
16383 and then Is_Access_Type (Etype (Deref)))))
16384 then
16385 if Nkind (Object) = N_Selected_Component then
16387 -- If the selector is not a component, then we definitely return
16388 -- False (it could be a function selector in a prefix form call
16389 -- occurring in an iterator specification).
16391 if Ekind (Entity (Selector_Name (Object))) not in
16392 E_Component | E_Discriminant
16393 then
16394 return False;
16395 end if;
16397 -- Get the original node of the prefix in case it has been
16398 -- rewritten, which can occur, for example, in qualified
16399 -- expression cases. Also, a discriminant check on a selected
16400 -- component may be expanded into a dereference when removing
16401 -- side effects, and the subtype of the original node may be
16402 -- unconstrained.
16404 P := Original_Node (Prefix (Object));
16405 Prefix_Type := Etype (P);
16407 -- If the prefix is a qualified expression, we want to look at its
16408 -- operand.
16410 if Nkind (P) = N_Qualified_Expression then
16411 P := Expression (P);
16412 Prefix_Type := Etype (P);
16413 end if;
16415 if Is_Entity_Name (P) then
16416 -- The Etype may not be set on P (which is wrong) in certain
16417 -- corner cases involving the deprecated front-end inlining of
16418 -- subprograms (via -gnatN), so use the Etype set on the
16419 -- the entity for these instances since we know it is present.
16421 if No (Prefix_Type) then
16422 Prefix_Type := Etype (Entity (P));
16423 end if;
16425 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
16426 Prefix_Type := Base_Type (Prefix_Type);
16427 end if;
16429 if Is_Aliased (Entity (P)) then
16430 P_Aliased := True;
16431 end if;
16433 -- For explicit dereferences we get the access prefix so we can
16434 -- treat this similarly to implicit dereferences and examine the
16435 -- kind of the access type and its designated subtype further
16436 -- below.
16438 elsif Nkind (P) = N_Explicit_Dereference then
16439 P := Prefix (P);
16440 Prefix_Type := Etype (P);
16442 else
16443 -- Check for prefix being an aliased component???
16445 null;
16446 end if;
16448 -- A heap object is constrained by its initial value
16450 -- Ada 2005 (AI-363): Always assume the object could be mutable in
16451 -- the dereferenced case, since the access value might denote an
16452 -- unconstrained aliased object, whereas in Ada 95 the designated
16453 -- object is guaranteed to be constrained. A worst-case assumption
16454 -- has to apply in Ada 2005 because we can't tell at compile
16455 -- time whether the object is "constrained by its initial value",
16456 -- despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are semantic
16457 -- rules (these rules are acknowledged to need fixing). We don't
16458 -- impose this more stringent checking for earlier Ada versions or
16459 -- when Relaxed_RM_Semantics applies (the latter for CodePeer's
16460 -- benefit, though it's unclear on why using -gnat95 would not be
16461 -- sufficient???).
16463 if Ada_Version < Ada_2005 or else Relaxed_RM_Semantics then
16464 if Is_Access_Type (Prefix_Type)
16465 or else Nkind (P) = N_Explicit_Dereference
16466 then
16467 return False;
16468 end if;
16470 else pragma Assert (Ada_Version >= Ada_2005);
16471 if Is_Access_Type (Prefix_Type) then
16472 -- We need to make sure we have the base subtype, in case
16473 -- this is actually an access subtype (whose Ekind will be
16474 -- E_Access_Subtype).
16476 Prefix_Type := Etype (Prefix_Type);
16478 -- If the access type is pool-specific, and there is no
16479 -- constrained partial view of the designated type, then the
16480 -- designated object is known to be constrained. If it's a
16481 -- formal access type and the renaming is in the generic
16482 -- spec, we also treat it as pool-specific (known to be
16483 -- constrained), but assume the worst if in the generic body
16484 -- (see RM 3.3(23.3/3)).
16486 if Ekind (Prefix_Type) = E_Access_Type
16487 and then (not Is_Generic_Type (Prefix_Type)
16488 or else not In_Generic_Body (Current_Scope))
16489 and then not Object_Type_Has_Constrained_Partial_View
16490 (Typ => Designated_Type (Prefix_Type),
16491 Scop => Current_Scope)
16492 then
16493 return False;
16495 -- Otherwise (general access type, or there is a constrained
16496 -- partial view of the designated type), we need to check
16497 -- based on the designated type.
16499 else
16500 Prefix_Type := Designated_Type (Prefix_Type);
16501 end if;
16502 end if;
16503 end if;
16505 Comp :=
16506 Original_Record_Component (Entity (Selector_Name (Object)));
16508 -- As per AI-0017, the renaming is illegal in a generic body, even
16509 -- if the subtype is indefinite (only applies to prefixes of an
16510 -- untagged formal type, see RM 3.3 (23.11/3)).
16512 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
16514 if not Is_Constrained (Prefix_Type)
16515 and then (Is_Definite_Subtype (Prefix_Type)
16516 or else
16517 (not Is_Tagged_Type (Prefix_Type)
16518 and then Is_Generic_Type (Prefix_Type)
16519 and then In_Generic_Body (Current_Scope)))
16521 and then (Is_Declared_Within_Variant (Comp)
16522 or else Has_Discriminant_Dependent_Constraint (Comp))
16523 and then (not P_Aliased or else Ada_Version >= Ada_2005)
16524 then
16525 return True;
16527 -- If the prefix is of an access type at this point, then we want
16528 -- to return False, rather than calling this function recursively
16529 -- on the access object (which itself might be a discriminant-
16530 -- dependent component of some other object, but that isn't
16531 -- relevant to checking the object passed to us). This avoids
16532 -- issuing wrong errors when compiling with -gnatc, where there
16533 -- can be implicit dereferences that have not been expanded.
16535 elsif Is_Access_Type (Etype (Prefix (Object))) then
16536 return False;
16538 else
16539 return
16540 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
16541 end if;
16543 elsif Nkind (Object) = N_Indexed_Component
16544 or else Nkind (Object) = N_Slice
16545 then
16546 return Is_Dependent_Component_Of_Mutable_Object
16547 (Original_Node (Prefix (Object)));
16549 -- A type conversion that Is_Variable is a view conversion:
16550 -- go back to the denoted object.
16552 elsif Nkind (Object) = N_Type_Conversion then
16553 return
16554 Is_Dependent_Component_Of_Mutable_Object
16555 (Original_Node (Expression (Object)));
16556 end if;
16557 end if;
16559 return False;
16560 end Is_Dependent_Component_Of_Mutable_Object;
16562 ---------------------
16563 -- Is_Dereferenced --
16564 ---------------------
16566 function Is_Dereferenced (N : Node_Id) return Boolean is
16567 P : constant Node_Id := Parent (N);
16568 begin
16569 return Nkind (P) in N_Selected_Component
16570 | N_Explicit_Dereference
16571 | N_Indexed_Component
16572 | N_Slice
16573 and then Prefix (P) = N;
16574 end Is_Dereferenced;
16576 ----------------------
16577 -- Is_Descendant_Of --
16578 ----------------------
16580 function Is_Descendant_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
16581 T : Entity_Id;
16582 Etyp : Entity_Id;
16584 begin
16585 pragma Assert (Nkind (T1) in N_Entity);
16586 pragma Assert (Nkind (T2) in N_Entity);
16588 T := Base_Type (T1);
16590 -- Immediate return if the types match
16592 if T = T2 then
16593 return True;
16595 -- Comment needed here ???
16597 elsif Ekind (T) = E_Class_Wide_Type then
16598 return Etype (T) = T2;
16600 -- All other cases
16602 else
16603 loop
16604 Etyp := Etype (T);
16606 -- Done if we found the type we are looking for
16608 if Etyp = T2 then
16609 return True;
16611 -- Done if no more derivations to check
16613 elsif T = T1
16614 or else T = Etyp
16615 then
16616 return False;
16618 -- Following test catches error cases resulting from prev errors
16620 elsif No (Etyp) then
16621 return False;
16623 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
16624 return False;
16626 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
16627 return False;
16628 end if;
16630 T := Base_Type (Etyp);
16631 end loop;
16632 end if;
16633 end Is_Descendant_Of;
16635 ----------------------------------------
16636 -- Is_Descendant_Of_Suspension_Object --
16637 ----------------------------------------
16639 function Is_Descendant_Of_Suspension_Object
16640 (Typ : Entity_Id) return Boolean
16642 Cur_Typ : Entity_Id;
16643 Par_Typ : Entity_Id;
16645 begin
16646 -- Climb the type derivation chain checking each parent type against
16647 -- Suspension_Object.
16649 Cur_Typ := Base_Type (Typ);
16650 while Present (Cur_Typ) loop
16651 Par_Typ := Etype (Cur_Typ);
16653 -- The current type is a match
16655 if Is_RTE (Cur_Typ, RE_Suspension_Object) then
16656 return True;
16658 -- Stop the traversal once the root of the derivation chain has been
16659 -- reached. In that case the current type is its own base type.
16661 elsif Cur_Typ = Par_Typ then
16662 exit;
16663 end if;
16665 Cur_Typ := Base_Type (Par_Typ);
16666 end loop;
16668 return False;
16669 end Is_Descendant_Of_Suspension_Object;
16671 ---------------------------------------------
16672 -- Is_Double_Precision_Floating_Point_Type --
16673 ---------------------------------------------
16675 function Is_Double_Precision_Floating_Point_Type
16676 (E : Entity_Id) return Boolean is
16677 begin
16678 return Is_Floating_Point_Type (E)
16679 and then Machine_Radix_Value (E) = Uint_2
16680 and then Machine_Mantissa_Value (E) = UI_From_Int (53)
16681 and then Machine_Emax_Value (E) = Uint_2 ** Uint_10
16682 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_10);
16683 end Is_Double_Precision_Floating_Point_Type;
16685 -----------------------------
16686 -- Is_Effectively_Volatile --
16687 -----------------------------
16689 function Is_Effectively_Volatile
16690 (Id : Entity_Id;
16691 Ignore_Protected : Boolean := False) return Boolean is
16692 begin
16693 if Is_Type (Id) then
16695 -- An arbitrary type is effectively volatile when it is subject to
16696 -- pragma Atomic or Volatile, unless No_Caching is enabled.
16698 if Is_Volatile (Id)
16699 and then not No_Caching_Enabled (Id)
16700 then
16701 return True;
16703 -- An array type is effectively volatile when it is subject to pragma
16704 -- Atomic_Components or Volatile_Components or its component type is
16705 -- effectively volatile.
16707 elsif Is_Array_Type (Id) then
16708 if Has_Volatile_Components (Id) then
16709 return True;
16710 else
16711 declare
16712 Anc : Entity_Id := Base_Type (Id);
16713 begin
16714 if Is_Private_Type (Anc) then
16715 Anc := Full_View (Anc);
16716 end if;
16718 -- Test for presence of ancestor, as the full view of a
16719 -- private type may be missing in case of error.
16721 return Present (Anc)
16722 and then Is_Effectively_Volatile
16723 (Component_Type (Anc), Ignore_Protected);
16724 end;
16725 end if;
16727 -- A protected type is always volatile unless Ignore_Protected is
16728 -- True.
16730 elsif Is_Protected_Type (Id) and then not Ignore_Protected then
16731 return True;
16733 -- A descendant of Ada.Synchronous_Task_Control.Suspension_Object is
16734 -- automatically volatile.
16736 elsif Is_Descendant_Of_Suspension_Object (Id) then
16737 return True;
16739 -- Otherwise the type is not effectively volatile
16741 else
16742 return False;
16743 end if;
16745 -- Otherwise Id denotes an object
16747 else pragma Assert (Is_Object (Id));
16748 -- A volatile object for which No_Caching is enabled is not
16749 -- effectively volatile.
16751 return
16752 (Is_Volatile (Id)
16753 and then not
16754 (Ekind (Id) = E_Variable and then No_Caching_Enabled (Id)))
16755 or else Has_Volatile_Components (Id)
16756 or else Is_Effectively_Volatile (Etype (Id), Ignore_Protected);
16757 end if;
16758 end Is_Effectively_Volatile;
16760 -----------------------------------------
16761 -- Is_Effectively_Volatile_For_Reading --
16762 -----------------------------------------
16764 function Is_Effectively_Volatile_For_Reading
16765 (Id : Entity_Id;
16766 Ignore_Protected : Boolean := False) return Boolean
16768 begin
16769 -- A concurrent type is effectively volatile for reading, except for a
16770 -- protected type when Ignore_Protected is True.
16772 if Is_Task_Type (Id)
16773 or else (Is_Protected_Type (Id) and then not Ignore_Protected)
16774 then
16775 return True;
16777 elsif Is_Effectively_Volatile (Id, Ignore_Protected) then
16779 -- Other volatile types and objects are effectively volatile for
16780 -- reading when they have property Async_Writers or Effective_Reads
16781 -- set to True. This includes the case of an array type whose
16782 -- Volatile_Components aspect is True (hence it is effectively
16783 -- volatile) which does not have the properties Async_Writers
16784 -- and Effective_Reads set to False.
16786 if Async_Writers_Enabled (Id)
16787 or else Effective_Reads_Enabled (Id)
16788 then
16789 return True;
16791 -- In addition, an array type is effectively volatile for reading
16792 -- when its component type is effectively volatile for reading.
16794 elsif Is_Array_Type (Id) then
16795 declare
16796 Anc : Entity_Id := Base_Type (Id);
16797 begin
16798 if Is_Private_Type (Anc) then
16799 Anc := Full_View (Anc);
16800 end if;
16802 -- Test for presence of ancestor, as the full view of a
16803 -- private type may be missing in case of error.
16805 return Present (Anc)
16806 and then Is_Effectively_Volatile_For_Reading
16807 (Component_Type (Anc), Ignore_Protected);
16808 end;
16809 end if;
16810 end if;
16812 return False;
16814 end Is_Effectively_Volatile_For_Reading;
16816 ------------------------------------
16817 -- Is_Effectively_Volatile_Object --
16818 ------------------------------------
16820 function Is_Effectively_Volatile_Object (N : Node_Id) return Boolean is
16821 function Is_Effectively_Volatile (E : Entity_Id) return Boolean is
16822 (Is_Effectively_Volatile (E, Ignore_Protected => False));
16824 function Is_Effectively_Volatile_Object_Inst
16825 is new Is_Effectively_Volatile_Object_Shared (Is_Effectively_Volatile);
16826 begin
16827 return Is_Effectively_Volatile_Object_Inst (N);
16828 end Is_Effectively_Volatile_Object;
16830 ------------------------------------------------
16831 -- Is_Effectively_Volatile_Object_For_Reading --
16832 ------------------------------------------------
16834 function Is_Effectively_Volatile_Object_For_Reading
16835 (N : Node_Id) return Boolean
16837 function Is_Effectively_Volatile_For_Reading
16838 (E : Entity_Id) return Boolean
16839 is (Is_Effectively_Volatile_For_Reading (E, Ignore_Protected => False));
16841 function Is_Effectively_Volatile_Object_For_Reading_Inst
16842 is new Is_Effectively_Volatile_Object_Shared
16843 (Is_Effectively_Volatile_For_Reading);
16844 begin
16845 return Is_Effectively_Volatile_Object_For_Reading_Inst (N);
16846 end Is_Effectively_Volatile_Object_For_Reading;
16848 -------------------------------------------
16849 -- Is_Effectively_Volatile_Object_Shared --
16850 -------------------------------------------
16852 function Is_Effectively_Volatile_Object_Shared
16853 (N : Node_Id) return Boolean
16855 begin
16856 if Is_Entity_Name (N) then
16857 return Is_Object (Entity (N))
16858 and then Is_Effectively_Volatile_Entity (Entity (N));
16860 elsif Nkind (N) in N_Indexed_Component | N_Slice then
16861 return Is_Effectively_Volatile_Object_Shared (Prefix (N));
16863 elsif Nkind (N) = N_Selected_Component then
16864 return
16865 Is_Effectively_Volatile_Object_Shared (Prefix (N))
16866 or else
16867 Is_Effectively_Volatile_Object_Shared (Selector_Name (N));
16869 elsif Nkind (N) in N_Qualified_Expression
16870 | N_Unchecked_Type_Conversion
16871 | N_Type_Conversion
16872 then
16873 return Is_Effectively_Volatile_Object_Shared (Expression (N));
16875 else
16876 return False;
16877 end if;
16878 end Is_Effectively_Volatile_Object_Shared;
16880 ----------------------------------------
16881 -- Is_Entity_Of_Quantified_Expression --
16882 ----------------------------------------
16884 function Is_Entity_Of_Quantified_Expression (Id : Entity_Id) return Boolean
16886 Par : constant Node_Id := Parent (Id);
16888 begin
16889 return (Nkind (Par) = N_Loop_Parameter_Specification
16890 or else Nkind (Par) = N_Iterator_Specification)
16891 and then Defining_Identifier (Par) = Id
16892 and then Nkind (Parent (Par)) = N_Quantified_Expression;
16893 end Is_Entity_Of_Quantified_Expression;
16895 -------------------
16896 -- Is_Entry_Body --
16897 -------------------
16899 function Is_Entry_Body (Id : Entity_Id) return Boolean is
16900 begin
16901 return
16902 Is_Entry (Id)
16903 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Body;
16904 end Is_Entry_Body;
16906 --------------------------
16907 -- Is_Entry_Declaration --
16908 --------------------------
16910 function Is_Entry_Declaration (Id : Entity_Id) return Boolean is
16911 begin
16912 return
16913 Is_Entry (Id)
16914 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Declaration;
16915 end Is_Entry_Declaration;
16917 ------------------------------------
16918 -- Is_Expanded_Priority_Attribute --
16919 ------------------------------------
16921 function Is_Expanded_Priority_Attribute (E : Entity_Id) return Boolean is
16922 begin
16923 return
16924 Nkind (E) = N_Function_Call
16925 and then not Configurable_Run_Time_Mode
16926 and then Nkind (Original_Node (E)) = N_Attribute_Reference
16927 and then (Is_RTE (Entity (Name (E)), RE_Get_Ceiling)
16928 or else Is_RTE (Entity (Name (E)), RO_PE_Get_Ceiling));
16929 end Is_Expanded_Priority_Attribute;
16931 ----------------------------
16932 -- Is_Expression_Function --
16933 ----------------------------
16935 function Is_Expression_Function (Subp : Entity_Id) return Boolean is
16936 begin
16937 if Ekind (Subp) in E_Function | E_Subprogram_Body then
16938 return
16939 Nkind (Original_Node (Unit_Declaration_Node (Subp))) =
16940 N_Expression_Function;
16941 else
16942 return False;
16943 end if;
16944 end Is_Expression_Function;
16946 ------------------------------------------
16947 -- Is_Expression_Function_Or_Completion --
16948 ------------------------------------------
16950 function Is_Expression_Function_Or_Completion
16951 (Subp : Entity_Id) return Boolean
16953 Subp_Decl : Node_Id;
16955 begin
16956 if Ekind (Subp) = E_Function then
16957 Subp_Decl := Unit_Declaration_Node (Subp);
16959 -- The function declaration is either an expression function or is
16960 -- completed by an expression function body.
16962 return
16963 Is_Expression_Function (Subp)
16964 or else (Nkind (Subp_Decl) = N_Subprogram_Declaration
16965 and then Present (Corresponding_Body (Subp_Decl))
16966 and then Is_Expression_Function
16967 (Corresponding_Body (Subp_Decl)));
16969 elsif Ekind (Subp) = E_Subprogram_Body then
16970 return Is_Expression_Function (Subp);
16972 else
16973 return False;
16974 end if;
16975 end Is_Expression_Function_Or_Completion;
16977 -----------------------------------------------
16978 -- Is_Extended_Precision_Floating_Point_Type --
16979 -----------------------------------------------
16981 function Is_Extended_Precision_Floating_Point_Type
16982 (E : Entity_Id) return Boolean is
16983 begin
16984 return Is_Floating_Point_Type (E)
16985 and then Machine_Radix_Value (E) = Uint_2
16986 and then Machine_Mantissa_Value (E) = Uint_64
16987 and then Machine_Emax_Value (E) = Uint_2 ** Uint_14
16988 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_14);
16989 end Is_Extended_Precision_Floating_Point_Type;
16991 -----------------------
16992 -- Is_EVF_Expression --
16993 -----------------------
16995 function Is_EVF_Expression (N : Node_Id) return Boolean is
16996 Orig_N : constant Node_Id := Original_Node (N);
16997 Alt : Node_Id;
16998 Expr : Node_Id;
16999 Id : Entity_Id;
17001 begin
17002 -- Detect a reference to a formal parameter of a specific tagged type
17003 -- whose related subprogram is subject to pragma Expresions_Visible with
17004 -- value "False".
17006 if Is_Entity_Name (N) and then Present (Entity (N)) then
17007 Id := Entity (N);
17009 return
17010 Is_Formal (Id)
17011 and then Is_Specific_Tagged_Type (Etype (Id))
17012 and then Extensions_Visible_Status (Id) =
17013 Extensions_Visible_False;
17015 -- A case expression is an EVF expression when it contains at least one
17016 -- EVF dependent_expression. Note that a case expression may have been
17017 -- expanded, hence the use of Original_Node.
17019 elsif Nkind (Orig_N) = N_Case_Expression then
17020 Alt := First (Alternatives (Orig_N));
17021 while Present (Alt) loop
17022 if Is_EVF_Expression (Expression (Alt)) then
17023 return True;
17024 end if;
17026 Next (Alt);
17027 end loop;
17029 -- An if expression is an EVF expression when it contains at least one
17030 -- EVF dependent_expression. Note that an if expression may have been
17031 -- expanded, hence the use of Original_Node.
17033 elsif Nkind (Orig_N) = N_If_Expression then
17034 Expr := Next (First (Expressions (Orig_N)));
17035 while Present (Expr) loop
17036 if Is_EVF_Expression (Expr) then
17037 return True;
17038 end if;
17040 Next (Expr);
17041 end loop;
17043 -- A qualified expression or a type conversion is an EVF expression when
17044 -- its operand is an EVF expression.
17046 elsif Nkind (N) in N_Qualified_Expression
17047 | N_Unchecked_Type_Conversion
17048 | N_Type_Conversion
17049 then
17050 return Is_EVF_Expression (Expression (N));
17052 -- Attributes 'Loop_Entry, 'Old, and 'Update are EVF expressions when
17053 -- their prefix denotes an EVF expression.
17055 elsif Nkind (N) = N_Attribute_Reference
17056 and then Attribute_Name (N) in Name_Loop_Entry
17057 | Name_Old
17058 | Name_Update
17059 then
17060 return Is_EVF_Expression (Prefix (N));
17061 end if;
17063 return False;
17064 end Is_EVF_Expression;
17066 --------------
17067 -- Is_False --
17068 --------------
17070 function Is_False (U : Opt_Ubool) return Boolean is
17071 begin
17072 return not Is_True (U);
17073 end Is_False;
17075 ---------------------------
17076 -- Is_Fixed_Model_Number --
17077 ---------------------------
17079 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
17080 S : constant Ureal := Small_Value (T);
17081 M : Urealp.Save_Mark;
17082 R : Boolean;
17084 begin
17085 M := Urealp.Mark;
17086 R := (U = UR_Trunc (U / S) * S);
17087 Urealp.Release (M);
17088 return R;
17089 end Is_Fixed_Model_Number;
17091 -----------------------------
17092 -- Is_Full_Access_Object --
17093 -----------------------------
17095 function Is_Full_Access_Object (N : Node_Id) return Boolean is
17096 begin
17097 return Is_Atomic_Object (N)
17098 or else Is_Volatile_Full_Access_Object_Ref (N);
17099 end Is_Full_Access_Object;
17101 -------------------------------
17102 -- Is_Fully_Initialized_Type --
17103 -------------------------------
17105 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
17106 begin
17107 -- Scalar types
17109 if Is_Scalar_Type (Typ) then
17111 -- A scalar type with an aspect Default_Value is fully initialized
17113 -- Note: Iniitalize/Normalize_Scalars also ensure full initialization
17114 -- of a scalar type, but we don't take that into account here, since
17115 -- we don't want these to affect warnings.
17117 return Has_Default_Aspect (Typ);
17119 elsif Is_Access_Type (Typ) then
17120 return True;
17122 elsif Is_Array_Type (Typ) then
17123 if Is_Fully_Initialized_Type (Component_Type (Typ))
17124 or else (Ada_Version >= Ada_2012 and then Has_Default_Aspect (Typ))
17125 then
17126 return True;
17127 end if;
17129 -- An interesting case, if we have a constrained type one of whose
17130 -- bounds is known to be null, then there are no elements to be
17131 -- initialized, so all the elements are initialized.
17133 if Is_Constrained (Typ) then
17134 declare
17135 Indx : Node_Id;
17136 Indx_Typ : Entity_Id;
17137 Lbd, Hbd : Node_Id;
17139 begin
17140 Indx := First_Index (Typ);
17141 while Present (Indx) loop
17142 if Etype (Indx) = Any_Type then
17143 return False;
17145 -- If index is a range, use directly
17147 elsif Nkind (Indx) = N_Range then
17148 Lbd := Low_Bound (Indx);
17149 Hbd := High_Bound (Indx);
17151 else
17152 Indx_Typ := Etype (Indx);
17154 if Is_Private_Type (Indx_Typ) then
17155 Indx_Typ := Full_View (Indx_Typ);
17156 end if;
17158 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
17159 return False;
17160 else
17161 Lbd := Type_Low_Bound (Indx_Typ);
17162 Hbd := Type_High_Bound (Indx_Typ);
17163 end if;
17164 end if;
17166 if Compile_Time_Known_Value (Lbd)
17167 and then
17168 Compile_Time_Known_Value (Hbd)
17169 then
17170 if Expr_Value (Hbd) < Expr_Value (Lbd) then
17171 return True;
17172 end if;
17173 end if;
17175 Next_Index (Indx);
17176 end loop;
17177 end;
17178 end if;
17180 -- If no null indexes, then type is not fully initialized
17182 return False;
17184 -- Record types
17186 elsif Is_Record_Type (Typ) then
17187 if Has_Defaulted_Discriminants (Typ)
17188 and then Is_Fully_Initialized_Variant (Typ)
17189 then
17190 return True;
17191 end if;
17193 -- We consider bounded string types to be fully initialized, because
17194 -- otherwise we get false alarms when the Data component is not
17195 -- default-initialized.
17197 if Is_Bounded_String (Typ) then
17198 return True;
17199 end if;
17201 -- Controlled records are considered to be fully initialized if
17202 -- there is a user defined Initialize routine. This may not be
17203 -- entirely correct, but as the spec notes, we are guessing here
17204 -- what is best from the point of view of issuing warnings.
17206 if Is_Controlled (Typ) then
17207 declare
17208 Utyp : constant Entity_Id := Underlying_Type (Typ);
17210 begin
17211 if Present (Utyp) then
17212 declare
17213 Init : constant Entity_Id :=
17214 (Find_Optional_Prim_Op
17215 (Underlying_Type (Typ), Name_Initialize));
17217 begin
17218 if Present (Init)
17219 and then Comes_From_Source (Init)
17220 and then not In_Predefined_Unit (Init)
17221 then
17222 return True;
17224 elsif Has_Null_Extension (Typ)
17225 and then
17226 Is_Fully_Initialized_Type
17227 (Etype (Base_Type (Typ)))
17228 then
17229 return True;
17230 end if;
17231 end;
17232 end if;
17233 end;
17234 end if;
17236 -- Otherwise see if all record components are initialized
17238 declare
17239 Comp : Entity_Id;
17241 begin
17242 Comp := First_Component (Typ);
17243 while Present (Comp) loop
17244 if (No (Parent (Comp))
17245 or else No (Expression (Parent (Comp))))
17246 and then not Is_Fully_Initialized_Type (Etype (Comp))
17248 -- Special VM case for tag components, which need to be
17249 -- defined in this case, but are never initialized as VMs
17250 -- are using other dispatching mechanisms. Ignore this
17251 -- uninitialized case. Note that this applies both to the
17252 -- uTag entry and the main vtable pointer (CPP_Class case).
17254 and then (Tagged_Type_Expansion or else not Is_Tag (Comp))
17255 then
17256 return False;
17257 end if;
17259 Next_Component (Comp);
17260 end loop;
17261 end;
17263 -- No uninitialized components, so type is fully initialized.
17264 -- Note that this catches the case of no components as well.
17266 return True;
17268 elsif Is_Concurrent_Type (Typ) then
17269 return True;
17271 elsif Is_Private_Type (Typ) then
17272 declare
17273 U : constant Entity_Id := Underlying_Type (Typ);
17275 begin
17276 if No (U) then
17277 return False;
17278 else
17279 return Is_Fully_Initialized_Type (U);
17280 end if;
17281 end;
17283 else
17284 return False;
17285 end if;
17286 end Is_Fully_Initialized_Type;
17288 ----------------------------------
17289 -- Is_Fully_Initialized_Variant --
17290 ----------------------------------
17292 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
17293 Loc : constant Source_Ptr := Sloc (Typ);
17294 Constraints : constant List_Id := New_List;
17295 Components : constant Elist_Id := New_Elmt_List;
17296 Comp_Elmt : Elmt_Id;
17297 Comp_Id : Node_Id;
17298 Comp_List : Node_Id;
17299 Discr : Entity_Id;
17300 Discr_Val : Node_Id;
17302 Report_Errors : Boolean;
17303 pragma Warnings (Off, Report_Errors);
17305 begin
17306 if Serious_Errors_Detected > 0 then
17307 return False;
17308 end if;
17310 if Is_Record_Type (Typ)
17311 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
17312 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
17313 then
17314 Comp_List := Component_List (Type_Definition (Parent (Typ)));
17316 Discr := First_Discriminant (Typ);
17317 while Present (Discr) loop
17318 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
17319 Discr_Val := Expression (Parent (Discr));
17321 if Present (Discr_Val)
17322 and then Is_OK_Static_Expression (Discr_Val)
17323 then
17324 Append_To (Constraints,
17325 Make_Component_Association (Loc,
17326 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
17327 Expression => New_Copy (Discr_Val)));
17328 else
17329 return False;
17330 end if;
17331 else
17332 return False;
17333 end if;
17335 Next_Discriminant (Discr);
17336 end loop;
17338 Gather_Components
17339 (Typ => Typ,
17340 Comp_List => Comp_List,
17341 Governed_By => Constraints,
17342 Into => Components,
17343 Report_Errors => Report_Errors);
17345 -- Check that each component present is fully initialized
17347 Comp_Elmt := First_Elmt (Components);
17348 while Present (Comp_Elmt) loop
17349 Comp_Id := Node (Comp_Elmt);
17351 if Ekind (Comp_Id) = E_Component
17352 and then (No (Parent (Comp_Id))
17353 or else No (Expression (Parent (Comp_Id))))
17354 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
17355 then
17356 return False;
17357 end if;
17359 Next_Elmt (Comp_Elmt);
17360 end loop;
17362 return True;
17364 elsif Is_Private_Type (Typ) then
17365 declare
17366 U : constant Entity_Id := Underlying_Type (Typ);
17368 begin
17369 if No (U) then
17370 return False;
17371 else
17372 return Is_Fully_Initialized_Variant (U);
17373 end if;
17374 end;
17376 else
17377 return False;
17378 end if;
17379 end Is_Fully_Initialized_Variant;
17381 ------------------------------------
17382 -- Is_Generic_Declaration_Or_Body --
17383 ------------------------------------
17385 function Is_Generic_Declaration_Or_Body (Decl : Node_Id) return Boolean is
17386 Spec_Decl : Node_Id;
17388 begin
17389 -- Package/subprogram body
17391 if Nkind (Decl) in N_Package_Body | N_Subprogram_Body
17392 and then Present (Corresponding_Spec (Decl))
17393 then
17394 Spec_Decl := Unit_Declaration_Node (Corresponding_Spec (Decl));
17396 -- Package/subprogram body stub
17398 elsif Nkind (Decl) in N_Package_Body_Stub | N_Subprogram_Body_Stub
17399 and then Present (Corresponding_Spec_Of_Stub (Decl))
17400 then
17401 Spec_Decl :=
17402 Unit_Declaration_Node (Corresponding_Spec_Of_Stub (Decl));
17404 -- All other cases
17406 else
17407 Spec_Decl := Decl;
17408 end if;
17410 -- Rather than inspecting the defining entity of the spec declaration,
17411 -- look at its Nkind. This takes care of the case where the analysis of
17412 -- a generic body modifies the Ekind of its spec to allow for recursive
17413 -- calls.
17415 return Nkind (Spec_Decl) in N_Generic_Declaration;
17416 end Is_Generic_Declaration_Or_Body;
17418 ---------------------------
17419 -- Is_Independent_Object --
17420 ---------------------------
17422 function Is_Independent_Object (N : Node_Id) return Boolean is
17423 function Is_Independent_Object_Entity (Id : Entity_Id) return Boolean;
17424 -- Determine whether arbitrary entity Id denotes an object that is
17425 -- Independent.
17427 function Prefix_Has_Independent_Components (P : Node_Id) return Boolean;
17428 -- Determine whether prefix P has independent components. This requires
17429 -- the presence of an Independent_Components aspect/pragma.
17431 ------------------------------------
17432 -- Is_Independent_Object_Entity --
17433 ------------------------------------
17435 function Is_Independent_Object_Entity (Id : Entity_Id) return Boolean is
17436 begin
17437 return
17438 Is_Object (Id)
17439 and then (Is_Independent (Id)
17440 or else
17441 Is_Independent (Etype (Id)));
17442 end Is_Independent_Object_Entity;
17444 -------------------------------------
17445 -- Prefix_Has_Independent_Components --
17446 -------------------------------------
17448 function Prefix_Has_Independent_Components (P : Node_Id) return Boolean
17450 Typ : constant Entity_Id := Etype (P);
17452 begin
17453 if Is_Access_Type (Typ) then
17454 return Has_Independent_Components (Designated_Type (Typ));
17456 elsif Has_Independent_Components (Typ) then
17457 return True;
17459 elsif Is_Entity_Name (P)
17460 and then Has_Independent_Components (Entity (P))
17461 then
17462 return True;
17464 else
17465 return False;
17466 end if;
17467 end Prefix_Has_Independent_Components;
17469 -- Start of processing for Is_Independent_Object
17471 begin
17472 if Is_Entity_Name (N) then
17473 return Is_Independent_Object_Entity (Entity (N));
17475 elsif Is_Independent (Etype (N)) then
17476 return True;
17478 elsif Nkind (N) = N_Indexed_Component then
17479 return Prefix_Has_Independent_Components (Prefix (N));
17481 elsif Nkind (N) = N_Selected_Component then
17482 return Prefix_Has_Independent_Components (Prefix (N))
17483 or else Is_Independent (Entity (Selector_Name (N)));
17485 else
17486 return False;
17487 end if;
17488 end Is_Independent_Object;
17490 ----------------------------
17491 -- Is_Inherited_Operation --
17492 ----------------------------
17494 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
17495 pragma Assert (Is_Overloadable (E));
17496 Kind : constant Node_Kind := Nkind (Parent (E));
17497 begin
17498 return Kind = N_Full_Type_Declaration
17499 or else Kind = N_Private_Extension_Declaration
17500 or else Kind = N_Subtype_Declaration
17501 or else (Ekind (E) = E_Enumeration_Literal
17502 and then Is_Derived_Type (Etype (E)));
17503 end Is_Inherited_Operation;
17505 -------------------------------------
17506 -- Is_Inherited_Operation_For_Type --
17507 -------------------------------------
17509 function Is_Inherited_Operation_For_Type
17510 (E : Entity_Id;
17511 Typ : Entity_Id) return Boolean
17513 begin
17514 -- Check that the operation has been created by the type declaration
17516 return Is_Inherited_Operation (E)
17517 and then Defining_Identifier (Parent (E)) = Typ;
17518 end Is_Inherited_Operation_For_Type;
17520 --------------------------------------
17521 -- Is_Inlinable_Expression_Function --
17522 --------------------------------------
17524 function Is_Inlinable_Expression_Function
17525 (Subp : Entity_Id) return Boolean
17527 Return_Expr : Node_Id;
17529 begin
17530 if Is_Expression_Function_Or_Completion (Subp)
17531 and then Has_Pragma_Inline_Always (Subp)
17532 and then Needs_No_Actuals (Subp)
17533 and then No (Contract (Subp))
17534 and then not Is_Dispatching_Operation (Subp)
17535 and then Needs_Finalization (Etype (Subp))
17536 and then not Is_Class_Wide_Type (Etype (Subp))
17537 and then not Has_Invariants (Etype (Subp))
17538 and then Present (Subprogram_Body (Subp))
17539 and then Was_Expression_Function (Subprogram_Body (Subp))
17540 then
17541 Return_Expr := Expression_Of_Expression_Function (Subp);
17543 -- The returned object must not have a qualified expression and its
17544 -- nominal subtype must be statically compatible with the result
17545 -- subtype of the expression function.
17547 return
17548 Nkind (Return_Expr) = N_Identifier
17549 and then Etype (Return_Expr) = Etype (Subp);
17550 end if;
17552 return False;
17553 end Is_Inlinable_Expression_Function;
17555 -----------------
17556 -- Is_Iterator --
17557 -----------------
17559 function Is_Iterator (Typ : Entity_Id) return Boolean is
17560 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean;
17561 -- Determine whether type Iter_Typ is a predefined forward or reversible
17562 -- iterator.
17564 ----------------------
17565 -- Denotes_Iterator --
17566 ----------------------
17568 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean is
17569 begin
17570 -- Check that the name matches, and that the ultimate ancestor is in
17571 -- a predefined unit, i.e the one that declares iterator interfaces.
17573 return
17574 Chars (Iter_Typ) in Name_Forward_Iterator | Name_Reversible_Iterator
17575 and then In_Predefined_Unit (Root_Type (Iter_Typ));
17576 end Denotes_Iterator;
17578 -- Local variables
17580 Iface_Elmt : Elmt_Id;
17581 Ifaces : Elist_Id;
17583 -- Start of processing for Is_Iterator
17585 begin
17586 -- The type may be a subtype of a descendant of the proper instance of
17587 -- the predefined interface type, so we must use the root type of the
17588 -- given type. The same is done for Is_Reversible_Iterator.
17590 if Is_Class_Wide_Type (Typ)
17591 and then Denotes_Iterator (Root_Type (Typ))
17592 then
17593 return True;
17595 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
17596 return False;
17598 elsif Present (Find_Value_Of_Aspect (Typ, Aspect_Iterable)) then
17599 return True;
17601 else
17602 Collect_Interfaces (Typ, Ifaces);
17604 Iface_Elmt := First_Elmt (Ifaces);
17605 while Present (Iface_Elmt) loop
17606 if Denotes_Iterator (Node (Iface_Elmt)) then
17607 return True;
17608 end if;
17610 Next_Elmt (Iface_Elmt);
17611 end loop;
17613 return False;
17614 end if;
17615 end Is_Iterator;
17617 ----------------------------
17618 -- Is_Iterator_Over_Array --
17619 ----------------------------
17621 function Is_Iterator_Over_Array (N : Node_Id) return Boolean is
17622 Container : constant Node_Id := Name (N);
17623 Container_Typ : constant Entity_Id := Base_Type (Etype (Container));
17624 begin
17625 return Is_Array_Type (Container_Typ);
17626 end Is_Iterator_Over_Array;
17628 --------------------------
17629 -- Known_To_Be_Assigned --
17630 --------------------------
17632 function Known_To_Be_Assigned
17633 (N : Node_Id;
17634 Only_LHS : Boolean := False) return Boolean
17636 function Known_Assn (N : Node_Id) return Boolean is
17637 (Known_To_Be_Assigned (N, Only_LHS));
17638 -- Local function to simplify the passing of parameters for recursive
17639 -- calls.
17641 P : constant Node_Id := Parent (N);
17642 Form : Entity_Id := Empty;
17643 Call : Node_Id := Empty;
17645 -- Start of processing for Known_To_Be_Assigned
17647 begin
17648 -- Check for out parameters
17650 Find_Actual (N, Form, Call);
17652 if Present (Form) then
17653 return Ekind (Form) /= E_In_Parameter and then not Only_LHS;
17654 end if;
17656 -- Otherwise look at the parent
17658 case Nkind (P) is
17660 -- Test left side of assignment
17662 when N_Assignment_Statement =>
17663 return N = Name (P);
17665 -- Test prefix of component or attribute. Note that the prefix of an
17666 -- explicit or implicit dereference cannot be an l-value. In the case
17667 -- of a 'Read attribute, the reference can be an actual in the
17668 -- argument list of the attribute.
17670 when N_Attribute_Reference =>
17671 return
17672 not Only_LHS and then
17673 ((N = Prefix (P)
17674 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P)))
17675 or else
17676 Attribute_Name (P) = Name_Read);
17678 -- For an expanded name, the name is an lvalue if the expanded name
17679 -- is an lvalue, but the prefix is never an lvalue, since it is just
17680 -- the scope where the name is found.
17682 when N_Expanded_Name =>
17683 if N = Prefix (P) then
17684 return Known_Assn (P);
17685 else
17686 return False;
17687 end if;
17689 -- For a selected component A.B, A is certainly an lvalue if A.B is.
17690 -- B is a little interesting, if we have A.B := 3, there is some
17691 -- discussion as to whether B is an lvalue or not, we choose to say
17692 -- it is. Note however that A is not an lvalue if it is of an access
17693 -- type since this is an implicit dereference.
17695 when N_Selected_Component =>
17696 if N = Prefix (P)
17697 and then Present (Etype (N))
17698 and then Is_Access_Type (Etype (N))
17699 then
17700 return False;
17701 else
17702 return Known_Assn (P);
17703 end if;
17705 -- For an indexed component or slice, the index or slice bounds is
17706 -- never an lvalue. The prefix is an lvalue if the indexed component
17707 -- or slice is an lvalue, except if it is an access type, where we
17708 -- have an implicit dereference.
17710 when N_Indexed_Component | N_Slice =>
17711 if N /= Prefix (P)
17712 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
17713 then
17714 return False;
17715 else
17716 return Known_Assn (P);
17717 end if;
17719 -- Prefix of a reference is an lvalue if the reference is an lvalue
17721 when N_Reference =>
17722 return Known_Assn (P);
17724 -- Prefix of explicit dereference is never an lvalue
17726 when N_Explicit_Dereference =>
17727 return False;
17729 -- Test for appearing in a conversion that itself appears in an
17730 -- lvalue context, since this should be an lvalue.
17732 when N_Type_Conversion =>
17733 return Known_Assn (P);
17735 -- Test for appearance in object renaming declaration
17737 when N_Object_Renaming_Declaration =>
17738 return not Only_LHS;
17740 -- All other references are definitely not lvalues
17742 when others =>
17743 return False;
17744 end case;
17745 end Known_To_Be_Assigned;
17747 -----------------------------
17748 -- Is_Library_Level_Entity --
17749 -----------------------------
17751 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
17752 begin
17753 -- The following is a small optimization, and it also properly handles
17754 -- discriminals, which in task bodies might appear in expressions before
17755 -- the corresponding procedure has been created, and which therefore do
17756 -- not have an assigned scope.
17758 if Is_Formal (E) then
17759 return False;
17761 -- If we somehow got an empty value for Scope, the tree must be
17762 -- malformed. Rather than blow up we return True in this case.
17764 elsif No (Scope (E)) then
17765 return True;
17767 -- Handle loops since Enclosing_Dynamic_Scope skips them; required to
17768 -- properly handle entities local to quantified expressions in library
17769 -- level specifications.
17771 elsif Ekind (Scope (E)) = E_Loop then
17772 return False;
17773 end if;
17775 -- Normal test is simply that the enclosing dynamic scope is Standard
17777 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
17778 end Is_Library_Level_Entity;
17780 --------------------------------
17781 -- Is_Limited_Class_Wide_Type --
17782 --------------------------------
17784 function Is_Limited_Class_Wide_Type (Typ : Entity_Id) return Boolean is
17785 begin
17786 return
17787 Is_Class_Wide_Type (Typ)
17788 and then (Is_Limited_Type (Typ) or else From_Limited_With (Typ));
17789 end Is_Limited_Class_Wide_Type;
17791 ---------------------------------
17792 -- Is_Local_Variable_Reference --
17793 ---------------------------------
17795 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
17796 begin
17797 if not Is_Entity_Name (Expr) then
17798 return False;
17800 else
17801 declare
17802 Ent : constant Entity_Id := Entity (Expr);
17803 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
17804 begin
17805 if Ekind (Ent)
17806 not in E_Variable | E_In_Out_Parameter | E_Out_Parameter
17807 then
17808 return False;
17809 else
17810 return Present (Sub) and then Sub = Current_Subprogram;
17811 end if;
17812 end;
17813 end if;
17814 end Is_Local_Variable_Reference;
17816 ---------------
17817 -- Is_Master --
17818 ---------------
17820 function Is_Master (N : Node_Id) return Boolean is
17821 Disable_Subexpression_Masters : constant Boolean := True;
17823 begin
17824 if Nkind (N) in N_Subprogram_Body | N_Task_Body | N_Entry_Body
17825 or else Is_Statement (N)
17826 then
17827 return True;
17828 end if;
17830 -- We avoid returning True when the master is a subexpression described
17831 -- in RM 7.6.1(3/2) for the proposes of accessibility level calculation
17832 -- in Accessibility_Level_Helper.Innermost_Master_Scope_Depth ???
17834 if not Disable_Subexpression_Masters
17835 and then Nkind (N) in N_Subexpr
17836 then
17837 declare
17838 Par : Node_Id := N;
17840 subtype N_Simple_Statement_Other_Than_Simple_Return
17841 is Node_Kind with Static_Predicate =>
17842 N_Simple_Statement_Other_Than_Simple_Return
17843 in N_Abort_Statement
17844 | N_Assignment_Statement
17845 | N_Code_Statement
17846 | N_Delay_Statement
17847 | N_Entry_Call_Statement
17848 | N_Free_Statement
17849 | N_Goto_Statement
17850 | N_Null_Statement
17851 | N_Raise_Statement
17852 | N_Requeue_Statement
17853 | N_Exit_Statement
17854 | N_Procedure_Call_Statement;
17855 begin
17856 while Present (Par) loop
17857 Par := Parent (Par);
17858 if Nkind (Par) in N_Subexpr |
17859 N_Simple_Statement_Other_Than_Simple_Return
17860 then
17861 return False;
17862 end if;
17863 end loop;
17865 return True;
17866 end;
17867 end if;
17869 return False;
17870 end Is_Master;
17872 -----------------------
17873 -- Is_Name_Reference --
17874 -----------------------
17876 function Is_Name_Reference (N : Node_Id) return Boolean is
17877 begin
17878 if Is_Entity_Name (N) then
17879 return Present (Entity (N)) and then Is_Object (Entity (N));
17880 end if;
17882 case Nkind (N) is
17883 when N_Indexed_Component
17884 | N_Slice
17886 return
17887 Is_Name_Reference (Prefix (N))
17888 or else Is_Access_Type (Etype (Prefix (N)));
17890 -- Attributes 'Input, 'Old and 'Result produce objects
17892 when N_Attribute_Reference =>
17893 return Attribute_Name (N) in Name_Input | Name_Old | Name_Result;
17895 when N_Selected_Component =>
17896 return
17897 Is_Name_Reference (Selector_Name (N))
17898 and then
17899 (Is_Name_Reference (Prefix (N))
17900 or else Is_Access_Type (Etype (Prefix (N))));
17902 when N_Explicit_Dereference =>
17903 return True;
17905 -- A view conversion of a tagged name is a name reference
17907 when N_Type_Conversion =>
17908 return
17909 Is_Tagged_Type (Etype (Subtype_Mark (N)))
17910 and then Is_Tagged_Type (Etype (Expression (N)))
17911 and then Is_Name_Reference (Expression (N));
17913 -- An unchecked type conversion is considered to be a name if the
17914 -- operand is a name (this construction arises only as a result of
17915 -- expansion activities).
17917 when N_Unchecked_Type_Conversion =>
17918 return Is_Name_Reference (Expression (N));
17920 when others =>
17921 return False;
17922 end case;
17923 end Is_Name_Reference;
17925 --------------------------
17926 -- Is_Newly_Constructed --
17927 --------------------------
17929 function Is_Newly_Constructed
17930 (Exp : Node_Id; Context_Requires_NC : Boolean) return Boolean
17932 Original_Exp : constant Node_Id := Original_Node (Exp);
17934 function Is_NC (Exp : Node_Id) return Boolean is
17935 (Is_Newly_Constructed (Exp, Context_Requires_NC));
17937 -- If the context requires that the expression shall be newly
17938 -- constructed, then "True" is a good result in the sense that the
17939 -- expression satisfies the requirements of the context (and "False"
17940 -- is analogously a bad result). If the context requires that the
17941 -- expression shall *not* be newly constructed, then things are
17942 -- reversed: "False" is the good value and "True" is the bad value.
17944 Good_Result : constant Boolean := Context_Requires_NC;
17945 Bad_Result : constant Boolean := not Good_Result;
17946 begin
17947 case Nkind (Original_Exp) is
17948 when N_Aggregate
17949 | N_Extension_Aggregate
17950 | N_Function_Call
17951 | N_Op
17953 return True;
17955 when N_Identifier =>
17956 return Present (Entity (Original_Exp))
17957 and then Ekind (Entity (Original_Exp)) = E_Function;
17959 when N_Qualified_Expression =>
17960 return Is_NC (Expression (Original_Exp));
17962 when N_Type_Conversion
17963 | N_Unchecked_Type_Conversion
17965 if Is_View_Conversion (Original_Exp) then
17966 return Is_NC (Expression (Original_Exp));
17967 elsif not Comes_From_Source (Exp) then
17968 if Exp /= Original_Exp then
17969 return Is_NC (Original_Exp);
17970 else
17971 return Is_NC (Expression (Original_Exp));
17972 end if;
17973 else
17974 return False;
17975 end if;
17977 when N_Explicit_Dereference
17978 | N_Indexed_Component
17979 | N_Selected_Component
17981 return Nkind (Exp) = N_Function_Call;
17983 -- A use of 'Input is a function call, hence allowed. Normally the
17984 -- attribute will be changed to a call, but the attribute by itself
17985 -- can occur with -gnatc.
17987 when N_Attribute_Reference =>
17988 return Attribute_Name (Original_Exp) = Name_Input;
17990 -- "return raise ..." is OK
17992 when N_Raise_Expression =>
17993 return Good_Result;
17995 -- For a case expression, all dependent expressions must be legal
17997 when N_Case_Expression =>
17998 declare
17999 Alt : Node_Id;
18001 begin
18002 Alt := First (Alternatives (Original_Exp));
18003 while Present (Alt) loop
18004 if Is_NC (Expression (Alt)) = Bad_Result then
18005 return Bad_Result;
18006 end if;
18008 Next (Alt);
18009 end loop;
18011 return Good_Result;
18012 end;
18014 -- For an if expression, all dependent expressions must be legal
18016 when N_If_Expression =>
18017 declare
18018 Then_Expr : constant Node_Id :=
18019 Next (First (Expressions (Original_Exp)));
18020 Else_Expr : constant Node_Id := Next (Then_Expr);
18021 begin
18022 if (Is_NC (Then_Expr) = Bad_Result)
18023 or else (Is_NC (Else_Expr) = Bad_Result)
18024 then
18025 return Bad_Result;
18026 else
18027 return Good_Result;
18028 end if;
18029 end;
18031 when others =>
18032 return False;
18033 end case;
18034 end Is_Newly_Constructed;
18036 ------------------------------------
18037 -- Is_Non_Preelaborable_Construct --
18038 ------------------------------------
18040 function Is_Non_Preelaborable_Construct (N : Node_Id) return Boolean is
18042 -- NOTE: the routines within Is_Non_Preelaborable_Construct are
18043 -- intentionally unnested to avoid deep indentation of code.
18045 Non_Preelaborable : exception;
18046 -- This exception is raised when the construct violates preelaborability
18047 -- to terminate the recursion.
18049 procedure Visit (Nod : Node_Id);
18050 -- Semantically inspect construct Nod to determine whether it violates
18051 -- preelaborability. This routine raises Non_Preelaborable.
18053 procedure Visit_List (List : List_Id);
18054 pragma Inline (Visit_List);
18055 -- Invoke Visit on each element of list List. This routine raises
18056 -- Non_Preelaborable.
18058 procedure Visit_Pragma (Prag : Node_Id);
18059 pragma Inline (Visit_Pragma);
18060 -- Semantically inspect pragma Prag to determine whether it violates
18061 -- preelaborability. This routine raises Non_Preelaborable.
18063 procedure Visit_Subexpression (Expr : Node_Id);
18064 pragma Inline (Visit_Subexpression);
18065 -- Semantically inspect expression Expr to determine whether it violates
18066 -- preelaborability. This routine raises Non_Preelaborable.
18068 -----------
18069 -- Visit --
18070 -----------
18072 procedure Visit (Nod : Node_Id) is
18073 begin
18074 case Nkind (Nod) is
18076 -- Declarations
18078 when N_Component_Declaration =>
18080 -- Defining_Identifier is left out because it is not relevant
18081 -- for preelaborability.
18083 Visit (Component_Definition (Nod));
18084 Visit (Expression (Nod));
18086 when N_Derived_Type_Definition =>
18088 -- Interface_List is left out because it is not relevant for
18089 -- preelaborability.
18091 Visit (Record_Extension_Part (Nod));
18092 Visit (Subtype_Indication (Nod));
18094 when N_Entry_Declaration =>
18096 -- A protected type with at leat one entry is not preelaborable
18097 -- while task types are never preelaborable. This renders entry
18098 -- declarations non-preelaborable.
18100 raise Non_Preelaborable;
18102 when N_Full_Type_Declaration =>
18104 -- Defining_Identifier and Discriminant_Specifications are left
18105 -- out because they are not relevant for preelaborability.
18107 Visit (Type_Definition (Nod));
18109 when N_Function_Instantiation
18110 | N_Package_Instantiation
18111 | N_Procedure_Instantiation
18113 -- Defining_Unit_Name and Name are left out because they are
18114 -- not relevant for preelaborability.
18116 Visit_List (Generic_Associations (Nod));
18118 when N_Object_Declaration =>
18120 -- Defining_Identifier is left out because it is not relevant
18121 -- for preelaborability.
18123 Visit (Object_Definition (Nod));
18125 if Has_Init_Expression (Nod) then
18126 Visit (Expression (Nod));
18128 elsif not Constant_Present (Nod)
18129 and then not Has_Preelaborable_Initialization
18130 (Etype (Defining_Entity (Nod)))
18131 then
18132 raise Non_Preelaborable;
18133 end if;
18135 when N_Private_Extension_Declaration
18136 | N_Subtype_Declaration
18138 -- Defining_Identifier, Discriminant_Specifications, and
18139 -- Interface_List are left out because they are not relevant
18140 -- for preelaborability.
18142 Visit (Subtype_Indication (Nod));
18144 when N_Protected_Type_Declaration
18145 | N_Single_Protected_Declaration
18147 -- Defining_Identifier, Discriminant_Specifications, and
18148 -- Interface_List are left out because they are not relevant
18149 -- for preelaborability.
18151 Visit (Protected_Definition (Nod));
18153 -- A [single] task type is never preelaborable
18155 when N_Single_Task_Declaration
18156 | N_Task_Type_Declaration
18158 raise Non_Preelaborable;
18160 -- Pragmas
18162 when N_Pragma =>
18163 Visit_Pragma (Nod);
18165 -- Statements
18167 when N_Statement_Other_Than_Procedure_Call =>
18168 if Nkind (Nod) /= N_Null_Statement then
18169 raise Non_Preelaborable;
18170 end if;
18172 -- Subexpressions
18174 when N_Subexpr =>
18175 Visit_Subexpression (Nod);
18177 -- Special
18179 when N_Access_To_Object_Definition =>
18180 Visit (Subtype_Indication (Nod));
18182 when N_Case_Expression_Alternative =>
18183 Visit (Expression (Nod));
18184 Visit_List (Discrete_Choices (Nod));
18186 when N_Component_Definition =>
18187 Visit (Access_Definition (Nod));
18188 Visit (Subtype_Indication (Nod));
18190 when N_Component_List =>
18191 Visit_List (Component_Items (Nod));
18192 Visit (Variant_Part (Nod));
18194 when N_Constrained_Array_Definition =>
18195 Visit_List (Discrete_Subtype_Definitions (Nod));
18196 Visit (Component_Definition (Nod));
18198 when N_Delta_Constraint
18199 | N_Digits_Constraint
18201 -- Delta_Expression and Digits_Expression are left out because
18202 -- they are not relevant for preelaborability.
18204 Visit (Range_Constraint (Nod));
18206 when N_Discriminant_Specification =>
18208 -- Defining_Identifier and Expression are left out because they
18209 -- are not relevant for preelaborability.
18211 Visit (Discriminant_Type (Nod));
18213 when N_Generic_Association =>
18215 -- Selector_Name is left out because it is not relevant for
18216 -- preelaborability.
18218 Visit (Explicit_Generic_Actual_Parameter (Nod));
18220 when N_Index_Or_Discriminant_Constraint =>
18221 Visit_List (Constraints (Nod));
18223 when N_Iterator_Specification =>
18225 -- Defining_Identifier is left out because it is not relevant
18226 -- for preelaborability.
18228 Visit (Name (Nod));
18229 Visit (Subtype_Indication (Nod));
18231 when N_Loop_Parameter_Specification =>
18233 -- Defining_Identifier is left out because it is not relevant
18234 -- for preelaborability.
18236 Visit (Discrete_Subtype_Definition (Nod));
18238 when N_Parameter_Association =>
18239 Visit (Explicit_Actual_Parameter (N));
18241 when N_Protected_Definition =>
18243 -- End_Label is left out because it is not relevant for
18244 -- preelaborability.
18246 Visit_List (Private_Declarations (Nod));
18247 Visit_List (Visible_Declarations (Nod));
18249 when N_Range_Constraint =>
18250 Visit (Range_Expression (Nod));
18252 when N_Record_Definition
18253 | N_Variant
18255 -- End_Label, Discrete_Choices, and Interface_List are left out
18256 -- because they are not relevant for preelaborability.
18258 Visit (Component_List (Nod));
18260 when N_Subtype_Indication =>
18262 -- Subtype_Mark is left out because it is not relevant for
18263 -- preelaborability.
18265 Visit (Constraint (Nod));
18267 when N_Unconstrained_Array_Definition =>
18269 -- Subtype_Marks is left out because it is not relevant for
18270 -- preelaborability.
18272 Visit (Component_Definition (Nod));
18274 when N_Variant_Part =>
18276 -- Name is left out because it is not relevant for
18277 -- preelaborability.
18279 Visit_List (Variants (Nod));
18281 -- Default
18283 when others =>
18284 null;
18285 end case;
18286 end Visit;
18288 ----------------
18289 -- Visit_List --
18290 ----------------
18292 procedure Visit_List (List : List_Id) is
18293 Nod : Node_Id;
18295 begin
18296 Nod := First (List);
18297 while Present (Nod) loop
18298 Visit (Nod);
18299 Next (Nod);
18300 end loop;
18301 end Visit_List;
18303 ------------------
18304 -- Visit_Pragma --
18305 ------------------
18307 procedure Visit_Pragma (Prag : Node_Id) is
18308 begin
18309 case Get_Pragma_Id (Prag) is
18310 when Pragma_Assert
18311 | Pragma_Assert_And_Cut
18312 | Pragma_Assume
18313 | Pragma_Async_Readers
18314 | Pragma_Async_Writers
18315 | Pragma_Attribute_Definition
18316 | Pragma_Check
18317 | Pragma_Constant_After_Elaboration
18318 | Pragma_CPU
18319 | Pragma_Deadline_Floor
18320 | Pragma_Dispatching_Domain
18321 | Pragma_Effective_Reads
18322 | Pragma_Effective_Writes
18323 | Pragma_Extensions_Visible
18324 | Pragma_Ghost
18325 | Pragma_Secondary_Stack_Size
18326 | Pragma_Task_Name
18327 | Pragma_Volatile_Function
18329 Visit_List (Pragma_Argument_Associations (Prag));
18331 -- Default
18333 when others =>
18334 null;
18335 end case;
18336 end Visit_Pragma;
18338 -------------------------
18339 -- Visit_Subexpression --
18340 -------------------------
18342 procedure Visit_Subexpression (Expr : Node_Id) is
18343 procedure Visit_Aggregate (Aggr : Node_Id);
18344 pragma Inline (Visit_Aggregate);
18345 -- Semantically inspect aggregate Aggr to determine whether it
18346 -- violates preelaborability.
18348 ---------------------
18349 -- Visit_Aggregate --
18350 ---------------------
18352 procedure Visit_Aggregate (Aggr : Node_Id) is
18353 begin
18354 if not Is_Preelaborable_Aggregate (Aggr) then
18355 raise Non_Preelaborable;
18356 end if;
18357 end Visit_Aggregate;
18359 -- Start of processing for Visit_Subexpression
18361 begin
18362 case Nkind (Expr) is
18363 when N_Allocator
18364 | N_Qualified_Expression
18365 | N_Type_Conversion
18366 | N_Unchecked_Expression
18367 | N_Unchecked_Type_Conversion
18369 -- Subpool_Handle_Name and Subtype_Mark are left out because
18370 -- they are not relevant for preelaborability.
18372 Visit (Expression (Expr));
18374 when N_Aggregate
18375 | N_Extension_Aggregate
18377 Visit_Aggregate (Expr);
18379 when N_Attribute_Reference
18380 | N_Explicit_Dereference
18381 | N_Reference
18383 -- Attribute_Name and Expressions are left out because they are
18384 -- not relevant for preelaborability.
18386 Visit (Prefix (Expr));
18388 when N_Case_Expression =>
18390 -- End_Span is left out because it is not relevant for
18391 -- preelaborability.
18393 Visit_List (Alternatives (Expr));
18394 Visit (Expression (Expr));
18396 when N_Delta_Aggregate =>
18397 Visit_Aggregate (Expr);
18398 Visit (Expression (Expr));
18400 when N_Expression_With_Actions =>
18401 Visit_List (Actions (Expr));
18402 Visit (Expression (Expr));
18404 when N_Function_Call =>
18406 -- Ada 2022 (AI12-0175): Calls to certain functions that are
18407 -- essentially unchecked conversions are preelaborable.
18409 if Ada_Version >= Ada_2022
18410 and then Nkind (Expr) = N_Function_Call
18411 and then Is_Entity_Name (Name (Expr))
18412 and then Is_Preelaborable_Function (Entity (Name (Expr)))
18413 then
18414 Visit_List (Parameter_Associations (Expr));
18415 else
18416 raise Non_Preelaborable;
18417 end if;
18419 when N_If_Expression =>
18420 Visit_List (Expressions (Expr));
18422 when N_Quantified_Expression =>
18423 Visit (Condition (Expr));
18424 Visit (Iterator_Specification (Expr));
18425 Visit (Loop_Parameter_Specification (Expr));
18427 when N_Range =>
18428 Visit (High_Bound (Expr));
18429 Visit (Low_Bound (Expr));
18431 when N_Slice =>
18432 Visit (Discrete_Range (Expr));
18433 Visit (Prefix (Expr));
18435 -- Default
18437 when others =>
18439 -- The evaluation of an object name is not preelaborable,
18440 -- unless the name is a static expression (checked further
18441 -- below), or statically denotes a discriminant.
18443 if Is_Entity_Name (Expr) then
18444 Object_Name : declare
18445 Id : constant Entity_Id := Entity (Expr);
18447 begin
18448 if Is_Object (Id) then
18449 if Ekind (Id) = E_Discriminant then
18450 null;
18452 elsif Ekind (Id) in E_Constant | E_In_Parameter
18453 and then Present (Discriminal_Link (Id))
18454 then
18455 null;
18457 else
18458 raise Non_Preelaborable;
18459 end if;
18460 end if;
18461 end Object_Name;
18463 -- A non-static expression is not preelaborable
18465 elsif not Is_OK_Static_Expression (Expr) then
18466 raise Non_Preelaborable;
18467 end if;
18468 end case;
18469 end Visit_Subexpression;
18471 -- Start of processing for Is_Non_Preelaborable_Construct
18473 begin
18474 Visit (N);
18476 -- At this point it is known that the construct is preelaborable
18478 return False;
18480 exception
18482 -- The elaboration of the construct performs an action which violates
18483 -- preelaborability.
18485 when Non_Preelaborable =>
18486 return True;
18487 end Is_Non_Preelaborable_Construct;
18489 ---------------------------------
18490 -- Is_Nontrivial_DIC_Procedure --
18491 ---------------------------------
18493 function Is_Nontrivial_DIC_Procedure (Id : Entity_Id) return Boolean is
18494 Body_Decl : Node_Id;
18495 Stmt : Node_Id;
18497 begin
18498 if Ekind (Id) = E_Procedure and then Is_DIC_Procedure (Id) then
18499 Body_Decl :=
18500 Unit_Declaration_Node
18501 (Corresponding_Body (Unit_Declaration_Node (Id)));
18503 -- The body of the Default_Initial_Condition procedure must contain
18504 -- at least one statement, otherwise the generation of the subprogram
18505 -- body failed.
18507 pragma Assert (Present (Handled_Statement_Sequence (Body_Decl)));
18509 -- To qualify as nontrivial, the first statement of the procedure
18510 -- must be a check in the form of an if statement. If the original
18511 -- Default_Initial_Condition expression was folded, then the first
18512 -- statement is not a check.
18514 Stmt := First (Statements (Handled_Statement_Sequence (Body_Decl)));
18516 return
18517 Nkind (Stmt) = N_If_Statement
18518 and then Nkind (Original_Node (Stmt)) = N_Pragma;
18519 end if;
18521 return False;
18522 end Is_Nontrivial_DIC_Procedure;
18524 -----------------------
18525 -- Is_Null_Extension --
18526 -----------------------
18528 function Is_Null_Extension
18529 (T : Entity_Id; Ignore_Privacy : Boolean := False) return Boolean
18531 Type_Decl : Node_Id;
18532 Type_Def : Node_Id;
18533 begin
18534 pragma Assert (not Is_Class_Wide_Type (T));
18536 if Ignore_Privacy then
18537 Type_Decl := Parent (Underlying_Type (Base_Type (T)));
18538 else
18539 Type_Decl := Parent (Base_Type (T));
18540 if Nkind (Type_Decl) /= N_Full_Type_Declaration then
18541 return False;
18542 end if;
18543 end if;
18544 pragma Assert (Nkind (Type_Decl) = N_Full_Type_Declaration);
18545 Type_Def := Type_Definition (Type_Decl);
18546 if Present (Discriminant_Specifications (Type_Decl))
18547 or else Nkind (Type_Def) /= N_Derived_Type_Definition
18548 or else not Is_Tagged_Type (T)
18549 or else No (Record_Extension_Part (Type_Def))
18550 then
18551 return False;
18552 end if;
18554 return Is_Null_Record_Definition (Record_Extension_Part (Type_Def));
18555 end Is_Null_Extension;
18557 --------------------------
18558 -- Is_Null_Extension_Of --
18559 --------------------------
18561 function Is_Null_Extension_Of
18562 (Descendant, Ancestor : Entity_Id) return Boolean
18564 Ancestor_Type : constant Entity_Id
18565 := Underlying_Type (Base_Type (Ancestor));
18566 Descendant_Type : Entity_Id := Underlying_Type (Base_Type (Descendant));
18567 begin
18568 pragma Assert (not Is_Class_Wide_Type (Descendant));
18569 pragma Assert (not Is_Class_Wide_Type (Ancestor));
18570 pragma Assert (Descendant_Type /= Ancestor_Type);
18572 while Descendant_Type /= Ancestor_Type loop
18573 if not Is_Null_Extension
18574 (Descendant_Type, Ignore_Privacy => True)
18575 then
18576 return False;
18577 end if;
18578 Descendant_Type := Etype (Subtype_Indication
18579 (Type_Definition (Parent (Descendant_Type))));
18580 Descendant_Type := Underlying_Type (Base_Type (Descendant_Type));
18581 end loop;
18582 return True;
18583 end Is_Null_Extension_Of;
18585 -------------------------------
18586 -- Is_Null_Record_Definition --
18587 -------------------------------
18589 function Is_Null_Record_Definition (Record_Def : Node_Id) return Boolean is
18590 Item : Node_Id;
18591 begin
18592 -- Testing Null_Present is just an optimization, not required.
18594 if Null_Present (Record_Def) then
18595 return True;
18596 elsif Present (Variant_Part (Component_List (Record_Def))) then
18597 return False;
18598 elsif No (Component_List (Record_Def)) then
18599 return True;
18600 end if;
18602 Item := First (Component_Items (Component_List (Record_Def)));
18604 while Present (Item) loop
18605 if Nkind (Item) = N_Component_Declaration
18606 and then Is_Internal_Name (Chars (Defining_Identifier (Item)))
18607 then
18608 null;
18609 elsif Nkind (Item) = N_Pragma then
18610 null;
18611 else
18612 return False;
18613 end if;
18614 Item := Next (Item);
18615 end loop;
18617 return True;
18618 end Is_Null_Record_Definition;
18620 -------------------------
18621 -- Is_Null_Record_Type --
18622 -------------------------
18624 function Is_Null_Record_Type
18625 (T : Entity_Id; Ignore_Privacy : Boolean := False) return Boolean
18627 Decl : Node_Id;
18628 Type_Def : Node_Id;
18629 begin
18630 if not Is_Record_Type (T) then
18631 return False;
18632 end if;
18634 if Ignore_Privacy then
18635 Decl := Parent (Underlying_Type (Base_Type (T)));
18636 else
18637 Decl := Parent (Base_Type (T));
18638 if Nkind (Decl) /= N_Full_Type_Declaration then
18639 return False;
18640 end if;
18641 end if;
18642 pragma Assert (Nkind (Decl) = N_Full_Type_Declaration);
18643 Type_Def := Type_Definition (Decl);
18645 if Has_Discriminants (Defining_Identifier (Decl)) then
18646 return False;
18647 end if;
18649 case Nkind (Type_Def) is
18650 when N_Record_Definition =>
18651 return Is_Null_Record_Definition (Type_Def);
18652 when N_Derived_Type_Definition =>
18653 if not Is_Null_Record_Type
18654 (Etype (Subtype_Indication (Type_Def)),
18655 Ignore_Privacy => Ignore_Privacy)
18656 then
18657 return False;
18658 elsif not Is_Tagged_Type (T) then
18659 return True;
18660 else
18661 return Is_Null_Extension (T, Ignore_Privacy => Ignore_Privacy);
18662 end if;
18663 when others =>
18664 return False;
18665 end case;
18666 end Is_Null_Record_Type;
18668 ---------------------
18669 -- Is_Object_Image --
18670 ---------------------
18672 function Is_Object_Image (Prefix : Node_Id) return Boolean is
18673 begin
18674 -- Here we test for the case that the prefix is not a type and assume
18675 -- if it is not then it must be a named value or an object reference.
18676 -- This is because the parser always checks that prefixes of attributes
18677 -- are named.
18679 return not (Is_Entity_Name (Prefix)
18680 and then Is_Type (Entity (Prefix))
18681 and then not Is_Current_Instance (Prefix));
18682 end Is_Object_Image;
18684 -------------------------
18685 -- Is_Object_Reference --
18686 -------------------------
18688 function Is_Object_Reference (N : Node_Id) return Boolean is
18689 function Safe_Prefix (N : Node_Id) return Node_Id;
18690 -- Return Prefix (N) unless it has been rewritten as an
18691 -- N_Raise_xxx_Error node, in which case return its original node.
18693 -----------------
18694 -- Safe_Prefix --
18695 -----------------
18697 function Safe_Prefix (N : Node_Id) return Node_Id is
18698 begin
18699 if Nkind (Prefix (N)) in N_Raise_xxx_Error then
18700 return Original_Node (Prefix (N));
18701 else
18702 return Prefix (N);
18703 end if;
18704 end Safe_Prefix;
18706 begin
18707 -- AI12-0068: Note that a current instance reference in a type or
18708 -- subtype's aspect_specification is considered a value, not an object
18709 -- (see RM 8.6(18/5)).
18711 if Is_Entity_Name (N) then
18712 return Present (Entity (N)) and then Is_Object (Entity (N))
18713 and then not Is_Current_Instance_Reference_In_Type_Aspect (N);
18715 else
18716 case Nkind (N) is
18717 when N_Indexed_Component
18718 | N_Slice
18720 return
18721 Is_Object_Reference (Safe_Prefix (N))
18722 or else Is_Access_Type (Etype (Safe_Prefix (N)));
18724 -- In Ada 95, a function call is a constant object; a procedure
18725 -- call is not.
18727 -- Note that predefined operators are functions as well, and so
18728 -- are attributes that are (can be renamed as) functions.
18730 when N_Function_Call
18731 | N_Op
18733 return Etype (N) /= Standard_Void_Type;
18735 -- Attributes references 'Loop_Entry, 'Old, 'Priority and 'Result
18736 -- yield objects, even though they are not functions.
18738 when N_Attribute_Reference =>
18739 return
18740 Attribute_Name (N) in Name_Loop_Entry
18741 | Name_Old
18742 | Name_Priority
18743 | Name_Result
18744 or else Is_Function_Attribute_Name (Attribute_Name (N));
18746 when N_Selected_Component =>
18747 return
18748 Is_Object_Reference (Selector_Name (N))
18749 and then
18750 (Is_Object_Reference (Safe_Prefix (N))
18751 or else Is_Access_Type (Etype (Safe_Prefix (N))));
18753 -- An explicit dereference denotes an object, except that a
18754 -- conditional expression gets turned into an explicit dereference
18755 -- in some cases, and conditional expressions are not object
18756 -- names.
18758 when N_Explicit_Dereference =>
18759 return Nkind (Original_Node (N)) not in
18760 N_Case_Expression | N_If_Expression;
18762 -- A view conversion of a tagged object is an object reference
18764 when N_Type_Conversion =>
18765 if Ada_Version <= Ada_2012 then
18766 -- A view conversion of a tagged object is an object
18767 -- reference.
18768 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
18769 and then Is_Tagged_Type (Etype (Expression (N)))
18770 and then Is_Object_Reference (Expression (N));
18772 else
18773 -- AI12-0226: In Ada 2022 a value conversion of an object is
18774 -- an object.
18776 return Is_Object_Reference (Expression (N));
18777 end if;
18779 -- An unchecked type conversion is considered to be an object if
18780 -- the operand is an object (this construction arises only as a
18781 -- result of expansion activities).
18783 when N_Unchecked_Type_Conversion =>
18784 return True;
18786 -- AI05-0003: In Ada 2012 a qualified expression is a name.
18787 -- This allows disambiguation of function calls and the use
18788 -- of aggregates in more contexts.
18790 when N_Qualified_Expression =>
18791 return Ada_Version >= Ada_2012
18792 and then Is_Object_Reference (Expression (N));
18794 -- In Ada 95 an aggregate is an object reference
18796 when N_Aggregate
18797 | N_Delta_Aggregate
18798 | N_Extension_Aggregate
18800 return Ada_Version >= Ada_95;
18802 -- A string literal is not an object reference, but it might come
18803 -- from rewriting of an object reference, e.g. from folding of an
18804 -- aggregate.
18806 when N_String_Literal =>
18807 return Is_Rewrite_Substitution (N)
18808 and then Is_Object_Reference (Original_Node (N));
18810 -- AI12-0125: Target name represents a constant object
18812 when N_Target_Name =>
18813 return True;
18815 when others =>
18816 return False;
18817 end case;
18818 end if;
18819 end Is_Object_Reference;
18821 -----------------------------------
18822 -- Is_OK_Variable_For_Out_Formal --
18823 -----------------------------------
18825 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
18826 begin
18827 Note_Possible_Modification (AV, Sure => True);
18829 -- We must reject parenthesized variable names. Comes_From_Source is
18830 -- checked because there are currently cases where the compiler violates
18831 -- this rule (e.g. passing a task object to its controlled Initialize
18832 -- routine). This should be properly documented in sinfo???
18834 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
18835 return False;
18837 -- A variable is always allowed
18839 elsif Is_Variable (AV) then
18840 return True;
18842 -- Generalized indexing operations are rewritten as explicit
18843 -- dereferences, and it is only during resolution that we can
18844 -- check whether the context requires an access_to_variable type.
18846 elsif Nkind (AV) = N_Explicit_Dereference
18847 and then Present (Etype (Original_Node (AV)))
18848 and then Has_Implicit_Dereference (Etype (Original_Node (AV)))
18849 and then Ada_Version >= Ada_2012
18850 then
18851 return not Is_Access_Constant (Etype (Prefix (AV)));
18853 -- Unchecked conversions are allowed only if they come from the
18854 -- generated code, which sometimes uses unchecked conversions for out
18855 -- parameters in cases where code generation is unaffected. We tell
18856 -- source unchecked conversions by seeing if they are rewrites of
18857 -- an original Unchecked_Conversion function call, or of an explicit
18858 -- conversion of a function call or an aggregate (as may happen in the
18859 -- expansion of a packed array aggregate).
18861 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
18862 if Nkind (Original_Node (AV)) in N_Function_Call | N_Aggregate then
18863 return False;
18865 elsif Nkind (Original_Node (Expression (AV))) = N_Function_Call then
18866 return False;
18868 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
18869 return Is_OK_Variable_For_Out_Formal (Expression (AV));
18871 else
18872 return True;
18873 end if;
18875 -- Normal type conversions are allowed if argument is a variable
18877 elsif Nkind (AV) = N_Type_Conversion then
18878 if Is_Variable (Expression (AV))
18879 and then Paren_Count (Expression (AV)) = 0
18880 then
18881 Note_Possible_Modification (Expression (AV), Sure => True);
18882 return True;
18884 -- We also allow a non-parenthesized expression that raises
18885 -- constraint error if it rewrites what used to be a variable
18887 elsif Raises_Constraint_Error (Expression (AV))
18888 and then Paren_Count (Expression (AV)) = 0
18889 and then Is_Variable (Original_Node (Expression (AV)))
18890 then
18891 return True;
18893 -- Type conversion of something other than a variable
18895 else
18896 return False;
18897 end if;
18899 -- If this node is rewritten, then test the original form, if that is
18900 -- OK, then we consider the rewritten node OK (for example, if the
18901 -- original node is a conversion, then Is_Variable will not be true
18902 -- but we still want to allow the conversion if it converts a variable).
18904 elsif Is_Rewrite_Substitution (AV) then
18905 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
18907 -- All other non-variables are rejected
18909 else
18910 return False;
18911 end if;
18912 end Is_OK_Variable_For_Out_Formal;
18914 ----------------------------
18915 -- Is_OK_Volatile_Context --
18916 ----------------------------
18918 function Is_OK_Volatile_Context
18919 (Context : Node_Id;
18920 Obj_Ref : Node_Id;
18921 Check_Actuals : Boolean) return Boolean
18923 function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean;
18924 -- Determine whether an arbitrary node denotes a call to a protected
18925 -- entry, function, or procedure in prefixed form where the prefix is
18926 -- Obj_Ref.
18928 function Within_Check (Nod : Node_Id) return Boolean;
18929 -- Determine whether an arbitrary node appears in a check node
18931 function Within_Volatile_Function (Id : Entity_Id) return Boolean;
18932 -- Determine whether an arbitrary entity appears in a volatile function
18934 ---------------------------------
18935 -- Is_Protected_Operation_Call --
18936 ---------------------------------
18938 function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean is
18939 Pref : Node_Id;
18940 Subp : Node_Id;
18942 begin
18943 -- A call to a protected operations retains its selected component
18944 -- form as opposed to other prefixed calls that are transformed in
18945 -- expanded names.
18947 if Nkind (Nod) = N_Selected_Component then
18948 Pref := Prefix (Nod);
18949 Subp := Selector_Name (Nod);
18951 return
18952 Pref = Obj_Ref
18953 and then Present (Etype (Pref))
18954 and then Is_Protected_Type (Etype (Pref))
18955 and then Is_Entity_Name (Subp)
18956 and then Present (Entity (Subp))
18957 and then Ekind (Entity (Subp)) in
18958 E_Entry | E_Entry_Family | E_Function | E_Procedure;
18959 else
18960 return False;
18961 end if;
18962 end Is_Protected_Operation_Call;
18964 ------------------
18965 -- Within_Check --
18966 ------------------
18968 function Within_Check (Nod : Node_Id) return Boolean is
18969 Par : Node_Id;
18971 begin
18972 -- Climb the parent chain looking for a check node
18974 Par := Nod;
18975 while Present (Par) loop
18976 if Nkind (Par) in N_Raise_xxx_Error then
18977 return True;
18979 -- Prevent the search from going too far
18981 elsif Is_Body_Or_Package_Declaration (Par) then
18982 exit;
18983 end if;
18985 Par := Parent (Par);
18986 end loop;
18988 return False;
18989 end Within_Check;
18991 ------------------------------
18992 -- Within_Volatile_Function --
18993 ------------------------------
18995 function Within_Volatile_Function (Id : Entity_Id) return Boolean is
18996 pragma Assert (Ekind (Id) = E_Return_Statement);
18998 Func_Id : constant Entity_Id := Return_Applies_To (Id);
19000 begin
19001 pragma Assert (Ekind (Func_Id) in E_Function | E_Generic_Function);
19003 return Is_Volatile_Function (Func_Id);
19004 end Within_Volatile_Function;
19006 -- Local variables
19008 Obj_Id : Entity_Id;
19010 -- Start of processing for Is_OK_Volatile_Context
19012 begin
19013 -- Ignore context restriction when doing preanalysis, e.g. on a copy of
19014 -- an expression function, because this copy is not fully decorated and
19015 -- it is not possible to reliably decide the legality of the context.
19016 -- Any violations will be reported anyway when doing the full analysis.
19018 if not Full_Analysis then
19019 return True;
19020 end if;
19022 -- For actual parameters within explicit parameter associations switch
19023 -- the context to the corresponding subprogram call.
19025 if Nkind (Context) = N_Parameter_Association then
19026 return Is_OK_Volatile_Context (Context => Parent (Context),
19027 Obj_Ref => Obj_Ref,
19028 Check_Actuals => Check_Actuals);
19030 -- The volatile object appears on either side of an assignment
19032 elsif Nkind (Context) = N_Assignment_Statement then
19033 return True;
19035 -- The volatile object is part of the initialization expression of
19036 -- another object.
19038 elsif Nkind (Context) = N_Object_Declaration
19039 and then Present (Expression (Context))
19040 and then Expression (Context) = Obj_Ref
19041 and then Nkind (Parent (Context)) /= N_Expression_With_Actions
19042 then
19043 Obj_Id := Defining_Entity (Context);
19045 -- The volatile object acts as the initialization expression of an
19046 -- extended return statement. This is valid context as long as the
19047 -- function is volatile.
19049 if Is_Return_Object (Obj_Id) then
19050 return Within_Volatile_Function (Scope (Obj_Id));
19052 -- Otherwise this is a normal object initialization
19054 else
19055 return True;
19056 end if;
19058 -- The volatile object acts as the name of a renaming declaration
19060 elsif Nkind (Context) = N_Object_Renaming_Declaration
19061 and then Name (Context) = Obj_Ref
19062 then
19063 return True;
19065 -- The volatile object appears as an actual parameter in a call to an
19066 -- instance of Unchecked_Conversion whose result is renamed.
19068 elsif Nkind (Context) = N_Function_Call
19069 and then Is_Entity_Name (Name (Context))
19070 and then Is_Unchecked_Conversion_Instance (Entity (Name (Context)))
19071 and then Nkind (Parent (Context)) = N_Object_Renaming_Declaration
19072 then
19073 return True;
19075 -- The volatile object is actually the prefix in a protected entry,
19076 -- function, or procedure call.
19078 elsif Is_Protected_Operation_Call (Context) then
19079 return True;
19081 -- The volatile object appears as the expression of a simple return
19082 -- statement that applies to a volatile function.
19084 elsif Nkind (Context) = N_Simple_Return_Statement
19085 and then Expression (Context) = Obj_Ref
19086 then
19087 return
19088 Within_Volatile_Function (Return_Statement_Entity (Context));
19090 -- The volatile object appears as the prefix of a name occurring in a
19091 -- non-interfering context.
19093 elsif Nkind (Context) in
19094 N_Attribute_Reference |
19095 N_Explicit_Dereference |
19096 N_Indexed_Component |
19097 N_Selected_Component |
19098 N_Slice
19099 and then Prefix (Context) = Obj_Ref
19100 and then Is_OK_Volatile_Context
19101 (Context => Parent (Context),
19102 Obj_Ref => Context,
19103 Check_Actuals => Check_Actuals)
19104 then
19105 return True;
19107 -- The volatile object appears as the prefix of attributes Address,
19108 -- Alignment, Component_Size, First, First_Bit, Last, Last_Bit, Length,
19109 -- Position, Size, Storage_Size.
19111 elsif Nkind (Context) = N_Attribute_Reference
19112 and then Prefix (Context) = Obj_Ref
19113 and then Attribute_Name (Context) in Name_Address
19114 | Name_Alignment
19115 | Name_Component_Size
19116 | Name_First
19117 | Name_First_Bit
19118 | Name_Last
19119 | Name_Last_Bit
19120 | Name_Length
19121 | Name_Position
19122 | Name_Size
19123 | Name_Storage_Size
19124 then
19125 return True;
19127 -- The volatile object appears as the expression of a type conversion
19128 -- occurring in a non-interfering context.
19130 elsif Nkind (Context) in N_Qualified_Expression
19131 | N_Type_Conversion
19132 | N_Unchecked_Type_Conversion
19133 and then Expression (Context) = Obj_Ref
19134 and then Is_OK_Volatile_Context
19135 (Context => Parent (Context),
19136 Obj_Ref => Context,
19137 Check_Actuals => Check_Actuals)
19138 then
19139 return True;
19141 -- The volatile object appears as the expression in a delay statement
19143 elsif Nkind (Context) in N_Delay_Statement then
19144 return True;
19146 -- Allow references to volatile objects in various checks. This is not a
19147 -- direct SPARK 2014 requirement.
19149 elsif Within_Check (Context) then
19150 return True;
19152 -- References to effectively volatile objects that appear as actual
19153 -- parameters in subprogram calls can be examined only after call itself
19154 -- has been resolved. Before that, assume such references to be legal.
19156 elsif Nkind (Context) in N_Subprogram_Call | N_Entry_Call_Statement then
19157 if Check_Actuals then
19158 declare
19159 Call : Node_Id;
19160 Formal : Entity_Id;
19161 Subp : constant Entity_Id := Get_Called_Entity (Context);
19162 begin
19163 Find_Actual (Obj_Ref, Formal, Call);
19164 pragma Assert (Call = Context);
19166 -- An effectively volatile object may act as an actual when the
19167 -- corresponding formal is of a non-scalar effectively volatile
19168 -- type (SPARK RM 7.1.3(10)).
19170 if not Is_Scalar_Type (Etype (Formal))
19171 and then Is_Effectively_Volatile_For_Reading (Etype (Formal))
19172 then
19173 return True;
19175 -- An effectively volatile object may act as an actual in a
19176 -- call to an instance of Unchecked_Conversion. (SPARK RM
19177 -- 7.1.3(10)).
19179 elsif Is_Unchecked_Conversion_Instance (Subp) then
19180 return True;
19182 else
19183 return False;
19184 end if;
19185 end;
19186 else
19187 return True;
19188 end if;
19189 else
19190 return False;
19191 end if;
19192 end Is_OK_Volatile_Context;
19194 ------------------------------------
19195 -- Is_Package_Contract_Annotation --
19196 ------------------------------------
19198 function Is_Package_Contract_Annotation (Item : Node_Id) return Boolean is
19199 Nam : Name_Id;
19201 begin
19202 if Nkind (Item) = N_Aspect_Specification then
19203 Nam := Chars (Identifier (Item));
19205 else pragma Assert (Nkind (Item) = N_Pragma);
19206 Nam := Pragma_Name (Item);
19207 end if;
19209 return Nam = Name_Abstract_State
19210 or else Nam = Name_Initial_Condition
19211 or else Nam = Name_Initializes
19212 or else Nam = Name_Refined_State;
19213 end Is_Package_Contract_Annotation;
19215 -----------------------------------
19216 -- Is_Partially_Initialized_Type --
19217 -----------------------------------
19219 function Is_Partially_Initialized_Type
19220 (Typ : Entity_Id;
19221 Include_Implicit : Boolean := True) return Boolean
19223 begin
19224 if Is_Scalar_Type (Typ) then
19225 return Has_Default_Aspect (Base_Type (Typ));
19227 elsif Is_Access_Type (Typ) then
19228 return Include_Implicit;
19230 elsif Is_Array_Type (Typ) then
19232 -- If component type is partially initialized, so is array type
19234 if Has_Default_Aspect (Base_Type (Typ))
19235 or else Is_Partially_Initialized_Type
19236 (Component_Type (Typ), Include_Implicit)
19237 then
19238 return True;
19240 -- Otherwise we are only partially initialized if we are fully
19241 -- initialized (this is the empty array case, no point in us
19242 -- duplicating that code here).
19244 else
19245 return Is_Fully_Initialized_Type (Typ);
19246 end if;
19248 elsif Is_Record_Type (Typ) then
19250 -- A discriminated type is always partially initialized if in
19251 -- all mode
19253 if Has_Discriminants (Typ) and then Include_Implicit then
19254 return True;
19256 -- A tagged type is always partially initialized
19258 elsif Is_Tagged_Type (Typ) then
19259 return True;
19261 -- Case of nondiscriminated record
19263 else
19264 declare
19265 Comp : Entity_Id;
19267 Component_Present : Boolean := False;
19268 -- Set True if at least one component is present. If no
19269 -- components are present, then record type is fully
19270 -- initialized (another odd case, like the null array).
19272 begin
19273 -- Loop through components
19275 Comp := First_Component (Typ);
19276 while Present (Comp) loop
19277 Component_Present := True;
19279 -- If a component has an initialization expression then the
19280 -- enclosing record type is partially initialized
19282 if Present (Parent (Comp))
19283 and then Present (Expression (Parent (Comp)))
19284 then
19285 return True;
19287 -- If a component is of a type which is itself partially
19288 -- initialized, then the enclosing record type is also.
19290 elsif Is_Partially_Initialized_Type
19291 (Etype (Comp), Include_Implicit)
19292 then
19293 return True;
19294 end if;
19296 Next_Component (Comp);
19297 end loop;
19299 -- No initialized components found. If we found any components
19300 -- they were all uninitialized so the result is false.
19302 if Component_Present then
19303 return False;
19305 -- But if we found no components, then all the components are
19306 -- initialized so we consider the type to be initialized.
19308 else
19309 return True;
19310 end if;
19311 end;
19312 end if;
19314 -- Concurrent types are always fully initialized
19316 elsif Is_Concurrent_Type (Typ) then
19317 return True;
19319 -- For a private type, go to underlying type. If there is no underlying
19320 -- type then just assume this partially initialized. Not clear if this
19321 -- can happen in a non-error case, but no harm in testing for this.
19323 elsif Is_Private_Type (Typ) then
19324 declare
19325 U : constant Entity_Id := Underlying_Type (Typ);
19326 begin
19327 if No (U) then
19328 return True;
19329 else
19330 return Is_Partially_Initialized_Type (U, Include_Implicit);
19331 end if;
19332 end;
19334 -- For any other type (are there any?) assume partially initialized
19336 else
19337 return True;
19338 end if;
19339 end Is_Partially_Initialized_Type;
19341 ------------------------------------
19342 -- Is_Potentially_Persistent_Type --
19343 ------------------------------------
19345 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
19346 Comp : Entity_Id;
19347 Indx : Node_Id;
19349 begin
19350 -- For private type, test corresponding full type
19352 if Is_Private_Type (T) then
19353 return Is_Potentially_Persistent_Type (Full_View (T));
19355 -- Scalar types are potentially persistent
19357 elsif Is_Scalar_Type (T) then
19358 return True;
19360 -- Record type is potentially persistent if not tagged and the types of
19361 -- all it components are potentially persistent, and no component has
19362 -- an initialization expression.
19364 elsif Is_Record_Type (T)
19365 and then not Is_Tagged_Type (T)
19366 and then not Is_Partially_Initialized_Type (T)
19367 then
19368 Comp := First_Component (T);
19369 while Present (Comp) loop
19370 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
19371 return False;
19372 else
19373 Next_Entity (Comp);
19374 end if;
19375 end loop;
19377 return True;
19379 -- Array type is potentially persistent if its component type is
19380 -- potentially persistent and if all its constraints are static.
19382 elsif Is_Array_Type (T) then
19383 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
19384 return False;
19385 end if;
19387 Indx := First_Index (T);
19388 while Present (Indx) loop
19389 if not Is_OK_Static_Subtype (Etype (Indx)) then
19390 return False;
19391 else
19392 Next_Index (Indx);
19393 end if;
19394 end loop;
19396 return True;
19398 -- All other types are not potentially persistent
19400 else
19401 return False;
19402 end if;
19403 end Is_Potentially_Persistent_Type;
19405 --------------------------------
19406 -- Is_Potentially_Unevaluated --
19407 --------------------------------
19409 function Is_Potentially_Unevaluated (N : Node_Id) return Boolean is
19410 function Has_Null_Others_Choice (Aggr : Node_Id) return Boolean;
19411 -- Aggr is an array aggregate with static bounds and an others clause;
19412 -- return True if the others choice of the given array aggregate does
19413 -- not cover any component (i.e. is null).
19415 function Immediate_Context_Implies_Is_Potentially_Unevaluated
19416 (Expr : Node_Id) return Boolean;
19417 -- Return True if the *immediate* context of this expression tells us
19418 -- that it is potentially unevaluated; return False if the *immediate*
19419 -- context doesn't provide an answer to this question and we need to
19420 -- keep looking.
19422 function Non_Static_Or_Null_Range (N : Node_Id) return Boolean;
19423 -- Return True if the given range is nonstatic or null
19425 ----------------------------
19426 -- Has_Null_Others_Choice --
19427 ----------------------------
19429 function Has_Null_Others_Choice (Aggr : Node_Id) return Boolean is
19430 Idx : constant Node_Id := First_Index (Etype (Aggr));
19431 Hiv : constant Uint := Expr_Value (Type_High_Bound (Etype (Idx)));
19432 Lov : constant Uint := Expr_Value (Type_Low_Bound (Etype (Idx)));
19434 begin
19435 declare
19436 Intervals : constant Interval_Lists.Discrete_Interval_List :=
19437 Interval_Lists.Aggregate_Intervals (Aggr);
19439 begin
19440 -- The others choice is null if, after normalization, we
19441 -- have a single interval covering the whole aggregate.
19443 return Intervals'Length = 1
19444 and then
19445 Intervals (Intervals'First).Low = Lov
19446 and then
19447 Intervals (Intervals'First).High = Hiv;
19448 end;
19450 -- If the aggregate is malformed (that is, indexes are not disjoint)
19451 -- then no action is needed at this stage; the error will be reported
19452 -- later by the frontend.
19454 exception
19455 when Interval_Lists.Intervals_Error =>
19456 return False;
19457 end Has_Null_Others_Choice;
19459 ----------------------------------------------------------
19460 -- Immediate_Context_Implies_Is_Potentially_Unevaluated --
19461 ----------------------------------------------------------
19463 function Immediate_Context_Implies_Is_Potentially_Unevaluated
19464 (Expr : Node_Id) return Boolean
19466 Par : constant Node_Id := Parent (Expr);
19468 function Aggregate_Type return Node_Id is (Etype (Parent (Par)));
19469 begin
19470 if Nkind (Par) = N_If_Expression then
19471 return Is_Elsif (Par) or else Expr /= First (Expressions (Par));
19473 elsif Nkind (Par) = N_Case_Expression then
19474 return Expr /= Expression (Par);
19476 elsif Nkind (Par) in N_And_Then | N_Or_Else then
19477 return Expr = Right_Opnd (Par);
19479 elsif Nkind (Par) in N_In | N_Not_In then
19481 -- If the membership includes several alternatives, only the first
19482 -- is definitely evaluated.
19484 if Present (Alternatives (Par)) then
19485 return Expr /= First (Alternatives (Par));
19487 -- If this is a range membership both bounds are evaluated
19489 else
19490 return False;
19491 end if;
19493 elsif Nkind (Par) = N_Quantified_Expression then
19494 return Expr = Condition (Par);
19496 elsif Nkind (Par) = N_Component_Association
19497 and then Expr = Expression (Par)
19498 and then Nkind (Parent (Par))
19499 in N_Aggregate | N_Delta_Aggregate | N_Extension_Aggregate
19500 and then Present (Aggregate_Type)
19501 and then Aggregate_Type /= Any_Composite
19502 then
19503 if Is_Array_Type (Aggregate_Type) then
19504 if Ada_Version >= Ada_2022 then
19505 -- For Ada 2022, this predicate returns True for
19506 -- any "repeatedly evaluated" expression.
19507 return True;
19508 end if;
19510 declare
19511 Choice : Node_Id;
19512 In_Others_Choice : Boolean := False;
19513 Array_Agg : constant Node_Id := Parent (Par);
19514 begin
19515 -- The expression of an array_component_association is
19516 -- potentially unevaluated if the associated choice is a
19517 -- subtype_indication or range that defines a nonstatic or
19518 -- null range.
19520 Choice := First (Choices (Par));
19521 while Present (Choice) loop
19522 if Nkind (Choice) = N_Range
19523 and then Non_Static_Or_Null_Range (Choice)
19524 then
19525 return True;
19527 elsif Nkind (Choice) = N_Identifier
19528 and then Present (Scalar_Range (Etype (Choice)))
19529 and then
19530 Non_Static_Or_Null_Range
19531 (Scalar_Range (Etype (Choice)))
19532 then
19533 return True;
19535 elsif Nkind (Choice) = N_Others_Choice then
19536 In_Others_Choice := True;
19537 end if;
19539 Next (Choice);
19540 end loop;
19542 -- It is also potentially unevaluated if the associated
19543 -- choice is an others choice and the applicable index
19544 -- constraint is nonstatic or null.
19546 if In_Others_Choice then
19547 if not Compile_Time_Known_Bounds (Aggregate_Type) then
19548 return True;
19549 else
19550 return Has_Null_Others_Choice (Array_Agg);
19551 end if;
19552 end if;
19553 end;
19555 elsif Is_Container_Aggregate (Parent (Par)) then
19556 -- a component of a container aggregate
19557 return True;
19558 end if;
19560 return False;
19562 else
19563 return False;
19564 end if;
19565 end Immediate_Context_Implies_Is_Potentially_Unevaluated;
19567 ------------------------------
19568 -- Non_Static_Or_Null_Range --
19569 ------------------------------
19571 function Non_Static_Or_Null_Range (N : Node_Id) return Boolean is
19572 Low, High : Node_Id;
19574 begin
19575 Get_Index_Bounds (N, Low, High);
19577 -- Check static bounds
19579 if not Compile_Time_Known_Value (Low)
19580 or else not Compile_Time_Known_Value (High)
19581 then
19582 return True;
19584 -- Check null range
19586 elsif Expr_Value (High) < Expr_Value (Low) then
19587 return True;
19588 end if;
19590 return False;
19591 end Non_Static_Or_Null_Range;
19593 -- Local variables
19595 Par : Node_Id;
19596 Expr : Node_Id;
19598 -- Start of processing for Is_Potentially_Unevaluated
19600 begin
19601 Expr := N;
19602 Par := N;
19604 -- A postcondition whose expression is a short-circuit is broken down
19605 -- into individual aspects for better exception reporting. The original
19606 -- short-circuit expression is rewritten as the second operand, and an
19607 -- occurrence of 'Old in that operand is potentially unevaluated.
19608 -- See sem_ch13.adb for details of this transformation. The reference
19609 -- to 'Old may appear within an expression, so we must look for the
19610 -- enclosing pragma argument in the tree that contains the reference.
19612 while Present (Par)
19613 and then Nkind (Par) /= N_Pragma_Argument_Association
19614 loop
19615 if Is_Rewrite_Substitution (Par)
19616 and then Nkind (Original_Node (Par)) = N_And_Then
19617 then
19618 return True;
19619 end if;
19621 Par := Parent (Par);
19622 end loop;
19624 -- Other cases; 'Old appears within other expression (not the top-level
19625 -- conjunct in a postcondition) with a potentially unevaluated operand.
19627 Par := Parent (Expr);
19629 while Present (Par)
19630 and then Nkind (Par) /= N_Pragma_Argument_Association
19631 loop
19632 if Comes_From_Source (Par)
19633 and then
19634 Immediate_Context_Implies_Is_Potentially_Unevaluated (Expr)
19635 then
19636 return True;
19638 -- For component associations continue climbing; it may be part of
19639 -- an array aggregate.
19641 elsif Nkind (Par) = N_Component_Association then
19642 null;
19644 -- If the context is not an expression, or if is the result of
19645 -- expansion of an enclosing construct (such as another attribute)
19646 -- the predicate does not apply.
19648 elsif Nkind (Par) = N_Case_Expression_Alternative then
19649 null;
19651 elsif Nkind (Par) not in N_Subexpr
19652 or else not Comes_From_Source (Par)
19653 then
19654 return False;
19655 end if;
19657 Expr := Par;
19658 Par := Parent (Par);
19659 end loop;
19661 return False;
19662 end Is_Potentially_Unevaluated;
19664 -----------------------------------------
19665 -- Is_Predefined_Dispatching_Operation --
19666 -----------------------------------------
19668 function Is_Predefined_Dispatching_Operation
19669 (E : Entity_Id) return Boolean
19671 TSS_Name : TSS_Name_Type;
19673 begin
19674 if not Is_Dispatching_Operation (E) then
19675 return False;
19676 end if;
19678 Get_Name_String (Chars (E));
19680 -- Most predefined primitives have internally generated names. Equality
19681 -- must be treated differently; the predefined operation is recognized
19682 -- as a homogeneous binary operator that returns Boolean.
19684 if Name_Len > TSS_Name_Type'Last then
19685 TSS_Name :=
19686 TSS_Name_Type
19687 (Name_Buffer (Name_Len - TSS_Name'Length + 1 .. Name_Len));
19689 if Chars (E) in Name_uAssign | Name_uSize
19690 or else
19691 (Chars (E) = Name_Op_Eq
19692 and then Etype (First_Formal (E)) = Etype (Last_Formal (E)))
19693 or else TSS_Name = TSS_Deep_Adjust
19694 or else TSS_Name = TSS_Deep_Finalize
19695 or else TSS_Name = TSS_Stream_Input
19696 or else TSS_Name = TSS_Stream_Output
19697 or else TSS_Name = TSS_Stream_Read
19698 or else TSS_Name = TSS_Stream_Write
19699 or else TSS_Name = TSS_Put_Image
19700 or else Is_Predefined_Interface_Primitive (E)
19701 then
19702 return True;
19703 end if;
19704 end if;
19706 return False;
19707 end Is_Predefined_Dispatching_Operation;
19709 ---------------------------------------
19710 -- Is_Predefined_Interface_Primitive --
19711 ---------------------------------------
19713 function Is_Predefined_Interface_Primitive (E : Entity_Id) return Boolean is
19714 begin
19715 -- In VM targets we don't restrict the functionality of this test to
19716 -- compiling in Ada 2005 mode since in VM targets any tagged type has
19717 -- these primitives.
19719 return (Ada_Version >= Ada_2005 or else not Tagged_Type_Expansion)
19720 and then Chars (E) in Name_uDisp_Asynchronous_Select
19721 | Name_uDisp_Conditional_Select
19722 | Name_uDisp_Get_Prim_Op_Kind
19723 | Name_uDisp_Get_Task_Id
19724 | Name_uDisp_Requeue
19725 | Name_uDisp_Timed_Select;
19726 end Is_Predefined_Interface_Primitive;
19728 ---------------------------------------
19729 -- Is_Predefined_Internal_Operation --
19730 ---------------------------------------
19732 function Is_Predefined_Internal_Operation
19733 (E : Entity_Id) return Boolean
19735 TSS_Name : TSS_Name_Type;
19737 begin
19738 if not Is_Dispatching_Operation (E) then
19739 return False;
19740 end if;
19742 Get_Name_String (Chars (E));
19744 -- Most predefined primitives have internally generated names. Equality
19745 -- must be treated differently; the predefined operation is recognized
19746 -- as a homogeneous binary operator that returns Boolean.
19748 if Name_Len > TSS_Name_Type'Last then
19749 TSS_Name :=
19750 TSS_Name_Type
19751 (Name_Buffer (Name_Len - TSS_Name'Length + 1 .. Name_Len));
19753 if Chars (E) in Name_uSize | Name_uAssign
19754 or else
19755 (Chars (E) = Name_Op_Eq
19756 and then Etype (First_Formal (E)) = Etype (Last_Formal (E)))
19757 or else TSS_Name = TSS_Deep_Adjust
19758 or else TSS_Name = TSS_Deep_Finalize
19759 or else Is_Predefined_Interface_Primitive (E)
19760 then
19761 return True;
19762 end if;
19763 end if;
19765 return False;
19766 end Is_Predefined_Internal_Operation;
19768 --------------------------------
19769 -- Is_Preelaborable_Aggregate --
19770 --------------------------------
19772 function Is_Preelaborable_Aggregate (Aggr : Node_Id) return Boolean is
19773 Aggr_Typ : constant Entity_Id := Etype (Aggr);
19774 Array_Aggr : constant Boolean := Is_Array_Type (Aggr_Typ);
19776 Anc_Part : Node_Id;
19777 Assoc : Node_Id;
19778 Choice : Node_Id;
19779 Comp_Typ : Entity_Id := Empty; -- init to avoid warning
19780 Expr : Node_Id;
19782 begin
19783 if Array_Aggr then
19784 Comp_Typ := Component_Type (Aggr_Typ);
19785 end if;
19787 -- Inspect the ancestor part
19789 if Nkind (Aggr) = N_Extension_Aggregate then
19790 Anc_Part := Ancestor_Part (Aggr);
19792 -- The ancestor denotes a subtype mark
19794 if Is_Entity_Name (Anc_Part)
19795 and then Is_Type (Entity (Anc_Part))
19796 then
19797 if not Has_Preelaborable_Initialization (Entity (Anc_Part)) then
19798 return False;
19799 end if;
19801 -- Otherwise the ancestor denotes an expression
19803 elsif not Is_Preelaborable_Construct (Anc_Part) then
19804 return False;
19805 end if;
19806 end if;
19808 -- Inspect the positional associations
19810 Expr := First (Expressions (Aggr));
19811 while Present (Expr) loop
19812 if not Is_Preelaborable_Construct (Expr) then
19813 return False;
19814 end if;
19816 Next (Expr);
19817 end loop;
19819 -- Inspect the named associations
19821 Assoc := First (Component_Associations (Aggr));
19822 while Present (Assoc) loop
19824 -- Inspect the choices of the current named association
19826 Choice := First (Choices (Assoc));
19827 while Present (Choice) loop
19828 if Array_Aggr then
19830 -- For a choice to be preelaborable, it must denote either a
19831 -- static range or a static expression.
19833 if Nkind (Choice) = N_Others_Choice then
19834 null;
19836 elsif Nkind (Choice) = N_Range then
19837 if not Is_OK_Static_Range (Choice) then
19838 return False;
19839 end if;
19841 elsif not Is_OK_Static_Expression (Choice) then
19842 return False;
19843 end if;
19845 else
19846 Comp_Typ := Etype (Choice);
19847 end if;
19849 Next (Choice);
19850 end loop;
19852 -- The type of the choice must have preelaborable initialization if
19853 -- the association carries a <>.
19855 pragma Assert (Present (Comp_Typ));
19856 if Box_Present (Assoc) then
19857 if not Has_Preelaborable_Initialization (Comp_Typ) then
19858 return False;
19859 end if;
19861 -- The type of the expression must have preelaborable initialization
19863 elsif not Is_Preelaborable_Construct (Expression (Assoc)) then
19864 return False;
19865 end if;
19867 Next (Assoc);
19868 end loop;
19870 -- At this point the aggregate is preelaborable
19872 return True;
19873 end Is_Preelaborable_Aggregate;
19875 --------------------------------
19876 -- Is_Preelaborable_Construct --
19877 --------------------------------
19879 function Is_Preelaborable_Construct (N : Node_Id) return Boolean is
19880 begin
19881 -- Aggregates
19883 if Nkind (N) in N_Aggregate | N_Extension_Aggregate then
19884 return Is_Preelaborable_Aggregate (N);
19886 -- Attributes are allowed in general, even if their prefix is a formal
19887 -- type. It seems that certain attributes known not to be static might
19888 -- not be allowed, but there are no rules to prevent them.
19890 elsif Nkind (N) = N_Attribute_Reference then
19891 return True;
19893 -- Expressions
19895 elsif Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then
19896 return True;
19898 elsif Nkind (N) = N_Qualified_Expression then
19899 return Is_Preelaborable_Construct (Expression (N));
19901 -- Names are preelaborable when they denote a discriminant of an
19902 -- enclosing type. Discriminals are also considered for this check.
19904 elsif Is_Entity_Name (N)
19905 and then Present (Entity (N))
19906 and then
19907 (Ekind (Entity (N)) = E_Discriminant
19908 or else (Ekind (Entity (N)) in E_Constant | E_In_Parameter
19909 and then Present (Discriminal_Link (Entity (N)))))
19910 then
19911 return True;
19913 -- Statements
19915 elsif Nkind (N) = N_Null then
19916 return True;
19918 -- Ada 2022 (AI12-0175): Calls to certain functions that are essentially
19919 -- unchecked conversions are preelaborable.
19921 elsif Ada_Version >= Ada_2022
19922 and then Nkind (N) = N_Function_Call
19923 and then Is_Entity_Name (Name (N))
19924 and then Is_Preelaborable_Function (Entity (Name (N)))
19925 then
19926 declare
19927 A : Node_Id;
19928 begin
19929 A := First_Actual (N);
19931 while Present (A) loop
19932 if not Is_Preelaborable_Construct (A) then
19933 return False;
19934 end if;
19936 Next_Actual (A);
19937 end loop;
19938 end;
19940 return True;
19942 -- Otherwise the construct is not preelaborable
19944 else
19945 return False;
19946 end if;
19947 end Is_Preelaborable_Construct;
19949 -------------------------------
19950 -- Is_Preelaborable_Function --
19951 -------------------------------
19953 function Is_Preelaborable_Function (Id : Entity_Id) return Boolean is
19954 SATAC : constant Rtsfind.RTU_Id := System_Address_To_Access_Conversions;
19955 Scop : constant Entity_Id := Scope (Id);
19957 begin
19958 -- Small optimization: every allowed function has convention Intrinsic
19959 -- (see Analyze_Subprogram_Instantiation for the subtlety in the test).
19961 if not Is_Intrinsic_Subprogram (Id)
19962 and then Convention (Id) /= Convention_Intrinsic
19963 then
19964 return False;
19965 end if;
19967 -- An instance of Unchecked_Conversion
19969 if Is_Unchecked_Conversion_Instance (Id) then
19970 return True;
19971 end if;
19973 -- A function declared in System.Storage_Elements
19975 if Is_RTU (Scop, System_Storage_Elements) then
19976 return True;
19977 end if;
19979 -- The functions To_Pointer and To_Address declared in an instance of
19980 -- System.Address_To_Access_Conversions (they are the only ones).
19982 if Ekind (Scop) = E_Package
19983 and then Nkind (Parent (Scop)) = N_Package_Specification
19984 and then Present (Generic_Parent (Parent (Scop)))
19985 and then Is_RTU (Generic_Parent (Parent (Scop)), SATAC)
19986 then
19987 return True;
19988 end if;
19990 return False;
19991 end Is_Preelaborable_Function;
19993 -----------------------------
19994 -- Is_Private_Library_Unit --
19995 -----------------------------
19997 function Is_Private_Library_Unit (Unit : Entity_Id) return Boolean is
19998 Comp_Unit : constant Node_Id := Parent (Unit_Declaration_Node (Unit));
19999 begin
20000 return Nkind (Comp_Unit) = N_Compilation_Unit
20001 and then Private_Present (Comp_Unit);
20002 end Is_Private_Library_Unit;
20004 ---------------------------------
20005 -- Is_Protected_Self_Reference --
20006 ---------------------------------
20008 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
20010 function In_Access_Definition (N : Node_Id) return Boolean;
20011 -- Returns true if N belongs to an access definition
20013 --------------------------
20014 -- In_Access_Definition --
20015 --------------------------
20017 function In_Access_Definition (N : Node_Id) return Boolean is
20018 P : Node_Id;
20020 begin
20021 P := Parent (N);
20022 while Present (P) loop
20023 if Nkind (P) = N_Access_Definition then
20024 return True;
20025 end if;
20027 P := Parent (P);
20028 end loop;
20030 return False;
20031 end In_Access_Definition;
20033 -- Start of processing for Is_Protected_Self_Reference
20035 begin
20036 -- Verify that prefix is analyzed and has the proper form. Note that
20037 -- the attributes Elab_Spec, Elab_Body, and Elab_Subp_Body, which also
20038 -- produce the address of an entity, do not analyze their prefix
20039 -- because they denote entities that are not necessarily visible.
20040 -- Neither of them can apply to a protected type.
20042 return Ada_Version >= Ada_2005
20043 and then Is_Entity_Name (N)
20044 and then Present (Entity (N))
20045 and then Is_Protected_Type (Entity (N))
20046 and then In_Open_Scopes (Entity (N))
20047 and then not In_Access_Definition (N);
20048 end Is_Protected_Self_Reference;
20050 -----------------------------
20051 -- Is_RCI_Pkg_Spec_Or_Body --
20052 -----------------------------
20054 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
20056 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
20057 -- Return True if the unit of Cunit is an RCI package declaration
20059 ---------------------------
20060 -- Is_RCI_Pkg_Decl_Cunit --
20061 ---------------------------
20063 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
20064 The_Unit : constant Node_Id := Unit (Cunit);
20066 begin
20067 if Nkind (The_Unit) /= N_Package_Declaration then
20068 return False;
20069 end if;
20071 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
20072 end Is_RCI_Pkg_Decl_Cunit;
20074 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
20076 begin
20077 return Is_RCI_Pkg_Decl_Cunit (Cunit)
20078 or else
20079 (Nkind (Unit (Cunit)) = N_Package_Body
20080 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
20081 end Is_RCI_Pkg_Spec_Or_Body;
20083 -----------------------------------------
20084 -- Is_Remote_Access_To_Class_Wide_Type --
20085 -----------------------------------------
20087 function Is_Remote_Access_To_Class_Wide_Type
20088 (E : Entity_Id) return Boolean
20090 begin
20091 -- A remote access to class-wide type is a general access to object type
20092 -- declared in the visible part of a Remote_Types or Remote_Call_
20093 -- Interface unit.
20095 return Ekind (E) = E_General_Access_Type
20096 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
20097 end Is_Remote_Access_To_Class_Wide_Type;
20099 -----------------------------------------
20100 -- Is_Remote_Access_To_Subprogram_Type --
20101 -----------------------------------------
20103 function Is_Remote_Access_To_Subprogram_Type
20104 (E : Entity_Id) return Boolean
20106 begin
20107 return (Ekind (E) = E_Access_Subprogram_Type
20108 or else (Ekind (E) = E_Record_Type
20109 and then Present (Corresponding_Remote_Type (E))))
20110 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
20111 end Is_Remote_Access_To_Subprogram_Type;
20113 --------------------
20114 -- Is_Remote_Call --
20115 --------------------
20117 function Is_Remote_Call (N : Node_Id) return Boolean is
20118 begin
20119 if Nkind (N) not in N_Subprogram_Call then
20121 -- An entry call cannot be remote
20123 return False;
20125 elsif Nkind (Name (N)) in N_Has_Entity
20126 and then Is_Remote_Call_Interface (Entity (Name (N)))
20127 then
20128 -- A subprogram declared in the spec of a RCI package is remote
20130 return True;
20132 elsif Nkind (Name (N)) = N_Explicit_Dereference
20133 and then Is_Remote_Access_To_Subprogram_Type
20134 (Etype (Prefix (Name (N))))
20135 then
20136 -- The dereference of a RAS is a remote call
20138 return True;
20140 elsif Present (Controlling_Argument (N))
20141 and then Is_Remote_Access_To_Class_Wide_Type
20142 (Etype (Controlling_Argument (N)))
20143 then
20144 -- Any primitive operation call with a controlling argument of
20145 -- a RACW type is a remote call.
20147 return True;
20148 end if;
20150 -- All other calls are local calls
20152 return False;
20153 end Is_Remote_Call;
20155 ----------------------
20156 -- Is_Renamed_Entry --
20157 ----------------------
20159 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
20160 Orig_Node : Node_Id := Empty;
20161 Subp_Decl : Node_Id :=
20162 (if No (Parent (Proc_Nam)) then Empty else Parent (Parent (Proc_Nam)));
20164 function Is_Entry (Nam : Node_Id) return Boolean;
20165 -- Determine whether Nam is an entry. Traverse selectors if there are
20166 -- nested selected components.
20168 --------------
20169 -- Is_Entry --
20170 --------------
20172 function Is_Entry (Nam : Node_Id) return Boolean is
20173 begin
20174 if Nkind (Nam) = N_Selected_Component then
20175 return Is_Entry (Selector_Name (Nam));
20176 end if;
20178 return Ekind (Entity (Nam)) = E_Entry;
20179 end Is_Entry;
20181 -- Start of processing for Is_Renamed_Entry
20183 begin
20184 if Present (Alias (Proc_Nam)) then
20185 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
20186 end if;
20188 -- Look for a rewritten subprogram renaming declaration
20190 if Nkind (Subp_Decl) = N_Subprogram_Declaration
20191 and then Present (Original_Node (Subp_Decl))
20192 then
20193 Orig_Node := Original_Node (Subp_Decl);
20194 end if;
20196 -- The rewritten subprogram is actually an entry
20198 if Present (Orig_Node)
20199 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
20200 and then Is_Entry (Name (Orig_Node))
20201 then
20202 return True;
20203 end if;
20205 return False;
20206 end Is_Renamed_Entry;
20208 ----------------------------
20209 -- Is_Reversible_Iterator --
20210 ----------------------------
20212 function Is_Reversible_Iterator (Typ : Entity_Id) return Boolean is
20213 Ifaces_List : Elist_Id;
20214 Iface_Elmt : Elmt_Id;
20215 Iface : Entity_Id;
20217 begin
20218 if Is_Class_Wide_Type (Typ)
20219 and then Chars (Root_Type (Typ)) = Name_Reversible_Iterator
20220 and then In_Predefined_Unit (Root_Type (Typ))
20221 then
20222 return True;
20224 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
20225 return False;
20227 else
20228 Collect_Interfaces (Typ, Ifaces_List);
20230 Iface_Elmt := First_Elmt (Ifaces_List);
20231 while Present (Iface_Elmt) loop
20232 Iface := Node (Iface_Elmt);
20233 if Chars (Iface) = Name_Reversible_Iterator
20234 and then In_Predefined_Unit (Iface)
20235 then
20236 return True;
20237 end if;
20239 Next_Elmt (Iface_Elmt);
20240 end loop;
20241 end if;
20243 return False;
20244 end Is_Reversible_Iterator;
20246 ---------------------------------
20247 -- Is_Single_Concurrent_Object --
20248 ---------------------------------
20250 function Is_Single_Concurrent_Object (Id : Entity_Id) return Boolean is
20251 begin
20252 return
20253 Is_Single_Protected_Object (Id) or else Is_Single_Task_Object (Id);
20254 end Is_Single_Concurrent_Object;
20256 -------------------------------
20257 -- Is_Single_Concurrent_Type --
20258 -------------------------------
20260 function Is_Single_Concurrent_Type (Id : Entity_Id) return Boolean is
20261 begin
20262 return
20263 Ekind (Id) in E_Protected_Type | E_Task_Type
20264 and then Is_Single_Concurrent_Type_Declaration
20265 (Declaration_Node (Id));
20266 end Is_Single_Concurrent_Type;
20268 -------------------------------------------
20269 -- Is_Single_Concurrent_Type_Declaration --
20270 -------------------------------------------
20272 function Is_Single_Concurrent_Type_Declaration
20273 (N : Node_Id) return Boolean
20275 begin
20276 return Nkind (Original_Node (N)) in
20277 N_Single_Protected_Declaration | N_Single_Task_Declaration;
20278 end Is_Single_Concurrent_Type_Declaration;
20280 ---------------------------------------------
20281 -- Is_Single_Precision_Floating_Point_Type --
20282 ---------------------------------------------
20284 function Is_Single_Precision_Floating_Point_Type
20285 (E : Entity_Id) return Boolean is
20286 begin
20287 return Is_Floating_Point_Type (E)
20288 and then Machine_Radix_Value (E) = Uint_2
20289 and then Machine_Mantissa_Value (E) = Uint_24
20290 and then Machine_Emax_Value (E) = Uint_2 ** Uint_7
20291 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_7);
20292 end Is_Single_Precision_Floating_Point_Type;
20294 --------------------------------
20295 -- Is_Single_Protected_Object --
20296 --------------------------------
20298 function Is_Single_Protected_Object (Id : Entity_Id) return Boolean is
20299 begin
20300 return
20301 Ekind (Id) = E_Variable
20302 and then Ekind (Etype (Id)) = E_Protected_Type
20303 and then Is_Single_Concurrent_Type (Etype (Id));
20304 end Is_Single_Protected_Object;
20306 ---------------------------
20307 -- Is_Single_Task_Object --
20308 ---------------------------
20310 function Is_Single_Task_Object (Id : Entity_Id) return Boolean is
20311 begin
20312 return
20313 Ekind (Id) = E_Variable
20314 and then Ekind (Etype (Id)) = E_Task_Type
20315 and then Is_Single_Concurrent_Type (Etype (Id));
20316 end Is_Single_Task_Object;
20318 -----------------------------
20319 -- Is_Specific_Tagged_Type --
20320 -----------------------------
20322 function Is_Specific_Tagged_Type (Typ : Entity_Id) return Boolean is
20323 Full_Typ : Entity_Id;
20325 begin
20326 -- Handle private types
20328 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
20329 Full_Typ := Full_View (Typ);
20330 else
20331 Full_Typ := Typ;
20332 end if;
20334 -- A specific tagged type is a non-class-wide tagged type
20336 return Is_Tagged_Type (Full_Typ) and not Is_Class_Wide_Type (Full_Typ);
20337 end Is_Specific_Tagged_Type;
20339 ------------------
20340 -- Is_Statement --
20341 ------------------
20343 function Is_Statement (N : Node_Id) return Boolean is
20344 begin
20345 return
20346 Nkind (N) in N_Statement_Other_Than_Procedure_Call
20347 or else Nkind (N) = N_Procedure_Call_Statement;
20348 end Is_Statement;
20350 --------------------------------------
20351 -- Is_Static_Discriminant_Component --
20352 --------------------------------------
20354 function Is_Static_Discriminant_Component (N : Node_Id) return Boolean is
20355 begin
20356 return Nkind (N) = N_Selected_Component
20357 and then not Is_In_Discriminant_Check (N)
20358 and then Present (Etype (Prefix (N)))
20359 and then Ekind (Etype (Prefix (N))) = E_Record_Subtype
20360 and then Has_Static_Discriminants (Etype (Prefix (N)))
20361 and then Present (Entity (Selector_Name (N)))
20362 and then Ekind (Entity (Selector_Name (N))) = E_Discriminant
20363 and then not In_Check_Node (N);
20364 end Is_Static_Discriminant_Component;
20366 ------------------------
20367 -- Is_Static_Function --
20368 ------------------------
20370 function Is_Static_Function (Subp : Entity_Id) return Boolean is
20371 begin
20372 -- Always return False for pre Ada 2022 to e.g. ignore the Static
20373 -- aspect in package Interfaces for Ada_Version < 2022 and also
20374 -- for efficiency.
20376 return Ada_Version >= Ada_2022
20377 and then Has_Aspect (Subp, Aspect_Static)
20378 and then
20379 (No (Find_Value_Of_Aspect (Subp, Aspect_Static))
20380 or else Is_True (Static_Boolean
20381 (Find_Value_Of_Aspect (Subp, Aspect_Static))));
20382 end Is_Static_Function;
20384 -----------------------------
20385 -- Is_Static_Function_Call --
20386 -----------------------------
20388 function Is_Static_Function_Call (Call : Node_Id) return Boolean is
20389 function Has_All_Static_Actuals (Call : Node_Id) return Boolean;
20390 -- Return whether all actual parameters of Call are static expressions
20392 ----------------------------
20393 -- Has_All_Static_Actuals --
20394 ----------------------------
20396 function Has_All_Static_Actuals (Call : Node_Id) return Boolean is
20397 Actual : Node_Id := First_Actual (Call);
20398 String_Result : constant Boolean :=
20399 Is_String_Type (Etype (Entity (Name (Call))));
20401 begin
20402 while Present (Actual) loop
20403 if not Is_Static_Expression (Actual) then
20405 -- ??? In the string-returning case we want to avoid a call
20406 -- being made to Establish_Transient_Scope in Resolve_Call,
20407 -- but at the point where that's tested for (which now includes
20408 -- a call to test Is_Static_Function_Call), the actuals of the
20409 -- call haven't been resolved, so expressions of the actuals
20410 -- may not have been marked Is_Static_Expression yet, so we
20411 -- force them to be resolved here, so we can tell if they're
20412 -- static. Calling Resolve here is admittedly a kludge, and we
20413 -- limit this call to string-returning cases.
20415 if String_Result then
20416 Resolve (Actual);
20417 end if;
20419 -- Test flag again in case it's now True due to above Resolve
20421 if not Is_Static_Expression (Actual) then
20422 return False;
20423 end if;
20424 end if;
20426 Next_Actual (Actual);
20427 end loop;
20429 return True;
20430 end Has_All_Static_Actuals;
20432 begin
20433 return Nkind (Call) = N_Function_Call
20434 and then Is_Entity_Name (Name (Call))
20435 and then Is_Static_Function (Entity (Name (Call)))
20436 and then Has_All_Static_Actuals (Call);
20437 end Is_Static_Function_Call;
20439 -------------------------------------------
20440 -- Is_Subcomponent_Of_Full_Access_Object --
20441 -------------------------------------------
20443 function Is_Subcomponent_Of_Full_Access_Object (N : Node_Id) return Boolean
20445 R : Node_Id;
20447 begin
20448 R := Get_Referenced_Object (N);
20450 while Nkind (R) in N_Indexed_Component | N_Selected_Component | N_Slice
20451 loop
20452 R := Get_Referenced_Object (Prefix (R));
20454 -- If the prefix is an access value, only the designated type matters
20456 if Is_Access_Type (Etype (R)) then
20457 if Is_Full_Access (Designated_Type (Etype (R))) then
20458 return True;
20459 end if;
20461 else
20462 if Is_Full_Access_Object (R) then
20463 return True;
20464 end if;
20465 end if;
20466 end loop;
20468 return False;
20469 end Is_Subcomponent_Of_Full_Access_Object;
20471 ---------------------------------------
20472 -- Is_Subprogram_Contract_Annotation --
20473 ---------------------------------------
20475 function Is_Subprogram_Contract_Annotation
20476 (Item : Node_Id) return Boolean
20478 Nam : Name_Id;
20480 begin
20481 if Nkind (Item) = N_Aspect_Specification then
20482 Nam := Chars (Identifier (Item));
20484 else pragma Assert (Nkind (Item) = N_Pragma);
20485 Nam := Pragma_Name (Item);
20486 end if;
20488 return Nam = Name_Contract_Cases
20489 or else Nam = Name_Depends
20490 or else Nam = Name_Extensions_Visible
20491 or else Nam = Name_Global
20492 or else Nam = Name_Post
20493 or else Nam = Name_Post_Class
20494 or else Nam = Name_Postcondition
20495 or else Nam = Name_Pre
20496 or else Nam = Name_Pre_Class
20497 or else Nam = Name_Precondition
20498 or else Nam = Name_Refined_Depends
20499 or else Nam = Name_Refined_Global
20500 or else Nam = Name_Refined_Post
20501 or else Nam = Name_Subprogram_Variant
20502 or else Nam = Name_Test_Case;
20503 end Is_Subprogram_Contract_Annotation;
20505 --------------------------------------------------
20506 -- Is_Subprogram_Stub_Without_Prior_Declaration --
20507 --------------------------------------------------
20509 function Is_Subprogram_Stub_Without_Prior_Declaration
20510 (N : Node_Id) return Boolean
20512 begin
20513 pragma Assert (Nkind (N) = N_Subprogram_Body_Stub);
20515 case Ekind (Defining_Entity (N)) is
20517 -- A subprogram stub without prior declaration serves as declaration
20518 -- for the actual subprogram body. As such, it has an attached
20519 -- defining entity of E_Function or E_Procedure.
20521 when E_Function
20522 | E_Procedure
20524 return True;
20526 -- Otherwise, it is completes a [generic] subprogram declaration
20528 when E_Generic_Function
20529 | E_Generic_Procedure
20530 | E_Subprogram_Body
20532 return False;
20534 when others =>
20535 raise Program_Error;
20536 end case;
20537 end Is_Subprogram_Stub_Without_Prior_Declaration;
20539 ---------------------------
20540 -- Is_Suitable_Primitive --
20541 ---------------------------
20543 function Is_Suitable_Primitive (Subp_Id : Entity_Id) return Boolean is
20544 begin
20545 -- The Default_Initial_Condition and invariant procedures must not be
20546 -- treated as primitive operations even when they apply to a tagged
20547 -- type. These routines must not act as targets of dispatching calls
20548 -- because they already utilize class-wide-precondition semantics to
20549 -- handle inheritance and overriding.
20551 if Ekind (Subp_Id) = E_Procedure
20552 and then (Is_DIC_Procedure (Subp_Id)
20553 or else
20554 Is_Invariant_Procedure (Subp_Id))
20555 then
20556 return False;
20557 end if;
20559 return True;
20560 end Is_Suitable_Primitive;
20562 ----------------------------
20563 -- Is_Synchronized_Object --
20564 ----------------------------
20566 function Is_Synchronized_Object (Id : Entity_Id) return Boolean is
20567 Prag : Node_Id;
20569 begin
20570 if Is_Object (Id) then
20572 -- The object is synchronized if it is of a type that yields a
20573 -- synchronized object.
20575 if Yields_Synchronized_Object (Etype (Id)) then
20576 return True;
20578 -- The object is synchronized if it is atomic and Async_Writers is
20579 -- enabled.
20581 elsif Is_Atomic_Object_Entity (Id)
20582 and then Async_Writers_Enabled (Id)
20583 then
20584 return True;
20586 -- A constant is a synchronized object by default, unless its type is
20587 -- access-to-variable type.
20589 elsif Ekind (Id) = E_Constant
20590 and then not Is_Access_Variable (Etype (Id))
20591 then
20592 return True;
20594 -- A variable is a synchronized object if it is subject to pragma
20595 -- Constant_After_Elaboration.
20597 elsif Ekind (Id) = E_Variable then
20598 Prag := Get_Pragma (Id, Pragma_Constant_After_Elaboration);
20600 return Present (Prag) and then Is_Enabled_Pragma (Prag);
20601 end if;
20602 end if;
20604 -- Otherwise the input is not an object or it does not qualify as a
20605 -- synchronized object.
20607 return False;
20608 end Is_Synchronized_Object;
20610 ---------------------------------
20611 -- Is_Synchronized_Tagged_Type --
20612 ---------------------------------
20614 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
20615 Kind : constant Entity_Kind := Ekind (Base_Type (E));
20617 begin
20618 -- A task or protected type derived from an interface is a tagged type.
20619 -- Such a tagged type is called a synchronized tagged type, as are
20620 -- synchronized interfaces and private extensions whose declaration
20621 -- includes the reserved word synchronized.
20623 return (Is_Tagged_Type (E)
20624 and then (Kind = E_Task_Type
20625 or else
20626 Kind = E_Protected_Type))
20627 or else
20628 (Is_Interface (E)
20629 and then Is_Synchronized_Interface (E))
20630 or else
20631 (Ekind (E) = E_Record_Type_With_Private
20632 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
20633 and then (Synchronized_Present (Parent (E))
20634 or else Is_Synchronized_Interface (Etype (E))));
20635 end Is_Synchronized_Tagged_Type;
20637 -----------------
20638 -- Is_Transfer --
20639 -----------------
20641 function Is_Transfer (N : Node_Id) return Boolean is
20642 Kind : constant Node_Kind := Nkind (N);
20644 begin
20645 if Kind in N_Simple_Return_Statement
20646 | N_Extended_Return_Statement
20647 | N_Goto_Statement
20648 | N_Raise_Statement
20649 | N_Requeue_Statement
20650 then
20651 return True;
20653 elsif Kind in N_Exit_Statement | N_Raise_xxx_Error
20654 and then No (Condition (N))
20655 then
20656 return True;
20658 elsif Kind = N_Procedure_Call_Statement
20659 and then Is_Entity_Name (Name (N))
20660 and then Present (Entity (Name (N)))
20661 and then No_Return (Entity (Name (N)))
20662 then
20663 return True;
20665 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
20666 return True;
20668 else
20669 return False;
20670 end if;
20671 end Is_Transfer;
20673 -------------
20674 -- Is_True --
20675 -------------
20677 function Is_True (U : Opt_Ubool) return Boolean is
20678 begin
20679 return No (U) or else U = Uint_1;
20680 end Is_True;
20682 ------------------------
20683 -- Is_Trivial_Boolean --
20684 ------------------------
20686 function Is_Trivial_Boolean (N : Node_Id) return Boolean is
20687 begin
20688 return Comes_From_Source (N)
20689 and then Nkind (N) in N_Identifier | N_Expanded_Name
20690 and then Entity (N) in Standard_True | Standard_False;
20691 end Is_Trivial_Boolean;
20693 --------------------------------------
20694 -- Is_Unchecked_Conversion_Instance --
20695 --------------------------------------
20697 function Is_Unchecked_Conversion_Instance (Id : Entity_Id) return Boolean is
20698 Par : Node_Id;
20700 begin
20701 -- Look for a function whose generic parent is the predefined intrinsic
20702 -- function Unchecked_Conversion, or for one that renames such an
20703 -- instance.
20705 if Ekind (Id) = E_Function then
20706 Par := Parent (Id);
20708 if Nkind (Par) = N_Function_Specification then
20709 Par := Generic_Parent (Par);
20711 if Present (Par) then
20712 return
20713 Chars (Par) = Name_Unchecked_Conversion
20714 and then Is_Intrinsic_Subprogram (Par)
20715 and then In_Predefined_Unit (Par);
20716 else
20717 return
20718 Present (Alias (Id))
20719 and then Is_Unchecked_Conversion_Instance (Alias (Id));
20720 end if;
20721 end if;
20722 end if;
20724 return False;
20725 end Is_Unchecked_Conversion_Instance;
20727 -------------------------------
20728 -- Is_Universal_Numeric_Type --
20729 -------------------------------
20731 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
20732 begin
20733 return T = Universal_Integer or else T = Universal_Real;
20734 end Is_Universal_Numeric_Type;
20736 ------------------------------
20737 -- Is_User_Defined_Equality --
20738 ------------------------------
20740 function Is_User_Defined_Equality (Id : Entity_Id) return Boolean is
20741 F1, F2 : Entity_Id;
20743 begin
20744 -- An equality operator is a function that carries the name "=", returns
20745 -- Boolean, and has exactly two formal parameters of an identical type.
20747 if Ekind (Id) = E_Function
20748 and then Chars (Id) = Name_Op_Eq
20749 and then Base_Type (Etype (Id)) = Standard_Boolean
20750 then
20751 F1 := First_Formal (Id);
20753 if No (F1) then
20754 return False;
20755 end if;
20757 F2 := Next_Formal (F1);
20759 return Present (F2)
20760 and then No (Next_Formal (F2))
20761 and then Base_Type (Etype (F1)) = Base_Type (Etype (F2));
20763 else
20764 return False;
20765 end if;
20766 end Is_User_Defined_Equality;
20768 -----------------------------
20769 -- Is_User_Defined_Literal --
20770 -----------------------------
20772 function Is_User_Defined_Literal
20773 (N : Node_Id;
20774 Typ : Entity_Id) return Boolean
20776 Literal_Aspect_Map :
20777 constant array (N_Numeric_Or_String_Literal) of Aspect_Id :=
20778 (N_Integer_Literal => Aspect_Integer_Literal,
20779 N_Real_Literal => Aspect_Real_Literal,
20780 N_String_Literal => Aspect_String_Literal);
20782 begin
20783 -- Return True when N is either a literal or a named number and the
20784 -- type has the appropriate user-defined literal aspect.
20786 return (Nkind (N) in N_Numeric_Or_String_Literal
20787 and then Has_Aspect (Typ, Literal_Aspect_Map (Nkind (N))))
20788 or else
20789 (Is_Entity_Name (N)
20790 and then Present (Entity (N))
20791 and then
20792 ((Ekind (Entity (N)) = E_Named_Integer
20793 and then Has_Aspect (Typ, Aspect_Integer_Literal))
20794 or else
20795 (Ekind (Entity (N)) = E_Named_Real
20796 and then Has_Aspect (Typ, Aspect_Real_Literal))));
20797 end Is_User_Defined_Literal;
20799 --------------------------------------
20800 -- Is_Validation_Variable_Reference --
20801 --------------------------------------
20803 function Is_Validation_Variable_Reference (N : Node_Id) return Boolean is
20804 Var : constant Node_Id := Unqual_Conv (N);
20805 Var_Id : Entity_Id;
20807 begin
20808 Var_Id := Empty;
20810 if Is_Entity_Name (Var) then
20811 Var_Id := Entity (Var);
20812 end if;
20814 return
20815 Present (Var_Id)
20816 and then Ekind (Var_Id) = E_Variable
20817 and then Present (Validated_Object (Var_Id));
20818 end Is_Validation_Variable_Reference;
20820 ----------------------------
20821 -- Is_Variable_Size_Array --
20822 ----------------------------
20824 function Is_Variable_Size_Array (E : Entity_Id) return Boolean is
20825 Idx : Node_Id;
20827 begin
20828 pragma Assert (Is_Array_Type (E));
20830 -- Check if some index is initialized with a non-constant value
20832 Idx := First_Index (E);
20833 while Present (Idx) loop
20834 if Nkind (Idx) = N_Range then
20835 if not Is_Constant_Bound (Low_Bound (Idx))
20836 or else not Is_Constant_Bound (High_Bound (Idx))
20837 then
20838 return True;
20839 end if;
20840 end if;
20842 Next_Index (Idx);
20843 end loop;
20845 return False;
20846 end Is_Variable_Size_Array;
20848 -----------------------------
20849 -- Is_Variable_Size_Record --
20850 -----------------------------
20852 function Is_Variable_Size_Record (E : Entity_Id) return Boolean is
20853 Comp : Entity_Id;
20854 Comp_Typ : Entity_Id;
20856 begin
20857 pragma Assert (Is_Record_Type (E));
20859 Comp := First_Component (E);
20860 while Present (Comp) loop
20861 Comp_Typ := Underlying_Type (Etype (Comp));
20863 -- Recursive call if the record type has discriminants
20865 if Is_Record_Type (Comp_Typ)
20866 and then Has_Discriminants (Comp_Typ)
20867 and then Is_Variable_Size_Record (Comp_Typ)
20868 then
20869 return True;
20871 elsif Is_Array_Type (Comp_Typ)
20872 and then Is_Variable_Size_Array (Comp_Typ)
20873 then
20874 return True;
20875 end if;
20877 Next_Component (Comp);
20878 end loop;
20880 return False;
20881 end Is_Variable_Size_Record;
20883 -----------------
20884 -- Is_Variable --
20885 -----------------
20887 -- Should Is_Variable be refactored to better handle dereferences and
20888 -- technical debt ???
20890 function Is_Variable
20891 (N : Node_Id;
20892 Use_Original_Node : Boolean := True) return Boolean
20894 Orig_Node : Node_Id;
20896 function In_Protected_Function (E : Entity_Id) return Boolean;
20897 -- Within a protected function, the private components of the enclosing
20898 -- protected type are constants. A function nested within a (protected)
20899 -- procedure is not itself protected. Within the body of a protected
20900 -- function the current instance of the protected type is a constant.
20902 function Is_Variable_Prefix (P : Node_Id) return Boolean;
20903 -- Prefixes can involve implicit dereferences, in which case we must
20904 -- test for the case of a reference of a constant access type, which can
20905 -- can never be a variable.
20907 ---------------------------
20908 -- In_Protected_Function --
20909 ---------------------------
20911 function In_Protected_Function (E : Entity_Id) return Boolean is
20912 Prot : Entity_Id;
20913 S : Entity_Id;
20915 begin
20916 -- E is the current instance of a type
20918 if Is_Type (E) then
20919 Prot := E;
20921 -- E is an object
20923 else
20924 Prot := Scope (E);
20925 end if;
20927 if not Is_Protected_Type (Prot) then
20928 return False;
20930 else
20931 S := Current_Scope;
20932 while Present (S) and then S /= Prot loop
20933 if Ekind (S) = E_Function and then Scope (S) = Prot then
20934 return True;
20935 end if;
20937 S := Scope (S);
20938 end loop;
20940 return False;
20941 end if;
20942 end In_Protected_Function;
20944 ------------------------
20945 -- Is_Variable_Prefix --
20946 ------------------------
20948 function Is_Variable_Prefix (P : Node_Id) return Boolean is
20949 begin
20950 if Is_Access_Type (Etype (P)) then
20951 return not Is_Access_Constant (Root_Type (Etype (P)));
20953 -- For the case of an indexed component whose prefix has a packed
20954 -- array type, the prefix has been rewritten into a type conversion.
20955 -- Determine variable-ness from the converted expression.
20957 elsif Nkind (P) = N_Type_Conversion
20958 and then not Comes_From_Source (P)
20959 and then Is_Packed_Array (Etype (P))
20960 then
20961 return Is_Variable (Expression (P));
20963 else
20964 return Is_Variable (P);
20965 end if;
20966 end Is_Variable_Prefix;
20968 -- Start of processing for Is_Variable
20970 begin
20971 -- Special check, allow x'Deref(expr) as a variable
20973 if Nkind (N) = N_Attribute_Reference
20974 and then Attribute_Name (N) = Name_Deref
20975 then
20976 return True;
20977 end if;
20979 -- Check if we perform the test on the original node since this may be a
20980 -- test of syntactic categories which must not be disturbed by whatever
20981 -- rewriting might have occurred. For example, an aggregate, which is
20982 -- certainly NOT a variable, could be turned into a variable by
20983 -- expansion.
20985 if Use_Original_Node then
20986 Orig_Node := Original_Node (N);
20987 else
20988 Orig_Node := N;
20989 end if;
20991 -- Definitely OK if Assignment_OK is set. Since this is something that
20992 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
20994 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
20995 return True;
20997 -- Normally we go to the original node, but there is one exception where
20998 -- we use the rewritten node, namely when it is an explicit dereference.
20999 -- The generated code may rewrite a prefix which is an access type with
21000 -- an explicit dereference. The dereference is a variable, even though
21001 -- the original node may not be (since it could be a constant of the
21002 -- access type).
21004 -- In Ada 2005 we have a further case to consider: the prefix may be a
21005 -- function call given in prefix notation. The original node appears to
21006 -- be a selected component, but we need to examine the call.
21008 elsif Nkind (N) = N_Explicit_Dereference
21009 and then Nkind (Orig_Node) /= N_Explicit_Dereference
21010 and then Present (Etype (Orig_Node))
21011 and then Is_Access_Type (Etype (Orig_Node))
21012 then
21013 -- Note that if the prefix is an explicit dereference that does not
21014 -- come from source, we must check for a rewritten function call in
21015 -- prefixed notation before other forms of rewriting, to prevent a
21016 -- compiler crash.
21018 return
21019 (Nkind (Orig_Node) = N_Function_Call
21020 and then not Is_Access_Constant (Etype (Prefix (N))))
21021 or else
21022 Is_Variable_Prefix (Original_Node (Prefix (N)));
21024 -- Generalized indexing operations are rewritten as explicit
21025 -- dereferences, and it is only during resolution that we can
21026 -- check whether the context requires an access_to_variable type.
21028 elsif Nkind (N) = N_Explicit_Dereference
21029 and then Present (Etype (Orig_Node))
21030 and then Has_Implicit_Dereference (Etype (Orig_Node))
21031 and then Ada_Version >= Ada_2012
21032 then
21033 return not Is_Access_Constant (Etype (Prefix (N)));
21035 -- A function call is never a variable
21037 elsif Nkind (N) = N_Function_Call then
21038 return False;
21040 -- All remaining checks use the original node
21042 elsif Is_Entity_Name (Orig_Node)
21043 and then Present (Entity (Orig_Node))
21044 then
21045 declare
21046 E : constant Entity_Id := Entity (Orig_Node);
21047 K : constant Entity_Kind := Ekind (E);
21049 begin
21050 if Is_Loop_Parameter (E) then
21051 return False;
21052 end if;
21054 return (K = E_Variable
21055 and then Nkind (Parent (E)) /= N_Exception_Handler)
21056 or else (K = E_Component
21057 and then not In_Protected_Function (E))
21058 or else (Present (Etype (E))
21059 and then Is_Access_Variable (Etype (E))
21060 and then Is_Dereferenced (N))
21061 or else K = E_Out_Parameter
21062 or else K = E_In_Out_Parameter
21063 or else K = E_Generic_In_Out_Parameter
21065 -- Current instance of type. If this is a protected type, check
21066 -- we are not within the body of one of its protected functions.
21068 or else (Is_Type (E)
21069 and then In_Open_Scopes (E)
21070 and then not In_Protected_Function (E))
21072 or else (Is_Incomplete_Or_Private_Type (E)
21073 and then In_Open_Scopes (Full_View (E)));
21074 end;
21076 else
21077 case Nkind (Orig_Node) is
21078 when N_Indexed_Component
21079 | N_Slice
21081 return Is_Variable_Prefix (Prefix (Orig_Node));
21083 when N_Selected_Component =>
21084 return (Is_Variable (Selector_Name (Orig_Node))
21085 and then Is_Variable_Prefix (Prefix (Orig_Node)))
21086 or else
21087 (Nkind (N) = N_Expanded_Name
21088 and then Scope (Entity (N)) = Entity (Prefix (N)));
21090 -- For an explicit dereference, the type of the prefix cannot
21091 -- be an access to constant or an access to subprogram.
21093 when N_Explicit_Dereference =>
21094 declare
21095 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
21096 begin
21097 return Is_Access_Type (Typ)
21098 and then not Is_Access_Constant (Root_Type (Typ))
21099 and then Ekind (Typ) /= E_Access_Subprogram_Type;
21100 end;
21102 -- The type conversion is the case where we do not deal with the
21103 -- context dependent special case of an actual parameter. Thus
21104 -- the type conversion is only considered a variable for the
21105 -- purposes of this routine if the target type is tagged. However,
21106 -- a type conversion is considered to be a variable if it does not
21107 -- come from source (this deals for example with the conversions
21108 -- of expressions to their actual subtypes).
21110 when N_Type_Conversion =>
21111 return Is_Variable (Expression (Orig_Node))
21112 and then
21113 (not Comes_From_Source (Orig_Node)
21114 or else
21115 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
21116 and then
21117 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
21119 -- GNAT allows an unchecked type conversion as a variable. This
21120 -- only affects the generation of internal expanded code, since
21121 -- calls to instantiations of Unchecked_Conversion are never
21122 -- considered variables (since they are function calls).
21124 when N_Unchecked_Type_Conversion =>
21125 return Is_Variable (Expression (Orig_Node));
21127 when others =>
21128 return False;
21129 end case;
21130 end if;
21131 end Is_Variable;
21133 ------------------------
21134 -- Is_View_Conversion --
21135 ------------------------
21137 function Is_View_Conversion (N : Node_Id) return Boolean is
21138 begin
21139 if Nkind (N) = N_Type_Conversion
21140 and then Nkind (Unqual_Conv (N)) in N_Has_Etype
21141 then
21142 if Is_Tagged_Type (Etype (N))
21143 and then Is_Tagged_Type (Etype (Unqual_Conv (N)))
21144 then
21145 return True;
21147 elsif Is_Actual_Parameter (N)
21148 and then (Is_Actual_Out_Parameter (N)
21149 or else Is_Actual_In_Out_Parameter (N))
21150 then
21151 return True;
21152 end if;
21153 end if;
21155 return False;
21156 end Is_View_Conversion;
21158 ---------------------------
21159 -- Is_Visibly_Controlled --
21160 ---------------------------
21162 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
21163 Root : constant Entity_Id := Root_Type (T);
21164 begin
21165 return Chars (Scope (Root)) = Name_Finalization
21166 and then Chars (Scope (Scope (Root))) = Name_Ada
21167 and then Scope (Scope (Scope (Root))) = Standard_Standard;
21168 end Is_Visibly_Controlled;
21170 ----------------------------------------
21171 -- Is_Volatile_Full_Access_Object_Ref --
21172 ----------------------------------------
21174 function Is_Volatile_Full_Access_Object_Ref (N : Node_Id) return Boolean is
21175 function Is_VFA_Object_Entity (Id : Entity_Id) return Boolean;
21176 -- Determine whether arbitrary entity Id denotes an object that is
21177 -- Volatile_Full_Access.
21179 ----------------------------
21180 -- Is_VFA_Object_Entity --
21181 ----------------------------
21183 function Is_VFA_Object_Entity (Id : Entity_Id) return Boolean is
21184 begin
21185 return
21186 Is_Object (Id)
21187 and then (Is_Volatile_Full_Access (Id)
21188 or else
21189 Is_Volatile_Full_Access (Etype (Id)));
21190 end Is_VFA_Object_Entity;
21192 -- Start of processing for Is_Volatile_Full_Access_Object_Ref
21194 begin
21195 if Is_Entity_Name (N) then
21196 return Is_VFA_Object_Entity (Entity (N));
21198 elsif Is_Volatile_Full_Access (Etype (N)) then
21199 return True;
21201 elsif Nkind (N) = N_Selected_Component then
21202 return Is_Volatile_Full_Access (Entity (Selector_Name (N)));
21204 else
21205 return False;
21206 end if;
21207 end Is_Volatile_Full_Access_Object_Ref;
21209 --------------------------
21210 -- Is_Volatile_Function --
21211 --------------------------
21213 function Is_Volatile_Function (Func_Id : Entity_Id) return Boolean is
21214 begin
21215 pragma Assert (Ekind (Func_Id) in E_Function | E_Generic_Function);
21217 -- A protected function is volatile
21219 if Nkind (Parent (Unit_Declaration_Node (Func_Id))) =
21220 N_Protected_Definition
21221 then
21222 return True;
21224 -- An instance of Ada.Unchecked_Conversion is a volatile function if
21225 -- either the source or the target are effectively volatile.
21227 elsif Is_Unchecked_Conversion_Instance (Func_Id)
21228 and then Has_Effectively_Volatile_Profile (Func_Id)
21229 then
21230 return True;
21232 -- Otherwise the function is treated as volatile if it is subject to
21233 -- enabled pragma Volatile_Function.
21235 else
21236 return
21237 Is_Enabled_Pragma (Get_Pragma (Func_Id, Pragma_Volatile_Function));
21238 end if;
21239 end Is_Volatile_Function;
21241 ----------------------------
21242 -- Is_Volatile_Object_Ref --
21243 ----------------------------
21245 function Is_Volatile_Object_Ref (N : Node_Id) return Boolean is
21246 function Is_Volatile_Object_Entity (Id : Entity_Id) return Boolean;
21247 -- Determine whether arbitrary entity Id denotes an object that is
21248 -- Volatile.
21250 function Prefix_Has_Volatile_Components (P : Node_Id) return Boolean;
21251 -- Determine whether prefix P has volatile components. This requires
21252 -- the presence of a Volatile_Components aspect/pragma or that P be
21253 -- itself a volatile object as per RM C.6(8).
21255 ---------------------------------
21256 -- Is_Volatile_Object_Entity --
21257 ---------------------------------
21259 function Is_Volatile_Object_Entity (Id : Entity_Id) return Boolean is
21260 begin
21261 return
21262 Is_Object (Id)
21263 and then (Is_Volatile (Id) or else Is_Volatile (Etype (Id)));
21264 end Is_Volatile_Object_Entity;
21266 ------------------------------------
21267 -- Prefix_Has_Volatile_Components --
21268 ------------------------------------
21270 function Prefix_Has_Volatile_Components (P : Node_Id) return Boolean is
21271 Typ : constant Entity_Id := Etype (P);
21273 begin
21274 if Is_Access_Type (Typ) then
21275 declare
21276 Dtyp : constant Entity_Id := Designated_Type (Typ);
21278 begin
21279 return Has_Volatile_Components (Dtyp)
21280 or else Is_Volatile (Dtyp);
21281 end;
21283 elsif Has_Volatile_Components (Typ) then
21284 return True;
21286 elsif Is_Entity_Name (P)
21287 and then Has_Volatile_Component (Entity (P))
21288 then
21289 return True;
21291 elsif Is_Volatile_Object_Ref (P) then
21292 return True;
21294 else
21295 return False;
21296 end if;
21297 end Prefix_Has_Volatile_Components;
21299 -- Start of processing for Is_Volatile_Object_Ref
21301 begin
21302 if Is_Entity_Name (N) then
21303 return Is_Volatile_Object_Entity (Entity (N));
21305 elsif Is_Volatile (Etype (N)) then
21306 return True;
21308 elsif Nkind (N) = N_Indexed_Component then
21309 return Prefix_Has_Volatile_Components (Prefix (N));
21311 elsif Nkind (N) = N_Selected_Component then
21312 return Prefix_Has_Volatile_Components (Prefix (N))
21313 or else Is_Volatile (Entity (Selector_Name (N)));
21315 else
21316 return False;
21317 end if;
21318 end Is_Volatile_Object_Ref;
21320 -----------------------------
21321 -- Iterate_Call_Parameters --
21322 -----------------------------
21324 procedure Iterate_Call_Parameters (Call : Node_Id) is
21325 Actual : Node_Id := First_Actual (Call);
21326 Formal : Entity_Id := First_Formal (Get_Called_Entity (Call));
21328 begin
21329 while Present (Formal) and then Present (Actual) loop
21330 Handle_Parameter (Formal, Actual);
21332 Next_Formal (Formal);
21333 Next_Actual (Actual);
21334 end loop;
21336 pragma Assert (No (Formal));
21337 pragma Assert (No (Actual));
21338 end Iterate_Call_Parameters;
21340 -------------------------
21341 -- Kill_Current_Values --
21342 -------------------------
21344 procedure Kill_Current_Values
21345 (Ent : Entity_Id;
21346 Last_Assignment_Only : Boolean := False)
21348 begin
21349 if Is_Assignable (Ent) then
21350 Set_Last_Assignment (Ent, Empty);
21351 end if;
21353 if Is_Object (Ent) then
21354 if not Last_Assignment_Only then
21355 Kill_Checks (Ent);
21356 Set_Current_Value (Ent, Empty);
21358 -- Do not reset the Is_Known_[Non_]Null and Is_Known_Valid flags
21359 -- for a constant. Once the constant is elaborated, its value is
21360 -- not changed, therefore the associated flags that describe the
21361 -- value should not be modified either.
21363 if Ekind (Ent) = E_Constant then
21364 null;
21366 -- Non-constant entities
21368 else
21369 if not Can_Never_Be_Null (Ent) then
21370 Set_Is_Known_Non_Null (Ent, False);
21371 end if;
21373 Set_Is_Known_Null (Ent, False);
21375 -- Reset the Is_Known_Valid flag unless the type is always
21376 -- valid. This does not apply to a loop parameter because its
21377 -- bounds are defined by the loop header and therefore always
21378 -- valid.
21380 if not Is_Known_Valid (Etype (Ent))
21381 and then Ekind (Ent) /= E_Loop_Parameter
21382 then
21383 Set_Is_Known_Valid (Ent, False);
21384 end if;
21385 end if;
21386 end if;
21387 end if;
21388 end Kill_Current_Values;
21390 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
21391 S : Entity_Id;
21393 begin
21394 -- Kill all saved checks, a special case of killing saved values
21396 if not Last_Assignment_Only then
21397 Kill_All_Checks;
21398 end if;
21400 -- Loop through relevant scopes, which includes the current scope and
21401 -- any parent scopes if the current scope is a block or a package.
21403 S := Current_Scope;
21404 Scope_Loop : loop
21406 -- Clear current values of all entities in current scope
21408 declare
21409 Ent : Entity_Id;
21410 begin
21411 Ent := First_Entity (S);
21412 while Present (Ent) loop
21413 Kill_Current_Values (Ent, Last_Assignment_Only);
21414 Next_Entity (Ent);
21415 end loop;
21416 end;
21418 -- If this is a not a subprogram, deal with parents
21420 if not Is_Subprogram (S) then
21421 S := Scope (S);
21422 exit Scope_Loop when S = Standard_Standard;
21423 else
21424 exit Scope_Loop;
21425 end if;
21426 end loop Scope_Loop;
21427 end Kill_Current_Values;
21429 --------------------------
21430 -- Kill_Size_Check_Code --
21431 --------------------------
21433 procedure Kill_Size_Check_Code (E : Entity_Id) is
21434 begin
21435 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
21436 and then Present (Size_Check_Code (E))
21437 then
21438 Remove (Size_Check_Code (E));
21439 Set_Size_Check_Code (E, Empty);
21440 end if;
21441 end Kill_Size_Check_Code;
21443 --------------------
21444 -- Known_Non_Null --
21445 --------------------
21447 function Known_Non_Null (N : Node_Id) return Boolean is
21448 Status : constant Null_Status_Kind := Null_Status (N);
21450 Id : Entity_Id;
21451 Op : Node_Kind;
21452 Val : Node_Id;
21454 begin
21455 -- The expression yields a non-null value ignoring simple flow analysis
21457 if Status = Is_Non_Null then
21458 return True;
21460 -- Otherwise check whether N is a reference to an entity that appears
21461 -- within a conditional construct.
21463 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
21465 -- First check if we are in decisive conditional
21467 Get_Current_Value_Condition (N, Op, Val);
21469 if Known_Null (Val) then
21470 if Op = N_Op_Eq then
21471 return False;
21472 elsif Op = N_Op_Ne then
21473 return True;
21474 end if;
21475 end if;
21477 -- If OK to do replacement, test Is_Known_Non_Null flag
21479 Id := Entity (N);
21481 if OK_To_Do_Constant_Replacement (Id) then
21482 return Is_Known_Non_Null (Id);
21483 end if;
21484 end if;
21486 -- Otherwise it is not possible to determine whether N yields a non-null
21487 -- value.
21489 return False;
21490 end Known_Non_Null;
21492 ----------------
21493 -- Known_Null --
21494 ----------------
21496 function Known_Null (N : Node_Id) return Boolean is
21497 Status : constant Null_Status_Kind := Null_Status (N);
21499 Id : Entity_Id;
21500 Op : Node_Kind;
21501 Val : Node_Id;
21503 begin
21504 -- The expression yields a null value ignoring simple flow analysis
21506 if Status = Is_Null then
21507 return True;
21509 -- Otherwise check whether N is a reference to an entity that appears
21510 -- within a conditional construct.
21512 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
21514 -- First check if we are in decisive conditional
21516 Get_Current_Value_Condition (N, Op, Val);
21518 -- If Get_Current_Value_Condition were to return Val = N, then the
21519 -- recursion below could be infinite.
21521 if Val = N then
21522 raise Program_Error;
21523 end if;
21525 if Known_Null (Val) then
21526 if Op = N_Op_Eq then
21527 return True;
21528 elsif Op = N_Op_Ne then
21529 return False;
21530 end if;
21531 end if;
21533 -- If OK to do replacement, test Is_Known_Null flag
21535 Id := Entity (N);
21537 if OK_To_Do_Constant_Replacement (Id) then
21538 return Is_Known_Null (Id);
21539 end if;
21540 end if;
21542 -- Otherwise it is not possible to determine whether N yields a null
21543 -- value.
21545 return False;
21546 end Known_Null;
21548 ---------------------------
21549 -- Last_Source_Statement --
21550 ---------------------------
21552 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
21553 N : Node_Id;
21555 begin
21556 N := Last (Statements (HSS));
21557 while Present (N) loop
21558 exit when Comes_From_Source (N);
21559 Prev (N);
21560 end loop;
21562 return N;
21563 end Last_Source_Statement;
21565 -----------------------
21566 -- Mark_Coextensions --
21567 -----------------------
21569 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
21570 Is_Dynamic : Boolean;
21571 -- Indicates whether the context causes nested coextensions to be
21572 -- dynamic or static
21574 function Mark_Allocator (N : Node_Id) return Traverse_Result;
21575 -- Recognize an allocator node and label it as a dynamic coextension
21577 --------------------
21578 -- Mark_Allocator --
21579 --------------------
21581 function Mark_Allocator (N : Node_Id) return Traverse_Result is
21582 begin
21583 if Nkind (N) = N_Allocator then
21584 if Is_Dynamic then
21585 Set_Is_Static_Coextension (N, False);
21586 Set_Is_Dynamic_Coextension (N);
21588 -- If the allocator expression is potentially dynamic, it may
21589 -- be expanded out of order and require dynamic allocation
21590 -- anyway, so we treat the coextension itself as dynamic.
21591 -- Potential optimization ???
21593 elsif Nkind (Expression (N)) = N_Qualified_Expression
21594 and then Nkind (Expression (Expression (N))) = N_Op_Concat
21595 then
21596 Set_Is_Static_Coextension (N, False);
21597 Set_Is_Dynamic_Coextension (N);
21598 else
21599 Set_Is_Dynamic_Coextension (N, False);
21600 Set_Is_Static_Coextension (N);
21601 end if;
21602 end if;
21604 return OK;
21605 end Mark_Allocator;
21607 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
21609 -- Start of processing for Mark_Coextensions
21611 begin
21612 -- An allocator that appears on the right-hand side of an assignment is
21613 -- treated as a potentially dynamic coextension when the right-hand side
21614 -- is an allocator or a qualified expression.
21616 -- Obj := new ...'(new Coextension ...);
21618 if Nkind (Context_Nod) = N_Assignment_Statement then
21619 Is_Dynamic := Nkind (Expression (Context_Nod)) in
21620 N_Allocator | N_Qualified_Expression;
21622 -- An allocator that appears within the expression of a simple return
21623 -- statement is treated as a potentially dynamic coextension when the
21624 -- expression is either aggregate, allocator, or qualified expression.
21626 -- return (new Coextension ...);
21627 -- return new ...'(new Coextension ...);
21629 elsif Nkind (Context_Nod) = N_Simple_Return_Statement then
21630 Is_Dynamic := Nkind (Expression (Context_Nod)) in
21631 N_Aggregate | N_Allocator | N_Qualified_Expression;
21633 -- An alloctor that appears within the initialization expression of an
21634 -- object declaration is considered a potentially dynamic coextension
21635 -- when the initialization expression is an allocator or a qualified
21636 -- expression.
21638 -- Obj : ... := new ...'(new Coextension ...);
21640 -- A similar case arises when the object declaration is part of an
21641 -- extended return statement.
21643 -- return Obj : ... := new ...'(new Coextension ...);
21644 -- return Obj : ... := (new Coextension ...);
21646 elsif Nkind (Context_Nod) = N_Object_Declaration then
21647 Is_Dynamic := Nkind (Root_Nod) in N_Allocator | N_Qualified_Expression
21648 or else Nkind (Parent (Context_Nod)) = N_Extended_Return_Statement;
21650 -- This routine should not be called with constructs that cannot contain
21651 -- coextensions.
21653 else
21654 raise Program_Error;
21655 end if;
21657 Mark_Allocators (Root_Nod);
21658 end Mark_Coextensions;
21660 ---------------------------------
21661 -- Mark_Elaboration_Attributes --
21662 ---------------------------------
21664 procedure Mark_Elaboration_Attributes
21665 (N_Id : Node_Or_Entity_Id;
21666 Checks : Boolean := False;
21667 Level : Boolean := False;
21668 Modes : Boolean := False;
21669 Warnings : Boolean := False)
21671 function Elaboration_Checks_OK
21672 (Target_Id : Entity_Id;
21673 Context_Id : Entity_Id) return Boolean;
21674 -- Determine whether elaboration checks are enabled for target Target_Id
21675 -- which resides within context Context_Id.
21677 procedure Mark_Elaboration_Attributes_Id (Id : Entity_Id);
21678 -- Preserve relevant attributes of the context in arbitrary entity Id
21680 procedure Mark_Elaboration_Attributes_Node (N : Node_Id);
21681 -- Preserve relevant attributes of the context in arbitrary node N
21683 ---------------------------
21684 -- Elaboration_Checks_OK --
21685 ---------------------------
21687 function Elaboration_Checks_OK
21688 (Target_Id : Entity_Id;
21689 Context_Id : Entity_Id) return Boolean
21691 Encl_Scop : Entity_Id;
21693 begin
21694 -- Elaboration checks are suppressed for the target
21696 if Elaboration_Checks_Suppressed (Target_Id) then
21697 return False;
21698 end if;
21700 -- Otherwise elaboration checks are OK for the target, but may be
21701 -- suppressed for the context where the target is declared.
21703 Encl_Scop := Context_Id;
21704 while Present (Encl_Scop) and then Encl_Scop /= Standard_Standard loop
21705 if Elaboration_Checks_Suppressed (Encl_Scop) then
21706 return False;
21707 end if;
21709 Encl_Scop := Scope (Encl_Scop);
21710 end loop;
21712 -- Neither the target nor its declarative context have elaboration
21713 -- checks suppressed.
21715 return True;
21716 end Elaboration_Checks_OK;
21718 ------------------------------------
21719 -- Mark_Elaboration_Attributes_Id --
21720 ------------------------------------
21722 procedure Mark_Elaboration_Attributes_Id (Id : Entity_Id) is
21723 begin
21724 -- Mark the status of elaboration checks in effect. Do not reset the
21725 -- status in case the entity is reanalyzed with checks suppressed.
21727 if Checks and then not Is_Elaboration_Checks_OK_Id (Id) then
21728 Set_Is_Elaboration_Checks_OK_Id (Id,
21729 Elaboration_Checks_OK
21730 (Target_Id => Id,
21731 Context_Id => Scope (Id)));
21732 end if;
21734 -- Mark the status of elaboration warnings in effect. Do not reset
21735 -- the status in case the entity is reanalyzed with warnings off.
21737 if Warnings and then not Is_Elaboration_Warnings_OK_Id (Id) then
21738 Set_Is_Elaboration_Warnings_OK_Id (Id, Elab_Warnings);
21739 end if;
21740 end Mark_Elaboration_Attributes_Id;
21742 --------------------------------------
21743 -- Mark_Elaboration_Attributes_Node --
21744 --------------------------------------
21746 procedure Mark_Elaboration_Attributes_Node (N : Node_Id) is
21747 function Extract_Name (N : Node_Id) return Node_Id;
21748 -- Obtain the Name attribute of call or instantiation N
21750 ------------------
21751 -- Extract_Name --
21752 ------------------
21754 function Extract_Name (N : Node_Id) return Node_Id is
21755 Nam : Node_Id;
21757 begin
21758 Nam := Name (N);
21760 -- A call to an entry family appears in indexed form
21762 if Nkind (Nam) = N_Indexed_Component then
21763 Nam := Prefix (Nam);
21764 end if;
21766 -- The name may also appear in qualified form
21768 if Nkind (Nam) = N_Selected_Component then
21769 Nam := Selector_Name (Nam);
21770 end if;
21772 return Nam;
21773 end Extract_Name;
21775 -- Local variables
21777 Context_Id : Entity_Id;
21778 Nam : Node_Id;
21780 -- Start of processing for Mark_Elaboration_Attributes_Node
21782 begin
21783 -- Mark the status of elaboration checks in effect. Do not reset the
21784 -- status in case the node is reanalyzed with checks suppressed.
21786 if Checks and then not Is_Elaboration_Checks_OK_Node (N) then
21788 -- Assignments, attribute references, and variable references do
21789 -- not have a "declarative" context.
21791 Context_Id := Empty;
21793 -- The status of elaboration checks for calls and instantiations
21794 -- depends on the most recent pragma Suppress/Unsuppress, as well
21795 -- as the suppression status of the context where the target is
21796 -- defined.
21798 -- package Pack is
21799 -- function Func ...;
21800 -- end Pack;
21802 -- with Pack;
21803 -- procedure Main is
21804 -- pragma Suppress (Elaboration_Checks, Pack);
21805 -- X : ... := Pack.Func;
21806 -- ...
21808 -- In the example above, the call to Func has elaboration checks
21809 -- enabled because there is no active general purpose suppression
21810 -- pragma, however the elaboration checks of Pack are explicitly
21811 -- suppressed. As a result the elaboration checks of the call must
21812 -- be disabled in order to preserve this dependency.
21814 if Nkind (N) in N_Entry_Call_Statement
21815 | N_Function_Call
21816 | N_Function_Instantiation
21817 | N_Package_Instantiation
21818 | N_Procedure_Call_Statement
21819 | N_Procedure_Instantiation
21820 then
21821 Nam := Extract_Name (N);
21823 if Is_Entity_Name (Nam) and then Present (Entity (Nam)) then
21824 Context_Id := Scope (Entity (Nam));
21825 end if;
21826 end if;
21828 Set_Is_Elaboration_Checks_OK_Node (N,
21829 Elaboration_Checks_OK
21830 (Target_Id => Empty,
21831 Context_Id => Context_Id));
21832 end if;
21834 -- Mark the enclosing level of the node. Do not reset the status in
21835 -- case the node is relocated and reanalyzed.
21837 if Level and then not Is_Declaration_Level_Node (N) then
21838 Set_Is_Declaration_Level_Node (N,
21839 Find_Enclosing_Level (N) = Declaration_Level);
21840 end if;
21842 -- Mark the Ghost and SPARK mode in effect
21844 if Modes then
21845 if Ghost_Mode = Ignore then
21846 Set_Is_Ignored_Ghost_Node (N);
21847 end if;
21849 if SPARK_Mode = On then
21850 Set_Is_SPARK_Mode_On_Node (N);
21851 end if;
21852 end if;
21854 -- Mark the status of elaboration warnings in effect. Do not reset
21855 -- the status in case the node is reanalyzed with warnings off.
21857 if Warnings and then not Is_Elaboration_Warnings_OK_Node (N) then
21858 Set_Is_Elaboration_Warnings_OK_Node (N, Elab_Warnings);
21859 end if;
21860 end Mark_Elaboration_Attributes_Node;
21862 -- Start of processing for Mark_Elaboration_Attributes
21864 begin
21865 -- Do not capture any elaboration-related attributes when switch -gnatH
21866 -- (legacy elaboration checking mode enabled) is in effect because the
21867 -- attributes are useless to the legacy model.
21869 if Legacy_Elaboration_Checks then
21870 return;
21871 end if;
21873 if Nkind (N_Id) in N_Entity then
21874 Mark_Elaboration_Attributes_Id (N_Id);
21875 else
21876 Mark_Elaboration_Attributes_Node (N_Id);
21877 end if;
21878 end Mark_Elaboration_Attributes;
21880 ----------------------------------------
21881 -- Mark_Save_Invocation_Graph_Of_Body --
21882 ----------------------------------------
21884 procedure Mark_Save_Invocation_Graph_Of_Body is
21885 Main : constant Node_Id := Cunit (Main_Unit);
21886 Main_Unit : constant Node_Id := Unit (Main);
21887 Aux_Id : Entity_Id;
21889 begin
21890 Set_Save_Invocation_Graph_Of_Body (Main);
21892 -- Assume that the main unit does not have a complimentary unit
21894 Aux_Id := Empty;
21896 -- Obtain the complimentary unit of the main unit
21898 if Nkind (Main_Unit) in N_Generic_Package_Declaration
21899 | N_Generic_Subprogram_Declaration
21900 | N_Package_Declaration
21901 | N_Subprogram_Declaration
21902 then
21903 Aux_Id := Corresponding_Body (Main_Unit);
21905 elsif Nkind (Main_Unit) in N_Package_Body
21906 | N_Subprogram_Body
21907 | N_Subprogram_Renaming_Declaration
21908 then
21909 Aux_Id := Corresponding_Spec (Main_Unit);
21910 end if;
21912 if Present (Aux_Id) then
21913 Set_Save_Invocation_Graph_Of_Body
21914 (Parent (Unit_Declaration_Node (Aux_Id)));
21915 end if;
21916 end Mark_Save_Invocation_Graph_Of_Body;
21918 ----------------------------------
21919 -- Matching_Static_Array_Bounds --
21920 ----------------------------------
21922 function Matching_Static_Array_Bounds
21923 (L_Typ : Node_Id;
21924 R_Typ : Node_Id) return Boolean
21926 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
21927 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
21929 L_Index : Node_Id := Empty; -- init to ...
21930 R_Index : Node_Id := Empty; -- ...avoid warnings
21931 L_Low : Node_Id;
21932 L_High : Node_Id;
21933 L_Len : Uint;
21934 R_Low : Node_Id;
21935 R_High : Node_Id;
21936 R_Len : Uint;
21938 begin
21939 if L_Ndims /= R_Ndims then
21940 return False;
21941 end if;
21943 -- Unconstrained types do not have static bounds
21945 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
21946 return False;
21947 end if;
21949 -- First treat specially the first dimension, as the lower bound and
21950 -- length of string literals are not stored like those of arrays.
21952 if Ekind (L_Typ) = E_String_Literal_Subtype then
21953 L_Low := String_Literal_Low_Bound (L_Typ);
21954 L_Len := String_Literal_Length (L_Typ);
21955 else
21956 L_Index := First_Index (L_Typ);
21957 Get_Index_Bounds (L_Index, L_Low, L_High);
21959 if Is_OK_Static_Expression (L_Low)
21960 and then
21961 Is_OK_Static_Expression (L_High)
21962 then
21963 if Expr_Value (L_High) < Expr_Value (L_Low) then
21964 L_Len := Uint_0;
21965 else
21966 L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
21967 end if;
21968 else
21969 return False;
21970 end if;
21971 end if;
21973 if Ekind (R_Typ) = E_String_Literal_Subtype then
21974 R_Low := String_Literal_Low_Bound (R_Typ);
21975 R_Len := String_Literal_Length (R_Typ);
21976 else
21977 R_Index := First_Index (R_Typ);
21978 Get_Index_Bounds (R_Index, R_Low, R_High);
21980 if Is_OK_Static_Expression (R_Low)
21981 and then
21982 Is_OK_Static_Expression (R_High)
21983 then
21984 if Expr_Value (R_High) < Expr_Value (R_Low) then
21985 R_Len := Uint_0;
21986 else
21987 R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
21988 end if;
21989 else
21990 return False;
21991 end if;
21992 end if;
21994 if (Is_OK_Static_Expression (L_Low)
21995 and then
21996 Is_OK_Static_Expression (R_Low))
21997 and then Expr_Value (L_Low) = Expr_Value (R_Low)
21998 and then L_Len = R_Len
21999 then
22000 null;
22001 else
22002 return False;
22003 end if;
22005 -- Then treat all other dimensions
22007 for Indx in 2 .. L_Ndims loop
22008 Next (L_Index);
22009 Next (R_Index);
22011 Get_Index_Bounds (L_Index, L_Low, L_High);
22012 Get_Index_Bounds (R_Index, R_Low, R_High);
22014 if (Is_OK_Static_Expression (L_Low) and then
22015 Is_OK_Static_Expression (L_High) and then
22016 Is_OK_Static_Expression (R_Low) and then
22017 Is_OK_Static_Expression (R_High))
22018 and then (Expr_Value (L_Low) = Expr_Value (R_Low)
22019 and then
22020 Expr_Value (L_High) = Expr_Value (R_High))
22021 then
22022 null;
22023 else
22024 return False;
22025 end if;
22026 end loop;
22028 -- If we fall through the loop, all indexes matched
22030 return True;
22031 end Matching_Static_Array_Bounds;
22033 -----------------
22034 -- Might_Raise --
22035 -----------------
22037 function Might_Raise (N : Node_Id) return Boolean is
22038 Result : Boolean := False;
22040 function Process (N : Node_Id) return Traverse_Result;
22041 -- Set Result to True if we find something that could raise an exception
22043 -------------
22044 -- Process --
22045 -------------
22047 function Process (N : Node_Id) return Traverse_Result is
22048 begin
22049 if Nkind (N) in N_Procedure_Call_Statement
22050 | N_Function_Call
22051 | N_Raise_Statement
22052 | N_Raise_xxx_Error
22053 | N_Raise_Expression
22054 then
22055 Result := True;
22056 return Abandon;
22057 else
22058 return OK;
22059 end if;
22060 end Process;
22062 procedure Set_Result is new Traverse_Proc (Process);
22064 -- Start of processing for Might_Raise
22066 begin
22067 -- False if exceptions can't be propagated
22069 if No_Exception_Handlers_Set then
22070 return False;
22071 end if;
22073 -- If the checks handled by the back end are not disabled, we cannot
22074 -- ensure that no exception will be raised.
22076 if not Access_Checks_Suppressed (Empty)
22077 or else not Discriminant_Checks_Suppressed (Empty)
22078 or else not Range_Checks_Suppressed (Empty)
22079 or else not Index_Checks_Suppressed (Empty)
22080 or else Opt.Stack_Checking_Enabled
22081 then
22082 return True;
22083 end if;
22085 Set_Result (N);
22086 return Result;
22087 end Might_Raise;
22089 ----------------------------------------
22090 -- Nearest_Class_Condition_Subprogram --
22091 ----------------------------------------
22093 function Nearest_Class_Condition_Subprogram
22094 (Kind : Condition_Kind;
22095 Spec_Id : Entity_Id) return Entity_Id
22097 Subp_Id : constant Entity_Id := Ultimate_Alias (Spec_Id);
22099 begin
22100 -- Prevent cascaded errors
22102 if not Is_Dispatching_Operation (Subp_Id) then
22103 return Empty;
22105 -- No need to search if this subprogram has class-wide postconditions
22107 elsif Present (Class_Condition (Kind, Subp_Id)) then
22108 return Subp_Id;
22109 end if;
22111 -- Process the contracts of inherited subprograms, looking for
22112 -- class-wide pre/postconditions.
22114 declare
22115 Subps : constant Subprogram_List := Inherited_Subprograms (Subp_Id);
22116 Subp_Id : Entity_Id;
22118 begin
22119 for Index in Subps'Range loop
22120 Subp_Id := Subps (Index);
22122 if Present (Alias (Subp_Id)) then
22123 Subp_Id := Ultimate_Alias (Subp_Id);
22124 end if;
22126 -- Wrappers of class-wide pre/postconditions reference the
22127 -- parent primitive that has the inherited contract.
22129 if Is_Wrapper (Subp_Id)
22130 and then Present (LSP_Subprogram (Subp_Id))
22131 then
22132 Subp_Id := LSP_Subprogram (Subp_Id);
22133 end if;
22135 if Present (Class_Condition (Kind, Subp_Id)) then
22136 return Subp_Id;
22137 end if;
22138 end loop;
22139 end;
22141 return Empty;
22142 end Nearest_Class_Condition_Subprogram;
22144 --------------------------------
22145 -- Nearest_Enclosing_Instance --
22146 --------------------------------
22148 function Nearest_Enclosing_Instance (E : Entity_Id) return Entity_Id is
22149 Inst : Entity_Id;
22151 begin
22152 Inst := Scope (E);
22153 while Present (Inst) and then Inst /= Standard_Standard loop
22154 if Is_Generic_Instance (Inst) then
22155 return Inst;
22156 end if;
22158 Inst := Scope (Inst);
22159 end loop;
22161 return Empty;
22162 end Nearest_Enclosing_Instance;
22164 ------------------------
22165 -- Needs_Finalization --
22166 ------------------------
22168 function Needs_Finalization (Typ : Entity_Id) return Boolean is
22169 function Has_Some_Controlled_Component
22170 (Input_Typ : Entity_Id) return Boolean;
22171 -- Determine whether type Input_Typ has at least one controlled
22172 -- component.
22174 -----------------------------------
22175 -- Has_Some_Controlled_Component --
22176 -----------------------------------
22178 function Has_Some_Controlled_Component
22179 (Input_Typ : Entity_Id) return Boolean
22181 Comp : Entity_Id;
22183 begin
22184 -- When a type is already frozen and has at least one controlled
22185 -- component, or is manually decorated, it is sufficient to inspect
22186 -- flag Has_Controlled_Component.
22188 if Has_Controlled_Component (Input_Typ) then
22189 return True;
22191 -- Otherwise inspect the internals of the type
22193 elsif not Is_Frozen (Input_Typ) then
22194 if Is_Array_Type (Input_Typ) then
22195 return Needs_Finalization (Component_Type (Input_Typ));
22197 elsif Is_Record_Type (Input_Typ) then
22198 Comp := First_Component (Input_Typ);
22199 while Present (Comp) loop
22200 if Needs_Finalization (Etype (Comp)) then
22201 return True;
22202 end if;
22204 Next_Component (Comp);
22205 end loop;
22206 end if;
22207 end if;
22209 return False;
22210 end Has_Some_Controlled_Component;
22212 -- Start of processing for Needs_Finalization
22214 begin
22215 -- Certain run-time configurations and targets do not provide support
22216 -- for controlled types.
22218 if Restriction_Active (No_Finalization) then
22219 return False;
22221 -- C++ types are not considered controlled. It is assumed that the non-
22222 -- Ada side will handle their clean up.
22224 elsif Convention (Typ) = Convention_CPP then
22225 return False;
22227 -- Class-wide types are treated as controlled because derivations from
22228 -- the root type may introduce controlled components.
22230 elsif Is_Class_Wide_Type (Typ) then
22231 return True;
22233 -- Concurrent types are controlled as long as their corresponding record
22234 -- is controlled.
22236 elsif Is_Concurrent_Type (Typ)
22237 and then Present (Corresponding_Record_Type (Typ))
22238 and then Needs_Finalization (Corresponding_Record_Type (Typ))
22239 then
22240 return True;
22242 -- Otherwise the type is controlled when it is either derived from type
22243 -- [Limited_]Controlled and not subject to aspect Disable_Controlled, or
22244 -- contains at least one controlled component.
22246 else
22247 return
22248 Is_Controlled (Typ) or else Has_Some_Controlled_Component (Typ);
22249 end if;
22250 end Needs_Finalization;
22252 ----------------------
22253 -- Needs_One_Actual --
22254 ----------------------
22256 function Needs_One_Actual (E : Entity_Id) return Boolean is
22257 Formal : Entity_Id;
22259 begin
22260 -- Ada 2005 or later, and formals present. The first formal must be
22261 -- of a type that supports prefix notation: a controlling argument,
22262 -- a class-wide type, or an access to such.
22264 if Ada_Version >= Ada_2005
22265 and then Present (First_Formal (E))
22266 and then No (Default_Value (First_Formal (E)))
22267 and then
22268 (Is_Controlling_Formal (First_Formal (E))
22269 or else Is_Class_Wide_Type (Etype (First_Formal (E)))
22270 or else Is_Anonymous_Access_Type (Etype (First_Formal (E))))
22271 then
22272 Formal := Next_Formal (First_Formal (E));
22273 while Present (Formal) loop
22274 if No (Default_Value (Formal)) then
22275 return False;
22276 end if;
22278 Next_Formal (Formal);
22279 end loop;
22281 return True;
22283 -- Ada 83/95 or no formals
22285 else
22286 return False;
22287 end if;
22288 end Needs_One_Actual;
22290 ----------------------------
22291 -- Needs_Secondary_Stack --
22292 ----------------------------
22294 function Needs_Secondary_Stack (Id : Entity_Id) return Boolean is
22295 pragma Assert (if Present (Id) then Ekind (Id) in E_Void | Type_Kind);
22297 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean;
22298 -- Called for untagged record and protected types. Return True if the
22299 -- size of function results is known in the caller for Typ.
22301 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean;
22302 -- Returns True if Typ is a nonlimited record with defaulted
22303 -- discriminants whose max size makes it unsuitable for allocating on
22304 -- the primary stack.
22306 ------------------------------
22307 -- Caller_Known_Size_Record --
22308 ------------------------------
22310 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean is
22311 pragma Assert (if Present (Typ) then Typ = Underlying_Type (Typ));
22313 function Depends_On_Discriminant (Typ : Entity_Id) return Boolean;
22314 -- Called for untagged record and protected types. Return True if Typ
22315 -- depends on discriminants, either directly when it is unconstrained
22316 -- or indirectly when it is constrained by uplevel discriminants.
22318 -----------------------------
22319 -- Depends_On_Discriminant --
22320 -----------------------------
22322 function Depends_On_Discriminant (Typ : Entity_Id) return Boolean is
22323 Cons : Elmt_Id;
22325 begin
22326 if Has_Discriminants (Typ) then
22327 if not Is_Constrained (Typ) then
22328 return True;
22330 else
22331 Cons := First_Elmt (Discriminant_Constraint (Typ));
22332 while Present (Cons) loop
22333 if Nkind (Node (Cons)) = N_Identifier
22334 and then Ekind (Entity (Node (Cons))) = E_Discriminant
22335 then
22336 return True;
22337 end if;
22339 Next_Elmt (Cons);
22340 end loop;
22341 end if;
22342 end if;
22344 return False;
22345 end Depends_On_Discriminant;
22347 begin
22348 -- This is a protected type without Corresponding_Record_Type set,
22349 -- typically because expansion is disabled. The safe thing to do is
22350 -- to return True, so Needs_Secondary_Stack returns False.
22352 if No (Typ) then
22353 return True;
22354 end if;
22356 -- First see if we have a variant part and return False if it depends
22357 -- on discriminants.
22359 if Has_Variant_Part (Typ) and then Depends_On_Discriminant (Typ) then
22360 return False;
22361 end if;
22363 -- Then loop over components and return False if their subtype has a
22364 -- caller-unknown size, possibly recursively.
22366 -- ??? This is overly conservative, an array could be nested inside
22367 -- some other record that is constrained by nondiscriminants. That
22368 -- is, the recursive calls are too conservative.
22370 declare
22371 Comp : Entity_Id;
22373 begin
22374 Comp := First_Component (Typ);
22375 while Present (Comp) loop
22376 declare
22377 Comp_Type : constant Entity_Id :=
22378 Underlying_Type (Etype (Comp));
22380 begin
22381 if Is_Record_Type (Comp_Type) then
22382 if not Caller_Known_Size_Record (Comp_Type) then
22383 return False;
22384 end if;
22386 elsif Is_Protected_Type (Comp_Type) then
22387 if not Caller_Known_Size_Record
22388 (Corresponding_Record_Type (Comp_Type))
22389 then
22390 return False;
22391 end if;
22393 elsif Is_Array_Type (Comp_Type) then
22394 if Size_Depends_On_Discriminant (Comp_Type) then
22395 return False;
22396 end if;
22397 end if;
22398 end;
22400 Next_Component (Comp);
22401 end loop;
22402 end;
22404 return True;
22405 end Caller_Known_Size_Record;
22407 ------------------------------
22408 -- Large_Max_Size_Mutable --
22409 ------------------------------
22411 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean is
22412 pragma Assert (Typ = Underlying_Type (Typ));
22414 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean;
22415 -- Returns true if the discrete type T has a large range
22417 ----------------------------
22418 -- Is_Large_Discrete_Type --
22419 ----------------------------
22421 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean is
22422 Threshold : constant Int := 16;
22423 -- Arbitrary threshold above which we consider it "large". We want
22424 -- a fairly large threshold, because these large types really
22425 -- shouldn't have default discriminants in the first place, in
22426 -- most cases.
22428 begin
22429 return UI_To_Int (RM_Size (T)) > Threshold;
22430 end Is_Large_Discrete_Type;
22432 -- Start of processing for Large_Max_Size_Mutable
22434 begin
22435 if Is_Record_Type (Typ)
22436 and then not Is_Limited_View (Typ)
22437 and then Has_Defaulted_Discriminants (Typ)
22438 then
22439 -- Loop through the components, looking for an array whose upper
22440 -- bound(s) depends on discriminants, where both the subtype of
22441 -- the discriminant and the index subtype are too large.
22443 declare
22444 Comp : Entity_Id;
22446 begin
22447 Comp := First_Component (Typ);
22448 while Present (Comp) loop
22449 declare
22450 Comp_Type : constant Entity_Id :=
22451 Underlying_Type (Etype (Comp));
22453 Hi : Node_Id;
22454 Indx : Node_Id;
22455 Ityp : Entity_Id;
22457 begin
22458 if Is_Array_Type (Comp_Type) then
22459 Indx := First_Index (Comp_Type);
22461 while Present (Indx) loop
22462 Ityp := Etype (Indx);
22463 Hi := Type_High_Bound (Ityp);
22465 if Nkind (Hi) = N_Identifier
22466 and then Ekind (Entity (Hi)) = E_Discriminant
22467 and then Is_Large_Discrete_Type (Ityp)
22468 and then Is_Large_Discrete_Type
22469 (Etype (Entity (Hi)))
22470 then
22471 return True;
22472 end if;
22474 Next_Index (Indx);
22475 end loop;
22476 end if;
22477 end;
22479 Next_Component (Comp);
22480 end loop;
22481 end;
22482 end if;
22484 return False;
22485 end Large_Max_Size_Mutable;
22487 -- Local declarations
22489 Typ : constant Entity_Id := Underlying_Type (Id);
22491 -- Start of processing for Needs_Secondary_Stack
22493 begin
22494 -- This is a private type which is not completed yet. This can only
22495 -- happen in a default expression (of a formal parameter or of a
22496 -- record component). The safe thing to do is to return False.
22498 if No (Typ) then
22499 return False;
22500 end if;
22502 -- Do not expand transient scope for non-existent procedure return or
22503 -- string literal types.
22505 if Typ = Standard_Void_Type
22506 or else Ekind (Typ) = E_String_Literal_Subtype
22507 then
22508 return False;
22510 -- If Typ is a generic formal incomplete type, then we want to look at
22511 -- the actual type.
22513 elsif Ekind (Typ) = E_Record_Subtype
22514 and then Present (Cloned_Subtype (Typ))
22515 then
22516 return Needs_Secondary_Stack (Cloned_Subtype (Typ));
22518 -- Class-wide types obviously have an unknown size. For specific tagged
22519 -- types, if a call returning one of them is dispatching on result, and
22520 -- this type is not returned on the secondary stack, then the call goes
22521 -- through a thunk that only moves the result from the primary onto the
22522 -- secondary stack, because the computation of the size of the result is
22523 -- possible but complex from the outside.
22525 elsif Is_Class_Wide_Type (Typ) then
22526 return True;
22528 -- If the return slot of the back end cannot be accessed, then there
22529 -- is no way to call Adjust at the right time for the return object if
22530 -- the type needs finalization, so the return object must be allocated
22531 -- on the secondary stack.
22533 elsif not Back_End_Return_Slot and then Needs_Finalization (Typ) then
22534 return True;
22536 -- Definite subtypes have a known size. This includes all elementary
22537 -- types. Tasks have a known size even if they have discriminants, so
22538 -- we return False here, with one exception:
22539 -- For a type like:
22540 -- type T (Last : Natural := 0) is
22541 -- X : String (1 .. Last);
22542 -- end record;
22543 -- we return True. That's because for "P(F(...));", where F returns T,
22544 -- we don't know the size of the result at the call site, so if we
22545 -- allocated it on the primary stack, we would have to allocate the
22546 -- maximum size, which is way too big.
22548 elsif Is_Definite_Subtype (Typ) or else Is_Task_Type (Typ) then
22549 return Large_Max_Size_Mutable (Typ);
22551 -- Indefinite (discriminated) record type
22553 elsif Is_Record_Type (Typ) then
22554 return not Caller_Known_Size_Record (Typ);
22556 -- Indefinite (discriminated) protected type
22558 elsif Is_Protected_Type (Typ) then
22559 return not Caller_Known_Size_Record (Corresponding_Record_Type (Typ));
22561 -- Unconstrained array type
22563 else
22564 pragma Assert (Is_Array_Type (Typ) and then not Is_Constrained (Typ));
22565 return True;
22566 end if;
22567 end Needs_Secondary_Stack;
22569 ---------------------------------
22570 -- Needs_Simple_Initialization --
22571 ---------------------------------
22573 function Needs_Simple_Initialization
22574 (Typ : Entity_Id;
22575 Consider_IS : Boolean := True) return Boolean
22577 Consider_IS_NS : constant Boolean :=
22578 Normalize_Scalars or (Initialize_Scalars and Consider_IS);
22580 begin
22581 -- Never need initialization if it is suppressed
22583 if Initialization_Suppressed (Typ) then
22584 return False;
22585 end if;
22587 -- Check for private type, in which case test applies to the underlying
22588 -- type of the private type.
22590 if Is_Private_Type (Typ) then
22591 declare
22592 RT : constant Entity_Id := Underlying_Type (Typ);
22593 begin
22594 if Present (RT) then
22595 return Needs_Simple_Initialization (RT);
22596 else
22597 return False;
22598 end if;
22599 end;
22601 -- Scalar type with Default_Value aspect requires initialization
22603 elsif Is_Scalar_Type (Typ) and then Has_Default_Aspect (Typ) then
22604 return True;
22606 -- Cases needing simple initialization are access types, and, if pragma
22607 -- Normalize_Scalars or Initialize_Scalars is in effect, then all scalar
22608 -- types.
22610 elsif Is_Access_Type (Typ)
22611 or else (Consider_IS_NS and then Is_Scalar_Type (Typ))
22612 then
22613 return True;
22615 -- If Initialize/Normalize_Scalars is in effect, string objects also
22616 -- need initialization, unless they are created in the course of
22617 -- expanding an aggregate (since in the latter case they will be
22618 -- filled with appropriate initializing values before they are used).
22620 elsif Consider_IS_NS
22621 and then Is_Standard_String_Type (Typ)
22622 and then
22623 (not Is_Itype (Typ)
22624 or else Nkind (Associated_Node_For_Itype (Typ)) /= N_Aggregate)
22625 then
22626 return True;
22628 else
22629 return False;
22630 end if;
22631 end Needs_Simple_Initialization;
22633 -------------------------------------
22634 -- Needs_Variable_Reference_Marker --
22635 -------------------------------------
22637 function Needs_Variable_Reference_Marker
22638 (N : Node_Id;
22639 Calls_OK : Boolean) return Boolean
22641 function Within_Suitable_Context (Ref : Node_Id) return Boolean;
22642 -- Deteremine whether variable reference Ref appears within a suitable
22643 -- context that allows the creation of a marker.
22645 -----------------------------
22646 -- Within_Suitable_Context --
22647 -----------------------------
22649 function Within_Suitable_Context (Ref : Node_Id) return Boolean is
22650 Par : Node_Id;
22652 begin
22653 Par := Ref;
22654 while Present (Par) loop
22656 -- The context is not suitable when the reference appears within
22657 -- the formal part of an instantiation which acts as compilation
22658 -- unit because there is no proper list for the insertion of the
22659 -- marker.
22661 if Nkind (Par) = N_Generic_Association
22662 and then Nkind (Parent (Par)) in N_Generic_Instantiation
22663 and then Nkind (Parent (Parent (Par))) = N_Compilation_Unit
22664 then
22665 return False;
22667 -- The context is not suitable when the reference appears within
22668 -- a pragma. If the pragma has run-time semantics, the reference
22669 -- will be reconsidered once the pragma is expanded.
22671 elsif Nkind (Par) = N_Pragma then
22672 return False;
22674 -- The context is not suitable when the reference appears within a
22675 -- subprogram call, and the caller requests this behavior.
22677 elsif not Calls_OK
22678 and then Nkind (Par) in N_Entry_Call_Statement
22679 | N_Function_Call
22680 | N_Procedure_Call_Statement
22681 then
22682 return False;
22684 -- Prevent the search from going too far
22686 elsif Is_Body_Or_Package_Declaration (Par) then
22687 exit;
22688 end if;
22690 Par := Parent (Par);
22691 end loop;
22693 return True;
22694 end Within_Suitable_Context;
22696 -- Local variables
22698 Prag : Node_Id;
22699 Var_Id : Entity_Id;
22701 -- Start of processing for Needs_Variable_Reference_Marker
22703 begin
22704 -- No marker needs to be created when switch -gnatH (legacy elaboration
22705 -- checking mode enabled) is in effect because the legacy ABE mechanism
22706 -- does not use markers.
22708 if Legacy_Elaboration_Checks then
22709 return False;
22711 -- No marker needs to be created when the reference is preanalyzed
22712 -- because the marker will be inserted in the wrong place.
22714 elsif Preanalysis_Active then
22715 return False;
22717 -- Only references warrant a marker
22719 elsif Nkind (N) not in N_Expanded_Name | N_Identifier then
22720 return False;
22722 -- Only source references warrant a marker
22724 elsif not Comes_From_Source (N) then
22725 return False;
22727 -- No marker needs to be created when the reference is erroneous, left
22728 -- in a bad state, or does not denote a variable.
22730 elsif not (Present (Entity (N))
22731 and then Ekind (Entity (N)) = E_Variable
22732 and then Entity (N) /= Any_Id)
22733 then
22734 return False;
22735 end if;
22737 Var_Id := Entity (N);
22738 Prag := SPARK_Pragma (Var_Id);
22740 -- Both the variable and reference must appear in SPARK_Mode On regions
22741 -- because this elaboration scenario falls under the SPARK rules.
22743 if not (Comes_From_Source (Var_Id)
22744 and then Present (Prag)
22745 and then Get_SPARK_Mode_From_Annotation (Prag) = On
22746 and then Is_SPARK_Mode_On_Node (N))
22747 then
22748 return False;
22750 -- No marker needs to be created when the reference does not appear
22751 -- within a suitable context (see body for details).
22753 -- Performance note: parent traversal
22755 elsif not Within_Suitable_Context (N) then
22756 return False;
22757 end if;
22759 -- At this point it is known that the variable reference will play a
22760 -- role in ABE diagnostics and requires a marker.
22762 return True;
22763 end Needs_Variable_Reference_Marker;
22765 ------------------------
22766 -- New_Copy_List_Tree --
22767 ------------------------
22769 function New_Copy_List_Tree (List : List_Id) return List_Id is
22770 NL : List_Id;
22771 E : Node_Id;
22773 begin
22774 if List = No_List then
22775 return No_List;
22777 else
22778 NL := New_List;
22779 E := First (List);
22781 while Present (E) loop
22782 Append (New_Copy_Tree (E), NL);
22783 Next (E);
22784 end loop;
22786 return NL;
22787 end if;
22788 end New_Copy_List_Tree;
22790 ----------------------------
22791 -- New_Copy_Separate_List --
22792 ----------------------------
22794 function New_Copy_Separate_List (List : List_Id) return List_Id is
22795 begin
22796 if List = No_List then
22797 return No_List;
22799 else
22800 declare
22801 List_Copy : constant List_Id := New_List;
22802 N : Node_Id := First (List);
22804 begin
22805 while Present (N) loop
22806 Append (New_Copy_Separate_Tree (N), List_Copy);
22807 Next (N);
22808 end loop;
22810 return List_Copy;
22811 end;
22812 end if;
22813 end New_Copy_Separate_List;
22815 ----------------------------
22816 -- New_Copy_Separate_Tree --
22817 ----------------------------
22819 function New_Copy_Separate_Tree (Source : Node_Id) return Node_Id is
22820 function Search_Decl (N : Node_Id) return Traverse_Result;
22821 -- Subtree visitor which collects declarations
22823 procedure Search_Declarations is new Traverse_Proc (Search_Decl);
22824 -- Subtree visitor instantiation
22826 -----------------
22827 -- Search_Decl --
22828 -----------------
22830 Decls : Elist_Id;
22832 function Search_Decl (N : Node_Id) return Traverse_Result is
22833 begin
22834 if Nkind (N) in N_Declaration then
22835 Append_New_Elmt (N, Decls);
22836 end if;
22838 return OK;
22839 end Search_Decl;
22841 -- Local variables
22843 Source_Copy : constant Node_Id := New_Copy_Tree (Source);
22845 -- Start of processing for New_Copy_Separate_Tree
22847 begin
22848 Decls := No_Elist;
22849 Search_Declarations (Source_Copy);
22851 -- Associate a new Entity with all the subtree declarations (keeping
22852 -- their original name).
22854 if Present (Decls) then
22855 declare
22856 Elmt : Elmt_Id;
22857 Decl : Node_Id;
22858 New_E : Entity_Id;
22860 begin
22861 Elmt := First_Elmt (Decls);
22862 while Present (Elmt) loop
22863 Decl := Node (Elmt);
22864 New_E := Make_Temporary (Sloc (Decl), 'P');
22866 if Nkind (Decl) = N_Expression_Function then
22867 Decl := Specification (Decl);
22868 end if;
22870 if Nkind (Decl) in N_Function_Instantiation
22871 | N_Function_Specification
22872 | N_Generic_Function_Renaming_Declaration
22873 | N_Generic_Package_Renaming_Declaration
22874 | N_Generic_Procedure_Renaming_Declaration
22875 | N_Package_Body
22876 | N_Package_Instantiation
22877 | N_Package_Renaming_Declaration
22878 | N_Package_Specification
22879 | N_Procedure_Instantiation
22880 | N_Procedure_Specification
22881 then
22882 Set_Chars (New_E, Chars (Defining_Unit_Name (Decl)));
22883 Set_Defining_Unit_Name (Decl, New_E);
22884 else
22885 Set_Chars (New_E, Chars (Defining_Identifier (Decl)));
22886 Set_Defining_Identifier (Decl, New_E);
22887 end if;
22889 Next_Elmt (Elmt);
22890 end loop;
22891 end;
22892 end if;
22894 return Source_Copy;
22895 end New_Copy_Separate_Tree;
22897 -------------------
22898 -- New_Copy_Tree --
22899 -------------------
22901 -- The following tables play a key role in replicating entities and Itypes.
22902 -- They are intentionally declared at the library level rather than within
22903 -- New_Copy_Tree to avoid elaborating them on each call. This performance
22904 -- optimization saves up to 2% of the entire compilation time spent in the
22905 -- front end. Care should be taken to reset the tables on each new call to
22906 -- New_Copy_Tree.
22908 NCT_Table_Max : constant := 511;
22910 subtype NCT_Table_Index is Nat range 0 .. NCT_Table_Max - 1;
22912 function NCT_Table_Hash (Key : Node_Or_Entity_Id) return NCT_Table_Index;
22913 -- Obtain the hash value of node or entity Key
22915 --------------------
22916 -- NCT_Table_Hash --
22917 --------------------
22919 function NCT_Table_Hash (Key : Node_Or_Entity_Id) return NCT_Table_Index is
22920 begin
22921 return NCT_Table_Index (Key mod NCT_Table_Max);
22922 end NCT_Table_Hash;
22924 ----------------------
22925 -- NCT_New_Entities --
22926 ----------------------
22928 -- The following table maps old entities and Itypes to their corresponding
22929 -- new entities and Itypes.
22931 -- Aaa -> Xxx
22933 package NCT_New_Entities is new Simple_HTable (
22934 Header_Num => NCT_Table_Index,
22935 Element => Entity_Id,
22936 No_Element => Empty,
22937 Key => Entity_Id,
22938 Hash => NCT_Table_Hash,
22939 Equal => "=");
22941 ------------------------
22942 -- NCT_Pending_Itypes --
22943 ------------------------
22945 -- The following table maps old Associated_Node_For_Itype nodes to a set of
22946 -- new itypes. Given a set of old Itypes Aaa, Bbb, and Ccc, where all three
22947 -- have the same Associated_Node_For_Itype Ppp, and their corresponding new
22948 -- Itypes Xxx, Yyy, Zzz, the table contains the following mapping:
22950 -- Ppp -> (Xxx, Yyy, Zzz)
22952 -- The set is expressed as an Elist
22954 package NCT_Pending_Itypes is new Simple_HTable (
22955 Header_Num => NCT_Table_Index,
22956 Element => Elist_Id,
22957 No_Element => No_Elist,
22958 Key => Node_Id,
22959 Hash => NCT_Table_Hash,
22960 Equal => "=");
22962 NCT_Tables_In_Use : Boolean := False;
22963 -- This flag keeps track of whether the two tables NCT_New_Entities and
22964 -- NCT_Pending_Itypes are in use. The flag is part of an optimization
22965 -- where certain operations are not performed if the tables are not in
22966 -- use. This saves up to 8% of the entire compilation time spent in the
22967 -- front end.
22969 -------------------
22970 -- New_Copy_Tree --
22971 -------------------
22973 function New_Copy_Tree
22974 (Source : Node_Id;
22975 Map : Elist_Id := No_Elist;
22976 New_Sloc : Source_Ptr := No_Location;
22977 New_Scope : Entity_Id := Empty;
22978 Scopes_In_EWA_OK : Boolean := False) return Node_Id
22980 -- This routine performs low-level tree manipulations and needs access
22981 -- to the internals of the tree.
22983 EWA_Level : Nat := 0;
22984 -- This counter keeps track of how many N_Expression_With_Actions nodes
22985 -- are encountered during a depth-first traversal of the subtree. These
22986 -- nodes may define new entities in their Actions lists and thus require
22987 -- special processing.
22989 EWA_Inner_Scope_Level : Nat := 0;
22990 -- This counter keeps track of how many scoping constructs appear within
22991 -- an N_Expression_With_Actions node.
22993 procedure Add_New_Entity (Old_Id : Entity_Id; New_Id : Entity_Id);
22994 pragma Inline (Add_New_Entity);
22995 -- Add an entry in the NCT_New_Entities table which maps key Old_Id to
22996 -- value New_Id. Old_Id is an entity which appears within the Actions
22997 -- list of an N_Expression_With_Actions node, or within an entity map.
22998 -- New_Id is the corresponding new entity generated during Phase 1.
23000 procedure Add_Pending_Itype (Assoc_Nod : Node_Id; Itype : Entity_Id);
23001 pragma Inline (Add_Pending_Itype);
23002 -- Add an entry in the NCT_Pending_Itypes which maps key Assoc_Nod to
23003 -- value Itype. Assoc_Nod is the associated node of an itype. Itype is
23004 -- an itype.
23006 procedure Build_NCT_Tables (Entity_Map : Elist_Id);
23007 pragma Inline (Build_NCT_Tables);
23008 -- Populate tables NCT_New_Entities and NCT_Pending_Itypes with the
23009 -- information supplied in entity map Entity_Map. The format of the
23010 -- entity map must be as follows:
23012 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
23014 function Copy_Any_Node_With_Replacement
23015 (N : Node_Or_Entity_Id) return Node_Or_Entity_Id;
23016 pragma Inline (Copy_Any_Node_With_Replacement);
23017 -- Replicate entity or node N by invoking one of the following routines:
23019 -- Copy_Node_With_Replacement
23020 -- Corresponding_Entity
23022 function Copy_Elist_With_Replacement (List : Elist_Id) return Elist_Id;
23023 -- Replicate the elements of entity list List
23025 function Copy_Field_With_Replacement
23026 (Field : Union_Id;
23027 Old_Par : Node_Id := Empty;
23028 New_Par : Node_Id := Empty;
23029 Semantic : Boolean := False) return Union_Id;
23030 -- Replicate field Field by invoking one of the following routines:
23032 -- Copy_Elist_With_Replacement
23033 -- Copy_List_With_Replacement
23034 -- Copy_Node_With_Replacement
23035 -- Corresponding_Entity
23037 -- If the field is not an entity list, entity, itype, syntactic list,
23038 -- or node, then the field is returned unchanged. The routine always
23039 -- replicates entities, itypes, and valid syntactic fields. Old_Par is
23040 -- the expected parent of a syntactic field. New_Par is the new parent
23041 -- associated with a replicated syntactic field. Flag Semantic should
23042 -- be set when the input is a semantic field.
23044 function Copy_List_With_Replacement (List : List_Id) return List_Id;
23045 -- Replicate the elements of syntactic list List
23047 function Copy_Node_With_Replacement (N : Node_Id) return Node_Id;
23048 -- Replicate node N
23050 function Corresponding_Entity (Id : Entity_Id) return Entity_Id;
23051 pragma Inline (Corresponding_Entity);
23052 -- Return the corresponding new entity of Id generated during Phase 1.
23053 -- If there is no such entity, return Id.
23055 function In_Entity_Map
23056 (Id : Entity_Id;
23057 Entity_Map : Elist_Id) return Boolean;
23058 pragma Inline (In_Entity_Map);
23059 -- Determine whether entity Id is one of the old ids specified in entity
23060 -- map Entity_Map. The format of the entity map must be as follows:
23062 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
23064 procedure Update_CFS_Sloc (N : Node_Or_Entity_Id);
23065 pragma Inline (Update_CFS_Sloc);
23066 -- Update the Comes_From_Source and Sloc attributes of node or entity N
23068 procedure Update_Named_Associations
23069 (Old_Call : Node_Id;
23070 New_Call : Node_Id);
23071 pragma Inline (Update_Named_Associations);
23072 -- Update semantic chain First/Next_Named_Association of call New_call
23073 -- based on call Old_Call.
23075 procedure Update_New_Entities (Entity_Map : Elist_Id);
23076 pragma Inline (Update_New_Entities);
23077 -- Update the semantic attributes of all new entities generated during
23078 -- Phase 1 that do not appear in entity map Entity_Map. The format of
23079 -- the entity map must be as follows:
23081 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
23083 procedure Update_Pending_Itypes
23084 (Old_Assoc : Node_Id;
23085 New_Assoc : Node_Id);
23086 pragma Inline (Update_Pending_Itypes);
23087 -- Update semantic attribute Associated_Node_For_Itype to refer to node
23088 -- New_Assoc for all itypes whose associated node is Old_Assoc.
23090 procedure Update_Semantic_Fields (Id : Entity_Id);
23091 pragma Inline (Update_Semantic_Fields);
23092 -- Subsidiary to Update_New_Entities. Update semantic fields of entity
23093 -- or itype Id.
23095 procedure Visit_Any_Node (N : Node_Or_Entity_Id);
23096 pragma Inline (Visit_Any_Node);
23097 -- Visit entity of node N by invoking one of the following routines:
23099 -- Visit_Entity
23100 -- Visit_Itype
23101 -- Visit_Node
23103 procedure Visit_Elist (List : Elist_Id);
23104 -- Visit the elements of entity list List
23106 procedure Visit_Entity (Id : Entity_Id);
23107 -- Visit entity Id. This action may create a new entity of Id and save
23108 -- it in table NCT_New_Entities.
23110 procedure Visit_Field
23111 (Field : Union_Id;
23112 Par_Nod : Node_Id := Empty;
23113 Semantic : Boolean := False);
23114 -- Visit field Field by invoking one of the following routines:
23116 -- Visit_Elist
23117 -- Visit_Entity
23118 -- Visit_Itype
23119 -- Visit_List
23120 -- Visit_Node
23122 -- If the field is not an entity list, entity, itype, syntactic list,
23123 -- or node, then the field is not visited. The routine always visits
23124 -- valid syntactic fields. Par_Nod is the expected parent of the
23125 -- syntactic field. Flag Semantic should be set when the input is a
23126 -- semantic field.
23128 procedure Visit_Itype (Itype : Entity_Id);
23129 -- Visit itype Itype. This action may create a new entity for Itype and
23130 -- save it in table NCT_New_Entities. In addition, the routine may map
23131 -- the associated node of Itype to the new itype in NCT_Pending_Itypes.
23133 procedure Visit_List (List : List_Id);
23134 -- Visit the elements of syntactic list List
23136 procedure Visit_Node (N : Node_Id);
23137 -- Visit node N
23139 procedure Visit_Semantic_Fields (Id : Entity_Id);
23140 pragma Inline (Visit_Semantic_Fields);
23141 -- Subsidiary to Visit_Entity and Visit_Itype. Visit common semantic
23142 -- fields of entity or itype Id.
23144 --------------------
23145 -- Add_New_Entity --
23146 --------------------
23148 procedure Add_New_Entity (Old_Id : Entity_Id; New_Id : Entity_Id) is
23149 begin
23150 pragma Assert (Present (Old_Id));
23151 pragma Assert (Present (New_Id));
23152 pragma Assert (Nkind (Old_Id) in N_Entity);
23153 pragma Assert (Nkind (New_Id) in N_Entity);
23155 NCT_Tables_In_Use := True;
23157 -- Sanity check the NCT_New_Entities table. No previous mapping with
23158 -- key Old_Id should exist.
23160 pragma Assert (No (NCT_New_Entities.Get (Old_Id)));
23162 -- Establish the mapping
23164 -- Old_Id -> New_Id
23166 NCT_New_Entities.Set (Old_Id, New_Id);
23167 end Add_New_Entity;
23169 -----------------------
23170 -- Add_Pending_Itype --
23171 -----------------------
23173 procedure Add_Pending_Itype (Assoc_Nod : Node_Id; Itype : Entity_Id) is
23174 Itypes : Elist_Id;
23176 begin
23177 pragma Assert (Present (Assoc_Nod));
23178 pragma Assert (Present (Itype));
23179 pragma Assert (Nkind (Itype) in N_Entity);
23180 pragma Assert (Is_Itype (Itype));
23182 NCT_Tables_In_Use := True;
23184 -- It is not possible to sanity check the NCT_Pendint_Itypes table
23185 -- directly because a single node may act as the associated node for
23186 -- multiple itypes.
23188 Itypes := NCT_Pending_Itypes.Get (Assoc_Nod);
23190 if No (Itypes) then
23191 Itypes := New_Elmt_List;
23192 NCT_Pending_Itypes.Set (Assoc_Nod, Itypes);
23193 end if;
23195 -- Establish the mapping
23197 -- Assoc_Nod -> (Itype, ...)
23199 -- Avoid inserting the same itype multiple times. This involves a
23200 -- linear search, however the set of itypes with the same associated
23201 -- node is very small.
23203 Append_Unique_Elmt (Itype, Itypes);
23204 end Add_Pending_Itype;
23206 ----------------------
23207 -- Build_NCT_Tables --
23208 ----------------------
23210 procedure Build_NCT_Tables (Entity_Map : Elist_Id) is
23211 Elmt : Elmt_Id;
23212 Old_Id : Entity_Id;
23213 New_Id : Entity_Id;
23215 begin
23216 -- Nothing to do when there is no entity map
23218 if No (Entity_Map) then
23219 return;
23220 end if;
23222 Elmt := First_Elmt (Entity_Map);
23223 while Present (Elmt) loop
23225 -- Extract the (Old_Id, New_Id) pair from the entity map
23227 Old_Id := Node (Elmt);
23228 Next_Elmt (Elmt);
23230 New_Id := Node (Elmt);
23231 Next_Elmt (Elmt);
23233 -- Establish the following mapping within table NCT_New_Entities
23235 -- Old_Id -> New_Id
23237 Add_New_Entity (Old_Id, New_Id);
23239 -- Establish the following mapping within table NCT_Pending_Itypes
23240 -- when the new entity is an itype.
23242 -- Assoc_Nod -> (New_Id, ...)
23244 -- IMPORTANT: the associated node is that of the old itype because
23245 -- the node will be replicated in Phase 2.
23247 if Is_Itype (Old_Id) then
23248 Add_Pending_Itype
23249 (Assoc_Nod => Associated_Node_For_Itype (Old_Id),
23250 Itype => New_Id);
23251 end if;
23252 end loop;
23253 end Build_NCT_Tables;
23255 ------------------------------------
23256 -- Copy_Any_Node_With_Replacement --
23257 ------------------------------------
23259 function Copy_Any_Node_With_Replacement
23260 (N : Node_Or_Entity_Id) return Node_Or_Entity_Id
23262 begin
23263 if Nkind (N) in N_Entity then
23264 return Corresponding_Entity (N);
23265 else
23266 return Copy_Node_With_Replacement (N);
23267 end if;
23268 end Copy_Any_Node_With_Replacement;
23270 ---------------------------------
23271 -- Copy_Elist_With_Replacement --
23272 ---------------------------------
23274 function Copy_Elist_With_Replacement (List : Elist_Id) return Elist_Id is
23275 Elmt : Elmt_Id;
23276 Result : Elist_Id;
23278 begin
23279 -- Copy the contents of the old list. Note that the list itself may
23280 -- be empty, in which case the routine returns a new empty list. This
23281 -- avoids sharing lists between subtrees. The element of an entity
23282 -- list could be an entity or a node, hence the invocation of routine
23283 -- Copy_Any_Node_With_Replacement.
23285 if Present (List) then
23286 Result := New_Elmt_List;
23288 Elmt := First_Elmt (List);
23289 while Present (Elmt) loop
23290 Append_Elmt
23291 (Copy_Any_Node_With_Replacement (Node (Elmt)), Result);
23293 Next_Elmt (Elmt);
23294 end loop;
23296 -- Otherwise the list does not exist
23298 else
23299 Result := No_Elist;
23300 end if;
23302 return Result;
23303 end Copy_Elist_With_Replacement;
23305 ---------------------------------
23306 -- Copy_Field_With_Replacement --
23307 ---------------------------------
23309 function Copy_Field_With_Replacement
23310 (Field : Union_Id;
23311 Old_Par : Node_Id := Empty;
23312 New_Par : Node_Id := Empty;
23313 Semantic : Boolean := False) return Union_Id
23315 function Has_More_Ids (N : Node_Id) return Boolean;
23316 -- Return True when N has attribute More_Ids set to True
23318 function Is_Syntactic_Node return Boolean;
23319 -- Return True when Field is a syntactic node
23321 ------------------
23322 -- Has_More_Ids --
23323 ------------------
23325 function Has_More_Ids (N : Node_Id) return Boolean is
23326 begin
23327 if Nkind (N) in N_Component_Declaration
23328 | N_Discriminant_Specification
23329 | N_Exception_Declaration
23330 | N_Formal_Object_Declaration
23331 | N_Number_Declaration
23332 | N_Object_Declaration
23333 | N_Parameter_Specification
23334 | N_Use_Package_Clause
23335 | N_Use_Type_Clause
23336 then
23337 return More_Ids (N);
23338 else
23339 return False;
23340 end if;
23341 end Has_More_Ids;
23343 -----------------------
23344 -- Is_Syntactic_Node --
23345 -----------------------
23347 function Is_Syntactic_Node return Boolean is
23348 Old_N : constant Node_Id := Node_Id (Field);
23350 begin
23351 if Parent (Old_N) = Old_Par then
23352 return True;
23354 elsif not Has_More_Ids (Old_Par) then
23355 return False;
23357 -- Perform the check using the last last id in the syntactic chain
23359 else
23360 declare
23361 N : Node_Id := Old_Par;
23363 begin
23364 while Present (N) and then More_Ids (N) loop
23365 Next (N);
23366 end loop;
23368 pragma Assert (Prev_Ids (N));
23369 return Parent (Old_N) = N;
23370 end;
23371 end if;
23372 end Is_Syntactic_Node;
23374 begin
23375 -- The field is empty
23377 if Field = Union_Id (Empty) then
23378 return Field;
23380 -- The field is an entity/itype/node
23382 elsif Field in Node_Range then
23383 declare
23384 Old_N : constant Node_Id := Node_Id (Field);
23385 Syntactic : constant Boolean := Is_Syntactic_Node;
23387 New_N : Node_Id;
23389 begin
23390 -- The field is an entity/itype
23392 if Nkind (Old_N) in N_Entity then
23394 -- An entity/itype is always replicated
23396 New_N := Corresponding_Entity (Old_N);
23398 -- Update the parent pointer when the entity is a syntactic
23399 -- field. Note that itypes do not have parent pointers.
23401 if Syntactic and then New_N /= Old_N then
23402 Set_Parent (New_N, New_Par);
23403 end if;
23405 -- The field is a node
23407 else
23408 -- A node is replicated when it is either a syntactic field
23409 -- or when the caller treats it as a semantic attribute.
23411 if Syntactic or else Semantic then
23412 New_N := Copy_Node_With_Replacement (Old_N);
23414 -- Update the parent pointer when the node is a syntactic
23415 -- field.
23417 if Syntactic and then New_N /= Old_N then
23418 Set_Parent (New_N, New_Par);
23419 end if;
23421 -- Otherwise the node is returned unchanged
23423 else
23424 New_N := Old_N;
23425 end if;
23426 end if;
23428 return Union_Id (New_N);
23429 end;
23431 -- The field is an entity list
23433 elsif Field in Elist_Range then
23434 return Union_Id (Copy_Elist_With_Replacement (Elist_Id (Field)));
23436 -- The field is a syntactic list
23438 elsif Field in List_Range then
23439 declare
23440 Old_List : constant List_Id := List_Id (Field);
23441 Syntactic : constant Boolean := Parent (Old_List) = Old_Par;
23443 New_List : List_Id;
23445 begin
23446 -- A list is replicated when it is either a syntactic field or
23447 -- when the caller treats it as a semantic attribute.
23449 if Syntactic or else Semantic then
23450 New_List := Copy_List_With_Replacement (Old_List);
23452 -- Update the parent pointer when the list is a syntactic
23453 -- field.
23455 if Syntactic and then New_List /= Old_List then
23456 Set_Parent (New_List, New_Par);
23457 end if;
23459 -- Otherwise the list is returned unchanged
23461 else
23462 New_List := Old_List;
23463 end if;
23465 return Union_Id (New_List);
23466 end;
23468 -- Otherwise the field denotes an attribute that does not need to be
23469 -- replicated (Chars, literals, etc).
23471 else
23472 return Field;
23473 end if;
23474 end Copy_Field_With_Replacement;
23476 --------------------------------
23477 -- Copy_List_With_Replacement --
23478 --------------------------------
23480 function Copy_List_With_Replacement (List : List_Id) return List_Id is
23481 Elmt : Node_Id;
23482 Result : List_Id;
23484 begin
23485 -- Copy the contents of the old list. Note that the list itself may
23486 -- be empty, in which case the routine returns a new empty list. This
23487 -- avoids sharing lists between subtrees. The element of a syntactic
23488 -- list is always a node, never an entity or itype, hence the call to
23489 -- routine Copy_Node_With_Replacement.
23491 if Present (List) then
23492 Result := New_List;
23494 Elmt := First (List);
23495 while Present (Elmt) loop
23496 Append (Copy_Node_With_Replacement (Elmt), Result);
23498 Next (Elmt);
23499 end loop;
23501 -- Otherwise the list does not exist
23503 else
23504 Result := No_List;
23505 end if;
23507 return Result;
23508 end Copy_List_With_Replacement;
23510 --------------------------------
23511 -- Copy_Node_With_Replacement --
23512 --------------------------------
23514 function Copy_Node_With_Replacement (N : Node_Id) return Node_Id is
23515 Result : Node_Id;
23517 function Transform (U : Union_Id) return Union_Id;
23518 -- Copies one field, replacing N with Result
23520 ---------------
23521 -- Transform --
23522 ---------------
23524 function Transform (U : Union_Id) return Union_Id is
23525 begin
23526 return Copy_Field_With_Replacement
23527 (Field => U,
23528 Old_Par => N,
23529 New_Par => Result);
23530 end Transform;
23532 procedure Walk is new Walk_Sinfo_Fields_Pairwise (Transform);
23534 -- Start of processing for Copy_Node_With_Replacement
23536 begin
23537 -- Assume that the node must be returned unchanged
23539 Result := N;
23541 if N > Empty_Or_Error then
23542 pragma Assert (Nkind (N) not in N_Entity);
23544 Result := New_Copy (N);
23546 Walk (Result, Result);
23548 -- Update the Comes_From_Source and Sloc attributes of the node
23549 -- in case the caller has supplied new values.
23551 Update_CFS_Sloc (Result);
23553 -- Update the Associated_Node_For_Itype attribute of all itypes
23554 -- created during Phase 1 whose associated node is N. As a result
23555 -- the Associated_Node_For_Itype refers to the replicated node.
23556 -- No action needs to be taken when the Associated_Node_For_Itype
23557 -- refers to an entity because this was already handled during
23558 -- Phase 1, in Visit_Itype.
23560 Update_Pending_Itypes
23561 (Old_Assoc => N,
23562 New_Assoc => Result);
23564 -- Update the First/Next_Named_Association chain for a replicated
23565 -- call.
23567 if Nkind (N) in N_Entry_Call_Statement
23568 | N_Function_Call
23569 | N_Procedure_Call_Statement
23570 then
23571 Update_Named_Associations
23572 (Old_Call => N,
23573 New_Call => Result);
23575 -- Update the Renamed_Object attribute of a replicated object
23576 -- declaration.
23578 elsif Nkind (N) = N_Object_Renaming_Declaration then
23579 Set_Renamed_Object_Of_Possibly_Void
23580 (Defining_Entity (Result), Name (Result));
23582 -- Update the Chars attribute of identifiers
23584 elsif Nkind (N) = N_Identifier then
23586 -- The Entity field of identifiers that denote aspects is used
23587 -- to store arbitrary expressions (and hence we must check that
23588 -- they reference an actual entity before copying their Chars
23589 -- value).
23591 if Present (Entity (Result))
23592 and then Nkind (Entity (Result)) in N_Entity
23593 then
23594 Set_Chars (Result, Chars (Entity (Result)));
23595 end if;
23596 end if;
23598 if Has_Aspects (N) then
23599 Set_Aspect_Specifications (Result,
23600 Copy_List_With_Replacement (Aspect_Specifications (N)));
23601 end if;
23602 end if;
23604 return Result;
23605 end Copy_Node_With_Replacement;
23607 --------------------------
23608 -- Corresponding_Entity --
23609 --------------------------
23611 function Corresponding_Entity (Id : Entity_Id) return Entity_Id is
23612 New_Id : Entity_Id;
23613 Result : Entity_Id;
23615 begin
23616 -- Assume that the entity must be returned unchanged
23618 Result := Id;
23620 if Id > Empty_Or_Error then
23621 pragma Assert (Nkind (Id) in N_Entity);
23623 -- Determine whether the entity has a corresponding new entity
23624 -- generated during Phase 1 and if it does, use it.
23626 if NCT_Tables_In_Use then
23627 New_Id := NCT_New_Entities.Get (Id);
23629 if Present (New_Id) then
23630 Result := New_Id;
23631 end if;
23632 end if;
23633 end if;
23635 return Result;
23636 end Corresponding_Entity;
23638 -------------------
23639 -- In_Entity_Map --
23640 -------------------
23642 function In_Entity_Map
23643 (Id : Entity_Id;
23644 Entity_Map : Elist_Id) return Boolean
23646 Elmt : Elmt_Id;
23647 Old_Id : Entity_Id;
23649 begin
23650 -- The entity map contains pairs (Old_Id, New_Id). The advancement
23651 -- step always skips the New_Id portion of the pair.
23653 if Present (Entity_Map) then
23654 Elmt := First_Elmt (Entity_Map);
23655 while Present (Elmt) loop
23656 Old_Id := Node (Elmt);
23658 if Old_Id = Id then
23659 return True;
23660 end if;
23662 Next_Elmt (Elmt);
23663 Next_Elmt (Elmt);
23664 end loop;
23665 end if;
23667 return False;
23668 end In_Entity_Map;
23670 ---------------------
23671 -- Update_CFS_Sloc --
23672 ---------------------
23674 procedure Update_CFS_Sloc (N : Node_Or_Entity_Id) is
23675 begin
23676 -- A new source location defaults the Comes_From_Source attribute
23678 if New_Sloc /= No_Location then
23679 Set_Comes_From_Source (N, Get_Comes_From_Source_Default);
23680 Set_Sloc (N, New_Sloc);
23681 end if;
23682 end Update_CFS_Sloc;
23684 -------------------------------
23685 -- Update_Named_Associations --
23686 -------------------------------
23688 procedure Update_Named_Associations
23689 (Old_Call : Node_Id;
23690 New_Call : Node_Id)
23692 New_Act : Node_Id;
23693 New_Next : Node_Id;
23694 Old_Act : Node_Id;
23695 Old_Next : Node_Id;
23697 begin
23698 if No (First_Named_Actual (Old_Call)) then
23699 return;
23700 end if;
23702 -- Recreate the First/Next_Named_Actual chain of a call by traversing
23703 -- the chains of both the old and new calls in parallel.
23705 New_Act := First (Parameter_Associations (New_Call));
23706 Old_Act := First (Parameter_Associations (Old_Call));
23707 while Present (Old_Act) loop
23708 if Nkind (Old_Act) = N_Parameter_Association
23709 and then Explicit_Actual_Parameter (Old_Act)
23710 = First_Named_Actual (Old_Call)
23711 then
23712 Set_First_Named_Actual (New_Call,
23713 Explicit_Actual_Parameter (New_Act));
23714 end if;
23716 if Nkind (Old_Act) = N_Parameter_Association
23717 and then Present (Next_Named_Actual (Old_Act))
23718 then
23719 -- Scan the actual parameter list to find the next suitable
23720 -- named actual. Note that the list may be out of order.
23722 New_Next := First (Parameter_Associations (New_Call));
23723 Old_Next := First (Parameter_Associations (Old_Call));
23724 while Nkind (Old_Next) /= N_Parameter_Association
23725 or else Explicit_Actual_Parameter (Old_Next) /=
23726 Next_Named_Actual (Old_Act)
23727 loop
23728 Next (New_Next);
23729 Next (Old_Next);
23730 end loop;
23732 Set_Next_Named_Actual (New_Act,
23733 Explicit_Actual_Parameter (New_Next));
23734 end if;
23736 Next (New_Act);
23737 Next (Old_Act);
23738 end loop;
23739 end Update_Named_Associations;
23741 -------------------------
23742 -- Update_New_Entities --
23743 -------------------------
23745 procedure Update_New_Entities (Entity_Map : Elist_Id) is
23746 New_Id : Entity_Id := Empty;
23747 Old_Id : Entity_Id := Empty;
23749 begin
23750 if NCT_Tables_In_Use then
23751 NCT_New_Entities.Get_First (Old_Id, New_Id);
23753 -- Update the semantic fields of all new entities created during
23754 -- Phase 1 which were not supplied via an entity map.
23755 -- ??? Is there a better way of distinguishing those?
23757 while Present (Old_Id) and then Present (New_Id) loop
23758 if not (Present (Entity_Map)
23759 and then In_Entity_Map (Old_Id, Entity_Map))
23760 then
23761 Update_Semantic_Fields (New_Id);
23762 end if;
23764 NCT_New_Entities.Get_Next (Old_Id, New_Id);
23765 end loop;
23766 end if;
23767 end Update_New_Entities;
23769 ---------------------------
23770 -- Update_Pending_Itypes --
23771 ---------------------------
23773 procedure Update_Pending_Itypes
23774 (Old_Assoc : Node_Id;
23775 New_Assoc : Node_Id)
23777 Item : Elmt_Id;
23778 Itypes : Elist_Id;
23780 begin
23781 if NCT_Tables_In_Use then
23782 Itypes := NCT_Pending_Itypes.Get (Old_Assoc);
23784 -- Update the Associated_Node_For_Itype attribute for all itypes
23785 -- which originally refer to Old_Assoc to designate New_Assoc.
23787 if Present (Itypes) then
23788 Item := First_Elmt (Itypes);
23789 while Present (Item) loop
23790 Set_Associated_Node_For_Itype (Node (Item), New_Assoc);
23792 Next_Elmt (Item);
23793 end loop;
23794 end if;
23795 end if;
23796 end Update_Pending_Itypes;
23798 ----------------------------
23799 -- Update_Semantic_Fields --
23800 ----------------------------
23802 procedure Update_Semantic_Fields (Id : Entity_Id) is
23803 begin
23804 -- Discriminant_Constraint
23806 if Is_Type (Id) and then Has_Discriminants (Base_Type (Id)) then
23807 Set_Discriminant_Constraint (Id, Elist_Id (
23808 Copy_Field_With_Replacement
23809 (Field => Union_Id (Discriminant_Constraint (Id)),
23810 Semantic => True)));
23811 end if;
23813 -- Etype
23815 Set_Etype (Id, Node_Id (
23816 Copy_Field_With_Replacement
23817 (Field => Union_Id (Etype (Id)),
23818 Semantic => True)));
23820 -- First_Index
23821 -- Packed_Array_Impl_Type
23823 if Is_Array_Type (Id) then
23824 if Present (First_Index (Id)) then
23825 Set_First_Index (Id, First (List_Id (
23826 Copy_Field_With_Replacement
23827 (Field => Union_Id (List_Containing (First_Index (Id))),
23828 Semantic => True))));
23829 end if;
23831 if Is_Packed (Id) then
23832 Set_Packed_Array_Impl_Type (Id, Node_Id (
23833 Copy_Field_With_Replacement
23834 (Field => Union_Id (Packed_Array_Impl_Type (Id)),
23835 Semantic => True)));
23836 end if;
23837 end if;
23839 -- Prev_Entity
23841 Set_Prev_Entity (Id, Node_Id (
23842 Copy_Field_With_Replacement
23843 (Field => Union_Id (Prev_Entity (Id)),
23844 Semantic => True)));
23846 -- Next_Entity
23848 Set_Next_Entity (Id, Node_Id (
23849 Copy_Field_With_Replacement
23850 (Field => Union_Id (Next_Entity (Id)),
23851 Semantic => True)));
23853 -- Scalar_Range
23855 if Is_Discrete_Type (Id) then
23856 Set_Scalar_Range (Id, Node_Id (
23857 Copy_Field_With_Replacement
23858 (Field => Union_Id (Scalar_Range (Id)),
23859 Semantic => True)));
23860 end if;
23862 -- Scope
23864 -- Update the scope when the caller specified an explicit one
23866 if Present (New_Scope) then
23867 Set_Scope (Id, New_Scope);
23868 else
23869 Set_Scope (Id, Node_Id (
23870 Copy_Field_With_Replacement
23871 (Field => Union_Id (Scope (Id)),
23872 Semantic => True)));
23873 end if;
23874 end Update_Semantic_Fields;
23876 --------------------
23877 -- Visit_Any_Node --
23878 --------------------
23880 procedure Visit_Any_Node (N : Node_Or_Entity_Id) is
23881 begin
23882 if Nkind (N) in N_Entity then
23883 if Is_Itype (N) then
23884 Visit_Itype (N);
23885 else
23886 Visit_Entity (N);
23887 end if;
23888 else
23889 Visit_Node (N);
23890 end if;
23891 end Visit_Any_Node;
23893 -----------------
23894 -- Visit_Elist --
23895 -----------------
23897 procedure Visit_Elist (List : Elist_Id) is
23898 Elmt : Elmt_Id;
23900 begin
23901 -- The element of an entity list could be an entity, itype, or a
23902 -- node, hence the call to Visit_Any_Node.
23904 if Present (List) then
23905 Elmt := First_Elmt (List);
23906 while Present (Elmt) loop
23907 Visit_Any_Node (Node (Elmt));
23909 Next_Elmt (Elmt);
23910 end loop;
23911 end if;
23912 end Visit_Elist;
23914 ------------------
23915 -- Visit_Entity --
23916 ------------------
23918 procedure Visit_Entity (Id : Entity_Id) is
23919 New_Id : Entity_Id;
23921 begin
23922 pragma Assert (Nkind (Id) in N_Entity);
23923 pragma Assert (not Is_Itype (Id));
23925 -- Nothing to do when the entity is not defined in the Actions list
23926 -- of an N_Expression_With_Actions node.
23928 if EWA_Level = 0 then
23929 return;
23931 -- Nothing to do when the entity is defined in a scoping construct
23932 -- within an N_Expression_With_Actions node, unless the caller has
23933 -- requested their replication.
23935 -- ??? should this restriction be eliminated?
23937 elsif EWA_Inner_Scope_Level > 0 and then not Scopes_In_EWA_OK then
23938 return;
23940 -- Nothing to do when the entity does not denote a construct that
23941 -- may appear within an N_Expression_With_Actions node. Relaxing
23942 -- this restriction leads to a performance penalty.
23944 -- ??? this list is flaky, and may hide dormant bugs
23945 -- Should functions be included???
23947 -- Quantified expressions contain an entity declaration that must
23948 -- always be replaced when the expander is active, even if it has
23949 -- not been analyzed yet like e.g. in predicates.
23951 elsif Ekind (Id) not in E_Block
23952 | E_Constant
23953 | E_Label
23954 | E_Procedure
23955 | E_Variable
23956 and then not Is_Entity_Of_Quantified_Expression (Id)
23957 and then not Is_Type (Id)
23958 then
23959 return;
23961 -- Nothing to do when the entity was already visited
23963 elsif NCT_Tables_In_Use
23964 and then Present (NCT_New_Entities.Get (Id))
23965 then
23966 return;
23968 -- Nothing to do when the declaration node of the entity is not in
23969 -- the subtree being replicated.
23971 elsif not In_Subtree
23972 (N => Declaration_Node (Id),
23973 Root => Source)
23974 then
23975 return;
23976 end if;
23978 -- Create a new entity by directly copying the old entity. This
23979 -- action causes all attributes of the old entity to be inherited.
23981 New_Id := New_Copy (Id);
23983 -- Create a new name for the new entity because the back end needs
23984 -- distinct names for debugging purposes, provided that the entity
23985 -- has already been analyzed.
23987 if Ekind (Id) /= E_Void then
23988 Set_Chars (New_Id, New_Internal_Name ('T'));
23989 end if;
23991 -- Update the Comes_From_Source and Sloc attributes of the entity in
23992 -- case the caller has supplied new values.
23994 Update_CFS_Sloc (New_Id);
23996 -- Establish the following mapping within table NCT_New_Entities:
23998 -- Id -> New_Id
24000 Add_New_Entity (Id, New_Id);
24002 -- Deal with the semantic fields of entities. The fields are visited
24003 -- because they may mention entities which reside within the subtree
24004 -- being copied.
24006 Visit_Semantic_Fields (Id);
24007 end Visit_Entity;
24009 -----------------
24010 -- Visit_Field --
24011 -----------------
24013 procedure Visit_Field
24014 (Field : Union_Id;
24015 Par_Nod : Node_Id := Empty;
24016 Semantic : Boolean := False)
24018 begin
24019 -- The field is empty
24021 if Field = Union_Id (Empty) then
24022 return;
24024 -- The field is an entity/itype/node
24026 elsif Field in Node_Range then
24027 declare
24028 N : constant Node_Id := Node_Id (Field);
24030 begin
24031 -- The field is an entity/itype
24033 if Nkind (N) in N_Entity then
24035 -- Itypes are always visited
24037 if Is_Itype (N) then
24038 Visit_Itype (N);
24040 -- An entity is visited when it is either a syntactic field
24041 -- or when the caller treats it as a semantic attribute.
24043 elsif Parent (N) = Par_Nod or else Semantic then
24044 Visit_Entity (N);
24045 end if;
24047 -- The field is a node
24049 else
24050 -- A node is visited when it is either a syntactic field or
24051 -- when the caller treats it as a semantic attribute.
24053 if Parent (N) = Par_Nod or else Semantic then
24054 Visit_Node (N);
24055 end if;
24056 end if;
24057 end;
24059 -- The field is an entity list
24061 elsif Field in Elist_Range then
24062 Visit_Elist (Elist_Id (Field));
24064 -- The field is a syntax list
24066 elsif Field in List_Range then
24067 declare
24068 List : constant List_Id := List_Id (Field);
24070 begin
24071 -- A syntax list is visited when it is either a syntactic field
24072 -- or when the caller treats it as a semantic attribute.
24074 if Parent (List) = Par_Nod or else Semantic then
24075 Visit_List (List);
24076 end if;
24077 end;
24079 -- Otherwise the field denotes information which does not need to be
24080 -- visited (chars, literals, etc.).
24082 else
24083 null;
24084 end if;
24085 end Visit_Field;
24087 -----------------
24088 -- Visit_Itype --
24089 -----------------
24091 procedure Visit_Itype (Itype : Entity_Id) is
24092 New_Assoc : Node_Id;
24093 New_Itype : Entity_Id;
24094 Old_Assoc : Node_Id;
24096 begin
24097 pragma Assert (Nkind (Itype) in N_Entity);
24098 pragma Assert (Is_Itype (Itype));
24100 -- Itypes that describe the designated type of access to subprograms
24101 -- have the structure of subprogram declarations, with signatures,
24102 -- etc. Either we duplicate the signatures completely, or choose to
24103 -- share such itypes, which is fine because their elaboration will
24104 -- have no side effects.
24106 if Ekind (Itype) = E_Subprogram_Type then
24107 return;
24109 -- Nothing to do if the itype was already visited
24111 elsif NCT_Tables_In_Use
24112 and then Present (NCT_New_Entities.Get (Itype))
24113 then
24114 return;
24116 -- Nothing to do if the associated node of the itype is not within
24117 -- the subtree being replicated.
24119 elsif not In_Subtree
24120 (N => Associated_Node_For_Itype (Itype),
24121 Root => Source)
24122 then
24123 return;
24124 end if;
24126 -- Create a new itype by directly copying the old itype. This action
24127 -- causes all attributes of the old itype to be inherited.
24129 New_Itype := New_Copy (Itype);
24131 -- Create a new name for the new itype because the back end requires
24132 -- distinct names for debugging purposes.
24134 Set_Chars (New_Itype, New_Internal_Name ('T'));
24136 -- Update the Comes_From_Source and Sloc attributes of the itype in
24137 -- case the caller has supplied new values.
24139 Update_CFS_Sloc (New_Itype);
24141 -- Establish the following mapping within table NCT_New_Entities:
24143 -- Itype -> New_Itype
24145 Add_New_Entity (Itype, New_Itype);
24147 -- The new itype must be unfrozen because the resulting subtree may
24148 -- be inserted anywhere and cause an earlier or later freezing.
24150 if Present (Freeze_Node (New_Itype)) then
24151 Set_Freeze_Node (New_Itype, Empty);
24152 Set_Is_Frozen (New_Itype, False);
24153 end if;
24155 -- If a record subtype is simply copied, the entity list will be
24156 -- shared, so Cloned_Subtype must be set to indicate this.
24158 if Ekind (Itype) in E_Class_Wide_Subtype | E_Record_Subtype then
24159 Set_Cloned_Subtype (New_Itype, Itype);
24160 end if;
24162 -- The associated node may denote an entity, in which case it may
24163 -- already have a new corresponding entity created during a prior
24164 -- call to Visit_Entity or Visit_Itype for the same subtree.
24166 -- Given
24167 -- Old_Assoc ---------> New_Assoc
24169 -- Created by Visit_Itype
24170 -- Itype -------------> New_Itype
24171 -- ANFI = Old_Assoc ANFI = Old_Assoc < must be updated
24173 -- In the example above, Old_Assoc is an arbitrary entity that was
24174 -- already visited for the same subtree and has a corresponding new
24175 -- entity New_Assoc. Old_Assoc was inherited by New_Itype by virtue
24176 -- of copying entities, however it must be updated to New_Assoc.
24178 Old_Assoc := Associated_Node_For_Itype (Itype);
24180 if Nkind (Old_Assoc) in N_Entity then
24181 if NCT_Tables_In_Use then
24182 New_Assoc := NCT_New_Entities.Get (Old_Assoc);
24184 if Present (New_Assoc) then
24185 Set_Associated_Node_For_Itype (New_Itype, New_Assoc);
24186 end if;
24187 end if;
24189 -- Otherwise the associated node denotes a node. Postpone the update
24190 -- until Phase 2 when the node is replicated. Establish the following
24191 -- mapping within table NCT_Pending_Itypes:
24193 -- Old_Assoc -> (New_Type, ...)
24195 else
24196 Add_Pending_Itype (Old_Assoc, New_Itype);
24197 end if;
24199 -- Deal with the semantic fields of itypes. The fields are visited
24200 -- because they may mention entities that reside within the subtree
24201 -- being copied.
24203 Visit_Semantic_Fields (Itype);
24204 end Visit_Itype;
24206 ----------------
24207 -- Visit_List --
24208 ----------------
24210 procedure Visit_List (List : List_Id) is
24211 Elmt : Node_Id;
24213 begin
24214 -- Note that the element of a syntactic list is always a node, never
24215 -- an entity or itype, hence the call to Visit_Node.
24217 if Present (List) then
24218 Elmt := First (List);
24219 while Present (Elmt) loop
24220 Visit_Node (Elmt);
24222 Next (Elmt);
24223 end loop;
24224 end if;
24225 end Visit_List;
24227 ----------------
24228 -- Visit_Node --
24229 ----------------
24231 procedure Visit_Node (N : Node_Id) is
24232 begin
24233 pragma Assert (Nkind (N) not in N_Entity);
24235 -- If the node is a quantified expression and expander is active,
24236 -- it contains an implicit declaration that may require a new entity
24237 -- when the condition has already been (pre)analyzed.
24239 if Nkind (N) = N_Expression_With_Actions
24240 or else
24241 (Nkind (N) = N_Quantified_Expression and then Expander_Active)
24242 then
24243 EWA_Level := EWA_Level + 1;
24245 elsif EWA_Level > 0
24246 and then Nkind (N) in N_Block_Statement
24247 | N_Subprogram_Body
24248 | N_Subprogram_Declaration
24249 then
24250 EWA_Inner_Scope_Level := EWA_Inner_Scope_Level + 1;
24251 end if;
24253 -- If the node is a block, we need to process all declarations
24254 -- in the block and make new entities for each.
24256 if Nkind (N) = N_Block_Statement and then Present (Declarations (N))
24257 then
24258 declare
24259 Decl : Node_Id := First (Declarations (N));
24261 begin
24262 while Present (Decl) loop
24263 if Nkind (Decl) = N_Object_Declaration then
24264 Add_New_Entity (Defining_Identifier (Decl),
24265 New_Copy (Defining_Identifier (Decl)));
24266 end if;
24268 Next (Decl);
24269 end loop;
24270 end;
24271 end if;
24273 declare
24274 procedure Action (U : Union_Id);
24275 procedure Action (U : Union_Id) is
24276 begin
24277 Visit_Field (Field => U, Par_Nod => N);
24278 end Action;
24280 procedure Walk is new Walk_Sinfo_Fields (Action);
24281 begin
24282 Walk (N);
24283 end;
24285 if EWA_Level > 0
24286 and then Nkind (N) in N_Block_Statement
24287 | N_Subprogram_Body
24288 | N_Subprogram_Declaration
24289 then
24290 EWA_Inner_Scope_Level := EWA_Inner_Scope_Level - 1;
24292 elsif Nkind (N) = N_Expression_With_Actions then
24293 EWA_Level := EWA_Level - 1;
24294 end if;
24295 end Visit_Node;
24297 ---------------------------
24298 -- Visit_Semantic_Fields --
24299 ---------------------------
24301 procedure Visit_Semantic_Fields (Id : Entity_Id) is
24302 begin
24303 pragma Assert (Nkind (Id) in N_Entity);
24305 -- Discriminant_Constraint
24307 if Is_Type (Id) and then Has_Discriminants (Base_Type (Id)) then
24308 Visit_Field
24309 (Field => Union_Id (Discriminant_Constraint (Id)),
24310 Semantic => True);
24311 end if;
24313 -- Etype
24315 Visit_Field
24316 (Field => Union_Id (Etype (Id)),
24317 Semantic => True);
24319 -- First_Index
24320 -- Packed_Array_Impl_Type
24322 if Is_Array_Type (Id) then
24323 if Present (First_Index (Id)) then
24324 Visit_Field
24325 (Field => Union_Id (List_Containing (First_Index (Id))),
24326 Semantic => True);
24327 end if;
24329 if Is_Packed (Id) then
24330 Visit_Field
24331 (Field => Union_Id (Packed_Array_Impl_Type (Id)),
24332 Semantic => True);
24333 end if;
24334 end if;
24336 -- Scalar_Range
24338 if Is_Discrete_Type (Id) then
24339 Visit_Field
24340 (Field => Union_Id (Scalar_Range (Id)),
24341 Semantic => True);
24342 end if;
24343 end Visit_Semantic_Fields;
24345 -- Start of processing for New_Copy_Tree
24347 begin
24348 -- Routine New_Copy_Tree performs a deep copy of a subtree by creating
24349 -- shallow copies for each node within, and then updating the child and
24350 -- parent pointers accordingly. This process is straightforward, however
24351 -- the routine must deal with the following complications:
24353 -- * Entities defined within N_Expression_With_Actions nodes must be
24354 -- replicated rather than shared to avoid introducing two identical
24355 -- symbols within the same scope. Note that no other expression can
24356 -- currently define entities.
24358 -- do
24359 -- Source_Low : ...;
24360 -- Source_High : ...;
24362 -- <reference to Source_Low>
24363 -- <reference to Source_High>
24364 -- in ... end;
24366 -- New_Copy_Tree handles this case by first creating new entities
24367 -- and then updating all existing references to point to these new
24368 -- entities.
24370 -- do
24371 -- New_Low : ...;
24372 -- New_High : ...;
24374 -- <reference to New_Low>
24375 -- <reference to New_High>
24376 -- in ... end;
24378 -- * Itypes defined within the subtree must be replicated to avoid any
24379 -- dependencies on invalid or inaccessible data.
24381 -- subtype Source_Itype is ... range Source_Low .. Source_High;
24383 -- New_Copy_Tree handles this case by first creating a new itype in
24384 -- the same fashion as entities, and then updating various relevant
24385 -- constraints.
24387 -- subtype New_Itype is ... range New_Low .. New_High;
24389 -- * The Associated_Node_For_Itype field of itypes must be updated to
24390 -- reference the proper replicated entity or node.
24392 -- * Semantic fields of entities such as Etype and Scope must be
24393 -- updated to reference the proper replicated entities.
24395 -- * Some semantic fields of nodes must be updated to reference
24396 -- the proper replicated nodes.
24398 -- Finally, quantified expressions contain an implicit declaration for
24399 -- the bound variable. Given that quantified expressions appearing
24400 -- in contracts are copied to create pragmas and eventually checking
24401 -- procedures, a new bound variable must be created for each copy, to
24402 -- prevent multiple declarations of the same symbol.
24404 -- To meet all these demands, routine New_Copy_Tree is split into two
24405 -- phases.
24407 -- Phase 1 traverses the tree in order to locate entities and itypes
24408 -- defined within the subtree. New entities are generated and saved in
24409 -- table NCT_New_Entities. The semantic fields of all new entities and
24410 -- itypes are then updated accordingly.
24412 -- Phase 2 traverses the tree in order to replicate each node. Various
24413 -- semantic fields of nodes and entities are updated accordingly.
24415 -- Preparatory phase. Clear the contents of tables NCT_New_Entities and
24416 -- NCT_Pending_Itypes in case a previous call to New_Copy_Tree left some
24417 -- data inside.
24419 if NCT_Tables_In_Use then
24420 NCT_Tables_In_Use := False;
24422 NCT_New_Entities.Reset;
24423 NCT_Pending_Itypes.Reset;
24424 end if;
24426 -- Populate tables NCT_New_Entities and NCT_Pending_Itypes with data
24427 -- supplied by a linear entity map. The tables offer faster access to
24428 -- the same data.
24430 Build_NCT_Tables (Map);
24432 -- Execute Phase 1. Traverse the subtree and generate new entities for
24433 -- the following cases:
24435 -- * An entity defined within an N_Expression_With_Actions node
24437 -- * An itype referenced within the subtree where the associated node
24438 -- is also in the subtree.
24440 -- All new entities are accessible via table NCT_New_Entities, which
24441 -- contains mappings of the form:
24443 -- Old_Entity -> New_Entity
24444 -- Old_Itype -> New_Itype
24446 -- In addition, the associated nodes of all new itypes are mapped in
24447 -- table NCT_Pending_Itypes:
24449 -- Assoc_Nod -> (New_Itype1, New_Itype2, .., New_ItypeN)
24451 Visit_Any_Node (Source);
24453 -- Update the semantic attributes of all new entities generated during
24454 -- Phase 1 before starting Phase 2. The updates could be performed in
24455 -- routine Corresponding_Entity, however this may cause the same entity
24456 -- to be updated multiple times, effectively generating useless nodes.
24457 -- Keeping the updates separates from Phase 2 ensures that only one set
24458 -- of attributes is generated for an entity at any one time.
24460 Update_New_Entities (Map);
24462 -- Execute Phase 2. Replicate the source subtree one node at a time.
24463 -- The following transformations take place:
24465 -- * References to entities and itypes are updated to refer to the
24466 -- new entities and itypes generated during Phase 1.
24468 -- * All Associated_Node_For_Itype attributes of itypes are updated
24469 -- to refer to the new replicated Associated_Node_For_Itype.
24471 return Copy_Node_With_Replacement (Source);
24472 end New_Copy_Tree;
24474 -------------------------
24475 -- New_External_Entity --
24476 -------------------------
24478 function New_External_Entity
24479 (Kind : Entity_Kind;
24480 Scope_Id : Entity_Id;
24481 Sloc_Value : Source_Ptr;
24482 Related_Id : Entity_Id;
24483 Suffix : Character;
24484 Suffix_Index : Int := 0;
24485 Prefix : Character := ' ') return Entity_Id
24487 N : constant Entity_Id :=
24488 Make_Defining_Identifier (Sloc_Value,
24489 New_External_Name
24490 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
24492 begin
24493 Mutate_Ekind (N, Kind);
24494 Set_Is_Internal (N, True);
24495 Append_Entity (N, Scope_Id);
24496 Set_Public_Status (N);
24498 if Kind in Type_Kind then
24499 Reinit_Size_Align (N);
24500 end if;
24502 return N;
24503 end New_External_Entity;
24505 -------------------------
24506 -- New_Internal_Entity --
24507 -------------------------
24509 function New_Internal_Entity
24510 (Kind : Entity_Kind;
24511 Scope_Id : Entity_Id;
24512 Sloc_Value : Source_Ptr;
24513 Id_Char : Character) return Entity_Id
24515 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
24517 begin
24518 Mutate_Ekind (N, Kind);
24519 Set_Is_Internal (N, True);
24520 Append_Entity (N, Scope_Id);
24522 if Kind in Type_Kind then
24523 Reinit_Size_Align (N);
24524 end if;
24526 return N;
24527 end New_Internal_Entity;
24529 -----------------
24530 -- Next_Actual --
24531 -----------------
24533 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
24534 Par : constant Node_Id := Parent (Actual_Id);
24535 N : Node_Id;
24537 begin
24538 -- If we are pointing at a positional parameter, it is a member of a
24539 -- node list (the list of parameters), and the next parameter is the
24540 -- next node on the list, unless we hit a parameter association, then
24541 -- we shift to using the chain whose head is the First_Named_Actual in
24542 -- the parent, and then is threaded using the Next_Named_Actual of the
24543 -- Parameter_Association. All this fiddling is because the original node
24544 -- list is in the textual call order, and what we need is the
24545 -- declaration order.
24547 if Is_List_Member (Actual_Id) then
24548 N := Next (Actual_Id);
24550 if Nkind (N) = N_Parameter_Association then
24552 -- In case of a build-in-place call, the call will no longer be a
24553 -- call; it will have been rewritten.
24555 if Nkind (Par) in N_Entry_Call_Statement
24556 | N_Function_Call
24557 | N_Procedure_Call_Statement
24558 then
24559 return First_Named_Actual (Par);
24561 -- In case of a call rewritten in GNATprove mode while "inlining
24562 -- for proof" go to the original call.
24564 elsif Nkind (Par) = N_Null_Statement then
24565 pragma Assert
24566 (GNATprove_Mode
24567 and then
24568 Nkind (Original_Node (Par)) in N_Subprogram_Call);
24570 return First_Named_Actual (Original_Node (Par));
24571 else
24572 return Empty;
24573 end if;
24574 else
24575 return N;
24576 end if;
24578 else
24579 return Next_Named_Actual (Parent (Actual_Id));
24580 end if;
24581 end Next_Actual;
24583 procedure Next_Actual (Actual_Id : in out Node_Id) is
24584 begin
24585 Actual_Id := Next_Actual (Actual_Id);
24586 end Next_Actual;
24588 -----------------
24589 -- Next_Global --
24590 -----------------
24592 function Next_Global (Node : Node_Id) return Node_Id is
24593 begin
24594 -- The global item may either be in a list, or by itself, in which case
24595 -- there is no next global item with the same mode.
24597 if Is_List_Member (Node) then
24598 return Next (Node);
24599 else
24600 return Empty;
24601 end if;
24602 end Next_Global;
24604 procedure Next_Global (Node : in out Node_Id) is
24605 begin
24606 Node := Next_Global (Node);
24607 end Next_Global;
24609 ------------------------
24610 -- No_Caching_Enabled --
24611 ------------------------
24613 function No_Caching_Enabled (Id : Entity_Id) return Boolean is
24614 Prag : constant Node_Id := Get_Pragma (Id, Pragma_No_Caching);
24615 Arg1 : Node_Id;
24617 begin
24618 if Present (Prag) then
24619 Arg1 := First (Pragma_Argument_Associations (Prag));
24621 -- The pragma has an optional Boolean expression, the related
24622 -- property is enabled only when the expression evaluates to True.
24624 if Present (Arg1) then
24625 return Is_True (Expr_Value (Get_Pragma_Arg (Arg1)));
24627 -- Otherwise the lack of expression enables the property by
24628 -- default.
24630 else
24631 return True;
24632 end if;
24634 -- The property was never set in the first place
24636 else
24637 return False;
24638 end if;
24639 end No_Caching_Enabled;
24641 --------------------------
24642 -- No_Heap_Finalization --
24643 --------------------------
24645 function No_Heap_Finalization (Typ : Entity_Id) return Boolean is
24646 begin
24647 if Ekind (Typ) in E_Access_Type | E_General_Access_Type
24648 and then Is_Library_Level_Entity (Typ)
24649 then
24650 -- A global No_Heap_Finalization pragma applies to all library-level
24651 -- named access-to-object types.
24653 if Present (No_Heap_Finalization_Pragma) then
24654 return True;
24656 -- The library-level named access-to-object type itself is subject to
24657 -- pragma No_Heap_Finalization.
24659 elsif Present (Get_Pragma (Typ, Pragma_No_Heap_Finalization)) then
24660 return True;
24661 end if;
24662 end if;
24664 return False;
24665 end No_Heap_Finalization;
24667 -----------------------
24668 -- Normalize_Actuals --
24669 -----------------------
24671 -- Chain actuals according to formals of subprogram. If there are no named
24672 -- associations, the chain is simply the list of Parameter Associations,
24673 -- since the order is the same as the declaration order. If there are named
24674 -- associations, then the First_Named_Actual field in the N_Function_Call
24675 -- or N_Procedure_Call_Statement node points to the Parameter_Association
24676 -- node for the parameter that comes first in declaration order. The
24677 -- remaining named parameters are then chained in declaration order using
24678 -- Next_Named_Actual.
24680 -- This routine also verifies that the number of actuals is compatible with
24681 -- the number and default values of formals, but performs no type checking
24682 -- (type checking is done by the caller).
24684 -- If the matching succeeds, Success is set to True and the caller proceeds
24685 -- with type-checking. If the match is unsuccessful, then Success is set to
24686 -- False, and the caller attempts a different interpretation, if there is
24687 -- one.
24689 -- If the flag Report is on, the call is not overloaded, and a failure to
24690 -- match can be reported here, rather than in the caller.
24692 procedure Normalize_Actuals
24693 (N : Node_Id;
24694 S : Entity_Id;
24695 Report : Boolean;
24696 Success : out Boolean)
24698 Actuals : constant List_Id := Parameter_Associations (N);
24699 Actual : Node_Id := Empty;
24700 Formal : Entity_Id;
24701 Last : Node_Id := Empty;
24702 First_Named : Node_Id := Empty;
24703 Found : Boolean;
24705 Formals_To_Match : Integer := 0;
24706 Actuals_To_Match : Integer := 0;
24708 procedure Chain (A : Node_Id);
24709 -- Add named actual at the proper place in the list, using the
24710 -- Next_Named_Actual link.
24712 function Reporting return Boolean;
24713 -- Determines if an error is to be reported. To report an error, we
24714 -- need Report to be True, and also we do not report errors caused
24715 -- by calls to init procs that occur within other init procs. Such
24716 -- errors must always be cascaded errors, since if all the types are
24717 -- declared correctly, the compiler will certainly build decent calls.
24719 -----------
24720 -- Chain --
24721 -----------
24723 procedure Chain (A : Node_Id) is
24724 begin
24725 if No (Last) then
24727 -- Call node points to first actual in list
24729 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
24731 else
24732 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
24733 end if;
24735 Last := A;
24736 Set_Next_Named_Actual (Last, Empty);
24737 end Chain;
24739 ---------------
24740 -- Reporting --
24741 ---------------
24743 function Reporting return Boolean is
24744 begin
24745 if not Report then
24746 return False;
24748 elsif not Within_Init_Proc then
24749 return True;
24751 elsif Is_Init_Proc (Entity (Name (N))) then
24752 return False;
24754 else
24755 return True;
24756 end if;
24757 end Reporting;
24759 -- Start of processing for Normalize_Actuals
24761 begin
24762 if Is_Access_Type (S) then
24764 -- The name in the call is a function call that returns an access
24765 -- to subprogram. The designated type has the list of formals.
24767 Formal := First_Formal (Designated_Type (S));
24768 else
24769 Formal := First_Formal (S);
24770 end if;
24772 while Present (Formal) loop
24773 Formals_To_Match := Formals_To_Match + 1;
24774 Next_Formal (Formal);
24775 end loop;
24777 -- Find if there is a named association, and verify that no positional
24778 -- associations appear after named ones.
24780 if Present (Actuals) then
24781 Actual := First (Actuals);
24782 end if;
24784 while Present (Actual)
24785 and then Nkind (Actual) /= N_Parameter_Association
24786 loop
24787 Actuals_To_Match := Actuals_To_Match + 1;
24788 Next (Actual);
24789 end loop;
24791 if No (Actual) and Actuals_To_Match = Formals_To_Match then
24793 -- Most common case: positional notation, no defaults
24795 Success := True;
24796 return;
24798 elsif Actuals_To_Match > Formals_To_Match then
24800 -- Too many actuals: will not work
24802 if Reporting then
24803 if Is_Entity_Name (Name (N)) then
24804 Error_Msg_N ("too many arguments in call to&", Name (N));
24805 else
24806 Error_Msg_N ("too many arguments in call", N);
24807 end if;
24808 end if;
24810 Success := False;
24811 return;
24812 end if;
24814 First_Named := Actual;
24816 while Present (Actual) loop
24817 if Nkind (Actual) /= N_Parameter_Association then
24818 Error_Msg_N
24819 ("positional parameters not allowed after named ones", Actual);
24820 Success := False;
24821 return;
24823 else
24824 Actuals_To_Match := Actuals_To_Match + 1;
24825 end if;
24827 Next (Actual);
24828 end loop;
24830 if Present (Actuals) then
24831 Actual := First (Actuals);
24832 end if;
24834 Formal := First_Formal (S);
24835 while Present (Formal) loop
24837 -- Match the formals in order. If the corresponding actual is
24838 -- positional, nothing to do. Else scan the list of named actuals
24839 -- to find the one with the right name.
24841 if Present (Actual)
24842 and then Nkind (Actual) /= N_Parameter_Association
24843 then
24844 Next (Actual);
24845 Actuals_To_Match := Actuals_To_Match - 1;
24846 Formals_To_Match := Formals_To_Match - 1;
24848 else
24849 -- For named parameters, search the list of actuals to find
24850 -- one that matches the next formal name.
24852 Actual := First_Named;
24853 Found := False;
24854 while Present (Actual) loop
24855 if Chars (Selector_Name (Actual)) = Chars (Formal) then
24856 Found := True;
24857 Chain (Actual);
24858 Actuals_To_Match := Actuals_To_Match - 1;
24859 Formals_To_Match := Formals_To_Match - 1;
24860 exit;
24861 end if;
24863 Next (Actual);
24864 end loop;
24866 if not Found then
24867 if Ekind (Formal) /= E_In_Parameter
24868 or else No (Default_Value (Formal))
24869 then
24870 if Reporting then
24871 if (Comes_From_Source (S)
24872 or else Sloc (S) = Standard_Location)
24873 and then Is_Overloadable (S)
24874 then
24875 if No (Actuals)
24876 and then
24877 Nkind (Parent (N)) in N_Procedure_Call_Statement
24878 | N_Function_Call
24879 | N_Parameter_Association
24880 and then Ekind (S) /= E_Function
24881 then
24882 Set_Etype (N, Etype (S));
24884 else
24885 Error_Msg_Name_1 := Chars (S);
24886 Error_Msg_Sloc := Sloc (S);
24887 Error_Msg_NE
24888 ("missing argument for parameter & "
24889 & "in call to % declared #", N, Formal);
24890 end if;
24892 elsif Is_Overloadable (S) then
24893 Error_Msg_Name_1 := Chars (S);
24895 -- Point to type derivation that generated the
24896 -- operation.
24898 Error_Msg_Sloc := Sloc (Parent (S));
24900 Error_Msg_NE
24901 ("missing argument for parameter & "
24902 & "in call to % (inherited) #", N, Formal);
24904 else
24905 Error_Msg_NE
24906 ("missing argument for parameter &", N, Formal);
24907 end if;
24908 end if;
24910 Success := False;
24911 return;
24913 else
24914 Formals_To_Match := Formals_To_Match - 1;
24915 end if;
24916 end if;
24917 end if;
24919 Next_Formal (Formal);
24920 end loop;
24922 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
24923 Success := True;
24924 return;
24926 else
24927 if Reporting then
24929 -- Find some superfluous named actual that did not get
24930 -- attached to the list of associations.
24932 Actual := First (Actuals);
24933 while Present (Actual) loop
24934 if Nkind (Actual) = N_Parameter_Association
24935 and then Actual /= Last
24936 and then No (Next_Named_Actual (Actual))
24937 then
24938 -- A validity check may introduce a copy of a call that
24939 -- includes an extra actual (for example for an unrelated
24940 -- accessibility check). Check that the extra actual matches
24941 -- some extra formal, which must exist already because
24942 -- subprogram must be frozen at this point.
24944 if Present (Extra_Formals (S))
24945 and then not Comes_From_Source (Actual)
24946 and then Nkind (Actual) = N_Parameter_Association
24947 and then Chars (Extra_Formals (S)) =
24948 Chars (Selector_Name (Actual))
24949 then
24950 null;
24951 else
24952 Error_Msg_N
24953 ("unmatched actual & in call", Selector_Name (Actual));
24954 exit;
24955 end if;
24956 end if;
24958 Next (Actual);
24959 end loop;
24960 end if;
24962 Success := False;
24963 return;
24964 end if;
24965 end Normalize_Actuals;
24967 --------------------------------
24968 -- Note_Possible_Modification --
24969 --------------------------------
24971 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
24972 Modification_Comes_From_Source : constant Boolean :=
24973 Comes_From_Source (Parent (N));
24975 Ent : Entity_Id;
24976 Exp : Node_Id;
24978 begin
24979 -- Loop to find referenced entity, if there is one
24981 Exp := N;
24982 loop
24983 Ent := Empty;
24985 if Is_Entity_Name (Exp) then
24986 Ent := Entity (Exp);
24988 -- If the entity is missing, it is an undeclared identifier,
24989 -- and there is nothing to annotate.
24991 if No (Ent) then
24992 return;
24993 end if;
24995 elsif Nkind (Exp) = N_Explicit_Dereference then
24996 declare
24997 P : constant Node_Id := Prefix (Exp);
24999 begin
25000 -- In formal verification mode, keep track of all reads and
25001 -- writes through explicit dereferences.
25003 if GNATprove_Mode then
25004 SPARK_Specific.Generate_Dereference (N, 'm');
25005 end if;
25007 if Nkind (P) = N_Selected_Component
25008 and then Present (Entry_Formal (Entity (Selector_Name (P))))
25009 then
25010 -- Case of a reference to an entry formal
25012 Ent := Entry_Formal (Entity (Selector_Name (P)));
25014 elsif Nkind (P) = N_Identifier
25015 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
25016 and then Present (Expression (Parent (Entity (P))))
25017 and then Nkind (Expression (Parent (Entity (P)))) =
25018 N_Reference
25019 then
25020 -- Case of a reference to a value on which side effects have
25021 -- been removed.
25023 Exp := Prefix (Expression (Parent (Entity (P))));
25024 goto Continue;
25026 else
25027 return;
25028 end if;
25029 end;
25031 elsif Nkind (Exp) in N_Type_Conversion | N_Unchecked_Type_Conversion
25032 then
25033 Exp := Expression (Exp);
25034 goto Continue;
25036 elsif Nkind (Exp) in
25037 N_Slice | N_Indexed_Component | N_Selected_Component
25038 then
25039 -- Special check, if the prefix is an access type, then return
25040 -- since we are modifying the thing pointed to, not the prefix.
25041 -- When we are expanding, most usually the prefix is replaced
25042 -- by an explicit dereference, and this test is not needed, but
25043 -- in some cases (notably -gnatc mode and generics) when we do
25044 -- not do full expansion, we need this special test.
25046 if Is_Access_Type (Etype (Prefix (Exp))) then
25047 return;
25049 -- Otherwise go to prefix and keep going
25051 else
25052 Exp := Prefix (Exp);
25053 goto Continue;
25054 end if;
25056 -- All other cases, not a modification
25058 else
25059 return;
25060 end if;
25062 -- Now look for entity being referenced
25064 if Present (Ent) then
25065 if Is_Object (Ent) then
25066 if Comes_From_Source (Exp)
25067 or else Modification_Comes_From_Source
25068 then
25069 -- Give warning if pragma unmodified is given and we are
25070 -- sure this is a modification.
25072 if Has_Pragma_Unmodified (Ent) and then Sure then
25074 -- Note that the entity may be present only as a result
25075 -- of pragma Unused.
25077 if Has_Pragma_Unused (Ent) then
25078 Error_Msg_NE
25079 ("??aspect Unused specified for &!", N, Ent);
25080 else
25081 Error_Msg_NE
25082 ("??aspect Unmodified specified for &!", N, Ent);
25083 end if;
25084 end if;
25086 Set_Never_Set_In_Source (Ent, False);
25087 end if;
25089 Set_Is_True_Constant (Ent, False);
25090 Set_Current_Value (Ent, Empty);
25091 Set_Is_Known_Null (Ent, False);
25093 if not Can_Never_Be_Null (Ent) then
25094 Set_Is_Known_Non_Null (Ent, False);
25095 end if;
25097 -- Follow renaming chain
25099 if Ekind (Ent) in E_Variable | E_Constant
25100 and then Present (Renamed_Object (Ent))
25101 then
25102 Exp := Renamed_Object (Ent);
25104 -- If the entity is the loop variable in an iteration over
25105 -- a container, retrieve container expression to indicate
25106 -- possible modification.
25108 if Present (Related_Expression (Ent))
25109 and then Nkind (Parent (Related_Expression (Ent))) =
25110 N_Iterator_Specification
25111 then
25112 Exp := Original_Node (Related_Expression (Ent));
25113 end if;
25115 goto Continue;
25117 -- The expression may be the renaming of a subcomponent of an
25118 -- array or container. The assignment to the subcomponent is
25119 -- a modification of the container.
25121 elsif Comes_From_Source (Original_Node (Exp))
25122 and then Nkind (Original_Node (Exp)) in
25123 N_Selected_Component | N_Indexed_Component
25124 then
25125 Exp := Prefix (Original_Node (Exp));
25126 goto Continue;
25127 end if;
25129 -- Generate a reference only if the assignment comes from
25130 -- source. This excludes, for example, calls to a dispatching
25131 -- assignment operation when the left-hand side is tagged. In
25132 -- GNATprove mode, we need those references also on generated
25133 -- code, as these are used to compute the local effects of
25134 -- subprograms.
25136 if Modification_Comes_From_Source or GNATprove_Mode then
25137 Generate_Reference (Ent, Exp, 'm');
25139 -- If the target of the assignment is the bound variable
25140 -- in an iterator, indicate that the corresponding array
25141 -- or container is also modified.
25143 if Ada_Version >= Ada_2012
25144 and then Nkind (Parent (Ent)) = N_Iterator_Specification
25145 then
25146 declare
25147 Domain : constant Node_Id := Name (Parent (Ent));
25149 begin
25150 -- ??? In the full version of the construct, the
25151 -- domain of iteration can be given by an expression.
25153 if Is_Entity_Name (Domain) then
25154 Generate_Reference (Entity (Domain), Exp, 'm');
25155 Set_Is_True_Constant (Entity (Domain), False);
25156 Set_Never_Set_In_Source (Entity (Domain), False);
25157 end if;
25158 end;
25159 end if;
25160 end if;
25161 end if;
25163 Kill_Checks (Ent);
25165 -- If we are sure this is a modification from source, and we know
25166 -- this modifies a constant, then give an appropriate warning.
25168 if Sure
25169 and then Modification_Comes_From_Source
25170 and then Overlays_Constant (Ent)
25171 and then Address_Clause_Overlay_Warnings
25172 then
25173 declare
25174 Addr : constant Node_Id := Address_Clause (Ent);
25175 O_Ent : Entity_Id;
25176 Off : Boolean;
25178 begin
25179 Find_Overlaid_Entity (Addr, O_Ent, Off);
25181 Error_Msg_Sloc := Sloc (Addr);
25182 Error_Msg_NE
25183 ("?o?constant& may be modified via address clause#",
25184 N, O_Ent);
25185 end;
25186 end if;
25188 return;
25189 end if;
25191 <<Continue>>
25192 null;
25193 end loop;
25194 end Note_Possible_Modification;
25196 -----------------
25197 -- Null_Status --
25198 -----------------
25200 function Null_Status (N : Node_Id) return Null_Status_Kind is
25201 function Is_Null_Excluding_Def (Def : Node_Id) return Boolean;
25202 -- Determine whether definition Def carries a null exclusion
25204 function Null_Status_Of_Entity (Id : Entity_Id) return Null_Status_Kind;
25205 -- Determine the null status of arbitrary entity Id
25207 function Null_Status_Of_Type (Typ : Entity_Id) return Null_Status_Kind;
25208 -- Determine the null status of type Typ
25210 ---------------------------
25211 -- Is_Null_Excluding_Def --
25212 ---------------------------
25214 function Is_Null_Excluding_Def (Def : Node_Id) return Boolean is
25215 begin
25216 return Nkind (Def) in N_Access_Definition
25217 | N_Access_Function_Definition
25218 | N_Access_Procedure_Definition
25219 | N_Access_To_Object_Definition
25220 | N_Component_Definition
25221 | N_Derived_Type_Definition
25222 and then Null_Exclusion_Present (Def);
25223 end Is_Null_Excluding_Def;
25225 ---------------------------
25226 -- Null_Status_Of_Entity --
25227 ---------------------------
25229 function Null_Status_Of_Entity
25230 (Id : Entity_Id) return Null_Status_Kind
25232 Decl : constant Node_Id := Declaration_Node (Id);
25233 Def : Node_Id;
25235 begin
25236 -- The value of an imported or exported entity may be set externally
25237 -- regardless of a null exclusion. As a result, the value cannot be
25238 -- determined statically.
25240 if Is_Imported (Id) or else Is_Exported (Id) then
25241 return Unknown;
25243 elsif Nkind (Decl) in N_Component_Declaration
25244 | N_Discriminant_Specification
25245 | N_Formal_Object_Declaration
25246 | N_Object_Declaration
25247 | N_Object_Renaming_Declaration
25248 | N_Parameter_Specification
25249 then
25250 -- A component declaration yields a non-null value when either
25251 -- its component definition or access definition carries a null
25252 -- exclusion.
25254 if Nkind (Decl) = N_Component_Declaration then
25255 Def := Component_Definition (Decl);
25257 if Is_Null_Excluding_Def (Def) then
25258 return Is_Non_Null;
25259 end if;
25261 Def := Access_Definition (Def);
25263 if Present (Def) and then Is_Null_Excluding_Def (Def) then
25264 return Is_Non_Null;
25265 end if;
25267 -- A formal object declaration yields a non-null value if its
25268 -- access definition carries a null exclusion. If the object is
25269 -- default initialized, then the value depends on the expression.
25271 elsif Nkind (Decl) = N_Formal_Object_Declaration then
25272 Def := Access_Definition (Decl);
25274 if Present (Def) and then Is_Null_Excluding_Def (Def) then
25275 return Is_Non_Null;
25276 end if;
25278 -- A constant may yield a null or non-null value depending on its
25279 -- initialization expression.
25281 elsif Ekind (Id) = E_Constant then
25282 return Null_Status (Constant_Value (Id));
25284 -- The construct yields a non-null value when it has a null
25285 -- exclusion.
25287 elsif Null_Exclusion_Present (Decl) then
25288 return Is_Non_Null;
25290 -- An object renaming declaration yields a non-null value if its
25291 -- access definition carries a null exclusion. Otherwise the value
25292 -- depends on the renamed name.
25294 elsif Nkind (Decl) = N_Object_Renaming_Declaration then
25295 Def := Access_Definition (Decl);
25297 if Present (Def) and then Is_Null_Excluding_Def (Def) then
25298 return Is_Non_Null;
25300 else
25301 return Null_Status (Name (Decl));
25302 end if;
25303 end if;
25304 end if;
25306 -- At this point the declaration of the entity does not carry a null
25307 -- exclusion and lacks an initialization expression. Check the status
25308 -- of its type.
25310 return Null_Status_Of_Type (Etype (Id));
25311 end Null_Status_Of_Entity;
25313 -------------------------
25314 -- Null_Status_Of_Type --
25315 -------------------------
25317 function Null_Status_Of_Type (Typ : Entity_Id) return Null_Status_Kind is
25318 Curr : Entity_Id;
25319 Decl : Node_Id;
25321 begin
25322 -- Traverse the type chain looking for types with null exclusion
25324 Curr := Typ;
25325 while Present (Curr) and then Etype (Curr) /= Curr loop
25326 Decl := Parent (Curr);
25328 -- Guard against itypes which do not always have declarations. A
25329 -- type yields a non-null value if it carries a null exclusion.
25331 if Present (Decl) then
25332 if Nkind (Decl) = N_Full_Type_Declaration
25333 and then Is_Null_Excluding_Def (Type_Definition (Decl))
25334 then
25335 return Is_Non_Null;
25337 elsif Nkind (Decl) = N_Subtype_Declaration
25338 and then Null_Exclusion_Present (Decl)
25339 then
25340 return Is_Non_Null;
25341 end if;
25342 end if;
25344 Curr := Etype (Curr);
25345 end loop;
25347 -- The type chain does not contain any null excluding types
25349 return Unknown;
25350 end Null_Status_Of_Type;
25352 -- Start of processing for Null_Status
25354 begin
25355 -- Prevent cascaded errors or infinite loops when trying to determine
25356 -- the null status of an erroneous construct.
25358 if Error_Posted (N) then
25359 return Unknown;
25361 -- An allocator always creates a non-null value
25363 elsif Nkind (N) = N_Allocator then
25364 return Is_Non_Null;
25366 -- Taking the 'Access of something yields a non-null value
25368 elsif Nkind (N) = N_Attribute_Reference
25369 and then Attribute_Name (N) in Name_Access
25370 | Name_Unchecked_Access
25371 | Name_Unrestricted_Access
25372 then
25373 return Is_Non_Null;
25375 -- "null" yields null
25377 elsif Nkind (N) = N_Null then
25378 return Is_Null;
25380 -- Check the status of the operand of a type conversion
25382 elsif Nkind (N) = N_Type_Conversion then
25383 return Null_Status (Expression (N));
25385 -- The input denotes a reference to an entity. Determine whether the
25386 -- entity or its type yields a null or non-null value.
25388 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
25389 return Null_Status_Of_Entity (Entity (N));
25390 end if;
25392 -- Otherwise it is not possible to determine the null status of the
25393 -- subexpression at compile time without resorting to simple flow
25394 -- analysis.
25396 return Unknown;
25397 end Null_Status;
25399 --------------------------------------
25400 -- Null_To_Null_Address_Convert_OK --
25401 --------------------------------------
25403 function Null_To_Null_Address_Convert_OK
25404 (N : Node_Id;
25405 Typ : Entity_Id := Empty) return Boolean
25407 begin
25408 if not Relaxed_RM_Semantics then
25409 return False;
25410 end if;
25412 if Nkind (N) = N_Null then
25413 return Present (Typ) and then Is_Descendant_Of_Address (Typ);
25415 elsif Nkind (N) in N_Op_Compare then
25416 declare
25417 L : constant Node_Id := Left_Opnd (N);
25418 R : constant Node_Id := Right_Opnd (N);
25420 begin
25421 -- We check the Etype of the complementary operand since the
25422 -- N_Null node is not decorated at this stage.
25424 return
25425 ((Nkind (L) = N_Null
25426 and then Is_Descendant_Of_Address (Etype (R)))
25427 or else
25428 (Nkind (R) = N_Null
25429 and then Is_Descendant_Of_Address (Etype (L))));
25430 end;
25431 end if;
25433 return False;
25434 end Null_To_Null_Address_Convert_OK;
25436 ---------------------------------
25437 -- Number_Of_Elements_In_Array --
25438 ---------------------------------
25440 function Number_Of_Elements_In_Array (T : Entity_Id) return Int is
25441 Indx : Node_Id;
25442 Typ : Entity_Id;
25443 Low : Node_Id;
25444 High : Node_Id;
25445 Num : Int := 1;
25447 begin
25448 pragma Assert (Is_Array_Type (T));
25450 Indx := First_Index (T);
25451 while Present (Indx) loop
25452 Typ := Underlying_Type (Etype (Indx));
25454 -- Never look at junk bounds of a generic type
25456 if Is_Generic_Type (Typ) then
25457 return 0;
25458 end if;
25460 -- Check the array bounds are known at compile time and return zero
25461 -- if they are not.
25463 Low := Type_Low_Bound (Typ);
25464 High := Type_High_Bound (Typ);
25466 if not Compile_Time_Known_Value (Low) then
25467 return 0;
25468 elsif not Compile_Time_Known_Value (High) then
25469 return 0;
25470 else
25471 Num :=
25472 Num * UI_To_Int ((Expr_Value (High) - Expr_Value (Low) + 1));
25473 end if;
25475 Next_Index (Indx);
25476 end loop;
25478 return Num;
25479 end Number_Of_Elements_In_Array;
25481 ---------------------------------
25482 -- Original_Aspect_Pragma_Name --
25483 ---------------------------------
25485 function Original_Aspect_Pragma_Name (N : Node_Id) return Name_Id is
25486 Item : Node_Id;
25487 Item_Nam : Name_Id;
25489 begin
25490 pragma Assert (Nkind (N) in N_Aspect_Specification | N_Pragma);
25492 Item := N;
25494 -- The pragma was generated to emulate an aspect, use the original
25495 -- aspect specification.
25497 if Nkind (Item) = N_Pragma and then From_Aspect_Specification (Item) then
25498 Item := Corresponding_Aspect (Item);
25499 end if;
25501 -- Retrieve the name of the aspect/pragma. As assertion pragmas from
25502 -- a generic instantiation might have been rewritten into pragma Check,
25503 -- we look at the original node for Item. Note also that Pre, Pre_Class,
25504 -- Post and Post_Class rewrite their pragma identifier to preserve the
25505 -- original name, so we look at the original node for the identifier.
25506 -- ??? this is kludgey
25508 if Nkind (Item) = N_Pragma then
25509 Item_Nam :=
25510 Chars (Original_Node (Pragma_Identifier (Original_Node (Item))));
25512 if Item_Nam = Name_Check then
25513 -- Pragma "Check" preserves the original pragma name as its first
25514 -- argument.
25515 Item_Nam :=
25516 Chars (Expression (First (Pragma_Argument_Associations
25517 (Original_Node (Item)))));
25518 end if;
25520 else
25521 pragma Assert (Nkind (Item) = N_Aspect_Specification);
25522 Item_Nam := Chars (Identifier (Item));
25523 end if;
25525 -- Deal with 'Class by converting the name to its _XXX form
25527 if Class_Present (Item) then
25528 if Item_Nam = Name_Invariant then
25529 Item_Nam := Name_uInvariant;
25531 elsif Item_Nam = Name_Post then
25532 Item_Nam := Name_uPost;
25534 elsif Item_Nam = Name_Pre then
25535 Item_Nam := Name_uPre;
25537 elsif Item_Nam in Name_Type_Invariant | Name_Type_Invariant_Class
25538 then
25539 Item_Nam := Name_uType_Invariant;
25541 -- Nothing to do for other cases (e.g. a Check that derived from
25542 -- Pre_Class and has the flag set). Also we do nothing if the name
25543 -- is already in special _xxx form.
25545 end if;
25546 end if;
25548 return Item_Nam;
25549 end Original_Aspect_Pragma_Name;
25551 --------------------------------------
25552 -- Original_Corresponding_Operation --
25553 --------------------------------------
25555 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
25557 Typ : constant Entity_Id := Find_Dispatching_Type (S);
25559 begin
25560 -- If S is an inherited primitive S2 the original corresponding
25561 -- operation of S is the original corresponding operation of S2
25563 if Present (Alias (S))
25564 and then Find_Dispatching_Type (Alias (S)) /= Typ
25565 then
25566 return Original_Corresponding_Operation (Alias (S));
25568 -- If S overrides an inherited subprogram S2 the original corresponding
25569 -- operation of S is the original corresponding operation of S2
25571 elsif Present (Overridden_Operation (S)) then
25572 return Original_Corresponding_Operation (Overridden_Operation (S));
25574 -- otherwise it is S itself
25576 else
25577 return S;
25578 end if;
25579 end Original_Corresponding_Operation;
25581 -----------------------------------
25582 -- Original_View_In_Visible_Part --
25583 -----------------------------------
25585 function Original_View_In_Visible_Part
25586 (Typ : Entity_Id) return Boolean
25588 Scop : constant Entity_Id := Scope (Typ);
25590 begin
25591 -- The scope must be a package
25593 if not Is_Package_Or_Generic_Package (Scop) then
25594 return False;
25595 end if;
25597 -- A type with a private declaration has a private view declared in
25598 -- the visible part.
25600 if Has_Private_Declaration (Typ) then
25601 return True;
25602 end if;
25604 return List_Containing (Parent (Typ)) =
25605 Visible_Declarations (Package_Specification (Scop));
25606 end Original_View_In_Visible_Part;
25608 -------------------
25609 -- Output_Entity --
25610 -------------------
25612 procedure Output_Entity (Id : Entity_Id) is
25613 Scop : Entity_Id;
25615 begin
25616 Scop := Scope (Id);
25618 -- The entity may lack a scope when it is in the process of being
25619 -- analyzed. Use the current scope as an approximation.
25621 if No (Scop) then
25622 Scop := Current_Scope;
25623 end if;
25625 Output_Name (Chars (Id), Scop);
25626 end Output_Entity;
25628 -----------------
25629 -- Output_Name --
25630 -----------------
25632 procedure Output_Name (Nam : Name_Id; Scop : Entity_Id := Current_Scope) is
25633 begin
25634 Write_Str
25635 (Get_Name_String
25636 (Get_Qualified_Name
25637 (Nam => Nam,
25638 Suffix => No_Name,
25639 Scop => Scop)));
25640 Write_Eol;
25641 end Output_Name;
25643 ------------------
25644 -- Param_Entity --
25645 ------------------
25647 -- This would be trivial, simply a test for an identifier that was a
25648 -- reference to a formal, if it were not for the fact that a previous call
25649 -- to Expand_Entry_Parameter will have modified the reference to the
25650 -- identifier. A formal of a protected entity is rewritten as
25652 -- typ!(recobj).rec.all'Constrained
25654 -- where rec is a selector whose Entry_Formal link points to the formal
25656 -- If the type of the entry parameter has a representation clause, then an
25657 -- extra temp is involved (see below).
25659 -- For a formal of a task entity, the formal is rewritten as a local
25660 -- renaming.
25662 -- In addition, a formal that is marked volatile because it is aliased
25663 -- through an address clause is rewritten as dereference as well.
25665 function Param_Entity (N : Node_Id) return Entity_Id is
25666 Renamed_Obj : Node_Id;
25668 begin
25669 -- Simple reference case
25671 if Nkind (N) in N_Identifier | N_Expanded_Name then
25672 if Is_Formal (Entity (N)) then
25673 return Entity (N);
25675 -- Handle renamings of formal parameters and formals of tasks that
25676 -- are rewritten as renamings.
25678 elsif Nkind (Parent (Entity (N))) = N_Object_Renaming_Declaration then
25679 Renamed_Obj := Get_Referenced_Object (Renamed_Object (Entity (N)));
25681 if Is_Entity_Name (Renamed_Obj)
25682 and then Is_Formal (Entity (Renamed_Obj))
25683 then
25684 return Entity (Renamed_Obj);
25686 elsif
25687 Nkind (Parent (Parent (Entity (N)))) = N_Accept_Statement
25688 then
25689 return Entity (N);
25690 end if;
25691 end if;
25693 else
25694 if Nkind (N) = N_Explicit_Dereference then
25695 declare
25696 P : Node_Id := Prefix (N);
25697 S : Node_Id;
25698 E : Entity_Id;
25699 Decl : Node_Id;
25701 begin
25702 -- If the type of an entry parameter has a representation
25703 -- clause, then the prefix is not a selected component, but
25704 -- instead a reference to a temp pointing at the selected
25705 -- component. In this case, set P to be the initial value of
25706 -- that temp.
25708 if Nkind (P) = N_Identifier then
25709 E := Entity (P);
25711 if Ekind (E) = E_Constant then
25712 Decl := Parent (E);
25714 if Nkind (Decl) = N_Object_Declaration then
25715 P := Expression (Decl);
25716 end if;
25717 end if;
25718 end if;
25720 if Nkind (P) = N_Selected_Component then
25721 S := Selector_Name (P);
25723 if Present (Entry_Formal (Entity (S))) then
25724 return Entry_Formal (Entity (S));
25725 end if;
25727 elsif Nkind (Original_Node (N)) = N_Identifier then
25728 return Param_Entity (Original_Node (N));
25729 end if;
25730 end;
25731 end if;
25732 end if;
25734 return Empty;
25735 end Param_Entity;
25737 ----------------------
25738 -- Policy_In_Effect --
25739 ----------------------
25741 function Policy_In_Effect (Policy : Name_Id) return Name_Id is
25742 function Policy_In_List (List : Node_Id) return Name_Id;
25743 -- Determine the mode of a policy in a N_Pragma list
25745 --------------------
25746 -- Policy_In_List --
25747 --------------------
25749 function Policy_In_List (List : Node_Id) return Name_Id is
25750 Arg1 : Node_Id;
25751 Arg2 : Node_Id;
25752 Prag : Node_Id;
25754 begin
25755 Prag := List;
25756 while Present (Prag) loop
25757 Arg1 := First (Pragma_Argument_Associations (Prag));
25758 Arg2 := Next (Arg1);
25760 Arg1 := Get_Pragma_Arg (Arg1);
25761 Arg2 := Get_Pragma_Arg (Arg2);
25763 -- The current Check_Policy pragma matches the requested policy or
25764 -- appears in the single argument form (Assertion, policy_id).
25766 if Chars (Arg1) in Name_Assertion | Policy then
25767 return Chars (Arg2);
25768 end if;
25770 Prag := Next_Pragma (Prag);
25771 end loop;
25773 return No_Name;
25774 end Policy_In_List;
25776 -- Local variables
25778 Kind : Name_Id;
25780 -- Start of processing for Policy_In_Effect
25782 begin
25783 if not Is_Valid_Assertion_Kind (Policy) then
25784 raise Program_Error;
25785 end if;
25787 -- Inspect all policy pragmas that appear within scopes (if any)
25789 Kind := Policy_In_List (Check_Policy_List);
25791 -- Inspect all configuration policy pragmas (if any)
25793 if Kind = No_Name then
25794 Kind := Policy_In_List (Check_Policy_List_Config);
25795 end if;
25797 -- The context lacks policy pragmas, determine the mode based on whether
25798 -- assertions are enabled at the configuration level. This ensures that
25799 -- the policy is preserved when analyzing generics.
25801 if Kind = No_Name then
25802 if Assertions_Enabled_Config then
25803 Kind := Name_Check;
25804 else
25805 Kind := Name_Ignore;
25806 end if;
25807 end if;
25809 -- In CodePeer mode and GNATprove mode, we need to consider all
25810 -- assertions, unless they are disabled. Force Name_Check on
25811 -- ignored assertions.
25813 if Kind in Name_Ignore | Name_Off
25814 and then (CodePeer_Mode or GNATprove_Mode)
25815 then
25816 Kind := Name_Check;
25817 end if;
25819 return Kind;
25820 end Policy_In_Effect;
25822 -------------------------------
25823 -- Preanalyze_Without_Errors --
25824 -------------------------------
25826 procedure Preanalyze_Without_Errors (N : Node_Id) is
25827 Status : constant Boolean := Get_Ignore_Errors;
25828 begin
25829 Set_Ignore_Errors (True);
25830 Preanalyze (N);
25831 Set_Ignore_Errors (Status);
25832 end Preanalyze_Without_Errors;
25834 -----------------------
25835 -- Predicate_Enabled --
25836 -----------------------
25838 function Predicate_Enabled (Typ : Entity_Id) return Boolean is
25839 begin
25840 return Present (Predicate_Function (Typ))
25841 and then not Predicates_Ignored (Typ)
25842 and then not Predicate_Checks_Suppressed (Empty);
25843 end Predicate_Enabled;
25845 ----------------------------------
25846 -- Predicate_Failure_Expression --
25847 ----------------------------------
25849 function Predicate_Failure_Expression
25850 (Typ : Entity_Id; Inherited_OK : Boolean) return Node_Id
25852 PF_Aspect : constant Node_Id :=
25853 Find_Aspect (Typ, Aspect_Predicate_Failure);
25854 begin
25855 -- Check for Predicate_Failure aspect specification via an
25856 -- aspect_specification (as opposed to via a pragma).
25858 if Present (PF_Aspect) then
25859 if Inherited_OK or else Entity (PF_Aspect) = Typ then
25860 return Expression (PF_Aspect);
25861 else
25862 return Empty;
25863 end if;
25864 end if;
25866 -- Check for Predicate_Failure aspect specification via a pragma.
25868 declare
25869 Rep_Item : Node_Id := First_Rep_Item (Typ);
25870 begin
25871 while Present (Rep_Item) loop
25872 if Nkind (Rep_Item) = N_Pragma
25873 and then Get_Pragma_Id (Rep_Item) = Pragma_Predicate_Failure
25874 then
25875 declare
25876 Arg1 : constant Node_Id :=
25877 Get_Pragma_Arg
25878 (First (Pragma_Argument_Associations (Rep_Item)));
25879 Arg2 : constant Node_Id :=
25880 Get_Pragma_Arg
25881 (Next (First (Pragma_Argument_Associations (Rep_Item))));
25882 begin
25883 if Inherited_OK or else
25884 (Nkind (Arg1) in N_Has_Entity
25885 and then Entity (Arg1) = Typ)
25886 then
25887 return Arg2;
25888 end if;
25889 end;
25890 end if;
25892 Next_Rep_Item (Rep_Item);
25893 end loop;
25894 end;
25896 -- If we are interested in an inherited Predicate_Failure aspect
25897 -- and we have an ancestor to inherit from, then recursively check
25898 -- for that case.
25900 if Inherited_OK and then Present (Nearest_Ancestor (Typ)) then
25901 return Predicate_Failure_Expression (Nearest_Ancestor (Typ),
25902 Inherited_OK => True);
25903 end if;
25905 return Empty;
25906 end Predicate_Failure_Expression;
25908 ----------------------------------
25909 -- Predicate_Tests_On_Arguments --
25910 ----------------------------------
25912 function Predicate_Tests_On_Arguments (Subp : Entity_Id) return Boolean is
25913 begin
25914 -- Always test predicates on indirect call
25916 if Ekind (Subp) = E_Subprogram_Type then
25917 return True;
25919 -- Do not test predicates on call to generated default Finalize, since
25920 -- we are not interested in whether something we are finalizing (and
25921 -- typically destroying) satisfies its predicates.
25923 elsif Chars (Subp) = Name_Finalize
25924 and then not Comes_From_Source (Subp)
25925 then
25926 return False;
25928 -- Do not test predicates on any internally generated routines
25930 elsif Is_Internal_Name (Chars (Subp)) then
25931 return False;
25933 -- Do not test predicates on call to Init_Proc, since if needed the
25934 -- predicate test will occur at some other point.
25936 elsif Is_Init_Proc (Subp) then
25937 return False;
25939 -- Do not test predicates on call to predicate function, since this
25940 -- would cause infinite recursion.
25942 elsif Ekind (Subp) = E_Function
25943 and then Is_Predicate_Function (Subp)
25944 then
25945 return False;
25947 -- For now, no other exceptions
25949 else
25950 return True;
25951 end if;
25952 end Predicate_Tests_On_Arguments;
25954 -----------------------
25955 -- Private_Component --
25956 -----------------------
25958 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
25959 Ancestor : constant Entity_Id := Base_Type (Type_Id);
25961 function Trace_Components
25962 (T : Entity_Id;
25963 Check : Boolean) return Entity_Id;
25964 -- Recursive function that does the work, and checks against circular
25965 -- definition for each subcomponent type.
25967 ----------------------
25968 -- Trace_Components --
25969 ----------------------
25971 function Trace_Components
25972 (T : Entity_Id;
25973 Check : Boolean) return Entity_Id
25975 Btype : constant Entity_Id := Base_Type (T);
25976 Component : Entity_Id;
25977 P : Entity_Id;
25978 Candidate : Entity_Id := Empty;
25980 begin
25981 if Check and then Btype = Ancestor then
25982 Error_Msg_N ("circular type definition", Type_Id);
25983 return Any_Type;
25984 end if;
25986 if Is_Private_Type (Btype) and then not Is_Generic_Type (Btype) then
25987 if Present (Full_View (Btype))
25988 and then Is_Record_Type (Full_View (Btype))
25989 and then not Is_Frozen (Btype)
25990 then
25991 -- To indicate that the ancestor depends on a private type, the
25992 -- current Btype is sufficient. However, to check for circular
25993 -- definition we must recurse on the full view.
25995 Candidate := Trace_Components (Full_View (Btype), True);
25997 if Candidate = Any_Type then
25998 return Any_Type;
25999 else
26000 return Btype;
26001 end if;
26003 else
26004 return Btype;
26005 end if;
26007 elsif Is_Array_Type (Btype) then
26008 return Trace_Components (Component_Type (Btype), True);
26010 elsif Is_Record_Type (Btype) then
26011 Component := First_Entity (Btype);
26012 while Present (Component)
26013 and then Comes_From_Source (Component)
26014 loop
26015 -- Skip anonymous types generated by constrained components
26017 if not Is_Type (Component) then
26018 P := Trace_Components (Etype (Component), True);
26020 if Present (P) then
26021 if P = Any_Type then
26022 return P;
26023 else
26024 Candidate := P;
26025 end if;
26026 end if;
26027 end if;
26029 Next_Entity (Component);
26030 end loop;
26032 return Candidate;
26034 else
26035 return Empty;
26036 end if;
26037 end Trace_Components;
26039 -- Start of processing for Private_Component
26041 begin
26042 return Trace_Components (Type_Id, False);
26043 end Private_Component;
26045 ---------------------------
26046 -- Primitive_Names_Match --
26047 ---------------------------
26049 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
26050 function Non_Internal_Name (E : Entity_Id) return Name_Id;
26051 -- Given an internal name, returns the corresponding non-internal name
26053 ------------------------
26054 -- Non_Internal_Name --
26055 ------------------------
26057 function Non_Internal_Name (E : Entity_Id) return Name_Id is
26058 begin
26059 Get_Name_String (Chars (E));
26060 Name_Len := Name_Len - 1;
26061 return Name_Find;
26062 end Non_Internal_Name;
26064 -- Start of processing for Primitive_Names_Match
26066 begin
26067 pragma Assert (Present (E1) and then Present (E2));
26069 return Chars (E1) = Chars (E2)
26070 or else
26071 (not Is_Internal_Name (Chars (E1))
26072 and then Is_Internal_Name (Chars (E2))
26073 and then Non_Internal_Name (E2) = Chars (E1))
26074 or else
26075 (not Is_Internal_Name (Chars (E2))
26076 and then Is_Internal_Name (Chars (E1))
26077 and then Non_Internal_Name (E1) = Chars (E2))
26078 or else
26079 (Is_Predefined_Dispatching_Operation (E1)
26080 and then Is_Predefined_Dispatching_Operation (E2)
26081 and then Same_TSS (E1, E2))
26082 or else
26083 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
26084 end Primitive_Names_Match;
26086 -----------------------
26087 -- Process_End_Label --
26088 -----------------------
26090 procedure Process_End_Label
26091 (N : Node_Id;
26092 Typ : Character;
26093 Ent : Entity_Id)
26095 Loc : Source_Ptr;
26096 Nam : Node_Id;
26097 Scop : Entity_Id;
26099 Label_Ref : Boolean;
26100 -- Set True if reference to end label itself is required
26102 Endl : Node_Id;
26103 -- Gets set to the operator symbol or identifier that references the
26104 -- entity Ent. For the child unit case, this is the identifier from the
26105 -- designator. For other cases, this is simply Endl.
26107 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
26108 -- N is an identifier node that appears as a parent unit reference in
26109 -- the case where Ent is a child unit. This procedure generates an
26110 -- appropriate cross-reference entry. E is the corresponding entity.
26112 -------------------------
26113 -- Generate_Parent_Ref --
26114 -------------------------
26116 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
26117 begin
26118 -- If names do not match, something weird, skip reference
26120 if Chars (E) = Chars (N) then
26122 -- Generate the reference. We do NOT consider this as a reference
26123 -- for unreferenced symbol purposes.
26125 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
26127 if Style_Check then
26128 Style.Check_Identifier (N, E);
26129 end if;
26130 end if;
26131 end Generate_Parent_Ref;
26133 -- Start of processing for Process_End_Label
26135 begin
26136 -- If no node, ignore. This happens in some error situations, and
26137 -- also for some internally generated structures where no end label
26138 -- references are required in any case.
26140 if No (N) then
26141 return;
26142 end if;
26144 -- Nothing to do if no End_Label, happens for internally generated
26145 -- constructs where we don't want an end label reference anyway. Also
26146 -- nothing to do if Endl is a string literal, which means there was
26147 -- some prior error (bad operator symbol)
26149 Endl := End_Label (N);
26151 if No (Endl) or else Nkind (Endl) = N_String_Literal then
26152 return;
26153 end if;
26155 -- Reference node is not in extended main source unit
26157 if not In_Extended_Main_Source_Unit (N) then
26159 -- Generally we do not collect references except for the extended
26160 -- main source unit. The one exception is the 'e' entry for a
26161 -- package spec, where it is useful for a client to have the
26162 -- ending information to define scopes.
26164 if Typ /= 'e' then
26165 return;
26167 else
26168 Label_Ref := False;
26170 -- For this case, we can ignore any parent references, but we
26171 -- need the package name itself for the 'e' entry.
26173 if Nkind (Endl) = N_Designator then
26174 Endl := Identifier (Endl);
26175 end if;
26176 end if;
26178 -- Reference is in extended main source unit
26180 else
26181 Label_Ref := True;
26183 -- For designator, generate references for the parent entries
26185 if Nkind (Endl) = N_Designator then
26187 -- Generate references for the prefix if the END line comes from
26188 -- source (otherwise we do not need these references) We climb the
26189 -- scope stack to find the expected entities.
26191 if Comes_From_Source (Endl) then
26192 Nam := Name (Endl);
26193 Scop := Current_Scope;
26194 while Nkind (Nam) = N_Selected_Component loop
26195 Scop := Scope (Scop);
26196 exit when No (Scop);
26197 Generate_Parent_Ref (Selector_Name (Nam), Scop);
26198 Nam := Prefix (Nam);
26199 end loop;
26201 if Present (Scop) then
26202 Generate_Parent_Ref (Nam, Scope (Scop));
26203 end if;
26204 end if;
26206 Endl := Identifier (Endl);
26207 end if;
26208 end if;
26210 -- If the end label is not for the given entity, then either we have
26211 -- some previous error, or this is a generic instantiation for which
26212 -- we do not need to make a cross-reference in this case anyway. In
26213 -- either case we simply ignore the call.
26215 if Chars (Ent) /= Chars (Endl) then
26216 return;
26217 end if;
26219 -- If label was really there, then generate a normal reference and then
26220 -- adjust the location in the end label to point past the name (which
26221 -- should almost always be the semicolon).
26223 Loc := Sloc (Endl);
26225 if Comes_From_Source (Endl) then
26227 -- If a label reference is required, then do the style check and
26228 -- generate an l-type cross-reference entry for the label
26230 if Label_Ref then
26231 if Style_Check then
26232 Style.Check_Identifier (Endl, Ent);
26233 end if;
26235 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
26236 end if;
26238 -- Set the location to point past the label (normally this will
26239 -- mean the semicolon immediately following the label). This is
26240 -- done for the sake of the 'e' or 't' entry generated below.
26242 Get_Decoded_Name_String (Chars (Endl));
26243 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
26244 end if;
26246 -- Now generate the e/t reference
26248 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
26250 -- Restore Sloc, in case modified above, since we have an identifier
26251 -- and the normal Sloc should be left set in the tree.
26253 Set_Sloc (Endl, Loc);
26254 end Process_End_Label;
26256 --------------------------------
26257 -- Propagate_Concurrent_Flags --
26258 --------------------------------
26260 procedure Propagate_Concurrent_Flags
26261 (Typ : Entity_Id;
26262 Comp_Typ : Entity_Id)
26264 begin
26265 if Has_Task (Comp_Typ) then
26266 Set_Has_Task (Typ);
26267 end if;
26269 if Has_Protected (Comp_Typ) then
26270 Set_Has_Protected (Typ);
26271 end if;
26273 if Has_Timing_Event (Comp_Typ) then
26274 Set_Has_Timing_Event (Typ);
26275 end if;
26276 end Propagate_Concurrent_Flags;
26278 ------------------------------
26279 -- Propagate_DIC_Attributes --
26280 ------------------------------
26282 procedure Propagate_DIC_Attributes
26283 (Typ : Entity_Id;
26284 From_Typ : Entity_Id)
26286 DIC_Proc : Entity_Id;
26287 Partial_DIC_Proc : Entity_Id;
26289 begin
26290 if Present (Typ) and then Present (From_Typ) then
26291 pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
26293 -- Nothing to do if both the source and the destination denote the
26294 -- same type.
26296 if From_Typ = Typ then
26297 return;
26299 -- Nothing to do when the destination denotes an incomplete type
26300 -- because the DIC is associated with the current instance of a
26301 -- private type, thus it can never apply to an incomplete type.
26303 elsif Is_Incomplete_Type (Typ) then
26304 return;
26305 end if;
26307 DIC_Proc := DIC_Procedure (From_Typ);
26308 Partial_DIC_Proc := Partial_DIC_Procedure (From_Typ);
26310 -- The setting of the attributes is intentionally conservative. This
26311 -- prevents accidental clobbering of enabled attributes. We need to
26312 -- call Base_Type twice, because it is sometimes not set to an actual
26313 -- base type???
26315 if Has_Inherited_DIC (From_Typ) then
26316 Set_Has_Inherited_DIC (Base_Type (Base_Type (Typ)));
26317 end if;
26319 if Has_Own_DIC (From_Typ) then
26320 Set_Has_Own_DIC (Base_Type (Base_Type (Typ)));
26321 end if;
26323 if Present (DIC_Proc) and then No (DIC_Procedure (Typ)) then
26324 Set_DIC_Procedure (Typ, DIC_Proc);
26325 end if;
26327 if Present (Partial_DIC_Proc)
26328 and then No (Partial_DIC_Procedure (Typ))
26329 then
26330 Set_Partial_DIC_Procedure (Typ, Partial_DIC_Proc);
26331 end if;
26332 end if;
26333 end Propagate_DIC_Attributes;
26335 ------------------------------------
26336 -- Propagate_Invariant_Attributes --
26337 ------------------------------------
26339 procedure Propagate_Invariant_Attributes
26340 (Typ : Entity_Id;
26341 From_Typ : Entity_Id)
26343 Full_IP : Entity_Id;
26344 Part_IP : Entity_Id;
26346 begin
26347 if Present (Typ) and then Present (From_Typ) then
26348 pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
26350 -- Nothing to do if both the source and the destination denote the
26351 -- same type.
26353 if From_Typ = Typ then
26354 return;
26355 end if;
26357 Full_IP := Invariant_Procedure (From_Typ);
26358 Part_IP := Partial_Invariant_Procedure (From_Typ);
26360 -- The setting of the attributes is intentionally conservative. This
26361 -- prevents accidental clobbering of enabled attributes. We need to
26362 -- call Base_Type twice, because it is sometimes not set to an actual
26363 -- base type???
26365 if Has_Inheritable_Invariants (From_Typ) then
26366 Set_Has_Inheritable_Invariants (Base_Type (Base_Type (Typ)));
26367 end if;
26369 if Has_Inherited_Invariants (From_Typ) then
26370 Set_Has_Inherited_Invariants (Base_Type (Base_Type (Typ)));
26371 end if;
26373 if Has_Own_Invariants (From_Typ) then
26374 Set_Has_Own_Invariants (Base_Type (Base_Type (Typ)));
26375 end if;
26377 if Present (Full_IP) and then No (Invariant_Procedure (Typ)) then
26378 Set_Invariant_Procedure (Typ, Full_IP);
26379 end if;
26381 if Present (Part_IP) and then No (Partial_Invariant_Procedure (Typ))
26382 then
26383 Set_Partial_Invariant_Procedure (Typ, Part_IP);
26384 end if;
26385 end if;
26386 end Propagate_Invariant_Attributes;
26388 ------------------------------------
26389 -- Propagate_Predicate_Attributes --
26390 ------------------------------------
26392 procedure Propagate_Predicate_Attributes
26393 (Typ : Entity_Id;
26394 From_Typ : Entity_Id)
26396 Pred_Func : Entity_Id;
26397 begin
26398 if Present (Typ) and then Present (From_Typ) then
26399 pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
26401 -- Nothing to do if both the source and the destination denote the
26402 -- same type.
26404 if From_Typ = Typ then
26405 return;
26406 end if;
26408 Pred_Func := Predicate_Function (From_Typ);
26410 -- The setting of the attributes is intentionally conservative. This
26411 -- prevents accidental clobbering of enabled attributes.
26413 if Has_Predicates (From_Typ) then
26414 Set_Has_Predicates (Typ);
26415 end if;
26417 if Present (Pred_Func) and then No (Predicate_Function (Typ)) then
26418 Set_Predicate_Function (Typ, Pred_Func);
26419 end if;
26420 end if;
26421 end Propagate_Predicate_Attributes;
26423 ---------------------------------------
26424 -- Record_Possible_Part_Of_Reference --
26425 ---------------------------------------
26427 procedure Record_Possible_Part_Of_Reference
26428 (Var_Id : Entity_Id;
26429 Ref : Node_Id)
26431 Encap : constant Entity_Id := Encapsulating_State (Var_Id);
26432 Refs : Elist_Id;
26434 begin
26435 -- The variable is a constituent of a single protected/task type. Such
26436 -- a variable acts as a component of the type and must appear within a
26437 -- specific region (SPARK RM 9(3)). Instead of recording the reference,
26438 -- verify its legality now.
26440 if Present (Encap) and then Is_Single_Concurrent_Object (Encap) then
26441 Check_Part_Of_Reference (Var_Id, Ref);
26443 -- The variable is subject to pragma Part_Of and may eventually become a
26444 -- constituent of a single protected/task type. Record the reference to
26445 -- verify its placement when the contract of the variable is analyzed.
26447 elsif Present (Get_Pragma (Var_Id, Pragma_Part_Of)) then
26448 Refs := Part_Of_References (Var_Id);
26450 if No (Refs) then
26451 Refs := New_Elmt_List;
26452 Set_Part_Of_References (Var_Id, Refs);
26453 end if;
26455 Append_Elmt (Ref, Refs);
26456 end if;
26457 end Record_Possible_Part_Of_Reference;
26459 ----------------
26460 -- Referenced --
26461 ----------------
26463 function Referenced (Id : Entity_Id; Expr : Node_Id) return Boolean is
26464 Seen : Boolean := False;
26466 function Is_Reference (N : Node_Id) return Traverse_Result;
26467 -- Determine whether node N denotes a reference to Id. If this is the
26468 -- case, set global flag Seen to True and stop the traversal.
26470 ------------------
26471 -- Is_Reference --
26472 ------------------
26474 function Is_Reference (N : Node_Id) return Traverse_Result is
26475 begin
26476 if Is_Entity_Name (N)
26477 and then Present (Entity (N))
26478 and then Entity (N) = Id
26479 then
26480 Seen := True;
26481 return Abandon;
26482 else
26483 return OK;
26484 end if;
26485 end Is_Reference;
26487 procedure Inspect_Expression is new Traverse_Proc (Is_Reference);
26489 -- Start of processing for Referenced
26491 begin
26492 Inspect_Expression (Expr);
26493 return Seen;
26494 end Referenced;
26496 ------------------------------------
26497 -- References_Generic_Formal_Type --
26498 ------------------------------------
26500 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
26502 function Process (N : Node_Id) return Traverse_Result;
26503 -- Process one node in search for generic formal type
26505 -------------
26506 -- Process --
26507 -------------
26509 function Process (N : Node_Id) return Traverse_Result is
26510 begin
26511 if Nkind (N) in N_Has_Entity then
26512 declare
26513 E : constant Entity_Id := Entity (N);
26514 begin
26515 if Present (E) then
26516 if Is_Generic_Type (E) then
26517 return Abandon;
26518 elsif Present (Etype (E))
26519 and then Is_Generic_Type (Etype (E))
26520 then
26521 return Abandon;
26522 end if;
26523 end if;
26524 end;
26525 end if;
26527 return Atree.OK;
26528 end Process;
26530 function Traverse is new Traverse_Func (Process);
26531 -- Traverse tree to look for generic type
26533 begin
26534 if Inside_A_Generic then
26535 return Traverse (N) = Abandon;
26536 else
26537 return False;
26538 end if;
26539 end References_Generic_Formal_Type;
26541 -------------------------------
26542 -- Remove_Entity_And_Homonym --
26543 -------------------------------
26545 procedure Remove_Entity_And_Homonym (Id : Entity_Id) is
26546 begin
26547 Remove_Entity (Id);
26548 Remove_Homonym (Id);
26549 end Remove_Entity_And_Homonym;
26551 --------------------
26552 -- Remove_Homonym --
26553 --------------------
26555 procedure Remove_Homonym (Id : Entity_Id) is
26556 Hom : Entity_Id;
26557 Prev : Entity_Id := Empty;
26559 begin
26560 if Id = Current_Entity (Id) then
26561 if Present (Homonym (Id)) then
26562 Set_Current_Entity (Homonym (Id));
26563 else
26564 Set_Name_Entity_Id (Chars (Id), Empty);
26565 end if;
26567 else
26568 Hom := Current_Entity (Id);
26569 while Present (Hom) and then Hom /= Id loop
26570 Prev := Hom;
26571 Hom := Homonym (Hom);
26572 end loop;
26574 -- If Id is not on the homonym chain, nothing to do
26576 if Present (Hom) then
26577 Set_Homonym (Prev, Homonym (Id));
26578 end if;
26579 end if;
26580 end Remove_Homonym;
26582 ------------------------------
26583 -- Remove_Overloaded_Entity --
26584 ------------------------------
26586 procedure Remove_Overloaded_Entity (Id : Entity_Id) is
26587 procedure Remove_Primitive_Of (Typ : Entity_Id);
26588 -- Remove primitive subprogram Id from the list of primitives that
26589 -- belong to type Typ.
26591 -------------------------
26592 -- Remove_Primitive_Of --
26593 -------------------------
26595 procedure Remove_Primitive_Of (Typ : Entity_Id) is
26596 Prims : Elist_Id;
26598 begin
26599 if Is_Tagged_Type (Typ) then
26600 Prims := Direct_Primitive_Operations (Typ);
26602 if Present (Prims) then
26603 Remove (Prims, Id);
26604 end if;
26605 end if;
26606 end Remove_Primitive_Of;
26608 -- Local variables
26610 Formal : Entity_Id;
26612 -- Start of processing for Remove_Overloaded_Entity
26614 begin
26615 Remove_Entity_And_Homonym (Id);
26617 -- The entity denotes a primitive subprogram. Remove it from the list of
26618 -- primitives of the associated controlling type.
26620 if Ekind (Id) in E_Function | E_Procedure and then Is_Primitive (Id) then
26621 Formal := First_Formal (Id);
26622 while Present (Formal) loop
26623 if Is_Controlling_Formal (Formal) then
26624 Remove_Primitive_Of (Etype (Formal));
26625 exit;
26626 end if;
26628 Next_Formal (Formal);
26629 end loop;
26631 if Ekind (Id) = E_Function and then Has_Controlling_Result (Id) then
26632 Remove_Primitive_Of (Etype (Id));
26633 end if;
26634 end if;
26635 end Remove_Overloaded_Entity;
26637 ---------------------
26638 -- Rep_To_Pos_Flag --
26639 ---------------------
26641 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
26642 begin
26643 return New_Occurrence_Of
26644 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
26645 end Rep_To_Pos_Flag;
26647 --------------------
26648 -- Require_Entity --
26649 --------------------
26651 procedure Require_Entity (N : Node_Id) is
26652 begin
26653 if Is_Entity_Name (N) and then No (Entity (N)) then
26654 if Total_Errors_Detected /= 0 then
26655 Set_Entity (N, Any_Id);
26656 else
26657 raise Program_Error;
26658 end if;
26659 end if;
26660 end Require_Entity;
26662 ------------------------------
26663 -- Requires_Transient_Scope --
26664 ------------------------------
26666 function Requires_Transient_Scope (Typ : Entity_Id) return Boolean is
26667 begin
26668 return Needs_Secondary_Stack (Typ) or else Needs_Finalization (Typ);
26669 end Requires_Transient_Scope;
26671 --------------------------
26672 -- Reset_Analyzed_Flags --
26673 --------------------------
26675 procedure Reset_Analyzed_Flags (N : Node_Id) is
26676 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
26677 -- Function used to reset Analyzed flags in tree. Note that we do
26678 -- not reset Analyzed flags in entities, since there is no need to
26679 -- reanalyze entities, and indeed, it is wrong to do so, since it
26680 -- can result in generating auxiliary stuff more than once.
26682 --------------------
26683 -- Clear_Analyzed --
26684 --------------------
26686 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
26687 begin
26688 if Nkind (N) not in N_Entity then
26689 Set_Analyzed (N, False);
26690 end if;
26692 return OK;
26693 end Clear_Analyzed;
26695 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
26697 -- Start of processing for Reset_Analyzed_Flags
26699 begin
26700 Reset_Analyzed (N);
26701 end Reset_Analyzed_Flags;
26703 ------------------------
26704 -- Restore_SPARK_Mode --
26705 ------------------------
26707 procedure Restore_SPARK_Mode
26708 (Mode : SPARK_Mode_Type;
26709 Prag : Node_Id)
26711 begin
26712 SPARK_Mode := Mode;
26713 SPARK_Mode_Pragma := Prag;
26714 end Restore_SPARK_Mode;
26716 --------------------------------
26717 -- Returns_Unconstrained_Type --
26718 --------------------------------
26720 function Returns_Unconstrained_Type (Subp : Entity_Id) return Boolean is
26721 begin
26722 return Ekind (Subp) = E_Function
26723 and then not Is_Scalar_Type (Etype (Subp))
26724 and then not Is_Access_Type (Etype (Subp))
26725 and then not Is_Constrained (Etype (Subp));
26726 end Returns_Unconstrained_Type;
26728 ----------------------------
26729 -- Root_Type_Of_Full_View --
26730 ----------------------------
26732 function Root_Type_Of_Full_View (T : Entity_Id) return Entity_Id is
26733 Rtyp : constant Entity_Id := Root_Type (T);
26735 begin
26736 -- The root type of the full view may itself be a private type. Keep
26737 -- looking for the ultimate derivation parent.
26739 if Is_Private_Type (Rtyp) and then Present (Full_View (Rtyp)) then
26740 return Root_Type_Of_Full_View (Full_View (Rtyp));
26741 else
26742 return Rtyp;
26743 end if;
26744 end Root_Type_Of_Full_View;
26746 ---------------------------
26747 -- Safe_To_Capture_Value --
26748 ---------------------------
26750 function Safe_To_Capture_Value
26751 (N : Node_Id;
26752 Ent : Entity_Id;
26753 Cond : Boolean := False) return Boolean
26755 begin
26756 -- The only entities for which we track constant values are variables
26757 -- that are not renamings, constants and formal parameters, so check
26758 -- if we have this case.
26760 -- Note: it may seem odd to track constant values for constants, but in
26761 -- fact this routine is used for other purposes than simply capturing
26762 -- the value. In particular, the setting of Known[_Non]_Null and
26763 -- Is_Known_Valid.
26765 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
26766 or else
26767 Ekind (Ent) = E_Constant
26768 or else
26769 Is_Formal (Ent)
26770 then
26771 null;
26773 -- For conditionals, we also allow loop parameters
26775 elsif Cond and then Ekind (Ent) = E_Loop_Parameter then
26776 null;
26778 -- For all other cases, not just unsafe, but impossible to capture
26779 -- Current_Value, since the above are the only entities which have
26780 -- Current_Value fields.
26782 else
26783 return False;
26784 end if;
26786 -- Skip if volatile or aliased, since funny things might be going on in
26787 -- these cases which we cannot necessarily track. Also skip any variable
26788 -- for which an address clause is given, or whose address is taken. Also
26789 -- never capture value of library level variables (an attempt to do so
26790 -- can occur in the case of package elaboration code).
26792 if Treat_As_Volatile (Ent)
26793 or else Is_Aliased (Ent)
26794 or else Present (Address_Clause (Ent))
26795 or else Address_Taken (Ent)
26796 or else (Is_Library_Level_Entity (Ent)
26797 and then Ekind (Ent) = E_Variable)
26798 then
26799 return False;
26800 end if;
26802 -- OK, all above conditions are met. We also require that the scope of
26803 -- the reference be the same as the scope of the entity, not counting
26804 -- packages and blocks and loops.
26806 declare
26807 E_Scope : constant Entity_Id := Scope (Ent);
26808 R_Scope : Entity_Id;
26810 begin
26811 R_Scope := Current_Scope;
26812 while R_Scope /= Standard_Standard loop
26813 exit when R_Scope = E_Scope;
26815 if Ekind (R_Scope) not in E_Package | E_Block | E_Loop then
26816 return False;
26817 else
26818 R_Scope := Scope (R_Scope);
26819 end if;
26820 end loop;
26821 end;
26823 -- We also require that the reference does not appear in a context
26824 -- where it is not sure to be executed (i.e. a conditional context
26825 -- or an exception handler). We skip this if Cond is True, since the
26826 -- capturing of values from conditional tests handles this ok.
26828 if Cond or else No (N) then
26829 return True;
26830 end if;
26832 declare
26833 Desc : Node_Id;
26834 P : Node_Id;
26836 begin
26837 Desc := N;
26839 -- Seems dubious that case expressions are not handled here ???
26841 P := Parent (N);
26842 while Present (P) loop
26843 if Is_Body (P) then
26844 return True;
26846 elsif Nkind (P) = N_If_Statement
26847 or else Nkind (P) = N_Case_Statement
26848 or else (Nkind (P) in N_Short_Circuit
26849 and then Desc = Right_Opnd (P))
26850 or else (Nkind (P) = N_If_Expression
26851 and then Desc /= First (Expressions (P)))
26852 or else Nkind (P) = N_Exception_Handler
26853 or else Nkind (P) = N_Selective_Accept
26854 or else Nkind (P) = N_Conditional_Entry_Call
26855 or else Nkind (P) = N_Timed_Entry_Call
26856 or else Nkind (P) = N_Asynchronous_Select
26857 then
26858 return False;
26860 else
26861 Desc := P;
26862 P := Parent (P);
26864 -- A special Ada 2012 case: the original node may be part
26865 -- of the else_actions of a conditional expression, in which
26866 -- case it might not have been expanded yet, and appears in
26867 -- a non-syntactic list of actions. In that case it is clearly
26868 -- not safe to save a value.
26870 if No (P)
26871 and then Is_List_Member (Desc)
26872 and then No (Parent (List_Containing (Desc)))
26873 then
26874 return False;
26875 end if;
26876 end if;
26877 end loop;
26878 end;
26880 -- OK, looks safe to set value
26882 return True;
26883 end Safe_To_Capture_Value;
26885 ---------------
26886 -- Same_Name --
26887 ---------------
26889 function Same_Name (N1, N2 : Node_Id) return Boolean is
26890 K1 : constant Node_Kind := Nkind (N1);
26891 K2 : constant Node_Kind := Nkind (N2);
26893 begin
26894 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
26895 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
26896 then
26897 return Chars (N1) = Chars (N2);
26899 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
26900 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
26901 then
26902 return Same_Name (Selector_Name (N1), Selector_Name (N2))
26903 and then Same_Name (Prefix (N1), Prefix (N2));
26905 else
26906 return False;
26907 end if;
26908 end Same_Name;
26910 -----------------
26911 -- Same_Object --
26912 -----------------
26914 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
26915 N1 : constant Node_Id := Original_Node (Node1);
26916 N2 : constant Node_Id := Original_Node (Node2);
26917 -- We do the tests on original nodes, since we are most interested
26918 -- in the original source, not any expansion that got in the way.
26920 K1 : constant Node_Kind := Nkind (N1);
26921 K2 : constant Node_Kind := Nkind (N2);
26923 begin
26924 -- First case, both are entities with same entity
26926 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
26927 declare
26928 EN1 : constant Entity_Id := Entity (N1);
26929 EN2 : constant Entity_Id := Entity (N2);
26930 begin
26931 if Present (EN1) and then Present (EN2)
26932 and then (Ekind (EN1) in E_Variable | E_Constant
26933 or else Is_Formal (EN1))
26934 and then EN1 = EN2
26935 then
26936 return True;
26937 end if;
26938 end;
26939 end if;
26941 -- Second case, selected component with same selector, same record
26943 if K1 = N_Selected_Component
26944 and then K2 = N_Selected_Component
26945 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
26946 then
26947 return Same_Object (Prefix (N1), Prefix (N2));
26949 -- Third case, indexed component with same subscripts, same array
26951 elsif K1 = N_Indexed_Component
26952 and then K2 = N_Indexed_Component
26953 and then Same_Object (Prefix (N1), Prefix (N2))
26954 then
26955 declare
26956 E1, E2 : Node_Id;
26957 begin
26958 E1 := First (Expressions (N1));
26959 E2 := First (Expressions (N2));
26960 while Present (E1) loop
26961 if not Same_Value (E1, E2) then
26962 return False;
26963 else
26964 Next (E1);
26965 Next (E2);
26966 end if;
26967 end loop;
26969 return True;
26970 end;
26972 -- Fourth case, slice of same array with same bounds
26974 elsif K1 = N_Slice
26975 and then K2 = N_Slice
26976 and then Nkind (Discrete_Range (N1)) = N_Range
26977 and then Nkind (Discrete_Range (N2)) = N_Range
26978 and then Same_Value (Low_Bound (Discrete_Range (N1)),
26979 Low_Bound (Discrete_Range (N2)))
26980 and then Same_Value (High_Bound (Discrete_Range (N1)),
26981 High_Bound (Discrete_Range (N2)))
26982 then
26983 return Same_Name (Prefix (N1), Prefix (N2));
26985 -- All other cases, not clearly the same object
26987 else
26988 return False;
26989 end if;
26990 end Same_Object;
26992 ---------------------------------
26993 -- Same_Or_Aliased_Subprograms --
26994 ---------------------------------
26996 function Same_Or_Aliased_Subprograms
26997 (S : Entity_Id;
26998 E : Entity_Id) return Boolean
27000 Subp_Alias : constant Entity_Id := Alias (S);
27001 Subp : Entity_Id := E;
27002 begin
27003 -- During expansion of subprograms with postconditions the original
27004 -- subprogram's declarations and statements get wrapped into a local
27005 -- _Wrapped_Statements subprogram.
27007 if Chars (Subp) = Name_uWrapped_Statements then
27008 Subp := Enclosing_Subprogram (Subp);
27009 end if;
27011 return S = Subp
27012 or else (Present (Subp_Alias) and then Subp_Alias = Subp);
27013 end Same_Or_Aliased_Subprograms;
27015 ---------------
27016 -- Same_Type --
27017 ---------------
27019 function Same_Type (T1, T2 : Entity_Id) return Boolean is
27020 begin
27021 if T1 = T2 then
27022 return True;
27024 elsif not Is_Constrained (T1)
27025 and then not Is_Constrained (T2)
27026 and then Base_Type (T1) = Base_Type (T2)
27027 then
27028 return True;
27030 -- For now don't bother with case of identical constraints, to be
27031 -- fiddled with later on perhaps (this is only used for optimization
27032 -- purposes, so it is not critical to do a best possible job)
27034 else
27035 return False;
27036 end if;
27037 end Same_Type;
27039 ----------------
27040 -- Same_Value --
27041 ----------------
27043 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
27044 begin
27045 if Compile_Time_Known_Value (Node1)
27046 and then Compile_Time_Known_Value (Node2)
27047 then
27048 -- Handle properly compile-time expressions that are not
27049 -- scalar.
27051 if Is_String_Type (Etype (Node1)) then
27052 return Expr_Value_S (Node1) = Expr_Value_S (Node2);
27054 else
27055 return Expr_Value (Node1) = Expr_Value (Node2);
27056 end if;
27058 elsif Same_Object (Node1, Node2) then
27059 return True;
27060 else
27061 return False;
27062 end if;
27063 end Same_Value;
27065 --------------------
27066 -- Set_SPARK_Mode --
27067 --------------------
27069 procedure Set_SPARK_Mode (Context : Entity_Id) is
27070 begin
27071 -- Do not consider illegal or partially decorated constructs
27073 if Ekind (Context) = E_Void or else Error_Posted (Context) then
27074 null;
27076 elsif Present (SPARK_Pragma (Context)) then
27077 Install_SPARK_Mode
27078 (Mode => Get_SPARK_Mode_From_Annotation (SPARK_Pragma (Context)),
27079 Prag => SPARK_Pragma (Context));
27080 end if;
27081 end Set_SPARK_Mode;
27083 -------------------------
27084 -- Scalar_Part_Present --
27085 -------------------------
27087 function Scalar_Part_Present (Typ : Entity_Id) return Boolean is
27088 Val_Typ : constant Entity_Id := Validated_View (Typ);
27089 Field : Entity_Id;
27091 begin
27092 if Is_Scalar_Type (Val_Typ) then
27093 return True;
27095 elsif Is_Array_Type (Val_Typ) then
27096 return Scalar_Part_Present (Component_Type (Val_Typ));
27098 elsif Is_Record_Type (Val_Typ) then
27099 Field := First_Component_Or_Discriminant (Val_Typ);
27100 while Present (Field) loop
27101 if Scalar_Part_Present (Etype (Field)) then
27102 return True;
27103 end if;
27105 Next_Component_Or_Discriminant (Field);
27106 end loop;
27107 end if;
27109 return False;
27110 end Scalar_Part_Present;
27112 ------------------------
27113 -- Scope_Is_Transient --
27114 ------------------------
27116 function Scope_Is_Transient return Boolean is
27117 begin
27118 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
27119 end Scope_Is_Transient;
27121 ------------------
27122 -- Scope_Within --
27123 ------------------
27125 function Scope_Within
27126 (Inner : Entity_Id;
27127 Outer : Entity_Id) return Boolean
27129 Curr : Entity_Id;
27131 begin
27132 Curr := Inner;
27133 while Present (Curr) and then Curr /= Standard_Standard loop
27134 Curr := Scope (Curr);
27136 if Curr = Outer then
27137 return True;
27139 -- A selective accept body appears within a task type, but the
27140 -- enclosing subprogram is the procedure of the task body.
27142 elsif Ekind (Implementation_Base_Type (Curr)) = E_Task_Type
27143 and then
27144 Outer = Task_Body_Procedure (Implementation_Base_Type (Curr))
27145 then
27146 return True;
27148 -- Ditto for the body of a protected operation
27150 elsif Is_Subprogram (Curr)
27151 and then Outer = Protected_Body_Subprogram (Curr)
27152 then
27153 return True;
27155 -- Outside of its scope, a synchronized type may just be private
27157 elsif Is_Private_Type (Curr)
27158 and then Present (Full_View (Curr))
27159 and then Is_Concurrent_Type (Full_View (Curr))
27160 then
27161 return Scope_Within (Full_View (Curr), Outer);
27162 end if;
27163 end loop;
27165 return False;
27166 end Scope_Within;
27168 --------------------------
27169 -- Scope_Within_Or_Same --
27170 --------------------------
27172 function Scope_Within_Or_Same
27173 (Inner : Entity_Id;
27174 Outer : Entity_Id) return Boolean
27176 Curr : Entity_Id := Inner;
27178 begin
27179 -- Similar to the above, but check for scope identity first
27181 while Present (Curr) and then Curr /= Standard_Standard loop
27182 if Curr = Outer then
27183 return True;
27185 elsif Ekind (Implementation_Base_Type (Curr)) = E_Task_Type
27186 and then
27187 Outer = Task_Body_Procedure (Implementation_Base_Type (Curr))
27188 then
27189 return True;
27191 elsif Is_Subprogram (Curr)
27192 and then Outer = Protected_Body_Subprogram (Curr)
27193 then
27194 return True;
27196 elsif Is_Private_Type (Curr)
27197 and then Present (Full_View (Curr))
27198 then
27199 if Full_View (Curr) = Outer then
27200 return True;
27201 else
27202 return Scope_Within (Full_View (Curr), Outer);
27203 end if;
27204 end if;
27206 Curr := Scope (Curr);
27207 end loop;
27209 return False;
27210 end Scope_Within_Or_Same;
27212 ------------------------
27213 -- Set_Current_Entity --
27214 ------------------------
27216 -- The given entity is to be set as the currently visible definition of its
27217 -- associated name (i.e. the Node_Id associated with its name). All we have
27218 -- to do is to get the name from the identifier, and then set the
27219 -- associated Node_Id to point to the given entity.
27221 procedure Set_Current_Entity (E : Entity_Id) is
27222 begin
27223 Set_Name_Entity_Id (Chars (E), E);
27224 end Set_Current_Entity;
27226 ---------------------------
27227 -- Set_Debug_Info_Needed --
27228 ---------------------------
27230 procedure Set_Debug_Info_Needed (T : Entity_Id) is
27232 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
27233 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
27234 -- Used to set debug info in a related node if not set already
27236 --------------------------------------
27237 -- Set_Debug_Info_Needed_If_Not_Set --
27238 --------------------------------------
27240 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
27241 begin
27242 if Present (E) and then not Needs_Debug_Info (E) then
27243 Set_Debug_Info_Needed (E);
27245 -- For a private type, indicate that the full view also needs
27246 -- debug information.
27248 if Is_Type (E)
27249 and then Is_Private_Type (E)
27250 and then Present (Full_View (E))
27251 then
27252 Set_Debug_Info_Needed (Full_View (E));
27253 end if;
27254 end if;
27255 end Set_Debug_Info_Needed_If_Not_Set;
27257 -- Start of processing for Set_Debug_Info_Needed
27259 begin
27260 -- Nothing to do if there is no available entity
27262 if No (T) then
27263 return;
27265 -- Nothing to do for an entity with suppressed debug information
27267 elsif Debug_Info_Off (T) then
27268 return;
27270 -- Nothing to do for an ignored Ghost entity because the entity will be
27271 -- eliminated from the tree.
27273 elsif Is_Ignored_Ghost_Entity (T) then
27274 return;
27276 -- Nothing to do if entity comes from a predefined file. Library files
27277 -- are compiled without debug information, but inlined bodies of these
27278 -- routines may appear in user code, and debug information on them ends
27279 -- up complicating debugging the user code.
27281 elsif In_Inlined_Body and then In_Predefined_Unit (T) then
27282 Set_Needs_Debug_Info (T, False);
27283 end if;
27285 -- Set flag in entity itself. Note that we will go through the following
27286 -- circuitry even if the flag is already set on T. That's intentional,
27287 -- it makes sure that the flag will be set in subsidiary entities.
27289 Set_Needs_Debug_Info (T);
27291 -- Set flag on subsidiary entities if not set already
27293 if Is_Object (T) then
27294 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
27296 elsif Is_Type (T) then
27297 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
27299 if Is_Record_Type (T) then
27300 declare
27301 Ent : Entity_Id := First_Entity (T);
27302 begin
27303 while Present (Ent) loop
27304 Set_Debug_Info_Needed_If_Not_Set (Ent);
27305 Next_Entity (Ent);
27306 end loop;
27307 end;
27309 -- For a class wide subtype, we also need debug information
27310 -- for the equivalent type.
27312 if Ekind (T) = E_Class_Wide_Subtype then
27313 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
27314 end if;
27316 elsif Is_Array_Type (T) then
27317 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
27319 declare
27320 Indx : Node_Id := First_Index (T);
27321 begin
27322 while Present (Indx) loop
27323 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
27324 Next_Index (Indx);
27325 end loop;
27326 end;
27328 -- For a packed array type, we also need debug information for
27329 -- the type used to represent the packed array. Conversely, we
27330 -- also need it for the former if we need it for the latter.
27332 if Is_Packed (T) then
27333 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Impl_Type (T));
27334 end if;
27336 if Is_Packed_Array_Impl_Type (T) then
27337 Set_Debug_Info_Needed_If_Not_Set (Original_Array_Type (T));
27338 end if;
27340 elsif Is_Access_Type (T) then
27341 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
27343 elsif Is_Private_Type (T) then
27344 declare
27345 FV : constant Entity_Id := Full_View (T);
27347 begin
27348 Set_Debug_Info_Needed_If_Not_Set (FV);
27350 -- If the full view is itself a derived private type, we need
27351 -- debug information on its underlying type.
27353 if Present (FV)
27354 and then Is_Private_Type (FV)
27355 and then Present (Underlying_Full_View (FV))
27356 then
27357 Set_Needs_Debug_Info (Underlying_Full_View (FV));
27358 end if;
27359 end;
27361 elsif Is_Protected_Type (T) then
27362 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
27364 elsif Is_Scalar_Type (T) then
27366 -- If the subrange bounds are materialized by dedicated constant
27367 -- objects, also include them in the debug info to make sure the
27368 -- debugger can properly use them.
27370 if Present (Scalar_Range (T))
27371 and then Nkind (Scalar_Range (T)) = N_Range
27372 then
27373 declare
27374 Low_Bnd : constant Node_Id := Type_Low_Bound (T);
27375 High_Bnd : constant Node_Id := Type_High_Bound (T);
27377 begin
27378 if Is_Entity_Name (Low_Bnd) then
27379 Set_Debug_Info_Needed_If_Not_Set (Entity (Low_Bnd));
27380 end if;
27382 if Is_Entity_Name (High_Bnd) then
27383 Set_Debug_Info_Needed_If_Not_Set (Entity (High_Bnd));
27384 end if;
27385 end;
27386 end if;
27387 end if;
27388 end if;
27389 end Set_Debug_Info_Needed;
27391 --------------------------------
27392 -- Set_Debug_Info_Defining_Id --
27393 --------------------------------
27395 procedure Set_Debug_Info_Defining_Id (N : Node_Id) is
27396 begin
27397 if Comes_From_Source (Defining_Identifier (N)) then
27398 Set_Debug_Info_Needed (Defining_Identifier (N));
27399 end if;
27400 end Set_Debug_Info_Defining_Id;
27402 ----------------------------
27403 -- Set_Entity_With_Checks --
27404 ----------------------------
27406 procedure Set_Entity_With_Checks (N : Node_Id; Val : Entity_Id) is
27407 Val_Actual : Entity_Id;
27408 Nod : Node_Id;
27409 Post_Node : Node_Id;
27411 begin
27412 -- Unconditionally set the entity
27414 Set_Entity (N, Val);
27416 -- The node to post on is the selector in the case of an expanded name,
27417 -- and otherwise the node itself.
27419 if Nkind (N) = N_Expanded_Name then
27420 Post_Node := Selector_Name (N);
27421 else
27422 Post_Node := N;
27423 end if;
27425 -- Check for violation of No_Fixed_IO
27427 if Restriction_Check_Required (No_Fixed_IO)
27428 and then
27429 ((RTU_Loaded (Ada_Text_IO)
27430 and then (Is_RTE (Val, RE_Decimal_IO)
27431 or else
27432 Is_RTE (Val, RE_Fixed_IO)))
27434 or else
27435 (RTU_Loaded (Ada_Wide_Text_IO)
27436 and then (Is_RTE (Val, RO_WT_Decimal_IO)
27437 or else
27438 Is_RTE (Val, RO_WT_Fixed_IO)))
27440 or else
27441 (RTU_Loaded (Ada_Wide_Wide_Text_IO)
27442 and then (Is_RTE (Val, RO_WW_Decimal_IO)
27443 or else
27444 Is_RTE (Val, RO_WW_Fixed_IO))))
27446 -- A special extra check, don't complain about a reference from within
27447 -- the Ada.Interrupts package itself!
27449 and then not In_Same_Extended_Unit (N, Val)
27450 then
27451 Check_Restriction (No_Fixed_IO, Post_Node);
27452 end if;
27454 -- Remaining checks are only done on source nodes. Note that we test
27455 -- for violation of No_Fixed_IO even on non-source nodes, because the
27456 -- cases for checking violations of this restriction are instantiations
27457 -- where the reference in the instance has Comes_From_Source False.
27459 if not Comes_From_Source (N) then
27460 return;
27461 end if;
27463 -- Check for violation of No_Abort_Statements, which is triggered by
27464 -- call to Ada.Task_Identification.Abort_Task.
27466 if Restriction_Check_Required (No_Abort_Statements)
27467 and then (Is_RTE (Val, RE_Abort_Task))
27469 -- A special extra check, don't complain about a reference from within
27470 -- the Ada.Task_Identification package itself!
27472 and then not In_Same_Extended_Unit (N, Val)
27473 then
27474 Check_Restriction (No_Abort_Statements, Post_Node);
27475 end if;
27477 if Val = Standard_Long_Long_Integer then
27478 Check_Restriction (No_Long_Long_Integers, Post_Node);
27479 end if;
27481 -- Check for violation of No_Dynamic_Attachment
27483 if Restriction_Check_Required (No_Dynamic_Attachment)
27484 and then RTU_Loaded (Ada_Interrupts)
27485 and then (Is_RTE (Val, RE_Is_Reserved) or else
27486 Is_RTE (Val, RE_Is_Attached) or else
27487 Is_RTE (Val, RE_Current_Handler) or else
27488 Is_RTE (Val, RE_Attach_Handler) or else
27489 Is_RTE (Val, RE_Exchange_Handler) or else
27490 Is_RTE (Val, RE_Detach_Handler) or else
27491 Is_RTE (Val, RE_Reference))
27493 -- A special extra check, don't complain about a reference from within
27494 -- the Ada.Interrupts package itself!
27496 and then not In_Same_Extended_Unit (N, Val)
27497 then
27498 Check_Restriction (No_Dynamic_Attachment, Post_Node);
27499 end if;
27501 -- Check for No_Implementation_Identifiers
27503 if Restriction_Check_Required (No_Implementation_Identifiers) then
27505 -- We have an implementation defined entity if it is marked as
27506 -- implementation defined, or is defined in a package marked as
27507 -- implementation defined. However, library packages themselves
27508 -- are excluded (we don't want to flag Interfaces itself, just
27509 -- the entities within it).
27511 if (Is_Implementation_Defined (Val)
27512 or else
27513 (Present (Scope (Val))
27514 and then Is_Implementation_Defined (Scope (Val))))
27515 and then not (Is_Package_Or_Generic_Package (Val)
27516 and then Is_Library_Level_Entity (Val))
27517 then
27518 Check_Restriction (No_Implementation_Identifiers, Post_Node);
27519 end if;
27520 end if;
27522 -- Do the style check
27524 if Style_Check
27525 and then not Suppress_Style_Checks (Val)
27526 and then not In_Instance
27527 then
27528 if Nkind (N) = N_Identifier then
27529 Nod := N;
27530 elsif Nkind (N) = N_Expanded_Name then
27531 Nod := Selector_Name (N);
27532 else
27533 return;
27534 end if;
27536 -- A special situation arises for derived operations, where we want
27537 -- to do the check against the parent (since the Sloc of the derived
27538 -- operation points to the derived type declaration itself).
27540 Val_Actual := Val;
27541 while not Comes_From_Source (Val_Actual)
27542 and then Nkind (Val_Actual) in N_Entity
27543 and then (Ekind (Val_Actual) = E_Enumeration_Literal
27544 or else Is_Subprogram_Or_Generic_Subprogram (Val_Actual))
27545 and then Present (Alias (Val_Actual))
27546 loop
27547 Val_Actual := Alias (Val_Actual);
27548 end loop;
27550 -- Renaming declarations for generic actuals do not come from source,
27551 -- and have a different name from that of the entity they rename, so
27552 -- there is no style check to perform here.
27554 if Chars (Nod) = Chars (Val_Actual) then
27555 Style.Check_Identifier (Nod, Val_Actual);
27556 end if;
27557 end if;
27558 end Set_Entity_With_Checks;
27560 ------------------------------
27561 -- Set_Invalid_Scalar_Value --
27562 ------------------------------
27564 procedure Set_Invalid_Scalar_Value
27565 (Scal_Typ : Float_Scalar_Id;
27566 Value : Ureal)
27568 Slot : Ureal renames Invalid_Floats (Scal_Typ);
27570 begin
27571 -- Detect an attempt to set a different value for the same scalar type
27573 pragma Assert (Slot = No_Ureal);
27574 Slot := Value;
27575 end Set_Invalid_Scalar_Value;
27577 ------------------------------
27578 -- Set_Invalid_Scalar_Value --
27579 ------------------------------
27581 procedure Set_Invalid_Scalar_Value
27582 (Scal_Typ : Integer_Scalar_Id;
27583 Value : Uint)
27585 Slot : Uint renames Invalid_Integers (Scal_Typ);
27587 begin
27588 -- Detect an attempt to set a different value for the same scalar type
27590 pragma Assert (No (Slot));
27591 Slot := Value;
27592 end Set_Invalid_Scalar_Value;
27594 ------------------------
27595 -- Set_Name_Entity_Id --
27596 ------------------------
27598 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
27599 begin
27600 Set_Name_Table_Int (Id, Int (Val));
27601 end Set_Name_Entity_Id;
27603 ---------------------
27604 -- Set_Next_Actual --
27605 ---------------------
27607 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
27608 begin
27609 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
27610 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
27611 end if;
27612 end Set_Next_Actual;
27614 ----------------------------------
27615 -- Set_Optimize_Alignment_Flags --
27616 ----------------------------------
27618 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
27619 begin
27620 if Optimize_Alignment = 'S' then
27621 Set_Optimize_Alignment_Space (E);
27622 elsif Optimize_Alignment = 'T' then
27623 Set_Optimize_Alignment_Time (E);
27624 end if;
27625 end Set_Optimize_Alignment_Flags;
27627 -----------------------
27628 -- Set_Public_Status --
27629 -----------------------
27631 procedure Set_Public_Status (Id : Entity_Id) is
27632 S : constant Entity_Id := Current_Scope;
27634 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
27635 -- Determines if E is defined within handled statement sequence or
27636 -- an if statement, returns True if so, False otherwise.
27638 ----------------------
27639 -- Within_HSS_Or_If --
27640 ----------------------
27642 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
27643 N : Node_Id;
27644 begin
27645 N := Declaration_Node (E);
27646 loop
27647 N := Parent (N);
27649 if No (N) then
27650 return False;
27652 elsif Nkind (N) in
27653 N_Handled_Sequence_Of_Statements | N_If_Statement
27654 then
27655 return True;
27656 end if;
27657 end loop;
27658 end Within_HSS_Or_If;
27660 -- Start of processing for Set_Public_Status
27662 begin
27663 -- Everything in the scope of Standard is public
27665 if S = Standard_Standard then
27666 Set_Is_Public (Id);
27668 -- Entity is definitely not public if enclosing scope is not public
27670 elsif not Is_Public (S) then
27671 return;
27673 -- An object or function declaration that occurs in a handled sequence
27674 -- of statements or within an if statement is the declaration for a
27675 -- temporary object or local subprogram generated by the expander. It
27676 -- never needs to be made public and furthermore, making it public can
27677 -- cause back end problems.
27679 elsif Nkind (Parent (Id)) in
27680 N_Object_Declaration | N_Function_Specification
27681 and then Within_HSS_Or_If (Id)
27682 then
27683 return;
27685 -- Entities in public packages or records are public
27687 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
27688 Set_Is_Public (Id);
27690 -- The bounds of an entry family declaration can generate object
27691 -- declarations that are visible to the back-end, e.g. in the
27692 -- the declaration of a composite type that contains tasks.
27694 elsif Is_Concurrent_Type (S)
27695 and then not Has_Completion (S)
27696 and then Nkind (Parent (Id)) = N_Object_Declaration
27697 then
27698 Set_Is_Public (Id);
27699 end if;
27700 end Set_Public_Status;
27702 -----------------------------
27703 -- Set_Referenced_Modified --
27704 -----------------------------
27706 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
27707 Pref : Node_Id;
27709 begin
27710 -- Deal with indexed or selected component where prefix is modified
27712 if Nkind (N) in N_Indexed_Component | N_Selected_Component then
27713 Pref := Prefix (N);
27715 -- If prefix is access type, then it is the designated object that is
27716 -- being modified, which means we have no entity to set the flag on.
27718 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
27719 return;
27721 -- Otherwise chase the prefix
27723 else
27724 Set_Referenced_Modified (Pref, Out_Param);
27725 end if;
27727 -- Otherwise see if we have an entity name (only other case to process)
27729 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
27730 Set_Referenced_As_LHS (Entity (N), not Out_Param);
27731 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
27732 end if;
27733 end Set_Referenced_Modified;
27735 ------------------
27736 -- Set_Rep_Info --
27737 ------------------
27739 procedure Set_Rep_Info (T1 : Entity_Id; T2 : Entity_Id) is
27740 begin
27741 Set_Is_Atomic (T1, Is_Atomic (T2));
27742 Set_Is_Independent (T1, Is_Independent (T2));
27743 Set_Is_Volatile_Full_Access (T1, Is_Volatile_Full_Access (T2));
27745 if Is_Base_Type (T1) then
27746 Set_Is_Volatile (T1, Is_Volatile (T2));
27747 end if;
27748 end Set_Rep_Info;
27750 ----------------------------
27751 -- Set_Scope_Is_Transient --
27752 ----------------------------
27754 procedure Set_Scope_Is_Transient (V : Boolean := True) is
27755 begin
27756 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
27757 end Set_Scope_Is_Transient;
27759 -------------------
27760 -- Set_Size_Info --
27761 -------------------
27763 procedure Set_Size_Info (T1, T2 : Entity_Id) is
27764 begin
27765 -- We copy Esize, but not RM_Size, since in general RM_Size is
27766 -- subtype specific and does not get inherited by all subtypes.
27768 Copy_Esize (To => T1, From => T2);
27769 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
27771 if Is_Discrete_Or_Fixed_Point_Type (T1)
27772 and then
27773 Is_Discrete_Or_Fixed_Point_Type (T2)
27774 then
27775 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
27776 end if;
27778 Copy_Alignment (To => T1, From => T2);
27779 end Set_Size_Info;
27781 ------------------------------
27782 -- Should_Ignore_Pragma_Par --
27783 ------------------------------
27785 function Should_Ignore_Pragma_Par (Prag_Name : Name_Id) return Boolean is
27786 pragma Assert (Compiler_State = Parsing);
27787 -- This one can't work during semantic analysis, because we don't have a
27788 -- correct Current_Source_File.
27790 Result : constant Boolean :=
27791 Get_Name_Table_Boolean3 (Prag_Name)
27792 and then not Is_Internal_File_Name
27793 (File_Name (Current_Source_File));
27794 begin
27795 return Result;
27796 end Should_Ignore_Pragma_Par;
27798 ------------------------------
27799 -- Should_Ignore_Pragma_Sem --
27800 ------------------------------
27802 function Should_Ignore_Pragma_Sem (N : Node_Id) return Boolean is
27803 pragma Assert (Compiler_State = Analyzing);
27804 Prag_Name : constant Name_Id := Pragma_Name (N);
27805 Result : constant Boolean :=
27806 Get_Name_Table_Boolean3 (Prag_Name)
27807 and then not In_Internal_Unit (N);
27809 begin
27810 return Result;
27811 end Should_Ignore_Pragma_Sem;
27813 --------------------
27814 -- Static_Boolean --
27815 --------------------
27817 function Static_Boolean (N : Node_Id) return Opt_Ubool is
27818 begin
27819 Analyze_And_Resolve (N, Standard_Boolean);
27821 if N = Error
27822 or else Error_Posted (N)
27823 or else Etype (N) = Any_Type
27824 then
27825 return No_Uint;
27826 end if;
27828 if Is_OK_Static_Expression (N) then
27829 if not Raises_Constraint_Error (N) then
27830 return Expr_Value (N);
27831 else
27832 return No_Uint;
27833 end if;
27835 elsif Etype (N) = Any_Type then
27836 return No_Uint;
27838 else
27839 Flag_Non_Static_Expr
27840 ("static boolean expression required here", N);
27841 return No_Uint;
27842 end if;
27843 end Static_Boolean;
27845 --------------------
27846 -- Static_Integer --
27847 --------------------
27849 function Static_Integer (N : Node_Id) return Uint is
27850 begin
27851 Analyze_And_Resolve (N, Any_Integer);
27853 if N = Error
27854 or else Error_Posted (N)
27855 or else Etype (N) = Any_Type
27856 then
27857 return No_Uint;
27858 end if;
27860 if Is_OK_Static_Expression (N) then
27861 if not Raises_Constraint_Error (N) then
27862 return Expr_Value (N);
27863 else
27864 return No_Uint;
27865 end if;
27867 elsif Etype (N) = Any_Type then
27868 return No_Uint;
27870 else
27871 Flag_Non_Static_Expr
27872 ("static integer expression required here", N);
27873 return No_Uint;
27874 end if;
27875 end Static_Integer;
27877 -------------------------------
27878 -- Statically_Denotes_Entity --
27879 -------------------------------
27881 function Statically_Denotes_Entity (N : Node_Id) return Boolean is
27882 E : Entity_Id;
27883 begin
27884 if not Is_Entity_Name (N) then
27885 return False;
27886 else
27887 E := Entity (N);
27888 end if;
27890 return
27891 Nkind (Parent (E)) /= N_Object_Renaming_Declaration
27892 or else Is_Prival (E)
27893 or else Statically_Denotes_Entity (Renamed_Object (E));
27894 end Statically_Denotes_Entity;
27896 -------------------------------
27897 -- Statically_Denotes_Object --
27898 -------------------------------
27900 function Statically_Denotes_Object (N : Node_Id) return Boolean is
27901 begin
27902 return Statically_Denotes_Entity (N)
27903 and then Is_Object_Reference (N);
27904 end Statically_Denotes_Object;
27906 --------------------------
27907 -- Statically_Different --
27908 --------------------------
27910 function Statically_Different (E1, E2 : Node_Id) return Boolean is
27911 R1 : constant Node_Id := Get_Referenced_Object (E1);
27912 R2 : constant Node_Id := Get_Referenced_Object (E2);
27913 begin
27914 return Is_Entity_Name (R1)
27915 and then Is_Entity_Name (R2)
27916 and then Entity (R1) /= Entity (R2)
27917 and then not Is_Formal (Entity (R1))
27918 and then not Is_Formal (Entity (R2));
27919 end Statically_Different;
27921 -----------------------------
27922 -- Statically_Names_Object --
27923 -----------------------------
27925 function Statically_Names_Object (N : Node_Id) return Boolean is
27926 begin
27927 if Statically_Denotes_Object (N) then
27928 return True;
27929 elsif Is_Entity_Name (N) then
27930 declare
27931 E : constant Entity_Id := Entity (N);
27932 begin
27933 return Nkind (Parent (E)) = N_Object_Renaming_Declaration
27934 and then Statically_Names_Object (Renamed_Object (E));
27935 end;
27936 end if;
27938 case Nkind (N) is
27939 when N_Indexed_Component =>
27940 if Is_Access_Type (Etype (Prefix (N))) then
27941 -- treat implicit dereference same as explicit
27942 return False;
27943 end if;
27945 if not Is_Constrained (Etype (Prefix (N))) then
27946 return False;
27947 end if;
27949 declare
27950 Indx : Node_Id := First_Index (Etype (Prefix (N)));
27951 Expr : Node_Id := First (Expressions (N));
27952 Index_Subtype : Node_Id;
27953 begin
27954 loop
27955 Index_Subtype := Etype (Indx);
27957 if not Is_Static_Subtype (Index_Subtype) then
27958 return False;
27959 end if;
27960 if not Is_OK_Static_Expression (Expr) then
27961 return False;
27962 end if;
27964 declare
27965 Index_Value : constant Uint := Expr_Value (Expr);
27966 Low_Value : constant Uint :=
27967 Expr_Value (Type_Low_Bound (Index_Subtype));
27968 High_Value : constant Uint :=
27969 Expr_Value (Type_High_Bound (Index_Subtype));
27970 begin
27971 if (Index_Value < Low_Value)
27972 or (Index_Value > High_Value)
27973 then
27974 return False;
27975 end if;
27976 end;
27978 Next_Index (Indx);
27979 Expr := Next (Expr);
27980 pragma Assert ((Present (Indx) = Present (Expr))
27981 or else (Serious_Errors_Detected > 0));
27982 exit when not (Present (Indx) and Present (Expr));
27983 end loop;
27984 end;
27986 when N_Selected_Component =>
27987 if Is_Access_Type (Etype (Prefix (N))) then
27988 -- treat implicit dereference same as explicit
27989 return False;
27990 end if;
27992 if Ekind (Entity (Selector_Name (N))) not in
27993 E_Component | E_Discriminant
27994 then
27995 return False;
27996 end if;
27998 declare
27999 Comp : constant Entity_Id :=
28000 Original_Record_Component (Entity (Selector_Name (N)));
28001 begin
28002 -- AI12-0373 confirms that we should not call
28003 -- Has_Discriminant_Dependent_Constraint here which would be
28004 -- too strong.
28006 if Is_Declared_Within_Variant (Comp) then
28007 return False;
28008 end if;
28009 end;
28011 when others => -- includes N_Slice, N_Explicit_Dereference
28012 return False;
28013 end case;
28015 pragma Assert (Present (Prefix (N)));
28017 return Statically_Names_Object (Prefix (N));
28018 end Statically_Names_Object;
28020 ---------------------------------
28021 -- String_From_Numeric_Literal --
28022 ---------------------------------
28024 function String_From_Numeric_Literal (N : Node_Id) return String_Id is
28025 Loc : constant Source_Ptr := Sloc (N);
28026 Sbuffer : constant Source_Buffer_Ptr :=
28027 Source_Text (Get_Source_File_Index (Loc));
28028 Src_Ptr : Source_Ptr := Loc;
28030 C : Character := Sbuffer (Src_Ptr);
28031 -- Current source program character
28033 function Belongs_To_Numeric_Literal (C : Character) return Boolean;
28034 -- Return True if C belongs to the numeric literal
28036 --------------------------------
28037 -- Belongs_To_Numeric_Literal --
28038 --------------------------------
28040 function Belongs_To_Numeric_Literal (C : Character) return Boolean is
28041 begin
28042 case C is
28043 when '0' .. '9' | '_' | '.' | 'e' | '#' | 'A' .. 'F' =>
28044 return True;
28046 -- Make sure '+' or '-' is part of an exponent
28048 when '+' | '-' =>
28049 declare
28050 Prev_C : constant Character := Sbuffer (Src_Ptr - 1);
28051 begin
28052 return Prev_C in 'e' | 'E';
28053 end;
28055 -- Other characters cannot belong to a numeric literal
28057 when others =>
28058 return False;
28059 end case;
28060 end Belongs_To_Numeric_Literal;
28062 -- Start of processing for String_From_Numeric_Literal
28064 begin
28065 Start_String;
28066 while Belongs_To_Numeric_Literal (C) loop
28067 Store_String_Char (C);
28068 Src_Ptr := Src_Ptr + 1;
28069 C := Sbuffer (Src_Ptr);
28070 end loop;
28072 return End_String;
28073 end String_From_Numeric_Literal;
28075 --------------------------------------
28076 -- Subject_To_Loop_Entry_Attributes --
28077 --------------------------------------
28079 function Subject_To_Loop_Entry_Attributes (N : Node_Id) return Boolean is
28080 Stmt : Node_Id;
28082 begin
28083 Stmt := N;
28085 -- The expansion mechanism transform a loop subject to at least one
28086 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
28087 -- the conditional part.
28089 if Nkind (Stmt) in N_Block_Statement | N_If_Statement
28090 and then Nkind (Original_Node (N)) = N_Loop_Statement
28091 then
28092 Stmt := Original_Node (N);
28093 end if;
28095 return
28096 Nkind (Stmt) = N_Loop_Statement
28097 and then Present (Identifier (Stmt))
28098 and then Present (Entity (Identifier (Stmt)))
28099 and then Has_Loop_Entry_Attributes (Entity (Identifier (Stmt)));
28100 end Subject_To_Loop_Entry_Attributes;
28102 ---------------------
28103 -- Subprogram_Name --
28104 ---------------------
28106 function Subprogram_Name (N : Node_Id) return String is
28107 Buf : Bounded_String;
28108 Ent : Node_Id := N;
28109 Nod : Node_Id;
28111 begin
28112 while Present (Ent) loop
28113 case Nkind (Ent) is
28114 when N_Subprogram_Body =>
28115 Ent := Defining_Unit_Name (Specification (Ent));
28116 exit;
28118 when N_Subprogram_Declaration =>
28119 Nod := Corresponding_Body (Ent);
28121 if Present (Nod) then
28122 Ent := Nod;
28123 else
28124 Ent := Defining_Unit_Name (Specification (Ent));
28125 end if;
28127 exit;
28129 when N_Subprogram_Instantiation
28130 | N_Package_Body
28131 | N_Package_Specification
28133 Ent := Defining_Unit_Name (Ent);
28134 exit;
28136 when N_Protected_Type_Declaration =>
28137 Ent := Corresponding_Body (Ent);
28138 exit;
28140 when N_Protected_Body
28141 | N_Task_Body
28143 Ent := Defining_Identifier (Ent);
28144 exit;
28146 when others =>
28147 null;
28148 end case;
28150 Ent := Parent (Ent);
28151 end loop;
28153 if No (Ent) then
28154 return "unknown subprogram:unknown file:0:0";
28155 end if;
28157 -- If the subprogram is a child unit, use its simple name to start the
28158 -- construction of the fully qualified name.
28160 if Nkind (Ent) = N_Defining_Program_Unit_Name then
28161 Ent := Defining_Identifier (Ent);
28162 end if;
28164 Append_Entity_Name (Buf, Ent);
28166 -- Append homonym number if needed
28168 if Nkind (N) in N_Entity and then Has_Homonym (N) then
28169 declare
28170 H : Entity_Id := Homonym (N);
28171 Nr : Nat := 1;
28173 begin
28174 while Present (H) loop
28175 if Scope (H) = Scope (N) then
28176 Nr := Nr + 1;
28177 end if;
28179 H := Homonym (H);
28180 end loop;
28182 if Nr > 1 then
28183 Append (Buf, '#');
28184 Append (Buf, Nr);
28185 end if;
28186 end;
28187 end if;
28189 -- Append source location of Ent to Buf so that the string will
28190 -- look like "subp:file:line:col".
28192 declare
28193 Loc : constant Source_Ptr := Sloc (Ent);
28194 begin
28195 Append (Buf, ':');
28196 Append (Buf, Reference_Name (Get_Source_File_Index (Loc)));
28197 Append (Buf, ':');
28198 Append (Buf, Nat (Get_Logical_Line_Number (Loc)));
28199 Append (Buf, ':');
28200 Append (Buf, Nat (Get_Column_Number (Loc)));
28201 end;
28203 return +Buf;
28204 end Subprogram_Name;
28206 -------------------------------
28207 -- Support_Atomic_Primitives --
28208 -------------------------------
28210 function Support_Atomic_Primitives (Typ : Entity_Id) return Boolean is
28211 Size : Int;
28213 begin
28214 -- Verify the alignment of Typ is known
28216 if not Known_Alignment (Typ) then
28217 return False;
28218 end if;
28220 if Known_Static_Esize (Typ) then
28221 Size := UI_To_Int (Esize (Typ));
28223 -- If the Esize (Object_Size) is unknown at compile time, look at the
28224 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
28226 elsif Known_Static_RM_Size (Typ) then
28227 Size := UI_To_Int (RM_Size (Typ));
28229 -- Otherwise, the size is considered to be unknown.
28231 else
28232 return False;
28233 end if;
28235 -- Check that the size of the component is 8, 16, 32, or 64 bits and
28236 -- that Typ is properly aligned.
28238 case Size is
28239 when 8 | 16 | 32 | 64 =>
28240 return Size = UI_To_Int (Alignment (Typ)) * 8;
28242 when others =>
28243 return False;
28244 end case;
28245 end Support_Atomic_Primitives;
28247 -----------------
28248 -- Trace_Scope --
28249 -----------------
28251 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
28252 begin
28253 if Debug_Flag_W then
28254 for J in 0 .. Scope_Stack.Last loop
28255 Write_Str (" ");
28256 end loop;
28258 Write_Str (Msg);
28259 Write_Name (Chars (E));
28260 Write_Str (" from ");
28261 Write_Location (Sloc (N));
28262 Write_Eol;
28263 end if;
28264 end Trace_Scope;
28266 -----------------------
28267 -- Transfer_Entities --
28268 -----------------------
28270 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
28271 procedure Set_Public_Status_Of (Id : Entity_Id);
28272 -- Set the Is_Public attribute of arbitrary entity Id by calling routine
28273 -- Set_Public_Status. If successful and Id denotes a record type, set
28274 -- the Is_Public attribute of its fields.
28276 --------------------------
28277 -- Set_Public_Status_Of --
28278 --------------------------
28280 procedure Set_Public_Status_Of (Id : Entity_Id) is
28281 Field : Entity_Id;
28283 begin
28284 if not Is_Public (Id) then
28285 Set_Public_Status (Id);
28287 -- When the input entity is a public record type, ensure that all
28288 -- its internal fields are also exposed to the linker. The fields
28289 -- of a class-wide type are never made public.
28291 if Is_Public (Id)
28292 and then Is_Record_Type (Id)
28293 and then not Is_Class_Wide_Type (Id)
28294 then
28295 Field := First_Entity (Id);
28296 while Present (Field) loop
28297 Set_Is_Public (Field);
28298 Next_Entity (Field);
28299 end loop;
28300 end if;
28301 end if;
28302 end Set_Public_Status_Of;
28304 -- Local variables
28306 Full_Id : Entity_Id;
28307 Id : Entity_Id;
28309 -- Start of processing for Transfer_Entities
28311 begin
28312 Id := First_Entity (From);
28314 if Present (Id) then
28316 -- Merge the entity chain of the source scope with that of the
28317 -- destination scope.
28319 if Present (Last_Entity (To)) then
28320 Link_Entities (Last_Entity (To), Id);
28321 else
28322 Set_First_Entity (To, Id);
28323 end if;
28325 Set_Last_Entity (To, Last_Entity (From));
28327 -- Inspect the entities of the source scope and update their Scope
28328 -- attribute.
28330 while Present (Id) loop
28331 Set_Scope (Id, To);
28332 Set_Public_Status_Of (Id);
28334 -- Handle an internally generated full view for a private type
28336 if Is_Private_Type (Id)
28337 and then Present (Full_View (Id))
28338 and then Is_Itype (Full_View (Id))
28339 then
28340 Full_Id := Full_View (Id);
28342 Set_Scope (Full_Id, To);
28343 Set_Public_Status_Of (Full_Id);
28344 end if;
28346 Next_Entity (Id);
28347 end loop;
28349 Set_First_Entity (From, Empty);
28350 Set_Last_Entity (From, Empty);
28351 end if;
28352 end Transfer_Entities;
28354 ------------------------
28355 -- Traverse_More_Func --
28356 ------------------------
28358 function Traverse_More_Func (Node : Node_Id) return Traverse_Final_Result is
28360 Processing_Itype : Boolean := False;
28361 -- Set to True while traversing the nodes under an Itype, to prevent
28362 -- looping on Itype handling during that traversal.
28364 function Process_More (N : Node_Id) return Traverse_Result;
28365 -- Wrapper over the Process callback to handle parts of the AST that
28366 -- are not normally traversed as syntactic children.
28368 function Traverse_Rec (N : Node_Id) return Traverse_Final_Result;
28369 -- Main recursive traversal implemented as an instantiation of
28370 -- Traverse_Func over a modified Process callback.
28372 ------------------
28373 -- Process_More --
28374 ------------------
28376 function Process_More (N : Node_Id) return Traverse_Result is
28378 procedure Traverse_More (N : Node_Id;
28379 Res : in out Traverse_Result);
28380 procedure Traverse_More (L : List_Id;
28381 Res : in out Traverse_Result);
28382 -- Traverse a node or list and update the traversal result to value
28383 -- Abandon when needed.
28385 -------------------
28386 -- Traverse_More --
28387 -------------------
28389 procedure Traverse_More (N : Node_Id;
28390 Res : in out Traverse_Result)
28392 begin
28393 -- Do not process any more nodes if Abandon was reached
28395 if Res = Abandon then
28396 return;
28397 end if;
28399 if Traverse_Rec (N) = Abandon then
28400 Res := Abandon;
28401 end if;
28402 end Traverse_More;
28404 procedure Traverse_More (L : List_Id;
28405 Res : in out Traverse_Result)
28407 N : Node_Id := First (L);
28409 begin
28410 -- Do not process any more nodes if Abandon was reached
28412 if Res = Abandon then
28413 return;
28414 end if;
28416 while Present (N) loop
28417 Traverse_More (N, Res);
28418 Next (N);
28419 end loop;
28420 end Traverse_More;
28422 -- Local variables
28424 Node : Node_Id;
28425 Result : Traverse_Result;
28427 -- Start of processing for Process_More
28429 begin
28430 -- Initial callback to Process. Return immediately on Skip/Abandon.
28431 -- Otherwise update the value of Node for further processing of
28432 -- non-syntactic children.
28434 Result := Process (N);
28436 case Result is
28437 when OK => Node := N;
28438 when OK_Orig => Node := Original_Node (N);
28439 when Skip => return Skip;
28440 when Abandon => return Abandon;
28441 end case;
28443 -- Process the relevant semantic children which are a logical part of
28444 -- the AST under this node before returning for the processing of
28445 -- syntactic children.
28447 -- Start with all non-syntactic lists of action nodes
28449 case Nkind (Node) is
28450 when N_Component_Association =>
28451 Traverse_More (Loop_Actions (Node), Result);
28453 when N_Elsif_Part =>
28454 Traverse_More (Condition_Actions (Node), Result);
28456 when N_Short_Circuit =>
28457 Traverse_More (Actions (Node), Result);
28459 when N_Case_Expression_Alternative =>
28460 Traverse_More (Actions (Node), Result);
28462 when N_Iterated_Component_Association =>
28463 Traverse_More (Loop_Actions (Node), Result);
28465 when N_Iterated_Element_Association =>
28466 Traverse_More (Loop_Actions (Node), Result);
28468 when N_Iteration_Scheme =>
28469 Traverse_More (Condition_Actions (Node), Result);
28471 when N_If_Expression =>
28472 Traverse_More (Then_Actions (Node), Result);
28473 Traverse_More (Else_Actions (Node), Result);
28475 -- Various nodes have a field Actions as a syntactic node,
28476 -- so it will be traversed in the regular syntactic traversal.
28478 when N_Compilation_Unit_Aux
28479 | N_Compound_Statement
28480 | N_Expression_With_Actions
28481 | N_Freeze_Entity
28483 null;
28485 when others =>
28486 null;
28487 end case;
28489 -- If Process_Itypes is True, process unattached nodes which come
28490 -- from Itypes. This only concerns currently ranges of scalar
28491 -- (possibly as index) types. This traversal is protected against
28492 -- looping with Processing_Itype.
28494 if Process_Itypes
28495 and then not Processing_Itype
28496 and then Nkind (Node) in N_Has_Etype
28497 and then Present (Etype (Node))
28498 and then Is_Itype (Etype (Node))
28499 then
28500 declare
28501 Typ : constant Entity_Id := Etype (Node);
28502 begin
28503 Processing_Itype := True;
28505 case Ekind (Typ) is
28506 when Scalar_Kind =>
28507 Traverse_More (Scalar_Range (Typ), Result);
28509 when Array_Kind =>
28510 declare
28511 Index : Node_Id := First_Index (Typ);
28512 Rng : Node_Id;
28513 begin
28514 while Present (Index) loop
28515 if Nkind (Index) in N_Has_Entity then
28516 Rng := Scalar_Range (Entity (Index));
28517 else
28518 Rng := Index;
28519 end if;
28521 Traverse_More (Rng, Result);
28522 Next_Index (Index);
28523 end loop;
28524 end;
28525 when others =>
28526 null;
28527 end case;
28529 Processing_Itype := False;
28530 end;
28531 end if;
28533 return Result;
28534 end Process_More;
28536 -- Define Traverse_Rec as a renaming of the instantiation, as an
28537 -- instantiation cannot complete a previous spec.
28539 function Traverse_Recursive is new Traverse_Func (Process_More);
28540 function Traverse_Rec (N : Node_Id) return Traverse_Final_Result
28541 renames Traverse_Recursive;
28543 -- Start of processing for Traverse_More_Func
28545 begin
28546 return Traverse_Rec (Node);
28547 end Traverse_More_Func;
28549 ------------------------
28550 -- Traverse_More_Proc --
28551 ------------------------
28553 procedure Traverse_More_Proc (Node : Node_Id) is
28554 function Traverse is new Traverse_More_Func (Process, Process_Itypes);
28555 Discard : Traverse_Final_Result;
28556 pragma Warnings (Off, Discard);
28557 begin
28558 Discard := Traverse (Node);
28559 end Traverse_More_Proc;
28561 ------------------------------------
28562 -- Type_Without_Stream_Operation --
28563 ------------------------------------
28565 function Type_Without_Stream_Operation
28566 (T : Entity_Id;
28567 Op : TSS_Name_Type := TSS_Null) return Entity_Id
28569 BT : constant Entity_Id := Base_Type (T);
28570 Op_Missing : Boolean;
28572 begin
28573 if not Restriction_Active (No_Default_Stream_Attributes) then
28574 return Empty;
28575 end if;
28577 if Is_Elementary_Type (T) then
28578 if Op = TSS_Null then
28579 Op_Missing :=
28580 No (TSS (BT, TSS_Stream_Read))
28581 or else No (TSS (BT, TSS_Stream_Write));
28583 else
28584 Op_Missing := No (TSS (BT, Op));
28585 end if;
28587 if Op_Missing then
28588 return T;
28589 else
28590 return Empty;
28591 end if;
28593 elsif Is_Array_Type (T) then
28594 return Type_Without_Stream_Operation (Component_Type (T), Op);
28596 elsif Is_Record_Type (T) then
28597 declare
28598 Comp : Entity_Id;
28599 C_Typ : Entity_Id;
28601 begin
28602 Comp := First_Component (T);
28603 while Present (Comp) loop
28604 C_Typ := Type_Without_Stream_Operation (Etype (Comp), Op);
28606 if Present (C_Typ) then
28607 return C_Typ;
28608 end if;
28610 Next_Component (Comp);
28611 end loop;
28613 return Empty;
28614 end;
28616 elsif Is_Private_Type (T) and then Present (Full_View (T)) then
28617 return Type_Without_Stream_Operation (Full_View (T), Op);
28618 else
28619 return Empty;
28620 end if;
28621 end Type_Without_Stream_Operation;
28623 ------------------------------
28624 -- Ultimate_Overlaid_Entity --
28625 ------------------------------
28627 function Ultimate_Overlaid_Entity (E : Entity_Id) return Entity_Id is
28628 Address : Node_Id;
28629 Alias : Entity_Id := E;
28630 Offset : Boolean;
28632 begin
28633 -- Currently this routine is only called for stand-alone objects that
28634 -- have been analysed, since the analysis of the Address aspect is often
28635 -- delayed.
28637 pragma Assert (Ekind (E) in E_Constant | E_Variable);
28639 loop
28640 Address := Address_Clause (Alias);
28641 if Present (Address) then
28642 Find_Overlaid_Entity (Address, Alias, Offset);
28643 if Present (Alias) then
28644 null;
28645 else
28646 return Empty;
28647 end if;
28648 elsif Alias = E then
28649 return Empty;
28650 else
28651 return Alias;
28652 end if;
28653 end loop;
28654 end Ultimate_Overlaid_Entity;
28656 ---------------------
28657 -- Ultimate_Prefix --
28658 ---------------------
28660 function Ultimate_Prefix (N : Node_Id) return Node_Id is
28661 Pref : Node_Id;
28663 begin
28664 Pref := N;
28665 while Nkind (Pref) in N_Explicit_Dereference
28666 | N_Indexed_Component
28667 | N_Selected_Component
28668 | N_Slice
28669 loop
28670 Pref := Prefix (Pref);
28671 end loop;
28673 return Pref;
28674 end Ultimate_Prefix;
28676 ----------------------------
28677 -- Unique_Defining_Entity --
28678 ----------------------------
28680 function Unique_Defining_Entity (N : Node_Id) return Entity_Id is
28681 begin
28682 return Unique_Entity (Defining_Entity (N));
28683 end Unique_Defining_Entity;
28685 -------------------
28686 -- Unique_Entity --
28687 -------------------
28689 function Unique_Entity (E : Entity_Id) return Entity_Id is
28690 U : Entity_Id := E;
28691 P : Node_Id;
28693 begin
28694 case Ekind (E) is
28695 when E_Constant =>
28696 if Present (Full_View (E)) then
28697 U := Full_View (E);
28698 end if;
28700 when Entry_Kind =>
28701 if Nkind (Parent (E)) = N_Entry_Body then
28702 declare
28703 Prot_Item : Entity_Id;
28704 Prot_Type : Entity_Id;
28706 begin
28707 if Ekind (E) = E_Entry then
28708 Prot_Type := Scope (E);
28710 -- Bodies of entry families are nested within an extra scope
28711 -- that contains an entry index declaration.
28713 else
28714 Prot_Type := Scope (Scope (E));
28715 end if;
28717 -- A protected type may be declared as a private type, in
28718 -- which case we need to get its full view.
28720 if Is_Private_Type (Prot_Type) then
28721 Prot_Type := Full_View (Prot_Type);
28722 end if;
28724 -- Full view may not be present on error, in which case
28725 -- return E by default.
28727 if Present (Prot_Type) then
28728 pragma Assert (Ekind (Prot_Type) = E_Protected_Type);
28730 -- Traverse the entity list of the protected type and
28731 -- locate an entry declaration which matches the entry
28732 -- body.
28734 Prot_Item := First_Entity (Prot_Type);
28735 while Present (Prot_Item) loop
28736 if Ekind (Prot_Item) in Entry_Kind
28737 and then Corresponding_Body (Parent (Prot_Item)) = E
28738 then
28739 U := Prot_Item;
28740 exit;
28741 end if;
28743 Next_Entity (Prot_Item);
28744 end loop;
28745 end if;
28746 end;
28747 end if;
28749 when Formal_Kind =>
28750 if Present (Spec_Entity (E)) then
28751 U := Spec_Entity (E);
28752 end if;
28754 when E_Package_Body =>
28755 P := Parent (E);
28757 if Nkind (P) = N_Defining_Program_Unit_Name then
28758 P := Parent (P);
28759 end if;
28761 if Nkind (P) = N_Package_Body
28762 and then Present (Corresponding_Spec (P))
28763 then
28764 U := Corresponding_Spec (P);
28766 elsif Nkind (P) = N_Package_Body_Stub
28767 and then Present (Corresponding_Spec_Of_Stub (P))
28768 then
28769 U := Corresponding_Spec_Of_Stub (P);
28770 end if;
28772 when E_Protected_Body =>
28773 P := Parent (E);
28775 if Nkind (P) = N_Protected_Body
28776 and then Present (Corresponding_Spec (P))
28777 then
28778 U := Corresponding_Spec (P);
28780 elsif Nkind (P) = N_Protected_Body_Stub
28781 and then Present (Corresponding_Spec_Of_Stub (P))
28782 then
28783 U := Corresponding_Spec_Of_Stub (P);
28785 if Is_Single_Protected_Object (U) then
28786 U := Etype (U);
28787 end if;
28788 end if;
28790 if Is_Private_Type (U) then
28791 U := Full_View (U);
28792 end if;
28794 when E_Subprogram_Body =>
28795 P := Parent (E);
28797 if Nkind (P) = N_Defining_Program_Unit_Name then
28798 P := Parent (P);
28799 end if;
28801 P := Parent (P);
28803 if Nkind (P) = N_Subprogram_Body
28804 and then Present (Corresponding_Spec (P))
28805 then
28806 U := Corresponding_Spec (P);
28808 elsif Nkind (P) = N_Subprogram_Body_Stub
28809 and then Present (Corresponding_Spec_Of_Stub (P))
28810 then
28811 U := Corresponding_Spec_Of_Stub (P);
28813 elsif Nkind (P) = N_Subprogram_Renaming_Declaration then
28814 U := Corresponding_Spec (P);
28815 end if;
28817 when E_Task_Body =>
28818 P := Parent (E);
28820 if Nkind (P) = N_Task_Body
28821 and then Present (Corresponding_Spec (P))
28822 then
28823 U := Corresponding_Spec (P);
28825 elsif Nkind (P) = N_Task_Body_Stub
28826 and then Present (Corresponding_Spec_Of_Stub (P))
28827 then
28828 U := Corresponding_Spec_Of_Stub (P);
28830 if Is_Single_Task_Object (U) then
28831 U := Etype (U);
28832 end if;
28833 end if;
28835 if Is_Private_Type (U) then
28836 U := Full_View (U);
28837 end if;
28839 when Type_Kind =>
28840 if Present (Full_View (E)) then
28841 U := Full_View (E);
28842 end if;
28844 when others =>
28845 null;
28846 end case;
28848 return U;
28849 end Unique_Entity;
28851 -----------------
28852 -- Unique_Name --
28853 -----------------
28855 function Unique_Name (E : Entity_Id) return String is
28857 -- Local subprograms
28859 function Add_Homonym_Suffix (E : Entity_Id) return String;
28861 function This_Name return String;
28863 ------------------------
28864 -- Add_Homonym_Suffix --
28865 ------------------------
28867 function Add_Homonym_Suffix (E : Entity_Id) return String is
28869 -- Names in E_Subprogram_Body or E_Package_Body entities are not
28870 -- reliable, as they may not include the overloading suffix.
28871 -- Instead, when looking for the name of E or one of its enclosing
28872 -- scope, we get the name of the corresponding Unique_Entity.
28874 U : constant Entity_Id := Unique_Entity (E);
28875 Nam : constant String := Get_Name_String (Chars (U));
28877 begin
28878 -- If E has homonyms but is not fully qualified, as done in
28879 -- GNATprove mode, append the homonym number on the fly. Strip the
28880 -- leading space character in the image of natural numbers. Also do
28881 -- not print the homonym value of 1.
28883 if Has_Homonym (U) then
28884 declare
28885 N : constant Pos := Homonym_Number (U);
28886 S : constant String := N'Img;
28887 begin
28888 if N > 1 then
28889 return Nam & "__" & S (2 .. S'Last);
28890 end if;
28891 end;
28892 end if;
28894 return Nam;
28895 end Add_Homonym_Suffix;
28897 ---------------
28898 -- This_Name --
28899 ---------------
28901 function This_Name return String is
28902 begin
28903 return Add_Homonym_Suffix (E);
28904 end This_Name;
28906 -- Local variables
28908 U : constant Entity_Id := Unique_Entity (E);
28910 -- Start of processing for Unique_Name
28912 begin
28913 if E = Standard_Standard
28914 or else Has_Fully_Qualified_Name (E)
28915 then
28916 return This_Name;
28918 elsif Ekind (E) = E_Enumeration_Literal then
28919 return Unique_Name (Etype (E)) & "__" & This_Name;
28921 else
28922 declare
28923 S : constant Entity_Id := Scope (U);
28924 pragma Assert (Present (S));
28926 begin
28927 -- Prefix names of predefined types with standard__, but leave
28928 -- names of user-defined packages and subprograms without prefix
28929 -- (even if technically they are nested in the Standard package).
28931 if S = Standard_Standard then
28932 if Ekind (U) = E_Package or else Is_Subprogram (U) then
28933 return This_Name;
28934 else
28935 return Unique_Name (S) & "__" & This_Name;
28936 end if;
28938 -- For intances of generic subprograms use the name of the related
28939 -- instance and skip the scope of its wrapper package.
28941 elsif Is_Wrapper_Package (S) then
28942 pragma Assert (Scope (S) = Scope (Related_Instance (S)));
28943 -- Wrapper package and the instantiation are in the same scope
28945 declare
28946 Related_Name : constant String :=
28947 Add_Homonym_Suffix (Related_Instance (S));
28948 Enclosing_Name : constant String :=
28949 Unique_Name (Scope (S)) & "__" & Related_Name;
28951 begin
28952 if Is_Subprogram (U)
28953 and then not Is_Generic_Actual_Subprogram (U)
28954 then
28955 return Enclosing_Name;
28956 else
28957 return Enclosing_Name & "__" & This_Name;
28958 end if;
28959 end;
28961 elsif Is_Child_Unit (U) then
28962 return Child_Prefix & Unique_Name (S) & "__" & This_Name;
28963 else
28964 return Unique_Name (S) & "__" & This_Name;
28965 end if;
28966 end;
28967 end if;
28968 end Unique_Name;
28970 ---------------------
28971 -- Unit_Is_Visible --
28972 ---------------------
28974 function Unit_Is_Visible (U : Entity_Id) return Boolean is
28975 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
28976 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
28978 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
28979 -- For a child unit, check whether unit appears in a with_clause
28980 -- of a parent.
28982 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
28983 -- Scan the context clause of one compilation unit looking for a
28984 -- with_clause for the unit in question.
28986 ----------------------------
28987 -- Unit_In_Parent_Context --
28988 ----------------------------
28990 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
28991 begin
28992 if Unit_In_Context (Par_Unit) then
28993 return True;
28995 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
28996 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
28998 else
28999 return False;
29000 end if;
29001 end Unit_In_Parent_Context;
29003 ---------------------
29004 -- Unit_In_Context --
29005 ---------------------
29007 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
29008 Clause : Node_Id;
29010 begin
29011 Clause := First (Context_Items (Comp_Unit));
29012 while Present (Clause) loop
29013 if Nkind (Clause) = N_With_Clause then
29014 if Library_Unit (Clause) = U then
29015 return True;
29017 -- The with_clause may denote a renaming of the unit we are
29018 -- looking for, eg. Text_IO which renames Ada.Text_IO.
29020 elsif
29021 Renamed_Entity (Entity (Name (Clause))) =
29022 Defining_Entity (Unit (U))
29023 then
29024 return True;
29025 end if;
29026 end if;
29028 Next (Clause);
29029 end loop;
29031 return False;
29032 end Unit_In_Context;
29034 -- Start of processing for Unit_Is_Visible
29036 begin
29037 -- The currrent unit is directly visible
29039 if Curr = U then
29040 return True;
29042 elsif Unit_In_Context (Curr) then
29043 return True;
29045 -- If the current unit is a body, check the context of the spec
29047 elsif Nkind (Unit (Curr)) = N_Package_Body
29048 or else
29049 (Nkind (Unit (Curr)) = N_Subprogram_Body
29050 and then not Acts_As_Spec (Unit (Curr)))
29051 then
29052 if Unit_In_Context (Library_Unit (Curr)) then
29053 return True;
29054 end if;
29055 end if;
29057 -- If the spec is a child unit, examine the parents
29059 if Is_Child_Unit (Curr_Entity) then
29060 if Nkind (Unit (Curr)) in N_Unit_Body then
29061 return
29062 Unit_In_Parent_Context
29063 (Parent_Spec (Unit (Library_Unit (Curr))));
29064 else
29065 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
29066 end if;
29068 else
29069 return False;
29070 end if;
29071 end Unit_Is_Visible;
29073 ------------------------------
29074 -- Universal_Interpretation --
29075 ------------------------------
29077 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
29078 Index : Interp_Index;
29079 It : Interp;
29081 begin
29082 -- The argument may be a formal parameter of an operator or subprogram
29083 -- with multiple interpretations, or else an expression for an actual.
29085 if Nkind (Opnd) = N_Defining_Identifier
29086 or else not Is_Overloaded (Opnd)
29087 then
29088 if Is_Universal_Numeric_Type (Etype (Opnd)) then
29089 return Etype (Opnd);
29090 else
29091 return Empty;
29092 end if;
29094 else
29095 Get_First_Interp (Opnd, Index, It);
29096 while Present (It.Typ) loop
29097 if Is_Universal_Numeric_Type (It.Typ) then
29098 return It.Typ;
29099 end if;
29101 Get_Next_Interp (Index, It);
29102 end loop;
29104 return Empty;
29105 end if;
29106 end Universal_Interpretation;
29108 ---------------
29109 -- Unqualify --
29110 ---------------
29112 function Unqualify (Expr : Node_Id) return Node_Id is
29113 begin
29114 -- Recurse to handle unlikely case of multiple levels of qualification
29116 if Nkind (Expr) = N_Qualified_Expression then
29117 return Unqualify (Expression (Expr));
29119 -- Normal case, not a qualified expression
29121 else
29122 return Expr;
29123 end if;
29124 end Unqualify;
29126 -----------------
29127 -- Unqual_Conv --
29128 -----------------
29130 function Unqual_Conv (Expr : Node_Id) return Node_Id is
29131 begin
29132 -- Recurse to handle unlikely case of multiple levels of qualification
29133 -- and/or conversion.
29135 if Nkind (Expr) in N_Qualified_Expression
29136 | N_Type_Conversion
29137 | N_Unchecked_Type_Conversion
29138 then
29139 return Unqual_Conv (Expression (Expr));
29141 -- Normal case, not a qualified expression
29143 else
29144 return Expr;
29145 end if;
29146 end Unqual_Conv;
29148 --------------------
29149 -- Validated_View --
29150 --------------------
29152 function Validated_View (Typ : Entity_Id) return Entity_Id is
29153 begin
29154 -- Scalar types can be always validated. In fast, switiching to the base
29155 -- type would drop the range constraints and force validation to use a
29156 -- larger type than necessary.
29158 if Is_Scalar_Type (Typ) then
29159 return Typ;
29161 -- Array types can be validated even when they are derived, because
29162 -- validation only requires their bounds and component types to be
29163 -- accessible. In fact, switching to the parent type would pollute
29164 -- expansion of attribute Valid_Scalars with unnecessary conversion
29165 -- that might not be eliminated by the frontend.
29167 elsif Is_Array_Type (Typ) then
29168 return Typ;
29170 -- For other types, in particular for record subtypes, we switch to the
29171 -- base type.
29173 elsif not Is_Base_Type (Typ) then
29174 return Validated_View (Base_Type (Typ));
29176 -- Obtain the full view of the input type by stripping away concurrency,
29177 -- derivations, and privacy.
29179 elsif Is_Concurrent_Type (Typ) then
29180 if Present (Corresponding_Record_Type (Typ)) then
29181 return Corresponding_Record_Type (Typ);
29182 else
29183 return Typ;
29184 end if;
29186 elsif Is_Derived_Type (Typ) then
29187 return Validated_View (Etype (Typ));
29189 elsif Is_Private_Type (Typ) then
29190 if Present (Underlying_Full_View (Typ)) then
29191 return Validated_View (Underlying_Full_View (Typ));
29193 elsif Present (Full_View (Typ)) then
29194 return Validated_View (Full_View (Typ));
29195 else
29196 return Typ;
29197 end if;
29199 else
29200 return Typ;
29201 end if;
29202 end Validated_View;
29204 -----------------------
29205 -- Visible_Ancestors --
29206 -----------------------
29208 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
29209 List_1 : Elist_Id;
29210 List_2 : Elist_Id;
29211 Elmt : Elmt_Id;
29213 begin
29214 pragma Assert (Is_Record_Type (Typ) and then Is_Tagged_Type (Typ));
29216 -- Collect all the parents and progenitors of Typ. If the full-view of
29217 -- private parents and progenitors is available then it is used to
29218 -- generate the list of visible ancestors; otherwise their partial
29219 -- view is added to the resulting list.
29221 Collect_Parents
29222 (T => Typ,
29223 List => List_1,
29224 Use_Full_View => True);
29226 Collect_Interfaces
29227 (T => Typ,
29228 Ifaces_List => List_2,
29229 Exclude_Parents => True,
29230 Use_Full_View => True);
29232 -- Join the two lists. Avoid duplications because an interface may
29233 -- simultaneously be parent and progenitor of a type.
29235 Elmt := First_Elmt (List_2);
29236 while Present (Elmt) loop
29237 Append_Unique_Elmt (Node (Elmt), List_1);
29238 Next_Elmt (Elmt);
29239 end loop;
29241 return List_1;
29242 end Visible_Ancestors;
29244 ---------------------------
29245 -- Warn_On_Hiding_Entity --
29246 ---------------------------
29248 procedure Warn_On_Hiding_Entity
29249 (N : Node_Id;
29250 Hidden, Visible : Entity_Id;
29251 On_Use_Clause : Boolean)
29253 begin
29254 -- Don't warn for record components since they always have a well
29255 -- defined scope which does not confuse other uses. Note that in
29256 -- some cases, Ekind has not been set yet.
29258 if Ekind (Hidden) /= E_Component
29259 and then Ekind (Hidden) /= E_Discriminant
29260 and then Nkind (Parent (Hidden)) /= N_Component_Declaration
29261 and then Ekind (Visible) /= E_Component
29262 and then Ekind (Visible) /= E_Discriminant
29263 and then Nkind (Parent (Visible)) /= N_Component_Declaration
29265 -- Don't warn for one character variables. It is too common to use
29266 -- such variables as locals and will just cause too many false hits.
29268 and then Length_Of_Name (Chars (Hidden)) /= 1
29270 -- Don't warn for non-source entities
29272 and then Comes_From_Source (Hidden)
29273 and then Comes_From_Source (Visible)
29275 -- Don't warn within a generic instantiation
29277 and then not In_Instance
29279 -- Don't warn unless entity in question is in extended main source
29281 and then In_Extended_Main_Source_Unit (Visible)
29283 -- Finally, in the case of a declaration, the hidden entity must
29284 -- be either immediately visible or use visible (i.e. from a used
29285 -- package). In the case of a use clause, the visible entity must
29286 -- be immediately visible.
29288 and then
29289 (if On_Use_Clause then
29290 Is_Immediately_Visible (Visible)
29291 else
29292 (Is_Immediately_Visible (Hidden)
29293 or else
29294 Is_Potentially_Use_Visible (Hidden)))
29295 then
29296 if On_Use_Clause then
29297 Error_Msg_Sloc := Sloc (Visible);
29298 Error_Msg_NE ("visible declaration of&# hides homonym "
29299 & "from use clause?h?", N, Hidden);
29300 else
29301 Error_Msg_Sloc := Sloc (Hidden);
29302 Error_Msg_NE ("declaration hides &#?h?", N, Visible);
29303 end if;
29304 end if;
29305 end Warn_On_Hiding_Entity;
29307 ----------------------
29308 -- Within_Init_Proc --
29309 ----------------------
29311 function Within_Init_Proc return Boolean is
29312 S : Entity_Id;
29314 begin
29315 S := Current_Scope;
29316 while not Is_Overloadable (S) loop
29317 if S = Standard_Standard then
29318 return False;
29319 else
29320 S := Scope (S);
29321 end if;
29322 end loop;
29324 return Is_Init_Proc (S);
29325 end Within_Init_Proc;
29327 ---------------------------
29328 -- Within_Protected_Type --
29329 ---------------------------
29331 function Within_Protected_Type (E : Entity_Id) return Boolean is
29332 Scop : Entity_Id := Scope (E);
29334 begin
29335 while Present (Scop) loop
29336 if Ekind (Scop) = E_Protected_Type then
29337 return True;
29338 end if;
29340 Scop := Scope (Scop);
29341 end loop;
29343 return False;
29344 end Within_Protected_Type;
29346 ------------------
29347 -- Within_Scope --
29348 ------------------
29350 function Within_Scope (E : Entity_Id; S : Entity_Id) return Boolean is
29351 begin
29352 return Scope_Within_Or_Same (Scope (E), S);
29353 end Within_Scope;
29355 ----------------
29356 -- Wrong_Type --
29357 ----------------
29359 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
29360 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
29361 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
29363 Err_Msg_Exp_Typ : Entity_Id := Expected_Type;
29364 -- Type entity used when printing errors concerning the expected type
29366 Matching_Field : Entity_Id;
29367 -- Entity to give a more precise suggestion on how to write a one-
29368 -- element positional aggregate.
29370 function Has_One_Matching_Field return Boolean;
29371 -- Determines if Expec_Type is a record type with a single component or
29372 -- discriminant whose type matches the found type or is one dimensional
29373 -- array whose component type matches the found type. In the case of
29374 -- one discriminant, we ignore the variant parts. That's not accurate,
29375 -- but good enough for the warning.
29377 ----------------------------
29378 -- Has_One_Matching_Field --
29379 ----------------------------
29381 function Has_One_Matching_Field return Boolean is
29382 E : Entity_Id;
29384 begin
29385 Matching_Field := Empty;
29387 if Is_Array_Type (Expec_Type)
29388 and then Number_Dimensions (Expec_Type) = 1
29389 and then Covers (Etype (Component_Type (Expec_Type)), Found_Type)
29390 then
29391 -- Use type name if available. This excludes multidimensional
29392 -- arrays and anonymous arrays.
29394 if Comes_From_Source (Expec_Type) then
29395 Matching_Field := Expec_Type;
29397 -- For an assignment, use name of target
29399 elsif Nkind (Parent (Expr)) = N_Assignment_Statement
29400 and then Is_Entity_Name (Name (Parent (Expr)))
29401 then
29402 Matching_Field := Entity (Name (Parent (Expr)));
29403 end if;
29405 return True;
29407 elsif not Is_Record_Type (Expec_Type) then
29408 return False;
29410 else
29411 E := First_Entity (Expec_Type);
29412 loop
29413 if No (E) then
29414 return False;
29416 elsif Ekind (E) not in E_Discriminant | E_Component
29417 or else Chars (E) in Name_uTag | Name_uParent
29418 then
29419 Next_Entity (E);
29421 else
29422 exit;
29423 end if;
29424 end loop;
29426 if not Covers (Etype (E), Found_Type) then
29427 return False;
29429 elsif Present (Next_Entity (E))
29430 and then (Ekind (E) = E_Component
29431 or else Ekind (Next_Entity (E)) = E_Discriminant)
29432 then
29433 return False;
29435 else
29436 Matching_Field := E;
29437 return True;
29438 end if;
29439 end if;
29440 end Has_One_Matching_Field;
29442 -- Start of processing for Wrong_Type
29444 begin
29445 -- Don't output message if either type is Any_Type, or if a message
29446 -- has already been posted for this node. We need to do the latter
29447 -- check explicitly (it is ordinarily done in Errout), because we
29448 -- are using ! to force the output of the error messages.
29450 if Expec_Type = Any_Type
29451 or else Found_Type = Any_Type
29452 or else Error_Posted (Expr)
29453 then
29454 return;
29456 -- If one of the types is a Taft-Amendment type and the other it its
29457 -- completion, it must be an illegal use of a TAT in the spec, for
29458 -- which an error was already emitted. Avoid cascaded errors.
29460 elsif Is_Incomplete_Type (Expec_Type)
29461 and then Has_Completion_In_Body (Expec_Type)
29462 and then Full_View (Expec_Type) = Etype (Expr)
29463 then
29464 return;
29466 elsif Is_Incomplete_Type (Etype (Expr))
29467 and then Has_Completion_In_Body (Etype (Expr))
29468 and then Full_View (Etype (Expr)) = Expec_Type
29469 then
29470 return;
29472 -- In an instance, there is an ongoing problem with completion of
29473 -- types derived from private types. Their structure is what Gigi
29474 -- expects, but the Etype is the parent type rather than the derived
29475 -- private type itself. Do not flag error in this case. The private
29476 -- completion is an entity without a parent, like an Itype. Similarly,
29477 -- full and partial views may be incorrect in the instance.
29478 -- There is no simple way to insure that it is consistent ???
29480 -- A similar view discrepancy can happen in an inlined body, for the
29481 -- same reason: inserted body may be outside of the original package
29482 -- and only partial views are visible at the point of insertion.
29484 -- If In_Generic_Actual (Expr) is True then we cannot assume that
29485 -- the successful semantic analysis of the generic guarantees anything
29486 -- useful about type checking of this instance, so we ignore
29487 -- In_Instance in that case. There may be cases where this is not
29488 -- right (the symptom would probably be rejecting something
29489 -- that ought to be accepted) but we don't currently have any
29490 -- concrete examples of this.
29492 elsif (In_Instance and then not In_Generic_Actual (Expr))
29493 or else In_Inlined_Body
29494 then
29495 if Etype (Etype (Expr)) = Etype (Expected_Type)
29496 and then
29497 (Has_Private_Declaration (Expected_Type)
29498 or else Has_Private_Declaration (Etype (Expr)))
29499 and then No (Parent (Expected_Type))
29500 then
29501 return;
29503 elsif Nkind (Parent (Expr)) = N_Qualified_Expression
29504 and then Entity (Subtype_Mark (Parent (Expr))) = Expected_Type
29505 then
29506 return;
29508 elsif Is_Private_Type (Expected_Type)
29509 and then Present (Full_View (Expected_Type))
29510 and then Covers (Full_View (Expected_Type), Etype (Expr))
29511 then
29512 return;
29514 -- Conversely, type of expression may be the private one
29516 elsif Is_Private_Type (Base_Type (Etype (Expr)))
29517 and then Full_View (Base_Type (Etype (Expr))) = Expected_Type
29518 then
29519 return;
29520 end if;
29521 end if;
29523 -- Avoid printing internally generated subtypes in error messages and
29524 -- instead use the corresponding first subtype in such cases.
29526 if not Comes_From_Source (Err_Msg_Exp_Typ)
29527 or else not Comes_From_Source (Declaration_Node (Err_Msg_Exp_Typ))
29528 then
29529 Err_Msg_Exp_Typ := First_Subtype (Err_Msg_Exp_Typ);
29530 end if;
29532 -- An interesting special check. If the expression is parenthesized
29533 -- and its type corresponds to the type of the sole component of the
29534 -- expected record type, or to the component type of the expected one
29535 -- dimensional array type, then assume we have a bad aggregate attempt.
29537 if Nkind (Expr) in N_Subexpr
29538 and then Paren_Count (Expr) /= 0
29539 and then Has_One_Matching_Field
29540 then
29541 Error_Msg_N ("positional aggregate cannot have one component", Expr);
29543 if Present (Matching_Field) then
29544 if Is_Array_Type (Expec_Type) then
29545 Error_Msg_NE
29546 ("\write instead `&''First ='> ...`", Expr, Matching_Field);
29547 else
29548 Error_Msg_NE
29549 ("\write instead `& ='> ...`", Expr, Matching_Field);
29550 end if;
29551 end if;
29553 -- Another special check, if we are looking for a pool-specific access
29554 -- type and we found an E_Access_Attribute_Type, then we have the case
29555 -- of an Access attribute being used in a context which needs a pool-
29556 -- specific type, which is never allowed. The one extra check we make
29557 -- is that the expected designated type covers the Found_Type.
29559 elsif Is_Access_Type (Expec_Type)
29560 and then Ekind (Found_Type) = E_Access_Attribute_Type
29561 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
29562 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
29563 and then Covers
29564 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
29565 then
29566 Error_Msg_N
29567 ("result must be general access type!", Expr);
29568 Error_Msg_NE -- CODEFIX
29569 ("\add ALL to }!", Expr, Err_Msg_Exp_Typ);
29571 -- Another special check, if the expected type is an integer type,
29572 -- but the expression is of type System.Address, and the parent is
29573 -- an addition or subtraction operation whose left operand is the
29574 -- expression in question and whose right operand is of an integral
29575 -- type, then this is an attempt at address arithmetic, so give
29576 -- appropriate message.
29578 elsif Is_Integer_Type (Expec_Type)
29579 and then Is_RTE (Found_Type, RE_Address)
29580 and then Nkind (Parent (Expr)) in N_Op_Add | N_Op_Subtract
29581 and then Expr = Left_Opnd (Parent (Expr))
29582 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
29583 then
29584 Error_Msg_N
29585 ("address arithmetic not predefined in package System",
29586 Parent (Expr));
29587 Error_Msg_N
29588 ("\possible missing with/use of System.Storage_Elements",
29589 Parent (Expr));
29590 return;
29592 -- If the expected type is an anonymous access type, as for access
29593 -- parameters and discriminants, the error is on the designated types.
29595 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
29596 if Comes_From_Source (Expec_Type) then
29597 Error_Msg_NE ("expected}!", Expr, Expec_Type);
29598 else
29599 Error_Msg_NE
29600 ("expected an access type with designated}",
29601 Expr, Designated_Type (Expec_Type));
29602 end if;
29604 if Is_Access_Type (Found_Type)
29605 and then not Comes_From_Source (Found_Type)
29606 then
29607 Error_Msg_NE
29608 ("\\found an access type with designated}!",
29609 Expr, Designated_Type (Found_Type));
29610 else
29611 if From_Limited_With (Found_Type) then
29612 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
29613 Error_Msg_Qual_Level := 99;
29614 Error_Msg_NE -- CODEFIX
29615 ("\\missing `WITH &;", Expr, Scope (Found_Type));
29616 Error_Msg_Qual_Level := 0;
29617 else
29618 Error_Msg_NE ("found}!", Expr, Found_Type);
29619 end if;
29620 end if;
29622 -- Normal case of one type found, some other type expected
29624 else
29625 -- If the names of the two types are the same, see if some number
29626 -- of levels of qualification will help. Don't try more than three
29627 -- levels, and if we get to standard, it's no use (and probably
29628 -- represents an error in the compiler) Also do not bother with
29629 -- internal scope names.
29631 declare
29632 Expec_Scope : Entity_Id;
29633 Found_Scope : Entity_Id;
29635 begin
29636 Expec_Scope := Expec_Type;
29637 Found_Scope := Found_Type;
29639 for Levels in Nat range 0 .. 3 loop
29640 if Chars (Expec_Scope) /= Chars (Found_Scope) then
29641 Error_Msg_Qual_Level := Levels;
29642 exit;
29643 end if;
29645 Expec_Scope := Scope (Expec_Scope);
29646 Found_Scope := Scope (Found_Scope);
29648 exit when Expec_Scope = Standard_Standard
29649 or else Found_Scope = Standard_Standard
29650 or else not Comes_From_Source (Expec_Scope)
29651 or else not Comes_From_Source (Found_Scope);
29652 end loop;
29653 end;
29655 if Is_Record_Type (Expec_Type)
29656 and then Present (Corresponding_Remote_Type (Expec_Type))
29657 then
29658 Error_Msg_NE ("expected}!", Expr,
29659 Corresponding_Remote_Type (Expec_Type));
29660 else
29661 Error_Msg_NE ("expected}!", Expr, Err_Msg_Exp_Typ);
29662 end if;
29664 if Is_Entity_Name (Expr)
29665 and then Is_Package_Or_Generic_Package (Entity (Expr))
29666 then
29667 Error_Msg_N ("\\found package name!", Expr);
29669 elsif Is_Entity_Name (Expr)
29670 and then Ekind (Entity (Expr)) in E_Procedure | E_Generic_Procedure
29671 then
29672 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
29673 Error_Msg_N
29674 ("found procedure name, possibly missing Access attribute!",
29675 Expr);
29676 else
29677 Error_Msg_N
29678 ("\\found procedure name instead of function!", Expr);
29679 end if;
29681 elsif Nkind (Expr) = N_Function_Call
29682 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
29683 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
29684 and then No (Parameter_Associations (Expr))
29685 then
29686 Error_Msg_N
29687 ("found function name, possibly missing Access attribute!",
29688 Expr);
29690 -- Catch common error: a prefix or infix operator which is not
29691 -- directly visible because the type isn't.
29693 elsif Nkind (Expr) in N_Op
29694 and then Is_Overloaded (Expr)
29695 and then not Is_Immediately_Visible (Expec_Type)
29696 and then not Is_Potentially_Use_Visible (Expec_Type)
29697 and then not In_Use (Expec_Type)
29698 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
29699 then
29700 Error_Msg_N
29701 ("operator of the type is not directly visible!", Expr);
29703 elsif Ekind (Found_Type) = E_Void
29704 and then Present (Parent (Found_Type))
29705 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
29706 then
29707 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
29709 else
29710 Error_Msg_NE ("\\found}!", Expr, Found_Type);
29711 end if;
29713 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
29714 -- of the same modular type, and (M1 and M2) = 0 was intended.
29716 if Expec_Type = Standard_Boolean
29717 and then Is_Modular_Integer_Type (Found_Type)
29718 and then Nkind (Parent (Expr)) in N_Op_And | N_Op_Or | N_Op_Xor
29719 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
29720 then
29721 declare
29722 Op : constant Node_Id := Right_Opnd (Parent (Expr));
29723 L : constant Node_Id := Left_Opnd (Op);
29724 R : constant Node_Id := Right_Opnd (Op);
29726 begin
29727 -- The case for the message is when the left operand of the
29728 -- comparison is the same modular type, or when it is an
29729 -- integer literal (or other universal integer expression),
29730 -- which would have been typed as the modular type if the
29731 -- parens had been there.
29733 if (Etype (L) = Found_Type
29734 or else
29735 Etype (L) = Universal_Integer)
29736 and then Is_Integer_Type (Etype (R))
29737 then
29738 Error_Msg_N
29739 ("\\possible missing parens for modular operation", Expr);
29740 end if;
29741 end;
29742 end if;
29744 -- Reset error message qualification indication
29746 Error_Msg_Qual_Level := 0;
29747 end if;
29748 end Wrong_Type;
29750 --------------------------------
29751 -- Yields_Synchronized_Object --
29752 --------------------------------
29754 function Yields_Synchronized_Object (Typ : Entity_Id) return Boolean is
29755 Has_Sync_Comp : Boolean := False;
29756 Id : Entity_Id;
29758 begin
29759 -- An array type yields a synchronized object if its component type
29760 -- yields a synchronized object.
29762 if Is_Array_Type (Typ) then
29763 return Yields_Synchronized_Object (Component_Type (Typ));
29765 -- A descendant of type Ada.Synchronous_Task_Control.Suspension_Object
29766 -- yields a synchronized object by default.
29768 elsif Is_Descendant_Of_Suspension_Object (Typ) then
29769 return True;
29771 -- A protected type yields a synchronized object by default
29773 elsif Is_Protected_Type (Typ) then
29774 return True;
29776 -- A record type or type extension yields a synchronized object when its
29777 -- discriminants (if any) lack default values and all components are of
29778 -- a type that yields a synchronized object.
29780 elsif Is_Record_Type (Typ) then
29782 -- Inspect all entities defined in the scope of the type, looking for
29783 -- components of a type that does not yield a synchronized object or
29784 -- for discriminants with default values.
29786 Id := First_Entity (Typ);
29787 while Present (Id) loop
29788 if Comes_From_Source (Id) then
29789 if Ekind (Id) = E_Component then
29790 if Yields_Synchronized_Object (Etype (Id)) then
29791 Has_Sync_Comp := True;
29793 -- The component does not yield a synchronized object
29795 else
29796 return False;
29797 end if;
29799 elsif Ekind (Id) = E_Discriminant
29800 and then Present (Expression (Parent (Id)))
29801 then
29802 return False;
29803 end if;
29804 end if;
29806 Next_Entity (Id);
29807 end loop;
29809 -- Ensure that the parent type of a type extension yields a
29810 -- synchronized object.
29812 if Etype (Typ) /= Typ
29813 and then not Is_Private_Type (Etype (Typ))
29814 and then not Yields_Synchronized_Object (Etype (Typ))
29815 then
29816 return False;
29817 end if;
29819 -- If we get here, then all discriminants lack default values and all
29820 -- components are of a type that yields a synchronized object.
29822 return Has_Sync_Comp;
29824 -- A synchronized interface type yields a synchronized object by default
29826 elsif Is_Synchronized_Interface (Typ) then
29827 return True;
29829 -- A task type yields a synchronized object by default
29831 elsif Is_Task_Type (Typ) then
29832 return True;
29834 -- A private type yields a synchronized object if its underlying type
29835 -- does.
29837 elsif Is_Private_Type (Typ)
29838 and then Present (Underlying_Type (Typ))
29839 then
29840 return Yields_Synchronized_Object (Underlying_Type (Typ));
29842 -- Otherwise the type does not yield a synchronized object
29844 else
29845 return False;
29846 end if;
29847 end Yields_Synchronized_Object;
29849 ---------------------------
29850 -- Yields_Universal_Type --
29851 ---------------------------
29853 function Yields_Universal_Type (N : Node_Id) return Boolean is
29854 begin
29855 -- Integer and real literals are of a universal type
29857 if Nkind (N) in N_Integer_Literal | N_Real_Literal then
29858 return True;
29860 -- The values of certain attributes are of a universal type
29862 elsif Nkind (N) = N_Attribute_Reference then
29863 return
29864 Universal_Type_Attribute (Get_Attribute_Id (Attribute_Name (N)));
29866 -- ??? There are possibly other cases to consider
29868 else
29869 return False;
29870 end if;
29871 end Yields_Universal_Type;
29873 package body Interval_Lists is
29875 procedure Check_Consistency (Intervals : Discrete_Interval_List);
29876 -- Check that list is sorted, lacks null intervals, and has gaps
29877 -- between intervals.
29879 function Chosen_Interval (Choice : Node_Id) return Discrete_Interval;
29880 -- Given an element of a Discrete_Choices list, a
29881 -- Static_Discrete_Predicate list, or an Others_Discrete_Choices
29882 -- list (but not an N_Others_Choice node) return the corresponding
29883 -- interval. If an element that does not represent a single
29884 -- contiguous interval due to a static predicate (or which
29885 -- represents a single contiguous interval whose bounds depend on
29886 -- a static predicate) is encountered, then that is an error on the
29887 -- part of whoever built the list in question.
29889 function In_Interval
29890 (Value : Uint; Interval : Discrete_Interval) return Boolean;
29891 -- Does the given value lie within the given interval?
29893 procedure Normalize_Interval_List
29894 (List : in out Discrete_Interval_List; Last : out Nat);
29895 -- Perform sorting and merging as required by Check_Consistency
29897 -------------------------
29898 -- Aggregate_Intervals --
29899 -------------------------
29901 function Aggregate_Intervals (N : Node_Id) return Discrete_Interval_List
29903 pragma Assert (Nkind (N) = N_Aggregate
29904 and then Is_Array_Type (Etype (N)));
29906 function Unmerged_Intervals_Count return Nat;
29907 -- Count the number of intervals given in the aggregate N; the others
29908 -- choice (if present) is not taken into account.
29910 ------------------------------
29911 -- Unmerged_Intervals_Count --
29912 ------------------------------
29914 function Unmerged_Intervals_Count return Nat is
29915 Count : Nat := 0;
29916 Choice : Node_Id;
29917 Comp : Node_Id;
29918 begin
29919 Comp := First (Component_Associations (N));
29920 while Present (Comp) loop
29921 Choice := First (Choices (Comp));
29923 while Present (Choice) loop
29924 if Nkind (Choice) /= N_Others_Choice then
29925 Count := Count + 1;
29926 end if;
29928 Next (Choice);
29929 end loop;
29931 Next (Comp);
29932 end loop;
29934 return Count;
29935 end Unmerged_Intervals_Count;
29937 -- Local variables
29939 Comp : Node_Id;
29940 Max_I : constant Nat := Unmerged_Intervals_Count;
29941 Intervals : Discrete_Interval_List (1 .. Max_I);
29942 Num_I : Nat := 0;
29944 -- Start of processing for Aggregate_Intervals
29946 begin
29947 -- No action needed if there are no intervals
29949 if Max_I = 0 then
29950 return Intervals;
29951 end if;
29953 -- Internally store all the unsorted intervals
29955 Comp := First (Component_Associations (N));
29956 while Present (Comp) loop
29957 declare
29958 Choice_Intervals : constant Discrete_Interval_List
29959 := Choice_List_Intervals (Choices (Comp));
29960 begin
29961 for J in Choice_Intervals'Range loop
29962 Num_I := Num_I + 1;
29963 Intervals (Num_I) := Choice_Intervals (J);
29964 end loop;
29965 end;
29967 Next (Comp);
29968 end loop;
29970 -- Normalize the lists sorting and merging the intervals
29972 declare
29973 Aggr_Intervals : Discrete_Interval_List (1 .. Num_I)
29974 := Intervals (1 .. Num_I);
29975 begin
29976 Normalize_Interval_List (Aggr_Intervals, Num_I);
29977 Check_Consistency (Aggr_Intervals (1 .. Num_I));
29978 return Aggr_Intervals (1 .. Num_I);
29979 end;
29980 end Aggregate_Intervals;
29982 ------------------------
29983 -- Check_Consistency --
29984 ------------------------
29986 procedure Check_Consistency (Intervals : Discrete_Interval_List) is
29987 begin
29988 if Serious_Errors_Detected > 0 then
29989 return;
29990 end if;
29992 -- low bound is 1 and high bound equals length
29993 pragma Assert (Intervals'First = 1 and Intervals'Last >= 0);
29994 for Idx in Intervals'Range loop
29995 -- each interval is non-null
29996 pragma Assert (Intervals (Idx).Low <= Intervals (Idx).High);
29997 if Idx /= Intervals'First then
29998 -- intervals are sorted with non-empty gaps between them
29999 pragma Assert
30000 (Intervals (Idx - 1).High < (Intervals (Idx).Low - 1));
30001 null;
30002 end if;
30003 end loop;
30004 end Check_Consistency;
30006 ---------------------------
30007 -- Choice_List_Intervals --
30008 ---------------------------
30010 function Choice_List_Intervals
30011 (Discrete_Choices : List_Id) return Discrete_Interval_List
30013 function Unmerged_Choice_Count return Nat;
30014 -- The number of intervals before adjacent intervals are merged
30016 ---------------------------
30017 -- Unmerged_Choice_Count --
30018 ---------------------------
30020 function Unmerged_Choice_Count return Nat is
30021 Choice : Node_Id := First (Discrete_Choices);
30022 Count : Nat := 0;
30023 begin
30024 while Present (Choice) loop
30025 -- Non-contiguous choices involving static predicates
30026 -- have already been normalized away.
30028 if Nkind (Choice) = N_Others_Choice then
30029 Count :=
30030 Count + List_Length (Others_Discrete_Choices (Choice));
30031 else
30032 Count := Count + 1; -- an ordinary expression or range
30033 end if;
30035 Next (Choice);
30036 end loop;
30037 return Count;
30038 end Unmerged_Choice_Count;
30040 -- Local variables
30042 Choice : Node_Id := First (Discrete_Choices);
30043 Result : Discrete_Interval_List (1 .. Unmerged_Choice_Count);
30044 Count : Nat := 0;
30046 -- Start of processing for Choice_List_Intervals
30048 begin
30049 while Present (Choice) loop
30050 if Nkind (Choice) = N_Others_Choice then
30051 declare
30052 Others_Choice : Node_Id
30053 := First (Others_Discrete_Choices (Choice));
30054 begin
30055 while Present (Others_Choice) loop
30056 Count := Count + 1;
30057 Result (Count) := Chosen_Interval (Others_Choice);
30058 Next (Others_Choice);
30059 end loop;
30060 end;
30061 else
30062 Count := Count + 1;
30063 Result (Count) := Chosen_Interval (Choice);
30064 end if;
30066 Next (Choice);
30067 end loop;
30069 pragma Assert (Count = Result'Last);
30070 Normalize_Interval_List (Result, Count);
30071 Check_Consistency (Result (1 .. Count));
30072 return Result (1 .. Count);
30073 end Choice_List_Intervals;
30075 ---------------------
30076 -- Chosen_Interval --
30077 ---------------------
30079 function Chosen_Interval (Choice : Node_Id) return Discrete_Interval is
30080 begin
30081 case Nkind (Choice) is
30082 when N_Range =>
30083 return (Low => Expr_Value (Low_Bound (Choice)),
30084 High => Expr_Value (High_Bound (Choice)));
30086 when N_Subtype_Indication =>
30087 declare
30088 Range_Exp : constant Node_Id
30089 := Range_Expression (Constraint (Choice));
30090 begin
30091 return (Low => Expr_Value (Low_Bound (Range_Exp)),
30092 High => Expr_Value (High_Bound (Range_Exp)));
30093 end;
30095 when N_Others_Choice =>
30096 raise Program_Error;
30098 when others =>
30099 if Is_Entity_Name (Choice) and then Is_Type (Entity (Choice))
30100 then
30101 return
30102 (Low => Expr_Value (Type_Low_Bound (Entity (Choice))),
30103 High => Expr_Value (Type_High_Bound (Entity (Choice))));
30104 else
30105 -- an expression
30106 return (Low | High => Expr_Value (Choice));
30107 end if;
30108 end case;
30109 end Chosen_Interval;
30111 -----------------
30112 -- In_Interval --
30113 -----------------
30115 function In_Interval
30116 (Value : Uint; Interval : Discrete_Interval) return Boolean is
30117 begin
30118 return Value >= Interval.Low and then Value <= Interval.High;
30119 end In_Interval;
30121 ---------------
30122 -- Is_Subset --
30123 ---------------
30125 function Is_Subset
30126 (Subset, Of_Set : Discrete_Interval_List) return Boolean
30128 -- Returns True iff for each interval of Subset we can find
30129 -- a single interval of Of_Set which contains the Subset interval.
30130 begin
30131 if Of_Set'Length = 0 then
30132 return Subset'Length = 0;
30133 end if;
30135 declare
30136 Set_Index : Pos range Of_Set'Range := Of_Set'First;
30138 begin
30139 for Ss_Idx in Subset'Range loop
30140 while not In_Interval
30141 (Value => Subset (Ss_Idx).Low,
30142 Interval => Of_Set (Set_Index))
30143 loop
30144 if Set_Index = Of_Set'Last then
30145 return False;
30146 end if;
30148 Set_Index := Set_Index + 1;
30149 end loop;
30151 if not In_Interval
30152 (Value => Subset (Ss_Idx).High,
30153 Interval => Of_Set (Set_Index))
30154 then
30155 return False;
30156 end if;
30157 end loop;
30158 end;
30160 return True;
30161 end Is_Subset;
30163 -----------------------------
30164 -- Normalize_Interval_List --
30165 -----------------------------
30167 procedure Normalize_Interval_List
30168 (List : in out Discrete_Interval_List; Last : out Nat)
30170 Temp_0 : Discrete_Interval := (others => Uint_0);
30171 -- Cope with Heap_Sort_G idiosyncrasies.
30173 function Is_Null (Idx : Pos) return Boolean;
30174 -- True iff List (Idx) defines a null range
30176 function Lt_Interval (Idx1, Idx2 : Natural) return Boolean;
30177 -- Compare two list elements
30179 procedure Merge_Intervals (Null_Interval_Count : out Nat);
30180 -- Merge contiguous ranges by replacing one with merged range and
30181 -- the other with a null value. Return a count of the null intervals,
30182 -- both preexisting and those introduced by merging.
30184 procedure Move_Interval (From, To : Natural);
30185 -- Copy interval from one location to another
30187 function Read_Interval (From : Natural) return Discrete_Interval;
30188 -- Normal array indexing unless From = 0
30190 ----------------------
30191 -- Interval_Sorting --
30192 ----------------------
30194 package Interval_Sorting is
30195 new Gnat.Heap_Sort_G (Move_Interval, Lt_Interval);
30197 -------------
30198 -- Is_Null --
30199 -------------
30201 function Is_Null (Idx : Pos) return Boolean is
30202 begin
30203 return List (Idx).Low > List (Idx).High;
30204 end Is_Null;
30206 -----------------
30207 -- Lt_Interval --
30208 -----------------
30210 function Lt_Interval (Idx1, Idx2 : Natural) return Boolean is
30211 Elem1 : constant Discrete_Interval := Read_Interval (Idx1);
30212 Elem2 : constant Discrete_Interval := Read_Interval (Idx2);
30213 Null_1 : constant Boolean := Elem1.Low > Elem1.High;
30214 Null_2 : constant Boolean := Elem2.Low > Elem2.High;
30215 begin
30216 if Null_1 /= Null_2 then
30217 -- So that sorting moves null intervals to high end
30218 return Null_2;
30220 elsif Elem1.Low /= Elem2.Low then
30221 return Elem1.Low < Elem2.Low;
30223 else
30224 return Elem1.High < Elem2.High;
30225 end if;
30226 end Lt_Interval;
30228 ---------------------
30229 -- Merge_Intervals --
30230 ---------------------
30232 procedure Merge_Intervals (Null_Interval_Count : out Nat) is
30233 Not_Null : Pos range List'Range;
30234 -- Index of the most recently examined non-null interval
30236 Null_Interval : constant Discrete_Interval
30237 := (Low => Uint_1, High => Uint_0); -- any null range ok here
30238 begin
30239 if List'Length = 0 or else Is_Null (List'First) then
30240 Null_Interval_Count := List'Length;
30241 -- no non-null elements, so no merge candidates
30242 return;
30243 end if;
30245 Null_Interval_Count := 0;
30246 Not_Null := List'First;
30248 for Idx in List'First + 1 .. List'Last loop
30249 if Is_Null (Idx) then
30251 -- all remaining elements are null
30253 Null_Interval_Count :=
30254 Null_Interval_Count + List (Idx .. List'Last)'Length;
30255 return;
30257 elsif List (Idx).Low = List (Not_Null).High + 1 then
30259 -- Merge the two intervals into one; discard the other
30261 List (Not_Null).High := List (Idx).High;
30262 List (Idx) := Null_Interval;
30263 Null_Interval_Count := Null_Interval_Count + 1;
30265 else
30266 if List (Idx).Low <= List (Not_Null).High then
30267 raise Intervals_Error;
30268 end if;
30270 pragma Assert (List (Idx).Low > List (Not_Null).High);
30271 Not_Null := Idx;
30272 end if;
30273 end loop;
30274 end Merge_Intervals;
30276 -------------------
30277 -- Move_Interval --
30278 -------------------
30280 procedure Move_Interval (From, To : Natural) is
30281 Rhs : constant Discrete_Interval := Read_Interval (From);
30282 begin
30283 if To = 0 then
30284 Temp_0 := Rhs;
30285 else
30286 List (Pos (To)) := Rhs;
30287 end if;
30288 end Move_Interval;
30290 -------------------
30291 -- Read_Interval --
30292 -------------------
30294 function Read_Interval (From : Natural) return Discrete_Interval is
30295 begin
30296 if From = 0 then
30297 return Temp_0;
30298 else
30299 return List (Pos (From));
30300 end if;
30301 end Read_Interval;
30303 -- Start of processing for Normalize_Interval_Lists
30305 begin
30306 Interval_Sorting.Sort (Natural (List'Last));
30308 declare
30309 Null_Interval_Count : Nat;
30311 begin
30312 Merge_Intervals (Null_Interval_Count);
30313 Last := List'Last - Null_Interval_Count;
30315 if Null_Interval_Count /= 0 then
30316 -- Move null intervals introduced during merging to high end
30317 Interval_Sorting.Sort (Natural (List'Last));
30318 end if;
30319 end;
30320 end Normalize_Interval_List;
30322 --------------------
30323 -- Type_Intervals --
30324 --------------------
30326 function Type_Intervals (Typ : Entity_Id) return Discrete_Interval_List
30328 begin
30329 if Has_Static_Predicate (Typ) then
30330 declare
30331 -- No sorting or merging needed
30332 SDP_List : constant List_Id := Static_Discrete_Predicate (Typ);
30333 Range_Or_Expr : Node_Id := First (SDP_List);
30334 Result : Discrete_Interval_List (1 .. List_Length (SDP_List));
30336 begin
30337 for Idx in Result'Range loop
30338 Result (Idx) := Chosen_Interval (Range_Or_Expr);
30339 Next (Range_Or_Expr);
30340 end loop;
30342 pragma Assert (No (Range_Or_Expr));
30343 Check_Consistency (Result);
30344 return Result;
30345 end;
30346 else
30347 declare
30348 Low : constant Uint := Expr_Value (Type_Low_Bound (Typ));
30349 High : constant Uint := Expr_Value (Type_High_Bound (Typ));
30350 begin
30351 if Low > High then
30352 declare
30353 Null_Array : Discrete_Interval_List (1 .. 0);
30354 begin
30355 return Null_Array;
30356 end;
30357 else
30358 return (1 => (Low => Low, High => High));
30359 end if;
30360 end;
30361 end if;
30362 end Type_Intervals;
30364 end Interval_Lists;
30366 package body Old_Attr_Util is
30367 package body Conditional_Evaluation is
30368 type Determining_Expr_Context is
30369 (No_Context, If_Expr, Case_Expr, Short_Circuit_Op, Membership_Test);
30371 -- Determining_Expr_Context enumeration elements (except for
30372 -- No_Context) correspond to the list items in RM 6.1.1 definition
30373 -- of "determining expression".
30375 type Determining_Expr
30376 (Context : Determining_Expr_Context := No_Context)
30377 is record
30378 Expr : Node_Id := Empty;
30379 case Context is
30380 when Short_Circuit_Op =>
30381 Is_And_Then : Boolean;
30382 when If_Expr =>
30383 Is_Then_Part : Boolean;
30384 when Case_Expr =>
30385 Alternatives : Node_Id;
30386 when Membership_Test =>
30387 -- Given a subexpression of <exp4> in a membership test
30388 -- <exp1> in <exp2> | <exp3> | <exp4> | <exp5>
30389 -- the corresponding determining expression value would
30390 -- have First_Non_Preceding = <exp4> (See RM 6.1.1).
30391 First_Non_Preceding : Node_Id;
30392 when No_Context =>
30393 null;
30394 end case;
30395 end record;
30397 type Determining_Expression_List is
30398 array (Positive range <>) of Determining_Expr;
30400 function Determining_Condition (Det : Determining_Expr)
30401 return Node_Id;
30402 -- Given a determining expression, build a Boolean-valued
30403 -- condition that incorporates that expression into condition
30404 -- suitable for deciding whether to initialize a 'Old constant.
30405 -- Polarity is "True => initialize the constant".
30407 function Determining_Expressions
30408 (Expr : Node_Id; Expr_Trailer : Node_Id := Empty)
30409 return Determining_Expression_List;
30410 -- Given a conditionally evaluated expression, return its
30411 -- determining expressions.
30412 -- See RM 6.1.1 for definition of term "determining expressions".
30413 -- Tests should be performed in the order they occur in the
30414 -- array, with short circuiting.
30415 -- A determining expression need not be of a boolean type (e.g.,
30416 -- it might be the determining expression of a case expression).
30417 -- The Expr_Trailer parameter should be defaulted for nonrecursive
30418 -- calls.
30420 function Is_Conditionally_Evaluated (Expr : Node_Id) return Boolean;
30421 -- See RM 6.1.1 for definition of term "conditionally evaluated".
30423 function Is_Known_On_Entry (Expr : Node_Id) return Boolean;
30424 -- See RM 6.1.1 for definition of term "known on entry".
30426 --------------------------------------
30427 -- Conditional_Evaluation_Condition --
30428 --------------------------------------
30430 function Conditional_Evaluation_Condition
30431 (Expr : Node_Id) return Node_Id
30433 Determiners : constant Determining_Expression_List :=
30434 Determining_Expressions (Expr);
30435 Loc : constant Source_Ptr := Sloc (Expr);
30436 Result : Node_Id :=
30437 New_Occurrence_Of (Standard_True, Loc);
30438 begin
30439 pragma Assert (Determiners'Length > 0 or else
30440 Is_Anonymous_Access_Type (Etype (Expr)));
30442 for I in Determiners'Range loop
30443 Result := Make_And_Then
30444 (Loc,
30445 Left_Opnd => Result,
30446 Right_Opnd =>
30447 Determining_Condition (Determiners (I)));
30448 end loop;
30449 return Result;
30450 end Conditional_Evaluation_Condition;
30452 ---------------------------
30453 -- Determining_Condition --
30454 ---------------------------
30456 function Determining_Condition (Det : Determining_Expr) return Node_Id
30458 Loc : constant Source_Ptr := Sloc (Det.Expr);
30459 begin
30460 case Det.Context is
30461 when Short_Circuit_Op =>
30462 if Det.Is_And_Then then
30463 return New_Copy_Tree (Det.Expr);
30464 else
30465 return Make_Op_Not (Loc, New_Copy_Tree (Det.Expr));
30466 end if;
30468 when If_Expr =>
30469 if Det.Is_Then_Part then
30470 return New_Copy_Tree (Det.Expr);
30471 else
30472 return Make_Op_Not (Loc, New_Copy_Tree (Det.Expr));
30473 end if;
30475 when Case_Expr =>
30476 declare
30477 Alts : List_Id := Discrete_Choices (Det.Alternatives);
30478 begin
30479 if Nkind (First (Alts)) = N_Others_Choice then
30480 Alts := Others_Discrete_Choices (First (Alts));
30481 end if;
30483 return Make_In (Loc,
30484 Left_Opnd => New_Copy_Tree (Det.Expr),
30485 Right_Opnd => Empty,
30486 Alternatives => New_Copy_List (Alts));
30487 end;
30489 when Membership_Test =>
30490 declare
30491 function Copy_Prefix
30492 (List : List_Id; Suffix_Start : Node_Id)
30493 return List_Id;
30494 -- Given a list and a member of that list, returns
30495 -- a copy (similar to Nlists.New_Copy_List) of the
30496 -- prefix of the list up to but not including
30497 -- Suffix_Start.
30499 -----------------
30500 -- Copy_Prefix --
30501 -----------------
30503 function Copy_Prefix
30504 (List : List_Id; Suffix_Start : Node_Id)
30505 return List_Id
30507 Result : constant List_Id := New_List;
30508 Elem : Node_Id := First (List);
30509 begin
30510 while Elem /= Suffix_Start loop
30511 Append (New_Copy (Elem), Result);
30512 Next (Elem);
30513 pragma Assert (Present (Elem));
30514 end loop;
30515 return Result;
30516 end Copy_Prefix;
30518 begin
30519 return Make_In (Loc,
30520 Left_Opnd => New_Copy_Tree (Left_Opnd (Det.Expr)),
30521 Right_Opnd => Empty,
30522 Alternatives => Copy_Prefix
30523 (Alternatives (Det.Expr),
30524 Det.First_Non_Preceding));
30525 end;
30527 when No_Context =>
30528 raise Program_Error;
30529 end case;
30530 end Determining_Condition;
30532 -----------------------------
30533 -- Determining_Expressions --
30534 -----------------------------
30536 function Determining_Expressions
30537 (Expr : Node_Id; Expr_Trailer : Node_Id := Empty)
30538 return Determining_Expression_List
30540 Par : Node_Id := Expr;
30541 Trailer : Node_Id := Expr_Trailer;
30542 Next_Element : Determining_Expr;
30543 begin
30544 -- We want to stop climbing up the tree when we reach the
30545 -- postcondition expression. An aspect_specification is
30546 -- transformed into a pragma, so reaching a pragma is our
30547 -- termination condition. This relies on the fact that
30548 -- pragmas are not allowed in declare expressions (or any
30549 -- other kind of expression).
30551 loop
30552 Next_Element.Expr := Empty;
30554 case Nkind (Par) is
30555 when N_Short_Circuit =>
30556 if Trailer = Right_Opnd (Par) then
30557 Next_Element :=
30558 (Expr => Left_Opnd (Par),
30559 Context => Short_Circuit_Op,
30560 Is_And_Then => Nkind (Par) = N_And_Then);
30561 end if;
30563 when N_If_Expression =>
30564 -- For an expression like
30565 -- (if C1 then ... elsif C2 then ... else Foo'Old)
30566 -- the RM says are two determining expressions,
30567 -- C1 and C2. Our treatment here (where we only add
30568 -- one determining expression to the list) is ok because
30569 -- we will see two if-expressions, one within the other.
30571 if Trailer /= First (Expressions (Par)) then
30572 Next_Element :=
30573 (Expr => First (Expressions (Par)),
30574 Context => If_Expr,
30575 Is_Then_Part =>
30576 Trailer = Next (First (Expressions (Par))));
30577 end if;
30579 when N_Case_Expression_Alternative =>
30580 pragma Assert (Nkind (Parent (Par)) = N_Case_Expression);
30582 Next_Element :=
30583 (Expr => Expression (Parent (Par)),
30584 Context => Case_Expr,
30585 Alternatives => Par);
30587 when N_Membership_Test =>
30588 if Trailer /= Left_Opnd (Par)
30589 and then Is_Non_Empty_List (Alternatives (Par))
30590 and then Trailer /= First (Alternatives (Par))
30591 then
30592 pragma Assert (No (Right_Opnd (Par)));
30593 pragma Assert
30594 (Is_List_Member (Trailer)
30595 and then List_Containing (Trailer)
30596 = Alternatives (Par));
30598 -- This one is different than the others
30599 -- because one element in the array result
30600 -- may represent multiple determining
30601 -- expressions (i.e. every member of the list
30602 -- Alternatives (Par)
30603 -- up to but not including Trailer).
30605 Next_Element :=
30606 (Expr => Par,
30607 Context => Membership_Test,
30608 First_Non_Preceding => Trailer);
30609 end if;
30611 when N_Pragma =>
30612 declare
30613 Previous : constant Node_Id := Prev (Par);
30614 Prev_Expr : Node_Id;
30615 begin
30616 if Nkind (Previous) = N_Pragma and then
30617 Split_PPC (Previous)
30618 then
30619 -- A source-level postcondition of
30620 -- A and then B and then C
30621 -- results in
30622 -- pragma Postcondition (A);
30623 -- pragma Postcondition (B);
30624 -- pragma Postcondition (C);
30625 -- with Split_PPC set to True on all but the
30626 -- last pragma. We account for that here.
30628 Prev_Expr :=
30629 Expression (First
30630 (Pragma_Argument_Associations (Previous)));
30632 -- This Analyze call is needed in the case when
30633 -- Sem_Attr.Analyze_Attribute calls
30634 -- Eligible_For_Conditional_Evaluation. Without
30635 -- it, we end up passing an unanalyzed expression
30636 -- to Is_Known_On_Entry and that doesn't work.
30638 Analyze (Prev_Expr);
30640 Next_Element :=
30641 (Expr => Prev_Expr,
30642 Context => Short_Circuit_Op,
30643 Is_And_Then => True);
30645 return Determining_Expressions (Prev_Expr)
30646 & Next_Element;
30647 else
30648 pragma Assert
30649 (Get_Pragma_Id (Pragma_Name (Par)) in
30650 Pragma_Post | Pragma_Postcondition
30651 | Pragma_Post_Class | Pragma_Refined_Post
30652 | Pragma_Check | Pragma_Contract_Cases);
30654 return (1 .. 0 => <>); -- recursion terminates here
30655 end if;
30656 end;
30658 when N_Empty =>
30659 -- This case should be impossible, but if it does
30660 -- happen somehow then we don't want an infinite loop.
30661 raise Program_Error;
30663 when others =>
30664 null;
30665 end case;
30667 Trailer := Par;
30668 Par := Parent (Par);
30670 if Present (Next_Element.Expr) then
30671 return Determining_Expressions
30672 (Expr => Par, Expr_Trailer => Trailer)
30673 & Next_Element;
30674 end if;
30675 end loop;
30676 end Determining_Expressions;
30678 -----------------------------------------
30679 -- Eligible_For_Conditional_Evaluation --
30680 -----------------------------------------
30682 function Eligible_For_Conditional_Evaluation
30683 (Expr : Node_Id) return Boolean
30685 begin
30686 if Is_Anonymous_Access_Type (Etype (Expr)) then
30687 -- The code in exp_attr.adb that also builds declarations
30688 -- for 'Old constants doesn't handle the anonymous access
30689 -- type case correctly, so we avoid that problem by
30690 -- returning True here.
30691 return True;
30693 elsif Ada_Version < Ada_2022 then
30694 return False;
30696 elsif Inside_Class_Condition_Preanalysis then
30697 -- No need to evaluate it during preanalysis of a class-wide
30698 -- pre/postcondition since the expression is not installed yet
30699 -- on its definite context.
30700 return False;
30702 elsif not Is_Conditionally_Evaluated (Expr) then
30703 return False;
30704 else
30705 declare
30706 Determiners : constant Determining_Expression_List :=
30707 Determining_Expressions (Expr);
30708 begin
30709 pragma Assert (Determiners'Length > 0);
30711 for Idx in Determiners'Range loop
30712 if not Is_Known_On_Entry (Determiners (Idx).Expr) then
30713 return False;
30714 end if;
30715 end loop;
30716 end;
30717 return True;
30718 end if;
30719 end Eligible_For_Conditional_Evaluation;
30721 --------------------------------
30722 -- Is_Conditionally_Evaluated --
30723 --------------------------------
30725 function Is_Conditionally_Evaluated (Expr : Node_Id) return Boolean
30727 -- There are three possibilities - the expression is
30728 -- unconditionally evaluated, repeatedly evaluated, or
30729 -- conditionally evaluated (see RM 6.1.1). So we implement
30730 -- this test by testing for the other two.
30732 function Is_Repeatedly_Evaluated (Expr : Node_Id) return Boolean;
30733 -- See RM 6.1.1 for definition of "repeatedly evaluated".
30735 -----------------------------
30736 -- Is_Repeatedly_Evaluated --
30737 -----------------------------
30739 function Is_Repeatedly_Evaluated (Expr : Node_Id) return Boolean is
30740 Par : Node_Id := Expr;
30741 Trailer : Node_Id := Empty;
30743 -- There are three ways that an expression can be repeatedly
30744 -- evaluated.
30745 begin
30746 -- An aspect_specification is transformed into a pragma, so
30747 -- reaching a pragma is our termination condition. We want to
30748 -- stop when we reach the postcondition expression.
30750 while Nkind (Par) /= N_Pragma loop
30751 pragma Assert (Present (Par));
30753 -- test for case 1:
30754 -- A subexpression of a predicate of a
30755 -- quantified_expression.
30757 if Nkind (Par) = N_Quantified_Expression
30758 and then Trailer = Condition (Par)
30759 then
30760 return True;
30761 elsif Nkind (Par) = N_Expression_With_Actions
30762 and then
30763 Nkind (Original_Node (Par)) = N_Quantified_Expression
30764 then
30765 return True;
30766 end if;
30768 -- test for cases 2 and 3:
30769 -- A subexpression of the expression of an
30770 -- array_component_association or of
30771 -- a container_element_associatiation.
30773 if Nkind (Par) = N_Component_Association
30774 and then Trailer = Expression (Par)
30775 then
30776 -- determine whether Par is part of an array aggregate
30777 -- or a container aggregate
30778 declare
30779 Rover : Node_Id := Par;
30780 begin
30781 while Nkind (Rover) not in N_Has_Etype loop
30782 pragma Assert (Present (Rover));
30783 Rover := Parent (Rover);
30784 end loop;
30785 if Present (Etype (Rover)) then
30786 if Is_Array_Type (Etype (Rover))
30787 or else Is_Container_Aggregate (Rover)
30788 then
30789 return True;
30790 end if;
30791 end if;
30792 end;
30793 end if;
30795 Trailer := Par;
30796 Par := Parent (Par);
30797 end loop;
30799 return False;
30800 end Is_Repeatedly_Evaluated;
30802 begin
30803 if not Is_Potentially_Unevaluated (Expr) then
30804 -- the expression is unconditionally evaluated
30805 return False;
30806 elsif Is_Repeatedly_Evaluated (Expr) then
30807 return False;
30808 end if;
30810 return True;
30811 end Is_Conditionally_Evaluated;
30813 -----------------------
30814 -- Is_Known_On_Entry --
30815 -----------------------
30817 function Is_Known_On_Entry (Expr : Node_Id) return Boolean is
30818 -- ??? This implementation is incomplete. See RM 6.1.1
30819 -- for details. In particular, this function *should* return
30820 -- True for a function call (or a user-defined literal, which
30821 -- is equivalent to a function call) if all actual parameters
30822 -- (including defaulted params) are known on entry and the
30823 -- function has "Globals => null" specified; the current
30824 -- implementation will incorrectly return False in this case.
30826 function All_Exps_Known_On_Entry
30827 (Expr_List : List_Id) return Boolean;
30828 -- Given a list of expressions, returns False iff
30829 -- Is_Known_On_Entry is False for at least one list element.
30831 -----------------------------
30832 -- All_Exps_Known_On_Entry --
30833 -----------------------------
30835 function All_Exps_Known_On_Entry
30836 (Expr_List : List_Id) return Boolean
30838 Expr : Node_Id := First (Expr_List);
30839 begin
30840 while Present (Expr) loop
30841 if not Is_Known_On_Entry (Expr) then
30842 return False;
30843 end if;
30844 Next (Expr);
30845 end loop;
30846 return True;
30847 end All_Exps_Known_On_Entry;
30849 begin
30850 if Is_Static_Expression (Expr) then
30851 return True;
30852 end if;
30854 if Is_Attribute_Old (Expr) then
30855 return True;
30856 end if;
30858 declare
30859 Pref : Node_Id := Expr;
30860 begin
30861 loop
30862 case Nkind (Pref) is
30863 when N_Selected_Component =>
30864 null;
30866 when N_Indexed_Component =>
30867 if not All_Exps_Known_On_Entry (Expressions (Pref))
30868 then
30869 return False;
30870 end if;
30872 when N_Slice =>
30873 return False; -- just to be clear about this case
30875 when others =>
30876 exit;
30877 end case;
30879 Pref := Prefix (Pref);
30880 end loop;
30882 if Is_Entity_Name (Pref)
30883 and then Is_Constant_Object (Entity (Pref))
30884 then
30885 declare
30886 Obj : constant Entity_Id := Entity (Pref);
30887 Obj_Typ : constant Entity_Id := Etype (Obj);
30888 begin
30889 case Ekind (Obj) is
30890 when E_In_Parameter =>
30891 if not Is_Elementary_Type (Obj_Typ) then
30892 return False;
30893 elsif Is_Aliased (Obj) then
30894 return False;
30895 end if;
30897 when E_Constant =>
30898 -- return False for a deferred constant
30899 if Present (Full_View (Obj)) then
30900 return False;
30901 end if;
30903 -- return False if not "all views are constant".
30904 if Is_Immutably_Limited_Type (Obj_Typ)
30905 or Needs_Finalization (Obj_Typ)
30906 then
30907 return False;
30908 end if;
30910 when others =>
30911 null;
30912 end case;
30913 end;
30915 return True;
30916 end if;
30918 -- ??? Cope with a malformed tree. Code to cope with a
30919 -- nonstatic use of an enumeration literal should not be
30920 -- necessary.
30921 if Is_Entity_Name (Pref)
30922 and then Ekind (Entity (Pref)) = E_Enumeration_Literal
30923 then
30924 return True;
30925 end if;
30926 end;
30928 case Nkind (Expr) is
30929 when N_Unary_Op =>
30930 return Is_Known_On_Entry (Right_Opnd (Expr));
30932 when N_Binary_Op =>
30933 return Is_Known_On_Entry (Left_Opnd (Expr))
30934 and then Is_Known_On_Entry (Right_Opnd (Expr));
30936 when N_Type_Conversion | N_Qualified_Expression =>
30937 return Is_Known_On_Entry (Expression (Expr));
30939 when N_If_Expression =>
30940 if not All_Exps_Known_On_Entry (Expressions (Expr)) then
30941 return False;
30942 end if;
30944 when N_Case_Expression =>
30945 if not Is_Known_On_Entry (Expression (Expr)) then
30946 return False;
30947 end if;
30949 declare
30950 Alt : Node_Id := First (Alternatives (Expr));
30951 begin
30952 while Present (Alt) loop
30953 if not Is_Known_On_Entry (Expression (Alt)) then
30954 return False;
30955 end if;
30956 Next (Alt);
30957 end loop;
30958 end;
30960 return True;
30962 when others =>
30963 null;
30964 end case;
30966 return False;
30967 end Is_Known_On_Entry;
30969 end Conditional_Evaluation;
30971 package body Indirect_Temps is
30973 Indirect_Temp_Access_Type_Char : constant Character := 'K';
30974 -- The character passed to Make_Temporary when declaring
30975 -- the access type that is used in the implementation of an
30976 -- indirect temporary.
30978 --------------------------
30979 -- Indirect_Temp_Needed --
30980 --------------------------
30982 function Indirect_Temp_Needed (Typ : Entity_Id) return Boolean is
30983 begin
30984 -- There should be no correctness issues if the only cases where
30985 -- this function returns False are cases where Typ is an
30986 -- anonymous access type and we need to generate a saooaaat (a
30987 -- stand-alone object of an anonymous access type) in order get
30988 -- accessibility right. In other cases where this function
30989 -- returns False, there would be no correctness problems with
30990 -- returning True instead; however, returning False when we can
30991 -- generally results in simpler code.
30993 return False
30995 -- If Typ is not definite, then we cannot generate
30996 -- Temp : Typ;
30998 or else not Is_Definite_Subtype (Typ)
31000 -- If Typ is tagged, then generating
31001 -- Temp : Typ;
31002 -- might generate an object with the wrong tag. If we had
31003 -- a predicate that indicated whether the nominal tag is
31004 -- trustworthy, we could use that predicate here.
31006 or else Is_Tagged_Type (Typ)
31008 -- If Typ needs finalization, then generating an implicit
31009 -- Temp : Typ;
31010 -- declaration could have user-visible side effects.
31012 or else Needs_Finalization (Typ)
31014 -- In the anonymous access type case, we need to
31015 -- generate a saooaaat. We don't want the code in
31016 -- in exp_attr.adb that deals with the case where this
31017 -- function returns False to have to deal with that case
31018 -- (just to avoid code duplication). So we cheat a little
31019 -- bit and return True here for an anonymous access type.
31021 or else Is_Anonymous_Access_Type (Typ);
31023 -- ??? Unimplemented - spec description says:
31024 -- For an unconstrained-but-definite discriminated subtype,
31025 -- returns True if the potential difference in size between an
31026 -- unconstrained object and a constrained object is large.
31028 -- For example,
31029 -- type Typ (Len : Natural := 0) is
31030 -- record F : String (1 .. Len); end record;
31032 -- See Large_Max_Size_Mutable function elsewhere in this file,
31033 -- currently declared inside of Needs_Secondary_Stack, so it
31034 -- would have to be moved if we want it to be callable from here.
31036 end Indirect_Temp_Needed;
31038 ---------------------------
31039 -- Declare_Indirect_Temp --
31040 ---------------------------
31042 procedure Declare_Indirect_Temp
31043 (Attr_Prefix : Node_Id; Indirect_Temp : out Entity_Id)
31045 Loc : constant Source_Ptr := Sloc (Attr_Prefix);
31046 Prefix_Type : constant Entity_Id := Etype (Attr_Prefix);
31047 Temp_Id : constant Entity_Id :=
31048 Make_Temporary (Loc, 'P', Attr_Prefix);
31050 procedure Declare_Indirect_Temp_Via_Allocation;
31051 -- Handle the usual case.
31053 -------------------------------------------
31054 -- Declare_Indirect_Temp_Via_Allocation --
31055 -------------------------------------------
31057 procedure Declare_Indirect_Temp_Via_Allocation is
31058 Access_Type_Id : constant Entity_Id
31059 := Make_Temporary
31060 (Loc, Indirect_Temp_Access_Type_Char, Attr_Prefix);
31062 Temp_Decl : constant Node_Id :=
31063 Make_Object_Declaration (Loc,
31064 Defining_Identifier => Temp_Id,
31065 Object_Definition =>
31066 New_Occurrence_Of (Access_Type_Id, Loc));
31068 Allocate_Class_Wide : constant Boolean :=
31069 Is_Specific_Tagged_Type (Prefix_Type);
31070 -- If True then access type designates the class-wide type in
31071 -- order to preserve (at run time) the value of the underlying
31072 -- tag.
31073 -- ??? We could do better here (in the case where Prefix_Type
31074 -- is tagged and specific) if we had a predicate which takes an
31075 -- expression and returns True iff the expression is of
31076 -- a specific tagged type and the underlying tag (at run time)
31077 -- is statically known to match that of the specific type.
31078 -- In that case, Allocate_Class_Wide could safely be False.
31080 function Designated_Subtype_Mark return Node_Id;
31081 -- Usually, a subtype mark indicating the subtype of the
31082 -- attribute prefix. If that subtype is a specific tagged
31083 -- type, then returns the corresponding class-wide type.
31084 -- If the prefix is of an anonymous access type, then returns
31085 -- the designated type of that type.
31087 -----------------------------
31088 -- Designated_Subtype_Mark --
31089 -----------------------------
31091 function Designated_Subtype_Mark return Node_Id is
31092 Typ : Entity_Id := Prefix_Type;
31093 begin
31094 if Allocate_Class_Wide then
31095 if Is_Private_Type (Typ)
31096 and then Present (Full_View (Typ))
31097 then
31098 Typ := Full_View (Typ);
31099 end if;
31100 Typ := Class_Wide_Type (Typ);
31101 end if;
31103 return New_Occurrence_Of (Typ, Loc);
31104 end Designated_Subtype_Mark;
31106 Access_Type_Def : constant Node_Id
31107 := Make_Access_To_Object_Definition
31108 (Loc, Subtype_Indication => Designated_Subtype_Mark);
31110 Access_Type_Decl : constant Node_Id
31111 := Make_Full_Type_Declaration
31112 (Loc, Access_Type_Id,
31113 Type_Definition => Access_Type_Def);
31114 begin
31115 Mutate_Ekind (Temp_Id, E_Variable);
31116 Set_Etype (Temp_Id, Access_Type_Id);
31117 Mutate_Ekind (Access_Type_Id, E_Access_Type);
31119 if Append_Decls_In_Reverse_Order then
31120 Append_Item (Temp_Decl, Is_Eval_Stmt => False);
31121 Append_Item (Access_Type_Decl, Is_Eval_Stmt => False);
31122 else
31123 Append_Item (Access_Type_Decl, Is_Eval_Stmt => False);
31124 Append_Item (Temp_Decl, Is_Eval_Stmt => False);
31125 end if;
31127 -- When a type associated with an indirect temporary gets
31128 -- created for a 'Old attribute reference we need to mark
31129 -- the type as such. This allows, for example, finalization
31130 -- masters associated with them to be finalized in the correct
31131 -- order after postcondition checks.
31133 if Attribute_Name (Parent (Attr_Prefix)) = Name_Old then
31134 Set_Stores_Attribute_Old_Prefix (Access_Type_Id);
31135 end if;
31137 Analyze (Access_Type_Decl);
31138 Analyze (Temp_Decl);
31140 pragma Assert
31141 (Is_Access_Type_For_Indirect_Temp (Access_Type_Id));
31143 declare
31144 Expression : Node_Id := Attr_Prefix;
31145 Allocator : Node_Id;
31146 begin
31147 if Allocate_Class_Wide then
31148 -- generate T'Class'(T'Class (<prefix>))
31149 Expression :=
31150 Make_Type_Conversion (Loc,
31151 Subtype_Mark => Designated_Subtype_Mark,
31152 Expression => Expression);
31153 end if;
31155 Allocator :=
31156 Make_Allocator (Loc,
31157 Make_Qualified_Expression
31158 (Loc,
31159 Subtype_Mark => Designated_Subtype_Mark,
31160 Expression => Expression));
31162 -- Allocate saved prefix value on the secondary stack
31163 -- in order to avoid introducing a storage leak. This
31164 -- allocated object is never explicitly reclaimed.
31166 -- ??? Emit storage leak warning if RE_SS_Pool
31167 -- unavailable?
31169 if RTE_Available (RE_SS_Pool) then
31170 Set_Storage_Pool (Allocator, RTE (RE_SS_Pool));
31171 Set_Procedure_To_Call
31172 (Allocator, RTE (RE_SS_Allocate));
31173 Set_Uses_Sec_Stack (Current_Scope);
31174 end if;
31176 Append_Item
31177 (Make_Assignment_Statement (Loc,
31178 Name => New_Occurrence_Of (Temp_Id, Loc),
31179 Expression => Allocator),
31180 Is_Eval_Stmt => True);
31181 end;
31182 end Declare_Indirect_Temp_Via_Allocation;
31184 begin
31185 Indirect_Temp := Temp_Id;
31187 if Is_Anonymous_Access_Type (Prefix_Type) then
31188 -- In the anonymous access type case, we do not want a level
31189 -- indirection (which would result in declaring an
31190 -- access-to-access type); that would result in correctness
31191 -- problems - the accessibility level of the type of the
31192 -- 'Old constant would be wrong (See 6.1.1.). So in that case,
31193 -- we do not generate an allocator. Instead we generate
31194 -- Temp : access Designated := null;
31195 -- which is unconditionally elaborated and then
31196 -- Temp := <attribute prefix>;
31197 -- which is conditionally executed.
31199 declare
31200 Temp_Decl : constant Node_Id :=
31201 Make_Object_Declaration (Loc,
31202 Defining_Identifier => Temp_Id,
31203 Object_Definition =>
31204 Make_Access_Definition
31205 (Loc,
31206 Constant_Present =>
31207 Is_Access_Constant (Prefix_Type),
31208 Subtype_Mark =>
31209 New_Occurrence_Of
31210 (Designated_Type (Prefix_Type), Loc)));
31211 begin
31212 Append_Item (Temp_Decl, Is_Eval_Stmt => False);
31213 Analyze (Temp_Decl);
31214 Append_Item
31215 (Make_Assignment_Statement (Loc,
31216 Name => New_Occurrence_Of (Temp_Id, Loc),
31217 Expression => Attr_Prefix),
31218 Is_Eval_Stmt => True);
31219 end;
31220 else
31221 -- the usual case
31222 Declare_Indirect_Temp_Via_Allocation;
31223 end if;
31224 end Declare_Indirect_Temp;
31226 -------------------------
31227 -- Indirect_Temp_Value --
31228 -------------------------
31230 function Indirect_Temp_Value
31231 (Temp : Entity_Id;
31232 Typ : Entity_Id;
31233 Loc : Source_Ptr) return Node_Id
31235 Result : Node_Id;
31236 begin
31237 if Is_Anonymous_Access_Type (Typ) then
31238 -- No indirection in this case; just evaluate the temp.
31239 Result := New_Occurrence_Of (Temp, Loc);
31240 Set_Etype (Result, Etype (Temp));
31242 else
31243 Result := Make_Explicit_Dereference (Loc,
31244 New_Occurrence_Of (Temp, Loc));
31246 Set_Etype (Result, Designated_Type (Etype (Temp)));
31248 if Is_Specific_Tagged_Type (Typ) then
31249 -- The designated type of the access type is class-wide, so
31250 -- convert to the specific type.
31252 Result :=
31253 Make_Type_Conversion (Loc,
31254 Subtype_Mark => New_Occurrence_Of (Typ, Loc),
31255 Expression => Result);
31257 Set_Etype (Result, Typ);
31258 end if;
31259 end if;
31261 return Result;
31262 end Indirect_Temp_Value;
31264 function Is_Access_Type_For_Indirect_Temp
31265 (T : Entity_Id) return Boolean is
31266 begin
31267 if Is_Access_Type (T)
31268 and then not Comes_From_Source (T)
31269 and then Is_Internal_Name (Chars (T))
31270 and then Nkind (Scope (T)) in N_Entity
31271 and then Ekind (Scope (T))
31272 in E_Entry | E_Entry_Family | E_Function | E_Procedure
31273 and then
31274 (Present (Wrapped_Statements (Scope (T)))
31275 or else Present (Contract (Scope (T))))
31276 then
31277 -- ??? Should define a flag for this. We could incorrectly
31278 -- return True if other clients of Make_Temporary happen to
31279 -- pass in the same character.
31280 declare
31281 Name : constant String := Get_Name_String (Chars (T));
31282 begin
31283 if Name (Name'First) = Indirect_Temp_Access_Type_Char then
31284 return True;
31285 end if;
31286 end;
31287 end if;
31289 return False;
31290 end Is_Access_Type_For_Indirect_Temp;
31292 end Indirect_Temps;
31293 end Old_Attr_Util;
31295 package body Storage_Model_Support is
31297 -----------------------------------------
31298 -- Has_Designated_Storage_Model_Aspect --
31299 -----------------------------------------
31301 function Has_Designated_Storage_Model_Aspect
31302 (Typ : Entity_Id) return Boolean
31304 begin
31305 return Has_Aspect (Typ, Aspect_Designated_Storage_Model);
31306 end Has_Designated_Storage_Model_Aspect;
31308 -----------------------------------
31309 -- Has_Storage_Model_Type_Aspect --
31310 -----------------------------------
31312 function Has_Storage_Model_Type_Aspect (Typ : Entity_Id) return Boolean
31314 begin
31315 return Has_Aspect (Typ, Aspect_Storage_Model_Type);
31316 end Has_Storage_Model_Type_Aspect;
31318 --------------------------
31319 -- Storage_Model_Object --
31320 --------------------------
31322 function Storage_Model_Object (Typ : Entity_Id) return Entity_Id is
31323 begin
31324 pragma Assert (Has_Designated_Storage_Model_Aspect (Typ));
31326 return
31327 Entity
31328 (Find_Value_Of_Aspect (Typ, Aspect_Designated_Storage_Model));
31329 end Storage_Model_Object;
31331 ------------------------
31332 -- Storage_Model_Type --
31333 ------------------------
31335 function Storage_Model_Type (Obj : Entity_Id) return Entity_Id is
31336 begin
31337 pragma Assert (Has_Storage_Model_Type_Aspect (Etype (Obj)));
31339 return Etype (Obj);
31340 end Storage_Model_Type;
31342 -----------------------------------
31343 -- Get_Storage_Model_Type_Entity --
31344 -----------------------------------
31346 function Get_Storage_Model_Type_Entity
31347 (SM_Obj_Or_Type : Entity_Id;
31348 Nam : Name_Id) return Entity_Id
31350 Typ : constant Entity_Id := (if Is_Object (SM_Obj_Or_Type) then
31351 Storage_Model_Type (SM_Obj_Or_Type)
31352 else
31353 SM_Obj_Or_Type);
31354 pragma Assert
31355 (Is_Type (Typ)
31356 and then
31357 Nam in Name_Address_Type
31358 | Name_Null_Address
31359 | Name_Allocate
31360 | Name_Deallocate
31361 | Name_Copy_From
31362 | Name_Copy_To
31363 | Name_Storage_Size);
31365 Assoc : Node_Id;
31366 SMT_Aspect_Value : constant Node_Id :=
31367 Find_Value_Of_Aspect (Typ, Aspect_Storage_Model_Type);
31369 begin
31370 -- When the aspect has an aggregate expression, search through it
31371 -- to locate a match for the name of the given "subaspect" and return
31372 -- the entity of the aggregate association's expression.
31374 if Present (SMT_Aspect_Value) then
31375 Assoc := First (Component_Associations (SMT_Aspect_Value));
31376 while Present (Assoc) loop
31377 if Chars (First (Choices (Assoc))) = Nam then
31378 return Entity (Expression (Assoc));
31379 end if;
31381 Next (Assoc);
31382 end loop;
31383 end if;
31385 -- The aggregate argument of Storage_Model_Type is optional, and when
31386 -- not present the aspect defaults to the native storage model, where
31387 -- the address type is System.Address. In that case, we return
31388 -- System.Address for Name_Address_Type and System.Null_Address for
31389 -- Name_Null_Address, but return Empty for other cases, and leave it
31390 -- to the back end to map those to the appropriate native operations.
31392 if Nam = Name_Address_Type then
31393 return RTE (RE_Address);
31395 elsif Nam = Name_Null_Address then
31396 return RTE (RE_Null_Address);
31398 else
31399 return Empty;
31400 end if;
31401 end Get_Storage_Model_Type_Entity;
31403 --------------------------------
31404 -- Storage_Model_Address_Type --
31405 --------------------------------
31407 function Storage_Model_Address_Type
31408 (SM_Obj_Or_Type : Entity_Id) return Entity_Id
31410 begin
31411 return
31412 Get_Storage_Model_Type_Entity (SM_Obj_Or_Type, Name_Address_Type);
31413 end Storage_Model_Address_Type;
31415 --------------------------------
31416 -- Storage_Model_Null_Address --
31417 --------------------------------
31419 function Storage_Model_Null_Address
31420 (SM_Obj_Or_Type : Entity_Id) return Entity_Id
31422 begin
31423 return
31424 Get_Storage_Model_Type_Entity (SM_Obj_Or_Type, Name_Null_Address);
31425 end Storage_Model_Null_Address;
31427 ----------------------------
31428 -- Storage_Model_Allocate --
31429 ----------------------------
31431 function Storage_Model_Allocate
31432 (SM_Obj_Or_Type : Entity_Id) return Entity_Id
31434 begin
31435 return Get_Storage_Model_Type_Entity (SM_Obj_Or_Type, Name_Allocate);
31436 end Storage_Model_Allocate;
31438 ------------------------------
31439 -- Storage_Model_Deallocate --
31440 ------------------------------
31442 function Storage_Model_Deallocate
31443 (SM_Obj_Or_Type : Entity_Id) return Entity_Id
31445 begin
31446 return
31447 Get_Storage_Model_Type_Entity (SM_Obj_Or_Type, Name_Deallocate);
31448 end Storage_Model_Deallocate;
31450 -----------------------------
31451 -- Storage_Model_Copy_From --
31452 -----------------------------
31454 function Storage_Model_Copy_From
31455 (SM_Obj_Or_Type : Entity_Id) return Entity_Id
31457 begin
31458 return Get_Storage_Model_Type_Entity (SM_Obj_Or_Type, Name_Copy_From);
31459 end Storage_Model_Copy_From;
31461 ---------------------------
31462 -- Storage_Model_Copy_To --
31463 ---------------------------
31465 function Storage_Model_Copy_To
31466 (SM_Obj_Or_Type : Entity_Id) return Entity_Id
31468 begin
31469 return Get_Storage_Model_Type_Entity (SM_Obj_Or_Type, Name_Copy_To);
31470 end Storage_Model_Copy_To;
31472 --------------------------------
31473 -- Storage_Model_Storage_Size --
31474 --------------------------------
31476 function Storage_Model_Storage_Size
31477 (SM_Obj_Or_Type : Entity_Id) return Entity_Id
31479 begin
31480 return
31481 Get_Storage_Model_Type_Entity (SM_Obj_Or_Type, Name_Storage_Size);
31482 end Storage_Model_Storage_Size;
31484 end Storage_Model_Support;
31486 begin
31487 Erroutc.Subprogram_Name_Ptr := Subprogram_Name'Access;
31488 end Sem_Util;